112 lines
4.6 KiB
XML
112 lines
4.6 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.niuan.erp.module.production.mapper.ProductionPlanMapper">
|
||
|
||
<!-- 通用查询映射结果 -->
|
||
<resultMap id="BaseResultMap" type="com.niuan.erp.module.production.entity.ProductionPlan">
|
||
<id column="Id" property="id" />
|
||
<result column="Status" property="status" />
|
||
<result column="CreateDate" property="createDate" />
|
||
<result column="CreateUserId" property="createUserId" />
|
||
<result column="CreateUserName" property="createUserName" />
|
||
<result column="UpdateDate" property="updateDate" />
|
||
<result column="UpdateUserId" property="updateUserId" />
|
||
<result column="UpdateUserName" property="updateUserName" />
|
||
<result column="ProductionNum" property="productionNum" />
|
||
<result column="ProjectName" property="projectName" />
|
||
<result column="ProjectId" property="projectId" />
|
||
<result column="ProductionCount" property="productionCount" />
|
||
<result column="ProductionStatus" property="productionStatus" />
|
||
<result column="ProductionNote" property="productionNote" />
|
||
<result column="ProductionReport" property="productionReport" />
|
||
<result column="ProductionMark" property="productionMark" />
|
||
<result column="reserve1" property="reserve1" />
|
||
<result column="reserve2" property="reserve2" />
|
||
<result column="StoreNo" property="storeNo" />
|
||
<result column="StoreName" property="storeName" />
|
||
<result column="GroupId" property="groupId" />
|
||
<result column="GroupName" property="groupName" />
|
||
<result column="CustomerId" property="customerId" />
|
||
</resultMap>
|
||
|
||
<select id="getProductionPlanRequiredQtyList" resultType="ProductionPlanShortageDto">
|
||
SELECT b.Id AS id, b.PartNumber AS partNumber, MAX(pro.ProductSpecs) AS productSpecs,
|
||
SUM(p.ProductionCount * b.ManufactureCount) AS requiredQty, COALESCE(MAX(s.ProductCount), 0) AS stockQty,
|
||
NULL AS diffQty
|
||
FROM produceorder p
|
||
INNER JOIN bom b ON p.ProjectId = b.BomId
|
||
INNER JOIN product pro ON b.PartNumber = pro.PartNumber
|
||
LEFT JOIN storagecount s ON s.PartNumber = pro.PartNumber
|
||
<if test="warehouseId != null">
|
||
AND s.StoreNo = #{warehouseId}
|
||
</if>
|
||
<where>
|
||
p.Id IN
|
||
<foreach item="id" collection="ids" open="(" separator="," close=")">
|
||
#{id}
|
||
</foreach>
|
||
</where>
|
||
GROUP BY b.Id, b.PartNumber, pro.ProductSpecs
|
||
</select>
|
||
|
||
|
||
|
||
|
||
<select id="selectProduceOrderData" resultType="ProduceOrderList">
|
||
SELECT
|
||
d.Id,
|
||
d.PartNumber AS Partnumber,
|
||
d.ProductSpecs AS Productspecs,
|
||
a.StoreNo,
|
||
b.SameUseCount,
|
||
b.SameUseNum1 AS SameNum1,
|
||
b.SameUseNum2 AS SameNum2,
|
||
b.SameUseNum3 AS SameNum3,
|
||
b.ManufactureCount AS BomTotal,
|
||
a.ProductionCount AS OrderTotal,
|
||
|
||
<!-- 1. 主料库存 -->
|
||
COALESCE(f_main.ProductCount, 0) AS MainStock,
|
||
|
||
<!-- 2. 替换料1库存 (根据 SameNum1 关联) -->
|
||
COALESCE(f_sub1.ProductCount, 0) AS Sub1Stock,
|
||
|
||
<!-- 3. 替换料2库存 (根据 SameNum2 关联) -->
|
||
COALESCE(f_sub2.ProductCount, 0) AS Sub2Stock,
|
||
|
||
<!-- 4. 替换料3库存 (根据 SameNum3 关联) -->
|
||
COALESCE(f_sub3.ProductCount, 0) AS Sub3Stock,
|
||
|
||
<!-- 占用数量 (示例设为0,实际请根据表结构补充) -->
|
||
0 AS OccupyTotal
|
||
|
||
FROM produceorder a
|
||
INNER JOIN bom b ON a.ProjectId = b.BomId
|
||
INNER JOIN product d ON b.PartNumber = d.PartNumber AND d.CustomerId = a.CustomerId
|
||
|
||
<!-- 关联主料库存 -->
|
||
LEFT JOIN storagecount f_main
|
||
ON a.StoreNo = f_main.StoreNo AND b.PartNumber = f_main.PartNumber
|
||
|
||
<!-- 关联替换料1库存 -->
|
||
LEFT JOIN storagecount f_sub1
|
||
ON a.StoreNo = f_sub1.StoreNo AND b.SameUseNum1 = f_sub1.PartNumber
|
||
|
||
<!-- 关联替换料2库存 -->
|
||
LEFT JOIN storagecount f_sub2
|
||
ON a.StoreNo = f_sub2.StoreNo AND b.SameUseNum2 = f_sub2.PartNumber
|
||
|
||
<!-- 关联替换料3库存 -->
|
||
LEFT JOIN storagecount f_sub3
|
||
ON a.StoreNo = f_sub3.StoreNo AND b.SameUseNum3 = f_sub3.PartNumber
|
||
|
||
<where>
|
||
a.Id IN
|
||
<foreach item="itemId" collection="ids" open="(" separator="," close=")">
|
||
#{itemId}
|
||
</foreach>
|
||
</where>
|
||
</select>
|
||
|
||
</mapper>
|