教师导入, 学生导入修复

beetlsql3-dev
Mlxa0324 2 years ago
parent 9638c61cb6
commit 46e10c958d

@ -36,7 +36,7 @@ public class MyValidateExcelCellDataListener<T> implements ReadListener<T> {
private List<ExcelFailRecord> failMap = new ArrayList<>();
public List<ExcelFailRecord> getFailMessage() {
return Collections.unmodifiableList(failMap);
return failMap;
}
public List<T> getData() {
@ -63,9 +63,24 @@ public class MyValidateExcelCellDataListener<T> implements ReadListener<T> {
int emptyColumnCount = 0;
Field[] fields = ReflectUtil.getFields(bean.getClass());
for (int columnIndex = 0; columnIndex < fields.length; columnIndex++) {
Field field = fields[columnIndex]; field.setAccessible(true);
final Field field = fields[columnIndex]; field.setAccessible(true);
try {
Object fieldValue = field.get(bean);
final Object fieldValue = field.get(bean);
// final String fieldName = field.getName();
// int finalColumnIndex = columnIndex;
// bean.getIndexMap().computeIfAbsent(fieldName, s -> new BaseExcelInfoDTO.BaseExcelIndexDTO() {
// @Override
// public Integer getRowIndex() {
// return rowIndex + 1;
// }
//
// @Override
// public Integer getColIndex() {
// return finalColumnIndex + 1;
// }
// });
ExcelRequireIgnore requireIgnore = field.getDeclaredAnnotation(ExcelRequireIgnore.class);
// 如果有忽略必传的注解,并且没有查询到值则直接跳过必传验证

@ -37,5 +37,5 @@ public interface UniversityFacultyDao extends BaseMapper<UniversityFaculty>{
* GROUP_CONCAT |||
* @return
*/
List<Map<String, String>> getAllUniversitiesCollegesWithFaculty();
List<Map<String, String>> getAllUniversityFacultyWithColleges();
}

@ -5,6 +5,8 @@ import com.ibeetl.admin.core.annotation.Dict;
import com.ibeetl.admin.core.entity.BaseEntity;
import com.ibeetl.admin.core.enums.MenuEnums;
import com.ibeetl.jlw.enums.GenderEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import org.beetl.sql.annotation.entity.AutoID;
import javax.validation.constraints.NotBlank;
@ -18,6 +20,8 @@ import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
*
* gen by Spring Boot2 Admin 2021-06-19
*/
@AllArgsConstructor
@Builder
public class Teacher extends BaseEntity implements AbstractToken {
//ID

@ -0,0 +1,35 @@
package com.ibeetl.jlw.entity.dto;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
/**
* : <br>
*
*
* @author: mlx
* @description:
* @date: 2023/2/14 13:56
* @version: 1.0
*/
@Data
public class BaseExcelInfoDTO {
private Map<String, BaseExcelIndexDTO> indexMap = new HashMap<>();
public interface BaseExcelIndexDTO {
/**
* + 1
* @return
*/
Integer getRowIndex();
/**
* + 1
* @return
*/
Integer getColIndex();
}
}

@ -35,7 +35,7 @@ public class SchoolClassBatchImportDTO {
/**
* ID
*/
@ExcelValidation(datasourceMethod = "com.ibeetl.jlw.service.UniversityFacultyService.getAllUniversitiesCollegesWithFaculty", beforeFieldName = "universitiesCollegesId")
@ExcelValidation(datasourceMethod = "com.ibeetl.jlw.service.UniversityFacultyService.getAllUniversityFacultyWithColleges", beforeFieldName = "universitiesCollegesId")
private String universityFacultyId ;
/**
* ID

@ -0,0 +1,99 @@
package com.ibeetl.jlw.entity.dto;
import com.ibeetl.admin.core.util.excelGroupValidation.ExcelFile;
import com.ibeetl.admin.core.util.excelGroupValidation.ExcelValidation;
import com.ibeetl.jlw.entity.Teacher;
import com.ibeetl.jlw.enums.GenderEnum;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;
import java.util.Date;
import java.util.function.Function;
import static cn.jlw.util.excel.ExcelUtil.longValuesOf;
/**
* : <br>
* ,
*
* @Author: lx
* @Date: 2023/2/5 23:50
*/
@Data
@FieldNameConstants
@ToString
@ExcelFile(fileHeadTemplate = "universitiesCollegesId|universityFacultyId|universitySystemId|teacherName|teacherSn|teacherMobile|teacherEmail",
fileMappingTemplate = "universitiesCollegesId=院校名称|universityFacultyId=院系名称|universitySystemId=专业名称|" +
"teacherName=教师姓名|teacherJobNumber=工号|teacherMobile=电话|teacherEmail=邮箱",
datasheetHidden = true, enableDataValidation = true)
public class TeacherBatchImportDTO {
/**
*
*/
@ExcelValidation(datasourceMethod = "com.ibeetl.jlw.service.UniversitiesCollegesService.getAllUniversitiesColleges")
private String universitiesCollegesId ;
/**
*
*/
@ExcelValidation(datasourceMethod = "com.ibeetl.jlw.service.UniversityFacultyService.getAllUniversityFacultyWithColleges", beforeFieldName = "universitiesCollegesId")
private String universityFacultyId ;
/**
*
*/
@ExcelValidation(datasourceMethod = "com.ibeetl.jlw.service.UniversitySystemService.getAllUniversitiesCollegesWithFaculty", beforeFieldName = "universityFacultyId")
private String universitySystemId ;
/**
*
*/
private String teacherName ;
/**
*
*/
private String teacherJobNumber ;
/**
*
*/
private String teacherMobile ;
/**
*
*/
private String teacherEmail ;
/**
*
*
* @param importPojo
* @param function
* @return
*/
public static Teacher pojo(TeacherBatchImportDTO importPojo, Function<Teacher, Teacher> function) {
Teacher build = Teacher.builder()
.universitiesCollegesId(longValuesOf(importPojo.getUniversitiesCollegesId()))
.universityFacultyId(longValuesOf(importPojo.getUniversityFacultyId()))
.universitySystemId(longValuesOf(importPojo.getUniversitySystemId()))
.teacherJobNumber(importPojo.getTeacherJobNumber())
.teacherStatus(1)
.teacherGender(GenderEnum.UN_KNOW)
.teacherPassword("123qwe")
.addTime(new Date())
.build();
return function.apply(build);
}
/**
*
*
* @param importPojo
* @return
*/
public static Teacher pojo(TeacherBatchImportDTO importPojo) {
return pojo(importPojo, e -> e);
}
}

@ -88,7 +88,7 @@ public class SchoolClassService extends CoreBaseService<SchoolClass>{
List<String> duplicateElements = getDuplicateElements(classSnList);
// 构建异常信息,传给前端
String duplicateElementsAsString = CollectionUtil.emptyIfNull(duplicateElements).stream().collect(Collectors.joining(","));
Assert.isTrue(CollectionUtil.isEmpty(duplicateElements), "本次上传,存在重复的的班级编号:\"{}\",请修改后再进行提交!", duplicateElementsAsString);
Assert.isTrue(CollectionUtil.isEmpty(duplicateElements), "本次上传的文件中,存在重复的的班级编号:\"{}\",请修改后再进行提交!", duplicateElementsAsString);
// 查询库里已经存在的编号
List<String> existsList = schoolClassDao.createLambdaQuery()
.andIsNotNull(SchoolClass::getClassSn)

@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.jlw.util.ToolUtils;
import cn.jlw.util.excel.listener.MyValidateExcelCellDataListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ibeetl.admin.console.service.UserConsoleService;
@ -22,6 +23,7 @@ import com.ibeetl.admin.core.web.JsonReturnCode;
import com.ibeetl.jlw.dao.SchoolClassDao;
import com.ibeetl.jlw.dao.StudentDao;
import com.ibeetl.jlw.entity.*;
import com.ibeetl.jlw.entity.dto.StudentBatchImportDTO;
import com.ibeetl.jlw.entity.vo.StudentLogAnalysisVO;
import com.ibeetl.jlw.entity.vo.StudentLoginLogVO;
import com.ibeetl.jlw.entity.vo.StudentUseLogVO;
@ -961,7 +963,7 @@ public class StudentService extends CoreBaseService<Student>{
}
public void validateStudentSnListIsExistsThrow(List<Student> list) {
public void validateStudentSnListIsExistsThrow(List<Student> list, MyValidateExcelCellDataListener<StudentBatchImportDTO> listener) {
if (CollectionUtil.isEmpty(list)) {
return;
}
@ -969,17 +971,27 @@ public class StudentService extends CoreBaseService<Student>{
List<String> studentSnList = list.stream().map(Student::getStudentSn).collect(Collectors.toList());
// 获取重复的元素
List<String> duplicateElements = getDuplicateElements(studentSnList);
// 构建异常信息,传给前端
String duplicateElementsAsString = CollectionUtil.emptyIfNull(duplicateElements).stream().collect(Collectors.joining(","));
Assert.isTrue(CollectionUtil.isEmpty(duplicateElements), "本次上传,存在重复的的学生编号:\"{}\",请修改后再进行提交!", duplicateElementsAsString);
for (String duplicateElement : duplicateElements) {
int errorRowIndex = studentSnList.indexOf(duplicateElement);
// 这里固定列索引,省事
listener.putFailMessage(
errorRowIndex, 4, StrUtil.format("本次上传的文件中,存在重复的的学生编号:\"{}\"", duplicateElement));
}
// 查询库里已经存在的编号
List<String> existsList = studentDao.createLambdaQuery()
.andIsNotNull(Student::getStudentSn)
.andIn(Student::getStudentSn, studentSnList).select(String.class,"student_sn");
// 如果存在的话,属于异常数据
String errorSns = CollectionUtil.emptyIfNull(existsList).stream().collect(Collectors.joining(","));
// 构建异常信息,传给前端
Assert.isTrue(StrUtil.isBlank(errorSns), "已存在的学生编号:\"{}\",请修改后再进行提交!", errorSns);
for (String duplicateElement : existsList) {
int errorRowIndex = studentSnList.indexOf(duplicateElement);
// 这里固定列索引,省事
listener.putFailMessage(
errorRowIndex, 4, StrUtil.format("已存在的学生编号:\"{}\"", duplicateElement));
}
}
//大赛任务二答卷 线程处理

@ -1,11 +1,14 @@
package com.ibeetl.jlw.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.jlw.util.ToolUtils;
import cn.jlw.util.excel.listener.MyValidateExcelCellDataListener;
import com.ibeetl.admin.console.service.UserConsoleService;
import com.ibeetl.admin.core.dao.CoreUserRoleDao;
import com.ibeetl.admin.core.entity.CoreUser;
@ -19,6 +22,7 @@ import com.ibeetl.admin.core.web.JsonReturnCode;
import com.ibeetl.jlw.dao.TeacherDao;
import com.ibeetl.jlw.dao.UniversitiesCollegesDao;
import com.ibeetl.jlw.entity.*;
import com.ibeetl.jlw.entity.dto.TeacherBatchImportDTO;
import com.ibeetl.jlw.job.CacheLogJob;
import com.ibeetl.jlw.web.query.*;
import org.apache.commons.collections4.CollectionUtils;
@ -55,6 +59,7 @@ import java.util.stream.Collectors;
import static cn.jlw.token.TokenService.updateByIds;
import static com.ibeetl.admin.core.enums.MenuEnums.JT_01;
import static com.ibeetl.admin.core.enums.MenuEnums.JT_S_02;
import static com.ibeetl.admin.core.util.ListUtils.getDuplicateElements;
import static com.ibeetl.jlw.web.IpAddressController.ipAddressMap;
@ -786,4 +791,43 @@ public class TeacherService extends CoreBaseService<Teacher> {
List<TeacherExtendSchoolInfo> infoList = teacherDao.getTeacherExtendSchoolInfoListByUserIds(userIds);
return ObjectUtil.isNotEmpty(infoList) ? infoList.get(0) : null;
}
/**
* : <br>
*
*
* @param list
* @param listener
* @Author: 87966
* @Date: 2023/2/14 15:23
*/
public void validateTeacherSnListIsExistsThrow(List<Teacher> list, MyValidateExcelCellDataListener<TeacherBatchImportDTO> listener) {
if (CollectionUtil.isEmpty(list)) {
return;
}
// 查询所有的班级编号
List<String> jobNumberList = list.stream().map(Teacher::getTeacherJobNumber).collect(Collectors.toList());
// 获取重复的元素
List<String> duplicateElements = getDuplicateElements(jobNumberList);
for (String duplicateElement : duplicateElements) {
int errorRowIndex = jobNumberList.indexOf(duplicateElement);
// 这里固定列索引,省事
listener.putFailMessage(
errorRowIndex, 4, StrUtil.format("本次上传的文件中,存在重复的的教师编号:\"{}\"", duplicateElement));
}
// 查询库里已经存在的编号
List<String> existsList = teacherDao.createLambdaQuery()
.andIsNotNull(Teacher::getTeacherSn)
.andIn(Teacher::getTeacherSn, jobNumberList).select(String.class,"teacher_job_number");
for (String duplicateElement : existsList) {
int errorRowIndex = jobNumberList.indexOf(duplicateElement);
// 这里固定列索引,省事
listener.putFailMessage(
errorRowIndex, 4, StrUtil.format("已存在的教师编号:\"{}\"", duplicateElement));
}
}
}

@ -171,8 +171,8 @@ public class UniversityFacultyService extends CoreBaseService<UniversityFaculty>
*
* @return
*/
public static Map<String, List<String>> getAllUniversitiesCollegesWithFaculty() {
List<Map<String, String>> data = SpringUtil.getBean(UniversityFacultyDao.class).getAllUniversitiesCollegesWithFaculty();
public static Map<String, List<String>> getAllUniversityFacultyWithColleges() {
List<Map<String, String>> data = SpringUtil.getBean(UniversityFacultyDao.class).getAllUniversityFacultyWithColleges();
Map<String, List<String>> groupMap = new ConcurrentHashMap<>(10);

@ -280,7 +280,6 @@ public class SchoolClassController extends BaseController {
public void exportBatchTemplate() {
Assert.notNull(getUser(), "请登录后再操作");
Assert.isNull(getStudent(), "学生无法访问该接口");
String filename = StrUtil.format("批量班级导入模板{}.xlsx", System.currentTimeMillis());

@ -2779,7 +2779,6 @@ public class StudentController extends BaseController{
public void exportBatchTemplate() {
Assert.notNull(getUser(), "请登录后再操作");
Assert.isNull(getStudent(), "学生无法访问该接口");
String filename = StrUtil.format("批量学生导入模板{}.xlsx", System.currentTimeMillis());
@ -2828,18 +2827,12 @@ public class StudentController extends BaseController{
return null;
}, true);
try {
studentService.validateStudentSnListIsExistsThrow(list);
}
catch (IllegalArgumentException e) {
listener.putFailMessage(e.getMessage());
}
finally {
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
}
studentService.validateStudentSnListIsExistsThrow(list, listener);
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
studentService.insertBatch(list);
// 导入并添加身份信息
list.forEach(studentService::add);
}
catch (IllegalArgumentException exception) {
return JsonResult.failMessage(exception.getMessage()).setCode(DIY_ERROR.getCode());

@ -1,13 +1,16 @@
package com.ibeetl.jlw.web;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.jlw.Interceptor.GetFile;
import cn.jlw.Interceptor.RFile;
import cn.jlw.Interceptor.SCoreUser;
import cn.jlw.util.JupyterNotebookUtils;
import cn.jlw.util.ToolUtils;
import cn.jlw.util.excel.ExcelUtil;
import cn.jlw.util.excel.listener.MyValidateExcelCellDataListener;
import cn.jlw.validate.ValidateConfig;
import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.entity.CoreUser;
@ -17,9 +20,12 @@ import com.ibeetl.admin.core.util.BeanCopyUtil;
import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.util.TimeTool;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.jlw.dao.UniversitiesCollegesDao;
import com.ibeetl.jlw.entity.*;
import com.ibeetl.jlw.entity.dto.TeacherBatchImportDTO;
import com.ibeetl.jlw.service.*;
import com.ibeetl.jlw.web.query.*;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -34,9 +40,11 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -46,8 +54,12 @@ import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
import static cn.jlw.util.CacheUserUtil.getStudent;
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.user.CacheUserUtil.getUser;
import static com.ibeetl.admin.core.web.JsonReturnCode.DIY_ERROR;
/**
* Teacher
@ -96,6 +108,7 @@ public class TeacherController extends BaseController {
@Autowired private StudentDefenceLogService studentDefenceLogService;
@Autowired private StudentDefenceLogInfoService studentDefenceLogInfoService;
@Autowired private UniversitiesCollegesDao universitiesCollegesDao;
@Autowired
FileService fileService;
@ -1276,7 +1289,7 @@ public class TeacherController extends BaseController {
}
//下载模板信息
@GetMapping(MODEL + "/downloadTemplate.json")
@GetMapping(MODEL + "/downloadTemplate_old.json")
public void download(HttpServletResponse response,@SCoreUser CoreUser coreUser) {
XSSFWorkbook workbook = null;
InputStream is = null;
@ -1340,7 +1353,7 @@ public class TeacherController extends BaseController {
}
//导入模板信息
@PostMapping(MODEL + "/importTemplate.json")
@PostMapping(MODEL + "/importTemplate_old.json")
@ResponseBody
public JsonResult importTemplate(@RFile FileEntity fileEntity) {
List<Long>list=new ArrayList<>();
@ -1493,4 +1506,75 @@ public class TeacherController extends BaseController {
}
}
/**
*
* @return
*/
@SneakyThrows
@GetMapping({ API + "/exportBatchTemplate.do", MODEL + "/downloadTemplate.json" })
@ResponseBody
public void exportBatchTemplate() {
Assert.notNull(getUser(), "请登录后再操作");
String filename = StrUtil.format("批量教师导入模板{}.xlsx", System.currentTimeMillis());
setExcelResponse(filename);
// 输出 Excel
com.ibeetl.admin.core.util.excelGroupValidation.ExcelUtil.createExcel(Arrays.asList(new TeacherBatchImportDTO()), response.getOutputStream());
}
/**
* : <br>
*
* excel
* @param file
* @return {@link JsonResult}
* @Author: 87966
* @Date: 2022/11/28 10:04
*/
@SneakyThrows
@PostMapping({MODEL + "/importTemplate.json", API + "/importBatchTemplate.do"})
@ResponseBody
public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
try {
Assert.isNull(getStudent(), "学生无法访问该接口");
// 输出 Excel
MyValidateExcelCellDataListener<TeacherBatchImportDTO> listener = new MyValidateExcelCellDataListener<>();
ExcelUtil.readExcelNotContainHeader(file, TeacherBatchImportDTO.class, listener);
// 判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
// 类型转换
List<Teacher> list = listener.getData().stream().map(TeacherBatchImportDTO::pojo)
.collect(Collectors.toList());
// 设置机构ID
setObjectOrgId(list, (e) -> {
UniversitiesColleges params = new UniversitiesColleges();
params.setUniversitiesCollegesId(e.getUniversitiesCollegesId());
params.setUniversitiesCollegesStatus(1);
UniversitiesColleges sc = universitiesCollegesDao.templateOne(params);
if (sc != null) {
return sc.getOrgId();
}
return null;
}, true);
teacherService.validateTeacherSnListIsExistsThrow(list, listener);
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
// 导入并添加身份信息
list.forEach(teacherService::add);
}
catch (IllegalArgumentException exception) {
return JsonResult.failMessage(exception.getMessage()).setCode(DIY_ERROR.getCode());
}
return JsonResult.successMessage("导入成功!");
}
}

@ -491,13 +491,12 @@ public class TeacherOpenCourseMergeResourcesQuestionController extends BaseContr
public void exportBatchTemplate() {
Assert.notNull(getUser(), "请登录后再操作");
Assert.isNull(getStudent(), "学生无法访问该接口");
String filename = StrUtil.format("批量题库导入模板{}.xlsx", System.currentTimeMillis());
// 输出 Excel
ExcelUtil.writeExcel(response, filename, Collections.emptyList(), TeacherOpenCourseMergeResourcesQuestion.class);
}
}
/**
* : <br>

@ -352,7 +352,7 @@ getValuesByQueryNotWithPermission
and find_in_set(t.org_id,#orgIdPlural#)
@}
getAllUniversitiesCollegesWithFaculty
getAllUniversityFacultyWithColleges
===
* 通过用户组织ID获取院校的的权限信息

Loading…
Cancel
Save