This commit is contained in:
yourtree 2020-02-18 14:34:40 +08:00
commit f2539d6c12
54 changed files with 831 additions and 132 deletions

13
pom.xml
View File

@ -113,6 +113,19 @@
<version>1.16.10</version> <version>1.16.10</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<!-- 使用 xlsx 格式需要额外引入此依赖 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,22 @@
package com.codesdream.ase.component;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* 手动获得Bean的工具类
*/
@Component
public class ASESpringUtil {
@Resource
private ApplicationContext applicationContext;
public <T> T getBean(Class<T> tClass){
return applicationContext.getBean(tClass);
}
}

View File

@ -0,0 +1,58 @@
package com.codesdream.ase.component.datamanager;
import com.codesdream.ase.component.ASESpringUtil;
import lombok.Data;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* DataModel对应Repository层查询器
*/
@Data
@Component
@Scope("prototype")
public class DataModelRepositorySearcher {
@Resource
ASESpringUtil springUtil;
public final String repositoryPath = "com.codesdream.ase.repository.";
private Class<?> repositoryClass = null;
private boolean present;
public void getDataModelRepositoryClass(String subSystem, String dataModel){
dataModel = doCheckName(dataModel);
try {
this.repositoryClass = Class.forName(dataModelFullNameGenerator(subSystem, dataModel));
this.setPresent(true);
} catch (ClassNotFoundException e) {
this.setPresent(false);
}
}
public <T> T getDataModelRepositoryInstance() {
// 确保可以引用
if(isPresent()) {
@SuppressWarnings("unchecked")
T repository = (T) springUtil.getBean(repositoryClass);
return repository;
}
return null;
}
public static String doCheckName(String string) {
char[] charArray = string.toCharArray();
if(Character.isLowerCase(charArray[0])) charArray[0] -= 32;
else return string;
return String.valueOf(charArray);
}
private String dataModelFullNameGenerator(String subSystem, String dataModel){
return new String(repositoryPath + subSystem + "." + dataModel + "Repository");
}
}

View File

@ -0,0 +1,70 @@
package com.codesdream.ase.component.datamanager;
import lombok.Data;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.swing.text.html.parser.Entity;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
/**
* 根据子系统及名称查找特定的Data Model
*/
@Data
@Component
@Scope("prototype")
public class DataModelSearcher {
public final String modelPath = "com.codesdream.ase.model.";
private Class<?> dataModelClass = null;
private boolean present;
public void getDataModelClass(String subSystem, String dataModel) {
dataModel = doCheckName(dataModel);
try {
dataModelClass = Class.forName(dataModelFullNameGenerator(subSystem, dataModel));
this.setPresent(true);
}catch (ClassNotFoundException e){
this.setPresent(false);
}
}
public Collection<String> getDataModelParamArgs() {
if(isPresent()) {
Collection<String> paramArgs = new ArrayList<>();
for (Field field : dataModelClass.getDeclaredFields()) {
paramArgs.add(field.getName());
}
return paramArgs;
}
return null;
}
public <T> T getDataModelInstance(Class<T> dataModelClass) {
if(isPresent()){
try {
return dataModelClass.newInstance();
} catch (IllegalAccessException e) {
this.setPresent(false);
return null;
} catch (InstantiationException e) {
e.printStackTrace();
return null;
}
}
return null;
}
public static String doCheckName(String string) {
char[] charArray = string.toCharArray();
if(Character.isLowerCase(charArray[0])) charArray[0] -= 32;
else return string;
return String.valueOf(charArray);
}
private String dataModelFullNameGenerator(String subSystem, String dataModel){
return new String(modelPath + subSystem + "." + dataModel);
}
}

View File

@ -0,0 +1,22 @@
package com.codesdream.ase.component.error;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "error")
public class ErrorResponse
{
public ErrorResponse(String message, List<String> details) {
super();
this.message = message;
this.details = details;
}
//General error message about nature of error
private String message;
//Specific errors in API request processing
private List<String> details;
//Getter and setters
}

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import org.springframework.security.authentication.*; import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
@ -11,8 +11,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection; import java.util.Collection;
@Component @Component

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
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;

View File

@ -1,8 +1,9 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.*; import com.codesdream.ase.model.permission.*;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -11,16 +12,9 @@ import java.util.Collection;
*/ */
@Component @Component
public class UserFunctionalPermissionContainersListGenerator { public class UserFunctionalPermissionContainersListGenerator {
@Resource
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator; private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator;
public UserFunctionalPermissionContainersListGenerator(
UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator)
{
if(userFunctionalScopeRelationsListGenerator == null) throw new NullPointerException();
this.functionalScopeRelationsListGenerator = userFunctionalScopeRelationsListGenerator;
}
public Collection<FunctionalPermissionContainer> generateFunctionalContainers( public Collection<FunctionalPermissionContainer> generateFunctionalContainers(
Collection<FunctionalScopeRelation> functionalScopeRelations){ Collection<FunctionalScopeRelation> functionalScopeRelations){
Collection<FunctionalPermissionContainer> functionalPermissionContainers Collection<FunctionalPermissionContainer> functionalPermissionContainers

View File

@ -1,10 +1,11 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.FunctionalScopeRelation; import com.codesdream.ase.model.permission.FunctionalScopeRelation;
import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.PermissionContainersCollection;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -14,15 +15,9 @@ import java.util.Collection;
@Component @Component
public class UserFunctionalScopeRelationsListGenerator { public class UserFunctionalScopeRelationsListGenerator {
@Resource
private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator; private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator;
public UserFunctionalScopeRelationsListGenerator(
UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator)
{
if(userPermissionContainersCollectionsListGenerator == null) throw new NullPointerException();
this.userPermissionContainersCollectionsListGenerator =
userPermissionContainersCollectionsListGenerator;
}
public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations( public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations(
Collection<PermissionContainersCollection> permissionContainersCollections){ Collection<PermissionContainersCollection> permissionContainersCollections){

View File

@ -1,10 +1,11 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.PermissionContainersCollection;
import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -13,15 +14,9 @@ import java.util.Collection;
*/ */
@Component @Component
public class UserPermissionContainersCollectionsListGenerator { public class UserPermissionContainersCollectionsListGenerator {
@Resource
private UserTagsListGenerator userTagsListGenerator; private UserTagsListGenerator userTagsListGenerator;
public UserPermissionContainersCollectionsListGenerator(UserTagsListGenerator userTagsListGenerator)
{
if(userTagsListGenerator == null) throw new NullPointerException();
this.userTagsListGenerator = userTagsListGenerator;
}
public Collection<PermissionContainersCollection> generatePermissionContainerCollections( public Collection<PermissionContainersCollection> generatePermissionContainerCollections(
Collection<Tag> tags){ Collection<Tag> tags){
Collection<PermissionContainersCollection> permissionContainersCollections = Collection<PermissionContainersCollection> permissionContainersCollections =

View File

@ -1,11 +1,13 @@
package com.codesdream.ase.component; 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;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -14,16 +16,9 @@ import java.util.Collection;
*/ */
@Component @Component
public class UserRolesListGenerator { public class UserRolesListGenerator {
@Resource
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator; private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator;
public UserRolesListGenerator(
UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator)
{
this.functionalPermissionContainersListGenerator =
userFunctionalPermissionContainersListGenerator;
}
public Collection<GrantedAuthority> generateRoles( public Collection<GrantedAuthority> generateRoles(
Collection<FunctionalPermissionContainer> functionalPermissionContainers){ Collection<FunctionalPermissionContainer> functionalPermissionContainers){
Collection<GrantedAuthority> authorities = new ArrayList<>(); Collection<GrantedAuthority> authorities = new ArrayList<>();

View File

@ -1,9 +1,9 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.ScopePermissionContainer; import com.codesdream.ase.model.permission.ScopePermissionContainer;
import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.repository.UserRepository; import com.codesdream.ase.repository.permission.UserRepository;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.component; package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;

View File

@ -1,9 +1,8 @@
package com.codesdream.ase.configure; package com.codesdream.ase.configure;
import com.codesdream.ase.component.ASEPasswordEncoder; import com.codesdream.ase.component.permission.ASEPasswordEncoder;
import com.codesdream.ase.component.ASESecurityAuthenticationProvider; import com.codesdream.ase.component.permission.ASESecurityAuthenticationProvider;
import com.codesdream.ase.service.ASEUserDetailsService; import com.codesdream.ase.service.ASEUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;

View File

@ -0,0 +1,23 @@
package com.codesdream.ase.controller;
import com.codesdream.ase.component.error.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import java.util.ArrayList;
import java.util.List;
@ControllerAdvice
public class ASEControllerAdvice {
@ExceptionHandler(value = {RuntimeException.class})
public final ResponseEntity<Object> handleRuntimeException(RuntimeException e, WebRequest webRequest){
List<String> details = new ArrayList<>();
details.add(e.getLocalizedMessage());
ErrorResponse errorResponse = new ErrorResponse("Runtime Error", details);
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

View File

@ -1,26 +1,44 @@
package com.codesdream.ase.controller; package com.codesdream.ase.controller;
import com.codesdream.ase.component.error.ErrorResponse;
import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.WebRequest;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller @Controller
public class ASEErrorController implements ErrorController { public class ASEErrorController implements ErrorController {
@RequestMapping("/error") @RequestMapping("/error")
public String handleError(HttpServletRequest request, Model model){ public String handleError(HttpServletRequest request, Model model){
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception"); Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
// 页面未找到 // 页面未找到
if(statusCode == 404){ if(statusCode == HttpStatus.NOT_FOUND.value()){
return "not_found"; return "not_found";
} }
model.addAttribute("http_status", statusCode);
model.addAttribute("exception_name", exception.getClass().getName());
model.addAttribute("exception_message", exception.getMessage());
List<String> stack_infos = new ArrayList<>();
for(StackTraceElement element : exception.getStackTrace()){
String s = element.toString();
stack_infos.add(s);
}
model.addAttribute("error_stack", stack_infos);
model.addAttribute("exception_date",new Date());
return "error";
return"error";
} }
@Override @Override

View File

@ -0,0 +1,42 @@
package com.codesdream.ase.controller;
import com.codesdream.ase.component.ASESpringUtil;
import com.codesdream.ase.component.datamanager.DataModelRepositorySearcher;
import com.codesdream.ase.component.datamanager.DataModelSearcher;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.w3c.dom.Entity;
import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.*;
@Controller
@RequestMapping(value = "/database")
public class DataManagerController {
@Resource
ASESpringUtil springUtil;
@RequestMapping(value = "{subSystem}/{dataModel}/query")
private String queryView(Model model, @PathVariable String dataModel, @PathVariable String subSystem) {
DataModelRepositorySearcher dataModelRepositorySearcher = springUtil.getBean(DataModelRepositorySearcher.class);
DataModelSearcher dataModelSearcher = springUtil.getBean(DataModelSearcher.class);
dataModelSearcher.getDataModelClass(subSystem, dataModel);
if(!dataModelSearcher.isPresent()){
throw new RuntimeException("Data Model Not Found");
}
dataModelRepositorySearcher.getDataModelRepositoryClass(subSystem, dataModel);
if(!dataModelRepositorySearcher.isPresent()){
throw new RuntimeException("Data Model Repository Not Found");
}
Map<String, Object> data;
return "query";
}
}

View File

@ -0,0 +1,17 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class UserInformationIllegalException extends RuntimeException {
String username;
public UserInformationIllegalException(String username){
super();
this.username = username;
}
}

View File

@ -0,0 +1,17 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class UserNotFoundException extends RuntimeException {
Integer id;
String username;
public UserNotFoundException(Integer id, String username){
super();
this.id = id;
this.username = username;
}
}

View File

@ -0,0 +1,16 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class UsernameAlreadyExistException extends RuntimeException {
String username;
public UsernameAlreadyExistException(String username){
super();
this.username = username;
}
}

View File

@ -0,0 +1,20 @@
package com.codesdream.ase.model.information;
import lombok.Data;
import javax.persistence.*;
/**
* 考生类别基本信息
*/
@Data
@Entity
@Table(name = "base_candidate_category")
public class BaseCandidateCategory {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
}

View File

@ -16,4 +16,7 @@ public class BaseCollege {
private int id; private int id;
private String name; private String name;
// 学院代码
private int number;
} }

View File

@ -4,6 +4,9 @@ import lombok.Data;
import javax.persistence.*; import javax.persistence.*;
/**
* 民族基本信息
*/
@Data @Data
@Entity @Entity
@Table(name = "base_ethnic") @Table(name = "base_ethnic")

View File

@ -4,6 +4,9 @@ import lombok.Data;
import javax.persistence.*; import javax.persistence.*;
/**
* 专业基本信息
*/
@Data @Data
@Entity @Entity
@Table(name = "base_major") @Table(name = "base_major")

View File

@ -0,0 +1,19 @@
package com.codesdream.ase.model.information;
import lombok.Data;
import javax.persistence.*;
/**
* 政治面貌基本信息
*/
@Data
@Entity
@Table(name = "base_political_status")
public class BasePoliticalStatus {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
}

View File

@ -0,0 +1,42 @@
package com.codesdream.ase.model.information;
import lombok.Data;
import javax.persistence.*;
/**
* 学生基本真实信息
*/
@Data
@Entity
@Table(name = "base_student_info")
public class BaseStudentInfo {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
// 真实姓名
private String name;
// 学号
private String studentId;
// 班号
private String classId;
// 性别
private String sex;
// 民族
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseEthnic ethnic;
// 学院
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseCollege college;
// 专业
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseMajor major;
// 政治面貌
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BasePoliticalStatus politicalStatus;
// 省份地区
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseAdministrativeDivision administrativeDivision;
}

View File

@ -0,0 +1,36 @@
package com.codesdream.ase.model.leaves;
import com.codesdream.ase.model.permission.User;
import lombok.Data;
import java.util.*;
import javax.persistence.*;
@Data
@Entity
@Table(name = "leaves_archive")
public class Leave {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
//发出人
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private User userFrom;
//审批人容器
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private Set <User> userTo;
//请假类型 病假事假等
@Column(name = "type", nullable = false)
private String type;
//批准状态
@Column(name = "Authentication", nullable = false)
private Boolean Authentication;
//开始时间
@Column(nullable = false)
private Date startTime;
@Column(nullable = false)
private Date endTime;
//申请时间
private Date applyTime;
//认证时间
private Date authTime;
}

View File

@ -0,0 +1,7 @@
package com.codesdream.ase.model.leaves;
/**
请假信息的管理系统
*/
public class LeavesSystem {
}

View File

@ -1,15 +1,10 @@
package com.codesdream.ase.model.permission; package com.codesdream.ase.model.permission;
import com.codesdream.ase.component.UserAuthoritiesGenerator;
import com.codesdream.ase.component.UserRolesListGenerator;
import com.codesdream.ase.model.activity.UserActivity; import com.codesdream.ase.model.activity.UserActivity;
import com.codesdream.ase.service.IUserService;
import lombok.Data; import lombok.Data;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.persistence.*; import javax.persistence.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -1,8 +1,6 @@
package com.codesdream.ase.model.permission; package com.codesdream.ase.model.permission;
import com.codesdream.ase.model.information.BaseAdministrativeDivision; import com.codesdream.ase.model.information.*;
import com.codesdream.ase.model.information.BaseCollege;
import com.codesdream.ase.model.information.BaseMajor;
import lombok.Data; import lombok.Data;
import javax.persistence.*; import javax.persistence.*;
@ -19,20 +17,28 @@ public class UserDetail {
private int id; private int id;
// 所属地区 // 所属地区
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseAdministrativeDivision baseAdministrativeDivision; private BaseAdministrativeDivision baseAdministrativeDivision;
// 所属学院 // 所属学院
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseCollege baseCollege; private BaseCollege baseCollege;
// 所属专业 // 所属专业
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseMajor baseMajor; private BaseMajor baseMajor;
// 民族
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BaseEthnic baseEthnic;
// 政治面貌
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private BasePoliticalStatus basePoliticalStatus;
// 真实姓名 // 真实姓名
private String realName; private String realName = "";
// 在校状态 // 在校状态
private boolean atSchool; private boolean atSchool = false;
} }

View File

@ -0,0 +1,12 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BaseAdministrativeDivision;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface BaseAdministrativeDivisionRepository extends CrudRepository<BaseAdministrativeDivision, Integer> {
Optional<BaseAdministrativeDivision> findByName(String name);
}

View File

@ -0,0 +1,12 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BaseCandidateCategory;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface BaseCandidateCategoryRepository extends CrudRepository<BaseCandidateCategory, Integer> {
Optional<BaseCandidateCategory> findByName(String name);
}

View File

@ -0,0 +1,13 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BaseCollege;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface BaseCollegeRepository extends CrudRepository<BaseCollege, Integer> {
Optional<BaseCollege> findByName(String name);
Optional<BaseCollege> findByNumber(Integer number);
}

View File

@ -0,0 +1,12 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BaseEthnic;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface BaseEthnicRepository extends CrudRepository<BaseEthnic, Integer> {
Optional<BaseEthnic> findByName(String name);
}

View File

@ -0,0 +1,12 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BaseMajor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface BaseMajorRepository extends CrudRepository<BaseMajor, Integer> {
Optional<BaseMajor> findByName(String name);
}

View File

@ -0,0 +1,10 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BasePoliticalStatus;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
public interface BasePoliticalStatusRepository extends CrudRepository<BasePoliticalStatus, Integer> {
Optional<BasePoliticalStatus> findByName(String name);
}

View File

@ -0,0 +1,14 @@
package com.codesdream.ase.repository.information;
import com.codesdream.ase.model.information.BaseStudentInfo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface BaseStudentInfoRepository extends CrudRepository<BaseStudentInfo, Integer> {
// 通过学号查找
Optional<BaseStudentInfo> findByStudentId(String student_id);
}

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository; package com.codesdream.ase.repository.permission;
import com.codesdream.ase.model.permission.FunctionalPermissionContainer; import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository; package com.codesdream.ase.repository.permission;
import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.PermissionContainersCollection;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository; package com.codesdream.ase.repository.permission;
import com.codesdream.ase.model.permission.ScopePermissionContainer; import com.codesdream.ase.model.permission.ScopePermissionContainer;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository; package com.codesdream.ase.repository.permission;
import com.codesdream.ase.model.permission.FunctionalPermissionContainer; import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.Tag;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository; package com.codesdream.ase.repository.permission;
import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;

View File

@ -1,6 +1,6 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.component.UserAuthoritiesGenerator; import com.codesdream.ase.component.permission.UserAuthoritiesGenerator;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
@ -9,7 +9,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.Optional;
@Service @Service
public class ASEUserDetailsService implements UserDetailsService { public class ASEUserDetailsService implements UserDetailsService {

View File

@ -0,0 +1,5 @@
package com.codesdream.ase.service;
public interface IBaseInformationService {
boolean checkAdministrativeDivision(String name);
}

View File

@ -1,6 +1,7 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import javafx.util.Pair;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import java.util.Collection; import java.util.Collection;
@ -16,20 +17,28 @@ public interface IUserService {
List<User> findAll(); List<User> findAll();
Optional<User> findUserById(int id); Optional<User> findUserById(int id);
User findUserByUsername(String username); User findUserByUsername(String username);
public Pair<Boolean, User> checkIfUserExists(String username);
// 获得用户所有的权限角色 // 获得用户所有的权限角色
Collection<? extends GrantedAuthority> getUserAuthorities(User user); Collection<? extends GrantedAuthority> getUserAuthorities(User user);
// 更新用户的密码 // 更新用户的密码
void updatePassword(User user, String password); void updatePassword(User user, String password);
// 生成随机用户名 // 根据学号生成随机用户名
void generateRandomUsernameByStudentID(User user, String id); void generateRandomUsernameByStudentID(User user, String id);
// 注册用户
User save(User user); User save(User user);
// 更新用户信息
User update(User user); User update(User user);
// 删除用户
void delete(User user);
} }

View File

@ -1,11 +1,11 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.component.UserFunctionalPermissionContainersListGenerator; import com.codesdream.ase.component.permission.UserFunctionalPermissionContainersListGenerator;
import com.codesdream.ase.component.UserFunctionalScopeRelationsListGenerator; import com.codesdream.ase.component.permission.UserFunctionalScopeRelationsListGenerator;
import com.codesdream.ase.model.permission.*; import com.codesdream.ase.model.permission.*;
import com.codesdream.ase.repository.FunctionalPermissionRepository; import com.codesdream.ase.repository.permission.FunctionalPermissionRepository;
import com.codesdream.ase.repository.ScopePermissionRepository; import com.codesdream.ase.repository.permission.ScopePermissionRepository;
import com.codesdream.ase.repository.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;
@ -30,7 +30,7 @@ public class PermissionService implements IPermissionService {
private UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator; private UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator;
@Resource @Resource
UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator; private UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator;
@Override @Override
public Optional<Tag> findTag(String name) { public Optional<Tag> findTag(String name) {

View File

@ -1,10 +1,14 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.component.ASEPasswordEncoder; import com.codesdream.ase.component.permission.ASEPasswordEncoder;
import com.codesdream.ase.component.ASEUsernameEncoder; import com.codesdream.ase.component.permission.ASEUsernameEncoder;
import com.codesdream.ase.component.UserRolesListGenerator; 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.permission.User; import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.repository.UserRepository; import com.codesdream.ase.repository.permission.UserRepository;
import javafx.util.Pair;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -41,10 +45,16 @@ public class UserService implements IUserService {
@Override @Override
public User findUserByUsername(String username) { public User findUserByUsername(String username) {
Optional<User> user = userRepository.findByUsername(username); Optional<User> user = userRepository.findByUsername(username);
if(!user.isPresent()) throw new UsernameNotFoundException("User Not Found"); if(!user.isPresent()) throw new UsernameNotFoundException(username);
return user.get(); return user.get();
} }
@Override
public Pair<Boolean, User> checkIfUserExists(String username){
Optional<User> user = userRepository.findByUsername(username);
return user.map(value -> new Pair<>(true, value)).orElseGet(() -> new Pair<>(false, null));
}
@Override @Override
public Collection<? extends GrantedAuthority> getUserAuthorities(User user) { public Collection<? extends GrantedAuthority> getUserAuthorities(User user) {
return userRolesListGenerator.generateRoles(user); return userRolesListGenerator.generateRoles(user);
@ -66,23 +76,43 @@ public class UserService implements IUserService {
public User save(User user) { public User save(User user) {
// 查找用户名是否已经被注册 // 查找用户名是否已经被注册
if(userRepository.findByUsername(user.getUsername()).isPresent()) if(userRepository.findByUsername(user.getUsername()).isPresent())
throw new RuntimeException("Username Already Exists"); throw new UsernameAlreadyExistException(user.getUsername());
// 用户信息一般性规范检查
if(user.getUserAuth().getUserAnswer().length() > 255
|| user.getUserAuth().getUserQuestion().length() > 255
|| user.getUserAuth().getStudentID().length() > 24
|| user.getUserAuth().getMail().length() > 64
|| user.getUserDetail().getRealName().length() > 12)
throw new UserInformationIllegalException(user.getUsername());
// 强制以哈希值(sha256)保存密码
user.setPassword(passwordEncoder.encode(user.getPassword())); user.setPassword(passwordEncoder.encode(user.getPassword()));
return userRepository.save(user); return userRepository.save(user);
} }
@Override @Override
public User update(User user) { public User update(User user) {
if(!userRepository.findByUsername(user.getUsername()).isPresent()) // 执行前检查
throw new RuntimeException("Username Already Exists"); if(!userRepository.findById(user.getId()).isPresent())
throw new UserNotFoundException(user.getId(), user.getUsername());
return userRepository.save(user); return userRepository.save(user);
} }
@Override
public void delete(User user) {
// 执行前检查
if(!userRepository.findById(user.getId()).isPresent())
throw new UserNotFoundException(user.getId(), user.getUsername());
userRepository.delete(user);
}
// 获得一个默认初始化的用户对象 // 获得一个默认初始化的用户对象
@Override @Override
public User getDefaultUser() { public User getDefaultUser() {
return new User(); return new User();
} }
} }

View File

@ -0,0 +1,45 @@
package com.codesdream.ase.test;
import com.codesdream.ase.component.ASESpringUtil;
import com.codesdream.ase.component.datamanager.DataModelRepositorySearcher;
import com.codesdream.ase.component.datamanager.DataModelSearcher;
import com.codesdream.ase.repository.permission.UserRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DataManagerTest {
@Resource
ASESpringUtil springUtil;
@Test
public void dataModelSearcherTest() {
DataModelSearcher dataModelSearcher = springUtil.getBean(DataModelSearcher.class);
dataModelSearcher.getDataModelClass("permission", "Tag");
Assert.assertTrue(dataModelSearcher.isPresent());
for(String param : dataModelSearcher.getDataModelParamArgs()){
System.out.println(param);
}
}
@Test
public void dataModelRepositorySearcherTest(){
DataModelRepositorySearcher dataModelRepositorySearcher =
springUtil.getBean(DataModelRepositorySearcher.class);
dataModelRepositorySearcher.getDataModelRepositoryClass("permission", "User");
Assert.assertTrue(dataModelRepositorySearcher.isPresent());
UserRepository userRepository = dataModelRepositorySearcher.getDataModelRepositoryInstance();
}
}

View File

@ -1,75 +1,71 @@
package com.codesdream.ase.test; package com.codesdream.ase.test;
import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.repository.UserRepository;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import com.codesdream.ase.service.UserService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import javafx.util.Pair;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap; import javax.annotation.Resource;
import java.util.HashSet;
/** /**
* 用户基本表单元测试 * 用户基本表单元测试
* 用于测试数据库与DAO层交互是否通畅 * 用于测试数据库与DAO层交互是否通畅
*/ */
@DataJpaTest
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest
public class UserTest { public class UserTest {
@Autowired @Resource
private TestEntityManager entityManager; private UserService userService;
@Autowired
private UserRepository userRepository;
/** /**
* 基本存储与查询测试 * 基本存储与查询测试
*/ */
@Test @Test
public void UserBaseTest_1(){ public void UserBaseTest_1(){
User user = new User("Tim", "123456"); // 查找数据库中是否有重复项
userRepository.save(user); Pair<Boolean, User> checker = userService.checkIfUserExists("Tim");
assertTrue(userRepository.findByUsername("Tim").isPresent()); if(checker.getKey()){
assertFalse(userRepository.findByUsername("Tom").isPresent()); userService.delete(checker.getValue());
user = userRepository.findByUsername("Tim").get(); }
User user = userService.getDefaultUser();
user.setUsername("Tim");
user.setPassword("123456");
user.getUserAuth().setStudentID("2018303026");
user.getUserAuth().setMail("937447984@qq.com");
user.getUserAuth().setUserQuestion("Your favourite animal?");
user.getUserAuth().setUserAnswer("Cat");
user.getUserDetail().setAtSchool(true);
userService.save(user);
user = userService.findUserByUsername("Tim");
assertEquals(user.getUsername(), "Tim"); assertEquals(user.getUsername(), "Tim");
assertEquals(user.getPassword(), "123456"); assertEquals(user.getPassword(),
"8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92");
// 检查账号状态
assertTrue(user.isEnabled()); assertTrue(user.isEnabled());
assertFalse(user.isDeleted()); assertFalse(user.isDeleted());
assertTrue(user.isAccountNonExpired());
assertTrue(user.isAccountNonLocked());
assertTrue(user.isCredentialsNonExpired());
assertEquals(user.getUserAuth().getStudentID(), "2018303026");
assertEquals(user.getUserAuth().getMail(), "937447984@qq.com");
assertEquals(user.getUserAuth().getUserQuestion(), "Your favourite animal?");
assertEquals(user.getUserAuth().getUserAnswer(), "Cat");
} }
@Test @Test
public void UserBaseTest_2(){ public void UserBaseTest_2(){
// 用户 User user = userService.findUserByUsername("Tim");
User user = new User("Pat", "123456");
// 标签
Tag tag = new Tag("学生","普通学生");
// 功能性权限容器
FunctionalPermissionContainer functionalPermissionContainer =
new FunctionalPermissionContainer("基本用户权限", "基本的用户权限");
// 添加为标签功能性权限容器
HashSet<FunctionalPermissionContainer> functionalPermissionContainers = new HashSet<>();
functionalPermissionContainers.add(functionalPermissionContainer);
// 等待添加
// 为用户添加标签
HashSet<Tag> tags = new HashSet<>();
tags.add(tag);
user.setTags(tags);
userRepository.save(user);

View File

@ -8,11 +8,89 @@
</head> </head>
<body> <body>
<div class="logo-header" data-background-color="blue" style="width:100%">
<h1><font color="#FFFFFF">Error</font></h1> <div class="wrapper">
<div class="main-header">
<nav class="navbar navbar-header navbar-expand-lg" data-background-color="blue2">
<div class="container-fluid">
<h1 style="color: white">Error Occurred</h1>
</div>
</nav>
</div>
<div class="main-panel">
<div class="content">
<div class="page-inner">
<div class="page-header">
<h4 class="page-title"><div class="fa fa-surprise"></div>&nbsp; 异常被抛出 (Exception Thrown)</h4>
</div>
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h4 class="card-title"><div class="fa fa-cogs"></div> &nbsp; 概要信息</h4>
</div>
<div class="card-body">
<div class="card-sub">
此次异常的简要信息已被异常管理子系统收集并概括如下表
</div>
<table class="table table-bordered table-head-bg-info table-bordered-bd-info mt-8">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">信息项</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr>
<td>0 </td>
<td>HTTP状态</td>
<td class="text-primary" th:text="${http_status}"></td>
</tr>
<tr>
<td>1</td>
<td>异常类型</td>
<td class="text-primary" th:text="${exception_name}"></td>
</tr>
<tr>
<td>2</td>
<td>附带消息</td>
<td class="text-primary" th:text="${exception_message}"></td>
</tr>
<tr>
<td>2</td>
<td>附带消息</td>
<td class="text-primary" th:text="${#dates.format(exception_date, 'yyyy-MM-dd HH:mm:ss')}"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="card">
<div class="card-header">
<h1 class="card-title"><div class="fa fa-bug"></div> &nbsp; 运行栈相关信息</h1>
</div>
<div class="card-body">
<ol class="activity-feed">
<li class="feed-item" th:each="line : ${error_stack}">
<span class="text" th:text="${line}"></span>
</li>
</ol>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -8,10 +8,23 @@
</head> </head>
<body> <body>
<div class="logo-header" data-background-color="blue" style="width:100%"> <div class="wrapper">
<h1><font color="#FFFFFF">404 Not Found</font></h1> <div class="main-header">
<nav class="navbar navbar-header navbar-expand-lg" data-background-color="blue2">
<div class="container-fluid">
<h1 style="color: white">Page Not Found</h1>
</div>
</nav>
</div> </div>
<div class="main-panel">
<div class="content">
<div class="col-md-8">
<div class="card"><img th:src="@{/assets/img/404.jpg}" /></div>
</div>
</div>
</div>
</div>
</body> </body>

View File

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>