<?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.unis.reserveLayout.modular.qualityInspectionOrg.mapper.QualityInspectionOrgMapper">
    <select id="wholeWarehouseQualityInspectionPage" parameterType="string" resultType="com.unis.reserveLayout.modular.qualityInspectionOrg.entity.QualityInspectionWhole">
        SELECT
            qqi.id,
            qqi.org_id orgId,
            oi.org_name orgName,
            qqi.basic_storehouse_id basicStorehouseId,
            bs.storehouse_name storehouseName,
            qqi.warehouse_id warehouseId,
            bw.warehouse_name warehouseName,
            qqi.grain_variety_id grainVarietyId,
            be.enumname grainVarietyName,
            qqi.grain_nature_id grainNatureId,
            be1.enumname grainNatureName,
            qqi.jysj
        FROM
            depot_qh.business_qc_quality_inspection qqi
        LEFT JOIN depot_qh.org_info oi ON qqi.org_id = oi.org_id
        LEFT JOIN depot_qh.basic_storehouse bs ON qqi.basic_storehouse_id = bs.storehouse_id
        LEFT JOIN depot_qh.basic_warehouse bw ON qqi.warehouse_id = bw.warehouse_id
        LEFT JOIN depot_qh.basic_enum be ON qqi.grain_variety_id = be.enumId
        LEFT JOIN depot_qh.basic_enum be1 ON qqi.grain_nature_id = be1.enumId
        <where>
            <if test="storehouseName != null and storehouseName != ''">
                bs.storehouse_name LIKE CONCAT('%', #{storehouseName}, '%')
            </if>
        </where>
    </select>
    <select id="getQualityInspection" parameterType="integer" resultType="com.unis.reserveLayout.modular.qualityInspectionOrg.entity.QualityInspectionWholeDetail">
        SELECT
            qqi.id,
            qqi.zjbgdh,
            qqi.jylb,
            qqi.org_id orgId,
            oi.org_name orgName,
            oi.address,
            qqi.basic_storehouse_id basicStorehouseId,
            bs.storehouse_name storehouseName,
            qqi.warehouse_id warehouseId,
            bw.warehouse_name warehouseName,
            qqi.grain_variety_id grainVarietyId,
            be.enumname grainVarietyName,
            qqi.grain_nature_id grainNatureId,
            be1.enumname grainNatureName,
            qqi.grain_grade_id grainGradeId,
            be2.enumname grainGradeName,
            kkd.ModifyDate modifyDate,
            kkd.scnf,
            kkd.gb,
            qqi.jydw,
            qqi.jyyj,
            qqi.check_result checkResult,
            qqi.jyr,
            qqi.qfrq,
            qqi.spaqzbsfhg,
            qqi.zblb,
            qqi.zbjgpd,
            qqi.sfzcccnx,
            qqi.qydbh,
            qqi.qyrxm,
            qqi.qyqy,
            qqi.jdrxm,
            qqi.ypbh,
            qqi.ypsl,
            qqi.ypdj,
            qqi.dbsl,
            qqi.sample_status sampleStatus,
            qqi.sample_package_model samplePackageModel,
            qqi.jysj
        FROM
            depot_qh.business_qc_quality_inspection qqi
        LEFT JOIN depot_qh.org_info oi ON qqi.org_id = oi.org_id
        LEFT JOIN depot_qh.basic_storehouse bs ON qqi.basic_storehouse_id = bs.storehouse_id
        LEFT JOIN depot_qh.basic_warehouse bw ON qqi.warehouse_id = bw.warehouse_id
        LEFT JOIN depot_qh.data_kcgl_kcsw_default kkd ON qqi.org_id = kkd.UnitID
        AND qqi.basic_storehouse_id = kkd.ch
        AND qqi.warehouse_id = kkd.hwh
        LEFT JOIN depot_qh.basic_enum be ON qqi.grain_variety_id = be.enumId
        LEFT JOIN depot_qh.basic_enum be1 ON qqi.grain_nature_id = be1.enumId
        LEFT JOIN depot_qh.basic_enum be2 ON qqi.grain_grade_id = be2.enumId
        WHERE
            id = #{qualityId}
    </select>
    <select id="getQualityInspectionItem" parameterType="integer" resultType="com.unis.reserveLayout.modular.qualityInspectionOrg.entity.BusinessQcQualityInspectionItem">
        SELECT
            qii.id,
            qii.qc_quality_inspection_id qcQualityInspectionId,
            qii.parent_inspection_item_id parentInspectionItemId,
            be.enumname parentInspectionItemName,
            qii.inspection_item_id inspectionItemId,
            be1.enumname inspectionItemName,
            qii.inspection_value inspectionValue,
            qii.single_conclusion singleConclusion,
            qii.inspection_method inspectionMethod
        FROM
            depot_qh.business_qc_quality_inspection_item qii
        LEFT JOIN depot_qh.basic_enum be ON qii.parent_inspection_item_id = be.enumId
        LEFT JOIN depot_qh.basic_enum be1 ON qii.parent_inspection_item_id = be1.enumId
        WHERE
            qii.qc_quality_inspection_id = #{qualityId}
    </select>


</mapper>