|
|
|
@ -24,7 +24,8 @@ import com.ibeetl.admin.core.util.TimeTool;
|
|
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
|
|
import com.ibeetl.jlw.dao.SchoolClassDao;
|
|
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.entity.dto.StudentBatchImportDTO;
|
|
|
|
|
import com.ibeetl.jlw.entity.dto.StudentBatchImportAdminDTO;
|
|
|
|
|
import com.ibeetl.jlw.entity.dto.StudentBatchImportUniAdminDTO;
|
|
|
|
|
import com.ibeetl.jlw.entity.vo.StudentLogAnalysisVO;
|
|
|
|
|
import com.ibeetl.jlw.entity.vo.StudentLoginLogVO;
|
|
|
|
|
import com.ibeetl.jlw.entity.vo.StudentUseLogVO;
|
|
|
|
@ -39,7 +40,6 @@ import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
|
import org.beetl.sql.core.query.LambdaQuery;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
@ -67,8 +67,7 @@ import static cn.jlw.util.excel.ExcelUtil.standardName;
|
|
|
|
|
import static com.ibeetl.admin.console.service.OrgConsoleService.setObjectOrgId;
|
|
|
|
|
import static com.ibeetl.admin.core.util.ExcelUtil.convertData;
|
|
|
|
|
import static com.ibeetl.admin.core.util.ExcelUtil.write;
|
|
|
|
|
import static com.ibeetl.admin.core.util.StreamUtils.listJoin;
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
|
|
|
|
|
import static com.ibeetl.admin.core.util.excelGroupValidation.ExcelUtil.createExcel;
|
|
|
|
|
import static com.ibeetl.admin.core.web.JsonReturnCode.DIY_ERROR;
|
|
|
|
|
import static com.ibeetl.jlw.web.IpAddressController.ipAddressMap;
|
|
|
|
|
import static java.util.function.UnaryOperator.identity;
|
|
|
|
@ -136,6 +135,8 @@ public class StudentController extends BaseController{
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
FileService fileService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UniversityFacultyService universityFacultyService;
|
|
|
|
|
|
|
|
|
|
/* 前端接口 */
|
|
|
|
|
|
|
|
|
@ -2786,16 +2787,22 @@ public class StudentController extends BaseController{
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@GetMapping({ API + "/exportBatchTemplate.do", MODEL + "/downloadTemplate.json" })
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public void exportBatchTemplate() {
|
|
|
|
|
|
|
|
|
|
Assert.notNull(getUser(), "请登录后再操作");
|
|
|
|
|
public void exportBatchTemplate(@SCoreUser CoreUser coreUser) {
|
|
|
|
|
|
|
|
|
|
String filename = StrUtil.format("批量学生导入模板{}.xlsx", System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
setExcelResponse(filename);
|
|
|
|
|
// 输出 Excel
|
|
|
|
|
com.ibeetl.admin.core.util.excelGroupValidation.ExcelUtil.createExcel(Arrays.asList(new StudentBatchImportDTO()), response.getOutputStream());
|
|
|
|
|
|
|
|
|
|
if (coreUser.isAdmin()) {
|
|
|
|
|
// 输出 Excel
|
|
|
|
|
createExcel(Arrays.asList(new StudentBatchImportAdminDTO()), response.getOutputStream());
|
|
|
|
|
}
|
|
|
|
|
else if(coreUser.isUniAdmin()) {
|
|
|
|
|
// 输出 Excel
|
|
|
|
|
createExcel(Arrays.asList(new StudentBatchImportUniAdminDTO()), response.getOutputStream());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new RuntimeException("该接口仅支持超管和管理员操作!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -2803,62 +2810,72 @@ public class StudentController extends BaseController{
|
|
|
|
|
* 〈导入批量模板数据〉
|
|
|
|
|
* 批量导入题目 excel版本,只支持单选多选,对错吧
|
|
|
|
|
* @param file
|
|
|
|
|
* @param coreUser 一般这个接口都是学校管理员操作的,所以直接取这个里面的机构ID就代表这个学校的机构ID
|
|
|
|
|
* @return {@link JsonResult}
|
|
|
|
|
* @Author: 87966
|
|
|
|
|
* @Date: 2022/11/28 10:04
|
|
|
|
|
*/
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@PostMapping({MODEL + "/importTemplate.json", API + "/importBatchTemplate.do"})
|
|
|
|
|
@PostMapping({MODEL + "/uniAdminImportBatchTemplate.json", API + "/uniAdminImportBatchTemplate.do"})
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
public JsonResult uniAdminImportBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
Assert.isNull(getStudent(), "学生无法访问该接口");
|
|
|
|
|
|
|
|
|
|
// 输出 Excel, 有判断空值的操作
|
|
|
|
|
MyValidateExcelCellDataListener<StudentBatchImportDTO> listener = new MyValidateExcelCellDataListener<>();
|
|
|
|
|
MyValidateExcelCellDataListener<StudentBatchImportUniAdminDTO> listener = new MyValidateExcelCellDataListener<>();
|
|
|
|
|
|
|
|
|
|
ExcelUtil.readExcelNotContainHeader(file, StudentBatchImportDTO.class, listener);
|
|
|
|
|
ExcelUtil.readExcelNotContainHeader(file, StudentBatchImportUniAdminDTO.class, listener);
|
|
|
|
|
// 判断错误的结果集
|
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
|
|
|
|
|
// 类型转换
|
|
|
|
|
List<Student> list = listener.getData().stream().map(item -> {
|
|
|
|
|
// 存的是班级名称,只是叫做classId而已
|
|
|
|
|
String classId = item.getClassId();
|
|
|
|
|
|
|
|
|
|
return StudentBatchImportDTO.pojo(item, importClassIdAsString -> {
|
|
|
|
|
SchoolClass params = new SchoolClass();
|
|
|
|
|
params.setClassName(classId);
|
|
|
|
|
params.setClassStatus(1);
|
|
|
|
|
params.setOrgId(coreUser.getOrgId());
|
|
|
|
|
LambdaQuery<SchoolClass> schoolClassLambdaQuery = schoolClassDao.createLambdaQuery()
|
|
|
|
|
.andEq(SchoolClass::getClassStatus, 1);
|
|
|
|
|
|
|
|
|
|
// 超管不用传机构ID
|
|
|
|
|
if (!coreUser.isAdmin()) {
|
|
|
|
|
schoolClassLambdaQuery.andEq(SchoolClass::getOrgId, coreUser.getOrgId());
|
|
|
|
|
}
|
|
|
|
|
List<SchoolClass> classList = schoolClassLambdaQuery
|
|
|
|
|
.andLike(SchoolClass::getClassName, "%"+classId+"%")
|
|
|
|
|
.select();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
consumerPutErrorMessage(classList, (cl) -> {
|
|
|
|
|
List<SchoolClass> tempList = (List<SchoolClass>) cl;
|
|
|
|
|
Assert.isTrue(CollectionUtil.isNotEmpty(classList),
|
|
|
|
|
"班级名称:【{}】未模糊匹配到任何班级!", classId);
|
|
|
|
|
|
|
|
|
|
// 模糊搜索到重复的班级名称
|
|
|
|
|
String repetitiveClassNames = listJoin(classList, SchoolClass::getClassName);
|
|
|
|
|
Assert.isFalse(tempList.size() > 1,
|
|
|
|
|
"提交的班级名称{},查询到多个【{}】,请修改后再来尝试!", classId, repetitiveClassNames);
|
|
|
|
|
}, listener);
|
|
|
|
|
|
|
|
|
|
if (classList.size() == 1) {
|
|
|
|
|
return classList.get(0).getClassId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的院系
|
|
|
|
|
UniversityFaculty universityFaculty = universityFacultyService.getByNameOrCreate(
|
|
|
|
|
item.getUniversityFacultyName(), coreUser.getOrgId(), coreUser.getId());
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的专业
|
|
|
|
|
UniversitySystem universitySystem = universitySystemService.getByNameOrCreate(
|
|
|
|
|
item.getUniversitySystemName(), coreUser.getOrgId(), coreUser.getId(), universityFaculty.getUniversityFacultyId());
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的专业
|
|
|
|
|
SchoolClass schoolClass = schoolClassService.getByNameOrCreate(item.getClassId(),
|
|
|
|
|
coreUser.getOrgId(), coreUser.getId(), universityFaculty.getUniversityFacultyId(),
|
|
|
|
|
universitySystem.getUniversitySystemId());
|
|
|
|
|
|
|
|
|
|
return StudentBatchImportUniAdminDTO.pojo(item, importClassIdAsString -> {
|
|
|
|
|
return schoolClass.getClassId();
|
|
|
|
|
// LambdaQuery<SchoolClass> schoolClassLambdaQuery = schoolClassDao.createLambdaQuery()
|
|
|
|
|
// .andEq(SchoolClass::getClassStatus, 1);
|
|
|
|
|
//
|
|
|
|
|
// // 超管不用传机构ID
|
|
|
|
|
// if (!coreUser.isAdmin()) {
|
|
|
|
|
// schoolClassLambdaQuery.andEq(SchoolClass::getOrgId, coreUser.getOrgId());
|
|
|
|
|
// }
|
|
|
|
|
// List<SchoolClass> classList = schoolClassLambdaQuery
|
|
|
|
|
// .andLike(SchoolClass::getClassName, "%"+classId+"%")
|
|
|
|
|
// .select();
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// consumerPutErrorMessage(classList, (cl) -> {
|
|
|
|
|
// List<SchoolClass> tempList = (List<SchoolClass>) cl;
|
|
|
|
|
// Assert.isTrue(CollectionUtil.isNotEmpty(classList),
|
|
|
|
|
// "班级名称:【{}】未模糊匹配到任何班级!", classId);
|
|
|
|
|
//
|
|
|
|
|
// // 模糊搜索到重复的班级名称
|
|
|
|
|
// String repetitiveClassNames = listJoin(classList, SchoolClass::getClassName);
|
|
|
|
|
// Assert.isFalse(tempList.size() > 1,
|
|
|
|
|
// "提交的班级名称{},查询到多个【{}】,请修改后再来尝试!", classId, repetitiveClassNames);
|
|
|
|
|
// }, listener);
|
|
|
|
|
//
|
|
|
|
|
// if (classList.size() == 1) {
|
|
|
|
|
// return classList.get(0).getClassId();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return null;
|
|
|
|
|
}, identity());
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
@ -2892,6 +2909,83 @@ public class StudentController extends BaseController{
|
|
|
|
|
|
|
|
|
|
return JsonResult.successMessage("导入成功!");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 功能描述: <br>
|
|
|
|
|
* 〈导入批量模板数据〉
|
|
|
|
|
* 批量导入题目 excel版本,只支持单选多选,对错吧
|
|
|
|
|
* @param file
|
|
|
|
|
* @param coreUser 一般这个接口都是学校管理员操作的,所以直接取这个里面的机构ID就代表这个学校的机构ID
|
|
|
|
|
* @return {@link JsonResult}
|
|
|
|
|
* @Author: 87966
|
|
|
|
|
* @Date: 2022/11/28 10:04
|
|
|
|
|
*/
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@PostMapping({MODEL + "/adminImportTemplate.json", API + "/adminImportBatchTemplate.do"})
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public JsonResult adminImportBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
Assert.isNull(getStudent(), "学生无法访问该接口");
|
|
|
|
|
|
|
|
|
|
// 输出 Excel, 有判断空值的操作
|
|
|
|
|
MyValidateExcelCellDataListener<StudentBatchImportAdminDTO> listener = new MyValidateExcelCellDataListener<>();
|
|
|
|
|
|
|
|
|
|
ExcelUtil.readExcelNotContainHeader(file, StudentBatchImportAdminDTO.class, listener);
|
|
|
|
|
// 判断错误的结果集
|
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
|
|
|
|
|
// 类型转换
|
|
|
|
|
List<Student> list = listener.getData().stream().map(item -> {
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的院系
|
|
|
|
|
UniversitiesColleges universitiesColleges = universitiesCollegesService.getByNameOrCreate(item.getUniversitiesCollegesName());
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的院系
|
|
|
|
|
UniversityFaculty universityFaculty = universityFacultyService.getByNameOrCreate(
|
|
|
|
|
item.getUniversityFacultyName(), universitiesColleges.getOrgId(), universitiesColleges.getUserId());
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的专业
|
|
|
|
|
UniversitySystem universitySystem = universitySystemService.getByNameOrCreate(
|
|
|
|
|
item.getUniversitySystemName(), universitiesColleges.getOrgId(), universitiesColleges.getUserId(), universityFaculty.getUniversityFacultyId());
|
|
|
|
|
|
|
|
|
|
// 查询这个院校已经存在的专业
|
|
|
|
|
SchoolClass schoolClass = schoolClassService.getByNameOrCreate(item.getClassId(),
|
|
|
|
|
universitiesColleges.getOrgId(), universitiesColleges.getUserId(), universityFaculty.getUniversityFacultyId(),
|
|
|
|
|
universitySystem.getUniversitySystemId());
|
|
|
|
|
|
|
|
|
|
return StudentBatchImportAdminDTO.pojo(item, importClassIdAsString -> schoolClass.getClassId(), identity());
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 设置机构ID
|
|
|
|
|
try {
|
|
|
|
|
setObjectOrgId(list, (e) -> {
|
|
|
|
|
SchoolClass params = new SchoolClass();
|
|
|
|
|
params.setClassId(e.getClassId());
|
|
|
|
|
params.setClassStatus(1);
|
|
|
|
|
SchoolClass sc = schoolClassDao.templateOne(params);
|
|
|
|
|
if (sc != null) {
|
|
|
|
|
return sc.getOrgId();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, true);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
studentService.validateStudentSnListIsExistsThrow(list, listener);
|
|
|
|
|
// 再次判断错误的结果集
|
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
|
|
|
|
|
|
|
|
|
|
// 导入并添加身份信息
|
|
|
|
|
list.forEach(studentService::add);
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalArgumentException exception) {
|
|
|
|
|
return JsonResult.failMessage(exception.getMessage()).setCode(DIY_ERROR.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonResult.successMessage("导入成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 消费并记录错误信息
|
|
|
|
|