gongchunyi
8 小时以前 346d463346701e8714b3a3a3ebb21e21960b5484
src/main/java/com/ruoyi/production/service/impl/ProductionOrderStructureServiceImpl.java
@@ -2,7 +2,6 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.production.dto.ProductionOrderStructureDto;
import com.ruoyi.production.mapper.ProductionOrderStructureMapper;
import com.ruoyi.production.pojo.ProductionOrderStructure;
@@ -32,13 +31,7 @@
    @Override
    public List<ProductionOrderStructureDto> listByOrderId(Long orderId) {
        List<ProductionOrderStructure> list = list(new LambdaQueryWrapper<ProductionOrderStructure>().eq(ProductionOrderStructure::getOrderId, orderId));
        List<ProductionOrderStructureDto> dtoList = list.stream().map(item -> {
            ProductionOrderStructureDto dto = new ProductionOrderStructureDto();
            BeanUtils.copyProperties(item, dto);
            return dto;
        }).collect(Collectors.toList());
        List<ProductionOrderStructureDto> dtoList = baseMapper.listByOrderId(orderId);
        Map<Long, ProductionOrderStructureDto> map = new HashMap<>();
        for (ProductionOrderStructureDto node : dtoList) {
@@ -58,12 +51,13 @@
    }
    @Override
    public void addOrUpdateBomStructs(ProductionOrderStructureDto instanceDto) {
        Long orderId = instanceDto.getOrderId();
    public void addOrUpdateBomStructs(Long orderId, List<ProductionOrderStructureDto> list) {
        // 扁平化前端传入的树
        List<ProductionOrderStructureDto> flatList = new ArrayList<>();
        flattenTree(instanceDto.getChildren(), flatList);
        for (ProductionOrderStructureDto root : list) {
            flatList.add(root);
            flattenTree(root.getChildren(), flatList);
        }
        // 查询数据库已有数据
        List<ProductionOrderStructure> dbList = list(new LambdaQueryWrapper<ProductionOrderStructure>()
@@ -90,7 +84,7 @@
        for (ProductionOrderStructureDto dto : flatList) {
            ProductionOrderStructure entity = new ProductionOrderStructure();
            BeanUtils.copyProperties(dto, entity);
            org.springframework.beans.BeanUtils.copyProperties(dto, entity);
            entity.setOrderId(orderId);
            if (dto.getId() == null) {
                entity.setId(null);
@@ -110,13 +104,13 @@
        // 回写新增节点的 parentId
        List<ProductionOrderStructure> parentFixList = new ArrayList<>();
        Long realParentId;
        for (ProductionOrderStructureDto dto : flatList) {
            if (dto.getId() != null) continue;
            ProductionOrderStructure child = tempEntityMap.get(dto.getTempId());
            if (child == null) continue;
            String parentTempId = dto.getParentTempId();
            if (parentTempId != null && !parentTempId.isEmpty()) {
                Long realParentId;
                if (tempEntityMap.containsKey(parentTempId)) {
                    realParentId = tempEntityMap.get(parentTempId).getId();
                } else {