From 00d4b006bc06851634a0e53b360b94388e428275 Mon Sep 17 00:00:00 2001 From: maLix Date: Sat, 1 Jul 2023 16:39:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=AF=BC=E5=85=A5=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E9=AA=8C=E8=AF=81=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E5=92=8C=E6=89=8B=E6=9C=BA=E6=A0=BC=E5=BC=8F=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9B=20=E5=AD=A6=E7=94=9F=E5=AF=BC=E5=85=A5=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BE=AE=E4=BF=A1=E5=8F=B7=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=BD=95=E5=85=A5=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ibeetl/admin/core/validation/Email.java | 28 ++++++++++++++++++ .../admin/core/validation/EmailValidator.java | 29 +++++++++++++++++++ .../MyValidateExcelCellDataListener.java | 20 +++++++++++-- .../java/com/ibeetl/jlw/dao/StudentDao.java | 4 +-- .../dto/StudentBatchImportAdminDTO.java | 15 ++++++++-- .../dto/StudentBatchImportUniAdminDTO.java | 15 ++++++++-- .../ibeetl/jlw/service/StudentService.java | 5 ++-- web/src/main/resources/sql/jlw/student.md | 10 +++++++ 8 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 admin-core/src/main/java/com/ibeetl/admin/core/validation/Email.java create mode 100644 admin-core/src/main/java/com/ibeetl/admin/core/validation/EmailValidator.java diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/validation/Email.java b/admin-core/src/main/java/com/ibeetl/admin/core/validation/Email.java new file mode 100644 index 00000000..953c3adc --- /dev/null +++ b/admin-core/src/main/java/com/ibeetl/admin/core/validation/Email.java @@ -0,0 +1,28 @@ +package com.ibeetl.admin.core.validation; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ + ElementType.METHOD, + ElementType.FIELD, + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.PARAMETER, + ElementType.TYPE_USE +}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Constraint( + validatedBy = EmailValidator.class +) +public @interface Email { + + String message() default "电子邮箱格式不正确"; + + Class[] groups() default {}; + + Class[] payload() default {}; + +} diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/validation/EmailValidator.java b/admin-core/src/main/java/com/ibeetl/admin/core/validation/EmailValidator.java new file mode 100644 index 00000000..fca4b501 --- /dev/null +++ b/admin-core/src/main/java/com/ibeetl/admin/core/validation/EmailValidator.java @@ -0,0 +1,29 @@ +package com.ibeetl.admin.core.validation; + +import cn.hutool.core.lang.Validator; +import cn.hutool.core.util.StrUtil; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +/** + * 注解 邮箱校验 + * @author lx + */ +public class EmailValidator implements ConstraintValidator { + + @Override + public void initialize(Email annotation) { + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + // 如果邮箱为空,默认不校验,即校验通过 + if (StrUtil.isEmpty(value)) { + return true; + } + // 校验邮箱 + return Validator.isEmail(value); + } + +} diff --git a/web/src/main/java/cn/jlw/util/excel/listener/MyValidateExcelCellDataListener.java b/web/src/main/java/cn/jlw/util/excel/listener/MyValidateExcelCellDataListener.java index 6c447f97..55565d72 100644 --- a/web/src/main/java/cn/jlw/util/excel/listener/MyValidateExcelCellDataListener.java +++ b/web/src/main/java/cn/jlw/util/excel/listener/MyValidateExcelCellDataListener.java @@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.validation.BeanValidationResult; +import cn.hutool.extra.validation.ValidationUtil; import cn.jlw.util.excel.ExcelFailRecord; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.exception.ExcelDataConvertException; @@ -66,8 +68,8 @@ public class MyValidateExcelCellDataListener implements ReadListener { final Field field = fields[columnIndex]; field.setAccessible(true); try { final Object fieldValue = field.get(bean); + final String fieldName = field.getName(); -// final String fieldName = field.getName(); // int finalColumnIndex = columnIndex; // bean.getIndexMap().computeIfAbsent(fieldName, s -> new BaseExcelInfoDTO.BaseExcelIndexDTO() { // @Override @@ -81,13 +83,14 @@ public class MyValidateExcelCellDataListener implements ReadListener { // } // }); + ExcelRequireIgnore requireIgnore = field.getDeclaredAnnotation(ExcelRequireIgnore.class); // 如果有忽略必传的注解,并且没有查询到值则直接跳过必传验证 if (requireIgnore != null && fieldValue == null) { ReflectUtil.setFieldValue(bean, field, requireIgnore.defaultValue()); - continue; } + // 空值判断 if (ObjectUtil.isEmpty(fieldValue)) { putFailMessage(rowIndex, columnIndex, "存在空值"); @@ -99,6 +102,19 @@ public class MyValidateExcelCellDataListener implements ReadListener { putFailMessage(rowIndex, columnIndex, "数据重复"); emptyColumnCount++; } + + + // 验证字段是否符合格式要求 + BeanValidationResult beanValidationResult = ValidationUtil.warpValidateProperty(bean, fieldName); + + if (!beanValidationResult.isSuccess()) { + int finalColumnIndex = columnIndex; + beanValidationResult.getErrorMessages().forEach(item -> { + putFailMessage(rowIndex, finalColumnIndex, StrUtil.format("内容:{} {}", item.getValue(), item.getMessage())); + }); + } + + } catch (IllegalAccessException e) { log.error(e.getMessage(), e); } diff --git a/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java b/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java index 048ee945..090f2963 100644 --- a/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java +++ b/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java @@ -5,9 +5,7 @@ import com.ibeetl.jlw.entity.CourseInfo; import com.ibeetl.jlw.entity.Student; import com.ibeetl.jlw.entity.StudentExtendSchoolInfo; import com.ibeetl.jlw.entity.api.student.StudentActiveInfo; -import com.ibeetl.jlw.entity.dto.SystemUseLogsAnalysisDTO; import com.ibeetl.jlw.entity.dto.StudentEditPasswordDTO; -import com.ibeetl.jlw.entity.vo.SystemUseLogsAnalysisVO; import com.ibeetl.jlw.entity.vo.StudentLogAnalysisVO; import com.ibeetl.jlw.entity.vo.StudentLoginLogVO; import com.ibeetl.jlw.entity.vo.StudentUseLogVO; @@ -37,6 +35,8 @@ public interface StudentDao extends BaseMapper{ @Update void deleteStudentByIds(String ids); @Update + void batchAppendCodeDelByIds(String ids); + @Update void deleteByIds(String ids); List> getExcelValues (StudentQuery studentQuery); List> getExcelValues2Competition (StudentQuery studentQuery); diff --git a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportAdminDTO.java b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportAdminDTO.java index 9ff0f109..0ea90435 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportAdminDTO.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportAdminDTO.java @@ -2,6 +2,8 @@ package com.ibeetl.jlw.entity.dto; import com.ibeetl.admin.core.annotation.ExcelRequireIgnore; import com.ibeetl.admin.core.util.excelGroupValidation.ExcelFile; +import com.ibeetl.admin.core.validation.Email; +import com.ibeetl.admin.core.validation.Mobile; import com.ibeetl.jlw.entity.Student; import com.ibeetl.jlw.enums.GenderEnum; import lombok.Data; @@ -24,8 +26,8 @@ import static cn.hutool.core.util.ObjectUtil.defaultIfNull; @Data @FieldNameConstants @ToString -@ExcelFile(fileHeadTemplate = "universitiesCollegesName|universityFacultyName|universitySystemName|classId|studentName|studentSn|studentMobile|studentEmail", - fileMappingTemplate = "universitiesCollegesName=院校名称|universityFacultyName=院系名称|universitySystemName=专业名称|classId=班级名称|studentName=学生姓名|studentSn=学号|studentMobile=电话|studentEmail=邮箱", +@ExcelFile(fileHeadTemplate = "universitiesCollegesName|universityFacultyName|universitySystemName|classId|studentName|studentSn|studentMobile|studentEmail|studentWeixinInfo", + fileMappingTemplate = "universitiesCollegesName=院校名称|universityFacultyName=院系名称|universitySystemName=专业名称|classId=班级名称|studentName=学生姓名|studentSn=学号|studentMobile=电话|studentEmail=邮箱|studentWeixinInfo=微信号", datasheetHidden = true, enableDataValidation = true) public class StudentBatchImportAdminDTO { @@ -62,13 +64,19 @@ public class StudentBatchImportAdminDTO { /** * 电话 */ + @Mobile private String studentMobile ; /** * 邮箱 */ - @ExcelRequireIgnore + @Email private String studentEmail ; + /** + * 微信 + */ + @ExcelRequireIgnore + private String studentWeixinInfo ; /** * 类型转换 @@ -85,6 +93,7 @@ public class StudentBatchImportAdminDTO { .studentSn(importPojo.getStudentSn()) .studentMobile(importPojo.getStudentMobile()) .studentEmail(importPojo.getStudentEmail()) + .studentWeixinInfo(importPojo.getStudentWeixinInfo()) .studentStatus(1) .studentGender(GenderEnum.UN_KNOW) .studentPassword("123qwe") diff --git a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportUniAdminDTO.java b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportUniAdminDTO.java index 9b711eee..6bb8ac32 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportUniAdminDTO.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentBatchImportUniAdminDTO.java @@ -2,6 +2,8 @@ package com.ibeetl.jlw.entity.dto; import com.ibeetl.admin.core.annotation.ExcelRequireIgnore; import com.ibeetl.admin.core.util.excelGroupValidation.ExcelFile; +import com.ibeetl.admin.core.validation.Email; +import com.ibeetl.admin.core.validation.Mobile; import com.ibeetl.jlw.entity.Student; import com.ibeetl.jlw.enums.GenderEnum; import lombok.Data; @@ -24,8 +26,8 @@ import static cn.hutool.core.util.ObjectUtil.defaultIfNull; @Data @FieldNameConstants @ToString -@ExcelFile(fileHeadTemplate = "universityFacultyName|universitySystemName|classId|studentName|studentSn|studentMobile|studentEmail", - fileMappingTemplate = "universityFacultyName=院系名称|universitySystemName=专业名称|classId=班级名称|studentName=学生姓名|studentSn=学号|studentMobile=电话|studentEmail=邮箱", +@ExcelFile(fileHeadTemplate = "universityFacultyName|universitySystemName|classId|studentName|studentSn|studentMobile|studentEmail|studentWeixinInfo", + fileMappingTemplate = "universityFacultyName=院系名称|universitySystemName=专业名称|classId=班级名称|studentName=学生姓名|studentSn=学号|studentMobile=电话|studentEmail=邮箱|studentWeixinInfo=微信号", datasheetHidden = true, enableDataValidation = true) public class StudentBatchImportUniAdminDTO { @@ -56,13 +58,19 @@ public class StudentBatchImportUniAdminDTO { /** * 电话 */ + @Mobile private String studentMobile ; /** * 邮箱 */ - @ExcelRequireIgnore + @Email private String studentEmail ; + /** + * 微信 + */ + @ExcelRequireIgnore + private String studentWeixinInfo ; /** * 类型转换 @@ -79,6 +87,7 @@ public class StudentBatchImportUniAdminDTO { .studentSn(importPojo.getStudentSn()) .studentMobile(importPojo.getStudentMobile()) .studentEmail(importPojo.getStudentEmail()) + .studentWeixinInfo(importPojo.getStudentWeixinInfo()) .studentStatus(1) .studentGender(GenderEnum.UN_KNOW) .studentPassword("123qwe") diff --git a/web/src/main/java/com/ibeetl/jlw/service/StudentService.java b/web/src/main/java/com/ibeetl/jlw/service/StudentService.java index b7d34598..00cb62c4 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/StudentService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/StudentService.java @@ -436,9 +436,10 @@ public class StudentService extends CoreBaseService{ //置空相应coreUser的code userConsoleService.batchSetCodeNullByIds(userIds); - + // 批量置空 学生编号后面追加@_DEL, 代表已经删除了 + studentDao.batchAppendCodeDelByIds(ids); + // 逻辑删除学生 studentDao.deleteStudentByIds(ids); - } public void deleteByList(List list){ diff --git a/web/src/main/resources/sql/jlw/student.md b/web/src/main/resources/sql/jlw/student.md index 0929d028..eae86458 100644 --- a/web/src/main/resources/sql/jlw/student.md +++ b/web/src/main/resources/sql/jlw/student.md @@ -398,6 +398,16 @@ deleteStudentByIds `student_status` = 2 WHERE FIND_IN_SET(student_id,#ids#) +batchAppendCodeDelByIds +=== + +* 批量 设置学生Code 后面追加@_DEL + + UPDATE `student` + SET + `student_sn` = concat(student_sn, '&_DEL&') + WHERE FIND_IN_SET(student_id, #ids#) + deleteByIds ===