Commit 020f2b74 hc

add:lizhen远程接口封装

1 个父辈 8ee00be2
package com.neotel.smfcore.custom.lizhen;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ApiException;
......@@ -21,6 +23,12 @@ import com.neotel.smfcore.core.order.service.po.LiteOrder;
import com.neotel.smfcore.core.order.service.po.LiteOrderItem;
import com.neotel.smfcore.core.system.service.manager.IDataLogManager;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.custom.lizhen.api.LizhenApiListener;
import com.neotel.smfcore.custom.lizhen.api.bean.request.GetReturnInventoryRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.request.GetSpareNoRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.request.GetUnclaimedRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.request.SpareInHourseRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.result.SpareInHourseResult;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.PreWarningItem;
import com.neotel.smfcore.custom.lizhen.innerBox.util.PreWarningItemCache;
import com.neotel.smfcore.custom.lizhen.third.maicheng.bean.AskReelBoxList;
......@@ -354,6 +362,78 @@ public class LizhenController {
return ResultBean.newErrorResult(-1,"","未找到相关信息");
}
@RequestMapping("/getSpareNo")
@ApiOperation("备品仓入库单号查询接口")
@AnonymousAccess
public ResultBean getSpareNo(@RequestBody Map<String, String> params) {
String functionDept = params.get("functionDept");
String deptId = params.get("deptId");
GetSpareNoRequest spareNoRequest = new GetSpareNoRequest();
spareNoRequest.setFunctionDept(functionDept);
spareNoRequest.setDeptId(deptId);
return ResultBean.newOkResult(LizhenApiListener.getSpareNo(spareNoRequest));
}
// 退库查询接口
@RequestMapping("/getReturnInventory")
@ApiOperation("退库查询接口")
@AnonymousAccess
public ResultBean getReturnInventory(@RequestBody Map<String, String> params) {
String functionDept = params.get("functionDept");
String deptId = params.get("deptId");
if (StringUtils.isEmpty(functionDept)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}功能部门不能为空", new String[]{""});
}
if (StringUtils.isEmpty(deptId)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}厂区ID不能为空", new String[]{""});
}
GetReturnInventoryRequest request = new GetReturnInventoryRequest();
request.setFunctionDept(functionDept);
request.setDeptId(deptId);
return ResultBean.newOkResult(LizhenApiListener.getReturnInventory(request));
}
// 预约待领取接口
@RequestMapping("/getUnclaimedDetails")
@ApiOperation("预约待领取接口")
@AnonymousAccess
public ResultBean getUnclaimedDetails(@RequestBody Map<String, String> params) {
String functionDept = params.get("functionDept");
String deptId = params.get("deptId");
if (StringUtils.isEmpty(functionDept)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}功能部门不能为空", new String[]{""});
}
if (StringUtils.isEmpty(deptId)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}厂区ID不能为空", new String[]{""});
}
GetUnclaimedRequest request = new GetUnclaimedRequest();
request.setFunctionDept(functionDept);
request.setDeptId(deptId);
// 假设还有其它参数需要解析
return ResultBean.newOkResult(LizhenApiListener.getUnclaimedDetails(request));
}
// 备品仓入库接口
@RequestMapping("/spareInHourse")
@ApiOperation("备品仓入库接口")
@AnonymousAccess
public ResultBean spareInHourse(@RequestBody SpareInHourseRequest request) {
if (StringUtils.isEmpty(request.getDeptId())) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}厂区id不能为空", new String[]{""});
}
if (StringUtils.isEmpty(request.getSpareNo())) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}单据号不能为空", new String[]{""});
}
if (StringUtils.isEmpty(request.getWhCode())) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}仓库代码不能为空", new String[]{""});
}
if (ObjectUtil.isNotEmpty(request.getDetailList())) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}料号明细列表不能为空", new String[]{""});
}
return ResultBean.newOkResult(LizhenApiListener.spareInHourse(request));
}
......
......@@ -215,10 +215,12 @@ public class AgvBoxDeviceClientController {
List<DataLog> allTasks = taskService.getAllTasks();
for (DataLog task : allTasks) {
if (task.getBarcode().equals(barcode.getBarcode())) {
taskData.put("barcode", barcode.getBarcode());
taskData.put("slotCode",task.getPosName());
return ResultBean.newOkResult(taskData);
if (!task.isFinished() && !task.isCancel()) {
if (task.getBarcode().equals(barcode.getBarcode())) {
taskData.put("barcode", barcode.getBarcode());
taskData.put("slotCode", task.getPosName());
return ResultBean.newOkResult(taskData);
}
}
}
StoragePos pos = taskService.findEmptyPosForPutIn(storageList, barcode, "", "");
......
package com.neotel.smfcore.custom.lizhen.api;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.api.listener.DefaultSmfApiListener;
import com.neotel.smfcore.custom.lizhen.api.bean.LizhenApiResult;
import com.neotel.smfcore.custom.lizhen.api.bean.request.GetReturnInventoryRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.request.GetSpareNoRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.request.GetUnclaimedRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.request.SpareInHourseRequest;
import com.neotel.smfcore.custom.lizhen.api.bean.result.GetReturnInventoryResult;
import com.neotel.smfcore.custom.lizhen.api.bean.result.GetSpareNoResult;
import com.neotel.smfcore.custom.lizhen.api.bean.result.GetUnclaimedResult;
import com.neotel.smfcore.custom.lizhen.api.bean.result.SpareInHourseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Map;
@Slf4j
@Component
public class LizhenApiListener extends DefaultSmfApiListener {
public static String GetSpareNoUrl;
public static String SpareInHourseUrl;
private static String GetUnclaimedUrl;
private static String GetReturnInventory;
@Value("${api.getSpareNo:}")
public void setGetSpareNoUrl(String url) {
LizhenApiListener.GetSpareNoUrl = url;
}
@Value("${api.spareInhourse:}")
public void setSpareInHourseUrl(String url) {
LizhenApiListener.SpareInHourseUrl = url;
}
@Value("${api.getUnclaimed:}")
private void setGetUnclaimedUrl(String url) {
LizhenApiListener.GetUnclaimedUrl = url;
}
@Value("${api.getReturnInventory:}")
private void setGetReturnInventory(String url) {
LizhenApiListener.GetReturnInventory = url;
}
// 备品仓退库查询接口的GET方法
public static GetReturnInventoryResult getReturnInventory(GetReturnInventoryRequest request) {
try {
// 记录请求日志
log.info("备品仓退库查询接口请求为: " + JSON.toJSONString(request));
// 构造请求URL,附加查询参数
String url = GetReturnInventory + getQueryStr(request);
// 发送GET请求并获取JSON格式的响应字符串
String resJsonStr = HttpHelper.sendGet(url);
log.info("备品仓退库查询接口返回为:" + JSON.toJSONString(request));
// 将响应字符串解析为LizhenApiResult对象
LizhenApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LizhenApiResult.class);
// 检查API调用是否成功,并返回结果对象
if (ObjectUtil.isNotNull(lizhenApiResult)) {
if (lizhenApiResult.getCode() != 200) {
throw new Exception(String.format("备品仓退库查询接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
GetReturnInventoryResult data = JSONObject.parseObject(lizhenApiResult.getData(), GetReturnInventoryResult.class);
return data;
}
} catch (Exception e) {
// 记录异常日志
log.error("备品仓退库查询接口请求失败: " + e.getMessage(), e);
// 抛出自定义异常
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
}
// 如果没有成功返回结果,抛出异常
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{GetReturnInventory});
}
public static GetUnclaimedResult getUnclaimedDetails(GetUnclaimedRequest request) {
try {
log.info("预约待领取接口请求为:" + request);
String url = GetUnclaimedUrl + getQueryStr(request);
log.info("预约待领取接口请求返回:" + JSON.toJSONString(request));
String resJsonStr = HttpHelper.sendGet(url);
LizhenApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LizhenApiResult.class);
if (lizhenApiResult.getCode() != 200) {
throw new Exception(String.format("预约待领取接口接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
String data = lizhenApiResult.getData();
GetUnclaimedResult getUnclaimedResult = JSONObject.parseObject(data, GetUnclaimedResult.class);
if (ObjectUtil.isNotNull(getUnclaimedResult)) {
return getUnclaimedResult;
}
} catch (Exception e) {
log.info("getUnclaimedDetails请求失败:" + e.getMessage());
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
}
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{GetUnclaimedUrl});
}
public static SpareInHourseResult spareInHourse(SpareInHourseRequest request) {
try {
log.info("备品仓入库接口请求为:" + JSON.toJSONString(request));
String resJsonStr = HttpHelper.postJson(SpareInHourseUrl, request);
log.info("备品仓入库接口返回:" + JSON.toJSONString(request));
LizhenApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LizhenApiResult.class);
if (lizhenApiResult.getCode() != 200) {
throw new ApiException(String.format("备品仓入库接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
SpareInHourseResult spareInHourseResult = JSONObject.parseObject(lizhenApiResult.getData(), SpareInHourseResult.class);
if (ObjectUtil.isNotNull(spareInHourseResult)) {
return spareInHourseResult;
}
} catch (ApiException e) {
log.info("备品仓入库接口请求失败:" + e.getMessage());
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
}
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{SpareInHourseUrl});
}
public static GetSpareNoResult getSpareNo(GetSpareNoRequest request) {
try {
log.info("获取入库单号请求为:" + JSON.toJSONString(request));
String url = GetSpareNoUrl + getQueryStr(request);
log.info("获取入库单号返回:" + JSON.toJSONString(request));
String resJsonStr = HttpHelper.sendGet(url);
LizhenApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LizhenApiResult.class);
if (lizhenApiResult.getCode() != 200) {
throw new Exception(String.format("获取入库单号接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
GetSpareNoResult spareNoResult = JSONObject.parseObject(lizhenApiResult.getData(), GetSpareNoResult.class);
if (ObjectUtil.isNotNull(spareNoResult)) {
return spareNoResult;
}
} catch (Exception e) {
log.info("getSpareNo请求失败:" + e.getMessage());
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
}
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{GetSpareNoUrl});
}
/*public static GetSpareNoResult getSpareNo(GetSpareNoRequest request) {
log.info("获取入库单号请求为:" + JSON.toJSONString(request));
HttpHelper.sendGet()
}*/
......@@ -32,4 +162,21 @@ public class LizhenApiListener extends DefaultSmfApiListener {
public boolean isForThisApi(String apiName) {
return apiName != null && apiName.equalsIgnoreCase("Lizhen");
}
private static String getQueryStr(Object obj) {
String str = "";
String queryStr = JSONObject.toJSONString(obj);
JSONObject queryJson = JSONObject.parseObject(queryStr);
for (Map.Entry<String, Object> entry : queryJson.entrySet()) {
Object value = entry.getValue();
if (value != null) {
if (StringUtils.isNotBlank(str)) {
str = str + "&" + entry.getKey() + "=" + entry.getValue();
} else {
str = "?" + entry.getKey() + "=" + entry.getValue();
}
}
}
return str;
}
}
package com.neotel.smfcore.custom.lizhen.api.bean.request;
import lombok.Data;
/**
* 请求类,用于获取退库库存的请求参数
*/
@Data
public class GetReturnInventoryRequest {
/**
* 功能部门
*/
private String functionDept;
/**
* 厂区id
*/
private String deptId;
}
package com.neotel.smfcore.custom.lizhen.api.bean.request;
import lombok.Data;
/**
* 请求类,用于获取未领取的备件申请信息
*/
@Data
public class GetUnclaimedRequest {
/**
* 厂区id
*/
private String deptId;
/**
* 功能部门
*/
private String functionDept;
}
package com.neotel.smfcore.custom.lizhen.api.bean.request;
import com.neotel.smfcore.custom.lizhen.api.bean.result.SpareInHourseDetail;
import lombok.Data;
import java.util.List;
/**
* 请求类,用于表示SpareInHourse的请求参数
*/
@Data
public class SpareInHourseRequest {
/**
* 厂区id
*/
private String deptId;
/**
* 单据号
*/
private String spareNo;
/**
* 仓库代码
*/
private String whCode;
/**
* 料号明细列表
*/
private List<SpareInHourseDetail> detailList;
}
package com.neotel.smfcore.custom.lizhen.api.bean.result;
import lombok.Data;
import java.util.Date;
/**
* 响应类,用于表示获取退库库存结果
*/
@Data
public class GetReturnInventoryResult {
/**
* 创建时间
*/
private Date createTime;
/**
* 单据号
*/
private String orderNo;
/**
* 料号
*/
private String partno;
/**
* 品名
*/
private String partname;
/**
* 仓库代码
*/
private String whCode;
/**
* 储位
*/
private String locationCode;
/**
* 功能部门
*/
private String functionDept;
/**
* 数量
*/
private Integer qty;
/**
* 区id
*/
private Integer deptId;
}
package com.neotel.smfcore.custom.lizhen.api.bean.result;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 请求类,用于获取未领取的备件申请信息
*/
@Data
public class GetUnclaimedResult {
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 1表示待领取
*/
private String status;
/**
* 单据号
*/
private String orderNo;
/**
* 功能部门
*/
private String functionDept;
/**
* 厂区id
*/
private Integer deptId;
/**
* 明细列表,以列表形式返回
*/
private List<SpareApplyDetail> spareApplyDetailList;
}
package com.neotel.smfcore.custom.lizhen.api.bean.result;
import lombok.Data;
/**
* 封装备件申请明细信息
*/
@Data
public class SpareApplyDetail {
/**
* 单据号
*/
private String orderNo;
/**
* 厂区id
*/
private Integer deptId;
/**
* 料号
*/
private String partNo;
/**
* 料名,例如红色/PVC
*/
private String partName;
/**
* 申请数量
*/
private Integer applyQty;
/**
* 预计数量
*/
private Integer expectQty;
}
package com.neotel.smfcore.custom.lizhen.api.bean.result;
import lombok.Data;
/**
* 封装料号明细中的详细信息
*/
@Data
public class SpareInHourseDetail {
/**
* 料号
*/
private String partno;
/**
* 储位
*/
private String locationCode;
/**
* 数量
*/
private Integer inQty;
}
package com.neotel.smfcore.custom.lizhen.api.bean.result;
import lombok.Data;
import java.util.List;
/**
* 表示SpareInHourse的结果
*/
@Data
public class SpareInHourseResult {
/**
* 厂区id
*/
private Integer deptId;
/**
* 单据号
*/
private String spareNo;
/**
* 仓库代码
*/
private String whCode;
/**
* 料号明细列表
*/
private List<SpareInHourseDetail> detailList;
}
......@@ -157,4 +157,16 @@ api:
binMove: http://10.42.220.171:8082/api/mlb/BinMove
#砍单回库
shipCancelUpshelf: http://10.42.220.171:8082/api/mlb/ShipCancelUpshelf
\ No newline at end of file
shipCancelUpshelf: http://10.42.220.171:8082/api/mlb/ShipCancelUpshelf
#备品仓入库单号查询接口
getSpareNo: http://10.42.220.118:8108/iams-api/getSpareNo
#备品仓入库接口
spareInhourse: http://10.42.220.118:8108/iams-api/spareInhourse
#预约待领取接口
getUnclaimed: http://10.42.220.118:8108/iams-api/getUnclaimed
#备品仓退库查询接口
getReturnInventory: http://10.42.220.118:8108/iams-api/getReturnInventory
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!