ShipmentQuantityIndustryStatisticsMapper.xml 9.06 KB
<?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.lframework.xingyun.sc.mappers.ShipmentQuantityIndustryStatisticsMapper">

    <resultMap id="ShipmentQuantityIndustryStatisticsDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto">
        <result column="shipment_date" property="shipmentDate"/>
        <result column="industry" property="industry"/>
        <result column="workshop_id" property="workshopId"/>
        <result column="workshop_code" property="workshopCode"/>
        <result column="workshop_name" property="workshopName"/>
        <result column="shipment_quantity" property="shipmentQuantity"/>
    </resultMap>

    <resultMap id="ShipmentQuantityStatisticsDateRangeDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDateRangeDto">
        <result column="start_date" property="startDate"/>
        <result column="end_date" property="endDate"/>
    </resultMap>

    <resultMap id="ShipmentQuantityIndustryStatisticsInvalidDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsInvalidDto">
        <result column="order_id" property="orderId"/>
        <result column="order_no" property="orderNo"/>
        <result column="line_id" property="lineId"/>
        <result column="shipment_date" property="shipmentDate"/>
        <result column="industry" property="industry"/>
        <result column="workshop_id" property="workshopId"/>
        <result column="quantity" property="quantity"/>
    </resultMap>

    <sql id="ShipmentQuantityIndustryStatistics_base_where">
        o.type = 'PRODUCTION'
        AND o.examine_status = 'PASS'
        AND (o.status IS NULL OR o.status != 'CANCEL')
        AND (ol.del_flag IS NULL OR ol.del_flag = 0)
    </sql>

    <select id="query" resultMap="ShipmentQuantityIndustryStatisticsDto">
        SELECT
            t.shipment_date,
            t.industry,
            t.workshop_id,
            t.workshop_code,
            t.shipment_quantity
        FROM (
            SELECT
                ol.delivery_date AS shipment_date,
                ol.industry AS industry,
                o.workshop_id AS workshop_id,
                ws.code AS workshop_code,
                ws.name AS workshop_name,
                SUM(ol.quantity) AS shipment_quantity
            FROM tbl_purchase_order_line ol
            INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
            LEFT JOIN base_data_workshop ws ON ws.id = o.workshop_id
            WHERE
                <include refid="ShipmentQuantityIndustryStatistics_base_where"/>
                AND ol.delivery_date IS NOT NULL
                AND ol.industry IS NOT NULL AND ol.industry != ''
                AND o.workshop_id IS NOT NULL AND o.workshop_id != ''
                AND ol.quantity IS NOT NULL
                <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''">
                    AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart}
                </if>
                <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''">
                    AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd}
                </if>
                <if test="vo.industry != null and vo.industry != ''">
                    AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
                </if>
                <if test="vo.workshopId != null and vo.workshopId != ''">
                    AND o.workshop_id = #{vo.workshopId}
                </if>
            GROUP BY ol.delivery_date, ol.industry, o.workshop_id
        ) t
        ORDER BY
            t.shipment_date DESC,
            CASE t.workshop_code
                WHEN 'yfc' THEN 1
                WHEN 'efc' THEN 2
                WHEN 'sfc' THEN 3
                WHEN 'ztfc' THEN 4
                ELSE 99
            END,
            t.industry
    </select>

    <select id="queryDateRange" resultMap="ShipmentQuantityStatisticsDateRangeDto">
        SELECT
            MIN(t.shipment_date) AS start_date,
            MAX(t.shipment_date) AS end_date
        FROM (
            SELECT
                ol.delivery_date AS shipment_date,
                o.workshop_id AS workshop_id
            FROM tbl_purchase_order_line ol
            INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
            WHERE
                <include refid="ShipmentQuantityIndustryStatistics_base_where"/>
                AND ol.delivery_date IS NOT NULL
                AND ol.industry IS NOT NULL AND ol.industry != ''
                AND o.workshop_id IS NOT NULL AND o.workshop_id != ''
                AND ol.quantity IS NOT NULL
                <if test="vo.industry != null and vo.industry != ''">
                    AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
                </if>
                <if test="vo.workshopId != null and vo.workshopId != ''">
                    AND o.workshop_id = #{vo.workshopId}
                </if>
        ) t
    </select>

    <select id="queryIndustryDim" resultType="java.lang.String">
        SELECT DISTINCT
            ol.industry AS industry
        FROM tbl_purchase_order_line ol
        INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
        WHERE
            <include refid="ShipmentQuantityIndustryStatistics_base_where"/>
            AND ol.delivery_date IS NOT NULL
            AND ol.industry IS NOT NULL AND ol.industry != ''
            AND o.workshop_id IS NOT NULL AND o.workshop_id != ''
            AND ol.quantity IS NOT NULL
            <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''">
                AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart}
            </if>
            <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''">
                AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd}
            </if>
            <if test="vo.industry != null and vo.industry != ''">
                AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
            </if>
            <if test="vo.workshopId != null and vo.workshopId != ''">
                AND o.workshop_id = #{vo.workshopId}
            </if>
        ORDER BY ol.industry
    </select>

    <select id="queryWorkshopDimByCodes" resultMap="ShipmentQuantityIndustryStatisticsDto">
        SELECT
            w.id AS workshop_id,
            w.code AS workshop_code,
            w.name AS workshop_name
        FROM base_data_workshop w
        WHERE w.code IN
        <foreach collection="codes" item="code" open="(" close=")" separator=",">
            #{code}
        </foreach>
        ORDER BY
            CASE w.code
                WHEN 'yfc' THEN 1
                WHEN 'efc' THEN 2
                WHEN 'sfc' THEN 3
                WHEN 'ztfc' THEN 4
                ELSE 99
            END,
            w.name
    </select>

    <select id="queryWorkshopDimById" resultMap="ShipmentQuantityIndustryStatisticsDto">
        SELECT
            w.id AS workshop_id,
            w.code AS workshop_code,
            w.name AS workshop_name
        FROM base_data_workshop w
        WHERE w.id = #{workshopId}
    </select>

    <select id="queryInvalid" resultMap="ShipmentQuantityIndustryStatisticsInvalidDto">
        SELECT
            t.order_id,
            t.order_no,
            t.line_id,
            t.shipment_date,
            t.industry,
            t.workshop_id,
            t.quantity
        FROM (
            SELECT
                o.id AS order_id,
                o.order_no AS order_no,
                ol.id AS line_id,
                ol.delivery_date AS shipment_date,
                ol.industry AS industry,
                o.workshop_id AS workshop_id,
                ol.quantity AS quantity,
                o.create_time AS create_time
            FROM tbl_purchase_order_line ol
            INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
            WHERE
                <include refid="ShipmentQuantityIndustryStatistics_base_where"/>
                AND (
                    ol.delivery_date IS NULL
                    OR ol.industry IS NULL OR ol.industry = ''
                    OR o.workshop_id IS NULL OR o.workshop_id = ''
                    OR ol.quantity IS NULL
                )
                <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''">
                    AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart})
                </if>
                <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''">
                    AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd})
                </if>
                <if test="vo.industry != null and vo.industry != ''">
                    AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
                </if>
                <if test="vo.workshopId != null and vo.workshopId != ''">
                    AND o.workshop_id = #{vo.workshopId}
                </if>
        ) t
        ORDER BY t.create_time DESC
        LIMIT 200
    </select>
</mapper>