Merge branch 'refs/heads/dev' into sit

This commit is contained in:
曹鹏飞 2024-04-24 08:08:35 +08:00
commit 654fb01f1e
16 changed files with 350 additions and 185 deletions

View File

@ -87,10 +87,10 @@ public class DQBomApi extends BaseApi {
* @return
*/
@ApiOperation("确认从excel导入数据")
@PostMapping("importBomSave")
@GetMapping("importBomConfirm")
@LogRecord(success = "电气BOM-确认导入,操作结果:{{#_ret}}", bizNo = "", type = "电气BOM导入")
public ResultVO importBomSave() {
dqBomImportService.save();
public ResultVO importBomConfirm(@Valid @RequestParam("save") @NotNull Boolean save) {
dqBomImportService.importBomConfirm(save);
return ResultVO.success();
}
@ -129,9 +129,8 @@ public class DQBomApi extends BaseApi {
*/
@PostMapping("temporary")
@ApiOperation("暂存")
public ResultVO<String> temporary(@Valid @RequestBody @NotNull BomNewDQbomSaveQuery query) {
dQBomService.save(query);
return ResultVO.success();
public ResultVO<BomNewDQbomSaveQuery> temporary(@Valid @RequestBody @NotNull BomNewDQbomSaveQuery query) {
return ResultVO.success(dQBomService.save(query));
}
/**

View File

@ -9,6 +9,5 @@ public class BomConstant {
public static final String SAP_YDBOM="1";
public static final String MATERIAL_NO_TEMPORARY_PREFIX = "TN";
public static final String DRAWING_NO_TEMPORARY_PREFIX = "TD";
public static final String NO_TEMPORARY_PREFIX = "T";
}

View File

@ -16,4 +16,6 @@ public interface BomNewDQbomChildMapper extends BaseMapper<BomNewDQbomChildEntit
void deleteAllChildren(Long parentRowId);
List<BomNewDQbomVO> getBomsByParentRowId(Long rowId);
List<BomNewDQbomVO> getBom(Long parentRowId, String materialNo);
}

View File

@ -0,0 +1,64 @@
package com.nflg.product.bomnew.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author 曹鹏飞
* @date 2024/4/23 15:10:28
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-entity-BomNewDQbomBaseEntity")
public class BomNewDQbomBaseEntity implements Serializable {
/**
* 主键-雪花
*/
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键-雪花")
protected Long rowId;
/**
* 图号
*/
@TableField(value = "drawing_no")
@ApiModelProperty(value = "图号")
protected String drawingNo;
/**
* 物料编码
*/
@TableField(value = "material_no")
@ApiModelProperty(value = "物料编码")
protected String materialNo;
/**
* 单位
*/
@TableField(value = "material_unit")
@ApiModelProperty(value = "单位")
protected String materialUnit;
/**
* 数量
*/
@TableField(value = "num")
@ApiModelProperty(value = "数量")
protected BigDecimal num;
/**
* 材质
*/
@TableField(value = "material_texture")
@ApiModelProperty(value = "材质")
protected String materialTexture;
}

View File

@ -1,15 +1,12 @@
package com.nflg.product.bomnew.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@ -21,14 +18,14 @@ import java.time.LocalDateTime;
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-entity-BomNewDQbomChildEntity")
@TableName(value = "t_bom_new_dqbom_child")
public class BomNewDQbomChildEntity implements Serializable {
public class BomNewDQbomChildEntity extends BomNewDQbomBaseEntity {
/**
* 主键-雪花
*/
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键-雪花")
private Long rowId;
// /**
// * 主键-雪花
// */
// @TableId(value = "row_id", type = IdType.ASSIGN_ID)
// @ApiModelProperty(value = "主键-雪花")
// private Long rowId;
/**
* 层次
@ -65,19 +62,19 @@ public class BomNewDQbomChildEntity implements Serializable {
@ApiModelProperty(value = "项目类别")
private String projectType;
/**
* 图号
*/
@TableField(value = "drawing_no")
@ApiModelProperty(value = "图号")
private String drawingNo;
/**
* 物料编码
*/
@TableField(value = "material_no")
@ApiModelProperty(value = "物料编码")
private String materialNo;
// /**
// * 图号
// */
// @TableField(value = "drawing_no")
// @ApiModelProperty(value = "图号")
// private String drawingNo;
//
// /**
// * 物料编码
// */
// @TableField(value = "material_no")
// @ApiModelProperty(value = "物料编码")
// private String materialNo;
/**
* 物料名称
@ -86,19 +83,19 @@ public class BomNewDQbomChildEntity implements Serializable {
@ApiModelProperty(value = "物料名称")
private String materialName;
/**
* 材质
*/
@TableField(value = "material_texture")
@ApiModelProperty(value = "材质")
private String materialTexture;
// /**
// * 材质
// */
// @TableField(value = "material_texture")
// @ApiModelProperty(value = "材质")
// private String materialTexture;
/**
* 单位
*/
@TableField(value = "material_unit")
@ApiModelProperty(value = "单位")
private String materialUnit;
// /**
// * 单位
// */
// @TableField(value = "material_unit")
// @ApiModelProperty(value = "单位")
// private String materialUnit;
/**
* 单重
@ -107,12 +104,12 @@ public class BomNewDQbomChildEntity implements Serializable {
@ApiModelProperty(value = "单重")
private BigDecimal unitWeight;
/**
* 数量
*/
@TableField(value = "num")
@ApiModelProperty(value = "数量")
private BigDecimal num;
// /**
// * 数量
// */
// @TableField(value = "num")
// @ApiModelProperty(value = "数量")
// private BigDecimal num;
/**
* 总重

View File

@ -1,15 +1,12 @@
package com.nflg.product.bomnew.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@ -21,14 +18,14 @@ import java.time.LocalDateTime;
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-entity-BomNewDQbomParentEntity")
@TableName(value = "t_bom_new_dqbom_parent")
public class BomNewDQbomParentEntity implements Serializable {
public class BomNewDQbomParentEntity extends BomNewDQbomBaseEntity {
/**
* 主键-雪花
*/
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键-雪花")
private Long rowId;
// /**
// * 主键-雪花
// */
// @TableId(value = "row_id", type = IdType.ASSIGN_ID)
// @ApiModelProperty(value = "主键-雪花")
// private Long rowId;
/**
* 层次
@ -37,19 +34,19 @@ public class BomNewDQbomParentEntity implements Serializable {
@ApiModelProperty(value = "层次")
private Integer level;
/**
* 图号
*/
@TableField(value = "drawing_no")
@ApiModelProperty(value = "图号")
private String drawingNo;
/**
* 物料编码
*/
@TableField(value = "material_no")
@ApiModelProperty(value = "物料编码")
private String materialNo;
// /**
// * 图号
// */
// @TableField(value = "drawing_no")
// @ApiModelProperty(value = "图号")
// private String drawingNo;
//
// /**
// * 物料编码
// */
// @TableField(value = "material_no")
// @ApiModelProperty(value = "物料编码")
// private String materialNo;
/**
* 物料名称
@ -58,19 +55,19 @@ public class BomNewDQbomParentEntity implements Serializable {
@ApiModelProperty(value = "物料名称")
private String materialName;
/**
* 材质
*/
@TableField(value = "material_texture")
@ApiModelProperty(value = "材质")
private String materialTexture;
// /**
// * 材质
// */
// @TableField(value = "material_texture")
// @ApiModelProperty(value = "材质")
// private String materialTexture;
/**
* 单位
*/
@TableField(value = "material_unit")
@ApiModelProperty(value = "单位")
private String materialUnit;
// /**
// * 单位
// */
// @TableField(value = "material_unit")
// @ApiModelProperty(value = "单位")
// private String materialUnit;
/**
* 单重
@ -79,12 +76,12 @@ public class BomNewDQbomParentEntity implements Serializable {
@ApiModelProperty(value = "单重")
private BigDecimal unitWeight;
/**
* 数量
*/
@TableField(value = "num")
@ApiModelProperty(value = "数量")
private BigDecimal num;
// /**
// * 数量
// */
// @TableField(value = "num")
// @ApiModelProperty(value = "数量")
// private BigDecimal num;
/**
* 总重

View File

@ -1,6 +1,6 @@
package com.nflg.product.bomnew.pojo.query;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomSaveVO;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -24,12 +24,12 @@ public class BomNewDQbomSaveQuery implements Serializable {
*/
@ApiModelProperty(value = "父级")
@NotNull
private BomNewDQbomSaveVO parent;
private BomNewDQbomVO parent;
/**
* 子级数据
*/
@ApiModelProperty(value = "子级数据")
@NotNull
private List<BomNewDQbomSaveVO> children;
private List<BomNewDQbomVO> children;
}

View File

@ -1,5 +1,7 @@
package com.nflg.product.bomnew.pojo.vo;
import cn.hutool.core.util.StrUtil;
import com.nflg.product.bomnew.constant.BomConstant;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -106,4 +108,30 @@ public class BomNewDQbomVO extends BomNewDQbomChildEntity implements Serializabl
*/
@ApiModelProperty(value = "导入SAP状态1-未导入3-已导入")
private Integer sapState;
/**
* 图号(显示用)
*/
@ApiModelProperty(value = "图号(显示用)")
private String drawingNoDesc;
public String getDrawingNoDesc() {
if (StrUtil.isNotBlank(getDrawingNo()) && getDrawingNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) {
return "";
}
return getDrawingNo();
}
/**
* 物料编码(显示用)
*/
@ApiModelProperty(value = "物料编码(显示用)")
private String materialNoDesc;
public String getMaterialNoDesc() {
if (StrUtil.isNotBlank(getMaterialNo()) && getMaterialNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) {
return "";
}
return getMaterialNo();
}
}

View File

@ -1,5 +1,6 @@
package com.nflg.product.bomnew.pojo.vo;
import cn.hutool.core.util.StrUtil;
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
import lombok.Data;
import org.ttzero.excel.annotation.ExcelColumn;
@ -28,6 +29,13 @@ public class DQbomExcelVO extends BaseImportExcelDTO {
@ExcelColumn("材料")
private String materialTexture;
public String getMaterialTexture() {
if (StrUtil.isBlank(materialTexture)) {
return "";
}
return materialTexture;
}
@ExcelColumn(value = "数量")
private BigDecimal num;

View File

@ -126,7 +126,7 @@ public class BomNewDQbomExceptionCheckService {
if (parent.getRootIs() == 1 || parent.getUserRootIs() == 1) {
if ("T".equals(parent.getProjectType())) {
parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
} else if (parent.getMaterialNo().startsWith(BomConstant.MATERIAL_NO_TEMPORARY_PREFIX)) {
} else if (parent.getMaterialNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) {
status = EBomExceptionStatusEnum.EXCEPT_NO_4;
} else {
BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(parent.getMaterialNo()))
@ -164,7 +164,7 @@ public class BomNewDQbomExceptionCheckService {
EBomExceptionStatusEnum status = EBomExceptionStatusEnum.OK;
if ("T".equals(child.getProjectType())) {
child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
} else if (child.getMaterialNo().startsWith(BomConstant.MATERIAL_NO_TEMPORARY_PREFIX)) {
} else if (child.getMaterialNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) {
status = EBomExceptionStatusEnum.EXCEPT_NO_4;
} else {
BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(child.getMaterialNo()))

View File

@ -41,4 +41,8 @@ public class DQBomChildService extends ServiceImpl<BomNewDQbomChildMapper, BomNe
public List<BomNewDQbomVO> getBomsByParentRowId(Long rowId) {
return this.getBaseMapper().getBomsByParentRowId(rowId);
}
public List<BomNewDQbomVO> getBom(Long parentRowId, String materialNo) {
return this.getBaseMapper().getBom(parentRowId, materialNo);
}
}

View File

@ -1,6 +1,7 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@ -8,10 +9,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Sets;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.constant.BomConstant;
import com.nflg.product.bomnew.constant.DQBomStatusEnum;
import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum;
import com.nflg.product.bomnew.constant.UserJobEnum;
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.util.*;
@ -74,9 +79,10 @@ public class DQBomImportService {
}
Pair<List<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> pcs = convertToBom(datas);
VUtils.isTure(CollUtil.isEmpty(pcs.getLeft())).throwMessage("所有数据都已经导入过了,请勿重复导入");
//VUtils.isTure(CollUtil.isEmpty(pcs.getLeft())).throwMessage("所有数据都已经导入过了,请勿重复导入");
try {
checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight());
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()))
.throwMessage("导入的数据已存在,请勿重复导入");
} catch (NflgBusinessException ex) {
if (Objects.equals(ex.getState(), STATE.InconsistentDataError)) {
BOMMAP.put(SessionUtil.getUserCode(), pcs);
@ -101,53 +107,119 @@ public class DQBomImportService {
@Transactional(rollbackFor = Exception.class)
public void save(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
// checkExceptionStatus(parents, children);
dQBomParentService.setLastVersionIs0(parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList()));
Set<String> materialNos = parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toSet());
List<BomNewDQbomParentEntity> oldParents = dQBomParentService.getLatestByMaterialNo(materialNos);
parents.forEach(p -> {
BomNewDQbomParentEntity oldParent = oldParents.stream().filter(op -> op.getMaterialNo().equals(p.getMaterialNo())).findFirst().orElse(null);
if (!Objects.isNull(oldParent) && Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
dQBomParentService.getBaseMapper().deleteById(oldParent.getRowId());
dQBomChildService.deleteAllChildren(oldParent.getRowId());
}
});
dQBomParentService.setLastVersionIs0(materialNos);
dQBomParentService.saveBatch(parents);
dQBomChildService.saveBatch(children);
BomNewDQbomParentEntity root = parents.stream().filter(p -> p.getRootIs() == 1).findFirst().orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在"));
dQBomService.checkException(root.getRowId());
}
// private void checkExceptionStatus(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
// BomNewDQbomExceptionCheckService checkService = new BomNewDQbomExceptionCheckService(dQBomParentService, dQBomChildService, materialMainService);
// checkService.check(parents, children);
// }
private void checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents,
private boolean checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents,
List<BomNewDQbomChildEntity> children) throws JsonProcessingException {
log.debug("checkInconsistentDataparent" + JsonUtil.toJson(parent));
log.debug("checkInconsistentDataentity" + JsonUtil.toJson(parent));
BomNewDQbomParentEntity oldParent = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo());
if (!Objects.isNull(oldParent)) {
Set<String> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId()))
.map(BomNewDQbomChildEntity::getMaterialNo)
.collect(Collectors.toSet());
Set<String> oc = dQBomChildService.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId())
.list()
.stream().map(BomNewDQbomChildEntity::getMaterialNo)
.collect(Collectors.toSet());
// if (!Sets.difference(cc, oc).isEmpty()) {
// throw new NflgBusinessException(STATE.InconsistentDataError, "导入的数据和已存在的数据不一致,是否覆盖?");
// if (parent.getRowId() > 0) {
// old = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo());
// } else {
// old = dQBomChildService.lambdaQuery()
// .eq(BomNewDQbomChildEntity::getParentRowId, parent.getRowId())
// .eq(BomNewDQbomChildEntity::getMaterialNo, parent.getMaterialNo())
// .one();
// }
boolean isSame = Sets.difference(cc, oc).isEmpty()
&& Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit())
&& Objects.equals(parent.getNum(), oldParent.getNum())
//BomNewDQbomParentEntity oldParent = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo());
boolean isSame = true;
if (Objects.isNull(oldParent)) {
return isSame;
}
isSame = Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit())
&& NumberUtil.equals(parent.getNum(), oldParent.getNum())
&& Objects.equals(parent.getMaterialTexture(), oldParent.getMaterialTexture());
VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入");
if (Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode()))
.throwMessage(StrUtil.format("此物料已由{}导入过,不能再次导入", oldParent.getCreatedName()));
throw new NflgBusinessException(STATE.InconsistentDataError, "导入的数据和已存在的数据不一致,是否覆盖?");
}
List<BomNewDQbomParentEntity> ps = parents.stream().filter(p -> cc.contains(p.getMaterialNo()))
if (isSame) {
List<BomNewDQbomChildEntity> cc = children.stream()
.filter(c -> c.getParentRowId().equals(parent.getRowId()))
.collect(Collectors.toList());
for (BomNewDQbomParentEntity p : ps) {
checkInconsistentData(p, parents, children);
List<BomNewDQbomChildEntity> oc = dQBomChildService.lambdaQuery()
.eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId())
.list();
isSame = cc.size() == oc.size()
&& cc.stream().filter(c -> c.getProjectType().equals("T")).count() == oc.stream().filter(c -> c.getProjectType().equals("T")).count()
&& Sets.difference(cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet()), oc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty();
//VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入");
for (BomNewDQbomChildEntity ccc : cc) {
if (!checkInconsistentData(parent.getRowId(), ccc, parents, children)) {
isSame = false;
}
}
}
if (!isSame && Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode()))
.throwMessage(StrUtil.format("{}已由{}导入过,不能再次导入", oldParent.getMaterialNo(), oldParent.getCreatedName()));
throw new NflgBusinessException(STATE.InconsistentDataError, oldParent.getMaterialNo() + "和已存在的数据不一致,是否覆盖?");
}
return isSame;
}
private boolean checkInconsistentData(Long parentRowId, BomNewDQbomChildEntity child, List<BomNewDQbomParentEntity> parents,
List<BomNewDQbomChildEntity> children) throws JsonProcessingException {
log.debug("checkInconsistentDataentity" + JsonUtil.toJson(child));
List<BomNewDQbomVO> oldChildren = dQBomChildService.getBom(parentRowId, child.getMaterialNo());
boolean isSame = true;
if (CollUtil.isEmpty(oldChildren)) return isSame;
BomNewDQbomVO oldChild;
if (oldChildren.size() == 1) {
oldChild = oldChildren.get(0);
} else {
oldChild = oldChildren.stream().filter(c -> Objects.equals(c.getOrderNumber(), child.getOrderNumber())).findFirst().orElse(null);
if (Objects.isNull(oldChild)) {
return isSame;
}
}
isSame = Objects.equals(child.getMaterialUnit(), oldChild.getMaterialUnit())
&& NumberUtil.equals(child.getNum(), oldChild.getNum())
&& Objects.equals(child.getMaterialTexture(), oldChild.getMaterialTexture());
if (isSame) {
BomNewDQbomParentEntity cp = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().orElse(null);
if (!Objects.isNull(cp)) {
List<BomNewDQbomChildEntity> cc = children.stream()
.filter(c -> c.getParentRowId().equals(cp.getRowId()))
.collect(Collectors.toList());
List<BomNewDQbomChildEntity> oc = dQBomChildService.lambdaQuery()
.eq(BomNewDQbomChildEntity::getParentRowId, oldChild.getBomRowId())
.list();
Set<String> ccm = cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet());
isSame = cc.size() == oc.size()
&& cc.stream().filter(c -> c.getProjectType().equals("T")).count() == oc.stream().filter(c -> c.getProjectType().equals("T")).count()
&& Sets.difference(ccm, oc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty();
//VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入");
for (BomNewDQbomChildEntity ccc : cc) {
if (!checkInconsistentData(cp.getRowId(), ccc, parents, children)) {
isSame = false;
}
}
}
}
if (!isSame && Objects.equals(oldChild.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
VUtils.isTure(!Objects.equals(oldChild.getCreatedBy(), SessionUtil.getUserCode()))
.throwMessage(StrUtil.format("{}已由{}导入过,不能再次导入", oldChild.getMaterialNo(), oldChild.getCreatedName()));
throw new NflgBusinessException(STATE.InconsistentDataError, oldChild.getMaterialNo() + "和已存在的数据不一致,是否覆盖?");
}
return isSame;
}
private List<OperationErrorMsgVO> checkExcel(List<DQbomExcelVO> datas) {
List<OperationErrorMsgVO> errorMsg = new ArrayList<>();
@ -226,7 +298,7 @@ public class DQBomImportService {
parent.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum());
parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight()));
parent.setProjectType(data.getProjectType());
parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
//parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
parent.setRootIs(index == 0 ? 1 : 0);
parent.setUserRootIs(index == 0 ? 1 : 0);
parent.setLastVersionIs(1);
@ -268,7 +340,7 @@ public class DQBomImportService {
child.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight()));
child.setOrderNumber(StrUtil.padPre(String.valueOf(orderMap.get(data.getLevel())), 3, '0'));
child.setDrawingNo(data.getDrawingNo());
child.setCurrentVersion(parent == null ? OriginalConstant.DEFAULT_BOM_VERSION : parent.getCurrentVersion());
//child.setCurrentVersion(parent == null ? OriginalConstant.DEFAULT_BOM_VERSION : parent.getCurrentVersion());
child.setMaterialNo(data.getMaterialNo());
child.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue());
child.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum());
@ -292,21 +364,25 @@ public class DQBomImportService {
dQbomExcelVO.setRowNum(rowNum.get());
if (dQbomExcelVO.getProjectType().equals("T")) {
BomNewDQbomParentEntity p = dQBomParentService.lambdaQuery()
.eq(BomNewDQbomParentEntity::getMaterialName, dQbomExcelVO.getMaterialName())
.orderByDesc(BomNewDQbomParentEntity::getRowId)
.last(" limit 1")
.one();
if (p != null) {
dQbomExcelVO.setMaterialNo(p.getMaterialNo());
dQbomExcelVO.setDrawingNo(p.getMaterialNo());
} else {
String id = BomConstant.DRAWING_NO_TEMPORARY_PREFIX + System.currentTimeMillis();
dQbomExcelVO.setMaterialNo(id);
dQbomExcelVO.setDrawingNo(id);
long id = System.currentTimeMillis();
dQbomExcelVO.setMaterialNo(BomConstant.NO_TEMPORARY_PREFIX + id);
dQbomExcelVO.setDrawingNo(BomConstant.NO_TEMPORARY_PREFIX + id);
if (StrUtil.isBlank(dQbomExcelVO.getMaterialUnit())) {
dQbomExcelVO.setMaterialUnit("PC");
}
if (Objects.isNull(dQbomExcelVO.getNum()) || NumberUtil.equals(dQbomExcelVO.getNum(), BigDecimal.ZERO)) {
dQbomExcelVO.setNum(BigDecimal.ONE);
}
}
excelContextTL.get().add(dQbomExcelVO);
}
public void importBomConfirm(Boolean save) {
if (save) {
save();
} else {
BOMMAP.remove(SessionUtil.getUserCode());
}
}
}

View File

@ -7,6 +7,7 @@ import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
/**
@ -24,7 +25,7 @@ public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, Bom
.one();
}
public void setLastVersionIs0(List<String> materialNo) {
public void setLastVersionIs0(Collection<String> materialNo) {
this.lambdaUpdate().in(BomNewDQbomParentEntity::getMaterialNo, materialNo)
.set(BomNewDQbomParentEntity::getLastVersionIs, 0)
.set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now())
@ -42,7 +43,7 @@ public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, Bom
.exists();
}
public List<BomNewDQbomParentEntity> getLatestByMaterialNo(List<String> materialNos) {
public List<BomNewDQbomParentEntity> getLatestByMaterialNo(Collection<String> materialNos) {
return this.lambdaQuery()
.in(BomNewDQbomParentEntity::getMaterialNo, materialNos)
.eq(BomNewDQbomParentEntity::getLastVersionIs, 1)

View File

@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
@ -37,6 +38,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@ -221,7 +223,7 @@ public class DQBomService {
* @param query 请求参数
*/
@Transactional(rollbackFor = Exception.class)
public void save(BomNewDQbomSaveQuery query) {
public BomNewDQbomSaveQuery save(BomNewDQbomSaveQuery query) {
BomNewDQbomParentEntity parent = new BomNewDQbomParentEntity();
BeanUtil.copyProperties(query.getParent(), parent);
@ -246,13 +248,14 @@ public class DQBomService {
parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue());
parent.setSource(2);
dQBomParentService.save(parent);
query.getParent().setRowId(parent.getRowId());
} else {
//修改数据
VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据");
// VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据");
if (CollUtil.isEmpty(query.getChildren())) {
dQBomChildService.deleteAllChildren(parent.getRowId());
return;
return query;
}
//删除
dQBomChildService.deleteAllChildren(parent.getRowId());
@ -271,6 +274,12 @@ public class DQBomService {
} else {
c.setModifyTime(LocalDateTime.now());
}
if (StrUtil.isBlank(c.getMaterialUnit())) {
c.setMaterialUnit("PC");
}
if (Objects.isNull(c.getNum()) || NumberUtil.equals(c.getNum(), BigDecimal.ZERO)) {
c.setNum(BigDecimal.ONE);
}
c.setLevel(parent.getLevel() + 1);
c.setParentRowId(parent.getRowId());
c.setIdentityNo(c.getParentRowId() + "_" + c.getRowId());
@ -278,36 +287,8 @@ public class DQBomService {
c.setTotalWeight(BomUtil.calculateTotalWeight(c.getNum(), query.getChildren().get(index).getUnitWeight()));
}
dQBomChildService.saveBatch(children);
// //处理parent
// List<BomNewDQbomParentEntity> parents = Convert.toList(BomNewDQbomParentEntity.class, query.getChildren());
// List<String> materialNos = dQBomParentService.lambdaQuery()
// .in(BomNewDQbomParentEntity::getMaterialNo, parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList()))
// .eq(BomNewDQbomParentEntity::getStatus, DQBomStatusEnum.WAIT_CONVERT.getValue())
// .list()
// .stream()
// .map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList());
// parents.removeIf(p -> materialNos.contains(p.getMaterialNo()));
// List<String> materialNos1 = parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList());
// if (CollUtil.isNotEmpty(materialNos1)) {
// dQBomParentService.lambdaUpdate().in(BomNewDQbomParentEntity::getMaterialNo, materialNos1)
// .set(BomNewDQbomParentEntity::getLastVersionIs, 0)
// .set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now())
// .update();
// }
// parents.stream().filter(p -> Objects.isNull(p.getRowId())).forEach(p -> {
// p.setRowId(IdWorker.getId());
// p.setCreatedBy(SessionUtil.getUserCode());
// p.setStatus(DQBomStatusEnum.WAIT_CONVERT.getValue());
// p.setRootIs(0);
// p.setUserRootIs(0);
// p.setBomExist(0);
// p.setEditStatus(1);
// p.setCreatedName(SessionUtil.getRealName());
// p.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue());
// p.setSource(2);
// });
// liParents.addAll(parents);
// dQBomParentService.saveOrUpdateBatch(liParents);
query.setChildren(Convert.toList(BomNewDQbomVO.class, children));
return query;
}
public void deleteBom(Long rowId) {

View File

@ -137,10 +137,11 @@ public class EBomToPBom {
*/
private void check() {
//动态判断异常
CheckEBomExceptoinDynamic.check(allBomDetail);
List<BomNewEbomParentVO> collect = allBomDetail.stream().filter(u -> !EBomExceptionStatusEnum.OK.getValue().equals(u.getExceptionStatus())).collect(Collectors.toList());
// CheckEBomExceptoinDynamic.check(allBomDetail);
// List<BomNewEbomParentVO> collect = allBomDetail.stream().filter(u -> !EBomExceptionStatusEnum.OK.getValue().equals(u.getExceptionStatus())).collect(Collectors.toList());
VUtils.isTure(CollUtil.isNotEmpty(collect)).throwMessage("存在异常数据,请处理完再转换");
// VUtils.isTure(CollUtil.isNotEmpty(collect)).throwMessage("存在异常数据,请处理完再转换");
VUtils.isTure(!Objects.equals(parent.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())).throwMessage("存在异常数据,请处理完再转换");
}

View File

@ -16,4 +16,12 @@
LEFT JOIN t_bom_new_dqbom_parent p ON p.material_no = c.material_no
WHERE c.parent_row_id = #{rowId}
</select>
<select id="getBom" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
SELECT c.*, p.row_id AS bomRowId, p.created_by AS bomCreateBy
FROM t_bom_new_dqbom_child c
LEFT JOIN t_bom_new_dqbom_parent p ON p.material_no = c.material_no AND c.status = p.status
WHERE c.parent_row_id = #{parentRowId}
AND c.material_no = #{materialNo}
</select>
</mapper>