Prechádzať zdrojové kódy

产线新增人均产出实现

zhangxin 1 mesiac pred
rodič
commit
5620ddf331

+ 2 - 0
prod-line-comm/src/main/java/com/huaxia/comm/domain/imes/MesLine.java

@@ -48,4 +48,6 @@ public class MesLine implements Serializable {
 
     @TableField(exist = false)
     private String day;//每天(星期几)
+
+    private Integer workerQty;//投产人员数量
 }

+ 20 - 5
prod-line-imes/src/main/java/com/huaxia/imes/controller/MesLineController.java

@@ -38,7 +38,7 @@ public class MesLineController extends BaseController {
      * @return
      */
     @GetMapping("/list")
-    public AjaxResult queryList(MesLineBO bo,@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize ) {
+    public AjaxResult queryList(MesLineBO bo, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
         IPage<MesLineVO> list = mesLineService.queryList(bo, pageNum, pageSize);
         return AjaxResult.success(new TableDataInfo(list.getRecords(), (int) list.getTotal()));
 
@@ -85,40 +85,55 @@ public class MesLineController extends BaseController {
 
     /**
      * 获取 星期1-7 统计数据
+     *
      * @return
      */
     @GetMapping("/count_day")
-    public R<Map<String,Map<String,Long>>> list(){
+    public R<Map<String, Map<String, Long>>> list() {
         return mesLineService.countDay();
     }
 
 
     /**
      * 获取每周的产线数据
+     *
      * @return
      */
     @GetMapping("/week_qty")
-    public R<Map<String,Map<String,Object>>> queryDay(){
+    public R<Map<String, Map<String, Object>>> queryDay() {
         return mesLineService.queryDay();
     }
 
 
     /**
      * 获取本月总产量
+     *
      * @return
      */
     @GetMapping("/month_total")
-    public R<Long> getMonthTotal(){
+    public R<Long> getMonthTotal() {
         return mesLineService.getMonthTotal();
     }
 
 
     /**
      * 获取合格率(星期1-7)
+     *
      * @return
      */
     @GetMapping("/pass_rate")
-    public R<Map<String,Map<String,Object>>> getPassRate(){
+    public R<Map<String, Map<String, Object>>> getPassRate() {
         return mesLineService.getPassRate();
     }
+
+
+    /**
+     * 获取人均产出(星期1-7)
+     *
+     * @return
+     */
+    @GetMapping("/worker_qty")
+    public R<Map<String,Map<String, Map<String,Object>>>> getWorkerQty() {
+        return mesLineService.getWorkerQty();
+    }
 }

+ 78 - 9
prod-line-imes/src/main/java/com/huaxia/imes/service/MesLineService.java

@@ -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);
+    }
 }