¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.*; |
| | | 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; |
| | | |
| | | /** |
| | | * @Description: OEE表 |
| | | * @Author: lius |
| | | * @Date: 2024-12-12 |
| | | */ |
| | | @Service |
| | | public class MdcOeeInfoServiceImpl extends ServiceImpl<MdcOeeInfoMapper, MdcOeeInfo> implements IMdcOeeInfoService { |
| | | |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | @Resource |
| | | private IMdcDowntimeService mdcDowntimeService; |
| | | |
| | | @Resource |
| | | private IMdcPartProcessInfoService mdcPartProcessInfoService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService; |
| | | |
| | | /** |
| | | * å页å表 |
| | | * |
| | | * @param userId |
| | | * @param page |
| | | * @param mdcOeeInfoVo |
| | | * @param req |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<MdcOeeInfo> pageList(String userId, Page<MdcOeeInfo> page, MdcOeeInfoVo mdcOeeInfoVo, HttpServletRequest req) { |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcOeeInfoVo.getParentId()) && StringUtils.isEmpty(mdcOeeInfoVo.getEquipmentId())) { |
| | | if ("2".equals(mdcOeeInfoVo.getTypeTree())) { |
| | | //é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcOeeInfoVo.getParentId()); |
| | | } else { |
| | | //产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcOeeInfoVo.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcOeeInfoVo.getEquipmentId())) { |
| | | //åå°è®¾å¤ä¿¡æ¯ |
| | | mdcOeeInfoVo.setEquipmentIdList(Collections.singletonList(mdcOeeInfoVo.getEquipmentId())); |
| | | } else { |
| | | //æ¥è¯¢ç¨æ·æ¥æçææè®¾å¤ä¿¡æ¯ |
| | | if ("2".equals(mdcOeeInfoVo.getTypeTree())) { |
| | | //é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | //产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | |
| | | if (mdcOeeInfoVo.getEquipmentIdList() == null || mdcOeeInfoVo.getEquipmentIdList().isEmpty()) { |
| | | mdcOeeInfoVo.setEquipmentIdList(equipmentIds); |
| | | } |
| | | |
| | | if (mdcOeeInfoVo.getEquipmentIdList() == null || mdcOeeInfoVo.getEquipmentIdList().isEmpty()) { |
| | | return null; |
| | | } |
| | | return this.baseMapper.pageList(page, mdcOeeInfoVo); |
| | | } |
| | | |
| | | /** |
| | | * å¯¼åº |
| | | * |
| | | * @param userId |
| | | * @param mdcOeeInfoVo |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ModelAndView exportXls(String userId, MdcOeeInfoVo mdcOeeInfoVo) { |
| | | LambdaQueryWrapper<MdcOeeInfo> queryWrapper = new LambdaQueryWrapper<>(); |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcOeeInfoVo.getParentId()) && StringUtils.isEmpty(mdcOeeInfoVo.getEquipmentId())) { |
| | | if ("2".equals(mdcOeeInfoVo.getTypeTree())) { |
| | | //é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcOeeInfoVo.getParentId()); |
| | | } else { |
| | | //产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcOeeInfoVo.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcOeeInfoVo.getEquipmentId())) { |
| | | //åå°è®¾å¤ä¿¡æ¯ |
| | | mdcOeeInfoVo.setEquipmentIdList(Collections.singletonList(mdcOeeInfoVo.getEquipmentId())); |
| | | } else { |
| | | //æ¥è¯¢ç¨æ·æ¥æçææè®¾å¤ä¿¡æ¯ |
| | | if ("2".equals(mdcOeeInfoVo.getTypeTree())) { |
| | | //é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | //产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | |
| | | if (mdcOeeInfoVo.getEquipmentIdList() == null || mdcOeeInfoVo.getEquipmentIdList().isEmpty()) { |
| | | mdcOeeInfoVo.setEquipmentIdList(equipmentIds); |
| | | } |
| | | |
| | | if (mdcOeeInfoVo.getEquipmentIdList() == null || mdcOeeInfoVo.getEquipmentIdList().isEmpty()) { |
| | | return null; |
| | | } else { |
| | | queryWrapper.in(MdcOeeInfo::getEquipmentId, mdcOeeInfoVo.getEquipmentIdList()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcOeeInfoVo.getEquipmentId())) { |
| | | queryWrapper.eq(MdcOeeInfo::getEquipmentId, mdcOeeInfoVo.getEquipmentId()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcOeeInfoVo.getStartTime()) && StringUtils.isNotEmpty(mdcOeeInfoVo.getEndTime())) { |
| | | queryWrapper.between(MdcOeeInfo::getTheDate, mdcOeeInfoVo.getStartTime(), mdcOeeInfoVo.getEndTime()); |
| | | } |
| | | queryWrapper.orderByDesc(MdcOeeInfo::getTheDate).orderByDesc(MdcOeeInfo::getEquipmentId); |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | List<MdcOeeInfo> mdcOeeInfos = this.baseMapper.selectList(queryWrapper); |
| | | // å¯¼åºæä»¶åç§° |
| | | 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æ°æ®")); |
| | | //update-end---author:wangshuai ---date:20211227 forï¼[JTC-116]导åºäººåæ»äº------------ |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, mdcOeeInfos); |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * 计ç®OEE |
| | | * |
| | | * @param mdcOeeComputeVo |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void computeOee(MdcOeeComputeVo mdcOeeComputeVo) { |
| | | List<MdcOeeInfo> result = new ArrayList<>(); |
| | | String startDate = mdcOeeComputeVo.getStartTime(); |
| | | String endDate = mdcOeeComputeVo.getEndTime(); |
| | | 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 = mdcDowntimeService.findPlanTimeDuration(equipmentId, validDate, CommonConstant.CLOSE_TYPE_0); |
| | | mdcOeeInfo.setPlanCloseLong(planCloseLong); |
| | | // è´è·æ¶é´(min) --- æ¥å工使¶é´-计ååæºæ¶é´ |
| | | Integer loadLong = mdcOeeInfo.getCalendarLong() - planCloseLong; |
| | | mdcOeeInfo.setLoadLong(loadLong); |
| | | // é计ååæºæ¶é´(min) --- æç»´æ¤æ°æ®ç»è®¡å½å¤©æ»æ¶é¿ |
| | | Integer noPlanCloseLong = mdcDowntimeService.findPlanTimeDuration(equipmentId, validDate, CommonConstant.CLOSE_TYPE_1); |
| | | 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); |
| | | effectiveRunLong = mdcEquipmentStatisticalInfoService.selectProcessLong(equipmentId, validDate.replace("-", "")); |
| | | if (effectiveRunLong == null) { |
| | | effectiveRunLong = 0; |
| | | } |
| | | 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.compareTo(new BigDecimal(100)) > 0 ? new BigDecimal(100) : performanceRate); |
| | | // å å·¥é¶ä»¶æ°é --- æç»´æ¤æ°æ®ç»è®¡å½å¤© |
| | | Integer processCount = mdcPartProcessInfoService.selectTotalProcessCount(equipmentId, validDate); |
| | | mdcOeeInfo.setProcessCount(processCount); |
| | | // åæ ¼é¶ä»¶æ°é --- æç»´æ¤æ°æ®ç»è®¡å½å¤© |
| | | Integer passCount = mdcPartProcessInfoService.selectTotalPassCount(equipmentId, validDate); |
| | | mdcOeeInfo.setPassCount(passCount); |
| | | // åæ ¼ç --- åæ ¼æ°/å å·¥æ° |
| | | BigDecimal passRate = new BigDecimal("100"); |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal findByEquIdAndMonth(List<String> equipmentIdList, String month) { |
| | | return this.baseMapper.findByEquIdAndMonth(equipmentIdList, month); |
| | | } |
| | | |
| | | } |