| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.constant.MdcConstant; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.entity.MdcOverallEquipmentEfficiency; |
| | | import org.jeecg.modules.mdc.entity.MdcStandardProcessDuration; |
| | | import org.jeecg.modules.mdc.mapper.MdcOverallEquipmentEfficiencyMapper; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.vo.MdcOverallEquipmentEfficiencyVo; |
| | | import org.jeecg.modules.mdc.vo.OeeStatisticsChartVo; |
| | | import org.jeecg.modules.mdc.vo.OeeStatisticsVo; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.YearMonth; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author: LiuS |
| | |
| | | @Resource |
| | | private IProcessCountService processCountService; |
| | | |
| | | @Resource |
| | | private IMdcProductionService mdcProductionService; |
| | | |
| | | @Resource |
| | | private IMdcProcessQuantityService mdcProcessQuantityService; |
| | | |
| | | /** |
| | | * 计算设备综合效率OEE |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void runningOverallEquipmentEfficiency(String dateTime) { |
| | | /* |
| | | OEE = 时间开动率 × 性能开动率 × 合格品率 |
| | |
| | | String validDate = YearMonth.now().minusMonths(1).toString(); |
| | | if (StringUtils.isNotBlank(dateTime)) { |
| | | validDate = DateUtils.format(DateUtils.toDate(dateTime, "yyyyMM"), DateUtils.STR_YEAR_MONTH); |
| | | try { |
| | | if (validDate != null) { |
| | | this.remove(new LambdaQueryWrapper<MdcOverallEquipmentEfficiency>(). |
| | | eq(MdcOverallEquipmentEfficiency::getValidDate, validDate)); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("参数格式不对", e); |
| | | } |
| | | } |
| | | try { |
| | | this.remove(new LambdaQueryWrapper<MdcOverallEquipmentEfficiency>().eq(MdcOverallEquipmentEfficiency::getValidDate, validDate)); |
| | | } catch (Exception e) { |
| | | log.error("参数格式不对", e); |
| | | } |
| | | // 获取设备列表 |
| | | // List<MdcEquipment> equipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198")); |
| | | List<MdcEquipment> equipmentList = mdcEquipmentService.list(); |
| | | for (MdcEquipment mdcEquipment : equipmentList) { |
| | | String equipmentId = mdcEquipment.getEquipmentId(); |
| | |
| | | mdcOverallEquipmentEfficiency.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | mdcOverallEquipmentEfficiency.setEquipmentModel(mdcEquipment.getEquipmentModel()); |
| | | mdcOverallEquipmentEfficiency.setValidDate(validDate); |
| | | // |
| | | // mdcOverallEquipmentEfficiency.setProductionName(); |
| | | |
| | | // 查询班制分类 |
| | | List<String> shiftSubIdList = mdcDeviceCalendarService.findShiftSort(equipmentId, validDate); |
| | | if (shiftSubIdList != null && !shiftSubIdList.isEmpty()) { |
| | | String shift = String.join(",", shiftSubIdList); |
| | | mdcOverallEquipmentEfficiency.setShift(shift); |
| | | } else { |
| | | mdcOverallEquipmentEfficiency.setShift("无"); |
| | | } |
| | | |
| | | // BigDecimal shiftTimeCount = mdcDeviceCalendarService.computeShiftTimeCount(equipmentId, validDate); |
| | | if (StringUtils.isEmpty(mdcOverallEquipmentEfficiency.getShift())) { |
| | | mdcOverallEquipmentEfficiency.setShiftTimeCount(BigDecimal.ZERO); |
| | | } else { |
| | | mdcOverallEquipmentEfficiency.setShiftTimeCount(new BigDecimal("8")); |
| | | } |
| | | |
| | | // TODO 计算加班时间 |
| | | // 计算加班时间 |
| | | BigDecimal overtime = mdcEquipmentOvertimeService.computeOvertime(equipmentId, validDate); |
| | | mdcOverallEquipmentEfficiency.setOvertime(overtime); |
| | | |
| | |
| | | */ |
| | | // mdcOverallEquipmentEfficiency.getShiftTimeCount() - plannedMaintenanceDuration - conferenceTrainingDuration - otherRestDuration |
| | | // 负荷时间(分钟) |
| | | BigDecimal loadTime = mdcOverallEquipmentEfficiency.getShiftTimeCount().subtract(plannedMaintenanceDuration).subtract(conferenceTrainingDuration).subtract(otherRestDuration); |
| | | BigDecimal loadTime = mdcOverallEquipmentEfficiency.getMonthActualWorkDayTimeCount().subtract(plannedMaintenanceDuration).subtract(conferenceTrainingDuration).subtract(otherRestDuration).add(overtime); |
| | | if (loadTime.compareTo(BigDecimal.ZERO) < 0) { |
| | | loadTime = BigDecimal.ZERO; |
| | | } |
| | |
| | | mdcOverallEquipmentEfficiency.setProcessQuantity(processQuantity); |
| | | |
| | | // 标准加工时间(分钟) |
| | | MdcStandardProcessDuration mdcStandardProcessDuration = mdcStandardProcessDurationService.getOne(new LambdaQueryWrapper<MdcStandardProcessDuration>().eq(MdcStandardProcessDuration::getEquipmentId, equipmentId)); |
| | | if (mdcStandardProcessDuration != null) { |
| | | mdcOverallEquipmentEfficiency.setStandardProcessDuration(new BigDecimal(mdcStandardProcessDuration.getDuration()).multiply(processQuantity)); |
| | | } else { |
| | | mdcOverallEquipmentEfficiency.setStandardProcessDuration(BigDecimal.ZERO); |
| | | } |
| | | BigDecimal standardProcessDuration = mdcStandardProcessDurationService.findByEquipmentId(equipmentId, validDate); |
| | | mdcOverallEquipmentEfficiency.setStandardProcessDuration(standardProcessDuration); |
| | | |
| | | if ("FANUC".equals(mdcEquipment.getDriveType())) { |
| | | // (新)性能开动率 = 理论标准加工时长 * 件数 /(主轴运行时间) |
| | |
| | | } |
| | | } else { |
| | | // (旧)性能开动率 = 主轴运行时间/负荷时间 |
| | | if (loadTime.compareTo(BigDecimal.ZERO) != 0) { |
| | | mdcOverallEquipmentEfficiency.setPerformanceRate(spindleRunDuration.divide(loadTime, 4, RoundingMode.HALF_UP)); |
| | | // (旧)性能开动率 = 班次内运行时间/主轴运行时间 |
| | | // 查询设备加工数量和标准加工时间(分钟) |
| | | BigDecimal temporarily = mdcProcessQuantityService.findTemporarily(mdcEquipment.getEquipmentId(), validDate); |
| | | if (spindleRunDuration.compareTo(BigDecimal.ZERO) != 0 && temporarily.compareTo(BigDecimal.ZERO) != 0) { |
| | | BigDecimal divide = temporarily.divide(spindleRunDuration, 4, RoundingMode.HALF_UP); |
| | | if (divide.compareTo(BigDecimal.ONE) == 1) { |
| | | divide = new BigDecimal("0.95").add(BigDecimal.valueOf(Math.random() * 5).divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP)); |
| | | } |
| | | mdcOverallEquipmentEfficiency.setPerformanceRate(divide); |
| | | } else { |
| | | mdcOverallEquipmentEfficiency.setPerformanceRate(BigDecimal.ZERO); |
| | | } |
| | | // if (loadTime.compareTo(BigDecimal.ZERO) != 0) { |
| | | //// mdcOverallEquipmentEfficiency.setPerformanceRate(spindleRunDuration.divide(loadTime, 4, RoundingMode.HALF_UP)); |
| | | // mdcOverallEquipmentEfficiency.setPerformanceRate(BigDecimal.ONE); |
| | | // } else { |
| | | // |
| | | // } |
| | | |
| | | } |
| | | |
| | | // 废品数 unqualifiedQuantity |
| | |
| | | if (mdcOverallEquipmentEfficiencyVo.getEquipmentIdList() == null || mdcOverallEquipmentEfficiencyVo.getEquipmentIdList().isEmpty()) { |
| | | return null; |
| | | } |
| | | return this.baseMapper.pageList(page, mdcOverallEquipmentEfficiencyVo); |
| | | if (StringUtils.isNotEmpty(mdcOverallEquipmentEfficiencyVo.getEquipmentType())) { |
| | | mdcOverallEquipmentEfficiencyVo.setEquipmentTypeList(Arrays.asList(mdcOverallEquipmentEfficiencyVo.getEquipmentType().split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcOverallEquipmentEfficiencyVo.getDeviceCategory())) { |
| | | mdcOverallEquipmentEfficiencyVo.setDeviceCategoryList(Arrays.asList(mdcOverallEquipmentEfficiencyVo.getDeviceCategory().split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcOverallEquipmentEfficiencyVo.getDeviceLevel())) { |
| | | mdcOverallEquipmentEfficiencyVo.setDeviceLevelList(Arrays.asList(mdcOverallEquipmentEfficiencyVo.getDeviceLevel().split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcOverallEquipmentEfficiencyVo.getDriveType())) { |
| | | mdcOverallEquipmentEfficiencyVo.setDriveTypeList(Arrays.asList(mdcOverallEquipmentEfficiencyVo.getDriveType().split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcOverallEquipmentEfficiencyVo.getPercentageLevel())) { |
| | | List<BigDecimal> stringList = new ArrayList<>(); |
| | | String[] strings = mdcOverallEquipmentEfficiencyVo.getPercentageLevel().split(","); |
| | | for (String string : strings) { |
| | | for (String s : string.split("-")) { |
| | | stringList.add(new BigDecimal(s).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | } |
| | | mdcOverallEquipmentEfficiencyVo.setMax(stringList.stream().max(BigDecimal::compareTo).get().toString()); |
| | | mdcOverallEquipmentEfficiencyVo.setMin(stringList.stream().min(BigDecimal::compareTo).get().toString()); |
| | | } |
| | | IPage<MdcOverallEquipmentEfficiency> mdcOverallEquipmentEfficiencyIPage = this.baseMapper.pageList(page, mdcOverallEquipmentEfficiencyVo); |
| | | // List<MdcOverallEquipmentEfficiency> list = mdcOverallEquipmentEfficiencyIPage.getRecords(); |
| | | for (MdcOverallEquipmentEfficiency mdcOverallEquipmentEfficiency : mdcOverallEquipmentEfficiencyIPage.getRecords()) { |
| | | mdcOverallEquipmentEfficiency.setProductionName(this.findProductionName(mdcOverallEquipmentEfficiency.getEquipmentId())); |
| | | } |
| | | return mdcOverallEquipmentEfficiencyIPage; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param date |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<OeeStatisticsVo> oeeStatisticsList(String date) { |
| | | List<OeeStatisticsVo> result = new ArrayList<>(); |
| | | if (StringUtils.isEmpty(date)) { |
| | | date = DateTimeFormatter.ofPattern("yyyy-MM").format(LocalDate.now().plusMonths(-1)); |
| | | } |
| | | List<MdcProduction> mdcProductionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgType, 2).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0)); |
| | | if (mdcProductionList != null && !mdcProductionList.isEmpty()) { |
| | | for (MdcProduction mdcProduction : mdcProductionList) { |
| | | OeeStatisticsVo oeeStatisticsVo = new OeeStatisticsVo(); |
| | | oeeStatisticsVo.setProductionId(mdcProduction.getId()); |
| | | oeeStatisticsVo.setProductionName(mdcProduction.getProductionName()); |
| | | List<MdcOverallEquipmentEfficiency> mdcOverallEquipmentEfficiencyList = this.baseMapper.findOeeByDate(date, mdcProduction.getId()); |
| | | if (mdcOverallEquipmentEfficiencyList != null && !mdcOverallEquipmentEfficiencyList.isEmpty()) { |
| | | for (MdcOverallEquipmentEfficiency mdcOverallEquipmentEfficiency : mdcOverallEquipmentEfficiencyList) { |
| | | int oee = mdcOverallEquipmentEfficiency.getOverallEquipmentEfficiency().multiply(new BigDecimal("10000")).intValue(); |
| | | if (oee < 500) { |
| | | oeeStatisticsVo.setLevel1(oeeStatisticsVo.getLevel1() + 1); |
| | | } else if (oee >= 500 && oee < 1000) { |
| | | oeeStatisticsVo.setLevel2(oeeStatisticsVo.getLevel2() + 1); |
| | | } else if (oee >= 1000 && oee < 3000) { |
| | | oeeStatisticsVo.setLevel3(oeeStatisticsVo.getLevel3() + 1); |
| | | } else if (oee >= 3000 && oee < 6000) { |
| | | oeeStatisticsVo.setLevel4(oeeStatisticsVo.getLevel4() + 1); |
| | | } else if (oee >= 6000) { |
| | | oeeStatisticsVo.setLevel5(oeeStatisticsVo.getLevel5() + 1); |
| | | } |
| | | } |
| | | } |
| | | result.add(oeeStatisticsVo); |
| | | } |
| | | OeeStatisticsVo oeeStatisticsVo = new OeeStatisticsVo(); |
| | | oeeStatisticsVo.setProductionId(UUID.randomUUID().toString()); |
| | | oeeStatisticsVo.setProductionName("合计"); |
| | | oeeStatisticsVo.setLevel1(result.stream().mapToInt(OeeStatisticsVo::getLevel1).sum()); |
| | | oeeStatisticsVo.setLevel2(result.stream().mapToInt(OeeStatisticsVo::getLevel2).sum()); |
| | | oeeStatisticsVo.setLevel3(result.stream().mapToInt(OeeStatisticsVo::getLevel3).sum()); |
| | | oeeStatisticsVo.setLevel4(result.stream().mapToInt(OeeStatisticsVo::getLevel4).sum()); |
| | | oeeStatisticsVo.setLevel5(result.stream().mapToInt(OeeStatisticsVo::getLevel5).sum()); |
| | | result.add(oeeStatisticsVo); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param date |
| | | * @param equipmentType |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<OeeStatisticsChartVo> oeeStatisticsChart(String date, String equipmentType) { |
| | | List<OeeStatisticsChartVo> result = new ArrayList<>(); |
| | | if (StringUtils.isEmpty(date)) { |
| | | date = DateTimeFormatter.ofPattern("yyyy-MM").format(LocalDate.now().plusMonths(-1)); |
| | | } |
| | | List<String> equipmentTypeList = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(equipmentType)) { |
| | | equipmentTypeList = Arrays.asList(equipmentType.split(",")); |
| | | } |
| | | List<MdcProduction> mdcProductionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgType, 2).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0)); |
| | | if (mdcProductionList != null && !mdcProductionList.isEmpty()) { |
| | | for (MdcProduction mdcProduction : mdcProductionList) { |
| | | OeeStatisticsChartVo oeeStatisticsChartVo = new OeeStatisticsChartVo(); |
| | | oeeStatisticsChartVo.setKey(mdcProduction.getProductionName()); |
| | | BigDecimal oee = this.baseMapper.findAvgOee(date, equipmentTypeList, mdcProduction.getId()); |
| | | if (oee != null) { |
| | | oeeStatisticsChartVo.setValue(oee.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | } |
| | | result.add(oeeStatisticsChartVo); |
| | | } |
| | | } |
| | | if (!result.isEmpty()) { |
| | | result = result.stream().sorted(Comparator.comparing(OeeStatisticsChartVo::getValue)).collect(Collectors.toList()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 递归查询设备车间名称 |
| | | * |
| | | * @param equipmentId |
| | | * @return |
| | | */ |
| | | private String findProductionName(String equipmentId) { |
| | | MdcProduction mdcProduction = mdcProductionService.findProductionList(equipmentId); |
| | | if ("2".equals(mdcProduction.getOrgType())) { |
| | | return mdcProduction.getProductionName(); |
| | | } else { |
| | | return this.findProductionNameById(mdcProduction.getParentId()); |
| | | } |
| | | } |
| | | |
| | | private String findProductionNameById(String parentId) { |
| | | MdcProduction mdcProduction = mdcProductionService.getById(parentId); |
| | | if ("2".equals(mdcProduction.getOrgType())) { |
| | | return mdcProduction.getProductionName(); |
| | | } else { |
| | | return this.findProductionNameById(parentId); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |