登录系统路由权限
This commit is contained in:
parent
e8cd90edb2
commit
850a816768
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import com.bonus.common.encryption.Sm4Utils;
|
||||
import com.bonus.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
|
@ -41,6 +42,9 @@ public class SysLoginController
|
|||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
|
||||
@PostMapping("/sendPhone")
|
||||
public AjaxResult sendPhone(@RequestBody LoginBody loginBody) {
|
||||
|
|
@ -59,15 +63,22 @@ public class SysLoginController
|
|||
public AjaxResult login(@RequestBody LoginBody loginBody) {
|
||||
|
||||
String token;
|
||||
String permissions; //权限字符
|
||||
String username= Sm4Utils.decrypt(loginBody.getUsername()); // 解密
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
if("2".equals(loginBody.getLoginType())){
|
||||
token = loginService.login(loginBody.getUsername(), loginBody.getCode());
|
||||
|
||||
permissions = userService.getPermissions(username,"2");
|
||||
}else{
|
||||
token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
||||
loginBody.getUuid());
|
||||
permissions = userService.getPermissions(username,"1");
|
||||
}
|
||||
// 生成令牌
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
ajax.put(Constants.JWT_AUTHORITIES, permissions);
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,17 @@ public class SysUser extends BaseEntity
|
|||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 权限 默认有大屏权限 1是有后台。0是没有 */
|
||||
private String permissions;
|
||||
|
||||
public String getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(String permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
/** 自增长序号,用于导出 */
|
||||
@Excel(name = "用户序号", type = Type.EXPORT)
|
||||
private Integer serialNumber;
|
||||
|
|
|
|||
|
|
@ -133,4 +133,12 @@ public interface SysUserMapper
|
|||
*/
|
||||
|
||||
String getUserInfo(@Param("phone") String phone);
|
||||
|
||||
/**
|
||||
* 获取权限
|
||||
* @param username
|
||||
* @param number
|
||||
* @return
|
||||
*/
|
||||
String getPermissions(@Param("username")String username, @Param("number")String number);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,4 +212,6 @@ public interface ISysUserService
|
|||
* @return
|
||||
*/
|
||||
SysUser selectUserByPhone(String username);
|
||||
|
||||
String getPermissions(String username, String number);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,6 +119,18 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
public SysUser selectUserByPhone(String username) {
|
||||
return userMapper.selectUserByPhone(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限
|
||||
* @param username
|
||||
* @param number
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getPermissions(String username, String number) {
|
||||
return userMapper.getPermissions(username,number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="permissions" column="permissions" />
|
||||
<result property="roleName" column="role_name" />
|
||||
<result property="postName" column="post_name" />
|
||||
<association property="dept" javaType="SysDept" resultMap="deptResult" />
|
||||
|
|
@ -52,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<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,
|
||||
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,r.is_admin
|
||||
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,r.is_admin,u.permissions
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
|
|
@ -62,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status,
|
||||
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader,
|
||||
r.role_name, sp.post_name
|
||||
r.role_name, sp.post_name,u.permissions
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
|
|
@ -167,7 +168,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select phonenumber from sys_user where phonenumber = #{phone} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
<select id="getPermissions" resultType="java.lang.String">
|
||||
SELECT permissions FROM `sys_user`
|
||||
WHERE del_flag = 0
|
||||
<if test="number ==1 || number =='1'">
|
||||
AND user_name = #{username}
|
||||
</if>
|
||||
|
||||
<if test="number ==2 || number =='2'">
|
||||
AND phonenumber = #{username}
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into sys_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
|
|
@ -181,6 +195,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="permissions != null and permissions != ''">permissions,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="userId != null and userId != ''">#{userId},</if>
|
||||
|
|
@ -195,6 +210,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="permissions != null and permissions != ''">#{permissions},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
|
@ -214,6 +230,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="loginDate != null">login_date = #{loginDate},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="permissions != null">permissions = #{permissions},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where user_id = #{userId}
|
||||
|
|
|
|||
Loading…
Reference in New Issue