Commit eca2cc90 LN

增加接口API012.

1 个父辈 503d9130
......@@ -444,8 +444,10 @@ public class LiteOrderCache {
order.setClosed(closed);
if (ObjectUtil.isNotEmpty(order.getMode())) {
String key = Constants.CACHE_DISPATCH + order.getMode();
log.info(" mode=" + order.getMode() + "的出库已结束,清空 key=" + key + " 的cache");
log.info(" mode=" + order.getMode() + "的出库已结束,清空 key=" + key + " 的cache,更改action=COMPLETE");
dataCache.updateCache(key, "");
MicronApi.ActionUpdate(order.getOperationId(),MicronApi.COMPLETE );
}
clearOrderLock(order);
}
......
......@@ -5,6 +5,7 @@ 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.Constants;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.JsonUtil;
import com.neotel.smfcore.core.api.listener.BaseSmfApiListener;
......@@ -22,17 +23,18 @@ import com.neotel.smfcore.custom.micron1053.loading.util.LoadingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Controller
@Slf4j
public class MicronApi {
// 每个流程开始时发START,流程正常结束发COMPLETE,流程异常结束发ABORT
public static String START="START";
public static String COMPLETE="COMPLETE";
public static String ABORT="ABORT";
public static boolean Debug=false;
private static MicronConfig config;
......@@ -877,6 +879,103 @@ public class MicronApi {
}
///API-012 Process GET T->H Update the current operation status operation/{OperationId} "In Body=
// {
// ""action"": <action>,
// ""dateTime"": <dateTime>
// }
//
// Action: ""START|COMPLETE|ABORT"" " "Http Status code:
// 200 - Success
// {
// ""trasactionId"": <guid>,
// ""operationId"" : <string>,
// ""operationStatus"" : <string>,
// ""startDateTime"" : <dateTime?>,
// ""endDateTime"" : <dateTime?>,
// ""source"" : <string>,
// ""username"" : <string>,
// ""mode"" : <string>,
// ""tag"":
// [
// <tagKey1> : <tagValue1>,
// <tagKey2> : <tagValue2>,
// ...
// ],
// }
//
// Error Status code:
// {
// ""transactionId"": <TransactionId>,
// ""tag"":
// [
// <tagKey1> : <tagValue1>,
// <tagKey2> : <tagValue2>,
// ...
// ],
// ""error"": <ErrCode>,
// ""message"": <ErrMessage>,
// ""detail"": <ErrDetail>
// }
//"
public static boolean ActionUpdate(String operationId, String action ) {
try {
boolean result = Api012(operationId, action);
if (result) {
log.info("ActionUpdate operationId=" + operationId + ",action=" + action + ", 调用Api012 ok:" + result);
} else {
log.error("ActionUpdate operationId=" + operationId + ",action=" + action + ", 调用Api012 fail:" + result);
}
return result;
} catch (Exception ex) {
log.error("ActionUpdate operationId=" + operationId + ",action=" + action + ", 调用Api012 error:" + ex.toString());
}
return false;
}
public static boolean Api012(String operationId, String action) {
String url = config.getUrl(config.api_name_012);
url = MessageFormat.format(url, operationId);
try {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("action", action);
String time = DateUtil.toDateTimeString(new Date());
paramMap.put("dateTime", time);
String paramStr = JsonUtil.toJsonStr(paramMap);
log.info("调用MES接口 Api012: url=" + url + ",body=" + paramStr + "");
MicronResult result = HttpHelper.postMicronJson(url, paramMap);
String errMsg = getDErrorMsg(result);
if (result.isOk()) {
String mode = result.getResult("mode", false);
String userName = result.getResult("result", false);
log.info(" Api012 operationId=" + operationId + ",获取到 ,mode=" + mode + ",userName=" + userName + ", ");
return true;
} else if (ObjectUtil.isNotEmpty(errMsg)) {
log.info("Api012 ,接口通信失败:" + errMsg);
throw new ApiException(errMsg);
} else {
log.info("Api012 ,接口通信失败");
throw new ApiException("smfcore.api.fail", "{0} Failed to get data", new String[]{"Api011 : " + result.getResponseData()});
}
} catch (Exception e) {
log.error(url + "出错", e);
}
return false;
}
public static boolean Api101(String id, String operationId, String skipSap) {
String url = config.getUrl(config.api_name_101);
url = MessageFormat.format(url,id,operationId,skipSap);
......
......@@ -65,6 +65,12 @@ public class MicronConfig {
* 获取OperationID ,Get operationId for Loading or Dispatching of material
*/
public String api_name_011="operation?mode={0}&username={1}&source={2}";
/**
* 增加接口API012调用
* 每个流程开始时发START,流程正常结束发COMPLETE,流程异常结束发ABORT
* 调用API011获取operationId之后就调用API012 开始START(出入库流程都需要)
*/
public String api_name_012="operation/{0}";
/**
* Validate if MBR (From Warehouse ) is valid
......@@ -186,6 +192,13 @@ public class MicronConfig {
}
api_name_011= api_config;
}
@Value("${micron.api_name_012:}")
public void setApi_name_012(String api_config) {
if(ObjectUtil.isEmpty(api_config)){
return;
}
api_name_012= api_config;
}
@Value("${micron.api_name_101:}")
public void setApi_name_101(String api_config) {
......
......@@ -208,6 +208,7 @@ public class LoadingController {
return ResultBean.newErrorResult(-1,"smfcore.api.fail", "Api011获取数据失败",new String[]{"Api011"});
}
MicronApi.ActionUpdate(id,MicronApi.START);
LoadingInfo loadingInfo = new LoadingInfo(APIMODE.MATRET, id, "", DateTime.now());
loadingInfo.inlistName = id + "-" + DateUtil.toDateString(loadingInfo.startTime);
dataCache.updateCache(Constants.CACHE_LOADING, loadingInfo);
......@@ -262,8 +263,9 @@ public class LoadingController {
} else {
//结束入库
log.info("终止 入库:"+inList.getMode()+","+inList.getOperationId()+" " +inList.getName());
log.info("终止 入库:"+inList.getMode()+","+inList.getOperationId()+" " +inList.getName()+",更改action=ABORT");
MicronApi.ActionUpdate(inList.getOperationId(),MicronApi.ABORT );
inList.setStatus(INLIST_STATUS.END);
inListManager.save(inList);
inListCache.addInListToMap(inList);
......@@ -285,7 +287,8 @@ public class LoadingController {
return ResultBean.newErrorResult(-1,"smfcore.micron.operationFailure","操作失败");
} else {
if (inList.getStatus() == INLIST_STATUS.OK){
log.info(" 入库单[" + inList.getName() + "]:任务已全部完成,清空当前loadinginfo");
log.info(" 入库单[" + inList.getName() + "]:任务已全部完成,清空当前loadinginfo,更改action=COMPLETE");
MicronApi.ActionUpdate(inList.getOperationId(),MicronApi.COMPLETE );
dataCache.updateCache(Constants.CACHE_LOADING, new LoadingInfo());
return ResultBean.newOkResult("");
}
......
......@@ -163,6 +163,7 @@ private IStoragePosManager storagePosManager;
dto.setOperationId(operationId);
dataCache.updateCache(Constants.CACHE_DISPATCH + mode, dto);
MicronApi.ActionUpdate(operationId,MicronApi.START);
//需要输入lineID
return ResultBean.newErrorResult(2, "", "");
} else {
......@@ -294,6 +295,7 @@ private IStoragePosManager storagePosManager;
if (StringUtils.isNotBlank(operationId)) {
dto.setOperationId(operationId);
dataCache.updateCache(Constants.CACHE_DISPATCH + mode, dto);
MicronApi.ActionUpdate(operationId,MicronApi.START);
} else {
return ResultBean.newErrorResult(-1, "smfcore.api.fail", "Api011 获取数据失败", new String[]{"API011"});
}
......@@ -675,8 +677,10 @@ private IStoragePosManager storagePosManager;
if (ObjectUtil.isNotEmpty(order.getMode())) {
String key = Constants.CACHE_DISPATCH + order.getMode();
log.info("abort mode=" + order.getMode() + " 清空 key=" + key + " 的cache");
log.info("abort mode=" + order.getMode() + " 清空 key=" + key + " 的cache,更改action=ABORT");
dataCache.updateCache(key, "");
MicronApi.ActionUpdate(order.getOperationId(),MicronApi.ABORT);
}
liteOrderCache.clearOrderLock(order);
}
......@@ -726,7 +730,8 @@ private IStoragePosManager storagePosManager;
}else {
String key = Constants.CACHE_DISPATCH +mode;
log.info("abort mode=" + mode + " 清空 key=" + key + " 的cache");
log.info("abort mode=" + mode + " 清空 key=" + key + " 的cache,更改action=ABORT");
MicronApi.ActionUpdate(order.getOperationId(),MicronApi.ABORT );
dataCache.updateCache(key, "");
}
return ResultBean.newOkResult("");
......
......@@ -125,6 +125,7 @@ public class MicronPreTaskController {
operationId = MicronApi.Api011(mode, SecurityUtils.getLoginUsername(), "");
if (StringUtils.isNotBlank(operationId)) {
MicronApi.ActionUpdate(operationId,MicronApi.START);
dto.setOperationId(operationId);
dataCache.updateCache(key, dto);
} else {
......@@ -343,7 +344,8 @@ public class MicronPreTaskController {
if(dto!=null){
//清空配置
String key=Constants.CACHE_DISPATCH+mode;
log.info("abort mode="+mode+" 清空 key="+key+" 的cache");
log.info("abort mode="+mode+" 清空 key="+key+" 的cache,更改action=ABORT");
MicronApi.ActionUpdate(order.getOperationId(),MicronApi.ABORT );
dataCache.updateCache(key,"");
return ResultBean.newOkResult("");
}
......@@ -402,9 +404,10 @@ public class MicronPreTaskController {
//清空配置
String key=Constants.CACHE_DISPATCH+order.getMode();
log.info(" mode="+order.getMode()+"工单已关闭,清空 key="+key+" 的cache");
log.info(" mode="+order.getMode()+"工单已关闭,清空 key="+key+" 的cache,更改action=ABORT");
dataCache.updateCache(key,"");
MicronApi.ActionUpdate(order.getOperationId(),MicronApi.ABORT);
liteOrderCache.clearOrderLock(order);
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!