feat: 添加电气bom保存数据和异常检查接口
This commit is contained in:
parent
1cb2952dd5
commit
2930ab3ba8
|
|
@ -5,6 +5,7 @@ import com.mzt.logapi.context.LogRecordContext;
|
||||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||||
import com.nflg.product.base.core.api.BaseApi;
|
import com.nflg.product.base.core.api.BaseApi;
|
||||||
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
|
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
|
||||||
|
import com.nflg.product.bomnew.pojo.query.BomNewDQbomSaveQuery;
|
||||||
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
|
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
|
||||||
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
||||||
import com.nflg.product.bomnew.service.DQBomImportService;
|
import com.nflg.product.bomnew.service.DQBomImportService;
|
||||||
|
|
@ -16,6 +17,8 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -60,13 +63,42 @@ public class DQBomApi extends BaseApi {
|
||||||
*/
|
*/
|
||||||
@PostMapping("getPageList")
|
@PostMapping("getPageList")
|
||||||
@ApiOperation("分页查询数据")
|
@ApiOperation("分页查询数据")
|
||||||
public ResultVO<Page<BomNewDQbomVO>> getPageList(@RequestBody BomNewDQbomPageQuery query) {
|
public ResultVO<Page<BomNewDQbomVO>> getPageList(@Valid @RequestBody @NotNull BomNewDQbomPageQuery query) {
|
||||||
return ResultVO.success(dQBomService.getPageList(query));
|
return ResultVO.success(dQBomService.getPageList(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子级数据
|
||||||
|
* @param bomRowId 父级rowId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@GetMapping("getChild")
|
@GetMapping("getChild")
|
||||||
@ApiOperation("获取子级数据")
|
@ApiOperation("获取子级数据")
|
||||||
public ResultVO<List<BomNewDQbomVO>> getChild(@RequestParam("bomRowId") Long bomRowId) {
|
public ResultVO<List<BomNewDQbomVO>> getChild(@Valid @RequestParam("bomRowId") @NotNull Long bomRowId) {
|
||||||
return ResultVO.success(dQBomService.getChild(bomRowId));
|
return ResultVO.success(dQBomService.getChild(bomRowId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存数据
|
||||||
|
* @param query 保存的数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("save")
|
||||||
|
@ApiOperation("保存数据")
|
||||||
|
public ResultVO<String> save(@Valid @RequestBody @NotNull BomNewDQbomSaveQuery query) {
|
||||||
|
dQBomService.save(query);
|
||||||
|
return ResultVO.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常检查
|
||||||
|
* @param rootRowIds 顶级rowId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("checkException")
|
||||||
|
@ApiOperation("异常检查")
|
||||||
|
public ResultVO<String> checkException(@RequestBody List<Long> rootRowIds) {
|
||||||
|
dQBomService.checkException(rootRowIds);
|
||||||
|
return ResultVO.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.nflg.product.bomnew.constant;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 曹鹏飞
|
||||||
|
* @date 2024/4/11 14:37:26
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum BomNewDQbomStatusEnum implements ValueEnum<Integer> {
|
||||||
|
|
||||||
|
WAIT_CONVERT(1, "待转换"),
|
||||||
|
CONVERTED(2, "已转换");
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
public static BomNewDQbomStatusEnum findByValue(Integer value) {
|
||||||
|
for (BomNewDQbomStatusEnum statusEnum : BomNewDQbomStatusEnum.values()) {
|
||||||
|
if (statusEnum.getValue().equals(value)) {
|
||||||
|
return statusEnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("无效的值");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ public enum EBomExceptionStatusEnum implements ValueEnum<Integer> {
|
||||||
EXCEPT_NO_11(11, "未填写变更原因和技术通知单"),
|
EXCEPT_NO_11(11, "未填写变更原因和技术通知单"),
|
||||||
EXCEPT_NO_12(12, "数量需要用户确认"),
|
EXCEPT_NO_12(12, "数量需要用户确认"),
|
||||||
EXCEPT_NO_13(13, "项目类型需要用户确认") ,
|
EXCEPT_NO_13(13, "项目类型需要用户确认") ,
|
||||||
EXCEPT_NO_14(14, "黄色警告"),
|
EXCEPT_NO_14(14, "黄色警告(下级节点存在异常)"),
|
||||||
EXCEPT_NO_15(15, "物料名称不一致");
|
EXCEPT_NO_15(15, "物料名称不一致");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,5 @@ import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
||||||
public interface BomNewDQbomChildMapper extends BaseMapper<BomNewDQbomChildEntity> {
|
public interface BomNewDQbomChildMapper extends BaseMapper<BomNewDQbomChildEntity> {
|
||||||
|
|
||||||
|
|
||||||
|
void deleteAllChildren(Long parentRowId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,6 @@ public interface BomNewDQbomParentMapper extends BaseMapper<BomNewDQbomParentEnt
|
||||||
Page<BomNewDQbomVO> getPageList(Page<Object> objectPage, BomNewDQbomPageQuery query, String userCode);
|
Page<BomNewDQbomVO> getPageList(Page<Object> objectPage, BomNewDQbomPageQuery query, String userCode);
|
||||||
|
|
||||||
List<BomNewDQbomVO> getChild(Long bomRowId);
|
List<BomNewDQbomVO> getChild(Long bomRowId);
|
||||||
|
|
||||||
|
void resetBomExist(Long rowId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,21 @@ public class BomNewDQbomChildEntity implements Serializable {
|
||||||
@TableField(value = "total_weight")
|
@TableField(value = "total_weight")
|
||||||
@ApiModelProperty(value = "总重")
|
@ApiModelProperty(value = "总重")
|
||||||
private BigDecimal totalWeight;
|
private BigDecimal totalWeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常状态
|
||||||
|
*/
|
||||||
|
@TableField(value = "exception_status")
|
||||||
|
@ApiModelProperty(value = "异常状态")
|
||||||
|
private Integer exceptionStatus = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常标记
|
||||||
|
*/
|
||||||
|
@TableField(value = "exception_tag")
|
||||||
|
@ApiModelProperty(value = "异常标记")
|
||||||
|
private String exceptionTag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人名称
|
* 创建人名称
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -135,20 +135,6 @@ public class BomNewDQbomParentEntity implements Serializable {
|
||||||
@ApiModelProperty(value = "转换状态")
|
@ApiModelProperty(value = "转换状态")
|
||||||
private Integer status = 1;
|
private Integer status = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* 异常状态
|
|
||||||
*/
|
|
||||||
@TableField(value = "exception_status")
|
|
||||||
@ApiModelProperty(value = "异常状态")
|
|
||||||
private Integer exceptionStatus = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 异常标记
|
|
||||||
*/
|
|
||||||
@TableField(value = "exception_tag")
|
|
||||||
@ApiModelProperty(value = "异常标记")
|
|
||||||
private String exceptionTag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人名称
|
* 创建人名称
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.nflg.product.bomnew.pojo.query;
|
||||||
|
|
||||||
|
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomSaveVO;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 曹鹏飞
|
||||||
|
* @date 2024/4/11 13:53:56
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-query-BomNewDQbomSaveQuery")
|
||||||
|
public class BomNewDQbomSaveQuery implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父级rowId
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "图号")
|
||||||
|
private Long parentRowId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子级数据
|
||||||
|
*/
|
||||||
|
private List<BomNewDQbomSaveVO> children;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.nflg.product.bomnew.pojo.vo;
|
||||||
|
|
||||||
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
|
||||||
|
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/11 13:59:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-vo-BomNewDQbomSaveVO")
|
||||||
|
public class BomNewDQbomSaveVO extends BomNewDQbomParentEntity implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父行ID
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "父行ID")
|
||||||
|
private Long parentRowId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "排序号")
|
||||||
|
private String orderNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数量
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "数量")
|
||||||
|
private BigDecimal num;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum;
|
||||||
|
import com.nflg.product.bomnew.constant.MaterialGetEnum;
|
||||||
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
||||||
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
|
||||||
|
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||||
|
import com.nflg.product.bomnew.util.VUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 曹鹏飞
|
||||||
|
* @date 2024/4/11 15:30:16
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class BomNewDQbomExceptionCheckService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
MaterialMainService materialMainService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DQBomParentService dQBomParentService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DQBomChildService dQBomChildService;
|
||||||
|
|
||||||
|
private List<BomNewDQbomParentEntity> parents = new ArrayList<>();
|
||||||
|
private List<BomNewDQbomChildEntity> children = new ArrayList<>();
|
||||||
|
private List<BaseMaterialVO> materialVOS;
|
||||||
|
|
||||||
|
public void check(Long parentRowId) {
|
||||||
|
VUtils.isTure(ObjectUtil.isNull(parentRowId) || parentRowId == 0L).throwMessage("无效的参数:" + parentRowId);
|
||||||
|
|
||||||
|
parents.clear();
|
||||||
|
children.clear();
|
||||||
|
|
||||||
|
BomNewDQbomParentEntity parent = dQBomParentService.getById(parentRowId);
|
||||||
|
VUtils.isTure(ObjectUtil.isNull(parent)).throwMessage("未找到数据:" + parentRowId);
|
||||||
|
buildData(parent);
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildData(BomNewDQbomParentEntity parent) {
|
||||||
|
parents.add(parent);
|
||||||
|
|
||||||
|
BomNewDQbomChildEntity child = dQBomChildService.getRoot(parent.getMaterialNo());
|
||||||
|
children.add(child);
|
||||||
|
|
||||||
|
List<BomNewDQbomChildEntity> cc = dQBomChildService.getByParentRowId(parent.getRowId());
|
||||||
|
if (CollUtil.isNotEmpty(cc)) {
|
||||||
|
children.addAll(cc);
|
||||||
|
List<BomNewDQbomParentEntity> pp = dQBomParentService.getLatestByMaterialNo(cc.stream()
|
||||||
|
.map(BomNewDQbomChildEntity::getMaterialNo)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
parents.addAll(pp);
|
||||||
|
pp.forEach(this::buildData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void check(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
||||||
|
if (CollUtil.isEmpty(children)) return;
|
||||||
|
this.parents = parents;
|
||||||
|
this.children = children;
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check() {
|
||||||
|
List<String> materialNos = children.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList());
|
||||||
|
materialVOS = materialMainService.getMaterialBaseInfo(materialNos);
|
||||||
|
check(children.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private EBomExceptionStatusEnum check(BomNewDQbomChildEntity child) {
|
||||||
|
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
VUtils.isTure(ObjectUtil.isNull(parent)).throwMessage(StrUtil.format("编号为{}的数据不完整", child.getMaterialNo()));
|
||||||
|
|
||||||
|
EBomExceptionStatusEnum status = EBomExceptionStatusEnum.OK;
|
||||||
|
assert parent != null;
|
||||||
|
if ("T".equals(parent.getProjectType())) {
|
||||||
|
child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
|
||||||
|
} else {
|
||||||
|
BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(parent.getMaterialNo())).findFirst().orElse(null);
|
||||||
|
if (materialVO == null) {
|
||||||
|
status = EBomExceptionStatusEnum.EXCEPT_NO_7;
|
||||||
|
} else if (materialVO.getMaterialState().equals(MaterialGetEnum.MaterialStateEnum.STATE_NO_4.getValue())) {
|
||||||
|
status = EBomExceptionStatusEnum.EXCEPT_NO_2;
|
||||||
|
} else if (!materialVO.getMaterialName().equals(parent.getMaterialName())) {
|
||||||
|
status = EBomExceptionStatusEnum.EXCEPT_NO_15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查下级节点
|
||||||
|
List<BomNewDQbomChildEntity> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
boolean hasError = cc.stream().map(this::check)
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.stream().anyMatch(e -> !e.equals(EBomExceptionStatusEnum.OK));
|
||||||
|
if (status == EBomExceptionStatusEnum.OK && hasError) {
|
||||||
|
status = EBomExceptionStatusEnum.EXCEPT_NO_14;
|
||||||
|
}
|
||||||
|
|
||||||
|
child.setExceptionStatus(status.getValue());
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
package com.nflg.product.bomnew.service;
|
package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.nflg.product.bomnew.mapper.master.BomNewDQbomChildMapper;
|
import com.nflg.product.bomnew.mapper.master.BomNewDQbomChildMapper;
|
||||||
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 曹鹏飞
|
* @author 曹鹏飞
|
||||||
* @date 2024/4/7 11:10:58
|
* @date 2024/4/7 11:10:58
|
||||||
|
|
@ -12,4 +15,25 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class DQBomChildService extends ServiceImpl<BomNewDQbomChildMapper, BomNewDQbomChildEntity> {
|
public class DQBomChildService extends ServiceImpl<BomNewDQbomChildMapper, BomNewDQbomChildEntity> {
|
||||||
|
|
||||||
|
public void deleteAllChildren(Long parentRowId) {
|
||||||
|
this.getBaseMapper().deleteAllChildren(parentRowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BomNewDQbomChildEntity> getByParentRowId(Long parentRowId) {
|
||||||
|
return this.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, parentRowId).list();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BomNewDQbomChildEntity getRoot(String materialNo) {
|
||||||
|
return this.lambdaQuery()
|
||||||
|
.eq(BomNewDQbomChildEntity::getMaterialNo, materialNo)
|
||||||
|
.eq(BomNewDQbomChildEntity::getParentRowId, 0L)
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int deleteNotIn(Long parentRowId, List<Long> rowIds) {
|
||||||
|
LambdaQueryWrapper<BomNewDQbomChildEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(BomNewDQbomChildEntity::getParentRowId, parentRowId);
|
||||||
|
queryWrapper.notIn(BomNewDQbomChildEntity::getRowId, rowIds);
|
||||||
|
return this.getBaseMapper().delete(queryWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,10 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
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.EBomExceptionStatusEnum;
|
|
||||||
import com.nflg.product.bomnew.constant.MaterialGetEnum;
|
|
||||||
import com.nflg.product.bomnew.constant.UserJobEnum;
|
import com.nflg.product.bomnew.constant.UserJobEnum;
|
||||||
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
|
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
|
||||||
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
||||||
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
|
||||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
|
||||||
import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO;
|
import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO;
|
||||||
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
||||||
import com.nflg.product.bomnew.util.*;
|
import com.nflg.product.bomnew.util.*;
|
||||||
|
|
@ -102,34 +99,8 @@ public class DQBomImportService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkExceptionStatus(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
private void checkExceptionStatus(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
||||||
List<String> materialNos = children.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList());
|
BomNewDQbomExceptionCheckService checkService = new BomNewDQbomExceptionCheckService();
|
||||||
List<BaseMaterialVO> materialVOS = materialMainService.getMaterialBaseInfo(materialNos);
|
checkService.check(parents, children);
|
||||||
checkChildExceptionStatus(parents.get(0), parents, children, materialVOS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkChildExceptionStatus(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children, List<BaseMaterialVO> materialVOS) {
|
|
||||||
//BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().get();
|
|
||||||
if (parent.getProjectType().equals("T")) {
|
|
||||||
parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
|
|
||||||
} else {
|
|
||||||
BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(parent.getMaterialNo())).findFirst().orElse(null);
|
|
||||||
if (materialVO == null) {
|
|
||||||
parent.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_7.getValue());
|
|
||||||
} else if (materialVO.getMaterialState().equals(MaterialGetEnum.MaterialStateEnum.STATE_NO_4.getValue())) {
|
|
||||||
parent.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_2.getValue());
|
|
||||||
} else if (!materialVO.getMaterialName().equals(parent.getMaterialName())) {
|
|
||||||
parent.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_15.getValue());
|
|
||||||
} else {
|
|
||||||
parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<String> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId()))
|
|
||||||
.map(BomNewDQbomChildEntity::getMaterialNo)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
List<BomNewDQbomParentEntity> pp = parents.stream().filter(p -> cc.contains(p.getMaterialNo())).collect(Collectors.toList());
|
|
||||||
for (BomNewDQbomParentEntity p : pp) {
|
|
||||||
checkChildExceptionStatus(p, parents, children, materialVOS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) throws JsonProcessingException {
|
private void checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) throws JsonProcessingException {
|
||||||
|
|
@ -197,7 +168,7 @@ public class DQBomImportService {
|
||||||
List<BomNewDQbomChildEntity> children = new ArrayList<>();
|
List<BomNewDQbomChildEntity> children = new ArrayList<>();
|
||||||
Map<Integer, Long> parentRowIdMap = new HashMap<>();
|
Map<Integer, Long> parentRowIdMap = new HashMap<>();
|
||||||
Map<Integer, Integer> orderMap = new HashMap<>();
|
Map<Integer, Integer> orderMap = new HashMap<>();
|
||||||
for (int index = 0; index < datas.size(); index++) {
|
for (int index = 0, count = datas.size(); index < count; index++) {
|
||||||
DQbomExcelVO data = datas.get(index);
|
DQbomExcelVO data = datas.get(index);
|
||||||
|
|
||||||
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
|
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
|
||||||
|
|
@ -209,7 +180,7 @@ public class DQBomImportService {
|
||||||
.list()
|
.list()
|
||||||
.stream().findFirst().orElse(null)
|
.stream().findFirst().orElse(null)
|
||||||
);
|
);
|
||||||
if (parent == null) {
|
if (parent == null && (count - 1 != index || datas.get(index + 1).getLevel() > data.getLevel())) {
|
||||||
parent = new BomNewDQbomParentEntity();
|
parent = new BomNewDQbomParentEntity();
|
||||||
parent.setRowId(IdWorker.getId());
|
parent.setRowId(IdWorker.getId());
|
||||||
parent.setLevel(data.getLevel());
|
parent.setLevel(data.getLevel());
|
||||||
|
|
@ -226,14 +197,16 @@ public class DQBomImportService {
|
||||||
parent.setCreatedName(SessionUtil.getRealName());
|
parent.setCreatedName(SessionUtil.getRealName());
|
||||||
parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue());
|
parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue());
|
||||||
parent.setRemark(data.getRemark());
|
parent.setRemark(data.getRemark());
|
||||||
if (index == datas.size() - 1 || datas.get(index + 1).getLevel() <= data.getLevel()) {
|
// if (index == datas.size() - 1 || datas.get(index + 1).getLevel() <= data.getLevel()) {
|
||||||
parent.setBomExist(0);
|
// parent.setBomExist(0);
|
||||||
} else {
|
// } else {
|
||||||
parent.setBomExist(1);
|
parent.setBomExist(1);
|
||||||
}
|
// }
|
||||||
parents.add(parent);
|
parents.add(parent);
|
||||||
}
|
}
|
||||||
|
if (parent != null) {
|
||||||
parentRowIdMap.put(data.getLevel(), parent.getRowId());
|
parentRowIdMap.put(data.getLevel(), parent.getRowId());
|
||||||
|
}
|
||||||
|
|
||||||
BomNewDQbomChildEntity child = new BomNewDQbomChildEntity();
|
BomNewDQbomChildEntity child = new BomNewDQbomChildEntity();
|
||||||
child.setRowId(IdWorker.getId());
|
child.setRowId(IdWorker.getId());
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,22 @@ public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, Bom
|
||||||
.set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now())
|
.set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now())
|
||||||
.update();
|
.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetBomExist(Long rowId) {
|
||||||
|
this.getBaseMapper().resetBomExist(rowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean existsMaterialNo(String materialNo) {
|
||||||
|
return this.lambdaQuery()
|
||||||
|
.eq(BomNewDQbomParentEntity::getMaterialNo, materialNo)
|
||||||
|
.eq(BomNewDQbomParentEntity::getLastVersionIs, 1)
|
||||||
|
.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BomNewDQbomParentEntity> getLatestByMaterialNo(List<String> materialNos) {
|
||||||
|
return this.lambdaQuery()
|
||||||
|
.in(BomNewDQbomParentEntity::getMaterialNo, materialNos)
|
||||||
|
.eq(BomNewDQbomParentEntity::getLastVersionIs, 1)
|
||||||
|
.list();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,21 @@
|
||||||
package com.nflg.product.bomnew.service;
|
package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||||
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
|
||||||
|
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
|
||||||
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
|
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
|
||||||
|
import com.nflg.product.bomnew.pojo.query.BomNewDQbomSaveQuery;
|
||||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||||
|
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomSaveVO;
|
||||||
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
|
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
|
||||||
|
import com.nflg.product.bomnew.util.VUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -29,6 +38,9 @@ public class DQBomService {
|
||||||
@Resource
|
@Resource
|
||||||
MaterialMainService materialMainService;
|
MaterialMainService materialMainService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
UserRoleService userRoleService;
|
||||||
|
|
||||||
public Page<BomNewDQbomVO> getPageList(BomNewDQbomPageQuery query) {
|
public Page<BomNewDQbomVO> getPageList(BomNewDQbomPageQuery query) {
|
||||||
Page<BomNewDQbomVO> ret = dQBomParentService.getBaseMapper().getPageList(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode());
|
Page<BomNewDQbomVO> ret = dQBomParentService.getBaseMapper().getPageList(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode());
|
||||||
initMaterialInfo(ret.getRecords());
|
initMaterialInfo(ret.getRecords());
|
||||||
|
|
@ -36,6 +48,7 @@ public class DQBomService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BomNewDQbomVO> getChild(Long bomRowId) {
|
public List<BomNewDQbomVO> getChild(Long bomRowId) {
|
||||||
|
VUtils.isTure(bomRowId == 0).throwMessage("无效的参数");
|
||||||
List<BomNewDQbomVO> data = dQBomParentService.getBaseMapper().getChild(bomRowId);
|
List<BomNewDQbomVO> data = dQBomParentService.getBaseMapper().getChild(bomRowId);
|
||||||
initMaterialInfo(data);
|
initMaterialInfo(data);
|
||||||
return data;
|
return data;
|
||||||
|
|
@ -53,4 +66,42 @@ public class DQBomService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkException(List<Long> rootRowIds) {
|
||||||
|
BomNewDQbomExceptionCheckService checkService = new BomNewDQbomExceptionCheckService();
|
||||||
|
rootRowIds.forEach(checkService::check);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
* @param query 请求参数
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void save(BomNewDQbomSaveQuery query) {
|
||||||
|
VUtils.isTure(query.getParentRowId() == 0).throwMessage("无效的参数");
|
||||||
|
|
||||||
|
BomNewDQbomParentEntity parent = dQBomParentService.getBaseMapper().selectById(query.getParentRowId());
|
||||||
|
VUtils.isTure(ObjectUtil.isNull(parent)).throwMessage("bom不存在");
|
||||||
|
|
||||||
|
VUtils.isTure(!parent.getCreatedBy().equals(SessionUtil.getUserCode())).throwMessage("不能修改他人的数据");
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(query.getChildren())) {
|
||||||
|
dQBomChildService.deleteAllChildren(query.getParentRowId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BomNewDQbomSaveVO> datas = query.getChildren();
|
||||||
|
//删除
|
||||||
|
dQBomChildService.deleteNotIn(parent.getRowId(), datas.stream().map(BomNewDQbomSaveVO::getRowId)
|
||||||
|
.filter(d -> ObjectUtil.isNotNull(d) && d > 0L)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
//处理子级
|
||||||
|
List<BomNewDQbomChildEntity> children = Convert.toList(BomNewDQbomChildEntity.class, datas);
|
||||||
|
children.forEach(c -> {
|
||||||
|
c.setParentRowId(query.getParentRowId());
|
||||||
|
});
|
||||||
|
|
||||||
|
dQBomParentService.resetBomExist(query.getParentRowId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.nflg.product.bomnew.mapper.master.BomNewDQbomChildMapper">
|
||||||
|
<delete id="deleteAllChildren">
|
||||||
|
DELETE
|
||||||
|
FROM t_bom_new_dqbom_child
|
||||||
|
WHERE parent_row_id = #{parentRowId};
|
||||||
|
UPDATE t_bom_new_dqbom_parent
|
||||||
|
SET bom_exist=0
|
||||||
|
WHERE row_id = #{parentRowId};
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
||||||
|
|
@ -64,4 +64,10 @@
|
||||||
WHERE c.parent_row_id = #{bomRowId}
|
WHERE c.parent_row_id = #{bomRowId}
|
||||||
ORDER BY c.order_number
|
ORDER BY c.order_number
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="resetBomExist">
|
||||||
|
UPDATE t_bom_new_dqbom_parent p
|
||||||
|
SET p.bom_exist = (IF(EXISTS (SELECT 1 FROM t_bom_new_dqbom_child WHERE parent_row_id = p.row_id), 1, 0))
|
||||||
|
WHERE p.row_id = #{rowId};
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue