THazardWorkPlanCheck.xml 13.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?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.testor.module.hazard.dao.THazardWorkPlanCheckDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.hazard.model.domain.THazardWorkPlanCheck">
        <id column="id" property="id"/>
        <id column="plan_id" property="planId"/>
        <id column="check_time" property="checkTime"/>
        <id column="is_compliant" property="isCompliant"/>
        <id column="problem_type" property="problemType"/>
        <id column="check_description" property="checkDescription"/>
        <id column="check_images" property="checkImages"/>
        <id column="check_signature" property="checkSignature"/>
        <id column="check_status" property="checkStatus"/>
        <id column="code" property="code"/>
        <id column="workType" property="workType"/>
        <id column="workLevel" property="workLevel"/>
        <id column="stakeholderWork" property="stakeholderWork"/>
        <id column="check_signature_time" property="checkSignatureTime"/>
22
        <id column="check_name" property="checkName"/>
23 24
        <id column="check_id" property="checkId"/>
        <id column="basic_id" property="basicId"/>
25 26 27 28 29
    </resultMap>

    <select id="selectTHazardWorkPlanCheckList" resultMap="BaseResultMap">
        select hwpc.*,hwp.code code,hwp.work_type workType,hwp.work_level workLevel,hwp.stakeholder_work stakeholderWork
        from t_hazard_work_plan_check hwpc
30
        left join t_hazard_work_plan hwp on hwpc.plan_id = hwp.id
31 32 33 34 35 36 37
        where hwpc.status = '0' and hwpc.plan_id = #{param.planId}
        order by hwpc.create_date desc
    </select>

    <select id="selectAppTHazardWorkPlanCheckList" resultMap="BaseResultMap">
        select hwpc.*,hwp.code code,hwp.work_type workType,hwp.work_level workLevel,hwp.stakeholder_work stakeholderWork
        from t_hazard_work_plan_check hwpc
38
        left join t_hazard_work_plan hwp on hwpc.plan_id = hwp.id
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        left join
        t_sys_dict_data dd on hwp.work_type = dd.dict_data_id
        left join
        t_sys_dict_data dd2 on hwp.work_level = dd2.dict_data_id
        left join
        t_sys_dict_data dd3 on hwpc.problem_type = dd3.dict_data_id
        where hwpc.status = '0'  and hwpc.create_by=#{param.createBy}
        <if test="param.planId!=null and param.planId!=''">
            and hwpc.plan_id = #{param.planId}
        </if>
        <if test="param.workType!=null and param.workType!=''">
            and hwp.work_type = #{param.workType}
        </if>
        <if test="param.keywords!=null and param.keywords!=''">
            AND (
            hwpc.basic_unit LIKE CONCAT('%', #{param.keywords}, '%')
            OR dd.dict_value LIKE CONCAT('%', #{param.keywords}, '%')
            OR dd2.dict_value LIKE CONCAT('%', #{param.keywords}, '%')
            OR hwpc.check_description LIKE CONCAT('%', #{param.keywords}, '%')
            OR (
            CASE
            WHEN hwpc.is_compliant = 1 THEN '是'
            WHEN hwpc.is_compliant = 0 THEN '否'
            ELSE ''
            END
            ) LIKE CONCAT('%', #{param.keywords}, '%')
            OR dd3.dict_value LIKE CONCAT('%', #{param.keywords}, '%')
            OR (
            CASE
            WHEN hwpc.check_status = 1 THEN '暂存'
            WHEN hwpc.check_status = 2 THEN '已完成'
            ELSE ''
            END
            ) LIKE CONCAT('%', #{param.keywords}, '%')
            )
        </if>
75
        order by hwpc.check_time desc
76 77
    </select>

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    <select id="selectTHazardWorkPlanCheckManageList" resultMap="BaseResultMap">
        select hwpc.*,hwp.code code,hwp.work_type workType,hwp.work_level workLevel,hwp.stakeholder_work stakeholderWork
        from t_hazard_work_plan_check hwpc
        left join t_hazard_work_plan hwp on hwpc.plan_id = hwp.id
        where hwpc.status = '0'
        <if test="param.code!=null and param.code!=''">
            and hwp.code like concat('%', #{param.code}, '%')
        </if>
        <if test="param.workType!=null and param.workType!=''">
            and hwp.work_type = #{param.workType}
        </if>
        <if test="param.workLevel!=null and param.workLevel!=''">
            and hwp.work_level = #{param.workLevel}
        </if>
        <if test="param.stakeholderWork!=null and param.stakeholderWork!=''">
            and hwp.stakeholder_work = #{param.stakeholderWork}
        </if>
        <if test="param.isCompliant!=null and param.isCompliant!=''">
            and hwpc.is_compliant = #{param.isCompliant}
        </if>
        <if test="param.problemType!=null and param.problemType!=''">
            and hwpc.problem_type = #{param.problemType}
        </if>
        <if test="param.checkDescription!=null and param.checkDescription!=''">
            and hwpc.check_description like concat('%', #{param.checkDescription}, '%')
        </if>
        <if test="param.checkName!=null and param.checkName!=''">
            and hwpc.check_name like concat('%', #{param.checkName}, '%')
        </if>
鲁鸿波's avatar
鲁鸿波 committed
107
        <if test="param.startTime != null and param.startTime != ''  and param.endTime != null and param.endTime != ''">
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
            and hwpc.check_time between #{param.startTime} and #{param.endTime}
        </if>
        <if test="param.orgIdList != null and param.orgIdList.size()>0">
            and (
            <foreach item="id" collection="param.orgIdList" separator=" OR ">
                hwpc.basic_id LIKE concat('%', #{id}, '%')
            </foreach>
            )
        </if>
        order by hwpc.check_time desc
    </select>

    <select id="selectTHazardWorkPlanCheckManageExportList" resultMap="BaseResultMap">
        select
        hwpc.id,hwpc.plan_id,hwpc.check_time,hwpc.is_compliant,dd4.dict_value problem_type,hwpc.check_description,hwpc.check_images,hwpc.check_signature,hwpc.status,
        hwpc.create_by,hwpc.create_date,hwpc.update_by,hwpc.update_date,hwpc.remarks,hwpc.check_unit,hwpc.basic_unit,hwpc.check_status,hwpc.check_signature_time,hwpc.check_name,hwpc.check_id,hwpc.basic_id,
        hwp.code code,
        dd.dict_value as workType,
        dd2.dict_value workLevel,
        dd3.dict_value stakeholderWork
        from
        t_hazard_work_plan_check hwpc
        left join
        t_hazard_work_plan hwp on hwpc.plan_id = hwp.id
        left join
        t_sys_dict_data dd on hwp.work_type = dd.dict_data_id
        left join
        t_sys_dict_data dd2 on hwp.work_level = dd2.dict_data_id
        left join
        t_sys_dict_data dd3 on hwp.stakeholder_work = dd3.dict_data_id
        left join
        t_sys_dict_data dd4 on hwpc.problem_type = dd4.dict_data_id
        where hwpc.status = '0'
        <if test="param.code!=null and param.code!=''">
            and hwp.code like concat('%', #{param.code}, '%')
        </if>
        <if test="param.workType!=null and param.workType!=''">
            and hwp.work_type = #{param.workType}
        </if>
        <if test="param.workLevel!=null and param.workLevel!=''">
            and hwp.work_level = #{param.workLevel}
        </if>
        <if test="param.stakeholderWork!=null and param.stakeholderWork!=''">
            and hwp.stakeholder_work = #{param.stakeholderWork}
        </if>
        <if test="param.isCompliant!=null and param.isCompliant!=''">
            and hwpc.is_compliant = #{param.isCompliant}
        </if>
        <if test="param.problemType!=null and param.problemType!=''">
            and hwpc.problem_type = #{param.problemType}
        </if>
        <if test="param.checkDescription!=null and param.checkDescription!=''">
            and hwpc.check_description like concat('%', #{param.checkDescription}, '%')
        </if>
        <if test="param.checkName!=null and param.checkName!=''">
            and hwpc.check_name like concat('%', #{param.checkName}, '%')
        </if>
鲁鸿波's avatar
鲁鸿波 committed
165
        <if test="param.startTime != null and param.startTime != ''  and param.endTime != null and param.endTime != ''">
166 167 168 169 170 171 172 173 174 175 176 177
            and hwpc.check_time between #{param.startTime} and #{param.endTime}
        </if>
        <if test="param.orgIdList != null and param.orgIdList.size()>0">
            and (
            <foreach item="id" collection="param.orgIdList" separator=" OR ">
                hwpc.basic_id LIKE concat('%', #{id}, '%')
            </foreach>
            )
        </if>
        order by hwpc.check_time desc
    </select>

178 179 180 181 182 183 184
    <select id="detail" resultMap="BaseResultMap">
        select hwpc.*,hwp.code code,hwp.work_type workType,hwp.work_level workLevel,hwp.stakeholder_work stakeholderWork
        from t_hazard_work_plan_check hwpc
        left join t_hazard_work_plan hwp on hwpc.plan_id = hwp.id
        where hwpc.status = '0' and hwpc.id = #{id}
    </select>

鲁鸿波's avatar
鲁鸿波 committed
185 186
    <select id="selectCheckComplianceStatistics" resultType="com.testor.module.hazard.model.vo.HazardWorkPlanCheckComplianceStatisticsVO">
        SELECT
鲁鸿波's avatar
鲁鸿波 committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200
        COALESCE(COUNT(*), 0) AS checkCount,
        COALESCE(SUM(CASE WHEN hwpc.is_compliant = 1 THEN 1 ELSE 0 END), 0) AS checkQualifiedCount,
        COALESCE(ROUND(
        CASE
        WHEN COUNT(*) = 0 THEN 0
        ELSE SUM(CASE WHEN hwpc.is_compliant = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(*)
        END,
        2
        ), 0) AS complianceRatePercent
        FROM
        t_hazard_work_plan_check hwpc
        LEFT JOIN t_hazard_work_plan hwp ON hwpc.plan_id = hwp.id
        WHERE
        hwpc.status = '0'
鲁鸿波's avatar
鲁鸿波 committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
        <if test="param.orgIdList != null and param.orgIdList.size()>0">
            and (
            <foreach item="id" collection="param.orgIdList" separator=" OR ">
                hwpc.basic_id LIKE concat('%', #{id}, '%')
            </foreach>
            )
        </if>
        <if test="param.workType!=null and param.workType!=''">
            and hwp.work_type = #{param.workType}
        </if>
        <if test="param.workLevel!=null and param.workLevel!=''">
            and hwp.work_level = #{param.workLevel}
        </if>
        <if test="param.stakeholderWork!=null and param.stakeholderWork!=''">
            and hwp.stakeholder_work = #{param.stakeholderWork}
        </if>
        <if test="param.startTime != null and param.startTime != ''  and param.endTime != null and param.endTime != ''">
            and hwpc.check_time between #{param.startTime} and #{param.endTime}
        </if>
    </select>

    <select id="selectCheckProblemTypeStatistics" resultType="com.testor.module.hazard.model.vo.HazardWorkPlanCheckProblemTypeStatisticsVO">
        select dd.dict_value problemName,count(*) problemCount
        from  t_sys_dict_data dd
        left join t_hazard_work_plan_check hwpc on hwpc.problem_type = dd.dict_data_id
鲁鸿波's avatar
鲁鸿波 committed
226
        LEFT JOIN t_hazard_work_plan hwp ON hwpc.plan_id = hwp.id
鲁鸿波's avatar
鲁鸿波 committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
        where hwpc.status = '0' AND hwpc.is_compliant = 0 AND hwpc.problem_type IS NOT NULL
        <if test="param.orgIdList != null and param.orgIdList.size()>0">
            and (
            <foreach item="id" collection="param.orgIdList" separator=" OR ">
                hwpc.basic_id LIKE concat('%', #{id}, '%')
            </foreach>
            )
        </if>
        <if test="param.workType!=null and param.workType!=''">
            and hwp.work_type = #{param.workType}
        </if>
        <if test="param.workLevel!=null and param.workLevel!=''">
            and hwp.work_level = #{param.workLevel}
        </if>
        <if test="param.stakeholderWork!=null and param.stakeholderWork!=''">
            and hwp.stakeholder_work = #{param.stakeholderWork}
        </if>
        <if test="param.startTime != null and param.startTime != ''  and param.endTime != null and param.endTime != ''">
            and hwpc.check_time between #{param.startTime} and #{param.endTime}
        </if>
        group by dd.dict_value
    </select>

    <select id="selectCheckProblemCountStatistics" resultType="com.testor.module.hazard.model.vo.HazardWorkPlanCheckProblemCountStatisticsVO">
        SELECT
鲁鸿波's avatar
鲁鸿波 committed
252
        dates.timeStr AS problemDate,
鲁鸿波's avatar
鲁鸿波 committed
253 254 255 256 257 258 259
        COUNT(hwpc.id) AS problemCount
        FROM
        (SELECT generate_series(
        #{param.startTime}::timestamp,
        #{param.endTime}::timestamp,
        '1 day'::interval
        )::date AS timeStr) dates
鲁鸿波's avatar
鲁鸿波 committed
260
        LEFT JOIN t_hazard_work_plan_check hwpc ON hwpc.check_time::date = dates.timeStr
鲁鸿波's avatar
鲁鸿波 committed
261 262 263 264 265 266 267 268 269 270
        AND hwpc.status = '0'
        AND hwpc.is_compliant = 0
        AND hwpc.problem_type IS NOT NULL
        <if test="param.orgIdList != null and param.orgIdList.size()>0">
            and (
            <foreach item="id" collection="param.orgIdList" separator=" OR ">
                hwpc.basic_id LIKE concat('%', #{id}, '%')
            </foreach>
            )
        </if>
鲁鸿波's avatar
鲁鸿波 committed
271 272 273 274
        <if test="param.startTime != null and param.startTime != ''  and param.endTime != null and param.endTime != ''">
            and hwpc.check_time between #{param.startTime} and #{param.endTime}
        </if>
        LEFT JOIN t_hazard_work_plan hwp ON hwpc.plan_id = hwp.id
鲁鸿波's avatar
鲁鸿波 committed
275 276 277 278 279 280 281 282 283
        <if test="param.workType!=null and param.workType!=''">
            and hwp.work_type = #{param.workType}
        </if>
        <if test="param.workLevel!=null and param.workLevel!=''">
            and hwp.work_level = #{param.workLevel}
        </if>
        <if test="param.stakeholderWork!=null and param.stakeholderWork!=''">
            and hwp.stakeholder_work = #{param.stakeholderWork}
        </if>
鲁鸿波's avatar
鲁鸿波 committed
284

鲁鸿波's avatar
鲁鸿波 committed
285 286 287 288 289 290
        GROUP BY
          dates.timeStr
        ORDER BY
          dates.timeStr
    </select>

291
</mapper>