|
@@ -10,6 +10,8 @@ import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.paper.library.common.bean.auth.AuthBean;
|
|
import com.qmth.paper.library.common.bean.auth.AuthBean;
|
|
import com.qmth.paper.library.common.bean.dto.UserDto;
|
|
import com.qmth.paper.library.common.bean.dto.UserDto;
|
|
import com.qmth.paper.library.common.bean.dto.VerifyCodeCheckDto;
|
|
import com.qmth.paper.library.common.bean.dto.VerifyCodeCheckDto;
|
|
|
|
+import com.qmth.paper.library.common.bean.dto.excel.DescribeImportDto;
|
|
|
|
+import com.qmth.paper.library.common.bean.dto.excel.SysUserImportDto;
|
|
import com.qmth.paper.library.common.bean.params.ApproveUserResult;
|
|
import com.qmth.paper.library.common.bean.params.ApproveUserResult;
|
|
import com.qmth.paper.library.common.bean.params.UserSaveParams;
|
|
import com.qmth.paper.library.common.bean.params.UserSaveParams;
|
|
import com.qmth.paper.library.common.bean.result.LoginResult;
|
|
import com.qmth.paper.library.common.bean.result.LoginResult;
|
|
@@ -30,9 +32,11 @@ import com.qmth.paper.library.common.util.Base64Util;
|
|
import com.qmth.paper.library.common.util.ResultUtil;
|
|
import com.qmth.paper.library.common.util.ResultUtil;
|
|
import com.qmth.paper.library.common.util.ServletUtil;
|
|
import com.qmth.paper.library.common.util.ServletUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
@@ -75,6 +79,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
@Resource
|
|
@Resource
|
|
SysUserService sysUserService;
|
|
SysUserService sysUserService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ SysOrgService sysOrgService;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
DictionaryConfig dictionaryConfig;
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
|
@@ -103,6 +110,78 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
return userDtoIPage;
|
|
return userDtoIPage;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> executeSysUserImportLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
|
|
|
|
+ SysUser requestUser = (SysUser) map.get(SystemConstant.SYS_USER);
|
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
|
+ List<Long> userIdList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
|
|
+ List<Object> sysUserImportDtoList = excelMap.get(i);
|
|
|
|
+ assert sysUserImportDtoList != null;
|
|
|
|
+ if (sysUserImportDtoList.get(0) instanceof DescribeImportDto) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理机构
|
|
|
|
+ if (sysUserImportDtoList.get(0) instanceof SysUserImportDto) {
|
|
|
|
+ List<SysUserImportDto> datasource = sysUserImportDtoList.stream().map(e -> {
|
|
|
|
+ SysUserImportDto sysUserImportDto = new SysUserImportDto();
|
|
|
|
+ BeanUtils.copyProperties(e, sysUserImportDto);
|
|
|
|
+ return sysUserImportDto;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ // 机构信息
|
|
|
|
+ List<String> orgInfoList = datasource.stream().map(SysUserImportDto::getOrgName).distinct().collect(Collectors.toList());
|
|
|
|
+ // 提前创建或获取机构信息并存入map
|
|
|
|
+ Map<String, Long> orgInfoMap = sysOrgService.createOrGetOrgByOrgInfo(orgInfoList, requestUser);
|
|
|
|
+ for (SysUserImportDto sysUserImportDto : datasource) {
|
|
|
|
+ String name = sysUserImportDto.getName();
|
|
|
|
+ String loginName = sysUserImportDto.getLoginName();
|
|
|
|
+ String phoneNumber = sysUserImportDto.getPhoneNumber();
|
|
|
|
+ String orgName = sysUserImportDto.getOrgName();
|
|
|
|
+ if (!orgInfoMap.containsKey(orgName)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("在解析的机构map集合中,没有找到excel数据中的用户机构名称【" + orgName + "】");
|
|
|
|
+ }
|
|
|
|
+ // 直接解析机构id
|
|
|
|
+ Long orgId = orgInfoMap.get(orgName);
|
|
|
|
+ String roleName = sysUserImportDto.getRoleName();
|
|
|
|
+
|
|
|
|
+ UserSaveParams userSaveParams = new UserSaveParams();
|
|
|
|
+
|
|
|
|
+ LinkedHashSet<Long> roleIdList = this.analyzeRoleName(schoolId, roleName);
|
|
|
|
+
|
|
|
|
+ SysUser oldUser = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getLoginName, loginName).eq(SysUser::getSchoolId, schoolId));
|
|
|
|
+ Long oldUserId = null;
|
|
|
|
+ Set<Long> oldRoleIdSet = new HashSet<>();
|
|
|
|
+ if (Objects.nonNull(oldUser)) {
|
|
|
|
+ oldUserId = oldUser.getId();
|
|
|
|
+ oldRoleIdSet = new HashSet<>(sysRoleService.getUserRoles(oldUserId));
|
|
|
|
+ }
|
|
|
|
+ String code = loginName;
|
|
|
|
+ if (SystemConstant.longNotNull(oldUserId)) {
|
|
|
|
+ // 编辑
|
|
|
|
+ userSaveParams.setId(oldUserId);
|
|
|
|
+ loginName = oldUser.getLoginName();
|
|
|
|
+ }
|
|
|
|
+ userSaveParams.setOrgId(orgId);
|
|
|
|
+ userSaveParams.setRealName(name);
|
|
|
|
+ userSaveParams.setLoginName(loginName);
|
|
|
|
+ userSaveParams.setRoleIds(roleIdList.toArray(new Long[0]));
|
|
|
|
+ if (SystemConstant.strNotNull(phoneNumber)) {
|
|
|
|
+ userSaveParams.setMobileNumber(phoneNumber);
|
|
|
|
+ }
|
|
|
|
+ userSaveParams.setCode(code);
|
|
|
|
+ userSaveParams.setSchoolId(schoolId);
|
|
|
|
+ Long upUserId = this.saveUserCommon(userSaveParams, requestUser.getId());
|
|
|
|
+ userIdList.add(upUserId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("userIdList", userIdList);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
public Long saveUser(UserSaveParams userSaveParams) {
|
|
public Long saveUser(UserSaveParams userSaveParams) {
|
|
@@ -532,4 +611,31 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据角色名称获取角色id集合
|
|
|
|
+ *
|
|
|
|
+ * @param schoolId 学校id
|
|
|
|
+ * @param roleName 角色名称组
|
|
|
|
+ * @return 角色集合
|
|
|
|
+ */
|
|
|
|
+ private LinkedHashSet<Long> analyzeRoleName(Long schoolId, String roleName) {
|
|
|
|
+ LinkedHashSet<Long> roleIdList = new LinkedHashSet<>();
|
|
|
|
+ String[] arr = roleName.split(SystemConstant.COMMA);
|
|
|
|
+ for (String cell : arr) {
|
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getEnable, true)
|
|
|
|
+ .eq(SysRole::getName, cell);
|
|
|
|
+ if (Objects.isNull(RoleTypeEnum.convertDescToEnum(cell))) {
|
|
|
|
+ // 自定义角色带学校id查
|
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getSchoolId, schoolId);
|
|
|
|
+ }
|
|
|
|
+ SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
|
|
+ if (Objects.isNull(sysRole)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("系统中不存在excel导入的角色【" + cell + "】");
|
|
|
|
+ }
|
|
|
|
+ roleIdList.add(sysRole.getId());
|
|
|
|
+ }
|
|
|
|
+ return roleIdList;
|
|
|
|
+ }
|
|
}
|
|
}
|