<?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.QualityInspectionMapper">
    <select id="pageList" parameterType="string" resultType="com.unis.reserveLayout.modular.qualityInspectionOrg.entity.BusinessQcQualityInspection">
        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.jysj,
            qqi.grain_variety_id grainVarietyId,
            be.enumname grainVarietyName,
            qqi.grain_nature_id grainNatureId,
            be1.enumname grainNatureName
        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.org_id = bs.org_id
        AND qqi.basic_storehouse_id = bs.storehouse_id
        LEFT JOIN depot_qh.basic_warehouse bw ON qqi.org_id = bw.org_id
        AND qqi.warehouse_id = bw.warehouse_id
        AND qqi.basic_storehouse_id = bs.storehouse_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="selectOnly" parameterType="map" resultType="string">
        SELECT
          zjbgdh
        FROM
          business_qc_quality_inspection
        <where>
            <if test="orgId != null and orgId != ''">
                org_id = #{orgId}
            </if>
            <if test="basicStorehouseId != null and basicStorehouseId != ''">
                and basic_storehouse_id = #{basicStorehouseId}
            </if>
            <if test="warehouseId != null and warehouseId != ''">
                and warehouse_id = #{warehouseId}
            </if>
        </where>
        ORDER BY createdate DESC
        LIMIT 1
    </select>
    <select id="reportPageList" resultType="com.unis.reserveLayout.modular.qualityInspectionOrg.entity.BusinessQcQualityInspection">
        SELECT
            qqi.id,
            qqi.jydw,
            qqi.org_id orgId,
            oi.org_name orgName,
            qqi.basic_storehouse_id basicStorehouseId,
            bs.storehouse_name storeHouseName,
            qqi.check_result checkResult,
            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.org_id = bs.org_id
        AND qqi.basic_storehouse_id = bs.storehouse_id
        <where>
            <if test="pageParam.jydw != null and pageParam.jydw != ''">
                qqi.jydw LIKE CONCAT("%", #{pageParam.jydw}, "%")
            </if>
            <if test="pageParam.checkResult != null and pageParam.checkResult != ''">
                AND qqi.check_result = #{pageParam.checkResult}
            </if>
            <if test="pageParam.jysjStart != null and pageParam.jysjEnd != null">
                AND qqi.jysj BETWEEN #{pageParam.jysjStart}
                AND #{pageParam.jysjEnd}
            </if>
        </where>
    </select>
</mapper>