Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
test
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
邬友楠
test
Commits
eaff27b8
Commit
eaff27b8
authored
Mar 09, 2021
by
雍欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
改造附件列表查询逻辑,根据登录人员密级过滤掉不满足密级要求的附件
parent
ba9a9b3b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
176 additions
and
75 deletions
+176
-75
SecrecyLevelComparator.java
...mp/doc/attachment/application/SecrecyLevelComparator.java
+12
-0
AbstractAttachmentSecretInfoResolver.java
...pplication/impl/AbstractAttachmentSecretInfoResolver.java
+68
-0
AttachmentApplicationImpl.java
...ttachment/application/impl/AttachmentApplicationImpl.java
+44
-15
BasedOnSequenceSecrecyLevelComparator.java
...plication/impl/BasedOnSequenceSecrecyLevelComparator.java
+34
-0
TestAttachmentSecretInfoResolver.java
...nt/application/impl/TestAttachmentSecretInfoResolver.java
+5
-48
WebUploaderServiceImpl.java
...c/attachment/application/impl/WebUploaderServiceImpl.java
+7
-9
application.properties
huigou-xt/src/main/resources/application.properties
+3
-0
spring-extend.xml
huigou-xt/src/main/resources/config/spring/spring-extend.xml
+3
-3
No files found.
huigou-uasp/src/main/java/com/huigou/uasp/bmp/doc/attachment/application/SecrecyLevelComparator.java
0 → 100644
View file @
eaff27b8
package
com
.
huigou
.
uasp
.
bmp
.
doc
.
attachment
.
application
;
import
java.util.Comparator
;
/**
* 密级比较器。
*
* @author yonghuan
*/
@FunctionalInterface
public
interface
SecrecyLevelComparator
extends
Comparator
<
String
>
{
}
huigou-uasp/src/main/java/com/huigou/uasp/bmp/doc/attachment/application/impl/AbstractAttachmentSecretInfoResolver.java
0 → 100644
View file @
eaff27b8
package
com
.
huigou
.
uasp
.
bmp
.
doc
.
attachment
.
application
.
impl
;
import
com.huigou.context.ThreadLocalUtil
;
import
com.huigou.uasp.bmp.doc.attachment.application.AttachmentSecretInfoResolver
;
import
com.huigou.uasp.bmp.doc.attachment.application.SecrecyLevelComparator
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.AttachmentConfiguration
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.FileInfo
;
import
com.huigou.uasp.bmp.doc.attachment.repository.AttachmentConfigurationRepository
;
import
com.huigou.uasp.bmp.opm.application.OrgApplication
;
import
com.huigou.uasp.bmp.opm.domain.model.org.Person
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.Assert
;
import
java.util.Objects
;
/**
* @author yonghuan
*/
public
abstract
class
AbstractAttachmentSecretInfoResolver
implements
AttachmentSecretInfoResolver
{
private
AttachmentConfigurationRepository
attachmentConfigurationRepository
;
private
OrgApplication
orgApplication
;
private
SecrecyLevelComparator
secrecyLevelComparator
;
@Autowired
public
void
setAttachmentConfigurationRepository
(
AttachmentConfigurationRepository
attachmentConfigurationRepository
)
{
this
.
attachmentConfigurationRepository
=
attachmentConfigurationRepository
;
}
@Autowired
public
void
setOrgApplication
(
OrgApplication
orgApplication
)
{
this
.
orgApplication
=
orgApplication
;
}
@Autowired
public
void
setSecrecyLevelComparator
(
SecrecyLevelComparator
secrecyLevelComparator
)
{
this
.
secrecyLevelComparator
=
secrecyLevelComparator
;
}
@Override
public
String
resolve
(
FileInfo
fileInfo
)
{
AttachmentConfiguration
attachmentConfiguration
=
attachmentConfigurationRepository
.
findByCode
(
fileInfo
.
getBizCode
());
if
(
attachmentConfiguration
==
null
)
{
return
null
;
}
if
(!
Objects
.
equals
(
attachmentConfiguration
.
getEnableSecret
(),
1
))
{
// 未启用密级
return
null
;
}
// 1、解析附件密级
String
attachmentSecurityLevel
=
resolveAttachmentSecurityLevel
(
fileInfo
);
// 2、校验附件密级是否与人员密级匹配
Person
person
=
orgApplication
.
loadPerson
(
ThreadLocalUtil
.
getOperator
().
getUserId
());
boolean
personSecurityGradeGreaterThanAttachmentSecurityGrade
=
secrecyLevelComparator
.
compare
(
person
.
getPersonSecurityGrade
(),
attachmentSecurityLevel
)
>
-
1
;
Assert
.
isTrue
(
personSecurityGradeGreaterThanAttachmentSecurityGrade
,
"附件密级与人员密级不匹配"
);
// 3、校验附件密级是否与表单密级匹配
Assert
.
hasText
(
fileInfo
.
getFormSecretLevel
(),
"表单密级不能为空"
);
boolean
formSecurityGradeThanAttachmentSecurityGrade
=
secrecyLevelComparator
.
compare
(
fileInfo
.
getFormSecretLevel
(),
attachmentSecurityLevel
)
>
-
1
;
Assert
.
isTrue
(
formSecurityGradeThanAttachmentSecurityGrade
,
"附件密级与表单密级不匹配"
);
// 4、返回附件密级
return
attachmentSecurityLevel
;
}
/**
* 解析附件密级。
*/
protected
abstract
String
resolveAttachmentSecurityLevel
(
FileInfo
fileInfo
);
}
huigou-uasp/src/main/java/com/huigou/uasp/bmp/doc/attachment/application/impl/AttachmentApplicationImpl.java
View file @
eaff27b8
package
com
.
huigou
.
uasp
.
bmp
.
doc
.
attachment
.
application
.
impl
;
import
java.sql.Types
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
com.huigou.context.MessageSourceContext
;
import
com.huigou.context.Operator
;
import
com.huigou.context.ThreadLocalUtil
;
...
...
@@ -23,15 +12,27 @@ import com.huigou.exception.ApplicationException;
import
com.huigou.uasp.bmp.common.application.BaseApplication
;
import
com.huigou.uasp.bmp.doc.attachment.application.AttachmentApplication
;
import
com.huigou.uasp.bmp.doc.attachment.application.AttachmentQueryApplication
;
import
com.huigou.uasp.bmp.doc.attachment.application.SecrecyLevelComparator
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.Attachment
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.AttachmentConfiguration
;
import
com.huigou.uasp.bmp.doc.attachment.domain.query.AttachmentConfigurationDesc
;
import
com.huigou.uasp.bmp.doc.attachment.repository.AttachmentConfigurationRepository
;
import
com.huigou.uasp.bmp.doc.attachment.repository.AttachmentRepository
;
import
com.huigou.uasp.bmp.opm.application.OrgApplication
;
import
com.huigou.uasp.bmp.opm.domain.model.org.Person
;
import
com.huigou.util.CommonUtil
;
import
com.huigou.util.DateUtil
;
import
com.huigou.util.FileHelper
;
import
com.huigou.util.StringUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
java.sql.Types
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
(
"attachmentApplication"
)
public
class
AttachmentApplicationImpl
extends
BaseApplication
implements
AttachmentApplication
,
AttachmentQueryApplication
{
...
...
@@ -41,6 +42,12 @@ public class AttachmentApplicationImpl extends BaseApplication implements Attach
@Autowired
private
AttachmentRepository
attachmentRepository
;
@Autowired
private
AttachmentConfigurationRepository
attachmentConfigurationRepository
;
@Autowired
private
OrgApplication
orgApplication
;
@Autowired
private
SecrecyLevelComparator
secrecyLevelComparator
;
@Override
@Transactional
...
...
@@ -49,7 +56,7 @@ public class AttachmentApplicationImpl extends BaseApplication implements Attach
attachmentConfiguration
=
(
AttachmentConfiguration
)
this
.
commonDomainService
.
loadAndFillinProperties
(
attachmentConfiguration
);
attachmentConfiguration
.
buildDetails
();
attachmentConfiguration
=
(
AttachmentConfiguration
)
this
.
commonDomainService
.
saveBaseInfoWithFolderEntity
(
attachmentConfiguration
,
configurationRepository
);
configurationRepository
);
return
attachmentConfiguration
.
getId
();
}
...
...
@@ -113,7 +120,7 @@ public class AttachmentApplicationImpl extends BaseApplication implements Attach
/**
* 判断是否允许多个文件
*
*
* @param attachment
*/
private
void
checkNeedMoreFile
(
Attachment
attachment
)
{
...
...
@@ -208,11 +215,33 @@ public class AttachmentApplicationImpl extends BaseApplication implements Attach
public
List
<
Attachment
>
queryAttachments
(
String
bizKindId
,
String
bizId
)
{
Assert
.
hasText
(
bizKindId
,
"参数bizKindId不能为空。"
);
Assert
.
hasText
(
bizId
,
"参数bizId不能为空。"
);
List
<
Attachment
>
attachments
=
this
.
attachmentRepository
.
findValidAttachments
(
bizKindId
,
bizId
);
if
(
attachments
.
isEmpty
())
{
return
attachments
;
}
AttachmentConfiguration
attachmentConfiguration
=
attachmentConfigurationRepository
.
findByCode
(
bizKindId
);
if
(
attachmentConfiguration
!=
null
)
{
if
(
Objects
.
equals
(
attachmentConfiguration
.
getEnableSecret
(),
1
))
{
Person
person
=
orgApplication
.
loadPerson
(
ThreadLocalUtil
.
getOperator
().
getUserId
());
return
attachments
.
stream
()
.
filter
(
attachment
->
matchingSecretLevel
(
person
,
attachment
))
.
collect
(
Collectors
.
toList
());
}
}
return
attachments
;
}
/**
* 判断人员密级是否与附件密级匹配
*/
private
boolean
matchingSecretLevel
(
Person
person
,
Attachment
attachment
)
{
return
// 附件未设置密级
StringUtils
.
isBlank
(
attachment
.
getSecretLevel
())
// 人员密级大于或者等于附件密级
||
secrecyLevelComparator
.
compare
(
person
.
getPersonSecurityGrade
(),
attachment
.
getSecretLevel
())
>
-
1
;
}
private
List
<
AttachmentConfigurationDesc
>
queryConfigurationDescsByCode
(
String
code
)
{
QueryDescriptor
queryDescriptor
=
this
.
sqlExecutorDao
.
getQuery
(
QUERY_XML_FILE_PATH
,
"attachmentConfigurationDetails"
);
String
sql
=
queryDescriptor
.
getSqlByName
(
"queryByBizCode"
);
...
...
@@ -264,7 +293,7 @@ public class AttachmentApplicationImpl extends BaseApplication implements Attach
/**
* 创建数据批量插入对象
*
*
* @return
*/
private
BatchSqlUpdateDetail
getBatchInsertDetail
()
{
...
...
huigou-uasp/src/main/java/com/huigou/uasp/bmp/doc/attachment/application/impl/BasedOnSequenceSecrecyLevelComparator.java
0 → 100644
View file @
eaff27b8
package
com
.
huigou
.
uasp
.
bmp
.
doc
.
attachment
.
application
.
impl
;
import
com.huigou.cache.DictionaryDesc
;
import
com.huigou.cache.SystemCache
;
import
com.huigou.uasp.bmp.doc.attachment.application.SecrecyLevelComparator
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.Assert
;
import
java.util.Map
;
/**
* 基于密级字典的排序字段进行密级大小比较
*
* @author yonghuan
*/
public
class
BasedOnSequenceSecrecyLevelComparator
implements
SecrecyLevelComparator
{
private
String
securityGradeDictionaryCode
;
@Value
(
"${securityGradeDictionaryCode}"
)
public
void
setSecurityGradeDictionaryCode
(
String
securityGradeDictionaryCode
)
{
this
.
securityGradeDictionaryCode
=
securityGradeDictionaryCode
;
}
@Override
public
int
compare
(
String
secrecyLeve1
,
String
secrecyLeve2
)
{
Map
<
String
,
DictionaryDesc
>
secrecyLevels
=
SystemCache
.
getDictionary
(
securityGradeDictionaryCode
);
DictionaryDesc
sc1
=
secrecyLevels
.
get
(
secrecyLeve1
);
Assert
.
notNull
(
sc1
,
String
.
format
(
"无效的密级:%s"
,
secrecyLeve1
));
DictionaryDesc
sc2
=
secrecyLevels
.
get
(
secrecyLeve2
);
Assert
.
notNull
(
sc2
,
String
.
format
(
"无效的密级:%s"
,
secrecyLeve2
));
return
sc1
.
getSequence
().
compareTo
(
sc2
.
getSequence
());
}
}
huigou-uasp/src/main/java/com/huigou/uasp/bmp/doc/attachment/application/impl/TestAttachmentSecretInfoResolver.java
View file @
eaff27b8
...
...
@@ -2,17 +2,11 @@ package com.huigou.uasp.bmp.doc.attachment.application.impl;
import
com.huigou.cache.DictionaryDesc
;
import
com.huigou.cache.SystemCache
;
import
com.huigou.context.ThreadLocalUtil
;
import
com.huigou.uasp.bmp.doc.attachment.application.AttachmentSecretInfoResolver
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.AttachmentConfiguration
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.FileInfo
;
import
com.huigou.uasp.bmp.doc.attachment.repository.AttachmentConfigurationRepository
;
import
com.huigou.uasp.bmp.opm.application.OrgApplication
;
import
com.huigou.uasp.bmp.opm.domain.model.org.Person
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.Assert
;
import
java.util.Collection
;
import
java.util.Objects
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -22,69 +16,32 @@ import java.util.regex.Pattern;
*
* @author yonghuan
*/
public
class
TestAttachmentSecretInfoResolver
implements
AttachmentSecretInfoResolver
{
public
class
TestAttachmentSecretInfoResolver
extends
AbstractAttachmentSecretInfoResolver
implements
AttachmentSecretInfoResolver
{
/**
* 附件文件名格式,如 【非密】报销单.pdf
*/
private
final
static
Pattern
FILE_NAME_PATTERN
=
Pattern
.
compile
(
"^【(.+)】.+$"
);
private
AttachmentConfigurationRepository
attachmentConfigurationRepository
;
private
OrgApplication
orgApplication
;
/**
* 密级字典编码
*/
private
String
securityGradeDictionaryCode
;
@Autowired
public
void
setAttachmentConfigurationRepository
(
AttachmentConfigurationRepository
attachmentConfigurationRepository
)
{
this
.
attachmentConfigurationRepository
=
attachmentConfigurationRepository
;
}
@Autowired
public
void
setOrgApplication
(
OrgApplication
orgApplication
)
{
this
.
orgApplication
=
orgApplication
;
}
@Value
(
"${securityGradeDictionaryCode}"
)
public
void
setSecurityGradeDictionaryCode
(
String
securityGradeDictionaryCode
)
{
this
.
securityGradeDictionaryCode
=
securityGradeDictionaryCode
;
}
@Override
public
String
resolve
(
FileInfo
fileInfo
)
{
AttachmentConfiguration
attachmentConfiguration
=
attachmentConfigurationRepository
.
findByCode
(
fileInfo
.
getBizCode
());
if
(!
Objects
.
equals
(
attachmentConfiguration
.
getEnableSecret
(),
1
))
{
// 未启用密级
return
null
;
}
// 1、从文件名中解析附件密级
protected
String
resolveAttachmentSecurityLevel
(
FileInfo
fileInfo
)
{
Matcher
matcher
=
FILE_NAME_PATTERN
.
matcher
(
fileInfo
.
getName
());
Assert
.
isTrue
(
matcher
.
matches
(),
"附件名不合法"
);
String
attachmentSecurityGradeName
=
matcher
.
group
(
1
);
Assert
.
hasText
(
attachmentSecurityGradeName
,
"附件名中未包含附件密级信息"
);
Collection
<
DictionaryDesc
>
secrecyLevels
=
SystemCache
.
getDictionary
(
securityGradeDictionaryCode
).
values
();
DictionaryDesc
attachmentSecurityGrade
=
secrecyLevels
DictionaryDesc
attachmentSecurityGrade
=
SystemCache
.
getDictionary
(
securityGradeDictionaryCode
).
values
()
.
stream
()
.
filter
(
e
->
Objects
.
equals
(
e
.
getName
(),
attachmentSecurityGradeName
))
.
findAny
()
.
orElseThrow
(()
->
new
IllegalArgumentException
(
String
.
format
(
"无效的附件密级:%s"
,
attachmentSecurityGradeName
)));
// 2、校验附件密级是否与人员密级匹配
Person
person
=
orgApplication
.
loadPerson
(
ThreadLocalUtil
.
getOperator
().
getUserId
());
DictionaryDesc
personSecurityGrade
=
secrecyLevels
.
stream
()
.
filter
(
e
->
Objects
.
equals
(
e
.
getValue
(),
person
.
getPersonSecurityGrade
()))
.
findAny
()
.
orElseThrow
(()
->
new
IllegalArgumentException
(
String
.
format
(
"无效的人员密级:%s"
,
person
.
getPersonSecurityGrade
())));
boolean
personSecurityGradeGreaterThanAttachmentSecurityGrade
=
personSecurityGrade
.
getSequence
().
compareTo
(
attachmentSecurityGrade
.
getSequence
())
>
-
1
;
Assert
.
isTrue
(
personSecurityGradeGreaterThanAttachmentSecurityGrade
,
"附件密级与人员密级不匹配"
);
// 3、校验附件密级是否与表单密级匹配
Assert
.
hasText
(
fileInfo
.
getFormSecretLevel
(),
"表单密级不能为空"
);
DictionaryDesc
formSecurityGrade
=
secrecyLevels
.
stream
()
.
filter
(
e
->
Objects
.
equals
(
e
.
getValue
(),
fileInfo
.
getFormSecretLevel
()))
.
findAny
()
.
orElseThrow
(()
->
new
IllegalArgumentException
(
String
.
format
(
"无效的表单密级:%s"
,
fileInfo
.
getFormSecretLevel
())));
boolean
formSecurityGradeThanAttachmentSecurityGrade
=
formSecurityGrade
.
getSequence
().
compareTo
(
attachmentSecurityGrade
.
getSequence
())
>
-
1
;
Assert
.
isTrue
(
formSecurityGradeThanAttachmentSecurityGrade
,
"附件密级与表单密级不匹配"
);
// 4、返回附件密级
return
attachmentSecurityGrade
.
getValue
();
}
}
huigou-uasp/src/main/java/com/huigou/uasp/bmp/doc/attachment/application/impl/WebUploaderServiceImpl.java
View file @
eaff27b8
...
...
@@ -8,18 +8,15 @@ import java.io.IOException;
import
java.math.BigDecimal
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.*
;
import
java.util.concurrent.locks.Lock
;
import
java.util.regex.Matcher
;
import
com.huigou.cache.DictionaryDesc
;
import
com.huigou.context.ThreadLocalUtil
;
import
com.huigou.uasp.bmp.doc.attachment.application.AttachmentSecretInfoResolver
;
import
com.huigou.uasp.bmp.doc.attachment.domain.model.AttachmentConfiguration
;
import
com.huigou.uasp.bmp.opm.domain.model.org.Person
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -36,6 +33,7 @@ import com.huigou.util.ClassHelper;
import
com.huigou.util.DateUtil
;
import
com.huigou.util.FileHelper
;
import
com.huigou.util.LogHome
;
import
org.springframework.util.Assert
;
@Service
(
"webUploaderService"
)
public
class
WebUploaderServiceImpl
extends
BaseApplication
implements
WebUploaderService
{
...
...
huigou-xt/src/main/resources/application.properties
View file @
eaff27b8
...
...
@@ -49,3 +49,6 @@ org.forceGenerateIdentifier=false
activemq.brokerURL
=
tcp://127.0.0.1:61616
activemq.userName
=
admin
activemq.password
=
admin
# 密级字典编码
securityGradeDictionaryCode
=
securityGrade
huigou-xt/src/main/resources/config/spring/spring-extend.xml
View file @
eaff27b8
...
...
@@ -73,7 +73,7 @@
<bean
id=
"awesomeCssIconParser"
class=
"com.huigou.uasp.bmp.opm.application.impl.FontAwesomeCssIconParser"
/>
<bean
id=
"attachmentSecretInfoResolver"
class=
"com.huigou.uasp.bmp.doc.attachment.application.impl.TestAttachmentSecretInfoResolver"
>
<property
name=
"securityGradeDictionaryCode"
value=
"securityGrade"
/>
<
/bean
>
class=
"com.huigou.uasp.bmp.doc.attachment.application.impl.TestAttachmentSecretInfoResolver"
/
>
<
bean
id=
"secrecyLevelComparator"
class=
"com.huigou.uasp.bmp.doc.attachment.application.impl.BasedOnSequenceSecrecyLevelComparator"
/
>
</beans>
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