|
|
@@ -5,22 +5,33 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
+import com.xjrsoft.common.enums.DeleteMark;
|
|
|
+import com.xjrsoft.common.enums.GenderDictionaryEnum;
|
|
|
import com.xjrsoft.common.enums.RoleEnum;
|
|
|
import com.xjrsoft.common.utils.RedisUtil;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.config.CommonPropertiesConfig;
|
|
|
+import com.xjrsoft.module.organization.entity.Department;
|
|
|
+import com.xjrsoft.module.organization.entity.Post;
|
|
|
import com.xjrsoft.module.organization.entity.User;
|
|
|
import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
|
import com.xjrsoft.module.organization.entity.UserPostRelation;
|
|
|
import com.xjrsoft.module.organization.entity.UserRoleRelation;
|
|
|
import com.xjrsoft.module.organization.mapper.UserDeptRelationMapper;
|
|
|
import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
|
|
|
+import com.xjrsoft.module.organization.service.IDepartmentService;
|
|
|
+import com.xjrsoft.module.organization.service.IPostService;
|
|
|
import com.xjrsoft.module.organization.service.IUserDeptRelationService;
|
|
|
import com.xjrsoft.module.organization.service.IUserPostRelationService;
|
|
|
import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.system.entity.DictionaryDetail;
|
|
|
+import com.xjrsoft.module.system.service.IDictionarydetailService;
|
|
|
import com.xjrsoft.module.teacher.dto.AddXjrUserDto;
|
|
|
import com.xjrsoft.module.teacher.dto.UpdateXjrUserDto;
|
|
|
import com.xjrsoft.module.teacher.entity.BaseTeacher;
|
|
|
@@ -44,9 +55,11 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -76,6 +89,11 @@ public class TeacherbaseManagerServiceImpl extends MPJBaseServiceImpl<XjrUserMap
|
|
|
private final IUserService userService;
|
|
|
private final CommonPropertiesConfig propertiesConfig;
|
|
|
private final IUserPostRelationService userPostRelationService;
|
|
|
+ private final IDictionarydetailService dictionaryService;
|
|
|
+ private final IDepartmentService departmentService;
|
|
|
+ private final IPostService postService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean add(AddXjrUserDto dto) {
|
|
|
@@ -430,4 +448,163 @@ public class TeacherbaseManagerServiceImpl extends MPJBaseServiceImpl<XjrUserMap
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入,根据第一个工号查询是否有相关信息
|
|
|
+ * 1、批量新增或者修改xjr_user、base_teacher、xjr_user_dept_relation、xjr_user_post_relation
|
|
|
+ * 2、更新redis里面的缓存
|
|
|
+ * @param excelDataList 导入的数据
|
|
|
+ * @return 成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean importData(List<Map<Integer, Object>> excelDataList) {
|
|
|
+ List<User> userList = userService.list(
|
|
|
+ new MPJLambdaWrapper<User>()
|
|
|
+ .select(User::getId)
|
|
|
+ .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(BaseTeacher.class, BaseTeacher::getUserId, User::getId)
|
|
|
+ );
|
|
|
+ Map<String, User> userMap = userList.stream().collect(Collectors.toMap(User::getUserName, x -> x));
|
|
|
+
|
|
|
+ List<BaseTeacher> teacherList = teacherbaseManagerBaseTeacherMapper.selectJoinList(BaseTeacher.class,
|
|
|
+ new MPJLambdaWrapper<BaseTeacher>()
|
|
|
+ .select(BaseTeacher::getId)
|
|
|
+ .select(BaseTeacher.class, x -> VoToColumnUtil.fieldsToColumns(BaseTeacher.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(User.class, User::getId, BaseTeacher::getUserId)
|
|
|
+ );
|
|
|
+ Map<Long, BaseTeacher> teacherMap = teacherList.stream().collect(Collectors.toMap(BaseTeacher::getUserId, x -> x));
|
|
|
+
|
|
|
+ List<Long> itemList = new ArrayList<>();
|
|
|
+ itemList.add(2023000000000000016L);
|
|
|
+ itemList.add(2023000000000000006L);
|
|
|
+
|
|
|
+ List<DictionaryDetail> dictionaryList = dictionaryService.list(
|
|
|
+ new QueryWrapper<DictionaryDetail>().lambda()
|
|
|
+ .in(DictionaryDetail::getItemId, itemList)
|
|
|
+ .eq(DictionaryDetail::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, String> dictionaryMap = dictionaryList.stream().collect(Collectors.toMap(DictionaryDetail::getName, DictionaryDetail::getCode));
|
|
|
+
|
|
|
+ List<Department> departmentList = departmentService.list(
|
|
|
+ new QueryWrapper<Department>().lambda()
|
|
|
+ .eq(Department::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> departmentMap = departmentList.stream().collect(Collectors.toMap(Department::getName, Department::getId));
|
|
|
+
|
|
|
+ List<UserDeptRelation> userDeptRelations = userDeptRelationMapper.selectList(
|
|
|
+ new MPJLambdaWrapper<UserDeptRelation>()
|
|
|
+ .select(UserDeptRelation::getId)
|
|
|
+ .select(UserDeptRelation.class, x -> VoToColumnUtil.fieldsToColumns(UserDeptRelation.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(User.class, User::getId, UserDeptRelation::getUserId)
|
|
|
+ .innerJoin(BaseTeacher.class, BaseTeacher::getUserId, User::getId)
|
|
|
+ );
|
|
|
+ Map<Long, UserDeptRelation> userDeptMap = userDeptRelations.stream().collect(Collectors.toMap(UserDeptRelation::getUserId, x -> x));
|
|
|
+
|
|
|
+ List<Post> postList = postService.list(
|
|
|
+ new QueryWrapper<Post>().lambda()
|
|
|
+ .eq(Post::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> postMap = postList.stream().collect(Collectors.toMap(Post::getName, Post::getId));
|
|
|
+
|
|
|
+ List<UserPostRelation> postRelations = userPostRelationService.list(
|
|
|
+ new MPJLambdaWrapper<UserPostRelation>()
|
|
|
+ .select(UserPostRelation::getId)
|
|
|
+ .select(UserPostRelation.class, x -> VoToColumnUtil.fieldsToColumns(UserPostRelation.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(User.class, User::getId, UserPostRelation::getUserId)
|
|
|
+ .innerJoin(BaseTeacher.class, BaseTeacher::getUserId, User::getId)
|
|
|
+ );
|
|
|
+ Map<Long, UserPostRelation> userPostMap = postRelations.stream().collect(Collectors.toMap(UserPostRelation::getUserId, x -> x));
|
|
|
+
|
|
|
+ List<User> updateUserList = new ArrayList<>();
|
|
|
+ List<BaseTeacher> updateTeacherList = new ArrayList<>();
|
|
|
+ List<UserDeptRelation> updateDeptList = new ArrayList<>();
|
|
|
+ List<UserPostRelation> updatePostList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map<Integer, Object> rowData : excelDataList) {
|
|
|
+ String jobCode = rowData.get(0).toString();
|
|
|
+ if(userMap.containsKey(jobCode)){
|
|
|
+ User user = userMap.get(jobCode);
|
|
|
+ user.setName(rowData.get(1).toString());
|
|
|
+ user.setGender(GenderDictionaryEnum.getCode(rowData.get(2).toString()));
|
|
|
+ user.setCredentialType(dictionaryMap.get(rowData.get(3).toString()));
|
|
|
+ user.setCredentialNumber(rowData.get(4).toString());
|
|
|
+ user.setMobile(rowData.get(5).toString());
|
|
|
+ updateUserList.add(user);
|
|
|
+
|
|
|
+ BaseTeacher teacher = teacherMap.get(user.getId());
|
|
|
+ teacher.setEmployType(dictionaryMap.get(rowData.get(6).toString()));
|
|
|
+ updateTeacherList.add(teacher);
|
|
|
+
|
|
|
+ UserDeptRelation userDeptRelation = userDeptMap.get(user.getId());
|
|
|
+ userDeptRelation.setDeptId(departmentMap.get(rowData.get(7).toString()));
|
|
|
+ updateDeptList.add(userDeptRelation);
|
|
|
+
|
|
|
+ UserPostRelation postRelation = userPostMap.get(user.getId());
|
|
|
+ postRelation.setPostId(postMap.get(rowData.get(8).toString()));
|
|
|
+ updatePostList.add(postRelation);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ User user = new User();
|
|
|
+ user.setName(rowData.get(1).toString());
|
|
|
+ user.setGender(GenderDictionaryEnum.getCode(rowData.get(2).toString()));
|
|
|
+ user.setCredentialType(dictionaryMap.get(rowData.get(3).toString()));
|
|
|
+ user.setCredentialNumber(rowData.get(4).toString());
|
|
|
+ user.setMobile(rowData.get(5).toString());
|
|
|
+ user.setCreateDate(LocalDateTime.now());
|
|
|
+ userService.save(user);
|
|
|
+
|
|
|
+ BaseTeacher teacher = new BaseTeacher();
|
|
|
+ teacher.setEmployType(dictionaryMap.get(rowData.get(6).toString()));
|
|
|
+ teacher.setUserId(user.getId());
|
|
|
+ teacher.setCreateDate(LocalDateTime.now());
|
|
|
+ teacherbaseManagerBaseTeacherMapper.insert(teacher);
|
|
|
+
|
|
|
+ UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
|
+ userDeptRelation.setDeptId(departmentMap.get(rowData.get(7).toString()));
|
|
|
+ userDeptRelation.setUserId(user.getId());
|
|
|
+ userDeptRelationMapper.insert(userDeptRelation);
|
|
|
+
|
|
|
+ UserPostRelation postRelation = new UserPostRelation();
|
|
|
+ postRelation.setPostId(postMap.get(rowData.get(8).toString()));
|
|
|
+ postRelation.setUserId(user.getId());
|
|
|
+ userPostRelationService.save(postRelation);
|
|
|
+
|
|
|
+ UserRoleRelation roleRelation = new UserRoleRelation();
|
|
|
+ roleRelation.setUserId(user.getId());
|
|
|
+ roleRelation.setRoleId(RoleEnum.TEACHER.getCode());
|
|
|
+ userRoleRelationMapper.insert(roleRelation);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!updateUserList.isEmpty()){
|
|
|
+ userService.updateBatchById(updateUserList);
|
|
|
+ }
|
|
|
+ if(!updateDeptList.isEmpty()){
|
|
|
+ for (UserDeptRelation relation : updateDeptList) {
|
|
|
+ userDeptRelationMapper.updateById(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!updatePostList.isEmpty()){
|
|
|
+ userPostRelationService.updateBatchById(updatePostList);
|
|
|
+ }
|
|
|
+ if(!updateTeacherList.isEmpty()){
|
|
|
+ for (BaseTeacher teacher : updateTeacherList) {
|
|
|
+ teacherbaseManagerBaseTeacherMapper.updateById(teacher);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<User> list = userService.list();
|
|
|
+ redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
|
|
|
+
|
|
|
+ List<UserDeptRelation> deptRelationList = userDeptRelationMapper.selectList(Wrappers.lambdaQuery(UserDeptRelation.class));
|
|
|
+ redisUtil.set(GlobalConstant.USER_DEPT_RELATION_CACHE_KEY, deptRelationList);
|
|
|
+
|
|
|
+ List<UserRoleRelation> userRoleRelationList = userRoleRelationMapper.selectList(Wrappers.lambdaQuery(UserRoleRelation.class));
|
|
|
+ redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, userRoleRelationList);
|
|
|
+
|
|
|
+ List<UserPostRelation> postRelationList = userPostRelationService.list(Wrappers.lambdaQuery(UserPostRelation.class));
|
|
|
+ redisUtil.set(GlobalConstant.USER_POST_RELATION_CACHE_KEY, postRelationList);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|