From ead6b83e2cbcc153e833a8e8d4f68f93f6a27272 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Tue, 13 Jan 2026 19:43:43 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=89=8B=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/nl/hand/rest/PadController.java | 56 +-- .../java/org/nl/hand/service/PadService.java | 33 +- .../nl/hand/service/impl/PadServiceImpl.java | 339 +++++++++++------- 3 files changed, 273 insertions(+), 155 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/hand/rest/PadController.java b/acs/nladmin-system/src/main/java/org/nl/hand/rest/PadController.java index 0a9fd63..e3e6948 100644 --- a/acs/nladmin-system/src/main/java/org/nl/hand/rest/PadController.java +++ b/acs/nladmin-system/src/main/java/org/nl/hand/rest/PadController.java @@ -1,5 +1,6 @@ package org.nl.hand.rest; +import cn.dev33.satoken.annotation.SaIgnore; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -8,10 +9,7 @@ import org.nl.hand.service.PadService; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -22,29 +20,45 @@ import java.util.Map; @Slf4j public class PadController { - private final PadService HandService; + private final PadService padService; - @PostMapping("/sendPointTask") + @PostMapping("/tasks") @Log("任务操作") @ApiOperation("任务操作") - //@PreAuthorize("@el.check('sect:list')") - public ResponseEntity Taskoperation(@RequestBody Map whereJson) { - return new ResponseEntity<>(HandService.sendPointTask(whereJson), HttpStatus.OK); + @SaIgnore + public ResponseEntity tasks(@RequestBody Map whereJson) { + return new ResponseEntity<>(padService.tasks(whereJson), HttpStatus.OK); } - @PostMapping("/getTaskInfoByStartPoint") - @Log("根据起点查询任务信息") - @ApiOperation("根据起点查询任务信息") - //@PreAuthorize("@el.check('sect:list')") - public ResponseEntity getTaskInfoByStartPoint(@RequestBody Map whereJson) { - return new ResponseEntity<>(HandService.getTaskInfoByStartPoint(whereJson), HttpStatus.OK); + @PostMapping("/taskoperation") + @Log("任务操作") + @ApiOperation("任务操作") + @SaIgnore + public ResponseEntity taskoperation(@RequestBody Map whereJson) { + return new ResponseEntity<>(padService.taskoperation(whereJson), HttpStatus.OK); } - @PostMapping("/getAllTaskType") - @Log("根据起点查询任务信息") - @ApiOperation("根据起点查询任务信息") - //@PreAuthorize("@el.check('sect:list')") - public ResponseEntity getAllTaskType() { - return new ResponseEntity<>(HandService.getAllTaskType(), HttpStatus.OK); + @PostMapping("/insts") + @Log("查询指令信息") + @ApiOperation("查询指令信息") + @SaIgnore + public ResponseEntity insts(@RequestBody Map whereJson) { + return new ResponseEntity<>(padService.insts(whereJson), HttpStatus.OK); + } + + @PostMapping("/instoperation") + @Log("指令操作") + @ApiOperation("指令操作") + @SaIgnore + public ResponseEntity instoperation(@RequestBody Map whereJson) { + return new ResponseEntity<>(padService.instoperation(whereJson), HttpStatus.OK); + } + + @PostMapping("/callTask") + @Log("定点任务") + @ApiOperation("定点任务") + @SaIgnore + public ResponseEntity callTask(@RequestBody Map whereJson) { + return new ResponseEntity<>(padService.callTask(whereJson), HttpStatus.OK); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/hand/service/PadService.java b/acs/nladmin-system/src/main/java/org/nl/hand/service/PadService.java index ea75279..af5f706 100644 --- a/acs/nladmin-system/src/main/java/org/nl/hand/service/PadService.java +++ b/acs/nladmin-system/src/main/java/org/nl/hand/service/PadService.java @@ -3,23 +3,44 @@ package org.nl.hand.service; import java.util.Map; public interface PadService { + /** - * 发送点位任务 + * 查看任务 + * * @param whereJson * @return */ - Map sendPointTask(Map whereJson); + Map tasks(Map whereJson); /** - * 获取任务信息 + * 任务操作 + * * @param whereJson * @return */ - Map getTaskInfoByStartPoint(Map whereJson); + Map taskoperation(Map whereJson); /** - * 获取所有任务类型 + * 获取所有指令 + * + * @param whereJson * @return */ - Map getAllTaskType(); + Map insts(Map whereJson); + + /** + * 指令操作 + * + * @param whereJson + * @return + */ + Map instoperation(Map whereJson); + + /** + * 定点任务 + * + * @param whereJson + * @return + */ + Map callTask(Map whereJson); } diff --git a/acs/nladmin-system/src/main/java/org/nl/hand/service/impl/PadServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/hand/service/impl/PadServiceImpl.java index 4001b71..97164c8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/hand/service/impl/PadServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/hand/service/impl/PadServiceImpl.java @@ -4,22 +4,21 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.service.dto.TaskConfigDto; -import org.nl.acs.device.service.impl.TaskConfigServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; -import org.nl.acs.task.service.impl.TaskServiceImpl; import org.nl.hand.service.PadService; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.wql.WQL; -import org.nl.modules.wql.util.SpringContextHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; @Service @RequiredArgsConstructor @@ -27,138 +26,222 @@ import java.util.Map; public class PadServiceImpl implements PadService { @Autowired - TaskService taskService; - @Override - public Map sendPointTask(Map whereJson) { - JSONObject resultJson = new JSONObject(); - String task_type = whereJson.get("task_type"); - String point_code1 = whereJson.get("point_code1"); - String point_code2 = whereJson.get("point_code2"); - String point_code3 = whereJson.get("point_code3"); - String point_code4 = whereJson.get("point_code4"); - String is_overrun = whereJson.get("is_overrun"); - if (StrUtil.isEmpty(point_code1)) { - throw new BadRequestException("起点1不能为空"); - } - if (StrUtil.isEmpty(point_code2)) { - throw new BadRequestException("终点1不能为空"); - } - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startDevice = appService.findDeviceByCode(point_code1); - Device nextDevice = appService.findDeviceByCode(point_code2); - if (startDevice == null) { - throw new BadRequestException("起点1不存在"); - } - if (nextDevice == null) { - throw new BadRequestException("终点1不存在"); - } - Device startDevice2 = null; - Device nextDevice2 = null; - if (!"1".equals(task_type)){ - if (StrUtil.isEmpty(point_code3)) { - throw new BadRequestException("起点2不能为空"); - } - if (StrUtil.isEmpty(point_code4)){ - throw new BadRequestException("终点2不能为空"); - } - startDevice2 = appService.findDeviceByCode(point_code3); - nextDevice2 = appService.findDeviceByCode(point_code4); - if (startDevice2 == null) { - throw new BadRequestException("起点2不存在"); - } - if (nextDevice2 == null) { - throw new BadRequestException("终点2不存在"); - } - //判断设备是否还有未完成的任务 - int count1 = taskService.queryDeviceUnfinishTask(point_code3); - if (count1 > 0) { - throw new BadRequestException("设备"+point_code3+"有未完成任务"); - } - int count2 = taskService.queryDeviceUnfinishTask(point_code4); - if (count2 > 0) { - throw new BadRequestException("设备"+point_code4+"有未完成任务"); - } - } + private TaskService taskService; + @Autowired + private InstructionService instructionService; + @Autowired + private DeviceAppService deviceAppService; - //判断设备是否还有未完成的任务 - int count1 = taskService.queryDeviceUnfinishTask(point_code1); - if (count1 > 0) { - throw new BadRequestException("设备"+point_code1+"有未完成任务"); - } - int count2 = taskService.queryDeviceUnfinishTask(point_code2); - if (count2 > 0) { - throw new BadRequestException("设备"+point_code2+"有未完成任务"); - } - TaskService taskService = SpringContextHolder.getBean(TaskServiceImpl.class); - TaskDto dto = new TaskDto(); - dto.setIs_active("1"); - dto.setIs_delete("0"); - dto.setStart_point_code(point_code1); - dto.setStart_device_code(point_code1); - dto.setNext_point_code(point_code2); - dto.setNext_device_code(point_code2); - dto.setNext_point_code2(point_code4); - dto.setNext_device_code2(point_code4); - dto.setStart_point_code2(point_code3); - dto.setStart_device_code2(point_code3); - dto.setTask_type(task_type); - dto.setPriority("1"); - try { - taskService.create(dto); - } catch (Exception e) { - resultJson.put("code", "400"); - resultJson.put("message", e.getMessage()); - return resultJson; - } - resultJson.put("code", "200"); - resultJson.put("message", "生成成功!"); + @Override + public Map tasks(Map whereJson) { + JSONObject resultJson = new JSONObject(); + String vehicle_code = StrUtil.trimToEmpty(whereJson.get("vehicle_code")); + String device_code = StrUtil.trimToEmpty(whereJson.get("device_code")); + List taskDtos = taskService.queryAllByCache(); + List> list = (taskDtos == null ? Stream.empty() : taskDtos.stream()) + .filter(t -> { + if (StrUtil.isEmpty(vehicle_code)) return true; + String vc = t.getVehicle_code(); + return StrUtil.isNotEmpty(vc) && vc.contains(vehicle_code); + }) + .filter(t -> { + if (StrUtil.isEmpty(device_code)) return true; + String s = t.getStart_device_code(); + String n = t.getNext_device_code(); + return (StrUtil.isNotEmpty(s) && s.contains(device_code)) + || (StrUtil.isNotEmpty(n) && n.contains(device_code)); + }) + .map(t -> { + Map m = new HashMap<>(); + m.put("task_id", t.getTask_id()); + m.put("task_no", t.getTask_code()); + m.put("priority", t.getPriority()); + m.put("start_device_code", t.getStart_device_code()); + m.put("next_device_code", t.getNext_device_code()); + m.put("inst_status", t.getTask_status()); + m.put("vehicle_code", t.getVehicle_code()); + m.put("create_time", t.getCreate_time()); + return m; + }) + .collect(Collectors.toList()); + resultJson.put("result", list); + resultJson.put("code", "1"); + resultJson.put("message", "ok"); return resultJson; } @Override - public Map getTaskInfoByStartPoint(Map whereJson) { - String task_type = whereJson.get("task_type"); - String point_code1 = whereJson.get("point_code1"); - if (StrUtil.isEmpty(point_code1)){ - throw new BadRequestException("起点1不能为空"); - } - if (StrUtil.isEmpty(task_type)){ - throw new BadRequestException("任务类型不能为空"); - } - TaskConfigServiceImpl taskConfigService = SpringContextHolder.getBean(TaskConfigServiceImpl.class); - TaskConfigDto taskConfigDto = taskConfigService.selectTaskConfigByStartPointAndTaskType(point_code1, task_type); - JSONObject ja = new JSONObject(); + public Map taskoperation(Map whereJson) { JSONObject resultJson = new JSONObject(); - if (taskConfigDto == null){ - resultJson.put("point_code2", ""); - resultJson.put("point_code3", ""); - resultJson.put("point_code4", ""); - ja.put("data", resultJson); - return ja; + String type = whereJson.get("type"); + if (StrUtil.isEmpty(type)) { + resultJson.put("code", "0"); + resultJson.put("message", "操作类型不能为空!"); + return resultJson; } - resultJson.put("point_code2", taskConfigDto.getPoint_code2()); - resultJson.put("point_code3", taskConfigDto.getPoint_code3()); - resultJson.put("point_code4", taskConfigDto.getPoint_code4()); - ja.put("data", resultJson); - return ja; + String task_id = whereJson.get("task_id"); + if (StrUtil.isEmpty(task_id)) { + resultJson.put("code", "0"); + resultJson.put("message", "任务ID不能为空!"); + return resultJson; + } + if (type.equals("1")) { + try { + taskService.cancel(task_id); + } catch (Exception e) { + resultJson.put("code", "0"); + resultJson.put("message", "取消失败, " + e.getMessage()); + return resultJson; + } + } else if (type.equals("2")) { + try { + taskService.finish(task_id); + } catch (Exception e) { + resultJson.put("code", "0"); + resultJson.put("message", "完成失败, " + e.getMessage()); + return resultJson; + } + } else if (type.equals("3")) { + try { + taskService.createInst(task_id); + } catch (Exception e) { + resultJson.put("code", "0"); + resultJson.put("message", "重新创建指令失败, " + e.getMessage()); + return resultJson; + } + } + resultJson.put("code", "1"); + resultJson.put("message", "操作成功!"); + return resultJson; } @Override - public Map getAllTaskType() { - // 返回值 - JSONObject resultJSON = new JSONObject(); + public Map insts(Map whereJson) { + JSONObject resultJson = new JSONObject(); + String vehicle_code = whereJson.get("vehicle_code"); + String device_code = whereJson.get("device_code"); + List instructions = instructionService.findAllInstFromCache(); + List> list = (instructions == null ? Stream.empty() : instructions.stream()) + .filter(instruction -> { + if (StrUtil.isEmpty(vehicle_code)) return true; + String vc = instruction.getVehicle_code(); + return StrUtil.isNotEmpty(vc) && vc.contains(vehicle_code); + }) + .filter(instruction -> { + if (StrUtil.isEmpty(device_code)) return true; + String s = instruction.getStart_device_code(); + String n = instruction.getNext_device_code(); + return (StrUtil.isNotEmpty(s) && s.contains(device_code)) + || (StrUtil.isNotEmpty(n) && n.contains(device_code)); + }) + .map(instruction -> { + Map m = new HashMap<>(); + m.put("inst_id", instruction.getInstruction_id()); + m.put("instruction_code", instruction.getInstruction_code()); + m.put("task_no", instruction.getTask_code()); + m.put("priority", instruction.getPriority()); + m.put("start_device_code", instruction.getStart_device_code()); + m.put("next_device_code", instruction.getNext_device_code()); + m.put("inst_status", instruction.getInstruction_status()); + m.put("vehicle_code", instruction.getVehicle_code()); + m.put("car_no", instruction.getCarno()); + m.put("create_time", instruction.getCreate_time()); + return m; + }) + .collect(Collectors.toList()); + resultJson.put("result", list); + resultJson.put("code", "1"); + resultJson.put("message", "ok"); + return resultJson; + } - // 查询任务类型 - resultJSON.put("data", - WQL - .getWO("PAD") - .addParam("flag", "1") - .process() - .getResultJSONArray(0)); + @Override + public Map instoperation(Map whereJson) { + JSONObject resultJson = new JSONObject(); + String type = whereJson.get("type"); + if (StrUtil.isEmpty(type)) { + resultJson.put("code", "0"); + resultJson.put("message", "操作类型不能为空!"); + return resultJson; + } + String inst_id = whereJson.get("inst_id"); + if (StrUtil.isEmpty(inst_id)) { + resultJson.put("code", "0"); + resultJson.put("message", "指令ID不能为空!"); + return resultJson; + } + if (type.equals("1")) { + try { + instructionService.cancel(inst_id); + } catch (Exception e) { + resultJson.put("code", "0"); + resultJson.put("message", "取消失败, " + e.getMessage()); + return resultJson; + } + } else if (type.equals("2")) { + try { + instructionService.finish(inst_id); + } catch (Exception e) { + resultJson.put("code", "0"); + resultJson.put("message", "完成失败, " + e.getMessage()); + return resultJson; + } + } + resultJson.put("code", "1"); + resultJson.put("message", "操作成功!"); + return resultJson; + } - // 返回 - resultJSON.put("code", "200"); - resultJSON.put("message", "查询成功"); - return resultJSON; + @Override + public Map callTask(Map whereJson) { + JSONObject resultJson = new JSONObject(); + String start_device_code = whereJson.get("start_device_code"); + if (StrUtil.isEmpty(start_device_code)) { + resultJson.put("code", "0"); + resultJson.put("message", "起始库位不能为空!"); + return resultJson; + } + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + if (startDevice == null) { + resultJson.put("code", "0"); + resultJson.put("message", "起始库位不存在,请添加起始库位!"); + return resultJson; + } + String next_device_code = whereJson.get("next_device_code"); + if (StrUtil.isEmpty(next_device_code)) { + resultJson.put("code", "0"); + resultJson.put("message", "目的库位不能为空!"); + return resultJson; + } + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + if (nextDevice == null) { + resultJson.put("code", "0"); + resultJson.put("message", "目的库位不存在,请添加目的库位!"); + return resultJson; + } + String vehicle_code = whereJson.get("vehicle_code"); + if (StrUtil.isEmpty(vehicle_code)) { + resultJson.put("code", "0"); + resultJson.put("message", "托盘号不能为空!"); + return resultJson; + } + TaskDto taskDto = new TaskDto(); + taskDto.setStart_device_code(start_device_code); + taskDto.setStart_point_code(start_device_code); + taskDto.setStart_parent_code(start_device_code); + taskDto.setNext_device_code(next_device_code); + taskDto.setNext_point_code(next_device_code); + taskDto.setNext_parent_code(next_device_code); + taskDto.setVehicle_code(vehicle_code); + try { + taskService.create(taskDto); + } catch (Exception e) { + resultJson.put("code", "0"); + resultJson.put("message", "生成失败, " + e.getMessage()); + return resultJson; + } + resultJson.put("code", "1"); + resultJson.put("message", "生成成功!"); + return resultJson; } }