From 0be02df3d287f802c76e5738916301a877dfaa0e Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 27 四月 2026 16:56:12 +0800
Subject: [PATCH] feat: 生产报工与报工台账功能更改完成
---
src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 93 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java
index a137d8d..747a0bd 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java
@@ -13,9 +13,13 @@
import com.ruoyi.common.utils.MatrixToImageWriter;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.production.dto.ProductWorkOrderDto;
+import com.ruoyi.production.mapper.ProductionProductMainMapper;
+import com.ruoyi.production.mapper.ProductionProductReportDailyMapper;
import com.ruoyi.production.mapper.ProductWorkOrderFileMapper;
import com.ruoyi.production.mapper.ProductWorkOrderMapper;
import com.ruoyi.production.mapper.ProductWorkOrderRapporteurMapper;
+import com.ruoyi.production.pojo.ProductionProductMain;
+import com.ruoyi.production.pojo.ProductionProductReportDaily;
import com.ruoyi.production.pojo.ProductWorkOrder;
import com.ruoyi.production.pojo.ProductWorkOrderFile;
import com.ruoyi.production.pojo.ProductWorkOrderRapporteur;
@@ -30,7 +34,9 @@
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
+import java.math.BigDecimal;
import java.net.URLEncoder;
+import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -39,6 +45,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@Service
@Transactional(rollbackFor = Exception.class)
@@ -52,14 +59,21 @@
private ProductWorkOrderRapporteurMapper productWorkOrderRapporteurMapper;
@Autowired
private SysUserMapper sysUserMapper;
+ @Autowired
+ private ProductionProductMainMapper productionProductMainMapper;
+ @Autowired
+ private ProductionProductReportDailyMapper productionProductReportDailyMapper;
@Value("${file.temp-dir}")
private String tempDir;
@Override
public IPage<ProductWorkOrderDto> listPage(Page<ProductWorkOrderDto> page, ProductWorkOrderDto productWorkOrder) {
- if (productWorkOrder != null && Integer.valueOf(2).equals(productWorkOrder.getType())) {
- productWorkOrder.setCurrentUserId(SecurityUtils.getUserId());
+ boolean reportView = productWorkOrder != null && Integer.valueOf(2).equals(productWorkOrder.getType());
+ Long currentUserId = null;
+ if (reportView) {
+ currentUserId = SecurityUtils.getUserId();
+ productWorkOrder.setCurrentUserId(currentUserId);
}
IPage<ProductWorkOrderDto> pageData = productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder);
List<ProductWorkOrderDto> records = pageData.getRecords();
@@ -92,6 +106,81 @@
List<Long> userIds = rapporteurMap.get(item.getId());
item.setReportWorkersId(userIds == null ? new Long[0] : userIds.toArray(new Long[0]));
});
+
+ // type=2 鏃讹細鍥炲~鈥滃綋鍓嶆姤宸ヤ汉浠婃棩鐘舵�佲��
+ if (reportView && currentUserId != null) {
+ // 1) 杩涜涓�(status=0)鐨勬姤宸�
+ List<ProductionProductMain> runningList = productionProductMainMapper.selectList(
+ Wrappers.<ProductionProductMain>lambdaQuery()
+ .in(ProductionProductMain::getWorkOrderId, workOrderIds)
+ .eq(ProductionProductMain::getUserId, currentUserId)
+ .eq(ProductionProductMain::getStatus, 0)
+ );
+ final java.util.Set<Long> runningWorkOrders = CollectionUtils.isNotEmpty(runningList)
+ ? runningList.stream().map(ProductionProductMain::getWorkOrderId).filter(Objects::nonNull).collect(Collectors.toSet())
+ : java.util.Collections.emptySet();
+
+ // 2) 浠婃棩宸茬粨鏉燂紙浠婃棩鏈� daily 鏄庣粏锛�
+ LocalDate today = LocalDate.now();
+ List<ProductionProductReportDaily> todayDailyList = productionProductReportDailyMapper.selectList(
+ Wrappers.<ProductionProductReportDaily>lambdaQuery()
+ .in(ProductionProductReportDaily::getWorkOrderId, workOrderIds)
+ .eq(ProductionProductReportDaily::getUserId, currentUserId)
+ .eq(ProductionProductReportDaily::getReportDate, today)
+ );
+ final java.util.Set<Long> endedTodayWorkOrders = CollectionUtils.isNotEmpty(todayDailyList)
+ ? todayDailyList.stream().map(ProductionProductReportDaily::getWorkOrderId).filter(Objects::nonNull).collect(Collectors.toSet())
+ : java.util.Collections.emptySet();
+
+ records.forEach(item -> {
+ Long woId = item.getId();
+ if (woId == null) {
+ item.setTodayReportState(1);
+ return;
+ }
+ if (runningWorkOrders.contains(woId)) {
+ item.setTodayReportState(2);
+ return;
+ }
+ if (endedTodayWorkOrders.contains(woId)) {
+ item.setTodayReportState(3);
+ return;
+ }
+ item.setTodayReportState(1);
+ });
+ }
+
+ // 鍥炲~鎶ュ伐鏃堕棿鎬诲拰(鍒嗛挓): type=2 鎸夊綋鍓嶇櫥褰曚汉姹囨�伙紝鍏朵粬鎸夊伐鍗曞叏鍛樻眹鎬�
+ QueryWrapper<ProductionProductReportDaily> totalDurationQw = new QueryWrapper<>();
+ totalDurationQw.select("work_order_id as workOrderId", "sum(duration_minutes) as totalMinutes")
+ .in("work_order_id", workOrderIds)
+ .groupBy("work_order_id");
+ if (reportView && currentUserId != null) {
+ totalDurationQw.eq("user_id", currentUserId);
+ }
+ List<Map<String, Object>> durationRows = productionProductReportDailyMapper.selectMaps(totalDurationQw);
+ Map<Long, BigDecimal> durationMap = new HashMap<>();
+ if (CollectionUtils.isNotEmpty(durationRows)) {
+ for (Map<String, Object> row : durationRows) {
+ Object workOrderObj = row.get("workOrderId");
+ if (workOrderObj == null) {
+ workOrderObj = row.get("work_order_id");
+ }
+ Object totalObj = row.get("totalMinutes");
+ if (totalObj == null) {
+ totalObj = row.get("total_minutes");
+ }
+ if (workOrderObj == null || totalObj == null) {
+ continue;
+ }
+ Long woId = workOrderObj instanceof Number ? ((Number) workOrderObj).longValue() : Long.valueOf(workOrderObj.toString());
+ BigDecimal totalMinutes = totalObj instanceof BigDecimal
+ ? (BigDecimal) totalObj
+ : new BigDecimal(totalObj.toString());
+ durationMap.put(woId, totalMinutes);
+ }
+ }
+ records.forEach(item -> item.setTotalReportDurationMinutes(durationMap.getOrDefault(item.getId(), BigDecimal.ZERO)));
return pageData;
}
@@ -118,9 +207,10 @@
return rows;
}
- List<Long> existUserIds = sysUserMapper.selectUserByIds(candidateUserIds).stream()
+ List<Long> existUserIds = sysUserMapper.selectUsersByIds(candidateUserIds).stream()
.map(SysUser::getUserId)
.filter(Objects::nonNull)
+ .distinct()
.collect(Collectors.toList());
if (existUserIds.size() != candidateUserIds.size()) {
List<Long> invalidUserIds = candidateUserIds.stream()
--
Gitblit v1.9.3