From 9f3a45da6d1dc9c71187f15131665eb9806f5588 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 28 十月 2025 15:58:03 +0800
Subject: [PATCH] yys 1.修改配置文件 2.增加模板
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 164 +++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 118 insertions(+), 46 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index ddc9f5a..0cbe9d1 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -8,13 +8,19 @@
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.pojo.AccountExpense;
+import com.ruoyi.account.pojo.AccountIncome;
+import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.basic.mapper.CustomerMapper;
import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
+import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
+import com.ruoyi.production.pojo.SalesLedgerScheduling;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.sales.dto.MonthlyAmountDto;
@@ -59,6 +65,7 @@
@RequiredArgsConstructor
@Slf4j
public class SalesLedgerServiceImpl extends ServiceImpl<SalesLedgerMapper, SalesLedger> implements ISalesLedgerService {
+ private final AccountIncomeService accountIncomeService;
private final SalesLedgerMapper salesLedgerMapper;
@@ -73,6 +80,8 @@
private final ReceiptPaymentMapper receiptPaymentMapper;
private final InvoiceLedgerMapper invoiceLedgerMapper;
+
+ private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
@Autowired
private SysDeptMapper sysDeptMapper;
@@ -91,6 +100,7 @@
return salesLedgerMapper.selectSalesLedgerList(salesLedgerDto);
}
+ @Override
public SalesLedgerDto getSalesLedgerWithProducts(SalesLedgerDto salesLedgerDto) {
// 1. 鏌ヨ涓昏〃
SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerDto.getId());
@@ -101,12 +111,15 @@
// 2. 鏌ヨ瀛愯〃
LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId());
+ productWrapper.eq(SalesLedgerProduct::getType, 1);
List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
for (SalesLedgerProduct product : products) {
product.setOriginalNoInvoiceNum(product.getNoInvoiceNum());
// 鎻愪緵涓存椂鏈紑绁ㄦ暟锛屾湭寮�绁ㄩ噾棰濅緵鍓嶆璁$畻
product.setTempnoInvoiceAmount(product.getNoInvoiceAmount());
product.setTempNoInvoiceNum(product.getNoInvoiceNum());
+ product.setRegister(SecurityUtils.getLoginUser().getUser().getNickName());
+ product.setRegisterDate(LocalDateTime.now());
}
// 3.鏌ヨ涓婁紶鏂囦欢
@@ -195,53 +208,77 @@
}
@Override
- public List<MonthlyAmountDto> getAmountHalfYear() {
+ public List<MonthlyAmountDto> getAmountHalfYear(Integer type) {
LocalDate now = LocalDate.now();
- YearMonth currentMonth = YearMonth.from(now);
+ LocalDateTime currentDateTime = LocalDateTime.now();
- List<MonthlyAmountDto> monthlyAmounts = new ArrayList<>();
+ // 鏍规嵁 type 纭畾鏌ヨ鐨勬椂闂撮棿闅旓紙澶╂暟锛夊拰鎬绘煡璇㈠ぉ鏁�
+ int daysPerPeriod;
+ int totalDays;
+ switch (type) {
+ case 1:
+ daysPerPeriod = 5; // 姣�5澶╂煡涓�娆�
+ totalDays = 30; // 6娆� 脳 5澶� = 30澶�
+ break;
+ case 2:
+ daysPerPeriod = 15; // 姣�15澶╂煡涓�娆�
+ totalDays = 90; // 6娆� 脳 15澶� = 90澶�
+ break;
+ case 3:
+ daysPerPeriod = 30; // 姣�30澶╂煡涓�娆�
+ totalDays = 180; // 6娆� 脳 30澶� = 180澶�
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid type value: " + type);
+ }
+ List<MonthlyAmountDto> result = new ArrayList<>();
+
+ // 寰幆6娆★紝姣忔鏌ヨ涓�涓椂闂存鐨勬暟鎹�
for (int i = 0; i < 6; i++) {
- YearMonth targetMonth = currentMonth.minusMonths(i);
- LocalDate firstDayOfMonth = targetMonth.atDay(1);
- LocalDate firstDayOfNextMonth = targetMonth.plusMonths(1).atDay(1);
+ // 璁$畻褰撳墠鏃堕棿娈电殑璧峰鍜岀粨鏉熸椂闂�
+ LocalDateTime endTime = currentDateTime.minusDays(i * daysPerPeriod);
+ LocalDateTime startTime = endTime.minusDays(daysPerPeriod);
- LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
- LocalDateTime startOfNextMonth = firstDayOfNextMonth.atStartOfDay();
+ // 鏌ヨ鍥炴閲戦
+ LambdaQueryWrapper<ReceiptPayment> receiptPaymentQuery = new LambdaQueryWrapper<>();
+ receiptPaymentQuery
+ .ge(ReceiptPayment::getCreateTime, startTime)
+ .lt(ReceiptPayment::getCreateTime, endTime);
+ List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(receiptPaymentQuery);
- LambdaQueryWrapper<ReceiptPayment> receiptPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
- receiptPaymentLambdaQueryWrapper.ge(ReceiptPayment::getCreateTime, startOfMonth)
- .lt(ReceiptPayment::getCreateTime, startOfNextMonth);
+ // 鏌ヨ寮�绁ㄩ噾棰�
+ LambdaQueryWrapper<InvoiceLedger> invoiceLedgerQuery = new LambdaQueryWrapper<>();
+ invoiceLedgerQuery
+ .ge(InvoiceLedger::getCreateTime, startTime)
+ .lt(InvoiceLedger::getCreateTime, endTime);
+ List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(invoiceLedgerQuery);
- LambdaQueryWrapper<InvoiceLedger> invoiceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
- invoiceLedgerLambdaQueryWrapper.ge(InvoiceLedger::getCreateTime, startOfMonth)
- .lt(InvoiceLedger::getCreateTime, startOfNextMonth);
-
- // 鑾峰彇鍥炴閲戦
- List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(receiptPaymentLambdaQueryWrapper);
- //寮�绁ㄩ噾棰�
- List<InvoiceLedger> invoiceLedgerList = invoiceLedgerMapper.selectList(invoiceLedgerLambdaQueryWrapper);
-
- // 浣跨敤 Stream 姹傚拰
- BigDecimal invoiceAmount = invoiceLedgerList.stream()
- .map(InvoiceLedger::getInvoiceTotal)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
-
- BigDecimal receiptAmount = receiptPaymentList.stream()
+ // 璁$畻鍥炴鎬婚
+ BigDecimal receiptAmount = receiptPayments.stream()
.map(ReceiptPayment::getReceiptPaymentAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- MonthlyAmountDto monthlyAmount = new MonthlyAmountDto();
- monthlyAmount.setMonth(targetMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
- monthlyAmount.setInvoiceAmount(invoiceAmount);
- monthlyAmount.setReceiptAmount(receiptAmount);
+ // 璁$畻寮�绁ㄦ�婚
+ BigDecimal invoiceAmount = invoiceLedgers.stream()
+ .map(InvoiceLedger::getInvoiceTotal)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
- monthlyAmounts.add(monthlyAmount);
+ // 鏋勯�犺繑鍥炵殑 DTO
+ MonthlyAmountDto dto = new MonthlyAmountDto();
+ dto.setMonth(startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " ~ " +
+ endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ dto.setReceiptAmount(receiptAmount);
+ dto.setInvoiceAmount(invoiceAmount);
+
+ result.add(dto);
}
- Collections.reverse(monthlyAmounts);
- return monthlyAmounts;
+
+ // 鍙嶈浆鍒楄〃锛屼娇鏃堕棿椤哄簭浠庢棭鍒版櫄
+ Collections.reverse(result);
+ return result;
}
@Override
@@ -307,15 +344,23 @@
List<Long> idList = Arrays.stream(ids)
.filter(Objects::nonNull)
.collect(Collectors.toList());
-
if (CollectionUtils.isEmpty(idList)) {
return 0;
+ }
+ // 鐢熶骇璁㈠崟鏈夊緟鎺掍骇鏁版嵁锛屽彴璐︿笉鍙垹闄�
+ LambdaQueryWrapper<SalesLedgerScheduling> salesLedgerSchedulingLambdaQueryWrapper = new LambdaQueryWrapper<SalesLedgerScheduling>()
+ .in(SalesLedgerScheduling::getSalesLedgerId, idList);
+ if (salesLedgerSchedulingMapper.selectCount(salesLedgerSchedulingLambdaQueryWrapper) > 0) {
+ throw new BaseException("鏈夋帓浜ф暟鎹紝涓嶅彲鍒犻櫎");
}
// 1. 鍏堝垹闄ゅ瓙琛ㄦ暟鎹�
LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
productWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList);
salesLedgerProductMapper.delete(productWrapper);
-
+ // 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
+ LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
+ .in(SalesLedgerScheduling::getSalesLedgerId, idList);
+ salesLedgerSchedulingMapper.delete(in);
// 2. 鍐嶅垹闄や富琛ㄦ暟鎹�
return salesLedgerMapper.deleteBatchIds(idList);
}
@@ -335,13 +380,36 @@
salesLedger.setCustomerName(customer.getCustomerName());
salesLedger.setTenantId(customer.getTenantId());
+ AccountIncome accountIncome = new AccountIncome();
+ accountIncome.setIncomeDate(salesLedger.getEntryDate());
+ accountIncome.setIncomeType("0");
+ accountIncome.setCustomerName(customer.getCustomerName());
+ accountIncome.setIncomeMoney(salesLedger.getContractAmount());
+ accountIncome.setIncomeMethod("0");
+ accountIncome.setInputTime(new Date());
+ accountIncome.setInputUser(salesLedger.getEntryPerson());
// 3. 鏂板鎴栨洿鏂颁富琛�
if (salesLedger.getId() == null) {
String contractNo = generateSalesContractNo();
salesLedger.setSalesContractNo(contractNo);
salesLedgerMapper.insert(salesLedger);
+ accountIncome.setIncomeDescribed("閿�鍞悎鍚岋細" + salesLedger.getSalesContractNo());
+ accountIncome.setInvoiceNumber(salesLedger.getSalesContractNo());
+ accountIncomeService.save(accountIncome);
} else {
salesLedgerMapper.updateById(salesLedger);
+ SalesLedger salesLedgerDB = salesLedgerMapper.selectById(salesLedger.getId());
+ AccountIncome accountIncomeDB = accountIncomeService.getByInvoiceNumber(salesLedger.getSalesContractNo());
+ if (ObjectUtils.isEmpty(accountIncomeDB)) {
+ throw new BaseException("鏀跺叆绠$悊鏃犺閿�鍞悎鍚岀殑鏀跺叆璁板綍");
+ }
+ accountIncomeDB.setCustomerName(salesLedgerDB.getCustomerName());
+ accountIncomeDB.setIncomeMoney(salesLedgerDB.getContractAmount());
+ accountIncomeDB.setIncomeDescribed("閿�鍞悎鍚岋細" + salesLedgerDB.getSalesContractNo());
+ accountIncomeDB.setInvoiceNumber(salesLedgerDB.getSalesContractNo());
+ accountIncomeDB.setInputTime(new Date());
+ accountIncomeDB.setInputUser(salesLedgerDB.getEntryPerson());
+ accountIncomeService.updateById(accountIncomeDB);
}
// 4. 澶勭悊瀛愯〃鏁版嵁
@@ -411,12 +479,15 @@
try {
// 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
- Files.move(
- Paths.get(tempFile.getTempPath()),
- formalFilePath,
- StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.ATOMIC_MOVE
- );
+// Files.move(
+// Paths.get(tempFile.getTempPath()),
+// formalFilePath,
+// StandardCopyOption.REPLACE_EXISTING,
+// StandardCopyOption.ATOMIC_MOVE
+// );
+ // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
+ Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+ Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
// 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
@@ -425,7 +496,8 @@
fileRecord.setName(originalFilename);
fileRecord.setUrl(formalFilePath.toString());
fileRecord.setCreateTime(LocalDateTime.now());
- fileRecord.setType("1");
+ //閿�鍞�
+ fileRecord.setType(FileNameType.SALE.getValue());
commonFileMapper.insert(fileRecord);
// 鍒犻櫎涓存椂鏂囦欢璁板綍
@@ -504,11 +576,11 @@
}
// 2. 鏌ヨ褰撳ぉ/鍏徃宸插瓨鍦ㄧ殑搴忓垪鍙凤紙涓庡師閫昏緫涓�鑷达級
- Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
- if(null != tenantId){
+ Long tenantId = SecurityUtils.getLoginUser().getTenantId();
+ if (null != tenantId) {
//鑾峰彇鍏徃缂栧彿
SysDept sysDept = sysDeptMapper.selectDeptById(tenantId.longValue());
- if(!ObjectUtils.isEmpty(sysDept)){
+ if (!ObjectUtils.isEmpty(sysDept)) {
datePart = (StringUtils.isEmpty(sysDept.getDeptNick()) ? "" : sysDept.getDeptNick()) + datePart;
}
}
--
Gitblit v1.9.3