Compare commits
5 Commits
kit_agv_ad
...
1f6e83f56c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f6e83f56c | ||
|
|
1aa2356340 | ||
|
|
16ed2580b1 | ||
|
|
851a937cdd | ||
|
|
980c1d880c |
@@ -15,12 +15,12 @@ import org.nl.acs.device.device.service.DeviceAppService;
|
||||
import org.nl.acs.task.history.ErrorUtil;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.service.InstructionService;
|
||||
import org.nl.acs.task.task.service.TaskService;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.config.lucene.service.LuceneExecuteLogService;
|
||||
import org.nl.extInterface.agvKit.service.AcsToKitService;
|
||||
import org.nl.extInterface.wms.service.AcsToWmsService;
|
||||
import org.nl.extInterface.wms.service.enums.WmsFeedbackStatusEnum;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -38,9 +38,9 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
|
||||
private final LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class);
|
||||
private final InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||
private final TaskService taskService = SpringContextHolder.getBean(TaskService.class);
|
||||
private final AcsToKitService acsToKitService = SpringContextHolder.getBean(AcsToKitService.class);
|
||||
private final DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
private final AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class);
|
||||
|
||||
private volatile int agvphase = 0;
|
||||
/**
|
||||
@@ -157,14 +157,13 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
Thread.sleep(2000);
|
||||
this.devicecode = this.getDevice().getDevice_code();
|
||||
if (this.reqTakeRequireSuccess && ObjectUtil.isNotEmpty(this.reqTakeInstCode)) {
|
||||
// 驱动按周期执行,当前直接 return 就会停留在等待态,下一轮继续请求 WMS 许可。
|
||||
Instruction instruction = instructionService.findByCodeFromCache(this.reqTakeInstCode);
|
||||
//取货申请
|
||||
log.info("点位上报状态,{},{}",instruction.getTask_code(),agvphase);
|
||||
if (ObjectUtil.isNotEmpty(instruction) && StrUtil.equals(instruction.getStart_point_code(), this.devicecode)) {
|
||||
if (agvphase == 1) {
|
||||
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
|
||||
TaskDto task = taskService.findByCode(instruction.getTask_code());
|
||||
if ((StrUtil.startWith(task.getTask_code(), "-"))) {
|
||||
if ((StrUtil.startWith(instruction.getTask_code(), "-"))) {
|
||||
log.info("定点任务下发agv允许取货信号");
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getStart_point_code());
|
||||
if (dto == null) {
|
||||
@@ -179,7 +178,8 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
} else {
|
||||
resetInstTask(agvphase);
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
HttpResponse result1 = acsToKitService.genAgvSchedulingTask(instruction, 10);
|
||||
if (ObjectUtils.isEmpty(result1) || result1.getStatus() != 200) {
|
||||
return;
|
||||
@@ -189,10 +189,8 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
}
|
||||
}
|
||||
if (agvphase == 2) {
|
||||
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
|
||||
TaskDto task = taskService.findByCode(instruction.getTask_code());
|
||||
|
||||
if ((StrUtil.startWith(task.getTask_code(), "-"))) {
|
||||
acsToWmsService.feedbackTask(instruction, WmsFeedbackStatusEnum.TAKE_FINISH.getValue());
|
||||
if ((StrUtil.startWith(instruction.getTask_code(), "-"))) {
|
||||
log.info("定点任务下发agv允许取货信号");
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getStart_point_code());
|
||||
if (dto == null) {
|
||||
@@ -220,9 +218,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
//放货申请
|
||||
else if (ObjectUtil.isNotEmpty(instruction) && StrUtil.equals(instruction.getNext_point_code(), this.devicecode)) {
|
||||
if (agvphase == 3) {
|
||||
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
|
||||
TaskDto task = taskService.findByCode(instruction.getTask_code());
|
||||
if ((StrUtil.startWith(task.getTask_code(), "-"))) {
|
||||
if ((StrUtil.startWith(instruction.getTask_code(), "-"))) {
|
||||
log.info("定点任务下发agv允许取货信号");
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getNext_point_code());
|
||||
if (dto == null) {
|
||||
@@ -247,9 +243,8 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
}
|
||||
}
|
||||
if (agvphase == 4) {
|
||||
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
|
||||
TaskDto task = taskService.findByCode(instruction.getTask_code());
|
||||
if ((StrUtil.startWith(task.getTask_code(), "-"))) {
|
||||
acsToWmsService.feedbackTask(instruction, WmsFeedbackStatusEnum.PUT_FINISH.getValue());
|
||||
if ((StrUtil.startWith(instruction.getTask_code(), "-"))) {
|
||||
log.info("定点任务下发agv允许取货信号");
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getNext_point_code());
|
||||
if (dto == null) {
|
||||
@@ -387,7 +382,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
return;
|
||||
}
|
||||
// 设置新任务
|
||||
// this.agvPhase = Integer.valueOf(innerParamss.get("agvphase"));
|
||||
this.agvphase = Integer.valueOf(innerParamss.get("agvphase"));
|
||||
this.reqTakeInstCode = taskId;
|
||||
this.reqTakeRequireSuccess = true;
|
||||
}
|
||||
@@ -406,4 +401,18 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver {
|
||||
this.agvphase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean requestPermission(Instruction instruction, String permissionStatus, String progressStatus) {
|
||||
boolean allowed = acsToWmsService.feedbackTask(instruction, permissionStatus);
|
||||
if (allowed) {
|
||||
// WMS 放行后,先把外部状态推进到执行中,再继续给 AGV 下发动作。
|
||||
acsToWmsService.feedbackTask(instruction, progressStatus);
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
|
||||
private String unusedResolveCard(Instruction instruction) {
|
||||
// 优先取任务上已绑定的车号,没有时再回退到当前指令上的车号。
|
||||
return instruction == null ? "" : StrUtil.blankToDefault(instruction.getCarno(), "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import org.nl.acs.device.storageMgt.service.impl.StorageCellServiceImpl;
|
||||
import org.nl.acs.device.device.service.DeviceAppService;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.service.InstructionService;
|
||||
import org.nl.acs.task.task.service.TaskService;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.extInterface.agvKit.service.AcsToKitService;
|
||||
import org.nl.extInterface.wms.service.AcsToWmsService;
|
||||
import org.nl.extInterface.wms.service.enums.WmsFeedbackStatusEnum;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,6 +32,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
private final InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||
private final DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
private final AcsToKitService acsToKitService = SpringContextHolder.getBean(AcsToKitService.class);
|
||||
private final AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class);
|
||||
|
||||
private int flag;
|
||||
|
||||
@@ -73,21 +74,31 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
if (this.reqTakeRequireSuccess && ObjectUtil.isNotEmpty(this.reqTakeInstCode)) {
|
||||
// 驱动按周期执行,当前直接 return 就会停留在等待态,下一轮继续请求 WMS 许可。
|
||||
Instruction instruction = instructionService.findByCodeFromCache(this.reqTakeInstCode);
|
||||
//取货申请F
|
||||
log.info("点位上报状态,{},{}", instruction.getTask_code(), agvPhase);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(instruction) && StrUtil.equals(instruction.getStart_point_code(), this.deviceCode)) {
|
||||
if (agvPhase == 1) {
|
||||
// device = deviceAppService.findDeviceByCode(this.deviceCode);
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getStart_point_code());
|
||||
//取货申请
|
||||
if (!requestPermission(instruction, WmsFeedbackStatusEnum.APPLY_TAKE.getValue())) {
|
||||
return;
|
||||
}
|
||||
//二次请求判断
|
||||
Instruction currentInstruction = redirectIfNeeded(instruction);
|
||||
if (currentInstruction == null) {
|
||||
return;
|
||||
}
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(currentInstruction.getStart_point_code());
|
||||
if (dto == null) {
|
||||
log.error(instruction.getStart_point_code() + "Storage_Cache_Map数据不存在");
|
||||
return;
|
||||
}
|
||||
instruction.setOffSet(dto.getAddress());
|
||||
instruction.setOffSetName(instruction.getStart_point_code());
|
||||
HttpResponse result = acsToKitService.genAgvSchedulingTask(instruction, 10);
|
||||
currentInstruction.setOffSet(dto.getAddress());
|
||||
currentInstruction.setOffSetName(currentInstruction.getStart_point_code());
|
||||
//反馈取货申请
|
||||
HttpResponse result = acsToKitService.genAgvSchedulingTask(currentInstruction, 10);
|
||||
if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) {
|
||||
return;
|
||||
} else {
|
||||
@@ -95,8 +106,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
}
|
||||
}
|
||||
if (agvPhase == 2) {
|
||||
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
|
||||
TaskDto task = taskService.findByCode(instruction.getTask_code());
|
||||
acsToWmsService.feedbackTask(instruction, WmsFeedbackStatusEnum.TAKE_FINISH.getValue());
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getStart_point_code());
|
||||
if (dto == null) {
|
||||
log.error(instruction.getStart_point_code() + "Storage_Cache_Map数据不存在");
|
||||
@@ -104,7 +114,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
}
|
||||
instruction.setOffSet(dto.getAddress());
|
||||
instruction.setOffSetName(instruction.getStart_point_code());
|
||||
if ((StrUtil.startWith(task.getTask_code(), "-"))) {
|
||||
if ((StrUtil.startWith(instruction.getTask_code(), "-"))) {
|
||||
log.info("定点任务下发agv允许取货信号");
|
||||
HttpResponse result = acsToKitService.genAgvSchedulingTask(instruction, 10);
|
||||
if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) {
|
||||
@@ -125,6 +135,10 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
//放货申请
|
||||
else if (ObjectUtil.isNotEmpty(instruction) && StrUtil.equals(instruction.getNext_point_code(), this.deviceCode)) {
|
||||
if (agvPhase == 3) {
|
||||
//放货申请
|
||||
if (!requestPermission(instruction, WmsFeedbackStatusEnum.APPLY_PUT.getValue())) {
|
||||
return;
|
||||
}
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getNext_point_code());
|
||||
if (dto == null) {
|
||||
log.error(instruction.getStart_point_code() + "Storage_Cache_Map数据不存在");
|
||||
@@ -140,8 +154,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
}
|
||||
}
|
||||
if (agvPhase == 4) {
|
||||
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
|
||||
TaskDto task = taskService.findByCode(instruction.getTask_code());
|
||||
acsToWmsService.feedbackTask(instruction, WmsFeedbackStatusEnum.PUT_FINISH.getValue());
|
||||
StorageCellDto dto = StorageCellServiceImpl.Storage_Cache_Map.get(instruction.getNext_point_code());
|
||||
if (dto == null) {
|
||||
log.error(instruction.getStart_point_code() + "Storage_Cache_Map数据不存在");
|
||||
@@ -149,7 +162,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
}
|
||||
instruction.setOffSet(dto.getAddress1());
|
||||
instruction.setOffSetName(instruction.getNext_point_code());
|
||||
if ((StrUtil.startWith(task.getTask_code(), "-"))) {
|
||||
if ((StrUtil.startWith(instruction.getTask_code(), "-"))) {
|
||||
log.info("定点任务下发agv允许取货信号");
|
||||
HttpResponse result = acsToKitService.genAgvSchedulingTask(instruction, 10);
|
||||
if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) {
|
||||
@@ -226,5 +239,30 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractStandardDeviceDriv
|
||||
this.agvPhase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean requestPermission(Instruction instruction, String permissionStatus) {
|
||||
return acsToWmsService.feedbackTask(instruction, permissionStatus);
|
||||
}
|
||||
|
||||
private Instruction redirectIfNeeded(Instruction instruction) {
|
||||
|
||||
if (!StrUtil.equals(instruction.getNext_point_code(), "7E")) {
|
||||
return instruction;
|
||||
}
|
||||
JSONObject response = acsToWmsService.taskRedirection(instruction.getTask_code(), instruction.getNext_point_code());
|
||||
if (response == null || !Integer.valueOf(0).equals(response.getInteger("responseCode"))) {
|
||||
log.error("taskRedirection failed, taskCode:{}, currLocation:{}, response:{}",
|
||||
instruction.getTask_code(), instruction.getNext_point_code(), response);
|
||||
return null;
|
||||
}
|
||||
String locationNew = response.getString("locationNew");
|
||||
if (StrUtil.isBlank(locationNew)) {
|
||||
log.error("taskRedirection locationNew is blank, taskCode:{}, response:{}",
|
||||
instruction.getTask_code(), response);
|
||||
return null;
|
||||
}
|
||||
instruction.setStart_device_code(locationNew);
|
||||
return instruction;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,9 @@ public class TaskConfig {
|
||||
* WMS系统接口地址
|
||||
*/
|
||||
public static String WMSURL = "wmsurl";
|
||||
public static String WMS_HOUSE_CODE = "wmsHouseCode";
|
||||
public static String WMS_SYSTEM_CODE = "wmsSystemCode";
|
||||
public static String WMS_FEEDBACK_RETRY_MS = "wmsFeedbackRetryMs";
|
||||
/**
|
||||
* WCS系统接口地址
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ 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;
|
||||
@@ -56,6 +57,7 @@ import org.nl.config.language.LangProcess;
|
||||
import org.nl.config.lucene.enums.LogLevelEnum;
|
||||
import org.nl.config.lucene.service.LuceneExecuteLogService;
|
||||
import org.nl.config.lucene.service.dto.LuceneLogDto;
|
||||
import org.nl.extInterface.agvKit.service.AcsToKitService;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.common.utils.CodeUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
@@ -67,6 +69,7 @@ import org.springframework.data.domain.Pageable;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -94,6 +97,8 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
|
||||
private RouteLineService routeLineService;
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
@Autowired
|
||||
private AcsToKitService acsToKitService;
|
||||
|
||||
@Autowired
|
||||
private LuceneExecuteLogService luceneExecuteLogService;
|
||||
@@ -431,7 +436,8 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
|
||||
if (StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE)) {
|
||||
throw new BadRequestException(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由类型不是agv类型");
|
||||
}
|
||||
if (shortPathsList.size() > 0 && StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE) && dto.getAgv_system_type().equals(AgvSystemTypeEnum.Two_NDC_System_Type.getIndex())) {
|
||||
if (shortPathsList.size() > 0 && StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE) && dto.getAgv_system_type().equals(AgvSystemTypeEnum.Two_NDC_System_Type.getIndex()))
|
||||
{
|
||||
// 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统
|
||||
if (!StrUtil.equals(task.getAgv_system_type(), "0")
|
||||
&& ObjectUtil.isNotEmpty(task.getAgv_system_type())) {
|
||||
@@ -439,49 +445,20 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
|
||||
String agv_system_type = task.getAgv_system_type();
|
||||
String task_type = task.getTask_type();
|
||||
if (!StrUtil.equals(agv_system_type, "1")) {
|
||||
// task_type
|
||||
//1、生箔; Itype=1:取空,取满,放空,放满;
|
||||
//2、分切 Itype=3取满、取空、放满、放空;
|
||||
//3、普通任务 Itype=2:取货、放货;
|
||||
//4、叉车任务
|
||||
//5、输送任务
|
||||
//6、行架
|
||||
//7、立库
|
||||
if (StrUtil.equals(task_type, "1")) {
|
||||
dto.setAgv_inst_type("1");
|
||||
} else if (StrUtil.equals(task_type, "3")) {
|
||||
dto.setAgv_inst_type("2");
|
||||
} else if (StrUtil.equals(task_type, "2")) {
|
||||
dto.setAgv_inst_type("3");
|
||||
} else if (StrUtil.equals(task_type, "8")) {
|
||||
dto.setAgv_inst_type("2");
|
||||
} else {
|
||||
log.info("未找到对应的AGV指令类型,任务号:" + task.getTask_code() + ",task_type:" + task.getTask_type());
|
||||
}
|
||||
} else {
|
||||
dto.setAgv_inst_type("4");
|
||||
|
||||
}
|
||||
dto.setAgv_system_type(task.getAgv_system_type());
|
||||
}
|
||||
// NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class);
|
||||
log.warn("下发AGV指令数据," + "指令号:" + dto.getInstruction_code() + ",AGV系统类型:" + dto.getAgv_system_type()
|
||||
+ ",AGV指令类型:" + dto.getInstruction_type());
|
||||
try {
|
||||
if (StrUtil.isEmpty(dto.getAgv_inst_type()) || StrUtil.isEmpty(dto.getAgv_system_type())) {
|
||||
log.info("sendAgvInstToNDC 指令校验:" + dto.getInstruction_code() + ",inst_type:" + dto.getInstruction_type()
|
||||
+ ",inst_system_type:" + dto.getAgv_system_type());
|
||||
}
|
||||
// log.info("2楼1区域AGV系统链接开始");
|
||||
// String ip = paramService.findByCode(AcsConfig.AGVURL).getValue();
|
||||
// int port = Integer.parseInt(paramService.findByCode(AcsConfig.AGVPORT).getValue());
|
||||
// InetSocketAddress socketAddress = new InetSocketAddress(ip, port);
|
||||
// Socket s = new Socket();
|
||||
// s.connect(socketAddress, 2 * 1000);
|
||||
// if (ObjectUtil.isNotEmpty(s)&&s.isConnected()==true) {
|
||||
// ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto);
|
||||
// } else {
|
||||
// log.error("agv连接出现异常:服务端被关闭");
|
||||
// }
|
||||
HttpResponse httpResponse = acsToKitService.genAgvSchedulingTask(dto, 3);
|
||||
log.warn("下发AGV指令数据," + "指令号:" + dto.getInstruction_code() + ",AGV系统类型:" + dto.getAgv_system_type()
|
||||
+ ",AGV指令类型:" + dto.getInstruction_type());
|
||||
|
||||
} catch (Exception e) {
|
||||
dto.setSend_status("2");
|
||||
dto.setRemark(e.getMessage());
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.nl.acs.device.device.service.DeviceService;
|
||||
import org.nl.acs.device.device.service.impl.DeviceServiceImpl;
|
||||
import org.nl.acs.device.deviceDriver.service.defination.DeviceDriverDefination;
|
||||
import org.nl.extInterface.wms.service.AcsToWmsService;
|
||||
import org.nl.extInterface.wms.service.enums.WmsFeedbackStatusEnum;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.domain.InstructionMybatis;
|
||||
import org.nl.acs.task.instruction.enums.InstructionStatusEnum;
|
||||
@@ -860,8 +861,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
|
||||
//向缓存添加任务信息
|
||||
this.addTaskToCache(dto);
|
||||
//反馈上位系统任务状态
|
||||
|
||||
this.feedWmsTaskStatus(entity);
|
||||
this.feedWmsTaskStatus(dto);
|
||||
|
||||
}
|
||||
|
||||
@@ -1763,29 +1763,19 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
|
||||
*
|
||||
* @param taskDto
|
||||
*/
|
||||
/**
|
||||
* 这里只处理任务终态回传。
|
||||
* 取货、放货等中间阶段由站点驱动结合 AGV 回调直接回传 WMS。
|
||||
*/
|
||||
private void feedWmsTaskStatus(TaskDto taskDto) {
|
||||
// 判断是否为WMS下发的任务,如果是反馈任务状态给WMS
|
||||
TaskDto entity = this.findById(taskDto.getTask_id());
|
||||
String hasWms = paramService.findByCode(TaskConfig.HASWMS).getValue();
|
||||
if (!StrUtil.startWith(taskDto.getTask_code(), CommonFinalParam.HYPHEN_) && StrUtil.equals(hasWms, CommonFinalParam.ONE)) {
|
||||
// FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest();
|
||||
// request.setTask_id(taskDto.getExt_task_id());
|
||||
// request.setTask_code(taskDto.getTask_code());
|
||||
// request.setTask_status(taskDto.getTask_status());
|
||||
// request.setRequest_medthod_code(RequestMethodEnum.feedback_task_status.getCode());
|
||||
// request.setRequest_medthod_name(RequestMethodEnum.feedback_task_status.getName());
|
||||
JSONObject feed_jo = new JSONObject();
|
||||
feed_jo.put("task_id", entity.getExt_task_id());
|
||||
feed_jo.put("task_code", entity.getTask_code());
|
||||
feed_jo.put("task_status", entity.getTask_status());
|
||||
if (ObjectUtil.isNotEmpty(entity.getWeight())) {
|
||||
feed_jo.put("weight", entity.getWeight());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(entity.getCarno())) {
|
||||
feed_jo.put("car_no", entity.getCarno());
|
||||
}
|
||||
JSONArray ja = new JSONArray();
|
||||
ja.add(feed_jo);
|
||||
if (!acstowmsService.isWmsTask(taskDto)) {
|
||||
return;
|
||||
}
|
||||
if (StrUtil.equals(taskDto.getTask_status(), TaskStatusEnum.CANCEL.getIndex())) {
|
||||
acstowmsService.deprecateTask(taskDto, taskDto.getRemark());
|
||||
} else if (StrUtil.equals(taskDto.getTask_status(), TaskStatusEnum.ERROR.getIndex())
|
||||
|| StrUtil.equals(taskDto.getTask_status(), TaskStatusEnum.FORCED_COMPLETION.getIndex())) {
|
||||
acstowmsService.feedbackTask(taskDto, taskDto.getCarno(), WmsFeedbackStatusEnum.ERROR_FINISH.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.nl.extInterface.agvKit.service.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* KIT消息处理器接口,定义消息类型支持与处理策略。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
public interface KitMessageHandler {
|
||||
/**
|
||||
* 返回当前策略所处理的KIT消息类型。
|
||||
*
|
||||
* @return MsgTypeEnum定义的类型值
|
||||
*/
|
||||
Integer supportType();
|
||||
|
||||
/**
|
||||
* 处理KIT消息负载并生成协议响应。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
JSONObject handle(JSONObject params) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.nl.extInterface.agvKit.service.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* KIT响应构建工具类,提供成功和失败响应的静态构建方法。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
public final class KitResponse {
|
||||
/**
|
||||
* 防止实例化响应工具类。
|
||||
*/
|
||||
private KitResponse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功的KIT响应。
|
||||
*
|
||||
* @param message 响应消息
|
||||
* @return 状态码200的响应体
|
||||
*/
|
||||
public static JSONObject success(String message) {
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("code", "200");
|
||||
response.put("message", message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败的KIT响应。
|
||||
*
|
||||
* @param message 失败原因
|
||||
* @return 状态码400的响应体
|
||||
*/
|
||||
public static JSONObject fail(String message) {
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("code", "400");
|
||||
response.put("message", message);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* AGV故障上报处理器,确认收到KIT上报的AGV故障信息。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class AgvErrorReportHandler implements KitMessageHandler {
|
||||
/**
|
||||
* 返回AGV故障上报消息类型。
|
||||
*
|
||||
* @return AGV_ERROR_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.AGV_ERROR_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认AGV故障上报。当前集成不持久化故障详情。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) {
|
||||
return KitResponse.success("更新指令执行中成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.enums.InstructionStatusEnum;
|
||||
import org.nl.acs.task.instruction.service.InstructionService;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* AGV车号上报处理器,持久化KIT上报的AGV车号并将指令标记为忙碌。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class AgvIdReportHandler implements KitMessageHandler {
|
||||
@Autowired
|
||||
private InstructionService instructionService;
|
||||
|
||||
/**
|
||||
* 返回AGV分配上报消息类型。
|
||||
*
|
||||
* @return AGV_ID_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.AGV_ID_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 持久化KIT上报的AGV车号,并将指令标记为忙碌。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) {
|
||||
String taskId = params.getString("taskId");
|
||||
String agvId = params.getString("agvId");
|
||||
Instruction instruction = instructionService.findByCodeFromCache(taskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
return KitResponse.fail("请求失败,任务信息不存在,指令号:" + taskId);
|
||||
}
|
||||
|
||||
instruction.setCarno(agvId);
|
||||
instruction.setInstruction_status(InstructionStatusEnum.BUSY.getCode());
|
||||
instruction.setUpdate_time(DateUtil.now());
|
||||
instructionService.update(instruction);
|
||||
return KitResponse.success("更新车号成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* AGV电量上报处理器,确认收到KIT上报的AGV电量信息。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class AgvPowerReportHandler implements KitMessageHandler {
|
||||
/**
|
||||
* 返回AGV电量上报消息类型。
|
||||
*
|
||||
* @return AGV_POWER_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.AGV_POWER_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认AGV电量上报。当前集成不持久化电量详情。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) {
|
||||
return KitResponse.success("更新指令执行中成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.nl.extInterface.wms.service.AcsToWmsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* AGV状态上报处理器,将KIT上报的AGV状态转发至WMS作为设备状态更新。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class AgvStateReportHandler implements KitMessageHandler {
|
||||
@Autowired
|
||||
private AcsToWmsService acsToWmsService;
|
||||
|
||||
/**
|
||||
* 返回AGV状态上报消息类型。
|
||||
*
|
||||
* @return AGV_STATE_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.AGV_STATE_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将KIT上报的AGV状态转发至WMS作为设备状态更新。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) {
|
||||
String deviceCode = StrUtil.blankToDefault(params.getString("deviceCode"), params.getString("agvId"));
|
||||
Integer status = params.getInteger("status");
|
||||
String statusDescription = params.getString("statusDescription");
|
||||
if (StrUtil.isEmpty(deviceCode) || status == null) {
|
||||
return KitResponse.fail("AGV状态上报参数异常");
|
||||
}
|
||||
|
||||
boolean success = acsToWmsService.deviceStatusUpdate(deviceCode, status, statusDescription);
|
||||
if (!success) {
|
||||
return KitResponse.fail("回馈WMS设备状态失败");
|
||||
}
|
||||
return KitResponse.success("更新指令执行中成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.enums.InstructionStatusEnum;
|
||||
import org.nl.acs.task.instruction.service.InstructionService;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 车辆任务生成上报处理器,KIT上报车辆任务生成后将ACS指令标记为忙碌。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class TaskIndexReportHandler implements KitMessageHandler {
|
||||
@Autowired
|
||||
private InstructionService instructionService;
|
||||
|
||||
/**
|
||||
* 返回车辆任务生成上报消息类型。
|
||||
*
|
||||
* @return TASK_INDEX_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.TASK_INDEX_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* KIT上报车辆任务生成后,将ACS指令标记为忙碌。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) {
|
||||
String taskId = params.getString("taskId");
|
||||
Instruction instruction = instructionService.findByCodeFromCache(taskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
return KitResponse.fail("请求失败,任务信息不存在,指令号:" + taskId);
|
||||
}
|
||||
|
||||
instruction.setInstruction_status(InstructionStatusEnum.BUSY.getCode());
|
||||
instruction.setUpdate_time(DateUtil.now());
|
||||
instructionService.update(instruction);
|
||||
return KitResponse.success("更新指令执行中成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 任务运行上报处理器,确认收到KIT上报的任务运行状态。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class TaskRunReportHandler implements KitMessageHandler {
|
||||
/**
|
||||
* 返回任务运行上报消息类型。
|
||||
*
|
||||
* @return TASK_RUN_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.TASK_RUN_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认任务运行上报。当前集成无额外状态更新。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) {
|
||||
return KitResponse.success("更新车号成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package org.nl.extInterface.agvKit.service.handler.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.acs.device.device.service.DeviceAppService;
|
||||
import org.nl.acs.device.device.service.entity.Device;
|
||||
import org.nl.acs.device.deviceDriver.service.driver.DeviceDriver;
|
||||
import org.nl.acs.device.storageMgt.service.StorageCellService;
|
||||
import org.nl.acs.device.storageMgt.service.entity.StorageCell;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.service.InstructionService;
|
||||
import org.nl.config.MapOf;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.enums.TaskPhaseEnum;
|
||||
import org.nl.extInterface.agvKit.service.enums.TaskStateEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 任务状态上报处理器,根据KIT任务状态上报推进ACS指令阶段,并通知相关设备驱动。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Component
|
||||
public class TaskStateReportHandler implements KitMessageHandler {
|
||||
@Autowired
|
||||
private InstructionService instructionService;
|
||||
@Autowired
|
||||
private StorageCellService storageCellService;
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
|
||||
/**
|
||||
* 返回任务状态上报消息类型。
|
||||
*
|
||||
* @return TASK_STATE_RPT类型值
|
||||
*/
|
||||
@Override
|
||||
public Integer supportType() {
|
||||
return MsgTypeEnum.TASK_STATE_RPT.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据KIT任务状态上报推进ACS指令阶段,并通知相关设备驱动。
|
||||
*
|
||||
* @param params KIT回调请求中的params节点
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject handle(JSONObject params) throws Exception {
|
||||
String instTaskId = params.getString("taskId");
|
||||
String taskPhase = params.getString("taskPhase");
|
||||
String taskState = params.getString("taskState");
|
||||
String taskPoint = params.getString("taskPoint");
|
||||
if (StrUtil.isEmpty(taskPhase)) {
|
||||
return KitResponse.fail("taskPhase参数异常");
|
||||
}
|
||||
|
||||
Instruction instruction = findInstruction(instTaskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
return KitResponse.fail("请求失败,任务信息不存在,指令号:" + instTaskId);
|
||||
}
|
||||
|
||||
if (TaskStateEnum.CANCELED.getValue().equals(taskState)) {
|
||||
instructionService.cancel(instruction.getInstruction_id());
|
||||
return KitResponse.success("取消任务成功");
|
||||
}
|
||||
|
||||
TaskPhaseEnum taskPhaseEnum = TaskPhaseEnum.fromPhase(taskPhase);
|
||||
switch (taskPhaseEnum) {
|
||||
case ENTER_REQUEST_OR_ALLOWED:
|
||||
case LEAVE_NOTICE_OR_ALLOWED:
|
||||
return handleSitePhase(instTaskId, taskPhase, taskPoint, taskPhaseEnum);
|
||||
case PICKUP_REQUEST_OR_RESPONSE:
|
||||
case PICKUP_COMPLETE:
|
||||
case RELEASE_REQUEST_OR_RESPONSE:
|
||||
case RELEASE_COMPLETE:
|
||||
return handleCargoPhase(instruction, instTaskId, taskPhase, taskState, taskPhaseEnum);
|
||||
default:
|
||||
return KitResponse.fail("taskPhase值不存在");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 先从缓存查找指令,缓存未命中则查数据库,数据库命中后重载缓存。
|
||||
*
|
||||
* @param instTaskId ACS指令编码
|
||||
* @return 查找到的指令,未找到则返回null
|
||||
*/
|
||||
private Instruction findInstruction(String instTaskId) {
|
||||
Instruction instruction = instructionService.findByCodeFromCache(instTaskId);
|
||||
if (ObjectUtil.isNotEmpty(instruction)) {
|
||||
return instruction;
|
||||
}
|
||||
|
||||
instruction = instructionService.findByCode(instTaskId);
|
||||
if (ObjectUtil.isNotEmpty(instruction)) {
|
||||
instructionService.reload();
|
||||
}
|
||||
return instruction;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理进入/离开站点阶段,将AGV阶段数据推入站点设备驱动。
|
||||
*
|
||||
* @param instTaskId ACS指令编码
|
||||
* @param taskPhase KIT上报的任务阶段
|
||||
* @param taskPoint KIT上报的站点地址
|
||||
* @param taskPhaseEnum 解析后的任务阶段枚举
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
private JSONObject handleSitePhase(String instTaskId, String taskPhase, String taskPoint,
|
||||
TaskPhaseEnum taskPhaseEnum) {
|
||||
StorageCell storageCellDto = storageCellService.findByAddress(taskPoint);
|
||||
if (ObjectUtil.isEmpty(storageCellDto)) {
|
||||
return KitResponse.fail("请求失败,点位信息不存在,点位站点号:" + taskPoint);
|
||||
}
|
||||
|
||||
Device device = deviceAppService.findDeviceByCode(storageCellDto.getStorage_code());
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
return KitResponse.fail("请求失败,请求位置编码不存在");
|
||||
}
|
||||
|
||||
DeviceDriver deviceDriver = device.getDeviceDriver();
|
||||
deviceDriver.setDeviceInnerParam(MapOf.of("taskId", instTaskId, "agvphase", taskPhase));
|
||||
return KitResponse.success(taskPhaseEnum.getDescription() + "处理完毕");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理取货/放货阶段,更新站点驱动并持久化指令执行阶段。
|
||||
*
|
||||
* @param instruction 当前ACS指令
|
||||
* @param instTaskId ACS指令编码
|
||||
* @param taskPhase KIT上报的任务阶段
|
||||
* @param taskState KIT上报的任务状态
|
||||
* @param taskPhaseEnum 解析后的任务阶段枚举
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
private JSONObject handleCargoPhase(Instruction instruction, String instTaskId, String taskPhase,
|
||||
String taskState, TaskPhaseEnum taskPhaseEnum) {
|
||||
Device device = findCargoPhaseDevice(instruction, taskPhase);
|
||||
if (device == null) {
|
||||
return KitResponse.fail("点位驱动不存在");
|
||||
}
|
||||
|
||||
device.getDeviceDriver().setDeviceInnerParam(MapOf.of("taskId", instTaskId, "agvphase", taskPhase));
|
||||
if (!taskPhase.equals(instruction.getExecute_status())) {
|
||||
instruction.setExecute_status(taskPhase);
|
||||
instructionService.update(instruction);
|
||||
}
|
||||
if (TaskStateEnum.COMPLETED.getValue().equals(taskState)) {
|
||||
return KitResponse.success("完成任务成功");
|
||||
}
|
||||
return KitResponse.success(taskPhaseEnum.getDescription() + "处理完毕");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据取货或放货阶段解析对应的设备。
|
||||
*
|
||||
* @param instruction 当前ACS指令
|
||||
* @param taskPhase KIT上报的任务阶段
|
||||
* @return 匹配的起点或终点设备,阶段不支持时返回null
|
||||
*/
|
||||
private Device findCargoPhaseDevice(Instruction instruction, String taskPhase) {
|
||||
if (TaskPhaseEnum.PICKUP_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)
|
||||
|| TaskPhaseEnum.PICKUP_COMPLETE.getValue().equals(taskPhase)) {
|
||||
return deviceAppService.findDeviceByCode(instruction.getStart_point_code());
|
||||
}
|
||||
if (TaskPhaseEnum.RELEASE_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)
|
||||
|| TaskPhaseEnum.RELEASE_COMPLETE.getValue().equals(taskPhase)) {
|
||||
return deviceAppService.findDeviceByCode(instruction.getNext_point_code());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,215 +1,60 @@
|
||||
package org.nl.extInterface.agvKit.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.device.device.service.entity.Device;
|
||||
import org.nl.acs.device.deviceDriver.service.driver.DeviceDriver;
|
||||
import org.nl.acs.device.storageMgt.service.entity.StorageCell;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.instruction.enums.InstructionStatusEnum;
|
||||
import org.nl.acs.task.instruction.service.InstructionService;
|
||||
import org.nl.acs.device.device.service.DeviceAppService;
|
||||
import org.nl.acs.device.storageMgt.service.StorageCellService;
|
||||
import org.nl.config.MapOf;
|
||||
import org.nl.extInterface.agvKit.service.KitToAcsService;
|
||||
import org.nl.extInterface.agvKit.service.enums.MsgTypeEnum;
|
||||
import org.nl.extInterface.agvKit.service.enums.TaskPhaseEnum;
|
||||
import org.nl.extInterface.agvKit.service.enums.TaskStateEnum;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitMessageHandler;
|
||||
import org.nl.extInterface.agvKit.service.handler.KitResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* KIT回调服务实现,构建类型-处理器注册表并路由回调请求。
|
||||
*
|
||||
* @author guannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class KitToAcsServiceImpl implements KitToAcsService {
|
||||
@Autowired
|
||||
private InstructionService instructionService;
|
||||
@Autowired
|
||||
private StorageCellService storageCellService;
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
private final Map<Integer, KitMessageHandler> handlerMap;
|
||||
|
||||
/**
|
||||
* 根据Spring管理的KIT处理器构建类型-处理器注册表。
|
||||
*
|
||||
* @param handlers Spring发现的所有KIT消息处理器
|
||||
*/
|
||||
@Autowired
|
||||
public KitToAcsServiceImpl(List<KitMessageHandler> handlers) {
|
||||
this.handlerMap = new HashMap<>();
|
||||
for (KitMessageHandler handler : handlers) {
|
||||
this.handlerMap.put(handler.supportType(), handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将KIT回调请求路由至支持其消息类型的处理器。
|
||||
*
|
||||
* @param requestParam KIT回调原始JSON,包含type和params
|
||||
* @return KIT协议响应体
|
||||
*/
|
||||
@Override
|
||||
public JSONObject agvCallback(JSONObject requestParam) throws Exception{
|
||||
JSONObject resp = new JSONObject();
|
||||
public JSONObject agvCallback(JSONObject requestParam) throws Exception {
|
||||
Integer type = requestParam.getInteger("type");
|
||||
JSONObject params = requestParam.getJSONObject("params");
|
||||
//任务状态上报
|
||||
if (MsgTypeEnum.TASK_STATE_RPT.getValue().equals(type)) {
|
||||
String instTaskId = params.getString("taskId");
|
||||
String taskPhase = params.getString("taskPhase");
|
||||
String taskState = params.getString("taskState");
|
||||
String taskPoint = params.getString("taskPoint");//请求进入/离开需要上报站点号
|
||||
if (StrUtil.isEmpty(taskPhase)){
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "taskPhase参数异常");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
Instruction instruction = instructionService.findByCodeFromCache(instTaskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
instruction = instructionService.findByCode(instTaskId);
|
||||
if (ObjectUtil.isEmpty(instruction)){
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,任务信息不存在,指令号:" + instTaskId);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
instructionService.reload();
|
||||
}
|
||||
KitMessageHandler handler = handlerMap.get(type);
|
||||
if (handler == null) {
|
||||
JSONObject response = KitResponse.fail(type + "type类型未定义");
|
||||
log.info("---kit响应请求---{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
//taskPhase 任务取消
|
||||
if (TaskStateEnum.CANCELED.getValue().equals(taskState)){
|
||||
instructionService.cancel(instruction.getInstruction_id());
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "取消任务成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
Device device = null;
|
||||
TaskPhaseEnum taskPhaseEnum = TaskPhaseEnum.fromPhase(taskPhase);
|
||||
switch (taskPhaseEnum){
|
||||
case ENTER_REQUEST_OR_ALLOWED:
|
||||
case LEAVE_NOTICE_OR_ALLOWED:
|
||||
StorageCell storageCellDto = storageCellService.findByAddress(taskPoint);
|
||||
if (ObjectUtil.isEmpty(storageCellDto)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,点位信息不存在,点位站点号:" + taskPoint);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
device = deviceAppService.findDeviceByCode(storageCellDto.getStorage_code());
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,请求位置编号不存在!");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
DeviceDriver deviceDriver = device.getDeviceDriver();
|
||||
deviceDriver.setDeviceInnerParam(MapOf.of("taskId",instTaskId,"agvphase",taskPhase));
|
||||
break;
|
||||
case PICKUP_REQUEST_OR_RESPONSE:
|
||||
case PICKUP_COMPLETE:
|
||||
case RELEASE_REQUEST_OR_RESPONSE:
|
||||
case RELEASE_COMPLETE:
|
||||
if (TaskPhaseEnum.PICKUP_REQUEST_OR_RESPONSE.getValue().equals(taskPhase) || TaskPhaseEnum.PICKUP_COMPLETE.getValue().equals(taskPhase)){
|
||||
device = deviceAppService.findDeviceByCode(instruction.getStart_point_code());
|
||||
}
|
||||
//taskPhase 请求放货上报,放货完成上报
|
||||
if (TaskPhaseEnum.RELEASE_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)||TaskPhaseEnum.RELEASE_COMPLETE.getValue().equals(taskPhase)){
|
||||
device = deviceAppService.findDeviceByCode(instruction.getNext_point_code());
|
||||
}
|
||||
if (device == null){
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "点位驱动不存在");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
device.getDeviceDriver().setDeviceInnerParam(MapOf.of("taskId",instTaskId,"agvphase",taskPhase));
|
||||
if (!taskPhase.equals(instruction.getExecute_status())){
|
||||
instruction.setExecute_status(taskPhase);
|
||||
instructionService.update(instruction);
|
||||
}
|
||||
//taskPhase 任务完成
|
||||
if (TaskStateEnum.COMPLETED.getValue().equals(taskState)){
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "完成任务成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "taskPhase值不存在");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
resp.put("code", "200");
|
||||
resp.put("message", taskPhaseEnum.getDescription()+"处理完毕");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//任务分配车辆上报
|
||||
else if (MsgTypeEnum.AGV_ID_RPT.getValue().equals(type)){
|
||||
String taskId = params.getString("taskId");
|
||||
String agvId = params.getString("agvId");
|
||||
Instruction instruction = instructionService.findByCodeFromCache(taskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//更新车号
|
||||
instruction.setCarno(agvId);
|
||||
instruction.setInstruction_status(InstructionStatusEnum.BUSY.getCode());
|
||||
instruction.setUpdate_time(DateUtil.now());
|
||||
instructionService.update(instruction);
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新车号成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.TASK_RUN_RPT.getValue().equals(type)){
|
||||
System.out.println("------");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新车号成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//车辆任务生成上报
|
||||
else if (MsgTypeEnum.TASK_INDEX_RPT.getValue().equals(type)){
|
||||
String taskId = params.getString("taskId");
|
||||
Instruction instruction = instructionService.findByCodeFromCache(taskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//修改指令状态执行中
|
||||
instruction.setInstruction_status(InstructionStatusEnum.BUSY.getCode());
|
||||
instruction.setUpdate_time(DateUtil.now());
|
||||
instructionService.update(instruction);
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.AGV_POWER_RPT.getValue().equals(type)){
|
||||
int agvId = params.getIntValue("agvId");
|
||||
int stateValue = params.getIntValue("stateValue");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.AGV_STATE_RPT.getValue().equals(type)){
|
||||
int agvId = params.getIntValue("agvId");
|
||||
int stateValue = params.getIntValue("stateValue");
|
||||
int xLocation = params.getIntValue("xLocation");
|
||||
int yLocation = params.getIntValue("yLocation");
|
||||
int angle = params.getIntValue("angle");
|
||||
int speed = params.getIntValue("speed");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.AGV_ERROR_RPT.getValue().equals(type)){
|
||||
int agvId = params.getIntValue("agvId");
|
||||
int errorCode = params.getIntValue("errState");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
resp.put("code", "400");
|
||||
resp.put("message", type+"type类型未定义");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
JSONObject response = handler.handle(params);
|
||||
log.info("---kit响应请求---{}", response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
|
||||
package org.nl.extInterface.wms.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.extInterface.wms.service.WmsToAcsService;
|
||||
import org.nl.extInterface.wms.service.dto.CreateTaskRequest;
|
||||
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;
|
||||
|
||||
@@ -12,7 +19,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/wms")
|
||||
@Api(tags = "wms->ACS")
|
||||
@RequestMapping({"/api/wms", "/restful/api/v3"})
|
||||
@Slf4j
|
||||
public class WmsToAcsController {
|
||||
private final WmsToAcsService wmsToAcsService;
|
||||
|
||||
@SaIgnore
|
||||
@PostMapping("/createTask")
|
||||
public ResponseEntity<Object> createTask(@RequestBody CreateTaskRequest request) {
|
||||
// 控制层只做协议接入,字段映射和业务处理统一下沉到 service。
|
||||
return new ResponseEntity<>(wmsToAcsService.createTask(request), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
package org.nl.extInterface.wms.service;
|
||||
|
||||
public interface AcsToWmsService {
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
|
||||
public interface AcsToWmsService {
|
||||
/**
|
||||
* 复用 WMS 的 feedbackTask 接口,同时承担阶段反馈和取放货许可判断。
|
||||
*/
|
||||
boolean feedbackTask(TaskDto taskDto, String card, String feedbackStatus);
|
||||
|
||||
boolean feedbackTask(Instruction instruction, String feedbackStatus);
|
||||
|
||||
boolean deprecateTask(TaskDto taskDto, String reason);
|
||||
|
||||
JSONObject taskRedirection(String taskCode, String currLocation);
|
||||
|
||||
boolean deviceStatusUpdate(String deviceCode, Integer status, String statusDescription);
|
||||
|
||||
/**
|
||||
* 判断任务是否需要进入 WMS 回传链路,避免本地任务误回传。
|
||||
*/
|
||||
boolean isWmsTask(TaskDto taskDto);
|
||||
|
||||
boolean isWmsInstruction(Instruction instruction);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package org.nl.extInterface.wms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.extInterface.wms.service.dto.CreateTaskRequest;
|
||||
|
||||
public interface WmsToAcsService {
|
||||
/**
|
||||
* 接收 WMS 的 createTask 报文,并映射到现有 ACS 任务流程。
|
||||
*/
|
||||
|
||||
JSONObject createTask(CreateTaskRequest request);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.nl.extInterface.wms.service.dto;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateTaskRequest {
|
||||
private String houseCode;
|
||||
private String systemCode;
|
||||
private JSONObject parameters;
|
||||
private String taskCode;
|
||||
private String taskType;
|
||||
private String taskCreateDateTime;
|
||||
private String containerCode;
|
||||
private String containerType;
|
||||
private String locationFrom;
|
||||
private String locationTo;
|
||||
private Integer priority;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.nl.extInterface.wms.service.enums;
|
||||
|
||||
|
||||
/**
|
||||
* WMS feedbackTask 接口使用的任务阶段状态枚举。
|
||||
*/
|
||||
public enum WmsFeedbackStatusEnum {
|
||||
/** 取货执行中。 */
|
||||
TAKING("taking"),
|
||||
/** 请求 WMS 允许取货。 */
|
||||
APPLY_TAKE("applyTake"),
|
||||
/** 取货完成。 */
|
||||
TAKE_FINISH("takeFinish"),
|
||||
/** 放货执行中。 */
|
||||
PUTTING("putting"),
|
||||
/** 请求 WMS 允许放货。 */
|
||||
APPLY_PUT("applyPut"),
|
||||
/** 放货完成。 */
|
||||
PUT_FINISH("putFinish"),
|
||||
/** 无目标点放货完成。 */
|
||||
NO_TARGET_PUT_FINISH("NoTargetPutFinish"),
|
||||
/** 异常完成。 */
|
||||
ERROR_FINISH("errorFinish"),
|
||||
/** 运行异常。 */
|
||||
EXCEPTION("exception"),
|
||||
/** 任务作废。 */
|
||||
DEPRECATE("deprecate");
|
||||
|
||||
/** 对外回传给 WMS 的状态值。 */
|
||||
private final String value;
|
||||
|
||||
WmsFeedbackStatusEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,153 @@
|
||||
package org.nl.extInterface.wms.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.task.TaskConfig;
|
||||
import org.nl.acs.task.instruction.domain.Instruction;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
import org.nl.common.db.CommonFinalParam;
|
||||
import org.nl.extInterface.wms.service.AcsToWmsService;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
private static final String FEEDBACK_TASK_PATH = "/restful/api/v3/system_car/feedbackTask";
|
||||
private static final String DEPRECATE_TASK_PATH = "/restful/api/v3/system_car/deprecateTask";
|
||||
private static final String TASK_REDIRECTION_PATH = "/restful/api/v3/system_car/taskRedirection";
|
||||
private static final String DEVICE_STATUS_PATH = "/restful/api/v3/system_car/deviceStatusUpdate";
|
||||
|
||||
private final ISysParamService paramService;
|
||||
|
||||
@Override
|
||||
public boolean feedbackTask(TaskDto taskDto, String card, String feedbackStatus) {
|
||||
if (!isWmsTask(taskDto)) {
|
||||
return true;
|
||||
}
|
||||
// 当前项目复用 feedbackTask 作为统一出口,既回传阶段,也做取放货许可判断。
|
||||
JSONObject body = baseBody();
|
||||
body.put("taskCode", getExternalTaskCode(taskDto));
|
||||
body.put("card", StrUtil.blankToDefault(card, ""));
|
||||
body.put("taskType", StrUtil.blankToDefault(taskDto.getTask_type(), ""));
|
||||
body.put("feedbackStatus", feedbackStatus);
|
||||
JSONObject response = postJson(buildUrl(FEEDBACK_TASK_PATH), body);
|
||||
return isSuccess(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean feedbackTask(Instruction instruction, String feedbackStatus) {
|
||||
if (!isWmsInstruction(instruction)) {
|
||||
return true;
|
||||
}
|
||||
JSONObject body = baseBody();
|
||||
body.put("taskCode", instruction.getTask_code());
|
||||
body.put("card", StrUtil.blankToDefault(instruction.getCarno(), ""));
|
||||
body.put("taskType", StrUtil.blankToDefault(instruction.getInstruction_type(), ""));
|
||||
body.put("feedbackStatus", feedbackStatus);
|
||||
JSONObject response = postJson(buildUrl(FEEDBACK_TASK_PATH), body);
|
||||
return isSuccess(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deprecateTask(TaskDto taskDto, String reason) {
|
||||
if (!isWmsTask(taskDto)) {
|
||||
return true;
|
||||
}
|
||||
JSONObject body = baseBody();
|
||||
body.put("taskCode", getExternalTaskCode(taskDto));
|
||||
body.put("reason", StrUtil.blankToDefault(reason, ""));
|
||||
JSONObject response = postJson(buildUrl(DEPRECATE_TASK_PATH), body);
|
||||
return isSuccess(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject taskRedirection(String taskCode, String currLocation) {
|
||||
JSONObject body = baseBody();
|
||||
body.put("taskCode", taskCode);
|
||||
body.put("currLocation", currLocation);
|
||||
return postJson(buildUrl(TASK_REDIRECTION_PATH), body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deviceStatusUpdate(String deviceCode, Integer status, String statusDescription) {
|
||||
JSONObject body = baseBody();
|
||||
body.put("deviceCode", deviceCode);
|
||||
body.put("status", status);
|
||||
body.put("statusDescription", statusDescription);
|
||||
JSONObject response = postJson(buildUrl(DEVICE_STATUS_PATH), body);
|
||||
return isSuccess(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWmsTask(TaskDto taskDto) {
|
||||
// 当前通过任务号规则和总开关共同判断,避免历史 ACS 本地任务进入 WMS 流程。
|
||||
return taskDto != null
|
||||
&& StrUtil.isNotBlank(taskDto.getTask_code())
|
||||
&& !StrUtil.startWith(taskDto.getTask_code(), CommonFinalParam.HYPHEN_)
|
||||
&& StrUtil.equals("1", getParam(TaskConfig.HASWMS, "0"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWmsInstruction(Instruction instruction) {
|
||||
return instruction != null
|
||||
&& StrUtil.isNotBlank(instruction.getTask_code())
|
||||
&& !StrUtil.startWith(instruction.getTask_code(), CommonFinalParam.HYPHEN_)
|
||||
&& StrUtil.equals("1", getParam(TaskConfig.HASWMS, "0"));
|
||||
}
|
||||
|
||||
protected JSONObject postJson(String url, JSONObject body) {
|
||||
try {
|
||||
String result = HttpRequest.post(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body.toJSONString())
|
||||
.timeout(8000)
|
||||
.execute()
|
||||
.body();
|
||||
return JSON.parseObject(result);
|
||||
} catch (Exception ex) {
|
||||
// 统一包装成失败响应,调用方可以按 WMS 拒绝的同一套逻辑处理。
|
||||
log.error("postJson failed, url={}, body={}", url, body, ex);
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("responseCode", 1);
|
||||
error.put("responseMessage", ex.getMessage());
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject baseBody() {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("houseCode", getParam(TaskConfig.WMS_HOUSE_CODE, ""));
|
||||
body.put("systemCode", getParam(TaskConfig.WMS_SYSTEM_CODE, ""));
|
||||
// 协议预留了扩展参数对象,即使当前流程没有额外字段也保持结构一致。
|
||||
body.put("parameters", new JSONObject());
|
||||
return body;
|
||||
}
|
||||
|
||||
private String buildUrl(String path) {
|
||||
String baseUrl = getParam(TaskConfig.WMSURL, "");
|
||||
if (StrUtil.endWith(baseUrl, "/")) {
|
||||
baseUrl = StrUtil.removeSuffix(baseUrl, "/");
|
||||
}
|
||||
return baseUrl + path;
|
||||
}
|
||||
|
||||
private String getExternalTaskCode(TaskDto taskDto) {
|
||||
return StrUtil.isNotBlank(taskDto.getExt_task_id()) ? taskDto.getExt_task_id() : taskDto.getTask_code();
|
||||
}
|
||||
|
||||
private boolean isSuccess(JSONObject response) {
|
||||
return response != null && Integer.valueOf(0).equals(response.getInteger("responseCode"));
|
||||
}
|
||||
|
||||
private String getParam(String code, String defaultValue) {
|
||||
Param param = paramService.findByCode(code);
|
||||
return param == null || StrUtil.isBlank(param.getValue()) ? defaultValue : param.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,57 @@
|
||||
package org.nl.extInterface.wms.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.task.task.service.TaskService;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
import org.nl.extInterface.wms.service.WmsToAcsService;
|
||||
import org.nl.extInterface.wms.service.dto.CreateTaskRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
private final TaskService taskService;
|
||||
|
||||
@Override
|
||||
public JSONObject createTask(CreateTaskRequest request) {
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
// 将 WMS 协议报文转换成现有 ACS 任务 DTO,复用已有建单和调度链路。
|
||||
TaskDto dto = new TaskDto();
|
||||
dto.setTask_code(request.getTaskCode());
|
||||
dto.setExt_task_id(request.getTaskCode());
|
||||
dto.setTask_type(StrUtil.blankToDefault(request.getTaskType(), "1"));
|
||||
dto.setVehicle_code(request.getContainerCode());
|
||||
dto.setVehicle_type(request.getContainerType());
|
||||
dto.setStart_point_code(request.getLocationFrom());
|
||||
dto.setStart_device_code(request.getLocationFrom());
|
||||
dto.setNext_point_code(request.getLocationTo());
|
||||
dto.setNext_device_code(request.getLocationTo());
|
||||
dto.setPriority(request.getPriority() == null ? null : String.valueOf(request.getPriority()));
|
||||
dto.setQuantity("1");
|
||||
dto.setRoute_plan_code("normal");
|
||||
dto.setCompound_task("0");
|
||||
dto.setCreate_type("WMS");
|
||||
dto.setFinish_type("WMS");
|
||||
// 当前任务模型没有完整承载 WMS 扩展字段的结构化列,先放入 remark 保留。
|
||||
JSONObject extInfo = new JSONObject();
|
||||
extInfo.put("houseCode", request.getHouseCode());
|
||||
extInfo.put("systemCode", request.getSystemCode());
|
||||
extInfo.put("taskCreateDateTime", request.getTaskCreateDateTime());
|
||||
extInfo.put("parameters", request.getParameters());
|
||||
dto.setRemark(extInfo.toJSONString());
|
||||
taskService.create(dto);
|
||||
response.put("responseCode", 0);
|
||||
response.put("responseMessage", "success");
|
||||
} catch (Exception ex) {
|
||||
log.error("createTask failed, taskCode={}", request.getTaskCode(), ex);
|
||||
response.put("responseCode", 1);
|
||||
response.put("responseMessage", ex.getMessage());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package org.nl.system.controller.notice;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.notice.IVersionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 版本更新通知控制器
|
||||
*
|
||||
* @author miguannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/version")
|
||||
public class VersionController {
|
||||
|
||||
@Autowired
|
||||
private IVersionService versionService;
|
||||
|
||||
/**
|
||||
* 发布版本更新通知
|
||||
*
|
||||
* @param json 版本信息
|
||||
* @return ResponseEntity
|
||||
*/
|
||||
@PostMapping("/release")
|
||||
@SaCheckPermission("version:release")
|
||||
public ResponseEntity<Object> release(@RequestBody JSONObject json) {
|
||||
versionService.releaseVersion(json);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前版本信息(供前端轮询)
|
||||
*
|
||||
* @return 版本信息
|
||||
*/
|
||||
@GetMapping("/current")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> current() {
|
||||
return new ResponseEntity<>(versionService.getCurrentVersion(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询版本通知列表
|
||||
*
|
||||
* @param pageQuery 分页参数
|
||||
* @return 版本通知分页数据
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@SaCheckPermission("version:list")
|
||||
public ResponseEntity<Object> list(PageQuery pageQuery) {
|
||||
return new ResponseEntity<>(versionService.listVersions(pageQuery), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改版本通知
|
||||
*
|
||||
* @param json 通知信息(id, title, content)
|
||||
* @return ResponseEntity
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@SaCheckPermission("version:edit")
|
||||
public ResponseEntity<Object> update(@RequestBody JSONObject json) {
|
||||
versionService.updateVersion(json);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除版本通知
|
||||
*
|
||||
* @param id 通知ID
|
||||
* @return ResponseEntity
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@SaCheckPermission("version:del")
|
||||
public ResponseEntity<Object> delete(@PathVariable String id) {
|
||||
versionService.deleteVersion(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.nl.system.service.notice;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 版本更新通知服务接口
|
||||
*
|
||||
* @author miguannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
public interface IVersionService {
|
||||
|
||||
/**
|
||||
* 发布版本更新通知
|
||||
*
|
||||
* @param json 版本信息(version, title, content)
|
||||
*/
|
||||
void releaseVersion(JSONObject json);
|
||||
|
||||
/**
|
||||
* 获取当前版本信息
|
||||
*
|
||||
* @return 包含 version、enabled、pollInterval、releaseTime 的 Map
|
||||
*/
|
||||
Map<String, Object> getCurrentVersion();
|
||||
|
||||
/**
|
||||
* 查询版本通知列表
|
||||
*
|
||||
* @param pageQuery 分页参数
|
||||
* @return 版本通知分页数据
|
||||
*/
|
||||
IPage<SysNotice> listVersions(PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 修改版本通知
|
||||
*
|
||||
* @param json 通知信息(id, title, content)
|
||||
*/
|
||||
void updateVersion(JSONObject json);
|
||||
|
||||
/**
|
||||
* 删除版本通知
|
||||
*
|
||||
* @param id 通知ID
|
||||
*/
|
||||
void deleteVersion(String id);
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
package org.nl.system.service.notice.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.extension.plugins.pagination.Page;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.enums.NoticeEnum;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.mnt.websocket.MsgType;
|
||||
import org.nl.common.mnt.websocket.SocketMsg;
|
||||
import org.nl.common.mnt.websocket.WebSocketServer;
|
||||
import org.nl.system.service.notice.ISysNoticeService;
|
||||
import org.nl.system.service.notice.IVersionService;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
import org.nl.system.service.notice.dao.mapper.SysNoticeMapper;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 版本更新通知服务实现
|
||||
*
|
||||
* @author miguannan
|
||||
* @date 2026-05-06
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class VersionServiceImpl implements IVersionService {
|
||||
|
||||
@Autowired
|
||||
private ISysNoticeService noticeService;
|
||||
|
||||
@Autowired
|
||||
private ISysParamService paramService;
|
||||
|
||||
@Autowired
|
||||
private SysNoticeMapper noticeMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void releaseVersion(JSONObject json) {
|
||||
String version = json.getString("version");
|
||||
String title = json.getString("title");
|
||||
String content = json.getString("content");
|
||||
|
||||
if (StrUtil.isBlank(version)) {
|
||||
throw new BadRequestException("版本号不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(title)) {
|
||||
throw new BadRequestException("标题不能为空");
|
||||
}
|
||||
|
||||
// 检查是否已有相同版本的未读通知,避免重复发布
|
||||
long count = noticeMapper.selectCount(new LambdaQueryWrapper<SysNotice>()
|
||||
.eq(SysNotice::getNotice_type, "version_update")
|
||||
.likeRight(SysNotice::getNotice_title, version + " "));
|
||||
if (count > 0) {
|
||||
throw new BadRequestException("已存在相同版本发布信息,请先处理后再发布");
|
||||
}
|
||||
|
||||
// 1. 创建通知记录
|
||||
noticeService.createNotice(content, version + " " + title, "version_update");
|
||||
|
||||
// 2. 更新系统版本号
|
||||
Param appVersionParam = paramService.findByCode("app_version");
|
||||
if (appVersionParam == null) {
|
||||
throw new BadRequestException("系统参数 app_version 不存在,请先执行初始化脚本");
|
||||
}
|
||||
appVersionParam.setValue(version);
|
||||
paramService.update(appVersionParam);
|
||||
|
||||
// 3. WebSocket 广播给所有在线用户
|
||||
JSONObject msgData = new JSONObject();
|
||||
msgData.put("data", "version_update");
|
||||
msgData.put("version", version);
|
||||
msgData.put("title", title);
|
||||
SocketMsg socketMsg = new SocketMsg(msgData, MsgType.INFO);
|
||||
try {
|
||||
WebSocketServer.sendInfo(socketMsg, null);
|
||||
} catch (IOException e) {
|
||||
log.error("版本更新WebSocket广播失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getCurrentVersion() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 当前版本号
|
||||
Param appVersionParam = paramService.findByCode("app_version");
|
||||
String version = (appVersionParam != null) ? appVersionParam.getValue() : "1.0.0";
|
||||
|
||||
// 功能开关
|
||||
Param enabledParam = paramService.findByCode("version_notify_enabled");
|
||||
boolean enabled = (enabledParam == null) || "true".equals(enabledParam.getValue());
|
||||
|
||||
// 轮询间隔
|
||||
Param intervalParam = paramService.findByCode("version_notify_poll_interval");
|
||||
int pollInterval = 30;
|
||||
if (intervalParam != null && StrUtil.isNotBlank(intervalParam.getValue())) {
|
||||
try {
|
||||
pollInterval = Integer.parseInt(intervalParam.getValue());
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("version_notify_poll_interval 值非法: {}", intervalParam.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
result.put("version", version);
|
||||
result.put("enabled", enabled);
|
||||
result.put("pollInterval", pollInterval);
|
||||
|
||||
// 最新版本通知的发布时间
|
||||
SysNotice latest = noticeMapper.selectOne(new QueryWrapper<SysNotice>()
|
||||
.eq("notice_type", "version_update")
|
||||
.orderByDesc("create_time")
|
||||
.last("LIMIT 1"));
|
||||
if (latest != null) {
|
||||
result.put("releaseTime", latest.getCreate_time());
|
||||
// notice_title 存储格式为 "version title",分离出版本号和标题
|
||||
String noticeTitle = latest.getNotice_title();
|
||||
if (StrUtil.isNotBlank(noticeTitle) && noticeTitle.startsWith(version + " ")) {
|
||||
result.put("title", noticeTitle.substring(version.length() + 1));
|
||||
} else {
|
||||
result.put("title", noticeTitle);
|
||||
}
|
||||
result.put("content", latest.getNotice_content());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<SysNotice> listVersions(PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SysNotice> lam = new LambdaQueryWrapper<>();
|
||||
lam.eq(SysNotice::getNotice_type, "version_update")
|
||||
.orderByDesc(SysNotice::getCreate_time);
|
||||
IPage<SysNotice> pages = new Page<>(pageQuery.getPage() + 1, pageQuery.getSize());
|
||||
noticeMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVersion(JSONObject json) {
|
||||
String id = json.getString("id");
|
||||
String title = json.getString("title");
|
||||
String content = json.getString("content");
|
||||
|
||||
if (StrUtil.isBlank(id)) {
|
||||
throw new BadRequestException("ID不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(title)) {
|
||||
throw new BadRequestException("标题不能为空");
|
||||
}
|
||||
|
||||
SysNotice notice = noticeMapper.selectById(id);
|
||||
if (notice == null || !"version_update".equals(notice.getNotice_type())) {
|
||||
throw new BadRequestException("版本通知不存在");
|
||||
}
|
||||
|
||||
notice.setNotice_title(title);
|
||||
notice.setNotice_content(content);
|
||||
noticeMapper.updateById(notice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVersion(String id) {
|
||||
if (StrUtil.isBlank(id)) {
|
||||
throw new BadRequestException("ID不能为空");
|
||||
}
|
||||
SysNotice notice = noticeMapper.selectById(id);
|
||||
if (notice == null || !"version_update".equals(notice.getNotice_type())) {
|
||||
throw new BadRequestException("版本通知不存在");
|
||||
}
|
||||
noticeMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.nl.extInterface.wms.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.nl.acs.task.TaskConfig;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class AcsToWmsServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void feedbackTaskTreatsZeroResponseCodeAsAllowed() {
|
||||
ISysParamService paramService = mock(ISysParamService.class);
|
||||
when(paramService.findByCode(TaskConfig.WMSURL)).thenReturn(param(TaskConfig.WMSURL, "http://wms"));
|
||||
when(paramService.findByCode(TaskConfig.HASWMS)).thenReturn(param(TaskConfig.HASWMS, "1"));
|
||||
when(paramService.findByCode(TaskConfig.WMS_HOUSE_CODE)).thenReturn(param(TaskConfig.WMS_HOUSE_CODE, "H1"));
|
||||
when(paramService.findByCode(TaskConfig.WMS_SYSTEM_CODE)).thenReturn(param(TaskConfig.WMS_SYSTEM_CODE, "WMS"));
|
||||
|
||||
TestableAcsToWmsServiceImpl service = new TestableAcsToWmsServiceImpl(paramService);
|
||||
service.nextResponse = jsonResponse(0, "ok");
|
||||
|
||||
TaskDto task = new TaskDto();
|
||||
task.setTask_code("TASK-1");
|
||||
task.setTask_type("MOVE");
|
||||
|
||||
boolean allowed = service.feedbackTask(task, "AGV-01", "applyTake");
|
||||
|
||||
assertTrue(allowed);
|
||||
assertEquals("http://wms/restful/api/v3/system_car/feedbackTask", service.lastUrl);
|
||||
assertEquals("TASK-1", service.lastBody.getString("taskCode"));
|
||||
assertEquals("AGV-01", service.lastBody.getString("card"));
|
||||
assertEquals("MOVE", service.lastBody.getString("taskType"));
|
||||
assertEquals("applyTake", service.lastBody.getString("feedbackStatus"));
|
||||
assertEquals("H1", service.lastBody.getString("houseCode"));
|
||||
assertEquals("WMS", service.lastBody.getString("systemCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void feedbackTaskTreatsNonZeroResponseCodeAsRejected() {
|
||||
ISysParamService paramService = mock(ISysParamService.class);
|
||||
when(paramService.findByCode(TaskConfig.WMSURL)).thenReturn(param(TaskConfig.WMSURL, "http://wms"));
|
||||
when(paramService.findByCode(TaskConfig.HASWMS)).thenReturn(param(TaskConfig.HASWMS, "1"));
|
||||
when(paramService.findByCode(TaskConfig.WMS_HOUSE_CODE)).thenReturn(param(TaskConfig.WMS_HOUSE_CODE, "H1"));
|
||||
when(paramService.findByCode(TaskConfig.WMS_SYSTEM_CODE)).thenReturn(param(TaskConfig.WMS_SYSTEM_CODE, "WMS"));
|
||||
|
||||
TestableAcsToWmsServiceImpl service = new TestableAcsToWmsServiceImpl(paramService);
|
||||
service.nextResponse = jsonResponse(2, "denied");
|
||||
|
||||
TaskDto task = new TaskDto();
|
||||
task.setTask_code("TASK-2");
|
||||
task.setTask_type("MOVE");
|
||||
|
||||
boolean allowed = service.feedbackTask(task, "AGV-02", "applyPut");
|
||||
|
||||
assertFalse(allowed);
|
||||
}
|
||||
|
||||
private static Param param(String code, String value) {
|
||||
Param param = new Param();
|
||||
param.setCode(code);
|
||||
param.setValue(value);
|
||||
return param;
|
||||
}
|
||||
|
||||
private static JSONObject jsonResponse(int code, String message) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("responseCode", code);
|
||||
json.put("responseMessage", message);
|
||||
return json;
|
||||
}
|
||||
|
||||
private static class TestableAcsToWmsServiceImpl extends AcsToWmsServiceImpl {
|
||||
private JSONObject nextResponse;
|
||||
private String lastUrl;
|
||||
private JSONObject lastBody;
|
||||
|
||||
private TestableAcsToWmsServiceImpl(ISysParamService paramService) {
|
||||
super(paramService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject postJson(String url, JSONObject body) {
|
||||
this.lastUrl = url;
|
||||
this.lastBody = body;
|
||||
return nextResponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.nl.extInterface.wms.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.nl.acs.task.task.service.TaskService;
|
||||
import org.nl.acs.task.task.service.dto.TaskDto;
|
||||
import org.nl.extInterface.wms.service.dto.CreateTaskRequest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WmsToAcsServiceImplTest {
|
||||
|
||||
@Mock
|
||||
private TaskService taskService;
|
||||
|
||||
@InjectMocks
|
||||
private WmsToAcsServiceImpl service;
|
||||
|
||||
@Test
|
||||
public void createTaskMapsRequestToTaskDto() throws Exception {
|
||||
CreateTaskRequest request = new CreateTaskRequest();
|
||||
request.setTaskCode("TASK-001");
|
||||
request.setTaskType("MOVE");
|
||||
request.setContainerCode("PALLET-1");
|
||||
request.setContainerType("PALLET");
|
||||
request.setLocationFrom("A01");
|
||||
request.setLocationTo("B01");
|
||||
request.setPriority(5);
|
||||
request.setHouseCode("H1");
|
||||
request.setSystemCode("WMS");
|
||||
JSONObject parameters = new JSONObject();
|
||||
parameters.put("batch", "B1");
|
||||
request.setParameters(parameters);
|
||||
|
||||
JSONObject response = service.createTask(request);
|
||||
|
||||
ArgumentCaptor<TaskDto> captor = ArgumentCaptor.forClass(TaskDto.class);
|
||||
verify(taskService).create(captor.capture());
|
||||
TaskDto dto = captor.getValue();
|
||||
assertEquals("TASK-001", dto.getTask_code());
|
||||
assertEquals("TASK-001", dto.getExt_task_id());
|
||||
assertEquals("MOVE", dto.getTask_type());
|
||||
assertEquals("PALLET-1", dto.getVehicle_code());
|
||||
assertEquals("PALLET", dto.getVehicle_type());
|
||||
assertEquals("A01", dto.getStart_point_code());
|
||||
assertEquals("A01", dto.getStart_device_code());
|
||||
assertEquals("B01", dto.getNext_point_code());
|
||||
assertEquals("B01", dto.getNext_device_code());
|
||||
assertEquals("5", dto.getPriority());
|
||||
assertEquals("1", dto.getQuantity());
|
||||
assertTrue(dto.getRemark().contains("\"houseCode\":\"H1\""));
|
||||
assertTrue(dto.getRemark().contains("\"systemCode\":\"WMS\""));
|
||||
assertEquals(Integer.valueOf(0), response.getInteger("responseCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTaskReturnsErrorWhenTaskCreationFails() throws Exception {
|
||||
CreateTaskRequest request = new CreateTaskRequest();
|
||||
request.setTaskCode("TASK-ERR");
|
||||
request.setContainerCode("PALLET-ERR");
|
||||
request.setLocationFrom("A01");
|
||||
request.setLocationTo("B01");
|
||||
|
||||
doThrow(new IllegalStateException("duplicate task")).when(taskService).create(any(TaskDto.class));
|
||||
|
||||
JSONObject response = service.createTask(request);
|
||||
|
||||
assertEquals(Integer.valueOf(1), response.getInteger("responseCode"));
|
||||
assertEquals("duplicate task", response.getString("responseMessage"));
|
||||
}
|
||||
}
|
||||
@@ -22,27 +22,15 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$bus.on('version_update', msg => {
|
||||
this.$bus.on('version_update', (msg) => {
|
||||
this.checkVersion(msg.version)
|
||||
})
|
||||
this.$bus.on('version_check', () => {
|
||||
this.doVersionCheck()
|
||||
})
|
||||
if (this.$route.path === '/login') {
|
||||
return
|
||||
}
|
||||
this.startPolling()
|
||||
if (localStorage.getItem('needVersionCheck') === '1') {
|
||||
localStorage.removeItem('needVersionCheck')
|
||||
this.doVersionCheck()
|
||||
} else {
|
||||
this.doVersionCheck()
|
||||
}
|
||||
this.checkVersionOnLogin()
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearInterval(this.pollTimer)
|
||||
this.$bus.off('version_update')
|
||||
this.$bus.off('version_check')
|
||||
},
|
||||
methods: {
|
||||
moveEvent: function() {
|
||||
@@ -70,10 +58,9 @@ export default {
|
||||
}
|
||||
this.$refs.versionDialog.show(serverVersion)
|
||||
},
|
||||
/**
|
||||
* 执行版本检查(登录后或手动触发)
|
||||
*/
|
||||
doVersionCheck() {
|
||||
checkVersionOnLogin() {
|
||||
const token = localStorage.getItem('token') || sessionStorage.getItem('token')
|
||||
if (!token) return
|
||||
getCurrentVersion().then(res => {
|
||||
if (!res.enabled) return
|
||||
this.checkVersion(res.version)
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 获取当前版本信息
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
export function getCurrentVersion() {
|
||||
return request({
|
||||
url: '/api/version/current',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布版本更新通知
|
||||
* @param {Object} data - { version, title, content }
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
export function releaseVersion(data) {
|
||||
return request({
|
||||
url: '/api/version/release',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询版本通知列表
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
export function listVersions(params) {
|
||||
return request({
|
||||
url: '/api/version/list',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改版本通知
|
||||
* @param {Object} data - { id, title, content }
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
export function updateVersion(data) {
|
||||
return request({
|
||||
url: '/api/version/update',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除版本通知
|
||||
* @param {string} id
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
export function deleteVersion(id) {
|
||||
return request({
|
||||
url: '/api/version/delete/' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
export default { getCurrentVersion, releaseVersion, listVersions, updateVersion, deleteVersion }
|
||||
@@ -1,120 +0,0 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:visible.sync="dialogVisible"
|
||||
:show-close="false"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:title="$t('auto.version.title')"
|
||||
width="600px"
|
||||
>
|
||||
<div class="version-notification">
|
||||
<div class="version-info">
|
||||
<span class="label">{{ $t('auto.version.versionNo') }}:</span>
|
||||
<el-tag type="success" size="medium">v{{ versionInfo.version }}</el-tag>
|
||||
</div>
|
||||
<div v-if="versionInfo.title" class="version-info">
|
||||
<span class="label">{{ $t('auto.version.noticeTitle') }}:</span>
|
||||
<span>{{ versionInfo.title }}</span>
|
||||
</div>
|
||||
<div v-if="versionInfo.releaseTime" class="version-info">
|
||||
<span class="label">{{ $t('auto.version.releaseTime') }}:</span>
|
||||
<span>{{ versionInfo.releaseTime }}</span>
|
||||
</div>
|
||||
<div v-if="versionInfo.content" class="version-content">
|
||||
<div class="label">{{ $t('auto.version.content') }}:</div>
|
||||
<div class="content-body" v-html="versionInfo.content" />
|
||||
</div>
|
||||
</div>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="handleConfirm">{{ $t('auto.version.confirm') }}</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getCurrentVersion } from '@/api/system/version'
|
||||
|
||||
export default {
|
||||
name: 'VersionNotification',
|
||||
data() {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
versionInfo: {
|
||||
version: '',
|
||||
title: '',
|
||||
releaseTime: '',
|
||||
content: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
hasShown() {
|
||||
return this.dialogVisible
|
||||
},
|
||||
/**
|
||||
* 检查版本是否需要弹窗
|
||||
* @param {string} serverVersion 服务端版本号
|
||||
*/
|
||||
checkVersion(serverVersion) {
|
||||
const lastSeen = localStorage.getItem('lastSeenVersion')
|
||||
if (!serverVersion || serverVersion === lastSeen) {
|
||||
return
|
||||
}
|
||||
this.show(serverVersion)
|
||||
},
|
||||
/**
|
||||
* 显示版本更新弹窗
|
||||
* @param {string} serverVersion 版本号
|
||||
*/
|
||||
show(serverVersion) {
|
||||
getCurrentVersion().then(res => {
|
||||
if (!res.enabled) return
|
||||
this.versionInfo.version = res.version || serverVersion
|
||||
this.versionInfo.title = res.title || ''
|
||||
this.versionInfo.releaseTime = res.releaseTime || ''
|
||||
this.versionInfo.content = res.content || ''
|
||||
this.dialogVisible = true
|
||||
})
|
||||
},
|
||||
handleConfirm() {
|
||||
localStorage.setItem('lastSeenVersion', this.versionInfo.version)
|
||||
this.dialogVisible = false
|
||||
// 点击后跳转到版本信息页面
|
||||
this.$router.push('/system/version')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.version-notification {
|
||||
padding: 10px 0;
|
||||
}
|
||||
.version-info {
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.version-info .label {
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
}
|
||||
.version-content {
|
||||
margin-top: 16px;
|
||||
}
|
||||
.version-content .label {
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.version-content .content-body {
|
||||
padding: 12px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.dialog-footer {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -3,21 +3,22 @@
|
||||
<vue-particles
|
||||
class="lizi"
|
||||
color="#dedede"
|
||||
:particle-opacity="0.7"
|
||||
:particles-number="80"
|
||||
shape-type="circle"
|
||||
:particle-size="4"
|
||||
lines-color="#dedede"
|
||||
:lines-width="1"
|
||||
:line-linked="true"
|
||||
:line-opacity="0.4"
|
||||
:lines-distance="150"
|
||||
:move-speed="3"
|
||||
:hover-effect="true"
|
||||
hover-mode="grab"
|
||||
:click-effect="true"
|
||||
click-mode="push"
|
||||
/>
|
||||
:particleOpacity="0.7"
|
||||
:particlesNumber="80"
|
||||
shapeType="circle"
|
||||
:particleSize="4"
|
||||
linesColor="#dedede"
|
||||
:linesWidth="1"
|
||||
:lineLinked="true"
|
||||
:lineOpacity="0.4"
|
||||
:linesDistance="150"
|
||||
:moveSpeed="3"
|
||||
:hoverEffect="true"
|
||||
hoverMode="grab"
|
||||
:clickEffect="true"
|
||||
clickMode="push"
|
||||
>
|
||||
</vue-particles>
|
||||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="left" label-width="0px" class="login-form">
|
||||
<h3 class="title">
|
||||
{{ title }}</h3>
|
||||
@@ -186,7 +187,6 @@ export default {
|
||||
}
|
||||
this.$store.dispatch('Login', user).then(() => {
|
||||
this.loading = false
|
||||
localStorage.setItem('needVersionCheck', '1')
|
||||
window.location.href = this.redirect
|
||||
// if (this.redirect === 'http://localhost:8013/dashboard'){
|
||||
// window.location.href = this.redirect
|
||||
|
||||
@@ -1,274 +0,0 @@
|
||||
<template>
|
||||
<div class="version-container">
|
||||
<!-- 当前版本信息 -->
|
||||
<el-card class="version-card" style="margin-top: 20px">
|
||||
<div slot="header" class="card-header">
|
||||
<span>{{ $t('auto.version.currentInfo') }}</span>
|
||||
</div>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item :label="$t('auto.version.versionNo')">
|
||||
<el-tag type="success">{{ currentVersion }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('auto.version.switch')">
|
||||
<el-tag
|
||||
:type="enabled ? 'success' : 'danger'"
|
||||
>{{ enabled ? $t('auto.version.enabled') : $t('auto.version.disabled') }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item
|
||||
:label="$t('auto.version.pollInterval')"
|
||||
>{{ pollInterval }}{{ $t('auto.version.seconds') }}</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('auto.version.releaseTime')">{{ releaseTime || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
|
||||
<!-- 版本历史列表 -->
|
||||
<el-card class="version-card" style="margin-top: 20px">
|
||||
<div slot="header" class="card-header">
|
||||
<span>版本历史</span>
|
||||
</div>
|
||||
<el-table v-loading="tableLoading" :data="tableData" style="width: 100%">
|
||||
<el-table-column prop="_versionNo" label="版本号" width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="_noticeTitle" label="通知标题" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="notice_content" label="更新内容" min-width="300" show-overflow-tooltip />
|
||||
<el-table-column prop="create_time" label="发布时间" width="180" />
|
||||
<el-table-column v-if="isAdmin" label="操作" width="180" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button v-if="isAdmin" type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
|
||||
<el-button
|
||||
v-if="isAdmin"
|
||||
type="text"
|
||||
size="small"
|
||||
style="color: #f56c6c"
|
||||
@click="handleDelete(scope.row)"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<!-- 发布版本表单(仅管理员可见) -->
|
||||
<el-card v-if="isAdmin" class="version-card">
|
||||
<div slot="header" class="card-header">
|
||||
<span>{{ $t('auto.version.releaseTitle') }}</span>
|
||||
</div>
|
||||
<el-form ref="publishForm" :model="publishForm" :rules="rules" label-width="100px">
|
||||
<el-form-item :label="$t('auto.version.versionNo')" prop="version">
|
||||
<el-input v-model="publishForm.version" placeholder="例如:2.7.0" style="width: 300px" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('auto.version.noticeTitle')" prop="title">
|
||||
<el-input v-model="publishForm.title" placeholder="例如:新增AGV多车调度功能" style="width: 500px" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('auto.version.content')" prop="content">
|
||||
<el-input
|
||||
v-model="publishForm.content"
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
placeholder="请输入更新内容,支持HTML格式"
|
||||
style="width: 600px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
v-if="isAdmin"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="handleRelease"
|
||||
>{{ $t('auto.version.release') }}</el-button>
|
||||
<el-button @click="handleReset">{{ $t('auto.common.Reset') }}</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<el-dialog title="编辑版本通知" :visible.sync="editDialogVisible" width="700px">
|
||||
<el-form ref="editForm" :model="editForm" :rules="editRules" label-width="100px">
|
||||
<el-form-item label="通知标题" prop="title">
|
||||
<el-input v-model="editForm.title" style="width: 520px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="更新内容" prop="content">
|
||||
<el-input
|
||||
v-model="editForm.content"
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
placeholder="请输入更新内容,支持HTML格式"
|
||||
style="width: 520px"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="editDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="editLoading" @click="submitEdit">确认</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getCurrentVersion,
|
||||
releaseVersion,
|
||||
listVersions,
|
||||
updateVersion,
|
||||
deleteVersion
|
||||
} from '@/api/system/version'
|
||||
|
||||
export default {
|
||||
name: 'VersionRelease',
|
||||
data() {
|
||||
return {
|
||||
// 发布表单
|
||||
loading: false,
|
||||
publishForm: {
|
||||
version: '',
|
||||
title: '',
|
||||
content: ''
|
||||
},
|
||||
rules: {
|
||||
version: [{ required: true, message: '请输入版本号', trigger: 'blur' }],
|
||||
title: [{ required: true, message: '请输入标题', trigger: 'blur' }]
|
||||
},
|
||||
// 当前版本信息
|
||||
currentVersion: '',
|
||||
enabled: false,
|
||||
pollInterval: 30,
|
||||
releaseTime: '',
|
||||
// 表格
|
||||
tableLoading: false,
|
||||
tableData: [],
|
||||
// 编辑弹窗
|
||||
editDialogVisible: false,
|
||||
editLoading: false,
|
||||
editForm: {
|
||||
id: '',
|
||||
title: '',
|
||||
content: ''
|
||||
},
|
||||
editRules: {
|
||||
title: [{ required: true, message: '请输入标题', trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
/**
|
||||
* 判断当前用户是否为管理员
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isAdmin() {
|
||||
const roles = this.$store.getters && this.$store.getters.roles
|
||||
return roles && roles.includes('admin')
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.fetchCurrentVersion()
|
||||
this.fetchList()
|
||||
},
|
||||
methods: {
|
||||
fetchCurrentVersion() {
|
||||
getCurrentVersion().then(res => {
|
||||
this.currentVersion = res.version || '-'
|
||||
// 表单默认填充当前版本号,供管理员参考修改
|
||||
this.publishForm.version = res.version || ''
|
||||
this.enabled = res.enabled
|
||||
this.pollInterval = res.pollInterval || 30
|
||||
this.releaseTime = res.releaseTime || ''
|
||||
})
|
||||
},
|
||||
fetchList() {
|
||||
this.tableLoading = true
|
||||
listVersions({ page: 0, size: 999 })
|
||||
.then(res => {
|
||||
// notice_title 格式为 "version title",拆分出版本号和标题
|
||||
this.tableData = (res.records || []).map(item => {
|
||||
const titleStr = item.notice_title || ''
|
||||
const idx = titleStr.indexOf(' ')
|
||||
const versionNo = idx >= 0 ? titleStr.substring(0, idx) : titleStr
|
||||
const noticeTitle = idx >= 0 ? titleStr.substring(idx + 1) : ''
|
||||
return {
|
||||
...item,
|
||||
_versionNo: versionNo,
|
||||
_noticeTitle: noticeTitle
|
||||
}
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
this.tableLoading = false
|
||||
})
|
||||
},
|
||||
handleRelease() {
|
||||
this.$refs.publishForm.validate(valid => {
|
||||
if (!valid) return
|
||||
this.loading = true
|
||||
releaseVersion(this.publishForm)
|
||||
.then(() => {
|
||||
this.$message.success('版本更新通知已发布')
|
||||
this.handleReset()
|
||||
this.fetchCurrentVersion()
|
||||
this.fetchList()
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
handleReset() {
|
||||
this.publishForm = {
|
||||
version: '',
|
||||
title: '',
|
||||
content: ''
|
||||
}
|
||||
this.$refs.publishForm && this.$refs.publishForm.clearValidate()
|
||||
},
|
||||
handleEdit(row) {
|
||||
this.editForm = {
|
||||
id: row.notice_id,
|
||||
title: row.notice_title,
|
||||
content: row.notice_content || ''
|
||||
}
|
||||
this.editDialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.editForm && this.$refs.editForm.clearValidate()
|
||||
})
|
||||
},
|
||||
submitEdit() {
|
||||
this.$refs.editForm.validate(valid => {
|
||||
if (!valid) return
|
||||
this.editLoading = true
|
||||
updateVersion(this.editForm)
|
||||
.then(() => {
|
||||
this.$message.success('修改成功')
|
||||
this.editDialogVisible = false
|
||||
this.fetchList()
|
||||
})
|
||||
.finally(() => {
|
||||
this.editLoading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
handleDelete(row) {
|
||||
this.$confirm('确认删除该版本通知?', '提示', { type: 'warning' }).then(
|
||||
() => {
|
||||
deleteVersion(row.notice_id).then(() => {
|
||||
this.$message.success('删除成功')
|
||||
this.fetchList()
|
||||
this.fetchCurrentVersion()
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.version-container {
|
||||
padding: 20px;
|
||||
}
|
||||
.version-card {
|
||||
}
|
||||
.card-header {
|
||||
font-weight: bold;
|
||||
}
|
||||
.dialog-footer {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user