<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.special" name="网格人员">

    <select id="findGridSpecialTaskList" parameterType="page" resultType="map" expose="true" name="查询专项任务">
        SELECT
            jgst.id,
            jgst.task_name,
            jgst.task_company_id,
            jgst.task_user_id,
            so.name taskCompanyName,
            su.name taskUserName,
            DATE_FORMAT(jgst.initiation_time,'%Y-%m-%d %T') initiation_time,
            DATE_FORMAT(jgst.deadline_time,'%Y-%m-%d %T') deadline_time,
            jgst.description_task,
            jgst.handling_company_id,
            jgst.handling_user_id,
            so1.name handlingCompanyName,
            su1.name handlingUserName,
            DATE_FORMAT(jgst.completion_time,'%Y-%m-%d %T') completion_time,
            jgst.description_task_end,
            jgst.is_complete
        FROM
            jl_grid_special_task jgst
        LEFT JOIN sys_office so ON jgst.task_company_id = so.id
        LEFT JOIN sys_office so1 ON jgst.handling_company_id = so1.id
        LEFT JOIN sys_user su ON jgst.task_user_id = su.id
        LEFT JOIN sys_user su1 ON jgst.handling_user_id = su1.id
        WHERE
            jgst.del_flag = '0'
        AND task_company_id = #{params._user.company_id}
        <if test="params.deadline_time != null and params.deadline_time != ''">
            AND deadline_time = #{params.deadline_time}
        </if>
        <if test="params.is_complete != null and params.is_complete != ''">
            AND is_complete = #{params.is_complete}
        </if>
        <if test="params.task_name != null and params.task_name != ''">
            AND task_name = #{params.task_name}
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="findGridSpecialTaskHandlingList" parameterType="page" resultType="map" expose="true" name="查询处置专项任务列表">
        SELECT
            jgst.id,
            jgst.task_name,
            jgst.task_company_id,
            jgst.task_user_id,
            so.name taskCompanyName,
            su.name taskUserName,
            DATE_FORMAT(jgst.initiation_time,'%Y-%m-%d %T') initiation_time,
            DATE_FORMAT(jgst.deadline_time,'%Y-%m-%d %T') deadline_time,
            jgst.description_task,
            jgst.handling_company_id,
            jgst.handling_user_id,
            so1.name handlingCompanyName,
            su1.name handlingUserName,
            DATE_FORMAT(jgst.completion_time,'%Y-%m-%d %T') completion_time,
            jgst.description_task_end,
            CASE jgst.is_complete WHEN '1' THEN '是' WHEN '2' THEN '否' ELSE '未知' END is_complete
        FROM
            jl_grid_special_task jgst
        LEFT JOIN sys_office so ON jgst.task_company_id = so.id
        LEFT JOIN sys_office so1 ON jgst.handling_company_id = so1.id
        LEFT JOIN sys_user su ON jgst.task_user_id = su.id
        LEFT JOIN sys_user su1 ON jgst.handling_user_id = su1.id
        <where>
            jgst.del_flag = '0'
            AND jgst.handling_company_id = #{params._user.company_id}
            <if test="params.deadline_time_start != null and params.deadline_time_start != '' and params.deadline_time_end != null and params.deadline_time_start != ''">
                AND deadline_time BETWEEN CONCAT(#{params.deadline_time_start},' 00:00:00') AND CONCAT(#{params.deadline_time_end},' 23:59:59')
            </if>
            <!-- 此处条件作为业务兼容，因为我不知道哪个页面调用了这个接口-->
            <if test="params.deadline_time != null and params.deadline_time != ''">
                AND jgst.deadline_time = #{params.deadline_time}
            </if>
            <if test="params.is_complete != null and params.is_complete != ''">
                AND jgst.is_complete = #{params.is_complete}
            </if>
            <if test="params.task_name != null and params.task_name != ''">
                AND jgst.task_name like CONCAT( #{params.task_name}, '%')
            </if>
            <if test="params.task_user_name != null and params.task_user_name != ''">
                AND su.name like CONCAT( #{params.task_user_name}, '%')
            </if>
            <if test="params.handling_company_name != null and params.handling_company_name != ''">
                AND so1.name like CONCAT( #{params.task_company_name}, '%')
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <insert id="insertGridSpecialTask" parameterType="map" expose="true" name="添加专项任务">
        INSERT INTO jl_grid_special_task(
            id,
            task_name,
            task_company_id,
            task_user_id,
            initiation_time,
            deadline_time,
            description_task,
            handling_company_id,
            del_flag,
            create_by,
            create_time
        )VALUES(
            UUID(),
            #{task_name},
            #{_user.company_id},
            #{_user.id},
            NOW(),
            #{deadline_time},
            #{description_task},
            #{handling_company_id},
            '0',
            #{_user.id},
            NOW()
        )
    </insert>

    <update id="updateGridSpecialTask" parameterType="map" expose="true" name="专项任务处置">
        UPDATE
            jl_grid_special_task
        SET
            handling_user_id = #{_user.id},
            completion_time = #{completion_time},
            description_task_end = #{description_task_end},
            is_complete = #{is_complete},
            update_by = #{_user.id},
            update_time = NOW()
        WHERE
            id = #{id}
    </update>
</mapper>
