|
|
@@ -3,20 +3,31 @@ package com.uas.eis.service.Impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.transsion.exchange.base.dto.EntryForPOST;
|
|
|
+import com.transsion.exchange.utils.ecit.OpenApiUtil;
|
|
|
import com.uas.eis.core.support.TokenProperties;
|
|
|
import com.uas.eis.dao.BaseDao;
|
|
|
import com.uas.eis.dao.SqlRowList;
|
|
|
import com.uas.eis.entity.*;
|
|
|
+import com.uas.eis.entity.transsion.SaleMaterialStockVO;
|
|
|
+import com.uas.eis.entity.transsion.SupplierSecondMaterialStockVO;
|
|
|
import com.uas.eis.sdk.entity.ApiResult;
|
|
|
import com.uas.eis.sdk.resp.ApiResponse;
|
|
|
import com.uas.eis.service.ERPService;
|
|
|
-import com.uas.eis.utils.*;
|
|
|
+import com.uas.eis.utils.BaseUtil;
|
|
|
+import com.uas.eis.utils.MD5Util;
|
|
|
+import com.uas.eis.utils.PSHttpUtils;
|
|
|
+import com.uas.eis.utils.StringUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -33,6 +44,187 @@ public class ERPServiceImpl implements ERPService {
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDao baseDao;
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResult<String> syncProductStock(String data) {
|
|
|
+ logger.info("sendProd-Begin:master {} ids {}");
|
|
|
+ try {
|
|
|
+ SqlRowList docMsg = baseDao.queryForRowSet(" select pr_id,to_char(sysdate,'yyyy-mm-dd') ba_date,ba_remain,tspr_eightcode,pr_code,tspr_ninecode,tspr_description,ba_code from product left join batch on pr_code=ba_prodcode left join transsionproduct on pr_code=tspr_uasprcode " +
|
|
|
+ " where tspr_enable=-1 and pr_statuscode='AUDITED' and ba_whcode='BSD056' and ba_remain>0");
|
|
|
+ if(!docMsg.hasNext()){
|
|
|
+ return ApiResponse.failRsp("102","没有需要同步的商品库存");
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> docMsgResultList = docMsg.getResultList();
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ List<Object> docCodes = new ArrayList<>();
|
|
|
+ List<SaleMaterialStockVO> list = new ArrayList<>();
|
|
|
+ Map<String,Object> reqMap = new HashMap<>();
|
|
|
+ String prCodes = "";
|
|
|
+ for (Map<String, Object> map : docMsgResultList) {
|
|
|
+ docCodes.add(map.get("pr_code"));
|
|
|
+ logger.info("sendProd-test: id {} code {}",map.get("pr_id"),map.get("pr_code"));
|
|
|
+ // 创建SaleMaterialStockVO对象
|
|
|
+ SaleMaterialStockVO saleMaterialStockVO = new SaleMaterialStockVO.Builder()
|
|
|
+ .location("BSD056")
|
|
|
+ .qdate(StringUtil.nvl(map.get("ba_date")," "))
|
|
|
+ .quanity(StringUtil.nvl(map.get("ba_remain")," "))
|
|
|
+ .materialNumber(StringUtil.nvl(map.get("tspr_eightcode")," "))
|
|
|
+ .supplierMaterialNumber(StringUtil.nvl(map.get("pr_code")," "))
|
|
|
+ .mpn(StringUtil.nvl(map.get("tspr_ninecode")," "))
|
|
|
+ .status(1)
|
|
|
+ .materialDescription(StringUtil.nvl(map.get("tspr_description")," "))
|
|
|
+ .batchNo(StringUtil.nvl(map.get("ba_code")," "))
|
|
|
+ .build();
|
|
|
+ list.add(saleMaterialStockVO);
|
|
|
+ }
|
|
|
+ reqMap.put("list",list);
|
|
|
+ logger.info("sendProd-End:master {} ids {}");
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ return ApiResponse.failRsp("101",errMsg.toString());
|
|
|
+ }
|
|
|
+ String json = null;
|
|
|
+ try{
|
|
|
+ json = objectMapper.writeValueAsString(reqMap);
|
|
|
+ logger.info("Request JSON: {}", json);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.info("sendProd-Error:JSON转换失败 codes {} ",prCodes);
|
|
|
+ return ApiResponse.failRsp("106","JSON转换失败");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
+ //baseDao.execute("update product set pr_sendwmsstatus='同步失败' ,pr_sendwmserr='操作:同步' where pr_code in ("+prCodes+")");
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //接口入参,接口平台会直接将当前账号信息传入接口
|
|
|
+ //String json ="{\"elsAccount\":\"864385\"}";
|
|
|
+ //接口提供方企业应用账号
|
|
|
+ String elsAccount = "864385";
|
|
|
+ //接口标识
|
|
|
+ String interfaceCode = "SRM009";
|
|
|
+ //接口参数组装
|
|
|
+ EntryForPOST post = EntryForPOST.builder().elsAccount(elsAccount)
|
|
|
+ .businessType(interfaceCode)
|
|
|
+ .reuestData(json)
|
|
|
+ .specialSign(interfaceCode)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject result = null;
|
|
|
+ try {
|
|
|
+ //接口调用
|
|
|
+ result = OpenApiUtil.doPost(post);
|
|
|
+ } catch (Exception e) {
|
|
|
+ jsonObject.put("message", e.getMessage());
|
|
|
+ System.out.println("error1"+e.getMessage());
|
|
|
+ }
|
|
|
+ //接口返回结果
|
|
|
+ jsonObject.put("message", result.toJSONString());
|
|
|
+ System.out.println(jsonObject.get("message"));
|
|
|
+ return ApiResponse.successRsp("0","同步库存成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", e.getMessage());
|
|
|
+ System.out.println("error1"+e.getMessage());
|
|
|
+ return ApiResponse.failRsp("101",jsonObject.getString("message"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResult<String> syncOriFactoryDelivery(String data) {
|
|
|
+ logger.info("sendOriFactoryDelivery-Begin:master {} ids {}");
|
|
|
+ try {
|
|
|
+ SqlRowList docMsg = baseDao.queryForRowSet(" select nvl(pd_qty-nvl(pd_acceptqty,0),0) wrkQty,tspr_uasprcode,tspr_eightcode,tspr_ninecode,to_char(pu_date,'yyyy-mm-dd') pu_date,pu_code,pd_detno, " +
|
|
|
+ " to_char(pd_delivery,'yyyy-mm-dd') pd_delivery,pd_qty,pd_qty pd_qtyreply,to_char(pd_delivery,'yyyy-mm-dd') pd_deliveryreply,'' pd_remark " +
|
|
|
+ " from purchasedetail left join purchase on pd_puid=pu_id left join transsionproduct on pd_prodcode=tspr_uasprcode " +
|
|
|
+ " where pu_statuscode = 'AUDITED' and nvl(pd_mrpstatuscode,' ')<>'FINISH' and pd_qty-nvl(pd_acceptqty,0)>0 and upper(pd_custname) in ('传音','上海传音') and nvl(tspr_uasprcode,' ') <> 'STK35F62' " +
|
|
|
+ " and nvl(TSPR_EIGHTCODE,' ')<>' ' and nvl(tspr_ENABLE,0) = -1 order by pd_prodcode,pd_puid,pd_detno");
|
|
|
+ if(!docMsg.hasNext()){
|
|
|
+ return ApiResponse.failRsp("102","没有需要同步的商品库存");
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> docMsgResultList = docMsg.getResultList();
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ List<Object> docCodes = new ArrayList<>();
|
|
|
+ List<SupplierSecondMaterialStockVO> list = new ArrayList<>();
|
|
|
+ Map<String,Object> reqMap = new HashMap<>();
|
|
|
+ String prCodes = "";
|
|
|
+ for (Map<String, Object> map : docMsgResultList) {
|
|
|
+ docCodes.add(map.get("pr_code"));
|
|
|
+ logger.info("sendProd-test: id {} code {}",map.get("pr_id"),map.get("pr_code"));
|
|
|
+ // 创建SaleMaterialStockVO对象
|
|
|
+ SupplierSecondMaterialStockVO supplierSecondMaterialStockVO = new SupplierSecondMaterialStockVO.Builder()
|
|
|
+ .materialOem(StringUtil.nvl(map.get("tspr_uasprcode")," "))
|
|
|
+ .matOrderDate(StringUtil.nvl(map.get("pu_date")," "))
|
|
|
+ .orderNumber(StringUtil.nvl(map.get("pu_code")," "))
|
|
|
+ .orderItemNumber(StringUtil.nvl(map.get("pd_detno")," "))
|
|
|
+ .orderReqDate(StringUtil.nvl(map.get("pd_delivery")," "))
|
|
|
+ .orderQty(StringUtil.nvl(map.get("pd_qty")," "))
|
|
|
+ .orderCondate(StringUtil.nvl(map.get("pd_deliveryreply")," "))
|
|
|
+ .orderConQty(StringUtil.nvl(map.get("pd_qtyreply")," "))
|
|
|
+ .supplierRemark(StringUtil.nvl(map.get("pd_remark")," "))
|
|
|
+ .build();
|
|
|
+ list.add(supplierSecondMaterialStockVO);
|
|
|
+ }
|
|
|
+ reqMap.put("list",list);
|
|
|
+ logger.info("sendOriFactoryDelivery-End:master {} ids {}");
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ return ApiResponse.failRsp("101",errMsg.toString());
|
|
|
+ }
|
|
|
+ String json = null;
|
|
|
+ try{
|
|
|
+ json = objectMapper.writeValueAsString(reqMap);
|
|
|
+ logger.info("Request JSON: {}", json);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.info("sendOriFactoryDelivery-Error:JSON转换失败 codes {} ",prCodes);
|
|
|
+ return ApiResponse.failRsp("106","JSON转换失败");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
+ //baseDao.execute("update product set pr_sendwmsstatus='同步失败' ,pr_sendwmserr='操作:同步' where pr_code in ("+prCodes+")");
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //接口入参,接口平台会直接将当前账号信息传入接口
|
|
|
+ //String json ="{\"elsAccount\":\"864385\"}";
|
|
|
+ //接口提供方企业应用账号
|
|
|
+ String elsAccount = "864385";
|
|
|
+ //接口标识
|
|
|
+ String interfaceCode = "SRM013";
|
|
|
+ //接口参数组装
|
|
|
+ EntryForPOST post = EntryForPOST.builder().elsAccount(elsAccount)
|
|
|
+ .businessType(interfaceCode)
|
|
|
+ .reuestData(json)
|
|
|
+ .specialSign(interfaceCode)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject result = null;
|
|
|
+ try {
|
|
|
+ //接口调用
|
|
|
+ result = OpenApiUtil.doPost(post);
|
|
|
+ } catch (Exception e) {
|
|
|
+ jsonObject.put("message", e.getMessage());
|
|
|
+ System.out.println("error1"+e.getMessage());
|
|
|
+ }
|
|
|
+ //接口返回结果
|
|
|
+ jsonObject.put("message", result.toJSONString());
|
|
|
+ System.out.println(jsonObject.get("message"));
|
|
|
+ return ApiResponse.successRsp("0","同步库存成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", e.getMessage());
|
|
|
+ System.out.println("error1"+e.getMessage());
|
|
|
+ return ApiResponse.failRsp("101",jsonObject.getString("message"));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public ApiResult<String> syncProduct(String data) {
|