Commit 6531b6c8 authored by 赵汉亭's avatar 赵汉亭

成本中心新增、冻结SAP接口对接,及接口返回数据重封装

parent b11825c4
......@@ -20,7 +20,6 @@ import com.huigou.topsun.util.MyBaseUtil;
import com.huigou.uasp.bmp.common.application.BaseApplication;
import com.huigou.util.SDO;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
......@@ -29,10 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
/**
* @author 16508
......@@ -187,16 +183,16 @@ public class ProofingMakeApplicationImpl extends BaseApplication implements Proo
});
// 给SAP返回BOM-JSON数据
ProofingMakeBom[] boms = getReturnBOMJson(proofingMakeBomList);
List<Map<String, Object>> boms = getReturnBOM(proofingMakeBomList);
String returnJson = saveToProduct(productId, sdo, boms, status);
List<ProofingMakeReturn> param = saveToProduct(productId, sdo, boms, status);
// 发送
// TODO 接口地址未定
String url = SystemCache.getParameter("sap.service.null.url", String.class);
try {
// TODO 返回数据未封装
String execute = httpClient.execute(returnJson, url);
String execute = httpClient.execute(param, url);
} catch (IOException e) {
throw new RuntimeException(e);
}
......@@ -258,18 +254,23 @@ public class ProofingMakeApplicationImpl extends BaseApplication implements Proo
*
* @return
*/
public ProofingMakeBom[] getReturnBOMJson(List<ProofingMakeBom> bomJson) throws JsonProcessingException {
ProofingMakeBom[] proofingMakeBoms = new ProofingMakeBom[bomJson.size()];
int flog = 0;
public List<Map<String, Object>> getReturnBOM(List<ProofingMakeBom> bomJson) throws JsonProcessingException {
List<Map<String, Object>> returnBOMList = new ArrayList<>();
for (ProofingMakeBom proofingMakeBom : bomJson) {
ProofingMakeBom bom = new ProofingMakeBom();
BeanUtils.copyProperties(proofingMakeBom, bom);
bom.setProductMaterialName(null);
proofingMakeBoms[flog] = bom;
flog++;
Map<String, Object> map = new HashMap<>();
map.put("IDNRK", proofingMakeBom.getProductMaterialId());
map.put("MENGE", proofingMakeBom.getProofingMakeBomNum());
map.put("MEINS", proofingMakeBom.getProofingMakeBomMeins());
map.put("AUSCH", proofingMakeBom.getProofingMakeBomAusch());
map.put("POTX1", proofingMakeBom.getProofingMakeBomText());
map.put("POTX2", proofingMakeBom.getProofingMakeBomMaterialText());
map.put("ALPGR", proofingMakeBom.getProofingMakeBomAlpgr());
map.put("ALPRF", proofingMakeBom.getProofingMakeBomAlprf());
map.put("ALPST", proofingMakeBom.getProofingMakeBomAlpst());
map.put("EWAHR", proofingMakeBom.getProofingMakeBomEwahr());
returnBOMList.add(map);
}
return proofingMakeBoms;
return returnBOMList;
}
@Override
......@@ -283,7 +284,7 @@ public class ProofingMakeApplicationImpl extends BaseApplication implements Proo
*
* @return
*/
public String saveToProduct(String productId, SDO sdo, ProofingMakeBom[] returnJson, String status) throws JsonProcessingException {
public List<ProofingMakeReturn> saveToProduct(String productId, SDO sdo, List<Map<String, Object>> returnJson, String status) throws JsonProcessingException {
String bomJson = sdo.getString("bom");
ObjectMapper objectMapper = new ObjectMapper();
//编辑产品信息
......@@ -362,14 +363,11 @@ public class ProofingMakeApplicationImpl extends BaseApplication implements Proo
proofingMakeReturn.setBOMItems(returnJson);
proofingMakeReturn.setUPDKZ(status);
String returnBomJson = new ObjectMapper().writeValueAsString(proofingMakeReturn);
returnBomJson = returnBomJson.replaceAll("materialId", "IDNRK")
.replaceAll("materialNumber", "MENGE")
.replaceAll("materialUnit", "MEINS")
.replaceAll("materialJson", "POTX2")
.replaceAll("\"materialName\":null,", "");
// returnJson = "[" + returnJson + "]";
return returnBomJson;
List<ProofingMakeReturn> proofingMakeReturns = new ArrayList<>();
proofingMakeReturns.add(proofingMakeReturn);
return proofingMakeReturns;
}
private ProductDetail ToProductDetail(ProofingMakeBaseInfo proofingMakeBaseInfo, String productId) {
......
......@@ -5,6 +5,8 @@ import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* title: 样品制作单数据传SAP接口
......@@ -73,66 +75,6 @@ public class ProofingMakeReturn implements Serializable {
*/
@JsonProperty(value = "ZPGBS",required = true)
private Integer dispatchMultiple;
//
// /**
// * 物料ID
// */
// @JsonProperty(value = "IDNRK",required = true)
// private String materialId;
//
// /**
// * 物料数量
// */
// @JsonProperty(value = "MENGE",required = true)
// private Integer materialNumber;
//
// /**
// * 组件计量单位
// */
// @JsonProperty(value = "MEINS",required = true)
// private String proofingMakeBomMeins;
//
// /**
// * 组件报废百分比
// */
// @JsonProperty(value = "AUSCH",required = true)
// private Double proofingMakeBomAusch;
//
// /**
// * BOM项目文本(行1)
// */
// @JsonProperty(value = "POTX1",required = true)
// private String proofingMakeBomText;
//
// /**
// * 物料清单项目文本(行2)
// */
// @JsonProperty(value = "POTX2",required = true)
// private String proofingMakeBomMaterialText;
//
// /**
// * 替代组
// */
// @JsonProperty(value = "ALPGR",required = true)
// private String proofingMakeBomAlpgr;
//
// /**
// * 替代优先级
// */
// @JsonProperty(value = "ALPRF",required = true)
// private Integer proofingMakeBomAlprf;
//
// /**
// * 策略
// */
// @JsonProperty(value = "ALPST",required = true)
// private String proofingMakeBomAlpst;
//
// /**
// * 使用概率
// */
// @JsonProperty(value = "EWAHR",required = true)
// private Long proofingMakeBomEwahr;
/**
* 更新标识
......@@ -143,6 +85,6 @@ public class ProofingMakeReturn implements Serializable {
/**
* bom结点
*/
private ProofingMakeBom[] BOMItems;
private List<Map<String ,Object >> BOMItems;
}
......@@ -2,6 +2,7 @@ package com.huigou.topsun.sap.costCenter.application.impl;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.cache.DictUtil;
import com.huigou.cache.SystemCache;
......@@ -26,9 +27,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Auther: xin.lu
......@@ -93,26 +95,45 @@ public class CostCenterApplicationImpl extends FlowBroker implements CostCenterA
@Override
public int updateCostCenterStatus(List<String> ids) {
AtomicInteger flog = new AtomicInteger();
ids.forEach(id -> {
HashMap<String, Object> FREEZEReturnMap = new HashMap<>();
FREEZEReturnMap.put("MODE", "FREEZE");
ArrayList<HashMap<String, String>> FREEZEList = new ArrayList<>();
int flog = 0;
for (String id : ids) {
CostCenter costCenter = costCenterRepository.findOne(id);
String returnJSON = new StringBuilder().append("[")
.append("{")
.append("'ZYWLX':'F',")
.append("'KOSTL':'").append(costCenter.getKostl()).append("'")
.append("}")
.append("]")
.toString().replaceAll("'", "\"");
CostCenterMessageVo costCenterMessageVo = send(returnJSON);
HashMap<String, String> map = new HashMap<>();
map.put("KOSTL", costCenter.getKostl());
map.put("KOKRS", "BSNG");
map.put("BKZKP", "X");
map.put("PKZKP", "X");
map.put("BKZKS", "X");
map.put("PKZKS", "X");
FREEZEList.add(map);
}
FREEZEReturnMap.put("FREEZE", FREEZEList);
// TODO 列表发送,SAP返回消息怎么匹配
String execute = send(FREEZEReturnMap);
List<CostCenterMessageVo> costCenterMessageVos;
try {
costCenterMessageVos = new ObjectMapper().readValue(execute, new TypeReference<List<CostCenterMessageVo>>() {
});
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
String[] id = (String[]) ids.toArray();
for (CostCenterMessageVo costCenterMessageVo : costCenterMessageVos) {
int row = Integer.parseInt(costCenterMessageVo.getROW());
CostCenter costCenter = costCenterRepository.findOne(id[row]);
if (!ObjectUtil.isEmpty(costCenterMessageVo) || costCenterMessageVo.getTYPE() == "S") {
// 冻结成功,修改状态
costCenter.setIsDelete(0);
flog.getAndIncrement();
flog++;
}
BeanUtils.copyProperties(costCenterMessageVo, costCenter);
costCenterRepository.save(costCenter);
});
if (ids.size() == flog.intValue())
}
if (ids.size() == flog)
return 1;
return 0;
}
......@@ -124,30 +145,54 @@ public class CostCenterApplicationImpl extends FlowBroker implements CostCenterA
BizBillStatus status = approvePassed() ? BizBillStatus.COMPLETED : BizBillStatus.ABORTED;
CostCenter costCenter = costCenterRepository.findOne(bizId);
costCenter.setStatusId(status.getId());
costCenterRepository.save(costCenter);
// 封装JSON数据
String returnJSON = getReturnVo(costCenter);
// 向SAP发送数据
CostCenterMessageVo send = send(returnJSON);
// 向SAP发送新增数据
CostCenterReturnVo costCenterReturnVo = new CostCenterReturnVo();
BeanUtils.copyProperties(costCenter, costCenterReturnVo);
// 封装新增返回数据
Map<String, Object> CREATEReturnMap = new HashMap<>();
CREATEReturnMap.put("MODE", "CREATE");
ObjectMapper objectMapper = new ObjectMapper();
HashMap data = objectMapper.convertValue(costCenterReturnVo, HashMap.class);
data.put("KOKRS", "BSNG");
data.put("KHINR", "BSNG");
if (costCenterReturnVo.getKosar() == "F")
data.put("MGEFL", "X");
data.put("BKZER", "X");
data.put("PKZER", "X");
data.put("BKZOB", "X");
CREATEReturnMap.put("DATA", data);
String execute = send(CREATEReturnMap);
CostCenterMessageVo costCenterMessageVo = null;
try {
costCenterMessageVo = new ObjectMapper().readValue(execute, CostCenterMessageVo.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
BeanUtils.copyProperties(costCenterMessageVo, costCenter);
costCenterRepository.save(costCenter);
}
/**
* 向SAP发送数据
*
* @param returnJSON
* @param o
* @return 返回的消息
*/
private CostCenterMessageVo send(String returnJSON) {
private String send(Object o) {
String url = SystemCache.getParameter("sap.service.costCent.url", String.class);
CostCenterMessageVo costCenterMessageVo;
String execute;
try {
String execute = httpClient.execute(returnJSON, url);
costCenterMessageVo = new ObjectMapper().readValue(execute, CostCenterMessageVo.class);
execute = httpClient.execute(o, url);
} catch (IOException e) {
throw new RuntimeException(e);
}
return costCenterMessageVo;
return execute;
}
/**
......@@ -183,21 +228,6 @@ public class CostCenterApplicationImpl extends FlowBroker implements CostCenterA
String bizId = delegateTask.getExecution().getProcessBusinessKey();
CostCenter costCenter = costCenterRepository.findOne(bizId);
costCenter.setStatusId(BizBillStatus.APPLYING.getId());
// 向SAP发送新增数据
CostCenterReturnVo costCenterReturnVo = new CostCenterReturnVo();
BeanUtils.copyProperties(costCenter, costCenterReturnVo);
costCenterReturnVo.setZYWLX("A");
String returnJson = null;
try {
returnJson = new ObjectMapper().writeValueAsString(costCenterReturnVo);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
// 发送
CostCenterMessageVo costCenterMessageVo = send(returnJson);
BeanUtils.copyProperties(costCenterMessageVo, costCenter);
costCenterRepository.save(costCenter);
}
}
......
......@@ -45,4 +45,9 @@ public class CostCenterMessageVo {
@Column(name = "LOG_NO")
@JsonProperty("LOG_NO")
private String LOG_NO;
/**
* 行
*/
private String ROW;
}
......@@ -16,10 +16,6 @@ import java.util.Date;
*/
@JsonIgnoreProperties
public class CostCenterReturnVo implements Serializable {
/**
* 业务类型
*/
private String ZYWLX;
/**
* 成本中心编码
......@@ -78,14 +74,6 @@ public class CostCenterReturnVo implements Serializable {
@JsonProperty("PRCTR")
private String prctr;
public String getZYWLX() {
return ZYWLX;
}
public void setZYWLX(String ZYWLX) {
this.ZYWLX = ZYWLX;
}
public String getKostl() {
return kostl;
}
......@@ -150,9 +138,8 @@ public class CostCenterReturnVo implements Serializable {
this.prctr = prctr;
}
public CostCenterReturnVo(String ZYWLX, String kostl, Date datab, Date datbi, String ktext, String ltext, String verak, String kosar, String prctr) {
public CostCenterReturnVo( String kostl, Date datab, Date datbi, String ktext, String ltext, String verak, String kosar, String prctr) {
this.ZYWLX = ZYWLX;
this.kostl = kostl;
this.datab = datab;
this.datbi = datbi;
......
......@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -88,11 +89,11 @@ public class SapFixedAssetsApplicationImpl extends FlowBroker implements SapFixe
fixedAssets.setStatusId(status.getId());
// 封装返回数据
String returnJSON = getReturnVo(fixedAssets);
List<SapFixedAssetsReturnVo> sapFixedAssetsReturnVoList = getReturnVo(fixedAssets);
String url = SystemCache.getParameter("sap.service.fixedAssets.url", String.class);
SapFixedAssets message;
try {
String execute = httpClient.execute(returnJSON, url);
String execute = httpClient.execute(sapFixedAssetsReturnVoList, url);
message = new ObjectMapper().readValue(execute, SapFixedAssets.class);
} catch (IOException e) {
throw new RuntimeException(e);
......@@ -104,18 +105,13 @@ public class SapFixedAssetsApplicationImpl extends FlowBroker implements SapFixe
/**
* 封装返回JSON
*/
private String getReturnVo(SapFixedAssets fixedAssets) {
private List<SapFixedAssetsReturnVo> getReturnVo(SapFixedAssets fixedAssets) {
SapFixedAssetsReturnVo sapFixedAssetsReturnVo = new SapFixedAssetsReturnVo();
BeanUtils.copyProperties(fixedAssets, sapFixedAssetsReturnVo);
// 转JSON
ObjectMapper objectMapper = new ObjectMapper();
String returnJson = null;
try {
returnJson = objectMapper.writeValueAsString(sapFixedAssetsReturnVo);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return returnJson;
List<SapFixedAssetsReturnVo> sapFixedAssetsReturnVos = new ArrayList<>();
sapFixedAssetsReturnVos.add(sapFixedAssetsReturnVo);
return sapFixedAssetsReturnVos;
}
@Override
......
......@@ -153,42 +153,23 @@ public class SapPriceMasterDataApplicationImpl extends FlowBroker implements Sap
param.put("VTWEG", queryRequest.getVtweg());
param.put("KUNNR", queryRequest.getKunnr());
param.put("MATNR", queryRequest.getMatnr());
String[] strings = new String[1];
try {
strings[0] = new ObjectMapper().writeValueAsString(param);
strings.toString();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[")
.append("{")
.append("'KSCHL':'").append(queryRequest.getKschl()).append("',")
.append("'VKORG':'").append(queryRequest.getVkorg()).append("',")
.append("'VTWEG':'").append(queryRequest.getVtweg()).append("',")
.append("'KUNNR':'").append(queryRequest.getKunnr()).append("',")
.append("'MATNR':'").append(queryRequest.getMatnr())
.append("'}")
.append("]")
.toString().replaceAll("'", "\"");
List<Object> objectArrayList = new ArrayList<>();
objectArrayList.add(param);
List<SapPriceMasterDataItem> sapPriceMasterDataItemList = null;
try {
// 调用接口,获取返回数据
// String execute = httpClient.execute(param, url);
String execute1 = httpClient.execute(stringBuilder.toString(), url);
String execute = httpClient.execute(objectArrayList, url);
// 解析返回数据
execute1 = execute1.replaceAll("MATNR", "matnr")
execute = execute.replaceAll("MATNR", "matnr")
.replaceAll("KBETR", "kbetr")
.replaceAll("KONWA", "konwa")
.replaceAll("KMEIN", "kmein")
.replaceAll("DATAB", "datab")
.replaceAll("DATBI", "datbi");
ObjectMapper objectMapper = new ObjectMapper();
sapPriceMasterDataItemList = objectMapper.readValue(execute1, new TypeReference<List<SapPriceMasterDataItem>>() {
sapPriceMasterDataItemList = objectMapper.readValue(execute, new TypeReference<List<SapPriceMasterDataItem>>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
......
......@@ -6,7 +6,6 @@ import com.huigou.context.OrgUnit;
import com.huigou.context.ThreadLocalUtil;
import com.huigou.data.query.model.QueryDescriptor;
import com.huigou.data.query.model.QueryModel;
import com.huigou.topsun.sap.dictionary.A;
import com.huigou.topsun.sap.purchaseApproval.application.SapPurchaseApprovalApplication;
import com.huigou.topsun.sap.purchaseApproval.application.SapPurchaseApprovalItemApplication;
import com.huigou.topsun.sap.purchaseApproval.domain.SapPurchaseApproval;
......@@ -89,7 +88,6 @@ public class SapPurchaseApprovalApplicationImpl extends FlowBroker implements Sa
/**
* 转换成SAP JSON格式数据
* @param sapPurchase
* @return
*/
/*public String getSapPurchaseVoJson(SapPurchaseApproval sapPurchase){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment