继续编写权限管理子系统;权限管理子系统服务层及相关方法名称均采取简称;
This commit is contained in:
parent
a89f82a3b2
commit
6d44e18795
@ -11,11 +11,11 @@ import java.util.Collection;
|
||||
* 生成功能性权限容器列表
|
||||
*/
|
||||
@Component
|
||||
public class UserFunctionalPermissionContainersListGenerator {
|
||||
public class UserFPCListGenerator {
|
||||
@Resource
|
||||
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator;
|
||||
private UserFSRGenerator fsrListGenerator;
|
||||
|
||||
public Collection<FunctionalPermissionContainer> generateFunctionalContainers(
|
||||
public Collection<FunctionalPermissionContainer> generateFPC(
|
||||
Collection<FunctionalScopeRelation> functionalScopeRelations){
|
||||
Collection<FunctionalPermissionContainer> functionalPermissionContainers
|
||||
= new ArrayList<>();
|
||||
@ -27,15 +27,15 @@ public class UserFunctionalPermissionContainersListGenerator {
|
||||
return functionalPermissionContainers;
|
||||
}
|
||||
|
||||
public Collection<FunctionalPermissionContainer> generateFunctionalPermissionContainers(User user){
|
||||
return generateFunctionalContainers(
|
||||
functionalScopeRelationsListGenerator.generateFunctionalScopeRelations(user)
|
||||
public Collection<FunctionalPermissionContainer> generateFPCs(User user){
|
||||
return generateFPC(
|
||||
fsrListGenerator.generateFSRs(user)
|
||||
);
|
||||
}
|
||||
|
||||
public Collection<FunctionalPermissionContainer> generateFunctionalPermissionContainers(String username){
|
||||
return generateFunctionalContainers(
|
||||
functionalScopeRelationsListGenerator.generateFunctionalScopeRelations(username)
|
||||
public Collection<FunctionalPermissionContainer> generateFPCs(String username){
|
||||
return generateFPC(
|
||||
fsrListGenerator.generateFSRs(username)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.codesdream.ase.component.permission;
|
||||
|
||||
import com.codesdream.ase.model.permission.FunctionalScopeRelation;
|
||||
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 生成功能性权限容器与范围性权限容器关联对列表
|
||||
*/
|
||||
@Component
|
||||
public class UserFSRGenerator {
|
||||
|
||||
@Resource
|
||||
private UserPCCListGenerator userPCCListGenerator;
|
||||
|
||||
|
||||
public Collection<FunctionalScopeRelation> generateFSRs(
|
||||
Collection<PermissionContainersCollection> pccs){
|
||||
Collection<FunctionalScopeRelation> fsrs =
|
||||
new ArrayList<>();
|
||||
|
||||
for(PermissionContainersCollection pcc : pccs){
|
||||
fsrs.addAll(pcc.getFunctionalScopeRelations());
|
||||
}
|
||||
|
||||
return fsrs;
|
||||
}
|
||||
|
||||
public Collection<FunctionalScopeRelation> generateFSRs(
|
||||
User user){
|
||||
return generateFSRs(
|
||||
userPCCListGenerator.generatePCCs(user));
|
||||
}
|
||||
|
||||
public Collection<FunctionalScopeRelation> generateFSRs(
|
||||
String username){
|
||||
return generateFSRs(
|
||||
userPCCListGenerator.generatePCCs(username));
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.codesdream.ase.component.permission;
|
||||
|
||||
import com.codesdream.ase.model.permission.FunctionalScopeRelation;
|
||||
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 生成功能性权限容器与范围性权限容器关联对列表
|
||||
*/
|
||||
@Component
|
||||
public class UserFunctionalScopeRelationsListGenerator {
|
||||
|
||||
@Resource
|
||||
private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator;
|
||||
|
||||
|
||||
public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations(
|
||||
Collection<PermissionContainersCollection> permissionContainersCollections){
|
||||
Collection<FunctionalScopeRelation> functionalScopeRelations =
|
||||
new ArrayList<>();
|
||||
|
||||
for(PermissionContainersCollection permissionContainersCollection : permissionContainersCollections){
|
||||
functionalScopeRelations.addAll(permissionContainersCollection.getFunctionalScopeRelations());
|
||||
}
|
||||
|
||||
return functionalScopeRelations;
|
||||
}
|
||||
|
||||
public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations(
|
||||
User user){
|
||||
return generateFunctionalScopeRelations(
|
||||
userPermissionContainersCollectionsListGenerator.generatePermissionContainerCollections(user));
|
||||
}
|
||||
|
||||
public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations(
|
||||
String username){
|
||||
return generateFunctionalScopeRelations(
|
||||
userPermissionContainersCollectionsListGenerator.generatePermissionContainerCollections(username));
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.codesdream.ase.component.permission;
|
||||
|
||||
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||
import com.codesdream.ase.model.permission.Tag;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 生成权限容器集合列表
|
||||
*/
|
||||
@Component
|
||||
public class UserPCCListGenerator {
|
||||
@Resource
|
||||
private UserTagsListGenerator userTagsListGenerator;
|
||||
|
||||
public Collection<PermissionContainersCollection> generatePCCs(
|
||||
Collection<Tag> tags){
|
||||
Collection<PermissionContainersCollection> pccs =
|
||||
new ArrayList<>();
|
||||
for(Tag tag : tags){
|
||||
pccs.addAll(tag.getPermissionContainersCollections());
|
||||
}
|
||||
return pccs;
|
||||
}
|
||||
|
||||
public Collection<PermissionContainersCollection> generatePCCs(
|
||||
User user) {
|
||||
return generatePCCs(userTagsListGenerator.generateTags(user));
|
||||
}
|
||||
|
||||
public Collection<PermissionContainersCollection> generatePCCs(
|
||||
String username){
|
||||
return generatePCCs(userTagsListGenerator.generateTags(username));
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.codesdream.ase.component.permission;
|
||||
|
||||
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||
import com.codesdream.ase.model.permission.Tag;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 生成权限容器集合列表
|
||||
*/
|
||||
@Component
|
||||
public class UserPermissionContainersCollectionsListGenerator {
|
||||
@Resource
|
||||
private UserTagsListGenerator userTagsListGenerator;
|
||||
|
||||
public Collection<PermissionContainersCollection> generatePermissionContainerCollections(
|
||||
Collection<Tag> tags){
|
||||
Collection<PermissionContainersCollection> permissionContainersCollections =
|
||||
new ArrayList<>();
|
||||
for(Tag tag : tags){
|
||||
permissionContainersCollections.addAll(tag.getPermissionContainersCollections());
|
||||
}
|
||||
return permissionContainersCollections;
|
||||
}
|
||||
|
||||
public Collection<PermissionContainersCollection> generatePermissionContainerCollections(
|
||||
User user) {
|
||||
return generatePermissionContainerCollections(userTagsListGenerator.generateTags(user));
|
||||
}
|
||||
|
||||
public Collection<PermissionContainersCollection> generatePermissionContainerCollections(
|
||||
String username){
|
||||
return generatePermissionContainerCollections(userTagsListGenerator.generateTags(username));
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.codesdream.ase.component.permission;
|
||||
|
||||
import com.codesdream.ase.component.permission.UserFunctionalPermissionContainersListGenerator;
|
||||
import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@ -17,13 +16,13 @@ import java.util.Collection;
|
||||
@Component
|
||||
public class UserRolesListGenerator {
|
||||
@Resource
|
||||
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator;
|
||||
private UserFPCListGenerator fpcListGenerator;
|
||||
|
||||
public Collection<GrantedAuthority> generateRoles(
|
||||
Collection<FunctionalPermissionContainer> functionalPermissionContainers){
|
||||
Collection<FunctionalPermissionContainer> fpcs){
|
||||
Collection<GrantedAuthority> authorities = new ArrayList<>();
|
||||
for(FunctionalPermissionContainer functionalPermissionContainer :functionalPermissionContainers){
|
||||
for(String role :functionalPermissionContainer.getRoles()){
|
||||
for(FunctionalPermissionContainer fpc :fpcs){
|
||||
for(String role :fpc.getRoles()){
|
||||
authorities.add(new SimpleGrantedAuthority(role));
|
||||
}
|
||||
}
|
||||
@ -32,14 +31,14 @@ public class UserRolesListGenerator {
|
||||
|
||||
public Collection<GrantedAuthority> generateRoles(String username){
|
||||
return generateRoles(
|
||||
functionalPermissionContainersListGenerator.generateFunctionalPermissionContainers(username)
|
||||
fpcListGenerator.generateFPCs(username)
|
||||
);
|
||||
}
|
||||
|
||||
public Collection<GrantedAuthority> generateRoles(User user){
|
||||
|
||||
return generateRoles(
|
||||
functionalPermissionContainersListGenerator.generateFunctionalPermissionContainers(user)
|
||||
fpcListGenerator.generateFPCs(user)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ public class UserTagsListGenerator {
|
||||
@Resource
|
||||
UserRepository userRepository;
|
||||
|
||||
public Collection<Tag> generateTags(ScopePermissionContainer scopePermissionContainer){
|
||||
return new ArrayList<>(scopePermissionContainer.getTags());
|
||||
public Collection<Tag> generateTags(ScopePermissionContainer spc){
|
||||
return new ArrayList<>(spc.getTags());
|
||||
}
|
||||
|
||||
public Collection<Tag> generateTags(User user){
|
||||
|
@ -7,9 +7,11 @@ import lombok.EqualsAndHashCode;
|
||||
@Data
|
||||
public class BaseInformationAlreadyExistException extends RuntimeException {
|
||||
private String className;
|
||||
private String value;
|
||||
|
||||
public BaseInformationAlreadyExistException(Class<?> aClass){
|
||||
public BaseInformationAlreadyExistException(Class<?> aClass, String value){
|
||||
super();
|
||||
this.className = aClass.getName();
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ public class BaseInformationIllegalException extends RuntimeException {
|
||||
String type;
|
||||
String value;
|
||||
|
||||
public BaseInformationIllegalException(String type, String value){
|
||||
public BaseInformationIllegalException(Class<?> aClass, String value){
|
||||
super();
|
||||
this.type = type;
|
||||
this.type = aClass.getName();
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,11 @@ import lombok.EqualsAndHashCode;
|
||||
@Data
|
||||
public class BaseInformationNotExistException extends RuntimeException {
|
||||
private String className;
|
||||
private String value;
|
||||
|
||||
public BaseInformationNotExistException(Class<?> baseInformationClass){
|
||||
public BaseInformationNotExistException(Class<?> baseInformationClass, String value){
|
||||
super();
|
||||
this.className = baseInformationClass.getName();
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ public class FunctionalScopeRelation {
|
||||
private int id;
|
||||
|
||||
// 对应功能性权限容器
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
|
||||
private FunctionalPermissionContainer functionalPermissionContainer;
|
||||
|
||||
// 对应范围性权限容器
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
|
||||
private ScopePermissionContainer scopePermissionContainer;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class ScopePermissionContainer {
|
||||
|
||||
private String description;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private List<Tag> tags;
|
||||
|
||||
@Column(nullable = false)
|
||||
|
@ -38,7 +38,7 @@ public class Tag {
|
||||
private boolean deleted;
|
||||
|
||||
// 对应权限容器集合
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
|
||||
private Set<PermissionContainersCollection> permissionContainersCollections;
|
||||
|
||||
public Tag(String name, String description) {
|
||||
|
@ -16,29 +16,32 @@ public class UserDetail {
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
// 学生班号
|
||||
private String classId = "";
|
||||
|
||||
// 所属地区
|
||||
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private BaseAdministrativeDivision baseAdministrativeDivision;
|
||||
private BaseAdministrativeDivision baseAdministrativeDivision = null;
|
||||
|
||||
// 所属学院
|
||||
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private BaseCollege baseCollege;
|
||||
private BaseCollege baseCollege = null;
|
||||
|
||||
// 所属专业
|
||||
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private BaseMajor baseMajor;
|
||||
private BaseMajor baseMajor = null;
|
||||
|
||||
// 民族
|
||||
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private BaseEthnic baseEthnic;
|
||||
private BaseEthnic baseEthnic = null;
|
||||
|
||||
// 政治面貌
|
||||
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private BasePoliticalStatus basePoliticalStatus;
|
||||
private BasePoliticalStatus basePoliticalStatus = null;
|
||||
|
||||
// 真实姓名
|
||||
private String realName = "";
|
||||
|
||||
// 在校状态
|
||||
// 在校认证状态
|
||||
private boolean atSchool = false;
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface FunctionalPermissionRepository extends CrudRepository<FunctionalPermissionContainer, Integer> {
|
||||
public interface FunctionalPermissionContainerRepository extends CrudRepository<FunctionalPermissionContainer, Integer> {
|
||||
Optional<FunctionalPermissionContainer> findByName(String name);
|
||||
}
|
@ -5,6 +5,6 @@ import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ScopePermissionRepository extends CrudRepository<ScopePermissionContainer, Integer> {
|
||||
public interface ScopePermissionContainerRepository extends CrudRepository<ScopePermissionContainer, Integer> {
|
||||
Optional<ScopePermissionContainer> findByName(String name);
|
||||
}
|
@ -6,6 +6,7 @@ import com.codesdream.ase.exception.BaseInformationIllegalException;
|
||||
import com.codesdream.ase.exception.BaseInformationNotExistException;
|
||||
import com.codesdream.ase.model.information.*;
|
||||
import com.codesdream.ase.repository.information.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -14,6 +15,7 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Vector;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BaseInformationService implements IBaseInformationService {
|
||||
|
||||
@ -70,7 +72,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
public boolean checkPoliticalStatus(String name) {
|
||||
Optional<BasePoliticalStatus> politicalStatus =
|
||||
politicalStatusRepository.findByName(name);
|
||||
return false;
|
||||
return politicalStatus.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -96,11 +98,12 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
// 检查
|
||||
if(!administrativeDivision.isPresent()) {
|
||||
// 如果填入未知数据
|
||||
log.warn("省级行政区域: " + name + " 未在数据库中找到,将使用未知符号占位");
|
||||
administrativeDivision = administrativeDivisionRepository.findByName("未知");
|
||||
if(administrativeDivision.isPresent()) {
|
||||
return administrativeDivision.get();
|
||||
}
|
||||
else throw new BaseInformationNotExistException(BaseAdministrativeDivision.class);
|
||||
else throw new BaseInformationNotExistException(BaseAdministrativeDivision.class, name);
|
||||
|
||||
}
|
||||
return administrativeDivision.get();
|
||||
@ -111,7 +114,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
Optional<BaseCollege> college =
|
||||
collegeRepository.findByName(name);
|
||||
// 检查
|
||||
if(!college.isPresent()) throw new BaseInformationNotExistException(BaseCollege.class);
|
||||
if(!college.isPresent()) throw new BaseInformationNotExistException(BaseCollege.class, name);
|
||||
return college.get();
|
||||
}
|
||||
|
||||
@ -119,7 +122,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
public BaseEthnic findEthnicByName(String name) {
|
||||
Optional<BaseEthnic> ethnic =
|
||||
ethnicRepository.findByName(name);
|
||||
if(!ethnic.isPresent()) throw new BaseInformationNotExistException(BaseEthnic.class);
|
||||
if(!ethnic.isPresent()) throw new BaseInformationNotExistException(BaseEthnic.class, name);
|
||||
return ethnic.get();
|
||||
}
|
||||
|
||||
@ -127,7 +130,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
public BaseMajor findMajorByName(String name) {
|
||||
Optional<BaseMajor> major =
|
||||
majorRepository.findByName(name);
|
||||
if(!major.isPresent()) throw new BaseInformationNotExistException(BaseMajor.class);
|
||||
if(!major.isPresent()) throw new BaseInformationNotExistException(BaseMajor.class, name);
|
||||
return major.get();
|
||||
}
|
||||
|
||||
@ -136,7 +139,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
Optional<BasePoliticalStatus> politicalStatus =
|
||||
politicalStatusRepository.findByName(name);
|
||||
if(!politicalStatus.isPresent())
|
||||
throw new BaseInformationNotExistException(BasePoliticalStatus.class);
|
||||
throw new BaseInformationNotExistException(BasePoliticalStatus.class, name);
|
||||
return politicalStatus.get();
|
||||
}
|
||||
|
||||
@ -145,7 +148,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
Optional<BaseCandidateCategory> candidateCategory =
|
||||
candidateCategoryRepository.findByName(name);
|
||||
if(!candidateCategory.isPresent())
|
||||
throw new BaseInformationNotExistException(BaseCandidateCategory.class);
|
||||
throw new BaseInformationNotExistException(BaseCandidateCategory.class, name);
|
||||
return candidateCategory.get();
|
||||
}
|
||||
|
||||
@ -154,13 +157,14 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
Optional<BaseStudentInfo> studentInfo =
|
||||
studentInfoRepository.findByStudentId(studentId);
|
||||
if(!studentInfo.isPresent())
|
||||
throw new BaseInformationNotExistException(BaseStudentInfo.class);
|
||||
throw new BaseInformationNotExistException(BaseStudentInfo.class, studentId);
|
||||
return studentInfo.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void studentInfoImportFromDataTable(DataTable table) {
|
||||
Collection<Optional<Integer>> infoIndexOptional = new ArrayList<>();
|
||||
|
||||
infoIndexOptional.add(table.getTitleIndex("学号"));
|
||||
infoIndexOptional.add(table.getTitleIndex("班号"));
|
||||
infoIndexOptional.add(table.getTitleIndex("姓名"));
|
||||
@ -171,10 +175,14 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
infoIndexOptional.add(table.getTitleIndex("政治面貌名称"));
|
||||
infoIndexOptional.add(table.getTitleIndex("省份名称"));
|
||||
|
||||
|
||||
Vector<Integer> infoIndex = new Vector<>();
|
||||
|
||||
for(Optional<Integer> infoIdx : infoIndexOptional){
|
||||
if(!infoIdx.isPresent()) throw new RuntimeException("Unfit Data Table");
|
||||
if(!infoIdx.isPresent()){
|
||||
log.error("所提供的数据表不符合学生信息导入规范, 有关键数据缺失");
|
||||
throw new RuntimeException("Unfit Data Table");
|
||||
}
|
||||
else infoIndex.add(infoIdx.get());
|
||||
}
|
||||
|
||||
@ -182,6 +190,7 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
|
||||
for(int i = 0; i < dataRowsSize; i++){
|
||||
Vector<String> row = table.getRowVector(i);
|
||||
try {
|
||||
BaseStudentInfo studentInfo =
|
||||
constructStudentInfo(row.elementAt(infoIndex.elementAt(0)),
|
||||
row.elementAt(infoIndex.elementAt(1)),
|
||||
@ -193,6 +202,19 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
row.elementAt(infoIndex.elementAt(7)),
|
||||
row.elementAt(infoIndex.elementAt(8)));
|
||||
save(studentInfo);
|
||||
} catch (BaseInformationNotExistException e){
|
||||
String log_info = String.format("一项学生信息的某项基本信息未在数据库找到, 该项数据无效." +
|
||||
" %s: %s",e.getClassName(), e.getValue());
|
||||
log.warn(log_info);
|
||||
} catch (BaseInformationIllegalException e){
|
||||
String log_info = String.format("一项学生信息的某项基本信息不合法, 该项数据无效." +
|
||||
" %s: %s", e.getType(), e.getValue());
|
||||
log.warn(log_info);
|
||||
} catch (BaseInformationAlreadyExistException e){
|
||||
String log_info = String.format("一项学生信息的学号已在数据库中包含." +
|
||||
" %s: %s",e.getClassName(), e.getValue());
|
||||
log.warn(log_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,13 +229,13 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
{
|
||||
// 检查
|
||||
if(!sex.equals("男") && !sex.equals("女"))
|
||||
throw new BaseInformationIllegalException("sex", sex);
|
||||
throw new BaseInformationIllegalException(String.class, sex);
|
||||
if(classId.length() != 8)
|
||||
throw new BaseInformationIllegalException("classId", classId);
|
||||
throw new BaseInformationIllegalException(String.class, classId);
|
||||
if(studentId.length() != 10)
|
||||
throw new BaseInformationIllegalException("studentId",studentId);
|
||||
throw new BaseInformationIllegalException(String.class, studentId);
|
||||
if(realName.length() > 64)
|
||||
throw new BaseInformationIllegalException("realName",realName);
|
||||
throw new BaseInformationIllegalException(String.class, realName);
|
||||
|
||||
BaseStudentInfo studentInfo = new BaseStudentInfo();
|
||||
studentInfo.setSex(sex);
|
||||
@ -239,14 +261,27 @@ public class BaseInformationService implements IBaseInformationService {
|
||||
|| baseStudentInfo.getClassId().equals("")
|
||||
|| baseStudentInfo.getStudentId().equals("")
|
||||
|| baseStudentInfo.getName().equals(""))
|
||||
throw new BaseInformationIllegalException("studentInfo", "didn't fully initialize");
|
||||
|
||||
throw new BaseInformationIllegalException(
|
||||
baseStudentInfo.getClass(),
|
||||
"One of the Attributes IS NULL or Empty");
|
||||
|
||||
// 检查学号重复
|
||||
if(checkStudentInfo(baseStudentInfo.getStudentId()))
|
||||
throw new BaseInformationAlreadyExistException(baseStudentInfo.getClass());
|
||||
throw new BaseInformationAlreadyExistException(
|
||||
baseStudentInfo.getClass(),
|
||||
baseStudentInfo.getStudentId());
|
||||
|
||||
studentInfoRepository.save(baseStudentInfo);
|
||||
|
||||
return null;
|
||||
|
||||
return studentInfoRepository.save(baseStudentInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseStudentInfo update(BaseStudentInfo baseStudentInfo) {
|
||||
// 更新前检查
|
||||
if(!checkStudentInfo(baseStudentInfo.getStudentId()))
|
||||
throw new BaseInformationNotExistException(BaseStudentInfo.class, baseStudentInfo.getStudentId());
|
||||
return studentInfoRepository.save(baseStudentInfo);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.component.datamanager.DataTable;
|
||||
import com.codesdream.ase.model.information.*;
|
||||
import com.fasterxml.jackson.databind.ser.Serializers;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IBaseInformationService {
|
||||
// 检查行政区域是否合法
|
||||
@ -25,8 +28,10 @@ public interface IBaseInformationService {
|
||||
// 检查学生信息是否存在
|
||||
boolean checkStudentInfo(String studentId);
|
||||
|
||||
// 根据名字查找有效的省级行政区划
|
||||
BaseAdministrativeDivision findAdministrativeDivisionByName(String name);
|
||||
|
||||
// 查找学院
|
||||
BaseCollege findCollegeByName(String name);
|
||||
|
||||
BaseEthnic findEthnicByName(String name);
|
||||
@ -47,4 +52,6 @@ public interface IBaseInformationService {
|
||||
String administrativeDivision);
|
||||
|
||||
BaseStudentInfo save(BaseStudentInfo baseStudentInfo);
|
||||
|
||||
BaseStudentInfo update(BaseStudentInfo baseStudentInfo);
|
||||
}
|
||||
|
@ -12,39 +12,45 @@ public interface IPermissionService {
|
||||
Optional<Tag> findTag(String name);
|
||||
|
||||
// 查找功能性权限容器
|
||||
Optional<FunctionalPermissionContainer> findFunctionalPermissionContainer(String name);
|
||||
Optional<FunctionalPermissionContainer> findFPC(String name);
|
||||
|
||||
// 查找范围性权限容器
|
||||
Optional<ScopePermissionContainer> findScopePermissionContainer(String name);
|
||||
Optional<ScopePermissionContainer> findSPC(String name);
|
||||
|
||||
// 根据id查找功能性权限容器
|
||||
Optional<FunctionalPermissionContainer> findFPC(int id);
|
||||
|
||||
// 根据id查找范围性权限容器
|
||||
Optional<ScopePermissionContainer> findSPC(int id);
|
||||
|
||||
// 标签下所有的获得权限容器集合列表
|
||||
Collection<PermissionContainersCollection> getPermissionContainerCollections(Tag tag);
|
||||
Collection<PermissionContainersCollection> getPCCs(Tag tag);
|
||||
|
||||
// 获得范围性权限容器下的所有标签列表
|
||||
Collection<Tag> getTagsFromScopePermissionContainers(
|
||||
ScopePermissionContainer scopePermissionContainer);
|
||||
Collection<Tag> getTagsFromSPC(
|
||||
ScopePermissionContainer spc);
|
||||
|
||||
// 查找用户下的所有标签列表
|
||||
Collection<Tag> getTagsFromUser(User user);
|
||||
|
||||
// 查找功能性权限容器下的所有范围性权限容器列表
|
||||
Collection<FunctionalPermissionContainer> getFunctionPermissionContainers(
|
||||
PermissionContainersCollection permissionContainersCollection);
|
||||
Collection<FunctionalPermissionContainer> getFPCs(
|
||||
PermissionContainersCollection pcc);
|
||||
|
||||
// 查找标签下的所有用户
|
||||
Collection<User> getUsersFromTag(Tag tag);
|
||||
|
||||
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||
void addRelationItemToPermissionContainerCollectionPermissionContainerCollection(
|
||||
PermissionContainersCollection permissionContainersCollection,
|
||||
FunctionalPermissionContainer functionalPermissionContainer,
|
||||
ScopePermissionContainer scopePermissionContainer);
|
||||
void addRelationItemToPCCollection(
|
||||
PermissionContainersCollection pcc,
|
||||
FunctionalPermissionContainer fpc,
|
||||
ScopePermissionContainer spc);
|
||||
|
||||
// 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||
void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection(
|
||||
PermissionContainersCollection permissionContainersCollection,
|
||||
void addRelationItemsToPCC(
|
||||
PermissionContainersCollection pcc,
|
||||
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>>
|
||||
functionalScopePermissionContainerPairs);
|
||||
fspcPairs);
|
||||
|
||||
// 添加一个用户到指定标签中
|
||||
void addUserToTag(Tag tag, User user);
|
||||
@ -53,19 +59,27 @@ public interface IPermissionService {
|
||||
void addUsersToTag(Tag tag, Collection<User> users);
|
||||
|
||||
// 为功能性权限容器添加一个访问控制角色
|
||||
void addRoleToFunctionalPermissionContainer(
|
||||
FunctionalPermissionContainer functionalPermissionContainer,
|
||||
void addRoleToFPC(
|
||||
FunctionalPermissionContainer fpc,
|
||||
String role);
|
||||
|
||||
// 为功能性权限容器添加多个访问控制角色
|
||||
void addRolesToFunctionalPermissionContainer(
|
||||
FunctionalPermissionContainer functionalPermissionContainer,
|
||||
void addRolesToFPC(
|
||||
FunctionalPermissionContainer fpc,
|
||||
Collection<String> roles);
|
||||
|
||||
void save(Tag tag);
|
||||
|
||||
void save(FunctionalPermissionContainer functionalPermissionContainer);
|
||||
void save(FunctionalPermissionContainer fpc);
|
||||
|
||||
void save(ScopePermissionContainer scopePermissionContainer);
|
||||
void save(ScopePermissionContainer spc);
|
||||
|
||||
void save(PermissionContainersCollection pcc);
|
||||
|
||||
void update(FunctionalPermissionContainer fpc);
|
||||
|
||||
void update(ScopePermissionContainer spc);
|
||||
|
||||
void update(PermissionContainersCollection pcc);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.information.BaseStudentInfo;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import javafx.util.Pair;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@ -14,6 +15,9 @@ public interface IUserService {
|
||||
// 获得一个空的默认用户
|
||||
User getDefaultUser();
|
||||
|
||||
// 由学生基本信息生成对应用户
|
||||
User getUserByStudentInfo(BaseStudentInfo studentInfo);
|
||||
|
||||
List<User> findAll();
|
||||
|
||||
Optional<User> findUserById(int id);
|
||||
@ -28,6 +32,9 @@ public interface IUserService {
|
||||
// 更新用户的密码
|
||||
void updatePassword(User user, String password);
|
||||
|
||||
// 封禁用户
|
||||
void disableUser(User user);
|
||||
|
||||
// 根据学号生成随机用户名
|
||||
void generateRandomUsernameByStudentID(User user, String id);
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.component.permission.UserFunctionalPermissionContainersListGenerator;
|
||||
import com.codesdream.ase.component.permission.UserFunctionalScopeRelationsListGenerator;
|
||||
import com.codesdream.ase.component.permission.UserFPCListGenerator;
|
||||
import com.codesdream.ase.component.permission.UserFSRGenerator;
|
||||
import com.codesdream.ase.model.permission.*;
|
||||
import com.codesdream.ase.repository.permission.FunctionalPermissionRepository;
|
||||
import com.codesdream.ase.repository.permission.ScopePermissionRepository;
|
||||
import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository;
|
||||
import com.codesdream.ase.repository.permission.ScopePermissionContainerRepository;
|
||||
import com.codesdream.ase.repository.permission.TagRepository;
|
||||
import javafx.util.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -21,16 +21,16 @@ public class PermissionService implements IPermissionService {
|
||||
private TagRepository tagRepository;
|
||||
|
||||
@Resource
|
||||
private FunctionalPermissionRepository functionalPermissionRepository;
|
||||
private FunctionalPermissionContainerRepository fpcRepository;
|
||||
|
||||
@Resource
|
||||
private ScopePermissionRepository scopePermissionRepository;
|
||||
private ScopePermissionContainerRepository spcRepository;
|
||||
|
||||
@Resource
|
||||
private UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator;
|
||||
private UserFPCListGenerator userFPCListGenerator;
|
||||
|
||||
@Resource
|
||||
private UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator;
|
||||
private UserFSRGenerator userFSRGenerator;
|
||||
|
||||
@Override
|
||||
public Optional<Tag> findTag(String name) {
|
||||
@ -38,23 +38,33 @@ public class PermissionService implements IPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FunctionalPermissionContainer> findFunctionalPermissionContainer(String name) {
|
||||
return functionalPermissionRepository.findByName(name);
|
||||
public Optional<FunctionalPermissionContainer> findFPC(String name) {
|
||||
return fpcRepository.findByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ScopePermissionContainer> findScopePermissionContainer(String name) {
|
||||
return scopePermissionRepository.findByName(name);
|
||||
public Optional<ScopePermissionContainer> findSPC(String name) {
|
||||
return spcRepository.findByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionContainersCollection> getPermissionContainerCollections(Tag tag) {
|
||||
public Optional<FunctionalPermissionContainer> findFPC(int id) {
|
||||
return fpcRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ScopePermissionContainer> findSPC(int id) {
|
||||
return spcRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionContainersCollection> getPCCs(Tag tag) {
|
||||
return new ArrayList<>(tag.getPermissionContainersCollections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Tag> getTagsFromScopePermissionContainers(ScopePermissionContainer scopePermissionContainer) {
|
||||
return new ArrayList<>(scopePermissionContainer.getTags());
|
||||
public Collection<Tag> getTagsFromSPC(ScopePermissionContainer spc) {
|
||||
return new ArrayList<>(spc.getTags());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,30 +73,46 @@ public class PermissionService implements IPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<FunctionalPermissionContainer> getFunctionPermissionContainers(PermissionContainersCollection permissionContainersCollection) {
|
||||
public Collection<FunctionalPermissionContainer> getFPCs(
|
||||
PermissionContainersCollection pcc)
|
||||
{
|
||||
|
||||
Collection<PermissionContainersCollection> permissionContainersCollections = new ArrayList<PermissionContainersCollection>(){{
|
||||
add(permissionContainersCollection);
|
||||
Collection<PermissionContainersCollection> pccCollections =
|
||||
new ArrayList<PermissionContainersCollection>(){{
|
||||
add(pcc);
|
||||
}};
|
||||
|
||||
// 生成功能性与范围性权限容器关联对
|
||||
Collection<FunctionalScopeRelation> functionalScopeRelations =
|
||||
userFunctionalScopeRelationsListGenerator.generateFunctionalScopeRelations(permissionContainersCollections);
|
||||
return userFunctionalPermissionContainersListGenerator.generateFunctionalContainers(functionalScopeRelations);
|
||||
Collection<FunctionalScopeRelation> fsr =
|
||||
userFSRGenerator.generateFSRs(pccCollections);
|
||||
return userFPCListGenerator.generateFPC(fsr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<User> getUsersFromTag(Tag tag) {
|
||||
return null;
|
||||
return new ArrayList<>(tag.getUsers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRelationItemToPermissionContainerCollectionPermissionContainerCollection(PermissionContainersCollection permissionContainersCollection, FunctionalPermissionContainer functionalPermissionContainer, ScopePermissionContainer scopePermissionContainer) {
|
||||
public void addRelationItemToPCCollection(PermissionContainersCollection pcc,
|
||||
FunctionalPermissionContainer fpc,
|
||||
ScopePermissionContainer spc)
|
||||
{
|
||||
if(!findFPC(fpc.getId()).isPresent()){
|
||||
|
||||
}
|
||||
FunctionalScopeRelation relation = new FunctionalScopeRelation();
|
||||
relation.setFunctionalPermissionContainer(fpc);
|
||||
relation.setScopePermissionContainer(spc);
|
||||
pcc.getFunctionalScopeRelations().add(relation);
|
||||
update(pcc);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection(PermissionContainersCollection permissionContainersCollection, Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>> functionalScopePermissionContainerPairs) {
|
||||
public void addRelationItemsToPCC(PermissionContainersCollection pcc,
|
||||
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>> fspcPairs)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -101,12 +127,12 @@ public class PermissionService implements IPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoleToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, String role) {
|
||||
public void addRoleToFPC(FunctionalPermissionContainer fpc, String role) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRolesToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, Collection<String> roles) {
|
||||
public void addRolesToFPC(FunctionalPermissionContainer fpc, Collection<String> roles) {
|
||||
|
||||
}
|
||||
|
||||
@ -116,12 +142,32 @@ public class PermissionService implements IPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(FunctionalPermissionContainer functionalPermissionContainer) {
|
||||
public void save(FunctionalPermissionContainer fpc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ScopePermissionContainer scopePermissionContainer) {
|
||||
public void save(ScopePermissionContainer spc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(PermissionContainersCollection pcc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(FunctionalPermissionContainer fpc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ScopePermissionContainer spc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PermissionContainersCollection pcc) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.codesdream.ase.component.permission.UserRolesListGenerator;
|
||||
import com.codesdream.ase.exception.UserInformationIllegalException;
|
||||
import com.codesdream.ase.exception.UserNotFoundException;
|
||||
import com.codesdream.ase.exception.UsernameAlreadyExistException;
|
||||
import com.codesdream.ase.model.information.BaseStudentInfo;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.repository.permission.UserRepository;
|
||||
import javafx.util.Pair;
|
||||
@ -67,6 +68,13 @@ public class UserService implements IUserService {
|
||||
update(user);
|
||||
}
|
||||
|
||||
// 封禁用户
|
||||
@Override
|
||||
public void disableUser(User user){
|
||||
user.setEnabled(false);
|
||||
update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateRandomUsernameByStudentID(User user, String id) {
|
||||
user.getUserAuth().setStudentID(id);
|
||||
@ -120,5 +128,28 @@ public class UserService implements IUserService {
|
||||
return new User();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByStudentInfo(BaseStudentInfo studentInfo) {
|
||||
User user = getDefaultUser();
|
||||
// 根据学生id生成用户名
|
||||
generateRandomUsernameByStudentID(user, studentInfo.getStudentId());
|
||||
// 填充用户基本信息
|
||||
user.getUserAuth().setStudentID(studentInfo.getStudentId());
|
||||
user.getUserDetail().setClassId(studentInfo.getClassId());
|
||||
user.getUserDetail().setRealName(studentInfo.getName());
|
||||
|
||||
// 填充用户详细信息
|
||||
user.getUserDetail().setBaseAdministrativeDivision(studentInfo.getAdministrativeDivision());
|
||||
user.getUserDetail().setBaseCollege(studentInfo.getCollege());
|
||||
user.getUserDetail().setBaseMajor(studentInfo.getMajor());
|
||||
user.getUserDetail().setBaseEthnic(studentInfo.getEthnic());
|
||||
user.getUserDetail().setBasePoliticalStatus(studentInfo.getPoliticalStatus());
|
||||
|
||||
// 添加在校学生认证
|
||||
user.getUserDetail().setAtSchool(true);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.codesdream.ase;
|
||||
package com.codesdream.ase.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
@ -1,9 +1,10 @@
|
||||
package com.codesdream.ase;
|
||||
package com.codesdream.ase.test;
|
||||
|
||||
import com.codesdream.ase.component.ASESpringUtil;
|
||||
import com.codesdream.ase.component.datamanager.DataExcelReader;
|
||||
import com.codesdream.ase.component.datamanager.DataTable;
|
||||
import com.codesdream.ase.service.IBaseInformationService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@ -27,4 +28,15 @@ public class BaseInformationTest {
|
||||
table.importTable(new DataExcelReader("SoftInformation.xlsx"));
|
||||
informationService.studentInfoImportFromDataTable(table);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseInformationBaseTest() {
|
||||
Assert.assertTrue(informationService.checkAdministrativeDivision("广东省"));
|
||||
Assert.assertEquals(informationService.findAdministrativeDivisionByName("广东").getName(), "广东省");
|
||||
Assert.assertTrue(informationService.checkCollege("软件学院"));
|
||||
Assert.assertTrue(informationService.checkEthnic("汉族"));
|
||||
Assert.assertTrue(informationService.checkMajor("软件工程"));
|
||||
Assert.assertTrue(informationService.checkPoliticalStatus("群众"));
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.codesdream.ase;
|
||||
package com.codesdream.ase.test;
|
||||
|
||||
import com.codesdream.ase.component.ASESpringUtil;
|
||||
import com.codesdream.ase.component.datamanager.*;
|
@ -0,0 +1,12 @@
|
||||
package com.codesdream.ase.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class PermissionServiceTest {
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.codesdream.ase;
|
||||
package com.codesdream.ase.test;
|
||||
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
|
||||
@ -65,8 +65,6 @@ public class UserTest {
|
||||
|
||||
@Test
|
||||
public void UserBaseTest_2(){
|
||||
User user = userService.findUserByUsername("Tim");
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user