Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
9e9b97d4
Commit
9e9b97d4
authored
Jul 04, 2025
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(amos-boot-module-jg): 重构模板版本校验逻辑
- 将 DataDockTemplateVersion 类重命名为 DataDockTemplateVersionUtils,改为实用类 - 移动模板版本校验方法到新工具类中 - 优化模板版本校验逻辑,提高可读性和可维护性 - 在数据导入前增加模板版本校验,确保数据正确性
parent
68736cd3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
41 deletions
+78
-41
DataDockTemplateVersionUtils.java
...ot/module/jg/api/common/DataDockTemplateVersionUtils.java
+59
-1
DataDockServiceImpl.java
.../boot/module/jg/biz/service/impl/DataDockServiceImpl.java
+12
-40
IdxBizJgRegisterInfoServiceImpl.java
.../jg/biz/service/impl/IdxBizJgRegisterInfoServiceImpl.java
+7
-0
No files found.
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-api/src/main/java/com/yeejoin/amos/boot/module/jg/api/common/DataDockTemplateVersion.java
→
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-api/src/main/java/com/yeejoin/amos/boot/module/jg/api/common/DataDockTemplateVersion
Utils
.java
View file @
9e9b97d4
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jg
.
api
.
common
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelReader
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
com.yeejoin.amos.boot.module.jg.api.dto.EquipInfoExcelDto
;
import
lombok.experimental.UtilityClass
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -17,7 +29,8 @@ import java.util.Map;
* @version v1.0
* @date 2025/7/4 13:44
*/
public
class
DataDockTemplateVersion
{
@UtilityClass
public
class
DataDockTemplateVersionUtils
{
/**
* 错误提示
...
...
@@ -80,4 +93,49 @@ public class DataDockTemplateVersion {
}
return
version
.
equals
(
VERSION_MAP
.
get
(
key
));
}
/**
* 校验上传的文件是否使用正确版本的模板
*
*
* @param file file
* @author yangyang
* @date 2025/7/4 15:19
*/
public
static
String
checkTemplateVersion
(
MultipartFile
file
)
throws
IOException
{
byte
[]
fileBytes
=
file
.
getBytes
();
ExcelReader
excelReader
=
EasyExcel
.
read
(
new
ByteArrayInputStream
(
fileBytes
)).
build
();
List
<
ReadSheet
>
sheetList
=
excelReader
.
excelExecutor
().
sheetList
();
// 获取所有 sheet
return
checkTemplateVersion
(
file
,
sheetList
);
}
public
static
String
checkTemplateVersion
(
MultipartFile
file
,
List
<
ReadSheet
>
sheetList
)
throws
IOException
{
byte
[]
fileBytes
=
file
.
getBytes
();
List
<
String
>
errorMessages
=
new
ArrayList
<>(
1
);
for
(
ReadSheet
readSheet
:
sheetList
)
{
String
sheetName
=
readSheet
.
getSheetName
();
if
(!
sheetName
.
contains
(
"版本信息"
))
{
continue
;
}
int
sheetNo
=
readSheet
.
getSheetNo
();
EasyExcel
.
read
(
new
ByteArrayInputStream
(
fileBytes
),
EquipInfoExcelDto
.
class
,
new
AnalysisEventListener
<
EquipInfoExcelDto
>()
{
@Override
public
void
invoke
(
EquipInfoExcelDto
data
,
AnalysisContext
context
)
{
if
(!
DataDockTemplateVersionUtils
.
isSameVersion
(
data
.
getTemplateKey
(),
data
.
getTemplateVersion
()))
{
errorMessages
.
add
(
DataDockTemplateVersionUtils
.
ERROR_MESSAGE
);
}
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
}
}).
headRowNumber
(
1
).
sheet
(
sheetNo
,
sheetName
).
doRead
();
}
return
ValidationUtil
.
isEmpty
(
errorMessages
)
?
""
:
errorMessages
.
get
(
0
);
}
}
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/service/impl/DataDockServiceImpl.java
View file @
9e9b97d4
...
...
@@ -27,7 +27,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ExcelImportErrorLogDao;
import
com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto
;
import
com.yeejoin.amos.boot.module.common.api.dto.ExcelImportErrorLogDto
;
import
com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent
;
import
com.yeejoin.amos.boot.module.jg.api.common.DataDockTemplateVersion
;
import
com.yeejoin.amos.boot.module.jg.api.common.DataDockTemplateVersion
Utils
;
import
com.yeejoin.amos.boot.module.jg.api.converter.DictParamsConverter
;
import
com.yeejoin.amos.boot.module.jg.api.converter.EquCategoryConverter
;
import
com.yeejoin.amos.boot.module.jg.api.converter.EquDefineConverter
;
...
...
@@ -77,7 +77,6 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import
org.typroject.tyboot.core.restful.exception.instance.BadRequest
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.sql.Timestamp
;
...
...
@@ -783,7 +782,11 @@ public class DataDockServiceImpl {
InputStream
inputStream
=
file
.
getInputStream
();
ExcelReader
excelReader
=
EasyExcel
.
read
(
inputStream
).
build
();
List
<
ReadSheet
>
sheetList
=
excelReader
.
excelExecutor
().
sheetList
();
// 获取所有 sheet
checkTemplateVersion
(
file
,
sheetList
);
// 判断模板版本号
String
templateVersionError
=
DataDockTemplateVersionUtils
.
checkTemplateVersion
(
file
,
sheetList
);
if
(!
ValidationUtil
.
isEmpty
(
templateVersionError
))
{
throw
new
BadRequest
(
templateVersionError
);
}
for
(
ReadSheet
readSheet
:
sheetList
)
{
String
sheetName
=
readSheet
.
getSheetName
();
...
...
@@ -1584,6 +1587,12 @@ public class DataDockServiceImpl {
List
<
String
>
resultGDError
=
new
ArrayList
<>();
List
<
String
>
pipelineNumList
=
new
ArrayList
<>();
try
{
// 判断模板版本号
String
templateVersionError
=
DataDockTemplateVersionUtils
.
checkTemplateVersion
(
multipartFile
);
if
(!
ValidationUtil
.
isEmpty
(
templateVersionError
))
{
resultGDError
.
add
(
templateVersionError
);
throw
new
BadRequest
(
templateVersionError
);
}
EasyExcel
.
read
(
multipartFile
.
getInputStream
(),
PipingExcelDto
.
class
,
new
AnalysisEventListener
<
PipingExcelDto
>()
{
@Override
public
void
invoke
(
PipingExcelDto
data
,
AnalysisContext
context
)
{
...
...
@@ -2897,41 +2906,4 @@ public class DataDockServiceImpl {
}
}
/**
* 校验上传的文件是否使用正确版本的模板
*
*
* @param file file
* @param sheetList sheetList
* @author yangyang
* @date 2025/7/4 15:19
*/
private
void
checkTemplateVersion
(
MultipartFile
file
,
List
<
ReadSheet
>
sheetList
)
throws
IOException
{
List
<
String
>
errorMessages
=
new
ArrayList
<>(
1
);
for
(
ReadSheet
readSheet
:
sheetList
)
{
String
sheetName
=
readSheet
.
getSheetName
();
if
(!
sheetName
.
contains
(
"版本信息"
))
{
continue
;
}
int
sheetNo
=
readSheet
.
getSheetNo
();
EasyExcel
.
read
(
file
.
getInputStream
(),
EquipInfoExcelDto
.
class
,
new
AnalysisEventListener
<
EquipInfoExcelDto
>()
{
@Override
public
void
invoke
(
EquipInfoExcelDto
data
,
AnalysisContext
context
)
{
if
(!
DataDockTemplateVersion
.
isSameVersion
(
data
.
getTemplateKey
(),
data
.
getTemplateVersion
()))
{
errorMessages
.
add
(
DataDockTemplateVersion
.
ERROR_MESSAGE
);
}
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
}
}).
headRowNumber
(
1
).
sheet
(
sheetNo
,
sheetName
).
doRead
();
}
if
(!
ValidationUtil
.
isEmpty
(
errorMessages
))
{
throw
new
BadRequest
(
JSON
.
toJSONString
(
errorMessages
));
}
}
}
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/service/impl/IdxBizJgRegisterInfoServiceImpl.java
View file @
9e9b97d4
...
...
@@ -28,6 +28,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import
com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto
;
import
com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.EquipmentCategoryService
;
import
com.yeejoin.amos.boot.module.jg.api.common.DataDockTemplateVersionUtils
;
import
com.yeejoin.amos.boot.module.jg.api.dto.*
;
import
com.yeejoin.amos.boot.module.jg.api.entity.*
;
import
com.yeejoin.amos.boot.module.jg.api.enums.*
;
...
...
@@ -3923,6 +3924,12 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
equCodeList
.
clear
();
factoryNumList
.
clear
();
try
{
// 判断模板版本号
String
templateVersionError
=
DataDockTemplateVersionUtils
.
checkTemplateVersion
(
multipartFile
);
if
(!
ValidationUtil
.
isEmpty
(
templateVersionError
))
{
resultError
.
add
(
templateVersionError
);
throw
new
BadRequest
(
templateVersionError
);
}
EasyExcel
.
read
(
multipartFile
.
getInputStream
(),
EquipInfoCylinderExcelDto
.
class
,
new
AnalysisEventListener
<
EquipInfoCylinderExcelDto
>()
{
// 每读取一行就调用该方法
@Override
...
...
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