¶Ô±ÈÐÂÎļþ |
| | |
| | | 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.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.*; |
| | | 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; |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @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; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentRepairService mdcEquipmentRepairService; |
| | | |
| | | /** |
| | | * 计ç®è®¾å¤åæ¥ç次è¿è¡æ°æ® |
| | | * |
| | | * @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())); |
| | | equipmentStatisticalShiftInfo.setTotalLong(equipmentStatisticalShiftInfo.getTotalLong().add(shiftInfo.getTotalLong())); |
| | | } |
| | | resultList.add(equipmentStatisticalShiftInfo); |
| | | } |
| | | } |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æä¸å¤©æä¸ªçæ¬¡çæ°æ® |
| | | * |
| | | * @param dates |
| | | * @param equipmentid |
| | | * @return |
| | | */ |
| | | private MdcEquipmentStatisticalShiftInfo selectRunningEquipment(MdcShiftDateVo dates, String equipmentid) { |
| | | if (dates == null || StringUtils.isBlank(equipmentid)) { |
| | | return null; |
| | | } |
| | | //æ¥è¯¢æ¯å¦éè¦ç»´ä¿®çè®¾å¤ |
| | | 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 { |
| | | 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(); |
| | | 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 è§£æ |
| | | 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 (section.getStatus() == 3) { |
| | | runs.add(section); |
| | | } |
| | | } |
| | | // åæ»å·¥æ¶ => æææ¶é¿å |
| | | 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 |
| | | * @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(); |
| | | } |
| | | } |