|
@@ -3,12 +3,18 @@ package com.emato.biz.service.impl;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
+import cn.hutool.http.HttpException;
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.emato.biz.config.OmsConfig;
|
|
import com.emato.biz.config.OmsConfig;
|
|
|
|
+import com.emato.biz.domain.warehouse.PullInveQueryVO;
|
|
import com.emato.biz.mapper.warehouse.WbInveMngMapper;
|
|
import com.emato.biz.mapper.warehouse.WbInveMngMapper;
|
|
|
|
+import com.emato.common.core.domain.AjaxResult;
|
|
|
|
+import com.emato.common.exception.ServiceException;
|
|
import com.emato.common.utils.DateUtils;
|
|
import com.emato.common.utils.DateUtils;
|
|
|
|
+import com.emato.common.utils.oms.JacksonUtils;
|
|
import com.emato.common.utils.oms.OkHttpUtils;
|
|
import com.emato.common.utils.oms.OkHttpUtils;
|
|
import com.emato.common.utils.oms.request.OmsSign;
|
|
import com.emato.common.utils.oms.request.OmsSign;
|
|
import okhttp3.Request;
|
|
import okhttp3.Request;
|
|
@@ -39,16 +45,62 @@ import javax.annotation.Resource;
|
|
@Service
|
|
@Service
|
|
public class OWbInveMngServiceImpl implements IOWbInveMngService
|
|
public class OWbInveMngServiceImpl implements IOWbInveMngService
|
|
{
|
|
{
|
|
- @Autowired
|
|
|
|
|
|
+ @Resource
|
|
private OWbInveMngMapper oWbInveMngMapper;
|
|
private OWbInveMngMapper oWbInveMngMapper;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private WbInveMngMapper wbInveMngMapper;
|
|
private WbInveMngMapper wbInveMngMapper;
|
|
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(OWbInveMngServiceImpl.class);
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(OWbInveMngServiceImpl.class);
|
|
|
|
+
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据条件拉取 OMS 数据
|
|
|
|
+ *
|
|
|
|
+ * @param queryVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult pullInveMng(PullInveQueryVO queryVO) {
|
|
|
|
+ // 构建请求报文
|
|
|
|
+ // 初始化请求 oms 参数 Map
|
|
|
|
+ Map<String, String> reqOmsPram = new TreeMap<>();
|
|
|
|
+ queryVO.setThirdMerchId("tmb770630141444423680");
|
|
|
|
+ // 请求 oms 数据
|
|
|
|
+ reqOmsPram.put("data", JacksonUtils.toJsonStr(queryVO));
|
|
|
|
+ // 请求 oms 商户号
|
|
|
|
+ reqOmsPram.put("merchId", OmsConfig.getMerchSn());
|
|
|
|
+ log.debug("===== 请求 oms 商户号 ====> {}", OmsConfig.getMerchSn());
|
|
|
|
+ // 请求 oms 时间戳
|
|
|
|
+ String timestamp = System.currentTimeMillis()/1000 + "";
|
|
|
|
+ reqOmsPram.put("timestamp", timestamp);
|
|
|
|
+ log.debug("===== 请求 oms 时间戳 ====> {}", timestamp);
|
|
|
|
+ // 请求 oms 签名
|
|
|
|
+ String sign = OmsSign.sign(reqOmsPram, OmsConfig.getMd5Salt());
|
|
|
|
+ reqOmsPram.put("sign", sign);
|
|
|
|
+ // oms 请求地址
|
|
|
|
+ String url = OmsConfig.getQueryMngInveUrl();
|
|
|
|
+ log.debug("===== 请求 oms 地址 ====> {}", url);
|
|
|
|
+ // 请求 oms 报文
|
|
|
|
+ String reqBody = JacksonUtils.toJsonStr(reqOmsPram);
|
|
|
|
+ log.debug("===== 请求 oms 报文 ====> {}", reqBody);
|
|
|
|
+
|
|
|
|
+ // oms 返回数据
|
|
|
|
+ String body = null;
|
|
|
|
+ try {
|
|
|
|
+ body = HttpRequest.post(url)
|
|
|
|
+ .body(JacksonUtils.toJsonStr(reqOmsPram))
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new ServiceException("请求 OMS 异常!");
|
|
|
|
+ }
|
|
|
|
+ log.debug("OMS 响应信息 => {}", body);
|
|
|
|
|
|
|
|
|
|
|
|
+ // 获取响应,入库
|
|
|
|
+ return AjaxResult.success("拉取库存成功!");
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询库存管理,wms入库回传时,增加库存数
|
|
* 查询库存管理,wms入库回传时,增加库存数
|
|
@@ -157,20 +209,20 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
|
|
String timestamp = String.valueOf(System.currentTimeMillis()/1000);
|
|
String timestamp = String.valueOf(System.currentTimeMillis()/1000);
|
|
sParaTemp.put("timestamp", timestamp);
|
|
sParaTemp.put("timestamp", timestamp);
|
|
//生成要请求给oms秘钥
|
|
//生成要请求给oms秘钥
|
|
- LOGGER.info("md5混淆码参数:" + OmsConfig.getMd5Salt());
|
|
|
|
|
|
+ log.info("md5混淆码参数:" + OmsConfig.getMd5Salt());
|
|
String sign = OmsSign.sign(sParaTemp,OmsConfig.getMd5Salt());
|
|
String sign = OmsSign.sign(sParaTemp,OmsConfig.getMd5Salt());
|
|
sParaTemp.put("sign", sign);
|
|
sParaTemp.put("sign", sign);
|
|
//构建Request
|
|
//构建Request
|
|
String url = OmsConfig.getQueryMngInveUrl();
|
|
String url = OmsConfig.getQueryMngInveUrl();
|
|
String jsonParam = JSONObject.toJSONString(sParaTemp);
|
|
String jsonParam = JSONObject.toJSONString(sParaTemp);
|
|
- Request request = OkHttpUtils.buildRequest(jsonParam,url,"");
|
|
|
|
- LOGGER.info("oms的请求报文:" + request);
|
|
|
|
|
|
+ log.info("Eccs 请求 OMS url => {}, 请求 OMS 报文 => {}", url, jsonParam);
|
|
|
|
+
|
|
// 同步访问,返回结果字符串
|
|
// 同步访问,返回结果字符串
|
|
String responseString = null;
|
|
String responseString = null;
|
|
try {
|
|
try {
|
|
JSONObject jsonObject = httpPost(url,JSONObject.parseObject(jsonParam));
|
|
JSONObject jsonObject = httpPost(url,JSONObject.parseObject(jsonParam));
|
|
|
|
|
|
- LOGGER.info("oms的响应报文"+jsonObject.toString());
|
|
|
|
|
|
+ log.info("oms的响应报文"+jsonObject.toString());
|
|
|
|
|
|
//解析响应数据
|
|
//解析响应数据
|
|
JSONArray result = (JSONArray) jsonObject.get("data");
|
|
JSONArray result = (JSONArray) jsonObject.get("data");
|
|
@@ -195,8 +247,7 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
|
|
}
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- LOGGER.error(e.getMessage());
|
|
|
|
|
|
+ log.error(e.getMessage());
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -237,13 +288,13 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
{
|
|
{
|
|
- LOGGER.error("post请求提交失败:" + url, e);
|
|
|
|
|
|
+ log.error("post请求提交失败:" + url, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (IOException e)
|
|
catch (IOException e)
|
|
{
|
|
{
|
|
- LOGGER.error("post请求提交失败:" + url, e);
|
|
|
|
|
|
+ log.error("post请求提交失败:" + url, e);
|
|
}
|
|
}
|
|
finally
|
|
finally
|
|
{
|
|
{
|