Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-module-operation
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-module-operation
Commits
cbf3faef
提交
cbf3faef
authored
12月 19, 2025
作者:
douxy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改常规陈列导出导入失败场景的返回值编码
上级
37cfca9b
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
64 行删除
+26
-64
ExportExcelServiceImpl.java
...ion/service/sales/export/impl/ExportExcelServiceImpl.java
+3
-3
ImportExcelServiceImpl.java
...ion/service/sales/export/impl/ImportExcelServiceImpl.java
+10
-9
NormalDisplayImportStrategyImpl.java
...trategy/impl/imports/NormalDisplayImportStrategyImpl.java
+5
-5
ExcelUtils.java
src/main/java/com/sfa/operation/util/excel/ExcelUtils.java
+8
-47
没有找到文件。
src/main/java/com/sfa/operation/service/sales/export/impl/ExportExcelServiceImpl.java
浏览文件 @
cbf3faef
...
@@ -38,11 +38,11 @@ public class ExportExcelServiceImpl implements IExportExcelService {
...
@@ -38,11 +38,11 @@ public class ExportExcelServiceImpl implements IExportExcelService {
log
.
info
(
"导出前缀为:{}的excel"
,
fileNamePrefix
);
log
.
info
(
"导出前缀为:{}的excel"
,
fileNamePrefix
);
byte
[]
excelBytesArray
=
strategy
.
generateExcel
(
salesApRequest
);
byte
[]
excelBytesArray
=
strategy
.
generateExcel
(
salesApRequest
);
ExcelUtils
.
exportExcelBytesToResponse
(
excelBytesArray
,
response
,
fileNamePrefix
);
ExcelUtils
.
exportExcelBytesToResponse
(
excelBytesArray
,
response
,
fileNamePrefix
);
log
.
info
(
"
常规陈列
数据导出成功!"
);
log
.
info
(
"数据导出成功!"
);
return
R
.
ok
(
R
.
SUCCESS
,
"数据导出成功"
)
;
return
R
.
ok
(
R
.
SUCCESS
,
"数据导出成功"
)
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"
常规陈列
数据导出异常!具体错误原因:"
,
e
);
log
.
error
(
"数据导出异常!具体错误原因:"
,
e
);
return
R
.
fail
(
R
.
FAIL
,
e
.
getMessage
());
return
R
.
fail
(
910
,
e
.
getMessage
());
}
}
}
}
...
...
src/main/java/com/sfa/operation/service/sales/export/impl/ImportExcelServiceImpl.java
浏览文件 @
cbf3faef
...
@@ -45,16 +45,17 @@ public class ImportExcelServiceImpl implements IImportExcelService {
...
@@ -45,16 +45,17 @@ public class ImportExcelServiceImpl implements IImportExcelService {
public
R
importApExcel
(
ImportApExcelRequest
request
)
{
public
R
importApExcel
(
ImportApExcelRequest
request
)
{
// 参数校验
// 参数校验
if
(
request
==
null
||
request
.
getImportApFilePath
()
==
null
||
request
.
getImportApFilePath
().
trim
().
isEmpty
()){
if
(
request
==
null
||
request
.
getImportApFilePath
()
==
null
||
request
.
getImportApFilePath
().
trim
().
isEmpty
()){
return
R
.
fail
(
"导入文件路径不能为空!
"
);
return
R
.
fail
(
910
,
"文件上传失败,请重新上传!
"
);
}
}
if
(
request
.
getImportApType
()
==
null
||
request
.
getImportApType
().
trim
().
isEmpty
()){
if
(
request
.
getImportApType
()
==
null
||
request
.
getImportApType
().
trim
().
isEmpty
()){
return
R
.
fail
(
"导入类型不能为空!
"
);
return
R
.
fail
(
910
,
"文件上传失败,请重新上传!
"
);
}
}
// 获取策略
// 获取策略
IImportApExcelStrategy
strategy
=
apImportExcelStrategyFactory
.
getStrategy
(
request
.
getImportApType
());
IImportApExcelStrategy
strategy
=
apImportExcelStrategyFactory
.
getStrategy
(
request
.
getImportApType
());
if
(
strategy
==
null
){
if
(
strategy
==
null
){
return
R
.
fail
(
"未找到对应的导入策略!"
);
log
.
error
(
"未找到对应的导入策略!"
);
return
R
.
fail
(
910
,
"文件上传失败,请重新上传!"
);
}
}
// 执行导入的数据验证(根据不同的策略独自设计验证)
// 执行导入的数据验证(根据不同的策略独自设计验证)
...
@@ -86,16 +87,16 @@ public class ImportExcelServiceImpl implements IImportExcelService {
...
@@ -86,16 +87,16 @@ public class ImportExcelServiceImpl implements IImportExcelService {
@Override
@Override
public
R
updateApEntity
(
ImportApExcelRequest
request
)
{
public
R
updateApEntity
(
ImportApExcelRequest
request
)
{
if
(
request
.
getImportApType
()
==
null
||
request
.
getImportApType
().
trim
().
isEmpty
())
{
if
(
request
.
getImportApType
()
==
null
||
request
.
getImportApType
().
trim
().
isEmpty
())
{
return
R
.
fail
(
"导入类型不能为空
!"
);
return
R
.
fail
(
910
,
"数据更新失败,请重新导入
!"
);
}
}
if
(
request
.
getUuid
()
==
null
||
request
.
getUuid
().
trim
().
isEmpty
())
{
if
(
request
.
getUuid
()
==
null
||
request
.
getUuid
().
trim
().
isEmpty
())
{
return
R
.
fail
(
"导入数据标识不能为空
!"
);
return
R
.
fail
(
910
,
"数据更新失败,请重新导入
!"
);
}
}
// 获取策略
// 获取策略
IImportApExcelStrategy
strategy
=
apImportExcelStrategyFactory
.
getStrategy
(
request
.
getImportApType
());
IImportApExcelStrategy
strategy
=
apImportExcelStrategyFactory
.
getStrategy
(
request
.
getImportApType
());
if
(
strategy
==
null
)
{
if
(
strategy
==
null
)
{
return
R
.
fail
(
"未找到对应的导入策略
!"
);
return
R
.
fail
(
910
,
"数据更新失败,请重新导入
!"
);
}
}
// 从redis获取数据
// 从redis获取数据
...
@@ -106,7 +107,7 @@ public class ImportExcelServiceImpl implements IImportExcelService {
...
@@ -106,7 +107,7 @@ public class ImportExcelServiceImpl implements IImportExcelService {
// 1校验Redis数据是否存在
// 1校验Redis数据是否存在
if
(
redisDataJson
==
null
||
redisDataJson
.
trim
().
isEmpty
())
{
if
(
redisDataJson
==
null
||
redisDataJson
.
trim
().
isEmpty
())
{
log
.
error
(
"Redis中无有效数据,key={}"
,
redisKey
);
log
.
error
(
"Redis中无有效数据,key={}"
,
redisKey
);
return
R
.
fail
(
"导入数据已过期或不存在
,请重新导入!"
);
return
R
.
fail
(
910
,
"数据更新失败
,请重新导入!"
);
}
}
// 解析Redis数据为JSONObject,仅提取table数组(核心修改点,适配JDK8)
// 解析Redis数据为JSONObject,仅提取table数组(核心修改点,适配JDK8)
...
@@ -126,7 +127,7 @@ public class ImportExcelServiceImpl implements IImportExcelService {
...
@@ -126,7 +127,7 @@ public class ImportExcelServiceImpl implements IImportExcelService {
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"解析Redis中的table数组失败,redisDataJson={}"
,
redisDataJson
,
e
);
log
.
error
(
"解析Redis中的table数组失败,redisDataJson={}"
,
redisDataJson
,
e
);
return
R
.
fail
(
"数据解析
失败,请重新导入!"
);
return
R
.
fail
(
910
,
"数据更新
失败,请重新导入!"
);
}
}
// 校验table数组非空
// 校验table数组非空
...
@@ -146,7 +147,7 @@ public class ImportExcelServiceImpl implements IImportExcelService {
...
@@ -146,7 +147,7 @@ public class ImportExcelServiceImpl implements IImportExcelService {
log
.
info
(
"批量更新结果:{}"
,
updateResult
);
log
.
info
(
"批量更新结果:{}"
,
updateResult
);
if
(
"更新失败"
.
equals
(
updateResult
))
{
if
(
"更新失败"
.
equals
(
updateResult
))
{
return
R
.
fail
(
updateResult
);
return
R
.
fail
(
910
,
updateResult
);
}
}
return
R
.
ok
(
updateResult
);
return
R
.
ok
(
updateResult
);
...
...
src/main/java/com/sfa/operation/strategy/impl/imports/NormalDisplayImportStrategyImpl.java
浏览文件 @
cbf3faef
...
@@ -53,8 +53,8 @@ public class NormalDisplayImportStrategyImpl implements IImportApExcelStrategy<S
...
@@ -53,8 +53,8 @@ public class NormalDisplayImportStrategyImpl implements IImportApExcelStrategy<S
Map
<
String
,
List
<
SalesApDisplayImportExcelDto
>>
errorMap
)
{
Map
<
String
,
List
<
SalesApDisplayImportExcelDto
>>
errorMap
)
{
// 基础校验
// 基础校验
if
(
inputStream
==
null
||
StringUtils
.
isBlank
(
filePathUrl
))
{
if
(
inputStream
==
null
||
StringUtils
.
isBlank
(
filePathUrl
))
{
SalesApDisplayImportExcelDto
errorDto
=
buildSimpleErrorDto
(
"文件
流/URL为空
"
);
SalesApDisplayImportExcelDto
errorDto
=
buildSimpleErrorDto
(
"文件
上传失败
"
);
errorMap
.
put
(
"
参数异常
"
,
Collections
.
singletonList
(
errorDto
));
errorMap
.
put
(
"
导如失败
"
,
Collections
.
singletonList
(
errorDto
));
// 修改:返回含错误DTO的列表
// 修改:返回含错误DTO的列表
return
Collections
.
singletonList
(
errorDto
);
return
Collections
.
singletonList
(
errorDto
);
}
}
...
@@ -342,14 +342,14 @@ public class NormalDisplayImportStrategyImpl implements IImportApExcelStrategy<S
...
@@ -342,14 +342,14 @@ public class NormalDisplayImportStrategyImpl implements IImportApExcelStrategy<S
// 获取文件流
// 获取文件流
inputStream
=
ExcelUtils
.
getOssFileInputStream
(
filePathUrl
);
inputStream
=
ExcelUtils
.
getOssFileInputStream
(
filePathUrl
);
if
(
inputStream
==
null
)
{
if
(
inputStream
==
null
)
{
SalesApDisplayImportExcelDto
errorDto
=
buildSimpleErrorDto
(
"文件
流获取失败:OSS文件不存在或权限不足
"
);
SalesApDisplayImportExcelDto
errorDto
=
buildSimpleErrorDto
(
"文件
上传失败
"
);
List
<
SalesApDisplayImportExcelDto
>
errorList
=
Collections
.
singletonList
(
errorDto
);
List
<
SalesApDisplayImportExcelDto
>
errorList
=
Collections
.
singletonList
(
errorDto
);
resultMap
.
put
(
"uuid"
,
UUID
.
randomUUID
().
toString
());
resultMap
.
put
(
"uuid"
,
UUID
.
randomUUID
().
toString
());
resultMap
.
put
(
"table"
,
errorList
);
resultMap
.
put
(
"table"
,
errorList
);
resultMap
.
put
(
"successCount"
,
0
);
resultMap
.
put
(
"successCount"
,
0
);
resultMap
.
put
(
"failCount"
,
errorList
.
size
());
resultMap
.
put
(
"failCount"
,
errorList
.
size
());
resultMap
.
put
(
"errorMsg"
,
"文件
流获取失败:OSS文件不存在或权限不足
"
);
resultMap
.
put
(
"errorMsg"
,
"文件
上传失败
"
);
return
resultMap
;
return
resultMap
;
}
}
...
@@ -373,7 +373,7 @@ public class NormalDisplayImportStrategyImpl implements IImportApExcelStrategy<S
...
@@ -373,7 +373,7 @@ public class NormalDisplayImportStrategyImpl implements IImportApExcelStrategy<S
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"常规陈列导入失败,filePathUrl={}"
,
filePathUrl
,
e
);
log
.
error
(
"常规陈列导入失败,filePathUrl={}"
,
filePathUrl
,
e
);
// 修改:异常时构建错误DTO,存入table
// 修改:异常时构建错误DTO,存入table
SalesApDisplayImportExcelDto
errorDto
=
buildSimpleErrorDto
(
"导入失败:"
+
e
.
getMessage
());
SalesApDisplayImportExcelDto
errorDto
=
buildSimpleErrorDto
(
e
.
getMessage
());
List
<
SalesApDisplayImportExcelDto
>
errorList
=
Collections
.
singletonList
(
errorDto
);
List
<
SalesApDisplayImportExcelDto
>
errorList
=
Collections
.
singletonList
(
errorDto
);
resultMap
.
put
(
"uuid"
,
UUID
.
randomUUID
().
toString
());
resultMap
.
put
(
"uuid"
,
UUID
.
randomUUID
().
toString
());
...
...
src/main/java/com/sfa/operation/util/excel/ExcelUtils.java
浏览文件 @
cbf3faef
...
@@ -60,46 +60,7 @@ public class ExcelUtils {
...
@@ -60,46 +60,7 @@ public class ExcelUtils {
@Autowired
@Autowired
private
OssConfigProperties
ossConfig
;
private
OssConfigProperties
ossConfig
;
// public static String extractFileNameFromUrl(String filePathUrl) {
// if (StringUtils.isBlank(filePathUrl)) {
// return "未知文件";
// }
// try {
// // 先尝试URL解码,处理包含特殊字符或中文的文件名
// String decodedUrl = URLDecoder.decode(filePathUrl, StandardCharsets.UTF_8.name());
//
// // 方案1:标准文件路径(file:///C:/Users/xxx/Desktop/data.xlsx)
// if (decodedUrl.startsWith("file:")) {
// return new File(decodedUrl.substring(6)).getName();
// }
//
// // 方案2:普通绝对/相对路径(如"C:\\Users\\xxx\\Desktop\\data.xlsx"或"./data.xlsx")
// if (decodedUrl.contains(".") || decodedUrl.contains("/")) {
// return new File(decodedUrl).getName();
// }
//
// // 方案3:URL路径(如"http://example.com/path/data.xlsx?version=1")
// if (decodedUrl.contains("://")) {
// String pathPart = decodedUrl.substring(decodedUrl.indexOf("://") + 3);
// if (pathPart.contains("/")) {
// pathPart = pathPart.substring(pathPart.indexOf("/") + 1);
// }
// // 移除查询参数(?之后的部分)
// if (pathPart.contains("?")) {
// pathPart = pathPart.substring(0, pathPart.indexOf("?"));
// }
// return new File(pathPart).getName();
// }
//
// // 默认兜底方案:直接当作文件名处理
// return decodedUrl;
// } catch (Exception e) {
// log.warn("解析文件名异常,使用原始名称:{},错误:{}", filePathUrl, e.getMessage());
// return filePathUrl;
// }
//
//
// }
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
...
@@ -371,7 +332,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
...
@@ -371,7 +332,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
}
}
int
lastRowNum
=
sheet
.
getLastRowNum
();
int
lastRowNum
=
sheet
.
getLastRowNum
();
if
(
lastRowNum
<=
HEADER_ROW
)
{
if
(
lastRowNum
<=
HEADER_ROW
)
{
errorList
.
add
(
"获取数据行数
小于等于表头行数
,文件内无内容,导入失败,请检查文件!"
);
errorList
.
add
(
"获取数据行数
为0
,文件内无内容,导入失败,请检查文件!"
);
return
dataList
;
return
dataList
;
}
}
...
@@ -390,7 +351,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
...
@@ -390,7 +351,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"导入Excel文件失败:{}"
,
e
.
getMessage
(),
e
);
log
.
error
(
"导入Excel文件失败:{}"
,
e
.
getMessage
(),
e
);
errorList
.
add
(
"文件读取失败:"
+
e
.
getMessage
());
errorList
.
add
(
e
.
getMessage
());
}
finally
{
}
finally
{
// 关闭流
// 关闭流
try
{
try
{
...
@@ -420,7 +381,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
...
@@ -420,7 +381,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
*/
*/
public
static
void
exportExcelBytesToResponse
(
byte
[]
excelBytes
,
HttpServletResponse
response
,
String
fileNamePrefix
)
throws
Exception
{
public
static
void
exportExcelBytesToResponse
(
byte
[]
excelBytes
,
HttpServletResponse
response
,
String
fileNamePrefix
)
throws
Exception
{
if
(
excelBytes
==
null
||
excelBytes
.
length
==
0
)
{
if
(
excelBytes
==
null
||
excelBytes
.
length
==
0
)
{
throw
new
Exception
(
"导出Excel失败
:生成的Excel字节数组为空
"
);
throw
new
Exception
(
"导出Excel失败"
);
}
}
if
(
StringUtils
.
isBlank
(
fileNamePrefix
))
{
if
(
StringUtils
.
isBlank
(
fileNamePrefix
))
{
fileNamePrefix
=
"导出文件"
;
fileNamePrefix
=
"导出文件"
;
...
@@ -447,7 +408,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
...
@@ -447,7 +408,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
outputStream
.
flush
();
outputStream
.
flush
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"写入Excel响应流失败:{}"
,
e
.
getMessage
(),
e
);
log
.
error
(
"写入Excel响应流失败:{}"
,
e
.
getMessage
(),
e
);
throw
new
Exception
(
"导出Excel失败
:"
+
e
.
getMessage
()
);
throw
new
Exception
(
"导出Excel失败
!"
);
}
}
}
}
...
@@ -463,13 +424,13 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
...
@@ -463,13 +424,13 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
public
static
byte
[]
generateExcelBytes
(
List
<
ExportColumnConfig
>
exportColumnConfigList
,
List
<?>
dataList
,
String
sheetName
)
throws
IOException
{
public
static
byte
[]
generateExcelBytes
(
List
<
ExportColumnConfig
>
exportColumnConfigList
,
List
<?>
dataList
,
String
sheetName
)
throws
IOException
{
//数据校验
//数据校验
if
(
CollectionUtils
.
isEmpty
(
exportColumnConfigList
))
{
if
(
CollectionUtils
.
isEmpty
(
exportColumnConfigList
))
{
throw
new
IOException
(
"导出Excel失败
:没有配置导出列
"
);
throw
new
IOException
(
"导出Excel失败"
);
}
}
if
(
CollectionUtils
.
isEmpty
(
dataList
))
{
if
(
CollectionUtils
.
isEmpty
(
dataList
))
{
throw
new
IOException
(
"暂无数据,请检查查询条件"
);
throw
new
IOException
(
"暂无数据,请检查查询条件"
);
}
}
if
(
sheetName
==
null
||
sheetName
.
trim
().
isEmpty
())
{
if
(
sheetName
==
null
||
sheetName
.
trim
().
isEmpty
())
{
throw
new
IOException
(
"导出Excel失败
:没有配置sheetName
"
);
throw
new
IOException
(
"导出Excel失败"
);
}
}
// 根据sheetName创建工作表
// 根据sheetName创建工作表
...
@@ -507,7 +468,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
...
@@ -507,7 +468,7 @@ public static <T> List<T> readApExcelWithColumnConfig(InputStream inputStream,
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"生成Excel文件失败:{}"
,
e
.
getMessage
(),
e
);
log
.
error
(
"生成Excel文件失败:{}"
,
e
.
getMessage
(),
e
);
throw
new
IOException
(
"生成Excel文件失败
:"
+
e
.
getMessage
()
);
throw
new
IOException
(
"生成Excel文件失败
!"
);
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论