<?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.BdDefdoclistDaoImpl">

    <resultMap id="get-BdDefdoclistEntity-result" type="com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity" >
       <result property="docislevflag" column="docislevflag" jdbcType="VARCHAR"/>
           <result property="doclistcode" column="doclistcode" jdbcType="VARCHAR"/>
           <result property="doclistname" column="doclistname" jdbcType="VARCHAR"/>
           <result property="doclistsystype" column="doclistsystype" jdbcType="INTEGER"/>
           <result property="dr" column="dr" jdbcType="INTEGER"/>
           <result property="iscorpcanchg" column="iscorpcanchg" jdbcType="VARCHAR"/>
           <result property="pkDefdoclist" column="pk_defdoclist" jdbcType="VARCHAR"/>
           <result property="ts" column="ts" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "BdDefdoclistEntity_Base_Column_List">
        docislevflag
       ,doclistcode 
        ,doclistname 
        ,doclistsystype 
        ,dr 
        ,iscorpcanchg 
        ,pk_defdoclist 
        ,ts 
     </sql>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-BdDefdoclistEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity">
    select
    <include refid="BdDefdoclistEntity_Base_Column_List" />
    from bd_defdoclist
    <trim prefix="where" prefixOverrides="and"> 
        <if test="docislevflag != null and docislevflag != ''"> and docislevflag = #{docislevflag} </if>
            <if test="doclistcode != null and doclistcode != ''"> and doclistcode = #{doclistcode} </if>
            <if test="doclistname != null and doclistname != ''"> and doclistname = #{doclistname} </if>
            <if test="doclistsystype != null"> and doclistsystype = #{doclistsystype} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="iscorpcanchg != null and iscorpcanchg != ''"> and iscorpcanchg = #{iscorpcanchg} </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist = #{pkDefdoclist} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </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.BdDefdoclistEntity">
        select  count(1)   from bd_defdoclist
    <trim prefix="where" prefixOverrides="and"> 
        <if test="docislevflag != null and docislevflag != ''"> and docislevflag = #{docislevflag} </if>
            <if test="doclistcode != null and doclistcode != ''"> and doclistcode = #{doclistcode} </if>
            <if test="doclistname != null and doclistname != ''"> and doclistname = #{doclistname} </if>
            <if test="doclistsystype != null"> and doclistsystype = #{doclistsystype} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="iscorpcanchg != null and iscorpcanchg != ''"> and iscorpcanchg = #{iscorpcanchg} </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist = #{pkDefdoclist} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </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>

    <!-- 分页查询列表 采用like格式 -->
<select id="entity_list_like" resultMap="get-BdDefdoclistEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity">
    select
    <include refid="BdDefdoclistEntity_Base_Column_List" />
    from bd_defdoclist
    <trim prefix="where" prefixOverrides="and"> 
        <if test="docislevflag != null and docislevflag != ''"> and docislevflag like concat('%',#{docislevflag},'%') </if>
            <if test="doclistcode != null and doclistcode != ''"> and doclistcode like concat('%',#{doclistcode},'%') </if>
            <if test="doclistname != null and doclistname != ''"> and doclistname like concat('%',#{doclistname},'%') </if>
            <if test="doclistsystype != null"> and doclistsystype like concat('%',#{doclistsystype},'%') </if>
            <if test="dr != null"> and dr like concat('%',#{dr},'%') </if>
            <if test="iscorpcanchg != null and iscorpcanchg != ''"> and iscorpcanchg like concat('%',#{iscorpcanchg},'%') </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist like concat('%',#{pkDefdoclist},'%') </if>
            <if test="ts != null and ts != ''"> and ts like concat('%',#{ts},'%') </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>

<!-- 查询列表 字段采用or格式 -->
<select id="BdDefdoclistentity_list_or" resultMap="get-BdDefdoclistEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity">
    select
    <include refid="BdDefdoclistEntity_Base_Column_List" />
    from bd_defdoclist
    <trim prefix="where" prefixOverrides="and"> 
         <if test="docislevflag != null and docislevflag != ''"> or docislevflag = #{docislevflag} </if>
             <if test="doclistcode != null and doclistcode != ''"> or doclistcode = #{doclistcode} </if>
             <if test="doclistname != null and doclistname != ''"> or doclistname = #{doclistname} </if>
             <if test="doclistsystype != null"> or doclistsystype = #{doclistsystype} </if>
             <if test="dr != null"> or dr = #{dr} </if>
             <if test="iscorpcanchg != null and iscorpcanchg != ''"> or iscorpcanchg = #{iscorpcanchg} </if>
             <if test="pkDefdoclist != null and pkDefdoclist != ''"> or pk_defdoclist = #{pkDefdoclist} </if>
             <if test="ts != null and ts != ''"> or ts = #{ts} </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>

<!--新增所有列-->
<insert id="entity_insert" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity" keyProperty="pkDefdoclist" useGeneratedKeys="true">
    insert into bd_defdoclist(
  <trim suffix="" suffixOverrides=",">
       <if test="docislevflag != null and docislevflag != ''"> docislevflag , </if>
            <if test="doclistcode != null and doclistcode != ''"> doclistcode , </if>
            <if test="doclistname != null and doclistname != ''"> doclistname , </if>
            <if test="doclistsystype != null"> doclistsystype , </if>
            <if test="dr != null"> dr , </if>
            <if test="iscorpcanchg != null and iscorpcanchg != ''"> iscorpcanchg , </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> pk_defdoclist , </if>
            <if test="ts != null and ts != ''"> ts , </if>
            <if test="sorts == null ">sorts,</if>
    <if test="sts == null ">sts,</if>
  </trim>
  )values(
 <trim suffix="" suffixOverrides=",">
       <if test="docislevflag != null and docislevflag != ''"> #{docislevflag} ,</if>
            <if test="doclistcode != null and doclistcode != ''"> #{doclistcode} ,</if>
            <if test="doclistname != null and doclistname != ''"> #{doclistname} ,</if>
            <if test="doclistsystype != null"> #{doclistsystype} ,</if>
            <if test="dr != null"> #{dr} ,</if>
            <if test="iscorpcanchg != null and iscorpcanchg != ''"> #{iscorpcanchg} ,</if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> #{pkDefdoclist} ,</if>
            <if test="ts != null and ts != ''"> #{ts} ,</if>
            <if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from bd_defdoclist a WHERE a.sts = 'Y' ),</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="pkDefdoclist" useGeneratedKeys="true">
  insert into bd_defdoclist(docislevflag, doclistcode, doclistname, doclistsystype, dr, iscorpcanchg, ts,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.docislevflag},#{entity.doclistcode},#{entity.doclistname},#{entity.doclistsystype},#{entity.dr},#{entity.iscorpcanchg},#{entity.ts}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="pkDefdoclist" useGeneratedKeys="true">
    insert into bd_defdoclist(docislevflag, doclistcode, doclistname, doclistsystype, dr, iscorpcanchg, ts)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.docislevflag},#{entity.doclistcode},#{entity.doclistname},#{entity.doclistsystype},#{entity.dr},#{entity.iscorpcanchg},#{entity.ts})
    </foreach>
    on duplicate key update
    docislevflag = values(docislevflag),
    doclistcode = values(doclistcode),
    doclistname = values(doclistname),
    doclistsystype = values(doclistsystype),
    dr = values(dr),
    iscorpcanchg = values(iscorpcanchg),
    ts = values(ts)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity" >
update bd_defdoclist  set
<trim suffix="" suffixOverrides=",">
  <if test="docislevflag != null and docislevflag != ''"> docislevflag = #{docislevflag},</if>
  <if test="doclistcode != null and doclistcode != ''"> doclistcode = #{doclistcode},</if>
  <if test="doclistname != null and doclistname != ''"> doclistname = #{doclistname},</if>
  <if test="doclistsystype != null"> doclistsystype = #{doclistsystype},</if>
  <if test="dr != null"> dr = #{dr},</if>
  <if test="iscorpcanchg != null and iscorpcanchg != ''"> iscorpcanchg = #{iscorpcanchg},</if>
  <if test="ts != null and ts != ''"> ts = #{ts},</if>
</trim>
where pk_defdoclist = #{pkDefdoclist}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity" >
update bd_defdoclist  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where pk_defdoclist = #{pkDefdoclist}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdoclistEntity" >
update bd_defdoclist  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
 <trim prefix="where" prefixOverrides="and"> 
        <if test="docislevflag != null and docislevflag != ''"> and docislevflag = #{docislevflag} </if>
            <if test="doclistcode != null and doclistcode != ''"> and doclistcode = #{doclistcode} </if>
            <if test="doclistname != null and doclistname != ''"> and doclistname = #{doclistname} </if>
            <if test="doclistsystype != null"> and doclistsystype = #{doclistsystype} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="iscorpcanchg != null and iscorpcanchg != ''"> and iscorpcanchg = #{iscorpcanchg} </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist = #{pkDefdoclist} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from bd_defdoclist where pk_defdoclist = #{pkDefdoclist}
</delete>

</mapper>

