From 6256daf29f4c44944fa71a7dbd211b06bf1a495d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 25 五月 2026 09:46:20 +0800
Subject: [PATCH] feat: 报工投入用“投入重量/数量”
---
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java | 788 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 595 insertions(+), 193 deletions(-)
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 3722729..e5b5843 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -1,5 +1,8 @@
package com.ruoyi.production.service.impl;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -13,9 +16,11 @@
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
-import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum;
+import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.production.dto.ProductStructureDto;
@@ -29,17 +34,17 @@
import com.ruoyi.quality.mapper.*;
import com.ruoyi.quality.pojo.*;
import com.ruoyi.quality.service.IQualityInspectService;
+import com.ruoyi.stock.support.FinishedProductStockDimensionResolver;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import com.ruoyi.production.mapper.ProductionProductMainMapper;
import java.math.BigDecimal;
-import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
+import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@@ -47,44 +52,34 @@
@Transactional(rollbackFor = Exception.class)
public class ProductionProductMainServiceImpl extends ServiceImpl<ProductionProductMainMapper, ProductionProductMain> implements ProductionProductMainService {
+ private static final String PROCESS_VOLTAGE_SORT = "鐢靛帇鍒嗛��";
+ private static final String PROCESS_OPTICAL_INSPECTION = "鍏夋澶栬";
+ private static final String PROCESS_PACKAGING = "鍖呰";
+ private static final String INPUT_WEIGHT_PARAMETER = "鎶曞叆閲嶉噺/鏁伴噺";
+ private static final String INPUT_WEIGHT_FIELD = "inputWeight";
+ private static final Object PRODUCT_MAIN_NO_LOCK = new Object();
+
private IQualityInspectService qualityInspectService;
private ProductionProductMainMapper productionProductMainMapper;
-
-
private ProductWorkOrderMapper productWorkOrderMapper;
-
private ProductProcessRouteItemMapper productProcessRouteItemMapper;
private SysUserMapper userMapper;
-
private ProductionProductOutputMapper productionProductOutputMapper;
-
-
private ProductModelMapper productModelMapper;
-
private QualityInspectMapper qualityInspectMapper;
private QualityUnqualifiedMapper qualityUnqualifiedMapper;
-
private ProductProcessMapper productProcessMapper;
private ProductProcessRouteMapper productProcessRouteMapper;
-
private ProductMapper productMapper;
-
-
private QualityTestStandardParamMapper qualityTestStandardParamMapper;
private QualityTestStandardMapper qualityTestStandardMapper;
-
private QualityInspectParamMapper qualityInspectParamMapper;
-
private ProductStructureMapper productStructureMapper;
-
private ProductionProductInputMapper productionProductInputMapper;
-
private ProductOrderMapper productOrderMapper;
-
private SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
-
private StockUtils stockUtils;
-
+ private FinishedProductStockDimensionResolver finishedProductStockDimensionResolver;
private ISysNoticeService sysNoticeService;
@Override
@@ -92,242 +87,574 @@
return productionProductMainMapper.listPageProductionProductMainDto(page, productionProductMainDto);
}
+ // 鏂板鎶ュ伐锛屽苟鎸夌収鎶ュ伐涓绘祦绋嬪鐞嗘姇鍏ユ墸搴撱�佷骇鍑恒�佽川妫�銆佸叆搴撱�佸伐鍗曡鍗曡繘搴﹀拰鏍哥畻鏁版嵁
@Override
public Boolean addProductMain(ProductionProductMainDto dto) {
- SysUser user = userMapper.selectUserById(dto.getUserId());
- ProductionProductMain productionProductMain = new ProductionProductMain();
- //褰撳墠宸ヨ壓璺嚎瀵瑰簲鐨勫伐搴忚鎯�
- ProductProcessRouteItem productProcessRouteItem = productProcessRouteItemMapper.selectById(dto.getProductProcessRouteItemId());
- if (productProcessRouteItem == null) {
- throw new RuntimeException("宸ヨ壓璺嚎椤逛笉瀛樺湪");
+ // 绗竴姝ワ細鍏堟牎楠屾姤宸ュ叆鍙傦紝閬垮厤绌哄�煎拰闈炴硶鏁伴噺杩涘叆鍚庣画娴佺▼
+ if (dto == null) {
+ throw new ServiceException("鎶ュ伐鍙傛暟涓嶈兘涓虹┖");
}
- // 鏄惁鑳芥姤宸ワ細 1. 绗竴涓伐搴忚兘鎶ュ伐 2. 涓婁竴涓伐搴忓凡鎶ュ伐 3. 涔嬪墠鐨勫伐搴忔湭琚殧绂�
- //妫�鏌ヤ笂涓�涓伐搴忔槸鍚﹀凡鎶ュ伐
+ if (dto.getProductProcessRouteItemId() == null) {
+ throw new ServiceException("宸ヨ壓璺嚎宸ュ簭椤逛笉鑳戒负绌�");
+ }
+ if (dto.getWorkOrderId() == null) {
+ throw new ServiceException("鐢熶骇宸ュ崟涓嶈兘涓虹┖");
+ }
+
+ BigDecimal reportQty = dto.getQuantity();
+ BigDecimal scrapQty = dto.getScrapQty() == null ? BigDecimal.ZERO : dto.getScrapQty();
+ BigDecimal bomInputQty = dto.getInputWeight();
+ if (bomInputQty == null) {
+ bomInputQty = resolveInputWeight(dto.getOtherData());
+ }
+ if (reportQty == null || reportQty.compareTo(BigDecimal.ZERO) <= 0) {
+ throw new ServiceException("鎶ュ伐鏁伴噺蹇呴』澶т簬0");
+ }
+ if (scrapQty.compareTo(BigDecimal.ZERO) < 0) {
+ throw new ServiceException("鎶ュ簾鏁伴噺涓嶈兘灏忎簬0");
+ }
+ if (scrapQty.compareTo(reportQty) > 0) {
+ throw new ServiceException("鎶ュ簾鏁伴噺涓嶈兘澶т簬鎶ュ伐鏁伴噺");
+ }
+ if (bomInputQty == null || bomInputQty.compareTo(BigDecimal.ZERO) < 0) {
+ throw new ServiceException("浜у搧缁撴瀯鎶曞叆鏁伴噺涓嶈兘灏忎簬0");
+ }
+
+ // 绗簩姝ワ細鍔犺浇褰撳墠宸ュ簭銆佸伐鍗曘�佸伐鑹鸿矾绾垮拰璁㈠崟鏁版嵁锛屽苟鏍¢獙鍩虹鍏宠仈鍏崇郴
+ ProductProcessRouteItem productProcessRouteItem =
+ productProcessRouteItemMapper.selectById(dto.getProductProcessRouteItemId());
+ if (productProcessRouteItem == null) {
+ throw new ServiceException("宸ヨ壓璺嚎宸ュ簭椤逛笉瀛樺湪");
+ }
+
+ ProductProcess productProcess = productProcessMapper.selectById(productProcessRouteItem.getProcessId());
+ if (productProcess == null) {
+ throw new ServiceException("褰撳墠宸ュ簭涓嶅瓨鍦�");
+ }
+
+ ProductModel productModel = productModelMapper.selectById(productProcessRouteItem.getProductModelId());
+ if (productModel == null) {
+ throw new ServiceException("褰撳墠宸ュ簭瀵瑰簲鐨勪骇鍝佸瀷鍙蜂笉瀛樺湪");
+ }
+
+ ProductProcessRoute productProcessRoute =
+ productProcessRouteMapper.selectById(productProcessRouteItem.getProductRouteId());
+ if (productProcessRoute == null) {
+ throw new ServiceException("宸ヨ壓璺嚎涓嶅瓨鍦�");
+ }
+
+ ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId());
+ if (productWorkOrder == null) {
+ throw new ServiceException("鐢熶骇宸ュ崟涓嶅瓨鍦�");
+ }
+ if (!Objects.equals(productWorkOrder.getProductProcessRouteItemId(), productProcessRouteItem.getId())) {
+ throw new ServiceException("鐢熶骇宸ュ崟涓庡綋鍓嶅伐搴忎笉鍖归厤");
+ }
+
+ ProductOrder productOrder = productOrderMapper.selectById(productWorkOrder.getProductOrderId());
+ if (productOrder == null) {
+ throw new ServiceException("鐢熶骇璁㈠崟涓嶅瓨鍦�");
+ }
+
+ // 绗笁姝ワ細鏍¢獙宸ュ簭娴佽浆閫昏緫锛屽繀椤绘槸鍚屼竴璁㈠崟鐨勪笂涓�閬撳伐搴忓凡鎶ュ伐涓斿墠搴忔棤鏈В闄ら殧绂昏褰�
Integer currentDragSort = productProcessRouteItem.getDragSort();
if (currentDragSort != null && currentDragSort > 1) {
boolean isPreviousReported = productionProductMainMapper.checkPreviousProcessReported(
- productProcessRouteItem.getProductRouteId(),
+ productWorkOrder.getId(),
currentDragSort
);
if (!isPreviousReported) {
- throw new RuntimeException("涓婁竴涓伐搴忓皻鏈姤宸ワ紝涓嶈兘杩涜褰撳墠宸ュ簭鎶ュ伐");
+ throw new ServiceException("涓婁竴閬撳伐搴忓皻鏈姤宸ワ紝褰撳墠宸ュ簭涓嶈兘鎶ュ伐");
}
- // 鏌ヨ鎵�鏈変箣鍓嶇殑宸ュ簭锛堟帓搴忓彿灏忎簬褰撳墠宸ュ簭锛�
+ ProductProcessRouteItem previousRouteItem = productProcessRouteItemMapper.selectOne(
+ Wrappers.<ProductProcessRouteItem>lambdaQuery()
+ .eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId())
+ .eq(ProductProcessRouteItem::getDragSort, currentDragSort - 1)
+ );
+ if (previousRouteItem == null) {
+ throw new ServiceException("涓婁竴閬撳伐搴忎笉瀛樺湪");
+ }
+
+ ProductWorkOrder previousWorkOrder = productWorkOrderMapper.selectOne(
+ Wrappers.<ProductWorkOrder>lambdaQuery()
+ .eq(ProductWorkOrder::getProductOrderId, productOrder.getId())
+ .eq(ProductWorkOrder::getProductProcessRouteItemId, previousRouteItem.getId())
+ );
+ if (previousWorkOrder == null) {
+ throw new ServiceException("涓婁竴閬撳伐搴忓伐鍗曚笉瀛樺湪");
+ }
+
+ BigDecimal currentReportedQty = BigDecimal.ZERO;
+ List<ProductionProductMain> currentMainList = productionProductMainMapper.selectList(
+ Wrappers.<ProductionProductMain>lambdaQuery()
+ .eq(ProductionProductMain::getWorkOrderId, productWorkOrder.getId())
+ );
+ if (CollectionUtils.isNotEmpty(currentMainList)) {
+ List<Long> currentMainIds = currentMainList.stream().map(ProductionProductMain::getId).collect(Collectors.toList());
+ List<ProductionProductOutput> currentOutputList = productionProductOutputMapper.selectList(
+ Wrappers.<ProductionProductOutput>lambdaQuery()
+ .in(ProductionProductOutput::getProductMainId, currentMainIds)
+ );
+ currentReportedQty = currentOutputList.stream()
+ .map(ProductionProductOutput::getQuantity)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+
+ BigDecimal previousCompleteQty =
+ previousWorkOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : previousWorkOrder.getCompleteQuantity();
+ if (currentReportedQty.add(reportQty).compareTo(previousCompleteQty) > 0) {
+ throw new ServiceException("鏈鎶ュ伐鏁伴噺瓒呰繃涓婇亾宸ュ簭鍙祦杞暟閲�");
+ }
+
List<ProductProcessRouteItem> previousItems = productProcessRouteItemMapper.selectList(
Wrappers.<ProductProcessRouteItem>lambdaQuery()
.eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId())
.lt(ProductProcessRouteItem::getDragSort, currentDragSort)
);
+
if (CollectionUtils.isNotEmpty(previousItems)) {
- // 鎻愬彇涔嬪墠宸ュ簭鐨勫悕绉板垪琛�
List<String> previousProcessNames = new ArrayList<>();
for (ProductProcessRouteItem item : previousItems) {
ProductProcess process = productProcessMapper.selectById(item.getProcessId());
- if (process != null) {
- previousProcessNames.add(process.getName());
+ if (process != null && StringUtils.isNotBlank(process.getName())) {
+ previousProcessNames.add(process.getName().trim());
}
}
- // 妫�鏌ヤ箣鍓嶇殑宸ュ簭鏄惁鏈夎闅旂鐨勪笉鍚堟牸璁板綍
- List<QualityUnqualified> unqualifiedList = qualityUnqualifiedMapper.selectUnqualifiedByProcessNames(previousProcessNames);
- if (CollectionUtils.isNotEmpty(unqualifiedList)) {
- throw new RuntimeException("涔嬪墠鐨勫伐搴忓凡琚殧绂伙紝涓嶈兘杩涜褰撳墠宸ュ簭鎶ュ伐");
+ if (CollectionUtils.isNotEmpty(previousProcessNames)) {
+ List<QualityUnqualified> unqualifiedList =
+ qualityUnqualifiedMapper.selectUnqualifiedByProductOrderAndProcessNames(productOrder.getId(), previousProcessNames);
+ if (CollectionUtils.isNotEmpty(unqualifiedList)) {
+ throw new ServiceException("鍓嶅簭宸ュ簭瀛樺湪闅旂璁板綍锛屽綋鍓嶅伐搴忎笉鑳芥姤宸�");
+ }
}
}
}
- //褰撳墠鍏蜂綋宸ュ簭
- ProductProcess productProcess = productProcessMapper.selectById(productProcessRouteItem.getProcessId());
- //宸ヨ壓璺嚎涓綋鍓嶅伐搴忓搴旂殑浜у嚭瑙勬牸鍨嬪彿
- ProductModel productModel = productModelMapper.selectById(productProcessRouteItem.getProductModelId());
- //鏌ヨ璇ョ敓浜ц鍗曞搴旂殑bom
- ProductProcessRoute productProcessRoute = productProcessRouteMapper.selectById(productProcessRouteItem.getProductRouteId());
- /*鏂板鎶ュ伐涓昏〃*/
- //鏌ヨ鏈�澶ф姤宸ョ紪鍙�
- String datePrefix = "BG" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
- QueryWrapper<ProductionProductMain> queryWrapper = new QueryWrapper<>();
- queryWrapper.select("MAX(product_no) as maxNo")
- .likeRight("product_no", datePrefix);
- List<Map<String, Object>> resultList = productionProductMainMapper.selectMaps(queryWrapper);
- int sequenceNumber = 1;
- if (resultList != null && !resultList.isEmpty()) {
- Map<String, Object> result = resultList.get(0);
- if (result != null) {
- Object maxNoObj = result.get("maxNo");
- if (maxNoObj != null) {
- String lastNo = maxNoObj.toString();
+
+ // 绗洓姝ワ細鎺у埗褰撳墠宸ュ崟鎬绘姤宸ラ噺涓嶈兘瓒呰繃璁″垝閲�
+ BigDecimal currentWorkOrderReportedQty = BigDecimal.ZERO;
+ List<ProductionProductMain> workOrderMainList = productionProductMainMapper.selectList(
+ Wrappers.<ProductionProductMain>lambdaQuery()
+ .eq(ProductionProductMain::getWorkOrderId, productWorkOrder.getId())
+ );
+ if (CollectionUtils.isNotEmpty(workOrderMainList)) {
+ List<Long> workOrderMainIds = workOrderMainList.stream().map(ProductionProductMain::getId).collect(Collectors.toList());
+ List<ProductionProductOutput> workOrderOutputList = productionProductOutputMapper.selectList(
+ Wrappers.<ProductionProductOutput>lambdaQuery()
+ .in(ProductionProductOutput::getProductMainId, workOrderMainIds)
+ );
+ currentWorkOrderReportedQty = workOrderOutputList.stream()
+ .map(ProductionProductOutput::getQuantity)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+ if (productWorkOrder.getPlanQuantity() != null
+ && currentWorkOrderReportedQty.add(reportQty).compareTo(productWorkOrder.getPlanQuantity()) > 0) {
+ throw new ServiceException("鏈鎶ュ伐鏁伴噺瓒呰繃宸ュ崟鍙姤鏁伴噺");
+ }
+
+ // 绗簲姝ワ細鐢熸垚鎶ュ伐鍗曞彿骞剁‘瀹氭姤宸ヤ汉淇℃伅
+ String productNo;
+ synchronized (PRODUCT_MAIN_NO_LOCK) {
+ String datePrefix = "BG" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
+ QueryWrapper<ProductionProductMain> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("MAX(product_no) as maxNo")
+ .likeRight("product_no", datePrefix);
+ List<Map<String, Object>> resultList = productionProductMainMapper.selectMaps(queryWrapper);
+
+ int sequenceNumber = 1;
+ if (CollectionUtils.isNotEmpty(resultList)) {
+ Map<String, Object> result = resultList.get(0);
+ if (result != null && result.get("maxNo") != null) {
+ String lastNo = result.get("maxNo").toString();
if (lastNo.startsWith(datePrefix)) {
try {
- String seqStr = lastNo.substring(datePrefix.length());
- sequenceNumber = Integer.parseInt(seqStr) + 1;
+ sequenceNumber = Integer.parseInt(lastNo.substring(datePrefix.length())) + 1;
} catch (NumberFormatException e) {
sequenceNumber = 1;
}
}
}
}
+ productNo = String.format("%s%03d", datePrefix, sequenceNumber);
}
- String productNo = String.format("%s%03d", datePrefix, sequenceNumber);
+
+ Long userId = dto.getUserId();
+ String userName = dto.getUserName();
+ if (userId == null) {
+ userId = SecurityUtils.getLoginUser().getUserId();
+ userName = SecurityUtils.getLoginUser().getNickName();
+ } else if (StringUtils.isBlank(userName)) {
+ SysUser user = userMapper.selectUserById(userId);
+ userName = user == null ? null : user.getNickName();
+ }
+
+ // 绗叚姝ワ細鍏堝啓鎶ュ伐涓昏〃
+ ProductionProductMain productionProductMain = new ProductionProductMain();
productionProductMain.setProductNo(productNo);
- productionProductMain.setUserId(dto.getUserId());
- productionProductMain.setUserName(dto.getUserName());
+ productionProductMain.setUserId(userId);
+ productionProductMain.setUserName(userName);
productionProductMain.setProductProcessRouteItemId(dto.getProductProcessRouteItemId());
productionProductMain.setWorkOrderId(dto.getWorkOrderId());
productionProductMain.setStatus(0);
productionProductMainMapper.insert(productionProductMain);
- /*鏂板鎶ュ伐鎶曞叆琛�*/
- List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomAndProcess(productProcessRoute.getBomId(), productProcess.getId());
- if (productStructureDtos.size() == 0) {
- //濡傛灉璇ュ伐搴忔病鏈変骇鍝佺粨鏋勭殑鎶曞叆鍝�,閭h繖涓姇鍏ュ搧鍜屼骇鍑哄搧鏄悓涓�涓�
+
+ // 绗竷姝ワ細鏍规嵁 BOM 鐢熸垚鎶曞叆璁板綍骞舵墸鍑忓師鏂欏簱瀛�
+ List<ProductStructureDto> productStructureDtos =
+ productStructureMapper.listBybomAndProcess(productProcessRoute.getBomId(), productProcess.getId());
+
+ if (CollectionUtils.isEmpty(productStructureDtos)) {
ProductStructureDto productStructureDto = new ProductStructureDto();
productStructureDto.setProductModelId(productProcessRouteItem.getProductModelId());
productStructureDto.setUnitQuantity(BigDecimal.ONE);
productStructureDtos.add(productStructureDto);
}
+
+ Set<Long> parentIds = productStructureDtos.stream()
+ .map(ProductStructureDto::getParentId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Map<Long, ProductStructureDto> parentMap = new HashMap<>();
+ if (CollectionUtils.isNotEmpty(parentIds)) {
+ parentMap = productStructureMapper.selectByIds(parentIds)
+ .stream()
+ .collect(Collectors.toMap(ProductStructureDto::getId, Function.identity(), (a, b) -> a));
+ }
+
+ // 绗竷姝�-1锛氭姇鍏ユ暟閲忓己鍒跺彇鍓嶇浼犲叆鐨� bomInputQty
+ BigDecimal inputBaseQty = bomInputQty;
+
for (ProductStructureDto productStructureDto : productStructureDtos) {
- System.out.println(productStructureDto.getProductModelId());
+ if (productStructureDto.getProductModelId() == null) {
+ throw new ServiceException("鎶曞叆鐗╂枡浜у搧鍨嬪彿涓嶈兘涓虹┖");
+ }
+
+ BigDecimal childQty = productStructureDto.getUnitQuantity();
+ if (childQty == null || childQty.compareTo(BigDecimal.ZERO) <= 0) {
+ throw new ServiceException("鎶曞叆鐗╂枡鐢ㄩ噺蹇呴』澶т簬0");
+ }
+
+ BigDecimal parentQty = BigDecimal.ONE;
+ if (productStructureDto.getParentId() != null) {
+ ProductStructureDto parent = parentMap.get(productStructureDto.getParentId());
+ if (parent != null) {
+ parentQty = parent.getUnitQuantity();
+ }
+ }
+
+ if (parentQty == null || parentQty.compareTo(BigDecimal.ZERO) <= 0) {
+ throw new ServiceException("鐖剁骇鐗╂枡鐢ㄩ噺蹇呴』澶т簬0");
+ }
+
+ BigDecimal needQty = inputBaseQty;
+
ProductionProductInput productionProductInput = new ProductionProductInput();
productionProductInput.setProductModelId(productStructureDto.getProductModelId());
- productionProductInput.setQuantity(productStructureDto.getUnitQuantity().multiply(dto.getQuantity()));
+ productionProductInput.setQuantity(needQty == null ? BigDecimal.ZERO : needQty);
productionProductInput.setProductMainId(productionProductMain.getId());
productionProductInputMapper.insert(productionProductInput);
- stockUtils.substractStock(productStructureDto.getProductModelId(), productionProductInput.getQuantity(), StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(), productionProductMain.getId());
+ stockUtils.substractStock(
+ productStructureDto.getProductModelId(),
+ needQty,
+ StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
+ productionProductMain.getId(),
+ null,
+ null
+ );
}
- /*鏂板鎶ュ伐浜у嚭琛�*/
+
+ // 绗叓姝ワ細鍐欎骇鍑鸿褰曞苟璁$畻鏈鍚堟牸鏁伴噺
ProductionProductOutput productionProductOutput = new ProductionProductOutput();
productionProductOutput.setProductMainId(productionProductMain.getId());
productionProductOutput.setProductModelId(productProcessRouteItem.getProductModelId());
- productionProductOutput.setQuantity(dto.getQuantity() != null ? dto.getQuantity() : BigDecimal.ZERO);
- productionProductOutput.setScrapQty(dto.getScrapQty() != null ? dto.getScrapQty() : BigDecimal.ZERO);
- productionProductOutput.setOtherData(dto.getOtherData() != null ? dto.getOtherData() : "");
+ productionProductOutput.setQuantity(reportQty);
+ productionProductOutput.setScrapQty(scrapQty);
+ productionProductOutput.setOtherData(dto.getOtherData() == null ? "" : dto.getOtherData());
productionProductOutputMapper.insert(productionProductOutput);
- ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId());
- ProductOrder productOrder = productOrderMapper.selectById(productWorkOrder.getProductOrderId());
+ BigDecimal qualifiedQty = reportQty.subtract(scrapQty);
- //鍚堟牸鏁伴噺=鎶ュ伐鏁伴噺-鎶ュ簾鏁伴噺
- BigDecimal productQty = productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty());
- List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(Wrappers.<ProductProcessRouteItem>lambdaQuery().eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId()));
- //鍙湁鍚堟牸鏁伴噺>0鎵嶈兘澧炲姞鐩稿簲鏁版嵁
- if (productQty.compareTo(BigDecimal.ZERO) > 0) {
- /*鏂板璐ㄦ*/
- if (productProcessRouteItem.getIsQuality()) {
- //瀵瑰簲鐨勮繃绋嬫鎴栬�呭嚭鍘傛
+ List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(
+ Wrappers.<ProductProcessRouteItem>lambdaQuery()
+ .eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId())
+ );
+
+ Integer maxDragSort = productProcessRouteItems.stream()
+ .map(ProductProcessRouteItem::getDragSort)
+ .filter(Objects::nonNull)
+ .max(Integer::compareTo)
+ .orElse(null);
+
+ boolean isRouteLastProcess = Objects.equals(productProcessRouteItem.getDragSort(), maxDragSort);
+ ReportStockRule reportStockRule =
+ resolveReportStockRule(productProcessRouteItem, productProcess, productProcessRouteItems);
+
+ // 绗節姝ワ細濡傛灉鏈夊悎鏍兼暟閲忥紝鍒欐牴鎹槸鍚﹁川妫�鍐冲畾璧拌川妫�鎴栫洿鎺ュ叆搴�
+ if (qualifiedQty.compareTo(BigDecimal.ZERO) > 0) {
+ if (Boolean.TRUE.equals(productProcessRouteItem.getIsQuality())) {
+ Product product = productMapper.selectById(productModel.getProductId());
+ if (product == null) {
+ throw new ServiceException("璐ㄦ浜у搧涓嶅瓨鍦�");
+ }
+
int inspectType = 1;
- String process = productProcess.getName();//宸ュ簭
- if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) {
- //鏈�鍚庝竴閬撳伐搴忕敓鎴愬嚭鍘傛
+ String process = productProcess.getName();
+
+ if (reportStockRule.finishedGoodsStockIn) {
inspectType = 2;
process = null;
}
- Product product = productMapper.selectById(productModel.getProductId());
+
QualityInspect qualityInspect = new QualityInspect();
qualityInspect.setProductId(product.getId());
qualityInspect.setProductName(product.getProductName());
qualityInspect.setModel(productModel.getModel());
qualityInspect.setUnit(productModel.getUnit());
- qualityInspect.setQuantity(productQty);
+ qualityInspect.setQuantity(reportQty);
qualityInspect.setProcess(process);
qualityInspect.setInspectState(0);
qualityInspect.setInspectType(inspectType);
- qualityInspect.setDefectiveQuantity(BigDecimal.ZERO);
+ qualityInspect.setDefectiveQuantity(scrapQty);
qualityInspect.setProductMainId(productionProductMain.getId());
qualityInspect.setProductModelId(productModel.getId());
qualityInspectMapper.insert(qualityInspect);
- List<QualityTestStandard> qualityTestStandard = qualityTestStandardMapper.getQualityTestStandardByProductId(product.getId(), inspectType, process);
- if (qualityTestStandard.size() > 0) {
- qualityInspect.setTestStandardId(qualityTestStandard.get(0).getId());
+
+ List<QualityTestStandard> qualityTestStandardList =
+ qualityTestStandardMapper.getQualityTestStandardByProductId(product.getId(), inspectType, process);
+
+ if (CollectionUtils.isNotEmpty(qualityTestStandardList)) {
+ QualityTestStandard qualityTestStandard = qualityTestStandardList.get(0);
+ qualityInspect.setTestStandardId(qualityTestStandard.getId());
qualityInspectMapper.updateById(qualityInspect);
- qualityTestStandardParamMapper.selectList(Wrappers.<QualityTestStandardParam>lambdaQuery()
- .eq(QualityTestStandardParam::getTestStandardId, qualityTestStandard.get(0).getId()))//榛樿鑾峰彇鏈�鏂扮殑
- .forEach(qualityTestStandardParam -> {
- QualityInspectParam param = new QualityInspectParam();
- BeanUtils.copyProperties(qualityTestStandardParam, param);
- param.setId(null);
- param.setInspectId(qualityInspect.getId());
- qualityInspectParamMapper.insert(param);
- });
+
+ qualityTestStandardParamMapper.selectList(
+ Wrappers.<QualityTestStandardParam>lambdaQuery()
+ .eq(QualityTestStandardParam::getTestStandardId, qualityTestStandard.getId())
+ ).forEach(qualityTestStandardParam -> {
+ QualityInspectParam param = new QualityInspectParam();
+ BeanUtils.copyProperties(qualityTestStandardParam, param);
+ param.setId(null);
+ param.setInspectId(qualityInspect.getId());
+ qualityInspectParamMapper.insert(param);
+ });
}
- }else {
- //鐩存帴鍏ュ簱
- //鏈�鍚庝竴閬撳伐搴忎负鎴愬搧
- if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) {
- //鎴愬搧瀹℃牳
- stockUtils.addStock(productProcessRouteItem.getProductModelId(), productQty, StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId());
- }else {
- //鍗婃垚鍝佷笉瀹℃牳
- stockUtils.addStockNoReview(productProcessRouteItem.getProductModelId(), productQty, StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId());
+ } else if (reportStockRule.createStockIn) {
+ //鎴愬搧鍏ュ簱闇�瑕佺數鍘嬶紝宸ュ簭绫诲埆锛堥摐锛岄摱锛�
+ if (reportStockRule.finishedGoodsStockIn) {
+ String processCategory =
+ finishedProductStockDimensionResolver.resolveProcessCategory(productionProductMain.getId());
+ String voltage =
+ finishedProductStockDimensionResolver.resolveVoltage(productionProductMain.getId());
+
+ stockUtils.addStock(
+ productProcessRouteItem.getProductModelId(),
+ qualifiedQty,
+ StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(),
+ productionProductMain.getId(),
+ processCategory,
+ voltage
+ );
+ } else {
+ stockUtils.addStockNoReview(
+ productProcessRouteItem.getProductModelId(),
+ qualifiedQty,
+ StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(),
+ productionProductMain.getId()
+ );
}
}
- /*鏇存柊宸ュ崟鍜岀敓浜ц鍗�*/
- productWorkOrder.setCompleteQuantity(productWorkOrder.getCompleteQuantity().add(productQty));
+
+ // 绗崄姝ワ細鏇存柊宸ュ崟銆佽鍗曞畬鎴愯繘搴﹀拰璁′欢鏍哥畻鏁版嵁
+ BigDecimal workOrderCompleteQuantity =
+ productWorkOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productWorkOrder.getCompleteQuantity();
+ productWorkOrder.setCompleteQuantity(workOrderCompleteQuantity.add(qualifiedQty));
+
if (ObjectUtils.isNull(productWorkOrder.getActualStartTime())) {
- productWorkOrder.setActualStartTime(LocalDate.now());//瀹為檯寮�濮嬫椂闂�
+ productWorkOrder.setActualStartTime(LocalDate.now());
}
- if (productWorkOrder.getCompleteQuantity().compareTo(productWorkOrder.getPlanQuantity()) == 0) {
- productWorkOrder.setActualEndTime(LocalDate.now());//瀹為檯缁撴潫鏃堕棿
+ if (productWorkOrder.getPlanQuantity() != null
+ && productWorkOrder.getCompleteQuantity().compareTo(productWorkOrder.getPlanQuantity()) >= 0) {
+ productWorkOrder.setActualEndTime(LocalDate.now());
}
productWorkOrderMapper.updateById(productWorkOrder);
- //鐢熶骇璁㈠崟
+
if (ObjectUtils.isNull(productOrder.getStartTime())) {
- productOrder.setStartTime(LocalDateTime.now());//寮�濮嬫椂闂�
+ productOrder.setStartTime(LocalDateTime.now());
}
- if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) {
- //濡傛灉鏄渶鍚庝竴閬撳伐搴忔姤宸ヤ箣鍚庣敓浜ц鍗曞畬鎴愭暟閲�+
- productOrder.setCompleteQuantity(productOrder.getCompleteQuantity().add(productQty));
- if (productOrder.getCompleteQuantity().compareTo(productOrder.getQuantity()) == 0) {
- productOrder.setEndTime(LocalDateTime.now());//缁撴潫鏃堕棿
+
+ if (isRouteLastProcess) {
+ BigDecimal orderCompleteQuantity =
+ productOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productOrder.getCompleteQuantity();
+ productOrder.setCompleteQuantity(orderCompleteQuantity.add(qualifiedQty));
+
+ if (productOrder.getQuantity() != null
+ && productOrder.getCompleteQuantity().compareTo(productOrder.getQuantity()) >= 0) {
+ productOrder.setEndTime(LocalDateTime.now());
}
}
productOrderMapper.updateById(productOrder);
- /*娣诲姞鐢熶骇鏍哥畻*/
- SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder()
- .productMainId(productionProductMain.getId())
- .schedulingUserId(user.getUserId())
- .schedulingUserName(user.getNickName())
- .finishedNum(productQty)
- .workHours(productProcess.getSalaryQuota())
- .process(productProcess.getName())
- .schedulingDate(LocalDate.now())
- .tenantId(dto.getTenantId())
- .build();
+
+ SalesLedgerProductionAccounting salesLedgerProductionAccounting =
+ SalesLedgerProductionAccounting.builder()
+ .productMainId(productionProductMain.getId())
+ .schedulingUserId(userId)
+ .schedulingUserName(userName)
+ .finishedNum(qualifiedQty)
+ .workHours(productProcess.getSalaryQuota())
+ .process(productProcess.getName())
+ .schedulingDate(LocalDate.now())
+ .tenantId(dto.getTenantId())
+ .build();
salesLedgerProductionAccountingMapper.insert(salesLedgerProductionAccounting);
}
- //濡傛灉鎶ュ簾鏁伴噺>0,闇�瑕佽繘鍏ユ姤搴熺殑搴撳瓨
- if (ObjectUtils.isNotEmpty(dto.getScrapQty())) {
- if (dto.getScrapQty().compareTo(BigDecimal.ZERO) > 0) {
- if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()){
- stockUtils.addUnStock(productModel.getId(), dto.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId());
- }else {
- stockUtils.addUnStockNoReview(productModel.getId(), dto.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId());
- }
- }
- }
+
+ // 绗崄涓�姝ワ細缁熶竴澶勭悊鎶ュ簾鏁伴噺鍏ヤ笉鍚堟牸搴撳瓨锛岄伩鍏嶅湪涓绘祦绋嬩腑閲嶅鍏ュ簱
+ handleScrapStock(productModel.getId(), scrapQty, isRouteLastProcess, productionProductMain.getId());
+
return true;
+ }
+
+ // 鍒ゆ柇褰撳墠鎶ュ伐鏄惁闇�瑕佸叆搴擄紝浠ュ強鏄惁鎸夋垚鍝佸叆搴撳鐞�
+ private ReportStockRule resolveReportStockRule(ProductProcessRouteItem currentRouteItem,
+ ProductProcess currentProcess,
+ List<ProductProcessRouteItem> routeItems) {
+ Integer maxDragSort = CollectionUtils.isEmpty(routeItems)
+ ? null
+ : routeItems.stream()
+ .map(ProductProcessRouteItem::getDragSort)
+ .filter(Objects::nonNull)
+ .max(Integer::compareTo)
+ .orElse(null);
+
+ boolean isRouteLastProcess = Objects.equals(currentRouteItem.getDragSort(), maxDragSort);
+ String currentProcessName = currentProcess == null || currentProcess.getName() == null
+ ? ""
+ : currentProcess.getName().trim();
+
+ if (PROCESS_VOLTAGE_SORT.equals(currentProcessName)) {
+ return new ReportStockRule(false, false);
+ }
+
+ Set<Long> processIds = CollectionUtils.isEmpty(routeItems)
+ ? Collections.emptySet()
+ : routeItems.stream()
+ .map(ProductProcessRouteItem::getProcessId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Map<Long, String> processNameMap = new HashMap<>();
+ if (CollectionUtils.isNotEmpty(processIds)) {
+ processNameMap = productProcessMapper.selectBatchIds(processIds)
+ .stream()
+ .collect(Collectors.toMap(
+ ProductProcess::getId,
+ process -> process.getName() == null ? "" : process.getName().trim(),
+ (a, b) -> a
+ ));
+ }
+
+ Set<String> routeProcessNames = CollectionUtils.isEmpty(routeItems)
+ ? Collections.emptySet()
+ : routeItems.stream()
+ .map(ProductProcessRouteItem::getProcessId)
+ .map(processNameMap::get)
+ .filter(StringUtils::isNotBlank)
+ .collect(Collectors.toSet());
+
+ boolean hasVoltageSort = routeProcessNames.contains(PROCESS_VOLTAGE_SORT);
+ boolean hasOpticalInspection = routeProcessNames.contains(PROCESS_OPTICAL_INSPECTION);
+ boolean hasPackaging = routeProcessNames.contains(PROCESS_PACKAGING);
+
+ if (hasPackaging && PROCESS_PACKAGING.equals(currentProcessName)) {
+ return new ReportStockRule(true, true);
+ }
+
+ if (hasPackaging && PROCESS_OPTICAL_INSPECTION.equals(currentProcessName)) {
+ return new ReportStockRule(false, false);
+ }
+
+ if (!hasPackaging
+ && hasVoltageSort
+ && hasOpticalInspection
+ && PROCESS_OPTICAL_INSPECTION.equals(currentProcessName)) {
+ return new ReportStockRule(true, true);
+ }
+
+ return new ReportStockRule(true, isRouteLastProcess);
+ }
+
+ // 缁熶竴澶勭悊鎶ュ簾鏁伴噺鍏ヤ笉鍚堟牸搴撳瓨锛岄伩鍏嶉噸澶嶅叆搴�
+ private void handleScrapStock(Long productModelId,
+ BigDecimal scrapQty,
+ boolean isRouteLastProcess,
+ Long productMainId) {
+ if (productModelId == null) {
+ throw new ServiceException("鎶ュ簾浜у搧鍨嬪彿涓嶈兘涓虹┖");
+ }
+
+ if (scrapQty == null || scrapQty.compareTo(BigDecimal.ZERO) <= 0) {
+ return;
+ }
+
+ if (isRouteLastProcess) {
+ stockUtils.addUnStock(
+ productModelId,
+ scrapQty,
+ StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(),
+ productMainId
+ );
+ } else {
+ stockUtils.addUnStockNoReview(
+ productModelId,
+ scrapQty,
+ StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(),
+ productMainId
+ );
+ }
+ }
+
+ // 鍗曟鎶ュ伐瀵瑰簲鐨勫叆搴撹鍒�
+ private static final class ReportStockRule {
+ private final boolean createStockIn;
+ private final boolean finishedGoodsStockIn;
+
+ private ReportStockRule(boolean createStockIn, boolean finishedGoodsStockIn) {
+ this.createStockIn = createStockIn;
+ this.finishedGoodsStockIn = finishedGoodsStockIn;
+ }
}
@Override
public Boolean removeProductMain(Long id) {
- //鍒ゆ柇璇ユ潯鎶ュ伐鏄惁涓嶅悎鏍煎鐞�,濡傛灉涓嶅悎鏍煎鐞嗕簡锛屽垯涓嶅厑璁稿垹闄�
- List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(Wrappers.<QualityInspect>lambdaQuery().eq(QualityInspect::getProductMainId, id));
- if (qualityInspects.size() > 0){
- List<QualityUnqualified> qualityUnqualifieds = qualityUnqualifiedMapper.selectList(Wrappers.<QualityUnqualified>lambdaQuery()
- .in(QualityUnqualified::getInspectId, qualityInspects.stream().map(QualityInspect::getId).collect(Collectors.toList())));
- if (qualityUnqualifieds.size() > 0 && qualityUnqualifieds.get(0).getInspectState()==1) {
- throw new ServiceException("璇ユ潯鎶ュ伐宸茬粡涓嶅悎鏍煎鐞嗕簡锛屼笉鍏佽鍒犻櫎");
+ // 鍒犻櫎鎶ュ伐鍓嶅厛妫�鏌ユ槸鍚﹀凡缁忓畬鎴愪笉鍚堟牸澶勭悊
+ List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(
+ Wrappers.<QualityInspect>lambdaQuery().eq(QualityInspect::getProductMainId, id)
+ );
+ if (!qualityInspects.isEmpty()) {
+ List<QualityUnqualified> qualityUnqualifieds = qualityUnqualifiedMapper.selectList(
+ Wrappers.<QualityUnqualified>lambdaQuery()
+ .in(QualityUnqualified::getInspectId, qualityInspects.stream().map(QualityInspect::getId).collect(Collectors.toList()))
+ );
+ if (!qualityUnqualifieds.isEmpty() && qualityUnqualifieds.get(0).getInspectState() == 1) {
+ throw new ServiceException("璇ユ姤宸ュ凡瀹屾垚涓嶅悎鏍煎鐞嗭紝涓嶈兘鍒犻櫎");
}
}
+
ProductionProductMain productionProductMain = productionProductMainMapper.selectById(id);
- //璇ユ姤宸ュ搴旂殑宸ヨ壓璺嚎璇︽儏
ProductProcessRouteItem productProcessRouteItem = productProcessRouteItemMapper.selectById(productionProductMain.getProductProcessRouteItemId());
- ProductionProductOutput productionProductOutput = productionProductOutputMapper.selectList(Wrappers.<ProductionProductOutput>lambdaQuery().eq(ProductionProductOutput::getProductMainId, productionProductMain.getId())).get(0);
- /*鍒犻櫎鏍哥畻*/
+ ProductionProductOutput productionProductOutput = productionProductOutputMapper.selectList(
+ Wrappers.<ProductionProductOutput>lambdaQuery().eq(ProductionProductOutput::getProductMainId, productionProductMain.getId())
+ ).get(0);
+
salesLedgerProductionAccountingMapper.delete(
new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
.eq(SalesLedgerProductionAccounting::getProductMainId, productionProductMain.getId())
);
- /*鏇存柊宸ュ崟鍜岀敓浜ц鍗�*/
+
ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(productionProductMain.getWorkOrderId());
if (productWorkOrder != null && productionProductOutput != null) {
BigDecimal outputQty = productionProductOutput.getQuantity() == null ? BigDecimal.ZERO : productionProductOutput.getQuantity();
@@ -335,16 +662,19 @@
BigDecimal completeQty = productWorkOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productWorkOrder.getCompleteQuantity();
BigDecimal validQuantity = outputQty.subtract(scrapQty);
-
productWorkOrder.setCompleteQuantity(completeQty.subtract(validQuantity));
productWorkOrder.setActualEndTime(null);
productWorkOrderMapper.updateById(productWorkOrder);
} else {
throw new ServiceException("鎿嶄綔澶辫触锛氬伐鍗曚俊鎭垨浜у嚭璁板綍涓嶅瓨鍦�");
}
- //鍒ゆ柇鏄惁鏄渶鍚庝竴閬撳伐搴�
- List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(Wrappers.<ProductProcessRouteItem>lambdaQuery().eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId()));
- if (productProcessRouteItem.getDragSort() != null && productProcessRouteItems != null && productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) {
+
+ List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(
+ Wrappers.<ProductProcessRouteItem>lambdaQuery().eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId())
+ );
+ if (productProcessRouteItem.getDragSort() != null
+ && productProcessRouteItems != null
+ && productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) {
ProductOrder productOrder = productOrderMapper.selectById(productWorkOrder.getProductOrderId());
if (productOrder != null) {
BigDecimal orderCompleteQty = productOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productOrder.getCompleteQuantity();
@@ -359,31 +689,30 @@
throw new ServiceException("鍏宠仈鐨勭敓浜ц鍗曚笉瀛樺湪");
}
}
- //鍒犻櫎璐ㄦ
+
qualityInspectMapper.selectList(
new LambdaQueryWrapper<QualityInspect>()
.eq(QualityInspect::getProductMainId, productionProductMain.getId())
).forEach(q -> {
qualityInspectParamMapper.delete(
new LambdaQueryWrapper<QualityInspectParam>()
- .eq(QualityInspectParam::getInspectId, q.getId()));
+ .eq(QualityInspectParam::getInspectId, q.getId())
+ );
qualityInspectMapper.deleteById(q.getId());
- stockUtils.deleteStockInRecord(q.getId(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode());
+ stockUtils.deleteStockInRecord(q.getId(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode());
});
- // 鍒犻櫎浜у嚭璁板綍
- productionProductOutputMapper.delete(new LambdaQueryWrapper<ProductionProductOutput>()
- .eq(ProductionProductOutput::getProductMainId, productionProductMain.getId()));
- //鍒犻櫎鎶曞叆璁板綍
- productionProductInputMapper.delete(new LambdaQueryWrapper<ProductionProductInput>()
- .eq(ProductionProductInput::getProductMainId, productionProductMain.getId()));
- //鍒犻櫎鎶ュ簾鐨勫叆搴撹褰�
+ productionProductOutputMapper.delete(
+ new LambdaQueryWrapper<ProductionProductOutput>()
+ .eq(ProductionProductOutput::getProductMainId, productionProductMain.getId())
+ );
+ productionProductInputMapper.delete(
+ new LambdaQueryWrapper<ProductionProductInput>()
+ .eq(ProductionProductInput::getProductMainId, productionProductMain.getId())
+ );
stockUtils.deleteStockInRecord(productionProductMain.getId(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode());
- //鍒犻櫎涓嶉渶瑕佽川妫�鐨勫悎鏍煎叆搴�
stockUtils.deleteStockInRecord(productionProductMain.getId(), StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode());
- //鍒犻櫎鎶曞叆瀵瑰簲鐨勫嚭搴撹褰�
stockUtils.deleteStockOutRecord(productionProductMain.getId(), StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode());
- // 鍒犻櫎涓昏〃
productionProductMainMapper.deleteById(productionProductMain.getId());
return true;
}
@@ -396,49 +725,39 @@
@Override
public List<ProductionProductMainDto> getByProductWorkOrderId(Long productWorkOrderId) {
List<ProductionProductMainDto> productionProductMainDtos = productionProductMainMapper.getByProductWorkOrderId(productWorkOrderId);
-
if (productionProductMainDtos == null || productionProductMainDtos.isEmpty()) {
return productionProductMainDtos;
}
-
- // 鏀堕泦鎵�鏈変骇鍝佷富璁板綍ID
+
List<Long> productMainIds = productionProductMainDtos.stream()
.map(ProductionProductMainDto::getId)
.collect(Collectors.toList());
-
- // 鎵归噺鏌ヨ鎵�鏈夌浉鍏崇殑璐ㄦ璁板綍
+
List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(
Wrappers.<QualityInspect>lambdaQuery()
.in(QualityInspect::getProductMainId, productMainIds)
);
-
+
if (!qualityInspects.isEmpty()) {
- // 鏀堕泦鎵�鏈夎川妫�璁板綍ID
List<Long> inspectIds = qualityInspects.stream()
.map(QualityInspect::getId)
.collect(Collectors.toList());
-
- // 鎵归噺鏌ヨ鎵�鏈夌浉鍏崇殑涓嶅悎鏍煎鐞嗚褰�
+
List<QualityUnqualified> qualityUnqualifieds = qualityUnqualifiedMapper.selectList(
Wrappers.<QualityUnqualified>lambdaQuery()
.in(QualityUnqualified::getInspectId, inspectIds)
);
-
- // 鏋勫缓璐ㄦID鍒颁笉鍚堟牸澶勭悊璁板綍鐨勬槧灏�
+
Map<Long, QualityUnqualified> inspectIdToUnqualifiedMap = qualityUnqualifieds.stream()
.collect(Collectors.toMap(QualityUnqualified::getInspectId, q -> q, (q1, q2) -> q1));
-
- // 鏋勫缓浜у搧涓籌D鍒拌川妫�璁板綍鐨勬槧灏�
+
Map<Long, QualityInspect> productMainIdToInspectMap = qualityInspects.stream()
.collect(Collectors.toMap(QualityInspect::getProductMainId, q -> q, (q1, q2) -> q1));
-
- // 鍏宠仈澶勭悊缁撴灉鍒颁骇鍝佷富璁板綍
+
productionProductMainDtos.forEach(p -> {
QualityInspect qualityInspect = productMainIdToInspectMap.get(p.getId());
if (qualityInspect != null) {
- // 涓嶈壇鏁伴噺
- p.setDefectiveQuantity( qualityInspect.getDefectiveQuantity());
- // 鍚堟牸鏁伴噺 = 鎶ュ伐鏁伴噺-鎶ュ簾鏁伴噺-涓嶈壇鏁伴噺
+ p.setDefectiveQuantity(qualityInspect.getDefectiveQuantity());
p.setQualifiedQty(p.getQuantity().subtract(p.getScrapQty()).subtract(p.getDefectiveQuantity()));
QualityUnqualified qualityUnqualified = inspectIdToUnqualifiedMap.get(qualityInspect.getId());
if (qualityUnqualified != null) {
@@ -447,7 +766,90 @@
}
});
}
-
+
return productionProductMainDtos;
}
-}
\ No newline at end of file
+
+ private BigDecimal resolveInputWeight(String otherData) {
+ if (StringUtils.isBlank(otherData)) {
+ return null;
+ }
+ Object parsed;
+ try {
+ parsed = JSON.parse(otherData);
+ } catch (Exception ex) {
+ throw new ServiceException("鎶ュ伐鍙傛暟鏍煎紡閿欒锛屾棤娉曡В鏋愭姇鍏ラ噸閲�/鏁伴噺");
+ }
+ String inputWeight = StringUtils.trim(findParameterValue(parsed, INPUT_WEIGHT_PARAMETER));
+ if (StringUtils.isBlank(inputWeight)) {
+ inputWeight = StringUtils.trim(findFieldValue(parsed, INPUT_WEIGHT_FIELD));
+ }
+ if (StringUtils.isBlank(inputWeight)) {
+ return null;
+ }
+ try {
+ return new BigDecimal(inputWeight);
+ } catch (NumberFormatException ex) {
+ throw new ServiceException("鎶ュ伐鍙傛暟涓殑鎶曞叆閲嶉噺/鏁伴噺鏍煎紡閿欒");
+ }
+ }
+
+ private String findParameterValue(Object node, String parameterItem) {
+ if (node instanceof JSONArray) {
+ JSONArray array = (JSONArray) node;
+ for (Object item : array) {
+ String value = findParameterValue(item, parameterItem);
+ if (StringUtils.isNotBlank(value)) {
+ return value;
+ }
+ }
+ return null;
+ }
+ if (node instanceof JSONObject) {
+ JSONObject object = (JSONObject) node;
+ if (parameterItem.equals(StringUtils.trim(object.getString("parameterItem")))) {
+ String value = StringUtils.trim(object.getString("value"));
+ if (StringUtils.isNotBlank(value)) {
+ return value;
+ }
+ }
+ for (Object value : object.values()) {
+ String matched = findParameterValue(value, parameterItem);
+ if (StringUtils.isNotBlank(matched)) {
+ return matched;
+ }
+ }
+ }
+ return null;
+ }
+
+ private String findFieldValue(Object node, String fieldName) {
+ if (node instanceof JSONArray) {
+ JSONArray array = (JSONArray) node;
+ for (Object item : array) {
+ String value = findFieldValue(item, fieldName);
+ if (StringUtils.isNotBlank(value)) {
+ return value;
+ }
+ }
+ return null;
+ }
+ if (node instanceof JSONObject) {
+ JSONObject object = (JSONObject) node;
+ Object fieldValue = object.get(fieldName);
+ if (fieldValue != null) {
+ String value = StringUtils.trim(String.valueOf(fieldValue));
+ if (StringUtils.isNotBlank(value)) {
+ return value;
+ }
+ }
+ for (Object value : object.values()) {
+ String matched = findFieldValue(value, fieldName);
+ if (StringUtils.isNotBlank(matched)) {
+ return matched;
+ }
+ }
+ }
+ return null;
+ }
+}
--
Gitblit v1.9.3