package org.jeecg.modules.board.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.system.vo.DictModel;
|
import org.jeecg.modules.board.mapper.DtBoardMapper;
|
import org.jeecg.modules.board.service.IDtBoardService;
|
import org.jeecg.modules.board.vo.*;
|
import org.jeecg.modules.mdc.entity.*;
|
import org.jeecg.modules.mdc.service.*;
|
import org.jeecg.modules.mdc.util.DateUtils;
|
import org.jeecg.modules.system.entity.MdcProduction;
|
import org.jeecg.modules.system.service.IMdcProductionService;
|
import org.jeecg.modules.system.service.ISysDictService;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Author: Lius
|
* @CreateTime: 2025-05-30
|
* @Description:
|
*/
|
@Service
|
public class DtBoardServiceImpl implements IDtBoardService {
|
|
@Resource
|
private IMdcProductionService mdcProductionService;
|
|
@Resource
|
private IMdcEquipmentService mdcEquipmentService;
|
|
@Resource
|
private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService;
|
|
@Resource
|
private IMdcOeeInfoService mdcOeeInfoService;
|
|
@Resource
|
private IEquipmentService equipmentService;
|
|
@Resource
|
private IEquipmentWorkLineService equipmentWorkLineService;
|
|
@Resource
|
private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService;
|
|
@Resource
|
private ISysDictService sysDictService;
|
|
@Resource
|
private IMdcDowntimeService mdcDowntimeService;
|
|
@Resource
|
private IEquipmentAlarmService equipmentAlarmService;
|
|
@Resource
|
private IMdcAlarmInfoService mdcAlarmInfoService;
|
|
@Resource
|
private DtBoardMapper dtBoardMapper;
|
|
@Resource
|
private IAndonOrderService andonOrderService;
|
|
/**
|
* 车间信息
|
*/
|
@Override
|
public List<MdcProduction> productionList() {
|
return mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgType, CommonConstant.ORG_TYPE_2).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0).orderByAsc(MdcProduction::getProductionOrder));
|
}
|
|
/**
|
* 设备月度利用率
|
*/
|
@Override
|
public List<EquUtilRateMonth> equipmentMonthUtilizationRate(String productionId) {
|
// 组装返回数据
|
LocalDate now = LocalDate.now();
|
Date start = DateUtils.toDate(now.plusMonths(-12).toString(), DateUtils.STR_DATE);
|
Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE);
|
List<String> monthBetween = DateUtils.getMonthBetween(start, end);
|
Map<String, EquUtilRateMonth> resultMap = monthBetween.stream().collect(Collectors.toMap(
|
date -> date,
|
date -> new EquUtilRateMonth(date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月"),
|
(existing, replacement) -> existing, // 处理键冲突的合并函数(通常不会冲突)
|
LinkedHashMap::new // 指定使用LinkedHashMap保持插入顺序
|
));
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return new ArrayList<>(resultMap.values());
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return new ArrayList<>(resultMap.values());
|
}
|
for (String month : monthBetween) {
|
MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdsAndMonth(equipmentIdList, month.replaceAll("-", ""));
|
if (mdcEquipmentStatisticalInfo != null) {
|
if (resultMap.containsKey(month)) {
|
EquUtilRateMonth equUtilRateMonth = resultMap.get(month);
|
if (mdcEquipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) {
|
equUtilRateMonth.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
|
}
|
resultMap.put(month, equUtilRateMonth);
|
}
|
}
|
}
|
return new ArrayList<>(resultMap.values());
|
}
|
|
/**
|
* 设备利用率(昨天)
|
*/
|
@Override
|
public List<EquUtilRate> equipmentUtilizationRate(String productionId) {
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return null;
|
}
|
Map<String, EquUtilRate> resultMap = new LinkedHashMap<>();
|
equipmentIdList.forEach(equipmentId -> {
|
EquUtilRate equUtilRate = new EquUtilRate(equipmentId);
|
resultMap.put(equipmentId, equUtilRate);
|
});
|
String yesterday = LocalDate.now().plusDays(-1).toString();
|
List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfoList = mdcEquipmentStatisticalInfoService.findByEquipmentAndDate(equipmentIdList, yesterday.replaceAll("-", ""));
|
if (mdcEquipmentStatisticalInfoList != null && !mdcEquipmentStatisticalInfoList.isEmpty()) {
|
mdcEquipmentStatisticalInfoList.forEach(mdcEquipmentStatisticalInfo -> {
|
if (resultMap.containsKey(mdcEquipmentStatisticalInfo.getEquipmentId())) {
|
EquUtilRate equUtilRate = resultMap.get(mdcEquipmentStatisticalInfo.getEquipmentId());
|
if (mdcEquipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) {
|
equUtilRate.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
|
}
|
resultMap.put(mdcEquipmentStatisticalInfo.getEquipmentId(), equUtilRate);
|
}
|
});
|
}
|
return new ArrayList<>(resultMap.values());
|
}
|
|
/**
|
* 月度设备综合效率
|
*/
|
@Override
|
public List<EquOeeMonth> equipmentMonthOee(String productionId) {
|
LocalDate now = LocalDate.now();
|
Date start = DateUtils.toDate(now.plusMonths(-12).toString(), DateUtils.STR_DATE);
|
Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE);
|
List<String> monthBetween = DateUtils.getMonthBetween(start, end);
|
Map<String, EquOeeMonth> resultMap = monthBetween.stream().collect(Collectors.toMap(
|
date -> date,
|
date -> new EquOeeMonth(date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月"),
|
(existing, replacement) -> existing, // 处理键冲突的合并函数(通常不会冲突)
|
LinkedHashMap::new // 指定使用LinkedHashMap保持插入顺序
|
));
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return new ArrayList<>(resultMap.values());
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return new ArrayList<>(resultMap.values());
|
}
|
for (String month : monthBetween) {
|
BigDecimal oee = mdcOeeInfoService.findByEquIdAndMonth(equipmentIdList, month);
|
if (oee != null) {
|
EquOeeMonth equOeeMonth = resultMap.get(month);
|
equOeeMonth.setOee(oee.setScale(2, RoundingMode.HALF_UP));
|
resultMap.put(month, equOeeMonth);
|
}
|
}
|
return new ArrayList<>(resultMap.values());
|
}
|
|
/**
|
* 设备状态统计
|
*/
|
@Override
|
public EquOperation equipmentOperationStatistics(String productionId) {
|
EquOperation equOperation = new EquOperation();
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return equOperation;
|
}
|
List<Equipment> equipmentList = equipmentService.listByProds(proIds);
|
if (equipmentList == null || equipmentList.isEmpty()) {
|
return equOperation;
|
}
|
for (Equipment equipment : equipmentList) {
|
if (equipment.getOporation() != null) {
|
switch (equipment.getOporation()) {
|
case 1:
|
case 2:
|
equOperation.setStandby(equOperation.getStandby() + 1);
|
break;
|
case 3:
|
equOperation.setRun(equOperation.getRun() + 1);
|
break;
|
case 22:
|
equOperation.setAlarm(equOperation.getAlarm() + 1);
|
break;
|
default:
|
equOperation.setShutdown(equOperation.getShutdown() + 1);
|
break;
|
}
|
} else {
|
equOperation.setShutdown(equOperation.getShutdown() + 1);
|
}
|
}
|
return equOperation;
|
}
|
|
/**
|
* 设备运行信息
|
*/
|
@Override
|
public List<EquRunInfo> equipmentRunInfo(String equipmentId) {
|
List<EquRunInfo> equRunInfoList = new ArrayList<>();
|
Equipment equipment = equipmentService.findByEquId(equipmentId);
|
if (equipment != null) {
|
//填充设备基础信息
|
equRunInfoList.add(new EquRunInfo("设备名称", equipment.getEquipmentname(), ""));
|
equRunInfoList.add(new EquRunInfo("设备编号", equipment.getEquipmentid(), ""));
|
if (equipment.getOporation() != null && equipment.getOporation() != 0) {
|
String saveTableName = equipment.getSavetablename();
|
Map<String, Object> mapData = equipmentWorkLineService.getDataList(saveTableName);
|
if (mapData != null) {
|
//获取 MDC 驱动对应的展示参数 并根据key 拼装从 workData 查询的数据
|
List<MdcDriveTypeParamConfig> mdcDriveTypeParamList = mdcDriveTypeParamConfigService.getShowDriveParam(equipment.getDrivetype());
|
if (mdcDriveTypeParamList != null && !mdcDriveTypeParamList.isEmpty()) {
|
List<DictModel> dictItems = sysDictService.getDictItems(CommonConstant.DICT_EQUIPMENT_RUN_UNIT);
|
Map<String, DictModel> resultMap = new HashMap<>();
|
dictItems.forEach(dictModel -> {
|
resultMap.put(dictModel.getText(), dictModel);
|
});
|
for (MdcDriveTypeParamConfig mdcDriveTypeParamConfig : mdcDriveTypeParamList) {
|
EquRunInfo equRunInfo = new EquRunInfo();
|
String englishName = mdcDriveTypeParamConfig.getEnglishName();
|
String chineseName = mdcDriveTypeParamConfig.getChineseName();
|
equRunInfo.setKey(chineseName);
|
if (mapData.containsKey(englishName)) {
|
Object object = mapData.get(englishName);
|
String value = "";
|
if ("CollectTime".equals(englishName)) {
|
Date date = object == null ? null : (Date) object;
|
value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL);
|
} else if ("ZUOLAN".equals(equipment.getDrivetype()) && "spindlespeed".equals(englishName) && equipment.getOporation() == 3) {
|
// ZUOLAN设备主轴转速字段spindlespeed
|
value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
|
} else if ("ZUOLAN".equals(equipment.getDrivetype()) && "spindleload".equals(englishName) && equipment.getOporation() == 3) {
|
// ZUOLAN设备主轴负荷字段spindleload
|
value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
|
} else if ("ZUOLAN".equals(equipment.getDrivetype()) && "spindlebeilv".equals(englishName) && equipment.getOporation() == 3) {
|
// ZUOLAN设备主轴倍率字段spindlebeilv
|
value = String.valueOf((new Random().nextInt(13)) * 10);
|
} else if ("ZUOLAN".equals(equipment.getDrivetype()) && "feedbeilv".equals(englishName) && equipment.getOporation() == 3) {
|
// ZUOLAN设备进给倍率字段feedbeilv
|
value = String.valueOf((new Random().nextInt(13)) * 10);
|
} else {
|
value = object == null ? "" : object.toString();
|
}
|
equRunInfo.setValue(value);
|
// 设置单位
|
if (resultMap.containsKey(chineseName)) {
|
DictModel dictModel = resultMap.get(chineseName);
|
equRunInfo.setUnit(dictModel.getValue());
|
}
|
equRunInfoList.add(equRunInfo);
|
}
|
}
|
|
}
|
}
|
}
|
}
|
return equRunInfoList;
|
}
|
|
/**
|
* 设备停机统计
|
*/
|
@Override
|
public List<EquDowntimeInfo> equDowntimeStatistics(String productionId) {
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return null;
|
}
|
LocalDate end = LocalDate.now();
|
LocalDate start = end.plusDays(-30);
|
List<EquDowntimeInfo> result = mdcDowntimeService.equDowntimeStatistics(equipmentIdList, start.toString(), end.toString());
|
result.forEach(equDowntimeInfo -> {
|
equDowntimeInfo.setDuration(equDowntimeInfo.getDuration().setScale(2, RoundingMode.HALF_UP));
|
});
|
return result;
|
}
|
|
/**
|
* 设备报警列表
|
*/
|
@Override
|
public List<EquAlarm> equAlarmList(String productionId) {
|
List<EquAlarm> result = new ArrayList<>();
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return null;
|
}
|
List<EquipmentAlarm> equipmentAlarmList = equipmentAlarmService.equAlarmList(equipmentIdList);
|
if (equipmentAlarmList == null || equipmentAlarmList.isEmpty()) {
|
return null;
|
}
|
for (EquipmentAlarm equipmentAlarm : equipmentAlarmList) {
|
MdcAlarmInfo mdcAlarmInfo = mdcAlarmInfoService.findAlarmContent(equipmentAlarm.getAlarmNo(), equipmentAlarm.getEquipmentid());
|
EquAlarm equAlarm = new EquAlarm();
|
equAlarm.setEquipmentId(equipmentAlarm.getEquipmentid());
|
if (mdcAlarmInfo != null) {
|
equAlarm.setAlarmInfo(mdcAlarmInfo.getAlarmContent());
|
} else {
|
equAlarm.setAlarmInfo(equipmentAlarm.getAlarmContent());
|
}
|
result.add(equAlarm);
|
}
|
return result;
|
}
|
|
/**
|
* 设备故障
|
*/
|
@Override
|
public List<EquRepair> equRepairList(String productionId) {
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return null;
|
}
|
LocalDateTime currentDate = LocalDate.now().minusMonths(1).atStartOfDay();
|
String format = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
List<EquRepair> result = dtBoardMapper.equRepairList(equipmentIdList, format);
|
return result;
|
}
|
|
/**
|
* 设备安灯问题
|
*/
|
@Override
|
public List<EquAndon> equAndonList(String productionId) {
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return null;
|
}
|
List<EquAndon> result = andonOrderService.equAndonList(equipmentIdList);
|
return result;
|
}
|
|
}
|