Commit 72bf5392 LN

西门子接口修改。

1 个父辈 135702d7
package com.neotel.smfcore.common.utils;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
public class JsonUtil {
// 定义jackson对象
private static final ObjectMapper MAPPER = new ObjectMapper();
static{
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
/**
* 将对象转换成json字符串。
* <p>Title: pojoToJson</p>
* <p>Description: </p>
* @param data
* @return
*/
public static String toJsonStr(Object data) {
try {
String string = MAPPER.writeValueAsString(data);
return string;
} catch (Exception e) {
log.info("转换JSON字符串出错:",e);
}
return null;
}
/**
* 将json结果集转化为对象
*
* @param jsonStr json数据
* @param beanType 对象中的object类型
* @return
*/
public static <T> T toObj(String jsonStr, Class<T> beanType) {
try {
T t = MAPPER.readValue(jsonStr, beanType);
return t;
} catch (Exception e) {
log.info(jsonStr + "转换对象出错:",e);
}
return null;
}
/**
* 将json数据转换成对象list
* <p>Title: jsonToList</p>
* <p>Description: </p>
* @param jsonStr
* @param beanType
* @return
*/
public static <T> List<T> toList(String jsonStr, Class<T> beanType) {
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
try {
List<T> list = MAPPER.readValue(jsonStr, javaType);
return list;
} catch (Exception e) {
log.info(jsonStr + "转换List出错:",e);
}
return new ArrayList<>();
}
public static Map<String, Object> toMap(String jsonStr){
//JavaType javaType = MAPPER.getTypeFactory().constructParametricType(HashMap.class, String.class, String.class);
try {
//Map<String, String> map = MAPPER.readValue(jsonStr, javaType);
Map<String, Object> map = MAPPER.readValue(jsonStr, Map.class);
return map;
} catch (Exception e) {
log.info(jsonStr + "转换Map出错:",e);
}
return new HashMap<>();
}
public static void main(String args[]) throws Exception{
String jsonStr = "[{\n" +
" \"action\": \"补料\",\n" +
" \"hSerial\": \"82\",\n" +
" \"so\": \"879235\",\n" +
"\"refno\": \"F001_879235N_1\",\n" +
"\"partNum\": \"7H.47134.1F1\",\n" +
" \"slot\": \"1-11\",\n" +
"\"qty\": \"2006\",\n" +
"\"facility\": \"SU\",\n" +
"\"sdte\": \"20191118\",\n" +
"\"stme\": \"85957\",\n" +
"\"reelcut\": \"N\",\n" +
"\"mdte\": \"20191115\",\n" +
"\"mtme\": \"172238\"\n" +
"},\n{\n" +
" \"action\": \"补料\",\n" +
" \"hSerial\": \"82\",\n" +
" \"so\": \"879235\",\n" +
"\"refno\": \"F001_879235N_1\",\n" +
"\"partNum\": \"7H.47134.1F1\",\n" +
" \"slot\": \"1-11\",\n" +
"\"qty\": \"2006\",\n" +
"\"facility\": \"SU\",\n" +
"\"sdte\": \"20191118\",\n" +
"\"stme\": \"85957\",\n" +
"\"reelcut\": \"N\",\n" +
"\"mdte\": \"20191115\",\n" +
"\"mtme\": \"172238\"\n" +
"}\n]";
// List<RequestOutItemBean> items = JsonUtil.toList(jsonStr, RequestOutItemBean.class);
// for (RequestOutItemBean item : items) {
// System.out.println(item);
// }
// System.out.println(DateUtil.toDateString(new Date(),"yyyyMMddHHmmssS"));
// System.out.println(DateUtil.toDateString(new Date(),"yyyyMMddHHmmssS"));
// System.out.println(DateUtil.toDateString(new Date(),"yyyyMMddHHmmssS"));
// System.out.println(DateUtil.toDateString(new Date(),"yyyyMMddHHmmssS"));
//
// System.out.println(System.nanoTime());
// System.out.println(System.nanoTime());
// System.out.println(System.currentTimeMillis());
// System.out.println(System.currentTimeMillis());
jsonStr = "{\"state\":\"0\",\"msg\":\"鏂欏嵎浣嶆暟涓嶅尮閰??\",\"info\":{\"so\":\"\",\"facility\":\"12334\",\"company\":\"\",\"qty\":\"\",\"soseq\":\"\"}}";
jsonStr = "{\"data\":[{\"Serial\":\"58890\",\"VehicleID\":\"D15\",\"Status\":\"\"},{\"Serial\":\"58890\",\"VehicleID\":\"D44\",\"Status\":\"\"},{\"Serial\":\"58890\",\"VehicleID\":\"D83\",\"Status\":\"\"},{\"Serial\":\"58890\",\"VehicleID\":\"D90\",\"Status\":\"\"},{\"Serial\":\"58890\",\"VehicleID\":\"D98\",\"Status\":\"\"}]}";
Map<String, Object> map = JsonUtil.toMap(jsonStr);
Object data = map.get("data");
if(data != null){
List<Object> dataList = (List)data;
for (Object info : dataList) {
Map<String,String> infoMap = (Map)info;
System.out.println(infoMap.get("Serial"));
}
}
}
}
......@@ -251,11 +251,11 @@ public class BaseDeviceHandler implements IDeviceHandler {
barcodeSave = codeResolve.resolveOneValideBarcode(codeStr,type);
}
//西门子接口验证
boolean result=SiemensApi.getMaterialLot(1, storage.getId(),storage.getName(),barcodeSave.getBarcode());
if(!result) {
throw new ValidateException("smfcore.error.getMaterialLot.in", "条码[{0}]验证失败,无法入库", new String[]{barcodeSave.getBarcode()});
}
// //西门子接口验证
// boolean result=SiemensApi.getMaterialLot(1, storage.getId(),storage.getName(),barcodeSave.getBarcode());
// if(!result) {
// throw new ValidateException("smfcore.error.getMaterialLot.in", "条码[{0}]验证失败,无法入库", new String[]{barcodeSave.getBarcode()});
// }
//查找库位,生成入库任务
DataLog putInTask = generatePutInTask(statusBean, barcodeSave, storage);
......@@ -658,8 +658,8 @@ public class BaseDeviceHandler implements IDeviceHandler {
task.setStatus(OP_STATUS.FINISHED.name());
taskService.updateFinishedTask(task);
//调用西门子接口
SiemensApi.processMaterialLot(1,storagePos.getStorageId(),task.getStorageName(),barcode.getBarcode());
// //调用西门子接口
// SiemensApi.lotInOut(barcode.getBarcode(),1);
}
......@@ -708,8 +708,8 @@ public class BaseDeviceHandler implements IDeviceHandler {
//更新缓存中的库存信息
dataCache.updateInventory(storagePos, barcode);
//调用西门子接口
SiemensApi.processMaterialLot(2,storagePos.getStorageId(),task.getStorageName(),barcode.getBarcode());
// 调用西门子接口
// SiemensApi.lotInOut(barcode.getBarcode(),2);
//记录日志
task.setStatus(OP_STATUS.FINISHED.name());
......
......@@ -125,11 +125,11 @@ public class MimoBoxHandler extends BaseDeviceHandler {
throw new ValidateException("smfcore.error.mimo.outFial", "未找到可出库的物料", new String[]{storageId});
} else {
//西门子接口验证
boolean result= SiemensApi.getMaterialLot(2, storage.getId(),storage.getName(),pos.getBarcode().getBarcode());
if(!result) {
throw new ValidateException("smfcore.error.getMaterialLot.out", "条码[{0}]验证失败,无法出库", new String[]{pos.getBarcode().getBarcode()});
}
// //西门子接口验证
// boolean result= SiemensApi.getMaterialLot(2, storage.getId(),storage.getName(),pos.getBarcode().getBarcode());
// if(!result) {
// throw new ValidateException("smfcore.error.getMaterialLot.out", "条码[{0}]验证失败,无法出库", new String[]{pos.getBarcode().getBarcode()});
// }
log.info("根据PN单盘出库:【" + storage.getName() + "_" + storage.getCid() + "】位置仓位【" + pos.getPosName() + "】");
String outResult = taskService.checkout(storage, pos, true, SecurityUtils.getCurrentUsername());
......
......@@ -346,11 +346,11 @@ public class StoragePosController {
// throw new ValidateException("料仓[" + pos.getStorageId() + "]不存在");
}
//西门子接口验证
boolean result=SiemensApi.getMaterialLot(2, storage.getId(),storage.getName(),pos.getBarcode().getBarcode());
if(!result) {
throw new ValidateException("smfcore.error.getMaterialLot.out", "条码[{0}]验证失败,无法出库", new String[]{pos.getBarcode().getBarcode()});
}
// //西门子接口验证
// boolean result=SiemensApi.getMaterialLot(2, storage.getId(),storage.getName(),pos.getBarcode().getBarcode());
// if(!result) {
// throw new ValidateException("smfcore.error.getMaterialLot.out", "条码[{0}]验证失败,无法出库", new String[]{pos.getBarcode().getBarcode()});
// }
log.info("出库料仓【" + storage.getName() + "_" + storage.getCid() + "】位置仓位【" + pos.getPosName() + "】");
String outResult = taskService.checkout(storage, pos, isSingleOut,SecurityUtils.getCurrentUsername());
......
package com.neotel.smfcore.siemens;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.JsonUtil;
import com.neotel.smfcore.common.utils.XmlUtil;
import com.neotel.smfcore.core.system.listener.ITaskListener;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.siemens.util.WSClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Component
public class SiemensApi {
public class SiemensApi implements ITaskListener {
private static SiemensConfig config;
@Autowired
public void setConfig(SiemensConfig config){
SiemensApi.config=config;
}
public static boolean getMaterialLot(int inoutType,String storageId,String storageName,String materialLot){
@Override
public void onTaskStatusChange(DataLog task) {
if(task.isFinished()){
if(task.isPutInTask()){
SiemensApi.lotInOut(task.getBarcode(),1);
}else{
SiemensApi.lotInOut(task.getBarcode(),2);
}
}
}
public static boolean lotInOut(String lot,int inoutType) {
if (ObjectUtil.isEmpty(config.url)) {
log.info("没有配置Siemens,无需通知");
return true;
}
String action = "IN";
if (inoutType == 2) {
action = "OUT";
}
log.info("Siemens[" + config.url + "]:料盘[" + lot + "][" + action + "]完成");
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("LotID", lot);
params.put("ACTION", inoutType);
String result = HttpHelper.postJson(config.url, params);
log.info("Siemens[" + config.url + "]返回料盘[" + lot + "]的[" + action + "]结果:" + result);
Map<String,Object> returnMap= JsonUtil.toMap(result);
if(returnMap!=null&&returnMap.containsKey("Status")) {
boolean res = Boolean.parseBoolean(returnMap.get("Status").toString());
return res;
}
} catch (Exception e) {
log.error("Siemens[" + config.url + "]:料盘[" + lot + "][" + action + "]完成 出错:", e);
}
return false;
// lot进tower:
// {
//  "LotID": "M03289629",
//  "ACTION": "IN"
// }
// 
// Lot出tower:
// {
//  "LotID": "M03289629",
//  "ACTION": "OUT"
// }
// 返回的信息:
// 进出无问题如下:
// {
//    "Status": true,
//    "Message": "OK",
//    "Data": null
// }
// 
// 检查数据存在一定逻辑错误而无法成功存取的返回信息如下:
// {
//    "Status": false,
//    "Message": "NG",
//    "Data": null
// }
}
private static boolean getMaterialLot(int inoutType,String storageId,String storageName,String materialLot){
if(ObjectUtil.isEmpty(config.url)){
return true;
......@@ -71,7 +146,7 @@ public class SiemensApi {
}
public static boolean processMaterialLot(int inoutType,String storageId,String storageName,String materialLot){
private static boolean processMaterialLot(int inoutType,String storageId,String storageName,String materialLot){
if(ObjectUtil.isEmpty(config.url)){
return true;
......@@ -273,4 +348,5 @@ public class SiemensApi {
return soap;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!