You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

483 lines
19 KiB

<?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.xjfast.mapper.MrpPlanDataMapper">
<resultMap id="BaseResultMap" type="com.xjfast.entity.MrpPlanData">
<result column="id" jdbcType="INTEGER" property="id"/>
<result column="site" jdbcType="VARCHAR" property="site"/>
<result column="ware_house_id" jdbcType="VARCHAR" property="wareHouseId"/>
<result column="part_no" jdbcType="VARCHAR" property="partNo"/>
<result column="calculation_type" jdbcType="VARCHAR" property="calculationType"/>
<result column="plan_date" jdbcType="TIMESTAMP" property="planDate"/>
<result column="plan_qty" jdbcType="FLOAT" property="planQty"/>
<result column="plan_desc" jdbcType="VARCHAR" property="planDesc"/>
<result column="order_ref1" jdbcType="VARCHAR" property="orderRef1"/>
<result column="order_ref2" jdbcType="VARCHAR" property="orderRef2"/>
<result column="order_ref3" jdbcType="VARCHAR" property="orderRef3"/>
</resultMap>
<!--添加库存记录-->
<insert id="insertMrpInventoryStock" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site,
plan_date,direction,calculation_type,plan_desc,created_by) SELECT
i.WarehouseID as ware_house_id,
i.PartNo as part_no,
i.QtyOnHand as plan_qty,
i.site as site,
CONVERT(VARCHAR (10), GETDATE(), 120) as plan_date,
'+' as direction,
#{calculationType} as calculation_type,
'库存' as plan_desc,
#{otherGroup2} as created_by
FROM InventoryStock i
LEFT JOIN WareHouse wh on ( i.WarehouseID = wh.WarehouseID)
LEFT JOIN part p ON ( p.PartNo = i.PartNo )
<where>
wh.WareHouseType_DB = #{wareHouseTypeDb}
<if test="partNo != null and partNo != ''">
and i.PartNo = #{partNo}
</if>
<if test="otherGroup2 != null and otherGroup2 != ''">
and p.OtherGroup2 = #{otherGroup2}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and i.WarehouseID = #{wareHouseId}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and i.WarehouseID = #{wareHouseId}
</if>
<if test="site != null and site != ''">
and i.site =#{site}
</if>
</where>
</insert>
<!-- 添加在途信息记录 -->
<insert id="insertMrpCode" parameterType="com.xjfast.entity.query.CodelheaderQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date,
direction,calculation_type,plan_desc,created_by)
SELECT cd.WarehouseID AS ware_house_id,
cd.PartNo AS part_no,
cd.ShipQty AS plan_qty,
cd.site AS site,
ch.DelDate AS plan_date,
'+' as direction,
#{calculationType} as calculation_type,
'在途' as plan_desc,
#{otherGroup2} as created_by
FROM CODelDetail cd
JOIN CODelHeader ch on (cd.DelNo = ch.DelNo)
LEFT JOIN part p ON ( cd.PartNo = p.PartNo )
<where>
<if test="partNo != null and partNo != ''">
cd.PartNo = #{partNo}
</if>
<if test="otherGroup2 != null and otherGroup2 != ''">
and p.OtherGroup2 = #{otherGroup2}
</if>
<if test="warehouseId != null and warehouseId != ''">
and cd.WarehouseID = #{warehouseId}
</if>
</where>
</insert>
<!--获取所有sku的日消耗 -->
<insert id="insertDaysMrp" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction,
calculation_type,plan_desc,created_by)
SELECT ppi.ware_house_id AS ware_house_id,
ppi.part_no AS part_no,
ppi.average_consume_qty AS plan_qty,
ppi.site AS site,
#{planDate} AS plan_date,
'-' AS direction,
#{calculationType} as calculation_type,
'日消耗' as plan_desc,
#{otherGroup2} as created_by
FROM part_plan_info ppi
LEFT JOIN WareHouse wh on(ppi.ware_house_id = wh.WareHouseID)
LEFT JOIN part p ON (ppi.part_no = p.PartNo )
<where>
wh.WareHouseType_DB = #{wareHouseTypeDb}
<if test="otherGroup2 != null and otherGroup2 != ''">
and p.OtherGroup2 = #{otherGroup2}
</if>
<if test="site != null and site != ''">
and site = #{site}
</if>
<if test="partNo != null and partNo != ''">
and ppi.part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and ppi.ware_house_id = #{wareHouseId}
</if>
</where>
</insert>
<!--库存需要保留安全位数-->
<insert id="insertInventoryMaintain" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction,
calculation_type,plan_desc,created_by)
SELECT ppi.ware_house_id AS ware_house_id,
ppi.part_no AS part_no,
ppi.average_consume_qty * cover_days AS plan_qty,
ppi.site AS site,
#{planDate} AS plan_date,
'-' AS direction,
#{calculationType} AS calculation_type,
'库存安全数' AS plan_desc,
#{otherGroup2} as created_by
FROM part_plan_info ppi
LEFT JOIN WareHouse wh on(ppi.ware_house_id = wh.WareHouseID)
LEFT JOIN part p ON (ppi.part_no = p.PartNo )
<where>
wh.WareHouseType_DB = #{wareHouseTypeDb}
<if test="otherGroup2 != null and otherGroup2 != ''">
and p.OtherGroup2 = #{otherGroup2}
</if>
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and ware_house_id = #{wareHouseId}
</if>
<if test="site != null and site != ''">
and wh.site =#{site}
</if>
</where>
</insert>
<!-- 导入补货建议单 -->
<insert id="insertMpsPlan" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction, calculation_type,
plan_desc,created_by)
SELECT ware_house_id AS ware_house_id,
part_no AS part_no,
MAX(qty_required) AS plan_qty,
site AS site,
MIN(need_date) AS plan_date,
'-' AS direction,
#{calculationType} AS calculation_type,
'备货' AS plan_desc,
#{otherGroup2} as created_by
FROM delivery_requisition d
<where>
status = '创建'
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
<if test="site != null and site != ''">
and site =#{site}
</if>
</where>
GROUP BY ware_house_id,
part_no,
site,
created_by,
status,
site
</insert>
<!-- 生成生产计划单 -->
<insert id="insertShopOrderRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO shop_order_requisition ( site, part_no, need_date, status, qty_required, created_by, created_date )
SELECT
site,
part_no,
MIN(plan_date) AS need_date,
'创建' AS status,
- SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) AS qty_required,
'admin' AS created_by,
GETDATE( ) AS created_date
FROM
mrp_plan_data
<where>
calculation_type = 'MPS' AND plan_desc != '建议生产'
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
</where>
GROUP BY
part_no,
site
HAVING
SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) <![CDATA[ <=]]> 0
</insert>
<!--临时补货 (虚拟记录)-->
<insert id="insertTemporaryStocking" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction,
calculation_type, plan_desc, created_by)
SELECT ware_house_id,
part_no,
-SUM(CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END) AS qty_required,
site,
#{planDate} AS plan_date,
'+' direction,
#{calculationType} calculation_type,
'临时补货' plan_desc,
#{otherGroup2} as created_by
FROM mrp_plan_data
where plan_date <![CDATA[<=]]> #{planDate}
and calculation_type = #{calculationType}
and site = #{site}
GROUP BY ware_house_id,
part_no,
site
HAVING SUM(CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END)<![CDATA[ <=]]> 0
</insert>
<insert id="addDelivryRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO delivery_requisition (qty_required, ware_house_id, part_no, need_date, site, status, created_date,
created_by)
SELECT SUM(plan_qty) AS qty_required,
ware_house_id,
part_no,
MIN(plan_date) AS need_date,
site,
'创建' status,
CONVERT(VARCHAR (10), GETDATE(), 120) created_date,
#{createdBy} created_by
FROM mrp_plan_data
<where>
plan_desc = #{planDesc}
<if test="wareHouseId != null and wareHouseId != ''">
and ware_house_id =#{wareHouseId}
</if>
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
</where>
GROUP BY ware_house_id,
part_no,
site
</insert>
<insert id="addMrpPlanData" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction, calculation_type,
plan_desc,created_by)
SELECT ware_house_id,
part_no,
SUM(plan_qty) AS plan_qty,
site,
MIN(plan_date) AS plan_date,
'+' AS direction,
'MS' calculation_type,
'建议备货' plan_desc,
#{otherGroup2} as created_by
FROM mrp_plan_data
<where>
plan_desc = #{planDesc}
<if test="site != null and site != ''">
and site = #{site}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and ware_house_id =#{wareHouseId}
</if>
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
</where>
GROUP BY ware_house_id,
part_no,
site
</insert>
<insert id="insertShopMrp" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data ( part_no, plan_qty, site, plan_date, direction, calculation_type,
plan_desc,created_by ) SELECT
PartNo AS part_no,
ISNULL(LotSize,0) -ISNULL(FinishedQty, 0) AS plan_qty,
NeedDate plan_date,
Site AS site,
'+' AS direction,
'MPS' AS calculation_type,
'库存' AS plan_desc,
#{otherGroup2} as created_by
FROM
ShopOrder
<where>
Status != '已取消' AND Status != '已结束' AND NeedDate <![CDATA[<=]]> #{planDate}
<if test=" site!=null and site!='' ">
and Site = #{site}
</if>
<if test=" partNo!=null and partNo!='' ">
and PartNo = #{partNo}
</if>
</where>
</insert>
<!--添加计算生产计划-->
<insert id="insertMrpShopOrder" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
INSERT INTO mrp_plan_data ( part_no, plan_qty, site, plan_date, direction, calculation_type,
plan_desc,created_by )
SELECT
part_no,
- SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) AS plan_qty,
site,
MIN(plan_date),
'+' AS direction,
'MPS' AS calculation_type,
'建议生产' AS plan_desc,
#{otherGroup2} as created_by
FROM
mrp_plan_data
<where>
calculation_type = 'MPS' and plan_desc != '建议生产'
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
</where>
GROUP BY
part_no,
site
HAVING
SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) <![CDATA[<=]]> 0
</insert>
<!-- 没有维护安全库存的 活动物料-->
<insert id="insertMrpPlanList" parameterType="collection">
INSERT INTO mrp_plan_data ( part_no, plan_qty, site,ware_house_id, plan_date, direction, calculation_type,
plan_desc,created_by )
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.partNo},
#{item.planQty},
#{item.site},
#{item.wareHouseId},
#{item.planDate},
#{item.direction},
#{item.calculationType},
#{item.planDesc},
#{item.createdBy}
)
</foreach>
</insert>
<!--更具活动时间范围 修改 mrp_plan_data 表对对应 的数据-->
<update id="updateMrpHis" parameterType="com.xjfast.entity.vo.PromotionHistVo">
UPDATE mrp_plan_data
SET plan_qty = #{averageConsumeQty},
direction = '-',
calculation_type = 'MS',
plan_desc = '活动消耗'
WHERE plan_date <![CDATA[>=]]> #{startDate}
AND plan_date <![CDATA[<=]]> #{finishDate}
AND ware_house_id = #{wareHouseId}
AND part_no = #{partNo}
AND plan_desc = '日消耗'
AND site = #{site}
</update>
<select id="selectInvetorySum" parameterType="com.xjfast.entity.query.MrpPlanDataQuery"
resultType="com.xjfast.entity.vo.MrpPlanDataVo">
SELECT mpd.ware_house_id, mpd.part_no, SUM(mpd.plan_qty) , SUM(mpd.plan_qty) - ppi.average_consume_qty as
difference
FROM mrp_plan_data mpd
LEFT JOIN part_plan_info ppi on (mpd.ware_house_id = ppi.ware_house_id and mpd.part_no = ppi.part_no)
<where>
<if test="partNo != null and partNo != ''">
mpd.part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and mpd.ware_house_id = #{wareHouseId}
</if>
</where>
GROUP BY mpd.ware_house_id, mpd.part_no, ppi.average_consume_qty
HAVING SUM(mpd.plan_qty) <![CDATA[<]]> ppi.average_consume_qty
</select>
<select id="searchMrpPlanDataList" resultType="com.xjfast.entity.vo.MrpPlanDataVo">
select m.*, p.PartDescription, w.WareHouseName
from mrp_plan_data m
left join Part p on (m.part_no = p.PartNo)
left join WareHouse w on (w.WareHouseID = m.ware_house_id)
<where>
m.site = #{site}
<if test="planDesc != null and planDesc != ''">
and m.plan_desc != #{planDesc}
</if>
<if test="partNo != null and partNo != ''">
and m.part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != ''">
and m.ware_house_id = #{wareHouseId}
</if>
<if test="deliveryRequisitionId != null and deliveryRequisitionId != ''">
and m.delivery_requisition_id = #{deliveryRequisitionId}
</if>
<if test="calculationType != null and calculationType != ''">
and m.calculation_type = #{calculationType}
</if>
</where>
order by m.plan_date
</select>
<!-- 删除mrp记录表信息-->
<delete id="removeMrpPlan" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
DELETE FROM mrp_plan_data
<where>
<if test="otherGroup2 != null and otherGroup2 != ''">
and created_by =#{otherGroup2}
</if>
<if test="site != null and site != ''">
and site =#{site}
</if>
<if test="partNo != null and partNo != '' ">
and part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != '' ">
and ware_house_id = #{wareHouseId}
</if>
<if test="id != null and id != ''">
and id = #{id}
</if>
<if test="calculationType != null and calculationType != ''">
and calculation_type = #{calculationType}
</if>
</where>
</delete>
<delete id="removeDelivryRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
DELETE FROM delivery_requisition
<where>
status = '创建'
<if test="site != null and site != ''">
and site =#{site}
</if>
<if test="otherGroup2 != null and otherGroup2 != ''">
and created_by =#{otherGroup2}
</if>
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != '' ">
and ware_house_id = #{wareHouseId}
</if>
</where>
</delete>
<!--删除生产计划单-->
<delete id="reomveShopOrderRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
DELETE FROM shop_order_requisition
<where>
status = '创建'
<if test="partNo != null and partNo != ''">
AND part_no = #{partNo}
</if>
<if test="site != null and site != ''">
and site =#{site}
</if>
</where>
</delete>
<delete id="removeMrpPlanLs" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
DELETE FROM mrp_plan_data
<where>
plan_desc = '临时补货'
<if test="site != null and site != ''">
and site =#{site}
</if>
<if test="otherGroup2 != null and otherGroup2 != ''">
and created_by =#{otherGroup2}
</if>
<if test="partNo != null and partNo != ''">
and part_no = #{partNo}
</if>
<if test="wareHouseId != null and wareHouseId != '' ">
and ware_house_id = #{wareHouseId}
</if>
</where>
</delete>
</mapper>