¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.jeecg.modules.mdc.dto.MdcProcessCountDto; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.mapper.MdcProcessCountMapper; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.util.TimeFieldUtils; |
| | | import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo; |
| | | import org.jeecg.modules.mdc.vo.MdcProcessCountVo; |
| | | import org.jeecg.modules.mdc.vo.MdcShiftDateVo; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author Lius |
| | | * @date 2023/11/23 10:17 |
| | | */ |
| | | @Service |
| | | public class ProcessCountServiceImpl extends ServiceImpl<MdcProcessCountMapper, MdcProcessCount> implements IProcessCountService { |
| | | |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | @Resource |
| | | private IMdcDeviceCalendarService mdcDeviceCalendarService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentOverFlagService mdcEquipmentOverFlagService; |
| | | |
| | | @Resource |
| | | private IEquipmentWorkLineService equipmentWorkLineService; |
| | | |
| | | /** |
| | | * 计ç®å 工工件个æ°åæ¶é´ä»»å¡ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public void runningProcessCount() { |
| | | // è·åææè®¾å¤ |
| | | List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(); |
| | | List<MdcProcessCount> result = new ArrayList<>(); |
| | | for (MdcEquipment mdcEquipment : mdcEquipmentList) { |
| | | List<MdcProcessCount> mdcProcessCountList = processCount(mdcEquipment); |
| | | if (mdcProcessCountList != null && !mdcProcessCountList.isEmpty()) { |
| | | result.addAll(mdcProcessCountList); |
| | | } |
| | | } |
| | | if (!result.isEmpty()) { |
| | | this.saveBatch(result); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å页æ¥è¯¢ |
| | | * |
| | | * @param userId |
| | | * @param page |
| | | * @param mdcProcessCountVo |
| | | * @param req |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<MdcProcessCountDto> pageList(String userId, Page<MdcProcessCountDto> page, MdcProcessCountVo mdcProcessCountVo, HttpServletRequest req) { |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcProcessCountVo.getParentId()) && StringUtils.isEmpty(mdcProcessCountVo.getEquipmentId())) { |
| | | if ("2".equals(mdcProcessCountVo.getTypeTree())) { |
| | | //é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcProcessCountVo.getParentId()); |
| | | } else { |
| | | //产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProcessCountVo.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcProcessCountVo.getEquipmentId())) { |
| | | //åå°è®¾å¤ä¿¡æ¯ |
| | | mdcProcessCountVo.setMdcSectionIds(Collections.singletonList(mdcProcessCountVo.getEquipmentId())); |
| | | } else { |
| | | //æ¥è¯¢ç¨æ·æ¥æçææè®¾å¤ä¿¡æ¯ |
| | | if ("2".equals(mdcProcessCountVo.getTypeTree())) { |
| | | //é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | //产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | if (mdcProcessCountVo.getMdcSectionIds() == null || mdcProcessCountVo.getMdcSectionIds().isEmpty()) { |
| | | mdcProcessCountVo.setMdcSectionIds(equipmentIds); |
| | | } |
| | | |
| | | if (mdcProcessCountVo.getMdcSectionIds() == null || mdcProcessCountVo.getMdcSectionIds().isEmpty()) { |
| | | return null; |
| | | } |
| | | return this.baseMapper.pageList(page, mdcProcessCountVo); |
| | | } |
| | | |
| | | @Transactional(readOnly = true) |
| | | List<MdcProcessCount> processCount(MdcEquipment mdcEquipment) { |
| | | Date initDate = null; |
| | | //åæåçç»è®¡æ°æ® |
| | | MdcProcessCount lastData = this.baseMapper.getLastData(mdcEquipment.getEquipmentId()); |
| | | Boolean flag = true; |
| | | if (lastData != 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); |
| | | } |
| | | } |
| | | 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(mdcEquipment.getEquipmentId(), stringDates); |
| | | if (listMap.isEmpty()) { |
| | | listMap = new HashMap<>(); |
| | | } |
| | | List<MdcProcessCount> 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; |
| | | } |
| | | for (MdcShiftDateVo mdcShiftDateVo : datesListByMdcDeviceCalendarVo) { |
| | | Date startDate = null; |
| | | //å¤çæ°æ® |
| | | //List<MdcProcessCount> result = new ArrayList<>(); |
| | | // æ¥è¯¢ç次å
设å¤è¿è¡ç¶ææ¶é´æ®µ |
| | | List<MdcEquipmentRunningSection> equipmentRunningSectionList = mdcEquipmentRunningSectionService.selectRunningData(mdcEquipment.getEquipmentId(), mdcShiftDateVo.getStartDate(), mdcShiftDateVo.getEndDate()); |
| | | if (equipmentRunningSectionList != null && !equipmentRunningSectionList.isEmpty()) { |
| | | // æ¶é´ä¿®æ£ |
| | | equipmentRunningSectionList.get(0).setStartTime(mdcShiftDateVo.getStartDate()); |
| | | if (equipmentRunningSectionList.size() > 1) { |
| | | equipmentRunningSectionList.get(equipmentRunningSectionList.size() - 1).setEndTime(mdcShiftDateVo.getEndDate()); |
| | | } else { |
| | | equipmentRunningSectionList.get(0).setEndTime(mdcShiftDateVo.getEndDate()); |
| | | } |
| | | if (!"FANUC".equals(mdcEquipment.getDriveType())) { |
| | | MdcEquipmentOverFlag equipmentOverFlag = mdcEquipmentOverFlagService.getOne(new LambdaQueryWrapper<MdcEquipmentOverFlag>().eq(MdcEquipmentOverFlag::getDriveType, mdcEquipment.getDriveType())); |
| | | if (equipmentOverFlag == null) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | for (int j = 0; j < equipmentRunningSectionList.size(); j++) { |
| | | MdcEquipmentRunningSection mdcEquipmentRunningSection = equipmentRunningSectionList.get(j); |
| | | // æ¥æ¾è®¾å¤å表è¿è¡æ°æ® |
| | | List<Map<String, Object>> mdcEquipmentDtoList = equipmentWorkLineService.findRunningData(mdcEquipment.getSaveTableName(), mdcEquipmentRunningSection.getStartTime(), mdcEquipmentRunningSection.getEndTime()); |
| | | if (mdcEquipmentDtoList == null || mdcEquipmentDtoList.isEmpty()) { |
| | | continue; |
| | | } |
| | | MdcProcessCount mdcProcessCount = new MdcProcessCount(); |
| | | mdcProcessCount.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | mdcProcessCount.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | mdcProcessCount.setTheDate(mdcShiftDateVo.getDay()); |
| | | if (lastData != null && flag) { |
| | | mdcProcessCount.setStartTime(lastData.getEndTime()); |
| | | startDate = mdcProcessCount.getStartTime(); |
| | | flag = false; |
| | | } else if (startDate == null) { |
| | | mdcProcessCount.setStartTime(mdcEquipmentRunningSection.getStartTime()); |
| | | startDate = mdcProcessCount.getStartTime(); |
| | | } else { |
| | | mdcProcessCount.setStartTime(startDate); |
| | | } |
| | | if ("FANUC".equals(mdcEquipment.getDriveType())) { |
| | | // æ³å
°å
è®¾å¤æ ¹æ®ProductCountåæ®µå¤æ |
| | | String productCount = mdcEquipmentDtoList.get(0).get("ProductCount").toString(); |
| | | for (int i = 0; i < mdcEquipmentDtoList.size(); i++) { |
| | | if (!productCount.equals(mdcEquipmentDtoList.get(i).get("ProductCount").toString())) { |
| | | productCount = mdcEquipmentDtoList.get(i).get("ProductCount").toString(); |
| | | if (mdcEquipmentDtoList.get(i - 1).get("CollectTime") != null) { |
| | | mdcProcessCount.setEndTime(DateUtils.toDate(mdcEquipmentDtoList.get(i - 1).get("CollectTime").toString(), DateUtils.STR_DATE_TIME)); |
| | | mdcProcessCount.setDuration(TimeFieldUtils.duration(mdcProcessCount.getStartTime(), mdcProcessCount.getEndTime())); |
| | | mdcProcessCount.setSequenceNumber(mdcEquipmentDtoList.get(i - 1).get("Sequencenumber").toString()); |
| | | resultList.add(mdcProcessCount); |
| | | if (TimeFieldUtils.duration(mdcProcessCount.getEndTime(), mdcEquipmentRunningSection.getEndTime()) > 60) { |
| | | //mdcProcessCount.setStartTime(mdcProcessCount.getEndTime()); |
| | | startDate = mdcProcessCount.getEndTime(); |
| | | } else if (j + 1 < equipmentRunningSectionList.size()) { |
| | | //mdcProcessCount.setStartTime(equipmentRunningSectionList.get(j + 1).getStartTime()); |
| | | startDate = equipmentRunningSectionList.get(j + 1).getStartTime(); |
| | | } else { |
| | | startDate = null; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | |
| | | 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 overtimeStartTime = temp.getOvertimeStartTime(); |
| | | String overtimeEndTime = temp.getOvertimeEndTime(); |
| | | 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); |
| | | } |
| | | // å¤çå çæ¶é´ |
| | | if (StringUtils.isNotEmpty(overtimeStartTime)) { |
| | | Date start = DateUtils.getFormatDate(eff + " " + overtimeStartTime, DateUtils.STR_DATE_TIME_SMALL); |
| | | Date end = DateUtils.getFormatDate(eff + " " + overtimeEndTime, DateUtils.STR_DATE_TIME_SMALL); |
| | | if ("true".equals(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; |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | } |