diff --git a/src/main/java/com/codesdream/ase/component/permission/UserFunctionalPermissionContainersListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserFPCListGenerator.java similarity index 52% rename from src/main/java/com/codesdream/ase/component/permission/UserFunctionalPermissionContainersListGenerator.java rename to src/main/java/com/codesdream/ase/component/permission/UserFPCListGenerator.java index 97de9f3..964973d 100644 --- a/src/main/java/com/codesdream/ase/component/permission/UserFunctionalPermissionContainersListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/permission/UserFPCListGenerator.java @@ -11,11 +11,11 @@ import java.util.Collection; * 生成功能性权限容器列表 */ @Component -public class UserFunctionalPermissionContainersListGenerator { +public class UserFPCListGenerator { @Resource - private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator; + private UserFSRGenerator fsrListGenerator; - public Collection generateFunctionalContainers( + public Collection generateFPC( Collection functionalScopeRelations){ Collection functionalPermissionContainers = new ArrayList<>(); @@ -27,15 +27,15 @@ public class UserFunctionalPermissionContainersListGenerator { return functionalPermissionContainers; } - public Collection generateFunctionalPermissionContainers(User user){ - return generateFunctionalContainers( - functionalScopeRelationsListGenerator.generateFunctionalScopeRelations(user) + public Collection generateFPCs(User user){ + return generateFPC( + fsrListGenerator.generateFSRs(user) ); } - public Collection generateFunctionalPermissionContainers(String username){ - return generateFunctionalContainers( - functionalScopeRelationsListGenerator.generateFunctionalScopeRelations(username) + public Collection generateFPCs(String username){ + return generateFPC( + fsrListGenerator.generateFSRs(username) ); } } diff --git a/src/main/java/com/codesdream/ase/component/permission/UserFSRGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserFSRGenerator.java new file mode 100644 index 0000000..077dddd --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/permission/UserFSRGenerator.java @@ -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 generateFSRs( + Collection pccs){ + Collection fsrs = + new ArrayList<>(); + + for(PermissionContainersCollection pcc : pccs){ + fsrs.addAll(pcc.getFunctionalScopeRelations()); + } + + return fsrs; + } + + public Collection generateFSRs( + User user){ + return generateFSRs( + userPCCListGenerator.generatePCCs(user)); + } + + public Collection generateFSRs( + String username){ + return generateFSRs( + userPCCListGenerator.generatePCCs(username)); + } +} diff --git a/src/main/java/com/codesdream/ase/component/permission/UserFunctionalScopeRelationsListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserFunctionalScopeRelationsListGenerator.java deleted file mode 100644 index 5bed3b3..0000000 --- a/src/main/java/com/codesdream/ase/component/permission/UserFunctionalScopeRelationsListGenerator.java +++ /dev/null @@ -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 generateFunctionalScopeRelations( - Collection permissionContainersCollections){ - Collection functionalScopeRelations = - new ArrayList<>(); - - for(PermissionContainersCollection permissionContainersCollection : permissionContainersCollections){ - functionalScopeRelations.addAll(permissionContainersCollection.getFunctionalScopeRelations()); - } - - return functionalScopeRelations; - } - - public Collection generateFunctionalScopeRelations( - User user){ - return generateFunctionalScopeRelations( - userPermissionContainersCollectionsListGenerator.generatePermissionContainerCollections(user)); - } - - public Collection generateFunctionalScopeRelations( - String username){ - return generateFunctionalScopeRelations( - userPermissionContainersCollectionsListGenerator.generatePermissionContainerCollections(username)); - } -} diff --git a/src/main/java/com/codesdream/ase/component/permission/UserPCCListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserPCCListGenerator.java new file mode 100644 index 0000000..ffb22f9 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/permission/UserPCCListGenerator.java @@ -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 generatePCCs( + Collection tags){ + Collection pccs = + new ArrayList<>(); + for(Tag tag : tags){ + pccs.addAll(tag.getPermissionContainersCollections()); + } + return pccs; + } + + public Collection generatePCCs( + User user) { + return generatePCCs(userTagsListGenerator.generateTags(user)); + } + + public Collection generatePCCs( + String username){ + return generatePCCs(userTagsListGenerator.generateTags(username)); + } +} diff --git a/src/main/java/com/codesdream/ase/component/permission/UserPermissionContainersCollectionsListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserPermissionContainersCollectionsListGenerator.java deleted file mode 100644 index 0a1fc50..0000000 --- a/src/main/java/com/codesdream/ase/component/permission/UserPermissionContainersCollectionsListGenerator.java +++ /dev/null @@ -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 generatePermissionContainerCollections( - Collection tags){ - Collection permissionContainersCollections = - new ArrayList<>(); - for(Tag tag : tags){ - permissionContainersCollections.addAll(tag.getPermissionContainersCollections()); - } - return permissionContainersCollections; - } - - public Collection generatePermissionContainerCollections( - User user) { - return generatePermissionContainerCollections(userTagsListGenerator.generateTags(user)); - } - - public Collection generatePermissionContainerCollections( - String username){ - return generatePermissionContainerCollections(userTagsListGenerator.generateTags(username)); - } -} diff --git a/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java index 1e39c9e..9b861c3 100644 --- a/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java @@ -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 generateRoles( - Collection functionalPermissionContainers){ + Collection fpcs){ Collection 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 generateRoles(String username){ return generateRoles( - functionalPermissionContainersListGenerator.generateFunctionalPermissionContainers(username) + fpcListGenerator.generateFPCs(username) ); } public Collection generateRoles(User user){ return generateRoles( - functionalPermissionContainersListGenerator.generateFunctionalPermissionContainers(user) + fpcListGenerator.generateFPCs(user) ); } } diff --git a/src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java index 9b82847..d53bfe4 100644 --- a/src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java @@ -19,8 +19,8 @@ public class UserTagsListGenerator { @Resource UserRepository userRepository; - public Collection generateTags(ScopePermissionContainer scopePermissionContainer){ - return new ArrayList<>(scopePermissionContainer.getTags()); + public Collection generateTags(ScopePermissionContainer spc){ + return new ArrayList<>(spc.getTags()); } public Collection generateTags(User user){ diff --git a/src/main/java/com/codesdream/ase/exception/BaseInformationAlreadyExistException.java b/src/main/java/com/codesdream/ase/exception/BaseInformationAlreadyExistException.java index a75a9f8..54a564b 100644 --- a/src/main/java/com/codesdream/ase/exception/BaseInformationAlreadyExistException.java +++ b/src/main/java/com/codesdream/ase/exception/BaseInformationAlreadyExistException.java @@ -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; } } diff --git a/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java b/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java index ab0fea7..34b485b 100644 --- a/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java +++ b/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java @@ -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; } } diff --git a/src/main/java/com/codesdream/ase/exception/BaseInformationNotExistException.java b/src/main/java/com/codesdream/ase/exception/BaseInformationNotExistException.java index 3102dc6..65da967 100644 --- a/src/main/java/com/codesdream/ase/exception/BaseInformationNotExistException.java +++ b/src/main/java/com/codesdream/ase/exception/BaseInformationNotExistException.java @@ -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; } } diff --git a/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java b/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java index 2f111ad..59bd01f 100644 --- a/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java +++ b/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java @@ -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; } diff --git a/src/main/java/com/codesdream/ase/model/permission/ScopePermissionContainer.java b/src/main/java/com/codesdream/ase/model/permission/ScopePermissionContainer.java index 4759a89..87e4485 100644 --- a/src/main/java/com/codesdream/ase/model/permission/ScopePermissionContainer.java +++ b/src/main/java/com/codesdream/ase/model/permission/ScopePermissionContainer.java @@ -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 tags; @Column(nullable = false) diff --git a/src/main/java/com/codesdream/ase/model/permission/Tag.java b/src/main/java/com/codesdream/ase/model/permission/Tag.java index bffab68..6b222aa 100644 --- a/src/main/java/com/codesdream/ase/model/permission/Tag.java +++ b/src/main/java/com/codesdream/ase/model/permission/Tag.java @@ -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 permissionContainersCollections; public Tag(String name, String description) { diff --git a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java index ef8d1ee..df7824c 100644 --- a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java +++ b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java @@ -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; } diff --git a/src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionRepository.java b/src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionContainerRepository.java similarity index 73% rename from src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionContainerRepository.java index 134b3f8..91cc1c8 100644 --- a/src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionContainerRepository.java @@ -7,6 +7,6 @@ import org.springframework.stereotype.Repository; import java.util.Optional; @Repository -public interface FunctionalPermissionRepository extends CrudRepository { +public interface FunctionalPermissionContainerRepository extends CrudRepository { Optional findByName(String name); } diff --git a/src/main/java/com/codesdream/ase/repository/permission/ScopePermissionRepository.java b/src/main/java/com/codesdream/ase/repository/permission/ScopePermissionContainerRepository.java similarity index 70% rename from src/main/java/com/codesdream/ase/repository/permission/ScopePermissionRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/ScopePermissionContainerRepository.java index 95893f8..1b808ce 100644 --- a/src/main/java/com/codesdream/ase/repository/permission/ScopePermissionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/ScopePermissionContainerRepository.java @@ -5,6 +5,6 @@ import org.springframework.data.repository.CrudRepository; import java.util.Optional; -public interface ScopePermissionRepository extends CrudRepository { +public interface ScopePermissionContainerRepository extends CrudRepository { Optional findByName(String name); } diff --git a/src/main/java/com/codesdream/ase/service/BaseInformationService.java b/src/main/java/com/codesdream/ase/service/BaseInformationService.java index 78298dd..870a816 100644 --- a/src/main/java/com/codesdream/ase/service/BaseInformationService.java +++ b/src/main/java/com/codesdream/ase/service/BaseInformationService.java @@ -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 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 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 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 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 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 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 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> infoIndexOptional = new ArrayList<>(); + 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("省份名称")); + Vector infoIndex = new Vector<>(); for(Optional 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()); } int dataRowsSize = table.getRowsSize(); - for(int i = 0; i row = table.getRowVector(i); - BaseStudentInfo studentInfo = - constructStudentInfo(row.elementAt(infoIndex.elementAt(0)), - row.elementAt(infoIndex.elementAt(1)), - row.elementAt(infoIndex.elementAt(2)), - row.elementAt(infoIndex.elementAt(3)), - row.elementAt(infoIndex.elementAt(4)), - row.elementAt(infoIndex.elementAt(5)), - row.elementAt(infoIndex.elementAt(6)), - row.elementAt(infoIndex.elementAt(7)), - row.elementAt(infoIndex.elementAt(8))); - save(studentInfo); + try { + BaseStudentInfo studentInfo = + constructStudentInfo(row.elementAt(infoIndex.elementAt(0)), + row.elementAt(infoIndex.elementAt(1)), + row.elementAt(infoIndex.elementAt(2)), + row.elementAt(infoIndex.elementAt(3)), + row.elementAt(infoIndex.elementAt(4)), + row.elementAt(infoIndex.elementAt(5)), + row.elementAt(infoIndex.elementAt(6)), + 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); } } diff --git a/src/main/java/com/codesdream/ase/service/IBaseInformationService.java b/src/main/java/com/codesdream/ase/service/IBaseInformationService.java index fbffb32..1a1e5c8 100644 --- a/src/main/java/com/codesdream/ase/service/IBaseInformationService.java +++ b/src/main/java/com/codesdream/ase/service/IBaseInformationService.java @@ -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); } diff --git a/src/main/java/com/codesdream/ase/service/IPermissionService.java b/src/main/java/com/codesdream/ase/service/IPermissionService.java index 77d96cc..0ccb611 100644 --- a/src/main/java/com/codesdream/ase/service/IPermissionService.java +++ b/src/main/java/com/codesdream/ase/service/IPermissionService.java @@ -12,39 +12,45 @@ public interface IPermissionService { Optional findTag(String name); // 查找功能性权限容器 - Optional findFunctionalPermissionContainer(String name); + Optional findFPC(String name); // 查找范围性权限容器 - Optional findScopePermissionContainer(String name); + Optional findSPC(String name); + + // 根据id查找功能性权限容器 + Optional findFPC(int id); + + // 根据id查找范围性权限容器 + Optional findSPC(int id); // 标签下所有的获得权限容器集合列表 - Collection getPermissionContainerCollections(Tag tag); + Collection getPCCs(Tag tag); // 获得范围性权限容器下的所有标签列表 - Collection getTagsFromScopePermissionContainers( - ScopePermissionContainer scopePermissionContainer); + Collection getTagsFromSPC( + ScopePermissionContainer spc); // 查找用户下的所有标签列表 Collection getTagsFromUser(User user); // 查找功能性权限容器下的所有范围性权限容器列表 - Collection getFunctionPermissionContainers( - PermissionContainersCollection permissionContainersCollection); + Collection getFPCs( + PermissionContainersCollection pcc); // 查找标签下的所有用户 Collection 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> - functionalScopePermissionContainerPairs); + fspcPairs); // 添加一个用户到指定标签中 void addUserToTag(Tag tag, User user); @@ -53,19 +59,27 @@ public interface IPermissionService { void addUsersToTag(Tag tag, Collection users); // 为功能性权限容器添加一个访问控制角色 - void addRoleToFunctionalPermissionContainer( - FunctionalPermissionContainer functionalPermissionContainer, + void addRoleToFPC( + FunctionalPermissionContainer fpc, String role); // 为功能性权限容器添加多个访问控制角色 - void addRolesToFunctionalPermissionContainer( - FunctionalPermissionContainer functionalPermissionContainer, + void addRolesToFPC( + FunctionalPermissionContainer fpc, Collection 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); } diff --git a/src/main/java/com/codesdream/ase/service/IUserService.java b/src/main/java/com/codesdream/ase/service/IUserService.java index 1759447..7b7c2b0 100644 --- a/src/main/java/com/codesdream/ase/service/IUserService.java +++ b/src/main/java/com/codesdream/ase/service/IUserService.java @@ -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 findAll(); Optional 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); diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index ee8f8f2..04b30da 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -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 findTag(String name) { @@ -38,23 +38,33 @@ public class PermissionService implements IPermissionService { } @Override - public Optional findFunctionalPermissionContainer(String name) { - return functionalPermissionRepository.findByName(name); + public Optional findFPC(String name) { + return fpcRepository.findByName(name); } @Override - public Optional findScopePermissionContainer(String name) { - return scopePermissionRepository.findByName(name); + public Optional findSPC(String name) { + return spcRepository.findByName(name); } @Override - public Collection getPermissionContainerCollections(Tag tag) { + public Optional findFPC(int id) { + return fpcRepository.findById(id); + } + + @Override + public Optional findSPC(int id) { + return spcRepository.findById(id); + } + + @Override + public Collection getPCCs(Tag tag) { return new ArrayList<>(tag.getPermissionContainersCollections()); } @Override - public Collection getTagsFromScopePermissionContainers(ScopePermissionContainer scopePermissionContainer) { - return new ArrayList<>(scopePermissionContainer.getTags()); + public Collection getTagsFromSPC(ScopePermissionContainer spc) { + return new ArrayList<>(spc.getTags()); } @Override @@ -63,30 +73,46 @@ public class PermissionService implements IPermissionService { } @Override - public Collection getFunctionPermissionContainers(PermissionContainersCollection permissionContainersCollection) { + public Collection getFPCs( + PermissionContainersCollection pcc) + { - Collection permissionContainersCollections = new ArrayList(){{ - add(permissionContainersCollection); + Collection pccCollections = + new ArrayList(){{ + add(pcc); }}; // 生成功能性与范围性权限容器关联对 - Collection functionalScopeRelations = - userFunctionalScopeRelationsListGenerator.generateFunctionalScopeRelations(permissionContainersCollections); - return userFunctionalPermissionContainersListGenerator.generateFunctionalContainers(functionalScopeRelations); + Collection fsr = + userFSRGenerator.generateFSRs(pccCollections); + return userFPCListGenerator.generateFPC(fsr); } @Override public Collection 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> functionalScopePermissionContainerPairs) { + public void addRelationItemsToPCC(PermissionContainersCollection pcc, + Collection> 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 roles) { + public void addRolesToFPC(FunctionalPermissionContainer fpc, Collection 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) { } } diff --git a/src/main/java/com/codesdream/ase/service/UserService.java b/src/main/java/com/codesdream/ase/service/UserService.java index 390b383..8af0386 100644 --- a/src/main/java/com/codesdream/ase/service/UserService.java +++ b/src/main/java/com/codesdream/ase/service/UserService.java @@ -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; + } + } diff --git a/src/test/java/com/codesdream/ase/AseApplicationTests.java b/src/test/java/com/codesdream/ase/test/AseApplicationTests.java similarity index 85% rename from src/test/java/com/codesdream/ase/AseApplicationTests.java rename to src/test/java/com/codesdream/ase/test/AseApplicationTests.java index 29866fd..761d785 100644 --- a/src/test/java/com/codesdream/ase/AseApplicationTests.java +++ b/src/test/java/com/codesdream/ase/test/AseApplicationTests.java @@ -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; diff --git a/src/test/java/com/codesdream/ase/BaseInformationTest.java b/src/test/java/com/codesdream/ase/test/BaseInformationTest.java similarity index 56% rename from src/test/java/com/codesdream/ase/BaseInformationTest.java rename to src/test/java/com/codesdream/ase/test/BaseInformationTest.java index 7cdea10..be5aaa1 100644 --- a/src/test/java/com/codesdream/ase/BaseInformationTest.java +++ b/src/test/java/com/codesdream/ase/test/BaseInformationTest.java @@ -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; @@ -22,9 +23,20 @@ public class BaseInformationTest { private ASESpringUtil springUtil; @Test - public void studentInfoImportTest(){ + public void studentInfoImportTest() { DataTable table = springUtil.getBean(DataTable.class); 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("群众")); + + } } diff --git a/src/test/java/com/codesdream/ase/DataManagerTest.java b/src/test/java/com/codesdream/ase/test/DataManagerTest.java similarity index 99% rename from src/test/java/com/codesdream/ase/DataManagerTest.java rename to src/test/java/com/codesdream/ase/test/DataManagerTest.java index da416c5..accbfde 100644 --- a/src/test/java/com/codesdream/ase/DataManagerTest.java +++ b/src/test/java/com/codesdream/ase/test/DataManagerTest.java @@ -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.*; diff --git a/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java b/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java new file mode 100644 index 0000000..f6c14bd --- /dev/null +++ b/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java @@ -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 { + +} diff --git a/src/test/java/com/codesdream/ase/UserTest.java b/src/test/java/com/codesdream/ase/test/UserTest.java similarity index 96% rename from src/test/java/com/codesdream/ase/UserTest.java rename to src/test/java/com/codesdream/ase/test/UserTest.java index 177a0db..a30513c 100644 --- a/src/test/java/com/codesdream/ase/UserTest.java +++ b/src/test/java/com/codesdream/ase/test/UserTest.java @@ -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"); - }