zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/IMainService.java
New file @@ -0,0 +1,51 @@ package com.zy.acs.manager.core.service; import com.zy.acs.common.domain.AgvProtocol; import com.zy.acs.manager.common.domain.param.HandlerPublishParam; import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam; import com.zy.acs.manager.manager.entity.Bus; import com.zy.acs.manager.manager.entity.Jam; import com.zy.acs.manager.manager.entity.Segment; import com.zy.acs.manager.manager.entity.Task; import com.zy.acs.manager.manager.enums.TaskTypeType; import java.util.Date; import java.util.List; /** * Created by vincent on 2023/6/14 */ public interface IMainService { //Bus generateBusAndTask(OpenBusSubmitParam busSubmitParam, String memo); /** * 任务分配给车辆 ( 车辆此时是空闲且静止的 ) */ void allocateTask(Bus bus); /** * 解析取放货集合任务,进行最优的排列组合顺序 ( 车辆此时是空闲且静止的 ) * todo: {@link com.zy.acs.manager.core.HandlerController#controlAgv(String, HandlerPublishParam)} */ void buildMajorTask(Long agvId, List<Task> taskList); /** * 充电 回待机位任务 */ //boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam); /** * 根据分片生成动作 ( 车辆可能已经做过一些任务了,正在等待下一段任务 ) */ void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime); void publishAction(String actionGroupId); void upDataSubscribe(AgvProtocol protocol); void settleSegmentList(List<Segment> segmentList, String serialNo); } zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -48,7 +48,7 @@ */ @Slf4j @Service("mainService") public class MainService { public class MainService implements IMainService { @Autowired private BusService busService; @@ -284,7 +284,9 @@ */ @Transactional(propagation = Propagation.REQUIRES_NEW) public void buildMajorTask(Long agvId, List<Task> taskList) { if (Cools.isEmpty(agvId, taskList)) { return; } if (Cools.isEmpty(agvId, taskList)) { return; } try { // valid ----------------------------------------------- Agv agv = agvService.getById(agvId); @@ -332,8 +334,10 @@ backpackLev ++; Code startCode = null; Code endCode = null; Loc oriLoc = null; Loc destLoc = null; Sta oriSta = null; Sta destSta = null; Loc oriLoc = null; Loc destLoc = null; Sta oriSta = null; Sta destSta = null; switch (Objects.requireNonNull(TaskTypeType.get(task.getTaskTypeEl()))) { case LOC_TO_LOC: oriLoc = locService.getById(task.getOriLoc()); @@ -530,9 +534,12 @@ /** * 充电 回待机位任务 */ @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) { if (Cools.isEmpty(agvId, taskType)) { return false; } if (Cools.isEmpty(agvId, taskType)) { return false; } try { String agvNo = agvService.getAgvNo(agvId); if (!agvService.judgeEnable(agvId)) { @@ -609,7 +616,8 @@ } // generate segment int segSerial = 0; segSerial ++; int segSerial = 0; segSerial++; List<Segment> segmentList = new ArrayList<>(); String posType = ""; @@ -685,7 +693,9 @@ @Transactional public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) { try { if (Cools.isEmpty(agvId, segmentList)) { return; } if (Cools.isEmpty(agvId, segmentList)) { return; } Date now = new Date(); long actionPrepareSts = ActionStsType.PREPARE.val(); // JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class); @@ -727,7 +737,9 @@ List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1); for (int i = 0; i < pathListPart.size(); i++) { if (i == 0) { continue; } if (i == 0) { continue; } String next = pathListPart.get(i); @@ -1469,8 +1481,10 @@ for (Segment segment : segmentList) { boolean taskComplete = false; Task task = taskService.getById(segment.getTaskId()); assert null != task; TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl()); assert null != typeType; Task task = taskService.getById(segment.getTaskId()); assert null != task; TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl()); assert null != typeType; TaskPosDto.PosType posType = TaskPosDto.queryPosType(segment.getPosType()); switch (Objects.requireNonNull(posType)) { zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainZkdService.java
@@ -19,7 +19,6 @@ import com.zy.acs.framework.exception.CoolException; import com.zy.acs.manager.common.domain.param.HandlerPublishParam; import com.zy.acs.manager.common.exception.BusinessException; import com.zy.acs.manager.core.domain.AgvBackpackDto; import com.zy.acs.manager.core.domain.TaskPosDto; import com.zy.acs.manager.core.service.astart.MapDataDispatcher; import com.zy.acs.manager.core.third.zkd.HttpUtils; @@ -46,8 +45,8 @@ * Created by vincent on 2023/6/14 */ @Slf4j @Service("mainService") public class MainZkdService { @Service("zkdMainService") public class MainZkdService implements IMainService { @Autowired private BusService busService; @@ -101,7 +100,7 @@ * 任务分配给车辆 ( 车辆此时是空闲且静止的 ) */ @Transactional public synchronized void allocateTaskByZkd(Bus bus) { public synchronized void allocateTask(Bus bus) { try { Date now = new Date(); List<Task> taskList = taskService.list(new LambdaQueryWrapper<Task>() @@ -182,6 +181,8 @@ } } /** * 解析取放货集合任务,进行最优的排列组合顺序 ( 车辆此时是空闲且静止的 ) * todo: {@link com.zy.acs.manager.core.HandlerController#controlAgv(String, HandlerPublishParam)} @@ -200,27 +201,30 @@ if (!travelService.save(travel)) { throw new BusinessException("任务组保存失败"); } // generate segment int segSerial = 0; List<Segment> segmentList = new ArrayList<>(); for (List<TaskPosDto> dtoList : list) { for (TaskPosDto taskPosDto : dtoList) { for (Navigation.CodeDTO codeDTO : navigation.getCodeList()) { segSerial++; AgvBackpackType backpackType = AgvBackpackDto.find(backpackDtoList, taskPosDto.getTaskId()); assert null != backpackType; Task task = taskService.getById(Long.parseLong(codeDTO.getTaskId())); Segment segment = new Segment(); segment.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); segment.setTravelId(travel.getId()); segment.setAgvId(agvId); segment.setTaskId(taskPosDto.getTaskId()); segment.setTaskId(task.getId()); segment.setSerial(segSerial); segment.setEndNode(taskPosDto.getCodeId()); segment.setPosType(taskPosDto.getPosType().toString()); segment.setBackpack(backpackType.lev); Code cacheByData = codeService.getCacheByData(codeDTO.getCode()); segment.setEndNode(cacheByData.getId()); segment.setPosType(codeDTO.getPosType()); segment.setBackpack(codeDTO.getLev()); segment.setState(SegmentStateType.INIT.toString()); segmentList.add(segment); task.setTaskSts(TaskStsType.ASSIGN.val()); task.setStartTime(new Date()); task.setUpdateTime(new Date()); if (!taskService.updateById(task)) { throw new BusinessException(task.getUuid() + "任务更新失败"); } } for (int i = 0; i < segmentList.size(); i++) { @@ -230,16 +234,6 @@ } if (!segmentService.save(segment)) { throw new BusinessException("任务组保存失败"); } } // task for (Task task : taskList) { task.setTaskSts(TaskStsType.ASSIGN.val()); task.setStartTime(now); task.setUpdateTime(now); if (!taskService.updateById(task)) { throw new BusinessException(task.getUuid() + "任务更新失败"); } } zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/TrafficZkdService.java
@@ -39,7 +39,7 @@ @Autowired private SegmentService segmentService; @Autowired private MainService mainService; private MainZkdService mainZkdService; @Autowired private MainLockWrapService mainLockWrapService; @Autowired @@ -99,7 +99,7 @@ segmentList.add(segment); mainService.generateAction(segment.getAgvId(), segmentList, pathList, now); mainZkdService.generateAction(segment.getAgvId(), segmentList, null, now); } catch (Exception e) { log.error("TrafficService.trigger", e); zy-acs-manager/src/main/java/com/zy/acs/manager/core/third/zkd/dto/Navigation.java
@@ -12,6 +12,8 @@ private List<CodeDTO> CodeList; private String segId; @Data public class CodeDTO implements Serializable { /** zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/OpenAlgorithmController.java
@@ -3,8 +3,10 @@ import com.zy.acs.framework.common.Cools; import com.zy.acs.framework.common.R; import com.zy.acs.manager.common.annotation.OperationLog; import com.zy.acs.manager.core.service.MainZkdService; import com.zy.acs.manager.core.third.zkd.dto.Navigation; import com.zy.acs.manager.manager.controller.param.OpenAgvParam; import com.zy.acs.manager.manager.service.AgvService; import com.zy.acs.manager.manager.service.CodeService; import com.zy.acs.manager.manager.service.OpenAlgorithmService; import com.zy.acs.manager.system.controller.BaseController; @@ -27,6 +29,12 @@ private OpenAlgorithmService openAlgorithmService; @Autowired private MainZkdService mainZkdService; @Autowired private AgvService agvService; @Autowired private CodeService codeService; @PostMapping("/getAgv") @@ -42,13 +50,10 @@ } @RequestMapping("/zkd/navigation/v1") public Object navigation(@RequestBody Navigation navigation) { String agvId = navigation.getAgvId(); navigation.getCodeList().forEach(codeDTO -> { }); Long agvId = agvService.getAgvId(navigation.getAgvId()); mainZkdService.buildMajorTask(agvId, navigation); return null; }