<?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.messageManageLogDetail.dao.impl.SysMessageManageLogDetailDaoImpl">

    <resultMap id="get-SysMessageManageLogDetailEntity-result"
               type="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="messageManageId" column="message_manage_id" jdbcType="VARCHAR"/>
        <result property="sourceData" column="source_data" jdbcType="VARCHAR"/>
        <result property="targetData" column="target_data" jdbcType="VARCHAR"/>
        <result property="returnData" column="return_data" 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"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="SysMessageManageLogDetailEntity_Base_Column_List">
        id
       ,message_manage_id
        ,source_data
        ,target_data
        ,return_data
        ,sorts
        ,create_user_id
        ,create_time
        ,modify_user_id
        ,modify_time
        ,sts
        ,org_id
     </sql>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-SysMessageManageLogDetailEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        select
        <include refid="SysMessageManageLogDetailEntity_Base_Column_List"/>
        from sys_message_manage_log_detail
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="messageManageId != null and messageManageId != ''">and message_manage_id = #{messageManageId}</if>
            <if test="sourceData != null and sourceData != ''">and source_data = #{sourceData}</if>
            <if test="targetData != null and targetData != ''">and target_data = #{targetData}</if>
            <if test="returnData != null and returnData != ''">and return_data = #{returnData}</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>
            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.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        select count(1) from sys_message_manage_log_detail
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="messageManageId != null and messageManageId != ''">and message_manage_id = #{messageManageId}</if>
            <if test="sourceData != null and sourceData != ''">and source_data = #{sourceData}</if>
            <if test="targetData != null and targetData != ''">and target_data = #{targetData}</if>
            <if test="returnData != null and returnData != ''">and return_data = #{returnData}</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>
            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-SysMessageManageLogDetailEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        select
        <include refid="SysMessageManageLogDetailEntity_Base_Column_List"/>
        from sys_message_manage_log_detail
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="messageManageId != null and messageManageId != ''">and message_manage_id like
                concat('%',#{messageManageId},'%')
            </if>
            <if test="sourceData != null and sourceData != ''">and source_data like concat('%',#{sourceData},'%')</if>
            <if test="targetData != null and targetData != ''">and target_data like concat('%',#{targetData},'%')</if>
            <if test="returnData != null and returnData != ''">and return_data like concat('%',#{returnData},'%')</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>
            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="SysMessageManageLogDetailEntity_list_or" resultMap="get-SysMessageManageLogDetailEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        select
        <include refid="SysMessageManageLogDetailEntity_Base_Column_List"/>
        from sys_message_manage_log_detail
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="messageManageId != null and messageManageId != ''">or message_manage_id = #{messageManageId}</if>
            <if test="sourceData != null and sourceData != ''">or source_data = #{sourceData}</if>
            <if test="targetData != null and targetData != ''">or target_data = #{targetData}</if>
            <if test="returnData != null and returnData != ''">or return_data = #{returnData}</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>
            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.messageManageLogDetail.entity.SysMessageManageLogDetailEntity"
            >
        insert into sys_message_manage_log_detail(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="messageManageId != null and messageManageId != ''">message_manage_id ,</if>
            <if test="sourceData != null and sourceData != ''">source_data ,</if>
            <if test="targetData != null and targetData != ''">target_data ,</if>
            <if test="returnData != null and returnData != ''">return_data ,</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="sts == null ">sts,</if>
        </trim>
        )values(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">#{id} ,</if>
            <if test="messageManageId != null and messageManageId != ''">#{messageManageId} ,</if>
            <if test="sourceData != null and sourceData != ''">#{sourceData} ,</if>
            <if test="targetData != null and targetData != ''">#{targetData} ,</if>
            <if test="returnData != null and returnData != ''">#{returnData} ,</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="sts == null ">'Y',</if>
        </trim>
        )
    </insert>
    <!-- 批量新增 -->
    <insert id="entityInsertBatch" >
        insert into sys_message_manage_log_detail(message_manage_id, source_data, target_data, return_data,sorts, create_user_id,
        create_time, modify_user_id, modify_time, sts, org_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.messageManageId},#{entity.sourceData},#{entity.targetData},#{entity.returnData},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},
            'Y')
        </foreach>
    </insert>
    <!-- 批量新增或者修改-->
    <insert id="entityInsertOrUpdateBatch" >
        insert into sys_message_manage_log_detail(message_manage_id,  source_data, target_data, return_data, sorts, create_user_id,
        create_time, modify_user_id, modify_time, sts, org_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.messageManageId},#{entity.sourceData},#{entity.targetData},#{entity.returnData},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id})
        </foreach>
        on duplicate key update
        message_manage_id = values(message_manage_id),
        source_data = values(source_data),
        target_data = values(target_data),
        return_data = values(return_data),
        sorts = values(sorts),
        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)
    </insert>

    <!--通过主键删除-->
    <delete id="entity_delete">
    delete from sys_message_manage_log_detail where id = #{id}
    </delete>

    <!-- 查询 查询上个月16号到上个月最后一号的数据 -->
    <select id="entity_list_detail_time" resultMap="get-SysMessageManageLogDetailEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        select
        <include refid="SysMessageManageLogDetailEntity_Base_Column_List"/>
        from sys_message_manage_log_detail
        <trim prefix="where" prefixOverrides="and">
            <if test="create_time != null">and create_time &gt;= #{create_time}</if>
            <if test="modify_time != null">and modify_time  &lt;= #{modify_time}</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>

    <!-- 批量更新 备份完成之后-->
    <update id="entity_update_detail_time"
            parameterType="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        UPDATE sys_message_manage_log_detail
        SET sts = 'N'
        WHERE id IN
        <foreach item="entity" index="index" collection="list" open="(" separator="," close=")">
            #{entity.id}
        </foreach>
    </update>

    <!-- 批量删除 备份完成之后-->
    <delete id="entity_delete_detail_time"
            parameterType="com.hzya.frame.sysnew.messageManageLogDetail.entity.SysMessageManageLogDetailEntity">
        DELETE FROM sys_message_manage_log_detail
        WHERE id IN
        <foreach item="entity" index="index" collection="list" open="(" separator="," close=")">
            #{entity.id}
        </foreach>
    </delete>

</mapper>

