optimize: 优化导入SAP返回的错误信息
This commit is contained in:
parent
850c44a18b
commit
b6273ac9ae
|
|
@ -13,10 +13,10 @@ import java.util.List;
|
||||||
public class ImportSapParamDTO {
|
public class ImportSapParamDTO {
|
||||||
|
|
||||||
@ApiModelProperty("流程标题,默认“主数据平台")
|
@ApiModelProperty("流程标题,默认“主数据平台")
|
||||||
private String I_LCBT = "主数据";
|
private String I_LCBT = "主数据平台";
|
||||||
|
|
||||||
@ApiModelProperty("默认X")
|
@ApiModelProperty("默认X")
|
||||||
private String I_ACT = "x";
|
private String I_ACT = "X";
|
||||||
|
|
||||||
private String ZID="";
|
private String ZID="";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +1,26 @@
|
||||||
package com.nflg.product.bomnew.pojo.vo;
|
package com.nflg.product.bomnew.pojo.vo;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 曹鹏飞
|
* @author 曹鹏飞
|
||||||
* @date 2024-03-21 14:49:05
|
* @date 2024-03-21 14:49:05
|
||||||
*/
|
*/
|
||||||
@Data
|
public class OperationErrorMsgVO extends OperationErrorMsgBaseVO implements Serializable {
|
||||||
@AllArgsConstructor
|
|
||||||
public class OperationErrorMsgVO {
|
|
||||||
|
|
||||||
@ApiModelProperty("主键数据")
|
@ApiModelProperty("主键数据")
|
||||||
private String primaryKey;
|
public String primaryKey;
|
||||||
|
|
||||||
@ApiModelProperty("错误描述")
|
public OperationErrorMsgVO() {
|
||||||
private String msg;
|
}
|
||||||
|
|
||||||
|
public OperationErrorMsgVO(String primaryKey, String msg) {
|
||||||
|
super(msg);
|
||||||
|
this.primaryKey = primaryKey;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
public static OperationErrorMsgVO create(String primaryKey, String msg) {
|
public static OperationErrorMsgVO create(String primaryKey, String msg) {
|
||||||
return new OperationErrorMsgVO(primaryKey, msg);
|
return new OperationErrorMsgVO(primaryKey, msg);
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,18 @@ package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.lang.TypeReference;
|
import cn.hutool.core.lang.TypeReference;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
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.ImportToSapDTO;
|
||||||
import com.nflg.product.bomnew.pojo.dto.sap.SapReqParams;
|
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.SapResult;
|
||||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParam2DTO;
|
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.ImportSapParamDTO;
|
||||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
|
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
|
||||||
|
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgBaseVO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import nflg.product.common.constant.STATE;
|
import nflg.product.common.constant.STATE;
|
||||||
import nflg.product.common.vo.ResultVO;
|
import nflg.product.common.vo.ResultVO;
|
||||||
|
|
@ -20,10 +21,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -143,18 +141,16 @@ public class SapOpUtilService {
|
||||||
if (CollUtil.isEmpty(impartSapParamDTO.getT1())) {
|
if (CollUtil.isEmpty(impartSapParamDTO.getT1())) {
|
||||||
return ResultVO.error("同步SAP 参数错误");
|
return ResultVO.error("同步SAP 参数错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SapReqParams params = new SapReqParams();
|
SapReqParams params = new SapReqParams();
|
||||||
// 接口名
|
// 接口名
|
||||||
params.setFunName("ZRFC_PP_003");
|
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);
|
ImportSapParam2DTO pp=Convert.convert(ImportSapParam2DTO.class ,impartSapParamDTO);
|
||||||
Map<String, Object> parentMap = Convert.convert(new TypeReference<Map<String, Object>>() {
|
Map<String, Object> parentMap = Convert.convert(new TypeReference<Map<String, Object>>() {
|
||||||
}, pp);
|
}, pp);
|
||||||
inputStructure.put("I_STKO", parentMap);
|
//inputStructure.put("I_STKO", parentMap);
|
||||||
params.setInputParams(parentMap);
|
params.setInputParams(parentMap);
|
||||||
|
|
||||||
Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
|
Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
|
||||||
|
|
@ -177,49 +173,41 @@ public class SapOpUtilService {
|
||||||
|
|
||||||
List< T1DTO > list=null;
|
List< T1DTO > list=null;
|
||||||
if (!CollectionUtils.isEmpty(tOut)) {
|
if (!CollectionUtils.isEmpty(tOut)) {
|
||||||
list = Convert.convert(new TypeReference<List< T1DTO > >() {
|
list = Convert.convert(new TypeReference<List<T1DTO>>() {
|
||||||
}, tOut);
|
}, tOut);
|
||||||
}
|
}
|
||||||
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
|
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
|
||||||
|
|
||||||
if(CollectionUtil.isNotEmpty(list)){
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
|
//StringBuffer errBuf=new StringBuffer();
|
||||||
StringBuffer errBuf=new StringBuffer();
|
List<OperationErrorMsgBaseVO> liError = new ArrayList<>();
|
||||||
AtomicInteger errCount= new AtomicInteger();
|
AtomicInteger errCount= new AtomicInteger();
|
||||||
AtomicInteger succCount= new AtomicInteger();
|
AtomicInteger succCount= new AtomicInteger();
|
||||||
for (T1DTO item:
|
for (T1DTO item : list) {
|
||||||
list) {
|
if (backList != null) {
|
||||||
|
backList.add(item);
|
||||||
|
}
|
||||||
if( backList !=null){
|
//"FLAG": "1" -- 0 失败;1 成功
|
||||||
backList.add(item);
|
if (item.getFLAG().equals("0")) {
|
||||||
}
|
errCount.getAndIncrement();
|
||||||
//"FLAG": "1" -- 0 失败;1 成功
|
//errBuf.append(item.getSTATUS() + ",");
|
||||||
if(item.getFLAG().equals("0")){
|
liError.add(OperationErrorMsgBaseVO.create(item.getSTATUS()));
|
||||||
errCount.getAndIncrement();
|
} else if (item.getFLAG().equals("1")) {
|
||||||
errBuf.append(item.getSTATUS()+",");
|
succCount.getAndIncrement();
|
||||||
}else if (item.getFLAG().equals("1")){
|
}
|
||||||
succCount.getAndIncrement();
|
}
|
||||||
}
|
if (errCount.get() > 0) {
|
||||||
|
//throw new Exception(errBuf.toString());
|
||||||
}
|
throw new ErrorMsgException(STATE.Success, "导入到SAP出错", liError);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(errCount.get()>0){
|
|
||||||
throw new Exception(errBuf.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
throw new Exception("获取sap返回数据转换异常");
|
throw new Exception("获取sap返回数据转换异常");
|
||||||
}
|
}
|
||||||
|
} catch (ErrorMsgException e) {
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResultVO.error(STATE.Error, e.getMessage());
|
return ResultVO.error(STATE.Error, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ResultVO.success();
|
return ResultVO.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,7 @@ public class SapService implements ApplicationContextAware {
|
||||||
res.setOutTablesMap(outTablesMap);
|
res.setOutTablesMap(outTablesMap);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("导入SAP出错", e);
|
||||||
res.setCode(500);
|
res.setCode(500);
|
||||||
res.setSuccess(false);
|
res.setSuccess(false);
|
||||||
res.setMsg(e.getMessage());
|
res.setMsg(e.getMessage());
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public class BaseGlobalExceptionHandle {
|
||||||
public ResultVO<String> handleJeecgBootException(NflgBusinessException e) {
|
public ResultVO<String> handleJeecgBootException(NflgBusinessException e) {
|
||||||
log.error(e.getMessage(), 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());
|
return ResultVO.error(e.getState(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = NoHandlerFoundException.class)
|
@ExceptionHandler(value = NoHandlerFoundException.class)
|
||||||
|
|
@ -152,4 +152,12 @@ public class BaseGlobalExceptionHandle {
|
||||||
log.error(ex.getMessage(),ex);
|
log.error(ex.getMessage(),ex);
|
||||||
return ResultVO.error(STATE.ParamErr, ex.getParameterName()+"参数不能为空");
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package nflg.product.common.vo;
|
package nflg.product.common.vo;
|
||||||
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import nflg.product.common.constant.STATE;
|
import nflg.product.common.constant.STATE;
|
||||||
|
|
@ -44,6 +43,7 @@ public class ResultVO<T> implements Serializable {
|
||||||
vo.msg = msg;
|
vo.msg = msg;
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> ResultVO<T> error(STATE code, String msg) {
|
public static <T> ResultVO<T> error(STATE code, String msg) {
|
||||||
return error(msg, code.getState(), null);
|
return error(msg, code.getState(), null);
|
||||||
}
|
}
|
||||||
|
|
@ -70,6 +70,12 @@ public class ResultVO<T> implements Serializable {
|
||||||
return error(msg ,STATE.PassportErr.getState());
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue