add:手持

This commit is contained in:
2026-01-13 19:43:43 +08:00
parent a47541f302
commit ead6b83e2c
3 changed files with 273 additions and 155 deletions

View File

@@ -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<Object> Taskoperation(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(HandService.sendPointTask(whereJson), HttpStatus.OK);
@SaIgnore
public ResponseEntity<Object> tasks(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(padService.tasks(whereJson), HttpStatus.OK);
}
@PostMapping("/getTaskInfoByStartPoint")
@Log("根据起点查询任务信息")
@ApiOperation("根据起点查询任务信息")
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> getTaskInfoByStartPoint(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(HandService.getTaskInfoByStartPoint(whereJson), HttpStatus.OK);
@PostMapping("/taskoperation")
@Log("任务操作")
@ApiOperation("任务操作")
@SaIgnore
public ResponseEntity<Object> taskoperation(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(padService.taskoperation(whereJson), HttpStatus.OK);
}
@PostMapping("/getAllTaskType")
@Log("根据起点查询任务信息")
@ApiOperation("根据起点查询任务信息")
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> getAllTaskType() {
return new ResponseEntity<>(HandService.getAllTaskType(), HttpStatus.OK);
@PostMapping("/insts")
@Log("查询指令信息")
@ApiOperation("查询指令信息")
@SaIgnore
public ResponseEntity<Object> insts(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(padService.insts(whereJson), HttpStatus.OK);
}
@PostMapping("/instoperation")
@Log("指令操作")
@ApiOperation("指令操作")
@SaIgnore
public ResponseEntity<Object> instoperation(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(padService.instoperation(whereJson), HttpStatus.OK);
}
@PostMapping("/callTask")
@Log("定点任务")
@ApiOperation("定点任务")
@SaIgnore
public ResponseEntity<Object> callTask(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(padService.callTask(whereJson), HttpStatus.OK);
}
}

View File

@@ -3,23 +3,44 @@ package org.nl.hand.service;
import java.util.Map;
public interface PadService {
/**
* 发送点位任务
* 查看任务
*
* @param whereJson
* @return
*/
Map<String, Object> sendPointTask(Map<String, String> whereJson);
Map<String, Object> tasks(Map<String, String> whereJson);
/**
* 获取任务信息
* 任务操作
*
* @param whereJson
* @return
*/
Map<String, Object> getTaskInfoByStartPoint(Map<String, String> whereJson);
Map<String, Object> taskoperation(Map<String, String> whereJson);
/**
* 获取所有任务类型
* 获取所有指令
*
* @param whereJson
* @return
*/
Map<String, Object> getAllTaskType();
Map<String, Object> insts(Map<String, String> whereJson);
/**
* 指令操作
*
* @param whereJson
* @return
*/
Map<String, Object> instoperation(Map<String, String> whereJson);
/**
* 定点任务
*
* @param whereJson
* @return
*/
Map<String, Object> callTask(Map<String, String> whereJson);
}

View File

@@ -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<String, Object> sendPointTask(Map<String, String> 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<String, Object> tasks(Map<String, String> whereJson) {
JSONObject resultJson = new JSONObject();
String vehicle_code = StrUtil.trimToEmpty(whereJson.get("vehicle_code"));
String device_code = StrUtil.trimToEmpty(whereJson.get("device_code"));
List<TaskDto> taskDtos = taskService.queryAllByCache();
List<Map<String, Object>> list = (taskDtos == null ? Stream.<TaskDto>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<String, Object> 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<String, Object> getTaskInfoByStartPoint(Map<String, String> 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<String, Object> taskoperation(Map<String, String> 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<String, Object> getAllTaskType() {
// 返回值
JSONObject resultJSON = new JSONObject();
public Map<String, Object> insts(Map<String, String> whereJson) {
JSONObject resultJson = new JSONObject();
String vehicle_code = whereJson.get("vehicle_code");
String device_code = whereJson.get("device_code");
List<Instruction> instructions = instructionService.findAllInstFromCache();
List<Map<String, Object>> list = (instructions == null ? Stream.<Instruction>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<String, Object> 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<String, Object> instoperation(Map<String, String> 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<String, Object> callTask(Map<String, String> 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;
}
}