<?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.grainInspectionArchive.mapper.GrainInspectionArchiveMapper">
    <select id="selectOnly" resultType="string">
        SELECT
            archive_number archiveNumber
        FROM
            biz_rlgi_grain_inspection_archive
        ORDER BY
            id DESC
        LIMIT 1
    </select>
    <select id="getDetailInfo" parameterType="map" resultType="com.unis.reserveLayout.modular.grainInspectionArchive.param.GrainInspectionInfoParam">
        SELECT
            bs.storehouse_id storehouseId,
            bs.storehouse_type storehouseType,
            be.enumname storehouseTypeName,
            kkd.pz grainVarietyId,
            tld.food_variety_name foodVarietyName,
            tld.temp_max tempMax,
            tld.temp_min tempMin,
            tld.temp_avg tempAvg
        FROM
            depot_qh.basic_storehouse bs
        LEFT JOIN depot_qh.basic_enum be ON bs.storehouse_type = be.enumId
        LEFT JOIN depot_qh.t_lq_data tld ON bs.org_id = tld.org_id
        AND bs.storehouse_code = tld.storehouse_code
        LEFT JOIN depot_qh.data_kcgl_kcsw_default kkd ON kkd.UnitID = bs.org_id
        AND kkd.ch = bs.storehouse_id
        WHERE
            iLq_yq = '0'
        AND bs.org_id = #{orgId}
        AND bs.storehouse_id = #{storehouseId}
        AND tld.gather_time BETWEEN #{startTime} AND #{endTime}
        ORDER BY tld.gather_time DESC
    </select>
    <select id="pageList" parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper" resultType="com.unis.reserveLayout.modular.grainInspectionArchive.entity.GrainInspectionArchive">
        SELECT
            gia.id,
            gia.org_id orgId,
            gia.basic_storehouse_id basicStorehouseId,
            gia.warehouse_id warehouseId,
            gia.storehouse_type storehouseType,
            be.enumname storehouseTypeName,
            gia.archive_number archiveNumber,
            gia.report_type reportType,
            CASE
        WHEN gia.report_type = 1 THEN
            '日报'
        WHEN gia.report_type = 2 THEN
            '周报'
        WHEN gia.report_type = 3 THEN
            '月报'
        WHEN gia.report_type = 4 THEN
            '季报'
        WHEN gia.report_type = 5 THEN
            '年报'
        ELSE
            ''
        END AS reportTypeName,
         gia.maximum_temperature maximumTemperature,
         gia.minimum_temperature minimumTemperature,
         gia.average_temperature averageTemperature,
         oi.org_name orgName,
         bs.storehouse_name storehouseName
        FROM
            biz_rlgi_grain_inspection_archive gia
        LEFT JOIN depot_qh.org_info oi ON gia.org_id = oi.org_id
        LEFT JOIN depot_qh.basic_storehouse bs ON gia.org_id = bs.org_id
        AND gia.basic_storehouse_id = bs.storehouse_id
        LEFT JOIN depot_qh.basic_enum be ON gia.storehouse_type = be.enumId
        ${ew.customSqlSegment}
    </select>
</mapper>