From 10b88a7ff17caf92f3d4e8a550c1085a70c2517a Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 28 五月 2026 17:43:26 +0800
Subject: [PATCH] Merge dev_New_pro into dev_山西_晋和园_pro

---
 src/main/java/com/ruoyi/account/service/impl/sales/AccountSalesCollectionServiceImpl.java |   96 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/account/service/impl/sales/AccountSalesCollectionServiceImpl.java b/src/main/java/com/ruoyi/account/service/impl/sales/AccountSalesCollectionServiceImpl.java
new file mode 100644
index 0000000..5f328bc
--- /dev/null
+++ b/src/main/java/com/ruoyi/account/service/impl/sales/AccountSalesCollectionServiceImpl.java
@@ -0,0 +1,96 @@
+package com.ruoyi.account.service.impl.sales;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.bean.dto.sales.AccountSalesCollectionDto;
+import com.ruoyi.account.bean.vo.sales.AccountSalesCollectionVo;
+import com.ruoyi.account.bean.vo.sales.SalesOutboundVo;
+import com.ruoyi.account.mapper.AccountStatementDetailsMapper;
+import com.ruoyi.account.mapper.sales.AccountSalesCollectionMapper;
+import com.ruoyi.account.pojo.AccountStatementDetails;
+import com.ruoyi.account.pojo.sales.AccountSalesCollection;
+import com.ruoyi.account.service.sales.AccountSalesCollectionService;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * <p>
+ * 璐㈠姟绠$悊--鏀舵鍗� 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author 鑺杞欢锛堟睙鑻忥級鏈夐檺鍏徃
+ * @since 2026-05-18 03:49:56
+ */
+@Service
+@RequiredArgsConstructor
+public class AccountSalesCollectionServiceImpl extends ServiceImpl<AccountSalesCollectionMapper, AccountSalesCollection> implements AccountSalesCollectionService {
+
+    private final AccountSalesCollectionMapper accountSalesCollectionMapper;
+    private final AccountStatementDetailsMapper accountStatementDetailsMapper;
+    private static final DateTimeFormatter CODE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss");
+
+
+    @Override
+    public IPage<AccountSalesCollectionVo> listPageAccountSalesCollection(Page page, AccountSalesCollectionDto accountSalesCollectionDto) {
+        return accountSalesCollectionMapper.listPageAccountSalesCollection(page, accountSalesCollectionDto);
+    }
+
+    @Override
+    public boolean addAccountSalesCollection(AccountSalesCollection accountSalesCollection) {
+        if (StringUtils.isEmpty(accountSalesCollection.getCollectionNumber())) {
+            accountSalesCollection.setCollectionNumber(genAccountSalesCollectionNo());
+        }
+        String stockOutRecordIds = accountSalesCollection.getStockOutRecordIds();
+        if (stockOutRecordIds != null && !stockOutRecordIds.isEmpty()) {
+            List<Long> ids = Arrays.stream(stockOutRecordIds.split(","))
+                    .map(Long::valueOf)
+                    .toList();
+            if (accountSalesCollectionMapper.existsByStockOutRecordId(ids)){
+                throw new ServiceException("瀛樺湪閲嶅鐨勫嚭搴撳崟");
+            }
+        }
+        return save(accountSalesCollection);
+    }
+
+    @Override
+    public void exportAccountSalesCollection(HttpServletResponse response, AccountSalesCollectionDto accountSalesCollectionDto) {
+        List<AccountSalesCollectionVo> list = accountSalesCollectionMapper.listPageAccountSalesCollection(new Page(1,-1),accountSalesCollectionDto).getRecords();
+        ExcelUtil<AccountSalesCollectionVo> util = new ExcelUtil<>(AccountSalesCollectionVo.class);
+        util.exportExcel(response, list , "鏀舵鍗�");
+    }
+
+    @Override
+    public boolean deleteAccountSalesCollection(List<Long> ids) {
+        //濡傛灉璇ユ敹娆惧崟宸茬粡鐢熸垚瀵硅处鍗曞垯鏃犳硶鍒犻櫎
+        List<AccountSalesCollection> accountSalesCollections = accountSalesCollectionMapper.selectByIds(ids);
+        List<String> strings = accountSalesCollections.stream().map(AccountSalesCollection::getCollectionNumber).toList();
+        List<AccountStatementDetails> accountStatementDetails = accountStatementDetailsMapper.selectList(Wrappers.<AccountStatementDetails>lambdaQuery()
+                .in(AccountStatementDetails::getReceiptNumber, strings));
+        if (CollectionUtils.isNotEmpty(accountStatementDetails)){
+            throw new ServiceException("璇ユ敹娆惧崟宸茬粡鐢熸垚瀵硅处鍗曪紝鏃犳硶鍒犻櫎");
+        }
+        return removeByIds(ids);
+    }
+
+    @Override
+    public List<SalesOutboundVo> getOutboundBatchesByCustomer(Integer customerId) {
+        return accountSalesCollectionMapper.getOutboundBatchesByCustomer(customerId);
+    }
+
+    private String genAccountSalesCollectionNo() {
+        return "SK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10);
+    }
+}

--
Gitblit v1.9.3