From 1946aa0712f623dd5e0221ef2481bc3d8d224e74 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 08 一月 2026 17:21:32 +0800
Subject: [PATCH] 1.销售订单到质检的关联删除 2.报工撤回的数量更新
---
src/main/java/com/ruoyi/production/mapper/ProductWorkOrderMapper.java | 11 +++
src/main/resources/mapper/production/ProductWorkOrderMapper.xml | 24 ++++++++
src/main/resources/mapper/production/ProductionProductInputMapper.xml | 8 ++
src/main/java/com/ruoyi/production/mapper/ProductionProductOutputMapper.java | 6 ++
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java | 23 ++++---
src/main/resources/mapper/production/ProductionProductOutputMapper.xml | 9 +++
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 50 ++++++++++++++--
src/main/resources/mapper/production/ProductionProductMainMapper.xml | 8 ++
src/main/java/com/ruoyi/production/mapper/ProductionProductInputMapper.java | 7 ++
src/main/java/com/ruoyi/quality/mapper/QualityInspectMapper.java | 5 +
src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java | 6 ++
src/main/resources/mapper/quality/QualityInspectMapper.xml | 9 +++
12 files changed, 151 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductWorkOrderMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductWorkOrderMapper.java
index 12a3963..1d5242e 100644
--- a/src/main/java/com/ruoyi/production/mapper/ProductWorkOrderMapper.java
+++ b/src/main/java/com/ruoyi/production/mapper/ProductWorkOrderMapper.java
@@ -8,8 +8,19 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import java.util.Map;
+
@Mapper
public interface ProductWorkOrderMapper extends BaseMapper<ProductWorkOrder> {
IPage<ProductWorkOrderDto> pageProductWorkOrder(Page<ProductWorkOrderDto> page, @Param("c") ProductWorkOrderDto productWorkOrder);
+
+ int updatePlanQuantity(Map<String, Object> params);
+
+ /**
+ * 鍥炴粴宸ュ崟璁″垝鏁伴噺锛氫粠production_product_output鍙杚uantity鍔犲洖plan_quantity
+ * @param productMainId
+ * @return
+ */
+ int rollbackPlanQuantity(@Param("productMainId") Long productMainId);
}
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductionProductInputMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductionProductInputMapper.java
index c8e8740..78e7d2a 100644
--- a/src/main/java/com/ruoyi/production/mapper/ProductionProductInputMapper.java
+++ b/src/main/java/com/ruoyi/production/mapper/ProductionProductInputMapper.java
@@ -8,7 +8,14 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import java.util.List;
+
@Mapper
public interface ProductionProductInputMapper extends BaseMapper<ProductionProductInput> {
IPage<ProductionProductInputDto> listPageProductionProductInputDto(Page page, @Param("c") ProductionProductInputDto productionProductInputDto);
+
+ /**
+ * 鏍规嵁鐢熶骇涓昏〃ID鎵归噺鍒犻櫎鎶曞叆琛ㄦ暟鎹�
+ */
+ int deleteByProductMainIds(@Param("productMainIds") List<Long> productMainIds);
}
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java
index cedb9f4..c9d1268 100644
--- a/src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java
+++ b/src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java
@@ -8,9 +8,15 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import java.util.List;
+
@Mapper
public interface ProductionProductMainMapper extends BaseMapper<ProductionProductMain> {
IPage<ProductionProductMainDto> listPageProductionProductMainDto(Page page, @Param("c") ProductionProductMainDto productionProductMainDto);
+ /**
+ * 鏍规嵁宸ュ崟ID鎵归噺鍒犻櫎鐢熶骇涓昏〃鏁版嵁
+ */
+ int deleteByWorkOrderIds(@Param("workOrderIds") List<Long> workOrderIds);
}
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductionProductOutputMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductionProductOutputMapper.java
index 15f1862..0283d42 100644
--- a/src/main/java/com/ruoyi/production/mapper/ProductionProductOutputMapper.java
+++ b/src/main/java/com/ruoyi/production/mapper/ProductionProductOutputMapper.java
@@ -8,8 +8,14 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import java.util.List;
+
@Mapper
public interface ProductionProductOutputMapper extends BaseMapper<ProductionProductOutput> {
IPage<ProductionProductOutputDto> listPageProductionProductOutputDto(Page page, @Param("c") ProductionProductOutputDto productionProductOutputDto);
+ /**
+ * 鏍规嵁鐢熶骇涓昏〃ID鎵归噺鍒犻櫎浜у嚭琛ㄦ暟鎹�
+ */
+ int deleteByProductMainIds(@Param("productMainIds") List<Long> productMainIds);
}
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
index 2664ea8..8e6aad1 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -33,6 +34,7 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -165,12 +167,13 @@
//鏇存柊宸ュ崟
if (insert > 0) {
- UpdateWrapper<ProductWorkOrder> wrapper = new UpdateWrapper<>();
- wrapper.set("report_work", true)
- .set("quantity", dto.getQuantity())
- .set("product_main_id", productionProductMain.getId())
- .eq("id", dto.getWorkOrderId());
- productWorkOrderMapper.update(null, wrapper);
+ Map<String, Object> params = new HashMap<>();
+ params.put("quantity", dto.getQuantity());
+ params.put("productMainId", productionProductMain.getId());
+ params.put("workOrderId", dto.getWorkOrderId());
+ params.put("deductQuantity", dto.getQuantity());
+
+ productWorkOrderMapper.updatePlanQuantity(params);
}
ProductProcess productProcess = productProcessMapper.selectById(productProcessRouteItem.getProcessId());
ProductModel productModel = productProcessRouteItem.getProductModelId() != null ?
@@ -252,6 +255,8 @@
public Boolean removeProductMain(ProductionProductMainDto dto) {
Long id = dto.getId();
+ // 鏇存柊宸ュ崟
+ productWorkOrderMapper.rollbackPlanQuantity(id);
// 鍒犻櫎璐ㄦ鍙傛暟鍜岃川妫�璁板綍
qualityInspectMapper.selectList(
new LambdaQueryWrapper<QualityInspect>()
@@ -270,9 +275,9 @@
// 鍒犻櫎鍏宠仈鐨勬牳绠楁暟鎹�
salesLedgerProductionAccountingMapper.delete(
- new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
- .eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id)
- );
+ new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
+ .eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id)
+ );
// 鍒犻櫎涓昏〃
return productionProductMainMapper.deleteById(id) > 0;
diff --git a/src/main/java/com/ruoyi/quality/mapper/QualityInspectMapper.java b/src/main/java/com/ruoyi/quality/mapper/QualityInspectMapper.java
index 9d96578..fdc57da 100644
--- a/src/main/java/com/ruoyi/quality/mapper/QualityInspectMapper.java
+++ b/src/main/java/com/ruoyi/quality/mapper/QualityInspectMapper.java
@@ -17,4 +17,9 @@
IPage<QualityInspect> qualityInspectListPage(Page page, @Param("qualityInspect") QualityInspect qualityInspect);
List<QualityInspect> qualityInspectExport(@Param("qualityInspect") QualityInspect qualityInspect);
+
+ /**
+ * 鏍规嵁鐢熶骇涓昏〃ID鎵归噺鍒犻櫎杩囩▼妫�楠�
+ */
+ int deleteByProductMainIds(@Param("productMainIds") List<Long> productMainIds);
}
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 1e5ec4f..2154217 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -23,6 +23,7 @@
import com.ruoyi.production.pojo.*;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
+import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.sales.dto.MonthlyAmountDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.mapper.*;
@@ -100,6 +101,14 @@
private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
private final ProductWorkOrderMapper productWorkOrderMapper;
+
+ private final ProductionProductMainMapper productionProductMainMapper;
+
+ private final ProductionProductOutputMapper productionProductOutputMapper;
+
+ private final ProductionProductInputMapper productionProductInputMapper;
+
+ private final QualityInspectMapper qualityInspectMapper;
@Autowired
private SysDeptMapper sysDeptMapper;
@@ -393,16 +402,46 @@
.in(ProductProcessRouteItem::getRouteId, orderIds)
);
- if (!org.springframework.util.CollectionUtils.isEmpty(allRouteItems)) {
+ if (!CollectionUtils.isEmpty(allRouteItems)) {
+ // 鑾峰彇瑕佸垹闄ょ殑宸ュ簭椤笽D
List<Long> routeItemIds = allRouteItems.stream()
.map(ProductProcessRouteItem::getId)
.collect(Collectors.toList());
- // 鎵归噺鍒犻櫎workOrder
- productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>()
- .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds));
- }
+ // 鏌ヨ鍏宠仈鐨勫伐鍗旾D
+ List<ProductWorkOrder> workOrders = productWorkOrderMapper.selectList(
+ new LambdaQueryWrapper<ProductWorkOrder>()
+ .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds)
+ );
+ if (!CollectionUtils.isEmpty(workOrders)) {
+ List<Long> workOrderIds = workOrders.stream()
+ .map(ProductWorkOrder::getId)
+ .collect(Collectors.toList());
+ // 鏌ヨ鍏宠仈鐨勭敓浜т富琛↖D
+ List<ProductionProductMain> productMains = productionProductMainMapper.selectList(
+ new LambdaQueryWrapper<ProductionProductMain>()
+ .in(ProductionProductMain::getWorkOrderId, workOrderIds)
+ );
+ List<Long> productMainIds = productMains.stream()
+ .map(ProductionProductMain::getId)
+ .collect(Collectors.toList());
+
+ // 鍒犻櫎浜у嚭琛ㄣ�佹姇鍏ヨ〃鏁版嵁
+ if (!CollectionUtils.isEmpty(productMainIds)) {
+ productionProductOutputMapper.deleteByProductMainIds(productMainIds);
+ productionProductInputMapper.deleteByProductMainIds(productMainIds);
+ qualityInspectMapper.deleteByProductMainIds(productMainIds);
+ }
+
+ // 鍒犻櫎鐢熶骇涓昏〃鏁版嵁
+ productionProductMainMapper.deleteByWorkOrderIds(workOrderIds);
+
+ // 鍒犻櫎宸ュ崟鏁版嵁
+ productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>()
+ .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds));
+ }
+ }
// 鎵归噺鍒犻櫎processRouteItem
productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>()
.in(ProductProcessRouteItem::getRouteId, orderIds));
@@ -440,7 +479,6 @@
wrapperTree.in(ReceiptPayment::getInvoiceLedgerId, invoiceLedgerIds);
receiptPaymentMapper.delete(wrapperTree);
}
-
// 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
// 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
diff --git a/src/main/resources/mapper/production/ProductWorkOrderMapper.xml b/src/main/resources/mapper/production/ProductWorkOrderMapper.xml
index 6c05996..cd5d97e 100644
--- a/src/main/resources/mapper/production/ProductWorkOrderMapper.xml
+++ b/src/main/resources/mapper/production/ProductWorkOrderMapper.xml
@@ -39,4 +39,28 @@
</if>
</where>
</select>
+
+ <update id="updatePlanQuantity" parameterType="java.util.Map">
+ UPDATE product_work_order
+ SET
+ report_work = #{reportWork},
+ quantity = #{quantity},
+ plan_quantity = plan_quantity - #{deductQuantity},
+ product_main_id = #{productMainId}
+ WHERE id = #{workOrderId}
+ </update>
+
+ <update id="rollbackPlanQuantity" parameterType="java.lang.Long">
+ UPDATE product_work_order pwo
+ INNER JOIN production_product_main ppm
+ ON pwo.id = ppm.work_order_id
+ AND ppm.id = #{productMainId}
+ INNER JOIN production_product_output ppo
+ ON ppo.product_main_id = ppm.id
+ SET
+ pwo.plan_quantity = pwo.plan_quantity + ppo.quantity,
+ pwo.report_work = 0,
+ pwo.quantity = 0
+ WHERE pwo.id = ppm.work_order_id
+ </update>
</mapper>
diff --git a/src/main/resources/mapper/production/ProductionProductInputMapper.xml b/src/main/resources/mapper/production/ProductionProductInputMapper.xml
index eab625b..7d203f3 100644
--- a/src/main/resources/mapper/production/ProductionProductInputMapper.xml
+++ b/src/main/resources/mapper/production/ProductionProductInputMapper.xml
@@ -25,4 +25,12 @@
</where>
order by ppi.id
</select>
+
+ <delete id="deleteByProductMainIds" parameterType="java.util.List">
+ DELETE FROM production_product_input
+ WHERE product_main_id IN
+ <foreach collection="productMainIds" item="id" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </delete>
</mapper>
diff --git a/src/main/resources/mapper/production/ProductionProductMainMapper.xml b/src/main/resources/mapper/production/ProductionProductMainMapper.xml
index 24feb0d..3a0542c 100644
--- a/src/main/resources/mapper/production/ProductionProductMainMapper.xml
+++ b/src/main/resources/mapper/production/ProductionProductMainMapper.xml
@@ -37,4 +37,12 @@
</where>
order by ppm.id
</select>
+
+ <delete id="deleteByWorkOrderIds" parameterType="java.util.List">
+ DELETE FROM production_product_main
+ WHERE work_order_id IN
+ <foreach collection="workOrderIds" item="id" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </delete>
</mapper>
diff --git a/src/main/resources/mapper/production/ProductionProductOutputMapper.xml b/src/main/resources/mapper/production/ProductionProductOutputMapper.xml
index 48c8c9e..e5d17fc 100644
--- a/src/main/resources/mapper/production/ProductionProductOutputMapper.xml
+++ b/src/main/resources/mapper/production/ProductionProductOutputMapper.xml
@@ -10,6 +10,7 @@
<result property="tenantId" column="tenant_id"/>
<result property="createTime" column="create_time"/>
</resultMap>
+
<select id="listPageProductionProductOutputDto" resultType="com.ruoyi.production.dto.ProductionProductOutputDto">
select ppo.*,
pm.model as model,
@@ -25,4 +26,12 @@
</where>
order by ppo.id
</select>
+
+ <delete id="deleteByProductMainIds" parameterType="java.util.List">
+ DELETE FROM production_product_output
+ WHERE product_main_id IN
+ <foreach collection="productMainIds" item="id" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </delete>
</mapper>
diff --git a/src/main/resources/mapper/quality/QualityInspectMapper.xml b/src/main/resources/mapper/quality/QualityInspectMapper.xml
index 8344fc5..dc3048e 100644
--- a/src/main/resources/mapper/quality/QualityInspectMapper.xml
+++ b/src/main/resources/mapper/quality/QualityInspectMapper.xml
@@ -46,4 +46,13 @@
AND product_name = #{qualityInspect.productName}
</if>
</select>
+
+ <delete id="deleteByProductMainIds">
+ DELETE FROM quality_inspect
+ WHERE product_main_id IN
+ <foreach collection="productMainIds" item="id" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </delete>
+
</mapper>
--
Gitblit v1.9.3