From db628292cb9b69b901b44b146ac88c5f68e38389 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 08 十月 2026 14:52:54 +0800
Subject: [PATCH] 财务管理系统模块优化

---
 src/main/java/com/ruoyi/account/service/impl/AccountServiceImpl.java |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 101 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/ruoyi/account/service/impl/AccountServiceImpl.java b/src/main/java/com/ruoyi/account/service/impl/AccountServiceImpl.java
index d1b6964..078f48c 100644
--- a/src/main/java/com/ruoyi/account/service/impl/AccountServiceImpl.java
+++ b/src/main/java/com/ruoyi/account/service/impl/AccountServiceImpl.java
@@ -1,30 +1,19 @@
 package com.ruoyi.account.service.impl;
 
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.account.dto.AccountDto3;
-import com.ruoyi.account.mapper.AccountIncomeMapper;
+import com.ruoyi.account.dto.AccountTransferDto;
 import com.ruoyi.account.mapper.AccountMapper;
 import com.ruoyi.account.pojo.Account;
-import com.ruoyi.account.pojo.AccountIncome;
-import com.ruoyi.account.service.AccountIncomeService;
 import com.ruoyi.account.service.AccountService;
-import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.dto.DateQueryDto;
-import com.ruoyi.project.system.domain.SysDictData;
-import com.ruoyi.project.system.mapper.SysDictDataMapper;
+import com.ruoyi.common.exception.ServiceException;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import javax.servlet.http.HttpServletResponse;
-import java.math.BigDecimal;
-import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Date;
 
 @AllArgsConstructor
 @Service
@@ -34,6 +23,102 @@
 
     @Override
     public IPage<Account> accountListPage(Page page, Account account) {
-        return accountMapper.accountListPage(page,account);
+        return accountMapper.accountListPage(page, account);
+    }
+
+    /**
+     * 娴佹按绫诲瀷 -> 鏀舵敮鏂瑰悜
+     * 0鏀跺叆 +1, 1鏀嚭 -1, 3瀛樺叆 +1, 4鍙栧嚭 -1, 2杞处鐢� transfer() 澶勭悊
+     */
+    private Integer resolveDirection(String flowType) {
+        if (flowType == null) {
+            return null;
+        }
+        switch (flowType) {
+            case "0":
+            case "3":
+                return 1;
+            case "1":
+            case "4":
+                return -1;
+            default:
+                return null;
+        }
+    }
+
+    @Override
+    public boolean saveFlow(Account account) {
+        if (account.getAccountId() == null) {
+            throw new ServiceException("璧勯噾璐︽埛涓嶈兘涓虹┖");
+        }
+        if (account.getAmount() == null || account.getAmount().signum() <= 0) {
+            throw new ServiceException("娴佹按閲戦蹇呴』澶т簬0");
+        }
+        if ("2".equals(account.getFlowType())) {
+            throw new ServiceException("杞处璇蜂娇鐢ㄨ浆璐︽帴鍙o紝浠ョ‘淇濈敓鎴愭垚瀵规祦姘�");
+        }
+        if (account.getDirection() == null) {
+            account.setDirection(resolveDirection(account.getFlowType()));
+        }
+        if (account.getDirection() == null) {
+            throw new ServiceException("璇烽�夋嫨鏈夋晥鐨勬祦姘寸被鍨�");
+        }
+        if (account.getAccountDate() == null) {
+            account.setAccountDate(new Date());
+        }
+        return this.save(account);
+    }
+
+    @Override
+    public boolean updateFlow(Account account) {
+        if (account.getId() == null) throw new ServiceException("娴佹按ID涓嶈兘涓虹┖");
+        Account existing = this.getById(account.getId());
+        if (existing == null) throw new ServiceException("璧勯噾娴佹按涓嶅瓨鍦�");
+        if ("2".equals(existing.getFlowType()) || "2".equals(account.getFlowType())) {
+            throw new ServiceException("杞处鎴愬娴佹按涓嶅彲鍗曠嫭缂栬緫");
+        }
+        if (account.getAccountId() == null) throw new ServiceException("璧勯噾璐︽埛涓嶈兘涓虹┖");
+        if (account.getAmount() == null || account.getAmount().signum() <= 0) throw new ServiceException("娴佹按閲戦蹇呴』澶т簬0");
+        Integer direction = resolveDirection(account.getFlowType());
+        if (direction == null) throw new ServiceException("璇烽�夋嫨鏈夋晥鐨勬祦姘寸被鍨�");
+        account.setDirection(direction);
+        return this.updateById(account);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean transfer(AccountTransferDto dto) {
+        if (dto.getFromAccountId() == null || dto.getToAccountId() == null) {
+            throw new ServiceException("杞嚭/杞叆璐︽埛涓嶈兘涓虹┖");
+        }
+        if (dto.getFromAccountId().equals(dto.getToAccountId())) {
+            throw new ServiceException("杞嚭涓庤浆鍏ヨ处鎴蜂笉鑳界浉鍚�");
+        }
+        if (dto.getAmount() == null || dto.getAmount().signum() <= 0) {
+            throw new ServiceException("杞处閲戦蹇呴』澶т簬0");
+        }
+        Date date = dto.getTransferDate() == null ? new Date() : dto.getTransferDate();
+
+        Account out = new Account();
+        out.setAccountDate(date);
+        out.setAccountId(dto.getFromAccountId());
+        out.setFlowType("2");
+        out.setDirection(-1);
+        out.setCounterAccountId(dto.getToAccountId());
+        out.setAmount(dto.getAmount());
+        out.setRemark(dto.getRemark());
+
+        Account in = new Account();
+        in.setAccountDate(date);
+        in.setAccountId(dto.getToAccountId());
+        in.setFlowType("2");
+        in.setDirection(1);
+        in.setCounterAccountId(dto.getFromAccountId());
+        in.setAmount(dto.getAmount());
+        in.setRemark(dto.getRemark());
+
+        this.save(out);
+        this.save(in);
+        return true;
     }
 }

--
Gitblit v1.9.3