| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.StorageBlobDTO; |
| | | import com.ruoyi.basic.dto.StorageBlobVO; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | 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.basic.utils.FileUtil; |
| | | import com.ruoyi.common.enums.PurchaseApplicationStatusEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private final SysUserMapper sysUserMapper; |
| | | private final ProductMapper productMapper; |
| | | private final ProductModelMapper productModelMapper; |
| | | private final FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public List<PurchaseApplication> selectApplicationList(PurchaseApplicationDto purchaseApplicationDto) { |
| | |
| | | PurchaseApplicationDto resultDto = new PurchaseApplicationDto(); |
| | | BeanUtils.copyProperties(application, resultDto); |
| | | resultDto.setProductData(listProducts(id)); |
| | | resultDto.setStorageBlobVOS(listAttachments(id)); |
| | | return resultDto; |
| | | } |
| | | |
| | |
| | | this.save(application); |
| | | |
| | | saveProducts(application.getId(), purchaseApplicationDto.getProductData()); |
| | | saveAttachments(application.getId(), purchaseApplicationDto.getStorageBlobDTOS()); |
| | | return application.getId(); |
| | | } |
| | | |
| | |
| | | purchaseApplicationProductMapper.delete(Wrappers.<PurchaseApplicationProduct>lambdaQuery() |
| | | .eq(PurchaseApplicationProduct::getPurchaseApplicationId, purchaseApplicationDto.getId())); |
| | | saveProducts(purchaseApplicationDto.getId(), purchaseApplicationDto.getProductData()); |
| | | saveAttachments(purchaseApplicationDto.getId(), purchaseApplicationDto.getStorageBlobDTOS()); |
| | | } |
| | | return updated; |
| | | } |
| | |
| | | .set(PurchaseApplication::getPurchaseLedgerId, purchaseLedgerId) |
| | | .set(PurchaseApplication::getConvertTime, LocalDateTime.now())); |
| | | return purchaseLedgerId; |
| | | } |
| | | |
| | | /** |
| | | * 保存附件:先清空该申请单的旧关联,再按前端提交的文件全量重建 |
| | | */ |
| | | private void saveAttachments(Long applicationId, List<StorageBlobDTO> storageBlobDTOS) { |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_APPLICATION, |
| | | applicationId, storageBlobDTOS); |
| | | } |
| | | |
| | | private List<StorageBlobVO> listAttachments(Long applicationId) { |
| | | return fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId( |
| | | ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_APPLICATION, applicationId); |
| | | } |
| | | |
| | | private List<PurchaseApplicationProduct> listProducts(Long applicationId) { |
| | |
| | | PurchaseLedgerDto purchaseLedgerDto = new PurchaseLedgerDto(); |
| | | purchaseLedgerDto.setSupplierId(application.getSupplierId()); |
| | | purchaseLedgerDto.setSupplierName(supplierManage.getSupplierName()); |
| | | purchaseLedgerDto.setRecorderId(application.getApplicantId()); |
| | | purchaseLedgerDto.setRecorderId(application.getRecorderId() != null |
| | | ? application.getRecorderId() : application.getApplicantId()); |
| | | purchaseLedgerDto.setRecorderName(application.getApplicantName()); |
| | | purchaseLedgerDto.setSalesContractNo(application.getSalesContractNo()); |
| | | purchaseLedgerDto.setSalesLedgerId(application.getSalesLedgerId()); |
| | |
| | | purchaseLedgerDto.setRemarks(application.getRemarks()); |
| | | purchaseLedgerDto.setPaymentMethod(application.getPaymentMethod()); |
| | | purchaseLedgerDto.setContractAmount(application.getContractAmount()); |
| | | LocalDate entryDate = application.getApplyDate() != null ? application.getApplyDate() : LocalDate.now(); |
| | | purchaseLedgerDto.setPurchaseContractNumber(application.getPurchaseContractNumber()); |
| | | purchaseLedgerDto.setExecutionDate(toDateOrNull(application.getExecutionDate())); |
| | | purchaseLedgerDto.setBestArrivalDate(toDateOrNull(application.getBestArrivalDate())); |
| | | purchaseLedgerDto.setApplicationSubmitTime(toDateOrNull(application.getApplicationSubmitTime())); |
| | | purchaseLedgerDto.setPurchaseCategory(application.getPurchaseCategory()); |
| | | purchaseLedgerDto.setLogisticsMethod(application.getLogisticsMethod()); |
| | | purchaseLedgerDto.setPickupMethod(application.getPickupMethod()); |
| | | purchaseLedgerDto.setOilDepotId(application.getOilDepotId()); |
| | | purchaseLedgerDto.setCustomerName(application.getCustomerName()); |
| | | purchaseLedgerDto.setPurchaseQuantity(application.getPurchaseQuantity()); |
| | | purchaseLedgerDto.setPurchaseOrderStatus(application.getPurchaseOrderStatus()); |
| | | |
| | | LocalDate entryDate = application.getEntryDate() != null ? application.getEntryDate() |
| | | : (application.getApplyDate() != null ? application.getApplyDate() : LocalDate.now()); |
| | | purchaseLedgerDto.setEntryDate(DateUtils.toDate(entryDate)); |
| | | |
| | | purchaseLedgerDto.setProductData(products.stream() |
| | | .map(this::toSalesLedgerProduct) |
| | | .collect(Collectors.toList())); |
| | | purchaseLedgerDto.setStorageBlobDTOS(toStorageBlobDtos(listAttachments(application.getId()))); |
| | | return purchaseLedgerDto; |
| | | } |
| | | |
| | | private static Date toDateOrNull(LocalDate date) { |
| | | return date == null ? null : DateUtils.toDate(date); |
| | | } |
| | | |
| | | private static Date toDateOrNull(LocalDateTime dateTime) { |
| | | return dateTime == null ? null : DateUtils.toDate(dateTime); |
| | | } |
| | | |
| | | /** |
| | | * 申请单附件原样关联到生成的采购台账:复用同一份 storage_blob,只改关联记录 |
| | | */ |
| | | private List<StorageBlobDTO> toStorageBlobDtos(List<StorageBlobVO> storageBlobVOS) { |
| | | if (storageBlobVOS == null || storageBlobVOS.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return storageBlobVOS.stream() |
| | | .map(vo -> { |
| | | StorageBlobDTO dto = new StorageBlobDTO(); |
| | | dto.setId(vo.getId()); |
| | | return dto; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private SalesLedgerProduct toSalesLedgerProduct(PurchaseApplicationProduct source) { |
| | |
| | | target.setSpecificationModel(source.getSpecificationModel()); |
| | | target.setUnit(source.getUnit()); |
| | | target.setQuantity(source.getQuantity()); |
| | | target.setWarnNum(source.getWarnNum()); |
| | | target.setTaxRate(source.getTaxRate()); |
| | | target.setTaxInclusiveUnitPrice(source.getTaxInclusiveUnitPrice()); |
| | | target.setTaxInclusiveTotalPrice(source.getTaxInclusiveTotalPrice()); |