<?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.goafanti.common.dao.BusinessCategoryMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.BusinessCategory">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="create_id" jdbcType="VARCHAR" property="createId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="delete_sign" jdbcType="INTEGER" property="deleteSign" />
    <result column="cid" jdbcType="VARCHAR" property="cid" />
    <result column="cname" jdbcType="VARCHAR" property="cname" />
    <result column="super_id" jdbcType="VARCHAR" property="superId" />
    <result column="layer" jdbcType="INTEGER" property="layer" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="varieties_logo" jdbcType="VARCHAR" property="varietiesLogo" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    id, create_id, create_time, update_time, delete_sign, cid, cname, super_id, layer, 
    status, varieties_logo, sort
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.BusinessCategoryExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from business_category
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from business_category
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    delete from business_category
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.BusinessCategoryExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    delete from business_category
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.BusinessCategory">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    insert into business_category (id, create_id, create_time, 
      update_time, delete_sign, cid, 
      cname, super_id, layer, 
      status, varieties_logo, sort
      )
    values (#{id,jdbcType=VARCHAR}, #{createId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{deleteSign,jdbcType=INTEGER}, #{cid,jdbcType=VARCHAR}, 
      #{cname,jdbcType=VARCHAR}, #{superId,jdbcType=VARCHAR}, #{layer,jdbcType=INTEGER}, 
      #{status,jdbcType=VARCHAR}, #{varietiesLogo,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.BusinessCategory">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    insert into business_category
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="createId != null">
        create_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="deleteSign != null">
        delete_sign,
      </if>
      <if test="cid != null">
        cid,
      </if>
      <if test="cname != null">
        cname,
      </if>
      <if test="superId != null">
        super_id,
      </if>
      <if test="layer != null">
        layer,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="varietiesLogo != null">
        varieties_logo,
      </if>
      <if test="sort != null">
        sort,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="createId != null">
        #{createId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteSign != null">
        #{deleteSign,jdbcType=INTEGER},
      </if>
      <if test="cid != null">
        #{cid,jdbcType=VARCHAR},
      </if>
      <if test="cname != null">
        #{cname,jdbcType=VARCHAR},
      </if>
      <if test="superId != null">
        #{superId,jdbcType=VARCHAR},
      </if>
      <if test="layer != null">
        #{layer,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="varietiesLogo != null">
        #{varietiesLogo,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.BusinessCategoryExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    select count(*) from business_category
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    update business_category
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.createId != null">
        create_id = #{record.createId,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deleteSign != null">
        delete_sign = #{record.deleteSign,jdbcType=INTEGER},
      </if>
      <if test="record.cid != null">
        cid = #{record.cid,jdbcType=VARCHAR},
      </if>
      <if test="record.cname != null">
        cname = #{record.cname,jdbcType=VARCHAR},
      </if>
      <if test="record.superId != null">
        super_id = #{record.superId,jdbcType=VARCHAR},
      </if>
      <if test="record.layer != null">
        layer = #{record.layer,jdbcType=INTEGER},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=VARCHAR},
      </if>
      <if test="record.varietiesLogo != null">
        varieties_logo = #{record.varietiesLogo,jdbcType=VARCHAR},
      </if>
      <if test="record.sort != null">
        sort = #{record.sort,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    update business_category
    set id = #{record.id,jdbcType=VARCHAR},
      create_id = #{record.createId,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      delete_sign = #{record.deleteSign,jdbcType=INTEGER},
      cid = #{record.cid,jdbcType=VARCHAR},
      cname = #{record.cname,jdbcType=VARCHAR},
      super_id = #{record.superId,jdbcType=VARCHAR},
      layer = #{record.layer,jdbcType=INTEGER},
      status = #{record.status,jdbcType=VARCHAR},
      varieties_logo = #{record.varietiesLogo,jdbcType=VARCHAR},
      sort = #{record.sort,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.BusinessCategory">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    update business_category
    <set>
      <if test="createId != null">
        create_id = #{createId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteSign != null">
        delete_sign = #{deleteSign,jdbcType=INTEGER},
      </if>
      <if test="cid != null">
        cid = #{cid,jdbcType=VARCHAR},
      </if>
      <if test="cname != null">
        cname = #{cname,jdbcType=VARCHAR},
      </if>
      <if test="superId != null">
        super_id = #{superId,jdbcType=VARCHAR},
      </if>
      <if test="layer != null">
        layer = #{layer,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=VARCHAR},
      </if>
      <if test="varietiesLogo != null">
        varieties_logo = #{varietiesLogo,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.BusinessCategory">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 09 15:08:39 CST 2018.
    -->
    update business_category
    set create_id = #{createId,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      delete_sign = #{deleteSign,jdbcType=INTEGER},
      cid = #{cid,jdbcType=VARCHAR},
      cname = #{cname,jdbcType=VARCHAR},
      super_id = #{superId,jdbcType=VARCHAR},
      layer = #{layer,jdbcType=INTEGER},
      status = #{status,jdbcType=VARCHAR},
      varieties_logo = #{varietiesLogo,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="getCount" resultType="string">
  	select count(1) from business_category
  	where delete_sign=0
  	and super_id=#{superId,jdbcType=VARCHAR} 
  	</select>
  	
  	<select id="getCid" resultType="string">
  	select cid from business_category
  	where id=#{ superId,jdbcType=VARCHAR} 
  	</select>
  	
  	<select id="findVarietiesListByPage" resultType="com.goafanti.business.bo.BusinessVarietiesBo">
 		 select b.id,b.create_id as createId ,b.create_time as createTime,b.update_time as updateTime,b.sort,
  		b.delete_sign daleteSign,b.cid,b.cname,b.super_id superId ,b.layer,b.status,b2.cname as superName
  		from business_category b
  		left join business_category b2 on b.super_id = b2.id
  		where b.delete_sign=0 and b.layer&gt;0
 		<if test="cname != null">
		and b.cname like CONCAT('%',#{cname,jdbcType=VARCHAR},'%')
		</if>
		<if test="superId != null">
		and b.super_id = #{superId,jdbcType=VARCHAR}
		</if>
		<if test="layer != null">
		and b.layer = #{layer,jdbcType=INTEGER}
		</if>
		<if test="status != null">
		and b.status = #{status,jdbcType=VARCHAR}
		</if>
		ORDER BY if(isnull(b.sort),1,0),b.sort
		<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  <select id="findVarietiesListCount" resultType="Integer">
 		select 
  			count(0)
  		from business_category b
  		 left join business_category b2 on b.super_id = b2.id
  		where b.delete_sign=0 and b.layer&gt;0
  		<if test="cname != null">
		and b.cname like CONCAT('%',#{cname,jdbcType=VARCHAR},'%')
		</if>
		<if test="superId != null">
		and b.super_id = #{superId,jdbcType=VARCHAR}
		</if>
		<if test="layer != null">
		and b.layer = #{layer,jdbcType=INTEGER}
		</if>
		<if test="status != null">
		and b.status = #{status,jdbcType=VARCHAR}
		</if>
		
  </select>
  
  <select id="getSuperList" resultType="com.goafanti.business.bo.BusinessVarietiesBo">
  		select b.id,b.create_id as createId ,b.create_time as createTime,b.update_time as updateTime,
  		b.delete_sign daleteSign,b.cid,b.cname,b.super_id superId ,b.layer,b.status
  		from business_category b
  		where b.delete_sign=0 and status=0
  </select>
  <select id="editVarieties" parameterType="string" resultType="com.goafanti.business.bo.BusinessVarietiesBo">
  		 select b.id,b.create_id as createId ,b.create_time as createTime,b.update_time as updateTime,b.varieties_logo as varietiesLogo,
  		b.delete_sign as deleteSign,b.cid,b.cname,b.super_id superId ,b.layer,b.status,b2.cname superName,a.name as createName,b.sort
  		from business_category b 
  		 left join business_category b2 on b.super_id = b2.id
  		 left join admin a on b.create_id = a.id
  		where b.delete_sign=0
 	<if test="id != null">
		and b.id = #{id,jdbcType=VARCHAR}
	</if>
  </select>
  
  <select id="ThanCid" resultType="string">
  		select b.id 
  		from business_category b
  		where b.cid= #{cid,jdbcType=VARCHAR} 
  	</select>
  	
  	<select id="getcname" resultType="Integer">
  		select count(1) 
  		from business_category b
  		where b.delete_sign=0
  		and b.cname= #{cname,jdbcType=VARCHAR}
  	</select>
  	
  	<select id="selectSuperid" resultType="com.goafanti.business.bo.BusinessVarietiesBo">
  		select b.id,b.create_id as createId ,b.create_time as createTime,b.update_time as updateTime,
  		b.delete_sign as deleteSign,b.cid,b.cname,b.super_id superId ,b.layer,b.status
  		from business_category b 
  		where b.delete_sign=0
  		and b.super_id= #{superId,jdbcType=VARCHAR}
  	</select>
  	
  	<select id="getThisCid" resultType="String">
  		select b.cid
  		from business_category b
  		
  		where b.id= #{id,jdbcType=VARCHAR}
  	</select>
  	
  	<select id="getThisCname" resultType="String">
  		select b.cname
  		from business_category b
  		where b.cid= #{cid,jdbcType=VARCHAR}
  	</select>
  	
  	<select id="getListId" resultType="String">
  		select b.id
  		from business_category b
  		where b.delete_sign=0
  		and b.status=0
  	</select>
  	
  	<select id="getLayer" resultType="Integer">
  		select b.layer
  		from business_category b
  		where b.delete_sign=0
  		and b.id= #{superId,jdbcType=VARCHAR}
  	</select>
  	<select id="getVarieties" resultType="com.goafanti.business.bo.VarietiesBo">
  		    select id, cname AS name, varieties_logo as varietiesLogo ,sort
	from business_category b
	where b.delete_sign=0
	and b.status=0
	and b.layer=1
	ORDER BY b.sort
  	</select>
  	
  	<select id="getCidMax" resultType="String">
  		select max(cid)
  from business_category
 where super_id=#{superId,jdbcType=VARCHAR}
  	</select>
  	
  	<select id="getSortMax" resultType="String">
  		select max(sort)
  from business_category
 	</select>
 	
 	<select id="selectBySort"  resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from business_category
    where sort = #{sort,jdbcType=VARCHAR}
  </select>
  
  <update id="updateFollowSort" parameterType="com.goafanti.common.model.BusinessCategory">
    update business_category
    set sort = sort-1
    where sort > #{sort,jdbcType=VARCHAR}
  </update>
</mapper>