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/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/job/CollectEquipmentDataMonthJob.java
@@ -101,18 +101,18 @@ mdcEquipmentStatisticalInfoMonth.setEquipmentId(mdcEquipment.getEquipmentId()); mdcEquipmentStatisticalInfoMonth.setTheMonth(date); if (mdcEquipmentStatisticalDto != null) { mdcEquipmentStatisticalInfoMonth.setCloseLong(mdcEquipmentStatisticalDto.getCloseLong().intValue()); mdcEquipmentStatisticalInfoMonth.setErrorLong(mdcEquipmentStatisticalDto.getErrorLong().intValue()); mdcEquipmentStatisticalInfoMonth.setOpenLong(mdcEquipmentStatisticalDto.getOpenLong().intValue()); mdcEquipmentStatisticalInfoMonth.setProcessLong(mdcEquipmentStatisticalDto.getProcessLong().intValue()); mdcEquipmentStatisticalInfoMonth.setWaitLong(mdcEquipmentStatisticalDto.getWaitLong().intValue()); mdcEquipmentStatisticalInfoMonth.setOpenRate(mdcEquipmentStatisticalDto.getOpenLong().divide((new BigDecimal("864").multiply(mdcEquipmentStatisticalDto.getDayNum())), 4, RoundingMode.HALF_UP)); mdcEquipmentStatisticalInfoMonth.setStartRate(mdcEquipmentStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentStatisticalDto.getProcessLong().divide(mdcEquipmentStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); mdcEquipmentStatisticalInfoMonth.setUtilizationRate(mdcEquipmentStatisticalDto.getProcessLong().divide((new BigDecimal("864").multiply(mdcEquipmentStatisticalDto.getDayNum())), 4, RoundingMode.HALF_UP)); mdcEquipmentStatisticalInfoMonth.setFaultLong(mdcEquipmentStatisticalDto.getFaultLong().intValue()); mdcEquipmentStatisticalInfoMonth.setFaultRate(mdcEquipmentStatisticalDto.getFaultRate()); mdcEquipmentStatisticalInfoMonth.setRemoveFaultRate(mdcEquipmentStatisticalDto.getRemoveFaultRate()); mdcEquipmentStatisticalInfoMonth.setRemoveFaultRunLong(mdcEquipmentStatisticalDto.getRemoveFaultRunLong().intValue()); mdcEquipmentStatisticalInfoMonth.setCloseLong(mdcEquipmentStatisticalDto.getCloseLong() == null ? 0 : mdcEquipmentStatisticalDto.getCloseLong().intValue()); mdcEquipmentStatisticalInfoMonth.setErrorLong(mdcEquipmentStatisticalDto.getErrorLong() == null ? 0 : mdcEquipmentStatisticalDto.getErrorLong().intValue()); mdcEquipmentStatisticalInfoMonth.setOpenLong(mdcEquipmentStatisticalDto.getOpenLong() == null ? 0 : mdcEquipmentStatisticalDto.getOpenLong().intValue()); mdcEquipmentStatisticalInfoMonth.setProcessLong(mdcEquipmentStatisticalDto.getProcessLong() == null ? 0 : mdcEquipmentStatisticalDto.getProcessLong().intValue()); mdcEquipmentStatisticalInfoMonth.setWaitLong(mdcEquipmentStatisticalDto.getWaitLong() == null ? 0 : mdcEquipmentStatisticalDto.getWaitLong().intValue()); mdcEquipmentStatisticalInfoMonth.setOpenRate(mdcEquipmentStatisticalDto.getOpenLong() == null || mdcEquipmentStatisticalDto.getDayNum() == null ? BigDecimal.ZERO : mdcEquipmentStatisticalDto.getOpenLong().divide((new BigDecimal("864").multiply(mdcEquipmentStatisticalDto.getDayNum())), 4, RoundingMode.HALF_UP)); mdcEquipmentStatisticalInfoMonth.setStartRate(mdcEquipmentStatisticalDto.getOpenLong() == null || mdcEquipmentStatisticalDto.getProcessLong() == null ? BigDecimal.ZERO : (mdcEquipmentStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentStatisticalDto.getProcessLong().divide(mdcEquipmentStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); mdcEquipmentStatisticalInfoMonth.setUtilizationRate(mdcEquipmentStatisticalDto.getProcessLong() == null || mdcEquipmentStatisticalDto.getDayNum() == null ? BigDecimal.ZERO : mdcEquipmentStatisticalDto.getProcessLong().divide((new BigDecimal("864").multiply(mdcEquipmentStatisticalDto.getDayNum())), 4, RoundingMode.HALF_UP)); mdcEquipmentStatisticalInfoMonth.setFaultLong(mdcEquipmentStatisticalDto.getFaultLong() == null ? 0 : mdcEquipmentStatisticalDto.getFaultLong().intValue()); mdcEquipmentStatisticalInfoMonth.setFaultRate(mdcEquipmentStatisticalDto.getFaultRate() == null ? BigDecimal.ZERO : mdcEquipmentStatisticalDto.getFaultRate()); mdcEquipmentStatisticalInfoMonth.setRemoveFaultRate(mdcEquipmentStatisticalDto.getRemoveFaultRate() == null ? BigDecimal.ZERO : mdcEquipmentStatisticalDto.getRemoveFaultRate()); mdcEquipmentStatisticalInfoMonth.setRemoveFaultRunLong(mdcEquipmentStatisticalDto.getRemoveFaultRunLong() == null ? 0 : mdcEquipmentStatisticalDto.getRemoveFaultRunLong().intValue()); } mdcEquipmentStatisticalInfoMonthList.add(mdcEquipmentStatisticalInfoMonth); // step.3 æ±æ»ç次å©ç¨çæ°æ® @@ -122,15 +122,25 @@ mdcEquipmentShiftInfoMonth.setTheMonth(date); mdcEquipmentShiftInfoMonth.setShiftType(CommonConstant.SHIFT_TYPE_1); if (mdcEquipmentShiftStatisticalDto != null) { mdcEquipmentShiftInfoMonth.setCloseLong(mdcEquipmentShiftStatisticalDto.getCloseLong().intValue()); mdcEquipmentShiftInfoMonth.setTotalLong(mdcEquipmentShiftStatisticalDto.getTotalLong().intValue()); mdcEquipmentShiftInfoMonth.setOpenLong(mdcEquipmentShiftStatisticalDto.getOpenLong().intValue()); mdcEquipmentShiftInfoMonth.setErrorLong(mdcEquipmentShiftStatisticalDto.getErrorLong().intValue()); mdcEquipmentShiftInfoMonth.setWaitLong(mdcEquipmentShiftStatisticalDto.getWaitLong().intValue()); mdcEquipmentShiftInfoMonth.setProcessLong(mdcEquipmentShiftStatisticalDto.getProcessLong().intValue()); mdcEquipmentShiftInfoMonth.setUtilizationRate(mdcEquipmentShiftStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getProcessLong().divide(mdcEquipmentShiftStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); mdcEquipmentShiftInfoMonth.setStartRate(mdcEquipmentShiftStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getProcessLong().divide(mdcEquipmentShiftStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); mdcEquipmentShiftInfoMonth.setOpenRate(mdcEquipmentShiftStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getOpenLong().divide(mdcEquipmentShiftStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); mdcEquipmentShiftInfoMonth.setCloseLong(mdcEquipmentShiftStatisticalDto.getCloseLong() == null ? 0 : mdcEquipmentShiftStatisticalDto.getCloseLong().intValue()); mdcEquipmentShiftInfoMonth.setTotalLong(mdcEquipmentShiftStatisticalDto.getTotalLong() == null ? 0 : mdcEquipmentShiftStatisticalDto.getTotalLong().intValue()); mdcEquipmentShiftInfoMonth.setOpenLong(mdcEquipmentShiftStatisticalDto.getOpenLong() == null ? 0 : mdcEquipmentShiftStatisticalDto.getOpenLong().intValue()); mdcEquipmentShiftInfoMonth.setErrorLong(mdcEquipmentShiftStatisticalDto.getErrorLong() == null ? 0 : mdcEquipmentShiftStatisticalDto.getErrorLong().intValue()); mdcEquipmentShiftInfoMonth.setWaitLong(mdcEquipmentShiftStatisticalDto.getWaitLong() == null ? 0 : mdcEquipmentShiftStatisticalDto.getWaitLong().intValue()); mdcEquipmentShiftInfoMonth.setProcessLong(mdcEquipmentShiftStatisticalDto.getProcessLong() == null ? 0 : mdcEquipmentShiftStatisticalDto.getProcessLong().intValue()); mdcEquipmentShiftInfoMonth.setUtilizationRate(mdcEquipmentShiftStatisticalDto.getTotalLong() == null || mdcEquipmentShiftStatisticalDto.getProcessLong() == null ? BigDecimal.ZERO : (mdcEquipmentShiftStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getProcessLong().divide(mdcEquipmentShiftStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); mdcEquipmentShiftInfoMonth.setStartRate(mdcEquipmentShiftStatisticalDto.getOpenLong() == null || mdcEquipmentShiftStatisticalDto.getProcessLong() == null ? BigDecimal.ZERO : (mdcEquipmentShiftStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getProcessLong().divide(mdcEquipmentShiftStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); mdcEquipmentShiftInfoMonth.setOpenRate(mdcEquipmentShiftStatisticalDto.getOpenLong() == null || mdcEquipmentShiftStatisticalDto.getTotalLong() == null ? BigDecimal.ZERO : (mdcEquipmentShiftStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getOpenLong().divide(mdcEquipmentShiftStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); } else { mdcEquipmentShiftInfoMonth.setCloseLong(0); mdcEquipmentShiftInfoMonth.setTotalLong(0); mdcEquipmentShiftInfoMonth.setOpenLong(0); mdcEquipmentShiftInfoMonth.setErrorLong(0); mdcEquipmentShiftInfoMonth.setWaitLong(0); mdcEquipmentShiftInfoMonth.setProcessLong(0); mdcEquipmentShiftInfoMonth.setUtilizationRate(BigDecimal.ZERO); mdcEquipmentShiftInfoMonth.setStartRate(BigDecimal.ZERO); mdcEquipmentShiftInfoMonth.setOpenRate(BigDecimal.ZERO); } mdcEquipmentStatisticalShiftInfoMonthList.add(mdcEquipmentShiftInfoMonth); // step.4 æ±æ»åçæ¬¡å©ç¨çæ°æ® @@ -141,15 +151,15 @@ equipmentStatisticalShiftInfoMonth.setEquipmentId(mdcEquipment.getEquipmentId()); equipmentStatisticalShiftInfoMonth.setTheMonth(date); equipmentStatisticalShiftInfoMonth.setShiftType(CommonConstant.SHIFT_TYPE_2); equipmentStatisticalShiftInfoMonth.setCloseLong(equipmentStatisticalDto.getCloseLong().intValue()); equipmentStatisticalShiftInfoMonth.setTotalLong(equipmentStatisticalDto.getTotalLong().intValue()); equipmentStatisticalShiftInfoMonth.setOpenLong(equipmentStatisticalDto.getOpenLong().intValue()); equipmentStatisticalShiftInfoMonth.setErrorLong(equipmentStatisticalDto.getErrorLong().intValue()); equipmentStatisticalShiftInfoMonth.setWaitLong(equipmentStatisticalDto.getWaitLong().intValue()); equipmentStatisticalShiftInfoMonth.setProcessLong(equipmentStatisticalDto.getProcessLong().intValue()); equipmentStatisticalShiftInfoMonth.setUtilizationRate(equipmentStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getProcessLong().divide(equipmentStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); equipmentStatisticalShiftInfoMonth.setStartRate(equipmentStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getProcessLong().divide(equipmentStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); equipmentStatisticalShiftInfoMonth.setOpenRate(equipmentStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getOpenLong().divide(equipmentStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); equipmentStatisticalShiftInfoMonth.setCloseLong(equipmentStatisticalDto.getCloseLong() == null ? 0 : equipmentStatisticalDto.getCloseLong().intValue()); equipmentStatisticalShiftInfoMonth.setTotalLong(equipmentStatisticalDto.getTotalLong() == null ? 0 : equipmentStatisticalDto.getTotalLong().intValue()); equipmentStatisticalShiftInfoMonth.setOpenLong(equipmentStatisticalDto.getOpenLong() == null ? 0 : equipmentStatisticalDto.getOpenLong().intValue()); equipmentStatisticalShiftInfoMonth.setErrorLong(equipmentStatisticalDto.getErrorLong() == null ? 0 : equipmentStatisticalDto.getErrorLong().intValue()); equipmentStatisticalShiftInfoMonth.setWaitLong(equipmentStatisticalDto.getWaitLong() == null ? 0 : equipmentStatisticalDto.getWaitLong().intValue()); equipmentStatisticalShiftInfoMonth.setProcessLong(equipmentStatisticalDto.getProcessLong() == null ? 0 : equipmentStatisticalDto.getProcessLong().intValue()); equipmentStatisticalShiftInfoMonth.setUtilizationRate(equipmentStatisticalDto.getTotalLong() == null || equipmentStatisticalDto.getProcessLong() == null ? BigDecimal.ZERO : (equipmentStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getProcessLong().divide(equipmentStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); equipmentStatisticalShiftInfoMonth.setStartRate(equipmentStatisticalDto.getOpenLong() == null || equipmentStatisticalDto.getProcessLong() == null ? BigDecimal.ZERO : (equipmentStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getProcessLong().divide(equipmentStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); equipmentStatisticalShiftInfoMonth.setOpenRate(equipmentStatisticalDto.getTotalLong() == null || equipmentStatisticalDto.getOpenLong() == null ? BigDecimal.ZERO : (equipmentStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getOpenLong().divide(equipmentStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO)); mdcEquipmentStatisticalShiftInfoMonthList.add(equipmentStatisticalShiftInfoMonth); } } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentFaultInfoMapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,22 @@ package org.jeecg.modules.mdc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.jeecg.modules.mdc.entity.MdcEquipmentFaultInfo; 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); String getMaxStaticsData(); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java
@@ -78,4 +78,6 @@ List<Integer> getDataList(@Param("equipmentId") String equipmentId, @Param("date") Date date); List<MdcEquipmentWaitSectionDto> findWaitList(@Param("date") String date); MdcEquipmentRunningSection getFirstRecord(); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEfficiencyReportMapper.xml
@@ -69,10 +69,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 <= #{ vo.endTime } AND t1.the_date >= #{ vo.startTime } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentFaultInfoMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,30 @@ <?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 < #{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> <select id="getMaxStaticsData" resultType="java.lang.String"> SELECT TOP 1 the_date FROM mdc_equipment_fault_info ORDER BY the_date DESC </select> </mapper> lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml
@@ -188,5 +188,7 @@ equipment_id, start_time DESC </select> <select id="getFirstRecord" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection"> SELECT TOP 1 * FROM mdc_equipment_running_section ORDER BY start_time </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 com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.mdc.entity.MdcEquipmentFaultInfo; /** * @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/IMdcEquipmentRunningSectionService.java
@@ -90,4 +90,7 @@ List<Integer> getDataList(String equipmentId, Date date); List<MdcEquipmentWaitSectionDto> findWaitList(String date); MdcEquipmentRunningSection getFirstRecord(); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,380 @@ package org.jeecg.modules.mdc.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang.StringUtils; import org.jeecg.modules.mdc.entity.Equipment; import org.jeecg.modules.mdc.entity.MdcEquipmentFaultInfo; import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection; import org.jeecg.modules.mdc.entity.MdcSystemParameters; 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 org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; 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) { Date initDate = null; if (StringUtils.isNotBlank(dateTime)) { initDate = DateUtils.toDate(dateTime, DateUtils.STRDATE); } else { // åæåçç»è®¡æ¶é´ String date = this.baseMapper.getMaxStaticsData(); if (date != null) { initDate = DateUtils.toDate(date, DateUtils.STRDATE); } else { // 忬¡åå¼ åææ©æ¶é´è®°å½ MdcEquipmentRunningSection equipmentRunningSection = mdcEquipmentRunningSectionService.getFirstRecord(); if (equipmentRunningSection != null) { initDate = equipmentRunningSection.getStartTime(); } } } Date endDate = DateUtils.addDays(DateUtils.getNow(), -1); List<String> dateList = DateUtils.getDatesStringList2(initDate, endDate); if (dateList.isEmpty()) { return; } try { this.remove(new LambdaQueryWrapper<MdcEquipmentFaultInfo>().in(MdcEquipmentFaultInfo::getTheDate, dateList)); } catch (Exception e) { log.error("åæ°æ ¼å¼ä¸å¯¹", e); } List<Equipment> equipmentList = equipmentService.list(); if (equipmentList == null || equipmentList.isEmpty()) { return; } 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()); for (String validDate : dateList) { 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 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)); map.forEach((key, value1) -> { MdcEquipmentFaultInfo equFaultRecords = value1; if (equFaultRecordMap.containsKey(key)) { List<EquFaultRecord> value = equFaultRecordMap.get(key); long faultLong = calculateTotalFaultDuration(value, start, end); equFaultRecords.setFaultLong((int) faultLong); if (faultLong != 0) { equFaultRecords.setFaultRate(new BigDecimal(faultLong).divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); } // 计ç®å»é¤æ éæ¶é¿çå å·¥æ¶é´ // step.1 æ¥è¯¢å å·¥æ¶é´ List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); 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); } } List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); if (!collect.isEmpty()) { // step.2 计ç®å»é¤æ éæ¶é¿çå å·¥æ¶é´ long processingTime = calculateProcessingTimeWithoutFaults(collect, value, start, end); equFaultRecords.setRemoveFaultRunLong((int) processingTime); if (faultLong != 0 && faultLong != 86400) { // 计ç®å»é¤æ éæ¶é¿çå©ç¨ç BigDecimal removeFaultRate = new BigDecimal(processingTime).divide(new BigDecimal("864").subtract(new BigDecimal(faultLong)), 2, RoundingMode.HALF_UP); equFaultRecords.setRemoveFaultRate(removeFaultRate); } } } } else { List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); 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); } } List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); if (!collect.isEmpty()) { long totalProcessingTime = 0; for (MdcEquipmentRunningSection mdcEquipmentRunningSection : collect) { totalProcessingTime += ChronoUnit.SECONDS.between(DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getStartTime()), DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getEndTime())); } equFaultRecords.setRemoveFaultRunLong((int) totalProcessingTime); // 计ç®å»é¤æ éæ¶é¿çå©ç¨ç BigDecimal removeFaultRate = new BigDecimal(totalProcessingTime).divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP); equFaultRecords.setRemoveFaultRate(removeFaultRate); } } } map.put(key, equFaultRecords); }); } else { map.forEach((key, value1) -> { MdcEquipmentFaultInfo equFaultRecords = value1; List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); 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); } } List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); if (!collect.isEmpty()) { long totalProcessingTime = 0; for (MdcEquipmentRunningSection mdcEquipmentRunningSection : collect) { totalProcessingTime += ChronoUnit.SECONDS.between(DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getStartTime()), DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getEndTime())); } equFaultRecords.setRemoveFaultRunLong((int) totalProcessingTime); // 计ç®å»é¤æ éæ¶é¿çå©ç¨ç BigDecimal removeFaultRate = new BigDecimal(totalProcessingTime).divide(new BigDecimal("864"), 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<EquFaultRecord> correctedRecords = correctRecordTimes(faultRecords, start, end); List<TimeInterval> mergedFaultIntervals = mergeIntervals(correctedRecords); 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
@@ -746,6 +746,11 @@ return this.baseMapper.findWaitList(date); } @Override public MdcEquipmentRunningSection getFirstRecord() { return this.baseMapper.getFirstRecord(); } private Map<String, List<MdcEquipmentRunningSectionDto>> logCharts(MdcEquipmentRunningSectionVo equipmentRunningSectionVo, String date) { Map<String, List<MdcEquipmentRunningSectionDto>> map = new HashMap<>(); List<MdcEquipmentRunningSectionDto> normal = new ArrayList<>(); 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; } } lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/controller/MsiWebapiJsonController.java
@@ -42,14 +42,14 @@ entity.setModuleType("MDC"); entity.setWebapiInfo(data.toString()); //åç»è¿è¡å ¶ä»ä¸å¡å ³è JsonMapper mapper = new JsonMapper(); // JsonMapper mapper = new JsonMapper(); service.save(entity); try { service.saveTableAutomationOne(data); } catch (Exception e) { log.error("JSON parsing error: {}", e.getMessage()); return Result.error("æ°æ®å¼å¸¸", e.getMessage()); } service.save(entity); return Result.OK("æ¥æ¶æå"); } lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java
@@ -3,8 +3,10 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import liquibase.util.JdbcUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity; import org.jeecg.modules.msi.webapi.mapper.MsiWebapiJsonMapper; import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService; @@ -15,7 +17,9 @@ import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.jetbrains.annotations.NotNull; import javax.annotation.Resource; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; @@ -24,29 +28,33 @@ import java.util.*; @Service @Slf4j public class MsiWebapiJsonServiceImpl extends ServiceImpl<MsiWebapiJsonMapper, MsiWebapiJsonEntity> implements IMsiWebapiJsonService { @Autowired private JdbcTemplate jdbcTemplate; @Resource private RedisUtil redisUtil; private final static String ZDHKEY = "ZDHKEY_"; /** * è§£æåæ¡æ°æ®ä¿åå°å表 * * @param data * @return */ @Override public boolean saveTableAutomationOne(List<MachineEquipentInfo> data) { if (data ==null || data.isEmpty()) { if (data == null || data.isEmpty()) { return false; } List<String> listStatus = new ArrayList<>(); List<String> listParameter = new ArrayList<>(); // ç¨äºè®°å½å䏿¡è®°å½çç¶æå¼ String prevRunningStatus = null; for (MachineEquipentInfo machineInfo : data) { System.out.println(machineInfo); // log.info("æ¥æ¶èªå¨åæ°æ®ï¼" + machineInfo); // è·åå½åè®°å½çrunningStatuså¼ String currentRunningStatus = null; @@ -57,23 +65,38 @@ } } // 妿å½åç¶æä¸å䏿¡ç¸åï¼åè·³è¿ if (currentRunningStatus != null && currentRunningStatus.equals(prevRunningStatus)) { continue; } // è·åå䏿¡ç¶æ if (redisUtil.hasKey(ZDHKEY + machineInfo.getMachineNo())) { String prevRunningStatus = (String) redisUtil.get(ZDHKEY + machineInfo.getMachineNo()); // æ´æ°å䏿¡è®°å½çç¶æå¼ prevRunningStatus = currentRunningStatus; // 妿å½åç¶æä¸å䏿¡ç¸åï¼ååªåå ¥åè¡¨æ°æ® if (currentRunningStatus != null && currentRunningStatus.equals(prevRunningStatus)) { String parameter = listSqlParameter(machineInfo); if (parameter != null && !parameter.equals("")) { listParameter.add(parameter); } continue; } // æ´æ°å䏿¡è®°å½çç¶æå¼ redisUtil.set(ZDHKEY + machineInfo.getMachineNo(), currentRunningStatus); } else { if (currentRunningStatus != null) { redisUtil.set(ZDHKEY + machineInfo.getMachineNo(), currentRunningStatus); } } // çæSQL String stutus = listSqls(machineInfo); if (stutus != null && !stutus.equals("")) { listStatus.add(stutus); } String parameter = listSqlParameter(machineInfo); if (parameter != null && !parameter.equals("")) { listParameter.add(parameter); } } // æ§è¡ç¶ææ°æ®SQL try { @@ -91,6 +114,7 @@ /** * æ¹éæ§è¡SQLè¯å¥ * * @param sqlList SQLè¯å¥å表 * @throws SQLException */ @@ -126,22 +150,23 @@ /** * æå ¥å°EquipmentLog * æå ¥å°è®¾å¤å表 * * @param machineInfo * @return */ public String listSqlParameter(MachineEquipentInfo machineInfo) { String listSqls = null; List<DetailedListVo> itemList = machineInfo.getItemList(); Map<String ,DetailedListVo> itemMap = new HashMap<String ,DetailedListVo>(); for (DetailedListVo item: itemList) { itemMap.put(item.getItemName(),item); Map<String, DetailedListVo> itemMap = new HashMap<String, DetailedListVo>(); for (DetailedListVo item : itemList) { itemMap.put(item.getItemName(), item); } String sql = "insert into "; sql = sql + "ZDH_" + machineInfo.getMachineNo() + " "; sql = sql + "(EquipmentID,EquipmentName,CollectTime,runningStatus,spindleSpeed,feedRatio,runDuration,spindleDuration,progName,progStatus,toolNo) values ( "; //EquipmentID if (machineInfo.getMachineNo() == null || machineInfo.getMachineNo().equals("")) { if (machineInfo.getMachineNo() == null || machineInfo.getMachineNo().equals("")) { return null; } else { sql = sql + "'" + machineInfo.getMachineNo() + "', "; @@ -151,18 +176,7 @@ //CollectTime // å设 endTime æ¯ "MM/dd/yyyy HH:mm:ss" æ ¼å¼çå符串 if (machineInfo.getEndTime() != null && !machineInfo.getEndTime().isEmpty()) { try { // 1. å°å符串解æä¸º Date 对象 SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); Date endDate = inputFormat.parse(machineInfo.getEndTime()); // 2. å° Date æ ¼å¼åä¸ºç®æ SQL æ ¼å¼ï¼å¦ "yyyy-MM-dd HH:mm:ss"ï¼ SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sql = sql + "'" + outputFormat.format(endDate) + "', "; } catch (ParseException e) { // å¤çè§£æå¤±è´¥çæ åµï¼å¦æ¥å¿è®°å½ææåºå¼å¸¸ï¼ throw new RuntimeException("Invalid end time format: " + machineInfo.getEndTime(), e); } sql = getTime(machineInfo, sql); } else { // 妿 endTime 为 null æç©ºï¼ä½¿ç¨å½åæ¶é´ sql = sql + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "', "; @@ -182,7 +196,7 @@ //feedRatio if (itemMap.containsKey("feedRatio")) { sql = sql + "'" + itemMap.get("feedRatio").getItemValue() + "', "; }else { } else { sql = sql + "NULL, "; } //runDuration @@ -217,7 +231,7 @@ } sql = sql + "); \n"; if (StringUtils.isBlank(listSqls) ) { if (StringUtils.isBlank(listSqls)) { listSqls = sql; } else { listSqls += sql; @@ -227,7 +241,8 @@ /** * æå ¥å°EquipmentLog * æå ¥å°EquipmentLog * * @param machineInfo * @return */ @@ -242,37 +257,72 @@ } sql = sql + null + ", "; if (machineInfo.getEndTime() != null) { sql = sql + "'" + DateUtils.formattedDate(machineInfo.getEndTime(),DateUtils.STR_DD_MM_YYYY,DateUtils.STR_DATE_TIME_SMALL) + "', "; sql = getTime(machineInfo, sql); } else { return null; } Map<String ,DetailedListVo> itemMap = new HashMap<String ,DetailedListVo>(); for (DetailedListVo item: itemList) { itemMap.put(item.getItemName(),item); Map<String, DetailedListVo> itemMap = new HashMap<String, DetailedListVo>(); for (DetailedListVo item : itemList) { itemMap.put(item.getItemName(), item); } if (itemMap.containsKey("runningStatus")) { int oporation = 0; switch (itemMap.get("runningStatus").getItemValue()) { case "0" : oporation =0;break; case "1" : oporation =2;break; case "2" : oporation =3;break; case "3" : oporation =2;break; case "4" : oporation =2;break; case "10" : oporation =2;break; case "13" : oporation =2;break; case "14" : oporation =2;break; case "10001" : oporation =2;break; default: break; case "0": oporation = 0; break; case "1": oporation = 2; break; case "2": oporation = 3; break; case "3": oporation = 2; break; case "4": oporation = 2; break; case "10": oporation = 2; break; case "13": oporation = 2; break; case "14": oporation = 2; break; case "10001": oporation = 2; break; default: break; } sql = sql + " " + oporation + ", "; sql = sql + " " + oporation + ", "; } else { return null; } sql = sql + null + " ); \n"; if (StringUtils.isBlank(listSqls) ) { sql = sql + null + " ); \n"; if (StringUtils.isBlank(listSqls)) { listSqls = sql; } return listSqls; } @NotNull private String getTime(MachineEquipentInfo machineInfo, String sql) { try { // 1. å°å符串解æä¸º Date 对象 SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); Date endDate = inputFormat.parse(machineInfo.getEndTime()); // 2. å° Date æ ¼å¼åä¸ºç®æ SQL æ ¼å¼ï¼å¦ "yyyy-MM-dd HH:mm:ss"ï¼ SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sql = sql + "'" + outputFormat.format(endDate) + "', "; } catch (ParseException e) { // å¤çè§£æå¤±è´¥çæ åµï¼å¦æ¥å¿è®°å½ææåºå¼å¸¸ï¼ throw new RuntimeException("Invalid end time format: " + machineInfo.getEndTime(), e); } return sql; } } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/controller/TriggerCreateController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,204 @@ package org.jeecg.modules.system.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.modules.system.vo.TriggerVo; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.FileWriter; import java.io.IOException; import java.sql.*; import java.util.ArrayList; import java.util.List; /** * @Author: Lius * @CreateTime: 2025-06-26 * @Description: */ @Api(tags = "触åå¨") @RestController @RequestMapping("/sys/trigger") @Slf4j public class TriggerCreateController { @AutoLog(value = "触åå¨-çæè§¦åå¨") @ApiOperation(value = "触åå¨-çæè§¦åå¨", notes = "触åå¨-çæè§¦åå¨") @GetMapping(value = "/list") public Result create(@RequestBody TriggerVo triggerVo) { String schemaName = "dbo"; // SQL Server é»è®¤æ¶æ String logTableName = "log_table"; // æ¥å¿è¡¨å try (Connection connection = DriverManager.getConnection(triggerVo.getJdbcUrl(), triggerVo.getUsername(), triggerVo.getPassword())) { // è·åæå®æ¶æä¸çææè¡¨ List<String> tables = getTables(connection, schemaName); // çæè§¦åå¨ SQL å¹¶ä¿åå°æä»¶ generateTriggersForTables(connection, schemaName, logTableName, tables); } catch (SQLException | IOException e) { e.printStackTrace(); } return Result.ok(); } /** * è·åæå®æ¶æä¸çææè¡¨ */ private static List<String> getTables(Connection connection, String schemaName) throws SQLException { List<String> tables = new ArrayList<>(); DatabaseMetaData metaData = connection.getMetaData(); try (ResultSet resultSet = metaData.getTables(null, schemaName, null, new String[]{"TABLE"})) { while (resultSet.next()) { String tableName = resultSet.getString("TABLE_NAME"); tables.add(tableName); } } return tables; } /** * è·å表çåæ®µå表 */ private static List<String> getTableColumns(Connection connection, String schemaName, String tableName) throws SQLException { List<String> columns = new ArrayList<>(); DatabaseMetaData metaData = connection.getMetaData(); try (ResultSet resultSet = metaData.getColumns(null, schemaName, tableName, null)) { while (resultSet.next()) { String columnName = resultSet.getString("COLUMN_NAME"); columns.add(columnName); } } return columns; } /** * è·å表ç主é®å */ private static String getPrimaryKeyColumn(Connection connection, String schemaName, String tableName) throws SQLException { DatabaseMetaData metaData = connection.getMetaData(); try (ResultSet resultSet = metaData.getPrimaryKeys(null, schemaName, tableName)) { if (resultSet.next()) { return resultSet.getString("COLUMN_NAME"); } } return "id"; // é»è®¤ä½¿ç¨idä½ä¸ºä¸»é®ï¼å¦ææ²¡ææ¾å°ä¸»é® } /** * 为ææè¡¨çæè§¦åå¨ */ private static void generateTriggersForTables(Connection connection, String schemaName, String logTableName, List<String> tables) throws SQLException, IOException { try (FileWriter writer = new FileWriter("triggers.sql")) { for (String tableName : tables) { // è·åè¡¨ç»æä¿¡æ¯ List<String> columns = getTableColumns(connection, schemaName, tableName); String primaryKey = getPrimaryKeyColumn(connection, schemaName, tableName); // çæè§¦åå¨ SQL String triggerSQL = generateTriggerSQL(schemaName, tableName, logTableName, columns, primaryKey); // å°çæç触åå¨ SQL åå ¥æä»¶ writer.write("-- 触åå¨è¡¨: " + tableName + "\n"); writer.write(triggerSQL); writer.write("\n\n"); // 妿éè¦ï¼å¯ä»¥ç´æ¥å¨æ°æ®åºä¸å建触åå¨ // createTrigger(connection, triggerSQL); } System.out.println("æåçæè§¦åå¨å¹¶ä¿åå°Triggers.sqlä¸!"); } } /** * çæ SQL Server 触åå¨ SQL */ private static String generateTriggerSQL(String schemaName, String tableName, String logTableName, List<String> columns, String primaryKey) { StringBuilder triggerSQL = new StringBuilder(); // 触åå¨å¤´é¨ triggerSQL.append("CREATE TRIGGER [") .append(tableName) .append("_trigger]\n") .append("ON [") .append(schemaName) .append("].[").append(tableName).append("]\n") .append("AFTER INSERT, UPDATE, DELETE\n") .append("AS\n") .append("BEGIN\n") .append(" SET NOCOUNT ON;\n\n"); // æå ¥æä½ triggerSQL.append(" -- æå ¥æä½\n") .append(" IF EXISTS (SELECT * FROM inserted) AND NOT EXISTS (SELECT * FROM deleted)\n") .append(" BEGIN\n") .append(" INSERT INTO [").append(logTableName).append("] (action, create_time, sql_log)\n") .append(" SELECT 'INSERT', GETDATE(), 'INSERT INTO [").append(tableName).append("] ("); // æ¼æ¥å段å for (int i = 0; i < columns.size(); i++) { triggerSQL.append("[").append(columns.get(i)).append("]"); if (i < columns.size() - 1) { triggerSQL.append(", "); } } triggerSQL.append(") VALUES (''' + "); // æ¼æ¥åæ®µå¼ for (int i = 0; i < columns.size(); i++) { triggerSQL.append("ISNULL(CAST(i.").append(columns.get(i)).append(" AS NVARCHAR(MAX)), '') + '''"); if (i < columns.size() - 1) { triggerSQL.append(", ''' + "); } } triggerSQL.append(");'\n") .append(" FROM inserted i;\n") .append(" END\n\n"); // æ´æ°æä½ triggerSQL.append(" -- æ´æ°æä½\n") .append(" IF EXISTS (SELECT * FROM inserted) AND EXISTS (SELECT * FROM deleted)\n") .append(" BEGIN\n") .append(" INSERT INTO [").append(logTableName).append("] (action, create_time, sql_log)\n") .append(" SELECT 'UPDATE', GETDATE(), 'UPDATE [").append(tableName).append("] SET "); // æ¼æ¥æ´æ°å段 for (int i = 0; i < columns.size(); i++) { triggerSQL.append("[").append(columns.get(i)).append("] = ''' + ISNULL(CAST(i.").append(columns.get(i)).append(" AS NVARCHAR(MAX)), '') + '''"); if (i < columns.size() - 1) { triggerSQL.append(", "); } } triggerSQL.append(" WHERE [").append(primaryKey).append("] = ''' + ISNULL(CAST(d.").append(primaryKey).append(" AS NVARCHAR(MAX)), '') + ''';'\n") .append(" FROM inserted i\n") .append(" INNER JOIN deleted d ON i.").append(primaryKey).append(" = d.").append(primaryKey).append(";\n") .append(" END\n\n"); // å é¤æä½ triggerSQL.append(" -- å 餿ä½\n") .append(" IF NOT EXISTS (SELECT * FROM inserted) AND EXISTS (SELECT * FROM deleted)\n") .append(" BEGIN\n") .append(" INSERT INTO [").append(logTableName).append("] (action, create_time, sql_log)\n") .append(" SELECT 'DELETE', GETDATE(), 'DELETE FROM [").append(tableName).append("] WHERE [").append(primaryKey).append("] = ''' + ISNULL(CAST(d.").append(primaryKey).append(" AS NVARCHAR(MAX)), '') + ''';'\n") .append(" FROM deleted d;\n") .append(" END\n\n"); triggerSQL.append("END;\n"); return triggerSQL.toString(); } } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/vo/TriggerVo.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,17 @@ package org.jeecg.modules.system.vo; import lombok.Data; /** * @Author: Lius * @CreateTime: 2025-06-26 * @Description: */ @Data public class TriggerVo { private String jdbcUrl; private String username; private String password; } lxzn-module-system/lxzn-system-start/src/main/resources/application-dev.yml
@@ -126,7 +126,7 @@ connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 datasource: master: url: jdbc:sqlserver://192.168.1.118:1433;databasename=LXZN_TEST_HANGYU_GK;nullCatalogMeansCurrent=true url: jdbc:sqlserver://localhost:1433;databasename=LXZN_TEST_HANGYU_GK;nullCatalogMeansCurrent=true username: sa password: 123 driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver lxzn-module-system/lxzn-system-start/src/main/resources/application-prod.yml
@@ -7,7 +7,7 @@ include-stacktrace: ALWAYS include-message: ALWAYS servlet: context-path: context-path: /jeecg-boot compression: enabled: true min-response-size: 1024 @@ -132,9 +132,9 @@ connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 datasource: master: url: jdbc:sqlserver://localhost:1433;databasename=LXZN_TEST_COMMON url: jdbc:sqlserver://DNC2\LXZN:1444;databasename=LXZN_TEST_COMMON;nullCatalogMeansCurrent=true username: sa password: 123 password: sa123 driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver #redis é ç½® redis: @@ -247,8 +247,8 @@ production: false basic: enable: true username: jeecg password: jeecg1314 username: lxzn password: lxzn1688 #ç¬¬ä¸æ¹ç»å½ justauth: enabled: true @@ -297,8 +297,34 @@ # appSecret client-secret: ?? agent-id: ?? #staticAccessPath: /api/ffile/** # å½å项ç®çéæèµæºè®¿é®é ç½®å¨nginxä¸ #æä»¶ä¸ä¼ ç®å½ï¼æ³¨æLinuxåWindowsä¸çç®å½ç»æä¸åï¼ fileHomePath: ${UPLOAD_FOLDER:d://lxzn_storage} fileNCPath: ${NC_FOLDER:D://NC} # NCæä»¶ä½ç½® ncSend: addOrDelete: false #//æ¯å¦å é¤seed ä¸çä¹åæä»¶ #staticAccessPath: /api/ffile/** # å½å项ç®çéæèµæºè®¿é®é ç½®å¨nginxä¸ #å·¥æ§ç½/æ¶å¯ç½é¨ç½²ç¸å ³é ç½®------------éè¿å çææ¸¡ deploy: #å·¥æ§ç½/æ¶å¯ç½é¨ç½² 0为æ¶å¯ç½ 1为工æ§ç½ deployType: 0 #æ¶å¯ç½ä¼ è¾å·¥æ§ç½ncæä»¶å¤¹(ææ´¾è®¾å¤ncæä»¶) å·¥æ§ç½ä¼ è¾æ¶å¯ç½ncæä»¶å¤¹(è§£æåä¼ åçncæä»¶) secretFolder: D:\\test\\a file: monitor: # ä¸ä¸ªçæ§ç®å½é ç½® paths: - D:\\hy_test\\ncFile #å·¥æ§è´è´£è§£æéé¢çæä»¶;æ¶å¯ç½è¿è¡è§£æåä¼ çæä½ - D:\\hy_test\\b - D:\\hy_test\\c interval: 10000 # çæ§é´é(ms) ferry: file: path: /data/ferry max-file-size: 10MB security: encryption-key: 1234567890abcdef #mdcæä»¶è·¯å¾é ç½® fileService: localFilePath: D:/data/sql/ #æ¬å°æä»¶è·¯å¾