<?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.hzya.frame.plugin.lets.dao.impl.BdSalestruDaoImpl">

    <resultMap id="get-BdSalestruEntity-result" type="com.hzya.frame.plugin.lets.entity.BdSalestruEntity" >
       <result property="belongcorp" column="belongcorp" jdbcType="VARCHAR"/>
           <result property="createdate" column="createdate" jdbcType="VARCHAR"/>
           <result property="csalestruid" column="csalestruid" jdbcType="VARCHAR"/>
           <result property="def1" column="def1" jdbcType="VARCHAR"/>
           <result property="def2" column="def2" jdbcType="VARCHAR"/>
           <result property="def3" column="def3" jdbcType="VARCHAR"/>
           <result property="def4" column="def4" jdbcType="VARCHAR"/>
           <result property="def5" column="def5" jdbcType="VARCHAR"/>
           <result property="dr" column="dr" jdbcType="INTEGER"/>
           <result property="isuseretail" column="isuseretail" jdbcType="VARCHAR"/>
           <result property="phone" column="phone" jdbcType="VARCHAR"/>
           <result property="pkCorp" column="pk_corp" jdbcType="VARCHAR"/>
           <result property="pkDeptdoc" column="pk_deptdoc" jdbcType="VARCHAR"/>
           <result property="pkFathsalestru" column="pk_fathsalestru" jdbcType="VARCHAR"/>
           <result property="sealdate" column="sealdate" jdbcType="VARCHAR"/>
           <result property="ts" column="ts" jdbcType="VARCHAR"/>
           <result property="vaddress" column="vaddress" jdbcType="VARCHAR"/>
           <result property="vprincipal" column="vprincipal" jdbcType="VARCHAR"/>
           <result property="vsalestrucode" column="vsalestrucode" jdbcType="VARCHAR"/>
           <result property="vsalestruname" column="vsalestruname" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "BdSalestruEntity_Base_Column_List">
        belongcorp
       ,createdate 
        ,csalestruid 
        ,def1 
        ,def2 
        ,def3 
        ,def4 
        ,def5 
        ,dr 
        ,isuseretail 
        ,phone 
        ,pk_corp 
        ,pk_deptdoc 
        ,pk_fathsalestru 
        ,sealdate 
        ,ts 
        ,vaddress 
        ,vprincipal 
        ,vsalestrucode 
        ,vsalestruname 
     </sql>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-BdSalestruEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity">
    select
    <include refid="BdSalestruEntity_Base_Column_List" />
    from bd_salestru
    <trim prefix="where" prefixOverrides="and"> 
        <if test="belongcorp != null and belongcorp != ''"> and belongcorp = #{belongcorp} </if>
            <if test="createdate != null and createdate != ''"> and createdate = #{createdate} </if>
            <if test="csalestruid != null and csalestruid != ''"> and csalestruid = #{csalestruid} </if>
            <if test="def1 != null and def1 != ''"> and def1 = #{def1} </if>
            <if test="def2 != null and def2 != ''"> and def2 = #{def2} </if>
            <if test="def3 != null and def3 != ''"> and def3 = #{def3} </if>
            <if test="def4 != null and def4 != ''"> and def4 = #{def4} </if>
            <if test="def5 != null and def5 != ''"> and def5 = #{def5} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="isuseretail != null and isuseretail != ''"> and isuseretail = #{isuseretail} </if>
            <if test="phone != null and phone != ''"> and phone = #{phone} </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp = #{pkCorp} </if>
            <if test="pkDeptdoc != null and pkDeptdoc != ''"> and pk_deptdoc = #{pkDeptdoc} </if>
            <if test="pkFathsalestru != null and pkFathsalestru != ''"> and pk_fathsalestru = #{pkFathsalestru} </if>
            <if test="sealdate != null and sealdate != ''"> and sealdate = #{sealdate} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </if>
            <if test="vaddress != null and vaddress != ''"> and vaddress = #{vaddress} </if>
            <if test="vprincipal != null and vprincipal != ''"> and vprincipal = #{vprincipal} </if>
            <if test="vsalestrucode != null and vsalestrucode != ''"> and vsalestrucode = #{vsalestrucode} </if>
            <if test="vsalestruname != null and vsalestruname != ''"> and vsalestruname = #{vsalestruname} </if>
    </trim>
<!--    <if test=" sort == null or sort == ''.toString() "> order by sorts asc</if>-->
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>
    
<!-- 查询符合条件的数量 -->
<select id="entity_count" resultType="Integer" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity">
        select  count(1)   from bd_salestru
    <trim prefix="where" prefixOverrides="and"> 
        <if test="belongcorp != null and belongcorp != ''"> and belongcorp = #{belongcorp} </if>
            <if test="createdate != null and createdate != ''"> and createdate = #{createdate} </if>
            <if test="csalestruid != null and csalestruid != ''"> and csalestruid = #{csalestruid} </if>
            <if test="def1 != null and def1 != ''"> and def1 = #{def1} </if>
            <if test="def2 != null and def2 != ''"> and def2 = #{def2} </if>
            <if test="def3 != null and def3 != ''"> and def3 = #{def3} </if>
            <if test="def4 != null and def4 != ''"> and def4 = #{def4} </if>
            <if test="def5 != null and def5 != ''"> and def5 = #{def5} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="isuseretail != null and isuseretail != ''"> and isuseretail = #{isuseretail} </if>
            <if test="phone != null and phone != ''"> and phone = #{phone} </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp = #{pkCorp} </if>
            <if test="pkDeptdoc != null and pkDeptdoc != ''"> and pk_deptdoc = #{pkDeptdoc} </if>
            <if test="pkFathsalestru != null and pkFathsalestru != ''"> and pk_fathsalestru = #{pkFathsalestru} </if>
            <if test="sealdate != null and sealdate != ''"> and sealdate = #{sealdate} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </if>
            <if test="vaddress != null and vaddress != ''"> and vaddress = #{vaddress} </if>
            <if test="vprincipal != null and vprincipal != ''"> and vprincipal = #{vprincipal} </if>
            <if test="vsalestrucode != null and vsalestrucode != ''"> and vsalestrucode = #{vsalestrucode} </if>
            <if test="vsalestruname != null and vsalestruname != ''"> and vsalestruname = #{vsalestruname} </if>
            and sts='Y'
    </trim>
    <if test=" sort == null or sort == ''.toString() "> order by sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null "> order by ${sort} ${order}</if>
    </select>

    <!-- 分页查询列表 采用like格式 -->
<select id="entity_list_like" resultMap="get-BdSalestruEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity">
    select
    <include refid="BdSalestruEntity_Base_Column_List" />
    from bd_salestru
    <trim prefix="where" prefixOverrides="and"> 
        <if test="belongcorp != null and belongcorp != ''"> and belongcorp like concat('%',#{belongcorp},'%') </if>
            <if test="createdate != null and createdate != ''"> and createdate like concat('%',#{createdate},'%') </if>
            <if test="csalestruid != null and csalestruid != ''"> and csalestruid like concat('%',#{csalestruid},'%') </if>
            <if test="def1 != null and def1 != ''"> and def1 like concat('%',#{def1},'%') </if>
            <if test="def2 != null and def2 != ''"> and def2 like concat('%',#{def2},'%') </if>
            <if test="def3 != null and def3 != ''"> and def3 like concat('%',#{def3},'%') </if>
            <if test="def4 != null and def4 != ''"> and def4 like concat('%',#{def4},'%') </if>
            <if test="def5 != null and def5 != ''"> and def5 like concat('%',#{def5},'%') </if>
            <if test="dr != null"> and dr like concat('%',#{dr},'%') </if>
            <if test="isuseretail != null and isuseretail != ''"> and isuseretail like concat('%',#{isuseretail},'%') </if>
            <if test="phone != null and phone != ''"> and phone like concat('%',#{phone},'%') </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp like concat('%',#{pkCorp},'%') </if>
            <if test="pkDeptdoc != null and pkDeptdoc != ''"> and pk_deptdoc like concat('%',#{pkDeptdoc},'%') </if>
            <if test="pkFathsalestru != null and pkFathsalestru != ''"> and pk_fathsalestru like concat('%',#{pkFathsalestru},'%') </if>
            <if test="sealdate != null and sealdate != ''"> and sealdate like concat('%',#{sealdate},'%') </if>
            <if test="ts != null and ts != ''"> and ts like concat('%',#{ts},'%') </if>
            <if test="vaddress != null and vaddress != ''"> and vaddress like concat('%',#{vaddress},'%') </if>
            <if test="vprincipal != null and vprincipal != ''"> and vprincipal like concat('%',#{vprincipal},'%') </if>
            <if test="vsalestrucode != null and vsalestrucode != ''"> and vsalestrucode like concat('%',#{vsalestrucode},'%') </if>
            <if test="vsalestruname != null and vsalestruname != ''"> and vsalestruname like concat('%',#{vsalestruname},'%') </if>
            and sts='Y'
    </trim>
    <if test=" sort == null or sort == ''.toString() "> order by sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>

<!-- 查询列表 字段采用or格式 -->
<select id="BdSalestruentity_list_or" resultMap="get-BdSalestruEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity">
    select
    <include refid="BdSalestruEntity_Base_Column_List" />
    from bd_salestru
    <trim prefix="where" prefixOverrides="and"> 
         <if test="belongcorp != null and belongcorp != ''"> or belongcorp = #{belongcorp} </if>
             <if test="createdate != null and createdate != ''"> or createdate = #{createdate} </if>
             <if test="csalestruid != null and csalestruid != ''"> or csalestruid = #{csalestruid} </if>
             <if test="def1 != null and def1 != ''"> or def1 = #{def1} </if>
             <if test="def2 != null and def2 != ''"> or def2 = #{def2} </if>
             <if test="def3 != null and def3 != ''"> or def3 = #{def3} </if>
             <if test="def4 != null and def4 != ''"> or def4 = #{def4} </if>
             <if test="def5 != null and def5 != ''"> or def5 = #{def5} </if>
             <if test="dr != null"> or dr = #{dr} </if>
             <if test="isuseretail != null and isuseretail != ''"> or isuseretail = #{isuseretail} </if>
             <if test="phone != null and phone != ''"> or phone = #{phone} </if>
             <if test="pkCorp != null and pkCorp != ''"> or pk_corp = #{pkCorp} </if>
             <if test="pkDeptdoc != null and pkDeptdoc != ''"> or pk_deptdoc = #{pkDeptdoc} </if>
             <if test="pkFathsalestru != null and pkFathsalestru != ''"> or pk_fathsalestru = #{pkFathsalestru} </if>
             <if test="sealdate != null and sealdate != ''"> or sealdate = #{sealdate} </if>
             <if test="ts != null and ts != ''"> or ts = #{ts} </if>
             <if test="vaddress != null and vaddress != ''"> or vaddress = #{vaddress} </if>
             <if test="vprincipal != null and vprincipal != ''"> or vprincipal = #{vprincipal} </if>
             <if test="vsalestrucode != null and vsalestrucode != ''"> or vsalestrucode = #{vsalestrucode} </if>
             <if test="vsalestruname != null and vsalestruname != ''"> or vsalestruname = #{vsalestruname} </if>
            and sts='Y'
    </trim>
    <if test=" sort == null or sort == ''.toString()  "> order by sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>

<!--新增所有列-->
<insert id="entity_insert" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity" keyProperty="csalestruid" useGeneratedKeys="true">
    insert into bd_salestru(
  <trim suffix="" suffixOverrides=",">
       <if test="belongcorp != null and belongcorp != ''"> belongcorp , </if>
            <if test="createdate != null and createdate != ''"> createdate , </if>
            <if test="csalestruid != null and csalestruid != ''"> csalestruid , </if>
            <if test="def1 != null and def1 != ''"> def1 , </if>
            <if test="def2 != null and def2 != ''"> def2 , </if>
            <if test="def3 != null and def3 != ''"> def3 , </if>
            <if test="def4 != null and def4 != ''"> def4 , </if>
            <if test="def5 != null and def5 != ''"> def5 , </if>
            <if test="dr != null"> dr , </if>
            <if test="isuseretail != null and isuseretail != ''"> isuseretail , </if>
            <if test="phone != null and phone != ''"> phone , </if>
            <if test="pkCorp != null and pkCorp != ''"> pk_corp , </if>
            <if test="pkDeptdoc != null and pkDeptdoc != ''"> pk_deptdoc , </if>
            <if test="pkFathsalestru != null and pkFathsalestru != ''"> pk_fathsalestru , </if>
            <if test="sealdate != null and sealdate != ''"> sealdate , </if>
            <if test="ts != null and ts != ''"> ts , </if>
            <if test="vaddress != null and vaddress != ''"> vaddress , </if>
            <if test="vprincipal != null and vprincipal != ''"> vprincipal , </if>
            <if test="vsalestrucode != null and vsalestrucode != ''"> vsalestrucode , </if>
            <if test="vsalestruname != null and vsalestruname != ''"> vsalestruname , </if>
            <if test="sorts == null ">sorts,</if>
    <if test="sts == null ">sts,</if>
  </trim>
  )values(
 <trim suffix="" suffixOverrides=",">
       <if test="belongcorp != null and belongcorp != ''"> #{belongcorp} ,</if>
            <if test="createdate != null and createdate != ''"> #{createdate} ,</if>
            <if test="csalestruid != null and csalestruid != ''"> #{csalestruid} ,</if>
            <if test="def1 != null and def1 != ''"> #{def1} ,</if>
            <if test="def2 != null and def2 != ''"> #{def2} ,</if>
            <if test="def3 != null and def3 != ''"> #{def3} ,</if>
            <if test="def4 != null and def4 != ''"> #{def4} ,</if>
            <if test="def5 != null and def5 != ''"> #{def5} ,</if>
            <if test="dr != null"> #{dr} ,</if>
            <if test="isuseretail != null and isuseretail != ''"> #{isuseretail} ,</if>
            <if test="phone != null and phone != ''"> #{phone} ,</if>
            <if test="pkCorp != null and pkCorp != ''"> #{pkCorp} ,</if>
            <if test="pkDeptdoc != null and pkDeptdoc != ''"> #{pkDeptdoc} ,</if>
            <if test="pkFathsalestru != null and pkFathsalestru != ''"> #{pkFathsalestru} ,</if>
            <if test="sealdate != null and sealdate != ''"> #{sealdate} ,</if>
            <if test="ts != null and ts != ''"> #{ts} ,</if>
            <if test="vaddress != null and vaddress != ''"> #{vaddress} ,</if>
            <if test="vprincipal != null and vprincipal != ''"> #{vprincipal} ,</if>
            <if test="vsalestrucode != null and vsalestrucode != ''"> #{vsalestrucode} ,</if>
            <if test="vsalestruname != null and vsalestruname != ''"> #{vsalestruname} ,</if>
            <if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from bd_salestru a WHERE a.sts = 'Y' ),</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="csalestruid" useGeneratedKeys="true">
  insert into bd_salestru(belongcorp, createdate, def1, def2, def3, def4, def5, dr, isuseretail, phone, pk_corp, pk_deptdoc, pk_fathsalestru, sealdate, ts, vaddress, vprincipal, vsalestrucode, vsalestruname,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.belongcorp},#{entity.createdate},#{entity.def1},#{entity.def2},#{entity.def3},#{entity.def4},#{entity.def5},#{entity.dr},#{entity.isuseretail},#{entity.phone},#{entity.pkCorp},#{entity.pkDeptdoc},#{entity.pkFathsalestru},#{entity.sealdate},#{entity.ts},#{entity.vaddress},#{entity.vprincipal},#{entity.vsalestrucode},#{entity.vsalestruname}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="csalestruid" useGeneratedKeys="true">
    insert into bd_salestru(belongcorp, createdate, def1, def2, def3, def4, def5, dr, isuseretail, phone, pk_corp, pk_deptdoc, pk_fathsalestru, sealdate, ts, vaddress, vprincipal, vsalestrucode, vsalestruname)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.belongcorp},#{entity.createdate},#{entity.def1},#{entity.def2},#{entity.def3},#{entity.def4},#{entity.def5},#{entity.dr},#{entity.isuseretail},#{entity.phone},#{entity.pkCorp},#{entity.pkDeptdoc},#{entity.pkFathsalestru},#{entity.sealdate},#{entity.ts},#{entity.vaddress},#{entity.vprincipal},#{entity.vsalestrucode},#{entity.vsalestruname})
    </foreach>
    on duplicate key update
    belongcorp = values(belongcorp),
    createdate = values(createdate),
    def1 = values(def1),
    def2 = values(def2),
    def3 = values(def3),
    def4 = values(def4),
    def5 = values(def5),
    dr = values(dr),
    isuseretail = values(isuseretail),
    phone = values(phone),
    pk_corp = values(pk_corp),
    pk_deptdoc = values(pk_deptdoc),
    pk_fathsalestru = values(pk_fathsalestru),
    sealdate = values(sealdate),
    ts = values(ts),
    vaddress = values(vaddress),
    vprincipal = values(vprincipal),
    vsalestrucode = values(vsalestrucode),
    vsalestruname = values(vsalestruname)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity" >
update bd_salestru  set
<trim suffix="" suffixOverrides=",">
  <if test="belongcorp != null and belongcorp != ''"> belongcorp = #{belongcorp},</if>
  <if test="createdate != null and createdate != ''"> createdate = #{createdate},</if>
  <if test="def1 != null and def1 != ''"> def1 = #{def1},</if>
  <if test="def2 != null and def2 != ''"> def2 = #{def2},</if>
  <if test="def3 != null and def3 != ''"> def3 = #{def3},</if>
  <if test="def4 != null and def4 != ''"> def4 = #{def4},</if>
  <if test="def5 != null and def5 != ''"> def5 = #{def5},</if>
  <if test="dr != null"> dr = #{dr},</if>
  <if test="isuseretail != null and isuseretail != ''"> isuseretail = #{isuseretail},</if>
  <if test="phone != null and phone != ''"> phone = #{phone},</if>
  <if test="pkCorp != null and pkCorp != ''"> pk_corp = #{pkCorp},</if>
  <if test="pkDeptdoc != null and pkDeptdoc != ''"> pk_deptdoc = #{pkDeptdoc},</if>
  <if test="pkFathsalestru != null and pkFathsalestru != ''"> pk_fathsalestru = #{pkFathsalestru},</if>
  <if test="sealdate != null and sealdate != ''"> sealdate = #{sealdate},</if>
  <if test="ts != null and ts != ''"> ts = #{ts},</if>
  <if test="vaddress != null and vaddress != ''"> vaddress = #{vaddress},</if>
  <if test="vprincipal != null and vprincipal != ''"> vprincipal = #{vprincipal},</if>
  <if test="vsalestrucode != null and vsalestrucode != ''"> vsalestrucode = #{vsalestrucode},</if>
  <if test="vsalestruname != null and vsalestruname != ''"> vsalestruname = #{vsalestruname},</if>
</trim>
where csalestruid = #{csalestruid}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity" >
update bd_salestru  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where csalestruid = #{csalestruid}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.plugin.lets.entity.BdSalestruEntity" >
update bd_salestru  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
 <trim prefix="where" prefixOverrides="and"> 
        <if test="belongcorp != null and belongcorp != ''"> and belongcorp = #{belongcorp} </if>
            <if test="createdate != null and createdate != ''"> and createdate = #{createdate} </if>
            <if test="csalestruid != null and csalestruid != ''"> and csalestruid = #{csalestruid} </if>
            <if test="def1 != null and def1 != ''"> and def1 = #{def1} </if>
            <if test="def2 != null and def2 != ''"> and def2 = #{def2} </if>
            <if test="def3 != null and def3 != ''"> and def3 = #{def3} </if>
            <if test="def4 != null and def4 != ''"> and def4 = #{def4} </if>
            <if test="def5 != null and def5 != ''"> and def5 = #{def5} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="isuseretail != null and isuseretail != ''"> and isuseretail = #{isuseretail} </if>
            <if test="phone != null and phone != ''"> and phone = #{phone} </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp = #{pkCorp} </if>
            <if test="pkDeptdoc != null and pkDeptdoc != ''"> and pk_deptdoc = #{pkDeptdoc} </if>
            <if test="pkFathsalestru != null and pkFathsalestru != ''"> and pk_fathsalestru = #{pkFathsalestru} </if>
            <if test="sealdate != null and sealdate != ''"> and sealdate = #{sealdate} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </if>
            <if test="vaddress != null and vaddress != ''"> and vaddress = #{vaddress} </if>
            <if test="vprincipal != null and vprincipal != ''"> and vprincipal = #{vprincipal} </if>
            <if test="vsalestrucode != null and vsalestrucode != ''"> and vsalestrucode = #{vsalestrucode} </if>
            <if test="vsalestruname != null and vsalestruname != ''"> and vsalestruname = #{vsalestruname} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from bd_salestru where csalestruid = #{csalestruid}
</delete>

</mapper>

