Lius
2024-12-17 2d727903343feb01fedc988370091395c368faf2
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java
@@ -6,20 +6,26 @@
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.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;
@@ -34,6 +40,15 @@
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
    @Resource
    private IMdcPlanCloseService mdcPlanCloseService;
    @Resource
    private IMdcPartProcessInfoService mdcPartProcessInfoService;
    @Resource
    private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService;
    /**
     * 分页列表
@@ -140,10 +155,84 @@
    /**
     * 计算oee
     * @param dateTime
     * @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);
    }
}