From 40c22341b74d5bec60cbec08e338d8c8b22fcc92 Mon Sep 17 00:00:00 2001
From: lius <Lius2225@163.com>
Date: 星期四, 27 七月 2023 17:28:23 +0800
Subject: [PATCH] 班次利用率

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalShiftInfoServiceImpl.java |  478 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 413 insertions(+), 65 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalShiftInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalShiftInfoServiceImpl.java
index 9b9c7dc..cc27400 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalShiftInfoServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalShiftInfoServiceImpl.java
@@ -4,14 +4,13 @@
 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.MdcEquipmentRepair;
 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.service.*;
 import org.jeecg.modules.mdc.util.DateUtils;
+import org.jeecg.modules.mdc.vo.MdcDateVo;
 import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo;
 import org.jeecg.modules.mdc.vo.MdcShiftDateVo;
 import org.springframework.stereotype.Service;
@@ -22,6 +21,7 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 璁惧鍗曟棩鐝杩愯鏁版嵁琛�
@@ -39,6 +39,9 @@
 
     @Resource
     private IMdcDeviceCalendarService mdcDeviceCalendarService;
+
+    @Resource
+    private IMdcEquipmentRepairService mdcEquipmentRepairService;
 
     /**
      * 璁$畻璁惧鍗曟棩鐝杩愯鏁版嵁
@@ -141,6 +144,7 @@
                         equipmentStatisticalShiftInfo.setOpenLong(equipmentStatisticalShiftInfo.getOpenLong().add(shiftInfo.getOpenLong()));
                         equipmentStatisticalShiftInfo.setErrorLong(equipmentStatisticalShiftInfo.getErrorLong().add(shiftInfo.getErrorLong()));
                     }
+                    resultList.add(equipmentStatisticalShiftInfo);
                 }
             }
         }
@@ -158,79 +162,423 @@
         if (dates == null || StringUtils.isBlank(equipmentid)) {
             return null;
         }
-        //涓嶈繃婊や紤鐝拰缁翠慨
-        //鑾峰彇鐝鏃堕棿娈靛唴鏁版嵁
-        List<MdcEquipmentRunningSection> sectionList = mdcEquipmentRunningSectionService.listEquipmentRunningSection(equipmentid, dates.getStart(), dates.getEnd());
-        //鏌ヨ鏃犳暟鎹渶瑕丒quipmentLog瑙f瀽
-        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());
+        //鏌ヨ鏄惁闇�瑕佺淮淇殑璁惧
+        List<MdcEquipmentRepair> repairs = mdcEquipmentRepairService.mdcRepairListDate(equipmentid, dates.getStartDate(), dates.getEndDate());
+        //鍒跺害鏃堕棿娈靛唴鐨勪紤鐝拰缁翠慨鏃堕棿娈电瓫閫�
+        List<MdcEquipmentRepair> repairList = this.findSubRepairs(repairs, dates);
+        List<MdcDateVo> dateList = new ArrayList<>();
+        if (repairList == null || repairList.isEmpty()) {
+            //鍒跺害鏃堕棿娈靛唴娌℃湁缁翠慨鍜屼紤鐝椂闂存
+            MdcEquipmentStatisticalShiftInfo shiftInfo = mdcRateEquipment(equipmentid, dates.getStartDate(), dates.getEndDate());
+            return shiftInfo;
+        } else {
+            if (repairList.size() == 1 ) {
+                long start = repairList.get(0).getStartTime().getTime();
+                long end = repairList.get(0).getEndTime().getTime();
+                if ( start > dates.getStart() && end < dates.getEnd() ) {
+                    MdcDateVo d1 = new MdcDateVo();
+                    d1.setStartTime(dates.getStartDate());
+                    d1.setEndTime(repairList.get(0).getStartTime());
+                    dateList.add(d1);
+                    MdcDateVo d2 = new MdcDateVo();
+                    d2.setStartTime(repairList.get(0).getEndTime());
+                    d2.setEndTime(dates.getEndDate());
+                    dateList.add(d2);
+                } else  if (start == dates.getStart() && end < dates.getEnd()){
+                    MdcDateVo d2 = new MdcDateVo();
+                    d2.setStartTime(repairList.get(0).getEndTime());
+                    d2.setEndTime(dates.getEndDate());
+                    dateList.add(d2);
+                } else if (start > dates.getStart() && end == dates.getEnd()) {
+                    MdcDateVo d1 = new MdcDateVo();
+                    d1.setStartTime(dates.getStartDate());
+                    d1.setEndTime(repairList.get(0).getStartTime());
+                    dateList.add(d1);
+                } else {
+                    //浼戠彮
+                    MdcEquipmentStatisticalShiftInfo vo = new MdcEquipmentStatisticalShiftInfo();
+                    vo.setTotalLong(BigDecimal.ZERO);
+                    vo.setErrorLong(BigDecimal.ZERO);
+                    vo.setProcessLong(BigDecimal.ZERO);
+                    vo.setWaitLong(BigDecimal.ZERO);
+                    vo.setCloseLong(BigDecimal.ZERO);
+                    vo.setOpenLong(BigDecimal.ZERO);
+                    return vo;
+                }
             } 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());
+                long s = dates.getStartDate().getTime();
+                for (int i = 0 ; i < repairList.size(); i ++) {
+                    long start = repairList.get(i).getStartTime().getTime();
+                    long end = repairList.get(i).getEndTime().getTime();
+
+                    if (start > s ) {
+                        MdcDateVo d = new MdcDateVo();
+                        d.setStartTime(dates.getStartDate());
+                        d.setEndTime(repairList.get(i).getStartTime());
+                        if (d.getEndTime().getTime() != d.getStartTime().getTime()) {
+                            dateList.add(d);
+                        }
+                        dates.setStartDate(repairList.get(i).getEndTime());
+                    } else if (start == s) {
+                        dates.setStartDate(repairList.get(i).getEndTime());
+                    }
+                    if(i == repairList.size() -1 ) {
+                        if(dates.getStartDate().getTime() >= end) {
+                            MdcDateVo d = new MdcDateVo();
+                            d.setStartTime(repairList.get(i).getEndTime());
+                            d.setEndTime(dates.getEndDate());
+                            if (d.getEndTime().getTime() != d.getStartTime().getTime()) {
+                                dateList.add(d);
+                            }
+                        }
+                    }
+                }
             }
         }
         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;
+        for (MdcDateVo date : dateList) {
+            MdcEquipmentStatisticalShiftInfo v = mdcRateEquipment(equipmentid, date.getStartTime(), date.getEndTime());
+            shiftInfo.setTotalLong(v.getTotalLong().add(shiftInfo.getTotalLong()));
+            shiftInfo.setOpenLong(v.getOpenLong().add(shiftInfo.getOpenLong()));
+            shiftInfo.setCloseLong(v.getCloseLong().add(shiftInfo.getCloseLong()));
+            shiftInfo.setWaitLong(v.getWaitLong().add(shiftInfo.getWaitLong()));
+            shiftInfo.setProcessLong(v.getProcessLong().add(shiftInfo.getProcessLong()));
+            shiftInfo.setErrorLong(v.getErrorLong().add(shiftInfo.getErrorLong()));
+        }
+        return shiftInfo;
+    }
+
+    private MdcEquipmentStatisticalShiftInfo mdcRateEquipment(String equipmentid, Date startDate, Date endDate) {
+        MdcDateVo date = new MdcDateVo();
+        date.setStartTime(startDate);
+        date.setEndTime(endDate);
+        List<MdcEquipmentRunningSection> runningSections = new ArrayList<>();
+        runningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(equipmentid, startDate.getTime(), endDate.getTime());
+        //鏌ヨ濡傛灉鏃犳暟鎹渶瑕� EquipmentLog 瑙f瀽
+        if (runningSections == null || runningSections.isEmpty()) {
+            runningSections = mdcEquipmentRunningSectionService.listRunningSectionFromLog(equipmentid, startDate.getTime(), endDate.getTime());
+        }
+        if(runningSections == null || runningSections.isEmpty()) {
+            runningSections = new ArrayList<>();
+        }
+        List<MdcEquipmentRunningSection> sectionErrors = mdcEquipmentRunningSectionService.listEquipmentRunningSectionError(equipmentid, startDate.getTime(), endDate.getTime());
+
+        // 鎺掗櫎鍩虹閰嶇疆鎶ヨ鍙凤紙鍩虹閰嶇疆鎶ヨ鍙风殑涓嶇畻鎶ヨ锛�
+        //sectionErrors = filterSectionErrors(equipmentId, sectionErrors);
+        MdcEquipmentStatisticalShiftInfo shiftInfo = new MdcEquipmentStatisticalShiftInfo();
+        BigDecimal totalLongRairs = new BigDecimal("0");
+        List<MdcEquipmentRunningSection> sectionList = findStatsEquipment(null, runningSections, date, sectionErrors);
+        if (sectionList == null || sectionList.isEmpty()) {
+            shiftInfo.setEquipmentId(equipmentid);
+            return shiftInfo;
+        }
+        List<MdcEquipmentRunningSection> runs = new ArrayList<>();
+        List<MdcEquipmentRunningSection> errs = new ArrayList<>();
+        for (MdcEquipmentRunningSection section : sectionList) {
+            if (section.getStatus() == 22 || section.getStatus() == 0) {
+                errs.add(section);
             }
-            if (status == 3) {
-                processLong += duration;
-            }
-            if (status == 0) {
-                closeLong += duration;
-            }
-            if (status == 22) {
-                errorLong += duration;
+            if (section.getStatus() == 3) {
+                runs.add(section);
             }
         }
-        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));
+        // 鍙婃�诲伐鏃� => 鏈夋晥鏃堕暱鍑�
+        BigDecimal totalLong = new BigDecimal(DateUtils.getSeconds(startDate, endDate)).subtract(totalLongRairs);
+        // 璁$畻鍔犲伐
+        BigDecimal processLong = new BigDecimal("0");
+        if (runs != null && !runs.isEmpty()) {
+            processLong = processLongInfo(runs);
+        }
+        // 鍏虫満鏁版嵁
+        List<MdcEquipmentRunningSection> closes = errs.stream().filter(section -> section.getStatus() != 22).collect(Collectors.toList());
 
+        // 鍏虫満鏃堕暱
+        BigDecimal closeLong = new BigDecimal("0");
+        closeLong = closeLong(closes);
+
+        /*鏁呴殰鏃堕棿  errs => 鍏虫満鏁版嵁 + 鎶ヨ鏁版嵁 */
+        BigDecimal faultLong = new BigDecimal("0");
+        faultLong =  faultLongInfo(errs);
+
+        //鎶ヨ鏁版嵁
+        List<MdcEquipmentRunningSection> alarms = errs.stream().filter(section -> section.getStatus() == 22).collect(Collectors.toList());
+
+        //鎶ヨ鏃堕暱
+        BigDecimal alarmLong = new BigDecimal("0");
+        alarmLong = alarmLong(alarms);
+
+        //寰呮満鏃堕暱 => 鏈夋晥鏃堕暱 - 杩愯鏃堕暱 - 鎶ヨ鏃堕暱
+        BigDecimal waitLong = totalLong.subtract(processLong).subtract(alarmLong);
+        if (waitLong.compareTo(BigDecimal.ZERO) < 0) {
+            waitLong = new BigDecimal("0");
+        }
+
+        // 寮�鏈烘椂闀� => 鏈夋晥鏃堕暱 - 鍏虫満鏃堕暱
+        BigDecimal openLong = totalLong.subtract(closeLong);
+        if (openLong.compareTo(BigDecimal.ZERO) < 0) {
+            openLong = new BigDecimal("0");
+        }
+
+        shiftInfo.setProcessLong(processLong);
+        shiftInfo.setTotalLong(totalLong);
+        shiftInfo.setWaitLong(waitLong);
+        shiftInfo.setErrorLong(alarmLong);
+        shiftInfo.setCloseLong(closeLong);
+        shiftInfo.setOpenLong(openLong);
         return shiftInfo;
     }
 
     /**
+     * 缁熻鍏虫満鏃堕暱
+     */
+    private BigDecimal closeLong(List<MdcEquipmentRunningSection> closes) {
+        BigDecimal closeLong = new BigDecimal("0");
+        for (MdcEquipmentRunningSection alarm : closes) {
+            closeLong = closeLong.add(new BigDecimal(alarm.getDuration()));
+        }
+        return closeLong;
+    }
+
+    /**
+     * 缁熻鎶ヨ鏃堕暱
+     */
+    private BigDecimal alarmLong(List<MdcEquipmentRunningSection> alarms) {
+        BigDecimal alarmLong = new BigDecimal("0");
+        for (MdcEquipmentRunningSection alarm : alarms) {
+            alarmLong = alarmLong.add(new BigDecimal(alarm.getDuration()));
+        }
+        return alarmLong;
+    }
+
+    /**
+     * 缁熻鏁呴殰鏃堕暱
+     */
+    private BigDecimal faultLongInfo(List<MdcEquipmentRunningSection> errs) {
+        BigDecimal faultLong = new BigDecimal("0");
+        for (MdcEquipmentRunningSection e : errs) {
+            faultLong = faultLong.add(new BigDecimal(e.getDuration()));
+        }
+        return faultLong;
+    }
+
+    /**
+     * 缁熻鍔犲伐鏃堕暱
+     */
+    private BigDecimal processLongInfo(List<MdcEquipmentRunningSection> runs) {
+        BigDecimal processLong = new BigDecimal("0");
+        for (MdcEquipmentRunningSection se : runs) {
+            if (se.getStatus() == 3) {
+                processLong = processLong.add(new BigDecimal(se.getDuration()));
+            }
+        }
+        return processLong;
+    }
+
+    private List<MdcEquipmentRunningSection> findStatsEquipment(List<MdcEquipmentRepair> repairs, List<MdcEquipmentRunningSection> sRun, MdcDateVo mdcDate, List<MdcEquipmentRunningSection> errors) {
+        if (sRun == null || sRun.isEmpty()) {
+            //鏃犳暟鎹鐞�
+            //TODO
+            return null;
+        }
+        Long  startMdc =  mdcDate.getStartTime().getTime();
+        Long  endMdc =  mdcDate.getEndTime().getTime();
+        if (sRun != null && !sRun.isEmpty()) {
+            for (int i = 0 ; i < sRun.size() ; i ++) {
+                Long start = sRun.get(i).getStartTime().getTime();
+                Long end =  sRun.get(i).getEndTime().getTime();
+                if (startMdc <= start ) {
+                    sRun.get(i).setStartTime( sRun.get(i).getStartTime());
+                } else {
+                    sRun.get(i).setStartTime(mdcDate.getStartTime());
+                }
+                if (endMdc >= end) {
+                    sRun.get(i).setEndTime( sRun.get(i).getEndTime());
+                } else {
+                    sRun.get(i).setEndTime(mdcDate.getEndTime());
+                }
+                Long sen = DateUtils.differentSecond( sRun.get(i).getStartTime(),
+                        sRun.get(i).getEndTime());
+                if (sen <= 0) {
+                    sRun.remove(i);
+                    i--;
+                } else {
+                    sRun.get(i).setDuration(sen);
+                    sRun.get(i).setStartLong( sRun.get(i).getStartTime().getTime());
+                    sRun.get(i).setEndLong( sRun.get(i).getEndTime().getTime());
+                }
+            }
+        }
+        //閮ㄥ垎鏁版嵁鏄淮淇�  1銆佽繍琛岀姸鎬佷笅鎶ヨ鎯呭喌
+        List<MdcEquipmentRunningSection> faultRun = new ArrayList<>();
+        //鍒跺害鏃堕棿娈靛唴鎶ヨ鏁版嵁
+        if (errors != null && !errors.isEmpty() ) {
+            for (int i = 0 ; i < errors.size() ; i ++) {
+                Long start = errors.get(i).getStartTime().getTime();
+                Long end =  errors.get(i).getEndTime().getTime();
+                if (startMdc <= start ) {
+                    errors.get(i).setStartTime( errors.get(i).getStartTime());
+                } else {
+                    errors.get(i).setStartTime(mdcDate.getStartTime());
+                }
+                if (endMdc >= end) {
+                    errors.get(i).setEndTime( errors.get(i).getEndTime());
+                } else {
+                    errors.get(i).setEndTime(mdcDate.getEndTime());
+                }
+                Long sen = DateUtils.differentSecond( errors.get(i).getStartTime(),
+                        errors.get(i).getEndTime());
+                if (sen <= 0) {
+                    errors.remove(i);
+                    i--;
+                } else {
+                    errors.get(i).setDuration(sen);
+                    errors.get(i).setStartLong( errors.get(i).getStartTime().getTime());
+                    errors.get(i).setEndLong( errors.get(i).getEndTime().getTime());
+                }
+            }
+
+            //鎶婅繍琛屼腑瀛樺湪鐨勬姤璀﹀墧闄ゆ帀
+            for (MdcEquipmentRunningSection se : sRun) {
+                long runStart = se.getStartTime().getTime();
+                long runEnd =  se.getEndTime().getTime();
+                if (se.getStatus() == 3) {
+                    if (errors != null && !errors.isEmpty() ) {
+                        //澶勭悊鎶ヨ鏁版嵁
+                        for (int i = 0 ; i < errors.size(); i ++ ) {
+                            long errStart = errors.get(i).getStartTime().getTime();
+                            long errEnd = errors.get(i).getEndTime().getTime();
+                            // 鎶ヨ寮�濮� 灏忎簬 杩愯寮�濮�  鎶ヨ缁撴潫 灏忎簬杩愯缁撴潫 鎶ヨ缁撴潫 澶т簬 杩愯寮�濮�
+                            if ( errStart  < runStart && errEnd <= runEnd && errEnd >  runStart ) {
+                                errors.get(i).setEndTime(se.getStartTime());
+                                Long sen = DateUtils.differentSecond(errors.get(i).getStartTime(),
+                                        errors.get(i).getEndTime());
+                                errors.get(i).setDuration(sen);
+                                errors.get(i).setStartLong(errors.get(i).getStartTime().getTime());
+                                errors.get(i).setEndLong(errors.get(i).getEndTime().getTime());
+                            }
+                            // 鎶ヨ寮�濮� 澶т簬 杩愯寮�濮� 锛� 鎶ヨ寮�濮� 灏忎簬 杩愯缁撴潫 锛屾姤璀︾粨鏉� 澶т簬 杩愯缁撴潫
+                            else if (errStart >=  runStart && errStart < runEnd &&  errEnd > runEnd ) {
+                                errors.get(i).setStartTime(se.getEndTime());
+                                Long sen = DateUtils.differentSecond(errors.get(i).getStartTime(),
+                                        errors.get(i).getEndTime());
+                                errors.get(i).setDuration(sen);
+                                errors.get(i).setStartLong(errors.get(i).getStartTime().getTime());
+                                errors.get(i).setEndLong(errors.get(i).getEndTime().getTime());
+                            }
+                            // 鎶ヨ寮�濮� 澶т簬 杩愯寮�濮� 锛� 鎶ヨ寮�濮� 灏忎簬 杩愯缁撴潫 锛屾姤璀︾粨鏉� 澶т簬 杩愯寮�濮嬶紝鎶ヨ缁撴潫 灏忎簬  杩愯缁撴潫
+                            else if (errStart >= runStart && errStart < runEnd &&
+                                    errEnd > runStart && errEnd <= runEnd ){
+                                errors.remove(i);
+                                i--;
+                            }
+                            //濡傛灉瓒呭嚭鑼冨洿
+                            else if (errStart <= runStart && errStart < runEnd &&
+                                    errEnd > runStart && errEnd >= runEnd ) {
+                                MdcEquipmentRunningSection errOne = new MdcEquipmentRunningSection();
+                                errOne.setEndTime(errors.get(i).getEndTime());
+
+                                errors.get(i).setStartTime(errors.get(i).getStartTime());
+                                errors.get(i).setEndTime(se.getStartTime());
+                                Long sen = DateUtils.differentSecond(errors.get(i).getStartTime(),
+                                        errors.get(i).getEndTime());
+                                //
+
+                                //TODO
+                                errOne.setStatus(22);
+                                errOne.setEquipmentId(errors.get(i).getEquipmentId());
+                                errOne.setStartTime(se.getEndTime());
+                                errors.get(i).setDuration(sen);
+                                errors.get(i).setStartLong(errors.get(i).getStartTime().getTime());
+                                errors.get(i).setEndLong(errors.get(i).getEndTime().getTime());
+
+                                Long one = DateUtils.differentSecond(errOne.getStartTime(), errOne.getEndTime());
+                                errOne.setDuration(one);
+                                errOne.setStartLong(errOne.getStartTime().getTime());
+                                errOne.setEndLong(errOne.getEndTime().getTime());
+                                if (sen <= 0) {
+                                    errors.remove(i);
+                                    errors.add(i,errOne);
+                                } else {
+                                    errors.add(i+1,errOne);
+                                    i++;
+                                }
+                            } else {
+                                continue;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        //澶勭悊鎶ヨ鏁版嵁
+        List<MdcEquipmentRunningSection> sectionList = new ArrayList<>();
+        if (sRun != null && !sRun.isEmpty()) {
+            for (MdcEquipmentRunningSection se : sRun) {
+                sectionList.add(se);
+            }
+        }
+        //鎶ヨ鍓旈櫎杩愯鎶ヨ
+        if (errors != null && !errors.isEmpty()) {
+            sectionList.addAll(errors);
+        }
+        //鍏虫満澶勭悊涓烘晠闅滄姤璀�
+        if (faultRun != null && !faultRun.isEmpty()) {
+            sectionList.addAll(faultRun);
+        }
+        return sectionList;
+    }
+
+    private List<MdcEquipmentRepair> findSubRepairs(List<MdcEquipmentRepair> repairs, MdcShiftDateVo dates) {
+        if (repairs == null || repairs.isEmpty() || dates == null) {
+            return null;
+        }
+        for (MdcEquipmentRepair repair : repairs) {
+            //璋冩暣
+            Date start = null;
+            Date end = null;
+            long dStart = dates.getStartDate().getTime();
+            long dEnd = dates.getEndDate().getTime();
+            long rStart = repair.getStartTime().getTime();
+            long rEnd = repair.getEndTime().getTime();
+
+            if (rStart <= dStart && rEnd >= dStart && rEnd <= dEnd) {
+                start = dates.getStartDate();
+                end = repair.getEndTime();
+            } else if (rStart >= dStart && rEnd <= dEnd) {
+                start = repair.getStartTime();
+                end = repair.getEndTime();
+            } else if (rStart >= dStart && rStart <= dEnd && rEnd >= dEnd) {
+                start = repair.getStartTime();
+                end = dates.getEndDate();
+            } else if (rStart <= dStart && rEnd >= dEnd) {
+                start = dates.getStartDate();
+                end = dates.getEndDate();
+            }
+            repair.setStartTime(start);
+            repair.setEndTime(end);
+            //澶勭悊寮傚父鏁版嵁
+            if (start == null || end == null) {
+                repair.setSecondLong(0);
+            } else {
+                try {
+                    repair.setSecondLong(DateUtils.getSeconds(start, end));
+                } catch (Exception e) {
+                    repair.setSecondLong(0);
+                }
+
+            }
+
+        }
+        for (int i = 0; i < repairs.size(); i++) {
+            if (repairs.get(i).getStartTime() == null || repairs.get(i).getEndTime() == null || repairs.get(i).getSecondLong() == 0) {
+                repairs.remove(i);
+                i--;
+            }
+        }
+        return repairs;
+    }
+
+    /**
      * 鏃堕棿闂澶勭悊 濡傛灉褰撳ぉ鏈�鏈熬鏃堕棿澶т簬褰撳墠鏃堕棿 杩斿洖0
      *
      * @param temp

--
Gitblit v1.9.3