From 9a07b2f0eeb632f698a87e49d1dcb25ec83fbaa5 Mon Sep 17 00:00:00 2001
From: lius <Lius2225@163.com>
Date: 星期三, 02 八月 2023 10:05:13 +0800
Subject: [PATCH] 设备日利用率

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/DayUtilizationRateDto.java                   |   19 ++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java |   95 +++++++++++++++++++++--
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEfficiencyReportController.java    |   12 +++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayRateDto.java                               |   17 ++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java                              |   19 ++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/MdcEfficiencyReportService.java          |   12 +++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateQueryVo.java                |   35 ++++++++
 7 files changed, 199 insertions(+), 10 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEfficiencyReportController.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEfficiencyReportController.java
index 0e2413e..cc80bee 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEfficiencyReportController.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEfficiencyReportController.java
@@ -8,6 +8,7 @@
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.mdc.dto.ComparativeAnalysisDto;
+import org.jeecg.modules.mdc.dto.DayUtilizationRateDto;
 import org.jeecg.modules.mdc.service.MdcEfficiencyReportService;
 import org.jeecg.modules.mdc.vo.*;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -15,6 +16,7 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * @author: LiuS
@@ -79,4 +81,14 @@
         return Result.OK(result);
     }
 
+    @AutoLog(value = "璁惧鏁堢巼鎶ヨ〃-璁惧鏃ュ埄鐢ㄧ巼")
+    @ApiOperation(value = "璁惧鏁堢巼鎶ヨ〃-璁惧鏃ュ埄鐢ㄧ巼", notes = "璁惧鏁堢巼鎶ヨ〃-璁惧鏃ュ埄鐢ㄧ巼")
+    @GetMapping("/dayUtilizationRate")
+    public Result dayUtilizationRate(DayUtilizationRateQueryVo vo) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = user.getId();
+        DayUtilizationRateDto result = mdcEfficiencyReportService.dayUtilizationRate(userId, vo);
+        return Result.OK(result);
+    }
+
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/DayUtilizationRateDto.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/DayUtilizationRateDto.java
new file mode 100644
index 0000000..0435c9e
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/DayUtilizationRateDto.java
@@ -0,0 +1,19 @@
+package org.jeecg.modules.mdc.dto;
+
+import lombok.Data;
+import org.jeecg.modules.mdc.vo.DayRateDto;
+
+import java.util.List;
+
+/**
+ * @author: LiuS
+ * @create: 2023-08-01 14:44
+ */
+@Data
+public class DayUtilizationRateDto {
+
+    private List<String> dateList;
+
+    private List<DayRateDto> dayRateDto;
+
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/MdcEfficiencyReportService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/MdcEfficiencyReportService.java
index b584468..aa5ffd7 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/MdcEfficiencyReportService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/MdcEfficiencyReportService.java
@@ -1,7 +1,10 @@
 package org.jeecg.modules.mdc.service;
 
 import org.jeecg.modules.mdc.dto.ComparativeAnalysisDto;
+import org.jeecg.modules.mdc.dto.DayUtilizationRateDto;
 import org.jeecg.modules.mdc.vo.*;
+
+import java.util.List;
 
 /**
  * @author: LiuS
@@ -53,4 +56,13 @@
      * @return
      */
     ComparativeAnalysisDto comparativeAnalysis(String userId, ComparativeAnalysisQueryVo vo);
+
+    /**
+     * 璁惧鏃ュ埄鐢ㄧ巼鍒嗘璁$畻
+     *
+     * @param userId
+     * @param vo
+     * @return
+     */
+    DayUtilizationRateDto dayUtilizationRate(String userId, DayUtilizationRateQueryVo vo);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
index bf39c27..30b6fd4 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
@@ -7,15 +7,9 @@
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.modules.mdc.dto.*;
-import org.jeecg.modules.mdc.entity.MdcEquipment;
-import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalShiftInfo;
-import org.jeecg.modules.mdc.entity.MdcShiftSub;
-import org.jeecg.modules.mdc.entity.MdcUtilizationRate;
+import org.jeecg.modules.mdc.entity.*;
 import org.jeecg.modules.mdc.mapper.MdcEfficiencyReportMapper;
-import org.jeecg.modules.mdc.service.IMdcEquipmentService;
-import org.jeecg.modules.mdc.service.IMdcShiftSubService;
-import org.jeecg.modules.mdc.service.IMdcUtilizationRateService;
-import org.jeecg.modules.mdc.service.MdcEfficiencyReportService;
+import org.jeecg.modules.mdc.service.*;
 import org.jeecg.modules.mdc.util.DateUtils;
 import org.jeecg.modules.mdc.vo.*;
 import org.jeecg.modules.system.entity.MdcProduction;
@@ -58,6 +52,9 @@
 
     @Resource
     private IMdcShiftSubService mdcShiftSubService;
+
+    @Resource
+    private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService;
 
     /**
      * 鍒╃敤鐜囨姤琛�
@@ -653,8 +650,9 @@
                     mdcEfficiencyShiftResultDto.setOpenLong(equipmentStatisticalShiftInfo.getOpenLong());
                     mdcEfficiencyShiftResultDto.setWaitLong(equipmentStatisticalShiftInfo.getWaitLong());
                     mdcEfficiencyShiftResultDto.setOpenRate(equipmentStatisticalShiftInfo.getOpenLong().divide(equipmentStatisticalShiftInfo.getTotalLong(), 6, BigDecimal.ROUND_HALF_UP));
+                    long rate = mdcEfficiencyShiftResultDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
                     for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
-                        if (mdcEfficiencyShiftResultDto.getUtilizationRate().longValue() * 100 >= mdcUtilizationRate.getMinimumRange() && mdcEfficiencyShiftResultDto.getUtilizationRate().longValue() * 100 < mdcUtilizationRate.getMaximumRange()) {
+                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
                             mdcEfficiencyShiftResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
                         }
                     }
@@ -866,6 +864,82 @@
         return result;
     }
 
+    /**
+     * 璁惧鏃ュ埄鐢ㄧ巼
+     *
+     * @param vo
+     * @return
+     */
+    @Override
+    public DayUtilizationRateDto dayUtilizationRate(String userId, DayUtilizationRateQueryVo vo) {
+        DayUtilizationRateDto result = new DayUtilizationRateDto();
+        if (StringUtils.isBlank(vo.getEquipmentId())) {
+            List<String> equipmentIds;
+            // 鑾峰彇鐢ㄦ埛鎷ユ湁璁惧鏉冮檺
+            if ("2".equals(vo.getTypeTree())) {
+                // 閮ㄩ棬灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
+            } else {
+                // 浜х嚎灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
+            }
+            if (equipmentIds != null && !equipmentIds.isEmpty()) {
+                vo.setEquipmentId(equipmentIds.get(0));
+            }
+        }
+
+        List<String> dateList = new ArrayList<>();
+        for (int i = 1; i <= 24 / vo.getTimeType(); i++) {
+            if (i * vo.getTimeType() < 10) {
+                dateList.add("0" + i * vo.getTimeType() + ":00");
+            } else {
+                dateList.add(i * vo.getTimeType() + ":00");
+            }
+        }
+
+//        result.setDateList(dateList);
+
+        dateList.add(0, "00:00");
+
+        List<DayRateDto> dayRateDtoList = new ArrayList<>();
+        for (int i = 0; i < dateList.size() - 1; i++) {
+            DayRateDto dayRateDto = new DayRateDto();
+            dayRateDto.setDateTime(dateList.get(i + 1));
+            String dateTime = DateUtils.dateConvertion(vo.getDateTime());
+            Date startTime = DateUtils.toDate(dateTime + " " + dateList.get(i), DateUtils.STR_DATE_TIME_MIN);
+            Date endTime = DateUtils.toDate(dateTime + " " + dateList.get(i + 1), DateUtils.STR_DATE_TIME_MIN);
+            List<MdcEquipmentRunningSection> runningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSection(vo.getEquipmentId(), startTime.getTime(), endTime.getTime());
+            if (runningSections != null && !runningSections.isEmpty()) {
+                // 鏃堕棿淇
+                runningSections.get(0).setStartTime(startTime);
+                if (runningSections.size() > 1) {
+                    runningSections.get(runningSections.size() - 1).setEndTime(endTime);
+                } else {
+                    runningSections.get(0).setEndTime(endTime);
+                }
+                // 鍒╃敤鐜囪绠�
+                BigDecimal processLong = new BigDecimal("0");
+                for (MdcEquipmentRunningSection runningSection : runningSections) {
+                    if (runningSection.getStatus() == 3) {
+                        long duration = DateUtils.differentSecond(runningSection.getStartTime(), runningSection.getEndTime());
+                        processLong = processLong.add(new BigDecimal(duration));
+                    }
+                }
+                BigDecimal totalLong = new BigDecimal(vo.getTimeType()).multiply(new BigDecimal("60")).multiply(new BigDecimal("60"));
+                BigDecimal utilizationRate = processLong.divide(totalLong, 6, BigDecimal.ROUND_HALF_UP);
+                dayRateDto.setUtilizationRate(utilizationRate);
+            } else {
+                dayRateDto.setUtilizationRate(new BigDecimal("0"));
+            }
+            dayRateDtoList.add(dayRateDto);
+        }
+        dateList.remove(0);
+        result.setDateList(dateList);
+        result.setDayRateDto(dayRateDtoList);
+
+        return result;
+    }
+
     private StatisticalAnalysisVo efficiencyStatisticalRate(List<MdcEfficiencyDto> efficiencyList) {
         StatisticalAnalysisVo vo = new StatisticalAnalysisVo();
         for (MdcEfficiencyDto mdcEfficiencyDto : efficiencyList) {
@@ -892,8 +966,9 @@
                     mdcEfficiencyResultDto.setOpenLong(efficiencyDto.getOpenLong());
                     mdcEfficiencyResultDto.setWaitLong(efficiencyDto.getWaitLong());
                     mdcEfficiencyResultDto.setCloseLong(efficiencyDto.getCloseLong());
+                    long rate = efficiencyDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
                     for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
-                        if (efficiencyDto.getUtilizationRate().longValue() * 100 >= mdcUtilizationRate.getMinimumRange() && efficiencyDto.getUtilizationRate().longValue() * 100 < mdcUtilizationRate.getMaximumRange()) {
+                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
                             mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
                         }
                     }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
index 401b6ce..5e77fa0 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
@@ -1038,4 +1038,23 @@
             return 0;
         }
     }
+
+    /**
+     * 鏃ユ湡杞崲锛屽皢鎺ュ彛杩斿洖鐨�20180524杞负2018-05-24
+     *
+     * @param str
+     * @return
+     */
+    public static String dateConvertion(String str) {
+        Date parse = null;
+        String dateString = "";
+        try {
+            parse = new SimpleDateFormat("yyyyMMdd").parse(str);
+            dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse);
+        } catch (ParseException e) {
+            dateString = null;
+        }
+
+        return dateString;
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayRateDto.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayRateDto.java
new file mode 100644
index 0000000..8fe2b46
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayRateDto.java
@@ -0,0 +1,17 @@
+package org.jeecg.modules.mdc.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author: LiuS
+ * @create: 2023-08-01 15:28
+ */
+@Data
+public class DayRateDto {
+
+    private String dateTime;
+    private BigDecimal utilizationRate;
+
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateQueryVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateQueryVo.java
new file mode 100644
index 0000000..1994ea2
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateQueryVo.java
@@ -0,0 +1,35 @@
+package org.jeecg.modules.mdc.vo;
+
+import lombok.Data;
+
+/**
+ * @author: LiuS
+ * @create: 2023-08-01 14:33
+ */
+@Data
+public class DayUtilizationRateQueryVo {
+
+    /**
+     * 鏃ユ湡  ->  20220101
+     */
+    private String dateTime;
+
+    /**
+     * 璁惧Id
+     */
+    private String equipmentId;
+    /**
+     * 璁惧鍚嶇О
+     */
+    private String equipmentName;
+    /**
+     * 鏍戠被鍨�    ->  1:杞﹂棿灞傜骇   2:閮ㄩ棬灞傜骇
+     */
+    private String typeTree;
+    /**
+     * 鏃堕棿闂撮殧
+     */
+    private Integer timeType;
+
+
+}

--
Gitblit v1.9.3