<?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.sendMessageLog.dao.impl.SysSendMessageLogDaoImpl">

    <resultMap id="get-SysSendMessageLogEntity-result" type="com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity" >
       <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="type" column="type" jdbcType="VARCHAR"/>
           <result property="recipientsPersonId" column="recipients_person_id" jdbcType="VARCHAR"/>
           <result property="recipientsInteriorId" column="recipients_interior_id" jdbcType="VARCHAR"/>
           <result property="sendCount" column="send_count" jdbcType="VARCHAR"/>
           <result property="sendDatetime" column="send_datetime" jdbcType="TIMESTAMP"/>
           <result property="sendPersonId" column="send_person_id" jdbcType="VARCHAR"/>
           <result property="sourceModelName" column="source_model_name" jdbcType="VARCHAR"/>
           <result property="state" column="state" jdbcType="INTEGER"/>
           <result property="resultMessage" column="result_message" jdbcType="VARCHAR"/>
           <result property="recipientsPersonName" column="recipients_person_name" jdbcType="VARCHAR"/>
           <result property="sendPersonName" column="send_person_name" jdbcType="VARCHAR"/>
           <result property="warningInterfaceId" column="warning_interface_id" jdbcType="VARCHAR"/>
           <result property="appId" column="app_id" jdbcType="VARCHAR"/>
           <result property="messageTitle" column="message_title" jdbcType="VARCHAR"/>
           <result property="appName" column="app_name" jdbcType="VARCHAR"/>
           <result property="btns" column="btns" jdbcType="VARCHAR"/>
        </resultMap>

    <!-- 查询的字段-->
    <sql id = "SysSendMessageLogEntity_Base_Column_List">
        id
       ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id
        ,type 
        ,recipients_person_id 
        ,recipients_interior_id 
        ,send_count 
        ,send_datetime 
        ,send_person_id 
        ,source_model_name 
        ,state 
        ,result_message
        ,warning_interface_id
     </sql>

    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysSendMessageLogEntity-result">
        select
            log.*
             ,p1.person_name as recipients_person_name
             ,p2.person_Name as send_person_name
        from sys_send_message_log log
                 LEFT JOIN sys_person p1 ON p1.id = log.recipients_person_id
                 LEFT JOIN sys_person p2 ON p2.id = log.send_person_id
        where log.id = #{ id } and log.sts='Y' and p1.sts='Y' and p2.sts='Y'
    </select>
    <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-SysSendMessageLogEntity-result" parameterType = "com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity">
    select
     log.*
     ,p1.person_name as recipients_person_name
     ,p2.person_Name as send_person_name
     ,i.app_id AS app_id
     from sys_send_message_log log
     LEFT JOIN sys_person p1 ON p1.id = log.recipients_person_id
     LEFT JOIN sys_person p2 ON p2.id = log.send_person_id
     LEFT JOIN sys_warning_interface i ON i.id = log.warning_interface_id
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and log.id = #{id} </if>
            <if test="sorts != null"> and log.sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and log.create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and log.create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and log.modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and log.modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and log.sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and log.org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and log.company_id = #{companyId} </if>
            <if test="type != null and type != ''"> and log.type = #{type} </if>
            <if test="recipientsPersonId != null and recipientsPersonId != ''"> and log.recipients_person_id = #{recipientsPersonId} </if>
            <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> and log.recipients_interior_id = #{recipientsInteriorId} </if>
            <if test="sendCount != null and sendCount != ''"> and log.send_count = #{sendCount} </if>
            <if test="sendDatetime != null"> and log.send_datetime = #{sendDatetime} </if>
            <if test="sendPersonId != null and sendPersonId != ''"> and log.send_person_id = #{sendPersonId} </if>
            <if test="sourceModelName != null and sourceModelName != ''"> and log.source_model_name = #{sourceModelName} </if>
            <if test="state != null"> and log.state = #{state} </if>
            <if test="resultMessage != null and resultMessage != ''"> and log.result_message = #{resultMessage} </if>
            <if test="appId != null and appId != ''" > and i.app_id = #{appId} </if>
            and log.sts='Y'
            and p1.sts='Y'
            and p2.sts='Y'
            and i.sts='Y'
    </trim>
<!--    <if test=" sort == null or sort == ''.toString() "> order by log.sorts asc</if>-->
<!--    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>-->
        order by log.send_datetime desc
</select>
    
<!-- 查询符合条件的数量 -->
<select id="entity_count" resultType="Integer" parameterType = "com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity">
        select  count(1)   from sys_send_message_log
    <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="type != null and type != ''"> and type = #{type} </if>
            <if test="recipientsPersonId != null and recipientsPersonId != ''"> and recipients_person_id = #{recipientsPersonId} </if>
            <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> and recipients_interior_id = #{recipientsInteriorId} </if>
            <if test="sendCount != null and sendCount != ''"> and send_count = #{sendCount} </if>
            <if test="sendDatetime != null"> and send_datetime = #{sendDatetime} </if>
            <if test="sendPersonId != null and sendPersonId != ''"> and send_person_id = #{sendPersonId} </if>
            <if test="sourceModelName != null and sourceModelName != ''"> and source_model_name = #{sourceModelName} </if>
            <if test="state != null"> and state = #{state} </if>
            <if test="resultMessage != null and resultMessage != ''"> and result_message = #{resultMessage} </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-SysSendMessageLogEntity-result" parameterType = "com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity">
    SELECT
    log.*,
    p1.person_name AS recipients_person_name,
    p2.person_Name AS send_person_name,
    i.app_id AS app_id,
    app.NAME AS app_name,
    template.btns,
    template.message_title
    FROM
    sys_send_message_log log
    LEFT JOIN sys_person p1 ON p1.id = log.recipients_person_id
    LEFT JOIN sys_person p2 ON p2.id = log.send_person_id
    LEFT JOIN sys_warning_interface i ON i.id = log.warning_interface_id
    LEFT JOIN sys_application app ON app.id = i.app_id
    LEFT JOIN sys_warning_config config ON i.warning_config_id = config.id
    LEFT JOIN sys_message_template template ON template.id = config.message_template_id
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and log.id like concat('%',#{id},'%') </if>
            <if test="sorts != null"> and log.sorts like concat('%',#{sorts},'%') </if>
            <if test="create_user_id != null and create_user_id != ''"> and log.create_user_id like concat('%',#{create_user_id},'%') </if>
            <if test="create_time != null"> and log.create_time like concat('%',#{create_time},'%') </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and log.modify_user_id like concat('%',#{modify_user_id},'%') </if>
            <if test="modify_time != null"> and log.modify_time like concat('%',#{modify_time},'%') </if>
            <if test="sts != null and sts != ''"> and log.sts like concat('%',#{sts},'%') </if>
            <if test="org_id != null and org_id != ''"> and log.org_id like concat('%',#{org_id},'%') </if>
            <if test="companyId != null and companyId != ''"> and log.company_id like concat('%',#{companyId},'%') </if>
            <if test="type != null and type != ''"> and log.type like concat('%',#{type},'%') </if>
            <if test="recipientsPersonId != null and recipientsPersonId != ''"> and log.recipients_person_id like concat('%',#{recipientsPersonId},'%') </if>
            <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> and log.recipients_interior_id like concat('%',#{recipientsInteriorId},'%') </if>
            <if test="sendCount != null and sendCount != ''"> and log.send_count like concat('%',#{sendCount},'%') </if>
            <if test="sendDatetime != null"> and log.send_datetime like concat('%',DATE (#{sendDatetime}),'%') </if>
            <if test="sendPersonId != null and sendPersonId != ''"> and log.send_person_id like concat('%',#{sendPersonId},'%') </if>
            <if test="sourceModelName != null and sourceModelName != ''"> and log.source_model_name like concat('%',#{sourceModelName},'%') </if>
            <if test="state != null"> and log.state like concat('%',#{state},'%') </if>
            <if test="resultMessage != null and resultMessage != ''"> and log.result_message like concat('%',#{resultMessage},'%') </if>
            <if test="appId != null and appId != ''">and i.app_id like concat('%',#{appId},'%') </if>
            and log.sts='Y'
            and i.sts='Y'
            and config.sts='Y'
            and template.sts='Y'
            and p1.sts='Y'
            and p2.sts='Y'
            and app.sts='Y'
    </trim>
<!--    <if test=" sort == null or sort == ''.toString() "> order by log.sorts asc</if>-->
<!--    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>-->
            order by log.send_datetime desc
</select>

<!-- 查询列表 字段采用or格式 -->
<select id="SysSendMessageLogentity_list_or" resultMap="get-SysSendMessageLogEntity-result" parameterType = "com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity">
    select
    <include refid="SysSendMessageLogEntity_Base_Column_List" />
    from sys_send_message_log
    <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="type != null and type != ''"> or type = #{type} </if>
             <if test="recipientsPersonId != null and recipientsPersonId != ''"> or recipients_person_id = #{recipientsPersonId} </if>
             <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> or recipients_interior_id = #{recipientsInteriorId} </if>
             <if test="sendCount != null and sendCount != ''"> or send_count = #{sendCount} </if>
             <if test="sendDatetime != null"> or send_datetime = #{sendDatetime} </if>
             <if test="sendPersonId != null and sendPersonId != ''"> or send_person_id = #{sendPersonId} </if>
             <if test="sourceModelName != null and sourceModelName != ''"> or source_model_name = #{sourceModelName} </if>
             <if test="state != null"> or state = #{state} </if>
             <if test="resultMessage != null and resultMessage != ''"> or result_message = #{resultMessage} </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.sendMessageLog.entity.SysSendMessageLogEntity">
    insert into sys_send_message_log(
  <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="type != null and type != ''"> type , </if>
            <if test="recipientsPersonId != null and recipientsPersonId != ''"> recipients_person_id , </if>
            <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> recipients_interior_id , </if>
            <if test="sendCount != null and sendCount != ''"> send_count , </if>
            <if test="sendDatetime != null"> send_datetime , </if>
            <if test="sendPersonId != null and sendPersonId != ''"> send_person_id , </if>
            <if test="sourceModelName != null and sourceModelName != ''"> source_model_name , </if>
            <if test="state != null"> state , </if>
            <if test="resultMessage != null and resultMessage != ''"> result_message , </if>
            <if test="warningInterfaceId != null and warningInterfaceId != ''"> warning_interface_id , </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="type != null and type != ''"> #{type} ,</if>
            <if test="recipientsPersonId != null and recipientsPersonId != ''"> #{recipientsPersonId} ,</if>
            <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> #{recipientsInteriorId} ,</if>
            <if test="sendCount != null and sendCount != ''"> #{sendCount} ,</if>
            <if test="sendDatetime != null"> #{sendDatetime} ,</if>
            <if test="sendPersonId != null and sendPersonId != ''"> #{sendPersonId} ,</if>
            <if test="sourceModelName != null and sourceModelName != ''"> #{sourceModelName} ,</if>
            <if test="state != null"> #{state} ,</if>
            <if test="resultMessage != null and resultMessage != ''"> #{resultMessage} ,</if>
            <if test="warningInterfaceId != null and warningInterfaceId != ''"> #{warningInterfaceId} ,</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="id" useGeneratedKeys="true">
  insert into sys_send_message_log(create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, bill_id, type, recipients_person_id, recipients_interior_id, send_count, send_datetime, send_person_id, source_model_name, state, result_message,  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.billId},#{entity.type},#{entity.recipientsPersonId},#{entity.recipientsInteriorId},#{entity.sendCount},#{entity.sendDatetime},#{entity.sendPersonId},#{entity.sourceModelName},#{entity.state},#{entity.resultMessage}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
    insert into sys_send_message_log(create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, bill_id, type, recipients_person_id, recipients_interior_id, send_count, send_datetime, send_person_id, source_model_name, state, result_message)
    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.billId},#{entity.type},#{entity.recipientsPersonId},#{entity.recipientsInteriorId},#{entity.sendCount},#{entity.sendDatetime},#{entity.sendPersonId},#{entity.sourceModelName},#{entity.state},#{entity.resultMessage})
    </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_id = values(bill_id),
    type = values(type),
    recipients_person_id = values(recipients_person_id),
    recipients_interior_id = values(recipients_interior_id),
    send_count = values(send_count),
    send_datetime = values(send_datetime),
    send_person_id = values(send_person_id),
    source_model_name = values(source_model_name),
    state = values(state),
    result_message = values(result_message)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity" >
update sys_send_message_log  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="type != null and type != ''"> type = #{type},</if>
  <if test="recipientsPersonId != null and recipientsPersonId != ''"> recipients_person_id = #{recipientsPersonId},</if>
  <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> recipients_interior_id = #{recipientsInteriorId},</if>
  <if test="sendCount != null and sendCount != ''"> send_count = #{sendCount},</if>
  <if test="sendDatetime != null"> send_datetime = #{sendDatetime},</if>
  <if test="sendPersonId != null and sendPersonId != ''"> send_person_id = #{sendPersonId},</if>
  <if test="sourceModelName != null and sourceModelName != ''"> source_model_name = #{sourceModelName},</if>
  <if test="state != null"> state = #{state},</if>
  <if test="resultMessage != null and resultMessage != ''"> result_message = #{resultMessage},</if>
</trim>
where id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.sysnew.sendMessageLog.entity.SysSendMessageLogEntity" >
update sys_send_message_log  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.sendMessageLog.entity.SysSendMessageLogEntity" >
update sys_send_message_log  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="type != null and type != ''"> and type = #{type} </if>
            <if test="recipientsPersonId != null and recipientsPersonId != ''"> and recipients_person_id = #{recipientsPersonId} </if>
            <if test="recipientsInteriorId != null and recipientsInteriorId != ''"> and recipients_interior_id = #{recipientsInteriorId} </if>
            <if test="sendCount != null and sendCount != ''"> and send_count = #{sendCount} </if>
            <if test="sendDatetime != null"> and send_datetime = #{sendDatetime} </if>
            <if test="sendPersonId != null and sendPersonId != ''"> and send_person_id = #{sendPersonId} </if>
            <if test="sourceModelName != null and sourceModelName != ''"> and source_model_name = #{sourceModelName} </if>
            <if test="state != null"> and state = #{state} </if>
            <if test="resultMessage != null and resultMessage != ''"> and result_message = #{resultMessage} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from sys_send_message_log where id = #{id}
</delete>

</mapper>

