导入sap

This commit is contained in:
jing's 2024-01-25 16:25:34 +08:00
parent 3fa277bc49
commit e5399295a7
4 changed files with 115 additions and 1 deletions

View File

@ -105,6 +105,14 @@ public class OptionalEbomConfigEntity implements Serializable {
@TableField(value = "created_by")
@ApiModelProperty(value = "操作人编码")
private String createdBy;
@TableField(value = "upload_sap_user")
@ApiModelProperty(value = "上传人")
private String uploadSapUser;
@TableField(value = "upload_sap_code")
@ApiModelProperty(value = "上传人code")
private String uploadSapCode;
/**
* 创建时间
*/

View File

@ -30,6 +30,7 @@ import com.nflg.product.bomnew.pojo.dto.OptionalMbomMaterialAddDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
import com.nflg.product.bomnew.pojo.entity.MaterialMainEntity;
import com.nflg.product.bomnew.pojo.entity.OptionalEbomConfigEntity;
import com.nflg.product.bomnew.pojo.entity.OptionalMbomMaterialEntity;
import com.nflg.product.bomnew.pojo.query.BomNewEbomMaterialQuery;
@ -178,7 +179,19 @@ public ResultVO<Boolean> importSap(Long rowId){
return SpringUtil.getBean(SapOpUtilService.class).importToSap(result);
ResultVO<Boolean> resultVO= SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result,null);
if(resultVO.getState().equals( STATE.Success.getState())){
OptionalEbomConfigEntity configEntity=new OptionalEbomConfigEntity();
configEntity.setRowId(entity.getRootRowId());
configEntity.setUpdatedTime(DateUtil.now());
configEntity.setUploadSapCode(SessionUtil.getUserCode());
configEntity.setUploadSapUser(SessionUtil.getUserName());
SpringUtil.getBean( OptionalEbomConfigService.class).updateById(configEntity);
}
return resultVO;
}

View File

@ -2,6 +2,7 @@ package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
@ -11,15 +12,18 @@ import com.nflg.product.bomnew.pojo.dto.sap.SapReqParams;
import com.nflg.product.bomnew.pojo.dto.sap.SapResult;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParam2DTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import nflg.product.common.vo.ResultVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@Service
@Slf4j
@ -129,6 +133,92 @@ public class SapOpUtilService {
}
return ResultVO.success();
}
public ResultVO<Boolean> importToSapV2(ImportSapParamDTO impartSapParamDTO,List<T1DTO> backList) {
if (CollUtil.isEmpty(impartSapParamDTO.getT1())) {
return ResultVO.error("同步SAP 参数错误");
}
SapReqParams params = new SapReqParams();
// 接口名
params.setFunName("ZRFC_PP_003");
Map<String, Map<String, Object>> inputStructure = new HashMap<>();
ImportSapParam2DTO pp=Convert.convert(ImportSapParam2DTO.class ,impartSapParamDTO);
Map<String, Object> parentMap = Convert.convert(new TypeReference<Map<String, Object>>() {
}, pp);
inputStructure.put("I_STKO", parentMap);
params.setInputParams(parentMap);
Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
List<Map<String, String>> childMapList = Convert.convert(new TypeReference<List<Map<String, String>>>() {
}, impartSapParamDTO.getT1());
inputTables.put("T1", childMapList);
params.setInputTables(inputTables);
try {
log.info("导入到SAP--参数:" + JSON.toJSONString(params));
SapResult sapResult = sapService.doSapFun(params);
if (!sapResult.isSuccess()) {
return ResultVO.error(STATE.Error, "接口连接失败,"+sapResult.getMsg());
}
Map<String, List<Map<String, Object>>> outTablesMap = sapResult.getOutTablesMap();
List<Map<String, Object>> tOut = outTablesMap.get("T1");
List< T1DTO > list=null;
if (!CollectionUtils.isEmpty(tOut)) {
list = Convert.convert(new TypeReference<List< T1DTO > >() {
}, tOut);
}
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
if(CollectionUtil.isNotEmpty(list)){
StringBuffer errBuf=new StringBuffer();
AtomicInteger errCount= new AtomicInteger();
AtomicInteger succCount= new AtomicInteger();
for (T1DTO item:
list) {
if(CollectionUtil.isNotEmpty(backList)){
backList.add(item);
}
//"FLAG": "1" -- 0 失败1 成功
if(item.getFLAG().equals("0")){
errCount.getAndIncrement();
errBuf.append(item.getSTATUS()+" ");
}else if (item.getFLAG().equals("1")){
succCount.getAndIncrement();
}
}
if(errCount.get()>0){
throw new Exception(errBuf.toString());
}
}else{
throw new Exception("获取sap返回数据转换异常");
}
} catch (Exception e) {
return ResultVO.error(STATE.Error, e.getMessage());
}
return ResultVO.success();
}
}

View File

@ -17,6 +17,9 @@
<result property="realName" column="real_name" jdbcType="VARCHAR"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="uploadSapUser" column="upload_sap_user" jdbcType="VARCHAR"/>
<result property="uploadSapCode" column="upload_sap_code" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="VARCHAR"/>
<result property="updatedTime" column="updated_time" jdbcType="VARCHAR"/>