feat: pbom增加导出到sap接口

This commit is contained in:
曹鹏飞 2024-04-29 10:06:22 +08:00
parent 10e545f6d1
commit 119e0d5faa
3 changed files with 91 additions and 27 deletions

View File

@ -14,10 +14,7 @@ import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewTechnologyPackageTypeEntity;
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.pojo.vo.BomCopyCheckResultVO;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomWorkExcelVO;
import com.nflg.product.bomnew.pojo.vo.*;
import com.nflg.product.bomnew.service.*;
import com.nflg.product.bomnew.util.EecExcelUtil;
import com.nflg.product.bomnew.util.VUtils;
@ -29,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -330,27 +328,15 @@ public class PBomApi extends BaseApi {
return result;
}
/**
* 导入到SAP
* @param rootBomRowIds 顶级bom的rowId
* @return
*/
@PostMapping("importToSAP")
@ApiOperation("导入到SAP")
public ResultVO<List<OperationErrorMsgVO>> importToSAP(@Valid @RequestBody @NotEmpty List<Long> rootBomRowIds) {
VUtils.isTure(rootBomRowIds.size() > 1).throwMessage("每次只能导入1条");
return bomNewPbomParentService.importToSAP(rootBomRowIds.get(0));
}
}

View File

@ -341,6 +341,20 @@ public class BomNewPbomParentEntity implements Serializable {
@ApiModelProperty(value = "修改时间")
private LocalDateTime modifyTime;
/**
* 导入SAP状态1-未导入3-已导入
*/
@TableField(value = "sap_state")
@ApiModelProperty(value = "导入SAP状态1-未导入3-已导入")
private Integer sapState;
/**
* 导入SAP时间
*/
@TableField(value = "sap_time")
@ApiModelProperty(value = "导入SAP时间")
private LocalDateTime sapTime;
private static final long serialVersionUID = -31999878274445137L;
}

View File

@ -3,7 +3,9 @@ package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@ -20,6 +22,7 @@ import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
import com.nflg.product.bomnew.pojo.dto.*;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
import com.nflg.product.bomnew.pojo.entity.*;
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
import com.nflg.product.bomnew.pojo.vo.*;
@ -40,6 +43,7 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
@ -1024,6 +1028,10 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
}
SpringUtil.getBean(BomNewPbomParentFormalService.class).copyPbomFormal(bomRowId);
CompletableFuture.runAsync(() -> {
importToSAP(bomRowId);
});
} catch (Exception ex) {
throw new NflgBusinessException(STATE.BusinessError, "发布Pbom失败" + ex.getMessage());
}
@ -1090,4 +1098,60 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
private void resetBomExist(Long rowId) {
this.getBaseMapper().resetBomExist(rowId);
}
public ResultVO<List<OperationErrorMsgVO>> importToSAP(Long rootRowId) {
BomNewPbomParentEntity root = this.getById(rootRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
VUtils.isTure(root.getRootIs() != 1).throwMessage("请选择根节点");
ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5));
sapDto.setI_WERKS("1");
sapDto.setI_STLAN("1");
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)
.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())
.update();
return update ? resultVO : ResultVO.error("更新数据失败");
}
private void buildChildrenForSap(BomNewPbomParentEntity parent, List<T1DTO> t1s) {
List<BomNewPbomChildEntity> children = pbomChildService.lambdaQuery()
.eq(BomNewPbomChildEntity::getParentRowId, parent.getRowId())
.list();
if (CollUtil.isNotEmpty(children)) {
String dateYMD = DateUtil.format(new Date(), "yyyyMMdd");
children.forEach(c -> {
T1DTO t1 = new T1DTO();
t1.setID(RandomUtil.randomNumbers(5));
t1.setMATNR(parent.getMaterialNo());
t1.setIDNRK(c.getMaterialNo());
t1.setMEINS(c.getMaterialUnit());
t1.setMENGE(c.getNum().toString());
t1.setPOSTP(c.getProjectType());
if (BomConstant.PROJECT_TYPE_TEMPORARY.equals(c.getProjectType())) {
t1.setIDNRK("");
t1.setPOTX1(c.getMaterialName());
}
t1.setDATUM(dateYMD);
t1s.add(t1);
BomNewPbomParentEntity cp = lambdaQuery()
.eq(BomNewPbomParentEntity::getMaterialNo, c.getMaterialNo())
.eq(BomNewPbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.one();
if (!Objects.isNull(cp)) {
buildChildrenForSap(cp, t1s);
}
});
}
}
}