<?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.rotationPlan.info.modular.rpWarnThreshold.mapper.RpWarnThresholdMapper">

    <select id="getReportsInfo" resultType="java.util.Map">
     SELECT DISTINCT
        c.id AS "id",
		b.org_id as "orgId",
        c.rp_report_id AS "rpReportId",
        a.unit_info_id AS "unitInfoId"
    FROM
        depot_qh.business_rp_report a
		LEFT JOIN depot_qh.business_rp_outbound b ON a.id = b.rp_report_id
    LEFT JOIN biz_rp_issuance c ON a.id = c.rp_report_id
    WHERE
        c.issuance_date IS NULL
    AND DATE_FORMAT(NOW(), "%Y-%m-%d") BETWEEN c.start_date AND c.end_date
    </select>
    <select id="getReportsInfoByIssuanceId" resultType="java.util.Map">
     SELECT
	c.id as "id",
	c.rp_report_id as "rpReportId",
	b.id as "outId",
	b.plan_quantity as "jhcksl",
	b.org_id AS "orgId",
	b.warehouse_id as "hwid",
	b.grain_variety_id as "lspzId",
	b.grain_nature_id as "lsxpzId",
	a.unit_info_id AS "unitInfoId"
    FROM
        depot_qh.business_rp_report a
    LEFT JOIN depot_qh.business_rp_outbound b ON a.id = b.rp_report_id
    LEFT JOIN biz_rp_issuance c on a.id = c.rp_report_id
    WHERE
	c.id = #{id}
    </select>

    <select id="getSealingRecord" resultType="java.util.Map">
          SELECT
            ywrq
        FROM
            warehouse_sealing_record
        WHERE
            tyajbm = #{hwid}
        AND lspzdm = #{lspzId}
        AND lsxzdm = #{lsxzId}
        -- and DATE_FORMAT(createdate,'%Y') = DATE_FORMAT(NOW(),'%Y')
        ORDER BY
        ywrq DESC
    LIMIT 1
    </select>
    <select id="getFristCarDate" resultType="java.util.Map">
        SELECT
	 DATE_FORMAT(rq, '%Y-%m-%d %T')  as 'fristCarDate'
    FROM
        depot_qh.data_kcgl_fcbgz_default a
    INNER JOIN depot_qh.data_crkyw_ckcmz_default b ON a.DataID = b.DataID
     INNER JOIN depot_qh.data_crkyw_ckrmdj_default c ON b.bizno = c.bizno
    WHERE
        a.hwh =  #{hwid}
    AND a.pz =  #{lspzId}
    AND a.hwxz = #{lsxzId}
    AND DATE_FORMAT(rq, '%Y-%m-%d') &gt;  #{fcrq}
    ORDER BY rq LIMIT 1

    </select>
    <select id="getCkslSum" resultType="java.util.Map">
        SELECT
	 IFNULL(sum(a.zcsl),0.0) as "cksl"
    FROM
        depot_qh.data_kcgl_fcbgz_default a
    INNER JOIN depot_qh.data_crkyw_ckcmz_default b ON a.DataID = b.DataID
    INNER JOIN depot_qh.data_crkyw_ckrmdj_default c ON b.bizno = c.bizno
    WHERE
        a.hwh in  (%{hwid})
    AND a.unitId =  #{orgId}
    AND DATE_FORMAT(rq, '%Y-%m-%d') &gt;  #{fristCarDate}
    </select>

    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT
        CAST(c.plan_year as char) as 'planYear',
        e.dwmc as "dwmc",
        d.org_name as "orgName",
        a.actual_rotation_quantity as "actualRotationQuantity",
        a.rotation_quantity_percentage as "rotationQuantityPercentage",
        a.should_rotation_quantity_percentage as "shouldRotationQuantityPercentage",
        DATE_FORMAT(a.warning_time,'%Y-%m-%d %T') as 'warningTime'
        FROM
        biz_rp_warn_threshold a
        LEFT JOIN biz_rp_issuance b ON a.rp_issuance_id = b.id
        LEFT JOIN depot_qh.business_rp_report c ON c.id = b.rp_report_id
        LEFT JOIN depot_qh.org_info d on a.org_id = d.org_id
        LEFT JOIN biz_unit_info e on c.unit_info_id = e.id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where ${ew.sqlSegment}
        </if>
        order by a.warning_time desc
    </select>
</mapper>