|
@@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
+
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.*;
|
|
@@ -71,6 +72,9 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
|
|
|
if (boy.getCreateTime() == null) {
|
|
|
boy.setCreateTime(new Date());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ Assert.isTrue(boy.getCreateTime().after(new Date()), "500-创建时间不能大于今天");
|
|
|
}
|
|
|
|
|
|
LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
@@ -91,6 +95,11 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
* @param boy
|
|
|
*/
|
|
|
public void edit(MesLine boy) {
|
|
|
+
|
|
|
+ this.check(boy);
|
|
|
+
|
|
|
+ Assert.isTrue(boy.getCreateTime() != null, "500-时间不能为空");
|
|
|
+ Assert.isTrue(boy.getCreateTime().after(new Date()), "500-创建时间不能大于今天");
|
|
|
boy.setUpdateTime(new Date())
|
|
|
.setUpdateBy(SecurityUtils.getUsername());
|
|
|
this.updateById(boy);
|
|
@@ -234,7 +243,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public R<Long> getMonthTotal() {
|
|
|
+ public R<Map<String,Long>> getMonthTotal() {
|
|
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
|
@@ -244,14 +253,21 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
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()) {
|
|
|
+
|
|
|
+ Map<String, Long> totalByLine = new HashMap<>();
|
|
|
+ if (list != null && !list.isEmpty()){
|
|
|
for (MesLine mesLine : list) {
|
|
|
- total += mesLine.getCurrentQty();
|
|
|
+ String lineName = mesLine.getLineName();
|
|
|
+ Long currentQty = mesLine.getCurrentQty();
|
|
|
+ if (totalByLine.containsKey(lineName)){
|
|
|
+ totalByLine.put(lineName, totalByLine.get(lineName) + currentQty);
|
|
|
+ }else {
|
|
|
+ totalByLine.put(lineName, currentQty);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- return R.ok(total);
|
|
|
+ return R.ok(totalByLine);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -259,7 +275,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public R<Map<String, Map<String, Object>>> getPassRate() {
|
|
|
+ public R<Map<String, List<Map<String, Map<String, Object>>>>> getPassRate() {
|
|
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
|
@@ -272,8 +288,12 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
List<MesLine> boy = mesLineMapper.selectList(wr);
|
|
|
|
|
|
Map<String, Map<String, Object>> weekMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ Map<String, List<Map<String, Map<String, Object>>>> map = new LinkedHashMap<>();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
|
|
|
+
|
|
|
String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
weekMap.put(dayOfWeekName, new HashMap<>());
|
|
|
}
|
|
@@ -315,12 +335,85 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- return R.ok(weekMap);
|
|
|
+ return R.ok(weekMap);*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
|
|
|
+ String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
+ if (boy != null && !boy.isEmpty()) {
|
|
|
+ for (MesLine mesLine : boy) {
|
|
|
+
|
|
|
+ String lineName = mesLine.getLineName();
|
|
|
+ if (!map.containsKey(lineName)) {
|
|
|
+ map.put(lineName, new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Map<String, Object>>> mapList = map.get(lineName);
|
|
|
+ boolean found = false;
|
|
|
+ for (Map<String, Map<String, Object>> dayData : mapList) {
|
|
|
+ if (dayData.containsKey(dayOfWeekName)) {
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found) {
|
|
|
+ Map<String, Map<String, Object>> dayData = new HashMap<>();
|
|
|
+ dayData.put(dayOfWeekName, new HashMap<>());
|
|
|
+ mapList.add(dayData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ String lineName = mesLine.getLineName();
|
|
|
+ List<Map<String, Map<String, Object>>> lineData = map.get(lineName);
|
|
|
+ for (Map<String, Map<String, Object>> dayData : lineData) {
|
|
|
+ if (dayData.containsKey(dayOfWeekName)) {
|
|
|
+ Map<String, Object> stats = dayData.get(dayOfWeekName);
|
|
|
+
|
|
|
+ Long totalOutput = (Long) stats.getOrDefault("产量", 0L);
|
|
|
+ Long count = mesLine.getCurrentQty();
|
|
|
+ Long poorQty = mesLine.getPoorQty();
|
|
|
+ totalOutput += (count + poorQty);
|
|
|
+ stats.put("产量", totalOutput);
|
|
|
+
|
|
|
+
|
|
|
+ Long totalPoorQty = (Long) stats.getOrDefault("不合格数量", 0L);
|
|
|
+ totalPoorQty += mesLine.getPoorQty();
|
|
|
+ stats.put("不合格数量", totalPoorQty);
|
|
|
+
|
|
|
+
|
|
|
+ Long totalQualifiedQty = (Long) stats.getOrDefault("合格数量", 0L);
|
|
|
+ totalQualifiedQty += count;
|
|
|
+ stats.put("合格数量", totalQualifiedQty);
|
|
|
+
|
|
|
+
|
|
|
+ if (totalOutput > 0) {
|
|
|
+ double qualificationRate = ((double) totalQualifiedQty / (double) totalOutput) * 100;
|
|
|
+ stats.put("合格率", String.format(Locale.US, "%.2f%%", qualificationRate));
|
|
|
+ } else {
|
|
|
+ stats.put("合格率", "0.00%");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(map);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- * 获取人均产出(星期1-7)
|
|
|
+ * 获取人均产出(按月)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
@@ -337,6 +430,23 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
List<MesLine> boy = mesLineMapper.selectList(wr);
|
|
|
|
|
|
Map<String, Map<String, Map<String, Object>>> weekMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ LocalDate currentDate = firstDayOfMonth;
|
|
|
+ while (currentDate.isBefore(now.plusDays(1))) {
|
|
|
+ String dateString = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ if (boy != null && !boy.isEmpty()) {
|
|
|
+ for (MesLine mesLine : boy) {
|
|
|
+ String lineName = mesLine.getLineName();
|
|
|
+ Map<String, Map<String, Object>> dayStats = weekMap.computeIfAbsent(lineName, k -> new TreeMap<>(Comparator.naturalOrder()));
|
|
|
+ dayStats.putIfAbsent(dateString, new HashMap<String, Object>() {{
|
|
|
+ put("产量", 0L);
|
|
|
+ put("每日工作人数", 0);
|
|
|
+ put("人均产出", BigDecimal.ZERO);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ currentDate = currentDate.plusDays(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if (boy != null && !boy.isEmpty()) {
|
|
|
for (MesLine mesLine : boy) {
|
|
@@ -347,8 +457,8 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
|
|
|
String dateString = createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
|
- Map<String, Map<String, Object>> dayStats = weekMap.computeIfAbsent(lineName, k -> new HashMap<>());
|
|
|
- Map<String, Object> lineStats = dayStats.computeIfAbsent(dateString, k -> new HashMap<>());
|
|
|
+ Map<String, Map<String, Object>> dayStats = weekMap.get(lineName);
|
|
|
+ Map<String, Object> lineStats = dayStats.get(dateString);
|
|
|
|
|
|
Long totalOutPut = (Long) lineStats.getOrDefault("产量", 0L);
|
|
|
Long count = mesLine.getCurrentQty();
|
|
@@ -378,8 +488,6 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return R.ok(weekMap);
|
|
|
}
|
|
|
}
|