add:增加统一外部调用服务
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package org.nl.wms.gateway.controller;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.gateway.service.GateWayService;
|
||||
import org.nl.wms.gateway.dto.InteracteDto;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.nl.common.base.TableDataInfo;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 网关执行控制层
|
||||
*
|
||||
* @author gbx
|
||||
* @since 2025-06-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/wms/out")
|
||||
@Slf4j
|
||||
public class GateWayController {
|
||||
|
||||
@Resource
|
||||
private GateWayService gateWayService;
|
||||
@PostMapping("/apply")
|
||||
@SaIgnore
|
||||
@Log("外层服务请求wms")
|
||||
public ResponseEntity<Object> apply(@RequestBody InteracteDto form) {
|
||||
return new ResponseEntity<>(TableDataInfo.buildJson(gateWayService.apply(form)),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.nl.wms.gateway.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2024/5/29 16:26
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InteracteDto<T> {
|
||||
|
||||
private String service;
|
||||
private String type;
|
||||
private String ip;
|
||||
private String request_time;
|
||||
private String trace_id;
|
||||
/**
|
||||
* 要么JSONArray要么JSONObject
|
||||
*/
|
||||
private T data;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.nl.wms.gateway.service;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.RedissonUtils;
|
||||
import org.nl.wms.ext.service.AcsToWmsService;
|
||||
import org.nl.wms.gateway.dto.InteracteDto;
|
||||
import org.nl.wms.gateway.service.impl.GateWayServiceImpl;
|
||||
import org.nl.wms.sch_manage.service.ISchBasePointService;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* 网关执行接口层
|
||||
*
|
||||
* @author gbx
|
||||
* @since 2025-06-27
|
||||
*/
|
||||
@Service
|
||||
public class GateWayService {
|
||||
|
||||
@Autowired
|
||||
private GateWayServiceImpl gateWayServiceImpl;
|
||||
@Autowired
|
||||
private ISchBasePointService iSchBasePointService;
|
||||
@Autowired
|
||||
private ISchBaseTaskService iSchBaseTaskService;
|
||||
|
||||
|
||||
public JSONObject apply(InteracteDto<Map> param) {
|
||||
JSONObject jsonObject = new JSONObject(param.getData());
|
||||
//处理日志相关
|
||||
JSONObject result = new JSONObject();
|
||||
String service = param.getService();
|
||||
String type = param.getType();
|
||||
//根据服务拆分不同的业务
|
||||
if ("InStorage".equals(service)) {
|
||||
RedissonUtils.lock(() -> {
|
||||
String taskCode = gateWayServiceImpl.applyTask(param.getService(), type, jsonObject, param);
|
||||
result.put("taskCode", taskCode);
|
||||
}, param.getService() + param.getType(), null);
|
||||
}
|
||||
if ("Task".equals(service)) {
|
||||
iSchBaseTaskService.operation(jsonObject);
|
||||
}
|
||||
if ("DeviceInfo".equals(service)) {
|
||||
|
||||
}
|
||||
if ("Device".equals(service)) {
|
||||
Assert.noNullElements(new Object[]{jsonObject.getString("devicePoint"), jsonObject.getString("status")}, "请求参数不能为空");
|
||||
if (!"1207".equals(jsonObject.getString("devicePoint")) && !"1210".equals(jsonObject.getString("devicePoint"))) {
|
||||
throw new BadRequestException("您输入的拣选位不存在,请输入1207或1210拣选位!");
|
||||
}
|
||||
RedissonUtils.lock(() -> {
|
||||
LambdaUpdateWrapper<SchBasePoint> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(SchBasePoint::getIs_used, "0".equals(jsonObject.getString("status")) ? 0 : 1);
|
||||
iSchBasePointService.update(updateWrapper);
|
||||
}, param.getService() + param.getType(), null);
|
||||
}
|
||||
if ("ErrorInfo".equals(service)) {
|
||||
Assert.noNullElements(new Object[]{type, jsonObject.getString("msg")}, "请求参数不能为空");
|
||||
String msg = jsonObject.getString("msg").trim();
|
||||
//iSchBasePointService.sendErrorMsg(type,null, msg);
|
||||
}
|
||||
if ("ErrorTask".equals(service)) {
|
||||
AtomicReference<JSONObject> reference = new AtomicReference<>(new JSONObject());
|
||||
RedissonUtils.lock(() -> {
|
||||
// reference.set(iSchBaseTaskService.errorTask(jsonObject, param.getType()));
|
||||
}, param.getService() + param.getType(), null);
|
||||
return reference.get();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.nl.wms.gateway.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.gateway.dto.InteracteDto;
|
||||
import org.nl.wms.sch_manage.service.ISchBasePointService;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch_manage.service.util.AbstractTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 网关执行实现层
|
||||
*
|
||||
* @author gbx
|
||||
* @since 2025-06-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class GateWayServiceImpl {
|
||||
|
||||
|
||||
@Resource
|
||||
private Map<String, AbstractTask> applyTaskMap;
|
||||
|
||||
public String applyTask(String service, String type, JSONObject data, InteracteDto<Map> param) {
|
||||
if ("InStorage".equals(service)) {
|
||||
try {
|
||||
String taskId = applyTaskMap.get(type).create(data);
|
||||
if (StringUtils.isBlank(taskId)) {
|
||||
log.error("创建任务失败:返回任务信息为空,申请参数为:" + JSON.toJSONString(param));
|
||||
throw new BadRequestException("创建任务失败:返回任务信息为空,申请参数为:" + JSON.toJSONString(param));
|
||||
}
|
||||
return taskId;
|
||||
} catch (Exception e) {
|
||||
if (param.getData() != null) {
|
||||
String title = param.getType() + DateUtil.today() + param.getData().toString();
|
||||
// iSchBasePointService.sendErrorMsg("1", title, "任务申请失败,申请参数为:" + JSON.toJSONString(param) + "请查看错误日志" + e);
|
||||
}
|
||||
throw new BadRequestException("申请任务失败,申请参数为:" + JSON.toJSONString(param) + "请查看错误日志:" + e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class AutoTask {
|
||||
private TaskFactory taskFactory;
|
||||
|
||||
private final RedissonClient redissonClient;
|
||||
|
||||
//定时任务
|
||||
@SneakyThrows
|
||||
public void run() {
|
||||
RLock lock = redissonClient.getLock(this.getClass().getName());
|
||||
@@ -54,7 +54,7 @@ public class AutoTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发任务
|
||||
* 定时下发任务
|
||||
*/
|
||||
private void sendTask() {
|
||||
List<SchBaseTask> taskList = taskService.list(new LambdaQueryWrapper<SchBaseTask>()
|
||||
|
||||
Reference in New Issue
Block a user