继续编写权限管理子系统;权限管理子系统服务层及相关方法名称均采取简称;

This commit is contained in:
Saturneric 2020-02-19 23:54:42 +08:00
parent a89f82a3b2
commit 6d44e18795
27 changed files with 370 additions and 202 deletions

View File

@ -11,11 +11,11 @@ import java.util.Collection;
* 生成功能性权限容器列表 * 生成功能性权限容器列表
*/ */
@Component @Component
public class UserFunctionalPermissionContainersListGenerator { public class UserFPCListGenerator {
@Resource @Resource
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator; private UserFSRGenerator fsrListGenerator;
public Collection<FunctionalPermissionContainer> generateFunctionalContainers( public Collection<FunctionalPermissionContainer> generateFPC(
Collection<FunctionalScopeRelation> functionalScopeRelations){ Collection<FunctionalScopeRelation> functionalScopeRelations){
Collection<FunctionalPermissionContainer> functionalPermissionContainers Collection<FunctionalPermissionContainer> functionalPermissionContainers
= new ArrayList<>(); = new ArrayList<>();
@ -27,15 +27,15 @@ public class UserFunctionalPermissionContainersListGenerator {
return functionalPermissionContainers; return functionalPermissionContainers;
} }
public Collection<FunctionalPermissionContainer> generateFunctionalPermissionContainers(User user){ public Collection<FunctionalPermissionContainer> generateFPCs(User user){
return generateFunctionalContainers( return generateFPC(
functionalScopeRelationsListGenerator.generateFunctionalScopeRelations(user) fsrListGenerator.generateFSRs(user)
); );
} }
public Collection<FunctionalPermissionContainer> generateFunctionalPermissionContainers(String username){ public Collection<FunctionalPermissionContainer> generateFPCs(String username){
return generateFunctionalContainers( return generateFPC(
functionalScopeRelationsListGenerator.generateFunctionalScopeRelations(username) fsrListGenerator.generateFSRs(username)
); );
} }
} }

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -1,6 +1,5 @@
package com.codesdream.ase.component.permission; 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.FunctionalPermissionContainer;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
@ -17,13 +16,13 @@ import java.util.Collection;
@Component @Component
public class UserRolesListGenerator { public class UserRolesListGenerator {
@Resource @Resource
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator; private UserFPCListGenerator fpcListGenerator;
public Collection<GrantedAuthority> generateRoles( public Collection<GrantedAuthority> generateRoles(
Collection<FunctionalPermissionContainer> functionalPermissionContainers){ Collection<FunctionalPermissionContainer> fpcs){
Collection<GrantedAuthority> authorities = new ArrayList<>(); Collection<GrantedAuthority> authorities = new ArrayList<>();
for(FunctionalPermissionContainer functionalPermissionContainer :functionalPermissionContainers){ for(FunctionalPermissionContainer fpc :fpcs){
for(String role :functionalPermissionContainer.getRoles()){ for(String role :fpc.getRoles()){
authorities.add(new SimpleGrantedAuthority(role)); authorities.add(new SimpleGrantedAuthority(role));
} }
} }
@ -32,14 +31,14 @@ public class UserRolesListGenerator {
public Collection<GrantedAuthority> generateRoles(String username){ public Collection<GrantedAuthority> generateRoles(String username){
return generateRoles( return generateRoles(
functionalPermissionContainersListGenerator.generateFunctionalPermissionContainers(username) fpcListGenerator.generateFPCs(username)
); );
} }
public Collection<GrantedAuthority> generateRoles(User user){ public Collection<GrantedAuthority> generateRoles(User user){
return generateRoles( return generateRoles(
functionalPermissionContainersListGenerator.generateFunctionalPermissionContainers(user) fpcListGenerator.generateFPCs(user)
); );
} }
} }

View File

@ -19,8 +19,8 @@ public class UserTagsListGenerator {
@Resource @Resource
UserRepository userRepository; UserRepository userRepository;
public Collection<Tag> generateTags(ScopePermissionContainer scopePermissionContainer){ public Collection<Tag> generateTags(ScopePermissionContainer spc){
return new ArrayList<>(scopePermissionContainer.getTags()); return new ArrayList<>(spc.getTags());
} }
public Collection<Tag> generateTags(User user){ public Collection<Tag> generateTags(User user){

View File

@ -7,9 +7,11 @@ import lombok.EqualsAndHashCode;
@Data @Data
public class BaseInformationAlreadyExistException extends RuntimeException { public class BaseInformationAlreadyExistException extends RuntimeException {
private String className; private String className;
private String value;
public BaseInformationAlreadyExistException(Class<?> aClass){ public BaseInformationAlreadyExistException(Class<?> aClass, String value){
super(); super();
this.className = aClass.getName(); this.className = aClass.getName();
this.value = value;
} }
} }

View File

@ -9,9 +9,9 @@ public class BaseInformationIllegalException extends RuntimeException {
String type; String type;
String value; String value;
public BaseInformationIllegalException(String type, String value){ public BaseInformationIllegalException(Class<?> aClass, String value){
super(); super();
this.type = type; this.type = aClass.getName();
this.value = value; this.value = value;
} }
} }

View File

@ -7,9 +7,11 @@ import lombok.EqualsAndHashCode;
@Data @Data
public class BaseInformationNotExistException extends RuntimeException { public class BaseInformationNotExistException extends RuntimeException {
private String className; private String className;
private String value;
public BaseInformationNotExistException(Class<?> baseInformationClass){ public BaseInformationNotExistException(Class<?> baseInformationClass, String value){
super(); super();
this.className = baseInformationClass.getName(); this.className = baseInformationClass.getName();
this.value = value;
} }
} }

View File

@ -18,10 +18,10 @@ public class FunctionalScopeRelation {
private int id; private int id;
// 对应功能性权限容器 // 对应功能性权限容器
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private FunctionalPermissionContainer functionalPermissionContainer; private FunctionalPermissionContainer functionalPermissionContainer;
// 对应范围性权限容器 // 对应范围性权限容器
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private ScopePermissionContainer scopePermissionContainer; private ScopePermissionContainer scopePermissionContainer;
} }

View File

@ -19,7 +19,7 @@ public class ScopePermissionContainer {
private String description; private String description;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<Tag> tags; private List<Tag> tags;
@Column(nullable = false) @Column(nullable = false)

View File

@ -38,7 +38,7 @@ public class Tag {
private boolean deleted; private boolean deleted;
// 对应权限容器集合 // 对应权限容器集合
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private Set<PermissionContainersCollection> permissionContainersCollections; private Set<PermissionContainersCollection> permissionContainersCollections;
public Tag(String name, String description) { public Tag(String name, String description) {

View File

@ -16,29 +16,32 @@ public class UserDetail {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private int id; private int id;
// 学生班号
private String classId = "";
// 所属地区 // 所属地区
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseAdministrativeDivision baseAdministrativeDivision; private BaseAdministrativeDivision baseAdministrativeDivision = null;
// 所属学院 // 所属学院
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseCollege baseCollege; private BaseCollege baseCollege = null;
// 所属专业 // 所属专业
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseMajor baseMajor; private BaseMajor baseMajor = null;
// 民族 // 民族
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseEthnic baseEthnic; private BaseEthnic baseEthnic = null;
// 政治面貌 // 政治面貌
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BasePoliticalStatus basePoliticalStatus; private BasePoliticalStatus basePoliticalStatus = null;
// 真实姓名 // 真实姓名
private String realName = ""; private String realName = "";
// 在校状态 // 在校认证状态
private boolean atSchool = false; private boolean atSchool = false;
} }

View File

@ -7,6 +7,6 @@ import org.springframework.stereotype.Repository;
import java.util.Optional; import java.util.Optional;
@Repository @Repository
public interface FunctionalPermissionRepository extends CrudRepository<FunctionalPermissionContainer, Integer> { public interface FunctionalPermissionContainerRepository extends CrudRepository<FunctionalPermissionContainer, Integer> {
Optional<FunctionalPermissionContainer> findByName(String name); Optional<FunctionalPermissionContainer> findByName(String name);
} }

View File

@ -5,6 +5,6 @@ import org.springframework.data.repository.CrudRepository;
import java.util.Optional; import java.util.Optional;
public interface ScopePermissionRepository extends CrudRepository<ScopePermissionContainer, Integer> { public interface ScopePermissionContainerRepository extends CrudRepository<ScopePermissionContainer, Integer> {
Optional<ScopePermissionContainer> findByName(String name); Optional<ScopePermissionContainer> findByName(String name);
} }

View File

@ -6,6 +6,7 @@ import com.codesdream.ase.exception.BaseInformationIllegalException;
import com.codesdream.ase.exception.BaseInformationNotExistException; import com.codesdream.ase.exception.BaseInformationNotExistException;
import com.codesdream.ase.model.information.*; import com.codesdream.ase.model.information.*;
import com.codesdream.ase.repository.information.*; import com.codesdream.ase.repository.information.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -14,6 +15,7 @@ import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import java.util.Vector; import java.util.Vector;
@Slf4j
@Service @Service
public class BaseInformationService implements IBaseInformationService { public class BaseInformationService implements IBaseInformationService {
@ -70,7 +72,7 @@ public class BaseInformationService implements IBaseInformationService {
public boolean checkPoliticalStatus(String name) { public boolean checkPoliticalStatus(String name) {
Optional<BasePoliticalStatus> politicalStatus = Optional<BasePoliticalStatus> politicalStatus =
politicalStatusRepository.findByName(name); politicalStatusRepository.findByName(name);
return false; return politicalStatus.isPresent();
} }
@Override @Override
@ -96,11 +98,12 @@ public class BaseInformationService implements IBaseInformationService {
// 检查 // 检查
if(!administrativeDivision.isPresent()) { if(!administrativeDivision.isPresent()) {
// 如果填入未知数据 // 如果填入未知数据
log.warn("省级行政区域: " + name + " 未在数据库中找到,将使用未知符号占位");
administrativeDivision = administrativeDivisionRepository.findByName("未知"); administrativeDivision = administrativeDivisionRepository.findByName("未知");
if(administrativeDivision.isPresent()) { if(administrativeDivision.isPresent()) {
return administrativeDivision.get(); return administrativeDivision.get();
} }
else throw new BaseInformationNotExistException(BaseAdministrativeDivision.class); else throw new BaseInformationNotExistException(BaseAdministrativeDivision.class, name);
} }
return administrativeDivision.get(); return administrativeDivision.get();
@ -111,7 +114,7 @@ public class BaseInformationService implements IBaseInformationService {
Optional<BaseCollege> college = Optional<BaseCollege> college =
collegeRepository.findByName(name); collegeRepository.findByName(name);
// 检查 // 检查
if(!college.isPresent()) throw new BaseInformationNotExistException(BaseCollege.class); if(!college.isPresent()) throw new BaseInformationNotExistException(BaseCollege.class, name);
return college.get(); return college.get();
} }
@ -119,7 +122,7 @@ public class BaseInformationService implements IBaseInformationService {
public BaseEthnic findEthnicByName(String name) { public BaseEthnic findEthnicByName(String name) {
Optional<BaseEthnic> ethnic = Optional<BaseEthnic> ethnic =
ethnicRepository.findByName(name); ethnicRepository.findByName(name);
if(!ethnic.isPresent()) throw new BaseInformationNotExistException(BaseEthnic.class); if(!ethnic.isPresent()) throw new BaseInformationNotExistException(BaseEthnic.class, name);
return ethnic.get(); return ethnic.get();
} }
@ -127,7 +130,7 @@ public class BaseInformationService implements IBaseInformationService {
public BaseMajor findMajorByName(String name) { public BaseMajor findMajorByName(String name) {
Optional<BaseMajor> major = Optional<BaseMajor> major =
majorRepository.findByName(name); majorRepository.findByName(name);
if(!major.isPresent()) throw new BaseInformationNotExistException(BaseMajor.class); if(!major.isPresent()) throw new BaseInformationNotExistException(BaseMajor.class, name);
return major.get(); return major.get();
} }
@ -136,7 +139,7 @@ public class BaseInformationService implements IBaseInformationService {
Optional<BasePoliticalStatus> politicalStatus = Optional<BasePoliticalStatus> politicalStatus =
politicalStatusRepository.findByName(name); politicalStatusRepository.findByName(name);
if(!politicalStatus.isPresent()) if(!politicalStatus.isPresent())
throw new BaseInformationNotExistException(BasePoliticalStatus.class); throw new BaseInformationNotExistException(BasePoliticalStatus.class, name);
return politicalStatus.get(); return politicalStatus.get();
} }
@ -145,7 +148,7 @@ public class BaseInformationService implements IBaseInformationService {
Optional<BaseCandidateCategory> candidateCategory = Optional<BaseCandidateCategory> candidateCategory =
candidateCategoryRepository.findByName(name); candidateCategoryRepository.findByName(name);
if(!candidateCategory.isPresent()) if(!candidateCategory.isPresent())
throw new BaseInformationNotExistException(BaseCandidateCategory.class); throw new BaseInformationNotExistException(BaseCandidateCategory.class, name);
return candidateCategory.get(); return candidateCategory.get();
} }
@ -154,13 +157,14 @@ public class BaseInformationService implements IBaseInformationService {
Optional<BaseStudentInfo> studentInfo = Optional<BaseStudentInfo> studentInfo =
studentInfoRepository.findByStudentId(studentId); studentInfoRepository.findByStudentId(studentId);
if(!studentInfo.isPresent()) if(!studentInfo.isPresent())
throw new BaseInformationNotExistException(BaseStudentInfo.class); throw new BaseInformationNotExistException(BaseStudentInfo.class, studentId);
return studentInfo.get(); return studentInfo.get();
} }
@Override @Override
public void studentInfoImportFromDataTable(DataTable table) { public void studentInfoImportFromDataTable(DataTable table) {
Collection<Optional<Integer>> infoIndexOptional = new ArrayList<>(); Collection<Optional<Integer>> infoIndexOptional = new ArrayList<>();
infoIndexOptional.add(table.getTitleIndex("学号")); infoIndexOptional.add(table.getTitleIndex("学号"));
infoIndexOptional.add(table.getTitleIndex("班号")); infoIndexOptional.add(table.getTitleIndex("班号"));
infoIndexOptional.add(table.getTitleIndex("姓名")); infoIndexOptional.add(table.getTitleIndex("姓名"));
@ -171,28 +175,46 @@ public class BaseInformationService implements IBaseInformationService {
infoIndexOptional.add(table.getTitleIndex("政治面貌名称")); infoIndexOptional.add(table.getTitleIndex("政治面貌名称"));
infoIndexOptional.add(table.getTitleIndex("省份名称")); infoIndexOptional.add(table.getTitleIndex("省份名称"));
Vector<Integer> infoIndex = new Vector<>(); Vector<Integer> infoIndex = new Vector<>();
for(Optional<Integer> infoIdx : infoIndexOptional){ 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()); else infoIndex.add(infoIdx.get());
} }
int dataRowsSize = table.getRowsSize(); int dataRowsSize = table.getRowsSize();
for(int i = 0; i <dataRowsSize; i++){ for(int i = 0; i < dataRowsSize; i++){
Vector<String> row = table.getRowVector(i); Vector<String> row = table.getRowVector(i);
BaseStudentInfo studentInfo = try {
constructStudentInfo(row.elementAt(infoIndex.elementAt(0)), BaseStudentInfo studentInfo =
row.elementAt(infoIndex.elementAt(1)), constructStudentInfo(row.elementAt(infoIndex.elementAt(0)),
row.elementAt(infoIndex.elementAt(2)), row.elementAt(infoIndex.elementAt(1)),
row.elementAt(infoIndex.elementAt(3)), row.elementAt(infoIndex.elementAt(2)),
row.elementAt(infoIndex.elementAt(4)), row.elementAt(infoIndex.elementAt(3)),
row.elementAt(infoIndex.elementAt(5)), row.elementAt(infoIndex.elementAt(4)),
row.elementAt(infoIndex.elementAt(6)), row.elementAt(infoIndex.elementAt(5)),
row.elementAt(infoIndex.elementAt(7)), row.elementAt(infoIndex.elementAt(6)),
row.elementAt(infoIndex.elementAt(8))); row.elementAt(infoIndex.elementAt(7)),
save(studentInfo); 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("")) if(!sex.equals("") && !sex.equals(""))
throw new BaseInformationIllegalException("sex", sex); throw new BaseInformationIllegalException(String.class, sex);
if(classId.length() != 8) if(classId.length() != 8)
throw new BaseInformationIllegalException("classId", classId); throw new BaseInformationIllegalException(String.class, classId);
if(studentId.length() != 10) if(studentId.length() != 10)
throw new BaseInformationIllegalException("studentId",studentId); throw new BaseInformationIllegalException(String.class, studentId);
if(realName.length() > 64) if(realName.length() > 64)
throw new BaseInformationIllegalException("realName",realName); throw new BaseInformationIllegalException(String.class, realName);
BaseStudentInfo studentInfo = new BaseStudentInfo(); BaseStudentInfo studentInfo = new BaseStudentInfo();
studentInfo.setSex(sex); studentInfo.setSex(sex);
@ -239,14 +261,27 @@ public class BaseInformationService implements IBaseInformationService {
|| baseStudentInfo.getClassId().equals("") || baseStudentInfo.getClassId().equals("")
|| baseStudentInfo.getStudentId().equals("") || baseStudentInfo.getStudentId().equals("")
|| baseStudentInfo.getName().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())) 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);
} }
} }

View File

@ -2,6 +2,9 @@ package com.codesdream.ase.service;
import com.codesdream.ase.component.datamanager.DataTable; import com.codesdream.ase.component.datamanager.DataTable;
import com.codesdream.ase.model.information.*; import com.codesdream.ase.model.information.*;
import com.fasterxml.jackson.databind.ser.Serializers;
import java.util.Optional;
public interface IBaseInformationService { public interface IBaseInformationService {
// 检查行政区域是否合法 // 检查行政区域是否合法
@ -25,8 +28,10 @@ public interface IBaseInformationService {
// 检查学生信息是否存在 // 检查学生信息是否存在
boolean checkStudentInfo(String studentId); boolean checkStudentInfo(String studentId);
// 根据名字查找有效的省级行政区划
BaseAdministrativeDivision findAdministrativeDivisionByName(String name); BaseAdministrativeDivision findAdministrativeDivisionByName(String name);
// 查找学院
BaseCollege findCollegeByName(String name); BaseCollege findCollegeByName(String name);
BaseEthnic findEthnicByName(String name); BaseEthnic findEthnicByName(String name);
@ -47,4 +52,6 @@ public interface IBaseInformationService {
String administrativeDivision); String administrativeDivision);
BaseStudentInfo save(BaseStudentInfo baseStudentInfo); BaseStudentInfo save(BaseStudentInfo baseStudentInfo);
BaseStudentInfo update(BaseStudentInfo baseStudentInfo);
} }

View File

@ -12,39 +12,45 @@ public interface IPermissionService {
Optional<Tag> findTag(String name); 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( Collection<Tag> getTagsFromSPC(
ScopePermissionContainer scopePermissionContainer); ScopePermissionContainer spc);
// 查找用户下的所有标签列表 // 查找用户下的所有标签列表
Collection<Tag> getTagsFromUser(User user); Collection<Tag> getTagsFromUser(User user);
// 查找功能性权限容器下的所有范围性权限容器列表 // 查找功能性权限容器下的所有范围性权限容器列表
Collection<FunctionalPermissionContainer> getFunctionPermissionContainers( Collection<FunctionalPermissionContainer> getFPCs(
PermissionContainersCollection permissionContainersCollection); PermissionContainersCollection pcc);
// 查找标签下的所有用户 // 查找标签下的所有用户
Collection<User> getUsersFromTag(Tag tag); Collection<User> getUsersFromTag(Tag tag);
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中 // 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
void addRelationItemToPermissionContainerCollectionPermissionContainerCollection( void addRelationItemToPCCollection(
PermissionContainersCollection permissionContainersCollection, PermissionContainersCollection pcc,
FunctionalPermissionContainer functionalPermissionContainer, FunctionalPermissionContainer fpc,
ScopePermissionContainer scopePermissionContainer); ScopePermissionContainer spc);
// 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中 // 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection( void addRelationItemsToPCC(
PermissionContainersCollection permissionContainersCollection, PermissionContainersCollection pcc,
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>> Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>>
functionalScopePermissionContainerPairs); fspcPairs);
// 添加一个用户到指定标签中 // 添加一个用户到指定标签中
void addUserToTag(Tag tag, User user); void addUserToTag(Tag tag, User user);
@ -53,19 +59,27 @@ public interface IPermissionService {
void addUsersToTag(Tag tag, Collection<User> users); void addUsersToTag(Tag tag, Collection<User> users);
// 为功能性权限容器添加一个访问控制角色 // 为功能性权限容器添加一个访问控制角色
void addRoleToFunctionalPermissionContainer( void addRoleToFPC(
FunctionalPermissionContainer functionalPermissionContainer, FunctionalPermissionContainer fpc,
String role); String role);
// 为功能性权限容器添加多个访问控制角色 // 为功能性权限容器添加多个访问控制角色
void addRolesToFunctionalPermissionContainer( void addRolesToFPC(
FunctionalPermissionContainer functionalPermissionContainer, FunctionalPermissionContainer fpc,
Collection<String> roles); Collection<String> roles);
void save(Tag tag); 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);
} }

View File

@ -1,5 +1,6 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.model.information.BaseStudentInfo;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import javafx.util.Pair; import javafx.util.Pair;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
@ -14,6 +15,9 @@ public interface IUserService {
// 获得一个空的默认用户 // 获得一个空的默认用户
User getDefaultUser(); User getDefaultUser();
// 由学生基本信息生成对应用户
User getUserByStudentInfo(BaseStudentInfo studentInfo);
List<User> findAll(); List<User> findAll();
Optional<User> findUserById(int id); Optional<User> findUserById(int id);
@ -28,6 +32,9 @@ public interface IUserService {
// 更新用户的密码 // 更新用户的密码
void updatePassword(User user, String password); void updatePassword(User user, String password);
// 封禁用户
void disableUser(User user);
// 根据学号生成随机用户名 // 根据学号生成随机用户名
void generateRandomUsernameByStudentID(User user, String id); void generateRandomUsernameByStudentID(User user, String id);

View File

@ -1,10 +1,10 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.component.permission.UserFunctionalPermissionContainersListGenerator; import com.codesdream.ase.component.permission.UserFPCListGenerator;
import com.codesdream.ase.component.permission.UserFunctionalScopeRelationsListGenerator; import com.codesdream.ase.component.permission.UserFSRGenerator;
import com.codesdream.ase.model.permission.*; import com.codesdream.ase.model.permission.*;
import com.codesdream.ase.repository.permission.FunctionalPermissionRepository; import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository;
import com.codesdream.ase.repository.permission.ScopePermissionRepository; import com.codesdream.ase.repository.permission.ScopePermissionContainerRepository;
import com.codesdream.ase.repository.permission.TagRepository; import com.codesdream.ase.repository.permission.TagRepository;
import javafx.util.Pair; import javafx.util.Pair;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -21,16 +21,16 @@ public class PermissionService implements IPermissionService {
private TagRepository tagRepository; private TagRepository tagRepository;
@Resource @Resource
private FunctionalPermissionRepository functionalPermissionRepository; private FunctionalPermissionContainerRepository fpcRepository;
@Resource @Resource
private ScopePermissionRepository scopePermissionRepository; private ScopePermissionContainerRepository spcRepository;
@Resource @Resource
private UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator; private UserFPCListGenerator userFPCListGenerator;
@Resource @Resource
private UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator; private UserFSRGenerator userFSRGenerator;
@Override @Override
public Optional<Tag> findTag(String name) { public Optional<Tag> findTag(String name) {
@ -38,23 +38,33 @@ public class PermissionService implements IPermissionService {
} }
@Override @Override
public Optional<FunctionalPermissionContainer> findFunctionalPermissionContainer(String name) { public Optional<FunctionalPermissionContainer> findFPC(String name) {
return functionalPermissionRepository.findByName(name); return fpcRepository.findByName(name);
} }
@Override @Override
public Optional<ScopePermissionContainer> findScopePermissionContainer(String name) { public Optional<ScopePermissionContainer> findSPC(String name) {
return scopePermissionRepository.findByName(name); return spcRepository.findByName(name);
} }
@Override @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()); return new ArrayList<>(tag.getPermissionContainersCollections());
} }
@Override @Override
public Collection<Tag> getTagsFromScopePermissionContainers(ScopePermissionContainer scopePermissionContainer) { public Collection<Tag> getTagsFromSPC(ScopePermissionContainer spc) {
return new ArrayList<>(scopePermissionContainer.getTags()); return new ArrayList<>(spc.getTags());
} }
@Override @Override
@ -63,30 +73,46 @@ public class PermissionService implements IPermissionService {
} }
@Override @Override
public Collection<FunctionalPermissionContainer> getFunctionPermissionContainers(PermissionContainersCollection permissionContainersCollection) { public Collection<FunctionalPermissionContainer> getFPCs(
PermissionContainersCollection pcc)
{
Collection<PermissionContainersCollection> permissionContainersCollections = new ArrayList<PermissionContainersCollection>(){{ Collection<PermissionContainersCollection> pccCollections =
add(permissionContainersCollection); new ArrayList<PermissionContainersCollection>(){{
add(pcc);
}}; }};
// 生成功能性与范围性权限容器关联对 // 生成功能性与范围性权限容器关联对
Collection<FunctionalScopeRelation> functionalScopeRelations = Collection<FunctionalScopeRelation> fsr =
userFunctionalScopeRelationsListGenerator.generateFunctionalScopeRelations(permissionContainersCollections); userFSRGenerator.generateFSRs(pccCollections);
return userFunctionalPermissionContainersListGenerator.generateFunctionalContainers(functionalScopeRelations); return userFPCListGenerator.generateFPC(fsr);
} }
@Override @Override
public Collection<User> getUsersFromTag(Tag tag) { public Collection<User> getUsersFromTag(Tag tag) {
return null; return new ArrayList<>(tag.getUsers());
} }
@Override @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 @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 @Override
public void addRoleToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, String role) { public void addRoleToFPC(FunctionalPermissionContainer fpc, String role) {
} }
@Override @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 @Override
public void save(FunctionalPermissionContainer functionalPermissionContainer) { public void save(FunctionalPermissionContainer fpc) {
} }
@Override @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) {
} }
} }

View File

@ -6,6 +6,7 @@ import com.codesdream.ase.component.permission.UserRolesListGenerator;
import com.codesdream.ase.exception.UserInformationIllegalException; import com.codesdream.ase.exception.UserInformationIllegalException;
import com.codesdream.ase.exception.UserNotFoundException; import com.codesdream.ase.exception.UserNotFoundException;
import com.codesdream.ase.exception.UsernameAlreadyExistException; import com.codesdream.ase.exception.UsernameAlreadyExistException;
import com.codesdream.ase.model.information.BaseStudentInfo;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.repository.permission.UserRepository; import com.codesdream.ase.repository.permission.UserRepository;
import javafx.util.Pair; import javafx.util.Pair;
@ -67,6 +68,13 @@ public class UserService implements IUserService {
update(user); update(user);
} }
// 封禁用户
@Override
public void disableUser(User user){
user.setEnabled(false);
update(user);
}
@Override @Override
public void generateRandomUsernameByStudentID(User user, String id) { public void generateRandomUsernameByStudentID(User user, String id) {
user.getUserAuth().setStudentID(id); user.getUserAuth().setStudentID(id);
@ -120,5 +128,28 @@ public class UserService implements IUserService {
return new User(); 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;
}
} }

View File

@ -1,4 +1,4 @@
package com.codesdream.ase; package com.codesdream.ase.test;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;

View File

@ -1,9 +1,10 @@
package com.codesdream.ase; package com.codesdream.ase.test;
import com.codesdream.ase.component.ASESpringUtil; import com.codesdream.ase.component.ASESpringUtil;
import com.codesdream.ase.component.datamanager.DataExcelReader; import com.codesdream.ase.component.datamanager.DataExcelReader;
import com.codesdream.ase.component.datamanager.DataTable; import com.codesdream.ase.component.datamanager.DataTable;
import com.codesdream.ase.service.IBaseInformationService; import com.codesdream.ase.service.IBaseInformationService;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -22,9 +23,20 @@ public class BaseInformationTest {
private ASESpringUtil springUtil; private ASESpringUtil springUtil;
@Test @Test
public void studentInfoImportTest(){ public void studentInfoImportTest() {
DataTable table = springUtil.getBean(DataTable.class); DataTable table = springUtil.getBean(DataTable.class);
table.importTable(new DataExcelReader("SoftInformation.xlsx")); table.importTable(new DataExcelReader("SoftInformation.xlsx"));
informationService.studentInfoImportFromDataTable(table); 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("群众"));
}
} }

View File

@ -1,4 +1,4 @@
package com.codesdream.ase; package com.codesdream.ase.test;
import com.codesdream.ase.component.ASESpringUtil; import com.codesdream.ase.component.ASESpringUtil;
import com.codesdream.ase.component.datamanager.*; import com.codesdream.ase.component.datamanager.*;

View File

@ -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 {
}

View File

@ -1,4 +1,4 @@
package com.codesdream.ase; package com.codesdream.ase.test;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
@ -65,8 +65,6 @@ public class UserTest {
@Test @Test
public void UserBaseTest_2(){ public void UserBaseTest_2(){
User user = userService.findUserByUsername("Tim");
} }