add:新增功能提交;

This commit is contained in:
2026-05-21 15:10:47 +08:00
parent 8a7cd4332c
commit eca0edad64
670 changed files with 2095 additions and 651 deletions

View File

@@ -10,6 +10,8 @@ public interface AcsConfig {
String ONEPOINTMAXTASK = "onePointMaxTask";
//同一任务创建最大指令数
String MAXINSTNUMBER = "maxInstNumber";
//同一任务创建最大RT车指令数
String MAXRTINSTNUMBER = "maxRtInstNumber";
//创建任务检查
String CREATETASKCHECK = "createTaskCheck";
//撤销任务检查

View File

@@ -1,25 +1,19 @@
package org.nl.acs.device_driver.basedriver.agv.ndcone;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import jodd.util.StringUtil;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.AcsConfig;
import org.nl.acs.agv.server.NDCAgvService;
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RequestMethodEnum;
import org.nl.acs.device_driver.basedriver.agv.utils.AgvActionEnum;
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractDeviceDriver;
import org.nl.acs.device_driver.storage.standard_storage.StandardStorageDeviceDriver;
import org.nl.acs.ext.wms.data.one.feedBackTaskStatus.FeedBackTaskStatusRequest;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
@@ -37,13 +31,11 @@ import org.nl.common.exception.BadRequestException;
import org.nl.config.SpringContextHolder;
import org.nl.config.thread.ThreadPoolExecutorUtil;
import org.nl.system.service.lucene.LuceneExecuteLogService;
import org.nl.system.service.lucene.dto.LuceneLogDto;
import org.nl.system.service.param.ISysParamService;
import org.nl.system.service.param.impl.SysParamServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
/**
@@ -149,6 +141,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
transportOrder = inst.getTask_code();
//车辆分配任务时 状态为1 执行中
task.setTask_status("1");
//车辆执行任务开始计时字段
if (StrUtil.isEmpty(task.getTo_x())) {
task.setTo_x(DateUtil.now());
}
//添加车号
if (StrUtil.isEmpty(task.getCar_no())) {
task.setCar_no(String.valueOf(carno));
}
taskserver.update(task);
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase" + "反馈:" + data);
//车辆状态归零
@@ -179,6 +179,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
feed_jo.put("task_status","10");
JSONArray ja = new JSONArray();
ja.add(feed_jo);
log.info("acs开始请求二次分配任务号{}",task.getTask_code());
acsToWmsService.feedTaskStatus(ja);
Instruction inst1 = instructionService.findBytaskCode(inst.getTask_id());
log.info("二次分配指令终点是{}",inst1.getNext_point_code());

View File

@@ -46,6 +46,7 @@ public class CreateTaskRequest extends BaseRequest {
*/
String vehicle_code2;
/**
* 载具类型
*/

View File

@@ -7,7 +7,6 @@ import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.domain.Device;
@@ -20,13 +19,14 @@ import org.nl.acs.ext.wms.data.one.CreateTaskRequest;
import org.nl.acs.ext.wms.data.one.CreateTaskResponse;
import org.nl.acs.ext.wms.service.WmsToAcsService;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.storage_cell.domain.StorageCell;
import org.nl.acs.storage_cell.service.mapper.StorageCellMapper;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.common.exception.BadRequestException;
import org.nl.system.service.lucene.LuceneExecuteLogService;
import org.nl.system.service.lucene.dto.LuceneLogDto;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -36,6 +36,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
@RequiredArgsConstructor
@@ -54,12 +55,16 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
@Autowired
private TaskService taskserver;
@Autowired
private RedissonClient redissonClient;
private String log_file_type = "log_file_type";
private String log_type = "LMS请求ACS";
@Override
public CreateTaskResponse crateTask(String param) {
try {
MDC.put(log_file_type, log_type);
log.info("ACS接收WMS任务-----输入参数{}", param);
@@ -117,7 +122,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
String next_height = request.getNext_height();
String params2 = request.getParams2();
Map<String, String> params = request.getParams();
String start_point_code = "";
String start_point_code2 = "";
String next_point_code = "";
@@ -147,87 +151,13 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
errArr.add(json);
continue;
}
if (StrUtil.equals(task_type, "8")) {
next_device_code = request.getPut_device_code();
put_device_code = request.getNext_device_code();
}
// StorageCell start_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper)
// .eq(StorageCell::getStorage_code, start_device_code)
// .one();
// StorageCell next_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper)
// .eq(StorageCell::getStorage_code, next_device_code)
// .one();
// StorageCell start2_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper)
// .eq(StorageCell::getStorage_code, start_device_code2)
// .one();
// StorageCell next2_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper)
// .eq(StorageCell::getStorage_code, next_device_code2)
// .one();
// StorageCell put_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper)
// .eq(StorageCell::getStorage_code, put_device_code)
// .one();
//
// JSONObject start_device_json = (JSONObject) JSONObject.toJSON(start_storageCell);
// if (!ObjectUtil.isEmpty(start_device_json)) {
// start_point_code = (String) start_device_json.get("parent_storage_code") == null ? start_device_code : (String) start_device_json.get("storage_code");
// }
// JSONObject next_device_json = (JSONObject) JSONObject.toJSON(next_storageCell);
// if (!ObjectUtil.isEmpty(next_device_json)) {
// next_point_code = (String) next_device_json.get("parent_storage_code") == null ? next_point_code : (String) next_device_json.get("storage_code");
// }
// JSONObject start_device_json2 = (JSONObject) JSONObject.toJSON(start2_storageCell);
// if (!ObjectUtil.isEmpty(start_device_json2)) {
// start_point_code2 = (String) start_device_json2.get("parent_storage_code") == null ? start_device_code2 : (String) start_device_json2.get("storage_code");
// }
// JSONObject next_device_json2 = (JSONObject) JSONObject.toJSON(next2_storageCell);
// if (!ObjectUtil.isEmpty(next_device_json2)) {
// next_point_code2 = (String) next_device_json2.get("parent_storage_code") == null ? next_device_code2 : (String) next_device_json2.get("storage_code");
// }
// JSONObject put_device_json = (JSONObject) JSONObject.toJSON(put_storageCell);
// if (!ObjectUtil.isEmpty(put_device_json)) {
// put_point_code = (String) put_device_json.get("parent_storage_code") == null ? put_device_code : (String) put_device_json.get("storage_code");
// }
// if (StrUtil.isNotEmpty(start_point_code) && start_point_code.indexOf("-") > 0) {
// String str[] = start_point_code.split("-");
// start_device_code = str[0];
// } else {
// start_device_code = start_point_code;
// }
// if (StrUtil.isNotEmpty(next_point_code) && next_point_code.indexOf("-") > 0) {
// String str[] = next_point_code.split("-");
// next_device_code = str[0];
// } else {
// next_device_code = next_point_code;
// }
// if (StrUtil.isNotEmpty(start_point_code2) && start_point_code2.indexOf("-") > 0) {
// String str[] = start_point_code2.split("-");
// start_device_code2 = str[0];
// } else {
// start_device_code2 = start_point_code2;
// }
//
// if (StrUtil.isNotEmpty(next_point_code2) && next_point_code2.indexOf("-") > 0) {
// String str[] = next_point_code2.split("-");
// next_device_code2 = str[0];
// } else {
// next_device_code2 = next_point_code2;
// }
//
// if (StrUtil.isNotEmpty(put_point_code) && put_point_code.indexOf("-") > 0) {
// String str[] = put_point_code.split("-");
// put_device_code = str[0];
// } else {
// put_device_code = put_point_code;
// }
if (StrUtil.isEmpty(route_plan_code)) {
route_plan_code = "normal";
}
TaskDto taskDto = taskserver.findByCodeFromCache(task_code);
if (taskDto != null) {
JSONObject json = new JSONObject();
@@ -250,7 +180,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
}
start_point_code=start_device_code;
next_point_code=next_device_code;
if (StrUtil.isEmpty(start_point_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
@@ -267,7 +196,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
errArr.add(json);
continue;
}
JSONObject jo = new JSONObject();
jo.put("task_id", IdUtil.simpleUUID());
jo.put("task_code", task_code);
@@ -312,7 +240,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
if (!StrUtil.isEmpty(ext_task_id)) {
jo.put("ext_task_id", ext_task_id);
}
TaskDto task_dto = jo.toJavaObject(TaskDto.class);
try {
taskserver.create(task_dto);
@@ -338,6 +265,239 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
}
response.setErrArr(errArr);
}
LuceneLogDto logDto1 = LuceneLogDto.builder()
.device_code("ACS接收WMS任务")
.content("ACS接收WMS任务-----返回参数:" + JSON.toJSONString(response))
.build();
logDto1.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto1);
log.info("ACS接收WMS任务--------------:输出参数:" + JSON.toJSONString(response));
return response;
} catch (Exception e) {
log.error("获取分布式锁或执行任务异常,可能 Redis 不可用", e);
CreateTaskResponse errorResp = new CreateTaskResponse();
errorResp.setStatus(500);
errorResp.setMessage("系统异常:" + e.getMessage());
return errorResp;
} finally {
MDC.remove(log_file_type);
}
}
public CreateTaskResponse crateTask1(String param) {
RLock lock = redissonClient.getLock(this.getClass().getName() + "-crateTask");
boolean locked = false;
try {
// 尝试获取分布式锁,避免并发创建相同任务号
locked = lock.tryLock(5, 30, TimeUnit.SECONDS);
if (!locked) {
log.warn("未获取到分布式锁,系统繁忙");
CreateTaskResponse errorResp = new CreateTaskResponse();
errorResp.setStatus(400);
errorResp.setMessage("系统繁忙,请稍后重试");
return errorResp;
}
MDC.put(log_file_type, log_type);
log.info("ACS接收WMS任务-----输入参数{}", param);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("ACS接收WMS任务")
.content("ACS接收WMS任务-----输入参数:" + param)
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
JSONArray datas = JSONArray.parseArray(param);
CreateTaskResponse response = new CreateTaskResponse();
JSONArray errArr = new JSONArray();
for (int i = 0; i < datas.size(); i++) {
String data = datas.get(i).toString();
CreateTaskRequest request = JsonUtl.format(data, CreateTaskRequest.class);
String paper_array = request.getPaper_array();
String ext_task_id = request.getExt_task_uuid();
String task_code = request.getTask_code();
//车辆类型
String car_type=request.getCar_type();
String car_width=request.getCar_width();
String start_device_code = request.getStart_device_code();
String start_device_code2 = request.getStart_device_code2();
String next_device_code = request.getNext_device_code();
String next_device_code2 = request.getNext_device_code2();
String put_device_code = request.getPut_device_code();
String task_type = request.getTask_type();
if(task_type.equals("1")&&car_type.equals("2")){
start_device_code=start_device_code+"-R";
}
String priority = request.getPriority();
String vehicle_code = request.getVehicle_code();
String vehicle_code2 = request.getVehicle_code2();
String vehicle_type = request.getVehicle_type();
String route_plan_code = request.getRoute_plan_code();
String class_type = request.getClass_type();
String truss_type = request.getTruss_type();
Integer agv_action_type = request.getAgv_action_type();
String empty_site = request.getEmpty_site();
String is_bushing = request.getIs_bushing();
String is_pulling = request.getIs_pulling();
String size = request.getSize();
String version = request.getVersion();
String bushing_num = request.getBushing_num();
String storage_task_type = request.getDtl_type();
String agv_system_type = request.getAgv_system_type();
String remark = request.getRemark();
double oven_time = 0.00d;
if (StrUtil.isNotEmpty(request.getOven_time())) {
oven_time = Double.parseDouble(request.getOven_time());
}
String temperature = request.getTemperature();
String start_height = request.getStart_height();
String next_height = request.getNext_height();
String params2 = request.getParams2();
Map<String, String> params = request.getParams();
String start_point_code = "";
String start_point_code2 = "";
String next_point_code = "";
String next_point_code2 = "";
String put_point_code = "";
if (StrUtil.isEmpty(task_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "任务号不能为空");
errArr.add(json);
continue;
}
if (StrUtil.isEmpty(start_device_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "起点不能为空");
errArr.add(json);
continue;
}
if (StrUtil.isEmpty(next_device_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "终点不能为空");
errArr.add(json);
continue;
}
if (StrUtil.equals(task_type, "8")) {
next_device_code = request.getPut_device_code();
put_device_code = request.getNext_device_code();
}
if (StrUtil.isEmpty(route_plan_code)) {
route_plan_code = "normal";
}
TaskDto taskDto = taskserver.findByCodeFromCache(task_code);
if (taskDto != null) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "存在相同的任务号:" + task_code);
errArr.add(json);
continue;
}
if (!StrUtil.isEmpty(vehicle_code)) {
TaskDto vehicle_dto = taskserver.findByContainer(vehicle_code);
if (vehicle_dto != null) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "已存在任务编号为" + vehicle_dto.getTask_code() + "托盘号:" + vehicle_code);
errArr.add(json);
continue;
}
}
start_point_code=start_device_code;
next_point_code=next_device_code;
if (StrUtil.isEmpty(start_point_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", request.getStart_device_code() + " 该设备号未找到对应点位");
errArr.add(json);
continue;
}
if (StrUtil.isEmpty(next_point_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", request.getNext_device_code() + " 该设备号未找到对应点位");
errArr.add(json);
continue;
}
JSONObject jo = new JSONObject();
jo.put("task_id", IdUtil.simpleUUID());
jo.put("task_code", task_code);
jo.put("start_point_code", start_point_code);
jo.put("next_point_code", next_point_code);
jo.put("start_point_code2", start_point_code2);
jo.put("next_point_code2", next_point_code2);
jo.put("put_point_code", put_point_code);
jo.put("start_parent_code", start_point_code);
jo.put("next_parent_code", next_point_code);
jo.put("start_device_code", start_device_code);
jo.put("next_device_code", next_device_code);
jo.put("start_device_code2", start_device_code2);
jo.put("next_device_code2", next_device_code2);
jo.put("put_device_code", put_device_code);
jo.put("agv_action_type", agv_action_type);
jo.put("priority", priority);
jo.put("vehicle_code", vehicle_code);
jo.put("vehicle_code2", vehicle_code2);
jo.put("vehicle_type", vehicle_type);
jo.put("storage_task_type", storage_task_type);
jo.put("agv_system_type", agv_system_type);
jo.put("start_height", start_height);
jo.put("next_height", next_height);
jo.put("oven_time", (int) Math.ceil(oven_time));
jo.put("remark", remark);
jo.put("params", params);
jo.put("params2", params2);
jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type));
jo.put("class_type", class_type);
jo.put("route_plan_code", route_plan_code);
jo.put("paper_array", JSONUtil.toJsonStr(paper_array));
jo.put("truss_type", JSONUtil.toJsonStr(truss_type));
jo.put("empty_site", JSONUtil.toJsonStr(empty_site));
jo.put("is_bushing", JSONUtil.toJsonStr(is_bushing));
jo.put("is_pulling", JSONUtil.toJsonStr(is_pulling));
jo.put("size", JSONUtil.toJsonStr(size));
jo.put("version", JSONUtil.toJsonStr(version));
jo.put("bushing_num", JSONUtil.toJsonStr(bushing_num));
jo.put("car_type",car_type);
jo.put("car_width",car_width);
if (!StrUtil.isEmpty(ext_task_id)) {
jo.put("ext_task_id", ext_task_id);
}
TaskDto task_dto = jo.toJavaObject(TaskDto.class);
try {
taskserver.create(task_dto);
} catch (Exception e) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", e.getMessage());
errArr.add(json);
continue;
}
}
if (ObjectUtil.isEmpty(errArr)) {
response.setStatus(200);
response.setCode(200);
response.setMessage("success");
} else {
response.setStatus(400);
if (ObjectUtil.isNotEmpty(errArr)) {
response.setMessage(errArr.getJSONObject(0).getString("message"));
} else {
response.setMessage("false");
}
response.setErrArr(errArr);
}
LuceneLogDto logDto1 = LuceneLogDto.builder()
.device_code("ACS接收WMS任务")
.content("ACS接收WMS任务-----返回参数:" + JSON.toJSONString(response))
@@ -347,7 +507,21 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
log.info("ACS接收WMS任务--------------:输出参数:" + JSON.toJSONString(response));
return response;
} catch (Exception e) {
log.error("获取分布式锁或执行任务异常,可能 Redis 不可用", e);
CreateTaskResponse errorResp = new CreateTaskResponse();
errorResp.setStatus(500);
errorResp.setMessage("系统异常:" + e.getMessage());
return errorResp;
} finally {
// 确保释放锁,且只能释放自己持有的锁
if (locked && lock.isHeldByCurrentThread()) {
try {
lock.unlock();
} catch (Exception e) {
log.error("释放分布式锁失败", e);
}
}
MDC.remove(log_file_type);
}
}

View File

@@ -6,12 +6,10 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
@@ -187,6 +185,7 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
String material_type = (String) whereJson.get("material_type");
String status = (String) whereJson.get("status");
String point_code = (String) whereJson.get("point_code");
String priority = (String) whereJson.get("priority");
String is_over = (String) whereJson.get("is_over");
String instruction_type = (String) whereJson.get("instruction_type");
@@ -196,6 +195,7 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
wrapper.and(StringUtils.isNotBlank(code), instructionMybatis -> instructionMybatis.like(InstructionMybatis::getInstruction_code, code).or().like(InstructionMybatis::getTask_code, code));
wrapper.like(StringUtils.isNotBlank(vehicle_code), InstructionMybatis::getVehicle_code, vehicle_code);
wrapper.eq(StringUtils.isNotBlank(material_type), InstructionMybatis::getMaterial, material_type);
wrapper.eq(StringUtils.isNotBlank(priority), InstructionMybatis::getPriority, priority);
wrapper.eq(StringUtils.isNotBlank(status), InstructionMybatis::getInstruction_status, status);
wrapper.and(StringUtils.isNotBlank(point_code), instructionMybatis -> instructionMybatis.like(InstructionMybatis::getStart_point_code, point_code).or().like(InstructionMybatis::getNext_point_code, point_code));
wrapper.eq(StringUtils.isNotBlank(instruction_type), InstructionMybatis::getInstruction_type, instruction_type);
@@ -368,7 +368,7 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
// dto.setIs_send(task.getLink_num());
// }
// if (task.getTask_type().equals(CommonFinalParam.ONE) || task.getTask_type().equals("2")) {
dto.setInstruction_type(task.getTask_type());
dto.setInstruction_type(task!=null?task.getTask_type():dto.getInstruction_type());
// } else if (false) {
//
// } else {
@@ -444,7 +444,7 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
} catch (Exception e) {
dto.setSend_status("2");
e.printStackTrace();
log.error("");
log.error("指令下发失败,异常信息:" + e.getMessage());
}
InstructionMybatis entity = ConvertUtil.convert(dto, InstructionMybatis.class);
instructionMapper.insert(entity);
@@ -776,15 +776,86 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
Task task = new LambdaQueryChainWrapper<>(taskMapper)
.eq(Task::getTask_id, insttaskid)
.one();
// =0 则不用再次请求
// =0 则不用再次请求,单路由任务
if (StrUtil.equals(task.getRequest_again(), "0")) {
if (StrUtil.equals(task.getNext_device_code(), instnextdevice)) {
taskService.finish(task.getTask_id());
} else {
//多路由任务
finishAndCreateNextInst((Instruction) entity);
}
}
//查询是否存在出库任务如果存在按优先级和创建时间创建1条出库任务的指令
List<Task> taskList = new LambdaQueryChainWrapper<>(taskMapper)
.eq(Task::getTask_status, "0")
.eq(Task::getIs_delete, "0")
.eq(Task::getCar_type, task.getCar_type())
.eq(Task::getTask_type, "1".equals(task.getTask_type()) ? "2" : "1")
.orderByDesc(Task::getPriority)
.orderByAsc(Task::getTask_code)
.list();
//指令列表
List<InstructionMybatis> instructionList = new LambdaQueryChainWrapper<>(instructionMapper)
.lt(InstructionMybatis::getInstruction_status, InstructionStatusEnum.FINISHED.getIndex())
.list();
if (ObjectUtil.isNotEmpty(taskList)) {
TaskDto acsTask = null;
List<TaskDto> priorityTaskList = ConvertUtil.convertList(taskList, TaskDto.class);
if (task.getTask_type().equals("2")) {
//包含"BCPRK"或"CPRK"的任务
List<TaskDto> collection1 = new ArrayList<>();
List<TaskDto> collection2 = new ArrayList<>();
// 分组任务
for (TaskDto taskDto : priorityTaskList) {
String startDeviceCode = taskDto.getStart_device_code();
if (startDeviceCode != null && (startDeviceCode.contains("BCPRK") || startDeviceCode.contains("CPRK"))) {
collection1.add(taskDto);
} else {
collection2.add(taskDto);
}
}
// 包含"BCPRK"或"CPRK"的指令
List<InstructionMybatis> collection3 = new ArrayList<>();
// 分组指令
for (InstructionMybatis instruction : instructionList) {
String startDeviceCode = instruction.getStart_device_code();
if (startDeviceCode != null && (startDeviceCode.contains("BCPRK") || startDeviceCode.contains("CPRK"))) {
collection3.add(instruction);
}
}
// 处理集合1与集合3的相同入库点
if (ObjectUtil.isNotEmpty(collection1) && ObjectUtil.isNotEmpty(collection3)) {
// 获取集合3中所有startDeviceCode.split("-")[0]
Set<String> collection3Prefixes = collection3.stream()
.map(InstructionMybatis::getStart_device_code)
.filter(code -> code != null && code.contains("-"))
.map(code -> code.split("-")[0])
.collect(Collectors.toSet());
// 移除不符合条件的任务
collection1.removeIf(taskDto -> {
String startDeviceCode = taskDto.getStart_device_code();
return startDeviceCode != null
&& startDeviceCode.contains("-")
&& collection3Prefixes.contains(startDeviceCode.split("-")[0]);
});
}
if (ObjectUtil.isNotEmpty(collection1)) {
acsTask = collection1.get(0);
} else {
if (ObjectUtil.isNotEmpty(collection2)) {
acsTask = collection2.get(0);
}
}
} else {
acsTask = priorityTaskList.get(0);
}
if (acsTask != null) {
//优先级最高
acsTask.setPriority("98");
acsTask.setUpdate_time(DateUtil.now());
taskService.update(acsTask);
}
}
removeByCodeFromCache(entity.getInstruction_code());
// this.reload();
}

View File

@@ -98,6 +98,9 @@ public class Task extends CommonModel<Task> implements Serializable {
/** 起始点位编码 */
private String start_point_code;
/**车号*/
private String car_no;
/** 起始设备编码 */
private String start_device_code;

View File

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
@@ -115,6 +116,7 @@ public class TaskController {
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("手动创建指令")
/** 手动创建指令 */
@PostMapping(value = "/createInst/{id}")
@@ -165,4 +167,14 @@ public class TaskController {
taskService.downloadTaskLogging(taskService.getTaskList(whereJson), response);
}
@SaIgnore
@Log("查询任务报表")
/** 查询任务报表 */
@PostMapping(value = "/queryTaskSheet")
public ResponseEntity<Object> queryTaskSheet(@RequestBody Map whereJson) {
return new ResponseEntity<>(taskService.queryTaskSheet(whereJson), HttpStatus.OK);
}
}

View File

@@ -8,6 +8,7 @@ import org.nl.acs.task.domain.Task;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.acs.task.service.dto.TaskQueryParam;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -143,6 +144,15 @@ public interface TaskService extends CommonService<Task> {
*/
List<TaskDto> queryAllByStatus(String task_status);
/**
* 根据状态查询
*
* @param task_status task_status
* @return AcsTask
*/
List<TaskDto> queryAllByInStatus(Set<String> task_status);
/**
* 查询所有数据不分页
@@ -495,4 +505,8 @@ public interface TaskService extends CommonService<Task> {
* @return 指令终点 B
*/
String queryAssignedByDeviceCode(String device_code, String task_nextDeice_code);
List<JSONObject> queryTaskSheet(Map whereJson);
}

View File

@@ -293,6 +293,12 @@ public class TaskDto implements Serializable {
private String agv_system_type;
/**
* 车号
*/
private String car_no;
/**
* 烘箱时间s
*/

View File

@@ -1,7 +1,7 @@
package org.nl.acs.task.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.nl.acs.AcsConfig;
import org.nl.acs.agv.server.XianGongAgvService;
@@ -29,13 +30,13 @@ import org.nl.acs.device.service.DeviceAssignedService;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device.service.dto.DeviceAssignedDto;
import org.nl.acs.device.service.impl.DeviceServiceImpl;
import org.nl.acs.device_driver.DeviceDriverDefination;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.domain.Instruction;
import org.nl.acs.instruction.domain.InstructionMybatis;
import org.nl.acs.instruction.enums.InstructionStatusEnum;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.InstructionDto;
import org.nl.acs.instruction.service.mapper.InstructionMapper;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.domain.RoutePlan;
@@ -55,7 +56,6 @@ import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.FileUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.common.utils.StringUtils;
import org.nl.config.SpringContextHolder;
import org.nl.config.language.LangProcess;
import org.nl.system.service.param.ISysParamService;
@@ -105,7 +105,8 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
private DeviceAssignedService deviceAssignedService;
@Autowired
private InstructionService instructionService;
@Autowired
private InstructionMapper instructionMapper;
/**
* 缓存
* 存储未完成的任务信息
@@ -199,6 +200,16 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
return ConvertUtil.convertList(taskList, TaskDto.class);
}
public List<TaskDto> queryAllByInStatus(Set<String> task_status) {
List<Task> taskList = new LambdaQueryChainWrapper<>(taskMapper)
.in(Task::getTask_status, task_status)
.eq(Task::getIs_delete, "0")
.orderByDesc(Task::getPriority)
.orderByAsc(Task::getTask_code)
.list();
return ConvertUtil.convertList(taskList, TaskDto.class);
}
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
@@ -208,6 +219,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
String status = (String) whereJson.get("status");
String point_code = (String) whereJson.get("point_code");
String is_over = (String) whereJson.get("is_over");
String priority = (String) whereJson.get("priority");
IPage<Task> queryPage = PageUtil.toMybatisPage(page);
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
@@ -220,6 +232,9 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
if (!StrUtil.isEmpty(material_type)) {
wrapper.eq(Task::getMaterial, material_type);
}
if (!StrUtil.isEmpty(priority)) {
wrapper.eq(Task::getPriority, priority);
}
if (!StrUtil.isEmpty(status)) {
wrapper.eq(Task::getTask_status, status);
}
@@ -233,14 +248,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
wrapper.lt(Task::getTask_status, TaskStatusEnum.FINISHED.getIndex());
}
}
// 关键修改:替换原有的 wrapper.le(Task::getTask_status, 1)
// 方案1使用 in 方法,直接指定需要的 task_status 值(推荐,简洁高效)
wrapper.in(Task::getTask_status, 1, 4 ,10 ,0);
// 方案2使用 or 拼接 eq 条件效果与方案1一致适合复杂条件扩展
// wrapper.eq(Task::getTask_status, 1).or().eq(Task::getTask_status, 4);
wrapper.orderByDesc(Task::getCreate_time);
IPage<Task> taskPage = taskMapper.selectPage(queryPage, wrapper);
final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(taskPage, TaskDto.class));
@@ -313,6 +321,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
@Override
public Map<String, Object> getAll(Map whereJson, Pageable page) {
String task_code = (String) whereJson.get("task_code");
String car_no = (String) whereJson.get("car_no");
String vehicle_code = (String) whereJson.get("vehicle_code");
String material_type = (String) whereJson.get("material_type");
String status = (String) whereJson.get("status");
@@ -322,6 +331,9 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
IPage<Task> queryPage = PageUtil.toMybatisPage(page);
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
if (!StrUtil.isEmpty(car_no)) {
wrapper.eq(Task::getCar_no, car_no);
}
if (!StrUtil.isEmpty(task_code)) {
wrapper.eq(Task::getTask_code, task_code);
}
@@ -750,6 +762,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
//反馈上位系统任务状态
//判断是否为WMS下发的任务如果是反馈任务状态给WMS
String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue();
//&& !StrUtil.equals(dto.getTask_status(),"0")
if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")&& !StrUtil.equals(dto.getTask_status(), "8")) {
this.feedWmsTaskStatus(entity);
}
@@ -781,10 +794,22 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
entity.setUpdate_time(now);
entity.setUpdate_by(currentUsername);
entity.setTask_status(TaskStatusEnum.FINISHED.getIndex());
//车辆执行任务完成计时字段
entity.setTo_y(now);
Task task = ConvertUtil.convert(entity, Task.class);
if (StrUtil.isNotBlank(entity.getTo_x())) {
DateTime toXTime = DateUtil.parse(entity.getTo_x());
DateTime nowTime = DateUtil.parse(now);
long diffMs = nowTime.getTime() - toXTime.getTime();
if (diffMs < 0) {
diffMs = 0;
}
long totalSeconds = diffMs / 1000;
long minutes = totalSeconds / 60;
long seconds = totalSeconds % 60;
task.setTo_z(String.format("%d.%02d", minutes, seconds));
}
taskMapper.updateById(task);
//移除任务缓存信息
this.removeByCodeFromCache(entity.getTask_code());
//反馈上位系统任务状态
@@ -830,6 +855,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
//判断是否为WMS下发的任务如果是反馈任务状态给WMS
String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue();
if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) {
log.info("acs手动取消任务任务号为"+entity.getTask_code());
this.feedWmsTaskStatus(entity);
}
}
@@ -847,7 +873,14 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
if (inst != null) {
throw new BadRequestException(LangProcess.msg("task_insRun"));
}
int unfinishedInstructionCount = new LambdaQueryChainWrapper<>(instructionMapper)
.lt(InstructionMybatis::getInstruction_status, InstructionStatusEnum.FINISHED.getIndex())
.count();
String maxInstNumber = paramService.findByCode(AcsConfig.MAXINSTNUMBER).getValue();
int maxInst = Integer.parseInt(maxInstNumber);
if (unfinishedInstructionCount >= maxInst) {
throw new BadRequestException("超过最大指令数:"+maxInstNumber+"个,请等待指令列表完成后再创建!");
}
String taskid = acsTask.getTask_id();
String taskcode = acsTask.getTask_code();
String car_type=acsTask.getCar_type();
@@ -1237,8 +1270,10 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
@NotNull
private LambdaQueryWrapper<Task> getTaskLambdaQueryWrapper(Map whereJson) {
String task_code = (String) whereJson.get("task_code");
String task_type = (String) whereJson.get("task_type");
String car_no = (String) whereJson.get("car_no");
String vehicle_code = (String) whereJson.get("vehicle_code");
String material_type = (String) whereJson.get("material_type");
// String material_type = (String) whereJson.get("material_type");
String status = (String) whereJson.get("status");
String point_code = (String) whereJson.get("point_code");
String create_time = (String) whereJson.get("createTime");
@@ -1248,12 +1283,15 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
if (!StrUtil.isEmpty(task_code)) {
wrapper.eq(Task::getTask_code, task_code);
}
if (!StrUtil.isEmpty(car_no)) {
wrapper.eq(Task::getCar_no, car_no);
}
if (!StrUtil.isEmpty(task_type)) {
wrapper.eq(Task::getTask_type, task_type);
}
if (!StrUtil.isEmpty(vehicle_code)) {
wrapper.like(Task::getVehicle_code, vehicle_code);
}
if (!StrUtil.isEmpty(material_type)) {
wrapper.eq(Task::getMaterial, material_type);
}
if (!StrUtil.isEmpty(status)) {
wrapper.eq(Task::getTask_status, status);
}
@@ -1296,16 +1334,19 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
for (JSONObject jsonObject : taskAndInst) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("任务号", jsonObject.getString("task_code"));
map.put("任务类型", jsonObject.getString("task_type"));
map.put("载具号", jsonObject.getString("vehicle_code"));
map.put("任务状态", jsonObject.getString("task_status"));
map.put("任务优先级", jsonObject.getString("priority"));
map.put("起点", jsonObject.getString("start_point_code"));
map.put("终点", jsonObject.getString("next_point_code"));
map.put("物料", jsonObject.getString("matarial"));
map.put("数量", jsonObject.getString("quantity"));
map.put("备注", jsonObject.getString("remark"));
map.put("创建者", jsonObject.getString("create_by"));
map.put("车号", jsonObject.getString("car_no"));
map.put("车辆运行开始时间", jsonObject.getString("to_x"));
map.put("车辆运行结束时间", jsonObject.getString("to_y"));
map.put("车辆运行时长(分钟)", jsonObject.getString("to_z"));
map.put("创建时间", jsonObject.getString("create_time"));
map.put("修改时间", jsonObject.getString("update_time"));
map.put("任务状态", jsonObject.getString("task_status"));
map.put("创建者", jsonObject.getString("create_by"));
list.add(map);
}
FileUtil.downloadExcel(list, response);
@@ -1313,17 +1354,19 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
@Override
public List<JSONObject> getTaskList(Map whereJson) {
whereJson.put("status", "2");
LambdaQueryWrapper<Task> wrapper = getTaskLambdaQueryWrapper(whereJson);
List<Task> taskList = taskMapper.selectList(wrapper);
return Optional
.ofNullable(taskList)
.orElse(new ArrayList<>())
.stream()
.stream().sorted(Comparator.comparing(Task::getTo_x, Comparator.nullsLast(Comparator.naturalOrder())))
.map(task -> {
JSONObject ins = new JSONObject();
ins.put("task_code", task.getTask_code());
ins.put("task_type", "1".equals(task.getTask_type()) ? "入库" : "出库");
ins.put("vehicle_code", task.getVehicle_code());
ins.put("task_status", task.getTask_status());
ins.put("task_status", "完成");
ins.put("priority", task.getPriority());
ins.put("start_point_code", task.getStart_point_code());
ins.put("next_point_code", task.getNext_point_code());
@@ -1332,6 +1375,11 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
ins.put("remark", task.getRemark());
ins.put("create_by", task.getCreate_by());
ins.put("create_time", task.getCreate_time());
ins.put("car_no", task.getCar_no());
ins.put("to_x", task.getTo_x());
ins.put("to_y", task.getTo_y());
ins.put("to_z", task.getTo_z());
ins.put("update_time", task.getUpdate_time());
return ins;
})
.collect(Collectors.toList());
@@ -1485,4 +1533,111 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
}
@Override
public List<JSONObject> queryTaskSheet(Map whereJson) {
//日期格式"2026-05-21"
String create_time = (String) whereJson.get("startDate");
String end_time = (String) whereJson.get("endDate");
if (StrUtil.isEmpty(create_time) || StrUtil.isEmpty(end_time)) {
//获取当天日期
String today = DateUtil.today();
create_time = today + " 00:00:00";
end_time = today + " 23:59:59";
} else {
if (create_time.length() == 10) {
create_time += " 00:00:00";
}
if (end_time.length() == 10) {
end_time += " 23:59:59";
}
}
//1.根据时间获取任务列表
LambdaQueryWrapper<Task> wrapper = getTaskLambdaQueryWrapper(whereJson);
wrapper.between(Task::getCreate_time, create_time, end_time);
List<Task> taskList = taskMapper.selectList(wrapper);
// 计算耗时 (分钟)
java.util.function.Function<Task, Integer> durationCalculator = task -> {
if (StrUtil.isEmpty(task.getTo_x()) || StrUtil.isEmpty(task.getTo_y())) {
return -1;
}
try {
long start = DateUtil.parse(task.getTo_x()).getTime();
long end = DateUtil.parse(task.getTo_y()).getTime();
return (int) ((end - start) / 60000);
} catch (Exception e) {
return -1;
}
};
// 2.区分出入库任务并分组统计
// 入库任务 (type 1), 按next_point_code分组
Map<String, List<Integer>> inTaskMap = taskList.stream()
.filter(t -> "1".equals(t.getTask_type()))
.filter(t -> StrUtil.isNotEmpty(t.getTo_x()) && StrUtil.isNotEmpty(t.getTo_y()))
.collect(Collectors.groupingBy(
t -> {
String code = t.getNext_point_code();
if (StrUtil.isNotEmpty(code)) {
if (code.contains("AB")) return "AB";
if (code.contains("AD")) return "AD";
if (code.contains("AC")) return "AC";
}
return "OTHER";
},
Collectors.mapping(durationCalculator, Collectors.toList())
));
long inTotal = inTaskMap.values().stream().mapToLong(List::size).sum();
// 出库任务 (type 2), 按start_point_code分组
Map<String, List<Integer>> outTaskMap = taskList.stream()
.filter(t -> "2".equals(t.getTask_type()))
.filter(t -> StrUtil.isNotEmpty(t.getTo_x()) && StrUtil.isNotEmpty(t.getTo_y()))
.collect(Collectors.groupingBy(
t -> {
String code = t.getStart_point_code();
if (StrUtil.isNotEmpty(code)) {
if (code.contains("AB")) return "AB";
if (code.contains("AD")) return "AD";
if (code.contains("AC")) return "AC";
}
return "OTHER";
},
Collectors.mapping(durationCalculator, Collectors.toList())
));
long outTotal = outTaskMap.values().stream().mapToLong(List::size).sum();
// 3.组装结果数据
JSONObject result = new JSONObject();
String[] groups = {"AB", "AD", "AC"};
int itemIndex = 1;
for (String group : groups) {
List<Integer> durations = inTaskMap.getOrDefault(group, new ArrayList<>());
long total = inTotal == 0 ? 1 : inTotal;
long c1 = durations.stream().filter(d -> d >= 1 && d < 3).count();
long c2 = durations.stream().filter(d -> d >= 3 && d < 5).count();
long c3 = durations.stream().filter(d -> d >= 5 && d < 8).count();
long c4 = durations.stream().filter(d -> d >= 8).count();
result.put("item" + itemIndex, String.valueOf(c1 * 100 / total));
result.put("item" + (itemIndex + 1), String.valueOf(c2 * 100 / total));
result.put("item" + (itemIndex + 2), String.valueOf(c3 * 100 / total));
result.put("item" + (itemIndex + 3), String.valueOf(c4 * 100 / total));
itemIndex += 4;
}
for (String group : groups) {
List<Integer> durations = outTaskMap.getOrDefault(group, new ArrayList<>());
long total = outTotal == 0 ? 1 : outTotal;
long c1 = durations.stream().filter(d -> d >= 1 && d < 3).count();
long c2 = durations.stream().filter(d -> d >= 3 && d < 5).count();
long c3 = durations.stream().filter(d -> d >= 5 && d < 8).count();
long c4 = durations.stream().filter(d -> d >= 8).count();
result.put("item" + itemIndex, String.valueOf(c1 * 100 / total));
result.put("item" + (itemIndex + 1), String.valueOf(c2 * 100 / total));
result.put("item" + (itemIndex + 2), String.valueOf(c3 * 100 / total));
result.put("item" + (itemIndex + 3), String.valueOf(c4 * 100 / total));
itemIndex += 4;
}
return Collections.singletonList(result);
}
}

View File

@@ -2,13 +2,18 @@ package org.nl.system.service.quartz.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.nl.acs.AcsConfig;
import org.nl.acs.instruction.domain.Instruction;
import org.nl.acs.instruction.domain.InstructionMybatis;
import org.nl.acs.instruction.enums.InstructionStatusEnum;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.mapper.InstructionMapper;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.task.enums.TaskStatusEnum;
@@ -20,9 +25,9 @@ import org.nl.config.SpringContextHolder;
import org.nl.system.service.lucene.LuceneExecuteLogService;
import org.nl.system.service.lucene.dto.LuceneLogDto;
import org.nl.system.service.lucene.impl.LuceneExecuteLogServiceImpl;
import org.nl.system.service.param.ISysParamService;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -39,265 +44,284 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class AutoCreateInst {
private final RedissonClient redissonClient;
private final ISysParamService paramService;
private final InstructionMapper instructionMapper;
private final TaskService taskserver;
private final InstructionService instructionService;
private final DeviceAppService appService;
private final LuceneExecuteLogService luceneExecuteLogService;
/**
* 根据任务状态创建指令、生成下一条指令
* 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货
*/
// public void run() throws Exception {
// log.info("自动生成指令" + DateUtil.now());
// TaskService taskserver = SpringContextHolder.getBean(TaskService.class);
// InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
// RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class);
// DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
// LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogServiceImpl.class);
// List<TaskDto> list = taskserver.queryAllByStatus("0");
// for (int i = 0; i < list.size(); i++) {
// TaskDto acsTask = list.get(i);
// if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.AGV_Task.getIndex()) && !StrUtil.startWith(acsTask.getTask_code(), "-")) {
// continue;
// }
// if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.Truss_Task.getIndex()) && !StrUtil.startWith(acsTask.getTask_code(), "-")) {
// continue;
// }
// Boolean flag=false;
// String taskid = acsTask.getTask_id();
// String taskcode = acsTask.getTask_code();
// String task_type = acsTask.getTask_type();
// String vehiclecode = acsTask.getVehicle_code();
// String priority = acsTask.getPriority();
// String is_send = acsTask.getIs_send();
//
// String start_device_code = acsTask.getStart_device_code();
// String start_point=null;
// if(start_device_code.contains("BCPRK")){
// String[] parts = start_device_code.split("-", 2);
// start_point=parts[0];
// }else if(start_device_code.contains("CPRK")){
// String[] parts = start_device_code.split("-", 2);
// start_point=parts[0];
// }
// if(start_point != null) {
// if (start_point.equals("CPRK1")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("CPRK1")) {
// flag = true;
// }
// }
// } else if (start_point.equals("CPRK2")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("CPRK2")) {
// flag = true;
// }
// }
// } else if (start_point.equals("CPRK3")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("CPRK3")) {
// flag = true;
// }
// }
// } else if (start_point.equals("CPRK4")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("CPRK4")) {
// flag = true;
// }
// }
// } else if (start_point.equals("CPRK5")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("CPRK5")) {
// flag = true;
// }
// }
// }else if (start_point.equals("BCPRK1")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("BCPRK1")) {
// flag = true;
// }
// }
// } else if (start_point.equals("BCPRK2")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("BCPRK2")) {
// flag = true;
// }
// }
// } else if (start_point.equals("BCPRK3")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("BCPRK3")) {
// flag = true;
// }
// }
// } else if (start_point.equals("BCPRK4")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("BCPRK4")) {
// flag = true;
// }
// }
// } else if (start_point.equals("BCPRK5")) {
// List<TaskDto> list1 = taskserver.queryAllByStatus("1");
// for (int j = 0; j < list1.size(); j++) {
// String start_device_code1 = list1.get(j).getStart_device_code();
// String[] parts = start_device_code1.split("-", 2);
// start_point = parts[0];
// if (start_point.equals("BCPRK5")) {
// flag = true;
// }
// }
// }
// }
// if (flag){
// continue;
// }
// String start_point_code = acsTask.getStart_point_code();
//
// String put_device_code = acsTask.getPut_device_code();
// String put_point_code = acsTask.getPut_point_code();
//
// String next_device_code = acsTask.getNext_device_code();
// String next_point_code = acsTask.getNext_point_code();
//
// String route_plan_code = acsTask.getRoute_plan_code();
// String vehicleType = acsTask.getVehicle_type();
// String agv_system_type = acsTask.getAgv_system_type();
//
// String start_height = acsTask.getStart_height();
// String next_height = acsTask.getNext_height();
// String car_type=acsTask.getCar_type();
// String car_width=acsTask.getCar_width();
//
//
// if (StrUtil.equals(is_send, "0")) {
// continue;
// }
//
//// //校验路由关系
//// List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code);
//// if (ObjectUtils.isEmpty(shortPathsList)) {
//// acsTask.setRemark("路由不通无法生成指令");
//// taskserver.updateByCodeFromCache(acsTask);
//// continue;
//// }
////
//// if (!StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE)) {
//// continue;
//// }
//// RouteLineDto routeLineDto = shortPathsList.get(0);
//// String path = routeLineDto.getPath();
//// String type = routeLineDto.getType();
//// String[] str = path.split("->");
//// List<String> pathlist = Arrays.asList(str);
//// int index = 0;
//// for (int m = 0; m < pathlist.size(); m++) {
//// if (pathlist.get(m).equals(start_device_code)) {
//// index = m + 1;
//// break;
//// }
//// }
//// next_device_code = pathlist.get(index);
//
// if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) {
// next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z();
// } else {
// next_point_code = next_device_code;
// }
//
// Instruction instdto = new Instruction();
// instdto.setInstruction_type(task_type);
// instdto.setInstruction_id(IdUtil.simpleUUID());
// instdto.setRoute_plan_code(route_plan_code);
// instdto.setRemark(acsTask.getRemark());
// instdto.setMaterial(acsTask.getMaterial());
// instdto.setQuantity(acsTask.getQuantity());
// instdto.setTask_id(taskid);
// instdto.setTask_code(taskcode);
// instdto.setVehicle_code(vehiclecode);
// String now = DateUtil.now();
// instdto.setCreate_time(now);
// instdto.setCreate_by(SecurityUtils.getCurrentNickName());
//
// instdto.setStart_device_code(start_point_code);
// instdto.setStart_point_code(start_point_code);
// instdto.setPut_device_code(put_device_code);
// instdto.setPut_point_code(put_point_code);
// instdto.setNext_device_code(next_device_code);
// instdto.setNext_point_code(next_point_code);
// instdto.setCar_type(car_type);
// instdto.setCar_width(car_width);
// instdto.setPriority(priority);
// instdto.setInstruction_status(InstructionStatusEnum.READY.getIndex());
// instdto.setExecute_device_code(start_point_code);
// instdto.setVehicle_type(vehicleType);
// instdto.setAgv_system_type(agv_system_type);
// instdto.setStart_height(start_height);
// instdto.setNext_height(next_height);
//
// try {
// instructionService.create(instdto);
// } catch (Exception e) {
// acsTask.setRemark(e.getMessage());
// taskserver.updateByCodeFromCache(acsTask);
// LuceneLogDto logDto = LuceneLogDto.builder()
// .device_code("定时创建指令失败")
// .content(e.getMessage())
// .build();
// logDto.setLog_level(2);
// luceneExecuteLogService.deviceExecuteLog(logDto);
// continue;
// }
// //创建指令后修改任务状态
// acsTask.setTask_status(TaskStatusEnum.BUSY.getIndex());
// acsTask.setUpdate_time(DateUtil.now());
// taskserver.update(acsTask);
//
// }
// }
public void run() throws Exception {
//log.info("自动生成指令开始: {}", DateUtil.now());
RLock lock = redissonClient.getLock("autoGenInstructionLock");
boolean locked = false;
try {
String maxPsnumber = paramService.findByCode(AcsConfig.MAXINSTNUMBER).getValue();
String maxRtNumber = paramService.findByCode(AcsConfig.MAXRTINSTNUMBER).getValue();
int maxPsInst = Integer.parseInt(maxPsnumber);
int maxRtnst = Integer.parseInt(maxRtNumber);
int rtInstNum = 0;
int psInstNum = 0;
long estimatedTime = (maxPsInst + maxRtnst) * 5L + 10;
locked = lock.tryLock(0, estimatedTime, TimeUnit.SECONDS);
if (!locked) {
//log.debug("未获取到分布式锁,跳过本次执行");
return;
}
//限制指令数每次最多下发maxInstNumber个指令
List<TaskDto> list = taskserver.queryAllByStatus("0");
if (CollectionUtils.isEmpty(list)) {
return;
}
List<TaskDto> pslist = list.stream().filter(r -> !"2".equals(r.getCar_type())).collect(Collectors.toList());
List<TaskDto> rtlist = list.stream().filter(r -> "2".equals(r.getCar_type())).collect(Collectors.toList());
//已创建
List<InstructionMybatis> instructionList = new LambdaQueryChainWrapper<>(instructionMapper)
.lt(InstructionMybatis::getInstruction_status, InstructionStatusEnum.FINISHED.getIndex())
.list();
if (ObjectUtil.isNotEmpty(instructionList)) {
rtInstNum = Math.toIntExact(instructionList.stream().filter(r -> "2".equals(r.getCar_type())).count());
psInstNum = instructionList.size() - rtInstNum;
}
if (ObjectUtil.isNotEmpty(pslist)) {
maxPsInst = Math.max(0, maxPsInst - psInstNum);
createInstruction(pslist, maxPsInst);
}
if (ObjectUtil.isNotEmpty(rtlist)) {
maxRtnst = Math.max(0, maxRtnst - rtInstNum);
createInstruction(rtlist, maxRtnst);
}
} catch (Exception e) {
log.error("自动生成指令异常", e);
} finally {
if (locked && lock.isHeldByCurrentThread()) {
try {
lock.unlock();
} catch (Exception e) {
log.error("释放分布式锁异常", e);
}
}
}
}
private void createInstruction(List<TaskDto> list, int maxNum) throws InterruptedException {
int createdCount = 0;
for (int i = 0; i < list.size(); i++) {
//每次循环前检查本次已创建指令数是否达到上限
if (createdCount >= maxNum) {
break;
}
TaskDto acsTask = list.get(i);
Boolean flag = false;
String taskid = acsTask.getTask_id();
String taskcode = acsTask.getTask_code();
String task_type = acsTask.getTask_type();
String vehiclecode = acsTask.getVehicle_code();
String priority = acsTask.getPriority();
String is_send = acsTask.getIs_send();
String start_device_code = acsTask.getStart_device_code();
String start_point = null;
if (start_device_code.contains("BCPRK")) {
String[] parts = start_device_code.split("-", 2);
start_point = parts[0];
} else if (start_device_code.contains("CPRK")) {
String[] parts = start_device_code.split("-", 2);
start_point = parts[0];
}
if (start_point != null) {
if (start_point.equals("CPRK1")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("CPRK1")) {
flag = true;
}
}
} else if (start_point.equals("CPRK2")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("CPRK2")) {
flag = true;
}
}
} else if (start_point.equals("CPRK3")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("CPRK3")) {
flag = true;
}
}
} else if (start_point.equals("CPRK4")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("CPRK4")) {
flag = true;
}
}
} else if (start_point.equals("CPRK5")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("CPRK5")) {
flag = true;
}
}
} else if (start_point.equals("BCPRK1")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("BCPRK1")) {
flag = true;
}
}
} else if (start_point.equals("BCPRK2")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("BCPRK2")) {
flag = true;
}
}
} else if (start_point.equals("BCPRK3")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("BCPRK3")) {
flag = true;
}
}
} else if (start_point.equals("BCPRK4")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("BCPRK4")) {
flag = true;
}
}
} else if (start_point.equals("BCPRK5")) {
List<TaskDto> list1 = taskserver.queryAllByStatus("1");
for (int j = 0; j < list1.size(); j++) {
String start_device_code1 = list1.get(j).getStart_device_code();
String[] parts = start_device_code1.split("-", 2);
start_point = parts[0];
if (start_point.equals("BCPRK5")) {
flag = true;
}
}
}
}
if (flag) {
continue;
}
String start_point_code = acsTask.getStart_point_code();
String put_device_code = acsTask.getPut_device_code();
String put_point_code = acsTask.getPut_point_code();
String next_device_code = acsTask.getNext_device_code();
String next_point_code = acsTask.getNext_point_code();
String route_plan_code = acsTask.getRoute_plan_code();
String vehicleType = acsTask.getVehicle_type();
String agv_system_type = acsTask.getAgv_system_type();
String start_height = acsTask.getStart_height();
String next_height = acsTask.getNext_height();
String car_type = acsTask.getCar_type();
String car_width = acsTask.getCar_width();
if (StrUtil.equals(is_send, "0")) {
continue;
}
if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) {
next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z();
} else {
next_point_code = next_device_code;
}
Instruction instdto = new Instruction();
instdto.setInstruction_type(task_type);
instdto.setInstruction_id(IdUtil.simpleUUID());
instdto.setRoute_plan_code(route_plan_code);
instdto.setRemark(acsTask.getRemark());
instdto.setMaterial(acsTask.getMaterial());
instdto.setQuantity(acsTask.getQuantity());
instdto.setTask_id(taskid);
instdto.setTask_code(taskcode);
instdto.setVehicle_code(vehiclecode);
String now = DateUtil.now();
instdto.setCreate_time(now);
instdto.setCreate_by(SecurityUtils.getCurrentNickName());
instdto.setStart_device_code(start_point_code);
instdto.setStart_point_code(start_point_code);
instdto.setPut_device_code(put_device_code);
instdto.setPut_point_code(put_point_code);
instdto.setNext_device_code(next_device_code);
instdto.setNext_point_code(next_point_code);
instdto.setCar_type(car_type);
instdto.setCar_width(car_width);
instdto.setPriority(priority);
instdto.setInstruction_status(InstructionStatusEnum.READY.getIndex());
instdto.setExecute_device_code(start_point_code);
instdto.setVehicle_type(vehicleType);
instdto.setAgv_system_type(agv_system_type);
instdto.setStart_height(start_height);
instdto.setNext_height(next_height);
try {
instructionService.create(instdto);
} catch (Exception e) {
acsTask.setRemark(e.getMessage());
taskserver.updateByCodeFromCache(acsTask);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("定时创建指令失败")
.content(e.getMessage())
.build();
logDto.setLog_level(2);
luceneExecuteLogService.deviceExecuteLog(logDto);
continue;
}
TimeUnit.SECONDS.sleep(5);
//创建指令后修改任务状态
acsTask.setTask_status(TaskStatusEnum.BUSY.getIndex());
acsTask.setUpdate_time(DateUtil.now());
taskserver.update(acsTask);
log.info("自动生成指令成功: {}{}", DateUtil.now(), acsTask.getTask_code());
createdCount++;
}
}
/**
* 根据任务状态创建指令、生成下一条指令
*/
public void run() throws Exception {
log.info("自动生成指令开始: {}", DateUtil.now());
public void run1() throws Exception {
//log.info("自动生成指令开始: {}", DateUtil.now());
RLock lock = redissonClient.getLock("autoGenInstructionLock");
boolean locked = false;
try {
locked = lock.tryLock(0, 5, TimeUnit.SECONDS); // 不等待锁持有5秒自动释放
if (!locked) {
log.debug("未获取到分布式锁,跳过本次执行");
//log.debug("未获取到分布式锁,跳过本次执行");
return;
}
TaskService taskserver = SpringContextHolder.getBean(TaskService.class);

View File

@@ -6,7 +6,8 @@ spring:
freemarker:
check-template-location: false
profiles:
active: prod
active: dev
# active: dev
# active: prod
jackson:
time-zone: GMT+8