package org.jeecg.modules.mdc.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.modules.mdc.constant.MdcConstant;
|
import org.jeecg.modules.mdc.entity.Equipment;
|
import org.jeecg.modules.mdc.entity.MdcEquipment;
|
import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo;
|
import org.jeecg.modules.mdc.service.*;
|
import org.jeecg.modules.mdc.util.DateUtils;
|
import org.jeecg.modules.mdc.vo.MdcBoardRateVo;
|
import org.jeecg.modules.mdc.vo.MdcEquipmentStatusVo;
|
import org.jeecg.modules.mdcJc.service.IMdcJcRcJobreportService;
|
import org.jeecg.modules.system.entity.MdcProduction;
|
import org.jeecg.modules.system.service.IMdcProductionService;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.time.LocalDate;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Author: Lius
|
* @CreateTime: 2025-05-06
|
* @Description: 看板接口
|
*/
|
@Service
|
public class MdcBoardServiceImpl implements IMdcBoardService {
|
|
@Resource
|
private IMdcProductionService mdcProductionService;
|
|
@Resource
|
private IEquipmentService equipmentService;
|
|
@Resource
|
private IMdcEquipmentService mdcEquipmentService;
|
|
@Resource
|
private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService;
|
|
@Resource
|
private IMdcOeeInfoService mdcOeeInfoService;
|
|
@Resource
|
private IMdcJcRcJobreportService mdcJcRcJobreportService;
|
|
/**
|
* 设备状态
|
*/
|
@Override
|
public Map<String, Object> equipmentStatusStatistics(String productionId) {
|
Map<String, Object> result = new HashMap<>();
|
if (StringUtils.isBlank(productionId)) {
|
MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
|
productionId = mdcProduction.getId();
|
result.put("productionName", mdcProduction.getProductionName());
|
} else {
|
MdcProduction mdcProduction = mdcProductionService.getById(productionId);
|
result.put("productionName", mdcProduction.getProductionName());
|
}
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return result;
|
}
|
List<Equipment> equipmentList = equipmentService.listByProds(proIds);
|
if (equipmentList == null || equipmentList.isEmpty()) {
|
return result;
|
}
|
|
MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo();
|
for (Equipment equipment : equipmentList) {
|
if (equipment.getOporation() != null) {
|
switch (equipment.getOporation()) {
|
case 1:
|
case 2:
|
mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1);
|
break;
|
case 3:
|
mdcEquipmentStatusVo.setRunCount(mdcEquipmentStatusVo.getRunCount() + 1);
|
break;
|
case 22:
|
mdcEquipmentStatusVo.setAlarmCount(mdcEquipmentStatusVo.getAlarmCount() + 1);
|
break;
|
default:
|
mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
|
break;
|
}
|
} else {
|
mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
|
}
|
}
|
result.put("equipmentStatus", mdcEquipmentStatusVo);
|
|
return result;
|
}
|
|
/**
|
* 获取产线列表
|
*/
|
@Override
|
public List<MdcProduction> proList(String productionId) {
|
if (StringUtils.isBlank(productionId)) {
|
MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
|
productionId = mdcProduction.getId();
|
}
|
return mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, productionId).eq(MdcProduction::getMdcFlag, "1").eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0).orderByAsc(MdcProduction::getProductionOrder));
|
}
|
|
/**
|
* 率分析走势
|
*/
|
@Override
|
public Map<String, Object> rateAnalysisTrend(String productionId) {
|
Map<String, Object> result = new HashMap<>();
|
if (StringUtils.isBlank(productionId)) {
|
MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
|
productionId = mdcProduction.getId();
|
}
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return result;
|
}
|
List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds);
|
if (equipmentIdList == null || equipmentIdList.isEmpty()) {
|
return result;
|
}
|
LocalDate now = LocalDate.now();
|
Date startDate = DateUtils.toDate(now.plusDays(-15).toString(), DateUtils.STR_DATE);
|
Date endDate = DateUtils.toDate(now.plusDays(-1).toString(), DateUtils.STR_DATE);
|
List<String> dateList = DateUtils.getDatesStringList(startDate, endDate);
|
List<String> dates = new ArrayList<>();
|
List<MdcBoardRateVo> dataList = new ArrayList<>();
|
for (String date : dateList) {
|
MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
|
String s = date.substring(5, 10);
|
dates.add(s);
|
mdcBoardRateVo.setDate(s);
|
// TEEP 开机率 开动率
|
MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquipmentAndDate(equipmentIdList, date.replaceAll("-", ""));
|
mdcBoardRateVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
|
mdcBoardRateVo.setOpenRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
|
if (mdcEquipmentStatisticalInfo.getOpenLong().compareTo(BigDecimal.ZERO) > 0) {
|
mdcBoardRateVo.setStartRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
|
}
|
// OEE
|
BigDecimal oee = mdcOeeInfoService.findByEquIdsAndDate(equipmentIdList, date);
|
if (oee != null) {
|
mdcBoardRateVo.setOee(oee.setScale(2, RoundingMode.HALF_UP));
|
}
|
dataList.add(mdcBoardRateVo);
|
}
|
result.put("dateList", dates);
|
result.put("dataList", dataList);
|
return result;
|
}
|
|
/**
|
* 设备列表
|
*/
|
@Override
|
public List<MdcEquipment> equipmentList(String productionId) {
|
List<String> proIds = mdcProductionService.findChildByProId(productionId);
|
if (proIds == null || proIds.isEmpty()) {
|
return null;
|
}
|
return mdcEquipmentService.findByProIds(proIds);
|
}
|
|
/**
|
* 设备日利用率分析
|
*/
|
@Override
|
public Map<String, Object> rateAnalysisTrendDay(String equipmentId) {
|
Map<String, Object> result = new HashMap<>();
|
LocalDate now = LocalDate.now();
|
Date startDate = DateUtils.toDate(now.plusDays(-7).toString(), DateUtils.STR_DATE);
|
Date endDate = DateUtils.toDate(now.plusDays(-1).toString(), DateUtils.STR_DATE);
|
List<String> dayBetween = DateUtils.getDatesStringList(startDate, endDate);
|
List<String> dateList = new ArrayList<>();
|
List<MdcBoardRateVo> dataList = new ArrayList<>();
|
for (String date : dayBetween) {
|
MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
|
String s = date.substring(5, 10);
|
dateList.add(s);
|
mdcBoardRateVo.setDate(s);
|
// TEEP
|
MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdAndDate(equipmentId, date.replaceAll("-", ""));
|
mdcBoardRateVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
|
// OEE
|
BigDecimal oee = mdcOeeInfoService.findByEquIdAndDate(equipmentId, date);
|
if (oee != null) {
|
mdcBoardRateVo.setOee(oee.setScale(2, RoundingMode.HALF_UP));
|
}
|
dataList.add(mdcBoardRateVo);
|
}
|
result.put("dateList", dateList);
|
result.put("dataList", dataList);
|
return result;
|
}
|
|
/**
|
* 设备月率分析
|
*/
|
@Override
|
public Map<String, Object> rateAnalysisTrendMonth(String equipmentId) {
|
Map<String, Object> result = new HashMap<>();
|
LocalDate now = LocalDate.now();
|
Date start = DateUtils.toDate(now.plusMonths(-6).toString(), DateUtils.STR_DATE);
|
Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE);
|
List<String> monthBetween = DateUtils.getMonthBetween(start, end);
|
List<String> dateList = new ArrayList<>();
|
List<MdcBoardRateVo> dataList = new ArrayList<>();
|
for (String month : monthBetween) {
|
String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月";
|
dateList.add(name);
|
MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
|
mdcBoardRateVo.setDate(name);
|
// TEEP
|
MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdAndMonth(equipmentId, month.replaceAll("-", ""));
|
if (mdcEquipmentStatisticalInfo != null) {
|
mdcBoardRateVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
|
}
|
// OEE
|
BigDecimal oee = mdcOeeInfoService.findByEquIdAndMonth(equipmentId, month);
|
if (oee != null) {
|
mdcBoardRateVo.setOee(oee.setScale(2, RoundingMode.HALF_UP));
|
}
|
// 合格率
|
BigDecimal passRate = mdcJcRcJobreportService.findRateByMonth(equipmentId, month);
|
if (passRate != null) {
|
mdcBoardRateVo.setPassRate(passRate);
|
}
|
dataList.add(mdcBoardRateVo);
|
}
|
result.put("dateList", dateList);
|
result.put("dataList", dataList);
|
return result;
|
}
|
|
// /**
|
// * 设备产品合格率
|
// */
|
// @Override
|
// public Map<String, Object> passRate(String equipmentId) {
|
// Map<String, Object> result = new HashMap<>();
|
// LocalDate now = LocalDate.now();
|
// Date start = DateUtils.toDate(now.plusMonths(-6).toString(), DateUtils.STR_DATE);
|
// Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE);
|
// List<String> monthBetween = DateUtils.getMonthBetween(start, end);
|
// List<String> dateList = new ArrayList<>();
|
// for (String month : monthBetween) {
|
// String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月";
|
// dateList.add(name);
|
// MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
|
// // 合格率
|
//
|
// }
|
// return result;
|
// }
|
}
|