Commit 4f6e99af zshaohui

入库单如果缓存没有,调用api接口获取

1 个父辈 6c958c57
......@@ -2,12 +2,14 @@ package com.neotel.smfcore.core.api;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.init.MenuInit;
import com.neotel.smfcore.core.api.listener.ISmfApiListener;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.api.bean.CodeValidateParam;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.inList.service.po.InList;
import com.neotel.smfcore.core.order.service.po.LiteOrder;
import com.neotel.smfcore.core.system.service.po.DataLog;
import lombok.extern.slf4j.Slf4j;
......@@ -262,6 +264,20 @@ public class SmfApi {
return false;
}
public InList fetchInList(String number) {
if (isUrlExist(fetchInListUrl)) {
for (ISmfApiListener apiListener : apiListenerList) {
if (apiListener.isForThisApi(apiName)) {
InList inList = apiListener.fetchInList(fetchInListUrl,number);
if (inList != null) {
return inList;
}
}
}
}
return null;
}
public String getApiName(){
return apiName;
}
......
......@@ -118,6 +118,11 @@ public abstract class BaseSmfApiListener implements ISmfApiListener {
public boolean canLogin(String loginCheckUrl, String userName, String pwd) throws ValidateException {
return true;
}
@Override
public InList fetchInList(String fetchInListUrl, String number){
return null;
}
protected String getData(Map<String, Object> dataMap, String dataKey) {
Object data = dataMap.get(dataKey);
if (data == null) {
......
......@@ -197,31 +197,31 @@ public class DefaultSmfApiListener extends BaseSmfApiListener {
}
}
public InList fetchInList(String fetchInListUrl, String number) throws ApiException {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("number",number);
public InList fetchInList(String fetchInListUrl, String number) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("number", number);
try {
log.info("调用获取入库单接口,参数" + JsonUtil.toJsonStr(paramMap));
String result = HttpHelper.postJson(fetchInListUrl, paramMap);
log.info(number + "获取入库单接口返回" + result);
ApiResult apiResult = JsonUtil.toObj(result,ApiResult.class);
if(apiResult.isOk()){
Map<String,Object> dataMap = (Map<String, Object>) apiResult.getData();
ApiResult apiResult = JsonUtil.toObj(result, ApiResult.class);
if (apiResult.isOk()) {
Map<String, Object> dataMap = (Map<String, Object>) apiResult.getData();
String returnNumber = dataMap.get("number").toString();
InList inList = new InList();
inList.setName(returnNumber);
List<InListItem> items = new ArrayList<>();
List<Map<String,Object>> itemList = (List<Map<String, Object>>) dataMap.get("items");
List<Map<String, Object>> itemList = (List<Map<String, Object>>) dataMap.get("items");
for (Map<String, Object> itemMap : itemList) {
String partNum = itemMap.get("partNum").toString();
Object qtyStr = itemMap.get("qty");
Object reelCountStr = itemMap.get("reelCount");
InListItem item = new InListItem();
item.setPN(partNum);
if(qtyStr != null && !qtyStr.toString().isEmpty()){
if (qtyStr != null && !qtyStr.toString().isEmpty()) {
item.setNum(Integer.valueOf(qtyStr.toString()));
}
if(reelCountStr != null && !qtyStr.toString().isEmpty()){
if (reelCountStr != null && !qtyStr.toString().isEmpty()) {
item.setInReelCount(Integer.valueOf(reelCountStr.toString()));
}
items.add(item);
......@@ -231,12 +231,12 @@ public class DefaultSmfApiListener extends BaseSmfApiListener {
inList = inListManager.createWithItems(inList);
inListCache.addInListToMap(inList);
return inList;
}else{
throw new ApiException("smfcore.fetchInList.ng","获取入库单MES返回NG:" + apiResult.getMsg());
} else {
throw new ApiException("smfcore.fetchInList.ng", "获取入库单MES返回NG:" + apiResult.getMsg());
}
} catch (Exception e) {
log.error(number + "获取入库单接口出错:" + e.getMessage());
throw new ApiException("smfcore.fetchInList.error","获取入库单出错:" + e.getMessage());
return null;
}
}
......
package com.neotel.smfcore.core.api.listener;
import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.api.bean.CodeValidateParam;
import com.neotel.smfcore.core.inList.service.po.InList;
import com.neotel.smfcore.core.order.service.po.LiteOrder;
import com.neotel.smfcore.core.system.service.po.DataLog;
......@@ -67,4 +69,7 @@ public interface ISmfApiListener {
* 是否可以登陆
*/
boolean canLogin(String loginCheckUrl, String userName,String pwd) throws ValidateException;
InList fetchInList(String fetchInListUrl, String number);
}
......@@ -9,6 +9,7 @@ import com.neotel.smfcore.common.csv.CsvReader;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.common.utils.QueryHelp;
import com.neotel.smfcore.core.api.SmfApi;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.inList.enums.INLIST_STATUS;
import com.neotel.smfcore.core.inList.rest.bean.dto.InListDto;
......@@ -73,6 +74,9 @@ public class InListController {
@Autowired
private IStorageManager storageManager;
@Autowired
private SmfApi smfApi;
@ApiOperation("上传入库单")
@PostMapping(value = "/upload")
@AnonymousAccess
......@@ -187,13 +191,16 @@ public class InListController {
String inListName = params.get("inListName");
String storageId = params.get("storageId");
String groupId = params.get("groupId");
if(ObjectUtil.isEmpty(inListName)){
if (ObjectUtil.isEmpty(inListName)) {
}
else {
} else {
InList inList = inListCache.getInList(inListName);
if (inList == null) {
return ResultBean.newErrorResult(1, "smfcore.inlist.notFound", "未找到入库单[{0}]", new String[]{inListName});
//如果入库单为空的话,调用api获取
inList = smfApi.fetchInList(inListName);
if (inList == null) {
return ResultBean.newErrorResult(1, "smfcore.inlist.notFound", "未找到入库单[{0}]", new String[]{inListName});
}
}
if (inList.getStatus() == INLIST_STATUS.OK) {
return ResultBean.newErrorResult(1, "smfcore.inlist.listOk", "入库单[{0}]已完成", new String[]{inListName});
......@@ -206,11 +213,11 @@ public class InListController {
for (String cid : cidList) {
Storage storage = dataCache.getStorage(cid);
if (storage != null) {
if (storage.isType(new DeviceType[]{DeviceType.NLP,DeviceType.NL,DeviceType.NLS})) {
if (storage.isType(new DeviceType[]{DeviceType.NLP, DeviceType.NL, DeviceType.NLS})) {
storage.setInListName(inListName);
log.info("设置组[" + groupId + "]料架[" + storage.getName() + "]的入库单为:[" + inListName + "]");
storageManager.save(storage);
dataCache.reloadStorage(storage,"");
dataCache.reloadStorage(storage, "");
}
}
......@@ -218,11 +225,11 @@ public class InListController {
} else {
Storage storage = dataCache.getStorageById(storageId);
if (storage != null) {
if (storage.isType(new DeviceType[]{DeviceType.NLP,DeviceType.NL,DeviceType.NLS})) {
if (storage.isType(new DeviceType[]{DeviceType.NLP, DeviceType.NL, DeviceType.NLS})) {
storage.setInListName(inListName);
log.info("设置料架[" + storage.getName() + "]的入库单为:[" + inListName + "]");
storageManager.save(storage);
dataCache.reloadStorage(storage,"");
dataCache.reloadStorage(storage, "");
}
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!