<?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.chushang.inspection.project.mapper.InspectionDataMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="inspectionConfigVOResult" type="com.chushang.inspection.work.vo.InspectionConfigVO">
        <id column="config_id" property="configId"/>
        <result column="config_name" property="configName"/>
        <result column="alias" property="alias"/>
        <result column="template" property="template"/>
        <result column="template_url" property="templateUrl"/>
        <result column="template_fid" property="templateFid"/>
        <collection property="details" ofType="com.chushang.inspection.work.vo.ConfigDataVO">
            <id column="data_id" property="dataId"/>
            <result column="detail_id" property="detailId"/>
            <result column="config_key" property="configKey"/>
            <result column="config_type" property="configType"/>
            <result column="config_label" property="configLabel"/>
            <result column="config_value" property="configValue"/>
            <result column="finalResult" property="finalResult"/>
            <result column="middleResult" property="middleResult"/>
            <result column="remark" property="remark"/>
            <result column="ins_id" property="wrkId"/>
        </collection>
    </resultMap>

    <select id="listInspectionsByWrkId" resultMap="inspectionConfigVOResult">
        <include refid="listInspectionsSql"/>
        AND id.ins_id = #{wrkId}
        <if test="true">
            ${query.sqlParam.get('dataScope')}
        </if>
    </select>
    <select id="listInspectionsByWrkIds" resultMap="inspectionConfigVOResult">
        <include refid="listInspectionsSql"/>
        AND id.ins_id IN
        <foreach collection="wrkIds" separator="," close=")" open="(" item="wrkId">
            #{wrkId}
        </foreach>
        <if test="true">
            ${query.sqlParam.get('dataScope')}
        </if>
    </select>
    <sql id="listInspectionsSql">
        SELECT id.data_id,
               id.config_value,
               id.remark,
               id.ins_id,
               id.result AS finalResult,
               idl.detail_id,
               idl.config_key,
               idl.config_type,
               idl.config_label,
               idl.result AS middleResult,
               ic.config_id,
               ic.template,
               ic.alias,
               ic.config_name,
               ic.template_url,
               ic.template_fid
        FROM inspection_data id
                 INNER JOIN inspection_detail idl ON id.detail_id = idl.detail_id
                 INNER JOIN inspection_config ic ON ic.config_id = idl.config_id
        WHERE id.del_state = 0
    </sql>
</mapper>
