|
@@ -23,9 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.time.DayOfWeek;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.ZoneId;
|
|
|
+import java.time.*;
|
|
|
import java.time.format.TextStyle;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
@@ -49,7 +47,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
* @param bo
|
|
|
* @return
|
|
|
*/
|
|
|
- public IPage<MesLineVO> queryList(MesLineBO bo,int pageNum,int pageSize) {
|
|
|
+ public IPage<MesLineVO> queryList(MesLineBO bo, int pageNum, int pageSize) {
|
|
|
int offset = (pageNum - 1) * pageSize;
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("boy", bo);
|
|
@@ -133,10 +131,8 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
LocalDate now = LocalDate.now();
|
|
|
// 计算本周的星期一
|
|
|
LocalDate mondayOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
- log.info("本周的星期一:" + mondayOfWeek);
|
|
|
// 计算本周的星期天
|
|
|
LocalDate sundayOfWeek = now.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
- log.info("本周的星期天:" + sundayOfWeek);
|
|
|
//获取星期一致星期天的数据
|
|
|
LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
|
wr.between(MesLine::getCreateTime, mondayOfWeek, sundayOfWeek);
|
|
@@ -164,4 +160,63 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
|
|
|
return R.ok(map);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计本周 每条产线数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public R<Map<String, Map<String, Object>>> queryDay() {
|
|
|
+ //获取当前时间
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ //计算本周的星期一
|
|
|
+ LocalDate mondayOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
+ // 计算本周的星期天
|
|
|
+ LocalDate sundayOfWeek = now.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
+ //获取星期一致星期天的数据
|
|
|
+ LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
|
+ wr.between(MesLine::getCreateTime, mondayOfWeek, sundayOfWeek);
|
|
|
+ List<MesLine> boy = mesLineMapper.selectList(wr);
|
|
|
+ // 创建一个LinkedHashMap用于存储统计结果
|
|
|
+ Map<String, Map<String, Object>> lineSummary = new LinkedHashMap<>();
|
|
|
+ // 遍历集合,统计每条产线的数据
|
|
|
+ if (boy != null && !boy.isEmpty()) {
|
|
|
+ for (MesLine mesLine : boy) {
|
|
|
+ try {
|
|
|
+ //获取产线名称
|
|
|
+ String lineName = mesLine.getLineName();
|
|
|
+ LocalDate createTime = mesLine.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+
|
|
|
+ if (createTime.isAfter(mondayOfWeek.minusDays(1)) && createTime.isBefore(sundayOfWeek.plusDays(1))) {
|
|
|
+ Map<String, Object> lineData = lineSummary.computeIfAbsent(lineName, k -> new HashMap<>());
|
|
|
+ //累加产量
|
|
|
+ Long totalOutput = (Long) lineData.getOrDefault("产量", 0L);
|
|
|
+ Long count = mesLine.getCurrentQty();
|
|
|
+ lineData.put("产量", totalOutput + count);
|
|
|
+ //累加不合格数量
|
|
|
+ Long totalPoorQty = (Long) lineData.getOrDefault("不合格数量", 0L);
|
|
|
+ Long currentPoorQty = mesLine.getPoorQty();
|
|
|
+ lineData.put("不合格数量", totalPoorQty + currentPoorQty);
|
|
|
+ //计算合格数量
|
|
|
+ Long totalQualifiedQty = (Long) lineData.getOrDefault("合格数量", 0L);
|
|
|
+ Long updatedTotalOutput = (Long) lineData.get("产量");
|
|
|
+ Long updatedTotalPoorQty = (Long) lineData.get("不合格数量");
|
|
|
+ totalQualifiedQty = updatedTotalOutput - updatedTotalPoorQty;
|
|
|
+ lineData.put("合格数量", totalQualifiedQty);
|
|
|
+ //更新合格率
|
|
|
+ if (updatedTotalOutput > 0) {
|
|
|
+ double qualificationRate = ((double) totalQualifiedQty / (double) updatedTotalOutput) * 100;
|
|
|
+ lineData.put("合格率", String.format("%.2f%%", qualificationRate));
|
|
|
+ } else {
|
|
|
+ lineData.put("合格率", "0.00%");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("数据转换异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok(lineSummary);
|
|
|
+ }
|
|
|
}
|