mirror of
https://github.com/1024-lab/smart-admin.git
synced 2025-09-24 22:15:22 +00:00
v3.20.0 【新增】优化登录使用spring cache;【新增】优化部门cache;【新增】代码生成枚举;【优化】三级等保Label显示宽度
This commit is contained in:
@@ -20,11 +20,6 @@ public class AdminCacheConst extends CacheKeyConst {
|
||||
*/
|
||||
public static final String DEPARTMENT_LIST_CACHE = "department_list_cache";
|
||||
|
||||
/**
|
||||
* 部门map
|
||||
*/
|
||||
public static final String DEPARTMENT_MAP_CACHE = "department_map_cache";
|
||||
|
||||
/**
|
||||
* 部门树
|
||||
*/
|
||||
@@ -54,4 +49,20 @@ public class AdminCacheConst extends CacheKeyConst {
|
||||
public static final String CATEGORY_TREE = "category_tree_cache";
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录相关
|
||||
*/
|
||||
public static class Login {
|
||||
|
||||
/**
|
||||
* 请求用户信息
|
||||
*/
|
||||
public static final String REQUEST_EMPLOYEE = "login_request_employee";
|
||||
|
||||
/**
|
||||
* 请求用户信息权限
|
||||
*/
|
||||
public static final String USER_PERMISSION = "login_user_permission";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import org.hibernate.validator.constraints.Length;
|
||||
* @Date 2021-10-25 20:26:54
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Data
|
||||
public class GoodsQueryForm extends PageParam {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package net.lab1024.sa.admin.module.business.goods.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.admin.module.business.goods.constant.GoodsStatusEnum;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.bank;
|
||||
package net.lab1024.sa.admin.module.business.oa.bank.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import net.lab1024.sa.admin.constant.AdminSwaggerTagConst;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.service.BankService;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.domain.BankCreateForm;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.domain.BankQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.domain.BankUpdateForm;
|
@@ -1,4 +1,4 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.bank;
|
||||
package net.lab1024.sa.admin.module.business.oa.bank.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -7,7 +7,6 @@ import net.lab1024.sa.admin.module.business.oa.bank.domain.BankQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.domain.BankVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.bank;
|
||||
package net.lab1024.sa.admin.module.business.oa.bank.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.dao.BankDao;
|
||||
import net.lab1024.sa.admin.module.business.oa.bank.domain.*;
|
||||
import net.lab1024.sa.admin.module.business.oa.enterprise.dao.EnterpriseDao;
|
||||
import net.lab1024.sa.admin.module.business.oa.enterprise.domain.entity.EnterpriseEntity;
|
@@ -1,4 +1,4 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.invoice;
|
||||
package net.lab1024.sa.admin.module.business.oa.invoice.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -7,6 +7,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.constant.AdminSwaggerTagConst;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.service.InvoiceService;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.domain.InvoiceAddForm;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.domain.InvoiceQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.domain.InvoiceUpdateForm;
|
@@ -1,4 +1,4 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.invoice;
|
||||
package net.lab1024.sa.admin.module.business.oa.invoice.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -7,7 +7,6 @@ import net.lab1024.sa.admin.module.business.oa.invoice.domain.InvoiceQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.domain.InvoiceVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.invoice;
|
||||
package net.lab1024.sa.admin.module.business.oa.invoice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.module.business.oa.enterprise.EnterpriseService;
|
||||
import net.lab1024.sa.admin.module.business.oa.enterprise.domain.vo.EnterpriseVO;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.dao.InvoiceDao;
|
||||
import net.lab1024.sa.admin.module.business.oa.invoice.domain.*;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
@@ -5,7 +5,6 @@ import net.lab1024.sa.admin.module.system.department.domain.entity.DepartmentEnt
|
||||
import net.lab1024.sa.admin.module.system.department.domain.vo.DepartmentVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -32,4 +31,5 @@ public interface DepartmentDao extends BaseMapper<DepartmentEntity> {
|
||||
*/
|
||||
List<DepartmentVO> listAll();
|
||||
|
||||
DepartmentVO selectDepartmentVO(@Param("departmentId")Long departmentId);
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
* @Date 2022-01-12 20:37:48
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -42,7 +42,7 @@ public class DepartmentCacheManager {
|
||||
log.info("clear " + cache);
|
||||
}
|
||||
|
||||
@CacheEvict(value = {AdminCacheConst.Department.DEPARTMENT_LIST_CACHE, AdminCacheConst.Department.DEPARTMENT_MAP_CACHE, AdminCacheConst.Department.DEPARTMENT_SELF_CHILDREN_CACHE, AdminCacheConst.Department.DEPARTMENT_TREE_CACHE, AdminCacheConst.Department.DEPARTMENT_PATH_CACHE,}, allEntries = true)
|
||||
@CacheEvict(value = {AdminCacheConst.Department.DEPARTMENT_LIST_CACHE, AdminCacheConst.Department.DEPARTMENT_SELF_CHILDREN_CACHE, AdminCacheConst.Department.DEPARTMENT_TREE_CACHE, AdminCacheConst.Department.DEPARTMENT_PATH_CACHE,}, allEntries = true)
|
||||
public void clearCache() {
|
||||
logClearInfo(AdminCacheConst.Department.DEPARTMENT_LIST_CACHE);
|
||||
}
|
||||
@@ -56,19 +56,8 @@ public class DepartmentCacheManager {
|
||||
return departmentDao.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门map
|
||||
*
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Department.DEPARTMENT_MAP_CACHE)
|
||||
public Map<Long, DepartmentVO> getDepartmentMap() {
|
||||
return departmentDao.listAll().stream().collect(Collectors.toMap(DepartmentVO::getDepartmentId, Function.identity()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存部门树结构
|
||||
*
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Department.DEPARTMENT_TREE_CACHE)
|
||||
public List<DepartmentTreeVO> getDepartmentTree() {
|
||||
@@ -78,7 +67,6 @@ public class DepartmentCacheManager {
|
||||
|
||||
/**
|
||||
* 缓存某个部门的下级id列表
|
||||
*
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Department.DEPARTMENT_SELF_CHILDREN_CACHE)
|
||||
public List<Long> getDepartmentSelfAndChildren(Long departmentId) {
|
||||
@@ -89,7 +77,6 @@ public class DepartmentCacheManager {
|
||||
|
||||
/**
|
||||
* 部门的路径名称
|
||||
*
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Department.DEPARTMENT_PATH_CACHE)
|
||||
public Map<Long, String> getDepartmentPathMap() {
|
||||
@@ -125,7 +112,6 @@ public class DepartmentCacheManager {
|
||||
|
||||
/**
|
||||
* 构建部门树结构
|
||||
*
|
||||
*/
|
||||
public List<DepartmentTreeVO> buildTree(List<DepartmentVO> voList) {
|
||||
if (CollectionUtils.isEmpty(voList)) {
|
||||
@@ -140,7 +126,7 @@ public class DepartmentCacheManager {
|
||||
return treeVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 构建所有根节点的下级树形结构
|
||||
* 返回值为层序遍历结果
|
||||
* [由于departmentDao中listAll给出数据根据Sort降序 所以同一层中Sort值较大的优先遍历]
|
||||
@@ -148,7 +134,7 @@ public class DepartmentCacheManager {
|
||||
private List<Long> recursiveBuildTree(List<DepartmentTreeVO> nodeList, List<DepartmentVO> allDepartmentList) {
|
||||
int nodeSize = nodeList.size();
|
||||
List<Long> childIdList = new ArrayList<>();
|
||||
for(int i = 0; i < nodeSize; i++) {
|
||||
for (int i = 0; i < nodeSize; i++) {
|
||||
int preIndex = i - 1;
|
||||
int nextIndex = i + 1;
|
||||
DepartmentTreeVO node = nodeList.get(i);
|
||||
@@ -167,14 +153,14 @@ public class DepartmentCacheManager {
|
||||
tempChildIdList = this.recursiveBuildTree(children, allDepartmentList);
|
||||
}
|
||||
|
||||
if(CollectionUtils.isEmpty(node.getSelfAndAllChildrenIdList())) {
|
||||
if (CollectionUtils.isEmpty(node.getSelfAndAllChildrenIdList())) {
|
||||
node.setSelfAndAllChildrenIdList(
|
||||
new ArrayList<>()
|
||||
);
|
||||
}
|
||||
node.getSelfAndAllChildrenIdList().add(node.getDepartmentId());
|
||||
|
||||
if(CollectionUtils.isNotEmpty(tempChildIdList)) {
|
||||
if (CollectionUtils.isNotEmpty(tempChildIdList)) {
|
||||
node.getSelfAndAllChildrenIdList().addAll(tempChildIdList);
|
||||
childIdList.addAll(tempChildIdList);
|
||||
}
|
||||
@@ -182,7 +168,7 @@ public class DepartmentCacheManager {
|
||||
}
|
||||
|
||||
// 保证本层遍历顺序
|
||||
for(int i = nodeSize - 1; i >= 0; i--) {
|
||||
for (int i = nodeSize - 1; i >= 0; i--) {
|
||||
childIdList.add(0, nodeList.get(i).getDepartmentId());
|
||||
}
|
||||
|
||||
@@ -192,7 +178,6 @@ public class DepartmentCacheManager {
|
||||
|
||||
/**
|
||||
* 获取子元素
|
||||
*
|
||||
*/
|
||||
private List<DepartmentTreeVO> getChildren(Long departmentId, List<DepartmentVO> voList) {
|
||||
List<DepartmentVO> childrenEntityList = voList.stream().filter(e -> departmentId.equals(e.getParentId())).collect(Collectors.toList());
|
||||
@@ -205,7 +190,6 @@ public class DepartmentCacheManager {
|
||||
|
||||
/**
|
||||
* 通过部门id,获取当前以及下属部门
|
||||
*
|
||||
*/
|
||||
public List<Long> selfAndChildrenIdList(Long departmentId, List<DepartmentVO> voList) {
|
||||
List<Long> selfAndChildrenIdList = Lists.newArrayList();
|
||||
|
@@ -26,7 +26,7 @@ import java.util.Map;
|
||||
* @Date 2022-01-12 20:37:48
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentService {
|
||||
@@ -44,7 +44,6 @@ public class DepartmentService {
|
||||
|
||||
/**
|
||||
* 新增添加部门
|
||||
*
|
||||
*/
|
||||
|
||||
public ResponseDTO<String> addDepartment(DepartmentAddForm departmentAddForm) {
|
||||
@@ -57,7 +56,6 @@ public class DepartmentService {
|
||||
|
||||
/**
|
||||
* 更新部门信息
|
||||
*
|
||||
*/
|
||||
public ResponseDTO<String> updateDepartment(DepartmentUpdateForm updateDTO) {
|
||||
if (updateDTO.getParentId() == null) {
|
||||
@@ -78,7 +76,6 @@ public class DepartmentService {
|
||||
* 根据id删除部门
|
||||
* 1、需要判断当前部门是否有子部门,有子部门则不允许删除
|
||||
* 2、需要判断当前部门是否有员工,有员工则不能删除
|
||||
*
|
||||
*/
|
||||
public ResponseDTO<String> deleteDepartment(Long departmentId) {
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
|
||||
@@ -122,7 +119,6 @@ public class DepartmentService {
|
||||
|
||||
/**
|
||||
* 自身以及所有下级的部门id列表
|
||||
*
|
||||
*/
|
||||
public List<Long> selfAndChildrenIdList(Long departmentId) {
|
||||
return departmentCacheManager.getDepartmentSelfAndChildren(departmentId);
|
||||
@@ -131,7 +127,6 @@ public class DepartmentService {
|
||||
|
||||
/**
|
||||
* 获取所有部门
|
||||
*
|
||||
*/
|
||||
public List<DepartmentVO> listAll() {
|
||||
return departmentCacheManager.getDepartmentList();
|
||||
@@ -140,10 +135,9 @@ public class DepartmentService {
|
||||
|
||||
/**
|
||||
* 获取部门
|
||||
*
|
||||
*/
|
||||
public DepartmentVO getDepartmentById(Long departmentId) {
|
||||
return departmentCacheManager.getDepartmentMap().get(departmentId);
|
||||
return departmentDao.selectDepartmentVO(departmentId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,38 +147,4 @@ public class DepartmentService {
|
||||
return departmentCacheManager.getDepartmentPathMap().get(departmentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部父级部门(不包含自己)
|
||||
*
|
||||
*/
|
||||
public List<DepartmentVO> queryAllParentDepartment(Long departmentId) {
|
||||
List<DepartmentVO> list = new ArrayList<>();
|
||||
|
||||
Map<Long, DepartmentVO> departmentMap = departmentCacheManager.getDepartmentMap();
|
||||
DepartmentVO departmentVO = departmentMap.get(departmentId);
|
||||
while (departmentVO != null) {
|
||||
list.add(departmentVO);
|
||||
departmentVO = departmentMap.get(departmentVO.getParentId());
|
||||
}
|
||||
Collections.reverse(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部父级部门(不包含自己)
|
||||
*
|
||||
*/
|
||||
public List<Long> queryAllParentDepartmentIdList(Long departmentId) {
|
||||
List<Long> list = new ArrayList<>();
|
||||
|
||||
Map<Long, DepartmentVO> departmentMap = departmentCacheManager.getDepartmentMap();
|
||||
DepartmentVO departmentVO = departmentMap.get(departmentId);
|
||||
while (departmentVO != null) {
|
||||
list.add(departmentVO.getDepartmentId());
|
||||
departmentVO = departmentMap.get(departmentVO.getParentId());
|
||||
}
|
||||
Collections.reverse(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,9 +2,7 @@ package net.lab1024.sa.admin.module.system.employee.domain.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.base.common.util.SmartVerificationUtil;
|
||||
|
||||
/**
|
||||
* 修改密码所需参数
|
||||
|
@@ -0,0 +1,162 @@
|
||||
package net.lab1024.sa.admin.module.system.login.manager;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.constant.AdminCacheConst;
|
||||
import net.lab1024.sa.admin.module.system.department.domain.vo.DepartmentVO;
|
||||
import net.lab1024.sa.admin.module.system.department.service.DepartmentService;
|
||||
import net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity;
|
||||
import net.lab1024.sa.admin.module.system.employee.service.EmployeeService;
|
||||
import net.lab1024.sa.admin.module.system.login.domain.RequestEmployee;
|
||||
import net.lab1024.sa.admin.module.system.menu.domain.vo.MenuVO;
|
||||
import net.lab1024.sa.admin.module.system.role.domain.vo.RoleVO;
|
||||
import net.lab1024.sa.admin.module.system.role.service.RoleEmployeeService;
|
||||
import net.lab1024.sa.admin.module.system.role.service.RoleMenuService;
|
||||
import net.lab1024.sa.base.common.constant.StringConst;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.domain.UserPermission;
|
||||
import net.lab1024.sa.base.common.enumeration.UserTypeEnum;
|
||||
import net.lab1024.sa.base.common.util.SmartBeanUtil;
|
||||
import net.lab1024.sa.base.module.support.file.service.IFileStorageService;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 登录Manager
|
||||
*
|
||||
* @Author 1024创新实验室: 卓大
|
||||
* @Date 2025-05-03 22:56:34
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LoginManager {
|
||||
|
||||
@Resource
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Resource
|
||||
private IFileStorageService fileStorageService;
|
||||
|
||||
@Resource
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@Resource
|
||||
private RoleEmployeeService roleEmployeeService;
|
||||
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求用户信息
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Login.REQUEST_EMPLOYEE)
|
||||
public RequestEmployee getRequestEmployee(Long requestEmployeeId ) {
|
||||
if (requestEmployeeId == null) {
|
||||
return null;
|
||||
}
|
||||
// 员工基本信息
|
||||
EmployeeEntity employeeEntity = employeeService.getById(requestEmployeeId);
|
||||
if (employeeEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.loadLoginInfo(employeeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
@CachePut(value = AdminCacheConst.Login.REQUEST_EMPLOYEE, key = "#employeeEntity.employeeId")
|
||||
public RequestEmployee loadLoginInfo(EmployeeEntity employeeEntity) {
|
||||
// 基础信息
|
||||
RequestEmployee requestEmployee = SmartBeanUtil.copy(employeeEntity, RequestEmployee.class);
|
||||
requestEmployee.setUserType(UserTypeEnum.ADMIN_EMPLOYEE);
|
||||
|
||||
// 部门信息
|
||||
DepartmentVO department = departmentService.getDepartmentById(employeeEntity.getDepartmentId());
|
||||
requestEmployee.setDepartmentName(null == department ? StringConst.EMPTY : department.getName());
|
||||
|
||||
// 头像信息
|
||||
String avatar = employeeEntity.getAvatar();
|
||||
if (StringUtils.isNotBlank(avatar)) {
|
||||
ResponseDTO<String> getFileUrl = fileStorageService.getFileUrl(avatar);
|
||||
if (BooleanUtils.isTrue(getFileUrl.getOk())) {
|
||||
requestEmployee.setAvatar(getFileUrl.getData());
|
||||
}
|
||||
}
|
||||
return requestEmployee;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的权限(包含 角色列表、权限列表)
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Login.USER_PERMISSION)
|
||||
public UserPermission getUserPermission(Long employeeId) {
|
||||
if(null == employeeId){
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.loadUserPermission(employeeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的权限(包含 角色列表、权限列表)
|
||||
*/
|
||||
@CachePut(AdminCacheConst.Login.USER_PERMISSION)
|
||||
public UserPermission loadUserPermission(Long employeeId) {
|
||||
UserPermission userPermission = new UserPermission();
|
||||
userPermission.setPermissionList(new ArrayList<>());
|
||||
userPermission.setRoleList(new ArrayList<>());
|
||||
|
||||
// 角色列表
|
||||
List<RoleVO> roleList = roleEmployeeService.getRoleIdList(employeeId);
|
||||
userPermission.getRoleList().addAll(roleList.stream().map(RoleVO::getRoleCode).collect(Collectors.toSet()));
|
||||
|
||||
// 前端菜单和功能点清单
|
||||
EmployeeEntity employeeEntity = employeeService.getById(employeeId);
|
||||
|
||||
List<MenuVO> menuAndPointsList = roleMenuService.getMenuList(roleList.stream().map(RoleVO::getRoleId).collect(Collectors.toList()), employeeEntity.getAdministratorFlag());
|
||||
|
||||
// 权限列表
|
||||
HashSet<String> permissionSet = new HashSet<>();
|
||||
for (MenuVO menu : menuAndPointsList) {
|
||||
if (menu.getPermsType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String perms = menu.getApiPerms();
|
||||
if (StringUtils.isEmpty(perms)) {
|
||||
continue;
|
||||
}
|
||||
//接口权限
|
||||
String[] split = perms.split(",");
|
||||
permissionSet.addAll(Arrays.asList(split));
|
||||
}
|
||||
userPermission.getPermissionList().addAll(permissionSet);
|
||||
|
||||
return userPermission;
|
||||
}
|
||||
|
||||
|
||||
@CacheEvict(value = {AdminCacheConst.Login.USER_PERMISSION, AdminCacheConst.Login.REQUEST_EMPLOYEE}, allEntries = true)
|
||||
public void clear(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -6,17 +6,16 @@ import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.extra.servlet.JakartaServletUtil;
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.module.system.department.domain.vo.DepartmentVO;
|
||||
import net.lab1024.sa.admin.module.system.department.service.DepartmentService;
|
||||
import net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity;
|
||||
import net.lab1024.sa.admin.module.system.employee.service.EmployeeService;
|
||||
import net.lab1024.sa.admin.module.system.login.domain.LoginForm;
|
||||
import net.lab1024.sa.admin.module.system.login.domain.LoginResultVO;
|
||||
import net.lab1024.sa.admin.module.system.login.domain.RequestEmployee;
|
||||
import net.lab1024.sa.admin.module.system.login.manager.LoginManager;
|
||||
import net.lab1024.sa.admin.module.system.menu.domain.vo.MenuVO;
|
||||
import net.lab1024.sa.admin.module.system.role.domain.vo.RoleVO;
|
||||
import net.lab1024.sa.admin.module.system.role.service.RoleEmployeeService;
|
||||
@@ -48,21 +47,22 @@ import net.lab1024.sa.base.module.support.mail.MailService;
|
||||
import net.lab1024.sa.base.module.support.mail.constant.MailTemplateCodeEnum;
|
||||
import net.lab1024.sa.base.module.support.redis.RedisService;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.domain.LoginFailEntity;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.service.*;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.service.Level3ProtectConfigService;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.service.SecurityLoginService;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.service.SecurityPasswordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @Author 1024创新实验室: 开云
|
||||
* @Date 2021-12-01 22:56:34
|
||||
* @Author 1024创新实验室: 卓大
|
||||
* @Date 2025-05-03 22:56:34
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
@@ -76,22 +76,6 @@ public class LoginService implements StpInterface {
|
||||
*/
|
||||
private static final String SUPER_PASSWORD_LOGIN_ID_PREFIX = "S";
|
||||
|
||||
/**
|
||||
* 最大在线缓存人数
|
||||
*/
|
||||
private static final long CACHE_MAX_ONLINE_PERSON_COUNT = 1000L;
|
||||
|
||||
/**
|
||||
* 登录信息二级缓存
|
||||
*/
|
||||
private final ConcurrentMap<Long, RequestEmployee> loginEmployeeCache = new ConcurrentLinkedHashMap.Builder<Long, RequestEmployee>().maximumWeightedCapacity(CACHE_MAX_ONLINE_PERSON_COUNT).build();
|
||||
|
||||
|
||||
/**
|
||||
* 权限 缓存
|
||||
*/
|
||||
private final ConcurrentMap<Long, UserPermission> permissionCache = new ConcurrentLinkedHashMap.Builder<Long, UserPermission>().maximumWeightedCapacity(CACHE_MAX_ONLINE_PERSON_COUNT).build();
|
||||
|
||||
@Resource
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@@ -134,6 +118,9 @@ public class LoginService implements StpInterface {
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private LoginManager loginManager;
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
@@ -224,10 +211,7 @@ public class LoginService implements StpInterface {
|
||||
}
|
||||
|
||||
// 获取员工信息
|
||||
RequestEmployee requestEmployee = loadLoginInfo(employeeEntity);
|
||||
|
||||
// 放入缓存
|
||||
loginEmployeeCache.put(employeeEntity.getEmployeeId(), requestEmployee);
|
||||
RequestEmployee requestEmployee = loginManager.loadLoginInfo(employeeEntity);
|
||||
|
||||
// 移除登录失败
|
||||
securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE);
|
||||
@@ -242,8 +226,8 @@ public class LoginService implements StpInterface {
|
||||
// 设置 token
|
||||
loginResultVO.setToken(token);
|
||||
|
||||
// 清除权限缓存
|
||||
permissionCache.remove(employeeEntity.getEmployeeId());
|
||||
// 更新用户权限
|
||||
loginManager.loadUserPermission(employeeEntity.getEmployeeId());
|
||||
|
||||
return ResponseDTO.ok(loginResultVO);
|
||||
}
|
||||
@@ -262,10 +246,6 @@ public class LoginService implements StpInterface {
|
||||
List<MenuVO> menuAndPointsList = roleMenuService.getMenuList(roleList.stream().map(RoleVO::getRoleId).collect(Collectors.toList()), requestEmployee.getAdministratorFlag());
|
||||
loginResultVO.setMenuList(menuAndPointsList);
|
||||
|
||||
// 更新下后端权限缓存
|
||||
UserPermission userPermission = getUserPermission(requestEmployee.getUserId());
|
||||
permissionCache.put(requestEmployee.getUserId(), userPermission);
|
||||
|
||||
// 上次登录信息
|
||||
LoginLogVO loginLogVO = loginLogService.queryLastByUserId(requestEmployee.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE, LoginLogResultEnum.LOGIN_SUCCESS);
|
||||
if (loginLogVO != null) {
|
||||
@@ -289,32 +269,6 @@ public class LoginService implements StpInterface {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
private RequestEmployee loadLoginInfo(EmployeeEntity employeeEntity) {
|
||||
|
||||
// 基础信息
|
||||
RequestEmployee requestEmployee = SmartBeanUtil.copy(employeeEntity, RequestEmployee.class);
|
||||
requestEmployee.setUserType(UserTypeEnum.ADMIN_EMPLOYEE);
|
||||
|
||||
// 部门信息
|
||||
DepartmentVO department = departmentService.getDepartmentById(employeeEntity.getDepartmentId());
|
||||
requestEmployee.setDepartmentName(null == department ? StringConst.EMPTY : department.getName());
|
||||
|
||||
// 头像信息
|
||||
String avatar = employeeEntity.getAvatar();
|
||||
if (StringUtils.isNotBlank(avatar)) {
|
||||
ResponseDTO<String> getFileUrl = fileStorageService.getFileUrl(avatar);
|
||||
if (BooleanUtils.isTrue(getFileUrl.getOk())) {
|
||||
requestEmployee.setAvatar(getFileUrl.getData());
|
||||
}
|
||||
}
|
||||
|
||||
return requestEmployee;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据登陆token 获取员请求工信息
|
||||
*/
|
||||
@@ -328,17 +282,7 @@ public class LoginService implements StpInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
RequestEmployee requestEmployee = loginEmployeeCache.get(requestEmployeeId);
|
||||
if (requestEmployee == null) {
|
||||
// 员工基本信息
|
||||
EmployeeEntity employeeEntity = employeeService.getById(requestEmployeeId);
|
||||
if (employeeEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
requestEmployee = this.loadLoginInfo(employeeEntity);
|
||||
loginEmployeeCache.put(requestEmployeeId, requestEmployee);
|
||||
}
|
||||
RequestEmployee requestEmployee = loginManager.getRequestEmployee(requestEmployeeId);
|
||||
|
||||
// 更新请求ip和user agent
|
||||
requestEmployee.setUserAgent(JakartaServletUtil.getHeaderIgnoreCase(request, RequestHeaderConst.USER_AGENT));
|
||||
@@ -382,7 +326,7 @@ public class LoginService implements StpInterface {
|
||||
StpUtil.logout();
|
||||
|
||||
// 清空登录信息缓存
|
||||
loginEmployeeCache.remove(requestUser.getUserId());
|
||||
loginManager.clear();
|
||||
|
||||
//保存登出日志
|
||||
LoginLogEntity loginEntity = LoginLogEntity.builder()
|
||||
@@ -400,14 +344,6 @@ public class LoginService implements StpInterface {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除员工登录缓存
|
||||
*/
|
||||
public void clearLoginEmployeeCache(Long employeeId) {
|
||||
// 清空登录信息缓存
|
||||
loginEmployeeCache.remove(employeeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存登录日志
|
||||
*/
|
||||
@@ -435,12 +371,7 @@ public class LoginService implements StpInterface {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
UserPermission userPermission = permissionCache.get(employeeId);
|
||||
if (userPermission == null) {
|
||||
userPermission = getUserPermission(employeeId);
|
||||
permissionCache.put(employeeId, userPermission);
|
||||
}
|
||||
|
||||
UserPermission userPermission = loginManager.getUserPermission(employeeId);
|
||||
return userPermission.getPermissionList();
|
||||
}
|
||||
|
||||
@@ -451,51 +382,10 @@ public class LoginService implements StpInterface {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
UserPermission userPermission = permissionCache.get(employeeId);
|
||||
if (userPermission == null) {
|
||||
userPermission = getUserPermission(employeeId);
|
||||
permissionCache.put(employeeId, userPermission);
|
||||
}
|
||||
UserPermission userPermission = loginManager.getUserPermission(employeeId);
|
||||
return userPermission.getRoleList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的权限(包含 角色列表、权限列表)
|
||||
*/
|
||||
private UserPermission getUserPermission(Long employeeId) {
|
||||
|
||||
UserPermission userPermission = new UserPermission();
|
||||
userPermission.setPermissionList(new ArrayList<>());
|
||||
userPermission.setRoleList(new ArrayList<>());
|
||||
|
||||
// 角色列表
|
||||
List<RoleVO> roleList = roleEmployeeService.getRoleIdList(employeeId);
|
||||
userPermission.getRoleList().addAll(roleList.stream().map(RoleVO::getRoleCode).collect(Collectors.toSet()));
|
||||
|
||||
// 前端菜单和功能点清单
|
||||
EmployeeEntity employeeEntity = employeeService.getById(employeeId);
|
||||
|
||||
List<MenuVO> menuAndPointsList = roleMenuService.getMenuList(roleList.stream().map(RoleVO::getRoleId).collect(Collectors.toList()), employeeEntity.getAdministratorFlag());
|
||||
|
||||
// 权限列表
|
||||
HashSet<String> permissionSet = new HashSet<>();
|
||||
for (MenuVO menu : menuAndPointsList) {
|
||||
if (menu.getPermsType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String perms = menu.getApiPerms();
|
||||
if (StringUtils.isEmpty(perms)) {
|
||||
continue;
|
||||
}
|
||||
//接口权限
|
||||
String[] split = perms.split(",");
|
||||
permissionSet.addAll(Arrays.asList(split));
|
||||
}
|
||||
userPermission.getPermissionList().addAll(permissionSet);
|
||||
|
||||
return userPermission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 邮箱 验证码
|
||||
@@ -590,4 +480,8 @@ public class LoginService implements StpInterface {
|
||||
String redisVerificationCodeKey = redisService.generateRedisKey(RedisKeyConst.Support.LOGIN_VERIFICATION_CODE, UserTypeEnum.ADMIN_EMPLOYEE.getValue() + RedisKeyConst.SEPARATOR + employeeId);
|
||||
redisService.delete(redisVerificationCodeKey);
|
||||
}
|
||||
|
||||
public void clearLoginEmployeeCache(Long employeeId) {
|
||||
loginManager.clear();
|
||||
}
|
||||
}
|
||||
|
@@ -3,11 +3,7 @@ package net.lab1024.sa.admin.module.system.role.manager;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.lab1024.sa.admin.module.system.role.dao.RoleEmployeeDao;
|
||||
import net.lab1024.sa.admin.module.system.role.domain.entity.RoleEmployeeEntity;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色员工 manager
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.lab1024.sa.admin.module.business.oa.bank.BankDao">
|
||||
<mapper namespace="net.lab1024.sa.admin.module.business.oa.bank.dao.BankDao">
|
||||
<update id="deleteBank">
|
||||
UPDATE t_oa_bank
|
||||
SET deleted_flag = #{deletedFlag}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.lab1024.sa.admin.module.business.oa.invoice.InvoiceDao">
|
||||
<mapper namespace="net.lab1024.sa.admin.module.business.oa.invoice.dao.InvoiceDao">
|
||||
<update id="deleteInvoice">
|
||||
UPDATE t_oa_invoice
|
||||
SET deleted_flag = #{deletedFlag}
|
||||
|
@@ -19,5 +19,16 @@
|
||||
WHERE parent_id = #{departmentId}
|
||||
</select>
|
||||
|
||||
<select id="selectDepartmentVO"
|
||||
resultType="net.lab1024.sa.admin.module.system.department.domain.vo.DepartmentVO">
|
||||
SELECT t_department.*,
|
||||
t_employee.actual_name as managerName,
|
||||
parent_department.`name` as parentName
|
||||
FROM t_department
|
||||
left join t_employee on t_department.manager_id = t_employee.employee_id
|
||||
left join t_department parent_department on t_department.parent_id = parent_department.department_id
|
||||
where t_department.department_id = #{departmentId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user