optimize: 优化导入SAP返回的错误信息

This commit is contained in:
曹鹏飞 2024-04-26 16:01:28 +08:00
parent 850c44a18b
commit b6273ac9ae
8 changed files with 110 additions and 54 deletions

View File

@ -13,10 +13,10 @@ import java.util.List;
public class ImportSapParamDTO {
@ApiModelProperty("流程标题,默认“主数据平台")
private String I_LCBT = "主数据";
private String I_LCBT = "主数据平台";
@ApiModelProperty("默认X")
private String I_ACT = "x";
private String I_ACT = "X";
private String ZID="";

View File

@ -0,0 +1,26 @@
package com.nflg.product.bomnew.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @author 曹鹏飞
* @date 2024/4/26 13:44:01
*/
public class OperationErrorMsgBaseVO implements Serializable {
@ApiModelProperty("错误描述")
public String msg;
public OperationErrorMsgBaseVO() {
}
public OperationErrorMsgBaseVO(String msg) {
this.msg = msg;
}
public static OperationErrorMsgBaseVO create(String msg) {
return new OperationErrorMsgBaseVO(msg);
}
}

View File

@ -1,22 +1,26 @@
package com.nflg.product.bomnew.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
/**
* @author 曹鹏飞
* @date 2024-03-21 14:49:05
*/
@Data
@AllArgsConstructor
public class OperationErrorMsgVO {
public class OperationErrorMsgVO extends OperationErrorMsgBaseVO implements Serializable {
@ApiModelProperty("主键数据")
private String primaryKey;
public String primaryKey;
@ApiModelProperty("错误描述")
private String msg;
public OperationErrorMsgVO() {
}
public OperationErrorMsgVO(String primaryKey, String msg) {
super(msg);
this.primaryKey = primaryKey;
this.msg = msg;
}
public static OperationErrorMsgVO create(String primaryKey, String msg) {
return new OperationErrorMsgVO(primaryKey, msg);

View File

@ -2,17 +2,18 @@ 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;
import com.alibaba.fastjson.JSON;
import com.nflg.product.base.core.exception.ErrorMsgException;
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 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 com.nflg.product.bomnew.pojo.vo.OperationErrorMsgBaseVO;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import nflg.product.common.vo.ResultVO;
@ -20,10 +21,7 @@ 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.Objects;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@Service
@ -143,18 +141,16 @@ public class SapOpUtilService {
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<>();
//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);
//inputStructure.put("I_STKO", parentMap);
params.setInputParams(parentMap);
Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
@ -177,49 +173,41 @@ public class SapOpUtilService {
List< T1DTO > list=null;
if (!CollectionUtils.isEmpty(tOut)) {
list = Convert.convert(new TypeReference<List< T1DTO > >() {
list = Convert.convert(new TypeReference<List<T1DTO>>() {
}, tOut);
}
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
if(CollectionUtil.isNotEmpty(list)){
StringBuffer errBuf=new StringBuffer();
if (CollUtil.isNotEmpty(list)) {
//StringBuffer errBuf=new StringBuffer();
List<OperationErrorMsgBaseVO> liError = new ArrayList<>();
AtomicInteger errCount= new AtomicInteger();
AtomicInteger succCount= new AtomicInteger();
for (T1DTO item:
list) {
if( backList !=null){
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());
for (T1DTO item : list) {
if (backList != null) {
backList.add(item);
}
//"FLAG": "1" -- 0 失败1 成功
if (item.getFLAG().equals("0")) {
errCount.getAndIncrement();
//errBuf.append(item.getSTATUS() + ",");
liError.add(OperationErrorMsgBaseVO.create(item.getSTATUS()));
} else if (item.getFLAG().equals("1")) {
succCount.getAndIncrement();
}
}
if (errCount.get() > 0) {
//throw new Exception(errBuf.toString());
throw new ErrorMsgException(STATE.Success, "导入到SAP出错", liError);
}
}else{
throw new Exception("获取sap返回数据转换异常");
throw new Exception("获取sap返回数据转换异常");
}
} catch (ErrorMsgException e) {
throw e;
} catch (Exception e) {
return ResultVO.error(STATE.Error, e.getMessage());
}
return ResultVO.success();
}
}

View File

@ -255,7 +255,7 @@ public class SapService implements ApplicationContextAware {
res.setOutTablesMap(outTablesMap);
} catch (Exception e) {
e.printStackTrace();
log.error("导入SAP出错", e);
res.setCode(500);
res.setSuccess(false);
res.setMsg(e.getMessage());

View File

@ -35,7 +35,7 @@ public class BaseGlobalExceptionHandle {
public ResultVO<String> handleJeecgBootException(NflgBusinessException e) {
log.error(e.getMessage(), e);
//return ResultVO.error(e.getState(), e.getMessage());
return ResultVO.error(e.getState(),e.getMessage());
return ResultVO.error(e.getState(), e.getMessage());
}
@ExceptionHandler(value = NoHandlerFoundException.class)
@ -152,4 +152,12 @@ public class BaseGlobalExceptionHandle {
log.error(ex.getMessage(),ex);
return ResultVO.error(STATE.ParamErr, ex.getParameterName()+"参数不能为空");
}
@ExceptionHandler(value = ErrorMsgException.class)
@ResponseBody
public ResultVO handleErrorMsgException(ErrorMsgException e) {
log.error(e.getMessage(), e);
//return ResultVO.error(e.getState(), e.getMessage());
return ResultVO.error(e.getState(), e.getMessage(), e.getData());
}
}

View File

@ -0,0 +1,24 @@
package com.nflg.product.base.core.exception;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
/**
* @author 曹鹏飞
* @date 2024/4/26 14:18:09
*/
@Getter
@Slf4j
public class ErrorMsgException extends RuntimeException {
private final STATE state;
private final String msg;
private final Object data;
public ErrorMsgException(STATE state, String msg, Object data) {
super(msg);
this.state = state;
this.msg = msg;
this.data = data;
}
}

View File

@ -1,6 +1,5 @@
package nflg.product.common.vo;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import nflg.product.common.constant.STATE;
@ -44,6 +43,7 @@ public class ResultVO<T> implements Serializable {
vo.msg = msg;
return vo;
}
public static <T> ResultVO<T> error(STATE code, String msg) {
return error(msg, code.getState(), null);
}
@ -70,6 +70,12 @@ public class ResultVO<T> implements Serializable {
return error(msg ,STATE.PassportErr.getState());
}
public static ResultVO error(STATE state, String msg, Object value) {
ResultVO vo = new ResultVO<>();
vo.data = value;
vo.state = state.getState();
vo.msg = msg;
return vo;
}
}