rev:增加任务校验

This commit is contained in:
2025-11-05 09:20:25 +08:00
parent 5209aca9a9
commit 257b512bea
14 changed files with 158 additions and 97 deletions

View File

@@ -27,6 +27,7 @@ import org.nl.system.service.param.ISysParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -67,15 +68,10 @@ public class QueryAGVStatus {
JSONObject taskStatus = json.getJSONObject("TaskStatus");
String instructionCode = taskStatus.getString("TaskNo");
if ("true".equals(json.getString("Result")) && instructionCode.equals(instruction.getInstruction_code())) {
// 已创建=CREATED
// 待分配=TOBEDISPATCHED
// 正在执行=RUNNING
// 完成=FINISHED
// 失败=FAILED(主动失败)
// 终止=STOPPED(被人为终止)
// 无法执行=Error(参数错误)
// 等待=WAITING
//执行中
// 正在执行=running
// 完成=finish
// 失败=failed(主动失败)
// 终止=aborted(被人为终止)
String state = json.getString("Status");
String carNo = json.getString("VehicleNo");
if ("running".equals(state)) {
@@ -85,7 +81,7 @@ public class QueryAGVStatus {
instruction.setInstruction_status("1");
instructionService.update(instruction);
instructionService.update(instruction);
task.setCarno(carNo);
task.setCar_no(carNo);
task.setTask_id(instruction.getTask_id());
taskService.update(task);
}
@@ -100,10 +96,12 @@ public class QueryAGVStatus {
e.printStackTrace();
}
}
} else if ("paused".equals(state) || "aborted".equals(state) || "Error".equals(state)) {
if (!"1".equals(instruction.getInstruction_status())) {
} else if ("failed".equals(state) || "aborted".equals(state)) {
TaskDto task = taskService.findById(instruction.getTask_id());
List<String> list = Arrays.asList("0", "1");
if (list.contains(instruction.getInstruction_status())&&"1".equals(task.getTask_status())) {
instruction.setInstruction_status("1");
//todo 备注异常信息
instruction.setRemark("调度取消指令");
instructionService.update(instruction);
}
}

View File

@@ -57,7 +57,7 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
@Override
public HttpResponse deleteTask(String instCode) throws Exception {
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("下发科聪任务")
.device_code("删除科聪任务")
.content(instCode)
.build();
logDto.setLog_level(4);
@@ -81,7 +81,7 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
.timeout(20000)
.execute();
LuceneLogDto logDto1 = LuceneLogDto.builder()
.device_code("删除科聪任务")
.device_code(instCode)
.content("指令号:" + instCode + ",删除科聪任务序列反馈参数:" + ja)
.build();
logDto.setLog_level(4);
@@ -209,10 +209,16 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
@Override
public JSONObject agvWaitPointRequest(JSONObject requestParam) {
log.info("科聪二次分配请求参数:" + requestParam);
log.info("agv二次分配请求参数:" + requestParam);
String instNo = requestParam.getString("TaskNo");
String vehicleNo = requestParam.getString("VehicleNo");
String type = requestParam.getString("type"); // 1 取货点等待 2 放货点等待
LuceneLogDto logDto1 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv二次分配请求参数:" + requestParam)
.build();
logDto1.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto1);
Instruction inst = instructionService.findByCodeFromCache(instNo);
if (ObjectUtil.isEmpty(inst)) {
throw new BadRequestException("请求失败,未找到指令!");
@@ -225,7 +231,13 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
ja.put("code", "200");
ja.put("message", "操作成功");
ja.put("point_code", String.valueOf(startAddress));
log.info("科聪二次分配返回参数:" + ja);
log.info("申请取货二次分配成功,返回agv参数:" + ja);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("申请取货二次分配成功,返回agv参数:" + inst.getTask_code() + "--" + ja)
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
return ja;
}
//如果是放货二次分配
@@ -237,11 +249,13 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
ja.put("code", "200");
ja.put("message", "操作成功");
ja.put("point_code", String.valueOf(nextAddress));
log.info("申请放货二次分配成功,返回agv参数:" + ja);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("放货二次分配,参数:" + inst.getTask_code() + "--" + ActionTypeEnum.getStatus(Integer.parseInt(inst.getInstruction_type())))
.content("申请放货二次分配成功,返回agv参数:" + inst.getTask_code() + "--" + ja)
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
return ja;
}
throw new BadRequestException("请求失败IN OUT 站点错误!");
@@ -254,7 +268,7 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
param.put("type", type);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("二次分配请求wms,参数:" + inst.getTask_code() + "--" + ActionTypeEnum.getStatus(Integer.parseInt(inst.getInstruction_type())))
.content("二次分配请求wms,参数:" + param)
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
@@ -263,21 +277,21 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
if (jo.getInteger("status") == 200) {
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("二次分配请求lms,参数,接口返回:" + jo)
.content("二次分配请求wms成功,接口返回参数:" + jo)
.build();
logDto2.setLog_level(4);
//二次分配更新点位
updataTask(inst, jo.getString("data"));
updataTask(inst, type,jo.getString("data"));
return jo.getString("data");
} else {
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("二次分配请求lms,返回参数:" + jo)
.content("二次分配请求wms失败,接口返回参数:" + jo)
.build();
logDto2.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto2);
log.info("科聪二次分配请求lms失败,返回参数:" + jo);
throw new BadRequestException("二次分配请求lms返回失败" + jo);
log.info("二次分配请求wms失败,接口返回参数:" + jo);
throw new BadRequestException("二次分配请求wms返回失败" + jo);
}
}
@@ -295,67 +309,72 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
@Override
public JSONObject applyIn(JSONObject requestParam) {
log.info("agv申请进入或者离开,请求参数:" + requestParam);
String resourceID = requestParam.getString("point_code");
String vehicleNo = requestParam.getString("VehicleNo");
LuceneLogDto logDto1 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv申请进入或者离开,请求参数:"+ requestParam)
.build();
logDto1.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto1);
if (resourceID.equals("659") || resourceID.equals("17")) {
log.info("科聪申请离开请求参数:" + requestParam);
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv申请进入请求离开成功")
.build();
logDto2.setLog_level(4);
JSONObject json = new JSONObject();
json.put("code", "200");
json.put("message", "操作成功");
log.info("agv申请离开成功返回参数"+ json);
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv申请离开成功返回参数"+ json)
.build();
logDto2.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto2);
return json;
}
log.info("科聪申请进入请求参数:" + requestParam);
List<StorageCell> storageCells = storageCellMapper.selectList(new LambdaQueryWrapper<StorageCell>().eq(StorageCell::getAddress, resourceID).orderByDesc(StorageCell::getUpdate_time));
StorageCell storageCell = storageCells.get(0);
String storage_code = storageCell.getStorage_code();
JSONObject ja = new JSONObject();
ja.put("point_code", storage_code);
String response = acsToWmsService.applyIn(ja);
JSONObject jo = JSON.parseObject(response);
if (jo.getInteger("status") == 200) {
log.info("agv申请进入请求lms成功,参数,接口返回:" + jo);
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv申请进入请求lms成功,参数,接口返回:" + jo)
.build();
logDto2.setLog_level(4);
JSONObject json = new JSONObject();
json.put("code", "200");
json.put("message", "操作成功");
log.info("科聪申请进入下发返回参数:" + json);
return json;
} else {
log.info("agv申请进入请求lms失败,参数,接口返回:" + jo);
log.info("agv申请进入成功返回agv参数:" + json);
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv申请进入请求lms失败,返回参数:" + jo)
.content("agv申请进入成功返回agv参数:" + json)
.build();
logDto2.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto2);
return json;
} else {
JSONObject json = new JSONObject();
json.put("code", "400");
json.put("message", "申请进入失败,接口返回:" + jo);
log.info("科聪申请进入下发返回参数:" + json);
log.info("agv申请进入失败返回agv参数:" + json);
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(vehicleNo)
.content("agv申请进入失败返回agv参数:" + json)
.build();
logDto2.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto2);
return json;
}
}
private void updataTask(Instruction instructionDto, String newPoint) {
private void updataTask(Instruction instructionDto,String type, String newPoint) {
TaskDto taskUpdate = new TaskDto();
if (AgvActionTypeEnum.IN_STOCK.getCode().equals(instructionDto.getAgv_action_type())) {
if ("1".equals(type)) {
instructionDto.setStart_point_code(newPoint);
taskUpdate.setStart_point_code(newPoint);
instructionDto.setStart_device_code(newPoint);
taskUpdate.setStart_device_code(newPoint);
}
if (AgvActionTypeEnum.OUT_STOCK.getCode().equals(instructionDto.getAgv_action_type())) {
if ("2".equals(type)) {
instructionDto.setNext_point_code(newPoint);
taskUpdate.setNext_point_code(newPoint);
instructionDto.setNext_device_code(newPoint);
@@ -377,19 +396,36 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
@Override
public JSONObject requestAction(JSONObject requestParam) {
String taskNo = requestParam.getString("TaskNo");
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code(taskNo)
.content("agv取货完成反馈,请求参数:" + requestParam)
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
Instruction instruction = instructionService.findByCode(taskNo);
JSONObject jsonObject = new JSONObject();
jsonObject.put("task_code", instruction.getTask_code());
LuceneLogDto logDto1 = LuceneLogDto.builder()
.device_code(taskNo)
.content("取货完成反馈:" + jsonObject.toJSONString() + ";指令号:" + taskNo)
.content("取货完成反馈wms,请求参数:" + jsonObject.toJSONString() + ";指令号:" + taskNo)
.build();
logDto1.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto1);
acsToWmsService.actionFinishRequest2(jsonObject);
TaskDto dto = taskserver.findByCode(instruction.getTask_code());
dto.setExecute_code("1");
instruction.setExecute_code("1");
taskserver.update(dto);
instructionService.update(instruction);
JSONObject jo = new JSONObject();
jo.put("code", "200");
jo.put("message", "请求成功");
LuceneLogDto logDto2 = LuceneLogDto.builder()
.device_code(taskNo)
.content("取货完成,返回agv参数:" + jsonObject.toJSONString() + ";指令号:" + taskNo)
.build();
logDto2.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto2);
return jo;
}

View File

@@ -738,7 +738,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
public String applyIn(JSONObject param) {
try {
MDC.put(log_file_type, log_type);
log.info("applyIn-----agv申请进入输入参数{}", param);
log.info("applyIn-----agv申请进入,请求lms参数{}", param);
String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue();
AddressDto addressDto = addressService.findByCode("applyIn");
String url = wmsurl + addressDto.getMethods_url();
@@ -759,13 +759,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
log.info("applyIn-----输出参数{}", "返回结果为空");
return null;
}
String type = "";
if (result2.getStatus() == 200) {
type = "info";
} else {
type = "error";
}
log.info("secondaryAllocationPoint-----输出参数{}", result2.body());
log.info("applyIn-----agv申请进入,lms返回参数{}", result2.body());
LuceneLogDto luceneLogDto = new LuceneLogDto(4, "applyIn", String.valueOf(result2.getStatus()),
JSON.toJSONString(param), String.valueOf(result2.body()), "agv申请进入");
luceneLogService.interfaceExecuteLog(luceneLogDto);

View File

@@ -498,7 +498,7 @@ public interface InstructionService extends CommonService<InstructionMybatis> {
List<Instruction> findByCodeAndExcute(String nextDeviceCode);
List<Instruction> findByNextCode(String nextDeviceCode);
List<Instruction> findByNextCode(String taskCode,String nextDeviceCode);
List<Instruction> findReadyIns();
List<Instruction> findReadyIns2();

View File

@@ -503,6 +503,11 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
if (regional(dto.getStart_device_code(), dto.getNext_device_code())) {
throw new BadRequestException(LangProcess.msg("error_regional_max"));
}
//判断是否存在到同一个等待点的任务
List<Instruction> byCodeAndExcute = this.findByNextCode(task_code,dto.getNext_device_code());
if (CollUtil.isNotEmpty(byCodeAndExcute)) {
throw new BadRequestException("存在相同终点的任务,无法生成指令");
}
String start_device_code = dto.getStart_device_code();
// if (StrUtil.isNotEmpty(dto.getTask_code())) {
@@ -628,7 +633,7 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
throw e;
// throw e;
}
InstructionMybatis entity = ConvertUtil.convert(dto, InstructionMybatis.class);
instructionMapper.insert(entity);
@@ -792,6 +797,10 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
@Transactional(rollbackFor = Exception.class)
public void finish(String id) {
InstructionDto entity = this.findById(id);
//execute_code=1 取货完成
if (ObjectUtil.isNotEmpty(entity.getExecute_code())&& !entity.getExecute_code().equals("1")){
throw new BadRequestException("agv还未取货不允许点完成");
}
// if (entity == null) throw new BadRequestException(LangProcess.msg("error_sysAuth"));
String currentUsername = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
@@ -1135,6 +1144,10 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
if (entity == null) {
throw new BadRequestException(LangProcess.msg("error_sysAuth"));
}
//execute_code=1 取货完成
if (ObjectUtil.isNotEmpty(entity.getExecute_code()) && entity.getExecute_code().equals("1")){
throw new BadRequestException("agv已经取货完成不允许取消");
}
TaskDto task = taskService.findByCodeFromCache(entity.getTask_code());
if (StrUtil.isEmpty(entity.getRoute_plan_code())) {
entity.setRoute_plan_code(task.getRoute_plan_code());
@@ -1149,30 +1162,14 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
//
// } else
//1=XZ 2=NDC
if (ObjectUtil.isNotEmpty(entity.getAgv_system_type()) && entity.getAgv_system_type().equals(CommonFinalParam.TWO)) {
// NDC agv指令不当场取消指令,需要等agv上报
if ("1".equals(entity.getSend_status())) {
ndcAgvService.deleteAgvInstToNDC(BeanUtil.copyProperties(entity, Instruction.class));
flag = true;
} else {
flag = true;
}
} else if (ObjectUtil.isNotEmpty(entity.getAgv_system_type()) && entity.getAgv_system_type().equals(CommonFinalParam.ONE)
&& !StrUtil.equals(entity.getSend_status(), "2")) {
XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class);
xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code());
flag = true;
} else if (ObjectUtil.isNotEmpty(entity.getAgv_system_type()) && entity.getAgv_system_type().equals(AgvSystemTypeEnum.XG_System_Type)
&& !StrUtil.equals(entity.getSend_status(), "2")) {
XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class);
xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code());
flag = true;
} else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "5")
if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "5")
&& !StrUtil.equals(entity.getSend_status(), "2")) {
KeCongAgvService keCongAgvService = SpringContextHolder.getBean(KeCongAgvService.class);
log.info("开始删除agv任务");
keCongAgvService.deleteTask(entity.getInstruction_code());
flag = true;
}else {
log.info("只删除系统任务!");
flag = true;
}
if (flag) {
@@ -1902,9 +1899,10 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
@Override
public List<Instruction> findByNextCode(String next_code) {
List<Instruction> instructionList = instructions.stream().filter(item -> item.getNext_device_code().equals(next_code)).collect(Collectors.toList());
public List<Instruction> findByNextCode(String taskCode,String next_code) {
List<Instruction> instructionList = instructions.stream().filter(item -> item.getNext_device_code().equals(next_code)
&& !item.getTask_code().equals(taskCode)
&& (StrUtil.equals(item.getInstruction_status(), InstructionStatusEnum.READY.getIndex()) || StrUtil.equals(item.getInstruction_status(), InstructionStatusEnum.BUSY.getIndex()))).collect(Collectors.toList());
return instructionList;
}

View File

@@ -244,6 +244,8 @@ public class Task extends CommonModel<Task> implements Serializable {
private String interaction_json;
private String car_no;
private Integer agv_action_type;

View File

@@ -57,7 +57,7 @@ public class TaskDto implements Serializable {
/**
* 车号
*/
private String carno;
private String car_no;
/**
* 复合任务

View File

@@ -893,6 +893,11 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
throw new BadRequestException(LangProcess.msg("error_sysAuth"));
}
//execute_code=1 取货完成
if (ObjectUtil.isNotEmpty(entity.getExecute_code())&& !entity.getExecute_code().equals("1")){
throw new BadRequestException("agv还未取货不允许点完成");
}
InstructionDto instdto = instructionService.findByTaskid(taskIdAndStatus.getTask_id(), "instruction_status <2 ");
if (instdto != null) {
throw new BadRequestException(LangProcess.msg("task_insHas"));
@@ -920,6 +925,10 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
if (entity == null) {
throw new BadRequestException(LangProcess.msg("error_sysAuth"));
}
//execute_code=1 取货完成
if (ObjectUtil.isNotEmpty(entity.getExecute_code()) && entity.getExecute_code().equals("1")){
throw new BadRequestException("agv已经取货完成不允许点取消");
}
InstructionDto instdto = instructionService.findByTaskid(id, "instruction_status <2 ");
if (instdto != null) {
@@ -1162,7 +1171,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
map.put("路由方案编码", acsTask.getRoute_plan_code());
map.put("是否需要反馈上位系统", acsTask.getIs_needfeedback());
map.put("备注", acsTask.getRemark());
map.put("agv车号", acsTask.getCarno());
map.put("agv车号", acsTask.getCar_no());
map.put("是否启用", acsTask.getIs_active());
map.put("是否删除", acsTask.getIs_delete());
map.put("创建者", acsTask.getCreate_by());
@@ -1797,8 +1806,8 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
if (ObjectUtil.isNotEmpty(entity.getWeight())) {
feed_jo.put("weight", entity.getWeight());
}
if (ObjectUtil.isNotEmpty(entity.getCarno())) {
feed_jo.put("car_no", entity.getCarno());
if (ObjectUtil.isNotEmpty(entity.getCar_no())) {
feed_jo.put("car_no", entity.getCar_no());
}
// JSONArray ja = new JSONArray();
// ja.add(feed_jo);

View File

@@ -104,6 +104,12 @@ public class AutoCreateInst {
if (!StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE)) {
continue;
}
//判断是否存在到同一个等待点的任务
List<Instruction> byCodeAndExcute = instructionService.findByNextCode(taskcode,next_device_code);
if (CollUtil.isNotEmpty(byCodeAndExcute)) {
log.info("存在相同等待点的任务,无法生成指令");
continue;
}
// RouteLineDto routeLineDto = shortPathsList.get(0);
// String path = routeLineDto.getPath();