| | |
| | | package org.jeecg.modules.system.controller; |
| | | |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | |
| | | import org.jeecg.modules.system.model.SysUserSysDepartModel; |
| | | import org.jeecg.modules.system.service.*; |
| | | import org.jeecg.modules.system.vo.SysDepartUsersVO; |
| | | import org.jeecg.modules.system.vo.SysUserRoleExitVo; |
| | | import org.jeecg.modules.system.vo.SysUserRoleVO; |
| | | import org.jeecgframework.poi.excel.ExcelImportUtil; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | |
| | | } |
| | | //update-end--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据---------------------- |
| | | List<SysUser> pageList = sysUserService.list(queryWrapper); |
| | | |
| | | // 查询用户角色 |
| | | List<String> userIds = pageList.stream().map(SysUser::getId).collect(Collectors.toList()); |
| | | List<SysUserRoleExitVo> userRoleExitVoList = sysUserRoleService.queryRoleNamesByUserIds(userIds); |
| | | if (!CollectionUtil.isEmpty(userRoleExitVoList)) { |
| | | Map<String, String> userRolesMap = userRoleExitVoList.stream().collect(Collectors.toMap(SysUserRoleExitVo::getUsername, SysUserRoleExitVo::getRoleNames)); |
| | | pageList.forEach(user -> { |
| | | if (userRolesMap.containsKey(user.getUsername())) { |
| | | user.setRoleIds(userRolesMap.get(user.getUsername())); |
| | | } |
| | | }); |
| | | } |
| | | //导出文件名称 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表"); |
| | | mv.addObject(NormalExcelConstants.CLASS, SysUser.class); |
| | |
| | | sysUserExcel.setSalt(salt); |
| | | String passwordEncode = PasswordUtil.encrypt(sysUserExcel.getUsername(), sysUserExcel.getPassword(), salt); |
| | | sysUserExcel.setPassword(passwordEncode); |
| | | sysUserExcel.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | sysUserExcel.setPasswordFlag(CommonConstant.DEL_FLAG_1); |
| | | sysUserExcel.setPasswordTime(new Date()); |
| | | try { |
| | | sysUserService.save(sysUserExcel); |
| | | successLines++; |
| | |
| | | } |
| | | userProductionService.saveBatch(userProductionList); |
| | | } |
| | | // 批量将角色和用户信息建立关联关系 |
| | | String roleIds = sysUserExcel.getRoleIds(); |
| | | if (StringUtils.isNotBlank(roleIds)) { |
| | | String userId = sysUserExcel.getId(); |
| | | String[] roleIdArray = roleIds.split(","); |
| | | List<SysUserRole> sysRoleList = new ArrayList<>(roleIdArray.length); |
| | | for (String roleId : roleIdArray) { |
| | | sysRoleList.add(new SysUserRole(userId, roleId)); |
| | | } |
| | | sysUserRoleService.saveBatch(sysRoleList); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | errorMessage.add("发生异常:" + e.getMessage()); |