add:acs任务下发、as任务反馈
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package org.nl.wms.ext.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.ext.service.AcsToWmsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ACS调用WMS 控制层
|
||||
* </p>
|
||||
*
|
||||
* @author Liuxy
|
||||
* @since 2025-06-09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/wms")
|
||||
@Slf4j
|
||||
public class AcsToWmsController {
|
||||
@Autowired
|
||||
private AcsToWmsService acsToWmsService;
|
||||
|
||||
@PostMapping("/status")
|
||||
@Log(value = "ACS给WMS反馈任务状态")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> receiveTaskStatusAcs(@RequestBody String string) {
|
||||
return new ResponseEntity<>(acsToWmsService.receiveTaskStatusAcs(string), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.nl.wms.ext.enums;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* acs任务反馈枚举
|
||||
* </p>
|
||||
*
|
||||
* @author Liuxy
|
||||
* @since 2025-06-09
|
||||
*/
|
||||
public enum ResultAcsStatus {
|
||||
/**
|
||||
* 执行中
|
||||
*/
|
||||
EXECUTING("1", "执行中", "执行中"),
|
||||
/**
|
||||
* 完成
|
||||
*/
|
||||
FINISHED("2", "完成", "完成");
|
||||
|
||||
|
||||
ResultAcsStatus(String code, String name, String desc) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private String desc;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.nl.wms.ext.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ACS调用WMS 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Liuxy
|
||||
* @since 2025-06-09
|
||||
*/
|
||||
public interface AcsToWmsService {
|
||||
|
||||
/**
|
||||
* ACS客户端--->WMS服务端
|
||||
* ACS向WMS反馈任务状态
|
||||
*
|
||||
* @param string ACS反馈的任务数组
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> receiveTaskStatusAcs(String string);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package org.nl.wms.ext.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.ext.enums.ResultAcsStatus;
|
||||
import org.nl.wms.ext.service.AcsToWmsService;
|
||||
import org.nl.wms.sch_manage.enums.TaskStatus;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
|
||||
import org.nl.wms.sch_manage.service.util.AbstractTask;
|
||||
import org.nl.wms.sch_manage.service.util.TaskFactory;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ACS调用WMS 实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Liuxy
|
||||
* @since 2025-06-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
|
||||
/*
|
||||
* redisson连接服务
|
||||
*/
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
/*
|
||||
* 任务服务
|
||||
*/
|
||||
@Autowired
|
||||
private ISchBaseTaskService iSchBaseTaskService;
|
||||
|
||||
/**
|
||||
* 任务工厂服务
|
||||
*/
|
||||
@Autowired
|
||||
private TaskFactory taskFactory;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@SneakyThrows
|
||||
public Map<String, Object> receiveTaskStatusAcs(String string) {
|
||||
log.info("acs向lms反馈任务状态,请求参数:--------------------------------------" + string);
|
||||
JSONArray array = JSONArray.parseArray(string);
|
||||
//返回处理失败的任务
|
||||
JSONArray errArr = new JSONArray();
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject row = array.getJSONObject(i);
|
||||
String task_id = row.getString("task_id");
|
||||
RLock lock = redissonClient.getLock(task_id);
|
||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (tryLock) {
|
||||
SchBaseTask taskObj = iSchBaseTaskService.getById(task_id);
|
||||
// acs反馈的任务类型
|
||||
String acs_task_status = row.getString("task_status");
|
||||
TaskStatus status;
|
||||
if (ResultAcsStatus.EXECUTING.getCode().equals(acs_task_status)) {
|
||||
// 执行中
|
||||
status = TaskStatus.EXECUTING;
|
||||
} else if (ResultAcsStatus.FINISHED.getCode().equals(acs_task_status)) {
|
||||
// 完成
|
||||
status = TaskStatus.FINISHED;
|
||||
iSchBaseTaskService.updateById(taskObj);
|
||||
} else {
|
||||
// 取消
|
||||
status = TaskStatus.CANCELED;
|
||||
}
|
||||
// 根据配置编码执行相关配置内的方法
|
||||
AbstractTask task = taskFactory.getTask(taskObj.getConfig_code());
|
||||
task.updateTaskStatus(taskObj.getTask_code(),status);
|
||||
|
||||
} else {
|
||||
throw new BadRequestException("任务标识为:" + task_id + "的任务正在操作中!");
|
||||
}
|
||||
} finally {
|
||||
if (tryLock) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", HttpStatus.OK.value());
|
||||
result.put("message", "任务状态反馈成功!");
|
||||
result.put("data", new JSONObject());
|
||||
result.put("errArr", errArr);
|
||||
log.info("acs向lms反馈任务状态,返回参数:--------------------------------------" + result.toString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,15 @@ public abstract class AbstractTask {
|
||||
return resultForAcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 反馈任务状态
|
||||
* @param taskCode 任务编码
|
||||
* @param status 状态码
|
||||
*/
|
||||
public void updateTaskStatus(String taskCode, TaskStatus status) {
|
||||
this.updateStatus(taskCode, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以下改为public会出现自动注入类出现问题
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user