From b12c9e77a6b6a7b410ac421c5a3d68da88823460 Mon Sep 17 00:00:00 2001
From: zhuguifei <312353457@qq.com>
Date: 星期五, 06 三月 2026 15:20:51 +0800
Subject: [PATCH] feat: 烟丝单柜产耗统计
---
RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java | 448 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 440 insertions(+), 8 deletions(-)
diff --git a/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java b/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java
index 5747535..2afb2fd 100644
--- a/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java
+++ b/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java
@@ -1,5 +1,8 @@
package org.dromara.qa.analy.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -9,6 +12,15 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.dromara.qa.analy.domain.FeedmatchTimeData;
+import org.dromara.qa.analy.domain.PackerTimeData;
+import org.dromara.qa.analy.domain.RollerTimeData;
+import org.dromara.qa.analy.domain.vo.StoreSilkDetailVo;
+import org.dromara.qa.analy.mapper.RollerTimeDataMapper;
+import org.dromara.qa.md.domain.MdShift;
+import org.dromara.qa.md.domain.bo.MdShiftBo;
+import org.dromara.qa.md.mapper.MdShiftMapper;
+import org.dromara.qa.md.service.OracleShiftReader;
import org.springframework.stereotype.Service;
import org.dromara.qa.analy.domain.bo.StoreSilkInfoBo;
import org.dromara.qa.analy.domain.vo.StoreSilkInfoVo;
@@ -17,9 +29,16 @@
import org.dromara.qa.analy.service.IStoreSilkInfoService;
import org.dromara.qa.analy.mapper.FeedmatchTimeDataMapper;
-import java.util.List;
-import java.util.Map;
-import java.util.Collection;
+import java.lang.reflect.Field;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
/**
* 鍌ㄤ笣鏌滀骇閲廠ervice涓氬姟灞傚鐞�
@@ -34,6 +53,10 @@
private final StoreSilkInfoMapper baseMapper;
private final FeedmatchTimeDataMapper feedmatchTimeDataMapper;
+ private final RollerTimeDataMapper rollerTimeDataMapper;
+ private final org.dromara.qa.analy.mapper.PackerTimeDataMapper packerTimeDataMapper;
+ private final MdShiftMapper mdShiftMapper;
+ private final OracleShiftReader oracleShiftReader;
/**
* 鏌ヨ鍌ㄤ笣鏌滀骇閲�
@@ -42,7 +65,7 @@
* @return 鍌ㄤ笣鏌滀骇閲�
*/
@Override
- public StoreSilkInfoVo queryById(Long id){
+ public StoreSilkInfoVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
@@ -61,19 +84,426 @@
queryFeedmatchData(result);
return TableDataInfo.build(result);
}
-
+
private void queryFeedmatchData(Page<StoreSilkInfoVo> page) {
if (page == null || page.getRecords() == null || page.getRecords().isEmpty()) {
return;
}
+ // 鏌ヨ鏁伴噰绯荤粺鐝鏃堕棿锛堢嫭绔嬩娇鐢� oracle 鏁版嵁婧愶級
+ List<MdShift> mdShifts = oracleShiftReader.listAll();
+
+
List<StoreSilkInfoVo> storeSilkInfoList = page.getRecords();
for (int i = 0; i < storeSilkInfoList.size(); i++) {
- //
+ //鍌ㄤ笣鏌�
StoreSilkInfoVo storeSilkInfoVo = storeSilkInfoList.get(i);
+ //鍑烘枡寮�濮嬫椂闂�
+ Date distimebegin = storeSilkInfoVo.getDistimebegin();
+ //鍑烘枡缁撴潫鏃堕棿
+ Date distimeend = storeSilkInfoVo.getDistimeend();
+
+ //鍌ㄤ笣鏌滄煖鍙�
+ String siloid = storeSilkInfoVo.getSiloid();
+ if (StringUtils.isEmpty(siloid)) continue;
+ int lastIndex = siloid.lastIndexOf("_");
+ String containerNum = siloid.substring(lastIndex + 1);
+ if (StringUtils.isEmpty(containerNum)) continue;
+
+ //鏍规嵁鍑烘枡寮�濮嬫椂闂存煡璇㈠杺涓濇満->鍌ㄤ笣鏌�->鏈哄彴瀵瑰簲鍏崇郴(feedmatch_time_data)
+ Timestamp targetTime = new Timestamp(distimebegin.getTime() + 10 * 60 * 1000); // 鏌ヨ鍑烘枡10鍒嗛挓鍚庣殑绗竴鏉¤褰曪紝淇濊瘉鏁版嵁鍑嗙‘鎬�
+ LambdaQueryWrapper<FeedmatchTimeData> lqw = new LambdaQueryWrapper<>();
+ lqw.ge(FeedmatchTimeData::getTime, targetTime)
+ .le(FeedmatchTimeData::getTime, distimeend) // 涓嶈兘澶т簬鍑烘枡缁撴潫鏃堕棿
+ .orderByAsc(FeedmatchTimeData::getTime)
+ .last("LIMIT 1");
+ FeedmatchTimeData feedMatch = feedmatchTimeDataMapper.selectOne(lqw);
+ if (feedMatch == null) {
+ // TODO 娣诲姞鎻愮ず
+ continue;
+ }
+
+ // feedMatch 杞琺ap TODO 閫嗚浆map闇�楠岃瘉key鏄惁浼氶噸澶�
+ //fsRevMap鏄�嗚浆map key->鍠備笣鏈哄搴旂殑鍌ㄤ笣鏌滃彿 value-> fs + 搴忓彿
+ Map<String, String> fsRevMap = new HashMap<>();
+ //pipeRevMap鏄�嗚浆map key->鏈虹粍瀵瑰簲鐨勫杺涓濇満鍜岀閬� value-> pipe + 搴忓彿
+ Map<String, String> pipeRevMap = new HashMap<>();
+ Map<String, String> pipeMap = new HashMap<>();
+ Field[] fields = feedMatch.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ field.setAccessible(true);
+ Object value = null;
+ try {
+ value = field.get(feedMatch);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ if (field.getName().startsWith("fs") && value != null) {
+ fsRevMap.put(value.toString(), field.getName());
+ } else if (field.getName().startsWith("pipe") && value != null) {
+ pipeRevMap.put(value.toString(), field.getName());
+ pipeMap.put(field.getName(),value.toString());
+ }
+ }
+ // 鏍规嵁鍌ㄤ笣鏌滃彿鑾峰彇鍠備笣鏈哄彿
+ String fsNum = fsRevMap.get(containerNum);
+ if (StringUtils.isEmpty(fsNum)) {
+ // TODO 鍠備笣鏈哄彿绌鸿繑鍥炰俊鎭�
+ continue;
+ }
+ if (pipeRevMap.isEmpty()) {
+ // TODO 绠¢亾鍙风┖杩斿洖淇℃伅
+ continue;
+ }
+ // List瀛�-> 鍠備笣鏈哄搴旂殑鏈虹粍锛堝 pipe01 pipe02 浠h〃1#銆�2#鍗锋帴鏈虹粍锛�
+ List<String> pipeList = new ArrayList<>();
+ for (Map.Entry<String, String> entry : pipeRevMap.entrySet()) {
+ //fsNum绗笁浣嶆槸鍠備笣鏈哄簭鍙�
+ if (entry.getKey().length() > 1 && entry.getKey().startsWith(fsNum.substring(2, 3))) {
+ pipeList.add(entry.getValue());
+ }
+ }
+ if (pipeList.isEmpty()) {
+ //TODO 娣诲姞鎻愮ず
+ continue;
+ }
+
+ // 鏍规嵁鍑烘枡寮�濮嬬粨鏉熸椂闂达紝鏌ヨ璇ユ煖鏂欏湪鍝嚑涓彮娆$敓浜�
+ List<MdShiftBo> distShiftList = calcShiftSpans(distimebegin, distimeend, mdShifts);
+ storeSilkInfoVo.setDistShiftList(distShiftList);
+ if (distShiftList.isEmpty()) continue;
+ //鏌ヨ鏃ユ湡鍜岀彮娆″唴鍗锋帴鏈虹粍鐨勪骇閲�
+ ZoneId zone = ZoneId.systemDefault();
+ // 鍗峰寘浜ч噺缁熻
+ Double rollerOutput = 0.0;
+ Double packerOutput = 0.0;
+ // 鏄庣粏鍒楄〃
+ List<StoreSilkDetailVo> rollerDetailList = new ArrayList<>();
+ List<StoreSilkDetailVo> packerDetailList = new ArrayList<>();
+
+ for (int s = 0; s < distShiftList.size(); s++) {
+ MdShiftBo shiftBo = distShiftList.get(s);
+ if (shiftBo.getDay() == null || StringUtils.isEmpty(shiftBo.getCode())) {
+ continue;
+ }
+ String shift = shiftBo.getCode();
+
+ // 瑙f瀽鐝鏃堕棿
+ // 1. 鑾峰彇鐝閰嶇疆鐨勫紑濮嬪拰缁撴潫鏃堕棿瀛楃涓� (鏍煎紡濡� "07:30:00")
+ String stimStr = shiftBo.getStim();
+ String etimStr = shiftBo.getEtim();
+ if (StringUtils.isEmpty(stimStr) || StringUtils.isEmpty(etimStr)) {
+ continue;
+ }
+ // 2. 琛ュ叏绉掓暟锛堝鏋滈厤缃粎涓� HH:mm锛�
+ if (stimStr.length() == 5) stimStr += ":00";
+ if (etimStr.length() == 5) etimStr += ":00";
+
+ // 3. 缁撳悎鏃ユ湡瑙f瀽涓� LocalDateTime
+ // 娉ㄦ剰锛歴hiftBo.getDay() 鏄鐝鐨勫綊灞炴棩鏈�
+ String dateStr = shiftBo.getDay().toInstant().atZone(zone).toLocalDate().toString();
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ LocalDateTime shiftStart = LocalDateTime.parse(dateStr + " " + stimStr, formatter);
+ LocalDateTime shiftEnd = LocalDateTime.parse(dateStr + " " + etimStr, formatter);
+
+ // 4. 澶勭悊璺ㄥぉ鐝锛氬鏋� 缁撴潫鏃堕棿 <= 寮�濮嬫椂闂达紝璇存槑璺ㄥぉ锛岀粨鏉熸椂闂撮渶 +1 澶�
+ if (!shiftEnd.isAfter(shiftStart)) {
+ shiftEnd = shiftEnd.plusDays(1);
+ }
+
+ // 杞崲 Date 瀵硅薄鐢ㄤ簬姣旇緝锛堝吋瀹圭幇鏈夐�昏緫锛�
+ Date stimDate = Date.from(shiftStart.atZone(zone).toInstant());
+ Date etimDate = Date.from(shiftEnd.atZone(zone).toInstant());
+
+ // 璁$畻鐝缁撴潫鍓�10鍒嗛挓鐨勬椂闂寸偣
+ String shiftEndStr = shiftEnd.format(formatter);
+ String tenMinBeforeShiftEnd = shiftEnd.minusMinutes(10).format(formatter);
+
+ // 鏍规嵁鍗锋帴鏈虹粍鍜岀彮娆¤幏鍙栦骇閲忥紙pipeList = 澶氬皯涓満缁勶級
+ for (int j = 0; j < pipeList.size(); j++) {
+ String pipe = pipeList.get(j);
+ // 鎻愬彇鏈虹粍鍙�
+ String equNo = pipe.replaceAll("\\D+", "");
+ //绠¢亾鍙�
+ String channel = pipeMap.get("pipe" + equNo);
+ if (channel != null && channel.length() > 0) {
+ channel = channel.substring(channel.length() - 1);
+ }else {
+ channel = "";
+ }
+
+ //娉ㄦ剰4鍙风閬撲互鍚庡搴旂殑鏈虹粍闇�瑕�+1锛屾満缁�4鍙风┖缂鸿烦鍒�5鍙�
+ try {
+ int equ = Integer.parseInt(equNo);
+ equNo = String.format("%02d", equ >= 4 ? equ + 1 : equ);
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO 娣诲姞鎻愮ず
+ continue;
+ }
+
+
+ // 鎷兼帴鍗锋帴鏈虹殑key锛屼腑闂� "1" 浠h〃鍗锋帴鏈猴紝鏍煎紡锛氱彮娆� + "1" + 鏈虹粍鍙�
+ String key = shift + "1" + equNo;
+ // 鎷兼帴鍖呰鏈虹殑key锛屼腑闂� "2" 浠h〃鍖呰鏈猴紝鏍煎紡锛氱彮娆� + "2" + 鏈虹粍鍙�
+ String packerKey = shift + "2" + equNo;
+
+ // ================= 鍗锋帴鏈轰骇閲忕粺璁� =================
+ Double currentRollerOutput = 0.0;
+ // 1. 鏌ヨ鐝缁撴潫鏃剁殑浜ч噺蹇収
+ LambdaQueryWrapper<RollerTimeData> rlqw = new LambdaQueryWrapper<>();
+ rlqw.le(RollerTimeData::getTime, shiftEndStr)
+ .eq(RollerTimeData::getKey, key)
+ .ge(RollerTimeData::getTime, tenMinBeforeShiftEnd)
+ .orderByDesc(RollerTimeData::getTime)
+ .isNotNull(RollerTimeData::getQty)
+ .gt(RollerTimeData::getQty, 0)
+ .last("LIMIT 1");
+
+ RollerTimeData rData = rollerTimeDataMapper.selectOne(rlqw);
+ if (rData != null) {
+ // 鍒濆浜ч噺璁句负鐝缁撴潫鏃剁殑绱鍊�
+ currentRollerOutput += rData.getQty();
+
+ // 2. 澶勭悊鈥滄墸澶粹�濓細鍑烘枡寮�濮嬫椂闂� > 鐝寮�濮嬫椂闂�
+ if (distimebegin.after(stimDate)) {
+ LocalDateTime distBeginTime = LocalDateTime.ofInstant(distimebegin.toInstant(), zone);
+ String distBeginStr = distBeginTime.format(formatter);
+ String tenMinBeforeDistBegin = distBeginTime.minusMinutes(10).format(formatter);
+
+ LambdaQueryWrapper<RollerTimeData> beginRlqw = new LambdaQueryWrapper<>();
+ beginRlqw.le(RollerTimeData::getTime, distBeginStr)
+ .eq(RollerTimeData::getKey, key)
+ .ge(RollerTimeData::getTime, tenMinBeforeDistBegin)
+ .orderByDesc(RollerTimeData::getTime)
+ .isNotNull(RollerTimeData::getQty)
+ .gt(RollerTimeData::getQty, 0)
+ .last("LIMIT 1");
+
+ RollerTimeData rBeginData = rollerTimeDataMapper.selectOne(beginRlqw);
+ if (rBeginData != null) {
+ currentRollerOutput -= rBeginData.getQty();
+ }
+ }
+
+ // 3. 澶勭悊鈥滄墸灏锯�濓細鍑烘枡缁撴潫鏃堕棿 < 鐝缁撴潫鏃堕棿
+ if (etimDate.after(distimeend)) {
+ LocalDateTime distEndTime = LocalDateTime.ofInstant(distimeend.toInstant(), zone);
+ String distEndStr = distEndTime.format(formatter);
+ String tenMinBeforeDistEnd = distEndTime.minusMinutes(10).format(formatter);
+
+ LambdaQueryWrapper<RollerTimeData> endRlqw = new LambdaQueryWrapper<>();
+ endRlqw.le(RollerTimeData::getTime, distEndStr)
+ .eq(RollerTimeData::getKey, key)
+ .ge(RollerTimeData::getTime, tenMinBeforeDistEnd)
+ .orderByDesc(RollerTimeData::getTime)
+ .isNotNull(RollerTimeData::getQty)
+ .gt(RollerTimeData::getQty, 0)
+ .last("LIMIT 1");
+
+ RollerTimeData rEndData = rollerTimeDataMapper.selectOne(endRlqw);
+ if (rEndData != null) {
+ double qtyDelta = rData.getQty() - rEndData.getQty();
+ if (qtyDelta > 0) {
+ currentRollerOutput -= qtyDelta;
+ }
+ }
+ }
+ }
+ // 绱鎬讳骇閲�
+ rollerOutput += currentRollerOutput;
+ // 璁板綍鍗锋帴鏈烘槑缁�
+ if (currentRollerOutput > 0) {
+ StoreSilkDetailVo detail = new StoreSilkDetailVo();
+ detail.setFsNum(fsNum.substring(2, 3));
+ detail.setSiloNum(containerNum);
+ detail.setPipeNum(channel);
+ detail.setEquNo(equNo);
+ detail.setShiftCode(shift);
+ detail.setShiftStartTime(stimDate);
+ detail.setShiftEndTime(etimDate);
+ detail.setOutput(currentRollerOutput);
+ rollerDetailList.add(detail);
+ }
+
+ // ================= 鍖呰鏈轰骇閲忕粺璁� =================
+ Double currentPackerOutput = 0.0;
+ // 1. 鏌ヨ鐝缁撴潫鏃剁殑浜ч噺蹇収
+ LambdaQueryWrapper<PackerTimeData> plqw = new LambdaQueryWrapper<>();
+ plqw.le(PackerTimeData::getTime, shiftEndStr)
+ .eq(PackerTimeData::getKey, packerKey)
+ .ge(PackerTimeData::getTime, tenMinBeforeShiftEnd)
+ .orderByDesc(PackerTimeData::getTime)
+ .isNotNull(PackerTimeData::getQty)
+ .gt(PackerTimeData::getQty, 0)
+ .last("LIMIT 1");
+
+ PackerTimeData pData = packerTimeDataMapper.selectOne(plqw);
+ if (pData != null) {
+ // 鍒濆浜ч噺璁句负鐝缁撴潫鏃剁殑绱鍊�
+ currentPackerOutput += pData.getQty();
+
+ // 2. 澶勭悊鈥滄墸澶粹��
+ if (distimebegin.after(stimDate)) {
+ LocalDateTime distBeginTime = LocalDateTime.ofInstant(distimebegin.toInstant(), zone);
+ String distBeginStr = distBeginTime.format(formatter);
+ String tenMinBeforeDistBegin = distBeginTime.minusMinutes(10).format(formatter);
+
+ LambdaQueryWrapper<PackerTimeData> beginPlqw = new LambdaQueryWrapper<>();
+ beginPlqw.le(PackerTimeData::getTime, distBeginStr)
+ .eq(PackerTimeData::getKey, packerKey)
+ .ge(PackerTimeData::getTime, tenMinBeforeDistBegin)
+ .orderByDesc(PackerTimeData::getTime)
+ .isNotNull(PackerTimeData::getQty)
+ .gt(PackerTimeData::getQty, 0)
+ .last("LIMIT 1");
+
+ PackerTimeData pBeginData = packerTimeDataMapper.selectOne(beginPlqw);
+ if (pBeginData != null) {
+ currentPackerOutput -= pBeginData.getQty();
+ }
+ }
+
+ // 3. 澶勭悊鈥滄墸灏锯��
+ if (etimDate.after(distimeend)) {
+ LocalDateTime distEndTime = LocalDateTime.ofInstant(distimeend.toInstant(), zone);
+ String distEndStr = distEndTime.format(formatter);
+ String tenMinBeforeDistEnd = distEndTime.minusMinutes(10).format(formatter);
+
+ LambdaQueryWrapper<PackerTimeData> endPlqw = new LambdaQueryWrapper<>();
+ endPlqw.le(PackerTimeData::getTime, distEndStr)
+ .eq(PackerTimeData::getKey, packerKey)
+ .ge(PackerTimeData::getTime, tenMinBeforeDistEnd)
+ .orderByDesc(PackerTimeData::getTime)
+ .isNotNull(PackerTimeData::getQty)
+ .gt(PackerTimeData::getQty, 0)
+ .last("LIMIT 1");
+
+ PackerTimeData pEndData = packerTimeDataMapper.selectOne(endPlqw);
+ if (pEndData != null) {
+ double qtyDelta = pData.getQty() - pEndData.getQty();
+ if (qtyDelta > 0) {
+ currentPackerOutput -= qtyDelta;
+ }
+ }
+ }
+ }
+ // 绱鎬讳骇閲�
+ packerOutput += currentPackerOutput;
+ // 璁板綍鍖呰鏈烘槑缁�
+ if (currentPackerOutput > 0) {
+ StoreSilkDetailVo detail = new StoreSilkDetailVo();
+ detail.setFsNum(fsNum.substring(2, 3));
+ detail.setSiloNum(containerNum);
+ detail.setPipeNum(channel);
+ detail.setEquNo(equNo);
+ detail.setShiftCode(shift);
+ detail.setShiftStartTime(stimDate);
+ detail.setShiftEndTime(etimDate);
+ detail.setOutput(currentPackerOutput);
+ packerDetailList.add(detail);
+ }
+ }
+ }
+ storeSilkInfoVo.setRollerOutput(rollerOutput);
+ storeSilkInfoVo.setPackerOutput(packerOutput);
+ storeSilkInfoVo.setRollerDetailList(rollerDetailList);
+ storeSilkInfoVo.setPackerDetailList(packerDetailList);
}
+ }
+
+ /**
+ * 璁$畻鍑烘枡鍖洪棿 [begin, end) 娑夊強鍒扮殑鐝锛堜粎 code=1銆�2 鐨勬棭/涓彮锛�
+ * 杩斿洖 Map<yyyy-MM-dd, code>锛岃〃绀鸿鏃ユ湡涓婄殑璇ョ彮娆′笌鍑烘枡鍖洪棿瀛樺湪鏃堕棿閲嶅彔
+ * 鑻ュ悓涓�鏃ユ湡鏃�/涓彮鍧囨湁閲嶅彔锛寁alue 浣跨敤閫楀彿鎷兼帴锛屽 "1,2"
+ * <p>
+ * 绠�鍖栨�濊矾锛�
+ * 1. 灏� begin/end 杞负 LocalDateTime锛屽彇鍑鸿鐩栫殑鎵�鏈夎嚜鐒舵棩
+ * 2. 瀵规瘡涓�澶╂寜鐝鐨� stim/etim 鐢熸垚鐝鏃堕棿绐� [shiftStart, shiftEnd)
+ * - 鑻� etim <= stim锛岃涓鸿法澶╃彮娆★細shiftEnd = 褰撳ぉ鏃ユ湡 + 1 澶� + etim
+ * 3. 鐢ㄧ畝鍗曠殑鍖洪棿閲嶅彔鍒ゆ柇锛歴hiftEnd > begin && shiftStart < end
+ */
+ private List<MdShiftBo> calcShiftSpans(Date begin, Date end, List<MdShift> mdShifts) {
+ List<MdShiftBo> result = new ArrayList<>();
+
+ // 鍩虹鏍¢獙
+ if (begin == null || end == null || !end.after(begin) || mdShifts == null || mdShifts.isEmpty()) {
+ return result;
+ }
+
+ // 浠呬繚鐣欐棭鐝�(code=1)涓庝腑鐝�(code=2)
+ // 鍚屾椂蹇界暐 stim/etim 涓虹┖鐨勭彮娆�
+ ZoneId zone = ZoneId.systemDefault();
+ LocalDateTime intervalStart = LocalDateTime.ofInstant(begin.toInstant(), zone);
+ LocalDateTime intervalEnd = LocalDateTime.ofInstant(end.toInstant(), zone);
+ LocalDate day = intervalStart.toLocalDate();
+ LocalDate lastDay = intervalEnd.toLocalDate();
+
+ // 瑙f瀽鏃堕棿鏍煎紡锛氭敮鎸� "H:mm" 鎴� "H:mm:ss"
+ DateTimeFormatter tf = DateTimeFormatter.ofPattern("H:mm[:ss]");
+ Set<String> seen = new HashSet<>();
+
+ // 鎸夊ぉ閬嶅巻瑕嗙洊鑼冨洿
+ while (!day.isAfter(lastDay)) {
+ for (MdShift s : mdShifts) {
+ // 浠呮棭/涓彮
+ String code = s.getCode();
+ if (!"1".equals(code) && !"2".equals(code)) {
+ continue;
+ }
+ String st = s.getStim();
+ String et = s.getEtim();
+ if (st == null || et == null) {
+ continue;
+ }
+ // 瑙f瀽鐝璧锋鏃堕棿
+ LocalTime stt;
+ LocalTime ett;
+ try {
+ stt = LocalTime.parse(st.trim(), tf);
+ ett = LocalTime.parse(et.trim(), tf);
+ } catch (Exception ignore) {
+ // 鏃堕棿鏍煎紡寮傚父鍒欒烦杩囪鐝
+ continue;
+ }
+ // 鐢熸垚褰撳ぉ璇ョ彮娆$殑鏃堕棿绐�
+ LocalDateTime shiftStart = LocalDateTime.of(day, stt);
+ LocalDateTime shiftEnd = ett.isAfter(stt) || ett.equals(stt)
+ ? LocalDateTime.of(day, ett)
+ : LocalDateTime.of(day.plusDays(1), ett); // 璺ㄥぉ澶勭悊
+
+ // 鍒ゆ柇鍖洪棿鏄惁閲嶅彔锛� [shiftStart, shiftEnd) 涓� [intervalStart, intervalEnd)
+ if (shiftEnd.isAfter(intervalStart) && shiftStart.isBefore(intervalEnd)) {
+ Date shiftDay = Date.from(day.atStartOfDay(zone).toInstant());
+ String dedupeKey = shiftDay.getTime() + "-" + code;
+ if (seen.add(dedupeKey)) {
+ MdShiftBo bo = new MdShiftBo();
+ bo.setId(s.getId());
+ bo.setWsId(s.getWsId());
+ bo.setCode(s.getCode());
+ bo.setName(s.getName());
+ bo.setStim(s.getStim());
+ bo.setEtim(s.getEtim());
+ bo.setSeq(s.getSeq());
+ bo.setEnable(s.getEnable());
+ bo.setDel(s.getDel());
+ bo.setCreateUserName(s.getCreateUserName());
+ bo.setCreateUserTime(s.getCreateUserTime());
+ bo.setUpdateUserName(s.getUpdateUserName());
+ bo.setUpdateUserTime(s.getUpdateUserTime());
+ bo.setDay(shiftDay);
+ result.add(bo);
+ }
+ }
+ }
+ day = day.plusDays(1);
+ }
+ result.sort(Comparator
+ .comparing(MdShiftBo::getDay, Comparator.nullsLast(Date::compareTo))
+ .thenComparing(MdShiftBo::getCode, Comparator.nullsLast(String::compareTo)));
+ return result;
}
/**
@@ -98,6 +528,8 @@
lqw.eq(bo.getDistimebegin() != null, StoreSilkInfo::getDistimebegin, bo.getDistimebegin());
lqw.eq(bo.getDistimeend() != null, StoreSilkInfo::getDistimeend, bo.getDistimeend());
lqw.eq(StringUtils.isNotBlank(bo.getSiloid()), StoreSilkInfo::getSiloid, bo.getSiloid());
+ lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
+ StoreSilkInfo::getDistimeend, params.get("beginTime"), params.get("endTime"));
return lqw;
}
@@ -134,7 +566,7 @@
/**
* 淇濆瓨鍓嶇殑鏁版嵁鏍¢獙
*/
- private void validEntityBeforeSave(StoreSilkInfo entity){
+ private void validEntityBeforeSave(StoreSilkInfo entity) {
//TODO 鍋氫竴浜涙暟鎹牎楠�,濡傚敮涓�绾︽潫
}
@@ -147,7 +579,7 @@
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
- if(isValid){
+ if (isValid) {
//TODO 鍋氫竴浜涗笟鍔′笂鐨勬牎楠�,鍒ゆ柇鏄惁闇�瑕佹牎楠�
}
return baseMapper.deleteByIds(ids) > 0;
--
Gitblit v1.9.3