<?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.messageManage.dao.impl.SysMessageManageDaoImpl">

    <resultMap id="get-SysMessageManageEntity-result"
               type="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="theme" column="theme" jdbcType="VARCHAR"/>
        <result property="code" column="code" jdbcType="VARCHAR"/>
        <result property="sendApp" column="send_app" jdbcType="VARCHAR"/>
        <result property="sendApi" column="send_api" jdbcType="VARCHAR"/>
        <result property="dataType" column="data_type" jdbcType="VARCHAR"/>
        <result property="remark" column="remark" 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="SysMessageManageEntity_Base_Column_List">
        id
       ,theme 
        ,code 
        ,send_app 
        ,send_api 
        ,data_type 
        ,remark 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
     </sql>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-SysMessageManageEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        select
        <include refid="SysMessageManageEntity_Base_Column_List"/>
        from sys_message_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="theme != null and theme != ''">and theme = #{theme}</if>
            <if test="code != null and code != ''">and code = #{code}</if>
            <if test="sendApp != null and sendApp != ''">and send_app = #{sendApp}</if>
            <if test="sendApi != null and sendApi != ''">and send_api = #{sendApi}</if>
            <if test="dataType != null and dataType != ''">and data_type = #{dataType}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</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.messageManage.entity.SysMessageManageEntity">
        select count(1) from sys_message_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="theme != null and theme != ''">and theme = #{theme}</if>
            <if test="code != null and code != ''">and code = #{code}</if>
            <if test="sendApp != null and sendApp != ''">and send_app = #{sendApp}</if>
            <if test="sendApi != null and sendApi != ''">and send_api = #{sendApi}</if>
            <if test="dataType != null and dataType != ''">and data_type = #{dataType}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</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_not_id" resultType="Integer"
            parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        select count(1) from sys_message_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id != #{id}</if>
            <if test="theme != null and theme != ''">and theme = #{theme}</if>
            <if test="code != null and code != ''">and code = #{code}</if>
            <if test="sendApp != null and sendApp != ''">and send_app = #{sendApp}</if>
            <if test="sendApi != null and sendApi != ''">and send_api = #{sendApi}</if>
            <if test="dataType != null and dataType != ''">and data_type = #{dataType}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</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>
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="entity_list_like" resultMap="get-SysMessageManageEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        select
        <include refid="SysMessageManageEntity_Base_Column_List"/>
        from sys_message_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="theme != null and theme != ''">and theme like concat('%',#{theme},'%')</if>
            <if test="code != null and code != ''">and code like concat('%',#{code},'%')</if>
            <if test="sendApp != null and sendApp != ''">and send_app like concat('%',#{sendApp},'%')</if>
            <if test="sendApi != null and sendApi != ''">and send_api like concat('%',#{sendApi},'%')</if>
            <if test="dataType != null and dataType != ''">and data_type like concat('%',#{dataType},'%')</if>
            <if test="remark != null and remark != ''">and remark like concat('%',#{remark},'%')</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="SysMessageManageentity_list_or" resultMap="get-SysMessageManageEntity-result"
            parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        select
        <include refid="SysMessageManageEntity_Base_Column_List"/>
        from sys_message_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="theme != null and theme != ''">or theme = #{theme}</if>
            <if test="code != null and code != ''">or code = #{code}</if>
            <if test="sendApp != null and sendApp != ''">or send_app = #{sendApp}</if>
            <if test="sendApi != null and sendApi != ''">or send_api = #{sendApi}</if>
            <if test="dataType != null and dataType != ''">or data_type = #{dataType}</if>
            <if test="remark != null and remark != ''">or remark = #{remark}</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.messageManage.entity.SysMessageManageEntity"
            >
        insert into sys_message_manage(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="theme != null and theme != ''">theme ,</if>
            <if test="code != null and code != ''">code ,</if>
            <if test="sendApp != null and sendApp != ''">send_app ,</if>
            <if test="sendApi != null and sendApi != ''">send_api ,</if>
            <if test="dataType != null and dataType != ''">data_type ,</if>
            <if test="remark != null and remark != ''">remark ,</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="theme != null and theme != ''">#{theme} ,</if>
            <if test="code != null and code != ''">#{code} ,</if>
            <if test="sendApp != null and sendApp != ''">#{sendApp} ,</if>
            <if test="sendApi != null and sendApi != ''">#{sendApi} ,</if>
            <if test="dataType != null and dataType != ''">#{dataType} ,</if>
            <if test="remark != null and remark != ''">#{remark} ,</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(theme, code, send_app, send_api, data_type, remark, sorts, create_user_id,
        create_time, modify_user_id, modify_time, sts, org_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.theme},#{entity.code},#{entity.sendApp},#{entity.sendApi},#{entity.dataType},#{entity.remark},#{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(theme, code, send_app, send_api, data_type, remark, sorts, create_user_id,
        create_time, modify_user_id, modify_time, sts, org_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.theme},#{entity.code},#{entity.sendApp},#{entity.sendApi},#{entity.dataType},#{entity.remark},#{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
        theme = values(theme),
        code = values(code),
        send_app = values(send_app),
        send_api = values(send_api),
        data_type = values(data_type),
        remark = values(remark),
        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>
    <!--通过主键修改方法-->
    <update id="entity_update" parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        update sys_message_manage set
        <trim suffix="" suffixOverrides=",">
            <if test="theme != null and theme != ''">theme = #{theme},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="sendApp != null and sendApp != ''">send_app = #{sendApp},</if>
            <if test="sendApi != null and sendApi != ''">send_api = #{sendApi},</if>
            <if test="dataType != null and dataType != ''">data_type = #{dataType},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="sorts != null">sorts = #{sorts},</if>
            <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>
        </trim>
        where id = #{id}
    </update>
    <!-- 逻辑删除 -->
    <update id="entity_logicDelete" parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
update sys_message_manage  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.messageManage.entity.SysMessageManageEntity">
        update sys_message_manage 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="theme != null and theme != ''">and theme = #{theme}</if>
            <if test="code != null and code != ''">and code = #{code}</if>
            <if test="sendApp != null and sendApp != ''">and send_app = #{sendApp}</if>
            <if test="sendApi != null and sendApi != ''">and send_api = #{sendApi}</if>
            <if test="dataType != null and dataType != ''">and data_type = #{dataType}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</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="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>
    </update>
    <!--通过主键删除-->
    <delete id="entity_delete">
    delete from sys_message_manage where id = #{id}
</delete>


    <!-- 分页查询列表 采用like格式 -->
    <select id="queryListByPageVo" resultType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManagePageVo"
            parameterType="com.hzya.frame.sysnew.messageManage.entity.SysMessageManageEntity">
        SELECT
        a.id AS id,
        a.theme AS theme,
        a.CODE AS CODE,
        app.name AS sendAppName,
        api.api_name AS sendApiName,
        a.data_type AS dataType,
        a.remark AS remark
        FROM
        sys_message_manage a
        LEFT JOIN sys_app app ON a.send_app = app.id AND app.sts = 'Y'
        LEFT JOIN sys_app_api api ON a.send_api = api.id AND api.sts = 'Y'
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and a.id like concat('%',#{id},'%')</if>
            <if test="theme != null and theme != ''">and a.theme like concat('%',#{theme},'%')</if>
            <if test="code != null and code != ''">and a.code like concat('%',#{code},'%')</if>
            <if test="sendApp != null and sendApp != ''">and a.send_app = #{sendApp}</if>
            <if test="sendApi != null and sendApi != ''">and a.send_api = #{sendApi}</if>
            <if test="dataType != null and dataType != ''">and a.data_type = #{dataType}</if>
            <if test="remark != null and remark != ''">and a.remark like concat('%',#{remark},'%')</if>
            <if test="org_id != null and org_id != ''">and a.org_id like concat('%',#{org_id},'%')</if>
            and a.sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by a.sorts asc</if>
    </select>
</mapper>

