| | |
| | | |
| | | 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; |
| | |
| | | |
| | | @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) { |
| | |
| | | } |
| | | |
| | | @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>() |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | // 回写新增节点的 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 { |