feat: 一些调整
This commit is contained in:
parent
b480272178
commit
12ccd21279
|
|
@ -5,7 +5,9 @@ import cn.dev33.satoken.stp.SaTokenInfo;
|
|||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.constant.UserState;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.AdminLoginVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.PermissionsVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.RoleVO;
|
||||
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||
import com.nflg.mobilebroken.common.util.SaTokenAdminUtil;
|
||||
import com.nflg.mobilebroken.common.util.VUtils;
|
||||
|
|
@ -20,6 +22,7 @@ import javax.validation.Valid;
|
|||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 管理端用户登录
|
||||
|
|
@ -45,20 +48,24 @@ public class AdminController extends ControllerBase {
|
|||
* @return token
|
||||
*/
|
||||
@GetMapping("login")
|
||||
public ApiResult<SaTokenInfo> login(@Valid @NotBlank(message = "用户名不能为空") @RequestParam("userName") String userName,
|
||||
public ApiResult<AdminLoginVO> login(@Valid @NotBlank(message = "用户名不能为空") @RequestParam("userName") String userName,
|
||||
@Valid @NotBlank(message = "密码不能为空") @RequestParam("password") String password) {
|
||||
AdminUser user=adminUserService.getUser(userName,password);
|
||||
VUtils.trueThrow(Objects.isNull(user)).throwMessage(STATE.PassportErr,"用户名或密码错误");
|
||||
VUtils.trueThrow(Objects.equals(user.getState(), UserState.Disabled.getState())).throwMessage(STATE.PassportErr, "账户被禁用,请联系管理员");
|
||||
VUtils.trueThrow(Objects.equals(user.getState(), UserState.ToBeActivated.getState())).throwMessage(STATE.PassportErr, "账户未激活");
|
||||
List<String> roleCodes = adminUserRoleMapService.getRoleList(user.getId());
|
||||
List<RoleVO> roleCodes = adminUserRoleMapService.getRoleList(user.getId());
|
||||
SaTokenAdminUtil.login(user.getId(), SaLoginConfig
|
||||
.setExtra("from", "admin")
|
||||
.setExtra("name", user.getUserName())
|
||||
.setExtra("code", user.getUserCode())
|
||||
.setExtra("email", user.getEmail())
|
||||
.setExtra("roles", roleCodes));
|
||||
return ApiResult.success(SaTokenAdminUtil.getTokenInfo());
|
||||
.setExtra("roles", roleCodes.stream().map(RoleVO::getCode).collect(Collectors.toList())));
|
||||
SaTokenInfo tokenInfo = SaTokenAdminUtil.getTokenInfo();
|
||||
return ApiResult.success(new AdminLoginVO()
|
||||
.setToken(tokenInfo.getTokenValue())
|
||||
.setExpire(tokenInfo.getTokenTimeout())
|
||||
.setRoles(roleCodes.stream().map(RoleVO::getName).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@ package com.nflg.mobilebroken.auth.controller;
|
|||
|
||||
import cn.dev33.satoken.stp.SaLoginConfig;
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.constant.UserState;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.AppLoginVO;
|
||||
import com.nflg.mobilebroken.common.util.SaTokenAdminUtil;
|
||||
import com.nflg.mobilebroken.common.util.SaTokenAppUtil;
|
||||
import com.nflg.mobilebroken.common.util.VUtils;
|
||||
import com.nflg.mobilebroken.repository.entity.AppUser;
|
||||
|
|
@ -39,7 +40,7 @@ public class AppController extends ControllerBase {
|
|||
* @return token
|
||||
*/
|
||||
@GetMapping("login")
|
||||
public ApiResult<SaTokenInfo> login(String userName, String password) {
|
||||
public ApiResult<AppLoginVO> login(String userName, String password) {
|
||||
AppUser user=appUserService.getUser(userName,password);
|
||||
VUtils.trueThrow(Objects.isNull(user)).throwMessage(STATE.PassportErr,"用户名或密码错误");
|
||||
VUtils.trueThrow(Objects.equals(user.getState(), UserState.Disabled.getState())).throwMessage(STATE.PassportErr, "账户被禁用,请联系管理员");
|
||||
|
|
@ -53,7 +54,11 @@ public class AppController extends ControllerBase {
|
|||
.setExtra("isPrimary", user.getIsPrimary()));
|
||||
user.setLastLoginTime(LocalDateTime.now());
|
||||
appUserService.updateById(user);
|
||||
return ApiResult.success(StpUtil.getTokenInfo());
|
||||
SaTokenInfo tokenInfo = SaTokenAdminUtil.getTokenInfo();
|
||||
return ApiResult.success(new AppLoginVO()
|
||||
.setToken(tokenInfo.getTokenValue())
|
||||
.setExpire(tokenInfo.getTokenTimeout())
|
||||
.setLanguageCode(user.getLanguageCode()));
|
||||
}
|
||||
|
||||
///**
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class AccountAddRequest {
|
|||
|
||||
//部门id
|
||||
@NotNull
|
||||
private Integer departmentId;
|
||||
private Long departmentId;
|
||||
|
||||
//职位id
|
||||
@NotNull
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ public class AddUserRequest {
|
|||
@NotBlank(message = "邮箱不能为空")
|
||||
private String email;
|
||||
|
||||
//语言编码
|
||||
@NotBlank(message = "语言编码不能为空")
|
||||
private String languageCode;
|
||||
|
||||
//手机号
|
||||
private String phone;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ public class PrimaryAppUserAddRequest {
|
|||
@Email
|
||||
private String email;
|
||||
|
||||
//语言编码
|
||||
@NotBlank(message = "语言编码不能为空")
|
||||
private String languageCode;
|
||||
|
||||
//手机
|
||||
private String phone;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class SearchAccountRequest extends PageRequest {
|
|||
private String userName;
|
||||
|
||||
// 部门id
|
||||
private Integer departmentId;
|
||||
private Long departmentId;
|
||||
|
||||
// 状态
|
||||
private Byte state;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.nflg.mobilebroken.common.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class AdminLoginVO {
|
||||
|
||||
private String token;
|
||||
|
||||
private Long expire;
|
||||
|
||||
//角色名称列表
|
||||
private List<String> roles;
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ public class AdminUserVO {
|
|||
private LocalDateTime updateTime;
|
||||
|
||||
//部门id
|
||||
private Integer departmentId;
|
||||
private Long departmentId;
|
||||
|
||||
//职位id
|
||||
private Integer titleId;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.mobilebroken.common.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class AppLoginVO {
|
||||
|
||||
private String token;
|
||||
|
||||
private Long expire;
|
||||
|
||||
//语言编码
|
||||
private String languageCode;
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ public class AdminUser implements Serializable {
|
|||
/**
|
||||
* 部门id
|
||||
*/
|
||||
private Integer departmentId;
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
* 职位id
|
||||
|
|
|
|||
|
|
@ -95,6 +95,11 @@ public class AppUser implements Serializable {
|
|||
*/
|
||||
private String salesUserName;
|
||||
|
||||
/**
|
||||
* 语言编码
|
||||
*/
|
||||
private String languageCode;
|
||||
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -79,6 +79,11 @@ public class AppUserApplyfor implements Serializable {
|
|||
*/
|
||||
private Integer titleId;
|
||||
|
||||
/**
|
||||
* 语言编码
|
||||
*/
|
||||
private String languageCode;
|
||||
|
||||
/**
|
||||
* 处理状态,0:待审核,1:审核通过,2:审核不通过
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.mobilebroken.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.RoleVO;
|
||||
import com.nflg.mobilebroken.repository.entity.AdminUserRoleMap;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -15,5 +16,5 @@ import java.util.List;
|
|||
*/
|
||||
public interface AdminUserRoleMapMapper extends BaseMapper<AdminUserRoleMap> {
|
||||
|
||||
List<String> getRoleList(Integer id);
|
||||
List<RoleVO> getRoleList(Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.nflg.mobilebroken.repository.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.mobilebroken.common.pojo.request.AuthorizeUserRequest;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.AdminUserVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.RoleVO;
|
||||
import com.nflg.mobilebroken.repository.entity.AdminUserRoleMap;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -21,5 +22,5 @@ public interface IAdminUserRoleMapService extends IService<AdminUserRoleMap> {
|
|||
|
||||
List<AdminUserVO> getAuthorizeUser(Integer roleId);
|
||||
|
||||
List<String> getRoleList(Integer id);
|
||||
List<RoleVO> getRoleList(Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.nflg.mobilebroken.repository.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -17,6 +18,7 @@ import com.nflg.mobilebroken.repository.service.IAdminRoleService;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -70,11 +72,17 @@ public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole
|
|||
|
||||
@Override
|
||||
public List<MenuVO> getMenusByRoleCodes(List<String> roleCodes) {
|
||||
if (CollectionUtil.isEmpty(roleCodes)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return baseMapper.getMenusByRoleCodes(roleCodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ButtonVO> getButtonsByRoleCodes(List<String> roleCodes) {
|
||||
if (CollectionUtil.isEmpty(roleCodes)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return baseMapper.getButtonsByRoleCodes(roleCodes);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.mobilebroken.common.pojo.request.AuthorizeUserRequest;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.AdminUserVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.RoleVO;
|
||||
import com.nflg.mobilebroken.repository.entity.AdminUser;
|
||||
import com.nflg.mobilebroken.repository.entity.AdminUserRoleMap;
|
||||
import com.nflg.mobilebroken.repository.mapper.AdminUserRoleMapMapper;
|
||||
|
|
@ -56,7 +57,7 @@ public class AdminUserRoleMapServiceImpl extends ServiceImpl<AdminUserRoleMapMap
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoleList(Integer id) {
|
||||
public List<RoleVO> getRoleList(Integer id) {
|
||||
return baseMapper.getRoleList(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
|||
updateById(user);
|
||||
}
|
||||
|
||||
private String getDepartmentName(Integer departmentId) {
|
||||
private String getDepartmentName(Long departmentId) {
|
||||
TBaseDepartment department = departmentService.lambdaQuery()
|
||||
.eq(TBaseDepartment::getId, departmentId)
|
||||
.one();
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public class AppUserApplyforServiceImpl extends ServiceImpl<AppUserApplyforMappe
|
|||
.setReason(request.getReason())
|
||||
.setState(AppUserApplyForState.PENDINGAPPROVAL.getState().byteValue())
|
||||
.setAreaId(request.getAreaId())
|
||||
.setLanguageCode(request.getLanguageCode())
|
||||
.setCompanyId(request.getCompanyId())
|
||||
.setTitleId(request.getTitleId())
|
||||
.setType(AppUserApplyforType.ADD.getState().byteValue())
|
||||
|
|
@ -149,6 +150,7 @@ public class AppUserApplyforServiceImpl extends ServiceImpl<AppUserApplyforMappe
|
|||
.setPhone(applyfor.getUserPhone())
|
||||
.setPassword(PASSWORDENCODER.encode(request.getPassword()))
|
||||
.setAreaId(applyfor.getAreaId())
|
||||
.setLanguageCode(applyfor.getLanguageCode())
|
||||
.setCompanyId(String.valueOf(applyfor.getCompanyId()))
|
||||
.setTitleId(applyfor.getTitleId())
|
||||
.setState(UserState.ToBeActivated.getState())
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
|||
.setPassword(encodePassword)
|
||||
.setCompanyId(StrUtil.join(",", request.getCompanyIds()))
|
||||
.setIsPrimary(true)
|
||||
.setLanguageCode(request.getLanguageCode())
|
||||
.setSalesUserName(request.getSalesUserName())
|
||||
// .setCreateBy(AdminUserUtil.getUserId())
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.mobilebroken.repository.mapper.AdminUserRoleMapMapper">
|
||||
|
||||
<select id="getRoleList" resultType="java.lang.String">
|
||||
SELECT r.`code`
|
||||
<select id="getRoleList" resultType="com.nflg.mobilebroken.common.pojo.vo.RoleVO">
|
||||
SELECT r.id,r.`code`,r.`name`
|
||||
FROM admin_user_role_map urm
|
||||
INNER JOIN admin_role r ON urm.role_id=r.id
|
||||
WHERE urm.user_id=#{id}
|
||||
|
|
|
|||
Loading…
Reference in New Issue