|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.BaseRes; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.R; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.SnowflakeIdWorker; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.wcs.common.domain.BaseParam; | 
|---|
|  |  |  | import com.zy.asrs.wcs.common.domain.KeyValVo; | 
|---|
|  |  |  | import com.zy.asrs.wcs.common.domain.PageParam; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.domain.param.ShuttleMoveLocParam; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.domain.param.ShuttleOperatorParam; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.BasShuttle; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Motion; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Task; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.TaskCtg; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.kernel.AnalyzeService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.DeviceCtgType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.TaskCtgType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.TaskStsType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.service.BasShuttleService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.service.MotionService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.service.TaskService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.utils.Utils; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.News; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.entity.Device; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.service.DeviceService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.thread.ShuttleThread; | 
|---|
|  |  |  | import com.zy.asrs.wcs.system.controller.BaseController; | 
|---|
|  |  |  | import com.zy.asrs.wcs.utils.ExcelUtil; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | private AnalyzeService analyzeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MotionService motionService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceService deviceService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('core:basShuttle:list')") | 
|---|
|  |  |  | @PostMapping("/basShuttle/page") | 
|---|
|  |  |  | 
|---|
|  |  |  | ExcelUtil.build(ExcelUtil.create(basShuttleService.list(), BasShuttle.class), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //手动操作 | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('core:basShuttle:operator')") | 
|---|
|  |  |  | @PostMapping("/basShuttle/operator/shuttle") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R shuttleOperator(@RequestBody ShuttleOperatorParam param) { | 
|---|
|  |  |  | public synchronized R shuttleOperator(@RequestBody ShuttleOperatorParam param) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getShuttleNo(), param.getShuttleTaskMode())) { | 
|---|
|  |  |  | return R.error("参数为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer shuttleNo = param.getShuttleNo(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取迁移任务类型 | 
|---|
|  |  |  | //获取手动任务类型 | 
|---|
|  |  |  | TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>() | 
|---|
|  |  |  | .eq(TaskCtg::getFlag, "MANUAL") | 
|---|
|  |  |  | .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.MANUAL)) | 
|---|
|  |  |  | .eq(TaskCtg::getStatus, 1)); | 
|---|
|  |  |  | if (taskCtg == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String sourceLoc = null;//源库位 | 
|---|
|  |  |  | String targetLoc = null;//任务目标(借用字段) | 
|---|
|  |  |  | String targetSite = param.getShuttleTaskMode();//任务类型(借用字段) | 
|---|
|  |  |  | if (param.getShuttleTaskMode().equals("moveLoc")) { | 
|---|
|  |  |  | //迁移任务 | 
|---|
|  |  |  | targetLoc = param.getTargetLocNo(); | 
|---|
|  |  |  | } else if (param.getShuttleTaskMode().equals("takeMove")) { | 
|---|
|  |  |  | //取放货任务 | 
|---|
|  |  |  | targetLoc = param.getTargetLocNo(); | 
|---|
|  |  |  | sourceLoc = param.getSourceLocNo(); | 
|---|
|  |  |  | } else if (param.getShuttleTaskMode().equals("reset")) { | 
|---|
|  |  |  | //复位 | 
|---|
|  |  |  | Device device = deviceService.getOne(new LambdaQueryWrapper<Device>() | 
|---|
|  |  |  | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) | 
|---|
|  |  |  | .eq(Device::getStatus, 1) | 
|---|
|  |  |  | .eq(Device::getDeviceNo, shuttleNo)); | 
|---|
|  |  |  | if (device == null) { | 
|---|
|  |  |  | return R.error("设备不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | return R.error("设备离线"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleThread.reset(null); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else if (param.getShuttleTaskMode().equals("requestWaiting")) { | 
|---|
|  |  |  | //申请确认 | 
|---|
|  |  |  | Device device = deviceService.getOne(new LambdaQueryWrapper<Device>() | 
|---|
|  |  |  | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) | 
|---|
|  |  |  | .eq(Device::getStatus, 1) | 
|---|
|  |  |  | .eq(Device::getDeviceNo, shuttleNo)); | 
|---|
|  |  |  | if (device == null) { | 
|---|
|  |  |  | return R.error("设备不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | return R.error("设备离线"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleThread.requestWaiting(); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Task task = new Task(); | 
|---|
|  |  |  | task.setUuid(String.valueOf(snowflakeIdWorker.nextId())); | 
|---|
|  |  |  | task.setTaskNo(String.valueOf(Utils.getTaskNo("MANUAL"))); | 
|---|
|  |  |  | task.setTaskSts(TaskStsType.NEW_MANUAL.getId()); | 
|---|
|  |  |  | task.setTaskSts(TaskStsType.NEW_MANUAL.sts); | 
|---|
|  |  |  | task.setTaskCtg(taskCtg.getId()); | 
|---|
|  |  |  | task.setPriority(10); | 
|---|
|  |  |  | task.setOriginSite(null); | 
|---|
|  |  |  | task.setOriginLoc(null); | 
|---|
|  |  |  | task.setDestSite(targetSite); | 
|---|
|  |  |  | task.setOriginLoc(sourceLoc); | 
|---|
|  |  |  | task.setDestSite(null); | 
|---|
|  |  |  | task.setDestLoc(targetLoc); | 
|---|
|  |  |  | task.setIoTime(new Date()); | 
|---|
|  |  |  | task.setStartTime(new Date()); | 
|---|
|  |  |  | task.setStatus(1); | 
|---|
|  |  |  | task.setMemo("manual"); | 
|---|
|  |  |  | task.setMemo(targetSite); | 
|---|
|  |  |  | task.setShuttleNo(param.getShuttleNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (param.getShuttleTaskMode().equals("takeMove")) { | 
|---|
|  |  |  | task.setRecordLoc("Y");//记录库存信息 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean result = taskService.save(task); | 
|---|
|  |  |  | if (!result) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task = taskService.getById(task.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // generate motion list | 
|---|
|  |  |  | List<Motion> motionList = analyzeService.generateShuttleManualMotion(task); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task.setTaskSts(TaskStsType.ANALYZE_MANUAL.getId()); | 
|---|
|  |  |  | task.setTaskSts(TaskStsType.ANALYZE_MANUAL.sts); | 
|---|
|  |  |  | if (!taskService.updateById(task)) { | 
|---|
|  |  |  | News.error("保存{}号四向穿梭车手动任务失败!!!", shuttleNo); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //跑库系统 | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('core:basShuttle:operator')") | 
|---|
|  |  |  | @PostMapping("/basShuttle/moveLoc") | 
|---|
|  |  |  | public synchronized R shuttleMoveLoc(@RequestBody ShuttleMoveLocParam param) { | 
|---|
|  |  |  | Device device = deviceService.getOne(new LambdaQueryWrapper<Device>() | 
|---|
|  |  |  | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) | 
|---|
|  |  |  | .eq(Device::getStatus, 1) | 
|---|
|  |  |  | .eq(Device::getHostId, getHostId()) | 
|---|
|  |  |  | .eq(Device::getDeviceNo, param.getShuttleNo())); | 
|---|
|  |  |  | if (device == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); | 
|---|
|  |  |  | if (shuttleProtocol == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleThread.isIdle()) { | 
|---|
|  |  |  | return R.error("小车忙碌中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleThread.enableMoveLoc(param, true); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //跑库系统关闭 | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('core:basShuttle:operator')") | 
|---|
|  |  |  | @PostMapping("/basShuttle/moveLocClose") | 
|---|
|  |  |  | public synchronized R shuttleMoveLocClose(@RequestBody ShuttleMoveLocParam param) { | 
|---|
|  |  |  | Device device = deviceService.getOne(new LambdaQueryWrapper<Device>() | 
|---|
|  |  |  | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) | 
|---|
|  |  |  | .eq(Device::getStatus, 1) | 
|---|
|  |  |  | .eq(Device::getHostId, getHostId()) | 
|---|
|  |  |  | .eq(Device::getDeviceNo, param.getShuttleNo())); | 
|---|
|  |  |  | if (device == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); | 
|---|
|  |  |  | if (shuttleProtocol == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleThread.enableMoveLoc(null, false); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|