| | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.mapper.SupplierManageMapper; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.pojo.SupplierManage; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | |
| | | private final SupplierManageMapper supplierManageMapper; |
| | | |
| | | private final ProductMapper productMapper; |
| | | |
| | | private final ProductModelMapper productModelMapper; |
| | | |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | |
| | | public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) { |
| | | LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>(); |
| | | if (StringUtils.isNotBlank(purchaseLedger.getPurchaseContractNumber())) { |
| | | queryWrapper.like(PurchaseLedger::getPurchaseContractNumber,purchaseLedger.getPurchaseContractNumber()); |
| | | queryWrapper.like(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber()); |
| | | } |
| | | return purchaseLedgerMapper.selectList(queryWrapper); |
| | | } |
| | |
| | | public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException { |
| | | |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId()); |
| | | |
| | | //业务员 |
| | | SysUser businessPerson = userMapper.selectUserById(purchaseLedgerDto.getBusinessPersonId()); |
| | | |
| | | if (salesLedger == null) { |
| | | throw new BaseException("销售台账不存在"); |
| | |
| | | purchaseLedger.setSupplierName(supplierManage.getSupplierName()); |
| | | purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId()); |
| | | purchaseLedger.setRecorderName(sysUser.getNickName()); |
| | | purchaseLedger.setBusinessPersonId(purchaseLedgerDto.getBusinessPersonId()); |
| | | purchaseLedger.setBusinessPerson(businessPerson.getNickName()); |
| | | purchaseLedger.setPhoneNumber(sysUser.getPhonenumber()); |
| | | |
| | | // 3. 新增或更新主表 |
| | |
| | | // 4. 处理子表数据 |
| | | List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData(); |
| | | if (productList != null && !productList.isEmpty()) { |
| | | handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType()); |
| | | handleSalesLedgerProducts(purchaseLedger.getId(), purchaseLedgerDto.getProductId(), purchaseLedgerDto.getProductModelId(), productList, purchaseLedgerDto.getType()); |
| | | } |
| | | |
| | | // 5. 迁移临时文件到正式目录 |
| | |
| | | return 1; |
| | | } |
| | | |
| | | private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) { |
| | | private void handleSalesLedgerProducts(Long salesLedgerId, Long productId, Long productModelId, List<SalesLedgerProduct> products, Integer type) { |
| | | Product pro = productMapper.selectById(productId); |
| | | ProductModel productModel = productModelMapper.selectById(productModelId); |
| | | |
| | | // 按ID分组,区分新增和更新的记录 |
| | | Map<Boolean, List<SalesLedgerProduct>> partitionedProducts = products.stream() |
| | | .peek(p -> p.setSalesLedgerId(salesLedgerId)) |
| | | .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); |
| | |
| | | resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo()); |
| | | resultDto.setSupplierName(purchaseLedger.getSupplierName()); |
| | | resultDto.setProjectName(purchaseLedger.getProjectName()); |
| | | resultDto.setBusinessPersonId(purchaseLedger.getBusinessPersonId()); |
| | | |
| | | // 查询并设置关联产品 |
| | | LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | @Override |
| | | public List getPurchasesNo() { |
| | | LambdaQueryWrapper<PurchaseLedger> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber,PurchaseLedger::getSupplierId); |
| | | queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber, PurchaseLedger::getSupplierId); |
| | | |
| | | // 获取原始查询结果 |
| | | List<Map<String, Object>> result = purchaseLedgerMapper.selectMaps(queryWrapper); |