Commit 4f6e99af zshaohui

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

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