|
@@ -1,10 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.as.service.aidingstudentsimportlist;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.log.Log;
|
|
|
-import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
-import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.as.controller.admin.aidingstudentsimportlist.vo.AidingStudentsImportExcelRespVO;
|
|
|
import cn.iocoder.yudao.module.as.controller.admin.aidingstudentsimportlist.vo.AidingStudentsImportExcelVO;
|
|
@@ -25,6 +22,7 @@ import javax.validation.ValidationException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -44,7 +42,7 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
|
|
|
// 插入
|
|
|
AidingStudentsImportExcelListDO aidingStudentsImportListDO = BeanUtils.toBean(createReqVO, AidingStudentsImportExcelListDO.class);
|
|
|
aidingStudentsImportListDO.setAsAidingStudentsManageId(aidingStudentsManageId);
|
|
|
- if (checkStudentIdNumberExists(aidingStudentsImportListDO.getStudentIdNumber(),aidingStudentsManageId)) {
|
|
|
+ if (checkStudentCodeExists(aidingStudentsImportListDO.getStudentIdNumber(),aidingStudentsManageId)) {
|
|
|
throw exception(AIDING_STUDENTS_IMPORT_LIST_STUDENT_EXISTS);
|
|
|
}
|
|
|
aidingStudentsImportListMapper.insert(aidingStudentsImportListDO);
|
|
@@ -70,17 +68,20 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
|
|
|
aidingStudentsImportListMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 根据id校验是否存在
|
|
|
private void validateAidingStudentsImportListExists(Long id) {
|
|
|
if (aidingStudentsImportListMapper.selectById(id) == null) {
|
|
|
throw exception(AIDING_STUDENTS_IMPORT_LIST_NOT_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //根据身份证号校验这次项目是否已经导入
|
|
|
- private boolean checkStudentIdNumberExists(String studentIdNumber, Long asAidingStudentsManageId) {
|
|
|
+ //根据学号校验这次项目该学生是否已经导入
|
|
|
+ private boolean checkStudentCodeExists(String studentCode, Long asAidingStudentsManageId) {
|
|
|
+ //存在返回true,不存在返回false
|
|
|
return aidingStudentsImportListMapper.selectCount(
|
|
|
Wrappers.lambdaQuery(AidingStudentsImportExcelListDO.class)
|
|
|
- .eq(AidingStudentsImportExcelListDO::getStudentIdNumber, studentIdNumber)
|
|
|
+ .eq(AidingStudentsImportExcelListDO::getStudentCode, studentCode)
|
|
|
.eq(AidingStudentsImportExcelListDO::getAsAidingStudentsManageId, asAidingStudentsManageId)
|
|
|
) > 0;
|
|
|
|
|
@@ -138,11 +139,11 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+//导入到数据库当中
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
- public AidingStudentsImportExcelRespVO aidingStudentsImportExcelList( Long asAidingStudentsManageId) {
|
|
|
- List<AidingStudentsImportExcelListDO> list = aidingStudentsImportListRedisDAO.getAllMatchingValues();
|
|
|
+ public AidingStudentsImportExcelRespVO aidingStudentsImportExcelList( Long asAidingStudentsManageId,String redisUUID) {
|
|
|
+ List<AidingStudentsImportExcelListDO> list = aidingStudentsImportListRedisDAO.getAllMatchingValues(redisUUID);
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
throw exception(AIDING_STUDENTS_IMPORT_LIST_IS_NULL);
|
|
|
}
|
|
@@ -161,7 +162,7 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
|
|
|
}
|
|
|
//赋值给外键
|
|
|
aidingStudentsImportEecleListDO.setAsAidingStudentsManageId(asAidingStudentsManageId);
|
|
|
- if (checkStudentIdNumberExists(aidingStudentsImportEecleListDO.getStudentIdNumber(),asAidingStudentsManageId)) {
|
|
|
+ if (checkStudentCodeExists(aidingStudentsImportEecleListDO.getStudentCode(),asAidingStudentsManageId)) {
|
|
|
respVO.getFailureStudentNames().put(aidingStudentsImportEecleListDO.getStudentName(), "该学生已导入过一次");
|
|
|
return;
|
|
|
}
|
|
@@ -175,20 +176,72 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
|
|
|
|
|
|
//导入到redis中
|
|
|
@Override
|
|
|
- public void aidingStudentsImportExcelToRedis(List<AidingStudentsImportExcelVO> list) {
|
|
|
+ public String aidingStudentsImportExcelToRedis(List<AidingStudentsImportExcelVO> list) {
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
throw exception(AIDING_STUDENTS_IMPORT_LIST_IS_NULL);
|
|
|
}
|
|
|
+ String redisUUID = String.valueOf(UUID.randomUUID());
|
|
|
try {
|
|
|
List<AidingStudentsImportExcelListDO> aidingStudentsImportEecleListDOS = BeanUtils.toBean(list, AidingStudentsImportExcelListDO.class);
|
|
|
aidingStudentsImportEecleListDOS.forEach(aidingStudentsImportEecleListDO -> {
|
|
|
- aidingStudentsImportListRedisDAO.set(aidingStudentsImportEecleListDO);
|
|
|
+ aidingStudentsImportListRedisDAO.setWithredisUUID(redisUUID,aidingStudentsImportEecleListDO);
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
|
log.error("导入redis失败", e);
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
}
|
|
|
+ return redisUUID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //重新导入
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void aidingStudentsImportExcelReImport(List<AidingStudentsImportExcelVO> list, Long aidingStudentsManageId, Integer strategyId) {
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ throw exception(AIDING_STUDENTS_IMPORT_LIST_IS_NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<AidingStudentsImportExcelListDO> aidingStudentsImportEecleListDOS = BeanUtils.toBean(list, AidingStudentsImportExcelListDO.class);
|
|
|
+ aidingStudentsImportEecleListDOS.forEach(aidingStudentsImportEecleListDO -> {
|
|
|
+ // 校验,判断是否有不符合的原因
|
|
|
+
|
|
|
+ String result = validateImportListForCreateOrUpdate(aidingStudentsImportEecleListDO.getStudentName(), aidingStudentsImportEecleListDO.getStudentIdNumber(),
|
|
|
+ aidingStudentsImportEecleListDO.getStudentCode(), aidingStudentsImportEecleListDO.getStudentAge(), aidingStudentsImportEecleListDO.getStudentSex());
|
|
|
+ if (result != null){
|
|
|
+ throw new ValidationException(aidingStudentsImportEecleListDO.getStudentName()+result);
|
|
|
+ }
|
|
|
+ // 赋值给外键
|
|
|
+ aidingStudentsImportEecleListDO.setAsAidingStudentsManageId(aidingStudentsManageId);
|
|
|
+ //数据库不存在,直接插入
|
|
|
+ if(!checkStudentCodeExists(aidingStudentsImportEecleListDO.getStudentCode(),aidingStudentsManageId)){
|
|
|
+ aidingStudentsImportListMapper.insert(aidingStudentsImportEecleListDO);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 数据库存在,判断策略,1表示覆盖
|
|
|
+ if(strategyId == 1){
|
|
|
+ aidingStudentsImportListMapper.update(aidingStudentsImportEecleListDO,
|
|
|
+ Wrappers.lambdaQuery(AidingStudentsImportExcelListDO.class)
|
|
|
+ .eq(AidingStudentsImportExcelListDO::getStudentCode, aidingStudentsImportEecleListDO.getStudentCode())
|
|
|
+ .eq(AidingStudentsImportExcelListDO::getAsAidingStudentsManageId, aidingStudentsManageId)
|
|
|
+ );
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //数据库存在,判断策略,2表示不改变
|
|
|
+ if (strategyId == 2){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ throw new ValidationException("导入失败");
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导入失败", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|