optimize: 优化导入SAP功能错误信息返回
This commit is contained in:
parent
be9702a415
commit
5a9948635e
|
|
@ -42,14 +42,14 @@ public class TestApi {
|
|||
List<T1DTO> t1s = new ArrayList<>();
|
||||
T1DTO t1 = new T1DTO();
|
||||
t1.setID(RandomUtil.randomNumbers(5));
|
||||
t1.setMATNR("2100677191");
|
||||
t1.setIDNRK("1100002498");
|
||||
t1.setMATNR("2200006651");
|
||||
t1.setIDNRK("2100675047");
|
||||
t1.setMEINS("PC");
|
||||
t1.setMENGE("3.00");
|
||||
t1.setMENGE("1.00");
|
||||
t1.setPOSTP("L");
|
||||
t1.setDATUM(dateYMD);
|
||||
t1s.add(t1);
|
||||
sapDto.setT1(t1s);
|
||||
return sapOpUtilService.importToSapV2(sapDto, null);
|
||||
return ResultVO.success(sapOpUtilService.importToSapV2(sapDto, null));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,22 +5,6 @@ import lombok.Getter;
|
|||
|
||||
public class MBomConstantEnum {
|
||||
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MBomStatusEnum implements ValueEnum<Integer> {
|
||||
//1、待发布(sap)、3=已发布
|
||||
UNPUB_SAP(1, "未导入"),
|
||||
PUB_RUNNING(2, "导入中"),
|
||||
PUB_SAP(3, "已导入"),
|
||||
PUB_ERROR(4, "部分导入失败"),
|
||||
PUB_ERROR_ALL(5, "全部导入失败");
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MBomSuperMaterialStatusEnum implements ValueEnum<Integer> {
|
||||
|
|
|
|||
|
|
@ -134,21 +134,5 @@ public class OptionalBomConstant {
|
|||
}
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum UploadSapStatusEnum {
|
||||
//是否导入sap(0 :否 1: 是)
|
||||
SAP_0(0, "未导入" ),
|
||||
SAP_1(1, "已导入" ) ;
|
||||
|
||||
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.product.bomnew.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author 曹鹏飞
|
||||
* @date 2024/4/30 11:12:47
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum SapStatusEnum implements ValueEnum<Integer> {
|
||||
|
||||
UNPUB_SAP(1, "未导入"),
|
||||
PUB_RUNNING(2, "导入中"),
|
||||
PUB_SAP(3, "已导入"),
|
||||
PUB_ERROR(4, "部分导入失败"),
|
||||
PUB_ERROR_ALL(5, "全部导入失败");
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.nflg.product.bomnew.pojo.vo;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.nflg.product.bomnew.constant.FactoryCodeEnum;
|
||||
import com.nflg.product.bomnew.constant.MBomConstantEnum;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.util.EnumUtils;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
|
@ -273,8 +273,8 @@ public class BomNewMbomMiddleVO extends BaseMaterialVO implements Serializable {
|
|||
|
||||
public String getStatusName(){
|
||||
if(materialBackStatus==null || materialBackStatus.equals(MBomConstantEnum.MaterialBackStatusEnum.APPLY_0.getValue())){
|
||||
if(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue().equals(status)){
|
||||
return MBomConstantEnum.MBomStatusEnum.PUB_SAP.getDescription();
|
||||
if (SapStatusEnum.PUB_SAP.getValue().equals(status)) {
|
||||
return SapStatusEnum.PUB_SAP.getDescription();
|
||||
}
|
||||
return MBomConstantEnum.MaterialBackStatusEnum.APPLY_0.getDescription();
|
||||
|
||||
|
|
|
|||
|
|
@ -926,10 +926,12 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
}
|
||||
}
|
||||
|
||||
public ResultVO<List<OperationErrorMsgVO>> importToSAP(Long bomRowId) {
|
||||
BomNewEbomParentEntity root = this.getById(bomRowId);
|
||||
public ResultVO<List<OperationErrorMsgVO>> importToSAP(Long rootBomRowId) {
|
||||
BomNewEbomParentEntity root = this.getById(rootBomRowId);
|
||||
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
|
||||
VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点");
|
||||
VUtils.isTure(Objects.equals(root.getSapState(), SapStatusEnum.PUB_RUNNING.getValue()))
|
||||
.throwMessage("正在导入中,请等待操作完成");
|
||||
|
||||
ImportSapParamDTO sapDto = new ImportSapParamDTO();
|
||||
sapDto.setZID(RandomUtil.randomNumbers(5));
|
||||
|
|
@ -939,17 +941,27 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
List<T1DTO> t1s = new ArrayList<>();
|
||||
buildChildrenForSap(root, t1s);
|
||||
sapDto.setT1(t1s);
|
||||
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
|
||||
boolean update = lambdaUpdate().eq(BomNewEbomParentEntity::getRowId, bomRowId)
|
||||
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
|
||||
List<OperationErrorMsgVO> liErrMsg = null;
|
||||
try {
|
||||
updateSapState(rootBomRowId, SapStatusEnum.PUB_RUNNING);
|
||||
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
|
||||
if (CollUtil.isEmpty(liErrMsg)) {
|
||||
state = SapStatusEnum.PUB_SAP;
|
||||
} else if (sapDto.getT1().size() != liErrMsg.size()) {
|
||||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
} finally {
|
||||
updateSapState(rootBomRowId, state);
|
||||
}
|
||||
return ResultVO.success(liErrMsg);
|
||||
}
|
||||
|
||||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
lambdaUpdate().eq(BomNewEbomParentEntity::getRowId, rootBomRowId)
|
||||
.set(BomNewEbomParentEntity::getSapTime, LocalDateTime.now())
|
||||
.set(Objects.equals(resultVO.getState(), STATE.Success.getState())
|
||||
, BomNewEbomParentEntity::getSapState, MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue())
|
||||
.set(!Objects.equals(resultVO.getState(), STATE.Success.getState()) && t1s.size() == resultVO.getData().size()
|
||||
, BomNewEbomParentEntity::getSapState, MBomConstantEnum.MBomStatusEnum.PUB_ERROR_ALL.getValue())
|
||||
.set(!Objects.equals(resultVO.getState(), STATE.Success.getState()) && t1s.size() != resultVO.getData().size()
|
||||
, BomNewEbomParentEntity::getSapState, MBomConstantEnum.MBomStatusEnum.PUB_ERROR.getValue())
|
||||
.set(BomNewEbomParentEntity::getSapState, sapState)
|
||||
.update();
|
||||
return update ? resultVO : ResultVO.error("更新数据失败");
|
||||
}
|
||||
|
||||
private void buildChildrenForSap(BomNewEbomParentEntity parent, List<T1DTO> t1s) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
package com.nflg.product.bomnew.service;
|
||||
|
||||
|
||||
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 cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
|
|
@ -12,13 +10,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.MBomConstantEnum;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewMbomDetailMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewMbomDetailVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewMbomMiddleVO;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -92,7 +89,7 @@ public class BomNewMbomDetailService extends ServiceImpl<BomNewMbomDetailMapper,
|
|||
throw new NflgBusinessException(STATE.Error, "顶层数据不存在");
|
||||
}
|
||||
|
||||
if (Objects.equals(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue(), parentEntity.getStatus())) {
|
||||
if (Objects.equals(SapStatusEnum.PUB_SAP.getValue(), parentEntity.getStatus())) {
|
||||
throw new NflgBusinessException(STATE.Error, "已发布数据不能操作");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.nflg.product.bomnew.constant.BomConstant;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.EBomSuperMaterialStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.MBomConstantEnum;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewMbomParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.dto.BomNewMBomChildDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
|
||||
|
|
@ -24,7 +24,6 @@ import com.nflg.product.bomnew.pojo.vo.BomNewMbomMiddleVO;
|
|||
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
||||
import com.nflg.product.bomnew.service.domain.MBom.IndexListTree;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -60,7 +59,7 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
|
|||
*/
|
||||
public Page<BomNewMbomMiddleVO> workListPage(BomNewMbomParentQuery query) {
|
||||
|
||||
query.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue());
|
||||
query.setStatus(SapStatusEnum.UNPUB_SAP.getValue());
|
||||
List<String> facCode= SpringUtil.getBean(UserRoleService.class).getUserOfFactory();
|
||||
String code= StrUtil.join(",",facCode);
|
||||
query.setFacCode(code);
|
||||
|
|
@ -119,7 +118,7 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
|
|||
|
||||
|
||||
public Page<BomNewMbomMiddleVO> formalListPage(BomNewMbomParentQuery query) {
|
||||
query.setStatus(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue());
|
||||
query.setStatus(SapStatusEnum.PUB_SAP.getValue());
|
||||
List<String> facCode= SpringUtil.getBean(UserRoleService.class).getUserOfFactory();
|
||||
String code= StrUtil.join(",",facCode);
|
||||
query.setFacCode(code);
|
||||
|
|
@ -200,6 +199,9 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
|
|||
BomNewMbomMiddleVO parentVO= getParentById(rowId);
|
||||
|
||||
VUtils.isTure(parentVO==null).throwMessage("选择顶层节点导入");
|
||||
VUtils.isTure(Objects.equals(parentVO.getStatus(), SapStatusEnum.PUB_RUNNING.getValue()))
|
||||
.throwMessage("正在导入中,请等待操作完成");
|
||||
|
||||
parentVO.setParentRowId(0l);
|
||||
parentVO.setBomRowId(parentVO.getRowId());
|
||||
parentVO.setBomExist(1);
|
||||
|
|
@ -274,11 +276,9 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
|
|||
result.setI_EMPNO(parentVO.getCreatedBy());
|
||||
String dateYMD= DateUtil.format(new Date(),"yyyyMMdd");
|
||||
|
||||
List<BomNewMbomMiddleVO> parentList=list.stream().filter(u -> u.getBomExist().intValue()>0).collect(Collectors.toList());
|
||||
List<BomNewMbomMiddleVO> parentList = list.stream().filter(u -> u.getBomExist() > 0).collect(Collectors.toList());
|
||||
|
||||
|
||||
for (BomNewMbomMiddleVO parent:
|
||||
parentList) {
|
||||
for (BomNewMbomMiddleVO parent : parentList) {
|
||||
List<BomNewMbomMiddleVO> childList=list.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
|
||||
if(CollectionUtil.isEmpty(childList)){
|
||||
continue;
|
||||
|
|
@ -300,36 +300,26 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
|
|||
}
|
||||
|
||||
}
|
||||
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result, null);
|
||||
|
||||
//上传成功更新状态
|
||||
// if(resultVO.getState().equals( STATE.Success.getState())){
|
||||
// BomNewMbomParentEntity parentEntity=new BomNewMbomParentEntity();
|
||||
// parentEntity.setRowId(parentVO.getRowId());
|
||||
// parentEntity.setStatus(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue());
|
||||
// parentEntity.setSysnSapUserName(SessionUtil.getUserName());
|
||||
// parentEntity.setSysnSapTime(LocalDateTimeUtil.now());
|
||||
// parentEntity.setModifyTime(LocalDateTimeUtil.now());
|
||||
// this.updateById(parentEntity);
|
||||
// }
|
||||
|
||||
boolean update = lambdaUpdate().eq(BomNewMbomParentEntity::getRowId, parentVO.getRowId())
|
||||
.set(BomNewMbomParentEntity::getSysnSapTime, LocalDateTime.now())
|
||||
.set(Objects.equals(resultVO.getState(), STATE.Success.getState())
|
||||
, BomNewMbomParentEntity::getStatus, MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue())
|
||||
.set(!Objects.equals(resultVO.getState(), STATE.Success.getState()) && result.getT1().size() == resultVO.getData().size()
|
||||
, BomNewMbomParentEntity::getStatus, MBomConstantEnum.MBomStatusEnum.PUB_ERROR_ALL.getValue())
|
||||
.set(!Objects.equals(resultVO.getState(), STATE.Success.getState()) && result.getT1().size() != resultVO.getData().size()
|
||||
, BomNewMbomParentEntity::getStatus, MBomConstantEnum.MBomStatusEnum.PUB_ERROR.getValue())
|
||||
.update();
|
||||
return update ? resultVO : ResultVO.error("更新数据失败");
|
||||
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
|
||||
List<OperationErrorMsgVO> liErrMsg = null;
|
||||
try {
|
||||
updateSapState(parentVO.getRowId(), SapStatusEnum.PUB_RUNNING);
|
||||
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result, null);
|
||||
if (CollUtil.isEmpty(liErrMsg)) {
|
||||
state = SapStatusEnum.PUB_SAP;
|
||||
} else if (result.getT1().size() != liErrMsg.size()) {
|
||||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
} finally {
|
||||
updateSapState(parentVO.getRowId(), state);
|
||||
}
|
||||
return ResultVO.success(liErrMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
lambdaUpdate().eq(BomNewMbomParentEntity::getRowId, rootBomRowId)
|
||||
.set(BomNewMbomParentEntity::getSysnSapTime, LocalDateTime.now())
|
||||
.set(BomNewMbomParentEntity::getStatus, sapState)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1103,6 +1103,8 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
BomNewPbomParentEntity root = this.getById(rootRowId);
|
||||
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
|
||||
VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点");
|
||||
VUtils.isTure(Objects.equals(root.getSapState(), SapStatusEnum.PUB_RUNNING.getValue()))
|
||||
.throwMessage("正在导入中,请等待操作完成");
|
||||
|
||||
ImportSapParamDTO sapDto = new ImportSapParamDTO();
|
||||
sapDto.setZID(RandomUtil.randomNumbers(5));
|
||||
|
|
@ -1112,17 +1114,27 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
List<T1DTO> t1s = new ArrayList<>();
|
||||
buildChildrenForSap(root, t1s);
|
||||
sapDto.setT1(t1s);
|
||||
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
|
||||
boolean update = lambdaUpdate().eq(BomNewPbomParentEntity::getRowId, rootRowId)
|
||||
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
|
||||
List<OperationErrorMsgVO> liErrMsg = null;
|
||||
try {
|
||||
updateSapState(rootRowId, SapStatusEnum.PUB_RUNNING);
|
||||
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
|
||||
if (CollUtil.isEmpty(liErrMsg)) {
|
||||
state = SapStatusEnum.PUB_SAP;
|
||||
} else if (sapDto.getT1().size() != liErrMsg.size()) {
|
||||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
} finally {
|
||||
updateSapState(rootRowId, state);
|
||||
}
|
||||
return ResultVO.success(liErrMsg);
|
||||
}
|
||||
|
||||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
lambdaUpdate().eq(BomNewPbomParentEntity::getRowId, rootBomRowId)
|
||||
.set(BomNewPbomParentEntity::getSapTime, LocalDateTime.now())
|
||||
.set(Objects.equals(resultVO.getState(), STATE.Success.getState())
|
||||
, BomNewPbomParentEntity::getSapState, MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue())
|
||||
.set(!Objects.equals(resultVO.getState(), STATE.Success.getState()) && t1s.size() == resultVO.getData().size()
|
||||
, BomNewPbomParentEntity::getSapState, MBomConstantEnum.MBomStatusEnum.PUB_ERROR_ALL.getValue())
|
||||
.set(!Objects.equals(resultVO.getState(), STATE.Success.getState()) && t1s.size() != resultVO.getData().size()
|
||||
, BomNewPbomParentEntity::getSapState, MBomConstantEnum.MBomStatusEnum.PUB_ERROR.getValue())
|
||||
.set(BomNewPbomParentEntity::getSapState, sapState.getValue())
|
||||
.update();
|
||||
return update ? resultVO : ResultVO.error("更新数据失败");
|
||||
}
|
||||
|
||||
private void buildChildrenForSap(BomNewPbomParentEntity parent, List<T1DTO> t1s) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.nflg.product.bomnew.util.BomUtil;
|
|||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
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.transaction.annotation.Transactional;
|
||||
|
|
@ -135,7 +134,7 @@ public class DQBomService {
|
|||
|
||||
private List<BomNewDQbomVO> buildParent(BomNewDQbomVO vo) {
|
||||
List<BomNewDQbomVO> parents = dQBomParentService.getVOById(vo.getParentRowId());
|
||||
parents.removeIf(c -> 0 == c.getLastVersionIs());
|
||||
//parents.removeIf(p -> vo.getStatus() == 2 && p.getStatus() != 2);
|
||||
if (parents.isEmpty()) {
|
||||
return CollUtil.toList(vo);
|
||||
} else {
|
||||
|
|
@ -390,9 +389,7 @@ public class DQBomService {
|
|||
BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId);
|
||||
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
|
||||
VUtils.isTure(root.getRootIs() == 0).throwMessage("请选择根节点");
|
||||
VUtils.isTure(Objects.equals(root.getSapState(), MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue()))
|
||||
.throwMessage("已导入过了,请勿重复操作");
|
||||
VUtils.isTure(Objects.equals(root.getSapState(), MBomConstantEnum.MBomStatusEnum.PUB_RUNNING.getValue()))
|
||||
VUtils.isTure(Objects.equals(root.getSapState(), SapStatusEnum.PUB_RUNNING.getValue()))
|
||||
.throwMessage("正在导入中,请等待操作完成");
|
||||
|
||||
List<BomNewDQbomVO> datas = getAll(rootBomRowId);
|
||||
|
|
@ -429,25 +426,26 @@ public class DQBomService {
|
|||
t1s.add(t1);
|
||||
});
|
||||
sapDto.setT1(t1s);
|
||||
Set<Long> bomRowIds = datas.stream().map(BomNewDQbomVO::getBomRowId).collect(Collectors.toSet());
|
||||
bomRowIds.add(rootBomRowId);
|
||||
updateSapState(bomRowIds, MBomConstantEnum.MBomStatusEnum.PUB_RUNNING);
|
||||
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
|
||||
MBomConstantEnum.MBomStatusEnum sapState;
|
||||
if (resultVO.getState().equals(STATE.Success.getState())) {
|
||||
sapState = MBomConstantEnum.MBomStatusEnum.PUB_SAP;
|
||||
} else if (t1s.size() == resultVO.getData().size()) {
|
||||
sapState = MBomConstantEnum.MBomStatusEnum.PUB_ERROR_ALL;
|
||||
} else {
|
||||
sapState = MBomConstantEnum.MBomStatusEnum.PUB_ERROR;
|
||||
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
|
||||
List<OperationErrorMsgVO> liErrMsg = null;
|
||||
try {
|
||||
updateSapState(rootBomRowId, SapStatusEnum.PUB_RUNNING);
|
||||
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
|
||||
log.debug("本次导入到sap数量共{}个,其中{}个有错误", sapDto.getT1().size(), liErrMsg.size());
|
||||
if (CollUtil.isEmpty(liErrMsg)) {
|
||||
state = SapStatusEnum.PUB_SAP;
|
||||
} else if (sapDto.getT1().size() != liErrMsg.size()) {
|
||||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
} finally {
|
||||
updateSapState(rootBomRowId, state);
|
||||
}
|
||||
boolean update = updateSapState(bomRowIds, sapState);
|
||||
return update ? resultVO : ResultVO.error(STATE.Error, "更新失败");
|
||||
return ResultVO.success(liErrMsg);
|
||||
}
|
||||
|
||||
private boolean updateSapState(Set<Long> bomRowIds, MBomConstantEnum.MBomStatusEnum sapState) {
|
||||
return dQBomParentService.lambdaUpdate()
|
||||
.in(BomNewDQbomParentEntity::getRowId, bomRowIds)
|
||||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
dQBomParentService.lambdaUpdate()
|
||||
.in(BomNewDQbomParentEntity::getRowId, rootBomRowId)
|
||||
.set(BomNewDQbomParentEntity::getSapTime, LocalDateTime.now())
|
||||
.set(BomNewDQbomParentEntity::getSapState, sapState.getValue())
|
||||
.update();
|
||||
|
|
@ -514,7 +512,6 @@ public class DQBomService {
|
|||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
bomNewPbomParentService.getBaseMapper().updatePBomMaterialUse();
|
||||
importToSAP(root.getRowId());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import cn.hutool.core.lang.TypeReference;
|
|||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -19,6 +18,7 @@ import com.nflg.product.base.core.conmon.util.SessionUtil;
|
|||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.BomConstant;
|
||||
import com.nflg.product.bomnew.constant.OptionalBomConstant;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.OptionalMbomMaterialMapper;
|
||||
import com.nflg.product.bomnew.pojo.dto.OptionalMbomMaterialAddDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
|
||||
|
|
@ -37,6 +37,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -161,26 +162,34 @@ public class OptionalMbomMaterialService extends ServiceImpl<OptionalMbomMateria
|
|||
|
||||
}
|
||||
|
||||
log.info(JSON.toJSONString(result));
|
||||
//log.info(JSON.toJSONString(result));
|
||||
|
||||
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
|
||||
List<OperationErrorMsgVO> liErrMsg = null;
|
||||
try {
|
||||
updateSapState(entity.getRootRowId(), SapStatusEnum.PUB_RUNNING);
|
||||
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result, null);
|
||||
if (CollUtil.isEmpty(liErrMsg)) {
|
||||
state = SapStatusEnum.PUB_SAP;
|
||||
} else if (result.getT1().size() != liErrMsg.size()) {
|
||||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
} finally {
|
||||
updateSapState(entity.getRootRowId(), state);
|
||||
}
|
||||
return ResultVO.success(liErrMsg);
|
||||
}
|
||||
|
||||
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result, null);
|
||||
|
||||
if(resultVO.getState().equals( STATE.Success.getState())){
|
||||
OptionalEbomConfigEntity configEntity=new OptionalEbomConfigEntity();
|
||||
configEntity.setRowId(entity.getRootRowId());
|
||||
configEntity.setUploadSapStatus(OptionalBomConstant.UploadSapStatusEnum.SAP_1.getValue());
|
||||
configEntity.setUpdatedTime(DateUtil.now());
|
||||
configEntity.setUploadSapCode(SessionUtil.getUserCode());
|
||||
configEntity.setUploadSapUser(SessionUtil.getUserName());
|
||||
SpringUtil.getBean( OptionalEbomConfigService.class).updateById(configEntity);
|
||||
|
||||
}
|
||||
return resultVO;
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
SpringUtil.getBean(OptionalEbomConfigService.class)
|
||||
.lambdaUpdate()
|
||||
.eq(OptionalEbomConfigEntity::getRowId, rootBomRowId)
|
||||
.set(OptionalEbomConfigEntity::getUpdatedTime, LocalDateTime.now())
|
||||
.set(OptionalEbomConfigEntity::getUploadSapStatus, sapState.getValue())
|
||||
.set(OptionalEbomConfigEntity::getUploadSapCode, SessionUtil.getUserCode())
|
||||
.set(OptionalEbomConfigEntity::getUploadSapUser, SessionUtil.getRealName())
|
||||
.update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ 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.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.BomConstant;
|
||||
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;
|
||||
|
|
@ -14,6 +15,7 @@ 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.OperationErrorMsgVO;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
|
|
@ -22,8 +24,11 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
|
|
@ -137,80 +142,59 @@ public class SapOpUtilService {
|
|||
}
|
||||
|
||||
|
||||
public ResultVO<List<OperationErrorMsgVO>> importToSapV2(ImportSapParamDTO impartSapParamDTO, List<T1DTO> backList) {
|
||||
if (CollUtil.isEmpty(impartSapParamDTO.getT1())) {
|
||||
return ResultVO.error("同步SAP 参数错误");
|
||||
}
|
||||
public List<OperationErrorMsgVO> importToSapV2(ImportSapParamDTO impartSapParamDTO, List<T1DTO> backList) {
|
||||
VUtils.isTure(CollUtil.isEmpty(impartSapParamDTO.getT1())).throwMessage("没有需要同步的数据");
|
||||
SapReqParams params = new SapReqParams();
|
||||
// 接口名
|
||||
params.setFunName("ZRFC_PP_003");
|
||||
|
||||
//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>>() {
|
||||
}, 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());
|
||||
}
|
||||
, 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 (CollUtil.isNotEmpty(list)) {
|
||||
//StringBuffer errBuf=new StringBuffer();
|
||||
List<OperationErrorMsgVO> 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() + ",");
|
||||
liError.add(OperationErrorMsgVO.create(
|
||||
StrUtil.format("{}项{}", item.getPOSTP(), StringUtils.stripStart(item.getIDNRK(), "0"))
|
||||
, 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);
|
||||
return ResultVO.error(STATE.BusinessError, "导入到SAP出错", liError);
|
||||
}
|
||||
}else{
|
||||
throw new Exception("获取sap返回数据转换异常");
|
||||
}
|
||||
} catch (ErrorMsgException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
return ResultVO.error(STATE.Error, e.getMessage());
|
||||
log.info("导入到SAP--参数:" + JSON.toJSONString(params));
|
||||
SapResult sapResult = sapService.doSapFun(params);
|
||||
if (!sapResult.isSuccess()) {
|
||||
throw new NflgBusinessException(STATE.ServiceConnectRefused, "接口连接失败," + sapResult.getMsg());
|
||||
}
|
||||
return ResultVO.success();
|
||||
Map<String, List<Map<String, Object>>> outTablesMap = sapResult.getOutTablesMap();
|
||||
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
|
||||
List<Map<String, Object>> tOut = outTablesMap.get("T1");
|
||||
List<T1DTO> list = null;
|
||||
if (!CollectionUtils.isEmpty(tOut)) {
|
||||
list = Convert.convert(new TypeReference<List<T1DTO>>() {
|
||||
}, tOut);
|
||||
}
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
throw new NflgBusinessException(STATE.BusinessError, "获取sap返回数据转换异常");
|
||||
}
|
||||
if (!Objects.isNull(backList)) {
|
||||
backList.addAll(list);
|
||||
}
|
||||
//"FLAG": "1" -- 0 失败;1 成功
|
||||
return list.stream()
|
||||
.filter(f -> f.getFLAG().equals("0"))
|
||||
.map(item -> OperationErrorMsgVO.create(buildErrCol1(item), item.getSTATUS()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String buildErrCol1(T1DTO item) {
|
||||
if (StrUtil.equals(item.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY)) {
|
||||
return StrUtil.format("{}的子级T项:{}", strip0(item.getMATNR()), item.getPOTX1());
|
||||
} else {
|
||||
return StrUtil.format("{}的子级{}项:{}", strip0(item.getMATNR()), item.getPOSTP(), strip0(item.getIDNRK()));
|
||||
}
|
||||
}
|
||||
|
||||
private String strip0(String str) {
|
||||
return StringUtils.stripStart(str, "0");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package com.nflg.product.bomnew.service.domain.PBom;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.MBomConstantEnum;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||
|
|
@ -80,7 +78,7 @@ public class ConvertToMBomBase {
|
|||
BomNewMbomParentEntity oldParent = SpringUtil.getBean(BomNewMbomParentService.class).lambdaQuery().eq(BomNewMbomParentEntity::getMaterialNo, parent.getMaterialNo()).eq(BomNewMbomParentEntity::getFacCode, facCode)
|
||||
.last(" order by current_version desc limit 1").one();
|
||||
if (Objects.nonNull(oldParent)) {
|
||||
if (MBomConstantEnum.MBomStatusEnum.PUB_SAP.equalsValue(oldParent.getStatus())) {
|
||||
if (SapStatusEnum.PUB_SAP.equalsValue(oldParent.getStatus())) {
|
||||
//将数据迁移到历史表
|
||||
SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().insertMBomIntoHistory(oldParent.getRowId());
|
||||
|
||||
|
|
@ -105,7 +103,7 @@ public class ConvertToMBomBase {
|
|||
mBomParent.setModifyTime(LocalDateTime.now());
|
||||
mBomParent.setSourceRowId(parent.getRowId());
|
||||
mBomParent.setLastVersionIs(1);
|
||||
mBomParent.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue());
|
||||
mBomParent.setStatus(SapStatusEnum.UNPUB_SAP.getValue());
|
||||
return mBomParent;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,12 @@
|
|||
<if test="query.endDate != null and query.endDate!=''">
|
||||
AND p.created_time <![CDATA[ <= ]]> #{query.endDate}
|
||||
</if>
|
||||
ORDER BY user_root_is DESC, p.row_id DESC
|
||||
<if test="query.status == 1">
|
||||
ORDER BY user_root_is DESC, p.row_id DESC
|
||||
</if>
|
||||
<if test="query.status == 2">
|
||||
ORDER BY convert_to_pbom_time DESC
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!--获取子级数据-->
|
||||
|
|
@ -65,7 +70,6 @@
|
|||
if(c.exception_status = 1, ifnull(p.exception_status, 1), c.exception_status) exception_status,
|
||||
ifnull(p.exception_tag, c.exception_tag) exception_tag,
|
||||
ifnull(p.bom_exist, 0) bom_exist,
|
||||
p2.sap_state,
|
||||
ifnull(p.current_version, if(c.status = 1, 'A00', p2.current_version)) current_version,
|
||||
c.*
|
||||
FROM t_bom_new_dqbom_child c
|
||||
|
|
@ -130,11 +134,9 @@
|
|||
</select>
|
||||
|
||||
<select id="getVOById" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
|
||||
SELECT a.row_id bomRowId
|
||||
, b.order_number
|
||||
, a.*
|
||||
FROM t_bom_new_dqbom_parent a
|
||||
LEFT JOIN t_bom_new_dqbom_child b ON a.material_no = b.material_no
|
||||
WHERE a.row_id = #{parentRowId}
|
||||
SELECT p.row_id bomRowId, c.parent_row_id, c.order_number, p.*
|
||||
FROM t_bom_new_dqbom_parent p
|
||||
LEFT JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no
|
||||
WHERE p.row_id = #{parentRowId}
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue