优化入库,自动获取物料
This commit is contained in:
@@ -21,4 +21,6 @@ public interface IToErpService {
|
||||
AjaxResult getInCode(BasProductCode basProductCode);
|
||||
|
||||
void callbackProduction();
|
||||
|
||||
BasProduct getErpProductByCode(String productId);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,16 @@ public class ToErpServiceImpl implements IToErpService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasProduct getErpProductByCode(String productId) {
|
||||
RequestLog requestLog = requestLogService.getRequestLogProduct(TO_ERP_URL,productId,"获取物料数据", "wms", "erp");
|
||||
BasProduct product = new BasProduct();
|
||||
if("1".equals(requestLog.getIsSuccessful())){
|
||||
product = basProductService.selectBasProductByProductId(productId);
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
private AjaxResult createProductionCallback(ProductionCallback productionCallback) {
|
||||
ErpInterfaceParam<WipTransferDoc> param = new ErpInterfaceParam<>();
|
||||
ErpStdData<WipTransferDoc> erpStdData = new ErpStdData<>();
|
||||
|
||||
@@ -117,7 +117,6 @@ public class ToWmsServiceImpl implements IToWmsService {
|
||||
String nw = findFirst(PATTERNS.get("NW"), trayCode);
|
||||
String gw = findFirst(PATTERNS.get("GW"), trayCode);;
|
||||
String productId = findFirst(PATTERNS.get("ITEM_CODE"), trayCode);
|
||||
//String productId = "KC01001000327";
|
||||
String bm = findFirst(PATTERNS.get("@"), trayCode);
|
||||
bm=bm.substring(0,bm.length()-1);
|
||||
String[] decode = ProcodeUtils.decode(bm);
|
||||
@@ -137,12 +136,15 @@ public class ToWmsServiceImpl implements IToWmsService {
|
||||
BasProduct basProductParam = new BasProduct();
|
||||
basProductParam.setProductId(productId);
|
||||
List<BasProduct> basProducts = basProductService.selectBasProductList(basProductParam);
|
||||
|
||||
BasProduct basProduct = new BasProduct();
|
||||
if (CollUtil.isEmpty(basProducts)) {
|
||||
return new AjaxResult(3, "物料不存在!");
|
||||
basProduct = toErpService.getErpProductByCode(productId);
|
||||
if(basProduct == null){
|
||||
return new AjaxResult(3, "物料不存在!");
|
||||
}
|
||||
}else{
|
||||
basProduct = basProducts.get(0);
|
||||
}
|
||||
BasProduct basProduct = basProducts.get(0);
|
||||
|
||||
List<MydoJob> inList = mydoJobService.getInJobBySerial(serial);
|
||||
List<BasStock> stockList = stockService.getStockBySerial(serial);
|
||||
if(!CollUtil.isEmpty(inList) || !CollUtil.isEmpty(stockList)) {
|
||||
|
||||
@@ -78,11 +78,13 @@ public interface IRequestLogService
|
||||
*/
|
||||
public RequestLog getRequestLog(String param, String remark, AjaxResult ajaxResult);
|
||||
|
||||
RequestLog getRequestLogGd(String workshopInboundOrderUrl, String jsonStr, String 创建工艺单, String wms, String erp);
|
||||
RequestLog getRequestLogGd(String workshopInboundOrderUrl, String jsonStr, String remark, String wms, String erp);
|
||||
|
||||
RequestLog getRequestLogOther(String otherInOutboundOrderUrl, String jsonStr, String 创建其他入出库单, String wms, String erp);
|
||||
RequestLog getRequestLogOther(String otherInOutboundOrderUrl, String jsonStr, String remark, String wms, String erp);
|
||||
|
||||
String getRequestLogDoc(String workshopInboundOrderUrl, String erpBill, String productId, String 获取工艺单号, String wms, String erp);
|
||||
String getRequestLogDoc(String workshopInboundOrderUrl, String erpBill, String productId, String remark, String wms, String erp);
|
||||
|
||||
RequestLog getRequestLogCode(String workshopInboundOrderUrl, String billNo, String 获取入库条码数据, String wms, String erp);
|
||||
RequestLog getRequestLogCode(String workshopInboundOrderUrl, String billNo, String remark, String wms, String erp);
|
||||
|
||||
RequestLog getRequestLogProduct(String url, String productId, String remark, String source, String target);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.ruoyi.api.domain.Condition;
|
||||
import com.ruoyi.bas.BasProduct.domain.BasProduct;
|
||||
import com.ruoyi.bas.BasProduct.mapper.BasProductMapper;
|
||||
import com.ruoyi.bas.BasProductCode.domain.BasProductCode;
|
||||
import com.ruoyi.bas.BasProductCode.mapper.BasProductCodeMapper;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
@@ -17,7 +18,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -32,9 +32,10 @@ import java.util.List;
|
||||
public class RequestLogServiceImpl implements IRequestLogService {
|
||||
@Autowired
|
||||
private RequestLogMapper requestLogMapper;
|
||||
|
||||
@Autowired
|
||||
private BasProductCodeMapper basProductCodeMapper;
|
||||
@Autowired
|
||||
private BasProductMapper basProductMapper;
|
||||
|
||||
/**
|
||||
* 查询接口记录
|
||||
@@ -402,6 +403,95 @@ public class RequestLogServiceImpl implements IRequestLogService {
|
||||
return requestLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestLog getRequestLogProduct(String url, String productId, String remark, String source, String target) {
|
||||
String param = "{ \"std_data\": {\n" +
|
||||
" \"parameter\": {\n" +
|
||||
" \"pageSize\": 20,\n" +
|
||||
" \"pageNo\": 1,\n" +
|
||||
" \"isGetSchema\": false,\n" +
|
||||
" \"isGetCount\": false,\n" +
|
||||
" \"conditions\": [\n" +
|
||||
" {\n" +
|
||||
" \"field_name\":\"ITEM_CODE\",\n" +
|
||||
" \"value\":\""+productId+"\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"orders\": []\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
RequestLog requestLog = new RequestLog();
|
||||
requestLog.setRequestTime(DateUtil.formatDateTime(new Date()));
|
||||
requestLog.setSourceSystem(source);
|
||||
requestLog.setTargetSystem(target);
|
||||
requestLog.setEndpoint(remark);
|
||||
requestLog.setRequestMethod("post");
|
||||
requestLog.setRequestHeaders(null);
|
||||
requestLog.setRequestBody(param);
|
||||
requestLog.setRequestUrl(url);
|
||||
|
||||
try {
|
||||
String resStr = HttpUtils.sendPostProduct(url, param, "application/json; charset=UTF-8");
|
||||
log.info("调用ERP获取物料数据,请求参数:"+param);
|
||||
log.info("调用ERP获取物料数据,接口返回:"+resStr);
|
||||
// 判断resStr的状态码,如果不是200抛出异常让catch捕获
|
||||
if (!JSONUtil.isJsonObj(resStr)) {
|
||||
throw new RuntimeException("返回结果不是有效的JSON对象");
|
||||
}
|
||||
JSONObject jsonObject = JSONUtil.parseObj(resStr);
|
||||
if (jsonObject == null) {
|
||||
throw new RuntimeException("请求失败");
|
||||
}
|
||||
Object codeObj = jsonObject.get("std_data");
|
||||
JSONObject obj = JSONUtil.parseObj(codeObj.toString());
|
||||
String docArr = JSONUtil.parseObj(obj.get("parameter").toString()).get("rows").toString();
|
||||
|
||||
if (docArr.length() > 0 && JSONUtil.parseArray(docArr).size() > 0) {
|
||||
for(int i = 0; i < JSONUtil.parseArray(docArr).size(); i++) {
|
||||
Object docObj = JSONUtil.parseArray(docArr).get(i);
|
||||
BasProduct product = new BasProduct();
|
||||
product.setProductId(JSONUtil.parseObj(docObj.toString()).get("ITEM_CODE").toString());
|
||||
product.setProductGuid(JSONUtil.parseObj(docObj.toString()).get("ITEM_CODE").toString());
|
||||
product.setProductName(JSONUtil.parseObj(docObj.toString()).get("ITEM_NAME").toString());
|
||||
product.setSpec(JSONUtil.parseObj(docObj.toString()).get("ITEM_SPECIFICATION").toString());
|
||||
product.setUnit(JSONUtil.parseObj(docObj.toString()).get("UNIT_CODE").toString());
|
||||
product.setSpare36(JSONUtil.parseObj(docObj.toString()).get("UDF011").toString());
|
||||
product.setSpare37(JSONUtil.parseObj(docObj.toString()).get("UDF012").toString());
|
||||
product.setSpare38(JSONUtil.parseObj(docObj.toString()).get("UDF013").toString());
|
||||
if(product.getSpare36() != null && product.getSpare37() != null){
|
||||
if("760".equals(product.getSpare36()) && "960".equals(product.getSpare37())){
|
||||
product.setSpare10("1");
|
||||
} else if ("1000".equals(product.getSpare36()) && "800".equals(product.getSpare37())) {
|
||||
product.setSpare10("2");
|
||||
} else if ("1130".equals(product.getSpare36()) && "800".equals(product.getSpare37())) {
|
||||
product.setSpare10("3");
|
||||
} else if ("1130".equals(product.getSpare36()) && "900".equals(product.getSpare37())) {
|
||||
product.setSpare10("4");
|
||||
} else{
|
||||
product.setSpare10("5");
|
||||
}
|
||||
}
|
||||
basProductMapper.insertBasProduct(product);
|
||||
}
|
||||
requestLog.setResponseBody(resStr);
|
||||
requestLog.setResponseTime(DateUtil.formatDateTime(new Date()));
|
||||
requestLog.setResponseStatus("1");
|
||||
requestLog.setDuration(Convert.toStr(DateUtil.between(Convert.toDate(requestLog.getRequestTime()), Convert.toDate(requestLog.getResponseTime()), DateUnit.MS)));
|
||||
requestLog.setIsSuccessful("1");
|
||||
} else {
|
||||
throw new RuntimeException("请求失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
requestLog.setErrorDetails(e.getMessage());
|
||||
requestLog.setIsSuccessful("0");
|
||||
requestLog.setResponseStatus("0");
|
||||
} finally {
|
||||
insertRequestLog(requestLog);
|
||||
}
|
||||
return requestLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入请求日志
|
||||
*
|
||||
|
||||
@@ -520,6 +520,72 @@ public class HttpUtils
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String sendPostProduct(String url, String param, String contentType) {
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
StringBuilder result = new StringBuilder();
|
||||
try
|
||||
{
|
||||
log.info("sendPostProduct - {}", url);
|
||||
URL realUrl = new URL(url);
|
||||
URLConnection conn = realUrl.openConnection();
|
||||
conn.setRequestProperty("digi-key", "40A5D983A5067EA847DFBD326944990E");
|
||||
conn.setRequestProperty("digi-host", "{\"ver\":\"5.7\",\"prod\":\"YLTK\",\"timezone\":\"+8\",\"ip\":\"192.168.116.1\",\"id\":\"\",\"lang\":\"zh_CN\",\"acct\":\"dcms\",\"timestamp\":\"2018071990007275\"}");
|
||||
conn.setRequestProperty("digi-service", "{\"prod\":\"E10\",\"ip\":\"192.168.116.179\",\"name\":\"yltk.item.query\",\"id\":\"E10_BLS_ZS_External\"}");
|
||||
conn.setRequestProperty("digi-data-exchange-protocol", "1.0");
|
||||
conn.setRequestProperty("digi-type", "sync");
|
||||
//conn.setRequestProperty("Accept-Charset", "utf-8");
|
||||
conn.setRequestProperty("Content-Type", contentType);
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
out = new PrintWriter(conn.getOutputStream());
|
||||
out.print(param);
|
||||
out.flush();
|
||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
result.append(line);
|
||||
}
|
||||
log.info("recv - {}", result);
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (SocketTimeoutException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (out != null)
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
private static class TrustAnyTrustManager implements X509TrustManager
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user