lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentStatisticalInfo.java
@@ -17,7 +17,7 @@ /** * @Description: 设å¤åæ¥è¿è¡æ°æ®è¡¨ * @Author: jeecg-boot * @Author: LiuS * @Date: 2023-04-14 * @Version: V1.0 */ @@ -28,6 +28,8 @@ @ApiModel(value = "mdc_equipment_statistical_info对象", description = "设å¤åæ¥è¿è¡æ°æ®è¡¨") public class MdcEquipmentStatisticalInfo implements Serializable { private static final long serialVersionUID = -4733120585358211415L; /** * ä¸»é® */ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentStatisticalShiftInfo.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,91 @@ 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 com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; /** * @Description: 设å¤çæ¬¡åæ¥è¿è¡æ°æ®è¡¨ * @author: LiuS * @create: 2023-07-24 11:13 */ @Data @TableName("mdc_equipment_statistical_shift_info") @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @ApiModel(value = "mdc_equipment_statistical_shift_info对象", description = "设å¤çæ¬¡åæ¥è¿è¡æ°æ®è¡¨") public class MdcEquipmentStatisticalShiftInfo implements Serializable { private static final long serialVersionUID = 1519876512924700514L; /** * ä¸»é® */ @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主é®") private String id; /** * 设å¤id */ @ApiModelProperty(value = "设å¤id") private String equipmentId; /** * çå¶id */ @ApiModelProperty(value = "çå¶id") private String shiftId; /** * çæ¬¡id */ @ApiModelProperty(value = "çæ¬¡id") private String shiftSubId; /** * 弿ºæ¶é¿ */ @ApiModelProperty(value = "弿ºæ¶é¿") private BigDecimal openLong = new BigDecimal("0"); /** * å ³æºæ¶é¿ */ @ApiModelProperty(value = "å ³æºæ¶é¿") private BigDecimal closeLong = new BigDecimal("0"); /** * å¾ æºæ¶é¿ */ @ApiModelProperty(value = "å¾ æºæ¶é¿") private BigDecimal waitLong = new BigDecimal("0"); /** * å å·¥æ¶é¿ */ @ApiModelProperty(value = "å å·¥æ¶é¿") private BigDecimal processLong = new BigDecimal("0"); /** * æ¥è¦æ¶é¿ */ @ApiModelProperty(value = "æ¥è¦æ¶é¿") private BigDecimal errorLong = new BigDecimal("0"); /** * æææ¥æ */ @ApiModelProperty(value = "æææ¥æ") private String theDate; /** * å建æ¶é´ */ @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "å建æ¶é´") private Date createTime; } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/RunningAllEquipmentShiftStatisticalProcessJob.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,43 @@ package org.jeecg.modules.mdc.job; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.mdc.service.IMdcEquipmentStatisticalShiftInfoService; import org.quartz.*; import javax.annotation.Resource; /** * @Description: 宿¶ç»è®¡åæ¥çæ¬¡æ°æ®ä»»å¡ * @author: LiuS * @create: 2023-07-24 10:26 */ @PersistJobDataAfterExecution @DisallowConcurrentExecution @Slf4j public class RunningAllEquipmentShiftStatisticalProcessJob implements Job { /** * è¥åæ°åéåä¿®æ¹ QuartzJobControllerä¸ä¹é对åºä¿®æ¹ æ¶é´ï¼ yyyyMMdd ä¾ï¼ 20230414 */ private String parameter; public void setParameter(String parameter) { this.parameter = parameter; } @Resource private IMdcEquipmentStatisticalShiftInfoService mdcEquipmentStatisticalShiftInfoService; @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { log.info(String.format("宿¶ç»è®¡åæ¥çæ¬¡æ°æ®ä»»å¡ param: %s RunningAllEquipmentShiftStatisticalProcessJob start! æ¶é´:" + DateUtils.now(), this.parameter)); try { mdcEquipmentStatisticalShiftInfoService.runningAllEquipmentShiftStatisticalProcess(this.parameter); log.info("宿¶ç»è®¡åæ¥çæ¬¡æ°æ®ä»»å¡ RunningAllEquipmentShiftStatisticalProcessJob æ§è¡æå!"); } catch (Exception e) { log.error("宿¶ç»è®¡åæ¥çæ¬¡æ°æ®ä»»å¡ RunningAllEquipmentShiftStatisticalProcessJob æ§è¡å¤±è´¥!"); log.error(e.getMessage(), e); } } } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/EquipmentLogMapper.java
@@ -1,11 +1,17 @@ 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.EquipmentLog; import java.util.Date; /** * @author: LiuS * @create: 2023-04-12 14:44 */ public interface EquipmentLogMapper extends BaseMapper<EquipmentLog> { EquipmentLog getRow(@Param("equipmentid") String equipmentid, @Param("startTime") Date startTime); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcDeviceCalendarMapper.java
@@ -7,6 +7,9 @@ import org.jeecg.modules.mdc.vo.MdcDeviceCalendarQueryVo; import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo; import java.util.Date; import java.util.List; /** * @Description: 设å¤å·¥ä½æ¥å表 * @Author: jeecg-boot @@ -16,4 +19,9 @@ public interface MdcDeviceCalendarMapper extends BaseMapper<MdcDeviceCalendar> { IPage<MdcDeviceCalendarVo> pageList(IPage<MdcDeviceCalendarVo> pageData, @Param("deviceCalendar") MdcDeviceCalendarQueryVo mdcDeviceCalendarQueryVo); List<MdcDeviceCalendarVo> listByEquipmentAndDate(@Param("equipmentid") String equipmentid, @Param("stringDate") String stringDate); List<MdcDeviceCalendarVo> findAcquiesceShift(); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java
@@ -34,4 +34,9 @@ * æ¥è¯¢è®¾å¤åæ¥è¿è¡ç¶ææ¶é´æ®µè®°å½ */ List<MdcEquipmentRunningSection> listForEquipmentStatisticalInfo(@Param("equipmentId") String equipmentId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); /** * 计ç®ä¸æ®µæ¶é´å çæ°æ® */ List<MdcEquipmentRunningSection> listEquipmentRunningSection(@Param("equipmentId") String equipmentid, @Param("startLong") long start, @Param("endLong") long end); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentStatisticalShiftInfoMapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,20 @@ 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.MdcEquipmentStatisticalShiftInfo; /** * @author: LiuS * @create: 2023-07-24 11:23 */ public interface MdcEquipmentStatisticalShiftInfoMapper extends BaseMapper<MdcEquipmentStatisticalShiftInfo> { /** * è·åè®¾å¤ææ°æ¥æçè¿è¡æ°æ® * * @param equipmentid * @return */ MdcEquipmentStatisticalShiftInfo getMaxStaticsData(@Param("equipmentId") String equipmentid); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/EquipmentLogMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,8 @@ <?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.EquipmentLogMapper"> <select id="getRow" resultType="org.jeecg.modules.mdc.entity.EquipmentLog"> SELECT top 1 * FROM EquipmentLog WHERE EquipmentID = #{ equipmentid } AND CollectTime <= #{ startTime } AND Oporation in ('0','1','2','3') ORDER BY CollectTime ASC </select> </mapper> lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcDeviceCalendarMapper.xml
@@ -42,4 +42,48 @@ ORDER BY t4.equipment_name ASC, t1.EFFECTIVE_DATE ASC </select> <select id="listByEquipmentAndDate" resultType="org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo"> SELECT t1.*, t2.shift_name, t3.shift_sub_name, t3.start_date, t3.end_date, t3.sleep_start_date, t3.sleep_end_date, t3.is_day_span, t4.equipment_name, t4.equipment_id FROM mdc_device_calendar t1 LEFT JOIN mdc_shift t2 ON t1.shift_id = t2.id LEFT JOIN mdc_shift_sub t3 ON t1.shift_sub_id = t3.id LEFT JOIN mdc_equipment t4 ON t1.equment_id = t4.equipment_id <where> <if test="equipmentid != null and equipmentid != ''"> AND t4.equment_id = #{ equipmentid } </if> <if test="stringDate != null and stringDate != ''"> AND t1.effective_date = #{ stringDate } </if> </where> </select> <select id="findAcquiesceShift" resultType="org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo"> SELECT t1.shift_id shiftId, t2.shift_sub_id shiftSubId, t1.shift_name shiftName, t2.shift_sub_name shiftSubName, t2.start_date startDate, t2.end_date endDate, t2.sleep_start_date sleepStartDate, t2.sleep_end_date sleepEndDate, t2.is_day_span isDaySpan FROM mdc_shift t1 LEFT JOIN mdc_shift_sub t2 ON t1.shift_sub_id = t2.id WHERE t1.default_shift = 'true' </select> </mapper> lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml
@@ -30,5 +30,18 @@ start_time </select> <!--计ç®ä¸æ®µæ¶é´å çæ°æ®--> <select id="listEquipmentRunningSection" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection"> SELECT * FROM mdc_equipment_running_section WHERE equipment_id = #{ equipmentId } AND (start_long <= #{ endLong } AND end_long >= #{ startLong }) ORDER BY start_time </select> </mapper> lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentStatisticalShiftInfoMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,9 @@ <?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.MdcEquipmentStatisticalShiftInfoMapper"> <select id="getMaxStaticsData" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalShiftInfo"> SELECT TOP 1 * FROM mdc_equipment_statistical_shift_info WHERE equipment_id = #{equipmentId} ORDER BY the_date DESC </select> </mapper> lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IEquipmentLogService.java
@@ -21,4 +21,9 @@ * æ¥è¯¢æä¸ªè®¾å¤æä¸ªæ¶é´ç¹ä¹åçæ°æ®(æ¥è¦æ°æ®) */ List<EquipmentLog> findEquipmentLogByErrorEndTime(String equipmentId, Date endTime); /** * è·åè®¾å¤æä¸ªæ¶é´ç¹ä¹åçææ°ä¸æ¡æ°æ® */ EquipmentLog getRow(String equipmentid, Date startTime); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDeviceCalendarService.java
@@ -8,11 +8,13 @@ import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; /** * @Description: 设å¤å·¥ä½æ¥å表 * @Author: jeecg-boot * @Date: 2023-04-10 * @Date: 2023-04-10 * @Version: V1.0 */ public interface IMdcDeviceCalendarService extends IService<MdcDeviceCalendar> { @@ -27,4 +29,12 @@ */ boolean saveCalendar(EquipmentCalendarVo calendarVo); /** * æ¥è¯¢çå¶æ°æ® * * @param equipmentid * @param stringDates * @return */ List<MdcDeviceCalendarVo> listByEquipmentAndDate(String equipmentid, List<String> stringDates); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentRunningSectionService.java
@@ -12,7 +12,7 @@ /** * @Description: 设å¤è¿è¡æ¶æ®µç¶æè¡¨ * @Author: LiuS * @Date: 2023-04-13 * @Date: 2023-04-13 * @Version: V1.0 */ public interface IMdcEquipmentRunningSectionService extends IService<MdcEquipmentRunningSection> { @@ -38,8 +38,17 @@ List<MdcEquipmentRunningSection> listForEquipmentStatisticalInfo(String equipmentId, Date startDate, Date endDate); /** * æ¥è¯¢è®¾å¤åå²è¿è¡ç¶æè®°å½æ°æ® * æ¥è¯¢è®¾å¤åå²è¿è¡ç¶æè®°å½æ°æ® */ List<Map<String, Object>> logChart(MdcEquipmentRunningSectionVo equipmentRunningSectionVo); /** * 计ç®ä¸æ®µæ¶é´å çæ°æ® */ List<MdcEquipmentRunningSection> listEquipmentRunningSection(String equipmentid, long start, long end); /** * æ¥è¯¢æä¸ªè®¾å¤ä¸æ®µæ¶é´å çæ°æ® */ List<MdcEquipmentRunningSection> listRunningSectionFromLog(String equipmentid, long start, long end); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalInfoService.java
@@ -5,7 +5,7 @@ /** * @Description: 设å¤åæ¥è¿è¡æ°æ®è¡¨ * @Author: jeecg-boot * @Author: lius * @Date: 2023-04-14 * @Version: V1.0 */ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalShiftInfoService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,19 @@ package org.jeecg.modules.mdc.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalShiftInfo; /** * @Description: 设å¤åæ¥ç次è¿è¡æ°æ®è¡¨ * @author: LiuS * @create: 2023-07-24 10:32 */ public interface IMdcEquipmentStatisticalShiftInfoService extends IService<MdcEquipmentStatisticalShiftInfo> { /** * 计ç®è®¾å¤åæ¥ç次è¿è¡æ°æ® * * @param dateTime */ void runningAllEquipmentShiftStatisticalProcess(String dateTime); } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/EquipmentLogServiceImpl.java
@@ -43,4 +43,9 @@ lambdaQuery.orderByAsc(EquipmentLog::getCollectTime); return lambdaQuery.list(); } @Override public EquipmentLog getRow(String equipmentid, Date startTime) { return this.baseMapper.getRow(equipmentid, startTime); } } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java
@@ -132,6 +132,40 @@ } /** * æ¥è¯¢çå¶æ°æ® * * @param equipmentid * @param stringDates * @return */ @Override public List<MdcDeviceCalendarVo> listByEquipmentAndDate(String equipmentid, List<String> stringDates) { List<MdcDeviceCalendarVo> result = new ArrayList<>(); try { //æ¥è¯¢é»è®¤çå¶ List<MdcDeviceCalendarVo> acquiesceShift = this.baseMapper.findAcquiesceShift(); for (String stringDate : stringDates) { List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = this.baseMapper.listByEquipmentAndDate(equipmentid, stringDate); if (mdcDeviceCalendarVos != null && !mdcDeviceCalendarVos.isEmpty()) { result.addAll(mdcDeviceCalendarVos); } else { acquiesceShift.forEach(mdcDeviceCalendarVo -> { mdcDeviceCalendarVo.setEquipmentId(equipmentid); mdcDeviceCalendarVo.setEffectiveDate(stringDate); }); // 设置é»è®¤çå¶ result.addAll(acquiesceShift); } } } catch (Exception e) { e.printStackTrace(); } return result; } /** * è·å䏿®µæ¶é´èå´å ç¬¦åææå çæ¥æéå * * @param startDate å¼å§æ¶é´ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java
@@ -519,8 +519,68 @@ return result; } /** * 计ç®ä¸æ®µæ¶é´å çæ°æ® */ @Override public List<MdcEquipmentRunningSection> listEquipmentRunningSection(String equipmentid, long start, long end) { return this.baseMapper.listEquipmentRunningSection(equipmentid, start, end); } @Override public List<MdcEquipmentRunningSection> listRunningSectionFromLog(String equipmentid, long start, long end) { if (StringUtils.isBlank(equipmentid) || start <= 0 || end <= 0) { return null; } Date startTime = DateUtils.toDate(DateUtils.longToDate(start), DateUtils.STR_DATE_TIME_SMALL); Date endTime = DateUtils.toDate(DateUtils.longToDate(end), DateUtils.STR_DATE_TIME_SMALL); EquipmentLog equipmentLog = equipmentLogService.getRow(equipmentid, startTime); if (equipmentLog == null) { return null; } List<EquipmentLog> logList = new ArrayList<>(); EquipmentLog equipmentOne = new EquipmentLog(); equipmentOne.setEquipmentId(equipmentid); equipmentOne.setOporation(equipmentLog.getOporation()); equipmentOne.setCollectTime(startTime); logList.add(equipmentOne); List<EquipmentLog> logListLast = equipmentLogService.findEquipmentLogByEndTime(equipmentid, startTime); if (logListLast == null || logListLast.isEmpty()) { EquipmentLog two = new EquipmentLog(); two.setEquipmentId(equipmentid); two.setOporation(equipmentLog.getOporation()); two.setCollectTime(endTime); logList.add(two); } else { for (EquipmentLog log : logListLast) { if (log.getCollectTime().getTime() <= endTime.getTime()) { logList.add(log); } } } if (logList.get(logList.size() - 1).getCollectTime().getTime() < endTime.getTime()) { EquipmentLog two = new EquipmentLog(); two.setEquipmentId(equipmentid); two.setOporation(logList.get(logList.size() - 1).getOporation()); two.setCollectTime(endTime); logList.add(two); } //ç¹æ°æ®è½¬ä¸ºæ®µæ°æ® List<MdcEquipmentRunningSection> erts = parseLogToRunningTrace(logList); if (erts.isEmpty()) { return Collections.emptyList(); } //æ´åå å·¥åå¾ æºæ¶é´å°äºnç§çæ°æ® erts = mergeLessMinTimeRecords(erts, null); List<MdcEquipmentRunningSection> running = mergeRunningTrace(erts); if (running != null || !running.isEmpty()) { this.ergodicTrim(running); } return running; } private Map<String, List<MdcEquipmentRunningSectionDto>> logCharts(MdcEquipmentRunningSectionVo equipmentRunningSectionVo, String date) { Map<String, List<MdcEquipmentRunningSectionDto>> map = new HashMap<>(); Map<String, List<MdcEquipmentRunningSectionDto>> map = new HashMap<>(); List<MdcEquipmentRunningSectionDto> normal = new ArrayList<>(); List<MdcEquipmentRunningSectionDto> waring = new ArrayList<>(); //è¿è¡ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
@@ -22,7 +22,7 @@ /** * @Description: 设å¤åæ¥è¿è¡æ°æ®è¡¨ * @Author: jeecg-boot * @Author: lius * @Date: 2023-04-14 * @Version: V1.0 */ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalShiftInfoServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,368 @@ 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.MdcEquipmentRunningSection; import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalShiftInfo; import org.jeecg.modules.mdc.mapper.MdcEquipmentStatisticalShiftInfoMapper; import org.jeecg.modules.mdc.service.IEquipmentService; import org.jeecg.modules.mdc.service.IMdcDeviceCalendarService; import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService; import org.jeecg.modules.mdc.service.IMdcEquipmentStatisticalShiftInfoService; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo; import org.jeecg.modules.mdc.vo.MdcShiftDateVo; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; /** * @Description: 设å¤åæ¥ç次è¿è¡æ°æ®è¡¨ * @author: LiuS * @create: 2023-07-24 11:19 */ @Service public class MdcEquipmentStatisticalShiftInfoServiceImpl extends ServiceImpl<MdcEquipmentStatisticalShiftInfoMapper, MdcEquipmentStatisticalShiftInfo> implements IMdcEquipmentStatisticalShiftInfoService { @Resource private IEquipmentService equipmentService; @Resource private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService; @Resource private IMdcDeviceCalendarService mdcDeviceCalendarService; /** * 计ç®è®¾å¤åæ¥ç次è¿è¡æ°æ® * * @param dateTime */ @Override @Transactional(rollbackFor = {Exception.class}) public void runningAllEquipmentShiftStatisticalProcess(String dateTime) { if (StringUtils.isNotBlank(dateTime)) { try { Date initDate = DateUtils.toDate(dateTime, "yyyyMMdd"); if (initDate != null) { this.remove(new LambdaQueryWrapper<MdcEquipmentStatisticalShiftInfo>().eq(MdcEquipmentStatisticalShiftInfo::getTheDate, dateTime)); } } catch (Exception e) { log.error("åæ°æ ¼å¼ä¸å¯¹", e); } } List<Equipment> equipmentList = equipmentService.list(); List<MdcEquipmentStatisticalShiftInfo> result = new ArrayList<>(); for (Equipment equipment : equipmentList) { List<MdcEquipmentStatisticalShiftInfo> equipmentStatisticalShiftInfoList = equipmentShiftStatisticalProcess(equipment, dateTime); if (equipmentStatisticalShiftInfoList != null && !equipmentStatisticalShiftInfoList.isEmpty()) { result.addAll(equipmentStatisticalShiftInfoList); } } if (!result.isEmpty()) { this.saveBatch(result); } } @Transactional(readOnly = true) List<MdcEquipmentStatisticalShiftInfo> equipmentShiftStatisticalProcess(Equipment equipment, String dateTime) { Date initDate = null; //åæåçç»è®¡æ°æ® if (StringUtils.isBlank(dateTime)) { MdcEquipmentStatisticalShiftInfo nearestDate = this.baseMapper.getMaxStaticsData(equipment.getEquipmentid()); if (nearestDate != null) { initDate = DateUtils.toDate(nearestDate.getTheDate(), "yyyyMMdd"); initDate = DateUtils.plusTime(initDate, 1); } else { //忬¡åå¼ åææ©æ¶é´ MdcEquipmentRunningSection equipmentRunningSection = mdcEquipmentRunningSectionService.getFirstData(equipment.getEquipmentid()); if (equipmentRunningSection != null) { initDate = equipmentRunningSection.getStartTime(); } } } else { try { initDate = DateUtils.toDate(dateTime, "yyyyMMdd"); initDate = DateUtils.plusTime(initDate, 0); } catch (Exception e) { log.error("åæ°æ ¼å¼ä¸å¯¹", null); return null; } } if (initDate == null) { return null; } Date endDate = DateUtils.plusTime(DateUtils.getNow(), 0); if (!DateUtils.less(initDate, endDate)) { return Collections.emptyList(); } //è·å两个æ¶é´æ®µçå·® List<String> stringDates = DateUtils.getDatesStringList2(initDate, DateUtils.plusTime(endDate, -1)); if (stringDates.isEmpty()) { return Collections.emptyList(); } //æ¥è¯¢çå¶çæ¬¡ä¿¡æ¯ Map<String, List<MdcDeviceCalendarVo>> listMap = this.mdcDeviceCalendarMap(equipment.getEquipmentid(), stringDates); if (listMap.isEmpty()) { listMap = new HashMap<>(); } List<MdcEquipmentStatisticalShiftInfo> resultList = new ArrayList<>(); for (String stringDate : stringDates) { if (listMap.containsKey(stringDate)) { List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = listMap.get(stringDate); for (MdcDeviceCalendarVo mdcDeviceCalendarVo : mdcDeviceCalendarVos) { //çå¶ç次æ¶é´éå List<MdcShiftDateVo> datesListByMdcDeviceCalendarVo = this.getDatesListByMdcDeviceCalendarVo(mdcDeviceCalendarVo); if (datesListByMdcDeviceCalendarVo == null || datesListByMdcDeviceCalendarVo.isEmpty()) { break; } //åå¹¶ MdcEquipmentStatisticalShiftInfo equipmentStatisticalShiftInfo = new MdcEquipmentStatisticalShiftInfo(); equipmentStatisticalShiftInfo.setEquipmentId(equipment.getEquipmentid()); //å¤çæ¶é´ Date date = DateUtils.strToDate(stringDate, DateUtils.STRDATE); equipmentStatisticalShiftInfo.setTheDate(DateUtils.format(date, DateUtils.STRDATE)); equipmentStatisticalShiftInfo.setShiftId(mdcDeviceCalendarVo.getShiftId()); equipmentStatisticalShiftInfo.setShiftSubId(mdcDeviceCalendarVo.getShiftSubId()); equipmentStatisticalShiftInfo.setCreateTime(new Date()); for (MdcShiftDateVo dates : datesListByMdcDeviceCalendarVo) { //å¤çæ°æ® MdcEquipmentStatisticalShiftInfo shiftInfo = this.selectRunningEquipment(dates, equipment.getEquipmentid()); equipmentStatisticalShiftInfo.setWaitLong(equipmentStatisticalShiftInfo.getWaitLong().add(shiftInfo.getWaitLong())); equipmentStatisticalShiftInfo.setProcessLong(equipmentStatisticalShiftInfo.getProcessLong().add(shiftInfo.getProcessLong())); equipmentStatisticalShiftInfo.setCloseLong(equipmentStatisticalShiftInfo.getCloseLong().add(shiftInfo.getCloseLong())); equipmentStatisticalShiftInfo.setOpenLong(equipmentStatisticalShiftInfo.getOpenLong().add(shiftInfo.getOpenLong())); equipmentStatisticalShiftInfo.setErrorLong(equipmentStatisticalShiftInfo.getErrorLong().add(shiftInfo.getErrorLong())); } } } } return resultList; } /** * æ¥è¯¢æä¸å¤©æä¸ªçæ¬¡çæ°æ® * * @param dates * @param equipmentid * @return */ private MdcEquipmentStatisticalShiftInfo selectRunningEquipment(MdcShiftDateVo dates, String equipmentid) { if (dates == null || StringUtils.isBlank(equipmentid)) { return null; } //ä¸è¿æ»¤ä¼çåç»´ä¿® //è·åçæ¬¡æ¶é´æ®µå æ°æ® List<MdcEquipmentRunningSection> sectionList = mdcEquipmentRunningSectionService.listEquipmentRunningSection(equipmentid, dates.getStart(), dates.getEnd()); //æ¥è¯¢æ æ°æ®éè¦EquipmentLogè§£æ if (sectionList.isEmpty()) { sectionList = mdcEquipmentRunningSectionService.listRunningSectionFromLog(equipmentid, dates.getStart(), dates.getEnd()); } if (sectionList == null || sectionList.isEmpty()) { sectionList = new ArrayList<>(); } //å¤çæ°æ® long datesStart = dates.getStart(); long datesEnd = dates.getEnd(); for (int i = 0; i < sectionList.size(); i++) { MdcEquipmentRunningSection equipmentRunningSection = sectionList.get(i); long start = equipmentRunningSection.getStartTime().getTime(); long end = equipmentRunningSection.getEndTime().getTime(); if (datesStart <= start) { equipmentRunningSection.setStartTime(equipmentRunningSection.getStartTime()); } else { equipmentRunningSection.setStartTime(dates.getStartDate()); } if (datesEnd >= end) { equipmentRunningSection.setEndTime(equipmentRunningSection.getEndTime()); } else { equipmentRunningSection.setEndTime(dates.getEndDate()); } Long sen = DateUtils.differentSecond(equipmentRunningSection.getStartTime(), equipmentRunningSection.getEndTime()); if (sen <= 0) { sectionList.remove(i); i--; } else { equipmentRunningSection.setDuration(sen); equipmentRunningSection.setStartLong(equipmentRunningSection.getStartTime().getTime()); equipmentRunningSection.setEndLong(equipmentRunningSection.getEndTime().getTime()); } } MdcEquipmentStatisticalShiftInfo shiftInfo = new MdcEquipmentStatisticalShiftInfo(); shiftInfo.setEquipmentId(equipmentid); shiftInfo.setShiftId(dates.getShiftId()); shiftInfo.setShiftSubId(dates.getShiftSubId()); shiftInfo.setTheDate(dates.getDay()); long waitLong = 0L; long processLong = 0L; long closeLong = 0L; long errorLong = 0L; for (MdcEquipmentRunningSection equipmentRunningSection : sectionList) { Long duration = equipmentRunningSection.getDuration(); int status = equipmentRunningSection.getStatus(); if (status == 2) { waitLong += duration; } if (status == 3) { processLong += duration; } if (status == 0) { closeLong += duration; } if (status == 22) { errorLong += duration; } } shiftInfo.setWaitLong(new BigDecimal(waitLong)); shiftInfo.setProcessLong(new BigDecimal(processLong)); shiftInfo.setCloseLong(new BigDecimal(closeLong)); //弿ºæ¶é´è®¡ç®ä¸º æææ¶é¿ - å ³æºæ¶é¿ shiftInfo.setOpenLong(new BigDecimal((datesEnd - datesStart) / 1000).subtract(shiftInfo.getCloseLong())); shiftInfo.setErrorLong(new BigDecimal(errorLong)); return shiftInfo; } /** * æ¶é´é®é¢å¤ç 妿å½å¤©ææ«å°¾æ¶é´å¤§äºå½åæ¶é´ è¿å0 * * @param temp * @return */ private List<MdcShiftDateVo> getDatesListByMdcDeviceCalendarVo(MdcDeviceCalendarVo temp) { List<MdcShiftDateVo> result = new ArrayList<>(); String startDateStr = temp.getStartDate(); String endDateStr = temp.getEndDate(); String sleepStartDateStr = temp.getSleepStartDate(); String sleepEndDateStr = temp.getSleepEndDate(); String effectiveDateStr = temp.getEffectiveDate(); String eff = DateUtils.format(DateUtils.toDate(effectiveDateStr, DateUtils.STRDATE), DateUtils.STR_DATE); try { Date effectiveDate = new SimpleDateFormat("yyyyMMdd").parse(effectiveDateStr); long startDate = getLongDate(effectiveDate, startDateStr, "false"); long endDate = getLongDate(effectiveDate, endDateStr, temp.getIsDaySpan()); //å¤çæåçæ¶é´é®é¢ æ¯å¦è¶ è¿å½åæ¶é´ å¦æè¶ è¿ä¸åå ¥è®¡ç® BUG Date endTime = null; if ("true".equals(temp.getIsDaySpan())) { Date day = DateUtils.toDate(effectiveDateStr, DateUtils.STRDATE); day = DateUtils.plusTime(day, 1); String dayTime = DateUtils.format(day, DateUtils.STR_DATE); endTime = DateUtils.toDate(dayTime + " " + temp.getEndDate(), DateUtils.STR_DATE_TIME_SMALL); } else { Date day = DateUtils.toDate(effectiveDateStr, DateUtils.STRDATE); String dayTime = DateUtils.format(day, DateUtils.STR_DATE); endTime = DateUtils.toDate(dayTime + " " + temp.getEndDate(), DateUtils.STR_DATE_TIME_SMALL); } if (endTime.getTime() > DateUtils.getNow().getTime()) { return null; } if (StringUtils.isNotEmpty(sleepStartDateStr)) { long sleepStartDate = getLongDate(effectiveDate, sleepStartDateStr, "false"); long sleepEndDate = getLongDate(effectiveDate, sleepEndDateStr, "false"); Date start1 = DateUtils.getFormatDate(eff + " " + startDateStr, DateUtils.STR_DATE_TIME_SMALL); Date end1 = DateUtils.getFormatDate(eff + " " + sleepStartDateStr, DateUtils.STR_DATE_TIME_SMALL); Date start2 = DateUtils.getFormatDate(eff + " " + sleepEndDateStr, DateUtils.STR_DATE_TIME_SMALL); Date end2 = DateUtils.getFormatDate(eff + " " + endDateStr, DateUtils.STR_DATE_TIME_SMALL); if ("true".equals(temp.getIsDaySpan())) { //跨天 å¤æçæ¬¡å¼å§æ¶é´åç»ææ¶é´æ¯å¦è·¨å¤© if (startDateStr.compareTo(endDateStr) < 0) { //çæ¬¡å¼å§æ¶é´åç»ææ¶é´é½è·¨å¤© startDate = getLongDate(effectiveDate, startDateStr, temp.getIsDaySpan()); start1 = DateUtils.addDays(start1, 1); end2 = DateUtils.addDays(end2, 1); //çæ¬¡å¼å§æ¶é´åç»ææ¶é´é½è·¨å¤© 伿¯å¼å§æ¶é´åç»ææ¶é´ä¹ä¸å®è·¨å¤© sleepStartDate = getLongDate(effectiveDate, sleepStartDateStr, temp.getIsDaySpan()); end1 = DateUtils.addDays(end1, 1); sleepEndDate = getLongDate(effectiveDate, sleepEndDateStr, temp.getIsDaySpan()); start2 = DateUtils.addDays(start2, 1); } else { //çæ¬¡å¼å§æ¶é´ä¸è·¨å¤©ï¼ ç»ææ¶é´è·¨å¤© end2 = DateUtils.addDays(end2, 1); //夿伿¯å¼å§æ¶é´æ¯å¦è·¨å¤© if (startDateStr.compareTo(sleepStartDateStr) > 0) { //å¼å§ä¼æ¯æ¶é´è·¨å¤©ï¼ ç»æä¼æ¯æ¶é´ä¹ä¸å®è·¨å¤© sleepStartDate = getLongDate(effectiveDate, sleepStartDateStr, temp.getIsDaySpan()); end1 = DateUtils.addDays(end1, 1); sleepEndDate = getLongDate(effectiveDate, sleepEndDateStr, temp.getIsDaySpan()); start2 = DateUtils.addDays(start2, 1); } else { //伿¯å¼å§æ¶é´ä¸è·¨å¤©, 夿伿¯ç»ææ¶é´æ¯å¦è·¨å¤© if (sleepStartDateStr.compareTo(sleepEndDateStr) > 0) { //伿¯ç»ææ¶é´è·¨å¤© sleepEndDate = getLongDate(effectiveDate, sleepEndDateStr, temp.getIsDaySpan()); start2 = DateUtils.addDays(start2, 1); } } } } MdcShiftDateVo dates1 = new MdcShiftDateVo(temp.getShiftId(), temp.getShiftSubId(), startDate, sleepStartDate, effectiveDateStr, endTime, start1, end1); result.add(dates1); MdcShiftDateVo dates2 = new MdcShiftDateVo(temp.getShiftId(), temp.getShiftSubId(), sleepEndDate, endDate, effectiveDateStr, endTime, start2, end2); result.add(dates2); } else { /*è·åçæ¬¡çå¼å§æ¶é´ç»ææ¶é´*/ Date start = DateUtils.getFormatDate(eff + " " + startDateStr, DateUtils.STR_DATE_TIME_SMALL); Date end = DateUtils.getFormatDate(eff + " " + endDateStr, DateUtils.STR_DATE_TIME_SMALL); if ("true".equals(temp.getIsDaySpan())) { if (startDateStr.compareTo(endDateStr) < 0) { startDate = getLongDate(effectiveDate, startDateStr, temp.getIsDaySpan()); start = DateUtils.addDays(start, 1); } end = DateUtils.addDays(end, 1); } MdcShiftDateVo dates = new MdcShiftDateVo(temp.getShiftId(), temp.getShiftSubId(), startDate, endDate, effectiveDateStr, endTime, start, end); result.add(dates); } } catch (ParseException e) { e.printStackTrace(); } return result; } /** * 设å¤çæ¬¡è½¬æ¢ * * @param equipmentid * @param stringDates * @return */ private Map<String, List<MdcDeviceCalendarVo>> mdcDeviceCalendarMap(String equipmentid, List<String> stringDates) { List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = mdcDeviceCalendarService.listByEquipmentAndDate(equipmentid, stringDates); if (mdcDeviceCalendarVos.isEmpty()) { return null; } Map<String, List<MdcDeviceCalendarVo>> map = new HashMap<>(); for (MdcDeviceCalendarVo mdcDeviceCalendarVo : mdcDeviceCalendarVos) { List<MdcDeviceCalendarVo> mdcDeviceCalendarVos1; if (map.containsKey(mdcDeviceCalendarVo.getEffectiveDate())) { mdcDeviceCalendarVos1 = map.get(mdcDeviceCalendarVo.getEffectiveDate()); } else { mdcDeviceCalendarVos1 = new ArrayList<>(); } mdcDeviceCalendarVos1.add(mdcDeviceCalendarVo); map.put(mdcDeviceCalendarVo.getEffectiveDate(), mdcDeviceCalendarVos1); } return map; } private long getLongDate(Date effectiveDate, String startDateStr, String isDaySpan) { String[] startDateArray = startDateStr.split(":"); Calendar cal = Calendar.getInstance(); cal.setTime(effectiveDate); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(startDateArray[0])); cal.set(Calendar.MINUTE, Integer.parseInt(startDateArray[1])); cal.set(Calendar.SECOND, Integer.parseInt(startDateArray[2])); if ("true".equals(isDaySpan)) { cal.add(Calendar.DAY_OF_YEAR, 1); } return cal.getTime().getTime(); } } lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcShiftDateVo.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,106 @@ package org.jeecg.modules.mdc.vo; import java.util.Date; /** * @author: LiuS * @create: 2023-07-25 10:32 */ public class MdcShiftDateVo { private String shiftId; private String shiftSubId; private long start; private long end; private String day; private Date endTime; /** * å¼å§æ¶é´ */ private Date startDate; /** * ç»ææ¶é´ */ private Date endDate; public String getShiftId() { return shiftId; } public void setShiftId(String shiftId) { this.shiftId = shiftId; } public String getShiftSubId() { return shiftSubId; } public void setShiftSubId(String shiftSubId) { this.shiftSubId = shiftSubId; } public long getStart() { return start; } public void setStart(long start) { this.start = start; } public long getEnd() { return end; } public void setEnd(long end) { this.end = end; } public String getDay() { return day; } public void setDay(String day) { this.day = day; } public Date getEndTime() { return endTime; } public void setEndTime(Date endTime) { this.endTime = endTime; } public Date getStartDate() { return startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; } public Date getEndDate() { return endDate; } public void setEndDate(Date endDate) { this.endDate = endDate; } public MdcShiftDateVo(String shiftId, String shiftSubId, long start, long end, String day, Date endTime, Date startDate, Date endDate) { this.shiftId = shiftId; this.shiftSubId = shiftSubId; this.start = start; this.end = end; this.day = day; this.endTime = endTime; this.startDate = startDate; this.endDate = endDate; } }