From 0050395dfb05425f0a929bc1587b971d78f1e95e Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期一, 26 五月 2025 17:47:28 +0800 Subject: [PATCH] 首页数据排序 --- src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 212 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java index c8ef0fc..3be1a26 100644 --- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java +++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java @@ -2,7 +2,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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; import com.ruoyi.other.mapper.TempFileMapper; @@ -10,14 +17,18 @@ 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.SalesLedgerFileMapper; +import com.ruoyi.sales.mapper.CommonFileMapper; import com.ruoyi.sales.mapper.SalesLedgerMapper; import com.ruoyi.sales.mapper.SalesLedgerProductMapper; +import com.ruoyi.sales.pojo.CommonFile; import com.ruoyi.sales.pojo.SalesLedger; -import com.ruoyi.sales.pojo.SalesLedgerFile; import com.ruoyi.sales.pojo.SalesLedgerProduct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -27,6 +38,7 @@ import org.springframework.stereotype.Service; import java.io.IOException; +import java.math.BigDecimal; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -34,10 +46,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; /** @@ -60,14 +69,28 @@ private final TempFileMapper tempFileMapper; - private final SalesLedgerFileMapper salesLedgerFileMapper; + private final CommonFileMapper commonFileMapper; + + private final SupplierManageMapper supplierManageMapper; + + private final ProductMapper productMapper; + + private final ProductModelMapper productModelMapper; + + private final TicketRegistrationMapper ticketRegistrationMapper; + + private final ProductRecordMapper productRecordMapper; @Value("${file.upload-dir}") private String uploadDir; @Override public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) { - return purchaseLedgerMapper.selectList(new LambdaQueryWrapper<>()); + LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotBlank(purchaseLedger.getPurchaseContractNumber())) { + queryWrapper.like(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber()); + } + return purchaseLedgerMapper.selectList(queryWrapper); } @Override @@ -78,15 +101,20 @@ if (salesLedger == null) { throw new BaseException("閿�鍞彴璐︿笉瀛樺湪"); } + //褰曞叆浜� SysUser sysUser = userMapper.selectUserById(purchaseLedgerDto.getRecorderId()); + + SupplierManage supplierManage = supplierManageMapper.selectById(purchaseLedgerDto.getSupplierId()); // DTO杞珽ntity PurchaseLedger purchaseLedger = new PurchaseLedger(); BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger); purchaseLedger.setTenantId(salesLedger.getTenantId()); purchaseLedger.setSalesContractNo(salesLedger.getSalesContractNo()); + purchaseLedger.setSupplierName(supplierManage.getSupplierName()); purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId()); purchaseLedger.setRecorderName(sysUser.getNickName()); + purchaseLedger.setPhoneNumber(sysUser.getPhonenumber()); // 3. 鏂板鎴栨洿鏂颁富琛� if (purchaseLedger.getId() == null) { @@ -99,7 +127,6 @@ List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData(); if (productList != null && !productList.isEmpty()) { handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType()); - } // 5. 杩佺Щ涓存椂鏂囦欢鍒版寮忕洰褰� @@ -111,9 +138,51 @@ } private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) { - // 鎸塈D鍒嗙粍锛屽尯鍒嗘柊澧炲拰鏇存柊鐨勮褰� + if (products == null || products.isEmpty()) { + throw new BaseException("浜у搧淇℃伅涓嶅瓨鍦�"); + } + + // 鎻愬墠鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑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)) .collect(Collectors.partitioningBy(p -> p.getId() != null)); List<SalesLedgerProduct> updateList = partitionedProducts.get(true); @@ -132,6 +201,18 @@ salesLedgerProduct.setType(type); salesLedgerProductMapper.insert(salesLedgerProduct); } + } + + // 璁$畻鎬诲惈绋庨噾棰� + BigDecimal totalTaxInclusiveAmount = products.stream() + .map(SalesLedgerProduct::getTaxInclusiveTotalPrice) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + // 鏇存柊涓昏〃鐨勬�婚噾棰濆瓧娈� + if (salesLedgerId != null) { + // 鐩存帴鏇存柊鎸囧畾ID鐨勮褰曠殑contractAmount瀛楁涓簍otalTaxInclusiveAmount + purchaseLedgerMapper.updateContractAmountById(salesLedgerId, totalTaxInclusiveAmount); } } @@ -186,12 +267,13 @@ log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath); // 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛� - SalesLedgerFile fileRecord = new SalesLedgerFile(); - fileRecord.setLedgerId(businessId); + CommonFile fileRecord = new CommonFile(); + fileRecord.setCommonId(businessId); fileRecord.setName(originalFilename); fileRecord.setUrl(formalFilePath.toString()); fileRecord.setCreateTime(LocalDateTime.now()); - salesLedgerFileMapper.insert(fileRecord); + fileRecord.setType("2"); + commonFileMapper.insert(fileRecord); // 鍒犻櫎涓存椂鏂囦欢璁板綍 tempFileMapper.deleteById(tempFile); @@ -207,6 +289,23 @@ @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)); } @@ -225,9 +324,9 @@ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); // 3.鏌ヨ涓婁紶鏂囦欢 - LambdaQueryWrapper<SalesLedgerFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>(); - salesLedgerFileWrapper.eq(SalesLedgerFile::getLedgerId, purchaseLedger.getId()); - List<SalesLedgerFile> salesLedgerFiles = salesLedgerFileMapper.selectList(salesLedgerFileWrapper); + LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>(); + salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId()); + List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper); // 4. 杞崲 DTO PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); @@ -239,4 +338,100 @@ } return resultDto; } + + @Override + public List getProduct(PurchaseLedgerDto purchaseLedgerDto) { + LambdaQueryWrapper<PurchaseLedger> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber); + + // 鑾峰彇鍘熷鏌ヨ缁撴灉 + List<Map<String, Object>> result = purchaseLedgerMapper.selectMaps(queryWrapper); + + // 灏嗕笅鍒掔嚎鍛藉悕杞崲涓洪┘宄板懡鍚� + return result.stream().map(map -> map.entrySet().stream() + .collect(Collectors.toMap( + entry -> underlineToCamel(entry.getKey()), + Map.Entry::getValue)) + ).collect(Collectors.toList()); + } + + @Override + public PurchaseLedgerDto getInfo(PurchaseLedgerDto purchaseLedgerDto) { + PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseLedgerDto.getId()); + if (purchaseLedger == null) { + throw new BaseException("閲囪喘鍙拌处涓嶅瓨鍦�"); + } + // 鍒涘缓骞跺~鍏匘TO + PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); + resultDto.setSalesContractNoId(purchaseLedger.getSalesLedgerId()); + resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo()); + resultDto.setSupplierName(purchaseLedger.getSupplierName()); + resultDto.setProjectName(purchaseLedger.getProjectName()); + + // 鏌ヨ骞惰缃叧鑱斾骇鍝� + LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>(); + 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; + } + + @Override + public List getPurchasesNo() { + LambdaQueryWrapper<PurchaseLedger> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber, PurchaseLedger::getSupplierId); + + // 鑾峰彇鍘熷鏌ヨ缁撴灉 + List<Map<String, Object>> result = purchaseLedgerMapper.selectMaps(queryWrapper); + + // 灏嗕笅鍒掔嚎鍛藉悕杞崲涓洪┘宄板懡鍚� + return result.stream().map(map -> map.entrySet().stream() + .collect(Collectors.toMap( + entry -> underlineToCamel(entry.getKey()), + Map.Entry::getValue)) + ).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; + } + + /** + * 涓嬪垝绾垮懡鍚嶈浆椹煎嘲鍛藉悕 + */ + private String underlineToCamel(String param) { + if (param == null || "".equals(param.trim())) { + return ""; + } + int len = param.length(); + StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) { + char c = param.charAt(i); + if (c == '_') { + if (++i < len) { + sb.append(Character.toUpperCase(param.charAt(i))); + } + } else { + sb.append(Character.toLowerCase(c)); + } + } + return sb.toString(); + } } -- Gitblit v1.9.3