Lius
2025-02-18 3423bb9ee5b25d270a00763b69ed73970d790f63
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java
@@ -7,10 +7,12 @@
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.mdc.entity.MdcDownTime;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.entity.MdcMttrInfo;
import org.jeecg.modules.mdc.entity.MdcRepairInfo;
import org.jeecg.modules.mdc.mapper.MdcRepairInfoMapper;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.service.IMdcMttrInfoService;
import org.jeecg.modules.mdc.service.IMdcRepairInfoService;
import org.jeecg.modules.mdc.vo.MdcRepairInfoVo;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -22,6 +24,8 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -36,6 +40,9 @@
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
    @Resource
    private IMdcMttrInfoService mdcMttrInfoService;
    /**
     * 分页列表
@@ -169,6 +176,48 @@
     */
    @Override
    public void computeMttr(String month) {
        /*
        设备平均修理时间(MTTR) = 总维修时间 / 总维修次数
         */
        List<MdcMttrInfo> mdcMttrInfos = mdcMttrInfoService.list(new LambdaQueryWrapper<MdcMttrInfo>().eq(MdcMttrInfo::getTheDate, month));
        if (mdcMttrInfos != null && !mdcMttrInfos.isEmpty()) {
            for (MdcMttrInfo mdcMttrInfo : mdcMttrInfos) {
                // 总维修时间
                BigDecimal totalRepairLong = this.baseMapper.findTotalRepairLong(month);
                mdcMttrInfo.setTotalRepairLong(totalRepairLong);
                // 总维修次数
                Integer totalRepairCount = this.baseMapper.findTotalRepairCount(month);
                mdcMttrInfo.setTotalRepairCount(totalRepairCount);
                // MTTR
                if (mdcMttrInfo.getTotalRepairCount() != 0) {
                    BigDecimal mttr = mdcMttrInfo.getTotalRepairLong().divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP);
                    mdcMttrInfo.setMttr(mttr);
                }
            }
            mdcMttrInfoService.updateBatchById(mdcMttrInfos);
        } else {
            List<MdcEquipment> equipmentList = mdcEquipmentService.list();
            if (equipmentList != null && !equipmentList.isEmpty()) {
                List<MdcMttrInfo> mmi = new ArrayList<>();
                for (MdcEquipment mdcEquipment : equipmentList) {
                    MdcMttrInfo mdcMttrInfo = new MdcMttrInfo();
                    mdcMttrInfo.setEquipmentId(mdcEquipment.getEquipmentId());
                    mdcMttrInfo.setTheDate(month);
                    // 总维修时间
                    BigDecimal totalRepairLong = this.baseMapper.findTotalRepairLong(month);
                    mdcMttrInfo.setTotalRepairLong(totalRepairLong);
                    // 总维修次数
                    Integer totalRepairCount = this.baseMapper.findTotalRepairCount(month);
                    mdcMttrInfo.setTotalRepairCount(totalRepairCount);
                    // MTTR
                    if (mdcMttrInfo.getTotalRepairCount() != 0) {
                        BigDecimal mttr = mdcMttrInfo.getTotalRepairLong().divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP);
                        mdcMttrInfo.setMttr(mttr);
                    }
                    mmi.add(mdcMttrInfo);
                }
                mdcMttrInfoService.saveBatch(mmi);
            }
        }
    }
}