feat: 电气专用bom功能

This commit is contained in:
曹鹏飞 2024-04-22 17:17:57 +08:00
parent f8ede45454
commit b1c757938b
6 changed files with 52 additions and 32 deletions

View File

@ -1,5 +1,7 @@
package com.nflg.product.bomnew.api.user;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableList;
import com.mzt.logapi.context.LogRecordContext;
@ -29,6 +31,7 @@ import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -99,6 +102,12 @@ public class DQBomApi extends BaseApi {
@PostMapping("getPageList")
@ApiOperation("分页查询数据")
public ResultVO<Page<BomNewDQbomVO>> getPageList(@Valid @RequestBody @NotNull BomNewDQbomPageQuery query) {
if (query.getStatus() == 2) {
if (StrUtil.isBlank(query.getStartDate()) && StrUtil.isBlank(query.getEndDate())) {
query.setStartDate(LocalDateTimeUtil.format(LocalDateTime.now().plusDays(-2), "yyyy-MM-dd"));
query.setEndDate(LocalDateTimeUtil.format(LocalDateTime.now().plusDays(1), "yyyy-MM-dd"));
}
}
return ResultVO.success(dQBomService.getPageList(query));
}
@ -156,10 +165,9 @@ public class DQBomApi extends BaseApi {
*/
@PostMapping("exportBom")
@ApiOperation("导出bom")
public ResultVO exportBom(@Valid @RequestBody @NotEmpty List<Long> rootBomRowIds) throws IOException {
public void exportBom(@Valid @RequestBody @NotEmpty List<Long> rootBomRowIds, HttpServletResponse response) throws IOException {
List<DQbomExcelVO> data = dQBomService.exportBom(rootBomRowIds.get(0));
EecExcelUtil.export(response, data, DQbomExcelVO.class, "专用bom正式表");
return ResultVO.success();
EecExcelUtil.export(response, data, DQbomExcelVO.class, "电气专用bom");
}
/**
@ -205,9 +213,8 @@ public class DQBomApi extends BaseApi {
*/
@PostMapping("importToSAP")
@ApiOperation("导入到SAP")
public ResultVO importToSAP(@Valid @RequestBody @NotEmpty List<Long> rootBomRowIds) {
dQBomService.importToSAP(rootBomRowIds.get(0));
return ResultVO.success();
public ResultVO<Boolean> importToSAP(@Valid @RequestBody @NotEmpty List<Long> rootBomRowIds) {
return dQBomService.importToSAP(rootBomRowIds.get(0));
}
/**

View File

@ -1,6 +1,5 @@
package com.nflg.product.bomnew.pojo.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -93,14 +92,18 @@ public class BomNewDQbomVO extends BomNewDQbomChildEntity implements Serializabl
/**
* 是否有子节点: 0- 1-
*/
@TableField(value = "bom_exist")
@ApiModelProperty(value = "是否有子节点")
private Integer bomExist;
/**
* 是否最新版0- 1-
*/
@TableField(value = "last_version_is")
@ApiModelProperty(value = "是否最新版")
private Integer lastVersionIs = 1;
/**
* 导入SAP状态1-未导入3-已导入
*/
@ApiModelProperty(value = "导入SAP状态1-未导入3-已导入")
private Integer sapState;
}

View File

@ -256,9 +256,11 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
List<String> materialNos = parentChild.stream().map(BaseMaterialVO::getMaterialNo).collect(Collectors.toList());
if (CollUtil.isNotEmpty(materialNos)) {
List<BomNewPbomParentEntity> list = this.lambdaQuery().in(BomNewPbomParentEntity::getMaterialNo, materialNos)
.eq(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()), BomNewPbomParentEntity::getLastVersionIs, 1)
.lt(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus,PBomStatusEnum.PUBLISH.getValue())
.eq(PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
// .eq(PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()), BomNewPbomParentEntity::getLastVersionIs, 1)
// .lt(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus,PBomStatusEnum.PUBLISH.getValue())
// .eq(PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
.eq(PBomStatusEnum.PUBLISH.getValue() > parent.getStatus(), BomNewPbomParentEntity::getLastVersionIs, 1)
.gt(PBomStatusEnum.PUBLISH.getValue() <= parent.getStatus(), BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
.list();
Map<String, BomNewPbomParentEntity> bomListMap= list.parallelStream()

View File

@ -92,6 +92,10 @@ public class DQBomImportService {
}
}
private void checkData(List<DQbomExcelVO> datas) {
}
public void save() {
Pair<List<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> pcs = BOMMAP.get(SessionUtil.getUserCode());
VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入");

View File

@ -39,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
@ -223,11 +224,8 @@ public class DQBomService {
public void save(BomNewDQbomSaveQuery query) {
BomNewDQbomParentEntity parent = new BomNewDQbomParentEntity();
BeanUtil.copyProperties(query.getParent(), parent);
//BomNewDQbomChildEntity child;
List<BomNewDQbomParentEntity> liParents = new ArrayList<>();
if (Objects.isNull(parent.getRowId())) {
if (Objects.isNull(parent.getRowId()) || parent.getRowId() == 0) {
//新增父级节点
BomNewDQbomParentEntity oldParent = dQBomParentService.lambdaQuery().eq(BomNewDQbomParentEntity::getMaterialNo, parent.getMaterialNo())
.eq(BomNewDQbomParentEntity::getLastVersionIs, 1)
@ -247,7 +245,7 @@ public class DQBomService {
parent.setCreatedName(SessionUtil.getRealName());
parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue());
parent.setSource(2);
liParents.add(parent);
dQBomParentService.save(parent);
} else {
//修改数据
VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据");
@ -257,16 +255,10 @@ public class DQBomService {
return;
}
//删除
// dQBomChildService.deleteNotIn(parent.getRowId(),
// query.getChildren().stream()
// .map(BomNewDQbomSaveVO::getRowId)
// .filter(d -> ObjectUtil.isNotNull(d) && d > 0L)
// .collect(Collectors.toList()));
dQBomChildService.deleteAllChildren(parent.getRowId());
parent.setBomExist(1);
parent.setModifyTime(LocalDateTime.now());
//child = dQBomChildService.getById(query.getParent().getBomChildRowId());
dQBomParentService.updateById(parent);
}
//处理child
List<BomNewDQbomChildEntity> children = Convert.toList(BomNewDQbomChildEntity.class, query.getChildren());
@ -383,7 +375,7 @@ public class DQBomService {
}
}
public void importToSAP(Long rootBomRowId) {
public ResultVO<Boolean> importToSAP(Long rootBomRowId) {
BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
VUtils.isTure(root.getRootIs() == 0).throwMessage("请选择根节点");
@ -416,6 +408,7 @@ public class DQBomService {
parentEntity.setSapTime(LocalDateTimeUtil.now());
dQBomParentService.updateById(parentEntity);
}
return resultVO;
}
public BomDQbomEditDetailVO editDetail(Long rowId, Long bomRowId) {
@ -475,7 +468,10 @@ public class DQBomService {
dQBomChildService.updateBatchById(children);
savePbomParents(parents);
savePbomChildren(children, parents);
importToSAP(root.getRowId());
CompletableFuture.runAsync(() -> {
importToSAP(root.getRowId());
});
}
private void savePbomChildren(List<BomNewDQbomChildEntity> children, List<BomNewDQbomParentEntity> parents) {
@ -513,6 +509,8 @@ public class DQBomService {
p.setFacCode(FactoryCodeEnum.FACTORY_1010.getValue());
p.setSourceRowId(p.getRowId());
p.setLevelNum(parents.stream().filter(ps -> Objects.equals(ps.getRowId(), p.getRowId())).findFirst().get().getLevel());
p.setReleaseTime(LocalDateTime.now());
p.setReleaseUserName(SessionUtil.getUserName());
});
bomNewPbomParentService.saveBatch(pparents);
}
@ -520,12 +518,17 @@ public class DQBomService {
private void buildPbom(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
parent.setStatus(2);
parent.setConvertToPbomTime(LocalDateTime.now());
parent.setModifyTime(LocalDateTime.now());
parents.add(parent);
LambdaQueryWrapper<BomNewDQbomParentEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BomNewDQbomParentEntity::getMaterialNo, parent.getMaterialNo());
wrapper.ne(BomNewDQbomParentEntity::getRowId, parent.getRowId());
dQBomParentService.getBaseMapper().delete(wrapper);
List<BomNewDQbomChildEntity> cc = dQBomChildService.getByParentRowId(parent.getRowId());
cc.forEach(c -> {
c.setStatus(2);
c.setModifyTime(LocalDateTime.now());
});
children.addAll(cc);
BomNewPbomParentEntity pp = bomNewPbomParentService.lambdaQuery().eq(BomNewPbomParentEntity::getMaterialNo, parent.getMaterialNo())
@ -557,14 +560,14 @@ public class DQBomService {
bomNewPbomChildService.getBaseMapper().delete(new LambdaQueryWrapper<BomNewPbomChildEntity>()
.eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId()));
}
//处理子级
dQBomParentService.lambdaQuery()
.in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList()))
.eq(BomNewDQbomParentEntity::getStatus, 1)
.list()
.forEach(p -> buildPbom(p, parents, children));
}
}
//处理子级
dQBomParentService.lambdaQuery()
.in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList()))
.eq(BomNewDQbomParentEntity::getStatus, 1)
.list()
.forEach(p -> buildPbom(p, parents, children));
}
private int versionCompare(String version1, String version2) {

View File

@ -65,6 +65,7 @@
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,
ifnull(p.sap_state, 1) sap_state,
c.*
FROM t_bom_new_dqbom_parent p
RIGHT JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no