From 5ae1b71ab6b57140d46e6a8b9e606bb4a390ce27 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期一, 03 三月 2025 11:11:46 +0800 Subject: [PATCH] webservice接口 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java | 194 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 187 insertions(+), 7 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java index ee6dd03..d2cac3a 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java @@ -6,20 +6,27 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; +import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.entity.MdcOeeInfo; import org.jeecg.modules.mdc.mapper.MdcOeeInfoMapper; -import org.jeecg.modules.mdc.service.IMdcEquipmentService; -import org.jeecg.modules.mdc.service.IMdcOeeInfoService; +import org.jeecg.modules.mdc.service.*; +import org.jeecg.modules.mdc.util.DateUtils; +import org.jeecg.modules.mdc.vo.MdcOeeComputeVo; import org.jeecg.modules.mdc.vo.MdcOeeInfoVo; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -35,8 +42,18 @@ @Resource private IMdcEquipmentService mdcEquipmentService; + @Resource + private IMdcPlanCloseService mdcPlanCloseService; + + @Resource + private IMdcPartProcessInfoService mdcPartProcessInfoService; + + @Resource + private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService; + /** * 鍒嗛〉鍒楄〃 + * * @param userId * @param page * @param mdcOeeInfoVo @@ -80,13 +97,14 @@ /** * 瀵煎嚭 + * * @param userId * @param mdcOeeInfoVo * @return */ @Override public ModelAndView exportXls(String userId, MdcOeeInfoVo mdcOeeInfoVo) { - LambdaQueryWrapper<MdcOeeInfo> queryWrapper = new LambdaQueryWrapper(); + LambdaQueryWrapper<MdcOeeInfo> queryWrapper = new LambdaQueryWrapper<>(); List<String> equipmentIds = new ArrayList<>(); if (StringUtils.isNotEmpty(mdcOeeInfoVo.getParentId()) && StringUtils.isEmpty(mdcOeeInfoVo.getEquipmentId())) { if ("2".equals(mdcOeeInfoVo.getTypeTree())) { @@ -129,7 +147,7 @@ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); List<MdcOeeInfo> mdcOeeInfos = this.baseMapper.selectList(queryWrapper); // 瀵煎嚭鏂囦欢鍚嶇О - mv.addObject(NormalExcelConstants.FILE_NAME, "OEE鏁版嵁鍒楄〃"); + mv.addObject(NormalExcelConstants.FILE_NAME, "OEE鏁版嵁鍒楄〃"); mv.addObject(NormalExcelConstants.CLASS, MdcOeeInfo.class); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("OEE鏁版嵁鍒楄〃鏁版嵁", "瀵煎嚭浜�:" + user.getRealname(), "OEE鏁版嵁")); @@ -139,11 +157,173 @@ } /** - * 璁$畻oee - * @param dateTime + * 璁$畻OEE + * + * @param mdcOeeComputeVo */ @Override - public void runningComputeOee(String dateTime) { + @Transactional(rollbackFor = Exception.class) + public void computeOee(MdcOeeComputeVo mdcOeeComputeVo) { + List<MdcOeeInfo> result = new ArrayList<>(); + String startDate = mdcOeeComputeVo.getStartDate(); + String endDate = mdcOeeComputeVo.getEndDate(); + List<String> dateList = DateUtils.getDatesStringList(DateUtils.getShortDate(startDate), DateUtils.getShortDate(endDate)); + if (!dateList.isEmpty()) { + //鑾峰彇璁惧鍒楄〃 + List<MdcEquipment> equipmentList = mdcEquipmentService.list(); + for (String validDate : dateList) { + try { + this.remove(new LambdaQueryWrapper<MdcOeeInfo>().eq(MdcOeeInfo::getTheDate, validDate)); + } catch (Exception e) { + log.error("鍙傛暟鏍煎紡涓嶅", e); + } + for (MdcEquipment mdcEquipment : equipmentList) { + String equipmentId = mdcEquipment.getEquipmentId(); + MdcOeeInfo mdcOeeInfo = new MdcOeeInfo(); + // 璁惧缂栧彿 + mdcOeeInfo.setEquipmentId(equipmentId); + // 璁$畻鏃ユ湡 + mdcOeeInfo.setTheDate(validDate); + // 宸ヤ綔鏃ュ巻鏃堕棿(min) --- 鎸夋瘡澶�24灏忔椂绠� + mdcOeeInfo.setCalendarLong(1440); + // 璁″垝鍋滄満鏃堕棿(min) --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶╂�绘椂闀� + Integer planCloseLong = mdcPlanCloseService.findPlanTimeDuration(equipmentId, validDate, CommonConstant.CLOSE_TYPE_1); + mdcOeeInfo.setPlanCloseLong(planCloseLong); + // 璐熻嵎鏃堕棿(min) --- 鏃ュ巻宸ヤ綔鏃堕棿-璁″垝鍋滄満鏃堕棿 + Integer loadLong = mdcOeeInfo.getCalendarLong() - planCloseLong; + mdcOeeInfo.setLoadLong(loadLong); + // 闈炶鍒掑仠鏈烘椂闂�(min) --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶╂�绘椂闀� + Integer noPlanCloseLong = mdcPlanCloseService.findPlanTimeDuration(equipmentId, validDate, CommonConstant.CLOSE_TYPE_2); + mdcOeeInfo.setNoplanCloseLong(noPlanCloseLong); + // 寮�鍔ㄦ椂闂�(min) --- 璐熻嵎鏃堕棿-闈炶鍒掑仠鏈烘椂闂� + int actuateLong = loadLong - noPlanCloseLong; + mdcOeeInfo.setActuateLong(actuateLong); + // 鏃堕棿寮�鍔ㄧ巼 --- 寮�鍔ㄦ椂闂�/璐熻嵎鏃堕棿 + BigDecimal timeActuationRate = new BigDecimal(actuateLong).divide(new BigDecimal(loadLong), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); + mdcOeeInfo.setTimeActuationRate(timeActuationRate); + // 鏈夋晥杩愯鏃堕棿 --- 鎸夐渶姹傜淮鎶ら浂浠跺姞宸ユ�绘椂闀縷|绯荤粺涓昏酱璐熻浇鏃堕棿 + Integer effectiveRunLong = 0; + Integer totalProcessLong = mdcPartProcessInfoService.selectTotalProcessLong(equipmentId, validDate); + if (totalProcessLong == 0) { + //鏌ヨ璁惧杩愯鏃堕棿 + effectiveRunLong = mdcEquipmentStatisticalInfoService.selectProcessLong(equipmentId, validDate.replace("-", "")); + } else { + effectiveRunLong = totalProcessLong; + } + mdcOeeInfo.setEffectiveRunLong(effectiveRunLong); + // 鎬ц兘寮�鍔ㄧ巼 --- 鏈夋晥杩愯鏃堕棿/寮�鍔ㄦ椂闂� + BigDecimal performanceRate = BigDecimal.ZERO; + if (effectiveRunLong != 0 && actuateLong != 0) { + performanceRate = new BigDecimal(effectiveRunLong).divide(new BigDecimal(actuateLong), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); + } + mdcOeeInfo.setPerformanceRate(performanceRate); + // 鍔犲伐闆朵欢鏁伴噺 --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶� + Integer processCount = mdcPartProcessInfoService.selectTotalProcessCount(equipmentId, validDate); + mdcOeeInfo.setProcessCount(processCount); + // 鍚堟牸闆朵欢鏁伴噺 --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶� + Integer passCount = mdcPartProcessInfoService.selectTotalPassCount(equipmentId, validDate); + mdcOeeInfo.setPassCount(passCount); + // 鍚堟牸鐜� --- 鍚堟牸鏁�/鍔犲伐鏁� + BigDecimal passRate = BigDecimal.ZERO; + if (processCount != 0 && passCount != 0) { + passRate = new BigDecimal(passCount).divide(new BigDecimal(processCount), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); + } + mdcOeeInfo.setPassRate(passRate); + // OEE --- 鏃堕棿寮�鍔ㄧ巼 * 鎬ц兘寮�鍔ㄧ巼 * 涓�娆″悎鏍肩巼 + BigDecimal oee = BigDecimal.ZERO; + if (!timeActuationRate.equals(BigDecimal.ZERO) && !performanceRate.equals(BigDecimal.ZERO) && !passRate.equals(BigDecimal.ZERO)) { + oee = timeActuationRate.multiply(performanceRate).multiply(passRate).divide(new BigDecimal("10000"), 4, RoundingMode.HALF_UP); + } + mdcOeeInfo.setOee(oee); + result.add(mdcOeeInfo); + } + } + } + super.saveBatch(result); + } + + /** + * 璁$畻oee + * + * @param dateTime 鍙傛暟 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void runningComputeOee(String dateTime) { + List<MdcOeeInfo> result = new ArrayList<>(); + // 鑾峰彇鏈夋晥鏃ユ湡 鏍煎紡 yyyy-MM-dd + String validDate = LocalDate.now().minusDays(1).toString(); + if (StringUtils.isNotBlank(dateTime)) { + validDate = DateUtils.format(DateUtils.toDate(dateTime, DateUtils.STRDATE), DateUtils.STR_DATE); + } + try { + this.remove(new LambdaQueryWrapper<MdcOeeInfo>().eq(MdcOeeInfo::getTheDate, validDate)); + } catch (Exception e) { + log.error("鍙傛暟鏍煎紡涓嶅", e); + } + //鑾峰彇璁惧鍒楄〃 + List<MdcEquipment> equipmentList = mdcEquipmentService.list(); + for (MdcEquipment mdcEquipment : equipmentList) { + String equipmentId = mdcEquipment.getEquipmentId(); + MdcOeeInfo mdcOeeInfo = new MdcOeeInfo(); + // 璁惧缂栧彿 + mdcOeeInfo.setEquipmentId(equipmentId); + // 璁$畻鏃ユ湡 + mdcOeeInfo.setTheDate(validDate); + // 宸ヤ綔鏃ュ巻鏃堕棿(min) --- 鎸夋瘡澶�24灏忔椂绠� + mdcOeeInfo.setCalendarLong(1440); + // 璁″垝鍋滄満鏃堕棿(min) --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶╂�绘椂闀� + Integer planCloseLong = mdcPlanCloseService.findPlanTimeDuration(equipmentId, validDate, CommonConstant.CLOSE_TYPE_1); + mdcOeeInfo.setPlanCloseLong(planCloseLong); + // 璐熻嵎鏃堕棿(min) --- 鏃ュ巻宸ヤ綔鏃堕棿-璁″垝鍋滄満鏃堕棿 + Integer loadLong = mdcOeeInfo.getCalendarLong() - planCloseLong; + mdcOeeInfo.setLoadLong(loadLong); + // 闈炶鍒掑仠鏈烘椂闂�(min) --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶╂�绘椂闀� + Integer noPlanCloseLong = mdcPlanCloseService.findPlanTimeDuration(equipmentId, validDate, CommonConstant.CLOSE_TYPE_2); + mdcOeeInfo.setNoplanCloseLong(noPlanCloseLong); + // 寮�鍔ㄦ椂闂�(min) --- 璐熻嵎鏃堕棿-闈炶鍒掑仠鏈烘椂闂� + int actuateLong = loadLong - noPlanCloseLong; + mdcOeeInfo.setActuateLong(actuateLong); + // 鏃堕棿寮�鍔ㄧ巼 --- 寮�鍔ㄦ椂闂�/璐熻嵎鏃堕棿 + BigDecimal timeActuationRate = new BigDecimal(actuateLong).divide(new BigDecimal(loadLong), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); + mdcOeeInfo.setTimeActuationRate(timeActuationRate); + // 鏈夋晥杩愯鏃堕棿 --- 鎸夐渶姹傜淮鎶ら浂浠跺姞宸ユ�绘椂闀縷|绯荤粺涓昏酱璐熻浇鏃堕棿 + Integer effectiveRunLong = 0; + Integer totalProcessLong = mdcPartProcessInfoService.selectTotalProcessLong(equipmentId, validDate); + if (totalProcessLong == 0) { + //鏌ヨ璁惧杩愯鏃堕棿 + effectiveRunLong = mdcEquipmentStatisticalInfoService.selectProcessLong(equipmentId, validDate.replace("-", "")); + } else { + effectiveRunLong = totalProcessLong; + } + mdcOeeInfo.setEffectiveRunLong(effectiveRunLong); + // 鎬ц兘寮�鍔ㄧ巼 --- 鏈夋晥杩愯鏃堕棿/寮�鍔ㄦ椂闂� + BigDecimal performanceRate = BigDecimal.ZERO; + if (effectiveRunLong != 0 && actuateLong != 0) { + performanceRate = new BigDecimal(effectiveRunLong).divide(new BigDecimal(actuateLong), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); + } + mdcOeeInfo.setPerformanceRate(performanceRate); + // 鍔犲伐闆朵欢鏁伴噺 --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶� + Integer processCount = mdcPartProcessInfoService.selectTotalProcessCount(equipmentId, validDate); + mdcOeeInfo.setProcessCount(processCount); + // 鍚堟牸闆朵欢鏁伴噺 --- 鎸夌淮鎶ゆ暟鎹粺璁″綋澶� + Integer passCount = mdcPartProcessInfoService.selectTotalPassCount(equipmentId, validDate); + mdcOeeInfo.setPassCount(passCount); + // 鍚堟牸鐜� --- 鍚堟牸鏁�/鍔犲伐鏁� + BigDecimal passRate = BigDecimal.ZERO; + if (processCount != 0 && passCount != 0) { + passRate = new BigDecimal(passCount).divide(new BigDecimal(processCount), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); + } + mdcOeeInfo.setPassRate(passRate); + // OEE --- 鏃堕棿寮�鍔ㄧ巼 * 鎬ц兘寮�鍔ㄧ巼 * 涓�娆″悎鏍肩巼 + BigDecimal oee = BigDecimal.ZERO; + if (!timeActuationRate.equals(BigDecimal.ZERO) && !performanceRate.equals(BigDecimal.ZERO) && !passRate.equals(BigDecimal.ZERO)) { + oee = timeActuationRate.multiply(performanceRate).multiply(passRate).divide(new BigDecimal("10000"), 4, RoundingMode.HALF_UP); + } + mdcOeeInfo.setOee(oee); + result.add(mdcOeeInfo); + } + super.saveBatch(result); } } -- Gitblit v1.9.3