ShipmentsPlanDetailMapper.xml 11.8 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.ShipmentsPlanDetailMapper">

    <resultMap id="ShipmentsPlanDetail" type="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail">
        <id column="id" property="id"/>
        <result column="plan_id" property="planId"/>
        <result column="shipment_order_id" property="shipmentOrderId"/>
        <result column="order_id" property="orderId"/>
        <result column="order_no" property="orderNo"/>
        <result column="contract_type" property="contractType"/>
        <result column="order_type" property="orderType"/>
        <result column="customer_id" property="customerId"/>
        <result column="customer_name" property="customerName"/>
        <result column="thickness" property="thickness"/>
        <result column="thickness_tol_pos" property="thicknessTolPos"/>
        <result column="thickness_tol_neg" property="thicknessTolNeg"/>
        <result column="width" property="width"/>
        <result column="width_tol_pos" property="widthTolPos"/>
        <result column="width_tol_neg" property="widthTolNeg"/>
        <result column="length" property="length"/>
        <result column="length_tol_pos" property="lengthTolPos"/>
        <result column="length_tol_neg" property="lengthTolNeg"/>
        <result column="parent_id" property="parentId"/>
        <result column="status" property="status"/>
        <result column="shipments_date" property="shipmentsDate"/>
        <result column="shipments_time" property="shipmentsTime"/>
        <result column="can_shipments" property="canShipments"/>
        <result column="del_flag" property="delFlag"/>
        <result column="create_by_id" property="createById"/>
        <result column="update_by_id" property="updateById"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="ShipmentsPlanDetail_sql">
        SELECT
            tb.id,
            tb.plan_id,
            tb.shipment_order_id,
            tb.order_id,
            o.order_no,
            s.type as contract_type,
            CASE
                WHEN s.type IN ('DISTRIB_STD', 'DIST_STOCK_CONTRACT', 'DRAFT_DIST_AGMT') THEN '经销'
                WHEN s.type IN ('INTL_STD_CONTRACT', 'INTL_INVENTORY_AGMT', 'INTL_OPEN_SPEC_AGMT') THEN '外贸'
                WHEN s.type = 'PROCESS_STD_AGMT' THEN '加工'
                ELSE '其它'
                END AS order_type,
            o.ordering_unit AS customer_id,
            ol.packaging_fee,
            o.shipping_cost,
            c.name AS customer_name,
            tb.order_spec_id,
            ol.brand,
            ol.thickness,
            ol.thickness_tol_pos,
            ol.thickness_tol_neg,
            ol.width,
            ol.width_tol_pos,
            ol.width_tol_neg,
            ol.length,
            ol.length_tol_pos,
            ol.length_tol_neg,
            ol.quantity,
            ol.sales_price,
            ol.status,
            tb.parent_id,
            tb.shipments_date,
            tb.shipments_time,
            tb.can_shipments,
            tb.actual_shipment_quantity,
            tb.num,
            tb.yield_batch_no,
            tb.del_flag,
            ws.name AS workshop_name,
            tb.create_by_id,
            tb.update_by_id,
            tb.create_time,
            tb.update_time
        FROM shipments_plan_detail AS tb
        INNER JOIN shipments_plan p ON tb.plan_id = p.id
        LEFT JOIN purchase_order_info o ON tb.order_id = o.id
        LEFT JOIN base_data_customer c ON o.ordering_unit = c.id
        LEFT JOIN tbl_purchase_order_line ol ON tb.order_spec_id = ol.id
        LEFT JOIN tbl_contract_distributor_standard s on s.id = o.contract_id
        LEFT JOIN base_data_workshop ws on ws.id = o.workshop_id
    </sql>

    <select id="query" resultMap="ShipmentsPlanDetail">
        <include refid="ShipmentsPlanDetail_sql"/>
        <where>
            and tb.del_flag = false
            <if test="vo.planId != null and vo.planId != ''">
                AND tb.plan_id = #{vo.planId}
            </if>
            <if test="vo.shipmentsOrderId != null and vo.shipmentsOrderId != ''">
                AND tb.shipment_order_id = #{vo.shipmentsOrderId}
            </if>
            <if test="vo.orderId != null and vo.orderId != ''">
                AND tb.order_id = #{vo.orderId}
            </if>
            <if test="vo.shipmentsDate != null">
                AND tb.shipments_date = #{vo.shipmentsDate}
            </if>
            <if test="vo.ids != null and vo.ids.size() > 0">
                AND tb.id in
                <foreach collection="vo.ids" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="vo.orderSpecIds != null and vo.orderSpecIds.size() > 0">
                AND ol.id IN
                <foreach collection="vo.orderSpecIds" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="vo.completed != null">
                <choose>
                    <when test="vo.completed == true">
                        AND tb.shipment_order_id IS NOT NULL AND tb.shipment_order_id != ''
                    </when>
                    <otherwise>
                        AND (tb.shipment_order_id IS NULL OR tb.shipment_order_id = '')
                    </otherwise>
                </choose>
            </if>
        </where>
        ORDER BY tb.create_time desc
    </select>

    <insert id="batchAdd">
        INSERT INTO shipments_plan_detail (
        id,
        plan_id,
        shipment_order_id,
        order_id,
        order_spec_id,
        parent_id,
        status,
        shipments_date,
        shipments_time,
        pre_shipments,
        can_shipments,
        del_flag,
        create_by_id,
        update_by_id,
        create_time,
        update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id},
            #{item.planId},
            #{item.shipmentOrderId},
            #{item.orderId},
            #{item.orderSpecId},
            #{item.parentId},
            #{item.status},
            #{item.shipmentsDate},
            #{item.shipmentsTime},
            #{item.preShipments},
            #{item.canShipments},
            #{item.delFlag},
            #{item.createById},
            #{item.updateById},
            #{item.createTime},
            #{item.updateTime}
            )
        </foreach>
    </insert>

    <select id="queryCanShipmentsData" resultType="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail">
        select
            ol.id,
            o.id as order_id,
            o.order_no,
            c.name AS customer_name,
            ol.thickness,
            ol.thickness_tol_pos,
            ol.thickness_tol_neg,
            ol.width,
            ol.width_tol_pos,
            ol.width_tol_neg,
            ol.length,
            ol.length_tol_pos,
            ol.length_tol_neg,
            ol.quantity
        from tbl_purchase_order_line ol
        inner join purchase_order_info o on ol.purchase_order_id = o.id
        left join base_data_customer c on o.ordering_unit = c.id
        where ol.delivery_date >= #{vo.shipmentDate} and ol.del_flag = false
        and o.type = 'PRODUCTION' and o.examine_status = 'PASS' and o.status not in ('SHIPPED', 'DELIVERED', 'CANCEL')
        and (o.revoke_status != 'UNDOING' or o.revoke_status is null)
        and (o.spec_change_status != 'IN_PROGRESS' or o.spec_change_status is null)
        <if test="vo.workshopId != null and vo.workshopId != ''">
            AND o.workshop_id = #{vo.workshopId}
        </if>
        <if test="vo.orderSpecIds != null and vo.orderSpecIds.size() > 0">
            and ol.id not in
            <foreach collection="vo.orderSpecIds" open="(" separator="," close=")" item="item">
                #{item}
            </foreach>
        </if>
        <if test="vo.orderNo != null and vo.orderNo != ''">
            AND o.order_no like concat('%', #{vo.orderNo}, '%')
        </if>
        <if test="vo.customerName != null and vo.customerName != ''">
            AND c.name like concat('%', #{vo.customerName}, '%')
        </if>
    </select>

    <select id="listByShipmentOrderId" resultType="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail">
        SELECT
            tb.id,
            tb.plan_id,
            tb.shipment_order_id,
            tb.order_id,
            o.order_no,
            o.ordering_unit AS customer_id,
            o.delivery_method,
            o.settlement_terms,
            ol.packaging_fee,
            o.shipping_cost,
            sc.type as contract_type,
            CASE
                WHEN sc.type IN ('DISTRIB_STD', 'DIST_STOCK_CONTRACT', 'DRAFT_DIST_AGMT') THEN '经销'
                WHEN sc.type IN ('INTL_STD_CONTRACT', 'INTL_INVENTORY_AGMT', 'INTL_OPEN_SPEC_AGMT') THEN '外贸'
                WHEN sc.type = 'PROCESS_STD_AGMT' THEN '加工'
            ELSE '其它'
            END AS order_type,
            c.name AS customer_name,
            tb.order_spec_id,
            ol.brand,
            ol.thickness,
            ol.thickness_tol_pos,
            ol.thickness_tol_neg,
            ol.width,
            ol.width_tol_pos,
            ol.width_tol_neg,
            ol.length,
            ol.length_tol_pos,
            ol.length_tol_neg,
            ol.quantity,
            ol.sales_price,
            ol.status,
            tb.parent_id,
            tb.shipments_date,
            tb.shipments_time,
            tb.can_shipments,
            tb.actual_shipment_quantity,
            tb.num,
            tb.yield_batch_no,
            tb.del_flag,
            tb.create_by_id,
            tb.update_by_id,
            tb.create_time,
            tb.update_time
        FROM shipments_plan_detail AS tb
        INNER JOIN shipments_order_info so ON tb.shipment_order_id = so.id
        LEFT JOIN purchase_order_info o ON tb.order_id = o.id
        LEFT JOIN tbl_contract_distributor_standard sc ON o.contract_id = sc.id
        LEFT JOIN base_data_customer c ON o.ordering_unit = c.id
        LEFT JOIN tbl_purchase_order_line ol ON tb.order_spec_id = ol.id
        WHERE tb.del_flag = false
        AND tb.shipment_order_id in
        <foreach collection="shipmentOrderIds" open="(" separator="," close=")" item="item">
            #{item}
        </foreach>
    </select>

    <select id="listByPlanId" resultType="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail">
        select
            pd.*,
            ol.quantity,
            c.id as customer_id
        from shipments_plan_detail pd
        <if test="includePreShipment == true">
            inner join shipments_plan p on pd.plan_id = p.id
        </if>
        <if test="includePreShipment == false">
            inner join shipments_plan p on pd.plan_id = p.id and pd.shipments_date = p.tomo_pre_ship_date
        </if>
        left join tbl_purchase_order_line ol on pd.order_spec_id = ol.id
        left join purchase_order_info o on pd.order_id = o.id
        left join base_data_customer c on o.ordering_unit = c.id
        where pd.del_flag = false
        and pd.plan_id = #{planId}
    </select>

    <select id="findById" resultType="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail">
        <include refid="ShipmentsPlanDetail_sql"/>
        <where>
            <if test="id != null and id != ''">
                AND tb.id = #{id}
            </if>
        </where>
    </select>

    <select id="getExistsOrderSpecIds" resultType="java.lang.String">
        select distinct tb.order_spec_id
        from shipments_plan_detail tb
        where tb.pre_shipments = false or (tb.pre_shipments = true and tb.shipments_date = #{shipmentsDate})
    </select>
</mapper>