update some code
This commit is contained in:
parent
e25faebd30
commit
1a3de75590
41
.idea/workspace.xml
generated
41
.idea/workspace.xml
generated
@ -2,16 +2,21 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e4baaf01-a2c2-445d-98a1-9f4c50c148cf" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/app/Dto/UserDto.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/job/business/FeishuBusiness.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/job/business/FeishuBusiness.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/controller/SysLoginController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/controller/SysLoginController.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/app/entity/UserEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/app/entity/UserEntity.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/controller/SysUserController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/controller/SysUserController.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application-dev.yml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/resources/mapper/generator/StaffOccupationDao.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/mapper/generator/StaffOccupationDao.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/application-dev.yml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/job/business/FeishuBusiness.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/job/business/FeishuBusiness.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/controller/SysLoginController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/controller/SysLoginController.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/dao/SysUserDao.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/dao/SysUserDao.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/entity/SysUserEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/entity/SysUserEntity.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/resources/logback-spring.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/logback-spring.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/resources/mapper/sys/SysUserDao.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/mapper/sys/SysUserDao.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/app/entity/UserEntity.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/app/entity/UserEntity.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/app/service/impl/StaffServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/app/service/impl/StaffServiceImpl.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/controller/SysUserController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/controller/SysUserController.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/entity/SysUserEntity.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/entity/SysUserEntity.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/service/impl/SysUserServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/lz/modules/sys/service/impl/SysUserServiceImpl.class" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -57,8 +62,8 @@
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyClassDialog.RECENTS_KEY">
|
||||
<recent name="com.lz.common.utils" />
|
||||
<recent name="com.lz.modules.app.Dto" />
|
||||
<recent name="com.lz.common.utils" />
|
||||
<recent name="com.lz.modules.app.enums" />
|
||||
<recent name="com.lz.modules.app.entity.excel" />
|
||||
<recent name="com.lz.modules.job.model.responseBo" />
|
||||
@ -179,7 +184,7 @@
|
||||
<workItem from="1588163384182" duration="74761000" />
|
||||
<workItem from="1588936950753" duration="95758000" />
|
||||
<workItem from="1590038091791" duration="38394000" />
|
||||
<workItem from="1590136970394" duration="14639000" />
|
||||
<workItem from="1590136970394" duration="24193000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@ -204,13 +209,23 @@
|
||||
<breakpoints>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<url>file://$PROJECT_DIR$/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java</url>
|
||||
<line>233</line>
|
||||
<line>232</line>
|
||||
<option name="timeStamp" value="104" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<url>file://$PROJECT_DIR$/src/main/java/com/lz/common/utils/FeishuUtil.java</url>
|
||||
<line>144</line>
|
||||
<option name="timeStamp" value="112" />
|
||||
<url>file://$PROJECT_DIR$/src/main/java/com/lz/modules/sys/controller/SysUserController.java</url>
|
||||
<line>121</line>
|
||||
<option name="timeStamp" value="114" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<url>file://$PROJECT_DIR$/src/main/java/com/lz/modules/sys/controller/SysUserController.java</url>
|
||||
<line>139</line>
|
||||
<option name="timeStamp" value="115" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<url>file://$PROJECT_DIR$/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java</url>
|
||||
<line>57</line>
|
||||
<option name="timeStamp" value="117" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
|
||||
94
src/main/java/com/lz/modules/app/Dto/UserDto.java
Normal file
94
src/main/java/com/lz/modules/app/Dto/UserDto.java
Normal file
@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Copyright (c) 2020 fumeiai All rights reserved.
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.lz.modules.app.Dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*
|
||||
* @author fumeiai@Linzikg.com
|
||||
*/
|
||||
@Data
|
||||
public class UserDto implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableId
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 员工姓名
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 员工工号
|
||||
*/
|
||||
private String userNo;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 盐
|
||||
*/
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
|
||||
/**
|
||||
* 状态 0:禁用 1:正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 角色ID列表
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<Long> roleIdList;
|
||||
|
||||
/**
|
||||
* 创建者ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
private String roleName;
|
||||
|
||||
}
|
||||
@ -22,7 +22,7 @@ import java.util.Date;
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Data
|
||||
@TableName("tb_user")
|
||||
@TableName("sys_user")
|
||||
public class UserEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -31,6 +31,12 @@ public class UserEntity implements Serializable {
|
||||
*/
|
||||
@TableId
|
||||
private Long userId;
|
||||
|
||||
private String realName;
|
||||
|
||||
private String userNo;
|
||||
|
||||
private String status;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.lz.modules.app.service.impl;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2020 fumeiai All rights reserved.
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.lz.modules.sys.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.lz.common.annotation.SysLog;
|
||||
import com.lz.common.utils.Constant;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
@ -16,6 +17,7 @@ import com.lz.common.validator.Assert;
|
||||
import com.lz.common.validator.ValidatorUtils;
|
||||
import com.lz.common.validator.group.AddGroup;
|
||||
import com.lz.common.validator.group.UpdateGroup;
|
||||
import com.lz.modules.app.entity.UserEntity;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.form.PasswordForm;
|
||||
import com.lz.modules.sys.service.SysUserRoleService;
|
||||
@ -37,123 +39,129 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/sys/user")
|
||||
public class SysUserController extends AbstractController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
|
||||
/**
|
||||
* 所有用户列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:user:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
//只有超级管理员,才能查看所有管理员列表
|
||||
if(getUserId() != Constant.SUPER_ADMIN){
|
||||
params.put("createUserId", getUserId());
|
||||
}
|
||||
PageUtils page = sysUserService.queryPage(params);
|
||||
/**
|
||||
* 所有用户列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("sys:user:list")
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
//只有超级管理员,才能查看所有管理员列表
|
||||
if (getUserId() != Constant.SUPER_ADMIN) {
|
||||
params.put("createUserId", getUserId());
|
||||
}
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
PageUtils page = sysUserService.queryPage(params);
|
||||
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public R info(){
|
||||
return R.ok().put("user", getUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改登录用户密码
|
||||
*/
|
||||
@SysLog("修改密码")
|
||||
@PostMapping("/password")
|
||||
public R password(@RequestBody PasswordForm form){
|
||||
Assert.isBlank(form.getNewPassword(), "新密码不为能空");
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
//sha256加密
|
||||
String password = new Sha256Hash(form.getPassword(), getUser().getSalt()).toHex();
|
||||
//sha256加密
|
||||
String newPassword = new Sha256Hash(form.getNewPassword(), getUser().getSalt()).toHex();
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public R info() {
|
||||
return R.ok().put("user", getUser());
|
||||
}
|
||||
|
||||
//更新密码
|
||||
boolean flag = sysUserService.updatePassword(getUserId(), password, newPassword);
|
||||
if(!flag){
|
||||
return R.error("原密码不正确");
|
||||
}
|
||||
/**
|
||||
* 修改登录用户密码
|
||||
*/
|
||||
@SysLog("修改密码")
|
||||
@PostMapping("/password")
|
||||
public R password(@RequestBody PasswordForm form) {
|
||||
Assert.isBlank(form.getNewPassword(), "新密码不为能空");
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
//sha256加密
|
||||
String password = new Sha256Hash(form.getPassword(), getUser().getSalt()).toHex();
|
||||
//sha256加密
|
||||
String newPassword = new Sha256Hash(form.getNewPassword(), getUser().getSalt()).toHex();
|
||||
|
||||
public static void main(String[] args) {
|
||||
String newPassword = new Sha256Hash("Linzi!@#123", "YzcmCZNvbXocrsz9dm8e").toHex();
|
||||
System.out.println(newPassword);
|
||||
}
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@GetMapping("/info/{userId}")
|
||||
@RequiresPermissions("sys:user:info")
|
||||
public R info(@PathVariable("userId") Long userId){
|
||||
SysUserEntity user = sysUserService.getById(userId);
|
||||
//更新密码
|
||||
boolean flag = sysUserService.updatePassword(getUserId(), password, newPassword);
|
||||
if (!flag) {
|
||||
return R.error("原密码不正确");
|
||||
}
|
||||
|
||||
//获取用户所属的角色列表
|
||||
List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
|
||||
user.setRoleIdList(roleIdList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
return R.ok().put("user", user);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
String newPassword = new Sha256Hash("Linzi!@#123", "YzcmCZNvbXocrsz9dm8e").toHex();
|
||||
System.out.println(newPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*/
|
||||
@SysLog("保存用户")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:user:save")
|
||||
public R save(@RequestBody SysUserEntity user){
|
||||
ValidatorUtils.validateEntity(user, AddGroup.class);
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@GetMapping("/info/{userId}")
|
||||
@RequiresPermissions("sys:user:info")
|
||||
public R info(@PathVariable("userId") Long userId) {
|
||||
SysUserEntity user = sysUserService.getById(userId);
|
||||
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.saveUser(user);
|
||||
//获取用户所属的角色列表
|
||||
List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
|
||||
user.setRoleIdList(roleIdList);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
return R.ok().put("user", user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@SysLog("修改用户")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:user:update")
|
||||
public R update(@RequestBody SysUserEntity user){
|
||||
ValidatorUtils.validateEntity(user, UpdateGroup.class);
|
||||
/**
|
||||
* 保存用户
|
||||
*/
|
||||
@SysLog("保存用户")
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("sys:user:save")
|
||||
public R save(@RequestBody SysUserEntity user) {
|
||||
ValidatorUtils.validateEntity(user, AddGroup.class);
|
||||
SysUserEntity queryUser = sysUserService.getOne(new QueryWrapper<SysUserEntity>().eq("mobile", user.getMobile()));
|
||||
if (queryUser != null) {
|
||||
return R.error("该手机号已存在,请重新输入!");
|
||||
}
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.saveUser(user);
|
||||
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.update(user);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@SysLog("修改用户")
|
||||
@PostMapping("/update")
|
||||
@RequiresPermissions("sys:user:update")
|
||||
public R update(@RequestBody SysUserEntity user) {
|
||||
ValidatorUtils.validateEntity(user, UpdateGroup.class);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@SysLog("删除用户")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:user:delete")
|
||||
public R delete(@RequestBody Long[] userIds){
|
||||
if(ArrayUtils.contains(userIds, 1L)){
|
||||
return R.error("系统管理员不能删除");
|
||||
}
|
||||
user.setCreateUserId(getUserId());
|
||||
sysUserService.update(user);
|
||||
|
||||
if(ArrayUtils.contains(userIds, getUserId())){
|
||||
return R.error("当前用户不能删除");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
sysUserService.deleteBatch(userIds);
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@SysLog("删除用户")
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:user:delete")
|
||||
public R delete(@RequestBody Long[] userIds) {
|
||||
if (ArrayUtils.contains(userIds, 1L)) {
|
||||
return R.error("系统管理员不能删除");
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
if (ArrayUtils.contains(userIds, getUserId())) {
|
||||
return R.error("当前用户不能删除");
|
||||
}
|
||||
|
||||
sysUserService.deleteBatch(userIds);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2020 fumeiai All rights reserved.
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.lz.modules.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lz.modules.app.Dto.UserDto;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@ -22,20 +23,24 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SysUserDao extends BaseMapper<SysUserEntity> {
|
||||
|
||||
/**
|
||||
* 查询用户的所有权限
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
List<String> queryAllPerms(Long userId);
|
||||
/**
|
||||
* 查询用户的所有权限
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
List<String> queryAllPerms(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户的所有菜单ID
|
||||
*/
|
||||
List<Long> queryAllMenuId(Long userId);
|
||||
/**
|
||||
* 查询用户的所有菜单ID
|
||||
*/
|
||||
List<Long> queryAllMenuId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户名,查询系统用户
|
||||
*/
|
||||
SysUserEntity queryByUserName(String username);
|
||||
/**
|
||||
* 根据用户名,查询系统用户
|
||||
*/
|
||||
SysUserEntity queryByUserName(String username);
|
||||
|
||||
List<UserDto> getUserInfos(String realName, Long createUserId, String mobile, String roleName, int pageLimit, int startIndex);
|
||||
|
||||
int getTotalCount(String realName, Long createUserId, String mobile, String roleName);
|
||||
|
||||
}
|
||||
|
||||
@ -37,10 +37,22 @@ public class SysUserEntity implements Serializable {
|
||||
@TableId
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 员工姓名
|
||||
*/
|
||||
@NotBlank(message="员工姓名不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 员工工号
|
||||
*/
|
||||
@NotBlank(message="工号不能为空", groups = AddGroup.class)
|
||||
private String userNo;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message="用户名不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
@NotBlank(message="账号不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
private String username;
|
||||
|
||||
/**
|
||||
@ -49,22 +61,25 @@ public class SysUserEntity implements Serializable {
|
||||
@NotBlank(message="密码不能为空", groups = AddGroup.class)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@NotBlank(message="手机号不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 盐
|
||||
*/
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@NotBlank(message="邮箱不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
// /**
|
||||
// * 邮箱
|
||||
// */
|
||||
// @NotBlank(message="邮箱不能为空", groups = {AddGroup.class, UpdateGroup.class})
|
||||
@Email(message="邮箱格式不正确", groups = {AddGroup.class, UpdateGroup.class})
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
|
||||
/**
|
||||
* 状态 0:禁用 1:正常
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) 2020 fumeiai All rights reserved.
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
@ -15,6 +15,7 @@ import com.lz.common.exception.RRException;
|
||||
import com.lz.common.utils.Constant;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.Query;
|
||||
import com.lz.modules.app.Dto.UserDto;
|
||||
import com.lz.modules.sys.dao.SysUserDao;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.service.SysRoleService;
|
||||
@ -40,106 +41,117 @@ import java.util.Map;
|
||||
*/
|
||||
@Service("sysUserService")
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String username = (String)params.get("username");
|
||||
Long createUserId = (Long)params.get("createUserId");
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String realName = (String) params.get("realName");
|
||||
Long createUserId = (Long) params.get("createUserId");
|
||||
String mobile = (String) params.get("mobile");
|
||||
String roleName = (String) params.get("roleName");
|
||||
|
||||
IPage<SysUserEntity> page = this.page(
|
||||
new Query<SysUserEntity>().getPage(params),
|
||||
new QueryWrapper<SysUserEntity>()
|
||||
.like(StringUtils.isNotBlank(username),"username", username)
|
||||
.eq(createUserId != null,"create_user_id", createUserId)
|
||||
);
|
||||
int pageSize = 20;
|
||||
int currPage = 1;
|
||||
if (params.containsKey("limit")) {
|
||||
pageSize = Integer.parseInt(params.get("limit").toString());
|
||||
}
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
if (params.containsKey("page")) {
|
||||
currPage = Integer.parseInt(params.get("page").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryAllPerms(Long userId) {
|
||||
return baseMapper.queryAllPerms(userId);
|
||||
}
|
||||
List<UserDto> users = sysUserDao.getUserInfos(realName, createUserId, mobile, roleName, pageSize, (currPage - 1) * pageSize);
|
||||
int totalCount = sysUserDao.getTotalCount(realName, createUserId, mobile, roleName);
|
||||
PageUtils pageInfo = new PageUtils(users, totalCount, pageSize, currPage);
|
||||
|
||||
@Override
|
||||
public List<Long> queryAllMenuId(Long userId) {
|
||||
return baseMapper.queryAllMenuId(userId);
|
||||
}
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity queryByUserName(String username) {
|
||||
return baseMapper.queryByUserName(username);
|
||||
}
|
||||
@Override
|
||||
public List<String> queryAllPerms(Long userId) {
|
||||
return baseMapper.queryAllPerms(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveUser(SysUserEntity user) {
|
||||
user.setCreateTime(new Date());
|
||||
//sha256加密
|
||||
String salt = RandomStringUtils.randomAlphanumeric(20);
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||
user.setSalt(salt);
|
||||
this.save(user);
|
||||
@Override
|
||||
public List<Long> queryAllMenuId(Long userId) {
|
||||
return baseMapper.queryAllMenuId(userId);
|
||||
}
|
||||
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
@Override
|
||||
public SysUserEntity queryByUserName(String username) {
|
||||
return baseMapper.queryByUserName(username);
|
||||
}
|
||||
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveUser(SysUserEntity user) {
|
||||
user.setCreateTime(new Date());
|
||||
//sha256加密
|
||||
String salt = RandomStringUtils.randomAlphanumeric(20);
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||
user.setSalt(salt);
|
||||
this.save(user);
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(SysUserEntity user) {
|
||||
if(StringUtils.isBlank(user.getPassword())){
|
||||
user.setPassword(null);
|
||||
}else{
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), user.getSalt()).toHex());
|
||||
}
|
||||
this.updateById(user);
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(SysUserEntity user) {
|
||||
if (StringUtils.isBlank(user.getPassword())) {
|
||||
user.setPassword(null);
|
||||
} else {
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), user.getSalt()).toHex());
|
||||
}
|
||||
this.updateById(user);
|
||||
|
||||
@Override
|
||||
public void deleteBatch(Long[] userId) {
|
||||
this.removeByIds(Arrays.asList(userId));
|
||||
}
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
@Override
|
||||
public boolean updatePassword(Long userId, String password, String newPassword) {
|
||||
SysUserEntity userEntity = new SysUserEntity();
|
||||
userEntity.setPassword(newPassword);
|
||||
return this.update(userEntity,
|
||||
new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
|
||||
}
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查角色是否越权
|
||||
*/
|
||||
private void checkRole(SysUserEntity user){
|
||||
if(user.getRoleIdList() == null || user.getRoleIdList().size() == 0){
|
||||
return;
|
||||
}
|
||||
//如果不是超级管理员,则需要判断用户的角色是否自己创建
|
||||
if(user.getCreateUserId() == Constant.SUPER_ADMIN){
|
||||
return ;
|
||||
}
|
||||
@Override
|
||||
public void deleteBatch(Long[] userId) {
|
||||
this.removeByIds(Arrays.asList(userId));
|
||||
}
|
||||
|
||||
//查询用户创建的角色列表
|
||||
List<Long> roleIdList = sysRoleService.queryRoleIdList(user.getCreateUserId());
|
||||
@Override
|
||||
public boolean updatePassword(Long userId, String password, String newPassword) {
|
||||
SysUserEntity userEntity = new SysUserEntity();
|
||||
userEntity.setPassword(newPassword);
|
||||
return this.update(userEntity,
|
||||
new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
|
||||
}
|
||||
|
||||
//判断是否越权
|
||||
if(!roleIdList.containsAll(user.getRoleIdList())){
|
||||
throw new RRException("新增用户所选角色,不是本人创建");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查角色是否越权
|
||||
*/
|
||||
private void checkRole(SysUserEntity user) {
|
||||
if (user.getRoleIdList() == null || user.getRoleIdList().size() == 0) {
|
||||
return;
|
||||
}
|
||||
//如果不是超级管理员,则需要判断用户的角色是否自己创建
|
||||
if (user.getCreateUserId() == Constant.SUPER_ADMIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
//查询用户创建的角色列表
|
||||
List<Long> roleIdList = sysRoleService.queryRoleIdList(user.getCreateUserId());
|
||||
|
||||
//判断是否越权
|
||||
if (!roleIdList.containsAll(user.getRoleIdList())) {
|
||||
throw new RRException("新增用户所选角色,不是本人创建");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,23 +2,58 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.lz.modules.sys.dao.SysUserDao">
|
||||
<!-- 查询用户的所有权限 -->
|
||||
<select id="queryAllPerms" resultType="string">
|
||||
<!-- 查询用户的所有权限 -->
|
||||
<select id="queryAllPerms" resultType="string">
|
||||
select m.perms from sys_user_role ur
|
||||
LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
|
||||
LEFT JOIN sys_menu m on rm.menu_id = m.menu_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!-- 查询用户的所有菜单ID -->
|
||||
<select id="queryAllMenuId" resultType="long">
|
||||
<!-- 查询用户的所有菜单ID -->
|
||||
<select id="queryAllMenuId" resultType="long">
|
||||
select distinct rm.menu_id from sys_user_role ur
|
||||
LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="queryByUserName" resultType="com.lz.modules.sys.entity.SysUserEntity">
|
||||
<select id="queryByUserName" resultType="com.lz.modules.sys.entity.SysUserEntity">
|
||||
select * from sys_user where username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="getUserInfos" resultType="com.lz.modules.app.Dto.UserDto">
|
||||
select su.*,sr.role_name from sys_user su left join sys_user_role sur on su.user_id=sur.user_id left join sys_role sr on
|
||||
sur.role_id=sr.role_id where 1=1
|
||||
<if test="realName != null and realName != ''">
|
||||
and su.real_name like concat('%',#{realName},'%')
|
||||
</if>
|
||||
<if test="createUserId != null and createUserId != ''">
|
||||
and su.create_user_id =#{createUserId}
|
||||
</if>
|
||||
<if test="mobile != null and mobile != ''">
|
||||
and su.mobile = #{mobile}
|
||||
</if>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
and sr.role_name like concat('%',#{roleName},'%')
|
||||
</if>
|
||||
limit #{startIndex}, #{pageLimit}
|
||||
</select>
|
||||
|
||||
<select id="getTotalCount" resultType="java.lang.Integer">
|
||||
select count(su.user_id) from sys_user su left join sys_user_role sur on su.user_id=sur.user_id left join sys_role sr on
|
||||
sur.role_id=sr.role_id where 1=1
|
||||
<if test="realName != null and realName != ''">
|
||||
and su.real_name like concat('%',#{realName},'%')
|
||||
</if>
|
||||
<if test="createUserId != null and createUserId != ''">
|
||||
and su.create_user_id =#{createUserId}
|
||||
</if>
|
||||
<if test="mobile != null and mobile != ''">
|
||||
and su.mobile = #{mobile}
|
||||
</if>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
and sr.role_name like concat('%',#{roleName},'%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
BIN
target/classes/com/lz/modules/app/Dto/UserDto.class
Normal file
BIN
target/classes/com/lz/modules/app/Dto/UserDto.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,7 +8,7 @@
|
||||
<springProfile name="dev,test">
|
||||
<logger name="org.springframework.web" level="INFO"/>
|
||||
<logger name="org.springboot.sample" level="INFO" />
|
||||
<!-- <logger name="com.lz.modules.app.dao" level="DEBUG" />-->
|
||||
<logger name="com.lz.modules.app.dao" level="DEBUG" />
|
||||
<logger name="io.lz" level="DEBUG" />
|
||||
</springProfile>
|
||||
|
||||
|
||||
@ -2,23 +2,58 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.lz.modules.sys.dao.SysUserDao">
|
||||
<!-- 查询用户的所有权限 -->
|
||||
<select id="queryAllPerms" resultType="string">
|
||||
<!-- 查询用户的所有权限 -->
|
||||
<select id="queryAllPerms" resultType="string">
|
||||
select m.perms from sys_user_role ur
|
||||
LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
|
||||
LEFT JOIN sys_menu m on rm.menu_id = m.menu_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!-- 查询用户的所有菜单ID -->
|
||||
<select id="queryAllMenuId" resultType="long">
|
||||
<!-- 查询用户的所有菜单ID -->
|
||||
<select id="queryAllMenuId" resultType="long">
|
||||
select distinct rm.menu_id from sys_user_role ur
|
||||
LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="queryByUserName" resultType="com.lz.modules.sys.entity.SysUserEntity">
|
||||
<select id="queryByUserName" resultType="com.lz.modules.sys.entity.SysUserEntity">
|
||||
select * from sys_user where username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="getUserInfos" resultType="com.lz.modules.app.Dto.UserDto">
|
||||
select su.*,sr.role_name from sys_user su left join sys_user_role sur on su.user_id=sur.user_id left join sys_role sr on
|
||||
sur.role_id=sr.role_id where 1=1
|
||||
<if test="realName != null and realName != ''">
|
||||
and su.real_name like concat('%',#{realName},'%')
|
||||
</if>
|
||||
<if test="createUserId != null and createUserId != ''">
|
||||
and su.create_user_id =#{createUserId}
|
||||
</if>
|
||||
<if test="mobile != null and mobile != ''">
|
||||
and su.mobile = #{mobile}
|
||||
</if>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
and sr.role_name like concat('%',#{roleName},'%')
|
||||
</if>
|
||||
limit #{startIndex}, #{pageLimit}
|
||||
</select>
|
||||
|
||||
<select id="getTotalCount" resultType="java.lang.Integer">
|
||||
select count(su.user_id) from sys_user su left join sys_user_role sur on su.user_id=sur.user_id left join sys_role sr on
|
||||
sur.role_id=sr.role_id where 1=1
|
||||
<if test="realName != null and realName != ''">
|
||||
and su.real_name like concat('%',#{realName},'%')
|
||||
</if>
|
||||
<if test="createUserId != null and createUserId != ''">
|
||||
and su.create_user_id =#{createUserId}
|
||||
</if>
|
||||
<if test="mobile != null and mobile != ''">
|
||||
and su.mobile = #{mobile}
|
||||
</if>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
and sr.role_name like concat('%',#{roleName},'%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user