From d18833c3accb1e01d01a832887f6dfbd0c025d41 Mon Sep 17 00:00:00 2001 From: lius <Lius2225@163.com> Date: 星期三, 02 八月 2023 15:35:58 +0800 Subject: [PATCH] 设备日利用率对比接口 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java | 72 +++++++++++++++++++++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEfficiencyReportController.java | 11 +++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateContrastQueryVo.java | 42 ++++++++++++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java | 21 +++++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/MdcEfficiencyReportService.java | 11 +++ 5 files changed, 152 insertions(+), 5 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 cc80bee..62a2f94 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 @@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.List; /** * @author: LiuS @@ -91,4 +90,14 @@ return Result.OK(result); } + @AutoLog(value = "璁惧鏁堢巼鎶ヨ〃-璁惧鏃ュ埄鐢ㄧ巼瀵规瘮") + @ApiOperation(value = "璁惧鏁堢巼鎶ヨ〃-璁惧鏃ュ埄鐢ㄧ巼瀵规瘮", notes = "璁惧鏁堢巼鎶ヨ〃-璁惧鏃ュ埄鐢ㄧ巼瀵规瘮") + @GetMapping("/dayUtilizationRateContrast") + public Result dayUtilizationRateContrast(DayUtilizationRateContrastQueryVo vo) { + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String userId = user.getId(); + DayUtilizationRateDto result = mdcEfficiencyReportService.dayUtilizationRateContrast(userId, vo); + return Result.OK(result); + } + } 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 aa5ffd7..abfd3f9 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 @@ -4,8 +4,6 @@ import org.jeecg.modules.mdc.dto.DayUtilizationRateDto; import org.jeecg.modules.mdc.vo.*; -import java.util.List; - /** * @author: LiuS * @create: 2023-06-15 17:25 @@ -65,4 +63,13 @@ * @return */ DayUtilizationRateDto dayUtilizationRate(String userId, DayUtilizationRateQueryVo vo); + + /** + * 璁惧鏃ュ埄鐢ㄧ巼瀵规瘮璁$畻 + * + * @param userId + * @param vo + * @return + */ + DayUtilizationRateDto dayUtilizationRateContrast(String userId, DayUtilizationRateContrastQueryVo 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 6cedc45..334fbf9 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 @@ -906,8 +906,8 @@ 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); + Date startTime = DateUtils.toDate(dateTime + " " + dateList.get(i) + ":00", DateUtils.STR_DATE_TIME_SMALL); + Date endTime = DateUtils.toDate(dateTime + " " + dateList.get(i + 1) + ":00", DateUtils.STR_DATE_TIME_SMALL); List<MdcEquipmentRunningSection> runningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSection(vo.getEquipmentId(), startTime.getTime(), endTime.getTime()); if (runningSections != null && !runningSections.isEmpty()) { // 鏃堕棿淇 @@ -940,6 +940,74 @@ return result; } + /** + * 璁惧鏃ュ埄鐢ㄧ巼瀵规瘮鍒嗘瀽 + * + * @param userId + * @param vo + * @return + */ + @Override + public DayUtilizationRateDto dayUtilizationRateContrast(String userId, DayUtilizationRateContrastQueryVo 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)); + } + } + result.setEquipmentId(vo.getEquipmentId()); + MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, vo.getEquipmentId())); + result.setEquipmentName(mdcEquipment.getEquipmentName()); + Date start = DateUtils.toDate(vo.getStartDate(), DateUtils.STRDATE); + Date end = DateUtils.toDate(vo.getEndDate(), DateUtils.STRDATE); + List<String> dateList = DateUtils.getDatesStringLists(start, end); + result.setDateList(dateList); + List<String> datesStringList = DateUtils.getDatesStringList(start, end); + List<DayRateDto> dayRateDtoList = new ArrayList<>(); + for (String date : datesStringList) { + DayRateDto dayRateDto = new DayRateDto(); + String format = DateUtils.format(DateUtils.toDate(date, DateUtils.STR_DATE), DateUtils.STR_MMDD); + dayRateDto.setDateTime(format); + Date startTime = DateUtils.toDate(date + " " + vo.getStartTime() + ":00", DateUtils.STR_DATE_TIME_SMALL); + Date endTime = DateUtils.toDate(date + " " + vo.getEndTime() + ":00", DateUtils.STR_DATE_TIME_SMALL); + 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(DateUtils.differentSecond(startTime, endTime)); + BigDecimal utilizationRate = processLong.divide(totalLong, 6, BigDecimal.ROUND_HALF_UP); + dayRateDto.setUtilizationRate(utilizationRate); + } else { + dayRateDto.setUtilizationRate(new BigDecimal("0")); + } + dayRateDtoList.add(dayRateDto); + } + result.setDayRateDto(dayRateDtoList); + return result; + } + private StatisticalAnalysisVo efficiencyStatisticalRate(List<MdcEfficiencyDto> efficiencyList) { StatisticalAnalysisVo vo = new StatisticalAnalysisVo(); for (MdcEfficiencyDto mdcEfficiencyDto : efficiencyList) { 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 5e77fa0..b3fbdc4 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 @@ -164,6 +164,7 @@ public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS"; public static final String STR_HHMMSS = "HH:mm:ss"; public static final String STR_HHMM = "HH:mm"; + public static final String STR_MMDD = "MM-dd"; /** * <p> @@ -672,6 +673,26 @@ return list; } + /** + * 鑾峰彇start/end鐨勬墍鏈夋棩鏈熷瓧绗︿覆 鏍煎紡MM-dd + * + * @param start + * @param end + * @return + */ + public static List<String> getDatesStringLists(Date start, Date end) { + List<String> list = new ArrayList<>(); + int i = getDays(start, end); + for (int j = 0; j <= i; j++) { + if (j == 0) { + list.add(format(start, STR_MMDD)); + } else { + list.add(format(plusTime(start, j), STR_MMDD)); + } + } + return list; + } + public static List<String> getMonthBetween(Date start, Date end) { List<String> list = new ArrayList<>(); Calendar min = Calendar.getInstance(); diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateContrastQueryVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateContrastQueryVo.java new file mode 100644 index 0000000..9611749 --- /dev/null +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/DayUtilizationRateContrastQueryVo.java @@ -0,0 +1,42 @@ +package org.jeecg.modules.mdc.vo; + +import lombok.Data; + +/** + * @author: LiuS + * @create: 2023-08-02 13:50 + */ +@Data +public class DayUtilizationRateContrastQueryVo { + + /** + * 鏃ユ湡 -> 20220101 + */ + private String startDate; + /** + * 鏃ユ湡 -> 20220101 + */ + private String endDate; + + /** + * 璁惧Id + */ + private String equipmentId; + /** + * 璁惧鍚嶇О + */ + private String equipmentName; + /** + * 鏍戠被鍨� -> 1:杞﹂棿灞傜骇 2:閮ㄩ棬灞傜骇 + */ + private String typeTree; + /** + * 鏃堕棿娈� + */ + private String startTime; + /** + * 鏃堕棿娈� + */ + private String endTime; + +} -- Gitblit v1.9.3