| | |
| | | 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.dto.MdcEquipmentDto; |
| | | import org.jeecg.modules.mdc.dto.MdcProcessCountDto; |
| | | import org.jeecg.modules.mdc.entity.MdcDeviceCalendar; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection; |
| | | import org.jeecg.modules.mdc.entity.MdcProcessCount; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | public void runningProcessCount() { |
| | | // 获取所有设备 |
| | | //List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198")); |
| | | List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(); |
| | | List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getDriveType, "FANUC")); |
| | | List<MdcProcessCount> result = new ArrayList<>(); |
| | | for (MdcEquipment mdcEquipment : mdcEquipmentList) { |
| | | if ("FANUC".equals(mdcEquipment.getDriveType())) { |
| | | List<MdcProcessCount> mdcProcessCountList = processCount(mdcEquipment); |
| | | if (mdcProcessCountList != null && !mdcProcessCountList.isEmpty()) { |
| | | result.addAll(mdcProcessCountList); |
| | | } |
| | | List<MdcProcessCount> mdcProcessCountList = processCount(mdcEquipment); |
| | | if (mdcProcessCountList != null && !mdcProcessCountList.isEmpty()) { |
| | | result.addAll(mdcProcessCountList); |
| | | } |
| | | } |
| | | if (!result.isEmpty()) { |
| | |
| | | return result == null ? BigDecimal.ZERO : result; |
| | | } |
| | | |
| | | // @Transactional(readOnly = true) |
| | | List<MdcProcessCount> processCount(MdcEquipment mdcEquipment) { |
| | | Date initDate = null; |
| | | //取最后的统计数据 |
| | |
| | | initDate = DateUtils.toDate(lastData.getTheDate(), DateUtils.STRDATE); |
| | | initDate = DateUtils.plusTime(initDate, 1); |
| | | } else { |
| | | //初次取值 取最早时间 |
| | | MdcDeviceCalendar mdcDeviceCalendar = mdcDeviceCalendarService.getFirstData(mdcEquipment.getEquipmentId()); |
| | | if (mdcDeviceCalendar != null) { |
| | | initDate = DateUtils.toDate(mdcDeviceCalendar.getEffectiveDate(), DateUtils.STRDATE); |
| | | } |
| | | //初次取值 取当前时间往前推一个月时间 |
| | | // MdcDeviceCalendar mdcDeviceCalendar = mdcDeviceCalendarService.getFirstData(mdcEquipment.getEquipmentId()); |
| | | initDate = DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE); |
| | | } |
| | | if (initDate == null) { |
| | | return null; |
| | |
| | | // 获取设备班次信息 |
| | | Map<String, List<MdcDeviceCalendarVo>> listMap = this.mdcDeviceCalendarMap(mdcEquipment.getEquipmentId(), stringDates); |
| | | if (listMap == null || listMap.isEmpty()) { |
| | | listMap = new HashMap<>(); |
| | | return null; |
| | | } |
| | | List<MdcProcessCount> resultList = new ArrayList<>(); |
| | | for (String stringDate : stringDates) { |
| | |
| | | // 处理班制班次时间 |
| | | MdcDateVo mdcDateVo = this.handleDeviceCalendar(mdcDeviceCalendarVos); |
| | | // 查找设备单表运行数据 |
| | | List<Map<String, Object>> mdcEquipmentDtoList = equipmentWorkLineService.findRunningData(mdcEquipment.getSaveTableName(), mdcDateVo.getStartTime(), mdcDateVo.getEndTime()); |
| | | if (mdcEquipmentDtoList == null || mdcEquipmentDtoList.isEmpty()) { |
| | | List<String> productCountList = new ArrayList<>(); |
| | | try { |
| | | productCountList = equipmentWorkLineService.findRunningData(mdcEquipment.getSaveTableName(), mdcDateVo.getStartTime(), mdcDateVo.getEndTime()); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | Map<String, Object> firstMap = new HashMap<>(mdcEquipmentDtoList.get(0)); |
| | | |
| | | if (productCountList == null || productCountList.isEmpty()) { |
| | | continue; |
| | | } |
| | | /* Map<String, Object> firstMap = new HashMap<>(mdcEquipmentDtoList.get(0)); |
| | | Map<String, Object> mdcEquipmentDtoMap = mdcEquipmentDtoList.get(0); |
| | | for (int i = 1; i < mdcEquipmentDtoList.size(); i++) { |
| | | String productCount1 = mdcEquipmentDtoList.get(i).get("ProductCount").toString(); |
| | |
| | | //根据productCount值查询开始时间 |
| | | String productCount = mdcEquipmentDtoList.get(i - 1).get("ProductCount").toString(); |
| | | MdcEquipmentDto mdcEquipmentDto = equipmentWorkLineService.findProductCountStartTime(mdcEquipment.getSaveTableName(), productCount); |
| | | if (mdcEquipmentDto == null) { |
| | | continue; |
| | | } |
| | | start = mdcEquipmentDto.getCollectTime(); |
| | | //程序号 |
| | | sequenceNumber = mdcEquipmentDtoList.get(i - 1).get("Sequencenumber").toString(); |
| | |
| | | } |
| | | mdcEquipmentDtoMap.put("ProductCount", mdcEquipmentDtoList.get(i).get("ProductCount").toString()); |
| | | mdcEquipmentDtoMap.put("CollectTime", mdcEquipmentDtoList.get(i).get("CollectTime").toString()); |
| | | |
| | | List<MdcEquipmentRunningSection> equipmentRunningSectionList = mdcEquipmentRunningSectionService.selectRunningData(mdcEquipment.getEquipmentId(), start, end); |
| | | if (equipmentRunningSectionList != null && !equipmentRunningSectionList.isEmpty()) { |
| | | //时间修正 |
| | | if (equipmentRunningSectionList.get(0).getStartTime().before(start)) { |
| | | equipmentRunningSectionList.get(0).setStartTime(start); |
| | | } |
| | | }*/ |
| | | for (String productCount : productCountList) { |
| | | MdcEquipmentDto mdcEquipmentDtoFirst = equipmentWorkLineService.findProductCountStartTime(mdcEquipment.getSaveTableName(), productCount, mdcDateVo.getStartTime(), mdcDateVo.getEndTime()); |
| | | if (mdcEquipmentDtoFirst == null) { |
| | | continue; |
| | | } |
| | | Date start = mdcEquipmentDtoFirst.getCollectTime(); |
| | | MdcEquipmentDto mdcEquipmentDtoLast = equipmentWorkLineService.findProductCountEndTime(mdcEquipment.getSaveTableName(), productCount, mdcDateVo.getStartTime(), mdcDateVo.getEndTime()); |
| | | if (mdcEquipmentDtoLast == null) { |
| | | continue; |
| | | } |
| | | Date end = mdcEquipmentDtoLast.getCollectTime(); |
| | | List<MdcEquipmentRunningSection> equipmentRunningSectionList = mdcEquipmentRunningSectionService.selectRunningData(mdcEquipment.getEquipmentId(), start, end); |
| | | if (equipmentRunningSectionList != null && !equipmentRunningSectionList.isEmpty()) { |
| | | //时间修正 |
| | | if (equipmentRunningSectionList.get(0).getStartTime().before(start)) { |
| | | equipmentRunningSectionList.get(0).setStartTime(start); |
| | | } |
| | | if (equipmentRunningSectionList.size() > 1) { |
| | | if (equipmentRunningSectionList.get(equipmentRunningSectionList.size() - 1).getEndTime().after(end)) { |
| | | equipmentRunningSectionList.get(equipmentRunningSectionList.size() - 1).setEndTime(end); |
| | | } |
| | | if (equipmentRunningSectionList.size() > 1) { |
| | | if (equipmentRunningSectionList.get(equipmentRunningSectionList.size() - 1).getEndTime().after(end)) { |
| | | equipmentRunningSectionList.get(equipmentRunningSectionList.size() - 1).setEndTime(end); |
| | | } |
| | | } else { |
| | | if (equipmentRunningSectionList.get(0).getEndTime().after(end)) { |
| | | equipmentRunningSectionList.get(0).setEndTime(end); |
| | | } |
| | | } |
| | | //计算加工时长 |
| | | long duration = this.handleProcessDuration(equipmentRunningSectionList); |
| | | if (duration != 0 && duration < 100000) { |
| | | MdcProcessCount mdcProcessCount = new MdcProcessCount(); |
| | | mdcProcessCount.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | mdcProcessCount.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | if (StringUtils.isBlank(mdcEquipmentDtoFirst.getSequencenumber())) { |
| | | mdcProcessCount.setSequenceNumber(mdcEquipmentDtoLast.getSequencenumber()); |
| | | } else { |
| | | if (equipmentRunningSectionList.get(0).getEndTime().after(end)) { |
| | | equipmentRunningSectionList.get(0).setEndTime(end); |
| | | } |
| | | mdcProcessCount.setSequenceNumber(mdcEquipmentDtoFirst.getSequencenumber()); |
| | | } |
| | | //计算加工时长 |
| | | long duration = this.handleProcessDuration(equipmentRunningSectionList); |
| | | if (duration != 0 && duration < 100000) { |
| | | MdcProcessCount mdcProcessCount = new MdcProcessCount(); |
| | | mdcProcessCount.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | mdcProcessCount.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | mdcProcessCount.setSequenceNumber(sequenceNumber); |
| | | mdcProcessCount.setDuration(duration); |
| | | mdcProcessCount.setTheDate(stringDate); |
| | | resultList.add(mdcProcessCount); |
| | | } |
| | | mdcProcessCount.setDuration(duration); |
| | | mdcProcessCount.setTheDate(stringDate); |
| | | resultList.add(mdcProcessCount); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | return resultList; |
| | |
| | | |
| | | private Map<String, List<MdcDeviceCalendarVo>> mdcDeviceCalendarMap(String equipmentId, List<String> stringDates) { |
| | | List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = mdcDeviceCalendarService.listByEquipmentAndDate(equipmentId, stringDates); |
| | | if (mdcDeviceCalendarVos.isEmpty()) { |
| | | if (mdcDeviceCalendarVos == null || mdcDeviceCalendarVos.isEmpty()) { |
| | | return null; |
| | | } |
| | | Map<String, List<MdcDeviceCalendarVo>> map = new HashMap<>(); |