maven
13 小时以前 30a4a720cfdd57248514f50d141dfd51519aa75d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.ruoyi.account.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.pojo.AccountExpense;
import com.ruoyi.account.pojo.AccountIncome;
import com.ruoyi.account.pojo.BorrowInfo;
import com.ruoyi.account.mapper.BorrowInfoMapper;
import com.ruoyi.account.service.AccountExpenseService;
import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.account.service.BorrowInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.sales.service.ReceiptPaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * <p>
 * 借款信息表 服务实现类
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-01-15 02:57:29
 */
@Service
@Slf4j
public class BorrowInfoServiceImpl extends ServiceImpl<BorrowInfoMapper, BorrowInfo> implements BorrowInfoService {
 
    @Autowired
    private BorrowInfoMapper borrowInfoMapper;
 
    @Autowired
    private AccountIncomeService accountIncomeService;
 
    @Autowired
    private AccountExpenseService accountExpenseService;
 
    @Override
    public AjaxResult listPage(Page page, BorrowInfo borrowInfo) {
        LambdaQueryWrapper<BorrowInfo> borrowInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(borrowInfo != null){
            if(StringUtils.isNotEmpty(borrowInfo.getEntryDateStart()) && StringUtils.isNotEmpty(borrowInfo.getEntryDateEnd())){
                borrowInfoLambdaQueryWrapper.ge(BorrowInfo::getBorrowDate, borrowInfo.getEntryDateStart());
                borrowInfoLambdaQueryWrapper.le(BorrowInfo::getBorrowDate, borrowInfo.getEntryDateEnd());
            }
            if(borrowInfo.getStatus() != null){
                borrowInfoLambdaQueryWrapper.eq(BorrowInfo::getStatus, borrowInfo.getStatus());
            }
            if(StringUtils.isNotEmpty(borrowInfo.getBorrowerName())){
                borrowInfoLambdaQueryWrapper.like(BorrowInfo::getBorrowerName, borrowInfo.getBorrowerName());
            }
        }
        return AjaxResult.success(borrowInfoMapper.selectPage(page, borrowInfoLambdaQueryWrapper));
    }
 
    @Override
    public AjaxResult add(BorrowInfo borrowInfo) {
        int insert = borrowInfoMapper.insert(borrowInfo);
        if(insert > 0){
            // 添加成功,进入收入管理
            AccountIncome accountIncome = new AccountIncome();
            accountIncome.setBusinessId(borrowInfo.getId());
            accountIncome.setBusinessType(2);
            accountIncome.setIncomeDate(DateUtils.toDate(borrowInfo.getBorrowDate()));
            accountIncome.setIncomeType("2");
            accountIncome.setIncomeMoney(borrowInfo.getBorrowAmount());
            accountIncome.setIncomeDescribed("借款");
            accountIncome.setIncomeMethod("3");
            accountIncome.setInputTime(DateUtils.getNowDate());
            accountIncome.setInputUser(borrowInfo.getBorrowerName());
            accountIncomeService.save(accountIncome);
            return AjaxResult.success("添加成功");
        }
        return AjaxResult.success("添加失败");
    }
 
    @Override
    public AjaxResult updateBorrowInfo(BorrowInfo borrowInfo) {
        int update = borrowInfoMapper.updateById(borrowInfo);
        if(update > 0){
            // 修改成功,修改收入管理
            AccountIncome one = accountIncomeService.getOne(new LambdaQueryWrapper<AccountIncome>()
                    .eq(AccountIncome::getBusinessId, borrowInfo.getId())
                    .eq(AccountIncome::getBusinessType, 2)
                    .last("limit 1"));
            if(one != null){
                one.setIncomeMoney(borrowInfo.getBorrowAmount());
                accountIncomeService.updateById(one);
            }
            // 是否为还款
            if(borrowInfo.getStatus() != null && borrowInfo.getStatus() == 2){
                // 新增支出记录
                AccountExpense accountExpense = new AccountExpense();
                accountExpense.setBusinessId(borrowInfo.getId());
                accountExpense.setBusinessType(2);
                accountExpense.setExpenseDate(DateUtils.toDate(borrowInfo.getRepayDate()));
                accountExpense.setExpenseType("4");
                accountExpense.setExpenseMoney(borrowInfo.getBorrowAmount());
                accountExpense.setExpenseDescribed("还款");
                accountExpense.setExpenseMethod("3");
                accountExpense.setInputTime(DateUtils.getNowDate());
                accountExpense.setInputUser(borrowInfo.getBorrowerName());
                accountExpenseService.save(accountExpense);
            }
            return AjaxResult.success("修改成功");
        }
        return  AjaxResult.success("修改失败");
    }
 
    @Override
    public AjaxResult delete(List<Long> ids) {
        int delete = borrowInfoMapper.deleteBatchIds(ids);
        if(delete > 0){
            // 删除成功,删除收入管理
            accountIncomeService.remove(new LambdaQueryWrapper<AccountIncome>()
                    .in(AccountIncome::getBusinessId, ids)
                    .eq(AccountIncome::getBusinessType, 2));
            // 删除支出管理
            accountExpenseService.remove(new LambdaQueryWrapper<AccountExpense>()
                    .in(AccountExpense::getBusinessId, ids)
                    .eq(AccountExpense::getBusinessType, 2));
            return AjaxResult.success("删除成功");
        }
        return  AjaxResult.success("删除失败");
    }
}