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

    <resultMap id="get-BdDefdocEntity-result" type="com.hzya.frame.plugin.lets.entity.BdDefdocEntity" >
       <result property="doccode" column="doccode" jdbcType="VARCHAR"/>
           <result property="docname" column="docname" jdbcType="VARCHAR"/>
           <result property="docsystype" column="docsystype" jdbcType="INTEGER"/>
           <result property="dr" column="dr" jdbcType="INTEGER"/>
           <result property="memo" column="memo" jdbcType="VARCHAR"/>
           <result property="pkCorp" column="pk_corp" jdbcType="VARCHAR"/>
           <result property="pkDefdoc" column="pk_defdoc" jdbcType="VARCHAR"/>
           <result property="pkDefdoc1" column="pk_defdoc1" jdbcType="VARCHAR"/>
           <result property="pkDefdoclist" column="pk_defdoclist" jdbcType="VARCHAR"/>
           <result property="sealflag" column="sealflag" jdbcType="VARCHAR"/>
           <result property="shortname" column="shortname" jdbcType="VARCHAR"/>
           <result property="ts" column="ts" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "BdDefdocEntity_Base_Column_List">
        doccode
       ,docname 
        ,docsystype 
        ,dr 
        ,memo 
        ,pk_corp 
        ,pk_defdoc 
        ,pk_defdoc1 
        ,pk_defdoclist 
        ,sealflag 
        ,shortname 
        ,ts 
     </sql>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-BdDefdocEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdocEntity">
    select
    <include refid="BdDefdocEntity_Base_Column_List" />
    from bd_defdoc
    <trim prefix="where" prefixOverrides="and"> 
        <if test="doccode != null and doccode != ''"> and doccode = #{doccode} </if>
            <if test="docname != null and docname != ''"> and docname = #{docname} </if>
            <if test="docsystype != null"> and docsystype = #{docsystype} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="memo != null and memo != ''"> and memo = #{memo} </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp = #{pkCorp} </if>
            <if test="pkDefdoc != null and pkDefdoc != ''"> and pk_defdoc = #{pkDefdoc} </if>
            <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> and pk_defdoc1 = #{pkDefdoc1} </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist = #{pkDefdoclist} </if>
            <if test="sealflag != null and sealflag != ''"> and sealflag = #{sealflag} </if>
            <if test="shortname != null and shortname != ''"> and shortname = #{shortname} </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.BdDefdocEntity">
        select  count(1)   from bd_defdoc
    <trim prefix="where" prefixOverrides="and"> 
        <if test="doccode != null and doccode != ''"> and doccode = #{doccode} </if>
            <if test="docname != null and docname != ''"> and docname = #{docname} </if>
            <if test="docsystype != null"> and docsystype = #{docsystype} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="memo != null and memo != ''"> and memo = #{memo} </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp = #{pkCorp} </if>
            <if test="pkDefdoc != null and pkDefdoc != ''"> and pk_defdoc = #{pkDefdoc} </if>
            <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> and pk_defdoc1 = #{pkDefdoc1} </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist = #{pkDefdoclist} </if>
            <if test="sealflag != null and sealflag != ''"> and sealflag = #{sealflag} </if>
            <if test="shortname != null and shortname != ''"> and shortname = #{shortname} </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-BdDefdocEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdocEntity">
    select
    <include refid="BdDefdocEntity_Base_Column_List" />
    from bd_defdoc
    <trim prefix="where" prefixOverrides="and"> 
        <if test="doccode != null and doccode != ''"> and doccode like concat('%',#{doccode},'%') </if>
            <if test="docname != null and docname != ''"> and docname like concat('%',#{docname},'%') </if>
            <if test="docsystype != null"> and docsystype like concat('%',#{docsystype},'%') </if>
            <if test="dr != null"> and dr like concat('%',#{dr},'%') </if>
            <if test="memo != null and memo != ''"> and memo like concat('%',#{memo},'%') </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp like concat('%',#{pkCorp},'%') </if>
            <if test="pkDefdoc != null and pkDefdoc != ''"> and pk_defdoc like concat('%',#{pkDefdoc},'%') </if>
            <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> and pk_defdoc1 like concat('%',#{pkDefdoc1},'%') </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist like concat('%',#{pkDefdoclist},'%') </if>
            <if test="sealflag != null and sealflag != ''"> and sealflag like concat('%',#{sealflag},'%') </if>
            <if test="shortname != null and shortname != ''"> and shortname like concat('%',#{shortname},'%') </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="BdDefdocentity_list_or" resultMap="get-BdDefdocEntity-result" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdocEntity">
    select
    <include refid="BdDefdocEntity_Base_Column_List" />
    from bd_defdoc
    <trim prefix="where" prefixOverrides="and"> 
         <if test="doccode != null and doccode != ''"> or doccode = #{doccode} </if>
             <if test="docname != null and docname != ''"> or docname = #{docname} </if>
             <if test="docsystype != null"> or docsystype = #{docsystype} </if>
             <if test="dr != null"> or dr = #{dr} </if>
             <if test="memo != null and memo != ''"> or memo = #{memo} </if>
             <if test="pkCorp != null and pkCorp != ''"> or pk_corp = #{pkCorp} </if>
             <if test="pkDefdoc != null and pkDefdoc != ''"> or pk_defdoc = #{pkDefdoc} </if>
             <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> or pk_defdoc1 = #{pkDefdoc1} </if>
             <if test="pkDefdoclist != null and pkDefdoclist != ''"> or pk_defdoclist = #{pkDefdoclist} </if>
             <if test="sealflag != null and sealflag != ''"> or sealflag = #{sealflag} </if>
             <if test="shortname != null and shortname != ''"> or shortname = #{shortname} </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.BdDefdocEntity" keyProperty="pkDefdoc" useGeneratedKeys="true">
    insert into bd_defdoc(
  <trim suffix="" suffixOverrides=",">
       <if test="doccode != null and doccode != ''"> doccode , </if>
            <if test="docname != null and docname != ''"> docname , </if>
            <if test="docsystype != null"> docsystype , </if>
            <if test="dr != null"> dr , </if>
            <if test="memo != null and memo != ''"> memo , </if>
            <if test="pkCorp != null and pkCorp != ''"> pk_corp , </if>
            <if test="pkDefdoc != null and pkDefdoc != ''"> pk_defdoc , </if>
            <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> pk_defdoc1 , </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> pk_defdoclist , </if>
            <if test="sealflag != null and sealflag != ''"> sealflag , </if>
            <if test="shortname != null and shortname != ''"> shortname , </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="doccode != null and doccode != ''"> #{doccode} ,</if>
            <if test="docname != null and docname != ''"> #{docname} ,</if>
            <if test="docsystype != null"> #{docsystype} ,</if>
            <if test="dr != null"> #{dr} ,</if>
            <if test="memo != null and memo != ''"> #{memo} ,</if>
            <if test="pkCorp != null and pkCorp != ''"> #{pkCorp} ,</if>
            <if test="pkDefdoc != null and pkDefdoc != ''"> #{pkDefdoc} ,</if>
            <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> #{pkDefdoc1} ,</if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> #{pkDefdoclist} ,</if>
            <if test="sealflag != null and sealflag != ''"> #{sealflag} ,</if>
            <if test="shortname != null and shortname != ''"> #{shortname} ,</if>
            <if test="ts != null and ts != ''"> #{ts} ,</if>
            <if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from bd_defdoc a WHERE a.sts = 'Y' ),</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="pkDefdoc" useGeneratedKeys="true">
  insert into bd_defdoc(doccode, docname, docsystype, dr, memo, pk_corp, pk_defdoc1, pk_defdoclist, sealflag, shortname, ts,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.doccode},#{entity.docname},#{entity.docsystype},#{entity.dr},#{entity.memo},#{entity.pkCorp},#{entity.pkDefdoc1},#{entity.pkDefdoclist},#{entity.sealflag},#{entity.shortname},#{entity.ts}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="pkDefdoc" useGeneratedKeys="true">
    insert into bd_defdoc(doccode, docname, docsystype, dr, memo, pk_corp, pk_defdoc1, pk_defdoclist, sealflag, shortname, ts)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.doccode},#{entity.docname},#{entity.docsystype},#{entity.dr},#{entity.memo},#{entity.pkCorp},#{entity.pkDefdoc1},#{entity.pkDefdoclist},#{entity.sealflag},#{entity.shortname},#{entity.ts})
    </foreach>
    on duplicate key update
    doccode = values(doccode),
    docname = values(docname),
    docsystype = values(docsystype),
    dr = values(dr),
    memo = values(memo),
    pk_corp = values(pk_corp),
    pk_defdoc1 = values(pk_defdoc1),
    pk_defdoclist = values(pk_defdoclist),
    sealflag = values(sealflag),
    shortname = values(shortname),
    ts = values(ts)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdocEntity" >
update bd_defdoc  set
<trim suffix="" suffixOverrides=",">
  <if test="doccode != null and doccode != ''"> doccode = #{doccode},</if>
  <if test="docname != null and docname != ''"> docname = #{docname},</if>
  <if test="docsystype != null"> docsystype = #{docsystype},</if>
  <if test="dr != null"> dr = #{dr},</if>
  <if test="memo != null and memo != ''"> memo = #{memo},</if>
  <if test="pkCorp != null and pkCorp != ''"> pk_corp = #{pkCorp},</if>
  <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> pk_defdoc1 = #{pkDefdoc1},</if>
  <if test="pkDefdoclist != null and pkDefdoclist != ''"> pk_defdoclist = #{pkDefdoclist},</if>
  <if test="sealflag != null and sealflag != ''"> sealflag = #{sealflag},</if>
  <if test="shortname != null and shortname != ''"> shortname = #{shortname},</if>
  <if test="ts != null and ts != ''"> ts = #{ts},</if>
</trim>
where pk_defdoc = #{pkDefdoc}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdocEntity" >
update bd_defdoc  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where pk_defdoc = #{pkDefdoc}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.plugin.lets.entity.BdDefdocEntity" >
update bd_defdoc  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
 <trim prefix="where" prefixOverrides="and"> 
        <if test="doccode != null and doccode != ''"> and doccode = #{doccode} </if>
            <if test="docname != null and docname != ''"> and docname = #{docname} </if>
            <if test="docsystype != null"> and docsystype = #{docsystype} </if>
            <if test="dr != null"> and dr = #{dr} </if>
            <if test="memo != null and memo != ''"> and memo = #{memo} </if>
            <if test="pkCorp != null and pkCorp != ''"> and pk_corp = #{pkCorp} </if>
            <if test="pkDefdoc != null and pkDefdoc != ''"> and pk_defdoc = #{pkDefdoc} </if>
            <if test="pkDefdoc1 != null and pkDefdoc1 != ''"> and pk_defdoc1 = #{pkDefdoc1} </if>
            <if test="pkDefdoclist != null and pkDefdoclist != ''"> and pk_defdoclist = #{pkDefdoclist} </if>
            <if test="sealflag != null and sealflag != ''"> and sealflag = #{sealflag} </if>
            <if test="shortname != null and shortname != ''"> and shortname = #{shortname} </if>
            <if test="ts != null and ts != ''"> and ts = #{ts} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from bd_defdoc where pk_defdoc = #{pkDefdoc}
</delete>

</mapper>

