|
@@ -1,28 +1,49 @@
|
|
|
package com.xjrsoft.module.base.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.secure.BCrypt;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
+import com.xjrsoft.common.enums.EnabledMark;
|
|
|
+import com.xjrsoft.common.enums.RoleEnum;
|
|
|
import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.utils.RedisUtil;
|
|
|
+import com.xjrsoft.config.CommonPropertiesConfig;
|
|
|
import com.xjrsoft.module.base.dto.WhitelistManagementPageDto;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.entity.BaseUserStudent;
|
|
|
import com.xjrsoft.module.base.entity.TreeNode;
|
|
|
import com.xjrsoft.module.base.entity.WhiteBaseClass;
|
|
|
import com.xjrsoft.module.base.entity.WhiteBaseGrade;
|
|
|
import com.xjrsoft.module.base.entity.WhitelistManagement;
|
|
|
import com.xjrsoft.module.base.mapper.WhitelistManagementMapper;
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.base.service.IBaseUserStudentService;
|
|
|
import com.xjrsoft.module.base.service.IWhitelistManagementService;
|
|
|
import com.xjrsoft.module.base.vo.WhitelistManagementPageVo;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.entity.UserRoleRelation;
|
|
|
+import com.xjrsoft.module.organization.service.IUserRoleRelationService;
|
|
|
+import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
+import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -40,6 +61,12 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
|
|
|
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
+ private final IUserService userService;
|
|
|
+ private final IBaseClassService classService;
|
|
|
+ private final IBaseStudentSchoolRollService rollService;
|
|
|
+ private final CommonPropertiesConfig propertiesConfig;
|
|
|
+ private final IBaseUserStudentService userStudentService;
|
|
|
+ private final IUserRoleRelationService roleRelationService;
|
|
|
@Override
|
|
|
public Page<WhitelistManagementPageVo> getPage(Page<Object> objectPage, WhitelistManagementPageDto dto) {
|
|
|
return whitelistManagementMapper.getPage(objectPage, dto);
|
|
@@ -156,4 +183,162 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
|
|
|
|
|
|
return errorList;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<Integer, Object>> activateImport(List<Map<Integer, Object>> savedDataList) {
|
|
|
+ List<Map<Integer, Object>> errorList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<User> studentList = userService.selectJoinList(User.class,
|
|
|
+ new MPJLambdaWrapper<User>()
|
|
|
+ .innerJoin(BaseStudent.class, BaseStudent::getUserId, User::getId)
|
|
|
+ );
|
|
|
+ Map<String, User> studentMap = new HashMap<>();
|
|
|
+ for (User user : studentList) {
|
|
|
+ String key = user.getName() + user.getCredentialNumber();
|
|
|
+ studentMap.put(key, user);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BaseClass> classList = classService.list(new QueryWrapper<BaseClass>());
|
|
|
+ Map<Long, Long> classTeacherMap = new HashMap<>();
|
|
|
+ for (BaseClass baseClass : classList) {
|
|
|
+ classTeacherMap.put(baseClass.getId(), baseClass.getTeacherId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BaseStudentSchoolRoll> schoolRollList = rollService.list(new QueryWrapper<BaseStudentSchoolRoll>());
|
|
|
+ Map<Long, Long> studentClassMap = new HashMap<>();
|
|
|
+ for (BaseStudentSchoolRoll el : schoolRollList) {
|
|
|
+ studentClassMap.put(el.getUserId(), el.getClassId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<User> parents = userService.list(
|
|
|
+ new QueryWrapper<User>().lambda()
|
|
|
+ .notIn(User::getId, "SELECT user_id FROM base_student")
|
|
|
+ );
|
|
|
+ Map<String, User> parentsMap = new HashMap<>();
|
|
|
+ for (User parent : parents) {
|
|
|
+ parentsMap.put(parent.getMobile(), parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> whitelistUsers = this.baseMapper.selectList(new QueryWrapper<>()).stream().map(WhitelistManagement::getUserId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<User> updateList = new ArrayList<>();
|
|
|
+ List<BaseUserStudent> userStudentList = new ArrayList<>();
|
|
|
+ List<User> parentInsList = new ArrayList<>();
|
|
|
+ List<User> parentUpdList = new ArrayList<>();
|
|
|
+ List<UserRoleRelation> roleRelationList = new ArrayList<>();
|
|
|
+ List<WhitelistManagement> whitelist = new ArrayList();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ Date createDate = new Date();
|
|
|
+ for (Map<Integer, Object> vo : savedDataList) {
|
|
|
+ List<String> errorLogs = new ArrayList<>();
|
|
|
+
|
|
|
+ if(vo.get(0) == null || "".equals(vo.get(0).toString())){
|
|
|
+ errorLogs.add("学生姓名为空");
|
|
|
+ }
|
|
|
+ if(vo.get(1) == null || "".equals(vo.get(1).toString())){
|
|
|
+ errorLogs.add("学生身份证为空");
|
|
|
+ }
|
|
|
+ if(vo.get(2) == null || "".equals(vo.get(2).toString())){
|
|
|
+ errorLogs.add("智慧校园卡号为空");
|
|
|
+ }
|
|
|
+ if(vo.get(3) == null || "".equals(vo.get(3).toString())){
|
|
|
+ errorLogs.add("家长姓名为空");
|
|
|
+ }
|
|
|
+ if(vo.get(4) == null || "".equals(vo.get(4).toString())){
|
|
|
+ errorLogs.add("家长手机号为空");
|
|
|
+ }
|
|
|
+ String studentKey = vo.get(0).toString() + vo.get(1).toString();
|
|
|
+ if(!studentMap.containsKey(studentKey)){
|
|
|
+ errorLogs.add("未能查询到该学生");
|
|
|
+ }
|
|
|
+ if(!errorLogs.isEmpty()){
|
|
|
+ vo.put(5, errorLogs.toString().replace("[", "").replace("]", ""));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ long parentId = IdUtil.getSnowflakeNextId();
|
|
|
+ if(parentsMap.get(vo.get(4).toString()) != null){
|
|
|
+ User parent = parentsMap.get(vo.get(4).toString());
|
|
|
+ parentId = parent.getId();
|
|
|
+ parent.setName(vo.get(3).toString());
|
|
|
+ parent.setModifyDate(now);
|
|
|
+ parentUpdList.add(parent);
|
|
|
+ }else{
|
|
|
+ User parent = new User();
|
|
|
+ parent.setId(parentId);
|
|
|
+ parent.setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
|
|
|
+ parent.setCreateDate(now);
|
|
|
+ parent.setMobile(vo.get(4).toString());
|
|
|
+ parent.setName(vo.get(3).toString());
|
|
|
+ parent.setUserName(vo.get(4).toString());
|
|
|
+ parent.setIsChangePassword(1);
|
|
|
+ parentInsList.add(parent);
|
|
|
+
|
|
|
+ UserRoleRelation roleRelation = new UserRoleRelation();
|
|
|
+ roleRelation.setRoleId(RoleEnum.PARENT.getCode());
|
|
|
+ roleRelation.setUserId(parentId);
|
|
|
+ roleRelationList.add(roleRelation);
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = studentMap.get(studentKey);
|
|
|
+ user.setMobile(vo.get(2).toString());
|
|
|
+ user.setEnabledMark(EnabledMark.ENABLED.getCode());
|
|
|
+ updateList.add(user);
|
|
|
+ Long classId = studentClassMap.get(user.getId());
|
|
|
+ Long teacherId = classTeacherMap.get(classId);
|
|
|
+
|
|
|
+ BaseUserStudent userStudent = new BaseUserStudent();
|
|
|
+ userStudent.setStatus(1);
|
|
|
+ userStudent.setStudentId(user.getId());
|
|
|
+ userStudent.setStudentIdentity(user.getCredentialNumber());
|
|
|
+ userStudent.setStudentNane(user.getName());
|
|
|
+ userStudent.setCreateDate(new Date());
|
|
|
+ userStudent.setClassId(classId);
|
|
|
+ userStudent.setTeacherId(teacherId);
|
|
|
+ userStudent.setUserId(parentId);
|
|
|
+ userStudent.setUserPhone(vo.get(4).toString());
|
|
|
+ userStudentList.add(userStudent);
|
|
|
+
|
|
|
+
|
|
|
+ if(!whitelistUsers.contains(user.getId())){
|
|
|
+ whitelist.add(new WhitelistManagement(){{
|
|
|
+ setCredentialNumber(user.getCredentialNumber());
|
|
|
+ setUserId(user.getId());
|
|
|
+ setName(user.getName());
|
|
|
+ setPhone(user.getMobile());
|
|
|
+ setCreateDate(createDate);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!updateList.isEmpty()){
|
|
|
+ userService.updateBatchById(updateList);
|
|
|
+ }
|
|
|
+ if(!userStudentList.isEmpty()){
|
|
|
+ userStudentService.updateBatchById(userStudentList);
|
|
|
+ }
|
|
|
+ if(!parentInsList.isEmpty()){
|
|
|
+ userService.saveBatch(parentInsList);
|
|
|
+ }
|
|
|
+ if(!parentUpdList.isEmpty()){
|
|
|
+ userService.updateBatchById(parentUpdList);
|
|
|
+ }
|
|
|
+ if(!roleRelationList.isEmpty()){
|
|
|
+ roleRelationService.saveBatch(roleRelationList);
|
|
|
+ }
|
|
|
+ if(!whitelist.isEmpty()){
|
|
|
+ this.saveBatch(whitelist);
|
|
|
+ }
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ List<User> list = userService.list();
|
|
|
+ redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
|
|
|
+
|
|
|
+ List<UserRoleRelation> userRoleRelationList = roleRelationService.list(Wrappers.lambdaQuery(UserRoleRelation.class));
|
|
|
+ redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, userRoleRelationList);
|
|
|
+
|
|
|
+ this.loadCaches();
|
|
|
+ });
|
|
|
+
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
}
|