<?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.dxhy.core.dao.ExtMessageControlDao">
    <resultMap id="BaseResultMap" type="com.dxhy.core.entity.ExtSysMessagecontrolVo">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="create_time" property="createTimeNew" jdbcType="VARCHAR"/>
        <result column="update_time" property="updateTimeNew" jdbcType="VARCHAR"/>
        <result column="user_account" property="userAccount" jdbcType="VARCHAR"/>
        <result column="operation_status" property="operationStatus" jdbcType="VARCHAR"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="url" property="url" jdbcType="VARCHAR"/>
    </resultMap>
    <select id="queryMessageContol" resultMap="BaseResultMap" databaseId="mysql">
        SELECT
        id,
        date_format(create_time,'%Y-%m-%d %H:%i:%S') create_time,
        date_format(update_time,'%Y-%m-%d %H:%i:%S') update_time,
        user_account,
        operation_status,
        title,
        content,
        url
        FROM
        sys_messagecontrol
        WHERE
        user_account = #{userName}
        <if test="operationStatus!=''and operationStatus!=null and operationStatus!='99' ">
            and operation_status = #{operationStatus}
        </if>
        ORDER BY operation_status ASC,update_time desc
    </select>
    <select id="queryMessageContol" resultMap="BaseResultMap" databaseId="oracle">
        SELECT
        id,
        to_char(create_time,'yyyy-MM-dd HH24:mi:ss') create_time,
        to_char(update_time,'yyyy-MM-dd HH24:mi:ss') update_time,
        user_account,
        operation_status,
        title,
        content,
        url
        FROM
        sys_messagecontrol
        WHERE
        user_account = #{userName}
        <if test="operationStatus!=''and operationStatus!=null ">
            and operation_status = #{operationStatus}
        </if>
        ORDER BY operation_status ASC,update_time desc
    </select>
    <select id="queryCount" resultType="java.lang.Integer">
        SELECT count(id)
        FROM sys_messagecontrol
        WHERE user_account = #{userName}
          AND operation_status = 0
    </select>
    <update id="updateOperationStatusById"
            parameterType="com.dxhy.core.entity.ExtSysMessagecontrol">
        update sys_messagecontrol
        set operation_status=1,
            update_time=#{updateTime}
        where id = #{id}
    </update>
    <update id="updateOperationStatusAll" parameterType="com.dxhy.core.entity.ExtSysMessagecontrol">
        update sys_messagecontrol
        set operation_status=1,
            update_time=#{updateTime}
        where user_account = #{userAccount}
          and operation_status = 0
    </update>
</mapper>
