4 changed files with 88 additions and 155 deletions
@ -1,73 +0,0 @@ |
|||||
package org.nl.wms.ext.util; |
|
||||
|
|
||||
import cn.hutool.core.util.ObjectUtil; |
|
||||
import cn.hutool.http.HttpRequest; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.nl.config.SpringContextHolder; |
|
||||
import org.nl.system.enums.SysParamConstant; |
|
||||
import org.nl.system.service.param.dao.Param; |
|
||||
import org.nl.system.service.param.impl.SysParamServiceImpl; |
|
||||
import org.nl.wms.ext.service.util.AcsResponse; |
|
||||
import org.nl.wms.warehouse_management.enums.IOSConstant; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
/** |
|
||||
* <p> |
|
||||
* ACS工具类 |
|
||||
* </p> |
|
||||
* |
|
||||
* @author Liuxy |
|
||||
* @since 2025-06-09 |
|
||||
*/ |
|
||||
@Slf4j |
|
||||
@Component |
|
||||
public class AcsUtil { |
|
||||
|
|
||||
/** |
|
||||
* 下发任务 |
|
||||
* @param api acs地址 |
|
||||
* @param param 下发参数 |
|
||||
* @return AcsResponse |
|
||||
*/ |
|
||||
public static <T> AcsResponse notifyAcs(String api, T param) { |
|
||||
log.info("下发ACS任务的输入参数为:-------------------" + param.toString()); |
|
||||
// 返回参数
|
|
||||
AcsResponse resultAcs; |
|
||||
// 系统参数类
|
|
||||
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class); |
|
||||
//判断是否连接ACS系统
|
|
||||
Param isConnectAcs = sysParamService.findByCode(SysParamConstant.IS_CONNECT_ACS); |
|
||||
if (ObjectUtil.isEmpty(isConnectAcs)) { |
|
||||
return AcsResponse.requestError("系统参数表中:" + SysParamConstant.IS_CONNECT_ACS + "不存在"); |
|
||||
} |
|
||||
if (isConnectAcs.getValue().equals(IOSConstant.IS_DELETE_NO)) { |
|
||||
return AcsResponse.requestOkMessage("下发成功,未连接ACS系统!"); |
|
||||
} |
|
||||
|
|
||||
//ACS地址
|
|
||||
Param acsUrlParam = sysParamService.findByCode(SysParamConstant.ACS_URL); |
|
||||
if (ObjectUtil.isEmpty(acsUrlParam)) { |
|
||||
return AcsResponse.requestError("系统参数表中:" + SysParamConstant.ACS_URL + "不存在"); |
|
||||
} |
|
||||
|
|
||||
String url = acsUrlParam.getValue() + api; |
|
||||
try { |
|
||||
String resultMsg = HttpRequest.post(url) |
|
||||
.body(String.valueOf(param)) |
|
||||
.execute().body(); |
|
||||
// 格式转换
|
|
||||
JSONObject result = JSONObject.parseObject(resultMsg); |
|
||||
resultAcs = JSONObject.toJavaObject(result, AcsResponse.class); |
|
||||
|
|
||||
log.info("下发ACS任务的输出参数为:-------------------" + resultMsg); |
|
||||
} catch (Exception e) { |
|
||||
//网络不通
|
|
||||
String msg = e.getMessage(); |
|
||||
log.error("连接失败:{}", msg); |
|
||||
return AcsResponse.requestError("网络不通,操作失败!"); |
|
||||
} |
|
||||
return resultAcs; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -0,0 +1,50 @@ |
|||||
|
package org.nl.wms.ext.util; |
||||
|
|
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import cn.hutool.http.HttpRequest; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.common.exception.BadRequestException; |
||||
|
import org.nl.config.SpringContextHolder; |
||||
|
import org.nl.system.service.param.dao.Param; |
||||
|
import org.nl.system.service.param.impl.SysParamServiceImpl; |
||||
|
import org.nl.wms.warehouse_management.enums.IOSConstant; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* <p> |
||||
|
* api连接工具类 |
||||
|
* </p> |
||||
|
* |
||||
|
* @author gbx |
||||
|
* @since 2025-07-08 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class NotifyUtil { |
||||
|
public static <T, R> R apiNotify(String api, String isNeedConnect, String systemType, T param, Class<R> responseClass) { |
||||
|
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class); |
||||
|
String connectValue = getParam(sysParamService, isNeedConnect); |
||||
|
if (IOSConstant.IS_DELETE_NO.equals(connectValue)) { |
||||
|
log.info("未连接系统,跳过下发!"); |
||||
|
} |
||||
|
String url = getParam(sysParamService, systemType) + api; |
||||
|
try { |
||||
|
String response = HttpRequest.post(url).body(String.valueOf(param)).execute().body(); |
||||
|
log.info("【下发任务请求】API: {}, param: {}", api, param); |
||||
|
log.info("下发ACS任务完成,api:{}下发参数为:-------------------{},响应信息:{}", api, param, response); |
||||
|
return JSONObject.parseObject(response, responseClass); |
||||
|
} catch (Exception e) { |
||||
|
log.error("下发任务失败,api: {}, 错误信息: {}", api, e.getMessage(), e); |
||||
|
throw new BadRequestException("下发任务失败:网络异常或调用失败!"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static String getParam(SysParamServiceImpl service, String code) { |
||||
|
Param param = service.findByCode(code); |
||||
|
if (param == null || StrUtil.isBlank(param.getValue())) { |
||||
|
throw new BadRequestException("系统参数不存在: " + code); |
||||
|
} |
||||
|
return param.getValue(); |
||||
|
} |
||||
|
} |
@ -1,82 +0,0 @@ |
|||||
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,38 @@ |
|||||
|
package org.nl.wms.gateway.service; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import org.nl.wms.ext.service.util.AcsResponse; |
||||
|
import org.nl.wms.gateway.dto.InteracteDto; |
||||
|
import org.nl.wms.gateway.dto.RcsResponse; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 网关执行接口层 |
||||
|
* |
||||
|
* @author gbx |
||||
|
* @since 2025-06-27 |
||||
|
*/ |
||||
|
@Service |
||||
|
public interface IGateWayService { |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 外部系统请求wms |
||||
|
*/ |
||||
|
JSONObject apply(InteracteDto<Map> param); |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 下发Rcs任务 |
||||
|
* @param list 任务集合 |
||||
|
* @return AcsResponse |
||||
|
*/ |
||||
|
RcsResponse renotifyRcs(List<String> list); |
||||
|
|
||||
|
|
||||
|
} |
Loading…
Reference in new issue