WebStatisticsFinancePageselectController.java
9.27 KB
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
package com.lhcredit.project.webbusiness.controller;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.project.business.frontDept.domain.FrontDept;
import com.lhcredit.project.business.frontDept.service.IFrontDeptService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.project.business.statisticsFinancePageselect.domain.StatisticsFinancePageselect;
import com.lhcredit.project.business.statisticsFinancePageselect.service.IStatisticsFinancePageselectService;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
/**
* 前台财务调用统计信息对外接口
*
* @author lhcredit
* @date 2025-03-03
*/
@Slf4j
@RestController
@RequestMapping("/web/statisticsFinancePageselect")
public class WebStatisticsFinancePageselectController extends BaseController {
@Autowired
private IStatisticsFinancePageselectService statisticsFinancePageselectService;
@Autowired
private IFrontDeptService frontDeptService;
/**
* 查询前台财务调用统计列表接口
*/
@ApiOperation("查询前台财务调用统计列表")
@Log(title = "前台财务调用统计", businessType = BusinessType.LIST, operatorType = OperatorType.WEB)
@GetMapping
public AjaxResult list(StatisticsFinancePageselect statisticsFinancePageselect) {
startPage();
List<StatisticsFinancePageselect> list = statisticsFinancePageselectService.changeModel(statisticsFinancePageselectService.selectStatisticsFinancePageselectList(statisticsFinancePageselect));
return toAjax(list);
}
/**
* 查询前台财务调用统计详情接口
*/
@ApiOperation("查询前台财务调用统计详情")
@ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "int", paramType = "path")
@Log(title = "前台财务调用统计", businessType = BusinessType.DETAIL, operatorType = OperatorType.WEB)
@GetMapping("/{id}")
public AjaxResult detail(@PathVariable Integer id) {
StatisticsFinancePageselect statisticsFinancePageselect =statisticsFinancePageselectService.changeModel(statisticsFinancePageselectService.selectStatisticsFinancePageselectById(id));
if (StringUtils.isNull(statisticsFinancePageselect)) {
return AjaxResult.error("该信息不存在");
}
return toAjax(statisticsFinancePageselect);
}
/**
* 新增保存前台财务调用统计接口
*/
@ApiOperation("新增前台财务调用统计")
@ApiImplicitParam(name = "statisticsFinancePageselect", value = "前台财务调用统计", dataType = "StatisticsFinancePageselect")
@Log(title = "前台财务调用统计", businessType = BusinessType.INSERT, operatorType = OperatorType.WEB)
@PostMapping
public AjaxResult addSave(StatisticsFinancePageselect statisticsFinancePageselect) {
statisticsFinancePageselect.setCreateBy(ShiroUtils.getLoginName());
statisticsFinancePageselect.setCreateTime(new Date());
statisticsFinancePageselect.setUpdateBy(ShiroUtils.getLoginName());
statisticsFinancePageselect.setUpdateTime(new Date());
return toAjax(statisticsFinancePageselectService.insertStatisticsFinancePageselect(statisticsFinancePageselect));
}
/**
* 修改保存前台财务调用统计接口
*/
@ApiOperation("修改前台财务调用统计")
@ApiImplicitParam(name = "statisticsFinancePageselect", value = "前台财务调用统计", dataType = "StatisticsFinancePageselect")
@Log(title = "前台财务调用统计", businessType = BusinessType.UPDATE, operatorType = OperatorType.WEB)
@PutMapping
public AjaxResult update(StatisticsFinancePageselect statisticsFinancePageselect) {
if (StringUtils.isNull(statisticsFinancePageselect) || StringUtils.isNull(statisticsFinancePageselect.getId())){
return AjaxResult.error("主键id不能为空");
}
statisticsFinancePageselect.setUpdateBy(ShiroUtils.getLoginName());
statisticsFinancePageselect.setUpdateTime(new Date());
return toAjax(statisticsFinancePageselectService.updateStatisticsFinancePageselect(statisticsFinancePageselect));
}
/**
* 删除前台财务调用统计接口
*/
@ApiOperation("删除前台财务调用统计")
@ApiImplicitParam(name = "ids", value = "主键id,多条以英文逗号分隔", required = true, dataType = "String", paramType = "path")
@Log(title = "前台财务调用统计", businessType = BusinessType.DELETE, operatorType = OperatorType.WEB)
@DeleteMapping("/{ids}")
public AjaxResult delete(@PathVariable String ids) {
return toAjax(statisticsFinancePageselectService.deleteStatisticsFinancePageselectByIds(ids));
}
/**
* 财务数据订单
*/
@PostMapping("/getOrder")
@ResponseBody
public TableDataInfo getOrder(@RequestBody StatisticsFinancePageselect statisticsFinancePageselect) {
startPage(statisticsFinancePageselect.getPageNum(),statisticsFinancePageselect.getPageSize());
return getDataTable(statisticsFinancePageselectService.getOrder(statisticsFinancePageselect));
}
/**
* 编辑对账状态
*/
@PostMapping("/updateStatus")
@ResponseBody
public AjaxResult updateStatus(@RequestBody String requestJson) {
return AjaxResult.success(statisticsFinancePageselectService.updateStatus(requestJson));
}
/**
* 财务数据订单导出
*/
@PostMapping("/orderExport")
@ResponseBody
public AjaxResult orderExport(@RequestBody StatisticsFinancePageselect statisticsFinancePageselect, HttpServletResponse response) throws IOException {
List<StatisticsFinancePageselect> list = statisticsFinancePageselectService.getOrder(statisticsFinancePageselect);
List<Long> collect = list.stream().map(item -> item.getOrgId()).distinct().collect(Collectors.toList());
Map<Long, String> frontDeptMap = new HashMap<>();
collect.forEach(item -> {
FrontDept frontDept = frontDeptService.selectFrontDeptById(item);
frontDeptMap.put(item, frontDept.getDeptName());
});
list.forEach(item -> {
item.setDeptName(frontDeptMap.get(item.getOrgId()));
});
/* List<JSONObject> jsonObjects = list.stream().map(item -> {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", item.getId());
jsonObject.put("企业名称", item.getEname());
jsonObject.put("用户所属公司", frontDeptMap.get(item.getOrgId()));
jsonObject.put("用户名称", item.getUserName());
jsonObject.put("数据类型", item.getDataType());
jsonObject.put("调取时间", item.getCreateTime());
jsonObject.put("查询结果", item.getResultRemark());
jsonObject.put("是否对账", "Y".equals(item.getReconciliation()) ? "是" : "否");
return jsonObject; // ⚠️ 注意:必须返回构建好的 jsonObject
}).collect(Collectors.toList());
// 设置响应头
configureResponseHeader(response, "财务数据");
// 导出数据到Excel
exportToExcel(jsonObjects, response.getOutputStream());*/
return AjaxResult.success(list);
}
private void configureResponseHeader(HttpServletResponse response, String fileName) {
try {
if (StrUtil.isBlank(fileName)) {
fileName = "企业数据导出";
}
// 确保文件名不包含非法字符
fileName = fileName.replaceAll("[\\\\/:*?\"<>|]", "_");
// 进行URL编码,防止中文乱码
String encodedFileName = URLEncoder.encode(fileName + ".xlsx", String.valueOf(StandardCharsets.UTF_8));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName);
} catch (Exception e) {
log.error("设置响应头失败", e);
}
}
private void exportToExcel(List<JSONObject> list, ServletOutputStream outputStream) {
// 创建ExcelWriter
try (ExcelWriter writer = cn.hutool.poi.excel.ExcelUtil.getWriter()) {
// 写入数据到Sheet
writer.write(list, true);
// 输出到流并关闭writer
writer.flush(outputStream, true);
}
}
}