Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
9
912fusion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
马晨俊
912fusion
Commits
9e9940bf
提交
9e9940bf
authored
3月 26, 2020
作者:
马晨俊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mcj:更新规则显示
上级
8adbace7
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
225 行增加
和
184 行删除
+225
-184
RuleController.java
...a/com/zjty/project/inspect/controller/RuleController.java
+3
-12
RuleAndReportVo.java
...java/com/zjty/project/inspect/entity/RuleAndReportVo.java
+0
-27
RuleCollection.java
.../java/com/zjty/project/inspect/entity/RuleCollection.java
+60
-0
Inspector.java
...main/java/com/zjty/project/inspect/inspect/Inspector.java
+48
-55
RuleService.java
...in/java/com/zjty/project/inspect/service/RuleService.java
+14
-11
RuleServiceImpl.java
...om/zjty/project/inspect/service/impl/RuleServiceImpl.java
+100
-79
没有找到文件。
src/main/java/com/zjty/project/inspect/controller/RuleController.java
浏览文件 @
9e9940bf
package
com
.
zjty
.
project
.
inspect
.
controller
;
import
com.zjty.project.inspect.entity.CustomPage
;
import
com.zjty.project.inspect.entity.PageResult
;
import
com.zjty.project.inspect.entity.RuleCollection
;
import
com.zjty.project.inspect.entity.RuleQo
;
import
com.zjty.project.inspect.service.RuleService
;
import
io.swagger.annotations.Api
;
...
...
@@ -77,16 +79,6 @@ public class RuleController {
return
ResponseEntity
.
ok
(
ruleService
.
findAll
());
}
/**
* 查询所有规则
* @return 规则
*/
@ApiOperation
(
"查询所有规则"
)
@GetMapping
(
"/test"
)
public
ResponseEntity
test
(){
ruleService
.
test
();
return
ResponseEntity
.
ok
(
200
);
}
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
...
...
@@ -101,7 +93,6 @@ public class RuleController {
})
@RequestMapping
(
value
=
"/search/{page}/{size}"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
findSearch
(
@RequestBody
Map
searchMap
,
@PathVariable
int
page
,
@PathVariable
int
size
){
CustomPage
<
RuleQo
>
search
=
ruleService
.
findSearch
(
searchMap
,
page
,
size
);
return
ResponseEntity
.
ok
(
search
);
return
ResponseEntity
.
ok
(
ruleService
.
findSearch
(
searchMap
,
page
,
size
));
}
}
src/main/java/com/zjty/project/inspect/entity/RuleAndReportVo.java
deleted
100644 → 0
浏览文件 @
8adbace7
package
com
.
zjty
.
project
.
inspect
.
entity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author Mcj
* @date 2020-02-27 14:42
*/
@Data
@ApiModel
(
value
=
"规则类"
)
public
class
RuleAndReportVo
{
/**
* 发现问题的文件地址
*/
private
String
filePath
;
/**
* 匹配行数
*/
@ApiModelProperty
(
value
=
"权限"
,
example
=
"1"
)
private
Integer
lineNum
;
}
src/main/java/com/zjty/project/inspect/entity/RuleCollection.java
0 → 100644
浏览文件 @
9e9940bf
package
com
.
zjty
.
project
.
inspect
.
entity
;
import
io.swagger.annotations.ApiModel
;
import
lombok.Data
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
java.util.Date
;
/**
* @author Mcj
* @date 2020-02-27 14:42
*/
@Data
@Entity
@ApiModel
(
value
=
"规则类"
)
public
class
RuleCollection
{
/**
* 主键id
*/
@Id
@Column
(
length
=
48
)
private
String
id
;
/**
* 技术名称
*/
private
String
technologyName
;
/**
* 目标关键字
*/
private
String
target
;
/**
* 匹配的文件后缀
*/
private
String
suffix
;
/**
* 适配技术id
*/
private
String
technologyId
;
/**
* 数据创建时间
*/
@Column
(
name
=
"create_time"
,
columnDefinition
=
"TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
,
insertable
=
false
,
updatable
=
false
)
@CreatedDate
private
Date
createDate
;
/**
* 数据更新时间
*/
@Column
(
name
=
"update_time"
,
columnDefinition
=
"TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
,
insertable
=
false
)
@LastModifiedDate
private
Date
updateDate
;
}
src/main/java/com/zjty/project/inspect/inspect/Inspector.java
浏览文件 @
9e9940bf
...
...
@@ -8,6 +8,7 @@ import com.zjty.project.inspect.enums.DependenceManagement;
import
com.zjty.project.inspect.enums.Framework
;
import
com.zjty.project.inspect.enums.Language
;
import
com.zjty.project.inspect.enums.RecastMethod
;
import
com.zjty.project.inspect.service.RuleService
;
import
com.zjty.project.inspect.utils.*
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
...
...
@@ -36,14 +37,13 @@ import java.util.stream.Collectors;
@Slf4j
@Transactional
()
public
class
Inspector
{
@Autowired
private
AnalysisFile
analysisFile
;
@Autowired
private
BudgetUitl
budgetUitl
;
@Autowired
private
Rule
Dao
ruleDao
;
private
Rule
Service
ruleService
;
@Autowired
private
TechnologyDao
technologyDao
;
@Autowired
...
...
@@ -138,6 +138,7 @@ public class Inspector {
/**
* 评估
*
* @return 报告
*/
public
ReportVo
inspect
()
throws
IOException
{
...
...
@@ -145,6 +146,7 @@ public class Inspector {
initData
();
//扫描文件
scanFiles
();
//配置
inspectParameter
.
setCodeSize
((
int
)
codeSize
);
report
.
setFileNum
(
fileNum
);
report
.
setFileLine
(
fileLine
);
...
...
@@ -152,7 +154,7 @@ public class Inspector {
//统计项目语言
setReportLanguageAndFrame
();
//根据扫描结果以及用户配置得出需要使用的规则及技术
ruleTransform
(
report
.
getRecastMethod
());
ruleTransform
(
inspectParameter
.
getRecastMethod
());
//解析配置文件集合
for
(
Map
.
Entry
<
String
,
List
<
Path
>>
entry
:
configFileTypePathsMapping
.
entrySet
())
{
switch
(
entry
.
getKey
())
{
...
...
@@ -169,6 +171,10 @@ public class Inspector {
for
(
PomDependency
dependency
:
projectPom
.
getDependencies
())
{
setRule
(
path
,
stringBuilder
,
dependency
);
}
List
<
String
>
lines
=
Files
.
readAllLines
(
path
);
for
(
int
i
=
0
;
i
<
lines
.
size
();
i
++)
{
valiWarn
(
rules
,
path
,
lines
.
get
(
i
),
i
+
1
);
}
dependencyVo
.
add
(
projectPom
);
}
}
...
...
@@ -192,7 +198,7 @@ public class Inspector {
//将文件的每一行都与规则匹配
List
<
String
>
strings
=
Files
.
readAllLines
(
path1
);
for
(
int
i
=
0
;
i
<
strings
.
size
();
i
++)
{
int
i1
=
valiWarn
(
rules
,
path1
,
strings
.
get
(
i
),
i
+
1
);
valiWarn
(
rules
,
path1
,
strings
.
get
(
i
),
i
+
1
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
"解析{}出错,异常信息为{}"
,
path1
.
toAbsolutePath
().
toString
(),
e
.
getMessage
());
...
...
@@ -222,7 +228,7 @@ public class Inspector {
report
.
setDependencyVo
(
dependencyVo
);
//数据转换
HashMap
<
String
,
List
<
Warn
>>
warnMap
=
getWarnMap
();
rule
Dao
.
saveAll
(
rules
);
rule
Service
.
addRule
(
rules
);
report
.
setWarnDetails
(
warnMap
);
log
.
info
(
"评估报告关键技术,{}"
,
warnMap
);
return
report
;
...
...
@@ -261,23 +267,24 @@ public class Inspector {
/**
* rule所需要数据装配
* @param status 状态
* 1:改造
* 2:适配
*/
private
void
ruleTransform
(
Integer
status
)
{
//如果需要改造则查询所有规则
if
(
status
==
1
)
{
List
<
Technology
>
front
=
technologyDao
.
findAllByBackorfrontEquals
(
1
);
List
<
String
>
ids
=
front
.
stream
().
map
(
Technology:
:
getId
).
collect
(
Collectors
.
toList
());
this
.
ruleList
=
ruleDao
.
findAllByTechnologyIdIn
(
ids
);
}
else
{
if
(
inspectParameter
.
getRecastMethod
()
==
1
)
{
this
.
ruleList
=
ruleDao
.
findAll
();
this
.
ruleList
=
ruleService
.
findRules
();
}
else
{
//只查询前端技术
List
<
Technology
>
front
=
technologyDao
.
findAllByBackorfrontEquals
(
1
);
List
<
String
>
i
ds
=
front
.
stream
().
map
(
Technology:
:
getId
).
collect
(
Collectors
.
toList
());
this
.
ruleList
=
ruleDao
.
findAllByTechnologyIdIn
(
i
ds
);
List
<
String
>
technologyI
ds
=
front
.
stream
().
map
(
Technology:
:
getId
).
collect
(
Collectors
.
toList
());
this
.
ruleList
=
ruleService
.
findAllByTechnologyIdIn
(
technologyI
ds
);
}
}
Set
<
String
>
id
=
ruleList
.
stream
().
map
(
Rule:
:
getTechnologyId
).
collect
(
Collectors
.
toSet
());
List
<
Technology
>
technologies
=
technologyDao
.
findAllByIdIn
(
new
ArrayList
<>(
id
));
//得到目前适用的技术id
Set
<
String
>
technologyIds
=
ruleList
.
stream
().
map
(
Rule:
:
getTechnologyId
).
collect
(
Collectors
.
toSet
());
List
<
Technology
>
technologies
=
technologyDao
.
findAllByIdIn
(
new
ArrayList
<>(
technologyIds
));
for
(
Technology
technology
:
technologies
)
{
technologyHashMap
.
put
(
technology
.
getId
(),
technology
);
}
...
...
@@ -291,13 +298,13 @@ public class Inspector {
}
}
ArrayList
<
String
>
ruleSuffixKeys
=
new
ArrayList
<>();
for
(
String
s
:
ruleSuffixFilePathMap
.
keySet
())
{
if
(!
ruleSuffixMap
.
containsKey
(
s
))
{
ruleSuffixKeys
.
add
(
s
);
for
(
String
s
uffix
:
ruleSuffixFilePathMap
.
keySet
())
{
if
(!
ruleSuffixMap
.
containsKey
(
s
uffix
))
{
ruleSuffixKeys
.
add
(
s
uffix
);
}
}
for
(
String
key
:
ruleSuffixKeys
)
{
ruleSuffixFilePathMap
.
remove
(
key
);
for
(
String
suffix
:
ruleSuffixKeys
)
{
ruleSuffixFilePathMap
.
remove
(
suffix
);
}
}
...
...
@@ -309,6 +316,7 @@ public class Inspector {
ruleSuffixFilePathMap
=
new
HashMap
<>();
ruleSuffixMap
=
new
HashMap
<>();
technologyHashMap
=
new
HashMap
<>();
supportWarns
=
new
ArrayList
<>();
warns
.
clear
();
rules
.
clear
();
//查询技术,构造支持与非支持技术对象,3个对象
...
...
@@ -341,9 +349,9 @@ public class Inspector {
* 查询三个默认依赖
*/
private
void
findExistTechnology
()
{
techJavaSupport
=
technologyDao
.
findAllByTechnologyNameEquals
(
"
国产化
依赖(支持)"
);
techNotCnSupport
=
technologyDao
.
findAllByTechnologyNameEquals
(
"
非国产化
依赖(不支持)"
);
techUnKnowSupport
=
technologyDao
.
findAllByTechnologyNameEquals
(
"
未知
依赖(未知)"
);
techJavaSupport
=
technologyDao
.
findAllByTechnologyNameEquals
(
"
内部
依赖(支持)"
);
techNotCnSupport
=
technologyDao
.
findAllByTechnologyNameEquals
(
"
内部
依赖(不支持)"
);
techUnKnowSupport
=
technologyDao
.
findAllByTechnologyNameEquals
(
"
内部
依赖(未知)"
);
}
/**
...
...
@@ -351,7 +359,7 @@ public class Inspector {
*/
private
void
initRule
()
{
//查询所有规则,第一遍扫描文件需要
this
.
ruleList
=
rule
Dao
.
findAll
();
this
.
ruleList
=
rule
Service
.
findRules
();
//根据后缀名,收集文件进行操作
for
(
Rule
rule
:
ruleList
)
{
if
(!
ruleSuffixFilePathMap
.
containsKey
(
rule
.
getSuffix
()))
{
...
...
@@ -417,39 +425,23 @@ public class Inspector {
private
void
setRule
(
Path
path
,
StringBuilder
stringBuilder
,
PomDependency
dependency
)
{
stringBuilder
.
append
(
dependency
.
getGroupId
()).
append
(
":"
).
append
(
dependency
.
getArtifactId
());
if
(
inspectParameter
.
getAdmin
()
==
1
)
{
Rule
rule
=
new
Rule
();
if
(
inspectParameter
.
getAdmin
()
==
1
)
{
rule
.
setTechnologyId
(
techJavaSupport
.
getId
());
rule
.
setTarget
(
dependency
.
getGroupId
());
rule
.
setTechnologyName
(
techJavaSupport
.
getTechnologyName
());
rule
.
setSuffix
(
"*"
);
rule
.
setId
(
UUIDUtil
.
getUUID
());
Rule
rule1
=
new
Rule
();
rule1
.
setTechnologyId
(
techJavaSupport
.
getId
());
rule1
.
setTarget
(
dependency
.
getArtifactId
());
rule1
.
setTechnologyName
(
techJavaSupport
.
getTechnologyName
());
rule1
.
setSuffix
(
"*"
);
rule1
.
setId
(
UUIDUtil
.
getUUID
());
if
(!
ruleMap
.
containsKey
(
dependency
.
getGroupId
()
+
":"
+
rule
.
getSuffix
()))
{
rules
.
add
(
rule
);
ruleMap
.
put
(
dependency
.
getGroupId
()
+
":"
+
rule
.
getSuffix
(),
rule
);
}
if
(!
ruleMap
.
containsKey
(
dependency
.
getArtifactId
()
+
":"
+
rule1
.
getSuffix
()))
{
rules
.
add
(
rule1
);
ruleMap
.
put
(
dependency
.
getArtifactId
()
+
":"
+
rule1
.
getSuffix
(),
rule1
);
}
dependency
.
setSupport
(
1
);
}
else
{
Rule
rule
=
new
Rule
();
rule
.
setTechnologyId
(
techUnKnowSupport
.
getId
());
rule
.
setTarget
(
dependency
.
getGroupId
());
rule
.
setTechnologyName
(
techUnKnowSupport
.
getTechnologyName
());
}
rule
.
setTarget
(
dependency
.
getGroupId
());
rule
.
setSuffix
(
"*"
);
rule
.
setId
(
UUIDUtil
.
getUUID
());
Rule
rule1
=
new
Rule
();
rule1
.
setTechnologyId
(
techUnKnow
Support
.
getId
());
rule1
.
setTechnologyId
(
techJava
Support
.
getId
());
rule1
.
setTarget
(
dependency
.
getArtifactId
());
rule1
.
setTechnologyName
(
techUnKnow
Support
.
getTechnologyName
());
rule1
.
setTechnologyName
(
techJava
Support
.
getTechnologyName
());
rule1
.
setSuffix
(
"*"
);
rule1
.
setId
(
UUIDUtil
.
getUUID
());
if
(!
ruleMap
.
containsKey
(
dependency
.
getGroupId
()
+
":"
+
rule
.
getSuffix
()))
{
...
...
@@ -460,10 +452,6 @@ public class Inspector {
rules
.
add
(
rule1
);
ruleMap
.
put
(
dependency
.
getArtifactId
()
+
":"
+
rule1
.
getSuffix
(),
rule1
);
}
int
i
=
valiWarn
(
ruleList
,
path
,
stringBuilder
.
toString
(),
0
);
dependency
.
setSupport
(
i
);
}
stringBuilder
.
delete
(
0
,
stringBuilder
.
length
());
}
...
...
@@ -508,9 +496,9 @@ public class Inspector {
if
(
supportWarns
.
size
()
!=
10
)
{
supportWarns
.
add
(
warn
);
}
Integer
size
=
report
.
getSupportSize
();
Integer
integer
=
s
ize
+
1
;
report
.
setSupportSize
(
i
nteger
);
Integer
s
upportS
ize
=
report
.
getSupportSize
();
int
i
=
supportS
ize
+
1
;
report
.
setSupportSize
(
i
);
supportStatus
=
1
;
}
}
...
...
@@ -518,6 +506,10 @@ public class Inspector {
return
supportStatus
;
}
/**
* 扫描源文件
* @throws IOException
*/
public
void
scanFiles
()
throws
IOException
{
//以下为计算文件名称匹配正则表达式
FileSystem
aDefault
=
FileSystems
.
getDefault
();
...
...
@@ -538,7 +530,7 @@ public class Inspector {
}
//文件读取
if
(
inspectParameter
.
getSourceAddress
()!=
null
)
{
if
(
inspectParameter
.
getSourceAddress
()
!=
null
)
{
Files
.
walkFileTree
(
Paths
.
get
(
inspectParameter
.
getSourceAddress
()),
new
FileVisitor
<
Path
>()
{
@Override
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
throws
IOException
{
...
...
@@ -629,6 +621,7 @@ public class Inspector {
});
}
}
public
class
Counter
{
private
int
i
=
0
;
...
...
src/main/java/com/zjty/project/inspect/service/RuleService.java
浏览文件 @
9e9940bf
package
com
.
zjty
.
project
.
inspect
.
service
;
import
com.zjty.project.inspect.entity.CustomPage
;
import
com.zjty.project.inspect.entity.RuleQo
;
import
com.zjty.project.inspect.entity.*
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -17,16 +16,13 @@ public interface RuleService {
* @param ruleQo 规则封装类
*/
public
void
addRule
(
RuleQo
ruleQo
);
public
void
addRule
(
List
<
Rule
>
rules
);
/**
* 修改规则
* @param ruleQo 规则封装类
*/
public
void
upRule
(
RuleQo
ruleQo
);
/**
* 根据id删除规则
* @param id
*/
public
void
deleteById
(
String
id
);
/**
* 删除规则
...
...
@@ -38,10 +34,17 @@ public interface RuleService {
* 查询所有规则
* @return 规则
*/
List
<
RuleQo
>
findAll
();
List
<
RuleCollection
>
findAll
();
/**
* 查询所有规则
* @return 规则
*/
List
<
Rule
>
findRules
();
List
<
RuleCollection
>
findByName
(
String
name
);
List
<
RuleQo
>
findByName
(
String
nam
e
);
CustomPage
<
RuleCollection
>
findSearch
(
Map
searchMap
,
int
page
,
int
siz
e
);
CustomPage
<
RuleQo
>
findSearch
(
Map
searchMap
,
int
page
,
int
size
);
void
test
();
List
<
Rule
>
findAllByTechnologyIdIn
(
List
<
String
>
technologyIds
);
}
src/main/java/com/zjty/project/inspect/service/impl/RuleServiceImpl.java
浏览文件 @
9e9940bf
package
com
.
zjty
.
project
.
inspect
.
service
.
impl
;
import
com.zjty.project.inspect.dao.RuleCollectionDao
;
import
com.zjty.project.inspect.dao.RuleDao
;
import
com.zjty.project.inspect.entity.CustomPage
;
import
com.zjty.project.inspect.entity.ExcelDataVo
;
import
com.zjty.project.inspect.entity.Rule
;
import
com.zjty.project.inspect.entity.RuleQo
;
import
com.zjty.project.inspect.entity.*
;
import
com.zjty.project.inspect.service.RuleService
;
import
com.zjty.project.inspect.service.TechnologyService
;
import
com.zjty.project.inspect.utils.ExcelReader
;
import
com.zjty.project.inspect.utils.UUIDUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Predicate
;
import
javax.persistence.criteria.Root
;
import
java.util.*
;
/**
...
...
@@ -39,31 +33,9 @@ public class RuleServiceImpl implements RuleService {
*/
@Autowired
private
RuleDao
ruleDao
;
@Autowired
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
);
}
}
@Autowired
private
RuleCollectionDao
ruleCollectionDao
;
/**
* 新增规则
...
...
@@ -76,7 +48,7 @@ public class RuleServiceImpl implements RuleService {
for
(
String
suffix
:
suffixes
)
{
Rule
rule1
=
ruleDao
.
findByTargetAndSuffixEqualsAndTechnologyIdEquals
(
ruleQo
.
getTarget
(),
suffix
,
ruleQo
.
getTechnologyId
());
if
(
rule1
!=
null
)
{
return
;
continue
;
}
Rule
rule
=
new
Rule
();
rule
.
setTarget
(
ruleQo
.
getTarget
());
...
...
@@ -86,9 +58,18 @@ public class RuleServiceImpl implements RuleService {
rule
.
setId
(
UUIDUtil
.
getUUID
());
ruleDao
.
save
(
rule
);
}
RuleCollection
ruleCollection
=
dataQo2RuleCollection
(
ruleQo
);
ruleCollectionDao
.
save
(
ruleCollection
);
}
@Override
public
void
addRule
(
List
<
Rule
>
rules
)
{
ruleDao
.
saveAll
(
rules
);
List
<
RuleCollection
>
ruleCollections
=
dataList2RuleCollection
(
rules
);
ruleCollectionDao
.
saveAll
(
ruleCollections
);
}
/**
* 条件查询+分页
*
...
...
@@ -98,17 +79,22 @@ public class RuleServiceImpl implements RuleService {
* @return
*/
@Override
public
CustomPage
<
RuleQo
>
findSearch
(
Map
whereMap
,
int
page
,
int
size
)
{
Specification
<
Rule
>
specification
=
createSpecification
(
whereMap
);
PageRequest
pageRequest
=
PageRequest
.
of
(
page
-
1
,
size
);
Page
<
Rule
>
all
=
ruleDao
.
findAll
(
specification
,
pageRequest
);
List
<
RuleQo
>
ruleQos
=
data2RuleQo
(
all
.
getContent
());
public
CustomPage
<
RuleCollection
>
findSearch
(
Map
whereMap
,
int
page
,
int
size
)
{
Specification
<
RuleCollection
>
specification
=
createSpecification
(
whereMap
);
Sort
sort
=
new
Sort
(
Sort
.
Direction
.
DESC
,
"updateDate"
);
PageRequest
pageRequest
=
PageRequest
.
of
(
page
-
1
,
size
,
sort
);
Page
<
RuleCollection
>
ruleCollections
=
ruleCollectionDao
.
findAll
(
specification
,
pageRequest
);
CustomPage
<
RuleCollection
>
customPage
=
new
CustomPage
<>();
customPage
.
setTotalPage
(
ruleCollections
.
getTotalPages
());
customPage
.
setTotalElement
((
int
)
ruleCollections
.
getTotalElements
());
customPage
.
setObjects
(
ruleCollections
.
getContent
());
return
customPage
;
}
CustomPage
<
RuleQo
>
myCustomPage
=
new
CustomPage
<>();
myCustomPage
.
setTotalPage
(
all
.
getTotalPages
());
myCustomPage
.
setTotalElement
((
int
)
all
.
getTotalElements
());
myCustomPage
.
setObjects
(
ruleQos
);
return
myCustomPage
;
@Override
public
List
<
Rule
>
findAllByTechnologyIdIn
(
List
<
String
>
technologyIds
)
{
return
ruleDao
.
findAllByTechnologyIdIn
(
technologyIds
);
}
/**
...
...
@@ -117,22 +103,18 @@ public class RuleServiceImpl implements RuleService {
* @param searchMap
* @return
*/
private
Specification
<
Rule
>
createSpecification
(
Map
searchMap
)
{
private
Specification
<
Rule
Collection
>
createSpecification
(
Map
searchMap
)
{
return
new
Specification
<
Rule
>()
{
@Override
public
Predicate
toPredicate
(
Root
<
Rule
>
root
,
CriteriaQuery
<?>
query
,
CriteriaBuilder
cb
)
{
List
<
Predicate
>
predicateList
=
new
ArrayList
<
Predicate
>();
return
(
root
,
query
,
cb
)
->
{
List
<
Predicate
>
predicateList
=
new
ArrayList
<>();
if
(
searchMap
.
get
(
"technologyName"
)
!=
null
&&
!
""
.
equals
(
searchMap
.
get
(
"technologyName"
)))
{
predicateList
.
add
(
cb
.
like
(
root
.
get
(
"technologyName"
).
as
(
String
.
class
),
"%"
+
(
String
)
searchMap
.
get
(
"technologyName"
)
+
"%"
));
predicateList
.
add
(
cb
.
like
(
root
.
get
(
"technologyName"
).
as
(
String
.
class
),
"%"
+
searchMap
.
get
(
"technologyName"
)
+
"%"
));
}
if
(
searchMap
.
get
(
"target"
)
!=
null
&&
!
""
.
equals
(
searchMap
.
get
(
"target"
)))
{
predicateList
.
add
(
cb
.
like
(
root
.
get
(
"target"
).
as
(
String
.
class
),
"%"
+
(
String
)
searchMap
.
get
(
"target"
)
+
"%"
));
predicateList
.
add
(
cb
.
like
(
root
.
get
(
"target"
).
as
(
String
.
class
),
"%"
+
searchMap
.
get
(
"target"
)
+
"%"
));
}
return
cb
.
and
(
predicateList
.
toArray
(
new
Predicate
[
predicateList
.
size
()]));
}
};
}
...
...
@@ -141,16 +123,16 @@ public class RuleServiceImpl implements RuleService {
public
void
upRule
(
RuleQo
ruleQo
)
{
RuleQo
oldRule
=
ruleQo
.
getOldRule
();
List
<
Rule
>
rules
=
ruleDao
.
findAllByTechnologyIdEqualsAndTargetEquals
(
oldRule
.
getTechnologyId
(),
oldRule
.
getTarget
());
RuleCollection
ruleCollection
=
ruleCollectionDao
.
findAllByTechnologyIdEqualsAndTargetEquals
(
oldRule
.
getTechnologyId
(),
oldRule
.
getTarget
());
for
(
Rule
rule
:
rules
)
{
ruleDao
.
deleteById
(
rule
.
getId
());
}
if
(
ruleCollection
!=
null
){
ruleCollectionDao
.
deleteById
(
ruleCollection
.
getId
());
}
addRule
(
ruleQo
);
}
@Override
public
void
deleteById
(
String
id
)
{
ruleDao
.
deleteById
(
id
);
}
@Override
@Modifying
...
...
@@ -159,6 +141,11 @@ public class RuleServiceImpl implements RuleService {
for
(
Rule
rule
:
rules
)
{
ruleDao
.
deleteById
(
rule
.
getId
());
}
RuleCollection
ruleCollection
=
ruleCollectionDao
.
findAllByTechnologyIdEqualsAndTargetEquals
(
ruleQo
.
getTechnologyId
(),
ruleQo
.
getTarget
());
if
(
ruleCollection
!=
null
){
ruleCollectionDao
.
deleteById
(
ruleCollection
.
getId
());
}
}
/**
...
...
@@ -172,40 +159,74 @@ public class RuleServiceImpl implements RuleService {
* @return RuleVoList
*/
@Override
public
List
<
RuleQo
>
findAll
()
{
List
<
Rule
>
rules
=
ruleDao
.
findAll
();
List
<
RuleQo
>
ruleQos
=
data2RuleQo
(
rules
);
return
ruleQos
;
public
List
<
RuleCollection
>
findAll
()
{
List
<
RuleCollection
>
rules
=
ruleCollectionDao
.
findAll
();
return
rules
;
}
@Override
public
List
<
Rule
>
findRules
()
{
return
ruleDao
.
findAll
();
}
@Override
public
List
<
RuleQo
>
findByName
(
String
name
)
{
List
<
Rule
>
rules
=
ruleDao
.
findAllByTargetLike
(
"%"
+
name
+
"%"
);
if
(
rules
!=
null
&&
rules
.
size
()
>
0
)
{
return
data2RuleQo
(
rules
);
public
List
<
RuleCollection
>
findByName
(
String
name
)
{
List
<
RuleCollection
>
rules
=
ruleCollectionDao
.
findAllByTargetLike
(
"%"
+
name
+
"%"
);
return
rules
;
}
private
RuleCollection
dataQo2RuleCollection
(
RuleQo
ruleQo
){
RuleCollection
ruleCollection
=
new
RuleCollection
();
ruleCollection
.
setTechnologyName
(
ruleQo
.
getTechnologyName
());
ruleCollection
.
setTechnologyId
(
ruleQo
.
getTechnologyId
());
ruleCollection
.
setTarget
(
ruleQo
.
getTarget
());
ruleCollection
.
setId
(
UUIDUtil
.
getUUID
());
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
String
suffix
:
ruleQo
.
getSuffix
())
{
if
(
stringBuilder
.
length
()==
0
){
stringBuilder
.
append
(
suffix
);
}
else
{
stringBuilder
.
append
(
","
).
append
(
suffix
);
}
return
null
;
}
ruleCollection
.
setSuffix
(
stringBuilder
.
toString
());
return
ruleCollection
;
}
private
List
<
RuleQo
>
data2RuleQo
(
List
<
Rule
>
rules
){
HashMap
<
String
,
RuleQo
>
hashMap
=
new
HashMap
<>();
private
List
<
RuleCollection
>
dataList2RuleCollection
(
List
<
Rule
>
rules
){
ArrayList
<
RuleCollection
>
ruleCollections
=
new
ArrayList
<>();
HashMap
<
String
,
ArrayList
<
String
>>
map
=
new
HashMap
<>();
HashMap
<
String
,
Rule
>
ruleMap
=
new
HashMap
<>();
for
(
Rule
rule
:
rules
)
{
if
(!
hashMap
.
containsKey
(
rule
.
getTarget
()+
rule
.
getTechnologyId
())){
RuleQo
ruleQo
=
new
RuleQo
();
ruleQo
.
setId
(
rule
.
getId
());
ruleQo
.
setTarget
(
rule
.
getTarget
());
ruleQo
.
setTechnologyId
(
rule
.
getTechnologyId
());
ruleQo
.
setTechnologyName
(
rule
.
getTechnologyName
());
ruleMap
.
put
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
(),
rule
);
if
(
map
.
containsKey
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
())){
ArrayList
<
String
>
suffix
=
map
.
get
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
());
suffix
.
add
(
rule
.
getSuffix
());
}
else
{
ArrayList
<
String
>
suffix
=
new
ArrayList
<>();
suffix
.
add
(
rule
.
getSuffix
());
ruleQo
.
setSuffix
(
suffix
);
hashMap
.
put
(
rule
.
getTarget
()+
rule
.
getTechnologyId
(),
ruleQo
);
map
.
put
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
(),
suffix
);
}
}
for
(
String
target
:
map
.
keySet
())
{
Rule
rule
=
ruleMap
.
get
(
target
);
RuleCollection
ruleCollection
=
new
RuleCollection
();
ruleCollection
.
setTarget
(
rule
.
getTarget
());
ruleCollection
.
setTechnologyId
(
rule
.
getTechnologyId
());
ruleCollection
.
setTechnologyName
(
rule
.
getTechnologyName
());
ruleCollection
.
setId
(
UUIDUtil
.
getUUID
());
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
String
suffix
:
map
.
get
(
target
))
{
if
(
stringBuilder
.
length
()==
0
){
stringBuilder
.
append
(
suffix
);
}
else
{
RuleQo
ruleQo
=
hashMap
.
get
(
rule
.
getTarget
()
+
rule
.
getTechnologyId
()
);
ruleQo
.
getSuffix
().
add
(
rule
.
getSuffix
());
stringBuilder
.
append
(
","
).
append
(
suffix
);
}
}
ruleCollection
.
setSuffix
(
stringBuilder
.
toString
());
ruleCollections
.
add
(
ruleCollection
);
}
return
new
ArrayList
<>(
hashMap
.
values
())
;
return
ruleCollections
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论