<?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.sysnew.messageTemplate.dao.impl.SysMessageTemplateDaoImpl">

    <resultMap id="get-SysMessageTemplateEntity-result" type="com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity" >
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="sorts" column="sorts" jdbcType="INTEGER"/>
        <result property="create_user_id" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="modify_user_id" column="modify_user_id" jdbcType="VARCHAR"/>
        <result property="modify_time" column="modify_time" jdbcType="TIMESTAMP"/>
        <result property="sts" column="sts" jdbcType="VARCHAR"/>
        <result property="org_id" column="org_id" jdbcType="VARCHAR"/>
        <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
           <result property="templateType" column="template_type" jdbcType="VARCHAR"/>
           <result property="templateName" column="template_name" jdbcType="VARCHAR"/>
           <result property="messageTitle" column="message_title" jdbcType="VARCHAR"/>
           <result property="messageContents" column="message_contents" jdbcType="VARCHAR"/>
           <result property="btns" column="btns" jdbcType="VARCHAR"/>
           <result property="dataSource" column="data_source" jdbcType="VARCHAR"/>
           <result property="state" column="state" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "SysMessageTemplateEntity_Base_Column_List">
        id
       ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id
        ,template_type 
        ,template_name 
        ,message_title 
        ,message_contents 
        ,btns 
        ,data_source
        ,state
     </sql>

    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysMessageTemplateEntity-result">
        select
        <include refid="SysMessageTemplateEntity_Base_Column_List" />
        from sys_message_template where id = #{ id } and sts='Y'
    </select>

 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-SysMessageTemplateEntity-result" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity">
    select
    <include refid="SysMessageTemplateEntity_Base_Column_List" />
    from sys_message_template
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </if>
            <if test="templateType != null and templateType != ''"> and template_type = #{templateType} </if>
            <if test="templateName != null and templateName != ''"> and template_name = #{templateName} </if>
            <if test="messageTitle != null and messageTitle != ''"> and message_title = #{messageTitle} </if>
            <if test="messageContents != null and messageContents != ''"> and message_contents = #{messageContents} </if>
            <if test="btns != null and btns != ''"> and btns = #{btns} </if>
            <if test="dataSource != null and dataSource != ''"> and data_source = #{dataSource} </if>
            <if test="state != null and state != ''"> and state = #{state} </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>
    
<!-- 查询符合条件的数量 -->
<select id="entity_count" resultType="Integer" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity">
        select  count(1)   from sys_message_template
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </if>
            <if test="templateType != null and templateType != ''"> and template_type = #{templateType} </if>
            <if test="templateName != null and templateName != ''"> and template_name = #{templateName} </if>
            <if test="messageTitle != null and messageTitle != ''"> and message_title = #{messageTitle} </if>
            <if test="messageContents != null and messageContents != ''"> and message_contents = #{messageContents} </if>
            <if test="btns != null and btns != ''"> and btns = #{btns} </if>
            <if test="dataSource != null and dataSource != ''"> and data_source = #{dataSource} </if>
            <if test="state != null and state != ''"> and state = #{state} </if>
            <if test="isdelete != null"> and isdelete = #{isdelete} </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-SysMessageTemplateEntity-result" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity">
    select
    <include refid="SysMessageTemplateEntity_Base_Column_List" />
    from sys_message_template
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id like concat('%',#{id},'%') </if>
            <if test="sorts != null"> and sorts like concat('%',#{sorts},'%') </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id like concat('%',#{create_user_id},'%') </if>
            <if test="create_time != null"> and create_time like concat('%',#{create_time},'%') </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id like concat('%',#{modify_user_id},'%') </if>
            <if test="modify_time != null"> and modify_time like concat('%',#{modify_time},'%') </if>
            <if test="sts != null and sts != ''"> and sts like concat('%',#{sts},'%') </if>
            <if test="org_id != null and org_id != ''"> and org_id like concat('%',#{org_id},'%') </if>
            <if test="companyId != null and companyId != ''"> and company_id like concat('%',#{companyId},'%') </if>
            <if test="templateType != null and templateType != ''"> and template_type like concat('%',#{templateType},'%') </if>
            <if test="templateName != null and templateName != ''"> and template_name like concat('%',#{templateName},'%') </if>
            <if test="messageTitle != null and messageTitle != ''"> and message_title like concat('%',#{messageTitle},'%') </if>
            <if test="messageContents != null and messageContents != ''"> and message_contents like concat('%',#{messageContents},'%') </if>
            <if test="btns != null and btns != ''"> and btns like concat('%',#{btns},'%') </if>
            <if test="dataSource != null and dataSource != ''"> and data_source like concat('%',#{dataSource},'%') </if>
            <if test="state != null and state != ''"> and state like concat('%',#{state},'%') </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="SysMessageTemplateentity_list_or" resultMap="get-SysMessageTemplateEntity-result" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity">
    select
    <include refid="SysMessageTemplateEntity_Base_Column_List" />
    from sys_message_template
    <trim prefix="where" prefixOverrides="and"> 
         <if test="id != null and id != ''"> or id = #{id} </if>
             <if test="sorts != null"> or sorts = #{sorts} </if>
             <if test="create_user_id != null and create_user_id != ''"> or create_user_id = #{create_user_id} </if>
              <if test="create_time != null"> or create_time = #{create_time} </if>
              <if test="modify_user_id != null and modify_user_id != ''"> or modify_user_id = #{modify_user_id} </if>
              <if test="modify_time != null"> or modify_time = #{modify_time} </if>
              <if test="sts != null and sts != ''"> or sts = #{sts} </if>
             <if test="org_id != null and org_id != ''"> or org_id = #{org_id} </if>
              <if test="companyId != null and companyId != ''"> or company_id = #{companyId} </if>
             <if test="templateType != null and templateType != ''"> or template_type = #{templateType} </if>
             <if test="templateName != null and templateName != ''"> or template_name = #{templateName} </if>
             <if test="messageTitle != null and messageTitle != ''"> or message_title = #{messageTitle} </if>
             <if test="messageContents != null and messageContents != ''"> or message_contents = #{messageContents} </if>
             <if test="btns != null and btns != ''"> or btns = #{btns} </if>
             <if test="dataSource != null and dataSource != ''"> or data_source = #{dataSource} </if>
             <if test="state != null and state != ''"> or state = #{state} </if>
             <if test="isdelete != null"> or isdelete = #{isdelete} </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.sysnew.messageTemplate.entity.SysMessageTemplateEntity" keyProperty="id" useGeneratedKeys="true">
    insert into sys_message_template(
  <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> id , </if>
            <if test="sorts != null"> sorts , </if>
            <if test="create_user_id != null and create_user_id != ''"> create_user_id , </if>
            <if test="create_time != null"> create_time , </if>
            <if test="modify_user_id != null and modify_user_id != ''"> modify_user_id , </if>
            <if test="modify_time != null"> modify_time , </if>
            <if test="sts != null and sts != ''"> sts , </if>
            <if test="org_id != null and org_id != ''"> org_id , </if>
            <if test="companyId != null and companyId != ''"> company_id , </if>
            <if test="templateType != null and templateType != ''"> template_type , </if>
            <if test="templateName != null and templateName != ''"> template_name , </if>
            <if test="messageTitle != null and messageTitle != ''"> message_title , </if>
            <if test="messageContents != null and messageContents != ''"> message_contents , </if>
            <if test="btns != null and btns != ''"> btns , </if>
            <if test="dataSource != null and dataSource != ''"> data_source , </if>
            <if test="state != null and state != ''"> state , </if>
    <if test="sts == null ">sts,</if>
  </trim>
  )values(
 <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> #{id} ,</if>
            <if test="sorts != null"> #{sorts} ,</if>
            <if test="create_user_id != null and create_user_id != ''"> #{create_user_id} ,</if>
            <if test="create_time != null"> #{create_time} ,</if>
            <if test="modify_user_id != null and modify_user_id != ''"> #{modify_user_id} ,</if>
            <if test="modify_time != null"> #{modify_time} ,</if>
            <if test="sts != null and sts != ''"> #{sts} ,</if>
            <if test="org_id != null and org_id != ''"> #{org_id} ,</if>
            <if test="companyId != null and companyId != ''"> #{companyId} ,</if>
            <if test="templateType != null and templateType != ''"> #{templateType} ,</if>
            <if test="templateName != null and templateName != ''"> #{templateName} ,</if>
            <if test="messageTitle != null and messageTitle != ''"> #{messageTitle} ,</if>
            <if test="messageContents != null and messageContents != ''"> #{messageContents} ,</if>
            <if test="btns != null and btns != ''"> #{btns} ,</if>
            <if test="dataSource != null and dataSource != ''"> #{dataSource} ,</if>
            <if test="state != null and state !=''"> #{state} ,</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="id" useGeneratedKeys="true">
  insert into sys_message_template(create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, bill_kind_id, template_type, template_name, message_title, message_contents, btns, data_source, create_date, create_person_id, state, isdelete,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId},#{entity.billKindId},#{entity.templateType},#{entity.templateName},#{entity.messageTitle},#{entity.messageContents},#{entity.btns},#{entity.dataSource},#{entity.createDate},#{entity.createPersonId},#{entity.state},#{entity.isdelete}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
    insert into sys_message_template(create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, bill_kind_id, template_type, template_name, message_title, message_contents, btns, data_source, create_date, create_person_id, state, isdelete)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId},#{entity.billKindId},#{entity.templateType},#{entity.templateName},#{entity.messageTitle},#{entity.messageContents},#{entity.btns},#{entity.dataSource},#{entity.createDate},#{entity.createPersonId},#{entity.state},#{entity.isdelete})
    </foreach>
    on duplicate key update
    create_user_id = values(create_user_id),
    create_time = values(create_time),
    modify_user_id = values(modify_user_id),
    modify_time = values(modify_time),
    sts = values(sts),
    org_id = values(org_id),
    company_id = values(company_id),
    bill_kind_id = values(bill_kind_id),
    template_type = values(template_type),
    template_name = values(template_name),
    message_title = values(message_title),
    message_contents = values(message_contents),
    btns = values(btns),
    data_source = values(data_source),
    create_date = values(create_date),
    create_person_id = values(create_person_id),
    state = values(state),
    isdelete = values(isdelete)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity" >
update sys_message_template  set
<trim suffix="" suffixOverrides=",">
  <if test="create_user_id != null and create_user_id != ''"> create_user_id = #{create_user_id},</if>
    <if test="create_time != null"> create_time = #{create_time},</if>
    <if test="modify_user_id != null and modify_user_id != ''"> modify_user_id = #{modify_user_id},</if>
    <if test="modify_time != null"> modify_time = #{modify_time},</if>
    <if test="sts != null and sts != ''"> sts = #{sts},</if>
  <if test="org_id != null and org_id != ''"> org_id = #{org_id},</if>
    <if test="companyId != null and companyId != ''"> company_id = #{companyId},</if>
  <if test="templateType != null and templateType != ''"> template_type = #{templateType},</if>
  <if test="templateName != null and templateName != ''"> template_name = #{templateName},</if>
  <if test="messageTitle != null and messageTitle != ''"> message_title = #{messageTitle},</if>
  <if test="messageContents != null and messageContents != ''"> message_contents = #{messageContents},</if>
  <if test="btns != null and btns != ''"> btns = #{btns},</if>
  <if test="dataSource != null and dataSource != ''"> data_source = #{dataSource},</if>
  <if test="state != null and state !=''"> state = #{state},</if>
</trim>
where id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity" >
update sys_message_template  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where id = #{id}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.sysnew.messageTemplate.entity.SysMessageTemplateEntity" >
update sys_message_template  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
 <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
                                                                <if test="sts != null and sts != ''"> and sts = #{sts} </if>
                         <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </if>
            <if test="billKindId != null and billKindId != ''"> and bill_kind_id = #{billKindId} </if>
            <if test="templateType != null and templateType != ''"> and template_type = #{templateType} </if>
            <if test="templateName != null and templateName != ''"> and template_name = #{templateName} </if>
            <if test="messageTitle != null and messageTitle != ''"> and message_title = #{messageTitle} </if>
            <if test="messageContents != null and messageContents != ''"> and message_contents = #{messageContents} </if>
            <if test="btns != null and btns != ''"> and btns = #{btns} </if>
            <if test="dataSource != null and dataSource != ''"> and data_source = #{dataSource} </if>
            <if test="createDate != null"> and create_date = #{createDate} </if>
            <if test="createPersonId != null and createPersonId != ''"> and create_person_id = #{createPersonId} </if>
            <if test="state != null"> and state = #{state} </if>
            <if test="isdelete != null"> and isdelete = #{isdelete} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from sys_message_template where id = #{id}
</delete>

</mapper>

