cuilei
2025-06-17 b5d02520af582a86aa95d7903558a5bf50a77aa7
Merge remote-tracking branch 'origin/master'
已添加7个文件
已修改14个文件
824 ■■■■■ 文件已修改
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/WorkStepServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/board/service/impl/DtBoardServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcEfficiencyDto.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcEfficiencyResultDto.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentFaultInfo.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentFaultInfoMapper.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEfficiencyReportMapper.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentFaultInfoMapper.xml 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentFaultInfoService.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java 123 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquFaultRecord.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java
@@ -129,16 +129,15 @@
            guideCardBatch.setProcessWorkCode(workStep.getStepCode());
            partsInfo=partsInfoService.getById(workStep.getPartsId());
        }
        if (partsInfo==null){
            return false;
        }
        guideCardBatch.setDocId(docId);
        guideCardBatch.setSerialNumber(getSerialNumber("C140"));
        guideCardBatch.setUnit(sysDictService.queryDictTextByKey("unit_code", "C140"));
        guideCardBatch.setDocName(docInfo.getDocName());
        if (partsInfo!=null){
        guideCardBatch.setPartsCode(partsInfo.getPartsCode());
        guideCardBatch.setPartsName(partsInfo.getPartsName());
        guideCardBatch.setMaterielDesp(partsInfo.getMaterielDesp());
        }
        guideCardBatch.setCompiler(user.getUsername());
        guideCardBatch.setCreateTime(new Date());
        return this.save(guideCardBatch);
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java
@@ -540,10 +540,10 @@
            List<DeviceType> deviceTypeList = deviceTypeService.getDeviceTypeByAttribution(processIds,
                    DocAttributionTypeEnum.PROCESS.getCode(),treeInfoRequest.getDeviceManagementName(),treeInfoRequest.getDeviceManagementCode());
            if (deviceTypeList != null && !deviceTypeList.isEmpty()) {
                List<String> deviceManagementIds=deviceTypeList.stream().map(DeviceType::getId).collect(Collectors.toList());
                List<String> deviceTypeIds=deviceTypeList.stream().map(DeviceType::getId).collect(Collectors.toList());
                DocInfoQueryRequest docQuery = new DocInfoQueryRequest();
                BeanUtil.copyProperties(treeInfoRequest,docQuery);
                docQuery.setAttributionIds(String.join(",",deviceManagementIds));
                docQuery.setAttributionIds(String.join(",",deviceTypeIds));
                docQuery.setDocClassCode("NC");
                docQuery.setAttributionType(DocAttributionTypeEnum.PROCESS.getCode());
                docInfos=docInfoService.findListByDocQuery(docQuery);
@@ -554,6 +554,10 @@
                treeInfoRequest.setProcessIds(id);
                List<DocInfo> docInfoList = workStepService.getByWorkStepNCFile(treeInfoRequest);
                docInfos.addAll(docInfoList);
            }else {
                treeInfoRequest.setProcessIds(processIds);
                List<DocInfo> docInfoList = workStepService.getByWorkStepNCFile(treeInfoRequest);
                docInfos.addAll(docInfoList);
            }
            return docInfos;
        }
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/WorkStepServiceImpl.java
@@ -469,10 +469,10 @@
            List<DeviceType> deviceTypeList = deviceTypeService.getDeviceTypeByAttribution(workStepIds,
                    DocAttributionTypeEnum.WORKSITE.getCode(),treeInfoRequest.getDeviceManagementName(),treeInfoRequest.getDeviceManagementCode());
            if (deviceTypeList != null && !deviceTypeList.isEmpty()) {
                List<String> deviceManagementIds=deviceTypeList.stream().map(DeviceType::getDeviceManagementId).collect(Collectors.toList());
                List<String> deviceTypeIds=deviceTypeList.stream().map(DeviceType::getId).collect(Collectors.toList());
                DocInfoQueryRequest docQuery = new DocInfoQueryRequest();
                BeanUtil.copyProperties(treeInfoRequest,docQuery);
                docQuery.setAttributionIds(String.join(",",deviceManagementIds));
                docQuery.setAttributionIds(String.join(",",deviceTypeIds));
                docQuery.setDocClassCode("NC");
                docQuery.setAttributionType(DocAttributionTypeEnum.WORKSITE.getCode());
                docInfos=docInfoService.findListByDocQuery(docQuery);
lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
@@ -6,9 +6,7 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.*;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.*;
@@ -1086,4 +1084,32 @@
        return dateString;
    }
    /**
     * Date与LocalDateTime互相转换的工具方法
     *
     * @param date
     * @return
     */
    public static LocalDateTime convertToLocalDateTime(Date date) {
        if (date == null) {
            return null;
        }
        return Instant.ofEpochMilli(date.getTime())
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
    }
    /**
     * Date与LocalDateTime互相转换的工具方法
     *
     * @param localDateTime
     * @return
     */
    public static Date convertToDate(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return null;
        }
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/board/service/impl/DtBoardServiceImpl.java
@@ -1,22 +1,17 @@
package org.jeecg.modules.board.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import liquibase.pro.packaged.I;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.board.mapper.DtBoardMapper;
import org.jeecg.modules.board.service.IDtBoardService;
import org.jeecg.modules.board.vo.*;
import org.jeecg.modules.eam.service.IEamRepairOrderService;
import org.jeecg.modules.mdc.constant.MdcConstant;
import org.jeecg.modules.mdc.entity.*;
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcEfficiencyDto.java
@@ -55,6 +55,17 @@
     * å…³æœºæ—¶é•¿
     */
    private BigDecimal closeLong;
    /**
     * æ•…障时长
     */
    private BigDecimal faultLong;
    /**
     * æ•…障率
     */
    private BigDecimal faultRate;
    /**
     * è¿è¡Œæ—¶é•¿(去除故障时间)
     */
    private BigDecimal removeFaultRunLong;
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcEfficiencyResultDto.java
@@ -43,11 +43,23 @@
     */
    private BigDecimal closeLong = BigDecimal.ZERO;
    /**
     * æ•…障时长
     */
    private BigDecimal faultLong = BigDecimal.ZERO;
    /**
     * æ•…障率
     */
    private BigDecimal faultRate = BigDecimal.ZERO;
    /**
     * è¿è¡Œæ—¶é•¿(去除故障时间)
     */
    private BigDecimal removeFaultRunLong = BigDecimal.ZERO;
    /**
     * é¢œè‰²
     */
    private String color;
    public MdcEfficiencyResultDto(String theDate, BigDecimal processLong, BigDecimal utilizationRate, BigDecimal startRate, BigDecimal openRate, BigDecimal openLong, BigDecimal waitLong, BigDecimal closeLong) {
    public MdcEfficiencyResultDto(String theDate, BigDecimal processLong, BigDecimal utilizationRate, BigDecimal startRate, BigDecimal openRate, BigDecimal openLong, BigDecimal waitLong, BigDecimal closeLong, BigDecimal faultLong, BigDecimal faultRate, BigDecimal removeFaultRunLong) {
        this.theDate = theDate;
        this.processLong = processLong;
        this.utilizationRate = utilizationRate;
@@ -56,6 +68,9 @@
        this.openLong = openLong;
        this.waitLong = waitLong;
        this.closeLong = closeLong;
        this.faultLong = faultLong;
        this.faultRate = faultRate;
        this.removeFaultRunLong = removeFaultRunLong;
    }
    public MdcEfficiencyResultDto() {
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentFaultInfo.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,87 @@
package org.jeecg.modules.mdc.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
 * @Description: æ•…障率表
 * @Author: Lius
 * @Date: 2025-06-16
 * @Version: V1.0
 */
@Data
@TableName("mdc_equipment_fault_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "mdc_equipment_fault_info对象", description = "故障率表")
public class MdcEquipmentFaultInfo implements Serializable {
    private static final long serialVersionUID = 7825739575204258911L;
    /**
     * ä¸»é”®
     */
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键")
    private String id;
    /**
     * è®¾å¤‡id
     */
    @Excel(name = "设备id", width = 15)
    @ApiModelProperty(value = "设备id")
    private String equipmentId;
    /**
     * æ•…障时长
     */
    @Excel(name = "故障时长", width = 15)
    @ApiModelProperty(value = "故障时长")
    private Integer faultLong = 0;
    /**
     * æ•…障率
     */
    @Excel(name = "故障率", width = 15)
    @ApiModelProperty(value = "故障率")
    private BigDecimal faultRate = BigDecimal.ZERO;
    /**
     * åŽ»é™¤æ•…éšœæ—¶é—´çš„è¿è¡Œæ—¶é—´
     */
    @Excel(name = "去除故障时间的运行时间", width = 15)
    @ApiModelProperty(value = "去除故障时间的运行时间")
    private Integer removeFaultRunLong = 0;
    /**
     * åŽ»é™¤æ•…éšœæ—¶é—´åˆ©ç”¨çŽ‡
     */
    @Excel(name = "去除故障时间利用率", width = 15)
    @ApiModelProperty(value = "去除故障时间利用率")
    private BigDecimal removeFaultRate = BigDecimal.ZERO;
    /**
     * æœ‰æ•ˆæ—¥æœŸ
     */
    @Excel(name = "有效日期", width = 15)
    @ApiModelProperty(value = "有效日期")
    private String theDate;
    /**
     * åˆ›å»ºæ—¶é—´
     */
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    public MdcEquipmentFaultInfo() {
    }
    public MdcEquipmentFaultInfo(String equipmentId, String theDate) {
        this.equipmentId = equipmentId;
        this.theDate = theDate;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java
@@ -100,4 +100,15 @@
    @TableField(exist = false)
    private Set<TmpEquipmentAlarm> tmpEquipmentAlarmSet;
    public MdcEquipmentRunningSection() {
    }
    public MdcEquipmentRunningSection(Integer status, String equipmentId, Date startTime, Date endTime, Long startLong, Long endLong) {
        this.status = status;
        this.equipmentId = equipmentId;
        this.startTime = startTime;
        this.endTime = endTime;
        this.startLong = startLong;
        this.endLong = endLong;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentFaultInfoMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,19 @@
package org.jeecg.modules.mdc.mapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.mdc.entity.MdcEquipmentFaultInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import java.util.List;
/**
 * @Description: æ•…障率表
 * @Author: jeecg-boot
 * @Date:   2025-06-16
 * @Version: V1.0
 */
public interface MdcEquipmentFaultInfoMapper extends BaseMapper<MdcEquipmentFaultInfo> {
    List<EquFaultRecord> findFaultRecord(@Param("equipmentIdList") List<String> equipmentIdList, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java
@@ -5,6 +5,7 @@
import org.jeecg.modules.mdc.dto.MdcAlarmListDto;
import org.jeecg.modules.mdc.dto.MdcEquipmentWaitSectionDto;
import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import org.jeecg.modules.mdc.vo.MdcAlarmAnalyzeQueryVo;
import java.util.Date;
@@ -78,4 +79,6 @@
    List<Integer> getDataList(@Param("equipmentId") String equipmentId, @Param("date") Date date);
    List<MdcEquipmentWaitSectionDto> findWaitList(@Param("date") String date);
    List<EquFaultRecord> findFaultList(@Param("equipmentId") String equipmentId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEfficiencyReportMapper.xml
@@ -18,10 +18,14 @@
            t1.open_long / 86400 openRate,
            t1.open_long openLong,
            t1.wait_long waitLong,
            t1.close_long closeLong
            t1.close_long closeLong,
            COALESCE(t3.fault_long, 0) faultLong,
            COALESCE(t3.fault_rate, 0) faultRate,
            COALESCE(t3.remove_fault_run_long, 0) removeFaultRunLong
        FROM
            mdc_equipment t2
            LEFT JOIN mdc_equipment_statistical_info t1 ON t1.equipment_id = t2.equipment_id
            LEFT JOIN mdc_equipment_fault_info t3 ON t2.equipment_id = t3.equipment_id AND t1.the_date = t3.the_date
        WHERE
            t1.the_date &lt;= #{ vo.endTime }
            AND t1.the_date &gt;= #{ vo.startTime }
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentFaultInfoMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mdc.mapper.MdcEquipmentFaultInfoMapper">
    <select id="findFaultRecord" resultType="org.jeecg.modules.mdc.vo.EquFaultRecord">
        SELECT
            t3.equipment_code equipmentId,
            t1.fault_start_time startTime,
            t2.actual_end_time endTime
        FROM
            eam_report_repair t1
            LEFT JOIN eam_repair_order t2 ON t2.report_id = t1.id
            LEFT JOIN eam_equipment t3 ON t1.equipment_id = t3.id
        WHERE
            (
                ( t1.fault_start_time BETWEEN #{startTime} AND #{endTime} )
                OR ( t2.actual_end_time BETWEEN #{startTime} AND #{endTime} )
                OR ( t1.fault_start_time &lt; #{startTime} AND t2.actual_end_time IS NULL )
            )
          AND t3.equipment_code IN
            <foreach collection="equipmentIdList" item="id" index="index" open="(" close=")" separator=",">
                #{ id }
            </foreach>
          AND t1.report_status != 'ABOLISH'
    </select>
</mapper>
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml
@@ -188,5 +188,24 @@
            equipment_id, start_time DESC
    </select>
    <select id="findFaultList" resultType="org.jeecg.modules.mdc.vo.EquFaultRecord">
        SELECT
            t3.equipment_code equipmentId,
            t1.fault_start_time startTime,
            t2.actual_end_time endTime
        FROM
            eam_report_repair t1
                LEFT JOIN eam_repair_order t2 ON t2.report_id = t1.id
                LEFT JOIN eam_equipment t3 ON t1.equipment_id = t3.id
        WHERE
            (
                ( t1.fault_start_time BETWEEN #{startTime} AND #{endTime} )
                OR ( t2.actual_end_time BETWEEN #{startTime} AND #{endTime} )
                OR ( t1.fault_start_time &lt; #{startTime} AND t2.actual_end_time IS NULL )
            )
          AND t3.equipment_code = #{equipmentId}
          AND t1.report_status != 'ABOLISH'
    </select>
</mapper>
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentFaultInfoService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,19 @@
package org.jeecg.modules.mdc.service;
import org.jeecg.modules.mdc.entity.MdcEquipmentFaultInfo;
import com.baomidou.mybatisplus.extension.service.IService;
/**
 * @Description: æ•…障率表
 * @Author: Lius
 * @Date: 2025-06-16
 * @Version: V1.0
 */
public interface IMdcEquipmentFaultInfoService extends IService<MdcEquipmentFaultInfo> {
    /**
     * ç»Ÿè®¡æ•…障时长,计算故障率
     * @param parameter
     */
    void runningAllEquFaultStatistical(String parameter);
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
@@ -196,6 +196,12 @@
                    mdcEfficiencyResultDto.setWaitLong(mdcEfficiencyResultDto.getWaitLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setCloseLong(mdcEfficiencyResultDto.getCloseLong());
                    mdcEfficiencyResultDto.setCloseLong(mdcEfficiencyResultDto.getCloseLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setFaultLong(mdcEfficiencyResultDto.getFaultLong());
                    mdcEfficiencyResultDto.setFaultLong(mdcEfficiencyResultDto.getFaultLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setFaultRate(mdcEfficiencyResultDto.getFaultRate());
                    mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong());
                    mdcEfficiencyResultDto.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    long rate = mdcEfficiencyResultDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
                    for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
@@ -284,6 +290,12 @@
                    mdcEfficiencyResultDto.setWaitLong(mdcEfficiencyResultDto.getWaitLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setCloseLong(mdcEfficiencyResultDto.getCloseLong());
                    mdcEfficiencyResultDto.setCloseLong(mdcEfficiencyResultDto.getCloseLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setFaultLong(mdcEfficiencyResultDto.getFaultLong());
                    mdcEfficiencyResultDto.setFaultLong(mdcEfficiencyResultDto.getFaultLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setFaultRate(mdcEfficiencyResultDto.getFaultRate());
                    mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
                    mdcEfficiencyResultDto1.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong());
                    mdcEfficiencyResultDto.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
                    long rate = mdcEfficiencyResultDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
                    for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
@@ -349,7 +361,10 @@
                            a.getOpenRate().add(b.getOpenRate()),
                            a.getOpenLong().add(b.getOpenLong()),
                            a.getWaitLong().add(b.getWaitLong()),
                            a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add);
                            a.getCloseLong().add(b.getCloseLong()),
                            a.getFaultLong().add(b.getFaultLong()),
                            a.getFaultRate().add(b.getFaultRate()),
                            a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add);
                });
        for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) {
            mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
@@ -392,7 +407,10 @@
                            a.getOpenRate().add(b.getOpenRate()),
                            a.getOpenLong().add(b.getOpenLong()),
                            a.getWaitLong().add(b.getWaitLong()),
                            a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add);
                            a.getCloseLong().add(b.getCloseLong()),
                            a.getFaultLong().add(b.getFaultLong()),
                            a.getFaultRate().add(b.getFaultRate()),
                            a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add);
                });
        for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) {
            mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
@@ -696,7 +714,10 @@
                            a.getOpenRate().add(b.getOpenRate()),
                            a.getOpenLong().add(b.getOpenLong()),
                            a.getWaitLong().add(b.getWaitLong()),
                            a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add);
                            a.getCloseLong().add(b.getCloseLong()),
                            a.getFaultLong().add(b.getFaultLong()),
                            a.getFaultRate().add(b.getFaultRate()),
                            a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add);
                });
        for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) {
            mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
@@ -706,6 +727,9 @@
            mdcEfficiencyResultDto.setWaitLong(mdcEfficiencyResultDto.getWaitLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setOpenLong(mdcEfficiencyResultDto.getOpenLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setProcessLong(mdcEfficiencyResultDto.getProcessLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setFaultLong(mdcEfficiencyResultDto.getFaultLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP));
            long rate = mdcEfficiencyResultDto.getStartRate().multiply(new BigDecimal("100")).longValue();
            for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
@@ -740,12 +764,16 @@
                            a.getOpenRate().add(b.getOpenRate()),
                            a.getOpenLong().add(b.getOpenLong()),
                            a.getWaitLong().add(b.getWaitLong()),
                            a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add);
                            a.getCloseLong().add(b.getCloseLong()),
                            a.getFaultLong().add(b.getFaultLong()),
                            a.getFaultRate().add(b.getFaultRate()),
                            a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add);
                });
        for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) {
            mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setOpenRate(mdcEfficiencyResultDto.getOpenRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setStartRate(mdcEfficiencyResultDto.getStartRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
            mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP));
            long rate = mdcEfficiencyResultDto.getStartRate().multiply(new BigDecimal("100")).longValue();
            for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
@@ -2146,6 +2174,9 @@
                    mdcEfficiencyResultDto.setOpenLong(efficiencyDto.getOpenLong());
                    mdcEfficiencyResultDto.setWaitLong(efficiencyDto.getWaitLong());
                    mdcEfficiencyResultDto.setCloseLong(efficiencyDto.getCloseLong());
                    mdcEfficiencyResultDto.setFaultLong(efficiencyDto.getFaultLong());
                    mdcEfficiencyResultDto.setFaultRate(efficiencyDto.getFaultRate());
                    mdcEfficiencyResultDto.setRemoveFaultRunLong(efficiencyDto.getRemoveFaultRunLong());
                    long rate = efficiencyDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
                    for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
@@ -2163,6 +2194,9 @@
            mdcEfficiencyResultDto.setOpenLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setWaitLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setCloseLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setFaultLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setFaultRate(new BigDecimal("0"));
            mdcEfficiencyResultDto.setRemoveFaultRunLong(new BigDecimal("0"));
            for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                if (0 >= mdcUtilizationRate.getMinimumRange() && 0 < mdcUtilizationRate.getMaximumRange()) {
                    mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
@@ -2178,6 +2212,9 @@
            mdcEfficiencyResultDto.setOpenLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setWaitLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setCloseLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setFaultLong(new BigDecimal("0"));
            mdcEfficiencyResultDto.setFaultRate(new BigDecimal("0"));
            mdcEfficiencyResultDto.setRemoveFaultRunLong(new BigDecimal("0"));
            for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
                if (0 >= mdcUtilizationRate.getMinimumRange() && 0 < mdcUtilizationRate.getMaximumRange()) {
                    mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
@@ -2191,6 +2228,9 @@
        efficiencyResultDto.setOpenLong(efficiencyResultDto.getOpenLong().add(mdcEfficiencyResultDto.getOpenLong()));
        efficiencyResultDto.setWaitLong(efficiencyResultDto.getWaitLong().add(mdcEfficiencyResultDto.getWaitLong()));
        efficiencyResultDto.setCloseLong(efficiencyResultDto.getCloseLong().add(mdcEfficiencyResultDto.getCloseLong()));
        efficiencyResultDto.setFaultLong(efficiencyResultDto.getFaultLong().add(mdcEfficiencyResultDto.getFaultLong()));
        efficiencyResultDto.setFaultRate(efficiencyResultDto.getFaultRate().add(mdcEfficiencyResultDto.getFaultRate()));
        efficiencyResultDto.setRemoveFaultRunLong(efficiencyResultDto.getRemoveFaultRunLong().add(mdcEfficiencyResultDto.getRemoveFaultRunLong()));
        return mdcEfficiencyResultDto;
    }
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package org.jeecg.modules.mdc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.mdc.entity.*;
import org.jeecg.modules.mdc.mapper.MdcEquipmentFaultInfoMapper;
import org.jeecg.modules.mdc.service.IEquipmentService;
import org.jeecg.modules.mdc.service.IMdcEquipmentFaultInfoService;
import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService;
import org.jeecg.modules.mdc.service.IMdcSystemParametersService;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import org.jeecg.modules.mdc.vo.TimeInterval;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @Description: æ•…障率表
 * @Author: Lius
 * @Date: 2025-06-16
 * @Version: V1.0
 */
@Service
public class MdcEquipmentFaultInfoServiceImpl extends ServiceImpl<MdcEquipmentFaultInfoMapper, MdcEquipmentFaultInfo> implements IMdcEquipmentFaultInfoService {
    @Resource
    private IEquipmentService equipmentService;
    @Resource
    private IMdcSystemParametersService mdcSystemParametersService;
    @Resource
    private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void runningAllEquFaultStatistical(String dateTime) {
        String validDate = LocalDate.now().minusDays(1).toString().replaceAll("-", "");
        if (StringUtils.isNotBlank(dateTime)) {
            validDate = DateUtils.format(DateUtils.toDate(dateTime, DateUtils.STRDATE), DateUtils.STRDATE);
        }
        try {
            this.remove(new LambdaQueryWrapper<MdcEquipmentFaultInfo>().eq(MdcEquipmentFaultInfo::getTheDate, validDate));
        } catch (Exception e) {
            log.error("参数格式不对", e);
        }
        List<Equipment> equipmentList = equipmentService.list();
        if (equipmentList == null || equipmentList.isEmpty()) {
            return;
        }
        Map<String, MdcEquipmentFaultInfo> map = new HashMap<>();
        String finalValidDate = validDate;
        equipmentList.forEach(equipment -> {
            MdcEquipmentFaultInfo mdcEquipmentFaultInfo = new MdcEquipmentFaultInfo(equipment.getEquipmentid(), finalValidDate);
            map.put(equipment.getEquipmentid(), mdcEquipmentFaultInfo);
        });
        String planTime = "00:00:00";
        MdcSystemParameters mdcSystemParameters = mdcSystemParametersService.getOne(new LambdaQueryWrapper<MdcSystemParameters>().eq(MdcSystemParameters::getCode, "equip_log_statis_time"));
        if (mdcSystemParameters != null) {
            planTime = mdcSystemParameters.getValue();
        }
        List<String> equipmentIdList = equipmentList.stream().map(Equipment::getEquipmentid).collect(Collectors.toList());
        String startTime = DateUtils.format(DateUtils.setTimeForDay(DateUtils.toDate(validDate, DateUtils.STRDATE), planTime), DateUtils.STR_DATE_TIME_SMALL);
        Date start = DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL);
        String endTime = DateUtils.format(DateUtils.addDays(DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL), 1), DateUtils.STR_DATE_TIME_SMALL);
        Date end = DateUtils.toDate(endTime, DateUtils.STR_DATE_TIME_SMALL);
        //查询故障记录
        List<EquFaultRecord> equFaultRecordList = this.baseMapper.findFaultRecord(equipmentIdList, startTime, endTime);
        if (equFaultRecordList != null && !equFaultRecordList.isEmpty()) {
            // ä¿®æ•´æ—¶é—´
            Map<String, List<EquFaultRecord>> equFaultRecordMap = equFaultRecordList.stream().collect(Collectors.groupingBy(EquFaultRecord::getEquipmentId));
            equFaultRecordMap.forEach((key, value) -> {
                if (map.containsKey(key)) {
                    MdcEquipmentFaultInfo equFaultRecords = map.get(key);
                    long faultLong = calculateTotalFaultDuration(value, start, end);
                    equFaultRecords.setFaultLong((int) faultLong);
                    if (faultLong != 0) {
                        equFaultRecords.setFaultRate(new BigDecimal(faultLong).divide(new BigDecimal("86400"), 2, RoundingMode.HALF_UP));
                    }
                    // è®¡ç®—去除故障时长的加工时间
                    // step.1 æŸ¥è¯¢åŠ å·¥æ—¶é—´
                    List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.selectRunningData(key, start, end);
                    if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) {
                        // æ—¶é—´ä¿®æ­£
                        if (mdcEquipmentRunningSections.get(0).getStartTime().before(start)) {
                            mdcEquipmentRunningSections.get(0).setStartTime(start);
                        }
                        if (mdcEquipmentRunningSections.size() > 1) {
                            if (mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).getEndTime().after(end)) {
                                mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).setEndTime(end);
                            }
                        } else {
                            if (mdcEquipmentRunningSections.get(0).getEndTime().after(end)) {
                                mdcEquipmentRunningSections.get(0).setEndTime(end);
                            }
                        }
                        // step.2 è®¡ç®—去除故障时长的加工时间
                        long processingTime = calculateProcessingTimeWithoutFaults(mdcEquipmentRunningSections, value, start, end);
                        equFaultRecords.setRemoveFaultRunLong((int) processingTime);
                        if (faultLong != 0) {
                            // è®¡ç®—去除故障时长的利用率
                            BigDecimal removeFaultRate = new BigDecimal(processingTime).divide(new BigDecimal("86400").subtract(new BigDecimal(faultLong)), 2, RoundingMode.HALF_UP);
                            equFaultRecords.setRemoveFaultRate(removeFaultRate);
                        }
                    }
                    map.put(key, equFaultRecords);
                }
            });
        }
        if (!map.isEmpty()) {
            this.saveBatch(new ArrayList<>(map.values()));
        }
    }
    public static long calculateTotalFaultDuration(List<EquFaultRecord> records, Date startTime, Date endTime) {
        LocalDateTime start = DateUtils.convertToLocalDateTime(startTime);
        LocalDateTime end = DateUtils.convertToLocalDateTime(endTime);
        // ä¿®æ­£è®°å½•æ—¶é—´
        List<EquFaultRecord> correctedRecords = correctRecordTimes(records, start, end);
        // æŒ‰å¼€å§‹æ—¶é—´æŽ’序
        correctedRecords.sort(Comparator.comparing(EquFaultRecord::getStartTime));
        // åˆå¹¶é‡å æ—¶é—´æ®µ
        List<TimeInterval> mergedIntervals = mergeIntervals(correctedRecords);
        // è®¡ç®—总时长(秒)
        return mergedIntervals.stream()
                .mapToLong(interval -> ChronoUnit.SECONDS.between(interval.getStart(), interval.getEnd()))
                .sum();
    }
    private static List<EquFaultRecord> correctRecordTimes(List<EquFaultRecord> records, LocalDateTime startTime, LocalDateTime endTime) {
        return records.stream()
                .map(record -> {
                    LocalDateTime recordStart = DateUtils.convertToLocalDateTime(record.getStartTime());
                    LocalDateTime recordEnd = record.getEndTime() != null ?
                            DateUtils.convertToLocalDateTime(record.getEndTime()) : null;
                    // ä¿®æ­£å¼€å§‹æ—¶é—´
                    LocalDateTime correctedStart = recordStart.isBefore(startTime) ?
                            startTime : recordStart;
                    // ä¿®æ­£ç»“束时间
                    LocalDateTime correctedEnd = recordEnd == null || recordEnd.isAfter(endTime) ?
                            endTime : recordEnd;
                    // åˆ›å»ºä¿®æ­£åŽçš„记录
                    return new EquFaultRecord(
                            record.getEquipmentId(),
                            DateUtils.convertToDate(correctedStart),
                            DateUtils.convertToDate(correctedEnd)
                    );
                })
                .collect(Collectors.toList());
    }
    private static List<TimeInterval> mergeIntervals(List<EquFaultRecord> records) {
        List<TimeInterval> intervals = records.stream()
                .map(record -> new TimeInterval(
                        DateUtils.convertToLocalDateTime(record.getStartTime()),
                        DateUtils.convertToLocalDateTime(record.getEndTime())))
                .collect(Collectors.toList());
        if (intervals.isEmpty()) {
            return Collections.emptyList();
        }
        List<TimeInterval> merged = new ArrayList<>();
        TimeInterval current = intervals.get(0);
        for (int i = 1; i < intervals.size(); i++) {
            TimeInterval next = intervals.get(i);
            if (next.getStart().isBefore(current.getEnd()) || next.getStart().equals(current.getEnd())) {
                // æœ‰é‡å ï¼Œåˆå¹¶åŒºé—´
                current.setEnd(current.getEnd().isAfter(next.getEnd()) ? current.getEnd() : next.getEnd());
            } else {
                // æ— é‡å ï¼Œæ·»åŠ å½“å‰åŒºé—´å¹¶æ›´æ–°å½“å‰åŒºé—´
                merged.add(current);
                current = next;
            }
        }
        merged.add(current); // æ·»åŠ æœ€åŽä¸€ä¸ªåŒºé—´
        return merged;
    }
    // è®¡ç®—去除故障时长后的加工时间
    private long calculateProcessingTimeWithoutFaults(
            List<MdcEquipmentRunningSection> runningSections,
            List<EquFaultRecord> faultRecords,
            Date startTime,
            Date endTime) {
        // è½¬æ¢ä¸ºLocalDateTime进行处理
        LocalDateTime start = DateUtils.convertToLocalDateTime(startTime);
        LocalDateTime end = DateUtils.convertToLocalDateTime(endTime);
        // å°†æ•…障记录转换为时间区间并合并重叠部分
//        List<TimeInterval> faultIntervals = faultRecords.stream()
//                .map(record -> new TimeInterval(
//                        convertToLocalDateTime(record.getStartTime()),
//                        convertToLocalDateTime(record.getEndTime())))
//                .collect(Collectors.toList());
        List<TimeInterval> mergedFaultIntervals = mergeIntervals(faultRecords);
        long totalProcessingTime = 0;
        // éåŽ†æ¯ä¸ªåŠ å·¥åŒºé—´ï¼ŒæŽ’é™¤æ•…éšœæ—¶é—´
        for (MdcEquipmentRunningSection section : runningSections) {
            LocalDateTime sectionStart = DateUtils.convertToLocalDateTime(section.getStartTime());
            LocalDateTime sectionEnd = DateUtils.convertToLocalDateTime(section.getEndTime());
            // æŽ’除故障时间后的有效加工时间
            List<TimeInterval> validIntervals = excludeFaultsFromSection(
                    new TimeInterval(sectionStart, sectionEnd),
                    mergedFaultIntervals);
            // ç´¯åŠ æœ‰æ•ˆåŠ å·¥æ—¶é—´ï¼ˆç§’ï¼‰
            for (TimeInterval interval : validIntervals) {
                totalProcessingTime += ChronoUnit.SECONDS.between(interval.getStart(), interval.getEnd());
            }
        }
        return totalProcessingTime;
    }
    // ä»Žè¿è¡ŒåŒºé—´ä¸­æŽ’除故障时间
    private List<TimeInterval> excludeFaultsFromSection(
            TimeInterval section,
            List<TimeInterval> faultIntervals) {
        List<TimeInterval> validIntervals = new ArrayList<>();
        validIntervals.add(section);
        // éåŽ†æ¯ä¸ªæ•…éšœåŒºé—´ï¼Œä»Žæœ‰æ•ˆåŒºé—´ä¸­æ‰£é™¤
        for (TimeInterval fault : faultIntervals) {
            List<TimeInterval> newValidIntervals = new ArrayList<>();
            for (TimeInterval valid : validIntervals) {
                // è®¡ç®—有效区间与故障区间的交集
                if (isOverlapping(valid, fault)) {
                    // åˆ†å‰²æœ‰æ•ˆåŒºé—´
                    splitInterval(valid, fault, newValidIntervals);
                } else {
                    // æ— äº¤é›†ï¼Œä¿ç•™åŽŸæœ‰æ•ˆåŒºé—´
                    newValidIntervals.add(valid);
                }
            }
            validIntervals = newValidIntervals;
        }
        return validIntervals;
    }
    // åˆ¤æ–­ä¸¤ä¸ªæ—¶é—´åŒºé—´æ˜¯å¦é‡å 
    private boolean isOverlapping(TimeInterval a, TimeInterval b) {
        return a.getStart().isBefore(b.getEnd()) && b.getStart().isBefore(a.getEnd());
    }
    // åˆ†å‰²åŒºé—´ï¼ˆæ‰£é™¤é‡å éƒ¨åˆ†ï¼‰
    private void splitInterval(
            TimeInterval valid,
            TimeInterval fault,
            List<TimeInterval> result) {
        // é‡å å‰çš„部分
        if (valid.getStart().isBefore(fault.getStart())) {
            result.add(new TimeInterval(valid.getStart(), fault.getStart()));
        }
        // é‡å åŽçš„部分
        if (valid.getEnd().isAfter(fault.getEnd())) {
            result.add(new TimeInterval(fault.getEnd(), valid.getEnd()));
        }
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java
@@ -13,15 +13,20 @@
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.TimeFieldUtils;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import org.jeecg.modules.mdc.vo.MdcAlarmAnalyzeQueryVo;
import org.jeecg.modules.mdc.vo.MdcEquipmentRunningSectionVo;
import org.jeecg.modules.mdc.vo.TimeInterval;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @Description: è®¾å¤‡è¿è¡Œæ—¶æ®µçŠ¶æ€è¡¨
@@ -64,6 +69,8 @@
        List<MdcEquipmentRunningSection> running = loadEquipmentRunningTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr());
        //查询报警数据
        List<MdcEquipmentRunningSection> errs = loadEquipmentErrorTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr());
        //查询故障数据
        List<MdcEquipmentRunningSection> faults = loadEquipmentFaultTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr());
        Equipment equip = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, equipmentRunningSectionVo.getEquipmentId()));
        if (!running.isEmpty()) {
            MdcEquipmentRunningSectionDto dto;
@@ -100,22 +107,12 @@
                        }
                    }
                }
//                Set<TmpEquipmentAlarm> set = entity.getTmpEquipmentAlarmSet();
//                if (entity.getStatus() == 22 && set != null && !set.isEmpty()) {
//                    Iterator<TmpEquipmentAlarm> iterator = entity.getTmpEquipmentAlarmSet().iterator();
//                    //获取报警编号相同的报警信息
//                    while (iterator.hasNext()) {
//                        TmpEquipmentAlarm next = iterator.next();
//                        if (StringUtils.isNotBlank(next.getAlarmNo()) && next.getAlarmNo().equals(entity.getStatus())) {
//                            dto.setAlarmContent(next.getAlarmContent());
//                        }
//                    }
//                }
                dtos.add(dto);
            }
        }
        List<MdcEquipmentRunningSectionDto> result = new ArrayList<>();
        //合并相同状态数据
        for (int i = 0; i < dtos.size() - 1; i++) {
            MdcEquipmentRunningSectionDto mdcEquipmentRunningSectionDto = dtos.get(i);
@@ -141,7 +138,105 @@
            result.addAll(dtos);
        }
        if (faults != null && !faults.isEmpty()) {
            MdcEquipmentRunningSectionDto dto;
            for (MdcEquipmentRunningSection entity : faults) {
                dto = new MdcEquipmentRunningSectionDto();
                BeanUtils.copyProperties(entity, dto);
                result.add(dto);
            }
        }
        return result;
    }
    private List<MdcEquipmentRunningSection> loadEquipmentFaultTrace(String equipmentId, String collectTimeStr) {
        List<MdcEquipmentRunningSection> result = new ArrayList<>();
        Date startTime = DateUtils.getShortDate(collectTimeStr);
        Date now = DateUtils.removeTime(DateUtils.getNow());
        long second = DateUtils.differentSecond(startTime, now);
        Date endTime = DateUtils.plusTime(startTime, 1);
        if (collectTimeStr.equals(LocalDate.now().toString())) {
            endTime = DateUtils.getNow();
        }
        if (second < 0) {
            return Collections.emptyList();
        } else {
            List<EquFaultRecord> equFaultRecordList = this.baseMapper.findFaultList(equipmentId, startTime, endTime);
            if (equFaultRecordList != null && !equFaultRecordList.isEmpty()) {
                // ä¿®æ­£è®°å½•æ—¶é—´
                List<EquFaultRecord> correctedRecords = correctRecordTimes(equFaultRecordList, DateUtils.convertToLocalDateTime(startTime), DateUtils.convertToLocalDateTime(endTime));
                // æŒ‰å¼€å§‹æ—¶é—´æŽ’序
                correctedRecords.sort(Comparator.comparing(EquFaultRecord::getStartTime));
                // åˆå¹¶é‡å æ—¶é—´æ®µ
                List<TimeInterval> mergedIntervals = mergeIntervals(correctedRecords);
                for (TimeInterval mergedInterval : mergedIntervals) {
                    MdcEquipmentRunningSection mdcEquipmentRunningSection = new MdcEquipmentRunningSection(25, equipmentId, DateUtils.convertToDate(mergedInterval.getStart()), DateUtils.convertToDate(mergedInterval.getEnd()), DateUtils.convertToDate(mergedInterval.getStart()).getTime(), DateUtils.convertToDate(mergedInterval.getEnd()).getTime());
                    mdcEquipmentRunningSection.setDuration(DateUtils.differentSecond(mdcEquipmentRunningSection.getStartTime(), mdcEquipmentRunningSection.getEndTime()));
                    result.add(mdcEquipmentRunningSection);
                }
            }
        }
        return result;
    }
    private static List<EquFaultRecord> correctRecordTimes(List<EquFaultRecord> records, LocalDateTime startTime, LocalDateTime endTime) {
        return records.stream()
                .map(record -> {
                    LocalDateTime recordStart = DateUtils.convertToLocalDateTime(record.getStartTime());
                    LocalDateTime recordEnd = record.getEndTime() != null ?
                            DateUtils.convertToLocalDateTime(record.getEndTime()) : null;
                    // ä¿®æ­£å¼€å§‹æ—¶é—´
                    LocalDateTime correctedStart = recordStart.isBefore(startTime) ?
                            startTime : recordStart;
                    // ä¿®æ­£ç»“束时间
                    LocalDateTime correctedEnd = recordEnd == null || recordEnd.isAfter(endTime) ?
                            endTime : recordEnd;
                    // åˆ›å»ºä¿®æ­£åŽçš„记录
                    return new EquFaultRecord(
                            record.getEquipmentId(),
                            DateUtils.convertToDate(correctedStart),
                            DateUtils.convertToDate(correctedEnd)
                    );
                })
                .collect(Collectors.toList());
    }
    private static List<TimeInterval> mergeIntervals(List<EquFaultRecord> records) {
        List<TimeInterval> intervals = records.stream()
                .map(record -> new TimeInterval(
                        DateUtils.convertToLocalDateTime(record.getStartTime()),
                        DateUtils.convertToLocalDateTime(record.getEndTime())))
                .collect(Collectors.toList());
        if (intervals.isEmpty()) {
            return Collections.emptyList();
        }
        List<TimeInterval> merged = new ArrayList<>();
        TimeInterval current = intervals.get(0);
        for (int i = 1; i < intervals.size(); i++) {
            TimeInterval next = intervals.get(i);
            if (next.getStart().isBefore(current.getEnd()) || next.getStart().equals(current.getEnd())) {
                // æœ‰é‡å ï¼Œåˆå¹¶åŒºé—´
                current.setEnd(current.getEnd().isAfter(next.getEnd()) ? current.getEnd() : next.getEnd());
            } else {
                // æ— é‡å ï¼Œæ·»åŠ å½“å‰åŒºé—´å¹¶æ›´æ–°å½“å‰åŒºé—´
                merged.add(current);
                current = next;
            }
        }
        merged.add(current); // æ·»åŠ æœ€åŽä¸€ä¸ªåŒºé—´
        return merged;
    }
    /**
@@ -520,9 +615,9 @@
            //获取running运行的日志记录
            List<MdcEquipmentRunningSection> list = this.equipmentRunningTracesLog(equipment.getEquipmentid());
            if (list != null && !list.isEmpty()) {
                List<MdcEquipmentRunningSection> equipList = addSequenceNumber(list); //添加程序号
                this.ergodicTrim(equipList);
                super.saveBatch(equipList);
//                List<MdcEquipmentRunningSection> equipList = addSequenceNumber(list); //添加程序号
                this.ergodicTrim(list);
                super.saveBatch(list);
            }
            //获取报警的日志记录
            List<MdcEquipmentRunningSection> errorList = this.equipmentRunningTracesErrorLog(equipment.getEquipmentid());
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
@@ -37,10 +37,7 @@
    private IMdcSystemParametersService mdcSystemParametersService;
    @Resource
    private ISysDictService sysDictService;
    @Resource
    private IEquipmentStatisticalInfoService equipmentStatisticalInfoService;
    private IMdcEquipmentFaultInfoService mdcEquipmentFaultInfoService;
    /**
     * è®¡ç®—设备单日运行数据
@@ -69,28 +66,8 @@
        }
        if (!result.isEmpty()) {
            this.saveBatch(result);
            List<DictModel> dictList = sysDictService.queryDictItemsByCode("data_synchronization_flag");
            if (dictList != null && !dictList.isEmpty() && "0".equals(dictList.get(0).getValue())) {
                List<EquipmentStatisticalInfo> list = this.dataHandle(result);
                equipmentStatisticalInfoService.saveBatch(list);
            }
        }
    }
    private List<EquipmentStatisticalInfo> dataHandle(List<MdcEquipmentStatisticalInfo> list) {
        List<EquipmentStatisticalInfo> result = new ArrayList<>();
        list.forEach(item -> {
            EquipmentStatisticalInfo equipmentStatisticalInfo = new EquipmentStatisticalInfo();
            equipmentStatisticalInfo.setEquipment(item.getEquipmentId());
            equipmentStatisticalInfo.setTheDate(item.getTheDate());
            equipmentStatisticalInfo.setClosedLong(item.getCloseLong());
            equipmentStatisticalInfo.setOpeningLong(item.getOpenLong());
            equipmentStatisticalInfo.setErroringLong(item.getErrorLong());
            equipmentStatisticalInfo.setProcessingLong(item.getProcessLong());
            equipmentStatisticalInfo.setWaitingLong(item.getWaitLong());
            result.add(equipmentStatisticalInfo);
        });
        return result;
        mdcEquipmentFaultInfoService.runningAllEquFaultStatistical(dateTime);
    }
    private List<MdcEquipmentStatisticalInfo> equipmentStatisticalProcess(Equipment equipment, String dateTime) {
@@ -141,7 +118,6 @@
                List<MdcEquipmentRunningSection> equipmentRunningSectionList = mdcEquipmentRunningSectionService.listForEquipmentStatisticalInfo(equipment.getEquipmentid(), startDate, endDate);
                return this.statisticsData(equipmentRunningSectionList, planTime, startDate, endDate, equipment);
            } else {
                //待验证
                Date end = DateUtils.plusTime(initDate, 1);
                endDate = DateUtils.setTimeForDay(end, planTime);
                List<MdcEquipmentRunningSection> equipmentRunningSectionList = mdcEquipmentRunningSectionService.listForEquipmentStatisticalInfo(equipment.getEquipmentid(), startDate, endDate);
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquFaultRecord.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,32 @@
package org.jeecg.modules.mdc.vo;
import lombok.Data;
import java.util.Date;
/**
 * @Author: Lius
 * @CreateTime: 2025-06-16
 * @Description:
 */
@Data
public class EquFaultRecord {
    /**
     * è®¾å¤‡ç¼–号
     */
    private String equipmentId;
    /**
     * å¼€å§‹æ—¶é—´
     */
    private Date startTime;
    /**
     * ç»“束时间
     */
    private Date endTime;
    public EquFaultRecord(String equipmentId, Date startTime, Date endTime) {
        this.equipmentId = equipmentId;
        this.startTime = startTime;
        this.endTime = endTime;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,21 @@
package org.jeecg.modules.mdc.vo;
import lombok.Data;
import java.time.LocalDateTime;
/**
 * @Author: Lius
 * @CreateTime: 2025-06-17
 * @Description:
 */
@Data
public class TimeInterval {
    LocalDateTime start;
    LocalDateTime end;
    public TimeInterval(LocalDateTime start, LocalDateTime end) {
        this.start = start;
        this.end = end;
    }
}