<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.tmerclub.cloud.biz.mapper.AttachFileGroupMapper">
  <resultMap id="attachFileGroupMap" type="com.tmerclub.cloud.biz.model.AttachFileGroup">
    <id column="attach_file_group_id" property="attachFileGroupId" />
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="shop_id" property="shopId"/>
    <result column="uid" property="uid"/>
    <result column="name" property="name"/>
    <result column="type" property="type"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `attach_file_group_id`,`create_time`,`update_time`,`shop_id`,`sys_type`,`uid`,`name`,`type`
  </sql>
  <select id="list" resultType="com.tmerclub.cloud.biz.vo.AttachFileGroupVO">
    select `attach_file_group_id`,`create_time`,`update_time`,`shop_id`,`name` from attach_file_group
    <where>
      <if test="shopId != null">
        and shop_id = #{shopId}
      </if>
      <if test="sysType != null">
        and sys_type = #{sysType}
      </if>
      <if test="uid != null">
        and uid = #{uid}
      </if>
      <if test="type != null">
        and `type` = #{type}
      </if>
    </where>
    order by attach_file_group_id desc
  </select>
  <select id="getByAttachFileGroupId" resultType="com.tmerclub.cloud.biz.vo.AttachFileGroupVO">
    select `attach_file_group_id`,`create_time`,`update_time`,`shop_id`,`name` from attach_file_group where attach_file_group_id = #{attachFileGroupId}
  </select>
  <select id="countByNameAndShopId" resultType="java.lang.Integer">
    select count(*) from `attach_file_group`
    where
          shop_id = #{shopId}
        and `name` = #{name} and `sys_type` = #{sysType} and type = #{type}
        <if test="attachFileGroupId != null and attachFileGroupId != ''">
          and attach_file_group_id != #{attachFileGroupId}
        </if>
  </select>
  <insert id="save">
    insert into attach_file_group (`shop_id`,`uid`,`name`,`type`,`sys_type`)
    values (#{attachFileGroup.shopId},#{attachFileGroup.uid},#{attachFileGroup.name},#{attachFileGroup.type},#{attachFileGroup.sysType});
  </insert>
  <update id="update">
    update attach_file_group
    <set>
      <if test="attachFileGroup.name != null">
        `name` = #{attachFileGroup.name},
      </if>
    </set>
    where attach_file_group_id = #{attachFileGroup.attachFileGroupId} and shop_id = #{attachFileGroup.shopId}
  </update>
  <update id="updateShopIdByUid">
    update attach_file_group set shop_id = #{shopId} where uid = #{uid}
  </update>
  <delete id="deleteById">
    delete from attach_file_group where attach_file_group_id = #{attachFileGroupId}
  </delete>

</mapper>
