|
@@ -21,9 +21,11 @@ import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import sun.util.resources.LocaleData;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.*;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.TextStyle;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
@@ -77,8 +79,10 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
|
wr.eq(MesLine::getLineName, boy.getLineName());
|
|
|
wr.eq(MesLine::getCreateTime, boy.getCreateTime());
|
|
|
+ //序列化时间格式 年月日
|
|
|
+ String format = boy.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString();
|
|
|
long aLong = this.count(wr);
|
|
|
- Assert.isTrue(aLong == 0, String.format("500-产线%s-%s已存在", boy.getLineName(), boy.getCreateTime()));
|
|
|
+ Assert.isTrue(aLong == 0, String.format("500-产线%s-%s已存在", boy.getLineName(), format));
|
|
|
//获取登录人信息
|
|
|
boy.setCreateBy(SecurityUtils.getUsername());
|
|
|
this.save(boy);
|
|
@@ -125,7 +129,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public R<Map<String, Map<String,Long>>> countDay() {
|
|
|
+ public R<Map<String, Map<String, Long>>> countDay() {
|
|
|
|
|
|
//获取当前时间
|
|
|
LocalDate now = LocalDate.now();
|
|
@@ -137,7 +141,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
|
wr.between(MesLine::getCreateTime, mondayOfWeek, sundayOfWeek);
|
|
|
List<MesLine> boy = mesLineMapper.selectList(wr);
|
|
|
- Map<String, Map<String,Long>> map = new LinkedHashMap<>();//格式 key:星期几 value:数量
|
|
|
+ Map<String, Map<String, Long>> map = new LinkedHashMap<>();//格式 key:星期几 value:数量
|
|
|
// 初始化Map中的键,并设置默认值为0
|
|
|
for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
|
|
|
String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
@@ -201,7 +205,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
Long totalOutput = (Long) lineData.getOrDefault("产量", 0L);
|
|
|
Long count = mesLine.getCurrentQty();//产量=产量(包含合格数量)+不合格数量
|
|
|
Long poorQty = mesLine.getPoorQty();//不合格数量
|
|
|
- totalOutput+=(count+poorQty);
|
|
|
+ totalOutput += (count + poorQty);
|
|
|
lineData.put("产量", totalOutput);
|
|
|
//累加不合格数量
|
|
|
Long totalPoorQty = (Long) lineData.getOrDefault("不合格数量", 0L);
|
|
@@ -211,7 +215,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
//计算合格数量
|
|
|
Long totalQualifiedQty = (Long) lineData.getOrDefault("合格数量", 0L);
|
|
|
totalQualifiedQty += count;
|
|
|
- lineData.put("合格数量",totalQualifiedQty);
|
|
|
+ lineData.put("合格数量", totalQualifiedQty);
|
|
|
//更新合格率
|
|
|
if (totalOutput > 0) {
|
|
|
double qualificationRate = ((double) totalQualifiedQty / (double) totalOutput) * 100;
|
|
@@ -258,7 +262,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public R<Map<String, Map<String,Object>>> getPassRate() {
|
|
|
+ public R<Map<String, Map<String, Object>>> getPassRate() {
|
|
|
//获取当前日期
|
|
|
LocalDate now = LocalDate.now();
|
|
|
//计算本周的星期一
|
|
@@ -270,7 +274,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
wr.between(MesLine::getCreateTime, mondayOfWeek, sundayOfWeek);
|
|
|
List<MesLine> boy = mesLineMapper.selectList(wr);
|
|
|
//创建Map 用于存储统计结果 星期一:合格率
|
|
|
- Map<String, Map<String,Object>> weekMap = new LinkedHashMap<>();
|
|
|
+ Map<String, Map<String, Object>> weekMap = new LinkedHashMap<>();
|
|
|
//添加星期一-星期日
|
|
|
for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
|
|
|
String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
@@ -290,7 +294,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
Long totalOutput = (Long) dayStats.getOrDefault("产量", 0L);
|
|
|
Long count = mesLine.getCurrentQty();//产量+不合格数
|
|
|
Long poorQty = mesLine.getPoorQty();//不合格数量
|
|
|
- totalOutput+=(count+poorQty);
|
|
|
+ totalOutput += (count + poorQty);
|
|
|
dayStats.put("产量", totalOutput);
|
|
|
|
|
|
// 累加不合格数量
|
|
@@ -301,7 +305,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
//计算合格数量
|
|
|
Long totalQualifiedQty = (Long) dayStats.getOrDefault("合格数量", 0L);
|
|
|
totalQualifiedQty += count;
|
|
|
- dayStats.put("合格数量",totalQualifiedQty);
|
|
|
+ dayStats.put("合格数量", totalQualifiedQty);
|
|
|
|
|
|
// 更新合格率
|
|
|
if (totalOutput > 0) {
|
|
@@ -316,4 +320,69 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
|
|
|
}
|
|
|
return R.ok(weekMap);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取人均产出(星期1-7)
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public R<Map<String, Map<String, Map<String, Object>>>> getWorkerQty() {
|
|
|
+ //获取当前系统时间
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ //计算当月的第一天
|
|
|
+ LocalDate firstDayOfMonth = now.withDayOfMonth(1);
|
|
|
+ //计算当月的最后一天
|
|
|
+ LocalDate lastDayOfMonth = now.withDayOfMonth(now.lengthOfMonth());
|
|
|
+ //获取当月的数据
|
|
|
+ LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
|
|
|
+ wr.between(MesLine::getCreateTime, firstDayOfMonth, lastDayOfMonth);
|
|
|
+ List<MesLine> boy = mesLineMapper.selectList(wr);
|
|
|
+ //创建Map 用于存储统计结果 日期:产线 每日产量 每日工作人数 人均产出
|
|
|
+ Map<String, Map<String, Map<String, Object>>> weekMap = new LinkedHashMap<>();
|
|
|
+ //遍历集合 获取某条线产量
|
|
|
+ if (boy != null && !boy.isEmpty()) {
|
|
|
+ for (MesLine mesLine : boy) {
|
|
|
+ //获取产线名称
|
|
|
+ String lineName = mesLine.getLineName();
|
|
|
+ // 获取创建日期
|
|
|
+ LocalDate createTime = mesLine.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ //序列化日期格式 年月日
|
|
|
+ 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<>());
|
|
|
+ //累加产量
|
|
|
+ Long totalOutPut = (Long) lineStats.getOrDefault("产量", 0L);
|
|
|
+ Long count = mesLine.getCurrentQty();//产量
|
|
|
+ totalOutPut += count;//产量
|
|
|
+ lineStats.put("产量", totalOutPut);
|
|
|
+ //累加每条线的投产人员
|
|
|
+ Integer workerQty = (Integer) lineStats.getOrDefault("每日工作人数", 0);
|
|
|
+ workerQty += mesLine.getWorkerQty();
|
|
|
+ lineStats.put("每日工作人数", workerQty);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 计算每个产线每天人均产出
|
|
|
+ for (Map.Entry<String, Map<String, Map<String, Object>>> entry : weekMap.entrySet()) {
|
|
|
+ String lineName = entry.getKey();
|
|
|
+ for (Map.Entry<String, Map<String, Object>> lineEntry : entry.getValue().entrySet()) {
|
|
|
+ String dateString = lineEntry.getKey();
|
|
|
+ Long totalOutput = (Long) lineEntry.getValue().get("产量");
|
|
|
+ Integer workerQty = (Integer) lineEntry.getValue().get("每日工作人数");
|
|
|
+ //计算平均人均产出
|
|
|
+ if (workerQty > 0) {
|
|
|
+ BigDecimal averageOutputPerPerson = BigDecimal.valueOf(totalOutput).divide(BigDecimal.valueOf(workerQty), 1, BigDecimal.ROUND_HALF_UP);
|
|
|
+ lineEntry.getValue().put("人均产出", averageOutputPerPerson);
|
|
|
+ } else {
|
|
|
+ lineEntry.getValue().put("人均产出", 0.0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return R.ok(weekMap);
|
|
|
+ }
|
|
|
}
|