Commit eaff27b8 authored by 雍欢's avatar 雍欢

改造附件列表查询逻辑,根据登录人员密级过滤掉不满足密级要求的附件

parent ba9a9b3b
package com.huigou.uasp.bmp.doc.attachment.application;
import java.util.Comparator;
/**
* 密级比较器。
*
* @author yonghuan
*/
@FunctionalInterface
public interface SecrecyLevelComparator extends Comparator<String> {
}
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);
}
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
......@@ -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");
......
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());
}
}
......@@ -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();
}
}
......@@ -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 {
......
......@@ -49,3 +49,6 @@ org.forceGenerateIdentifier=false
activemq.brokerURL=tcp://127.0.0.1:61616
activemq.userName=admin
activemq.password=admin
# 密级字典编码
securityGradeDictionaryCode=securityGrade
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment