Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspect
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
inspect
Commits
32f582fe
提交
32f582fe
authored
3月 25, 2020
作者:
马晨俊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mcj:新增规则查询逻辑,新增表
上级
760b10ab
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
172 行增加
和
80 行删除
+172
-80
RuleController.java
...main/java/com/zjty/inspect/controller/RuleController.java
+2
-5
Rule.java
src/main/java/com/zjty/inspect/entity/Rule.java
+1
-1
RuleAndReportVo.java
src/main/java/com/zjty/inspect/entity/RuleAndReportVo.java
+0
-27
RuleCollection.java
src/main/java/com/zjty/inspect/entity/RuleCollection.java
+61
-0
RuleService.java
src/main/java/com/zjty/inspect/service/RuleService.java
+4
-8
RuleServiceImpl.java
...n/java/com/zjty/inspect/service/impl/RuleServiceImpl.java
+57
-39
task.java
src/main/java/com/zjty/inspect/task/task.java
+47
-0
没有找到文件。
src/main/java/com/zjty/inspect/controller/RuleController.java
浏览文件 @
32f582fe
package
com
.
zjty
.
inspect
.
controller
;
import
com.zjty.inspect.entity.Page
;
import
com.zjty.inspect.entity.PageResult
;
import
com.zjty.inspect.entity.Rule
;
import
com.zjty.inspect.entity.RuleQo
;
import
com.zjty.inspect.entity.*
;
import
com.zjty.inspect.service.RuleService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
...
...
@@ -92,7 +89,7 @@ public class RuleController {
})
@RequestMapping
(
value
=
"/search/{page}/{size}"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
findSearch
(
@RequestBody
Map
searchMap
,
@PathVariable
int
page
,
@PathVariable
int
size
){
Page
<
Rule
Qo
>
search
=
ruleService
.
findSearch
(
searchMap
,
page
,
size
);
Page
<
Rule
Collection
>
search
=
ruleService
.
findSearch
(
searchMap
,
page
,
size
);
return
ResponseEntity
.
ok
(
search
);
}
}
src/main/java/com/zjty/inspect/entity/Rule.java
浏览文件 @
32f582fe
...
...
@@ -32,7 +32,7 @@ public class Rule {
@Column
(
length
=
48
)
private
String
id
;
/**
*
建议
*
适配技术名称
*/
private
String
technologyName
;
/**
...
...
src/main/java/com/zjty/inspect/entity/RuleAndReportVo.java
deleted
100644 → 0
浏览文件 @
760b10ab
package
com
.
zjty
.
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/inspect/entity/RuleCollection.java
0 → 100644
浏览文件 @
32f582fe
package
com
.
zjty
.
inspect
.
entity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
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/inspect/service/RuleService.java
浏览文件 @
32f582fe
package
com
.
zjty
.
inspect
.
service
;
import
com.zjty.inspect.entity.Page
;
import
com.zjty.inspect.entity.RuleCollection
;
import
com.zjty.inspect.entity.RuleQo
;
import
java.util.List
;
...
...
@@ -21,11 +22,6 @@ public interface RuleService {
* @param ruleQo 规则封装类
*/
public
void
upRule
(
RuleQo
ruleQo
);
/**
* 根据id删除规则
* @param id
*/
public
void
deleteById
(
String
id
);
/**
* 删除规则
...
...
@@ -37,9 +33,9 @@ public interface RuleService {
* 查询所有规则
* @return 规则
*/
List
<
Rule
Qo
>
findAll
();
List
<
Rule
Collection
>
findAll
();
List
<
Rule
Qo
>
findByName
(
String
name
);
List
<
Rule
Collection
>
findByName
(
String
name
);
Page
<
Rule
Qo
>
findSearch
(
Map
searchMap
,
int
page
,
int
size
);
Page
<
Rule
Collection
>
findSearch
(
Map
searchMap
,
int
page
,
int
size
);
}
src/main/java/com/zjty/inspect/service/impl/RuleServiceImpl.java
浏览文件 @
32f582fe
package
com
.
zjty
.
inspect
.
service
.
impl
;
import
com.zjty.inspect.dao.RuleCollectionDao
;
import
com.zjty.inspect.dao.RuleDao
;
import
com.zjty.inspect.entity.ExcelDataVo
;
import
com.zjty.inspect.entity.Rule
;
import
com.zjty.inspect.entity.RuleCollection
;
import
com.zjty.inspect.entity.RuleQo
;
import
com.zjty.inspect.service.RuleService
;
import
com.zjty.inspect.service.TechnologyService
;
...
...
@@ -38,9 +40,9 @@ public class RuleServiceImpl implements RuleService {
*/
@Autowired
private
RuleDao
ruleDao
;
@Autowired
private
TechnologyService
technologyService
;
@Autowired
private
RuleCollectionDao
ruleCollectionDao
;
/**
* 新增规则
...
...
@@ -53,7 +55,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
());
...
...
@@ -63,6 +65,8 @@ public class RuleServiceImpl implements RuleService {
rule
.
setId
(
UUIDUtil
.
getUUID
());
ruleDao
.
save
(
rule
);
}
RuleCollection
ruleCollection
=
data2RuleCollection
(
ruleQo
);
ruleCollectionDao
.
save
(
ruleCollection
);
}
...
...
@@ -75,17 +79,16 @@ public class RuleServiceImpl implements RuleService {
* @return
*/
@Override
public
com
.
zjty
.
inspect
.
entity
.
Page
<
Rule
Qo
>
findSearch
(
Map
whereMap
,
int
page
,
int
size
)
{
Specification
<
Rule
>
specification
=
createSpecification
(
whereMap
);
public
com
.
zjty
.
inspect
.
entity
.
Page
<
Rule
Collection
>
findSearch
(
Map
whereMap
,
int
page
,
int
size
)
{
Specification
<
Rule
Collection
>
specification
=
createSpecification
(
whereMap
);
Sort
sort
=
new
Sort
(
Sort
.
Direction
.
DESC
,
"updateDate"
);
PageRequest
pageRequest
=
PageRequest
.
of
(
page
-
1
,
size
,
sort
);
Page
<
Rule
>
all
=
ruleDao
.
findAll
(
specification
,
pageRequest
);
List
<
RuleQo
>
ruleQos
=
data2RuleQo
(
all
.
getContent
());
Page
<
RuleCollection
>
ruleCollections
=
ruleCollectionDao
.
findAll
(
specification
,
pageRequest
);
com
.
zjty
.
inspect
.
entity
.
Page
<
Rule
Qo
>
myPage
=
new
com
.
zjty
.
inspect
.
entity
.
Page
<>();
myPage
.
setTotalPage
(
all
.
getTotalPages
());
myPage
.
setTotalElement
((
int
)
all
.
getTotalElements
());
myPage
.
setObjects
(
rule
Qos
);
com
.
zjty
.
inspect
.
entity
.
Page
<
Rule
Collection
>
myPage
=
new
com
.
zjty
.
inspect
.
entity
.
Page
<>();
myPage
.
setTotalPage
(
ruleCollections
.
getTotalPages
());
myPage
.
setTotalElement
((
int
)
ruleCollections
.
getTotalElements
());
myPage
.
setObjects
(
rule
Collections
.
getContent
()
);
return
myPage
;
}
...
...
@@ -95,22 +98,18 @@ public class RuleServiceImpl implements RuleService {
* @param searchMap
* @return
*/
private
Specification
<
Rule
>
createSpecification
(
Map
searchMap
)
{
return
new
Specification
<
Rule
>()
{
@Override
public
Predicate
toPredicate
(
Root
<
Rule
>
root
,
CriteriaQuery
<?>
query
,
CriteriaBuilder
cb
)
{
List
<
Predicate
>
predicateList
=
new
ArrayList
<
Predicate
>();
if
(
searchMap
.
get
(
"technologyName"
)
!=
null
&&
!
""
.
equals
(
searchMap
.
get
(
"technologyName"
)))
{
predicateList
.
add
(
cb
.
like
(
root
.
get
(
"technologyName"
).
as
(
String
.
class
),
"%"
+
(
String
)
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"
)
+
"%"
));
}
return
cb
.
and
(
predicateList
.
toArray
(
new
Predicate
[
predicateList
.
size
()]));
private
Specification
<
RuleCollection
>
createSpecification
(
Map
searchMap
)
{
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
),
"%"
+
searchMap
.
get
(
"technologyName"
)
+
"%"
));
}
if
(
searchMap
.
get
(
"target"
)
!=
null
&&
!
""
.
equals
(
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
()]));
};
}
...
...
@@ -119,16 +118,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
...
...
@@ -137,6 +136,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
());
}
}
/**
...
...
@@ -150,19 +154,15 @@ 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
<
RuleQo
>
findByName
(
String
name
)
{
List
<
Rule
>
rules
=
ruleDao
.
findAllByTargetLike
(
"%"
+
name
+
"%"
);
if
(
rules
!=
null
&&
rules
.
size
()
>
0
)
{
return
data2RuleQo
(
rules
);
}
return
null
;
public
List
<
RuleCollection
>
findByName
(
String
name
)
{
List
<
RuleCollection
>
rules
=
ruleCollectionDao
.
findAllByTargetLike
(
"%"
+
name
+
"%"
);
return
rules
;
}
private
List
<
RuleQo
>
data2RuleQo
(
List
<
Rule
>
rules
){
...
...
@@ -186,4 +186,22 @@ public class RuleServiceImpl implements RuleService {
}
return
new
ArrayList
<>(
hashMap
.
values
());
}
private
RuleCollection
data2RuleCollection
(
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
);
}
}
ruleCollection
.
setSuffix
(
stringBuilder
.
toString
());
return
ruleCollection
;
}
}
src/main/java/com/zjty/inspect/task/task.java
浏览文件 @
32f582fe
package
com
.
zjty
.
inspect
.
task
;
import
com.zjty.inspect.dao.CoefficientModelDao
;
import
com.zjty.inspect.dao.RuleCollectionDao
;
import
com.zjty.inspect.dao.RuleDao
;
import
com.zjty.inspect.dao.TechnologyDao
;
import
com.zjty.inspect.entity.CoefficientModel
;
import
com.zjty.inspect.entity.Rule
;
import
com.zjty.inspect.entity.RuleCollection
;
import
com.zjty.inspect.entity.Technology
;
import
com.zjty.inspect.service.InspectService
;
import
com.zjty.inspect.utils.AnalysisFile
;
...
...
@@ -37,6 +39,9 @@ public class task implements CommandLineRunner {
@Autowired
private
InspectService
inspectService
;
@Autowired
private
RuleCollectionDao
ruleCollectionDao
;
@Autowired
private
AnalysisFile
analysisFile
;
...
...
@@ -257,5 +262,47 @@ public class task implements CommandLineRunner {
// ruleDao.save(rule);
// ruleDao.save(NotCnJavaTechnology);
// ruleDao.save(UnknowunMysqlRule);
//文件后缀map
if
(
ruleCollectionDao
.
count
()!=
0
){
return
;
}
HashMap
<
String
,
ArrayList
<
String
>>
map
=
new
HashMap
<>();
//
HashMap
<
String
,
Rule
>
map1
=
new
HashMap
<>();
ArrayList
<
RuleCollection
>
ruleCollections
=
new
ArrayList
<>();
List
<
Rule
>
all
=
ruleDao
.
findAll
();
for
(
Rule
rule
:
all
)
{
if
(!
map
.
containsKey
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
())){
ArrayList
<
String
>
suffixes
=
new
ArrayList
<>();
suffixes
.
add
(
rule
.
getSuffix
());
map
.
put
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
(),
suffixes
);
}
else
{
map
.
get
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
()).
add
(
rule
.
getSuffix
());
}
map1
.
put
(
rule
.
getTarget
()+
":"
+
rule
.
getTechnologyId
(),
rule
);
}
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
String
key
:
map
.
keySet
())
{
RuleCollection
ruleCollection
=
new
RuleCollection
();
ruleCollection
.
setId
(
UUIDUtil
.
getUUID
());
ArrayList
<
String
>
suffixes
=
map
.
get
(
key
);
for
(
String
suffix
:
suffixes
)
{
if
(
stringBuilder
.
length
()==
0
){
stringBuilder
.
append
(
suffix
);
}
else
{
stringBuilder
.
append
(
","
).
append
(
suffix
);
}
}
ruleCollection
.
setSuffix
(
stringBuilder
.
toString
());
stringBuilder
.
delete
(
0
,
stringBuilder
.
length
());
Rule
rule
=
map1
.
get
(
key
);
ruleCollection
.
setTarget
(
rule
.
getTarget
());
ruleCollection
.
setTechnologyId
(
rule
.
getTechnologyId
());
ruleCollection
.
setTechnologyName
(
rule
.
getTechnologyName
());
ruleCollections
.
add
(
ruleCollection
);
}
ruleCollectionDao
.
saveAll
(
ruleCollections
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论