97 lines
3.5 KiB
XML
97 lines
3.5 KiB
XML
<?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.klp.erp.mapper.PurchaseRequirementCalcMapper">
|
|
|
|
<resultMap id="ProductDemandMap" type="com.klp.erp.domain.dto.ProductDemandDTO">
|
|
<result property="productId" column="product_id"/>
|
|
<result property="demandQuantity" column="demand_quantity"/>
|
|
</resultMap>
|
|
|
|
<resultMap id="ProductStockMap" type="com.klp.erp.domain.dto.ProductStockDTO">
|
|
<result property="productId" column="product_id"/>
|
|
<result property="coilCount" column="coil_count"/>
|
|
<result property="totalWeight" column="total_weight"/>
|
|
</resultMap>
|
|
|
|
<resultMap id="RawStockMap" type="com.klp.erp.domain.dto.RawStockDTO">
|
|
<result property="rawMaterialId" column="raw_material_id"/>
|
|
<result property="coilCount" column="coil_count"/>
|
|
<result property="totalWeight" column="total_weight"/>
|
|
</resultMap>
|
|
|
|
<resultMap id="RawTransitMap" type="com.klp.erp.domain.dto.RawTransitDTO">
|
|
<result property="rawMaterialId" column="raw_material_id"/>
|
|
<result property="quantity" column="quantity"/>
|
|
</resultMap>
|
|
|
|
<select id="selectProductDemand" resultMap="ProductDemandMap">
|
|
SELECT
|
|
od.product_id,
|
|
COALESCE(SUM(od.quantity), 0) AS demand_quantity
|
|
FROM wms_order_detail od
|
|
JOIN wms_order o ON od.order_id = o.order_id
|
|
WHERE o.del_flag = 0
|
|
AND od.del_flag = 0
|
|
AND o.order_status IN (0, 1)
|
|
GROUP BY od.product_id
|
|
</select>
|
|
|
|
<select id="selectProductStock" resultMap="ProductStockMap">
|
|
SELECT
|
|
item_id AS product_id,
|
|
COUNT(*) AS coil_count,
|
|
COALESCE(SUM(net_weight), 0) AS total_weight
|
|
FROM wms_material_coil
|
|
WHERE del_flag = 0
|
|
AND status = 0
|
|
AND data_type = 0
|
|
AND item_type = 'product'
|
|
AND (material_type IS NULL OR material_type != '废品')
|
|
GROUP BY item_id
|
|
</select>
|
|
|
|
<select id="selectRawStock" resultMap="RawStockMap">
|
|
SELECT
|
|
item_id AS raw_material_id,
|
|
COUNT(*) AS coil_count,
|
|
COALESCE(SUM(net_weight), 0) AS total_weight
|
|
FROM wms_material_coil
|
|
WHERE del_flag = 0
|
|
AND status = 0
|
|
AND data_type = 0
|
|
AND item_type = 'raw_material'
|
|
AND (material_type IS NULL OR material_type != '废品')
|
|
GROUP BY item_id
|
|
</select>
|
|
|
|
<sql id="PurchaseOrderJoin">
|
|
FROM erp_purchase_order_item poi
|
|
JOIN erp_purchase_order po ON poi.order_id = po.order_id
|
|
LEFT JOIN wms_raw_material rm ON rm.raw_material_code = poi.material_type_code
|
|
WHERE poi.del_flag = 0
|
|
AND po.del_flag = 0
|
|
AND rm.raw_material_id IS NOT NULL
|
|
</sql>
|
|
|
|
<select id="selectRawInTransit" resultMap="RawTransitMap">
|
|
SELECT
|
|
rm.raw_material_id,
|
|
COALESCE(SUM(poi.quantity), 0) AS quantity
|
|
<include refid="PurchaseOrderJoin"/>
|
|
AND po.order_status = 1
|
|
GROUP BY rm.raw_material_id
|
|
</select>
|
|
|
|
<select id="selectRawPending" resultMap="RawTransitMap">
|
|
SELECT
|
|
rm.raw_material_id,
|
|
COALESCE(SUM(poi.quantity), 0) AS quantity
|
|
<include refid="PurchaseOrderJoin"/>
|
|
AND po.order_status = 0
|
|
GROUP BY rm.raw_material_id
|
|
</select>
|
|
</mapper>
|
|
|