<?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.casic.missiles.modular.system.dao.MessagePusherMapper">

    <sql id="date_toChar" databaseId="mysql">
       DATE_FORMAT(${paramTime},'%Y-%m-%d %H:%i:%s')
    </sql>

    <sql id="date_toChar" databaseId="pgsql">
       TO_CHAR(${paramTime},'yyyy-mm-dd hh24:mi:ss')
    </sql>

    <sql id="date_toChar" databaseId="oracle">
       TO_CHAR(${paramTime},'yyyy-mm-dd hh24:mi:ss')
    </sql>

    <update id="getJob" flushCache="true">
        update alarm_job set job_status = 1,
        JOB_BELONG_TO = #{personId},<!--add 0605-->
        GET_JOB_PERSON = #{personId},
        GET_JOB_TIME = #{getTime},
        SHOULD_HANDLE_TIME = #{shouldHandleTime}
        where id = #{id}
    </update>



    <select id="getDeptIdsByDevcode" resultType="Map">
        SELECT bwi.deptid AS "deptid",bwi.responsible_dept  AS  "ownerDeptId"
        FROM bus_device bd
        JOIN bus_device_well bdw ON bdw.device_id=bd.id
        JOIN bus_well_info bwi ON bwi.id=bdw.well_id
        WHERE  bd.devcode=#{devcode}
    </select>

    <select id="getUserPush" resultType="com.casic.missiles.modular.system.model.UserPush">
        select id AS "id",client_id  AS  "clientId",user_id AS "userId",
        <include refid="date_toChar">
              <property name="paramTime" value="create_time"/>
         </include> AS "createTime",
        <include refid="date_toChar">
            <property name="paramTime" value="update_time"/>
        </include>  AS "updateTime",tag,type
        from sys_user_push
    </select>

    <select id="getUserIdList" resultType="Long">
        select id
        from   sys_user
        where  dept_id=#{ownerDeptId}
    </select>

    <select id="getPushByUserId" resultType="com.casic.missiles.modular.system.model.UserPush">
        select id,client_id  AS  "clientId",user_id AS "userId",
        <include refid="date_toChar">
            <property name="paramTime" value="create_time"/>
        </include> AS "createTime",
        <include refid="date_toChar">
            <property name="paramTime" value="update_time"/>
        </include>  AS "updateTime",tag,type
        from sys_user_push
        where user_id=#{userId} AND   type=#{type}
    </select>


</mapper>