package org.jeecg.modules.mdc.subcontrol.service.impl;
|
|
import org.apache.commons.lang.StringUtils;
|
import org.jeecg.modules.mdc.entity.EquipmentLog;
|
import org.jeecg.modules.mdc.service.*;
|
import org.jeecg.modules.mdc.subcontrol.service.MdcBigScreenService;
|
import org.jeecg.modules.mdc.subcontrol.vo.LastWeekDataRankingVo;
|
import org.jeecg.modules.mdc.subcontrol.vo.LastWeekDataVo;
|
import org.jeecg.modules.mdc.subcontrol.vo.MdcEquipmentOpVo;
|
import org.jeecg.modules.mdc.vo.MdcEquipmentVo;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.time.DayOfWeek;
|
import java.time.LocalDate;
|
import java.time.format.DateTimeFormatter;
|
import java.time.temporal.TemporalAdjusters;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author: LiuS
|
* @create: 2023-01-05 11:42
|
*/
|
@Service
|
public class MdcBigScreenServiceImpl implements MdcBigScreenService {
|
|
@Resource
|
private IMdcEquipmentService mdcEquipmentService;
|
|
@Resource
|
private IEquipmentStatisticalInfoService equipmentStatisticalInfoService;
|
@Autowired
|
private IMdcEquipmentStatisticalShiftInfoService mdcEquipmentStatisticalShiftInfoService;
|
|
|
@Resource
|
private IEquipmentLogService equipmentLogService;
|
|
|
/**
|
* 根据厂区id获取上周数据
|
*/
|
@Override
|
public Map<String, Object> findDataByLastWeek() {
|
Map<String, Object> result = new HashMap<>();
|
List<BigDecimal> openingRateList = new ArrayList<>();
|
List<BigDecimal> processingRateList = new ArrayList<>();
|
List<BigDecimal> shiftRateList = new ArrayList<>();
|
//获取上周周一日期和周六日期
|
LocalDate today = LocalDate.now().minusDays(7L);
|
LocalDate monday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
LocalDate saturday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SATURDAY));
|
List<String> dates = getMiddleDate(monday, saturday);
|
List<String> equipmentIdList = new ArrayList<>();
|
//根据厂区id获取厂区设备信息
|
equipmentIdList = mdcEquipmentService.listEquipmentId(null);
|
//上周利用率和开机率数据
|
List<LastWeekDataVo> lastWeekDataVos = equipmentStatisticalInfoService.findDataForBigScreen(equipmentIdList, monday.format(DateTimeFormatter.BASIC_ISO_DATE), saturday.format(DateTimeFormatter.BASIC_ISO_DATE));
|
if (lastWeekDataVos.isEmpty()) {
|
for (int i = 0; i < dates.size(); i++) {
|
openingRateList.add(new BigDecimal("0"));
|
processingRateList.add(new BigDecimal("0"));
|
}
|
} else {
|
for (int i = 0; i < dates.size(); i++) {
|
Integer size = equipmentStatisticalInfoService.findEquipmentId(equipmentIdList, dates.get(i));
|
if (dates.get(i).equals(lastWeekDataVos.get(i).getTheDate())) {
|
openingRateList.add(new BigDecimal(String.format("%.2f", (Float.parseFloat(lastWeekDataVos.get(i).getOpeningLong()) / (86400 * size) * 100))));
|
processingRateList.add(new BigDecimal(String.format("%.2f", (Float.parseFloat(lastWeekDataVos.get(i).getProcessingLong()) / (86400 * size) * 100))));
|
} else {
|
openingRateList.add(new BigDecimal("0"));
|
processingRateList.add(new BigDecimal("0"));
|
}
|
}
|
}
|
|
//上周班次利用率数据
|
List<LastWeekDataVo> lastWeekDataList = mdcEquipmentStatisticalShiftInfoService.findDataForBigScreen(equipmentIdList, monday.toString(), saturday.toString());
|
List<String> middleDates = getMiddleDates(monday, saturday);
|
if (lastWeekDataList.isEmpty()) {
|
for (int i = 0; i < middleDates.size(); i++) {
|
shiftRateList.add(new BigDecimal("0"));
|
}
|
} else {
|
for (int i = 0; i < middleDates.size(); i++) {
|
if (i < lastWeekDataList.size()) {
|
if (middleDates.get(i).equals(lastWeekDataList.get(i).getTheDate())
|
&& !"0".equals(lastWeekDataList.get(i).getTotalLong())) {
|
shiftRateList.add(new BigDecimal(lastWeekDataList.get(i).getProcessingLong()).
|
divide(new BigDecimal(lastWeekDataList.get(i).getTotalLong()),
|
6, BigDecimal.ROUND_HALF_UP)
|
.setScale(6, BigDecimal.ROUND_HALF_UP));
|
} else {
|
shiftRateList.add(new BigDecimal("0"));
|
}
|
}
|
else {
|
shiftRateList.add(new BigDecimal("0"));
|
}
|
}
|
}
|
result.put("openingRateList", openingRateList);
|
result.put("processingRateList", processingRateList);
|
result.put("shiftRateList", shiftRateList);
|
|
return result;
|
}
|
|
/**
|
* 根据厂区id获取上周运行效率排名
|
*/
|
@Override
|
public List<LastWeekDataRankingVo> findDataRankingByLastWeek() {
|
List<LastWeekDataRankingVo> voList = new ArrayList<>();
|
|
//获取上周周一日期和周六日期
|
LocalDate today = LocalDate.now();
|
String monday = today.minusDays(7).format(DateTimeFormatter.BASIC_ISO_DATE);
|
String saturday = today.minusDays(1).format(DateTimeFormatter.BASIC_ISO_DATE);
|
//根据id获取设备id集合
|
List<String> equipmentIdList = mdcEquipmentService.listEquipmentId(null);
|
if (!equipmentIdList.isEmpty()) {
|
List<LastWeekDataVo> lastWeekDataVos = equipmentStatisticalInfoService.findDataRankingForBigScreen(equipmentIdList, monday, saturday);
|
if (!lastWeekDataVos.isEmpty()) {
|
for (LastWeekDataVo lastWeekDataVo : lastWeekDataVos) {
|
Long size = equipmentStatisticalInfoService.selectSize(lastWeekDataVo.getEquipment(), monday, saturday);
|
lastWeekDataVo.setUtilization(new BigDecimal(String.format("%.2f", (Float.parseFloat(lastWeekDataVo.getProcessingLong()) / (86400 * size) * 100))));
|
}
|
List<LastWeekDataVo> collect = lastWeekDataVos.stream().sorted(Comparator.comparing(LastWeekDataVo::getUtilization).reversed()).collect(Collectors.toList());
|
if (collect.size() > 3) {
|
List<LastWeekDataVo> topList = collect.subList(0, 6);
|
for (LastWeekDataVo vo : topList) {
|
LastWeekDataRankingVo rankingVo = new LastWeekDataRankingVo();
|
rankingVo.setTopName(vo.getEquipment());
|
rankingVo.setTopRate(vo.getUtilization().toString());
|
voList.add(rankingVo);
|
}
|
}
|
|
}
|
}
|
|
return voList;
|
|
}
|
|
/**
|
* 获取设备当前状态
|
*/
|
@Override
|
public List<MdcEquipmentOpVo> findEquipmentStatus() {
|
List<MdcEquipmentOpVo> result = new ArrayList<>();
|
//根据id获取设备id集合
|
List<String> equipmentIdList = mdcEquipmentService.listEquipmentId(null);
|
|
if (!equipmentIdList.isEmpty()) {
|
List<EquipmentLog> logs = equipmentLogService.getEquipmentStatusList(equipmentIdList);
|
//根据设备id集合查询设备实时状态
|
for (EquipmentLog equipmentId : logs) {
|
if (equipmentId != null) {
|
MdcEquipmentOpVo vo = new MdcEquipmentOpVo();
|
vo.setEquipmentId(equipmentId.getEquipmentId());
|
if (equipmentId.getOporation() != null) {
|
switch (equipmentId.getOporation()) {
|
case 1:
|
vo.setOporation(1);
|
vo.setOporationDict("待机");
|
break;
|
case 2:
|
vo.setOporationDict("待机");
|
vo.setOporation(2);
|
break;
|
case 3:
|
vo.setOporationDict("运行");
|
vo.setOporation(3);
|
break;
|
case 22:
|
vo.setOporationDict("报警");
|
vo.setOporation(22);
|
break;
|
default:
|
vo.setOporationDict("关机");
|
vo.setOporation(0);
|
break;
|
}
|
} else {
|
vo.setOporation(0);
|
vo.setOporationDict("关机");
|
}
|
result.add(vo);
|
} else {
|
MdcEquipmentOpVo vo = new MdcEquipmentOpVo();
|
vo.setOporation(0);
|
vo.setOporationDict("关机");
|
result.add(vo);
|
}
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 获取全厂当前设备状态信息
|
*/
|
@Override
|
public Map<String, Object> findAllEquipmentStatus() {
|
int runCount = 0;
|
int standbyCount = 0;
|
int alarmCount = 0;
|
int offCount = 0;
|
List<String> equipmentIdList = mdcEquipmentService.listEquipmentId(null);
|
List<EquipmentLog> equipmentLogs = new ArrayList<>();
|
for (String equipmentId : equipmentIdList) {
|
EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(equipmentId);
|
if (equipmentLog != null) {
|
equipmentLogs.add(equipmentLog);
|
} else {
|
offCount += 1;
|
}
|
}
|
if (!equipmentLogs.isEmpty()) {
|
for (EquipmentLog equipmentLog : equipmentLogs) {
|
if (equipmentLog.getOporation() != null) {
|
switch (equipmentLog.getOporation()) {
|
case 1:
|
case 2:
|
standbyCount += 1;
|
break;
|
case 3:
|
runCount += 1;
|
break;
|
case 22:
|
alarmCount += 1;
|
break;
|
default:
|
offCount += 1;
|
break;
|
}
|
} else {
|
offCount += 1;
|
}
|
}
|
}
|
Map<String, Object> result = new HashMap<>();
|
result.put("runCount", runCount);
|
result.put("standbyCount", standbyCount);
|
result.put("alarmCount", alarmCount);
|
result.put("offCount", offCount);
|
|
return result;
|
}
|
|
/**
|
* 20230101
|
*
|
* @param begin 开始日期
|
* @param end 结束日期
|
* @return 开始与结束之间的所有日期,包括起止
|
*/
|
public static List<String> getMiddleDate(LocalDate begin, LocalDate end) {
|
List<String> localDateList = new ArrayList<>();
|
long length = end.toEpochDay() - begin.toEpochDay();
|
for (long i = length; i >= 0; i--) {
|
localDateList.add(end.minusDays(i).format(DateTimeFormatter.BASIC_ISO_DATE));
|
}
|
return localDateList;
|
}
|
|
/**
|
* 2023-01-01
|
*
|
* @param begin 开始日期
|
* @param end 结束日期
|
* @return 开始与结束之间的所有日期,包括起止
|
*/
|
public static List<String> getMiddleDates(LocalDate begin, LocalDate end) {
|
List<String> localDateList = new ArrayList<>();
|
long length = end.toEpochDay() - begin.toEpochDay();
|
for (long i = length; i >= 0; i--) {
|
localDateList.add(end.minusDays(i).toString());
|
}
|
return localDateList;
|
}
|
|
}
|