提交修改
This commit is contained in:
parent
0fe6a7f58a
commit
4757e4fe1c
@ -68,4 +68,5 @@ public interface StaffDao extends BaseMapper<StaffEntity> {
|
||||
|
||||
int addStaff(StaffEntity staff);
|
||||
|
||||
StaffEntity selectByPhone(@Param("phone") String phone);
|
||||
}
|
||||
|
||||
@ -67,5 +67,7 @@ public interface StaffService extends IService<StaffEntity> {
|
||||
|
||||
|
||||
int deleteStaffById(Long id);
|
||||
|
||||
StaffEntity selectByPhone(String userName);
|
||||
}
|
||||
|
||||
|
||||
@ -82,8 +82,10 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
|
||||
return staffDao.deleteStaffById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public StaffEntity selectByPhone(String phone) {
|
||||
return staffDao.selectByPhone(phone);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@ -30,4 +30,5 @@ public interface FlowDepartmentMapper extends BaseMapper<FlowDepartment> {
|
||||
int deleteFlowDepartmentById(@Param("id")Long id);
|
||||
|
||||
|
||||
FlowDepartment selectByStaffId(@Param("staffId") Long staffId);
|
||||
}
|
||||
@ -30,4 +30,5 @@ public interface StaffRoleMapper extends BaseMapper<StaffRole> {
|
||||
int deleteStaffRoleById(@Param("id")Long id);
|
||||
|
||||
|
||||
StaffRole selectByStaffId(@Param("staffId") Long staffId);
|
||||
}
|
||||
@ -30,4 +30,5 @@ public interface FlowDepartmentService extends IService<FlowDepartment> {
|
||||
int deleteFlowDepartmentById(Long id);
|
||||
|
||||
|
||||
FlowDepartment selectByStaffId(Long staffId);
|
||||
}
|
||||
@ -30,5 +30,5 @@ public interface StaffRoleService extends IService<StaffRole> {
|
||||
int deleteStaffRoleById(Long id);
|
||||
|
||||
|
||||
|
||||
StaffRole selectByStaffId(Long staffId);
|
||||
}
|
||||
@ -58,7 +58,10 @@ public class FlowDepartmentServiceImpl extends ServiceImpl<FlowDepartmentMapper,
|
||||
return flowDepartmentMapper.deleteFlowDepartmentById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FlowDepartment selectByStaffId(Long staffId) {
|
||||
return flowDepartmentMapper.selectByStaffId(staffId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -58,8 +58,10 @@ public class StaffRoleServiceImpl extends ServiceImpl<StaffRoleMapper, StaffRole
|
||||
return staffRoleMapper.deleteStaffRoleById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public StaffRole selectByStaffId(Long staffId) {
|
||||
return staffRoleMapper.selectByStaffId(staffId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -28,4 +28,5 @@ public abstract class AbstractController {
|
||||
protected Long getUserId() {
|
||||
return getUser().getUserId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,9 +13,11 @@ import com.lz.common.utils.*;
|
||||
import com.lz.modules.app.dto.SmsResult;
|
||||
import com.lz.modules.app.entity.CodeRecordEntity;
|
||||
import com.lz.modules.app.entity.SmsTemplateEntity;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.enums.SmsTypeEnum;
|
||||
import com.lz.modules.app.service.CodeRecordService;
|
||||
import com.lz.modules.app.service.SmsTemplateService;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
import com.lz.modules.sys.entity.SysConfigEntity;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.form.SysLoginForm;
|
||||
@ -68,6 +70,9 @@ public class SysLoginController extends AbstractController {
|
||||
@Value(value = "${spring.console.env}")
|
||||
private String environment;
|
||||
|
||||
@Autowired
|
||||
private StaffService staffService ;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
@ -170,7 +175,19 @@ public class SysLoginController extends AbstractController {
|
||||
//用户信息
|
||||
SysUserEntity user = sysUserService.queryByUserName(form.getUserName());
|
||||
if (user == null) {
|
||||
return R.error("账号不存在!");
|
||||
StaffEntity staffEntity = staffService.selectByPhone(form.getUserName());
|
||||
if(staffEntity != null){
|
||||
user.setPassword(staffEntity.getPassword());
|
||||
user.setMobile(staffEntity.getMobile());
|
||||
user.setUserId(staffEntity.getId());
|
||||
user.setEmail(staffEntity.getEmail());
|
||||
user.setSalt(staffEntity.getSalt());
|
||||
user.setStatus(1);
|
||||
user.setRealName(staffEntity.getName());
|
||||
user.setUserNo(staffEntity.getMobile());
|
||||
}else{
|
||||
return R.error("账号不存在!");
|
||||
}
|
||||
}
|
||||
//账号不存在、密码错误
|
||||
if (!user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
|
||||
@ -190,12 +207,13 @@ public class SysLoginController extends AbstractController {
|
||||
codeRecordService.updateById(codeRecordEntity);*/
|
||||
|
||||
//生成token,并保存到数据库
|
||||
R r = sysUserTokenService.createToken(user.getUserId());
|
||||
R r = sysUserTokenService.createToken(user);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
|
||||
@ -13,6 +13,7 @@ import com.lz.common.exception.RRException;
|
||||
import com.lz.common.utils.Constant;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.sys.entity.SysMenuEntity;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.service.ShiroService;
|
||||
import com.lz.modules.sys.service.SysMenuService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -42,7 +43,7 @@ public class SysMenuController extends AbstractController {
|
||||
@GetMapping("/nav")
|
||||
public R nav(){
|
||||
List<SysMenuEntity> menuList = sysMenuService.getUserMenuList(getUserId());
|
||||
Set<String> permissions = shiroService.getUserPermissions(getUserId());
|
||||
Set<String> permissions = shiroService.getUserPermissions(getUser());
|
||||
return R.ok().put("menuList", menuList).put("permissions", permissions);
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ 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;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -43,4 +44,6 @@ public interface SysUserDao extends BaseMapper<SysUserEntity> {
|
||||
|
||||
int getTotalCount(String realName, Long createUserId, String mobile, String roleName);
|
||||
|
||||
|
||||
List<Long> queryMenuIdListByRoleId(@Param("roleId") Long roleId);
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
package com.lz.modules.sys.oauth2;
|
||||
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.lz.modules.sys.service.ShiroService;
|
||||
@ -31,6 +33,9 @@ public class OAuth2Realm extends AuthorizingRealm {
|
||||
@Autowired
|
||||
private ShiroService shiroService;
|
||||
|
||||
@Autowired
|
||||
private StaffService staffService;
|
||||
|
||||
@Override
|
||||
public boolean supports(AuthenticationToken token) {
|
||||
return token instanceof OAuth2Token;
|
||||
@ -42,11 +47,8 @@ public class OAuth2Realm extends AuthorizingRealm {
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
SysUserEntity user = (SysUserEntity)principals.getPrimaryPrincipal();
|
||||
Long userId = user.getUserId();
|
||||
|
||||
//用户权限列表
|
||||
Set<String> permsSet = shiroService.getUserPermissions(userId);
|
||||
|
||||
Set<String> permsSet = shiroService.getUserPermissions(user);
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.setStringPermissions(permsSet);
|
||||
return info;
|
||||
@ -66,8 +68,23 @@ public class OAuth2Realm extends AuthorizingRealm {
|
||||
if(tokenEntity == null || tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()){
|
||||
throw new IncorrectCredentialsException("token失效,请重新登录");
|
||||
}
|
||||
|
||||
//查询用户信息
|
||||
SysUserEntity user = shiroService.queryUser(tokenEntity.getUserId());
|
||||
SysUserEntity user = null;
|
||||
if(tokenEntity.getType() == 0){ //如果是系统用户
|
||||
user = shiroService.queryUser(tokenEntity.getUserId());
|
||||
}else{
|
||||
user = new SysUserEntity();//如果是普通用户
|
||||
StaffEntity staffEntity = staffService.selectStaffById(tokenEntity.getUserId());
|
||||
user.setPassword(staffEntity.getPassword());
|
||||
user.setMobile(staffEntity.getMobile());
|
||||
user.setUserId(staffEntity.getId());
|
||||
user.setEmail(staffEntity.getEmail());
|
||||
user.setSalt(staffEntity.getSalt());
|
||||
user.setStatus(1);
|
||||
user.setRealName(staffEntity.getName());
|
||||
user.setUserNo(staffEntity.getMobile());
|
||||
}
|
||||
//账号锁定
|
||||
if(user.getStatus() == 0){
|
||||
throw new LockedAccountException("账号已被锁定,请联系管理员");
|
||||
|
||||
@ -22,7 +22,7 @@ public interface ShiroService {
|
||||
/**
|
||||
* 获取用户权限列表
|
||||
*/
|
||||
Set<String> getUserPermissions(long userId);
|
||||
Set<String> getUserPermissions(SysUserEntity user);
|
||||
|
||||
SysUserTokenEntity queryByToken(String token);
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ package com.lz.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.modules.sys.entity.SysMenuEntity;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -43,7 +44,7 @@ public interface SysMenuService extends IService<SysMenuEntity> {
|
||||
/**
|
||||
* 获取用户菜单列表
|
||||
*/
|
||||
List<SysMenuEntity> getUserMenuList(Long userId);
|
||||
List<SysMenuEntity> getUserMenuList(SysUserEntity user);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
|
||||
@ -63,4 +63,6 @@ public interface SysUserService extends IService<SysUserEntity> {
|
||||
* @param newPassword 新密码
|
||||
*/
|
||||
boolean updatePassword(Long userId, String password, String newPassword);
|
||||
|
||||
List<Long> queryMenuIdListByRoleId(Long roleId);
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ package com.lz.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.entity.SysUserTokenEntity;
|
||||
|
||||
/**
|
||||
@ -23,7 +24,7 @@ public interface SysUserTokenService extends IService<SysUserTokenEntity> {
|
||||
* 生成token
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
R createToken(long userId);
|
||||
R createToken(SysUserEntity user);
|
||||
|
||||
/**
|
||||
* 退出,修改token值
|
||||
|
||||
@ -32,18 +32,17 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
private SysUserTokenDao sysUserTokenDao;
|
||||
|
||||
@Override
|
||||
public Set<String> getUserPermissions(long userId) {
|
||||
List<String> permsList;
|
||||
|
||||
public Set<String> getUserPermissions(SysUserEntity user) {
|
||||
List<String> permsList = null;
|
||||
//系统管理员,拥有最高权限
|
||||
if(userId == Constant.SUPER_ADMIN){
|
||||
if(user.getUserId() == Constant.SUPER_ADMIN || user.getType() == 2){
|
||||
List<SysMenuEntity> menuList = sysMenuDao.selectList(null);
|
||||
permsList = new ArrayList<>(menuList.size());
|
||||
for(SysMenuEntity menu : menuList){
|
||||
permsList.add(menu.getPerms());
|
||||
}
|
||||
}else{
|
||||
permsList = sysUserDao.queryAllPerms(userId);
|
||||
permsList = sysUserDao.queryAllPerms(user.getUserId());
|
||||
}
|
||||
//用户权限列表
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
|
||||
@ -12,8 +12,13 @@ package com.lz.modules.sys.service.impl;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lz.common.utils.Constant;
|
||||
import com.lz.common.utils.MapUtils;
|
||||
import com.lz.modules.flow.entity.FlowDepartment;
|
||||
import com.lz.modules.flow.entity.StaffRole;
|
||||
import com.lz.modules.flow.service.FlowDepartmentService;
|
||||
import com.lz.modules.flow.service.StaffRoleService;
|
||||
import com.lz.modules.sys.dao.SysMenuDao;
|
||||
import com.lz.modules.sys.entity.SysMenuEntity;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.service.SysMenuService;
|
||||
import com.lz.modules.sys.service.SysRoleMenuService;
|
||||
import com.lz.modules.sys.service.SysUserService;
|
||||
@ -31,13 +36,18 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> i
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
@Autowired
|
||||
private FlowDepartmentService flowDepartmentService ;
|
||||
|
||||
@Autowired
|
||||
private StaffRoleService staffRoleService;
|
||||
|
||||
@Override
|
||||
public List<SysMenuEntity> queryListParentId(Long parentId, List<Long> menuIdList) {
|
||||
List<SysMenuEntity> menuList = queryListParentId(parentId);
|
||||
if(menuIdList == null){
|
||||
return menuList;
|
||||
}
|
||||
|
||||
List<SysMenuEntity> userMenuList = new ArrayList<>();
|
||||
for(SysMenuEntity menu : menuList){
|
||||
if(menuIdList.contains(menu.getMenuId())){
|
||||
@ -58,14 +68,28 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuEntity> getUserMenuList(Long userId) {
|
||||
public List<SysMenuEntity> getUserMenuList(SysUserEntity user) {
|
||||
//系统管理员,拥有最高权限
|
||||
if(userId == Constant.SUPER_ADMIN){
|
||||
if(user.getUserId() == Constant.SUPER_ADMIN){
|
||||
return getAllMenuList(null);
|
||||
}
|
||||
|
||||
//用户菜单列表
|
||||
List<Long> menuIdList = sysUserService.queryAllMenuId(userId);
|
||||
List<Long> menuIdList = null;
|
||||
if (user.getType() == 0) {
|
||||
menuIdList = sysUserService.queryAllMenuId(user.getUserId());
|
||||
} else {
|
||||
Long roleId = 13l; //普通员工角色
|
||||
FlowDepartment flowDepartment = flowDepartmentService.selectByStaffId(user.getUserId());
|
||||
if (flowDepartment != null) {
|
||||
roleId = 14l;
|
||||
} else {
|
||||
StaffRole staffRole = staffRoleService.selectByStaffId(user.getUserId());
|
||||
if (staffRole != null) {
|
||||
roleId = 14l;
|
||||
}
|
||||
}
|
||||
menuIdList = sysUserService.queryMenuIdListByRoleId(roleId);
|
||||
}
|
||||
return getAllMenuList(menuIdList);
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
|
||||
@Autowired
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String realName = (String) params.get("realName");
|
||||
@ -132,6 +133,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
|
||||
new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryMenuIdListByRoleId(Long roleId) {
|
||||
return baseMapper.queryMenuIdListByRoleId(roleId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查角色是否越权
|
||||
*/
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
package com.lz.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.entity.SysUserTokenEntity;
|
||||
import com.lz.modules.sys.oauth2.TokenGenerator;
|
||||
import com.lz.modules.sys.service.SysUserTokenService;
|
||||
@ -26,7 +27,7 @@ public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUse
|
||||
|
||||
|
||||
@Override
|
||||
public R createToken(long userId) {
|
||||
public R createToken(SysUserEntity user ) {
|
||||
//生成一个token
|
||||
String token = TokenGenerator.generateValue();
|
||||
|
||||
@ -36,13 +37,14 @@ public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUse
|
||||
Date expireTime = new Date(now.getTime() + EXPIRE * 1000);
|
||||
|
||||
//判断是否生成过token
|
||||
SysUserTokenEntity tokenEntity = this.getById(userId);
|
||||
SysUserTokenEntity tokenEntity = this.getById(user.getUserId());
|
||||
if(tokenEntity == null){
|
||||
tokenEntity = new SysUserTokenEntity();
|
||||
tokenEntity.setUserId(userId);
|
||||
tokenEntity.setUserId(user.getUserId());
|
||||
tokenEntity.setToken(token);
|
||||
tokenEntity.setUpdateTime(now);
|
||||
tokenEntity.setExpireTime(expireTime);
|
||||
tokenEntity.setType(user.getType());
|
||||
|
||||
//保存token
|
||||
this.save(tokenEntity);
|
||||
@ -50,13 +52,10 @@ public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUse
|
||||
tokenEntity.setToken(token);
|
||||
tokenEntity.setUpdateTime(now);
|
||||
tokenEntity.setExpireTime(expireTime);
|
||||
|
||||
//更新token
|
||||
this.updateById(tokenEntity);
|
||||
}
|
||||
|
||||
R r = R.ok().put("token", token).put("expire", EXPIRE);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<insert id="insertFlowDepartment" parameterType="FlowDepartment" useGeneratedKeys="true" keyProperty="id" >
|
||||
insert into lz_flow_department(
|
||||
<if test="departmentId != null">department_id, </if>
|
||||
@ -89,5 +90,11 @@
|
||||
update lz_flow_department set is_delete = 1 where id=#{id} limit 1
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectByStaffId" resultType="com.lz.modules.flow.entity.FlowDepartment">
|
||||
select * from lz_flow_department where is_delete = 0 and taff_id = #{staffId} limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@ -74,5 +74,10 @@
|
||||
update lz_staff_role set is_delete = 1 where id=#{id} limit 1
|
||||
</update>
|
||||
|
||||
<select id="selectByStaffId" resultType="com.lz.modules.flow.entity.StaffRole">
|
||||
select * from lz_staff_role where is_delete = 0 and staff_id = #{staffId} limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@ -422,11 +422,15 @@
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="addStaff">
|
||||
INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id,avatar,job_number)
|
||||
VALUES
|
||||
(#{name},#{gender},#{mobile},#{email},#{openId},#{employeeId},#{unionId},#{avatar},#{jobNumber})
|
||||
</insert>
|
||||
|
||||
<select id="selectByPhone" resultType="com.lz.modules.app.entity.StaffEntity">
|
||||
select * from lz_staff where is_delete = 0 and ( mobile = #{phone} or mobile = concat('+86',#{phone},'')) limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -56,5 +56,11 @@
|
||||
and sr.role_name like concat('%',#{roleName},'%')
|
||||
</if>
|
||||
</select>
|
||||
<select id="queryMenuIdListByRoleId" resultType="java.lang.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.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user