package org.jeecg.modules.mdc.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.apache.commons.lang3.StringUtils;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.modules.mdc.dto.MdcOeeListDto;
|
import org.jeecg.modules.mdc.dto.MdcOeeResultDto;
|
import org.jeecg.modules.mdc.entity.*;
|
import org.jeecg.modules.mdc.mapper.MdcOeeInfoMapper;
|
import org.jeecg.modules.mdc.service.*;
|
import org.jeecg.modules.mdc.util.DateUtils;
|
import org.jeecg.modules.mdc.vo.MdcOeeInfoQueryVo;
|
import org.jeecg.modules.mdc.vo.MdcOeeVo;
|
import org.jeecg.modules.mdcJc.entity.MdcProductDayschedule;
|
import org.jeecg.modules.mdcJc.service.IMdcProductDayScheduleService;
|
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;
|
|
/**
|
* @Description: OEE
|
* @Author: lius
|
* @Date: 2024-10-22
|
* @Version: V1.0
|
*/
|
@Service
|
public class MdcOeeInfoServiceImpl extends ServiceImpl<MdcOeeInfoMapper, MdcOeeInfo> implements IMdcOeeInfoService {
|
|
@Resource
|
private IMdcEquipmentService mdcEquipmentService;
|
|
@Resource
|
private IMdcShiftSubService mdcShiftSubService;
|
|
@Resource
|
private IMdcUtilizationRateService mdcUtilizationRateService;
|
|
@Resource
|
private IMdcComponentInfoService mdcComponentInfoService;
|
|
@Resource
|
private IMdcProductDayScheduleService mdcProductDayScheduleService;
|
|
@Resource
|
private IEquipmentService equipmentService;
|
|
@Resource
|
private IMdcEquipmentStatisticalShiftInfoService mdcEquipmentStatisticalShiftInfoService;
|
|
/**
|
* oee列表
|
* @param userId
|
* @param vo
|
* @return
|
*/
|
@Override
|
public MdcOeeVo pageList(String userId, MdcOeeInfoQueryVo vo) {
|
MdcOeeVo result = new MdcOeeVo();
|
List<MdcOeeListDto> listDtos = new ArrayList<>();
|
List<String> equipmentIds = new ArrayList<>();
|
if (StringUtils.isNotEmpty(vo.getParentId()) && StringUtils.isEmpty(vo.getEquipmentId())) {
|
if ("2".equals(vo.getTypeTree())) {
|
// 部门层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, vo.getParentId());
|
} else {
|
// 产线层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, vo.getParentId());
|
}
|
} else if (StringUtils.isNotEmpty(vo.getEquipmentId())) {
|
// 单台设备信息
|
vo.setEquipmentIdList(Collections.singletonList(vo.getEquipmentId()));
|
} else {
|
// 查询用户拥有的所有设备信息
|
if ("2".equals(vo.getTypeTree())) {
|
// 部门层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
|
} else {
|
// 产线层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
|
}
|
}
|
if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) {
|
vo.setEquipmentIdList(equipmentIds);
|
}
|
|
List<String> dates = DateUtils.getDatesStringList2(DateUtils.getShortDate2(vo.getStartTime()), DateUtils.getShortDate2(vo.getEndTime()));
|
result.setDates(dates);
|
|
// oee等级
|
List<MdcUtilizationRate> mdcUtilizationRateList = mdcUtilizationRateService.listByType("oee");
|
|
if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) {
|
result.setMdcOeeListDtoList(listDtos);
|
} else {
|
LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.isNotNull(MdcEquipment::getEquipmentId);
|
if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
|
queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
|
}
|
queryWrapper.orderByAsc(MdcEquipment::getEquipmentName);
|
List<MdcEquipment> equipmentList = mdcEquipmentService.list(queryWrapper);
|
//查询oee数据
|
List<MdcOeeInfo> oeeList = this.baseMapper.oeeList(vo);
|
//数据处理
|
String shiftSubName = "全部";
|
List<MdcShiftSub> mdcShiftSubList = new ArrayList<>();
|
if (StringUtils.isNotBlank(vo.getShiftSubId())) {
|
mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getId, vo.getShiftSubId()).eq(MdcShiftSub::getShiftSubStatus, "1"));
|
//oeeList = oeeList.stream().filter(mdcOeeInfo -> mdcOeeInfo.getShiftId().equals(vo.getShiftId()) && mdcOeeInfo.getShiftSubId().equals(vo.getShiftSubId())).collect(Collectors.toList());
|
List<String> shiftSubNames = mdcShiftSubList.stream().map(MdcShiftSub::getShiftSubName).collect(Collectors.toList());
|
shiftSubName = String.join(",", shiftSubNames);
|
}
|
|
|
for (MdcEquipment mdcEquipment : equipmentList) {
|
MdcOeeListDto mdcOeeListDto = new MdcOeeListDto();
|
mdcOeeListDto.setEquipmentId(mdcEquipment.getEquipmentId());
|
mdcOeeListDto.setEquipmentName(mdcEquipment.getEquipmentName());
|
mdcOeeListDto.setEquipmentType(mdcEquipment.getEquipmentType());
|
mdcOeeListDto.setShiftSubName(shiftSubName);
|
mdcOeeListDto.setClazz(mdcProductDayScheduleService.findClazz(mdcEquipment.getEquipmentId()));
|
List<MdcOeeResultDto> mdcOeeResultList = new ArrayList<>();
|
for (String date : dates) {
|
MdcOeeResultDto mdcOeeResultDto = new MdcOeeResultDto();
|
mdcOeeResultDto.setTheDate(date);
|
String format = DateUtils.format(DateUtils.toDate(date, DateUtils.STRDATE), DateUtils.STR_DATE);
|
List<MdcOeeInfo> mdcOeeInfoList = oeeList.stream().filter(mdcOeeInfo -> mdcOeeInfo.getEquipmentId().equals(mdcEquipment.getEquipmentId()) && mdcOeeInfo.getWorkDate().equals(format)).collect(Collectors.toList());
|
BigDecimal oeeRate = BigDecimal.ZERO;
|
if (!mdcOeeInfoList.isEmpty()) {
|
BigDecimal count = mdcOeeInfoList.stream().map(MdcOeeInfo::getOeeRate).reduce(BigDecimal.ZERO, BigDecimal::add);
|
oeeRate = count.divide(new BigDecimal(mdcOeeInfoList.size()), 2, RoundingMode.HALF_UP);
|
mdcOeeResultDto.setOeeRate(oeeRate);
|
}
|
long rate = oeeRate.multiply(new BigDecimal("100")).longValue();
|
for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
|
if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
|
mdcOeeResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
|
}
|
}
|
mdcOeeResultList.add(mdcOeeResultDto);
|
}
|
mdcOeeListDto.setDataList(mdcOeeResultList);
|
listDtos.add(mdcOeeListDto);
|
}
|
result.setMdcOeeListDtoList(listDtos);
|
}
|
|
return result;
|
}
|
|
/**
|
* 计算oee
|
* @param date
|
*/
|
@Override
|
public void runningOverallEquipmentEfficiency(String date) {
|
// 获取有效日期 格式 yyyy-MM-dd
|
String validDate = LocalDate.now().plusDays(-1).toString();
|
if (StringUtils.isNotBlank(date)) {
|
validDate = DateUtils.format(DateUtils.toDate(date, "yyyyMMdd"), DateUtils.STR_DATE);
|
try {
|
if (validDate != null) {
|
this.remove(new LambdaQueryWrapper<MdcOeeInfo>().
|
eq(MdcOeeInfo::getWorkDate, validDate));
|
}
|
} catch (Exception e) {
|
log.error("参数格式不对", e);
|
}
|
}
|
//获取班次
|
List<MdcShiftSub> mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getShiftSubStatus, CommonConstant.STATUS_1));
|
if (mdcShiftSubList == null || mdcShiftSubList.isEmpty()) {
|
return;
|
}
|
List<Equipment> equipmentList = equipmentService.list();
|
if (equipmentList == null || equipmentList.isEmpty()) {
|
return;
|
}
|
List<MdcOeeInfo> result = new ArrayList<>();
|
for (Equipment equipment : equipmentList) {
|
//获取零部件计划
|
List<MdcProductDayschedule> productDayScheduleList = mdcProductDayScheduleService.list(new LambdaQueryWrapper<MdcProductDayschedule>()
|
.eq(MdcProductDayschedule::getPlanDate, validDate)
|
.eq(MdcProductDayschedule::getEquipmentId, equipment.getEquipmentid()));
|
if (productDayScheduleList != null && !productDayScheduleList.isEmpty()) {
|
MdcProductDayschedule mdcProductDayschedule;
|
MdcOeeInfo mdcOeeInfo = new MdcOeeInfo();
|
for (MdcShiftSub mdcShiftSub : mdcShiftSubList) {
|
String id = mdcShiftSub.getId();
|
if (productDayScheduleList.stream().anyMatch(productDayschedule -> productDayschedule.getOrderId().substring(8, 10).equals(id))) {
|
mdcOeeInfo.setEquipmentId(equipment.getEquipmentid());
|
mdcOeeInfo.setWorkDate(validDate);
|
mdcOeeInfo.setStartTime(mdcShiftSub.getStartDate());
|
mdcOeeInfo.setEndTime(mdcShiftSub.getEndDate());
|
mdcOeeInfo.setInterDayFlag(mdcShiftSub.getIsDaySpan());
|
mdcOeeInfo.setShiftId(mdcShiftSub.getShiftId());
|
mdcOeeInfo.setShiftSubId(id);
|
//获取设备运行数据
|
MdcEquipmentStatisticalShiftInfo mdcEquipmentStatisticalShiftInfo = mdcEquipmentStatisticalShiftInfoService.getOne(new LambdaQueryWrapper<MdcEquipmentStatisticalShiftInfo>()
|
.eq(MdcEquipmentStatisticalShiftInfo::getEquipmentId, equipment.getEquipmentid())
|
.eq(MdcEquipmentStatisticalShiftInfo::getTheDate, validDate)
|
.eq(MdcEquipmentStatisticalShiftInfo::getShiftSubId, id));
|
if (mdcEquipmentStatisticalShiftInfo == null) {
|
continue;
|
}
|
mdcOeeInfo.setProcessLong(mdcEquipmentStatisticalShiftInfo.getProcessLong());
|
mdcOeeInfo.setWaitLong(mdcEquipmentStatisticalShiftInfo.getWaitLong());
|
mdcOeeInfo.setOpenLong(mdcEquipmentStatisticalShiftInfo.getOpenLong());
|
mdcOeeInfo.setCloseLong(mdcEquipmentStatisticalShiftInfo.getCloseLong());
|
//获取设备生产计划
|
mdcProductDayschedule = productDayScheduleList.stream().filter(productDayschedule -> productDayschedule.getOrderId().substring(8, 10).equals(id)).findAny().orElse(null);
|
if (mdcProductDayschedule == null) {
|
continue;
|
}
|
mdcOeeInfo.setWorkTeam(mdcProductDayschedule.getClazz());
|
mdcOeeInfo.setPlanNum(mdcProductDayschedule.getPlanCount());
|
mdcOeeInfo.setCompleteNum(mdcProductDayschedule.getCompletionCount());
|
mdcOeeInfo.setQualityNum(mdcProductDayschedule.getQualifiedCount());
|
mdcOeeInfo.setComponentNo(mdcProductDayschedule.getProductNo());
|
//查询班产能
|
MdcComponentInfo mdcComponentInfo = null;
|
if (mdcProductDayschedule.getIsAutomaticLine().equals(CommonConstant.STATUS_1)) {
|
//自动线
|
mdcComponentInfo = mdcComponentInfoService.findByComponentNo(equipment.getEquipmentid(), mdcProductDayschedule.getProductNo());
|
} else {
|
//非自动线
|
List<MdcComponentInfo> componentInfoList = mdcComponentInfoService.list(new LambdaQueryWrapper<MdcComponentInfo>()
|
.eq(MdcComponentInfo::getComponentNo, mdcProductDayschedule.getProductNo())
|
.like(MdcComponentInfo::getEquipmentId, equipment.getEquipmentid()));
|
if (componentInfoList != null && !componentInfoList.isEmpty()) {
|
mdcComponentInfo = componentInfoList.get(0);
|
}
|
}
|
if (mdcComponentInfo == null) {
|
continue;
|
}
|
mdcOeeInfo.setScheduleNum(mdcComponentInfo.getScheduleNum());
|
|
BigDecimal oeeRate = mdcOeeInfo.getProcessLong().multiply(new BigDecimal(mdcOeeInfo.getPlanNum())).multiply(new BigDecimal(mdcOeeInfo.getQualityNum()))
|
.divide(mdcEquipmentStatisticalShiftInfo.getTotalLong(), 2, RoundingMode.HALF_UP)
|
.divide(new BigDecimal(mdcOeeInfo.getScheduleNum()), 2, RoundingMode.HALF_UP)
|
.divide(new BigDecimal(mdcOeeInfo.getCompleteNum()), 2, RoundingMode.HALF_UP);
|
mdcOeeInfo.setOeeRate(oeeRate);
|
result.add(mdcOeeInfo);
|
}
|
}
|
}
|
}
|
if (!result.isEmpty()) {
|
this.saveBatch(result);
|
}
|
}
|
|
}
|