编写基本信息接口及服务;
This commit is contained in:
parent
d64a4aca62
commit
eef59c2eb5
@ -0,0 +1,15 @@
|
|||||||
|
package com.codesdream.ase.exception;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class BaseInformationAlreadyExistException extends RuntimeException {
|
||||||
|
private String className;
|
||||||
|
|
||||||
|
public BaseInformationAlreadyExistException(Class<?> aClass){
|
||||||
|
super();
|
||||||
|
this.className = aClass.getName();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.codesdream.ase.exception;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class BaseInformationIllegalException extends RuntimeException {
|
||||||
|
String type;
|
||||||
|
String value;
|
||||||
|
|
||||||
|
public BaseInformationIllegalException(String type, String value){
|
||||||
|
super();
|
||||||
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.codesdream.ase.exception;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class BaseInformationNotExistException extends RuntimeException {
|
||||||
|
private String className;
|
||||||
|
|
||||||
|
public BaseInformationNotExistException(Class<?> baseInformationClass){
|
||||||
|
super();
|
||||||
|
this.className = baseInformationClass.getName();
|
||||||
|
}
|
||||||
|
}
|
@ -16,27 +16,27 @@ public class BaseStudentInfo {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
// 真实姓名
|
// 真实姓名
|
||||||
private String name;
|
private String name = "";
|
||||||
// 学号
|
// 学号
|
||||||
private String studentId;
|
private String studentId = "";
|
||||||
// 班号
|
// 班号
|
||||||
private String classId;
|
private String classId = "";
|
||||||
// 性别
|
// 性别
|
||||||
private String sex;
|
private String sex = "";
|
||||||
// 民族
|
// 民族
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private BaseEthnic ethnic;
|
private BaseEthnic ethnic = null;
|
||||||
// 学院
|
// 学院
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private BaseCollege college;
|
private BaseCollege college = null;
|
||||||
// 专业
|
// 专业
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private BaseMajor major;
|
private BaseMajor major = null;
|
||||||
// 政治面貌
|
// 政治面貌
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private BasePoliticalStatus politicalStatus;
|
private BasePoliticalStatus politicalStatus = null;
|
||||||
// 省份地区
|
// 省份地区
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private BaseAdministrativeDivision administrativeDivision;
|
private BaseAdministrativeDivision administrativeDivision = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,200 @@
|
|||||||
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
|
import com.codesdream.ase.exception.BaseInformationAlreadyExistException;
|
||||||
|
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 javax.annotation.Resource;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class BaseInformationService implements IBaseInformationService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaseAdministrativeDivisionRepository administrativeDivisionRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaseCandidateCategoryRepository candidateCategoryRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaseCollegeRepository collegeRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaseEthnicRepository ethnicRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaseMajorRepository majorRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BasePoliticalStatusRepository politicalStatusRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaseStudentInfoRepository studentInfoRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkAdministrativeDivision(String name) {
|
||||||
|
Optional<BaseAdministrativeDivision> administrativeDivision =
|
||||||
|
administrativeDivisionRepository.findByName(name);
|
||||||
|
return administrativeDivision.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkCollege(String name) {
|
||||||
|
Optional<BaseCollege> college =
|
||||||
|
collegeRepository.findByName(name);
|
||||||
|
return college.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkEthnic(String name) {
|
||||||
|
Optional<BaseEthnic> ethnic =
|
||||||
|
ethnicRepository.findByName(name);
|
||||||
|
return ethnic.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkMajor(String name) {
|
||||||
|
Optional<BaseMajor> major =
|
||||||
|
majorRepository.findByName(name);
|
||||||
|
return major.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkPoliticalStatus(String name) {
|
||||||
|
Optional<BasePoliticalStatus> politicalStatus =
|
||||||
|
politicalStatusRepository.findByName(name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkCandidateStatus(String name) {
|
||||||
|
Optional<BaseCandidateCategory> candidateCategory =
|
||||||
|
candidateCategoryRepository.findByName(name);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkStudentInfo(String studentId) {
|
||||||
|
Optional<BaseStudentInfo> studentInfo =
|
||||||
|
studentInfoRepository.findByStudentId(studentId);
|
||||||
|
return studentInfo.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseAdministrativeDivision findAdministrativeDivisionByName(String name) {
|
||||||
|
Optional<BaseAdministrativeDivision> administrativeDivision =
|
||||||
|
administrativeDivisionRepository.findByName(name);
|
||||||
|
// 检查
|
||||||
|
if(!administrativeDivision.isPresent())
|
||||||
|
throw new BaseInformationNotExistException(BaseAdministrativeDivision.class);
|
||||||
|
return administrativeDivision.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseCollege findCollegeByName(String name) {
|
||||||
|
Optional<BaseCollege> college =
|
||||||
|
collegeRepository.findByName(name);
|
||||||
|
// 检查
|
||||||
|
if(!college.isPresent()) throw new BaseInformationNotExistException(BaseCollege.class);
|
||||||
|
return college.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseEthnic findEthnicByName(String name) {
|
||||||
|
Optional<BaseEthnic> ethnic =
|
||||||
|
ethnicRepository.findByName(name);
|
||||||
|
if(!ethnic.isPresent()) throw new BaseInformationNotExistException(BaseEthnic.class);
|
||||||
|
return ethnic.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseMajor findMajorByName(String name) {
|
||||||
|
Optional<BaseMajor> major =
|
||||||
|
majorRepository.findByName(name);
|
||||||
|
if(!major.isPresent()) throw new BaseInformationNotExistException(BaseMajor.class);
|
||||||
|
return major.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BasePoliticalStatus findPoliticalStatusByName(String name) {
|
||||||
|
Optional<BasePoliticalStatus> politicalStatus =
|
||||||
|
politicalStatusRepository.findByName(name);
|
||||||
|
if(!politicalStatus.isPresent())
|
||||||
|
throw new BaseInformationNotExistException(BasePoliticalStatus.class);
|
||||||
|
return politicalStatus.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseCandidateCategory findCandidateCategoryByName(String name) {
|
||||||
|
Optional<BaseCandidateCategory> candidateCategory =
|
||||||
|
candidateCategoryRepository.findByName(name);
|
||||||
|
if(!candidateCategory.isPresent())
|
||||||
|
throw new BaseInformationNotExistException(BaseCandidateCategory.class);
|
||||||
|
return candidateCategory.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseStudentInfo findStudentInfoByStudentId(String studentId) {
|
||||||
|
Optional<BaseStudentInfo> studentInfo =
|
||||||
|
studentInfoRepository.findByStudentId(studentId);
|
||||||
|
if(!studentInfo.isPresent())
|
||||||
|
throw new BaseInformationNotExistException(BaseStudentInfo.class);
|
||||||
|
return studentInfo.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseStudentInfo constructStudentInfo(String studentId,
|
||||||
|
String classId,
|
||||||
|
String realName, String sex,
|
||||||
|
String college,
|
||||||
|
String major, String ethnic,
|
||||||
|
String candidateCategory, String politicalStatus,
|
||||||
|
String administrativeDivision)
|
||||||
|
{
|
||||||
|
// 检查
|
||||||
|
if(!sex.equals("男") && !sex.equals("女"))
|
||||||
|
throw new BaseInformationIllegalException("sex", sex);
|
||||||
|
if(classId.length() != 8)
|
||||||
|
throw new BaseInformationIllegalException("classId", classId);
|
||||||
|
if(studentId.length() != 10)
|
||||||
|
throw new BaseInformationIllegalException("studentId",studentId);
|
||||||
|
if(realName.length() > 64)
|
||||||
|
throw new BaseInformationIllegalException("realName",realName);
|
||||||
|
|
||||||
|
BaseStudentInfo studentInfo = new BaseStudentInfo();
|
||||||
|
studentInfo.setSex(sex);
|
||||||
|
studentInfo.setClassId(classId);
|
||||||
|
studentInfo.setName(realName);
|
||||||
|
studentInfo.setStudentId(studentId);
|
||||||
|
studentInfo.setAdministrativeDivision(findAdministrativeDivisionByName(administrativeDivision));
|
||||||
|
studentInfo.setCollege(findCollegeByName(college));
|
||||||
|
studentInfo.setEthnic(findEthnicByName(ethnic));
|
||||||
|
studentInfo.setMajor(findMajorByName(major));
|
||||||
|
studentInfo.setPoliticalStatus(findPoliticalStatusByName(politicalStatus));
|
||||||
|
|
||||||
|
return studentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseStudentInfo save(BaseStudentInfo baseStudentInfo) {
|
||||||
|
if(baseStudentInfo.getAdministrativeDivision() == null
|
||||||
|
|| baseStudentInfo.getCollege() == null
|
||||||
|
|| baseStudentInfo.getEthnic() == null
|
||||||
|
|| baseStudentInfo.getMajor() == null
|
||||||
|
|| baseStudentInfo.getPoliticalStatus() == null
|
||||||
|
|| baseStudentInfo.getClassId().equals("")
|
||||||
|
|| baseStudentInfo.getStudentId().equals("")
|
||||||
|
|| baseStudentInfo.getName().equals(""))
|
||||||
|
throw new BaseInformationIllegalException("studentInfo", "didn't fully initialize");
|
||||||
|
|
||||||
|
// 检查学号重复
|
||||||
|
if(checkStudentInfo(baseStudentInfo.getStudentId()))
|
||||||
|
throw new BaseInformationAlreadyExistException(baseStudentInfo.getClass());
|
||||||
|
|
||||||
|
studentInfoRepository.save(baseStudentInfo);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,46 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.information.*;
|
||||||
|
|
||||||
public interface IBaseInformationService {
|
public interface IBaseInformationService {
|
||||||
|
// 检查行政区域是否合法
|
||||||
boolean checkAdministrativeDivision(String name);
|
boolean checkAdministrativeDivision(String name);
|
||||||
|
|
||||||
|
// 检查学院名称是否合法
|
||||||
|
boolean checkCollege(String name);
|
||||||
|
|
||||||
|
// 检查民族名称是否合法
|
||||||
|
boolean checkEthnic(String name);
|
||||||
|
|
||||||
|
// 检查专业信息是否合法
|
||||||
|
boolean checkMajor(String name);
|
||||||
|
|
||||||
|
// 检查政治面貌信息是否合法
|
||||||
|
boolean checkPoliticalStatus(String name);
|
||||||
|
|
||||||
|
// 检查考生类型是否合法
|
||||||
|
boolean checkCandidateStatus(String name);
|
||||||
|
|
||||||
|
// 检查学生信息是否存在
|
||||||
|
boolean checkStudentInfo(String studentId);
|
||||||
|
|
||||||
|
BaseAdministrativeDivision findAdministrativeDivisionByName(String name);
|
||||||
|
|
||||||
|
BaseCollege findCollegeByName(String name);
|
||||||
|
|
||||||
|
BaseEthnic findEthnicByName(String name);
|
||||||
|
|
||||||
|
BaseMajor findMajorByName(String name);
|
||||||
|
|
||||||
|
BasePoliticalStatus findPoliticalStatusByName(String name);
|
||||||
|
|
||||||
|
BaseCandidateCategory findCandidateCategoryByName(String name);
|
||||||
|
|
||||||
|
BaseStudentInfo findStudentInfoByStudentId(String studentId);
|
||||||
|
|
||||||
|
BaseStudentInfo constructStudentInfo(String studentId,
|
||||||
|
String classId, String realName, String sex, String college, String major, String ethnic, String candidateCategory, String politicalStatus,
|
||||||
|
String administrativeDivision);
|
||||||
|
|
||||||
|
BaseStudentInfo save(BaseStudentInfo baseStudentInfo);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public class UserService implements IUserService {
|
|||||||
|| user.getUserAuth().getUserQuestion().length() > 255
|
|| user.getUserAuth().getUserQuestion().length() > 255
|
||||||
|| user.getUserAuth().getStudentID().length() > 24
|
|| user.getUserAuth().getStudentID().length() > 24
|
||||||
|| user.getUserAuth().getMail().length() > 64
|
|| user.getUserAuth().getMail().length() > 64
|
||||||
|| user.getUserDetail().getRealName().length() > 12)
|
|| user.getUserDetail().getRealName().length() > 64)
|
||||||
throw new UserInformationIllegalException(user.getUsername());
|
throw new UserInformationIllegalException(user.getUsername());
|
||||||
|
|
||||||
// 强制以哈希值(sha256)保存密码
|
// 强制以哈希值(sha256)保存密码
|
||||||
|
@ -12,7 +12,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试DataModel相关查找器
|
||||||
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class DataManagerTest {
|
public class DataManagerTest {
|
||||||
|
0
src/main/resources/data_base_college.sql
Normal file
0
src/main/resources/data_base_college.sql
Normal file
Loading…
Reference in New Issue
Block a user