| | |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerDto; |
| | | import com.ruoyi.purchase.mapper.ProductRecordMapper; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.mapper.TicketRegistrationMapper; |
| | | import com.ruoyi.purchase.pojo.ProductRecord; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.purchase.pojo.TicketRegistration; |
| | | import com.ruoyi.purchase.service.IPurchaseLedgerService; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | |
| | | |
| | | private final ProductModelMapper productModelMapper; |
| | | |
| | | private final TicketRegistrationMapper ticketRegistrationMapper; |
| | | |
| | | private final ProductRecordMapper productRecordMapper; |
| | | |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | |
| | | // 4. 处理子表数据 |
| | | List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData(); |
| | | if (productList != null && !productList.isEmpty()) { |
| | | handleSalesLedgerProducts(purchaseLedger.getId(), purchaseLedgerDto.getProductId(), purchaseLedgerDto.getProductModelId(), productList, purchaseLedgerDto.getType()); |
| | | handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType()); |
| | | } |
| | | |
| | | // 5. 迁移临时文件到正式目录 |
| | |
| | | return 1; |
| | | } |
| | | |
| | | private void handleSalesLedgerProducts(Long salesLedgerId, Long productId, Long productModelId, List<SalesLedgerProduct> products, Integer type) { |
| | | Product pro = productMapper.selectById(productId); |
| | | ProductModel productModel = productModelMapper.selectById(productModelId); |
| | | private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) { |
| | | if (products == null || products.isEmpty()) { |
| | | throw new BaseException("产品信息不存在"); |
| | | } |
| | | |
| | | // 按ID分组,区分新增和更新的记录 |
| | | // 提前收集所有需要查询的ID |
| | | Set<Long> productIds = products.stream() |
| | | .map(SalesLedgerProduct::getProductId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | Set<Long> modelIds = products.stream() |
| | | .map(SalesLedgerProduct::getProductModelId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | // 一次性查询产品和型号信息 |
| | | Map<Long, String> productMap = new HashMap<>(); |
| | | if (!productIds.isEmpty()) { |
| | | List<Product> productList = productMapper.selectBatchIds(productIds); |
| | | productList.forEach(p -> productMap.put(p.getId(), p.getProductName())); |
| | | } |
| | | |
| | | Map<Long, String> modelMap = new HashMap<>(); |
| | | if (!modelIds.isEmpty()) { |
| | | List<ProductModel> modelList = productModelMapper.selectBatchIds(modelIds); |
| | | modelList.forEach(m -> modelMap.put(m.getId(), m.getModel())); |
| | | } |
| | | |
| | | // 设置字段 |
| | | for (SalesLedgerProduct product : products) { |
| | | product.setSalesLedgerId(salesLedgerId); |
| | | |
| | | Long productId = product.getProductId(); |
| | | if (productId != null && productMap.containsKey(productId)) { |
| | | product.setProductCategory(productMap.get(productId)); |
| | | } |
| | | |
| | | Long productModelId = product.getProductModelId(); |
| | | if (productModelId != null && modelMap.containsKey(productModelId)) { |
| | | product.setSpecificationModel(modelMap.get(productModelId)); |
| | | } |
| | | } |
| | | |
| | | // 分组处理 |
| | | Map<Boolean, List<SalesLedgerProduct>> partitionedProducts = products.stream() |
| | | .peek(p -> { |
| | | p.setSalesLedgerId(salesLedgerId); |
| | | p.setProductId(productId); |
| | | p.setProductCategory(pro.getProductName()); |
| | | p.setProductModelId(productModelId); |
| | | p.setSpecificationModel(productModel.getModel()); |
| | | }) |
| | | .collect(Collectors.partitioningBy(p -> p.getId() != null)); |
| | | |
| | | List<SalesLedgerProduct> updateList = partitionedProducts.get(true); |
| | |
| | | |
| | | @Override |
| | | public int deletePurchaseLedgerByIds(Long[] ids) { |
| | | if (ids == null || ids.length == 0) { |
| | | throw new BaseException("请选中至少一条数据"); |
| | | } |
| | | // 批量删除关联的采购台账产品 |
| | | LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, ids) |
| | | .eq(SalesLedgerProduct::getType, "2"); |
| | | salesLedgerProductMapper.delete(queryWrapper); |
| | | // 批量删除关联的采购台账的来票登记 |
| | | LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getSalesLedgerId,ids); |
| | | ticketRegistrationMapper.delete(ticketRegistrationLambdaQueryWrapper); |
| | | // 批量删除关联的采购台账的来票登记记录 |
| | | LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids); |
| | | productRecordMapper.delete(productRecordLambdaQueryWrapper); |
| | | // 批量删除采购台账 |
| | | return purchaseLedgerMapper.deleteBatchIds(Arrays.asList(ids)); |
| | | } |
| | | |
| | |
| | | queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, 2); |
| | | List<SalesLedgerProduct> productList = salesLedgerProductMapper.selectList(queryWrapper); |
| | | productList.forEach(product -> { |
| | | product.setFutureTickets(product.getFutureTickets() != null ? product.getFutureTickets() : product.getQuantity().longValue()); |
| | | product.setFutureTicketsAmount(product.getFutureTicketsAmount() != null ? product.getFutureTicketsAmount() : product.getTaxInclusiveTotalPrice()); |
| | | product.setTicketsNum(null); |
| | | product.setTicketsAmount(null); |
| | | }); |
| | | resultDto.setProductData(productList); |
| | | |
| | | return resultDto; |
| | | } |
| | | |
| | |
| | | ).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public PurchaseLedgerDto getPurchaseNoById(Long id) { |
| | | PurchaseLedgerDto purchaseLedgerDto = new PurchaseLedgerDto(); |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(id); |
| | | BeanUtils.copyProperties(purchaseLedger, purchaseLedgerDto); |
| | | // TicketRegistration ticketRegistration = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getPurchaseLedgerId, id)); |
| | | // if (ticketRegistration != null) { |
| | | // purchaseLedgerDto.setInvoiceNumber(ticketRegistration.getInvoiceNumber()); |
| | | // purchaseLedgerDto.setInvoiceAmount(ticketRegistration.getInvoiceAmount()); |
| | | // purchaseLedgerDto.setTicketRegistrationId(ticketRegistration.getId()); |
| | | // } |
| | | return purchaseLedgerDto; |
| | | } |
| | | |
| | | /** |
| | | * 下划线命名转驼峰命名 |
| | | */ |