wujianwei
2026-03-27 279366f14d6e1361b6caf7c05b74f0cea4227a36
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package com.ruoyi.cwgl.controller;
 
import java.util.List;
 
import com.ruoyi.cwgl.domain.ReceivableBillCustomerSummary;
import com.ruoyi.cwgl.domain.vo.ReceivableBillAccountAnalysisVo;
import com.ruoyi.cwgl.domain.vo.ReceivableBillAgingAnalysisVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.utils.file.DownloadExportUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import com.ruoyi.cwgl.domain.InvoiceManage;
import com.ruoyi.cwgl.domain.ReceivableBillManagement;
import com.ruoyi.cwgl.domain.ReceivableInvoiceBusiness;
import com.ruoyi.cwgl.service.IInvoiceManageService;
import com.ruoyi.cwgl.service.IReceivableBillManagementService;
import com.ruoyi.cwgl.service.IReceivableInvoiceBusinessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
/**
 * 应收账单管理Controller
 *
 * @author ruoyi
 * @date 2025-12-17
 */
@RestController
@RequestMapping("/cwgl/receivableBillManagement")
public class ReceivableBillManagementController extends BaseController
{
    @Autowired
    private IReceivableBillManagementService receivableBillManagementService;
 
    @Autowired
    private IInvoiceManageService invoiceManageService;
 
    @Autowired
    private IReceivableInvoiceBusinessService receivableInvoiceBusinessService;
 
 
 
    /**
     * 查询应收账单管理列表
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReceivableBillManagement receivableBillManagement)
    {
        startPage();
        List<ReceivableBillManagement> list = receivableBillManagementService.selectReceivableBillManagementList(receivableBillManagement);
        return getDataTable(list);
    }
 
    /**
     * 导出应收账单管理列表
     * @param receivableBillManagement 查询条件对象
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:export')")
    @Log(title = "应收账单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReceivableBillManagement receivableBillManagement,String exportKey)
    {
        receivableBillManagementService.export(receivableBillManagement,exportKey);
        return AjaxResult.success("导出请求成功,请稍后点击下载...!");
    }
 
 
 
    /**
     * 获取应收账单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(receivableBillManagementService.selectReceivableBillManagementById(id));
    }
 
    /**
     * 新增应收账单管理
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:add')")
    @Log(title = "应收账单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceivableBillManagement receivableBillManagement)
    {
        return toAjax(receivableBillManagementService.insertReceivableBillManagement(receivableBillManagement));
    }
 
    /**
     * 修改应收账单管理
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:edit')")
    @Log(title = "应收账单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceivableBillManagement receivableBillManagement)
    {
        return toAjax(receivableBillManagementService.updateReceivableBillManagement(receivableBillManagement));
    }  /**
     * 修改应收账单管理
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:edit')")
    @PutMapping("aging")
    public AjaxResult aging(@RequestBody ReceivableBillManagement receivableBillManagement)
    {
        return toAjax(receivableBillManagementService.aging(receivableBillManagement));
    }
@PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:edit')")
    @PutMapping("account")
    public AjaxResult account(@RequestBody ReceivableBillManagement receivableBillManagement)
    {
        return toAjax(receivableBillManagementService.account(receivableBillManagement));
    }
 
    /**
     * 删除应收账单管理
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:remove')")
    @Log(title = "应收账单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(receivableBillManagementService.deleteReceivableBillManagementByIds(ids));
    }
    
    /**
     * 作废应收账单管理记录
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:void')")
    @Log(title = "应收账单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/void/{id}")
    public AjaxResult voidReceivableBill(@PathVariable("id") Integer id)
    {
        return toAjax(receivableBillManagementService.voidReceivableBillManagement(id));
    }
 
    /**
     * 应收账单申请开票
     * @param invoiceManage 发票管理对象
     * @param id 应收账单ID
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:invoice')")
    @Log(title = "应收账单管理", businessType = BusinessType.OTHER)
    @PostMapping("/invoice/{id}")
    public AjaxResult applyReceivableInvoice(@RequestBody InvoiceManage invoiceManage, @PathVariable("id") Integer id)
    {
        return invoiceManageService.applyReceivableInvoice(invoiceManage, id);
    }
 
    /**
     * 查询应收账单已开票金额
     * @param id 应收账单ID
     * @return 已开票金额
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:query')")
    @GetMapping("/invoice/amount/{id}")
    public AjaxResult getReceivableInvoicedAmount(@PathVariable("id") Integer id)
    {
        // 查询receivable_invoice_business表中status为1的记录
        ReceivableInvoiceBusiness query = new ReceivableInvoiceBusiness();
        query.setHeadId(id);
        query.setStatus(1);
        List<ReceivableInvoiceBusiness> invoices = receivableInvoiceBusinessService.selectReceivableInvoiceBusinessList(query);
        
        // 计算已开票金额
        BigDecimal invoicedAmount = invoices.stream()
                .map(ReceivableInvoiceBusiness::getInvoicingAmount)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        
        return AjaxResult.success(invoicedAmount);
    }
 
    /**
     * 查询应收账单客户汇总列表
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:list')")
    @GetMapping("/customerSummary")
    public TableDataInfo customerSummary(ReceivableBillManagement receivableBillManagement)
    {
        List<ReceivableBillCustomerSummary> list = receivableBillManagementService.selectReceivableBillCustomerSummaryList(receivableBillManagement);
        return getDataTable(list);
    }
    /**
     * 导出应收账单管理列表
     * @param receivableBillManagement 查询条件对象
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:export')")
    @GetMapping("/customerSummary/export")
    public AjaxResult customerSummaryExport(ReceivableBillManagement receivableBillManagement,String exportKey)
    {
        receivableBillManagementService.customerSummaryExport(receivableBillManagement,exportKey);
        return AjaxResult.success("导出请求成功,请稍后点击下载...!");
    }
 
    /**
     * 查询应收账单账龄分析列表
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:list')")
    @GetMapping("/agingAnalysis")
    public TableDataInfo agingAnalysis(ReceivableBillManagement receivableBillManagement)
    {
        startPage();
        List<ReceivableBillAgingAnalysisVo> list = receivableBillManagementService.selectReceivableBillAgingAnalysisList(receivableBillManagement);
        return getDataTable(list);
    }
 
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:export')")
    @GetMapping("/agingAnalysis/export")
    public AjaxResult agingAnalysisExport(ReceivableBillManagement receivableBillManagement,String exportKey)
    {
        receivableBillManagementService.agingAnalysisExport(receivableBillManagement,exportKey);
        return AjaxResult.success("导出请求成功,请稍后点击下载...!");
    }
    /**
     * 查询应收账单账款分析列表
     */
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:list')")
    @GetMapping("/accountAnalysis")
    public TableDataInfo accountAnalysis(ReceivableBillManagement receivableBillManagement)
    {
        startPage();
        List<ReceivableBillAccountAnalysisVo> list = receivableBillManagementService.selectReceivableBillAccountAnalysisList(receivableBillManagement);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:export')")
    @GetMapping("/accountAnalysis/export")
    public AjaxResult accountAnalysisExport(ReceivableBillManagement receivableBillManagement,String exportKey)
    {
        receivableBillManagementService.accountAnalysisExport(receivableBillManagement,exportKey);
        return AjaxResult.success("导出请求成功,请稍后点击下载...!");
    }
    
}