| | |
| | | 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 javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | |
| | | @Resource |
| | | private IMdcDeviceCalendarService mdcDeviceCalendarService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentRepairService mdcEquipmentRepairService; |
| | | |
| | | /** |
| | | * 计算设备单日班次运行数据 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询主轴运行时间 |
| | | * |
| | | * @param equipmentId |
| | | * @param validDate |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BigDecimal findSpindleRunDuration(String equipmentId, String validDate) { |
| | | validDate = validDate.replaceAll("-", ""); |
| | | BigDecimal duration = this.baseMapper.findSpindleRunDuration(equipmentId, validDate); |
| | | if (duration != null && duration.compareTo(BigDecimal.ZERO) != 0) { |
| | | return duration.divide(new BigDecimal("60"), 0, RoundingMode.HALF_UP); |
| | | } else { |
| | | return new BigDecimal("0"); |
| | | } |
| | | } |
| | | |
| | | @Transactional(readOnly = true) |
| | | List<MdcEquipmentStatisticalShiftInfo> equipmentShiftStatisticalProcess(Equipment equipment, String dateTime) { |
| | | Date initDate = null; |
| | | //取最后的统计数据 |
| | |
| | | * 查询某一天某个班次的数据 |
| | | * |
| | | * @param dates |
| | | * @param equipmentid |
| | | * @param equipmentId |
| | | * @return |
| | | */ |
| | | private MdcEquipmentStatisticalShiftInfo selectRunningEquipment(MdcShiftDateVo dates, String equipmentid) { |
| | | if (dates == null || StringUtils.isBlank(equipmentid)) { |
| | | 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())); |
| | | } |
| | | MdcEquipmentStatisticalShiftInfo shiftInfo = mdcRateEquipment(equipmentId, dates.getStartDate(), dates.getEndDate()); |
| | | return shiftInfo; |
| | | } |
| | | |
| | |
| | | //sectionErrors = filterSectionErrors(equipmentId, sectionErrors); |
| | | MdcEquipmentStatisticalShiftInfo shiftInfo = new MdcEquipmentStatisticalShiftInfo(); |
| | | BigDecimal totalLongRairs = new BigDecimal("0"); |
| | | List<MdcEquipmentRunningSection> sectionList = findStatsEquipment(null, runningSections, date, sectionErrors); |
| | | List<MdcEquipmentRunningSection> sectionList = findStatsEquipment(runningSections, date, sectionErrors); |
| | | if (sectionList == null || sectionList.isEmpty()) { |
| | | shiftInfo.setEquipmentId(equipmentid); |
| | | return shiftInfo; |
| | |
| | | return processLong; |
| | | } |
| | | |
| | | private List<MdcEquipmentRunningSection> findStatsEquipment(List<MdcEquipmentRepair> repairs, List<MdcEquipmentRunningSection> sRun, MdcDateVo mdcDate, List<MdcEquipmentRunningSection> errors) { |
| | | private List<MdcEquipmentRunningSection> findStatsEquipment(List<MdcEquipmentRunningSection> sRun, MdcDateVo mdcDate, List<MdcEquipmentRunningSection> errors) { |
| | | if (sRun == null || sRun.isEmpty()) { |
| | | //无数据处理 |
| | | //TODO |
| | | return null; |
| | | } |
| | | Long startMdc = mdcDate.getStartTime().getTime(); |
| | |
| | | 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()); |
| | |
| | | } |
| | | 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; |
| | | } |
| | | // |
| | | // 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 |