完成后台查看所有用户和修改用户状态接口。
This commit is contained in:
parent
3ab7f5787f
commit
dba521c55e
@ -0,0 +1,112 @@
|
||||
package com.ruoyi.web.controller.backstage;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.domain.UserInfo;
|
||||
import com.ruoyi.system.domain.dto.UpdateUserStateDto;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.system.service.IUserInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static com.ruoyi.common.utils.PageUtils.startPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.core.domain.AjaxResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/backstage/system")
|
||||
public class BackstageController {
|
||||
|
||||
@Autowired
|
||||
private IUserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@GetMapping("/getAllUserInfo")
|
||||
public TableDataInfo getAllUserInfo(){
|
||||
|
||||
// 这里面是不是就没有user_type啊,直接解码的token不包含user_type
|
||||
SysUser user = SecurityUtils.getLoginUser().getUser();
|
||||
Long userId = user.getUserId();
|
||||
|
||||
SysUser user1 = sysUserService.selectUserById(userId);
|
||||
String userType = user1.getUserType();
|
||||
|
||||
|
||||
if (userType.equals(Constants.USER_TYPE_ADMIN)){
|
||||
// 分页
|
||||
startPage();
|
||||
List<UserInfo> userInfoList = userInfoService.selectAllUserInfo();
|
||||
|
||||
return getDataTable(userInfoList);
|
||||
}
|
||||
else{
|
||||
return noAuthority();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/changeUserStatus")
|
||||
public AjaxResult changeUserState(@RequestBody UpdateUserStateDto updateUserStateDto){
|
||||
|
||||
if(isAtuthority(Constants.USER_TYPE_ADMIN)){
|
||||
String username = updateUserStateDto.getUsername();
|
||||
String status = updateUserStateDto.getStatus();
|
||||
|
||||
int back = sysUserService.updateUserState1(username,status);
|
||||
|
||||
if(back>0){
|
||||
return success();
|
||||
}
|
||||
else{
|
||||
return AjaxResult.error("修改用户权限失败");
|
||||
}
|
||||
}
|
||||
else{
|
||||
return AjaxResult.error("无权限");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TableDataInfo getDataTable(List<?> list)
|
||||
{
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(list);
|
||||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
private TableDataInfo noAuthority()
|
||||
{
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.ERROR);
|
||||
rspData.setMsg("无权限");
|
||||
return rspData;
|
||||
}
|
||||
private boolean isAtuthority(String type){
|
||||
SysUser user = SecurityUtils.getLoginUser().getUser();
|
||||
Long userId = user.getUserId();
|
||||
SysUser user1 = sysUserService.selectUserById(userId);
|
||||
String userType = user1.getUserType();
|
||||
|
||||
if(userType.equals(type)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -134,6 +134,11 @@ public class Constants
|
||||
*/
|
||||
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
|
||||
|
||||
/**
|
||||
* 管理员用户类型
|
||||
*/
|
||||
public static final String USER_TYPE_ADMIN = "66";
|
||||
|
||||
/**
|
||||
* 定时任务违规的字符
|
||||
*/
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
public class UpdateUserStateDto {
|
||||
private String username;
|
||||
private String status;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
@ -67,6 +67,8 @@ public interface SysUserMapper
|
||||
*/
|
||||
public int updateUser(SysUser user);
|
||||
|
||||
public int updateUserState1(@Param("username") String username, @Param("status") String status);
|
||||
|
||||
/**
|
||||
* 修改用户头像
|
||||
*
|
||||
@ -131,5 +133,5 @@ public interface SysUserMapper
|
||||
|
||||
SysUser selectUserByPhonenumber(@Param("phoneNumber") String phoneNumber);
|
||||
|
||||
int test();
|
||||
// int test();
|
||||
}
|
||||
|
||||
@ -28,6 +28,8 @@ public interface UserInfoMapper
|
||||
*/
|
||||
public List<UserInfo> selectUserInfoList(UserInfo userInfo);
|
||||
|
||||
public List<UserInfo> selectAllUserInfo();
|
||||
|
||||
/**
|
||||
* 新增用户个人信息
|
||||
*
|
||||
|
||||
@ -128,6 +128,9 @@ public interface ISysUserService
|
||||
*/
|
||||
public int updateUser(SysUser user);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户授权角色
|
||||
*
|
||||
@ -144,6 +147,8 @@ public interface ISysUserService
|
||||
*/
|
||||
public int updateUserStatus(SysUser user);
|
||||
|
||||
public int updateUserState1(String username, String status);
|
||||
|
||||
/**
|
||||
* 修改用户基本信息
|
||||
*
|
||||
|
||||
@ -27,6 +27,8 @@ public interface IUserInfoService
|
||||
*/
|
||||
public List<UserInfo> selectUserInfoList(UserInfo userInfo);
|
||||
|
||||
public List<UserInfo> selectAllUserInfo();
|
||||
|
||||
/**
|
||||
* 新增用户个人信息
|
||||
*
|
||||
@ -66,6 +68,8 @@ public interface IUserInfoService
|
||||
* */
|
||||
public boolean updateSignature(String phonenumber, String signature);
|
||||
|
||||
// public int updateUserState(String username, String state);
|
||||
|
||||
/*
|
||||
* 更新用户头像
|
||||
* */
|
||||
|
||||
@ -191,8 +191,8 @@ public class SysUserOnlineTimeServiceImpl implements ISysUserOnlineTimeService {
|
||||
// System.out.println("定时任务输出"+date);
|
||||
// }
|
||||
// 每天凌晨 1 点计算近7/30天的在线时长
|
||||
// @Scheduled(cron="0 0 1 * * ?")
|
||||
@Scheduled(cron="0 * * * * ?")
|
||||
@Scheduled(cron="0 0 1 * * ?")
|
||||
// @Scheduled(cron="0 * * * * ?")
|
||||
@Override
|
||||
public void calculateUserOnlineStats() {
|
||||
|
||||
|
||||
@ -299,6 +299,11 @@ public class SysUserServiceImpl implements ISysUserService
|
||||
return userMapper.updateUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateUserState1(String userName, String status){
|
||||
return userMapper.updateUserState1(userName, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户授权角色
|
||||
*
|
||||
|
||||
@ -55,6 +55,11 @@ public class UserInfoServiceImpl implements IUserInfoService
|
||||
return userInfoMapper.insertUserInfo(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserInfo> selectAllUserInfo(){
|
||||
return userInfoMapper.selectAllUserInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户个人信息
|
||||
*
|
||||
@ -67,6 +72,14 @@ public class UserInfoServiceImpl implements IUserInfoService
|
||||
return userInfoMapper.updateUserInfo(userInfo);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 更新用户状态
|
||||
// */
|
||||
// @Override
|
||||
// public int updateUserState(String username, String state){
|
||||
// return userInfoMapper.updateUserState(username, state);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 批量删除用户个人信息
|
||||
*
|
||||
|
||||
@ -48,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectUserVo">
|
||||
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
|
||||
select u.user_id, u.dept_id, u.user_name ,u.nick_name,u.user_type, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
|
||||
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
|
||||
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
|
||||
from sys_user u
|
||||
@ -210,6 +210,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<update id="updateUserStatus" parameterType="SysUser">
|
||||
update sys_user set status = #{status} where user_id = #{userId}
|
||||
</update>
|
||||
<update id="updateUserState1" parameterType="sysUser">
|
||||
update sys_user set status = #{status} where user_name = #{username}
|
||||
</update>
|
||||
|
||||
<update id="updateNickName" parameterType="SysUser">
|
||||
update sys_user set nick_name = #{nickName} where user_name = #{userName}
|
||||
|
||||
@ -72,6 +72,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectUserInfoVo"/>
|
||||
where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectAllUserInfo" resultMap="UserInfoResult">
|
||||
select user_id, authentication_status, real_name, id_card, sex, signature, avatar, card_front, card_back, email, receive_rockets, send_rockets, shares, followers, s_online_time, s_mr_time, s_consumption, th_consumption, phonenumber, t_mr_time, t_online_time, t_consumption, update_time, date_of_birth, back_ground, calculation_time from user_info
|
||||
</select>
|
||||
|
||||
<insert id="insertUserInfo" parameterType="UserInfo">
|
||||
insert into user_info
|
||||
@ -165,6 +169,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
<delete id="deleteUserInfoByUserId" parameterType="Long">
|
||||
delete from user_info where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
@ -1,58 +1,219 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-input v-model="url" type="text" style="width: 20%" />
|
||||
<el-button @click="join" type="primary">连接</el-button>
|
||||
<el-button @click="exit" type="danger">断开</el-button>
|
||||
|
||||
<br />
|
||||
<el-input type="textarea" v-model="message" :rows="9" />
|
||||
<el-button type="info" @click="send">发送消息</el-button>
|
||||
<br />
|
||||
<br />
|
||||
<el-input type="textarea" v-model="text_content" :rows="9" /> 返回内容
|
||||
<br />
|
||||
<br />
|
||||
<div class="login">
|
||||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
||||
<h3 class="title">若依后台管理系统</h3>
|
||||
<el-form-item prop="username">
|
||||
<el-input
|
||||
v-model="loginForm.username"
|
||||
type="text"
|
||||
auto-complete="off"
|
||||
placeholder="账号"
|
||||
>
|
||||
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
auto-complete="off"
|
||||
placeholder="密码"
|
||||
@keyup.enter.native="handleLogin"
|
||||
>
|
||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code" v-if="captchaEnabled">
|
||||
<el-input
|
||||
v-model="loginForm.code"
|
||||
auto-complete="off"
|
||||
placeholder="验证码"
|
||||
style="width: 63%"
|
||||
@keyup.enter.native="handleLogin"
|
||||
>
|
||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
||||
</el-input>
|
||||
<div class="login-code">
|
||||
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
|
||||
<el-form-item style="width:100%;">
|
||||
<el-button
|
||||
:loading="loading"
|
||||
size="medium"
|
||||
type="primary"
|
||||
style="width:100%;"
|
||||
@click.native.prevent="handleLogin"
|
||||
>
|
||||
<span v-if="!loading">登 录</span>
|
||||
<span v-else>登 录 中...</span>
|
||||
</el-button>
|
||||
<div style="float: right;" v-if="register">
|
||||
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<!-- 底部 -->
|
||||
<div class="el-login-footer">
|
||||
<span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getCodeImg } from "@/api/login";
|
||||
import Cookies from "js-cookie";
|
||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||
|
||||
export default {
|
||||
name: "Login",
|
||||
data() {
|
||||
return {
|
||||
url: "ws://127.0.0.1:8080/websocket/message",
|
||||
message: "",
|
||||
text_content: "",
|
||||
ws: null,
|
||||
codeUrl: "",
|
||||
loginForm: {
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
rememberMe: false,
|
||||
code: "",
|
||||
uuid: ""
|
||||
},
|
||||
loginRules: {
|
||||
username: [
|
||||
{ required: true, trigger: "blur", message: "请输入您的账号" }
|
||||
],
|
||||
password: [
|
||||
{ required: true, trigger: "blur", message: "请输入您的密码" }
|
||||
],
|
||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
||||
},
|
||||
loading: false,
|
||||
// 验证码开关
|
||||
captchaEnabled: true,
|
||||
// 注册开关
|
||||
register: false,
|
||||
redirect: undefined
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
join() {
|
||||
const wsuri = this.url;
|
||||
this.ws = new WebSocket(wsuri);
|
||||
const self = this;
|
||||
this.ws.onopen = function (event) {
|
||||
self.text_content = self.text_content + "已经打开连接!" + "\n";
|
||||
};
|
||||
this.ws.onmessage = function (event) {
|
||||
self.text_content = event.data + "\n";
|
||||
};
|
||||
this.ws.onclose = function (event) {
|
||||
self.text_content = self.text_content + "已经关闭连接!" + "\n";
|
||||
};
|
||||
},
|
||||
exit() {
|
||||
if (this.ws) {
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
},
|
||||
send() {
|
||||
if (this.ws) {
|
||||
this.ws.send(this.message);
|
||||
} else {
|
||||
alert("未连接到服务器");
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
$route: {
|
||||
handler: function(route) {
|
||||
this.redirect = route.query && route.query.redirect;
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getCode();
|
||||
this.getCookie();
|
||||
},
|
||||
methods: {
|
||||
getCode() {
|
||||
getCodeImg().then(res => {
|
||||
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
||||
if (this.captchaEnabled) {
|
||||
this.codeUrl = "data:image/gif;base64," + res.img;
|
||||
this.loginForm.uuid = res.uuid;
|
||||
}
|
||||
});
|
||||
},
|
||||
getCookie() {
|
||||
const username = Cookies.get("username");
|
||||
const password = Cookies.get("password");
|
||||
const rememberMe = Cookies.get('rememberMe')
|
||||
this.loginForm = {
|
||||
username: username === undefined ? this.loginForm.username : username,
|
||||
password: password === undefined ? this.loginForm.password : decrypt(password),
|
||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
||||
};
|
||||
},
|
||||
handleLogin() {
|
||||
this.$refs.loginForm.validate(valid => {
|
||||
if (valid) {
|
||||
this.loading = true;
|
||||
if (this.loginForm.rememberMe) {
|
||||
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
||||
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
||||
} else {
|
||||
Cookies.remove("username");
|
||||
Cookies.remove("password");
|
||||
Cookies.remove('rememberMe');
|
||||
}
|
||||
this.$store.dispatch("Login", this.loginForm).then(() => {
|
||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
||||
}).catch(() => {
|
||||
this.loading = false;
|
||||
if (this.captchaEnabled) {
|
||||
this.getCode();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style rel="stylesheet/scss" lang="scss">
|
||||
.login {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
background-image: url("../assets/images/login-background.jpg");
|
||||
background-size: cover;
|
||||
}
|
||||
.title {
|
||||
margin: 0px auto 30px auto;
|
||||
text-align: center;
|
||||
color: #707070;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
border-radius: 6px;
|
||||
background: #ffffff;
|
||||
width: 400px;
|
||||
padding: 25px 25px 5px 25px;
|
||||
.el-input {
|
||||
height: 38px;
|
||||
input {
|
||||
height: 38px;
|
||||
}
|
||||
}
|
||||
.input-icon {
|
||||
height: 39px;
|
||||
width: 14px;
|
||||
margin-left: 2px;
|
||||
}
|
||||
}
|
||||
.login-tip {
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
color: #bfbfbf;
|
||||
}
|
||||
.login-code {
|
||||
width: 33%;
|
||||
height: 38px;
|
||||
float: right;
|
||||
img {
|
||||
cursor: pointer;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
.el-login-footer {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-family: Arial;
|
||||
font-size: 12px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.login-code-img {
|
||||
height: 38px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user