| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.bigstorage.entity.BigStorageCage; |
| | | import com.mes.bigstorage.entity.BigStorageCageDetails; |
| | | import com.mes.bigstorage.entity.BigStorageDTO; |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | | import com.mes.bigstorage.service.BigStorageCageService; |
| | | import com.mes.bigstoragecageIntask.entity.BigStorageCageInTask; |
| | | import com.mes.bigstoragecageIntask.service.BigStorageCageInTaskService; |
| | | import com.mes.bigstoragetask.entity.BigStorageCageFeedTask; |
| | | import com.mes.bigstoragetask.entity.BigStorageCageOutTask; |
| | | import com.mes.bigstoragetask.entity.UpdateBigStorageCageDTO; |
| | |
| | | import com.mes.common.config.Const; |
| | | import com.mes.damage.entity.Damage; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.edgglasstask.service.EdgGlassTaskInfoService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.mes.tools.service.BigStorageBaseService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Component |
| | | @Slf4j |
| | | public class OpcPlcStorageCageTask { |
| | | |
| | | @Resource |
| | | private BigStorageCageService bigStorageCageService; |
| | | @Resource |
| | | private BigStorageCageDetailsService bigStorageCageDetailsService; |
| | | @Resource |
| | | private GlassInfoService glassInfoService; |
| | | @Resource |
| | | private BigStorageCageFeedTaskService bigStorageCageFeedTaskService; |
| | | @Resource |
| | | private BigStorageCageOutTaskService bigStorageCageOutTaskService; |
| | | @Resource |
| | | private EdgGlassTaskInfoService edgGlassTaskInfoService; |
| | | @Resource |
| | | private TemperingGlassInfoService temperingGlassInfoService; |
| | | @Resource |
| | | private DamageService damageService; |
| | | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | @Resource |
| | | private GlassInfoService glassInfoService; |
| | | @Resource |
| | | private BigStorageCageService bigStorageCageService; |
| | | |
| | | @Resource(name = "bigStorageStartCallback") |
| | | SubscriptionCallback bigStorageStartCallback; |
| | | |
| | | @Value("${mes.carWidth}") |
| | | private Integer carWidth; |
| | | |
| | | @Value("${mes.slotWidth}") |
| | | private Integer slotWidth; |
| | | @Resource |
| | | private BigStorageBaseService baseService; |
| | | @Resource |
| | | private BigStorageCageInTaskService bigStorageBaseInTaskService; |
| | | |
| | | @Value("${mes.glassGap}") |
| | | private Integer glassGap; |
| | | |
| | | @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | public void startOpcTask() throws Exception { |
| | | //设备一二的进片请求 |
| | | miloService.subscriptionFromOpcUa(Arrays.asList("my.device01.x1", "my.device02.x1"), bigStorageStartCallback); |
| | | } |
| | | // @Resource |
| | | // private BigStorageCage bigStorageBaseInTaskService; |
| | | |
| | | @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | public void outOpcTask() throws Exception { |
| | | //设备1的出片请求 |
| | | miloService.subscriptionFromOpcUa(Arrays.asList("my.device03.x1"), bigStorageStartCallback); |
| | | // @Autowired(required = false) |
| | | // MiloService miloService; |
| | | // |
| | | // @Resource(name = "bigStorageStartCallback") |
| | | // SubscriptionCallback bigStorageStartCallback; |
| | | |
| | | |
| | | // @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | // public void startOpcTask() throws Exception { |
| | | // //设备一二的进片请求 |
| | | // miloService.subscriptionFromOpcUa(Arrays.asList("my.device01.x1", "my.device02.x1"), bigStorageStartCallback); |
| | | // } |
| | | |
| | | // @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | // public void outOpcTask() throws Exception { |
| | | // //设备1的出片请求 |
| | | // miloService.subscriptionFromOpcUa(Arrays.asList("my.device03.x1"), bigStorageStartCallback); |
| | | // } |
| | | |
| | | |
| | | @Scheduled(fixedDelay = 200) |
| | | public void inBigStorageTask() { |
| | | //todo:获取进片任务表 |
| | | List<BigStorageCageInTask> inTaskList = bigStorageBaseInTaskService.queryTaskMessage("big_storage_cage_in_one_task"); |
| | | if (CollectionUtils.isEmpty(inTaskList)) { |
| | | log.info("当前大车无进片任务,结束本地定时任务"); |
| | | } |
| | | List<String> glassIdList = inTaskList.stream().map(BigStorageCageInTask::getGlassId).collect(Collectors.toList()); |
| | | Map<String, List<BigStorageCageInTask>> taskMap = inTaskList.stream().collect(Collectors.groupingBy(BigStorageCageInTask::getGlassId)); |
| | | List<GlassInfo> glassInfoList = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().in(GlassInfo::getGlassId, glassIdList)); |
| | | //todo:计算目标格子 |
| | | for (GlassInfo info : glassInfoList) { |
| | | //获取目标格子信息 |
| | | BigStorageDTO bigStorageDTO = bigStorageCageDetailsService.queryTargetSlotByTempering(info); |
| | | // 临时更新格子的剩余尺寸:防止相邻玻璃进同一格子造成剩余尺寸不足,玻璃越界的情况,任务完成后再次更新大理片笼表剩余宽度(按照笼内玻璃数量更新大理片笼剩余尺寸) |
| | | bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>() |
| | | .set(BigStorageCage::getRemainWidth, bigStorageDTO.getWidth() - Math.max(info.getWidth(), info.getHeight()) - glassGap) |
| | | .eq(BigStorageCage::getSlot, bigStorageDTO.getSlot())); |
| | | BigStorageCageInTask task = taskMap.get(info.getGlassId()).get(0); |
| | | task.setTargetSlot(bigStorageDTO.getSlot()); |
| | | task.setGlassId(info.getGlassId()); |
| | | task.setTaskRunning(Const.BIG_STORAGE_TASK_RUNNING); |
| | | bigStorageBaseInTaskService.updateTaskMessage("", task); |
| | | //todo:存放历史任务 |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | bigStorageCageDetailsService.updateBySlot(storageCageDTOList, Const.GLASS_STATE_IN); |
| | | log.info("4、大理片笼进片状态已完成已完成的玻璃信息id:{}", inSuccessGlass); |
| | | //更新理片笼玻璃尺寸 |
| | | updateSlotRemainBySlots(inSuccessGlassSlot); |
| | | baseService.updateSlotRemainBySlots(inSuccessGlassSlot); |
| | | log.info("5、大理片笼进片目标格子尺寸更新完成"); |
| | | } |
| | | |
| | |
| | | List<Integer> outSuccessSlotList = outSuccessGlass.stream().map(BigStorageCageOutTask::getStartSlot).collect(Collectors.toList()); |
| | | log.info("4、大理片笼出片状态已完成已完成的玻璃信息id:{}", outSuccessGlass); |
| | | //更新理片笼玻璃尺寸 |
| | | updateSlotRemainBySlots(outSuccessSlotList); |
| | | baseService.updateSlotRemainBySlots(outSuccessSlotList); |
| | | log.info("5、大理片笼进片目标格子尺寸更新完成"); |
| | | } |
| | | } |
| | |
| | | //更新理片笼玻璃尺寸 |
| | | List<Integer> slotList = scheduleSuccessGlass.stream().map(BigStorageCageOutTask::getStartSlot).distinct().collect(Collectors.toList()); |
| | | slotList.addAll(scheduleSuccessGlass.stream().map(BigStorageCageOutTask::getEndSlot).distinct().collect(Collectors.toList())); |
| | | updateSlotRemainBySlots(slotList); |
| | | baseService.updateSlotRemainBySlots(slotList); |
| | | log.info("5、大理片笼进片目标格子尺寸更新完成"); |
| | | } |
| | | } |
| | |
| | | slotList.add(bigStorageCageFeedTask.getTargetSlot()); |
| | | } |
| | | //更新格子剩余宽度 |
| | | updateSlotRemainBySlots(slotList); |
| | | baseService.updateSlotRemainBySlots(slotList); |
| | | log.info("进片任务执行完成"); |
| | | } |
| | | //获取出片任务表中状态为破损的数据 |
| | |
| | | slotList.add(bigStorageCageOutTask.getStartSlot()); |
| | | } |
| | | //更新格子剩余宽度 |
| | | updateSlotRemainBySlots(slotList); |
| | | baseService.updateSlotRemainBySlots(slotList); |
| | | log.info("出片任务执行完成"); |
| | | } |
| | | Date endDate = new Date(); |
| | | log.info("大理片笼破损玻璃清除任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime()); |
| | | return; |
| | | } |
| | | |
| | | public void updateSlotRemainBySlots(List<Integer> slotList) { |
| | | //获取格子内所有的玻璃信息 |
| | | List<BigStorageCageDetails> inSlotGlassList = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>() |
| | | .in(BigStorageCageDetails::getSlot, slotList).in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL)); |
| | | Map<Integer, Double> slotRemainMap = new HashMap<>(); |
| | | //是否存在有格子非空的玻璃 |
| | | if (CollectionUtils.isNotEmpty(inSlotGlassList)) { |
| | | //存在 将格子内的玻璃分别进行更新 |
| | | slotRemainMap = inSlotGlassList.stream() |
| | | .collect(Collectors.groupingBy(BigStorageCageDetails::getSlot, Collectors.summingDouble(item -> Math.max(item.getWidth(), item.getHeight()) + glassGap))); |
| | | slotRemainMap.forEach((e, v) -> { |
| | | double remainWidth = slotWidth - v >= 0 ? slotWidth - v : 0; |
| | | bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, remainWidth) |
| | | .eq(BigStorageCage::getSlot, e)); |
| | | }); |
| | | } |
| | | //过滤不存在玻璃的格子 将宽度重置为原始宽度5000 |
| | | Set<Integer> remainSlotList = slotRemainMap.keySet(); |
| | | slotList.removeAll(remainSlotList); |
| | | if (CollectionUtils.isNotEmpty(slotList)) { |
| | | bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, slotWidth) |
| | | .in(BigStorageCage::getSlot, slotList)); |
| | | } |
| | | } |
| | | |
| | | |