<?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.warningConfig.dao.impl.SysWarningConfigDaoImpl">

    <resultMap id="get-SysWarningConfigEntity-result" type="com.hzya.frame.sysnew.warningConfig.entity.SysWarningConfigEntity" >
       <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="messageTemplateId" column="message_template_id" jdbcType="VARCHAR"/>
           <result property="appIdList" column="app_id_list" jdbcType="VARCHAR"/>
           <result property="warningAppId" column="warning_app_id" jdbcType="VARCHAR"/>
           <result property="acceptMessageApiCode" column="accept_message_api_code" jdbcType="INTEGER"/>
           <result property="remark" column="remark" jdbcType="VARCHAR"/>
           <result property="status" column="status" jdbcType="VARCHAR"/>
           <result property="recipientIdList" column="recipient_id_list" jdbcType="VARCHAR"/>
           <result property="templateName" column="template_name" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "SysWarningConfigEntity_Base_Column_List">
        id
       ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id 
        ,message_template_id 
        ,app_id_list 
        ,warning_app_id 
        ,accept_message_api_code 
        ,remark 
        ,status 
        ,recipient_id_list 
     </sql>

    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysWarningConfigEntity-result">
        select
             config.*
             ,template.template_name
        from sys_warning_config config
        LEFT JOIN sys_message_template template ON template.id = config.message_template_id
        where config.id = #{ id } AND config.sts='Y' AND template.sts='Y'
    </select>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-SysWarningConfigEntity-result" parameterType = "com.hzya.frame.sysnew.warningConfig.entity.SysWarningConfigEntity">
    select
    <include refid="SysWarningConfigEntity_Base_Column_List" />
    from sys_warning_config
    <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="messageTemplateId != null and messageTemplateId != ''"> and message_template_id = #{messageTemplateId} </if>
            <if test="appIdList != null and appIdList != ''"> and app_id_list = #{appIdList} </if>
            <if test="warningAppId != null and warningAppId != ''"> and warning_app_id = #{warningAppId} </if>
            <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> and accept_message_api_code = #{acceptMessageApiCode} </if>
            <if test="remark != null and remark != ''"> and remark = #{remark} </if>
            <if test="status != null and status != ''"> and status = #{status} </if>
            <if test="recipientIdList != null and recipientIdList != ''"> and recipient_id_list = #{recipientIdList} </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.warningConfig.entity.SysWarningConfigEntity">
        select  count(1)   from sys_warning_config
    <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="messageTemplateId != null and messageTemplateId != ''"> and message_template_id = #{messageTemplateId} </if>
            <if test="appIdList != null and appIdList != ''"> and app_id_list = #{appIdList} </if>
            <if test="warningAppId != null and warningAppId != ''"> and warning_app_id = #{warningAppId} </if>
            <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> and accept_message_api_code = #{acceptMessageApiCode} </if>
            <if test="remark != null and remark != ''"> and remark = #{remark} </if>
            <if test="status != null and status != ''"> and status = #{status} </if>
            <if test="recipientIdList != null and recipientIdList != ''"> and recipient_id_list = #{recipientIdList} </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-SysWarningConfigEntity-result" parameterType = "com.hzya.frame.sysnew.warningConfig.entity.SysWarningConfigEntity">
    select
    config.*
    ,template.template_name
    from sys_warning_config config
    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 config.id like concat('%',#{id},'%') </if>
            <if test="sorts != null"> and config.sorts like concat('%',#{sorts},'%') </if>
            <if test="create_user_id != null and create_user_id != ''"> and config.create_user_id like concat('%',#{create_user_id},'%') </if>
            <if test="create_time != null"> and config.create_time like concat('%',#{create_time},'%') </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and config.modify_user_id like concat('%',#{modify_user_id},'%') </if>
            <if test="modify_time != null"> and config.modify_time like concat('%',#{modify_time},'%') </if>
            <if test="sts != null and sts != ''"> and config.sts like concat('%',#{sts},'%') </if>
            <if test="org_id != null and org_id != ''"> and config.org_id like concat('%',#{org_id},'%') </if>
            <if test="companyId != null and companyId != ''"> and config.company_id like concat('%',#{companyId},'%') </if>
            <if test="messageTemplateId != null and messageTemplateId != ''"> and config.message_template_id like concat('%',#{messageTemplateId},'%') </if>
            <if test="appIdList != null and appIdList != ''"> and config.app_id_list like concat('%',#{appIdList},'%') </if>
            <if test="warningAppId != null and warningAppId != ''"> and config.warning_app_id like concat('%',#{warningAppId},'%') </if>
            <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> and config.accept_message_api_code like concat('%',#{acceptMessageApiCode},'%') </if>
            <if test="remark != null and remark != ''"> and config.remark like concat('%',#{remark},'%') </if>
            <if test="status != null and status != ''"> and config.status like concat('%',#{status},'%') </if>
            <if test="recipientIdList != null and recipientIdList != ''"> and config.recipient_id_list like concat('%',#{recipientIdList},'%') </if>
            and config.sts='Y'
            and template.sts='Y'
    </trim>
    <if test=" sort == null or sort == ''.toString() "> order by config.sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>

<!-- 查询列表 字段采用or格式 -->
<select id="SysWarningConfigentity_list_or" resultMap="get-SysWarningConfigEntity-result" parameterType = "com.hzya.frame.sysnew.warningConfig.entity.SysWarningConfigEntity">
    select
    <include refid="SysWarningConfigEntity_Base_Column_List" />
    from sys_warning_config
    <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="messageTemplateId != null and messageTemplateId != ''"> or message_template_id = #{messageTemplateId} </if>
             <if test="appIdList != null and appIdList != ''"> or app_id_list = #{appIdList} </if>
             <if test="warningAppId != null and warningAppId != ''"> or warning_app_id = #{warningAppId} </if>
             <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> or accept_message_api_code = #{acceptMessageApiCode} </if>
             <if test="remark != null and remark != ''"> or remark = #{remark} </if>
             <if test="status != null and status != ''"> or status = #{status} </if>
             <if test="recipientIdList != null and recipientIdList != ''"> or recipient_id_list = #{recipientIdList} </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.warningConfig.entity.SysWarningConfigEntity" keyProperty="id" useGeneratedKeys="true">
    insert into sys_warning_config(
  <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="messageTemplateId != null and messageTemplateId != ''"> message_template_id , </if>
            <if test="appIdList != null and appIdList != ''"> app_id_list , </if>
            <if test="warningAppId != null and warningAppId != ''"> warning_app_id , </if>
            <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> accept_message_api_code , </if>
            <if test="remark != null and remark != ''"> remark , </if>
            <if test="status != null and status != ''"> status , </if>
            <if test="recipientIdList != null and recipientIdList != ''"> recipient_id_list , </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="messageTemplateId != null and messageTemplateId != ''"> #{messageTemplateId} ,</if>
            <if test="appIdList != null and appIdList != ''"> #{appIdList} ,</if>
            <if test="warningAppId != null and warningAppId != ''"> #{warningAppId} ,</if>
            <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> #{acceptMessageApiCode} ,</if>
            <if test="remark != null and remark != ''"> #{remark} ,</if>
            <if test="status != null and status != ''"> #{status} ,</if>
            <if test="recipientIdList != null and recipientIdList != ''"> #{recipientIdList} ,</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="id" useGeneratedKeys="true">
  insert into sys_warning_config(create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, message_template_id, app_id_list, warning_app_id, accept_message_api_code, remark, status, recipient_id_list,  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.messageTemplateId},#{entity.appIdList},#{entity.warningAppId},#{entity.acceptMessageApiCode},#{entity.remark},#{entity.status},#{entity.recipientIdList}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
    insert into sys_warning_config(create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, message_template_id, app_id_list, warning_app_id, accept_message_api_code, remark, status, recipient_id_list)
    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.messageTemplateId},#{entity.appIdList},#{entity.warningAppId},#{entity.acceptMessageApiCode},#{entity.remark},#{entity.status},#{entity.recipientIdList})
    </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),
    message_template_id = values(message_template_id),
    app_id_list = values(app_id_list),
    warning_app_id = values(warning_app_id),
    accept_message_api_code = values(accept_message_api_code),
    remark = values(remark),
    status = values(status),
    recipient_id_list = values(recipient_id_list)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.sysnew.warningConfig.entity.SysWarningConfigEntity" >
update sys_warning_config  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="messageTemplateId != null and messageTemplateId != ''"> message_template_id = #{messageTemplateId},</if>
  <if test="appIdList != null and appIdList != ''"> app_id_list = #{appIdList},</if>
  <if test="warningAppId != null and warningAppId != ''"> warning_app_id = #{warningAppId},</if>
  <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> accept_message_api_code = #{acceptMessageApiCode},</if>
  <if test="remark != null and remark != ''"> remark = #{remark},</if>
  <if test="status != null and status != ''"> status = #{status},</if>
  <if test="recipientIdList != null and recipientIdList != ''"> recipient_id_list = #{recipientIdList},</if>
</trim>
where id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.sysnew.warningConfig.entity.SysWarningConfigEntity" >
update sys_warning_config  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.warningConfig.entity.SysWarningConfigEntity" >
update sys_warning_config  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="messageTemplateId != null and messageTemplateId != ''"> and message_template_id = #{messageTemplateId} </if>
            <if test="appIdList != null and appIdList != ''"> and app_id_list = #{appIdList} </if>
            <if test="warningAppId != null and warningAppId != ''"> and warning_app_id = #{warningAppId} </if>
            <if test="acceptMessageApiCode != null and acceptMessageApiCode != ''"> and accept_message_api_code = #{acceptMessageApiCode} </if>
            <if test="remark != null and remark != ''"> and remark = #{remark} </if>
            <if test="status != null and status != ''"> and status = #{status} </if>
            <if test="recipientIdList != null and recipientIdList != ''"> and recipient_id_list = #{recipientIdList} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from sys_warning_config where id = #{id}
</delete>

</mapper>

