| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.acs.manager.common.domain.param.HandlerPublishParam; |
| | | import com.zy.acs.manager.common.exception.BusinessException; |
| | | import com.zy.acs.manager.core.service.AvoidWaveCalculator; |
| | |
| | | import com.zy.acs.manager.core.service.ThreadPoolRegulator; |
| | | import com.zy.acs.manager.core.service.TrafficService; |
| | | import com.zy.acs.manager.core.service.astart.MapDataDispatcher; |
| | | import com.zy.acs.manager.manager.entity.Agv; |
| | | import com.zy.acs.manager.manager.entity.AgvDetail; |
| | | import com.zy.acs.manager.manager.entity.Loc; |
| | | import com.zy.acs.manager.manager.entity.Task; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.ActionStsType; |
| | | import com.zy.acs.manager.manager.enums.LocStsType; |
| | | import com.zy.acs.manager.manager.enums.TaskStsType; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.manager.system.controller.BaseController; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/handler") |
| | | @RequestMapping("/api/handler") |
| | | public class HandlerController extends BaseController { |
| | | |
| | | public static final String APP_KEY = "xltys1995"; |
| | |
| | | @Autowired |
| | | private AvoidWaveCalculator avoidWaveCalculator; |
| | | |
| | | @RequestMapping(value = "/publish", method = {RequestMethod.GET, RequestMethod.POST}) |
| | | @RequestMapping(value = "/control/agv", method = {RequestMethod.GET, RequestMethod.POST}) |
| | | @Transactional |
| | | public R publish(@RequestHeader String appKey, |
| | | public R controlAgv(@RequestHeader String appKey, |
| | | @RequestBody HandlerPublishParam param) { |
| | | if (Cools.isEmpty(param.getAgvNo(), param.getTaskType(), appKey)) { |
| | | if (Cools.isEmpty(param.getAgvNo(), param.getTaskMode(), appKey)) { |
| | | return R.error(); |
| | | } |
| | | if (!APP_KEY.equals(appKey)) { |
| | |
| | | } |
| | | |
| | | // generate |
| | | switch (param.getTaskType()) { |
| | | switch (param.getTaskMode()) { |
| | | case MOVE: |
| | | if (Cools.isEmpty(param.getEndCode())) { |
| | | Code endCode = null; |
| | | if (!Cools.isEmpty(param.getEndCode())) { |
| | | endCode = codeService.getById(param.getEndCode()); |
| | | } |
| | | if (!Cools.isEmpty(param.getEndCodeStr())) { |
| | | endCode = codeService.selectByData(param.getEndCodeStr()); |
| | | } |
| | | if (null == endCode) { |
| | | return R.error(); |
| | | } |
| | | if (null == codeService.selectByData(param.getEndCode())) { |
| | | return R.error(); |
| | | } |
| | | if (!mainService.buildMinorTask(agv, agvDetail, param.getTaskType(), param.getEndCode())) { |
| | | if (!mainService.buildMinorTask(agv, agvDetail, param.getTaskMode(), endCode.getData())) { |
| | | return R.error(); |
| | | } |
| | | break; |
| | | case TO_CHARGE: |
| | | case TO_STANDBY: |
| | | if (!mainService.buildMinorTask(agv, agvDetail, param.getTaskType(), null)) { |
| | | if (!mainService.buildMinorTask(agv, agvDetail, param.getTaskMode(), null)) { |
| | | return R.error(); |
| | | } |
| | | break; |
| | | case LOC_TO_LOC: |
| | | if (Cools.isEmpty(param.getStartLocNo(), param.getEndLocNo())) { |
| | | return R.error(); |
| | | // oriLoc |
| | | Loc oriLoc = null; |
| | | if (!Cools.isEmpty(param.getStartLocNo())) { |
| | | oriLoc = locService.getById(param.getStartLocNo()); |
| | | } |
| | | Loc oriLoc = locService.selecatByLocNo(param.getStartLocNo()); |
| | | if (!Cools.isEmpty(param.getStartLocNoStr())) { |
| | | oriLoc = locService.selecatByLocNo(param.getStartLocNoStr()); |
| | | } |
| | | if (null == oriLoc) { |
| | | return R.error(); |
| | | } |
| | | Loc destLoc = locService.selecatByLocNo(param.getEndLocNo()); |
| | | if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | throw new BusinessException("oriLoc:" + oriLoc.getLocNo() + " 不是在库状态"); |
| | | } |
| | | // destLoc |
| | | Loc destLoc = null; |
| | | if (!Cools.isEmpty(param.getEndLocNo())) { |
| | | destLoc = locService.getById(param.getEndLocNo()); |
| | | } |
| | | if (!Cools.isEmpty(param.getEndLocNoStr())) { |
| | | destLoc = locService.selecatByLocNo(param.getEndLocNoStr()); |
| | | } |
| | | if (null == destLoc) { |
| | | return R.error(); |
| | | } |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + destLoc.getLocNo() + " 不是空闲状态"); |
| | | } |
| | | |
| | | |
| | | // task |
| | | Task task = new Task(); |
| | |
| | | task.setOriLoc(oriLoc.getId()); |
| | | task.setDestLoc(destLoc.getId()); |
| | | |
| | | task.setTaskType(param.getTaskType().val()); |
| | | task.setTaskType(param.getTaskMode().val()); |
| | | task.setTaskSts(TaskStsType.WAITING.val()); |
| | | |
| | | task.setPriority(999); |
| | |
| | | } |
| | | |
| | | // loc |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " 不是在库状态"); |
| | | } |
| | | oriLoc.setLocSts(LocStsType.PAKOUT.val()); |
| | | oriLoc.setUpdateTime(now); |
| | | if (!locService.updateById(oriLoc)) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " 修改库位状态失败"); |
| | | } |
| | | |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " 不是空闲状态"); |
| | | } |
| | | destLoc.setLocSts(LocStsType.PAKIN.val()); |
| | | destLoc.setUpdateTime(now); |
| | | if (!locService.updateById(destLoc)) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " 修改库位状态失败"); |
| | | } |
| | | |
| | | break; |
| | | default: |
| | | break; |