<?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.jly.mapper.CheckItemsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jly.entity.CheckItems">
<!--        <id column="id" property="id"/>-->
<!--        <result column="check_plan_id" property="checkPlanId"/>-->
<!--        <result column="check_item" property="checkItem"/>-->
<!--        <result column="check_name" property="checkName"/>-->
<!--        <result column="check_result" property="checkResult"/>-->
<!--        <result column="comment" property="comment"/>-->
<!--        <result column="epc" property="epc"/>-->
<!--        <result column="check_clause" property="checkClause"/>-->
<!--        <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="require" property="require" />-->
    </resultMap>

    <select id="getCheckItemsForReport" resultType="java.util.HashMap">
        SELECT o.id AS id, o.check_plan_id AS checkPlanId,o.check_item AS checkItem,o.check_result AS checkResult,o.comment,o.epc,o.check_clause AS checkClause,t1.total AS accord,
        o.non_code AS nonCode ,o.non_case AS nonCase,o.non_req AS nonReq,
        t2.total AS notAccord,t3.total AS inapplicability,t4.total AS survey,t5.total
         FROM check_items o
        LEFT JOIN (SELECT COUNT(*) AS total,check_plan_id FROM check_items WHERE check_plan_id = #{checkPlanId} AND epc = #{epc} AND check_result = 1 AND del_flag = "1") t1 ON o.check_plan_id = t1.check_plan_id
        LEFT JOIN (SELECT COUNT(*) AS total,check_plan_id FROM check_items WHERE check_plan_id = #{checkPlanId} AND epc = #{epc} AND check_result = 2 AND del_flag = "1") t2 ON o.check_plan_id = t2.check_plan_id
        LEFT JOIN (SELECT COUNT(*) AS total,check_plan_id FROM check_items WHERE check_plan_id = #{checkPlanId} AND epc = #{epc} AND check_result = 3 AND del_flag = "1") t3 ON o.check_plan_id = t3.check_plan_id
        LEFT JOIN (SELECT COUNT(*) AS total,check_plan_id FROM check_items WHERE check_plan_id = #{checkPlanId} AND epc = #{epc} AND check_result = 4 AND del_flag = "1") t4 ON o.check_plan_id = t4.check_plan_id
        LEFT JOIN (SELECT COUNT(*) AS total,check_plan_id FROM check_items WHERE check_plan_id = #{checkPlanId} AND epc = #{epc} AND del_flag = "1") t5 ON o.check_plan_id = t5.check_plan_id
        WHERE o.epc = #{epc} AND o.check_plan_id = #{checkPlanId}
        AND o.check_result = #{checkResult} ORDER BY o.check_item
    </select>
    <select id="queryItems" resultType="com.nantian.cloud.jly.entity.CheckItems">
        SELECT o.check_plan_id,
        o.id,
        o.check_item,
        o.check_result,
        o.comment,
        o.abarbeitung,
        i.check_name,
        o.serial
        FROM check_items o
        LEFT JOIN examination_clause i ON o.check_item = i.check_item
        WHERE o.check_plan_id = #{checkPlanId} and o.epc = #{epc}
    </select>
    <select id="getNoN" resultType="java.util.Map">
        SELECT o.check_plan_id,
        o.id,
        o.check_item,
        o.check_result,
        o.comment,
        o.abarbeitung,
        o.epc,
        i.check_name
        FROM check_items o
        LEFT JOIN examination_clause i ON o.check_item = i.check_item
        WHERE o.check_plan_id = #{checkPlanId} and o.epc in (
        <foreach collection="epcList" item="epcList" separator=",">
            #{epcList}
        </foreach>
        )
    </select>


</mapper>
