From ff361539e3ffd6e62100e392ddda2f4ab9dfee62 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 27 五月 2026 13:15:42 +0800
Subject: [PATCH] 工序调整, 报工反改订单数量,判断是最后一道工序才修改订单完成数量
---
src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java | 260 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 232 insertions(+), 28 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
index 71e41ce..60b3dc2 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
@@ -1,14 +1,21 @@
package com.ruoyi.production.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.basic.pojo.Product;
+import com.ruoyi.basic.pojo.ProductModel;
+import com.ruoyi.basic.service.IProductModelService;
+import com.ruoyi.basic.service.IProductService;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.DictUtils;
+import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.dto.ProductProcessDto;
+import com.ruoyi.production.dto.ProductProcessImportDto;
import com.ruoyi.production.mapper.ProcessRouteItemMapper;
import com.ruoyi.production.mapper.ProductProcessMapper;
import com.ruoyi.production.mapper.ProductProcessRouteItemMapper;
@@ -16,22 +23,43 @@
import com.ruoyi.production.pojo.ProductProcess;
import com.ruoyi.production.pojo.ProductProcessRouteItem;
import com.ruoyi.production.service.ProductProcessService;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.mapper.SysUserMapper;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
+import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
+@Slf4j
@Service
-public class ProductProcessServiceImpl extends ServiceImpl<ProductProcessMapper, ProductProcess> implements ProductProcessService {
+public class ProductProcessServiceImpl extends ServiceImpl<ProductProcessMapper, ProductProcess>
+ implements ProductProcessService {
+
@Autowired
private ProductProcessMapper productProcessMapper;
+
@Autowired
private ProcessRouteItemMapper processRouteItemMapper;
+
@Autowired
private ProductProcessRouteItemMapper productProcessRouteItemMapper;
+
+ @Autowired
+ private IProductModelService productModelService;
+
+ @Autowired
+ private IProductService productService;
+
+ @Autowired
+ private SysUserMapper sysUserMapper;
@Override
public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) {
@@ -39,46 +67,222 @@
}
@Override
- public AjaxResult add(ProductProcessDto productProcessDto) {
+ @Transactional(rollbackFor = Exception.class)
+ public void add(ProductProcessDto productProcessDto) {
+ if (ObjectUtils.isEmpty(productProcessDto.getName())) {
+ throw new ServiceException("閮ㄤ欢鍚嶇О涓嶈兘涓虹┖");
+ }
+
+ if (ObjectUtils.isNotEmpty(productProcessDto.getNo())) {
+ long noCount = this.count(Wrappers.<ProductProcess>lambdaQuery().eq(ProductProcess::getNo, productProcessDto.getNo()));
+ if (noCount > 0) {
+ throw new ServiceException("宸ュ簭缂栧彿宸插瓨鍦紝涓嶈兘閲嶅");
+ }
+ }
+ // 鍒ゆ柇璁″垝宸ユ椂鏄惁涓虹┖
+ if (ObjectUtils.isEmpty(productProcessDto.getSalaryQuota())) {
+ throw new ServiceException("鏂板澶辫触,璁″垝宸ユ椂涓嶈兘涓虹┖");
+ }
+ // 鍒ゆ柇浜у搧鏄惁瀛樺湪
+// if (ObjectUtils.isEmpty(productProcessDto.getProductModelId())) {
+// throw new ServiceException("鏂板澶辫触,閮ㄤ欢涓嶈兘涓虹┖");
+// }
+// ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId());
+// if (productModel == null) {
+// throw new ServiceException("鏂板澶辫触,璇ラ儴浠朵笉瀛樺湪");
+// }
+// validateDuplicateTypeForSameProduct(productModel.getId(), productProcessDto.getType(), null);
+
ProductProcess productProcess = new ProductProcess();
- BeanUtils.copyProperties(productProcessDto,productProcess);
+ BeanUtils.copyProperties(productProcessDto, productProcess);
+// productProcess.setProductModelId(productModel.getId());
+
+ validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null);
+
boolean save = productProcessMapper.insert(productProcess) > 0;
- if (save && ObjectUtils.isNull(productProcessDto.getNo())) {
- // 鏍规嵁id鐢熸垚no瀛楁锛欸X + 8浣嶆暟瀛楋紙涓嶈冻8浣嶅墠闈㈣ˉ0锛�
+ if (save && ObjectUtils.isEmpty(productProcess.getNo())) {
String no = "GX" + String.format("%08d", productProcess.getId());
productProcess.setNo(no);
-
productProcessMapper.updateById(productProcess);
- return AjaxResult.success();
}
- return AjaxResult.success();
}
@Override
- public AjaxResult importData(MultipartFile file) {
- try {
- ExcelUtil<ProductProcess> util = new ExcelUtil<ProductProcess>(ProductProcess.class);
- List<ProductProcess> productProcessList = util.importExcel(file.getInputStream());
- if(CollectionUtils.isEmpty(productProcessList)){
- return AjaxResult.warn("妯℃澘閿欒鎴栧鍏ユ暟鎹负绌�");
+ @Transactional(rollbackFor = Exception.class)
+ public void update(ProductProcessDto productProcessDto) {
+ if (ObjectUtils.isEmpty(productProcessDto.getId())) {
+ throw new ServiceException("淇敼澶辫触锛屽伐搴廔D涓嶈兘涓虹┖");
+ }
+ if (ObjectUtils.isEmpty(productProcessDto.getName())) {
+ throw new ServiceException("閮ㄤ欢鍚嶇О涓嶈兘涓虹┖");
+ }
+ if (ObjectUtils.isNotEmpty(productProcessDto.getNo())) {
+ long noCount = this.count(Wrappers.<ProductProcess>lambdaQuery()
+ .eq(ProductProcess::getNo, productProcessDto.getNo())
+ .ne(ProductProcess::getId, productProcessDto.getId()));
+ if (noCount > 0) {
+ throw new ServiceException("宸ュ簭缂栧彿宸插瓨鍦紝涓嶈兘閲嶅");
}
- this.saveOrUpdateBatch(productProcessList);
- return AjaxResult.success(true);
- }catch (Exception e){
- e.printStackTrace();
- return AjaxResult.error("瀵煎叆澶辫触");
+ }
+
+ ProductProcess oldProductProcess = this.getById(productProcessDto.getId());
+ if (oldProductProcess == null) {
+ throw new ServiceException("淇敼澶辫触锛屽伐搴忎笉瀛樺湪");
+ }
+// Long finalProductModelId = ObjectUtils.isNotEmpty(productProcessDto.getProductModelId())
+// ? productProcessDto.getProductModelId() : oldProductProcess.getProductModelId();
+// Integer finalType = ObjectUtils.isNotEmpty(productProcessDto.getType())
+// ? productProcessDto.getType() : oldProductProcess.getType();
+//
+ // 鍒ゆ柇鍏宠仈浜у搧鏄惁瀛樺湪
+// ProductModel productModel = productModelService.getById(finalProductModelId);
+// if (productModel == null) {
+// throw new ServiceException("淇敼澶辫触锛屽叧鑱旈儴浠朵笉瀛樺湪");
+// }
+// validateDuplicateTypeForSameProduct(productModel.getId(), finalType, productProcessDto.getId());
+
+ // 鏍¢獙璁″垝浜哄憳
+ validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null);
+
+ ProductProcess productProcess = new ProductProcess();
+ BeanUtils.copyProperties(productProcessDto, productProcess);
+ this.updateById(productProcess);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void importData(MultipartFile file) {
+ try {
+ ExcelUtil<ProductProcessImportDto> util = new ExcelUtil<>(ProductProcessImportDto.class);
+ List<ProductProcessImportDto> importList = util.importExcel(file.getInputStream());
+ if (CollectionUtils.isEmpty(importList)) {
+ throw new ServiceException("妯℃澘閿欒鎴栧鍏ユ暟鎹负绌�");
+ }
+
+ List<ProductProcess> productProcessList = new ArrayList<>();
+ for (int i = 0; i < importList.size(); i++) {
+ ProductProcessImportDto importDto = importList.get(i);
+ int rowNum = i + 2;
+ SysUser sysUser = null;
+
+ if (ObjectUtils.isEmpty(importDto)) {
+ throw new ServiceException("绗�" + rowNum + "琛屾暟鎹负绌猴紝璇蜂娇鐢ㄦ纭殑妯℃澘杩涜瀵煎叆");
+ }
+ if (ObjectUtils.isEmpty(importDto.getName())) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢鍚嶇О涓嶈兘涓虹┖");
+ }
+ if (ObjectUtils.isEmpty(importDto.getProductModel())) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢瑙勬牸涓嶈兘涓虹┖");
+ }
+ // 妫�楠屼骇鍝佷笌绫诲瀷鏄惁瀛樺湪
+ Product product = productService.getOne(new LambdaQueryWrapper<Product>().eq(Product::getProductName, importDto.getName()));
+ if (product == null) {
+ throw new ServiceException("绗�" + rowNum + "琛�: 閮ㄤ欢銆�" + importDto.getName() + "銆戜笉瀛樺湪");
+ }
+ ProductModel productModel = productModelService.getOne(new LambdaQueryWrapper<ProductModel>().eq(ProductModel::getProductId, product.getId()).eq(ProductModel::getModel, importDto.getProductModel()));
+ if (ObjectUtils.isEmpty(productModel)) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢瑙勬牸銆�" + importDto.getProductModel() + "銆戜笉瀛樺湪");
+ }
+
+ if (ObjectUtils.isEmpty(importDto.getProductProcessType())) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢銆�" + importDto.getName() + "銆戠殑绫诲瀷涓嶈兘涓虹┖");
+ }
+ String dictValue = DictUtils.getDictValue("product_process_type", importDto.getProductProcessType());
+ if (StringUtils.isEmpty(dictValue)) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢銆�" + importDto.getName() + "銆戠殑绫诲瀷銆�"
+ + importDto.getProductProcessType() + "銆戜笉瀛樺湪锛岃濉啓姝g‘鐨勭被鍨嬶細" + DictUtils.getDictLabels("product_process_type"));
+ }
+ // 妫�楠岃鍒掑伐鏃�
+ if (importDto.getSalaryQuota() == null || importDto.getSalaryQuota().compareTo(BigDecimal.ZERO) < 0) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細璁″垝宸ユ椂涓嶈兘涓虹┖涓庤礋鏁�");
+ }
+ // 妫�楠岃鍒掍汉鍛�
+ if (StringUtils.isNotEmpty(importDto.getPlannerName())) {
+ sysUser = sysUserMapper.selectUserByNickName(importDto.getPlannerName());
+ if (ObjectUtils.isEmpty(sysUser)) {
+ throw new ServiceException("绗�" + rowNum + "琛岋細璁″垝浜哄憳銆�" + importDto.getPlannerName() + "銆戜笉瀛樺湪");
+ }
+ }
+
+ ProductProcess productProcess = new ProductProcess();
+ BeanUtils.copyProperties(importDto, productProcess);
+ productProcess.setProductModelId(productModel.getId());
+ productProcess.setType(Integer.valueOf(dictValue));
+ if (sysUser != null) {
+ productProcess.setPlannerId(sysUser.getUserId());
+ productProcess.setPlannerName(sysUser.getNickName());
+ }
+ productProcessList.add(productProcess);
+ }
+
+ saveOrUpdateBatch(productProcessList);
+ } catch (ServiceException e) {
+ throw e;
+ } catch (Exception e) {
+ log.error("閮ㄤ欢瀵煎叆寮傚父:{}", e.getMessage(), e);
+ throw new ServiceException("閮ㄤ欢瀵煎叆寮傚父锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 鏍¢獙璁″垝浜哄憳鏄惁瀛樺湪
+ *
+ * @param plannerId 璁″垝浜哄憳ID
+ * @param plannerName 璁″垝浜哄憳濮撳悕
+ * @param rowNum 琛屽彿
+ */
+ private void validatePlanner(Long plannerId, String plannerName, Integer rowNum) {
+ String prefix = rowNum != null ? "绗�" + rowNum + "琛岋細" : "";
+ if (plannerId != null) {
+ if (sysUserMapper.selectUserById(plannerId) == null) {
+ throw new ServiceException(prefix + "璁″垝浜哄憳ID銆�" + plannerId + "銆戜笉瀛樺湪");
+ }
+ } else if (ObjectUtils.isNotEmpty(plannerName)) {
+ if (sysUserMapper.selectUserByNickName(plannerName) == null) {
+ throw new ServiceException(prefix + "璁″垝浜哄憳濮撳悕銆�" + plannerName + "銆戜笉瀛樺湪");
+ }
+ }
+ }
+
+ /**
+ * 鏍¢獙鍚屼竴浜у搧涓嬪伐搴忕被鍨嬩笉鑳介噸澶�
+ */
+ private void validateDuplicateTypeForSameProduct(Long productModelId, Integer type, Long excludeId) {
+ if (productModelId == null || type == null) {
+ return;
+ }
+ ProductModel currentModel = productModelService.getById(productModelId);
+ if (currentModel == null || currentModel.getProductId() == null) {
+ return;
+ }
+ List<ProductModel> productModels = productModelService.list(
+ Wrappers.<ProductModel>lambdaQuery().eq(ProductModel::getProductId, currentModel.getProductId()));
+ if (CollectionUtils.isEmpty(productModels)) {
+ return;
+ }
+ List<Long> productModelIds = productModels.stream().map(ProductModel::getId).collect(Collectors.toList());
+ LambdaQueryWrapper<ProductProcess> queryWrapper = Wrappers.<ProductProcess>lambdaQuery()
+ .in(ProductProcess::getProductModelId, productModelIds)
+ .eq(ProductProcess::getType, type);
+ if (excludeId != null) {
+ queryWrapper.ne(ProductProcess::getId, excludeId);
+ }
+ if (this.count(queryWrapper) > 0) {
+ throw new ServiceException("鎿嶄綔澶辫触锛屽悓涓�浜у搧涓嶈兘瀛樺湪閲嶅鐨勯儴浠剁被鍨�");
}
}
@Override
- public String batchDelete(List<Integer> ids) {
- //鏌ヨ鏄惁鐢熶骇涓凡缁忓紩鐢ㄤ簡杩欎簺宸ュ簭
- List<ProcessRouteItem> processRouteItems = processRouteItemMapper.selectList(Wrappers.<ProcessRouteItem>lambdaQuery().in(ProcessRouteItem::getProcessId, ids));
- List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(Wrappers.<ProductProcessRouteItem>lambdaQuery().in(ProductProcessRouteItem::getProcessId, ids));
- if (!CollectionUtils.isEmpty(processRouteItems) || !CollectionUtils.isEmpty(productProcessRouteItems)){
- throw new RuntimeException("璇ュ伐搴忓凡缁忚浣跨敤锛屾棤娉曞垹闄�");
+ @Transactional(rollbackFor = Exception.class)
+ public void batchDelete(List<Integer> ids) {
+ // 鏌ヨ鏄惁鐢熶骇涓凡缁忓紩鐢ㄤ簡杩欎簺宸ュ簭
+ List<ProcessRouteItem> processRouteItems = processRouteItemMapper
+ .selectList(Wrappers.<ProcessRouteItem>lambdaQuery().in(ProcessRouteItem::getProcessId, ids));
+ List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(
+ Wrappers.<ProductProcessRouteItem>lambdaQuery().in(ProductProcessRouteItem::getProcessId, ids));
+ if (!CollectionUtils.isEmpty(processRouteItems) || !CollectionUtils.isEmpty(productProcessRouteItems)) {
+ throw new ServiceException("璇ュ伐搴忓凡缁忚浣跨敤锛屾棤娉曞垹闄�");
}
productProcessMapper.deleteBatchIds(ids);
- return null;
}
}
--
Gitblit v1.9.3