Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspect
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
inspect
Commits
8568b692
提交
8568b692
authored
3月 19, 2020
作者:
马晨俊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mcj:更新
上级
77026748
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
4 行增加
和
255 行删除
+4
-255
pom.xml
pom.xml
+3
-30
RuleController.java
...main/java/com/zjty/inspect/controller/RuleController.java
+0
-10
RuleService.java
src/main/java/com/zjty/inspect/service/RuleService.java
+0
-1
RuleServiceImpl.java
...n/java/com/zjty/inspect/service/impl/RuleServiceImpl.java
+0
-23
ExcelReader.java
src/main/java/com/zjty/inspect/utils/ExcelReader.java
+0
-190
application.properties
src/main/resources/application.properties
+1
-1
没有找到文件。
pom.xml
浏览文件 @
8568b692
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.
0.4
.RELEASE
</version>
<version>
2.
1.6
.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
<relativePath/>
<!-- lookup parent from repository -->
</parent>
</parent>
<groupId>
com.zjty
</groupId>
<groupId>
com.zjty
</groupId>
...
@@ -22,28 +22,11 @@
...
@@ -22,28 +22,11 @@
</profile>
</profile>
</profiles>
</profiles>
<properties>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
<spring-cloud.version>
Finchley.RELEASE
</spring-cloud.version>
<swagger.version>
2.9.2
</swagger.version>
<swagger.version>
2.9.2
</swagger.version>
<lombok.version>
1.18.2
</lombok.version>
<fastjson.version>
1.2.46
</fastjson.version>
<!--<fastjson.version>1.2.31</fastjson.version>-->
<liujie.latest.version>
1.0-SNAPSHOT
</liujie.latest.version>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
4.0.1
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
4.0.1
</version>
</dependency>
<dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<artifactId>
springfox-swagger2
</artifactId>
...
@@ -115,10 +98,8 @@
...
@@ -115,10 +98,8 @@
<artifactId>
snakeyaml
</artifactId>
<artifactId>
snakeyaml
</artifactId>
<version>
1.25
</version>
<version>
1.25
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
net.lingala.zip4j
</groupId>
<groupId>
net.lingala.zip4j
</groupId>
<artifactId>
zip4j
</artifactId>
<artifactId>
zip4j
</artifactId>
...
@@ -138,14 +119,6 @@
...
@@ -138,14 +119,6 @@
<plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
<goal>
build-info
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
...
...
src/main/java/com/zjty/inspect/controller/RuleController.java
浏览文件 @
8568b692
...
@@ -78,16 +78,6 @@ public class RuleController {
...
@@ -78,16 +78,6 @@ public class RuleController {
return
ResponseEntity
.
ok
(
ruleService
.
findAll
());
return
ResponseEntity
.
ok
(
ruleService
.
findAll
());
}
}
/**
* 查询所有规则
* @return 规则
*/
@ApiOperation
(
"查询所有规则"
)
@GetMapping
(
"/test"
)
public
ResponseEntity
test
(){
ruleService
.
test
();
return
ResponseEntity
.
ok
(
200
);
}
/**
/**
* 分页+多条件查询
* 分页+多条件查询
* @param searchMap 查询条件封装
* @param searchMap 查询条件封装
...
...
src/main/java/com/zjty/inspect/service/RuleService.java
浏览文件 @
8568b692
...
@@ -42,5 +42,4 @@ public interface RuleService {
...
@@ -42,5 +42,4 @@ public interface RuleService {
List
<
RuleQo
>
findByName
(
String
name
);
List
<
RuleQo
>
findByName
(
String
name
);
Page
<
RuleQo
>
findSearch
(
Map
searchMap
,
int
page
,
int
size
);
Page
<
RuleQo
>
findSearch
(
Map
searchMap
,
int
page
,
int
size
);
void
test
();
}
}
src/main/java/com/zjty/inspect/service/impl/RuleServiceImpl.java
浏览文件 @
8568b692
...
@@ -6,7 +6,6 @@ import com.zjty.inspect.entity.Rule;
...
@@ -6,7 +6,6 @@ import com.zjty.inspect.entity.Rule;
import
com.zjty.inspect.entity.RuleQo
;
import
com.zjty.inspect.entity.RuleQo
;
import
com.zjty.inspect.service.RuleService
;
import
com.zjty.inspect.service.RuleService
;
import
com.zjty.inspect.service.TechnologyService
;
import
com.zjty.inspect.service.TechnologyService
;
import
com.zjty.inspect.utils.ExcelReader
;
import
com.zjty.inspect.utils.UUIDUtil
;
import
com.zjty.inspect.utils.UUIDUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
...
@@ -41,28 +40,6 @@ public class RuleServiceImpl implements RuleService {
...
@@ -41,28 +40,6 @@ public class RuleServiceImpl implements RuleService {
@Autowired
@Autowired
private
TechnologyService
technologyService
;
private
TechnologyService
technologyService
;
@Override
public
void
test
()
{
List
<
ExcelDataVo
>
excelDataVos
=
ExcelReader
.
readExcel
(
"C:\\Users\\Jey\\Desktop\\生成代码\\规则表.xlsx"
);
System
.
out
.
println
(
excelDataVos
);
HashSet
<
String
>
set
=
new
HashSet
();
for
(
ExcelDataVo
excelDataVo
:
excelDataVos
)
{
List
<
Rule
>
rules
=
ruleDao
.
findAllByTarget
(
excelDataVo
.
getName
());
if
(
rules
==
null
||
rules
.
size
()==
0
){
set
.
add
(
excelDataVo
.
getName
());
}
}
for
(
String
s
:
set
)
{
Rule
rule
=
new
Rule
();
rule
.
setTechnologyName
(
"国产化依赖(支持)"
);
rule
.
setTechnologyId
(
"967a8bd0-eb27-4fb6-ba1d-1bca21cea5b4"
);
rule
.
setSuffix
(
"java"
);
rule
.
setTarget
(
s
);
rule
.
setId
(
UUIDUtil
.
getUUID
());
ruleDao
.
save
(
rule
);
}
}
/**
/**
* 新增规则
* 新增规则
...
...
src/main/java/com/zjty/inspect/utils/ExcelReader.java
deleted
100644 → 0
浏览文件 @
77026748
package
com
.
zjty
.
inspect
.
utils
;
import
com.zjty.inspect.entity.ExcelDataVo
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
ExcelReader
{
private
static
final
String
XLS
=
"xls"
;
private
static
final
String
XLSX
=
"xlsx"
;
/**
* 根据文件后缀名类型获取对应的工作簿对象
* @param inputStream 读取文件的输入流
* @param fileType 文件后缀名类型(xls或xlsx)
* @return 包含文件数据的工作簿对象
* @throws IOException
*/
public
static
Workbook
getWorkbook
(
InputStream
inputStream
,
String
fileType
)
throws
IOException
{
Workbook
workbook
=
null
;
if
(
fileType
.
equalsIgnoreCase
(
XLS
))
{
workbook
=
new
HSSFWorkbook
(
inputStream
);
}
else
if
(
fileType
.
equalsIgnoreCase
(
XLSX
))
{
workbook
=
new
XSSFWorkbook
(
inputStream
);
}
return
workbook
;
}
/**
* 读取Excel文件内容
* @param fileName 要读取的Excel文件所在路径
* @return 读取结果列表,读取失败时返回null
*/
public
static
List
<
ExcelDataVo
>
readExcel
(
String
fileName
)
{
Workbook
workbook
=
null
;
FileInputStream
inputStream
=
null
;
try
{
// 获取Excel后缀名
String
fileType
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
,
fileName
.
length
());
// 获取Excel文件
File
excelFile
=
new
File
(
fileName
);
if
(!
excelFile
.
exists
())
{
System
.
out
.
println
(
"指定的Excel文件不存在!"
);
return
null
;
}
// 获取Excel工作簿
inputStream
=
new
FileInputStream
(
excelFile
);
workbook
=
getWorkbook
(
inputStream
,
fileType
);
// 读取excel中的数据
List
<
ExcelDataVo
>
resultDataList
=
parseExcel
(
workbook
);
return
resultDataList
;
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"解析Excel失败,文件名:"
+
fileName
+
" 错误信息:"
+
e
.
getMessage
());
return
null
;
}
finally
{
try
{
if
(
null
!=
workbook
)
{
workbook
.
close
();
}
if
(
null
!=
inputStream
)
{
inputStream
.
close
();
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"关闭数据流出错!错误信息:"
+
e
.
getMessage
());
return
null
;
}
}
}
/**
* 解析Excel数据
* @param workbook Excel工作簿对象
* @return 解析结果
*/
private
static
List
<
ExcelDataVo
>
parseExcel
(
Workbook
workbook
)
{
List
<
ExcelDataVo
>
resultDataList
=
new
ArrayList
<>();
// 解析sheet
for
(
int
sheetNum
=
0
;
sheetNum
<
workbook
.
getNumberOfSheets
();
sheetNum
++)
{
Sheet
sheet
=
workbook
.
getSheetAt
(
sheetNum
);
// 校验sheet是否合法
if
(
sheet
==
null
)
{
continue
;
}
// 获取第一行数据
int
firstRowNum
=
sheet
.
getFirstRowNum
();
Row
firstRow
=
sheet
.
getRow
(
firstRowNum
);
if
(
null
==
firstRow
)
{
System
.
out
.
println
(
"解析Excel失败,在第一行没有读取到任何数据!"
);
}
// 解析每一行的数据,构造数据对象
int
rowStart
=
firstRowNum
+
1
;
int
rowEnd
=
sheet
.
getPhysicalNumberOfRows
();
for
(
int
rowNum
=
rowStart
;
rowNum
<
rowEnd
;
rowNum
++)
{
Row
row
=
sheet
.
getRow
(
rowNum
);
if
(
null
==
row
)
{
continue
;
}
ExcelDataVo
resultData
=
convertRowToData
(
row
);
if
(
null
==
resultData
)
{
System
.
out
.
println
(
"第 "
+
row
.
getRowNum
()
+
"行数据不合法,已忽略!"
);
continue
;
}
resultDataList
.
add
(
resultData
);
}
}
return
resultDataList
;
}
/**
* 将单元格内容转换为字符串
* @param cell
* @return
*/
private
static
String
convertCellValueToString
(
Cell
cell
)
{
if
(
cell
==
null
){
return
null
;
}
String
returnValue
=
null
;
switch
(
cell
.
getCellType
())
{
case
NUMERIC:
//数字
Double
doubleValue
=
cell
.
getNumericCellValue
();
// 格式化科学计数法,取一位整数
DecimalFormat
df
=
new
DecimalFormat
(
"0"
);
returnValue
=
df
.
format
(
doubleValue
);
break
;
case
STRING:
//字符串
returnValue
=
cell
.
getStringCellValue
();
break
;
case
BOOLEAN:
//布尔
Boolean
booleanValue
=
cell
.
getBooleanCellValue
();
returnValue
=
booleanValue
.
toString
();
break
;
case
BLANK:
// 空值
break
;
case
FORMULA:
// 公式
returnValue
=
cell
.
getCellFormula
();
break
;
case
ERROR:
// 故障
break
;
default
:
break
;
}
return
returnValue
;
}
/**
* 提取每一行中需要的数据,构造成为一个结果数据对象
*
* 当该行中有单元格的数据为空或不合法时,忽略该行的数据
*
* @param row 行数据
* @return 解析后的行数据对象,行数据错误时返回null
*/
private
static
ExcelDataVo
convertRowToData
(
Row
row
)
{
ExcelDataVo
resultData
=
new
ExcelDataVo
();
Cell
cell
;
int
cellNum
=
0
;
// 获取姓名
cell
=
row
.
getCell
(
cellNum
++);
String
name
=
convertCellValueToString
(
cell
);
resultData
.
setName
(
name
);
return
resultData
;
}
}
src/main/resources/application.properties
浏览文件 @
8568b692
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#spring.profiles.active=prod
#spring.profiles.active=prod
# \u670D\u52A1\u5668\u76F8\u5173\u914D\u7F6E
# \u670D\u52A1\u5668\u76F8\u5173\u914D\u7F6E
server.port
=
80
80
server.port
=
80
79
spring.jpa.database-platform
=
org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database-platform
=
org.hibernate.dialect.MySQL5InnoDBDialect
# \u65E5\u5FD7\u6587\u4EF6\u76F8\u5173\u914D\u7F6E
# \u65E5\u5FD7\u6587\u4EF6\u76F8\u5173\u914D\u7F6E
# logging.level.org.hibernate.sql=debug
# logging.level.org.hibernate.sql=debug
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论