Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-csf
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-csf
Commits
20226f96
Commit
20226f96
authored
Dec 31, 2025
by
jianan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
前端对接问题修复30
parent
a360bd18
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
55 deletions
+59
-55
yd-csf-api/src/main/java/com/yd/csf/api/controller/ApiFortuneController.java
+15
-11
yd-csf-service/src/main/java/com/yd/csf/service/service/impl/FortuneServiceImpl.java
+44
-44
No files found.
yd-csf-api/src/main/java/com/yd/csf/api/controller/ApiFortuneController.java
View file @
20226f96
...
...
@@ -198,24 +198,28 @@ public class ApiFortuneController {
*/
@Operation
(
summary
=
"生成出账清单"
)
@PostMapping
(
"/download/account"
)
public
void
downloadAccount
(
@RequestBody
FortuneDownloadRequest
fortuneDownloadRequest
,
HttpServletResponse
response
)
throws
IOException
{
public
Result
<
Boolean
>
downloadAccount
(
@RequestBody
FortuneDownloadRequest
fortuneDownloadRequest
,
HttpServletResponse
response
)
throws
IOException
{
if
(
CollectionUtils
.
isEmpty
(
fortuneDownloadRequest
.
getFortuneBizIdList
()))
{
throw
new
BusinessException
(
ResultCode
.
PARAMS_ERROR
.
getCode
(),
"请选择要出账的发佣数据"
);
}
try
{
fortuneService
.
downloadAccount
(
fortuneDownloadRequest
,
response
);
return
Result
.
success
(
true
);
}
catch
(
Exception
e
)
{
// 设置响应类型为 JSON,而不是文件流
response
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
response
.
setContentType
(
MediaType
.
APPLICATION_JSON_VALUE
);
response
.
setCharacterEncoding
(
"UTF-8"
);
Result
<
String
>
errorResult
=
Result
.
fail
(
ResultCode
.
FAIL
.
getCode
(),
e
.
getMessage
()
);
// // 设置响应类型为 JSON,而不是文件流
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
// response.setContentType(MediaType.APPLICATION_JSON_VALUE);
// response.setCharacterEncoding("UTF-8");
//
// Result<String> errorResult = Result.fail(
// ResultCode.FAIL.getCode(),
// e.getMessage()
// );
//
// response.getWriter().write(new ObjectMapper().writeValueAsString(errorResult));
response
.
getWriter
().
write
(
new
ObjectMapper
().
writeValueAsString
(
errorResult
));
log
.
error
(
"生成出账清单失败"
,
e
);
return
Result
.
success
(
false
);
}
}
...
...
yd-csf-service/src/main/java/com/yd/csf/service/service/impl/FortuneServiceImpl.java
View file @
20226f96
...
...
@@ -265,54 +265,54 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
accountExportDTOList
.
add
(
accountDTO
);
}
// 设置响应头
response
.
setContentType
(
"application/vnd.ms-excel;charset=UTF-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
String
fileName
=
"fortune_account_"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
fileName
);
// 创建动态表头
List
<
List
<
String
>>
head
=
new
ArrayList
<>();
head
.
add
(
Collections
.
singletonList
(
"转介人"
));
head
.
add
(
Collections
.
singletonList
(
"所属团队"
));
head
.
add
(
Collections
.
singletonList
(
"出账币种"
));
head
.
add
(
Collections
.
singletonList
(
"出账总额"
));
// 添加所有fortune项目作为表头
for
(
String
fortuneName
:
allFortuneNames
)
{
head
.
add
(
Collections
.
singletonList
(
fortuneName
+
"金额"
));
}
// 构建数据行
List
<
List
<
Object
>>
dataList
=
new
ArrayList
<>();
for
(
FortuneAccountExportDTO
dto
:
accountExportDTOList
)
{
List
<
Object
>
row
=
new
ArrayList
<>();
row
.
add
(
dto
.
getBroker
());
row
.
add
(
dto
.
getTeam
());
row
.
add
(
dto
.
getCurrency
());
row
.
add
(
dto
.
getAmount
());
for
(
String
fortuneName
:
allFortuneNames
)
{
row
.
add
(
dto
.
getFortuneAmount
(
fortuneName
));
}
dataList
.
add
(
row
);
}
//
// 设置响应头
//
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
//
response.setCharacterEncoding("utf-8");
//
String fileName = "fortune_account_" + System.currentTimeMillis() + ".xlsx";
//
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
//
//
// 创建动态表头
//
List<List<String>> head = new ArrayList<>();
//
head.add(Collections.singletonList("转介人"));
//
head.add(Collections.singletonList("所属团队"));
//
head.add(Collections.singletonList("出账币种"));
//
head.add(Collections.singletonList("出账总额"));
//
//
// 添加所有fortune项目作为表头
//
for (String fortuneName : allFortuneNames) {
//
head.add(Collections.singletonList(fortuneName + "金额"));
//
}
//
//
// 构建数据行
//
List<List<Object>> dataList = new ArrayList<>();
//
for (FortuneAccountExportDTO dto : accountExportDTOList) {
//
List<Object> row = new ArrayList<>();
//
row.add(dto.getBroker());
//
row.add(dto.getTeam());
//
row.add(dto.getCurrency());
//
row.add(dto.getAmount());
//
for (String fortuneName : allFortuneNames) {
//
row.add(dto.getFortuneAmount(fortuneName));
//
}
//
dataList.add(row);
//
}
// 写入数据库
fortuneAccountService
.
saveFortuneAccount
(
accountExportDTOList
);
// 使用try-with-resources确保流正确关闭
try
(
ServletOutputStream
outputStream
=
response
.
getOutputStream
())
{
// 写入 Excel
EasyExcel
.
write
(
outputStream
)
.
head
(
head
)
.
sheet
(
"出账清单"
)
.
doWrite
(
dataList
);
outputStream
.
flush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"导出失败"
,
e
);
throw
new
BusinessException
(
ResultCode
.
FAIL
.
getCode
(),
"导出失败"
);
}
//
// 使用try-with-resources确保流正确关闭
//
try (ServletOutputStream outputStream = response.getOutputStream()) {
//
// 写入 Excel
//
EasyExcel.write(outputStream)
//
.head(head)
//
.sheet("出账清单")
//
.doWrite(dataList);
//
//
outputStream.flush();
//
} catch (Exception e) {
//
log.error("导出失败", e);
//
throw new BusinessException(ResultCode.FAIL.getCode(), "导出失败");
//
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment