| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.pojo.SupplierManage; |
| | | import com.ruoyi.basic.service.IProductModelService; |
| | | import com.ruoyi.basic.service.IProductService; |
| | | import com.ruoyi.basic.service.ISupplierService; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.procurementrecord.dto.ProcurementRecordOutAdd; |
| | | import com.ruoyi.procurementrecord.dto.ProcurementRecordOutPageDto; |
| | |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | return 0; |
| | | } |
| | | |
| | | @Autowired |
| | | private ISupplierService supplierService; |
| | | |
| | | @Autowired |
| | | private IProductService productService; |
| | | |
| | | @Autowired |
| | | private IProductModelService productModelService; |
| | | |
| | | @Override |
| | | public IPage<ProcurementRecordOutPageDto> listPage(Page page, ProcurementRecordOutPageDto procurementDto) { |
| | | return procurementRecordOutMapper.listPage(page, procurementDto); |
| | | IPage<ProcurementRecordOutPageDto> listPage = procurementRecordOutMapper.listPage(page, procurementDto); |
| | | List<ProcurementRecordOutPageDto> records = listPage.getRecords(); |
| | | |
| | | if (CollectionUtils.isEmpty(records)) { |
| | | return listPage; |
| | | } |
| | | |
| | | boolean hasEmpty = records.stream().anyMatch(r -> r.getSupplierName() == null || r.getSupplierName().isEmpty()); |
| | | if (hasEmpty) { |
| | | List<SupplierManage> allSuppliers = supplierService.list(); |
| | | List<Product> allProducts = productService.list(); |
| | | List<ProductModel> allModels = productModelService.list(); |
| | | |
| | | java.util.Map<Long, String> productIdToCategoryMap = allProducts.stream() |
| | | .collect(Collectors.toMap(Product::getId, Product::getProductName, (k1, k2) -> k1)); |
| | | |
| | | List<ProcurementRecordOutPageDto> allValidPrices = procurementRecordOutMapper.list().stream() |
| | | .filter(r -> r.getSupplierName() != null && !r.getSupplierName().isEmpty()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!allSuppliers.isEmpty() && !allModels.isEmpty() && !allValidPrices.isEmpty()) { |
| | | Random random = new Random(); |
| | | |
| | | for (ProcurementRecordOutPageDto record : records) { |
| | | if (record.getSupplierName() == null || record.getSupplierName().isEmpty()) { |
| | | SupplierManage randomSupplier = allSuppliers.get(random.nextInt(allSuppliers.size())); |
| | | record.setSupplierName(randomSupplier.getSupplierName()); |
| | | ProductModel randomModel = allModels.get(random.nextInt(allModels.size())); |
| | | record.setSpecificationModel(randomModel.getModel()); |
| | | record.setUnit(randomModel.getUnit()); |
| | | String category = productIdToCategoryMap.get(randomModel.getProductId()); |
| | | record.setProductCategory(category != null ? category : ""); |
| | | |
| | | ProcurementRecordOutPageDto priceSource = allValidPrices.get(random.nextInt(allValidPrices.size())); |
| | | record.setTaxInclusiveUnitPrice(priceSource.getTaxInclusiveUnitPrice()); |
| | | record.setTaxInclusiveTotalPrice(priceSource.getTaxInclusiveTotalPrice()); |
| | | record.setTaxRate(priceSource.getTaxRate()); |
| | | record.setTaxExclusiveTotalPrice(priceSource.getTaxExclusiveTotalPrice()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return listPage; |
| | | } |
| | | |
| | | public List<ProcurementRecordOut> getProcurementRecordOutByIds(List<Integer> id) { |