|
@@ -219,4 +219,90 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
}
|
|
}
|
|
return R.ok(lineSummary);
|
|
return R.ok(lineSummary);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取本月总产量
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public R<Long> getMonthTotal() {
|
|
|
|
+ //获取当前时间
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
|
+ //获取本月的开始时间和结束时间
|
|
|
|
+ LocalDate startOfMonth = now.withDayOfMonth(1);
|
|
|
|
+ LocalDate endOfMonth = now.withDayOfMonth(now.lengthOfMonth());
|
|
|
|
+ //按月份查询数据
|
|
|
|
+ LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
|
|
+ wr.between(MesLine::getCreateTime, startOfMonth, endOfMonth);
|
|
|
|
+ List<MesLine> list = mesLineMapper.selectList(wr);
|
|
|
|
+ //开始累加本月总产量
|
|
|
|
+ Long total = 0L;
|
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
|
+ for (MesLine mesLine : list) {
|
|
|
|
+ total += mesLine.getCurrentQty();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return R.ok(total);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取合格率 星期1-7
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public R<Map<String, Map<String,Object>>> getPassRate() {
|
|
|
|
+ //获取当前日期
|
|
|
|
+ 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);
|
|
|
|
+ //创建Map 用于存储统计结果 星期一:合格率
|
|
|
|
+ Map<String, Map<String,Object>> weekMap = new LinkedHashMap<>();
|
|
|
|
+ //添加星期一-星期日
|
|
|
|
+ for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
|
|
|
|
+ String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
|
+ weekMap.put(dayOfWeekName, new HashMap<>());
|
|
|
|
+ }
|
|
|
|
+ //遍历集合,统计每条产线的数据
|
|
|
|
+ if (boy != null && !boy.isEmpty()) {
|
|
|
|
+ for (MesLine mesLine : boy) {
|
|
|
|
+ // 获取创建日期
|
|
|
|
+ LocalDate createTime = mesLine.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
+ if (createTime.isAfter(mondayOfWeek.minusDays(1)) && createTime.isBefore(sundayOfWeek.plusDays(1))) {
|
|
|
|
+ DayOfWeek dayOfWeek = createTime.getDayOfWeek();
|
|
|
|
+ String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
|
+ Map<String, Object> dayStats = weekMap.get(dayOfWeekName);
|
|
|
|
+
|
|
|
|
+ // 累加总产量
|
|
|
|
+ Long totalOutput = (Long) dayStats.getOrDefault("产量", 0L);
|
|
|
|
+ totalOutput += mesLine.getCurrentQty();
|
|
|
|
+ dayStats.put("产量", totalOutput);
|
|
|
|
+
|
|
|
|
+ // 累加不合格数量
|
|
|
|
+ Long totalPoorQty = (Long) dayStats.getOrDefault("不合格数", 0L);
|
|
|
|
+ totalPoorQty += mesLine.getPoorQty();
|
|
|
|
+ dayStats.put("不合格数", totalPoorQty);
|
|
|
|
+
|
|
|
|
+ // 计算合格数量
|
|
|
|
+ Long totalQualifiedQty = totalOutput - totalPoorQty;
|
|
|
|
+ dayStats.put("合格数", totalQualifiedQty);
|
|
|
|
+
|
|
|
|
+ // 更新合格率
|
|
|
|
+ if (totalOutput > 0) {
|
|
|
|
+ double qualificationRate = ((double) totalQualifiedQty / (double) totalOutput) * 100;
|
|
|
|
+ dayStats.put("合格率", String.format(Locale.US, "%.2f%%", qualificationRate));
|
|
|
|
+ } else {
|
|
|
|
+ dayStats.put("合格率", "0.00%");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return R.ok(weekMap);
|
|
|
|
+ }
|
|
}
|
|
}
|