<?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.nantian.cloud.jljc.mapper.TSupervisionSuggestMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TSupervisionSuggest">
        <id column="id" property="id" />
        <result column="userid" property="userid" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
        <result column="dept_id" property="deptId" />
        <result column="monitor_id" property="monitorId" />
        <result column="component_name" property="componentName" />
        <result column="remark" property="remark" />
        <result column="name" property="name" />
        <result column="area" property="area" />
        <result column="Illegal_act" property="illegalAct" />
        <result column="suggestion" property="suggestion" />
        <result column="basis" property="basis" />
        <result column="review_type" property="reviewType" />
        <result column="review_situation" property="reviewSituation" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, userid, update_time, del_flag, dept_id, monitor_id, component_name, remark, name, area, Illegal_act, suggestion, basis, review_type, review_situation
    </sql>

    <!--查询条件(year年份,code监察编号,area地区,name监察单位名称,type类型(1复查情况,0处理建议))-->
    <select id="getSuggestPage" resultType="com.nantian.cloud.jljc.entity.TSupervisionSuggest">
        select s.id, s.userid, s.update_time, s.del_flag, s.dept_id, s.monitor_id, IFNULL(s.component_name,'-') component_name, IFNULL(s.name,'-') name,
        IFNULL(s.area,'-') area, IFNULL(s.Illegal_act,'-') Illegal_act, IFNULL(s.suggestion,'-') suggestion, IFNULL(s.basis,'-') basis , s.review_type, IFNULL(s.review_situation,'-') review_situation, IFNULL(d.meaning2,'-') region,
        IFNULL(s.remark,case when t.type = "1" then concat("书面监察/",t.source) when t.type = "2" then concat("现场监察/",t.source) else concat('',t.source) end) remark
        from t_supervision_suggest s
        left join t_supervise_task t on t.monitor_id = s.monitor_id
        left join dict_region d on concat(left(t.locate,4),'00') = d.id
        where s.del_flag = "1"
        <if test="query.code != null and query.code != ''">
            and s.monitor_id like concat("%",#{query.code},"%")
        </if>
        <if test="query.year != null and query.year != ''">
            and s.monitor_id like concat("%",#{query.year},"%")
        </if>
        <if test="query.type != null and query.type != ''">
            and s.review_type = #{query.type}
        </if>
        <if test="query.area != null and query.area != ''">
            and t.locate like concat(#{query.area},"%")
        </if>
        <if test="query.name != null and query.name != ''">
            and s.component_name like concat("%",#{query.name},"%")
        </if>
    </select>

    <update id="updateData" parameterType="com.nantian.cloud.jljc.entity.TSupervisionSuggest">
        UPDATE t_supervision_suggest a
        set a.Illegal_act=#{illegalAct},
        a.review_type=#{reviewType},
        a.review_situation=#{reviewSituation},
        a.remark=#{remark},
        a.update_time =#{updateTime},
        a.userid=#{userid},
        a.basis = #{basis},
        a.suggestion = #{suggestion}
        where a.id=#{id}
    </update>


    <select id="getSuggestList" resultType="com.nantian.cloud.jljc.entity.TSupervisionSuggest">
        select s.id, s.userid, s.update_time, s.del_flag, s.dept_id, s.monitor_id, IFNULL(s.component_name,'-') component_name, IFNULL(s.name,'-') name,
        IFNULL(s.area,'-') area, IFNULL(s.Illegal_act,'-') Illegal_act, IFNULL(s.suggestion,'-') suggestion, IFNULL(s.basis,'-') basis , s.review_type, IFNULL(s.review_situation,'-') review_situation, IFNULL(d.meaning2,'-') region,
        IFNULL(s.remark,case when t.type = "1" then concat("书面监察/",t.source) when t.type = "2" then concat("现场监察/",t.source) else concat('',t.source) end) remark
        from t_supervision_suggest s
        left join t_supervise_task t on t.monitor_id = s.monitor_id
        left join dict_region d on concat(left(t.locate,4),'00') = d.id
        where s.del_flag = "1"
        <if test="query.code != null and query.code != ''">
            and s.monitor_id like concat("%",#{query.code},"%")
        </if>
        <if test="query.year != null and query.year != ''">
            and s.monitor_id like concat("%",#{query.year},"%")
        </if>
        <if test="query.type != null and query.type != ''">
            and s.review_type = #{query.type}
        </if>
        <if test="query.area != null and query.area != ''">
            and t.locate like concat(#{query.area},"%")
        </if>
        <if test="query.name != null and query.name != ''">
            and s.component_name like concat("%",#{query.name},"%")
        </if>
    </select>

</mapper>
