李永德
1 year ago
20 changed files with 298 additions and 74 deletions
@ -1,9 +1,22 @@ |
|||||
package org.nl.wms.ext.acs.service; |
package org.nl.wms.ext.acs.service; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import org.nl.wms.ext.acs.service.dto.ResultForAcs; |
||||
|
import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
/** |
/** |
||||
* @Author: lyd |
* @Author: lyd |
||||
* @Description: Wms请求Acs |
* @Description: Wms请求Acs |
||||
* @Date: 2023/6/30 |
* @Date: 2023/6/30 |
||||
*/ |
*/ |
||||
public interface WmsToAcsService { |
public interface WmsToAcsService { |
||||
|
|
||||
|
/** |
||||
|
* 下发工单 |
||||
|
* @param workorder |
||||
|
* @return |
||||
|
*/ |
||||
|
ResultForAcs order(PdmBdWorkorder workorder); |
||||
} |
} |
||||
|
@ -0,0 +1,44 @@ |
|||||
|
package org.nl.wms.ext.acs.service.dto; |
||||
|
|
||||
|
import cn.hutool.core.date.DateUtil; |
||||
|
import cn.hutool.http.HttpStatus; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @Author: lyd |
||||
|
* @Description: 统一接口返回 - 请求ACS返回的数据类型 |
||||
|
* @Date: 2023/7/28 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ResultForAcs { |
||||
|
private int status; |
||||
|
private String message; |
||||
|
private String timestamp; |
||||
|
private JSONObject data; |
||||
|
|
||||
|
public static ResultForAcs requestRefuse(String message) { |
||||
|
ResultForAcs result = new ResultForAcs(); |
||||
|
result.setStatus(HttpStatus.HTTP_BAD_REQUEST); |
||||
|
result.setMessage(message); |
||||
|
result.setTimestamp(DateUtil.now()); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static ResultForAcs requestOk() { |
||||
|
ResultForAcs result = new ResultForAcs(); |
||||
|
result.setStatus(HttpStatus.HTTP_OK); |
||||
|
result.setMessage("请求成功"); |
||||
|
result.setTimestamp(DateUtil.now()); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static ResultForAcs requestOk(String message, JSONObject data) { |
||||
|
ResultForAcs result = new ResultForAcs(); |
||||
|
result.setStatus(HttpStatus.HTTP_OK); |
||||
|
result.setMessage(message); |
||||
|
result.setTimestamp(DateUtil.now()); |
||||
|
result.setData(data); |
||||
|
return result; |
||||
|
} |
||||
|
} |
@ -1,15 +1,46 @@ |
|||||
package org.nl.wms.ext.acs.service.impl; |
package org.nl.wms.ext.acs.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.date.DateUtil; |
||||
|
import cn.hutool.http.HttpStatus; |
||||
import lombok.extern.slf4j.Slf4j; |
import lombok.extern.slf4j.Slf4j; |
||||
import org.nl.wms.ext.acs.service.WmsToAcsService; |
import org.nl.wms.ext.acs.service.WmsToAcsService; |
||||
|
import org.nl.wms.ext.acs.service.dto.ResultForAcs; |
||||
|
import org.nl.wms.ext.record.service.ISysInteractRecordService; |
||||
|
import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; |
||||
|
import org.nl.wms.sch.task_manage.GeneralDefinition; |
||||
|
import org.nl.wms.sch.task_manage.task.AcsUtil; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
/** |
/** |
||||
* @Author: lyd |
* @Author: lyd |
||||
* @Description: |
* @Description: WMS请求ACS - 业务开发 |
||||
* @Date: 2023/6/30 |
* @Date: 2023/6/30 |
||||
*/ |
*/ |
||||
@Slf4j |
@Slf4j |
||||
@Service |
@Service |
||||
public class WmsToAcsServiceImpl implements WmsToAcsService { |
public class WmsToAcsServiceImpl implements WmsToAcsService { |
||||
|
@Autowired |
||||
|
private ISysInteractRecordService interactRecordService; |
||||
|
@Override |
||||
|
public ResultForAcs order(PdmBdWorkorder workorder) { |
||||
|
String api = "api/wms/order"; |
||||
|
List<PdmBdWorkorder> list = new ArrayList<>(); |
||||
|
list.add(workorder); |
||||
|
ResultForAcs resultForAcs = ResultForAcs.requestOk(); |
||||
|
try { |
||||
|
resultForAcs = AcsUtil.notifyAcs(api, list); |
||||
|
} catch (Exception e) { |
||||
|
log.error(api + ": {}", e.getMessage()); |
||||
|
resultForAcs.setTimestamp(DateUtil.now()); |
||||
|
resultForAcs.setStatus(HttpStatus.HTTP_BAD_REQUEST); |
||||
|
resultForAcs.setMessage(e.getMessage()); |
||||
|
} |
||||
|
// 记录日志
|
||||
|
interactRecordService.saveRecord(workorder, resultForAcs, GeneralDefinition.LMS_ACS); |
||||
|
return resultForAcs; |
||||
|
} |
||||
} |
} |
||||
|
@ -1,105 +1,67 @@ |
|||||
|
|
||||
package org.nl.wms.sch.task_manage.task; |
package org.nl.wms.sch.task_manage.task; |
||||
|
|
||||
import cn.hutool.core.util.ObjectUtil; |
import cn.hutool.core.util.ObjectUtil; |
||||
import cn.hutool.core.util.StrUtil; |
import cn.hutool.core.util.StrUtil; |
||||
import cn.hutool.http.HttpRequest; |
import cn.hutool.http.HttpRequest; |
||||
import com.alibaba.fastjson.JSONArray; |
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
import com.alibaba.fastjson.JSONObject; |
||||
import lombok.extern.slf4j.Slf4j; |
import lombok.extern.slf4j.Slf4j; |
||||
import org.nl.common.exception.BadRequestException; |
import org.nl.common.exception.BadRequestException; |
||||
import org.nl.config.SpringContextHolder; |
import org.nl.config.SpringContextHolder; |
||||
import org.nl.system.service.param.dao.Param; |
import org.nl.system.service.param.dao.Param; |
||||
import org.nl.system.service.param.impl.SysParamServiceImpl; |
import org.nl.system.service.param.impl.SysParamServiceImpl; |
||||
import org.nl.wms.ext.record.service.ISysInteractRecordService; |
import org.nl.wms.ext.acs.service.dto.ResultForAcs; |
||||
import org.nl.wms.ext.record.service.impl.SysInteractRecordServiceImpl; |
|
||||
import org.nl.wms.sch.task_manage.AcsTaskDto; |
|
||||
import org.nl.wms.sch.task_manage.GeneralDefinition; |
import org.nl.wms.sch.task_manage.GeneralDefinition; |
||||
import org.springframework.http.HttpStatus; |
|
||||
|
|
||||
import java.util.List; |
import java.util.List; |
||||
|
|
||||
/** |
/** |
||||
* ACS连接工具类: |
* ACS连接工具类: 不允许直接操作结果,将其封装到ResultForAcs,由实现类操作 |
||||
*/ |
*/ |
||||
@Slf4j |
@Slf4j |
||||
public class AcsUtil { |
public class AcsUtil { |
||||
/** |
/** |
||||
* 统一多数据入口 |
* 统一多数据入口: 默认执行的参数都是jsonArray |
||||
* @param api |
* @param api |
||||
* @param list |
* @param list |
||||
* @return |
* @return |
||||
* @param <T> |
* @param <T> |
||||
*/ |
*/ |
||||
public static <T> JSONObject notifyAcs(String api, List<T> list) { |
public static <T> ResultForAcs notifyAcs(String api, List<T> list) { |
||||
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class); |
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class); |
||||
|
// list转JSONArray
|
||||
|
String s = JSON.toJSONString(list); |
||||
//判断是否连接ACS系统
|
//判断是否连接ACS系统
|
||||
Param isConnectAcs = sysParamService.findByCode("IS_CONNECT_ACS"); |
Param isConnectAcs = sysParamService.findByCode(GeneralDefinition.IS_CONNECT_ACS); |
||||
if (ObjectUtil.isEmpty(isConnectAcs)) { |
if (ObjectUtil.isEmpty(isConnectAcs)) { |
||||
throw new BadRequestException("参数表中:IS_CONNECT_ACS不存在"); |
throw new BadRequestException("参数表中:" + GeneralDefinition.IS_CONNECT_ACS + "不存在"); |
||||
} |
} |
||||
String isConnect = isConnectAcs.getValue(); |
String isConnect = isConnectAcs.getValue(); |
||||
JSONObject result = new JSONObject(); |
|
||||
if (StrUtil.equals(GeneralDefinition.NO, isConnect)) { |
|
||||
result.put("status", HttpStatus.BAD_REQUEST.value()); |
|
||||
result.put("message", "未连接ACS!"); |
|
||||
result.put("data", new JSONObject()); |
|
||||
return result; |
|
||||
} |
|
||||
//ACS地址:127.0.0.1:8010
|
//ACS地址:127.0.0.1:8010
|
||||
Param acsUrlObj = sysParamService.findByCode("ACS_URL"); |
Param acsUrlObj = sysParamService.findByCode(GeneralDefinition.ACS_URL); |
||||
if (ObjectUtil.isEmpty(acsUrlObj)) { |
if (ObjectUtil.isEmpty(acsUrlObj)) { |
||||
throw new BadRequestException("参数表中:ACS_URL不存在"); |
throw new BadRequestException("参数表中:" + GeneralDefinition.ACS_URL + "不存在"); |
||||
} |
} |
||||
String acsUrl = acsUrlObj.getValue(); |
String acsUrl = acsUrlObj.getValue(); |
||||
String url = acsUrl + api; |
JSONObject result; |
||||
log.info("下发acs任务的参数为:{}", list.toString()); |
|
||||
try { |
|
||||
String resultMsg = HttpRequest.post(url) |
|
||||
.body(String.valueOf(list)) |
|
||||
.execute().body(); |
|
||||
result = JSONObject.parseObject(resultMsg); |
|
||||
} catch (Exception e) { |
|
||||
String msg = e.getMessage(); |
|
||||
//ConnectException: Connection refused: connect
|
|
||||
//网络不通
|
|
||||
log.error("连接失败:{}", msg); |
|
||||
result.put("status", HttpStatus.BAD_REQUEST); |
|
||||
result.put("message", "网络不通,操作失败!"); |
|
||||
result.put("data", new JSONObject()); |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
public static <T> JSONObject notifyAcs(String api, T object) { |
|
||||
//判断是否连接ACS系统
|
|
||||
String isConnect = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("IS_CONNECT_ACS").getValue(); |
|
||||
JSONObject result = new JSONObject(); |
|
||||
if (StrUtil.equals(GeneralDefinition.NO, isConnect)) { |
if (StrUtil.equals(GeneralDefinition.NO, isConnect)) { |
||||
result.put("status", HttpStatus.BAD_REQUEST.value()); |
return ResultForAcs.requestRefuse("未连接ACS!"); |
||||
result.put("message", "未连接ACS!"); |
|
||||
result.put("data", new JSONObject()); |
|
||||
return result; |
|
||||
} |
} |
||||
//ACS地址:127.0.0.1:8010
|
|
||||
String acsUrl = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("ACS_URL").getValue(); |
|
||||
|
|
||||
String url = acsUrl + api; |
String url = acsUrl + api; |
||||
log.info("下发acs任务的参数为:{}", object.toString()); |
log.info("下发acs任务的参数为:{}", list.toString()); |
||||
|
ResultForAcs resultForAcs; |
||||
try { |
try { |
||||
String resultMsg = HttpRequest.post(url) |
String resultMsg = HttpRequest.post(url) |
||||
.body(String.valueOf(object)) |
.body(s) |
||||
.execute().body(); |
.execute().body(); |
||||
result = JSONObject.parseObject(resultMsg); |
result = JSONObject.parseObject(resultMsg); |
||||
|
resultForAcs = JSONObject.toJavaObject(result, ResultForAcs.class); |
||||
} catch (Exception e) { |
} catch (Exception e) { |
||||
String msg = e.getMessage(); |
String msg = e.getMessage(); |
||||
//ConnectException: Connection refused: connect
|
|
||||
//网络不通
|
//网络不通
|
||||
log.error("连接失败:{}", msg); |
log.error("连接失败:{}", msg); |
||||
result.put("status", HttpStatus.BAD_REQUEST); |
return ResultForAcs.requestRefuse("网络不通,操作失败!"); |
||||
result.put("message", "网络不通,操作失败!"); |
|
||||
result.put("data", new JSONObject()); |
|
||||
} |
} |
||||
// 记录交互表
|
return resultForAcs; |
||||
return result; |
|
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue