<?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.ruoyi.system.mapper.check.TdCheckReportMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.check.TdCheckReport">
            <id property="checkId" column="check_id" jdbcType="VARCHAR"/>
            <result property="adduser" column="adduser" jdbcType="VARCHAR"/>
            <result property="depart" column="depart" jdbcType="VARCHAR"/>
            <result property="checkStartTime" column="check_start_time" jdbcType="TIMESTAMP"/>
            <result property="checkEndTime" column="check_end_time" jdbcType="TIMESTAMP"/>
            <result property="checkType" column="check_type" jdbcType="VARCHAR"/>
            <result property="area" column="area" jdbcType="VARCHAR"/>
            <result property="framework" column="framework" jdbcType="VARCHAR"/>
            <result property="checkState" column="check_state" jdbcType="VARCHAR"/>
            <result property="checkName" column="check_name" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        check_id,adduser,depart,
        check_start_time,check_end_time,check_type,
        area,framework,check_state,
        check_name,create_time
    </sql>
    <select id="selectTdCheckReportList" resultType="com.ruoyi.system.domain.check.TdCheckReport">
        select  <include refid="Base_Column_List"/> from  td_check_report
        <trim prefix="where" prefixOverrides="and|or">
            <if test="area!=null and area!=''">
                AND area = #{area}
            </if>
            <if test="framework!=null and framework!=''">
                AND framework = #{framework}
            </if>
            <if test="checkState!=null and checkState!=''">
                AND check_state = #{checkState}
            </if>
            <if test="depart!=null and depart!=''">
                AND depart = #{depart}
            </if>
            AND  (check_type = '0' or check_type is null)
        </trim>
        ORDER BY create_time DESC
    </select>

    <select id="selectTdCheckResultList" resultType="com.ruoyi.system.domain.check.TdCheckReport">
        select  <include refid="Base_Column_List"/> from  td_check_report
        <trim prefix="where" prefixOverrides="and|or">
            <if test="area!=null and area!=''">
                AND area = #{area}
            </if>
            <if test="framework!=null and framework!=''">
                AND framework = #{framework}
            </if>
            <if test="checkState!=null and checkState!=''">
                AND check_state = #{checkState}
            </if>
            <if test="depart!=null and depart!=''">
                AND depart = #{depart}
            </if>
            AND check_type in (0,1)
        </trim>
        ORDER BY create_time DESC
    </select>


    <select id="selectTypeCount"  resultType="com.ruoyi.system.domain.count.CheckTypeCountDTO">
        SELECT
            SUM (CASE WHEN check_type = 0 THEN 1 ELSE 0 END) AS zxjc,
            SUM (CASE WHEN check_type = 1 THEN 1 ELSE 0 END) AS bmjjc
        from td_check_report
    </select>

    <select id="selectResultCount"  resultType="com.ruoyi.system.domain.count.CheckResultCountDTO">
        SELECT
            SUM (CASE WHEN check_state = 0 THEN 1 ELSE 0 END) AS tg,
            SUM (CASE WHEN check_state = 1 THEN 1 ELSE 0 END) AS wtg,
            SUM (CASE WHEN check_state = 2 THEN 1 ELSE 0 END) AS djc
        from td_check_report
    </select>

</mapper>