fix 用户导入导出
This commit is contained in:
+1
-4
@@ -9,10 +9,8 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.modules.quartz.entity.QuartzJob;
|
||||
@@ -22,7 +20,6 @@ import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -259,7 +256,7 @@ public class QuartzJobController {
|
||||
}
|
||||
}
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
return ImportExcelUtil.importReturnRes(errorLines,successLines,errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -381,7 +381,7 @@ public class SysDepartController {
|
||||
Set keys4 = redisTemplate.keys(CacheConstant.SYS_DEPART_IDS_CACHE + "*");
|
||||
redisTemplate.delete(keys3);
|
||||
redisTemplate.delete(keys4);
|
||||
return ImportExcelUtil.imporReturnRes(errorMessageList.size(), listSysDeparts.size() - errorMessageList.size(), errorMessageList);
|
||||
return ImportExcelUtil.importReturnRes(errorMessageList.size(), listSysDeparts.size() - errorMessageList.size(), errorMessageList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("文件导入失败:"+e.getMessage());
|
||||
|
||||
+1
-4
@@ -1,7 +1,6 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -17,7 +16,6 @@ import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.DictQuery;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.common.util.SqlInjectionUtil;
|
||||
@@ -37,7 +35,6 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -520,7 +517,7 @@ public class SysDictController {
|
||||
errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
|
||||
}
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
return ImportExcelUtil.importReturnRes(errorLines,successLines,errorMessage);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("文件导入失败:"+e.getMessage());
|
||||
|
||||
+43
-14
@@ -9,12 +9,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.system.util.UserUtil;
|
||||
import com.jero.modules.system.vo.SysUserVo;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import com.jero.common.api.vo.Result;
|
||||
@@ -116,8 +117,8 @@ public class SysUserController {
|
||||
IPage<SysUserVo> pageList = sysUserService.queryPageListByRoleAndDepart(page, user, roleId, departId);
|
||||
List<SysUserVo> userList = new ArrayList<>();
|
||||
for (SysUserVo record : pageList.getRecords()) {
|
||||
record.setEmail(PasswordUtil.decrypt(record.getEmail()));
|
||||
record.setPhone(PasswordUtil.decrypt(record.getPhone()));
|
||||
//处理邮箱和手机号的加密
|
||||
UserUtil.decryptUser(record);
|
||||
userList.add(record);
|
||||
}
|
||||
pageList.setRecords(userList);
|
||||
@@ -158,8 +159,8 @@ public class SysUserController {
|
||||
IPage<SysUser> pageList = sysUserService.page(page, queryWrapper);
|
||||
List<SysUser> userList = new ArrayList<>();
|
||||
for (SysUser record : pageList.getRecords()) {
|
||||
record.setEmail(PasswordUtil.decrypt(record.getEmail()));
|
||||
record.setPhone(PasswordUtil.decrypt(record.getPhone()));
|
||||
//处理邮箱和手机号的加密
|
||||
UserUtil.decryptUser(record);
|
||||
userList.add(record);
|
||||
}
|
||||
pageList.setRecords(userList);
|
||||
@@ -191,8 +192,8 @@ public class SysUserController {
|
||||
List<SysUser> userList = new ArrayList<>();
|
||||
List<SysUser> records = pageList.getRecords();
|
||||
for (SysUser record : records) {
|
||||
record.setEmail(PasswordUtil.decrypt(record.getEmail()));
|
||||
record.setPhone(PasswordUtil.decrypt(record.getPhone()));
|
||||
//处理邮箱和手机号的加密
|
||||
UserUtil.decryptUser(record);
|
||||
userList.add(record);
|
||||
}
|
||||
pageList.setRecords(userList);
|
||||
@@ -540,12 +541,21 @@ public class SysUserController {
|
||||
}
|
||||
//update-end--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据----------------------
|
||||
List<SysUser> pageList = sysUserService.list(queryWrapper);
|
||||
|
||||
for (SysUser record : pageList) {
|
||||
String username = record.getUsername();
|
||||
String phone = record.getPhone();
|
||||
if (StringUtils.isNotBlank(phone)){
|
||||
record.setPhone(PasswordUtil.decrypt(phone));
|
||||
}
|
||||
List<String> roleIdsByUsername = sysBaseAPI.getRoleIdsByUsername(username);
|
||||
List<String> departIdsByUsername = sysBaseAPI.getDepartIdsByUsername(username);
|
||||
record.setRoleIds(Joiner.on(",").join(roleIdsByUsername));
|
||||
record.setDepartIds(Joiner.on(",").join(departIdsByUsername));
|
||||
}
|
||||
//导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("用户列表数据", "导出人:"+user.getRealname(), "导出信息");
|
||||
ExportParams exportParams = new ExportParams("用户列表数据", "导出信息");
|
||||
exportParams.setImageBasePath(upLoadPath);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
@@ -555,7 +565,7 @@ public class SysUserController {
|
||||
/**
|
||||
* 导出excel模板
|
||||
*/
|
||||
@RequiresPermissions("defect:download:template")
|
||||
@RequiresPermissions("sys:user:import")
|
||||
@ApiOperation(value="用户-导出excel模板", notes="用户-导出excel模板")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
public ModelAndView exportTemplate() {
|
||||
@@ -594,6 +604,7 @@ public class SysUserController {
|
||||
try {
|
||||
List<SysUser> listSysUsers = ExcelImportUtil.importExcel(file.getInputStream(), SysUser.class, params);
|
||||
for (int i = 0; i < listSysUsers.size(); i++) {
|
||||
int lineNumber = i + 3;
|
||||
SysUser sysUserExcel = listSysUsers.get(i);
|
||||
if (StringUtils.isBlank(sysUserExcel.getPassword())) {
|
||||
// 存入默认密码
|
||||
@@ -603,14 +614,22 @@ public class SysUserController {
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
sysUserExcel.setSalt(salt);
|
||||
String passwordEncode = PasswordUtil.encrypt(sysUserExcel.getUsername(), sysUserExcel.getPassword(), salt);
|
||||
try {
|
||||
ValidUtil.validate(sysUserExcel);
|
||||
}catch (JeroBootException e) {
|
||||
errorLines++;
|
||||
errorMessage.add("第 " + lineNumber + " 行:" + e.getMessage());
|
||||
}
|
||||
sysUserExcel.setPassword(passwordEncode);
|
||||
//处理邮箱和手机号的加密
|
||||
UserUtil.encryptUser(sysUserExcel);
|
||||
sysUserExcel.setDelFlag(0);
|
||||
try {
|
||||
sysUserService.save(sysUserExcel);
|
||||
successLines++;
|
||||
} catch (Exception e) {
|
||||
errorLines++;
|
||||
String message = e.getMessage().toLowerCase();
|
||||
int lineNumber = i + 1;
|
||||
// 通过索引名判断出错信息
|
||||
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_USERNAME)) {
|
||||
errorMessage.add("第 " + lineNumber + " 行:用户名已经存在,忽略导入。");
|
||||
@@ -625,10 +644,10 @@ public class SysUserController {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
String userId = sysUserExcel.getId();
|
||||
// 批量将部门和用户信息建立关联关系
|
||||
String departIds = sysUserExcel.getDepartIds();
|
||||
if (StringUtils.isNotBlank(departIds)) {
|
||||
String userId = sysUserExcel.getId();
|
||||
String[] departIdArray = departIds.split(",");
|
||||
List<SysUserDepart> userDepartList = new ArrayList<>(departIdArray.length);
|
||||
for (String departId : departIdArray) {
|
||||
@@ -636,6 +655,16 @@ public class SysUserController {
|
||||
}
|
||||
sysUserDepartService.saveBatch(userDepartList);
|
||||
}
|
||||
//批量处理角色和用户的关联关系
|
||||
String roleIds = sysUserExcel.getRoleIds();
|
||||
if (StringUtils.isNotBlank(roleIds)) {
|
||||
String[] roleIdArray = roleIds.split(",");
|
||||
List<SysUserRole> userRoleList = new ArrayList<>();
|
||||
for (String roleId : roleIdArray) {
|
||||
userRoleList.add(new SysUserRole(userId,roleId));
|
||||
}
|
||||
sysUserRoleService.saveBatch(userRoleList);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -649,7 +678,7 @@ public class SysUserController {
|
||||
}
|
||||
}
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
return ImportExcelUtil.importReturnRes(errorLines,successLines,errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,9 +20,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -48,17 +46,17 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
@Excel(name = "登录账号", width = 15)
|
||||
@NotBlank(message = "账号不能为空")
|
||||
@Size(max = 50,message = "账号最长为50")
|
||||
@Excel(name = "用户账号", width = 15)
|
||||
@NotBlank(message = "用户账号不能为空")
|
||||
@Size(max = 50,message = "用户账号最长为50")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
@Excel(name = "真实姓名", width = 15)
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
@Size(max = 50,message = "姓名最长为50")
|
||||
@Excel(name = "用户姓名", width = 15)
|
||||
@NotBlank(message = "用户姓名不能为空")
|
||||
@Size(max = 50,message = "用户姓名最长为50")
|
||||
private String realname;
|
||||
|
||||
/**
|
||||
@@ -77,13 +75,11 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@Excel(name = "头像", width = 15,type = 2)
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
@Excel(name = "生日", width = 15, format = "yyyy-MM-dd")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date birthday;
|
||||
@@ -91,21 +87,21 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 性别(1:男 2:女)
|
||||
*/
|
||||
@Excel(name = "性别", width = 15,dicCode="sex")
|
||||
@Dict(dicCode = "sex")
|
||||
private Integer sex;
|
||||
|
||||
/**
|
||||
* 电子邮箱
|
||||
*/
|
||||
@Excel(name = "电子邮箱", width = 15)
|
||||
@Email(message = "电子邮箱格式不正确")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
@Excel(name = "电话", width = 15)
|
||||
@Excel(name = "手机号", width = 15)
|
||||
@NotEmpty(message = "手机号不能为空!")
|
||||
@Pattern(regexp = "^((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(17[0135678])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$",message = "手机号码格式错误")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
@@ -119,27 +115,23 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 状态(1:正常 2:冻结 )
|
||||
*/
|
||||
@Excel(name = "状态", width = 15,dicCode="user_status")
|
||||
@Dict(dicCode = "user_status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 删除状态(0,正常,1已删除)
|
||||
*/
|
||||
@Excel(name = "删除状态", width = 15,dicCode="del_flag")
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 工号,唯一键
|
||||
*/
|
||||
@Excel(name = "工号", width = 15)
|
||||
private String workNo;
|
||||
|
||||
/**
|
||||
* 座机号
|
||||
*/
|
||||
@Excel(name = "座机号", width = 15)
|
||||
private String telephone;
|
||||
|
||||
/**
|
||||
@@ -150,6 +142,9 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "创建时间", orderNum = "1",format = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
@@ -171,13 +166,6 @@ public class SysUser implements Serializable {
|
||||
*/
|
||||
private Integer userIdentity;
|
||||
|
||||
/**
|
||||
* 负责部门
|
||||
*/
|
||||
@Excel(name="负责部门",width = 15,dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
|
||||
@Dict(dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
|
||||
private String departIds;
|
||||
|
||||
/**
|
||||
* 角色类型
|
||||
*/
|
||||
@@ -185,6 +173,13 @@ public class SysUser implements Serializable {
|
||||
@Dict(dictTable ="sys_role",dicText = "role_name",dicCode = "id")
|
||||
private String roleIds;
|
||||
|
||||
/**
|
||||
* 组织机构
|
||||
*/
|
||||
@Excel(name="组织机构",width = 15,dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
|
||||
@Dict(dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
|
||||
private String departIds;
|
||||
|
||||
/**
|
||||
* 多租户id配置,编辑用户的时候设置
|
||||
*/
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
List<String> list = ImportExcelUtil.importDateSave(listSysRoles, ISysRoleService.class, errorStrs, CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE);
|
||||
errorLines+=list.size();
|
||||
successLines+=(listSysRoles.size()-errorLines);
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,list);
|
||||
return ImportExcelUtil.importReturnRes(errorLines,successLines,list);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.jero.modules.system.util;
|
||||
|
||||
import com.jero.common.util.PasswordUtil;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
* @date 2021-08-30 16:42
|
||||
*/
|
||||
public class UserUtil {
|
||||
/**
|
||||
* 解密密文SysUser手机号邮箱
|
||||
*
|
||||
* @param record
|
||||
* SysUser
|
||||
*/
|
||||
public static void decryptUser(SysUser record) {
|
||||
//处理邮箱和手机号的加密
|
||||
String email = record.getEmail();
|
||||
if (StringUtils.isNotBlank(email)){
|
||||
record.setEmail(PasswordUtil.decrypt(email));
|
||||
}
|
||||
String phone = record.getPhone();
|
||||
if (StringUtils.isNotBlank(phone)){
|
||||
record.setPhone(PasswordUtil.decrypt(phone));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密密文SysUser手机号邮箱
|
||||
*
|
||||
* @param record
|
||||
* SysUser
|
||||
*/
|
||||
public static void encryptUser(SysUser record) {
|
||||
//处理邮箱和手机号的加密
|
||||
String email = record.getEmail();
|
||||
if (StringUtils.isNotBlank(email)){
|
||||
record.setEmail(PasswordUtil.encrypt(email));
|
||||
}
|
||||
String phone = record.getPhone();
|
||||
if (StringUtils.isNotBlank(phone)){
|
||||
record.setPhone(PasswordUtil.encrypt(phone));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user