From a372a11167f095bd70d1070d70ec36af56489898 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期五, 18 四月 2025 17:56:58 +0800
Subject: [PATCH] 人工上架任务修改
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/QlyIsptItemServiceImpl.java | 75 ++++++++++++++++++++++++++++++++-----
1 files changed, 64 insertions(+), 11 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/QlyIsptItemServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/QlyIsptItemServiceImpl.java
index f8bcbe2..4fbb4bf 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/QlyIsptItemServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/QlyIsptItemServiceImpl.java
@@ -6,17 +6,28 @@
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.manager.controller.params.IsptItemsParams;
import com.vincent.rsf.server.manager.controller.params.QlyInspectAndItem;
+import com.vincent.rsf.server.manager.entity.QlyInspect;
+import com.vincent.rsf.server.manager.enums.QlyIsptResult;
+import com.vincent.rsf.server.manager.enums.QlyIsptStatus;
import com.vincent.rsf.server.manager.mapper.QlyIsptItemMapper;
import com.vincent.rsf.server.manager.entity.QlyIsptItem;
+import com.vincent.rsf.server.manager.service.QlyInspectService;
import com.vincent.rsf.server.manager.service.QlyIsptItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.stream.Collectors;
@Service("qlyIsptItemService")
public class QlyIsptItemServiceImpl extends ServiceImpl<QlyIsptItemMapper, QlyIsptItem> implements QlyIsptItemService {
+
+ @Autowired
+ private QlyInspectService qlyInspectService;
/**
* @author Ryan
@@ -26,20 +37,62 @@
* @time 2025/4/1 09:40
*/
@Override
+ @Transactional(rollbackFor = Exception.class)
public boolean batchUpdate(IsptItemsParams params) {
- if (Objects.isNull(params.getIds()) || params.getIds().isEmpty()) {
+ if (Objects.isNull(params.getIsptItem()) || params.getIsptItem().isEmpty()) {
throw new CoolException("ID涓嶈兘涓虹┖锛侊紒");
}
- QlyIsptItem isptItem = params.getIsptItem();
- if (Objects.isNull(isptItem)) {
- throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛�");
+ List<QlyIsptItem> isptItem = params.getIsptItem();
+ List<Long> list = isptItem.stream().map(QlyIsptItem::getId).collect(Collectors.toList());
+ if (Short.parseShort(params.getType()) == QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val || Short.parseShort(params.getType()) == QlyIsptResult.QLY_ISPT_RESULT_DEFECT.val) {
+ //1锛氬悎鏍硷紝 2锛氫笉鍚堟牸, 0: 鍏跺畠锛堥粯璁わ級
+ isptItem.forEach(item -> {
+ if (Short.parseShort(params.getType()) == QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val) {
+ //TODO 鍏堟崱鍚庢敹涓洪�佽揣鏁伴噺锛屽厛鏀跺悗鎹′负鏀惰揣鏁伴噺
+ item.setSafeQty(item.getDlyQty());
+ item.setDisQty(0.0);
+ } else {
+ item.setSafeQty(0.0);
+ item.setDisQty(item.getDlyQty());
+ }
+ if (!this.update(new LambdaUpdateWrapper<QlyIsptItem>()
+ .set(QlyIsptItem::getSafeQty, item.getSafeQty())
+ .set(QlyIsptItem::getIsptResult, Short.parseShort(params.getType()))
+ .set(QlyIsptItem::getDisQty, item.getDisQty())
+ .in(QlyIsptItem::getId, item.getId()))) {
+ throw new CoolException("淇敼澶辫触锛侊紒");
+ }
+ });
+ } else {
+ if (!this.updateBatchById(isptItem)) {
+ throw new CoolException("鏄庣粏淇敼澶辫触");
+ }
}
-
- return this.update(new LambdaUpdateWrapper<QlyIsptItem>()
- .in(QlyIsptItem::getId, params.getIds())
- .set(!Objects.isNull(isptItem.getIsptStatus()), QlyIsptItem::getIsptStatus, !Objects.isNull(isptItem.getIsptStatus()) ? isptItem.getIsptStatus() : "0")
- .set(!Objects.isNull(isptItem.getDisQty()), QlyIsptItem::getDisQty, !Objects.isNull(isptItem.getDisQty()) ? isptItem.getDisQty() : 0)
- .set(!Objects.isNull(isptItem.getDlyQty()), QlyIsptItem::getDlyQty, !Objects.isNull(isptItem.getDlyQty()) ? isptItem.getDlyQty() : 0)
- .set(!Objects.isNull(isptItem.getIsptResult()), QlyIsptItem::getIsptResult, !Objects.isNull(isptItem.getIsptResult()) ? isptItem.getIsptResult() : "0"));
+ List<QlyIsptItem> isptItems = this.list(new LambdaQueryWrapper<QlyIsptItem>().in(QlyIsptItem::getId, list));
+ if (isptItems.isEmpty()) {
+ throw new CoolException("鏁版嵁閿欒锛氭槑缁嗕笉瀛樺湪锛侊紒");
+ }
+ Map<Long, List<QlyIsptItem>> listMap = isptItems.stream().collect(Collectors.groupingBy(QlyIsptItem::getIspectId));
+ for (Long key : listMap.keySet()) {
+ QlyInspect inspect = qlyInspectService.getById(key);
+ List<QlyIsptItem> items = listMap.get(key);
+ Double safeQty = items.stream().mapToDouble(QlyIsptItem::getSafeQty).sum();
+ Double disQty = items.stream().mapToDouble(QlyIsptItem::getDisQty).sum();
+ Double qlyQty = safeQty + disQty;
+ //瀹夊叏鏁伴噺锛岃川妫�鏁伴噺
+ inspect.setSafeQty(safeQty)
+ .setIsptQty(qlyQty);
+ if (Double.compare(disQty, 0) > 0) {
+ inspect.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_SECTION.val);
+ }
+ if (Double.compare(safeQty, inspect.getDlyQty()) == 0) {
+// inspect.setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_DONE.val);
+ inspect.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val);
+ }
+ if (!qlyInspectService.updateById(inspect)) {
+ throw new CoolException("璐ㄦ鏁伴噺淇敼澶辫触锛侊紒");
+ }
+ }
+ return true;
}
}
--
Gitblit v1.9.1