用户逻辑删除&不允许删除修改管理员

master
RuoYi 7 years ago committed by Limy
parent 1e89cf769b
commit cb931cedbf

@ -48,23 +48,22 @@ create table sys_user (
avatar varchar(100) default '' comment '头像路径', avatar varchar(100) default '' comment '头像路径',
password varchar(100) default '' comment '密码', password varchar(100) default '' comment '密码',
salt varchar(100) default '' comment '盐加密', salt varchar(100) default '' comment '盐加密',
user_type char(1) default 'N' comment '类型:Y默认用户,N非默认用户', status int(1) default 0 comment '帐号状态0正常 1禁用 2删除',
status int(1) default 0 comment '帐号状态:0正常,1禁用',
refuse_des varchar(500) default '' comment '拒绝登录描述',
login_ip varchar(100) default '' comment '最后登陆IP', login_ip varchar(100) default '' comment '最后登陆IP',
login_date datetime comment '最后登陆时间', login_date datetime comment '最后登陆时间',
create_by varchar(64) default '' comment '创建者', create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间', create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者', update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间', update_time datetime comment '更新时间',
remark varchar(500) default '' comment '备注',
primary key (user_id) primary key (user_id)
) engine=innodb auto_increment=100 default charset=utf8 comment = '用户信息表'; ) engine=innodb auto_increment=100 default charset=utf8 comment = '用户信息表';
-- ---------------------------- -- ----------------------------
-- 初始化-用户信息表数据 -- 初始化-用户信息表数据
-- ---------------------------- -- ----------------------------
insert into sys_user values(1, 106, 'admin', '若依', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', 'Y', 0, '正常', '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); insert into sys_user values(1, 106, 'admin', '若依', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', 0, '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '管理员');
insert into sys_user values(2, 108, 'ry', '若依', 'ry@qq.com', '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', 'N', 0, '正常', '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); insert into sys_user values(2, 108, 'ry', '若依', 'ry@qq.com', '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', 0, '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '测试员');
-- ---------------------------- -- ----------------------------
-- 3、岗位信息表 -- 3、岗位信息表

@ -16,6 +16,7 @@ import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.SystemLogUtils; import com.ruoyi.common.utils.SystemLogUtils;
import com.ruoyi.common.utils.security.ShiroUtils; import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.user.domain.User; import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.domain.UserStatus;
import com.ruoyi.project.system.user.service.IUserService; import com.ruoyi.project.system.user.service.IUserService;
/** /**
@ -78,7 +79,7 @@ public class LoginService
user = userService.selectUserByEmail(username); user = userService.selectUserByEmail(username);
} }
if (user == null) if (user == null || UserStatus.DELETED.getCode() == user.getStatus())
{ {
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.not.exists")); SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.not.exists"));
throw new UserNotExistsException(); throw new UserNotExistsException();
@ -86,10 +87,10 @@ public class LoginService
passwordService.validate(user, password); passwordService.validate(user, password);
if (UserConstants.USER_BLOCKED == user.getStatus()) if (UserStatus.DISABLE.getCode() == user.getStatus())
{ {
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRefuseDes())); SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark()));
throw new UserBlockedException(user.getRefuseDes()); throw new UserBlockedException(user.getRemark());
} }
SystemLogUtils.log(username, CommonConstant.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); SystemLogUtils.log(username, CommonConstant.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
recordLoginInfo(user); recordLoginInfo(user);

@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.Message; import com.ruoyi.framework.web.domain.Message;
@ -21,6 +23,7 @@ import com.ruoyi.project.system.post.service.IPostService;
import com.ruoyi.project.system.role.domain.Role; import com.ruoyi.project.system.role.domain.Role;
import com.ruoyi.project.system.role.service.IRoleService; import com.ruoyi.project.system.role.service.IRoleService;
import com.ruoyi.project.system.user.domain.User; import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.domain.UserStatus;
import com.ruoyi.project.system.user.service.IUserService; import com.ruoyi.project.system.user.service.IUserService;
/** /**
@ -129,11 +132,12 @@ public class UserController extends BaseController
{ {
return Message.error("用户不存在"); return Message.error("用户不存在");
} }
if (userService.deleteUserById(userId) > 0) else if (User.isAdmin(userId))
{ {
return Message.success(); return Message.error("不允许删除超级管理员用户");
} }
return Message.error(); user.setStatus(UserStatus.DELETED.getCode());
return userService.updateUser(user) > 0 ? Message.success() : Message.error();
} }
@RequiresPermissions("system:user:batchRemove") @RequiresPermissions("system:user:batchRemove")
@ -161,11 +165,11 @@ public class UserController extends BaseController
@ResponseBody @ResponseBody
public Message save(User user) public Message save(User user)
{ {
if (userService.saveUser(user) > 0) if (StringUtils.isNotNull(user.getUserId()) && User.isAdmin(user.getUserId()))
{ {
return Message.success(); return Message.error("不允许修改超级管理员用户");
} }
return Message.error(); return userService.saveUser(user) > 0 ? Message.success() : Message.error();
} }
/** /**
@ -183,7 +187,6 @@ public class UserController extends BaseController
return uniqueFlag; return uniqueFlag;
} }
/** /**
* *
*/ */

@ -36,12 +36,8 @@ public class User extends BaseEntity
private String password; private String password;
/** 盐加密 */ /** 盐加密 */
private String salt; private String salt;
/** 类型:Y默认用户,N非默认用户 */ /** 帐号状态:0正常,1禁用,2删除 */
private String userType;
/** 帐号状态:0正常,1禁用 */
private int status; private int status;
/** 拒绝登录描述 */
private String refuseDes;
/** 最后登陆IP */ /** 最后登陆IP */
private String loginIp; private String loginIp;
/** 最后登陆时间 */ /** 最后登陆时间 */
@ -63,6 +59,16 @@ public class User extends BaseEntity
this.userId = userId; this.userId = userId;
} }
public boolean isAdmin()
{
return isAdmin(this.userId);
}
public static boolean isAdmin(Long userId)
{
return userId != null && 1L == userId;
}
public Long getDeptId() public Long getDeptId()
{ {
return deptId; return deptId;
@ -174,16 +180,6 @@ public class User extends BaseEntity
setSalt(hex); setSalt(hex);
} }
public String getUserType()
{
return userType;
}
public void setUserType(String userType)
{
this.userType = userType;
}
public int getStatus() public int getStatus()
{ {
return status; return status;
@ -194,16 +190,6 @@ public class User extends BaseEntity
this.status = status; this.status = status;
} }
public String getRefuseDes()
{
return refuseDes;
}
public void setRefuseDes(String refuseDes)
{
this.refuseDes = refuseDes;
}
public String getLoginIp() public String getLoginIp()
{ {
return loginIp; return loginIp;
@ -259,8 +245,8 @@ public class User extends BaseEntity
{ {
return "User [userId=" + userId + ", deptId=" + deptId + ", parentId=" + parentId + ", loginName=" + loginName return "User [userId=" + userId + ", deptId=" + deptId + ", parentId=" + parentId + ", loginName=" + loginName
+ ", userName=" + userName + ", email=" + email + ", phonenumber=" + phonenumber + ", sex=" + sex + ", userName=" + userName + ", email=" + email + ", phonenumber=" + phonenumber + ", sex=" + sex
+ ", avatar=" + avatar + ", password=" + password + ", salt=" + salt + ", userType=" + userType + ", avatar=" + avatar + ", password=" + password + ", salt=" + salt + ", status=" + status
+ ", status=" + status + ", refuseDes=" + refuseDes + ", dept=" + dept + ", roleIds=" + ", loginIp=" + loginIp + ", loginDate=" + loginDate + ", dept=" + dept + ", roleIds="
+ Arrays.toString(roleIds) + ", postIds=" + Arrays.toString(postIds) + "]"; + Arrays.toString(roleIds) + ", postIds=" + Arrays.toString(postIds) + "]";
} }

@ -0,0 +1,31 @@
package com.ruoyi.project.system.user.domain;
/**
*
*
* @author ruoyi
*
*/
public enum UserStatus
{
OK(0, "正常"), DISABLE(1, "禁用"), DELETED(2, "删除");
private final int code;
private final String info;
UserStatus(int code, String info)
{
this.code = code;
this.info = info;
}
public int getCode()
{
return code;
}
public String getInfo()
{
return info;
}
}

@ -15,15 +15,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="avatar" column="avatar" /> <result property="avatar" column="avatar" />
<result property="password" column="password" /> <result property="password" column="password" />
<result property="salt" column="salt" /> <result property="salt" column="salt" />
<result property="userType" column="user_type" />
<result property="status" column="status" /> <result property="status" column="status" />
<result property="refuseDes" column="refuse_des" />
<result property="loginIp" column="login_ip" /> <result property="loginIp" column="login_ip" />
<result property="loginDate" column="login_date" /> <result property="loginDate" column="login_date" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<association property="dept" column="dept_id" javaType="Dept" resultMap="deptResult"/> <association property="dept" column="dept_id" javaType="Dept" resultMap="deptResult"/>
</resultMap> </resultMap>
@ -36,19 +35,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<select id="selectUserList" parameterType="User" resultMap="UserResult"> <select id="selectUserList" parameterType="User" resultMap="UserResult">
select user_id, dept_id, login_name, user_name, email, phonenumber, password, sex, avatar, salt, user_type, status, refuse_des, create_by, create_time from sys_user select user_id, dept_id, login_name, user_name, email, phonenumber, password, sex, avatar, salt, status, create_by, create_time, remark from sys_user
<where> where status in (0,1)
<if test="searchValue != null and searchValue != ''"> <if test="searchValue != null and searchValue != ''">
AND login_name like concat(concat('%', #{searchValue}), '%') AND login_name like concat(concat('%', #{searchValue}), '%')
</if> </if>
<if test="deptId != null and parentId != null and parentId != 0"> <if test="deptId != null and parentId != null and parentId != 0">
AND dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId}) AND dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId})
</if> </if>
</where>
</select> </select>
<select id="selectUserByLoginName" parameterType="String" resultMap="UserResult"> <select id="selectUserByLoginName" parameterType="String" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.login_ip, u.login_date, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -57,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserByPhoneNumber" parameterType="String" resultMap="UserResult"> <select id="selectUserByPhoneNumber" parameterType="String" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.login_ip, u.login_date, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -66,7 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserByEmail" parameterType="String" resultMap="UserResult"> <select id="selectUserByEmail" parameterType="String" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.login_ip, u.login_date, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -87,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserById" parameterType="Long" resultMap="UserResult"> <select id="selectUserById" parameterType="Long" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.login_ip, u.login_date, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -119,10 +117,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="password != null and password != ''">password = #{password},</if> <if test="password != null and password != ''">password = #{password},</if>
<if test="salt != null and salt != ''">salt = #{salt},</if> <if test="salt != null and salt != ''">salt = #{salt},</if>
<if test="status !=null">status = #{status},</if> <if test="status !=null">status = #{status},</if>
<if test="refuseDes != null and refuseDes != ''">refuse_des = #{refuseDes},</if>
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if> <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
<if test="loginDate != null">login_date = #{loginDate},</if> <if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
update_time = sysdate() update_time = sysdate()
</set> </set>
where 1=1 where 1=1
@ -141,8 +139,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="password != null and password != ''">password,</if> <if test="password != null and password != ''">password,</if>
<if test="salt != null and salt != ''">salt,</if> <if test="salt != null and salt != ''">salt,</if>
<if test="status !=null and status != ''">status,</if> <if test="status !=null and status != ''">status,</if>
<if test="refuseDes != null and refuseDes != ''">refuse_des,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
create_time create_time
)values( )values(
<if test="userId != null and userId != ''">#{userId},</if> <if test="userId != null and userId != ''">#{userId},</if>
@ -155,8 +153,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="password != null and password != ''">#{password},</if> <if test="password != null and password != ''">#{password},</if>
<if test="salt != null and salt != ''">#{salt},</if> <if test="salt != null and salt != ''">#{salt},</if>
<if test="status !=null and status != ''">#{status},</if> <if test="status !=null and status != ''">#{status},</if>
<if test="refuseDes != null and refuseDes != ''">#{refuseDes},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate() sysdate()
) )
</insert> </insert>

@ -51,15 +51,11 @@ function queryUserList() {
title: '操作', title: '操作',
align: 'center', align: 'center',
formatter: function(value, row, index) { formatter: function(value, row, index) {
if(row.userType == "N") {
var actions = []; var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> '); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> ');
actions.push('<a class="btn btn-info btn-xs ' + resetPwdFlag + '" href="#" onclick="resetPwd(\'' + row.userId + '\')"><i class="fa fa-key"></i>重置</a>'); actions.push('<a class="btn btn-info btn-xs ' + resetPwdFlag + '" href="#" onclick="resetPwd(\'' + row.userId + '\')"><i class="fa fa-key"></i>重置</a>');
return actions.join(''); return actions.join('');
} else {
return "";
}
} }
}]; }];
var url = prefix + "/list"; var url = prefix + "/list";

Loading…
Cancel
Save