同步sap+发布PBOM
This commit is contained in:
parent
716ff8fe32
commit
c1265b656b
|
|
@ -119,6 +119,7 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
@ -129,6 +130,7 @@
|
||||||
<version>2.6.4</version>
|
<version>2.6.4</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -108,6 +108,10 @@ public class NacosConfig {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static NacosConfig getNacosConfig(){
|
public static NacosConfig getNacosConfig(){
|
||||||
return SpringContextUtils.getBean(NacosConfig.class);
|
return SpringContextUtils.getBean(NacosConfig.class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.nflg.product.bomnew.pojo.dto.sap;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ImportToSapChildDTO {
|
||||||
|
// 物料编码
|
||||||
|
private String IDNRK;
|
||||||
|
// 序号
|
||||||
|
private String POSNR;
|
||||||
|
// 项目类别
|
||||||
|
private String POSTP;
|
||||||
|
// 数量
|
||||||
|
private String MENGE;
|
||||||
|
// 单位
|
||||||
|
private String MEINS;
|
||||||
|
|
||||||
|
/** 暂时未用到的字段 */
|
||||||
|
// // 工厂
|
||||||
|
// private String WERKS;
|
||||||
|
// // 物料描述
|
||||||
|
// private String MAKTX;
|
||||||
|
// // 创建日期
|
||||||
|
// @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
// private String ANDAT;
|
||||||
|
// // 修改日期
|
||||||
|
// @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
// private String AEDAT;
|
||||||
|
// // 有效起始日
|
||||||
|
// private String DATUV;
|
||||||
|
// // 有效至
|
||||||
|
// private String DATUB;
|
||||||
|
// // 设计人员
|
||||||
|
// private String ANNAM;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.nflg.product.bomnew.pojo.dto.sap;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ImportToSapDTO {
|
||||||
|
|
||||||
|
// 抬头
|
||||||
|
private ImportToSapParentDTO parent;
|
||||||
|
|
||||||
|
// 组件
|
||||||
|
private List<ImportToSapChildDTO> childList;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.nflg.product.bomnew.pojo.dto.sap;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ImportToSapParentDTO {
|
||||||
|
// 工厂
|
||||||
|
private String WERKS;
|
||||||
|
// 物料号
|
||||||
|
private String MATNR;
|
||||||
|
// BOM用途
|
||||||
|
private String STLAN;
|
||||||
|
// 基本数量
|
||||||
|
private String BMENG;
|
||||||
|
// 单位
|
||||||
|
private String BMEIN;
|
||||||
|
// BOM状态:1=EBOM生成、2=暂存(当编辑时状态改为暂存)、3=已发布
|
||||||
|
private String STLST;
|
||||||
|
// 有效起始日
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private String DATUV;
|
||||||
|
|
||||||
|
/** 暂时未用到的字段 */
|
||||||
|
// 物料描述
|
||||||
|
// private String MAKTX;
|
||||||
|
// 可选的bom
|
||||||
|
// private String STLAL;
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.nflg.product.bomnew.util.sap;
|
package com.nflg.product.bomnew.pojo.dto.sap;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.nflg.product.bomnew.util.sap;
|
package com.nflg.product.bomnew.pojo.dto.sap;
|
||||||
|
|
||||||
import com.sap.conn.jco.JCoParameterList;
|
import com.sap.conn.jco.JCoParameterList;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
package com.nflg.product.bomnew.service;
|
package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.lang.TypeReference;
|
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
@ -19,26 +16,27 @@ import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||||
import com.nflg.product.bomnew.constant.*;
|
import com.nflg.product.bomnew.constant.*;
|
||||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
|
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
|
||||||
import com.nflg.product.bomnew.pojo.dto.*;
|
import com.nflg.product.bomnew.pojo.dto.*;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapChildDTO;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapDTO;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapParentDTO;
|
||||||
import com.nflg.product.bomnew.pojo.entity.*;
|
import com.nflg.product.bomnew.pojo.entity.*;
|
||||||
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
|
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
|
||||||
import com.nflg.product.bomnew.pojo.vo.*;
|
import com.nflg.product.bomnew.pojo.vo.*;
|
||||||
import com.nflg.product.bomnew.service.domain.PBom.*;
|
import com.nflg.product.bomnew.service.domain.PBom.*;
|
||||||
import com.nflg.product.bomnew.util.*;
|
import com.nflg.product.bomnew.util.*;
|
||||||
import com.nflg.product.bomnew.util.sap.LevelNumUtil;
|
import com.nflg.product.bomnew.util.LevelNumUtil;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import nflg.product.common.constant.STATE;
|
import nflg.product.common.constant.STATE;
|
||||||
|
import nflg.product.common.vo.ResultVO;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.ttzero.excel.entity.ListMapSheet;
|
|
||||||
import org.ttzero.excel.entity.ListSheet;
|
|
||||||
import org.ttzero.excel.entity.Workbook;
|
import org.ttzero.excel.entity.Workbook;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
@ -93,6 +91,9 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
||||||
@Resource
|
@Resource
|
||||||
BomNewPbomMaterialUseService pbomMaterialUseService;
|
BomNewPbomMaterialUseService pbomMaterialUseService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
SapOpUtilService sapOpUtilService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pbom-工作列表
|
* pbom-工作列表
|
||||||
*
|
*
|
||||||
|
|
@ -721,6 +722,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
||||||
*
|
*
|
||||||
* @param bomRowId
|
* @param bomRowId
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean realesePbom(Long bomRowId) {
|
public boolean realesePbom(Long bomRowId) {
|
||||||
BomNewPbomParentEntity parent = this.getById(bomRowId);
|
BomNewPbomParentEntity parent = this.getById(bomRowId);
|
||||||
try {
|
try {
|
||||||
|
|
@ -729,8 +731,9 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
||||||
Integer state = (parent.getMaterialNo().startsWith("31") && parent.getFacCode().equals(EBomConstant.MAIN_FACTORY_CODE_1010)) ? PBomStatusEnum.WAIT_FACTORY.getValue() : PBomStatusEnum.PUBLISH.getValue();
|
Integer state = (parent.getMaterialNo().startsWith("31") && parent.getFacCode().equals(EBomConstant.MAIN_FACTORY_CODE_1010)) ? PBomStatusEnum.WAIT_FACTORY.getValue() : PBomStatusEnum.PUBLISH.getValue();
|
||||||
bomRowIds.add(bomRowId);
|
bomRowIds.add(bomRowId);
|
||||||
this.getBaseMapper().bomRelease(state, SessionUtil.getUserName(), bomRowIds);
|
this.getBaseMapper().bomRelease(state, SessionUtil.getUserName(), bomRowIds);
|
||||||
//保存订单号
|
//同步sap
|
||||||
// this.updateById(parent);
|
saySyncDEMO();
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new NflgBusinessException(STATE.BusinessError, "发布Pbom失败:" + ex.getMessage());
|
throw new NflgBusinessException(STATE.BusinessError, "发布Pbom失败:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -738,6 +741,86 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saySyncDEMO(){
|
||||||
|
ImportToSapDTO result=new ImportToSapDTO();
|
||||||
|
SimpleDateFormat spt=new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
ImportToSapParentDTO sapParent=new ImportToSapParentDTO();
|
||||||
|
sapParent.setWERKS("1010");
|
||||||
|
sapParent.setMATNR("2100564157");
|
||||||
|
sapParent.setSTLAN("");
|
||||||
|
sapParent.setBMENG("1");
|
||||||
|
sapParent.setBMEIN("PC");
|
||||||
|
sapParent.setSTLST("3");
|
||||||
|
sapParent.setDATUV("2024-01-16");
|
||||||
|
|
||||||
|
result.setParent(sapParent);
|
||||||
|
List<ImportToSapChildDTO> childResult=new ArrayList<>();
|
||||||
|
ImportToSapChildDTO childEnt =new ImportToSapChildDTO();
|
||||||
|
childEnt.setIDNRK("1100021745");
|
||||||
|
childEnt.setPOSNR("045");
|
||||||
|
childEnt.setPOSTP("F");
|
||||||
|
childEnt.setMENGE("6");
|
||||||
|
childEnt.setMEINS("PC");
|
||||||
|
childResult.add(childEnt);
|
||||||
|
|
||||||
|
result.setChildList(childResult);
|
||||||
|
|
||||||
|
|
||||||
|
List<ImportToSapDTO> sapParams=new ArrayList<>();
|
||||||
|
|
||||||
|
sapParams.add(result);
|
||||||
|
ResultVO<Boolean> syncResult = sapOpUtilService.importPBomToSap(sapParams);
|
||||||
|
VUtils.isTure(!syncResult.getState().equals(STATE.Success)).throwMessage("同步SAP失败:"+syncResult.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importSap(BomNewPbomParentEntity parent, List<BomNewPbomParentVO> children){
|
||||||
|
|
||||||
|
List<BomNewPbomParentVO> pbom = children.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList());
|
||||||
|
List<BomNewPbomParentVO> parentChild = children.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
|
||||||
|
List<ImportToSapDTO> sapParams=new ArrayList<>();
|
||||||
|
sapParams.add(buildSapBom(Convert.convert(BomNewPbomParentVO.class, parent), parentChild));
|
||||||
|
|
||||||
|
for (BomNewPbomParentVO pt :pbom) {
|
||||||
|
List<BomNewPbomParentVO> pChild = children.stream().filter(u -> u.getParentRowId().equals(pt.getBomRowId())).collect(Collectors.toList());
|
||||||
|
sapParams.add(buildSapBom(Convert.convert(BomNewPbomParentVO.class, parent), pChild));
|
||||||
|
}
|
||||||
|
if(CollUtil.isNotEmpty(sapParams)) {
|
||||||
|
sapOpUtilService.importPBomToSap(sapParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImportToSapDTO buildSapBom(BomNewPbomParentVO parentVO, List<BomNewPbomParentVO> children){
|
||||||
|
|
||||||
|
ImportToSapDTO result=new ImportToSapDTO();
|
||||||
|
ImportToSapParentDTO sapParent=new ImportToSapParentDTO();
|
||||||
|
SimpleDateFormat spt=new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
sapParent.setWERKS(parentVO.getFacCode());
|
||||||
|
sapParent.setMATNR(parentVO.getMaterialNo());
|
||||||
|
sapParent.setSTLAN("");
|
||||||
|
sapParent.setBMENG(parentVO.getNum().toString());
|
||||||
|
sapParent.setBMEIN(parentVO.getMaterialUnit());
|
||||||
|
sapParent.setSTLST("3");
|
||||||
|
sapParent.setDATUV(spt.format( parentVO.getCreatedTime()));
|
||||||
|
|
||||||
|
List<ImportToSapChildDTO> childResult=new ArrayList<>();
|
||||||
|
for (BomNewPbomParentVO child :children) {
|
||||||
|
ImportToSapChildDTO childEnt =new ImportToSapChildDTO();
|
||||||
|
childEnt.setIDNRK(child.getMaterialNo());
|
||||||
|
childEnt.setPOSNR(child.getOrderNumber());
|
||||||
|
childEnt.setPOSTP(child.getProjectType());
|
||||||
|
childEnt.setMENGE(child.getNum().toString());
|
||||||
|
childEnt.setMEINS(child.getMaterialUnit());
|
||||||
|
childResult.add(childEnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setParent(sapParent);
|
||||||
|
result.setChildList(childResult);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取CRM 订单号
|
* 获取CRM 订单号
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.lang.TypeReference;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapDTO;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.SapReqParams;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.SapResult;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import nflg.product.common.constant.STATE;
|
||||||
|
import nflg.product.common.vo.ResultVO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SapOpUtilService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
SapService sapService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public ResultVO<Boolean> importPBomToSap(List<ImportToSapDTO> sapList) {
|
||||||
|
if (CollUtil.isEmpty(sapList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ImportToSapDTO importToSapDTO : sapList) {
|
||||||
|
SapReqParams params = new SapReqParams();
|
||||||
|
// 接口名
|
||||||
|
params.setFunName("ZRFC_PP_CREATEBOM");
|
||||||
|
|
||||||
|
Map<String, Map<String, Object>> inputStructure = new HashMap<>();
|
||||||
|
Map<String, Object> parentMap = Convert.convert(new TypeReference<Map<String, Object>>() {
|
||||||
|
}, importToSapDTO.getParent());
|
||||||
|
inputStructure.put("I_STKO", parentMap);
|
||||||
|
params.setInputStructure(inputStructure);
|
||||||
|
|
||||||
|
Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
|
||||||
|
List<Map<String, String>> childMapList = Convert.convert(new TypeReference<List<Map<String, String>>>() {
|
||||||
|
}, importToSapDTO.getChildList());
|
||||||
|
inputTables.put("T_BOM", childMapList);
|
||||||
|
params.setInputTables(inputTables);
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("PBOM导入到SAP--参数:" + JSON.toJSONString(params));
|
||||||
|
SapResult sapResult = sapService.doSapFun(params);
|
||||||
|
Map<String, Object> exportMap = sapResult.getExportMap();
|
||||||
|
if (!sapResult.isSuccess()) {
|
||||||
|
return ResultVO.error(STATE.Error, "接口连接失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("PBOM导入到SAP--返回值:" + JSON.toJSONString(exportMap));
|
||||||
|
String eErrmsg = String.valueOf(exportMap.get("E_ERRMSG"));
|
||||||
|
if (StrUtil.isNotEmpty(eErrmsg)) {
|
||||||
|
return ResultVO.error(STATE.Error, eErrmsg);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultVO.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,26 @@
|
||||||
package com.nflg.product.bomnew.util.sap;
|
package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.SapReqParams;
|
||||||
|
import com.nflg.product.bomnew.pojo.dto.sap.SapResult;
|
||||||
import com.sap.conn.jco.*;
|
import com.sap.conn.jco.*;
|
||||||
import com.sap.conn.jco.ext.DestinationDataProvider;
|
import com.sap.conn.jco.ext.DestinationDataProvider;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SAP JCO3 连接池
|
* sap服務
|
||||||
*/
|
*/
|
||||||
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
public class SapService implements ApplicationContextAware {
|
||||||
public class ConnectPooled {
|
|
||||||
|
|
||||||
@Value("${custom.sap.host}")
|
@Value("${custom.sap.host}")
|
||||||
private String sapHost;
|
private String sapHost;
|
||||||
@Value("${custom.sap.sysnr}")
|
@Value("${custom.sap.sysnr}")
|
||||||
|
|
@ -36,33 +38,31 @@ public class ConnectPooled {
|
||||||
@Value("${custom.sap.peak}")
|
@Value("${custom.sap.peak}")
|
||||||
private String sapPeak;
|
private String sapPeak;
|
||||||
|
|
||||||
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
|
private static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化SAP连接
|
|
||||||
* PostConstruct 注解的方法在项目启动的时候执行这个方法,也可以理解为在spring容器启动的时候执行,可作为一些数据的常规化加载,比如数据字典之类的
|
|
||||||
*/
|
|
||||||
@PostConstruct
|
|
||||||
private void initProperties() {
|
private void initProperties() {
|
||||||
Properties connectProperties = new Properties();
|
Properties connectProperties = new Properties();
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, sapHost);
|
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, sapHost);
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sapSysnr);
|
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,sapSysnr);
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, sapClient);
|
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT,sapClient);
|
||||||
// QAS800
|
// QAS800
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_USER, sapUsername);
|
connectProperties.setProperty(DestinationDataProvider.JCO_USER,sapUsername);
|
||||||
// 注:密码是区分大小写的,要注意大小写
|
// 注:密码是区分大小写的,要注意大小写
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, sapPassword);
|
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,sapPassword);
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, sapLang);
|
connectProperties.setProperty(DestinationDataProvider.JCO_LANG ,sapLang);
|
||||||
// *********连接池方式与直接不同的是设置了下面两个连接属性
|
// *********连接池方式与直接不同的是设置了下面两个连接属性
|
||||||
// JCO_PEAK_LIMIT - 同时可创建的最大活动连接数,0表示无限制,默认为JCO_POOL_CAPACITY的值
|
// JCO_PEAK_LIMIT - 同时可创建的最大活动连接数,0表示无限制,默认为JCO_POOL_CAPACITY的值
|
||||||
// 如果小于JCO_POOL_CAPACITY的值,则自动设置为该值,在没有设置JCO_POOL_CAPACITY的情况下为0
|
// 如果小于JCO_POOL_CAPACITY的值,则自动设置为该值,在没有设置JCO_POOL_CAPACITY的情况下为0
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, sapPeak);
|
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,sapPeak);
|
||||||
// JCO_POOL_CAPACITY - 空闲连接数,如果为0,则没有连接池效果,默认为1
|
// JCO_POOL_CAPACITY - 空闲连接数,如果为0,则没有连接池效果,默认为1
|
||||||
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, sapPool);
|
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY,sapPool);
|
||||||
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
|
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createDataFile(String name, String suffix, Properties properties) {
|
|
||||||
|
void createDataFile(String name, String suffix, Properties properties) {
|
||||||
File cfg = new File(name + "." + suffix);
|
File cfg = new File(name + "." + suffix);
|
||||||
if (!cfg.exists()) {
|
if (!cfg.exists()) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -75,6 +75,7 @@ public class ConnectPooled {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void connectWithPooled() throws JCoException {
|
public static void connectWithPooled() throws JCoException {
|
||||||
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
|
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
|
||||||
System.out.println("Attributes:");
|
System.out.println("Attributes:");
|
||||||
|
|
@ -295,10 +296,8 @@ public class ConnectPooled {
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void main(String[] args) throws JCoException {
|
@Override
|
||||||
//// connectWithPooled();
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
//// accessSAPStructure();
|
initProperties();
|
||||||
//// workWithTable();
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -305,9 +305,10 @@ public class EBomToPBom {
|
||||||
if (CollUtil.isNotEmpty(parentList)) {
|
if (CollUtil.isNotEmpty(parentList)) {
|
||||||
sum = NumberUtil.mul(sum, parentList.get(0).getNum());
|
sum = NumberUtil.mul(sum, parentList.get(0).getNum());
|
||||||
parentFullPathNum.add(parentList.get(0).getNum());
|
parentFullPathNum.add(parentList.get(0).getNum());
|
||||||
} else {
|
|
||||||
parentFullPathNum.add(parentList.get(0).getNum());
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// parentFullPathNum.add(parentList.get(0).getNum());
|
||||||
|
// }
|
||||||
parentLevelNo = BomLevelUtil.getParentLevelNo(parentLevelNo);
|
parentLevelNo = BomLevelUtil.getParentLevelNo(parentLevelNo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,6 @@ public class BomLevelUtil {
|
||||||
public static String getParentLevelNo(String levelNo){
|
public static String getParentLevelNo(String levelNo){
|
||||||
List<String> result=new ArrayList<>();
|
List<String> result=new ArrayList<>();
|
||||||
String[] parts = levelNo.split("-");
|
String[] parts = levelNo.split("-");
|
||||||
return String.join("-", Arrays.copyOfRange(parts, 0, levelNo.length()-1));
|
return String.join("-", Arrays.copyOfRange(parts, 0, parts.length-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.nflg.product.bomnew.util.sap;
|
package com.nflg.product.bomnew.util;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
Loading…
Reference in New Issue