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

This commit is contained in:
曹鹏飞 2024-04-30 17:53:55 +08:00
parent be9702a415
commit 5a9948635e
14 changed files with 211 additions and 220 deletions

View File

@ -42,14 +42,14 @@ public class TestApi {
List<T1DTO> t1s = new ArrayList<>(); List<T1DTO> t1s = new ArrayList<>();
T1DTO t1 = new T1DTO(); T1DTO t1 = new T1DTO();
t1.setID(RandomUtil.randomNumbers(5)); t1.setID(RandomUtil.randomNumbers(5));
t1.setMATNR("2100677191"); t1.setMATNR("2200006651");
t1.setIDNRK("1100002498"); t1.setIDNRK("2100675047");
t1.setMEINS("PC"); t1.setMEINS("PC");
t1.setMENGE("3.00"); t1.setMENGE("1.00");
t1.setPOSTP("L"); t1.setPOSTP("L");
t1.setDATUM(dateYMD); t1.setDATUM(dateYMD);
t1s.add(t1); t1s.add(t1);
sapDto.setT1(t1s); sapDto.setT1(t1s);
return sapOpUtilService.importToSapV2(sapDto, null); return ResultVO.success(sapOpUtilService.importToSapV2(sapDto, null));
} }
} }

View File

@ -5,22 +5,6 @@ import lombok.Getter;
public class MBomConstantEnum { public class MBomConstantEnum {
@AllArgsConstructor
@Getter
public enum MBomStatusEnum implements ValueEnum<Integer> {
//1待发布sap3=已发布
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 @AllArgsConstructor
@Getter @Getter
public enum MBomSuperMaterialStatusEnum implements ValueEnum<Integer> { public enum MBomSuperMaterialStatusEnum implements ValueEnum<Integer> {

View File

@ -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;
}
} }

View File

@ -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;
}

View File

@ -1,9 +1,9 @@
package com.nflg.product.bomnew.pojo.vo; package com.nflg.product.bomnew.pojo.vo;
import cn.hutool.core.util.StrUtil; 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.FactoryCodeEnum;
import com.nflg.product.bomnew.constant.MBomConstantEnum; import com.nflg.product.bomnew.constant.MBomConstantEnum;
import com.nflg.product.bomnew.constant.SapStatusEnum;
import com.nflg.product.bomnew.util.EnumUtils; import com.nflg.product.bomnew.util.EnumUtils;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -273,8 +273,8 @@ public class BomNewMbomMiddleVO extends BaseMaterialVO implements Serializable {
public String getStatusName(){ public String getStatusName(){
if(materialBackStatus==null || materialBackStatus.equals(MBomConstantEnum.MaterialBackStatusEnum.APPLY_0.getValue())){ if(materialBackStatus==null || materialBackStatus.equals(MBomConstantEnum.MaterialBackStatusEnum.APPLY_0.getValue())){
if(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue().equals(status)){ if (SapStatusEnum.PUB_SAP.getValue().equals(status)) {
return MBomConstantEnum.MBomStatusEnum.PUB_SAP.getDescription(); return SapStatusEnum.PUB_SAP.getDescription();
} }
return MBomConstantEnum.MaterialBackStatusEnum.APPLY_0.getDescription(); return MBomConstantEnum.MaterialBackStatusEnum.APPLY_0.getDescription();

View File

@ -926,10 +926,12 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
} }
} }
public ResultVO<List<OperationErrorMsgVO>> importToSAP(Long bomRowId) { public ResultVO<List<OperationErrorMsgVO>> importToSAP(Long rootBomRowId) {
BomNewEbomParentEntity root = this.getById(bomRowId); BomNewEbomParentEntity root = this.getById(rootBomRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在"); VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点"); VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点");
VUtils.isTure(Objects.equals(root.getSapState(), SapStatusEnum.PUB_RUNNING.getValue()))
.throwMessage("正在导入中,请等待操作完成");
ImportSapParamDTO sapDto = new ImportSapParamDTO(); ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5)); sapDto.setZID(RandomUtil.randomNumbers(5));
@ -939,17 +941,27 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
List<T1DTO> t1s = new ArrayList<>(); List<T1DTO> t1s = new ArrayList<>();
buildChildrenForSap(root, t1s); buildChildrenForSap(root, t1s);
sapDto.setT1(t1s); sapDto.setT1(t1s);
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null); SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
boolean update = lambdaUpdate().eq(BomNewEbomParentEntity::getRowId, bomRowId) 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(BomNewEbomParentEntity::getSapTime, LocalDateTime.now())
.set(Objects.equals(resultVO.getState(), STATE.Success.getState()) .set(BomNewEbomParentEntity::getSapState, sapState)
, 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())
.update(); .update();
return update ? resultVO : ResultVO.error("更新数据失败");
} }
private void buildChildrenForSap(BomNewEbomParentEntity parent, List<T1DTO> t1s) { private void buildChildrenForSap(BomNewEbomParentEntity parent, List<T1DTO> t1s) {

View File

@ -1,10 +1,8 @@
package com.nflg.product.bomnew.service; package com.nflg.product.bomnew.service;
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.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 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.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.EBomConstant; import com.nflg.product.bomnew.constant.EBomConstant;
import com.nflg.product.bomnew.constant.MBomConstantEnum; 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.mapper.master.BomNewMbomDetailMapper;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity; import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity; 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 com.nflg.product.bomnew.pojo.vo.BomNewMbomMiddleVO;
import nflg.product.common.constant.STATE; import nflg.product.common.constant.STATE;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -92,7 +89,7 @@ public class BomNewMbomDetailService extends ServiceImpl<BomNewMbomDetailMapper,
throw new NflgBusinessException(STATE.Error, "顶层数据不存在"); 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, "已发布数据不能操作"); throw new NflgBusinessException(STATE.Error, "已发布数据不能操作");
} }

View File

@ -13,7 +13,7 @@ import com.google.common.collect.ImmutableList;
import com.nflg.product.bomnew.constant.BomConstant; import com.nflg.product.bomnew.constant.BomConstant;
import com.nflg.product.bomnew.constant.EBomConstant; import com.nflg.product.bomnew.constant.EBomConstant;
import com.nflg.product.bomnew.constant.EBomSuperMaterialStatusEnum; 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.mapper.master.BomNewMbomParentMapper;
import com.nflg.product.bomnew.pojo.dto.BomNewMBomChildDTO; import com.nflg.product.bomnew.pojo.dto.BomNewMBomChildDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO; 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.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.service.domain.MBom.IndexListTree; import com.nflg.product.bomnew.service.domain.MBom.IndexListTree;
import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VUtils;
import nflg.product.common.constant.STATE;
import nflg.product.common.vo.ResultVO; import nflg.product.common.vo.ResultVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -60,7 +59,7 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
*/ */
public Page<BomNewMbomMiddleVO> workListPage(BomNewMbomParentQuery query) { 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(); List<String> facCode= SpringUtil.getBean(UserRoleService.class).getUserOfFactory();
String code= StrUtil.join(",",facCode); String code= StrUtil.join(",",facCode);
query.setFacCode(code); query.setFacCode(code);
@ -119,7 +118,7 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
public Page<BomNewMbomMiddleVO> formalListPage(BomNewMbomParentQuery query) { 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(); List<String> facCode= SpringUtil.getBean(UserRoleService.class).getUserOfFactory();
String code= StrUtil.join(",",facCode); String code= StrUtil.join(",",facCode);
query.setFacCode(code); query.setFacCode(code);
@ -200,6 +199,9 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
BomNewMbomMiddleVO parentVO= getParentById(rowId); BomNewMbomMiddleVO parentVO= getParentById(rowId);
VUtils.isTure(parentVO==null).throwMessage("选择顶层节点导入"); VUtils.isTure(parentVO==null).throwMessage("选择顶层节点导入");
VUtils.isTure(Objects.equals(parentVO.getStatus(), SapStatusEnum.PUB_RUNNING.getValue()))
.throwMessage("正在导入中,请等待操作完成");
parentVO.setParentRowId(0l); parentVO.setParentRowId(0l);
parentVO.setBomRowId(parentVO.getRowId()); parentVO.setBomRowId(parentVO.getRowId());
parentVO.setBomExist(1); parentVO.setBomExist(1);
@ -274,11 +276,9 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
result.setI_EMPNO(parentVO.getCreatedBy()); result.setI_EMPNO(parentVO.getCreatedBy());
String dateYMD= DateUtil.format(new Date(),"yyyyMMdd"); 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()); List<BomNewMbomMiddleVO> childList=list.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(childList)){ if(CollectionUtil.isEmpty(childList)){
continue; continue;
@ -300,36 +300,26 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
} }
} }
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result, null); SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
List<OperationErrorMsgVO> liErrMsg = null;
//上传成功更新状态 try {
// if(resultVO.getState().equals( STATE.Success.getState())){ updateSapState(parentVO.getRowId(), SapStatusEnum.PUB_RUNNING);
// BomNewMbomParentEntity parentEntity=new BomNewMbomParentEntity(); liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result, null);
// parentEntity.setRowId(parentVO.getRowId()); if (CollUtil.isEmpty(liErrMsg)) {
// parentEntity.setStatus(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue()); state = SapStatusEnum.PUB_SAP;
// parentEntity.setSysnSapUserName(SessionUtil.getUserName()); } else if (result.getT1().size() != liErrMsg.size()) {
// parentEntity.setSysnSapTime(LocalDateTimeUtil.now()); state = SapStatusEnum.PUB_ERROR;
// parentEntity.setModifyTime(LocalDateTimeUtil.now()); }
// this.updateById(parentEntity); } finally {
// } updateSapState(parentVO.getRowId(), state);
}
boolean update = lambdaUpdate().eq(BomNewMbomParentEntity::getRowId, parentVO.getRowId()) return ResultVO.success(liErrMsg);
.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("更新数据失败");
} }
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
lambdaUpdate().eq(BomNewMbomParentEntity::getRowId, rootBomRowId)
.set(BomNewMbomParentEntity::getSysnSapTime, LocalDateTime.now())
.set(BomNewMbomParentEntity::getStatus, sapState)
.update();
}
} }

View File

@ -1103,6 +1103,8 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
BomNewPbomParentEntity root = this.getById(rootRowId); BomNewPbomParentEntity root = this.getById(rootRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在"); VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点"); VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点");
VUtils.isTure(Objects.equals(root.getSapState(), SapStatusEnum.PUB_RUNNING.getValue()))
.throwMessage("正在导入中,请等待操作完成");
ImportSapParamDTO sapDto = new ImportSapParamDTO(); ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5)); sapDto.setZID(RandomUtil.randomNumbers(5));
@ -1112,17 +1114,27 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
List<T1DTO> t1s = new ArrayList<>(); List<T1DTO> t1s = new ArrayList<>();
buildChildrenForSap(root, t1s); buildChildrenForSap(root, t1s);
sapDto.setT1(t1s); sapDto.setT1(t1s);
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null); SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
boolean update = lambdaUpdate().eq(BomNewPbomParentEntity::getRowId, rootRowId) 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(BomNewPbomParentEntity::getSapTime, LocalDateTime.now())
.set(Objects.equals(resultVO.getState(), STATE.Success.getState()) .set(BomNewPbomParentEntity::getSapState, sapState.getValue())
, 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())
.update(); .update();
return update ? resultVO : ResultVO.error("更新数据失败");
} }
private void buildChildrenForSap(BomNewPbomParentEntity parent, List<T1DTO> t1s) { private void buildChildrenForSap(BomNewPbomParentEntity parent, List<T1DTO> t1s) {

View File

@ -27,7 +27,6 @@ import com.nflg.product.bomnew.util.BomUtil;
import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VUtils;
import com.nflg.product.bomnew.util.VersionUtil; import com.nflg.product.bomnew.util.VersionUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import nflg.product.common.vo.ResultVO; import nflg.product.common.vo.ResultVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -135,7 +134,7 @@ public class DQBomService {
private List<BomNewDQbomVO> buildParent(BomNewDQbomVO vo) { private List<BomNewDQbomVO> buildParent(BomNewDQbomVO vo) {
List<BomNewDQbomVO> parents = dQBomParentService.getVOById(vo.getParentRowId()); 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()) { if (parents.isEmpty()) {
return CollUtil.toList(vo); return CollUtil.toList(vo);
} else { } else {
@ -390,9 +389,7 @@ public class DQBomService {
BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId); BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在"); VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
VUtils.isTure(root.getRootIs() == 0).throwMessage("请选择根节点"); VUtils.isTure(root.getRootIs() == 0).throwMessage("请选择根节点");
VUtils.isTure(Objects.equals(root.getSapState(), MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue())) VUtils.isTure(Objects.equals(root.getSapState(), SapStatusEnum.PUB_RUNNING.getValue()))
.throwMessage("已导入过了,请勿重复操作");
VUtils.isTure(Objects.equals(root.getSapState(), MBomConstantEnum.MBomStatusEnum.PUB_RUNNING.getValue()))
.throwMessage("正在导入中,请等待操作完成"); .throwMessage("正在导入中,请等待操作完成");
List<BomNewDQbomVO> datas = getAll(rootBomRowId); List<BomNewDQbomVO> datas = getAll(rootBomRowId);
@ -429,25 +426,26 @@ public class DQBomService {
t1s.add(t1); t1s.add(t1);
}); });
sapDto.setT1(t1s); sapDto.setT1(t1s);
Set<Long> bomRowIds = datas.stream().map(BomNewDQbomVO::getBomRowId).collect(Collectors.toSet()); SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
bomRowIds.add(rootBomRowId); List<OperationErrorMsgVO> liErrMsg = null;
updateSapState(bomRowIds, MBomConstantEnum.MBomStatusEnum.PUB_RUNNING); try {
ResultVO<List<OperationErrorMsgVO>> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null); updateSapState(rootBomRowId, SapStatusEnum.PUB_RUNNING);
MBomConstantEnum.MBomStatusEnum sapState; liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
if (resultVO.getState().equals(STATE.Success.getState())) { log.debug("本次导入到sap数量共{}个,其中{}个有错误", sapDto.getT1().size(), liErrMsg.size());
sapState = MBomConstantEnum.MBomStatusEnum.PUB_SAP; if (CollUtil.isEmpty(liErrMsg)) {
} else if (t1s.size() == resultVO.getData().size()) { state = SapStatusEnum.PUB_SAP;
sapState = MBomConstantEnum.MBomStatusEnum.PUB_ERROR_ALL; } else if (sapDto.getT1().size() != liErrMsg.size()) {
} else { state = SapStatusEnum.PUB_ERROR;
sapState = MBomConstantEnum.MBomStatusEnum.PUB_ERROR; }
} finally {
updateSapState(rootBomRowId, state);
} }
boolean update = updateSapState(bomRowIds, sapState); return ResultVO.success(liErrMsg);
return update ? resultVO : ResultVO.error(STATE.Error, "更新失败");
} }
private boolean updateSapState(Set<Long> bomRowIds, MBomConstantEnum.MBomStatusEnum sapState) { private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
return dQBomParentService.lambdaUpdate() dQBomParentService.lambdaUpdate()
.in(BomNewDQbomParentEntity::getRowId, bomRowIds) .in(BomNewDQbomParentEntity::getRowId, rootBomRowId)
.set(BomNewDQbomParentEntity::getSapTime, LocalDateTime.now()) .set(BomNewDQbomParentEntity::getSapTime, LocalDateTime.now())
.set(BomNewDQbomParentEntity::getSapState, sapState.getValue()) .set(BomNewDQbomParentEntity::getSapState, sapState.getValue())
.update(); .update();
@ -514,7 +512,6 @@ public class DQBomService {
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
bomNewPbomParentService.getBaseMapper().updatePBomMaterialUse(); bomNewPbomParentService.getBaseMapper().updatePBomMaterialUse();
importToSAP(root.getRowId());
}); });
} }

View File

@ -9,7 +9,6 @@ import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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;
@ -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.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.BomConstant; import com.nflg.product.bomnew.constant.BomConstant;
import com.nflg.product.bomnew.constant.OptionalBomConstant; 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.mapper.master.OptionalMbomMaterialMapper;
import com.nflg.product.bomnew.pojo.dto.OptionalMbomMaterialAddDTO; 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.ImportSapParamDTO;
@ -37,6 +37,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; 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); private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
SpringUtil.getBean(OptionalEbomConfigService.class)
if(resultVO.getState().equals( STATE.Success.getState())){ .lambdaUpdate()
OptionalEbomConfigEntity configEntity=new OptionalEbomConfigEntity(); .eq(OptionalEbomConfigEntity::getRowId, rootBomRowId)
configEntity.setRowId(entity.getRootRowId()); .set(OptionalEbomConfigEntity::getUpdatedTime, LocalDateTime.now())
configEntity.setUploadSapStatus(OptionalBomConstant.UploadSapStatusEnum.SAP_1.getValue()); .set(OptionalEbomConfigEntity::getUploadSapStatus, sapState.getValue())
configEntity.setUpdatedTime(DateUtil.now()); .set(OptionalEbomConfigEntity::getUploadSapCode, SessionUtil.getUserCode())
configEntity.setUploadSapCode(SessionUtil.getUserCode()); .set(OptionalEbomConfigEntity::getUploadSapUser, SessionUtil.getRealName())
configEntity.setUploadSapUser(SessionUtil.getUserName()); .update();
SpringUtil.getBean( OptionalEbomConfigService.class).updateById(configEntity); }
}
return resultVO;
}

View File

@ -6,7 +6,8 @@ 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.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.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;
@ -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.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.OperationErrorMsgVO; import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.util.VUtils;
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;
@ -22,8 +24,11 @@ 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.*; import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
@ -137,80 +142,59 @@ public class SapOpUtilService {
} }
public ResultVO<List<OperationErrorMsgVO>> importToSapV2(ImportSapParamDTO impartSapParamDTO, List<T1DTO> backList) { public List<OperationErrorMsgVO> importToSapV2(ImportSapParamDTO impartSapParamDTO, List<T1DTO> backList) {
if (CollUtil.isEmpty(impartSapParamDTO.getT1())) { VUtils.isTure(CollUtil.isEmpty(impartSapParamDTO.getT1())).throwMessage("没有需要同步的数据");
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<>(); 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);
params.setInputParams(parentMap); params.setInputParams(parentMap);
Map<String, List<Map<String, String>>> inputTables = new HashMap<>(); Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
List<Map<String, String>> childMapList = Convert.convert(new TypeReference<List<Map<String, String>>>() { List<Map<String, String>> childMapList = Convert.convert(new TypeReference<List<Map<String, String>>>() {
}, impartSapParamDTO.getT1()); }
, impartSapParamDTO.getT1());
inputTables.put("T1", childMapList); inputTables.put("T1", childMapList);
params.setInputTables(inputTables); params.setInputTables(inputTables);
try { log.info("导入到SAP--参数:" + JSON.toJSONString(params));
log.info("导入到SAP--参数:" + JSON.toJSONString(params)); SapResult sapResult = sapService.doSapFun(params);
SapResult sapResult = sapService.doSapFun(params); if (!sapResult.isSuccess()) {
throw new NflgBusinessException(STATE.ServiceConnectRefused, "接口连接失败," + sapResult.getMsg());
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());
} }
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");
} }
} }

View File

@ -1,13 +1,11 @@
package com.nflg.product.bomnew.service.domain.PBom; package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.nflg.product.base.core.conmon.util.SessionUtil; import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.EBomConstant; import com.nflg.product.bomnew.constant.SapStatusEnum;
import com.nflg.product.bomnew.constant.MBomConstantEnum;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity; import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity; import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity; 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) 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(); .last(" order by current_version desc limit 1").one();
if (Objects.nonNull(oldParent)) { 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()); SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().insertMBomIntoHistory(oldParent.getRowId());
@ -105,7 +103,7 @@ public class ConvertToMBomBase {
mBomParent.setModifyTime(LocalDateTime.now()); mBomParent.setModifyTime(LocalDateTime.now());
mBomParent.setSourceRowId(parent.getRowId()); mBomParent.setSourceRowId(parent.getRowId());
mBomParent.setLastVersionIs(1); mBomParent.setLastVersionIs(1);
mBomParent.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue()); mBomParent.setStatus(SapStatusEnum.UNPUB_SAP.getValue());
return mBomParent; return mBomParent;
} }

View File

@ -55,7 +55,12 @@
<if test="query.endDate != null and query.endDate!=''"> <if test="query.endDate != null and query.endDate!=''">
AND p.created_time <![CDATA[ <= ]]> #{query.endDate} AND p.created_time <![CDATA[ <= ]]> #{query.endDate}
</if> </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> </select>
<!--获取子级数据--> <!--获取子级数据-->
@ -65,7 +70,6 @@
if(c.exception_status = 1, ifnull(p.exception_status, 1), c.exception_status) exception_status, 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.exception_tag, c.exception_tag) exception_tag,
ifnull(p.bom_exist, 0) bom_exist, ifnull(p.bom_exist, 0) bom_exist,
p2.sap_state,
ifnull(p.current_version, if(c.status = 1, 'A00', p2.current_version)) current_version, ifnull(p.current_version, if(c.status = 1, 'A00', p2.current_version)) current_version,
c.* c.*
FROM t_bom_new_dqbom_child c FROM t_bom_new_dqbom_child c
@ -130,11 +134,9 @@
</select> </select>
<select id="getVOById" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO"> <select id="getVOById" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
SELECT a.row_id bomRowId SELECT p.row_id bomRowId, c.parent_row_id, c.order_number, p.*
, b.order_number FROM t_bom_new_dqbom_parent p
, a.* LEFT JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no
FROM t_bom_new_dqbom_parent a WHERE p.row_id = #{parentRowId}
LEFT JOIN t_bom_new_dqbom_child b ON a.material_no = b.material_no
WHERE a.row_id = #{parentRowId}
</select> </select>
</mapper> </mapper>