This commit is contained in:
yourtree 2020-02-19 14:34:39 +08:00
commit 0a975dd82a
28 changed files with 849 additions and 59 deletions

View File

@ -0,0 +1,84 @@
package com.codesdream.ase.component.datamanager;
import com.codesdream.ase.exception.DataFileNotFoundException;
import com.codesdream.ase.exception.DataIOException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
/**
* 利用数据生成Excel文件
*/
public class DataExcelGenerator implements DataGenerator {
Workbook workbook = new XSSFWorkbook();
Sheet sheet;
Integer colNumber;
String path;
public DataExcelGenerator(String path) {
sheet = workbook.createSheet("Data");
this.path = path;
}
public void setTableTitle(Collection<String> titles){
Row sheetRow = sheet.createRow(0);
int idx = 0;
for(String title : titles){
sheetRow.createCell(idx).setCellValue(title);
idx++;
}
colNumber = titles.size();
}
public void insertRow(int rowIndex, Collection<String> dataCollection){
Row row = sheet.createRow(rowIndex);
int idx = 0;
for(String data : dataCollection){
// 限制表头与表体的数据数目
if(idx >= colNumber) break;
row.createCell(idx).setCellValue(data);
idx++;
}
}
public void insertRow(Collection<String> dataCollection){
insertRow(sheet.getLastRowNum() + 1, dataCollection);
}
public void insertRowDataALL(Collection<String> dataCollections){
int cellIdx = 0;
Collection<String> dataCollection = new ArrayList<>();
for(String dataCollectionItem :dataCollections){
dataCollection.add(dataCollectionItem);
cellIdx++;
if(cellIdx % colNumber == 0) {
insertRow(dataCollection);
dataCollection.clear();
cellIdx = 0;
}
}
}
public void save() {
try {
FileOutputStream stream = new FileOutputStream(path, false);
workbook.write(stream);
stream.close();
} catch (FileNotFoundException e) {
throw new DataFileNotFoundException(path);
} catch (IOException e) {
throw new DataIOException();
}
}
}

View File

@ -0,0 +1,119 @@
package com.codesdream.ase.component.datamanager;
import com.codesdream.ase.exception.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
/**
* 读取简单表格式的Excel文件
*/
public class DataExcelReader implements DataReader {
Workbook workbook = null;
Sheet sheet = null;
short colNumber = 0;
int rowNumberNow = 0;
String path;
boolean hasReadFile = false;
public DataExcelReader(String path){
this.path = path;
readFile();
}
public void readFile(){
if(hasReadFile) return;
try{
FileInputStream fileInputStream = new FileInputStream(path);
workbook = WorkbookFactory.create(fileInputStream);
sheet = workbook.getSheetAt(0);
fileInputStream.close();
} catch (FileNotFoundException e) {
throw new DataFileNotFoundException(path);
} catch (InvalidFormatException e) {
throw new DataInvalidFormatException(e);
} catch (IOException e) {
throw new DataIOException();
}
}
public Collection<String> readColsTitle(){
Row titleRow = sheet.getRow(0);
colNumber = titleRow.getLastCellNum();
// 表头项目个数不可为0
if(colNumber == 0) throw new DataIllegalTableFormatException();
Collection<String> title = new ArrayList<>();
for(int cellIdx = 0; cellIdx < colNumber; cellIdx++){
title.add(readCell(titleRow.getCell(cellIdx)));
}
return title;
}
public Collection<String> readRow(int idx){
// 检查是否获取表头数据
if(this.colNumber == 0) readColsTitle();
if(idx > getRowsSize()) throw new DataReaderRowIndexOutOfRangeException();
this.rowNumberNow = idx;
Collection<String> data = new ArrayList<>();
Row dataRow = sheet.getRow(rowNumberNow);
// 检查列数是否合适
if(dataRow.getLastCellNum() > colNumber) throw new DataIllegalTableFormatException();
for(int cellIdx = 0; cellIdx < colNumber; cellIdx++){
data.add(readCell(dataRow.getCell(cellIdx)));
}
return data;
}
@Override
public int getRowsSize() {
return lastDataRowIndex() - firstDataRowIndex();
}
@Override
public int firstDataRowIndex() {
return 1;
}
@Override
public int lastDataRowIndex() {
return sheet.getLastRowNum();
}
public Collection<String> readRow(){
if(rowNumberNow >= getRowsSize()) return null;
return readRow(rowNumberNow + 1);
}
private String readCell(Cell cell){
String cellValue = "";
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
cellValue = cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
cellValue = cell.getDateCellValue().toString();
} else {
cellValue = String.valueOf(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
cellValue = String.valueOf(cell.getCellFormula());
break;
case Cell.CELL_TYPE_BLANK:
break;
default:
}
return cellValue;
}
}

View File

@ -0,0 +1,17 @@
package com.codesdream.ase.component.datamanager;
import java.util.Collection;
/**
* 表给狗数据文件生成器接口
*/
public interface DataGenerator {
// 读取表头信息
void setTableTitle(Collection<String> titles);
// 向表中写入一行数据
void insertRow(int rowIndex, Collection<String> dataCollection);
// 将修改保存表到文件中
void save();
}

View File

@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* DataModel对应Repository层查询器
* Model对应Repository层查询器
*/
@Data
@Component
@ -43,7 +43,6 @@ public class DataModelRepositorySearcher {
return null;
}
public static String doCheckName(String string) {
char[] charArray = string.toCharArray();
if(Character.isLowerCase(charArray[0])) charArray[0] -= 32;

View File

@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.Collection;
/**
* 根据子系统及名称查找特定的Data Model
* 根据子系统及名称查找特定的MModel
*/
@Data
@Component

View File

@ -0,0 +1,27 @@
package com.codesdream.ase.component.datamanager;
import java.util.Collection;
/**
* 表结构信息读取器接口
*/
public interface DataReader {
// 从文件中读取数据(在使用上要求这个调用可有可无)
void readFile();
// 获得表头列的数目
Collection<String> readColsTitle();
// 读取特定序号的行的数据
Collection<String> readRow(int row);
// 得到数据的总行数
int getRowsSize();
// 得到第一数据行的序号
int firstDataRowIndex();
// 得到最后一行数据行的序号
int lastDataRowIndex();
}

View File

@ -0,0 +1,61 @@
package com.codesdream.ase.component.datamanager;
import com.codesdream.ase.exception.DataIllegalTableFormatException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
// 描述一张数据表
@Component
@Scope("prototype")
public class DataTable {
Collection<String> titleCollection = new ArrayList<>();
Vector<DataTableRow> dataRows = new Vector<>();
// 为表添加列及列名
public DataTable addColTitle(String title){
titleCollection.add(title);
return this;
}
// 获得特定行的数据
public Collection<String> getRow(int index){
return dataRows.elementAt(index).getRow();
}
// 从DataReader导入特定表
public void ImportTable(DataReader reader){
// 从文件中读取数据
reader.readFile();
// 读取列信息
titleCollection = reader.readColsTitle();
int rowsSize = reader.getRowsSize();
int index = 0;
for(int i = reader.firstDataRowIndex(); i < reader.lastDataRowIndex(); i++){
dataRows.add(new DataTableRow(index++, reader.readRow(i)));
// 检查是否列数一致
if(dataRows.lastElement().getColsSize() != this.getColsSize()) {
// 清空表数据
this.dataRows.clear();
throw new DataIllegalTableFormatException();
}
}
}
// 为表添加行
public void addRow(Collection<String> row){
dataRows.add(new DataTableRow(dataRows.size() + 1, row));
}
// 获得表的列数
public int getColsSize(){
return titleCollection.size();
}
// 获得表的行数
public int getRowsSize(){
return dataRows.size();
}
}

View File

@ -0,0 +1,21 @@
package com.codesdream.ase.component.datamanager;
import lombok.Data;
import java.util.Collection;
// 描述数据表的行
@Data
public class DataTableRow {
int index;
Collection<String> row;
public DataTableRow(int index, Collection<String> row){
this.index = index;
this.row = row;
}
public int getColsSize(){
return row.size();
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,15 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class DataFileNotFoundException extends RuntimeException {
private String path;
public DataFileNotFoundException(String filePath){
super();
this.path = filePath;
}
}

View File

@ -0,0 +1,9 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class DataIOException extends RuntimeException {
}

View File

@ -0,0 +1,9 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class DataIllegalTableFormatException extends RuntimeException {
}

View File

@ -0,0 +1,15 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class DataInvalidFormatException extends RuntimeException {
String information;
public DataInvalidFormatException(Exception e){
super();
information = e.getMessage();
}
}

View File

@ -0,0 +1,9 @@
package com.codesdream.ase.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class DataReaderRowIndexOutOfRangeException extends RuntimeException {
}

View File

@ -16,27 +16,27 @@ public class BaseStudentInfo {
@GeneratedValue(strategy = GenerationType.AUTO)
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)
private BaseEthnic ethnic;
private BaseEthnic ethnic = null;
// 学院
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseCollege college;
private BaseCollege college = null;
// 专业
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseMajor major;
private BaseMajor major = null;
// 政治面貌
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BasePoliticalStatus politicalStatus;
private BasePoliticalStatus politicalStatus = null;
// 省份地区
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseAdministrativeDivision administrativeDivision;
private BaseAdministrativeDivision administrativeDivision = null;
}

View File

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

View File

@ -1,5 +1,46 @@
package com.codesdream.ase.service;
import com.codesdream.ase.model.information.*;
public interface IBaseInformationService {
// 检查行政区域是否合法
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);
}

View File

@ -31,6 +31,9 @@ public interface IUserService {
// 根据学号生成随机用户名
void generateRandomUsernameByStudentID(User user, String id);
// 随机生成一个用户名
void generateRandomUsername(User user);
// 注册用户
User save(User user);

View File

@ -17,6 +17,7 @@ import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Service
public class UserService implements IUserService {
@ -72,6 +73,11 @@ public class UserService implements IUserService {
user.setUsername(usernameEncoder.encode(id));
}
@Override
public void generateRandomUsername(User user) {
user.setUsername(usernameEncoder.encode(UUID.randomUUID().toString()));
}
@Override
public User save(User user) {
// 查找用户名是否已经被注册
@ -83,7 +89,7 @@ public class UserService implements IUserService {
|| user.getUserAuth().getUserQuestion().length() > 255
|| user.getUserAuth().getStudentID().length() > 24
|| user.getUserAuth().getMail().length() > 64
|| user.getUserDetail().getRealName().length() > 12)
|| user.getUserDetail().getRealName().length() > 64)
throw new UserInformationIllegalException(user.getUsername());
// 强制以哈希值(sha256)保存密码

View File

@ -1,45 +0,0 @@
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

@ -0,0 +1,14 @@
INSERT INTO `base_political_status`(`id`, `name`) VALUES (0, '----');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (1, '中共党员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (2, '中共预备党员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (3, '共青团员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (4, '民革会员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (5, '民盟盟员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (6, '民建会员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (7, '民进会员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (8, '农工党党员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (9, '致公党党员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (10, '九三学社社员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (11, '台盟盟员');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (12, '无党派民主人士');
INSERT INTO `base_political_status`(`id`, `name`) VALUES (13, '群众');

View File

@ -0,0 +1,25 @@
-- ----------------------------
-- Records of base_college
-- ----------------------------
INSERT INTO `base_college` VALUES ('01', '航空学院', '1');
INSERT INTO `base_college` VALUES ('02', '航天学院', '2');
INSERT INTO `base_college` VALUES ('03', '航海学院', '3');
INSERT INTO `base_college` VALUES ('04', '材料学院', '4');
INSERT INTO `base_college` VALUES ('05', '机电学院', '5');
INSERT INTO `base_college` VALUES ('06', '力学与土木建筑学院', '6');
INSERT INTO `base_college` VALUES ('07', '动力与能源学院', '7');
INSERT INTO `base_college` VALUES ('08', '电子信息学院', '8');
INSERT INTO `base_college` VALUES ('09', '自动化学院', '9');
INSERT INTO `base_college` VALUES ('10', '计算机学院', '10');
INSERT INTO `base_college` VALUES ('11', '理学院', '11');
INSERT INTO `base_college` VALUES ('12', '管理学院', '12');
INSERT INTO `base_college` VALUES ('13', '人文与经法学院', '13');
INSERT INTO `base_college` VALUES ('14', '软件学院学院', '14');
INSERT INTO `base_college` VALUES ('15', '生命学院', '15');
INSERT INTO `base_college` VALUES ('16', '外国语学院', '16');
INSERT INTO `base_college` VALUES ('17', '教育实验学院', '17');
INSERT INTO `base_college` VALUES ('18', '西北工业大学伦敦玛丽女王大学工程学院', '18');
INSERT INTO `base_college` VALUES ('19', '马克思主义学院', '19');
INSERT INTO `base_college` VALUES ('20', '微电子学院', '20');
INSERT INTO `base_college` VALUES ('21', '网络空间安全学院', '21');
INSERT INTO `base_college` VALUES ('22', '民航学院', '22');

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>

View File

@ -0,0 +1,108 @@
package com.codesdream.ase;
import com.codesdream.ase.component.ASESpringUtil;
import com.codesdream.ase.component.datamanager.DataExcelGenerator;
import com.codesdream.ase.component.datamanager.DataExcelReader;
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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* 测试DataModel相关查找器
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class DataManagerTest {
@Resource
ASESpringUtil springUtil;
// Model 查找器测试
@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);
}
}
// Repository 查找器测试
@Test
public void dataModelRepositorySearcherTest(){
DataModelRepositorySearcher dataModelRepositorySearcher =
springUtil.getBean(DataModelRepositorySearcher.class);
dataModelRepositorySearcher.getDataModelRepositoryClass("permission", "User");
Assert.assertTrue(dataModelRepositorySearcher.isPresent());
UserRepository userRepository = dataModelRepositorySearcher.getDataModelRepositoryInstance();
}
// 测试Excel导出功能
@Test
public void dataExcelGeneratorTest(){
DataExcelGenerator dataExcelGenerator = new DataExcelGenerator("DataExcelGeneratorTest.xlsx");
// 设置表头信息
Collection<String> titles = new ArrayList<>();
titles.add("Name");
titles.add("Sex");
titles.add("Age");
dataExcelGenerator.setTableTitle(titles);
Collection<String> dataCollection = new ArrayList<>();
dataCollection.add("Tom");
dataCollection.add("M");
dataCollection.add("18");
dataExcelGenerator.insertRow(1, dataCollection);
dataExcelGenerator.insertRow(dataCollection);
dataCollection.add("Tom");
dataCollection.add("M");
dataCollection.add("18");
dataExcelGenerator.insertRowDataALL(dataCollection);
// 保存数据
dataExcelGenerator.save();
}
// 测试Excel导入功能
@Test
public void dataExcelReaderTest(){
DataExcelReader dataExcelReader = new DataExcelReader("DataExcelGeneratorTest.xlsx");
// 从文件中读取数据
dataExcelReader.readFile();
// 读取表头信息
Collection<String> title = dataExcelReader.readColsTitle();
// 读一行取数据
Collection<String> data = dataExcelReader.readRow();
Iterator<String> iterator = title.iterator();
Assert.assertEquals(iterator.next(), "Name");
Assert.assertEquals(iterator.next(), "Sex");
Assert.assertEquals(iterator.next(), "Age");
iterator = data.iterator();
Assert.assertEquals(iterator.next(), "Tom");
Assert.assertEquals(iterator.next(), "M");
Assert.assertEquals(iterator.next(), "18");
}
}

View File

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