瀏覽代碼

系统重构

sakuya 3 年之前
父節點
當前提交
67008507f9
共有 36 個文件被更改,包括 346 次插入741 次删除
  1. 3 9
      eladmin-system/src/main/java/me/zhengjie/application/admin/controller/DemoController.java
  2. 3 1
      eladmin-system/src/main/java/me/zhengjie/application/admin/controller/MenuController.java
  3. 1 2
      eladmin-system/src/main/java/me/zhengjie/application/admin/controller/NotaryOrderController.java
  4. 4 2
      eladmin-system/src/main/java/me/zhengjie/application/admin/controller/OrderRoomIdController.java
  5. 3 1
      eladmin-system/src/main/java/me/zhengjie/application/admin/controller/RoleController.java
  6. 46 18
      eladmin-system/src/main/java/me/zhengjie/application/admin/controller/UserController.java
  7. 1 1
      eladmin-system/src/main/java/me/zhengjie/application/admin/job/GenerateNotarizationJob.java
  8. 45 0
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/dto/JwtUserDto.java
  9. 3 1
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/DeptServiceImpl.java
  10. 12 10
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/ModelNotarizationServiceImpl.java
  11. 4 1
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/NotaryOfficeServiceImpl.java
  12. 11 9
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/NotaryOrderServiceImpl.java
  13. 5 2
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/OfficeXbankServiceImpl.java
  14. 0 25
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/RoleServiceImpl.java
  15. 71 75
      eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java
  16. 15 33
      eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/UserServiceImpl.java
  17. 2 1
      eladmin-system/src/main/java/me/zhengjie/application/bank/controller/AppBankController.java
  18. 1 1
      eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/ApiBankServiceImpl.java
  19. 5 5
      eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/BorrowerServiceImpl.java
  20. 1 1
      eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/GuaranteeServiceImpl.java
  21. 1 1
      eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/MortgageServiceImpl.java
  22. 11 14
      eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/NotaryNoteServiceImpl.java
  23. 18 16
      eladmin-system/src/main/java/me/zhengjie/application/user/app/mq/WebSocketReceiver.java
  24. 1 1
      eladmin-system/src/main/java/me/zhengjie/application/user/service/impl/ApiServiceImpl.java
  25. 1 1
      eladmin-system/src/main/java/me/zhengjie/base/BaseController.java
  26. 1 2
      eladmin-system/src/main/java/me/zhengjie/base/mq/MessagePushConfig.java
  27. 67 0
      eladmin-system/src/main/java/me/zhengjie/base/util/ApplicationContextUtil.java
  28. 1 10
      eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/BorrowerEntity.java
  29. 1 10
      eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/GuaranteeEntity.java
  30. 1 10
      eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/MortgageEntity.java
  31. 7 4
      eladmin-system/src/main/java/me/zhengjie/domain/user/impl/UserDomainImpl.java
  32. 0 134
      eladmin-system/src/main/java/me/zhengjie/modules/security/config/SpringSecurityConfig2.java
  33. 0 53
      eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserCacheClean.java
  34. 0 110
      eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserCacheManager.java
  35. 0 87
      eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java
  36. 0 90
      eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/OnlineUserDto.java

+ 3 - 9
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/DemoController.java

@@ -2,11 +2,11 @@ package me.zhengjie.application.admin.controller;
 
 import com.tencentyun.TLSSigAPIv2;
 import me.zhengjie.annotation.AnonymousAccess;
-import me.zhengjie.modules.mnt.websocket.MsgType;
-import me.zhengjie.modules.mnt.websocket.SocketMsg;
-import me.zhengjie.modules.mnt.websocket.WebSocketServer;
 import me.zhengjie.base.BaseResponse;
 import me.zhengjie.base.ResultData;
+import me.zhengjie.websocket.MsgType;
+import me.zhengjie.websocket.SocketMsg;
+import me.zhengjie.websocket.WebSocketServer;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
@@ -36,7 +36,6 @@ public class DemoController {
         return "success";
     }
 
-
     /**
      * 机构 查询  银行+公证处
      *
@@ -51,9 +50,4 @@ public class DemoController {
         response.setData(new ResultData(s));
         return response;
     }
-
-
-
-
-
 }

+ 3 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/MenuController.java

@@ -21,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.annotation.Log;
 import me.zhengjie.base.AppBaseResponse;
+import me.zhengjie.base.util.ApplicationContextUtil;
 import me.zhengjie.dao.mybatis.entity.Menu;
 import me.zhengjie.exception.BadRequestException;
 import me.zhengjie.application.admin.service.MenuService;
@@ -51,6 +52,7 @@ public class MenuController {
 
     private final MenuService menuService;
     private final MenuMapper menuMapper;
+    private final ApplicationContextUtil contextUtil;
     private static final String ENTITY_NAME = "menu";
 
     @ApiOperation("导出菜单数据")
@@ -63,7 +65,7 @@ public class MenuController {
     @GetMapping(value = "/build")
     @ApiOperation("获取前端所需菜单")
     public ResponseEntity<Object> buildMenus(){
-        List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId());
+        List<MenuDto> menuDtoList = menuService.findByUser(contextUtil.getCurrentUserId());
         List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
         return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK);
     }

+ 1 - 2
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/NotaryOrderController.java

@@ -43,13 +43,13 @@ public class NotaryOrderController {
 
     @Autowired
     private NotaryOrderService notaryOrderService;
-
     @Autowired
     private BorrowerService borrowerService;
     @Autowired
     MortgageService mortgageService;
     @Autowired
     GuaranteeService guaranteeService;
+
     /**
      * 公证订单 查询
      *
@@ -60,7 +60,6 @@ public class NotaryOrderController {
         return notaryOrderService.query(req);
     }
 
-
     /**
      * 查询 客户经理信息
      *

+ 4 - 2
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/OrderRoomIdController.java

@@ -2,6 +2,7 @@ package me.zhengjie.application.admin.controller;
 
 import java.util.List;
 
+import me.zhengjie.base.util.ApplicationContextUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
@@ -20,7 +21,6 @@ import me.zhengjie.application.bank.service.OrderRoomIdService;
 import me.zhengjie.base.util.FileUploadUtil;
 import me.zhengjie.base.ResultCode;
 import me.zhengjie.base.util.WebSocketMap;
-import me.zhengjie.utils.SecurityUtils;
 
 @RestController
 @Validated
@@ -29,6 +29,8 @@ import me.zhengjie.utils.SecurityUtils;
 public class OrderRoomIdController {
 	@Autowired
 	OrderRoomIdService orderRoomService;
+	@Autowired
+	ApplicationContextUtil contextUtil;
 
 	/**
 	 * 查询 借款人信息
@@ -75,7 +77,7 @@ public class OrderRoomIdController {
 		String socketId = jsonObj.getString("socketId");
 		List<JSONObject> data = WebSocketMap.get(socketId);
 		// try
-		String userName = SecurityUtils.getCurrentUsername();
+		String userName = contextUtil.getCurrentUsername();
 
 		AppBaseResponse<?> result = null;
 		if (data != null && data.size() > 0) {

+ 3 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/RoleController.java

@@ -20,6 +20,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.annotation.Log;
+import me.zhengjie.base.util.ApplicationContextUtil;
 import me.zhengjie.dao.mybatis.entity.Role;
 import me.zhengjie.exception.BadRequestException;
 import me.zhengjie.application.admin.service.RoleService;
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
 public class RoleController {
 
     private final RoleService roleService;
+    private final ApplicationContextUtil contextUtil;
 
     private static final String ENTITY_NAME = "role";
 
@@ -142,7 +144,7 @@ public class RoleController {
      * @return /
      */
     private int getLevels(Integer level){
-        List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
+        List<Integer> levels = roleService.findByUsersId(contextUtil.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
         int min = Collections.min(levels);
         if(level != null){
             if(level < min){

+ 46 - 18
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/UserController.java

@@ -21,22 +21,23 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.annotation.Log;
 import me.zhengjie.annotation.rest.AnonymousPostMapping;
+import me.zhengjie.application.admin.controller.vo.UserPassVo;
+import me.zhengjie.application.admin.controller.vo.UserReq;
+import me.zhengjie.application.admin.service.*;
+import me.zhengjie.application.admin.service.dto.JwtUserDto;
+import me.zhengjie.application.admin.service.dto.RoleSmallDto;
+import me.zhengjie.application.admin.service.dto.UserDto;
+import me.zhengjie.application.admin.service.dto.UserQueryCriteria;
+import me.zhengjie.application.bank.service.FileInfoService;
 import me.zhengjie.base.AppBaseResponse;
+import me.zhengjie.base.util.ApplicationContextUtil;
+import me.zhengjie.base.util.FileUploadUtil;
 import me.zhengjie.config.RsaProperties;
 import me.zhengjie.dao.mybatis.entity.Dept;
-import me.zhengjie.application.admin.controller.vo.UserReq;
-import me.zhengjie.application.admin.service.DataService;
+import me.zhengjie.dao.mybatis.entity.FileInfoEntity;
 import me.zhengjie.dao.mybatis.entity.User;
 import me.zhengjie.exception.BadRequestException;
-import me.zhengjie.application.admin.controller.vo.UserPassVo;
-import me.zhengjie.application.admin.service.DeptService;
-import me.zhengjie.application.admin.service.RoleService;
-import me.zhengjie.application.admin.service.dto.RoleSmallDto;
-import me.zhengjie.application.admin.service.dto.UserDto;
-import me.zhengjie.application.admin.service.dto.UserQueryCriteria;
-import me.zhengjie.application.admin.service.VerifyService;
-import me.zhengjie.utils.*;
-import me.zhengjie.application.admin.service.UserService;
+import me.zhengjie.utils.RsaUtils;
 import me.zhengjie.utils.enums.CodeEnum;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -47,9 +48,13 @@ import org.springframework.util.ObjectUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.*;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -68,6 +73,29 @@ public class UserController {
     private final DeptService deptService;
     private final RoleService roleService;
     private final VerifyService verificationCodeService;
+    private final FileInfoService fileInfoService;
+    private final ApplicationContextUtil contextUtil;
+
+    @ApiOperation("获取用户信息")
+    @GetMapping(value = "/info")
+    public ResponseEntity<Object> getUserInfo() {
+        // 这里需要处理图片显示问题
+        JwtUserDto jwtUserDto = contextUtil.getCurrentUser();
+        // 处理图片的显示,重新查询一下当前的用户的值
+        UserDto cacheUser = jwtUserDto.getUser();
+        UserDto user = userService.findUserNoCacheId(cacheUser.getId());
+        if (user != null) {
+            FileInfoEntity fileInfo = fileInfoService.getById(user.getSignImgId());
+            if (fileInfo != null) {
+                String signImgUrl = FileUploadUtil.getFileUrl(fileInfo.getPath());
+                cacheUser.setSignImgUrl(signImgUrl);
+            }else {
+                //这里需要设置图片的路径为空
+                cacheUser.setSignImgUrl("");
+            }
+        }
+        return ResponseEntity.ok(jwtUserDto);
+    }
 
     @ApiOperation("导出用户数据")
     @GetMapping(value = "/download")
@@ -88,7 +116,7 @@ public class UserController {
             userReq.getDeptIds().addAll(deptService.getDeptChildren(data));
         }
         // 数据权限
-        List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
+        List<Long> dataScopes = dataService.getDeptIds(userService.findByName(contextUtil.getCurrentUsername()));
         // getDeptIds() 不为空并且数据权限不为空则取交集
         Map<String,Object> userList = null;
         if (!CollectionUtils.isEmpty(userReq.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){
@@ -130,7 +158,7 @@ public class UserController {
     @ApiOperation("修改用户:个人中心")
     @PutMapping(value = "center")
     public ResponseEntity<Object> centerUser(@Validated(User.Update.class) @RequestBody User resources){
-        if(!resources.getId().equals(SecurityUtils.getCurrentUserId())){
+        if(!resources.getId().equals(contextUtil.getCurrentUserId())){
             throw new BadRequestException("不能修改他人资料");
         }
         userService.updateCenter(resources);
@@ -143,7 +171,7 @@ public class UserController {
     @PreAuthorize("@el.check('user:del')")
     public ResponseEntity<Object> deleteUser(@RequestBody Set<Long> ids){
         for (Long id : ids) {
-            Integer currentLevel =  Collections.min(roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
+            Integer currentLevel =  Collections.min(roleService.findByUsersId(contextUtil.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
             Integer optLevel =  Collections.min(roleService.findByUsersId(id).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
             if (currentLevel > optLevel) {
                 throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
@@ -158,7 +186,7 @@ public class UserController {
     public ResponseEntity<Object> updateUserPass(@RequestBody UserPassVo passVo) throws Exception {
         String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getOldPass());
         String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getNewPass());
-        UserDto user = userService.findByName(SecurityUtils.getCurrentUsername());
+        UserDto user = userService.findByName(contextUtil.getCurrentUsername());
         if(!passwordEncoder.matches(oldPass, user.getPassword())){
             throw new BadRequestException("修改失败,旧密码错误");
         }
@@ -180,7 +208,7 @@ public class UserController {
     @PostMapping(value = "/updateEmail/{code}")
     public ResponseEntity<Object> updateUserEmail(@PathVariable String code,@RequestBody User user) throws Exception {
         String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,user.getPassword());
-        UserDto userDto = userService.findByName(SecurityUtils.getCurrentUsername());
+        UserDto userDto = userService.findByName(contextUtil.getCurrentUsername());
         if(!passwordEncoder.matches(password, userDto.getPassword())){
             throw new BadRequestException("密码错误");
         }
@@ -221,7 +249,7 @@ public class UserController {
      * @param resources /
      */
     private void checkLevel(User resources) {
-        Integer currentLevel =  Collections.min(roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
+        Integer currentLevel =  Collections.min(roleService.findByUsersId(contextUtil.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
         Integer optLevel = roleService.findByRoles(resources.getRoles());
         if (currentLevel > optLevel) {
             throw new BadRequestException("角色权限不足");

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/job/GenerateNotarizationJob.java

@@ -98,7 +98,7 @@ public class GenerateNotarizationJob {
     private void signNotarization(OrderFileEntity orderFile) throws Exception{
         SysUserEntity notaryUser;
         NotaryOfficeEntity notaryOffice;
-        Integer notaryUserId;
+        String notaryUserId;
         if ("10".equals(orderFile.getContractId().substring(0, 2))) {
             BorrowerEntity borrower = borrowerMapper.selectById(orderFile.getContractId());
             notaryUserId = borrower.getNotaryUserId();

+ 45 - 0
eladmin-system/src/main/java/me/zhengjie/application/admin/service/dto/JwtUserDto.java

@@ -0,0 +1,45 @@
+/*
+ *  Copyright 2019-2020 Zheng Jie
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package me.zhengjie.application.admin.service.dto;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import me.zhengjie.security.service.dto.OnlineUserDto;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author Zheng Jie
+ * @date 2018-11-23
+ */
+@NoArgsConstructor
+@Getter
+@Setter
+public class JwtUserDto extends OnlineUserDto {
+
+    private UserDto user;
+
+    public Set<String> getRoles() {
+        return getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
+    }
+}

+ 3 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/DeptServiceImpl.java

@@ -18,6 +18,7 @@ package me.zhengjie.application.admin.service.impl;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
+import me.zhengjie.base.util.ApplicationContextUtil;
 import me.zhengjie.exception.BadRequestException;
 import me.zhengjie.dao.mybatis.entity.Dept;
 import me.zhengjie.dao.mybatis.entity.User;
@@ -54,11 +55,12 @@ public class DeptServiceImpl implements DeptService {
     private final UserRepository userRepository;
     private final RedisUtils redisUtils;
     private final RoleRepository roleRepository;
+    private final ApplicationContextUtil contextUtil;
 
     @Override
     public List<DeptDto> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
         Sort sort = Sort.by(Sort.Direction.ASC, "deptSort");
-        String dataScopeType = SecurityUtils.getDataScopeType();
+        String dataScopeType = contextUtil.getDataScopeType();
         if (isQuery) {
             if(dataScopeType.equals(DataScopeEnum.ALL.getValue())){
                 criteria.setPidIsNull(true);

+ 12 - 10
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/ModelNotarizationServiceImpl.java

@@ -4,22 +4,22 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.dao.mybatis.entity.NotaryNoteEntity;
+import me.zhengjie.application.admin.controller.vo.ModelReq;
+import me.zhengjie.application.admin.controller.vo.NotaryNoteReq;
+import me.zhengjie.application.admin.service.ModelNotarizationService;
+import me.zhengjie.application.admin.service.dto.JwtUserDto;
 import me.zhengjie.base.AppBaseResponse;
 import me.zhengjie.base.AppResultData;
-import me.zhengjie.dao.mybatis.mapper.INotaryNoteDao;
-import me.zhengjie.base.util.BeanCopyUtils;
 import me.zhengjie.base.ResultCode;
-import me.zhengjie.modules.security.service.dto.JwtUserDto;
-import me.zhengjie.domain.user.UserDomain;
+import me.zhengjie.base.util.ApplicationContextUtil;
+import me.zhengjie.base.util.BeanCopyUtils;
 import me.zhengjie.dao.mybatis.entity.ModelEntity;
+import me.zhengjie.dao.mybatis.entity.NotaryNoteEntity;
 import me.zhengjie.dao.mybatis.entity.NotaryOfficeEntity;
-import me.zhengjie.application.admin.controller.vo.ModelReq;
-import me.zhengjie.application.admin.controller.vo.NotaryNoteReq;
+import me.zhengjie.dao.mybatis.mapper.INotaryNoteDao;
 import me.zhengjie.dao.mybatis.mapper.ModelMapper;
 import me.zhengjie.dao.mybatis.mapper.NotaryOfficeMapper;
-import me.zhengjie.application.admin.service.ModelNotarizationService;
-import me.zhengjie.utils.SecurityUtils;
+import me.zhengjie.domain.user.UserDomain;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -42,6 +42,8 @@ public class ModelNotarizationServiceImpl implements ModelNotarizationService {
     private INotaryNoteDao notaryNoteDao;
     @Autowired
     private NotaryOfficeMapper notaryOfficeMapper;
+    @Autowired
+    private ApplicationContextUtil contextUtil;
 
     /**
      * 查询公证文书列表
@@ -106,7 +108,7 @@ public class ModelNotarizationServiceImpl implements ModelNotarizationService {
         String roleName = userDomain.getUserMaxRole();
         if ("超级管理员".equals(roleName)) {
         } else if ("公证处管理员".equals(roleName)) {
-            JwtUserDto user = (JwtUserDto) SecurityUtils.getCurrentUser();
+            JwtUserDto user = contextUtil.getCurrentUser();
             qw.eq("notary_office_id", user.getUser().getOrgId().split("_")[1]);
         } else {
             return null;

+ 4 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/NotaryOfficeServiceImpl.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.base.config.AppConfigInfo;
+import me.zhengjie.base.util.ApplicationContextUtil;
 import me.zhengjie.dao.mybatis.entity.SysUserEntity;
 import me.zhengjie.base.AppBaseResponse;
 import me.zhengjie.base.AppResultData;
@@ -75,6 +76,8 @@ public class NotaryOfficeServiceImpl extends ServiceImpl<NotaryOfficeMapper, Not
 	private String systemEnv;
 	@Autowired
 	private FileInfoService fileInfoService;
+	@Autowired
+	private ApplicationContextUtil contextUtil;
 
 	/**
 	 * 查询公证处信息
@@ -83,7 +86,7 @@ public class NotaryOfficeServiceImpl extends ServiceImpl<NotaryOfficeMapper, Not
 	 */
 	public AppBaseResponse<NotaryOfficeQueryRsp> detail() {
 		AppBaseResponse<NotaryOfficeQueryRsp> response = new AppBaseResponse<>();
-		SysUserEntity user = userMapper.selectById(SecurityUtils.getCurrentUserId());
+		SysUserEntity user = userMapper.selectById(contextUtil.getCurrentUserId());
 		NotaryOfficeEntity office = notaryOfficeMapper.selectById(user.getOrgId().split("_")[1]);
 		NotaryOfficeQueryRsp officeQueryRsp = BeanCopyUtils.convertObj(office, NotaryOfficeQueryRsp.class);
 		// 需要判断是否是字符串

+ 11 - 9
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/NotaryOrderServiceImpl.java

@@ -93,6 +93,8 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 	
 	@Autowired
 	FileInfoService fileInfoService;
+	@Autowired
+	ApplicationContextUtil contextUtil;
 	
 	@Override
 	public AppBaseResponse<List<NotaryOrderQueryRsp>> query(NotaryOrderQueryReq req) {
@@ -119,7 +121,7 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 	 */
 	private QueryWrapper<NotaryOrderEntity> getQueryWrapper(NotaryOrderQueryReq req) {
 		QueryWrapper<NotaryOrderEntity> qw = new QueryWrapper<>();
-		SysUserEntity user = userDao.selectById(SecurityUtils.getCurrentUserId());
+		SysUserEntity user = userDao.selectById(contextUtil.getCurrentUserId());
 		String maxRole = userDomain.getUserMaxRole();
 		if ("超级管理员".equals(maxRole)) {
 		} else if ("公证处管理员".equals(maxRole)) {
@@ -272,7 +274,7 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 	@Override
 	public AppBaseResponse checkInfoPass(NotaryOrderQueryReq req) {
 		AppBaseResponse response = new AppBaseResponse();
-		String currentUserId = String.valueOf(SecurityUtils.getCurrentUserId());
+		String currentUserId = String.valueOf(contextUtil.getCurrentUserId());
 		String status = StatusEnum.NotaryStatusEnum.NOTARIZED.getStatus().toString();
 		Long partyId = Long.parseLong(req.getPartyId());
 		if ("1".equals(req.getRoleId())) {
@@ -466,7 +468,7 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 		notaryOrderFile.setPdfUrl(pdfPath);
 		notaryOrderFile.setSortNum(modelEntity.getSort());
 		notaryOrderFile.setCreateTime(new Date());
-		notaryOrderFile.setCreatorId(SecurityUtils.getCurrentUserId());
+		notaryOrderFile.setCreatorId(contextUtil.getCurrentUserId());
 		orderFileMapper.insert(notaryOrderFile);
 		// 更新当前公证书编号
 		NotarizationNoEntity notarizationNo = new NotarizationNoEntity();
@@ -490,15 +492,15 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 		// 更新子订单数据
 		if (orderId.startsWith("10")) {
 			borrowerMapper.updateById(BorrowerEntity.builder().updateTime(LocalDateTime.now())
-					.updater(SecurityUtils.getCurrentUserId().toString()).id(Long.parseLong(orderId))
+					.updater(contextUtil.getCurrentUserId().toString()).id(Long.parseLong(orderId))
 					.status(StatusEnum.NotaryStatusEnum.PASS.getStatus().toString()).build());
 		} else if (orderId.startsWith("11")) {
 			mortgageMapper.updateById(MortgageEntity.builder().updateTime(LocalDateTime.now())
-					.updater(SecurityUtils.getCurrentUserId().toString()).id(Long.parseLong(orderId))
+					.updater(contextUtil.getCurrentUserId().toString()).id(Long.parseLong(orderId))
 					.status(StatusEnum.NotaryStatusEnum.PASS.getStatus().toString()).build());
 		} else if (orderId.startsWith("12")) {
 			guaranteeMapper.updateById(GuaranteeEntity.builder().updateTime(LocalDateTime.now())
-					.updater(SecurityUtils.getCurrentUserId().toString()).id(Long.parseLong(orderId))
+					.updater(contextUtil.getCurrentUserId().toString()).id(Long.parseLong(orderId))
 					.status(StatusEnum.NotaryStatusEnum.PASS.getStatus().toString()).build());
 		}
 		// 更新主订单数据
@@ -535,7 +537,7 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 			NotaryOrderEntity saveOrder = new NotaryOrderEntity();
 			saveOrder.setId(notaryOrderEntity.getId());
 			saveOrder.setUpdateTime(LocalDateTime.now());
-			saveOrder.setUpdater(SecurityUtils.getCurrentUserId().toString());
+			saveOrder.setUpdater(contextUtil.getCurrentUserId().toString());
 			saveOrder.setStatus(StatusEnum.NotaryStatusEnum.PASS.getStatus().toString());
 			notaryOrderMapper.updateById(saveOrder);
 			//流程走完之后需要把数据插入到order_cochain
@@ -643,7 +645,7 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 		AppBaseResponse response = new AppBaseResponse();
 		try {
 			NotaryOrderEntity orderEntity = orderMapper.selectById(req.getId());
-			SysUserEntity user = userDao.selectById(SecurityUtils.getCurrentUserId());
+			SysUserEntity user = userDao.selectById(contextUtil.getCurrentUserId());
 			if ("notary".equals(user.getOrgId().split("_")[0])
 					&& orderEntity.getNotaryOfficeId().equals(user.getOrgId().split("_")[1])) {
 				SysUserEntity customer = userDao.selectById(orderEntity.getCustomerId());
@@ -691,7 +693,7 @@ public class NotaryOrderServiceImpl extends ServiceImpl<NotaryOrderMapper, Notar
 		notaryOrderFile.setCode(code);
 		notaryOrderFile.setSignedPdfUrl(fileInfoEntity.getPath());
 		notaryOrderFile.setCreateTime(new Date());
-		notaryOrderFile.setCreatorId(SecurityUtils.getCurrentUserId());
+		notaryOrderFile.setCreatorId(contextUtil.getCurrentUserId());
 		notaryOrderFile.setFileName(file.getFileName());
 		orderFileMapper.insert(notaryOrderFile);
 

+ 5 - 2
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/OfficeXbankServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.base.AppBaseResponse;
 import me.zhengjie.base.AppResultData;
+import me.zhengjie.base.util.ApplicationContextUtil;
 import me.zhengjie.base.util.BeanCopyUtils;
 import me.zhengjie.base.ResultCode;
 import me.zhengjie.dao.mybatis.entity.BankEntity;
@@ -35,6 +36,8 @@ public class OfficeXbankServiceImpl implements OfficeXbankService {
     private OfficeXbankMapper officeXbankMapper;
     @Autowired
     private NotaryOrderMapper notaryOrderMapper;
+    @Autowired
+    private ApplicationContextUtil contextUtil;
 
     /**
      * 查找尚未关联的银行列表
@@ -114,7 +117,7 @@ public class OfficeXbankServiceImpl implements OfficeXbankService {
                 entity.setBankId(bankId);
                 entity.setBzStatus("1");
                 entity.setCreateTime(new Date());
-                entity.setCreatorId(String.valueOf(SecurityUtils.getCurrentUserId()));
+                entity.setCreatorId(String.valueOf(contextUtil.getCurrentUserId()));
                 officeXbankMapper.insert(entity);
             }
             // 设置删除配置状态
@@ -127,7 +130,7 @@ public class OfficeXbankServiceImpl implements OfficeXbankService {
                 OfficeXbankEntity entity = new OfficeXbankEntity();
                 entity.setBzStatus("0");
                 entity.setUpdateTime(new Date());
-                entity.setUpdatorId(String.valueOf(SecurityUtils.getCurrentUserId()));
+                entity.setUpdatorId(String.valueOf(contextUtil.getCurrentUserId()));
                 officeXbankMapper.update(entity, uw);
             }
         }catch (Exception e){

+ 0 - 25
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/RoleServiceImpl.java

@@ -18,7 +18,6 @@ package me.zhengjie.application.admin.service.impl;
 import cn.hutool.core.collection.CollectionUtil;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.exception.BadRequestException;
-import me.zhengjie.modules.security.service.UserCacheClean;
 import me.zhengjie.dao.mybatis.entity.Menu;
 import me.zhengjie.dao.mybatis.entity.Role;
 import me.zhengjie.exception.EntityExistException;
@@ -61,7 +60,6 @@ public class RoleServiceImpl implements RoleService {
     private final RoleSmallMapper roleSmallMapper;
     private final RedisUtils redisUtils;
     private final UserRepository userRepository;
-    private final UserCacheClean userCacheClean;
 
     @Override
     public List<RoleDto> queryAll() {
@@ -115,8 +113,6 @@ public class RoleServiceImpl implements RoleService {
         role.setDepts(resources.getDepts());
         role.setLevel(resources.getLevel());
         roleRepository.save(role);
-        // 更新相关缓存
-        delCaches(role.getId(), null);
     }
 
     @Override
@@ -125,7 +121,6 @@ public class RoleServiceImpl implements RoleService {
         List<User> users = userRepository.findByRoleId(role.getId());
         // 更新菜单
         role.setMenus(resources.getMenus());
-        delCaches(resources.getId(), users);
         roleRepository.save(role);
     }
 
@@ -139,10 +134,6 @@ public class RoleServiceImpl implements RoleService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void delete(Set<Long> ids) {
-        for (Long id : ids) {
-            // 更新相关缓存
-            delCaches(id, null);
-        }
         roleRepository.deleteAllByIdIn(ids);
     }
 
@@ -206,20 +197,4 @@ public class RoleServiceImpl implements RoleService {
     public List<Role> findInMenuId(List<Long> menuIds) {
         return roleRepository.findInMenuId(menuIds);
     }
-
-    /**
-     * 清理缓存
-     * @param id /
-     */
-    public void delCaches(Long id, List<User> users) {
-        users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users;
-        if (CollectionUtil.isNotEmpty(users)) {
-            users.forEach(item -> userCacheClean.cleanUserCache(item.getUsername()));
-            Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
-            redisUtils.delByKeys(CacheKey.DATA_USER, userIds);
-            redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
-            redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
-        }
-        redisUtils.del(CacheKey.ROLE_ID + id);
-    }
 }

+ 71 - 75
eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java

@@ -13,27 +13,25 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package me.zhengjie.modules.security.service;
+package me.zhengjie.application.admin.service.impl;
 
 import lombok.RequiredArgsConstructor;
-import me.zhengjie.exception.BadRequestException;
-import me.zhengjie.exception.EntityNotFoundException;
-import me.zhengjie.modules.security.config.bean.LoginProperties;
-import me.zhengjie.modules.security.service.dto.JwtUserDto;
-import me.zhengjie.dao.mybatis.entity.BankEntity;
-import me.zhengjie.dao.mybatis.entity.NotaryOfficeEntity;
-import me.zhengjie.dao.mybatis.mapper.BankMapper;
-import me.zhengjie.dao.mybatis.mapper.NotaryOfficeMapper;
 import me.zhengjie.application.admin.service.DataService;
 import me.zhengjie.application.admin.service.RoleService;
 import me.zhengjie.application.admin.service.UserService;
+import me.zhengjie.application.admin.service.dto.JwtUserDto;
 import me.zhengjie.application.admin.service.dto.UserDto;
-import org.springframework.beans.factory.annotation.Autowired;
+import me.zhengjie.dao.mybatis.entity.BankEntity;
+import me.zhengjie.dao.mybatis.entity.NotaryOfficeEntity;
+import me.zhengjie.dao.mybatis.mapper.BankMapper;
+import me.zhengjie.dao.mybatis.mapper.NotaryOfficeMapper;
+import me.zhengjie.exception.BadRequestException;
+import me.zhengjie.exception.EntityNotFoundException;
+import me.zhengjie.security.config.bean.LoginProperties;
 import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -48,13 +46,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
     private final RoleService roleService;
     private final DataService dataService;
     private final LoginProperties loginProperties;
-
-    private final UserCacheManager USER_DTO_CACHE;
-
-    @Autowired
-    private NotaryOfficeMapper notaryOfficeMapper;
-    @Autowired
-    private BankMapper bankMapper;
+    private final NotaryOfficeMapper notaryOfficeMapper;
+    private final BankMapper bankMapper;
 
     public void setEnableCache(boolean enableCache) {
         this.loginProperties.setCacheEnable(enableCache);
@@ -65,8 +58,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
     @Override
     public JwtUserDto loadUserByUsername(String username) {
         JwtUserDto jwtUserDto = null;
-        Future<JwtUserDto> future = USER_DTO_CACHE.get(username);
-        if (!loginProperties.isCacheEnable()) {
+//        Future<JwtUserDto> future = USER_DTO_CACHE.get(username);
+//        if (!loginProperties.isCacheEnable()) {
             UserDto user;
             try {
                 user = userService.findByName(username);
@@ -91,58 +84,63 @@ public class UserDetailsServiceImpl implements UserDetailsService {
                         user.setAutoGenerate(notaryOfficeEntity.getAutoGenerate());
                     }
                 }
-                jwtUserDto = new JwtUserDto(
-                        user,
-                        dataService.getDeptIds(user),
-                        roleService.mapToGrantedAuthorities(user)
-                );
+                jwtUserDto = new JwtUserDto();
+                jwtUserDto.setUser(user);
+                jwtUserDto.setUserId(user.getId());
+                jwtUserDto.setDataScopes(dataService.getDeptIds(user));
+                jwtUserDto.setAuthorities(roleService.mapToGrantedAuthorities(user));
+                jwtUserDto.setEnabled(user.getEnabled());
+                jwtUserDto.setUsername(user.getUsername());
+                jwtUserDto.setPassword(user.getPassword());
+                jwtUserDto.setNickName(user.getNickName());
+                jwtUserDto.setDept(user.getDept().getName());
             }
             return jwtUserDto;
-        }
-
-        if (future == null) {
-            Callable<JwtUserDto> call = () -> getJwtBySearchDb(username);
-            FutureTask<JwtUserDto> ft = new FutureTask<>(call);
-            future = USER_DTO_CACHE.putIfAbsent(username, ft);
-            if (future == null) {
-                future = ft;
-                executor.submit(ft);
-            }
-            try {
-                return future.get();
-            } catch (CancellationException e) {
-                USER_DTO_CACHE.remove(username);
-                System.out.println("error" + Thread.currentThread().getName());
-            } catch (InterruptedException | ExecutionException e) {
-                throw new RuntimeException(e.getMessage());
-            }
-        } else {
-            try {
-                jwtUserDto = future.get();
-            } catch (UsernameNotFoundException e) {
-                throw new UsernameNotFoundException(e.getMessage());
-            }
-            catch (InterruptedException | ExecutionException e) {
-                throw new RuntimeException(e.getMessage());
-            }
-            // 检查dataScope是否修改
-            List<Long> dataScopes = jwtUserDto.getDataScopes();
-            dataScopes.clear();
-            dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
-
-        }
-        if (!org.springframework.util.StringUtils.isEmpty(jwtUserDto.getUser().getOrgId())){
-            String[] split = jwtUserDto.getUser().getOrgId().split("_");
-            if ("bank".equals(split[0])){
-                BankEntity bankEntity = bankMapper.selectById(split[1]);
-                jwtUserDto.getUser().setOrgName(bankEntity.getBankName());
-            } else {
-                NotaryOfficeEntity notaryOfficeEntity = notaryOfficeMapper.selectById(split[1]);
-                jwtUserDto.getUser().setOrgName(notaryOfficeEntity.getName());
-                jwtUserDto.getUser().setAutoGenerate(notaryOfficeEntity.getAutoGenerate());
-            }
-        }
-        return jwtUserDto;
+//        }
+//
+//        if (future == null) {
+//            Callable<JwtUserDto> call = () -> getJwtBySearchDb(username);
+//            FutureTask<JwtUserDto> ft = new FutureTask<>(call);
+//            future = USER_DTO_CACHE.putIfAbsent(username, ft);
+//            if (future == null) {
+//                future = ft;
+//                executor.submit(ft);
+//            }
+//            try {
+//                return future.get();
+//            } catch (CancellationException e) {
+//                USER_DTO_CACHE.remove(username);
+//                System.out.println("error" + Thread.currentThread().getName());
+//            } catch (InterruptedException | ExecutionException e) {
+//                throw new RuntimeException(e.getMessage());
+//            }
+//        } else {
+//            try {
+//                jwtUserDto = future.get();
+//            } catch (UsernameNotFoundException e) {
+//                throw new UsernameNotFoundException(e.getMessage());
+//            }
+//            catch (InterruptedException | ExecutionException e) {
+//                throw new RuntimeException(e.getMessage());
+//            }
+//            // 检查dataScope是否修改
+//            List<Long> dataScopes = jwtUserDto.getDataScopes();
+//            dataScopes.clear();
+//            dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
+//
+//        }
+//        if (!org.springframework.util.StringUtils.isEmpty(jwtUserDto.getUser().getOrgId())){
+//            String[] split = jwtUserDto.getUser().getOrgId().split("_");
+//            if ("bank".equals(split[0])){
+//                BankEntity bankEntity = bankMapper.selectById(split[1]);
+//                jwtUserDto.getUser().setOrgName(bankEntity.getBankName());
+//            } else {
+//                NotaryOfficeEntity notaryOfficeEntity = notaryOfficeMapper.selectById(split[1]);
+//                jwtUserDto.getUser().setOrgName(notaryOfficeEntity.getName());
+//                jwtUserDto.getUser().setAutoGenerate(notaryOfficeEntity.getAutoGenerate());
+//            }
+//        }
+//        return jwtUserDto;
     }
 
     private JwtUserDto getJwtBySearchDb(String username) {
@@ -170,11 +168,9 @@ public class UserDetailsServiceImpl implements UserDetailsService {
                     user.setAutoGenerate(notaryOfficeEntity.getAutoGenerate());
                 }
             }
-            return new JwtUserDto(
-                    user,
-                    dataService.getDeptIds(user),
-                    roleService.mapToGrantedAuthorities(user)
-            );
+            JwtUserDto jwtUserDto = new JwtUserDto();
+            jwtUserDto.setUser(user);
+            return jwtUserDto;
         }
 
     }

+ 15 - 33
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/UserServiceImpl.java

@@ -20,29 +20,24 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
+import me.zhengjie.application.admin.controller.vo.UserReq;
+import me.zhengjie.application.admin.service.UserService;
 import me.zhengjie.application.admin.service.dto.*;
+import me.zhengjie.application.admin.service.mapstruct.UserMapper;
 import me.zhengjie.base.AppBaseResponse;
 import me.zhengjie.base.AppResultData;
-import me.zhengjie.base.util.BeanCopyUtils;
-import me.zhengjie.base.util.FileUploadUtil;
 import me.zhengjie.base.ResultCode;
+import me.zhengjie.base.util.*;
 import me.zhengjie.config.FileProperties;
 import me.zhengjie.dao.mybatis.entity.*;
 import me.zhengjie.dao.mybatis.mapper.*;
-import me.zhengjie.exception.BadRequestException;
-import me.zhengjie.exception.EntityExistException;
-import me.zhengjie.exception.EntityNotFoundException;
-import me.zhengjie.modules.security.service.OnlineUserService;
-import me.zhengjie.modules.security.service.UserCacheClean;
-import me.zhengjie.modules.security.service.dto.JwtUserDto;
 import me.zhengjie.domain.office.NotaryOfficeConstant;
 import me.zhengjie.domain.user.UserConstant;
 import me.zhengjie.domain.user.UserDomain;
-import me.zhengjie.application.admin.controller.vo.UserReq;
-import me.zhengjie.application.admin.service.UserService;
-import me.zhengjie.application.admin.service.mapstruct.UserMapper;
-import me.zhengjie.base.util.CFCACertUtil;
-import me.zhengjie.base.util.TencentServiceUtil;
+import me.zhengjie.exception.BadRequestException;
+import me.zhengjie.exception.EntityExistException;
+import me.zhengjie.exception.EntityNotFoundException;
+import me.zhengjie.security.service.OnlineUserService;
 import me.zhengjie.utils.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -73,8 +68,8 @@ public class UserServiceImpl implements UserService {
     private final UserMapper userMapper;
     private final FileProperties properties;
     private final RedisUtils redisUtils;
-    private final UserCacheClean userCacheClean;
     private final OnlineUserService onlineUserService;
+    private final ApplicationContextUtil contextUtil;
     @Autowired
     private NotaryOfficeMapper notaryOfficeMapper;
     @Autowired
@@ -205,7 +200,7 @@ public class UserServiceImpl implements UserService {
      */
     private QueryWrapper<SysUserEntity> getQueryWrapper(UserReq userReq) {
         QueryWrapper<SysUserEntity> qw = new QueryWrapper<>();
-        JwtUserDto userDto = (JwtUserDto) SecurityUtils.getCurrentUser();
+        JwtUserDto userDto = contextUtil.getCurrentUser();
         String maxRole = userDomain.getUserMaxRole();
         if ("超级管理员".equals(maxRole)) {
         } else if ("公证处管理员".equals(maxRole) || "银行管理员".equals(maxRole)) {
@@ -304,7 +299,7 @@ public class UserServiceImpl implements UserService {
      */
     public AppBaseResponse uploadSeal(User resources){
         AppBaseResponse response = new AppBaseResponse();
-        SysUserEntity user = userDao.selectById(SecurityUtils.getCurrentUserId());
+        SysUserEntity user = userDao.selectById(contextUtil.getCurrentUserId());
         if(UserConstant.USER_TYPE_NOTARY.equals(user.getOrgId().split("_")[0])) {
             NotaryOfficeEntity entity = notaryOfficeMapper.selectById(user.getOrgId().split("_")[1]);
             if (NotaryOfficeConstant.NOTARY_AUTO_GENERATE.equals(entity.getAutoGenerate())) {
@@ -429,7 +424,6 @@ public class UserServiceImpl implements UserService {
     @Transactional(rollbackFor = Exception.class)
     public void updatePass(String username, String pass) {
         userRepository.updatePass(username, pass, new Date());
-        flushCache(username);
     }
 
     @Override
@@ -443,7 +437,7 @@ public class UserServiceImpl implements UserService {
         if(fileType != null && !image.contains(fileType)){
             throw new BadRequestException("文件格式错误!, 仅支持 " + image +" 格式");
         }
-        User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
+        User user = userRepository.findByUsername(contextUtil.getCurrentUsername());
         String oldPath = user.getAvatarPath();
         File file = FileUtil.upload(multipartFile, properties.getPath().getAvatar());
         user.setAvatarPath(Objects.requireNonNull(file).getPath());
@@ -453,7 +447,6 @@ public class UserServiceImpl implements UserService {
             FileUtil.del(oldPath);
         }
         @NotBlank String username = user.getUsername();
-        flushCache(username);
         return new HashMap<String, String>(1) {{
             put("avatar", file.getName());
         }};
@@ -463,7 +456,6 @@ public class UserServiceImpl implements UserService {
     @Transactional(rollbackFor = Exception.class)
     public void updateEmail(String username, String email) {
         userRepository.updateEmail(username, email);
-        flushCache(username);
     }
 
     @Override
@@ -493,16 +485,6 @@ public class UserServiceImpl implements UserService {
      */
     public void delCaches(Long id, String username) {
         redisUtils.del(CacheKey.USER_ID + id);
-        flushCache(username);
-    }
-
-    /**
-     * 清理 登陆时 用户缓存信息
-     *
-     * @param username /
-     */
-    private void flushCache(String username) {
-        userCacheClean.cleanUserCache(username);
     }
 
     @Override
@@ -526,7 +508,7 @@ public class UserServiceImpl implements UserService {
             e.printStackTrace();
             throw new EntityNotFoundException(User.class, "安心签接口错误", "验证授权验证码出错");
         }
-        user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
+        user = userRepository.findByUsername(contextUtil.getCurrentUsername());
         user.setAxqIsAuth("1");
         userRepository.save(user);
         // 清除缓存
@@ -540,8 +522,8 @@ public class UserServiceImpl implements UserService {
     @Override
     public AppBaseResponse getAuthStatus() {
         AppBaseResponse response = new AppBaseResponse();
-        SysUserEntity userEntity = userDao.selectById(SecurityUtils.getCurrentUserId());
-        System.out.println(SecurityUtils.getCurrentUserId());
+        SysUserEntity userEntity = userDao.selectById(contextUtil.getCurrentUserId());
+        System.out.println(contextUtil.getCurrentUserId());
         String authStatus = StringUtils.isEmpty(userEntity.getAxqIsAuth()) ? "0" : userEntity.getAxqIsAuth();
         if ("0".equals(authStatus)) {
             CFCACertUtil.proxySwitchOn = "dev".equals(systemEnv);

+ 2 - 1
eladmin-system/src/main/java/me/zhengjie/application/bank/controller/AppBankController.java

@@ -20,7 +20,7 @@ import me.zhengjie.base.ResultCode;
 import me.zhengjie.base.BaseController;
 import me.zhengjie.dao.mybatis.OrderFileRepository;
 import me.zhengjie.dao.mybatis.entity.OrderFileEntity;
-import me.zhengjie.modules.security.security.TokenProvider;
+import me.zhengjie.security.security.TokenProvider;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.validation.annotation.Validated;
@@ -170,6 +170,7 @@ public class AppBankController extends BaseController {
 		OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult();
 		return ResponseDTO.success(detailDto);
 	}
+
 	@RequestMapping("/order/search")
 	public ResponseDTO<?> orderSearch(@RequestBody String json) {
 		 

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/ApiBankServiceImpl.java

@@ -3,6 +3,7 @@ package me.zhengjie.application.bank.service.impl;
 import java.util.ArrayList;
 import java.util.List;
 
+import me.zhengjie.security.security.TokenProvider;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -21,7 +22,6 @@ import me.zhengjie.base.ResponseDTO;
 import me.zhengjie.base.ResultCode;
 import me.zhengjie.dao.mybatis.OrderFileRepository;
 import me.zhengjie.dao.mybatis.entity.OrderFileEntity;
-import me.zhengjie.modules.security.security.TokenProvider;
 
 /**
  * 银行app端登录

+ 5 - 5
eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/BorrowerServiceImpl.java

@@ -103,11 +103,11 @@ public class BorrowerServiceImpl extends AbstractServiceImpl<BorrowerMapper, Bor
         if (note != null) {
             order.setAuthNote(FileUploadUtil.getPreviewUrl(note.getSignedPdfUrl()));
         }
-		if (!StringUtils.isEmpty(String.valueOf(borrowers.getNotaryUserId()))) {
-			SysUserEntity user = userDao.selectById(borrowers.getNotaryUserId());
-			order.setNotaryUserName(user.getNickName());
-			order.setNotaryFee(200);
-		}
+        if (!StringUtils.isEmpty(borrowers.getNotaryUserId())) {
+            SysUserEntity user = userDao.selectById(borrowers.getNotaryUserId());
+            order.setNotaryUserName(user.getNickName());
+            order.setNotaryFee(200);
+        }
 		response.setData(new AppResultData<OrderDetailDto>(order));
 		return response;
 	}

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/GuaranteeServiceImpl.java

@@ -65,7 +65,7 @@ public class GuaranteeServiceImpl extends AbstractServiceImpl<GuaranteeMapper, G
 		if (note != null) {
 			order.setAuthNote(FileUploadUtil.getPreviewUrl(note.getSignedPdfUrl()));
 		}
-		if (!StringUtils.isEmpty(String.valueOf(entity.getNotaryUserId()))) {
+		if (!StringUtils.isEmpty(entity.getNotaryUserId())) {
 			SysUserEntity user = userDao.selectById(entity.getNotaryUserId());
 			order.setNotaryUserName(user.getNickName());
 			order.setNotaryFee(200);

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/MortgageServiceImpl.java

@@ -63,7 +63,7 @@ public class MortgageServiceImpl extends AbstractServiceImpl<MortgageMapper, Mor
 		if (note != null) {
 			order.setAuthNote(FileUploadUtil.getPreviewUrl(note.getSignedPdfUrl()));
 		}
-		if (!StringUtils.isEmpty(String.valueOf(entity.getNotaryUserId()))) {
+		if (!StringUtils.isEmpty(entity.getNotaryUserId())) {
 			SysUserEntity user = userDao.selectById(entity.getNotaryUserId());
 			order.setNotaryUserName(user.getNickName());
 			order.setNotaryFee(200);

+ 11 - 14
eladmin-system/src/main/java/me/zhengjie/application/bank/service/impl/NotaryNoteServiceImpl.java

@@ -3,22 +3,17 @@ package me.zhengjie.application.bank.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import me.zhengjie.application.admin.service.dto.UserDto;
 import me.zhengjie.application.bank.controller.vo.NotaryNoteDto;
-import me.zhengjie.dao.mybatis.entity.*;
-import me.zhengjie.base.AppBaseResponse;
-import me.zhengjie.dao.mybatis.mapper.*;
+import me.zhengjie.application.bank.controller.vo.NotaryNoteVo;
 import me.zhengjie.application.bank.service.NotaryNoteService;
 import me.zhengjie.application.bank.service.OrderService;
-import me.zhengjie.base.util.DateUtils;
-import me.zhengjie.base.util.FileUploadUtil;
-import me.zhengjie.base.util.StatusEnum;
-import me.zhengjie.application.bank.controller.vo.NotaryNoteVo;
+import me.zhengjie.base.AppBaseResponse;
+import me.zhengjie.base.util.*;
 import me.zhengjie.dao.mybatis.ModelRepository;
+import me.zhengjie.dao.mybatis.entity.*;
+import me.zhengjie.dao.mybatis.mapper.*;
 import me.zhengjie.domain.order.OrderBizCodeMessage;
-import me.zhengjie.modules.security.service.dto.JwtUserDto;
-import me.zhengjie.application.admin.service.dto.UserDto;
-import me.zhengjie.base.util.TextTempletUtil;
-import me.zhengjie.utils.SecurityUtils;
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -58,6 +53,8 @@ public class NotaryNoteServiceImpl extends ServiceImpl<INotaryNoteDao, NotaryNot
 	ModelRepository modelRepository;
 	@Autowired
 	OrderFileMapper orderFileMapper;
+	@Autowired
+	ApplicationContextUtil contextUtil;
 
 	@Override
 	public JSONObject getNotaryNoteByType(NotaryNoteVo notary) {
@@ -69,7 +66,7 @@ public class NotaryNoteServiceImpl extends ServiceImpl<INotaryNoteDao, NotaryNot
 		noteValue.put("$Know$","知道");
 		noteValue.put("$AdditionalContent$","没有了");
 		// 设置用户参数
-		UserDto user = ((JwtUserDto) SecurityUtils.getCurrentUser()).getUser();
+		UserDto user = contextUtil.getCurrentUser().getUser();
 		noteValue.put("$Greffier$", user.getNickName());
 		// 设置公证处参数
 		NotaryOfficeEntity entity = notaryOfficeMapper.selectById(user.getOrgId().split("_")[1]);
@@ -183,7 +180,7 @@ public class NotaryNoteServiceImpl extends ServiceImpl<INotaryNoteDao, NotaryNot
 		} else {
 			code = "8";
 		}
-		UserDto userDto = ((JwtUserDto) SecurityUtils.getCurrentUser()).getUser();
+		UserDto userDto = contextUtil.getCurrentUser().getUser();
 		String notaryOfficeId = userDto.getOrgId().split("_")[1];
 		String[] codes = {code};
 		if (modelRepository.existModelInEditing(notaryOfficeId, codes)) {
@@ -224,7 +221,7 @@ public class NotaryNoteServiceImpl extends ServiceImpl<INotaryNoteDao, NotaryNot
 	 * @param businessNo
 	 */
 	private void saveNotaryUserId(String businessNo){
-		Integer currentUserId = SecurityUtils.getCurrentUserId().intValue();
+		String currentUserId = String.valueOf(contextUtil.getCurrentUserId());
 		QueryWrapper<BorrowerEntity> borrowerQw = new QueryWrapper<>();
 		borrowerQw.eq("business_no",businessNo);
 		BorrowerEntity borrowerEntity = borrowerMapper.selectOne(borrowerQw);

+ 18 - 16
eladmin-system/src/main/java/me/zhengjie/application/user/app/mq/WebSocketReceiver.java

@@ -4,15 +4,16 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.base.websocket.AppSocketServer;
-import me.zhengjie.dao.mybatis.entity.SysUserEntity;
-import me.zhengjie.application.bank.service.SysUserService;
-import me.zhengjie.modules.security.service.OnlineUserService;
-import me.zhengjie.modules.security.service.dto.OnlineUserDto;
-import me.zhengjie.dao.mybatis.entity.NotaryOrderEntity;
 import me.zhengjie.application.admin.service.NotaryOrderService;
+import me.zhengjie.application.admin.service.dto.JwtUserDto;
 import me.zhengjie.application.admin.service.dto.RoleSmallDto;
+import me.zhengjie.application.admin.service.dto.UserDto;
+import me.zhengjie.application.bank.service.SysUserService;
 import me.zhengjie.base.util.WebSocketMap;
+import me.zhengjie.base.websocket.AppSocketServer;
+import me.zhengjie.dao.mybatis.entity.NotaryOrderEntity;
+import me.zhengjie.dao.mybatis.entity.SysUserEntity;
+import me.zhengjie.security.service.OnlineUserService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.connection.MessageListener;
@@ -46,7 +47,7 @@ public class WebSocketReceiver implements MessageListener {
 		String orderId = jsonObj.getString("orderId");
 		String roomId = jsonObj.getString("roomId");
 		String businessNo = jsonObj.getString("businessNo");
-		List<OnlineUserDto> users = onlineUserService.getAll("");
+		List<Object> users = onlineUserService.getAllLoginUser();
 		// share_userId
 		QueryWrapper<NotaryOrderEntity> queryWrapper = new QueryWrapper<>();
 		queryWrapper.eq("business_no", businessNo);
@@ -58,15 +59,16 @@ public class WebSocketReceiver implements MessageListener {
 		String notaryId = "notary_" + notaryOrder.getNotaryOfficeId();
 		log.info("判断登录的公证处和查询的公证处比较:" + notaryId);
 		WebSocketMap.set(socketId, list);
-		for (OnlineUserDto user : users) {
-			String orgId = user.getOrgId();
-			if (StringUtils.isNotBlank(orgId) && orgId.equalsIgnoreCase(notaryId) && isNotrayUser(user)) {
+		for (Object user : users) {
+			JwtUserDto userDto = (JwtUserDto) user;
+			String orgId = userDto.getUser().getOrgId();
+			if (StringUtils.isNotBlank(orgId) && orgId.equalsIgnoreCase(notaryId) && isNotrayUser(userDto.getUser())) {
 				CopyOnWriteArraySet<AppSocketServer> socketServers = AppSocketServer.getWebSocketSet();
 				log.info("得到所有的websocket对象:" + socketServers);
 				for (AppSocketServer webSocket : socketServers) {
-					if (webSocket.getSname().equalsIgnoreCase(user.getUserName())) {
+					if (webSocket.getSname().equalsIgnoreCase(userDto.getUsername())) {
 						JSONObject obj = new JSONObject();
-						obj.put("accountId", user.getUserName());
+						obj.put("accountId", userDto.getUsername());
 						obj.put("orderId", orderId);
 						obj.put("roomId", roomId);
 						obj.put("businessNo", businessNo);
@@ -83,7 +85,7 @@ public class WebSocketReceiver implements MessageListener {
 						obj.put("borrowerName", notaryOrder.getLoanName());
 						obj.put("bankName", notaryOrder.getBankName());
 						log.info("socket数据的推送给页面:" + notaryId);
-						AppSocketServer.sendInfo(webSocket, obj.toString(), user.getUserName());
+						AppSocketServer.sendInfo(webSocket, obj.toString(), userDto.getUsername());
 					}
 				}
 			}
@@ -96,10 +98,10 @@ public class WebSocketReceiver implements MessageListener {
 	 * @param user 在线用户对象
 	 * @return 返回是否公证员boolean值
 	 */
-	private boolean isNotrayUser(OnlineUserDto user) {
+	private boolean isNotrayUser(UserDto user) {
 		Set<RoleSmallDto> roles = user.getRoles();
-		for (RoleSmallDto role : roles) {
-			if ("公证员".equals(role.getName())) {
+		for(RoleSmallDto role:roles){
+			if("公证员".equals(role.getName())){
 				return true;
 			}
 		}

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/application/user/service/impl/ApiServiceImpl.java

@@ -7,6 +7,7 @@ import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 
+import me.zhengjie.security.security.TokenProvider;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -46,7 +47,6 @@ import me.zhengjie.dao.mybatis.OrderFileRepository;
 import me.zhengjie.dao.mybatis.entity.OrderFileEntity;
 import me.zhengjie.dao.mybatis.entity.OrderRoomIdEntity;
 import me.zhengjie.dao.mybatis.mapper.NotaryOrderMapper;
-import me.zhengjie.modules.security.security.TokenProvider;
 
 @Slf4j
 @Service

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/base/BaseController.java

@@ -4,7 +4,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import com.alibaba.fastjson.JSON;
 import me.zhengjie.dao.mybatis.entity.SysUserEntity;
-import me.zhengjie.modules.security.security.TokenProvider;
+import me.zhengjie.security.security.TokenProvider;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.request.RequestContextHolder;

+ 1 - 2
eladmin-system/src/main/java/me/zhengjie/base/mq/MessagePushConfig.java

@@ -4,8 +4,7 @@ import com.corundumstudio.socketio.Configuration;
 import com.corundumstudio.socketio.SocketConfig;
 import com.corundumstudio.socketio.SocketIOServer;
 import me.zhengjie.base.config.AppConfigInfo;
-import me.zhengjie.modules.mnt.websocket.WebSocketEventListenner;
-
+import me.zhengjie.websocket.WebSocketEventListenner;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;

+ 67 - 0
eladmin-system/src/main/java/me/zhengjie/base/util/ApplicationContextUtil.java

@@ -0,0 +1,67 @@
+package me.zhengjie.base.util;
+
+import com.alibaba.fastjson.JSON;
+import lombok.RequiredArgsConstructor;
+import me.zhengjie.application.admin.service.dto.JwtUserDto;
+import me.zhengjie.security.service.dto.OnlineUserDto;
+import me.zhengjie.utils.RedisUtils;
+import me.zhengjie.utils.SecurityUtils;
+import me.zhengjie.utils.enums.DataScopeEnum;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@RequiredArgsConstructor
+public class ApplicationContextUtil {
+    private final RedisUtils redisUtils;
+
+    /**
+     * 获取当前登录的用户
+     * @return UserDetails
+     */
+    public JwtUserDto getCurrentUser() {
+        OnlineUserDto onlineUser = (OnlineUserDto) SecurityUtils.getCurrentUser();
+        return JSON.parseObject((String) redisUtils.get(onlineUser.getOnlineToken()), JwtUserDto.class);
+    }
+
+    /**
+     * 获取系统用户名称
+     *
+     * @return 系统用户名称
+     */
+    public String getCurrentUsername() {
+        JwtUserDto jwtUserDto = getCurrentUser();
+        return jwtUserDto.getUsername();
+    }
+
+    /**
+     * 获取系统用户ID
+     * @return 系统用户ID
+     */
+    public Long getCurrentUserId() {
+        JwtUserDto jwtUserDto = getCurrentUser();
+        return jwtUserDto.getUserId();
+    }
+
+    /**
+     * 获取当前用户的数据权限
+     * @return /
+     */
+    public List<Long> getCurrentUserDataScope(){
+        JwtUserDto jwtUserDto = getCurrentUser();
+        return jwtUserDto.getDataScopes();
+    }
+
+    /**
+     * 获取数据权限级别
+     * @return 级别
+     */
+    public String getDataScopeType() {
+        List<Long> dataScopes = getCurrentUserDataScope();
+        if(dataScopes.size() != 0){
+            return "";
+        }
+        return DataScopeEnum.ALL.getValue();
+    }
+}

+ 1 - 10
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/BorrowerEntity.java

@@ -183,14 +183,5 @@ public class BorrowerEntity implements Serializable {
     private String orderBy;
 
     @TableField("notary_user_id")
-    private Integer notaryUserId;
-
-//    /**
-//     * 是否删除  1 删除
-//     */
-//    @TableField("del_flag")
-//    @TableLogic
-//    private Integer delFlag;
-
-
+    private String notaryUserId;
 }

+ 1 - 10
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/GuaranteeEntity.java

@@ -174,14 +174,5 @@ public class GuaranteeEntity implements Serializable {
     private String orderBy;
 
     @TableField("notary_user_id")
-    private Integer notaryUserId;
-
-//    /**
-//     * 是否删除  1 删除
-//     */
-//    @TableField("del_flag")
-//    @TableLogic
-//    private Integer delFlag;
-
-
+    private String notaryUserId;
 }

+ 1 - 10
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/MortgageEntity.java

@@ -182,14 +182,5 @@ public class MortgageEntity implements Serializable {
     private String orderBy;
 
     @TableField("notary_user_id")
-    private Integer notaryUserId;
-
-//    /**
-//     * 是否删除  1 删除
-//     */
-//    @TableField("del_flag")
-//    @TableLogic
-//    private Integer delFlag;
-
-
+    private String notaryUserId;
 }

+ 7 - 4
eladmin-system/src/main/java/me/zhengjie/domain/user/impl/UserDomainImpl.java

@@ -3,10 +3,11 @@ package me.zhengjie.domain.user.impl;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
-import me.zhengjie.domain.user.UserDomain;
-import me.zhengjie.modules.security.service.dto.JwtUserDto;
+import me.zhengjie.application.admin.service.dto.JwtUserDto;
 import me.zhengjie.application.admin.service.dto.RoleSmallDto;
-import me.zhengjie.utils.SecurityUtils;
+import me.zhengjie.base.util.ApplicationContextUtil;
+import me.zhengjie.domain.user.UserDomain;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.HashSet;
@@ -16,13 +17,15 @@ import java.util.Set;
 @NoArgsConstructor
 @Component
 public class UserDomainImpl implements UserDomain {
+    @Autowired
+    private ApplicationContextUtil contextUtil;
     /**
      * 获取用户最大权限
      * @return
      */
     @Override
     public String getUserMaxRole(){
-        JwtUserDto userDto = (JwtUserDto) SecurityUtils.getCurrentUser();
+        JwtUserDto userDto = contextUtil.getCurrentUser();
         Set<RoleSmallDto> roles = userDto.getUser().getRoles();
         Set<String> roleNameSet = new HashSet<>();
         for (RoleSmallDto role : roles) {

+ 0 - 134
eladmin-system/src/main/java/me/zhengjie/modules/security/config/SpringSecurityConfig2.java

@@ -1,134 +0,0 @@
-/*
- *  Copyright 2019-2020 Zheng Jie
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package me.zhengjie.modules.security.config;
-
-import lombok.RequiredArgsConstructor;
-import me.zhengjie.annotation.AnonymousAccess;
-import me.zhengjie.modules.security.config.bean.SecurityProperties;
-import me.zhengjie.modules.security.security.*;
-import me.zhengjie.modules.security.service.OnlineUserService;
-import me.zhengjie.modules.security.service.UserCacheClean;
-import me.zhengjie.utils.enums.RequestMethodEnum;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpMethod;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.config.core.GrantedAuthorityDefaults;
-import org.springframework.security.config.http.SessionCreationPolicy;
-import org.springframework.security.core.userdetails.User;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.filter.CorsFilter;
-import org.springframework.web.method.HandlerMethod;
-import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
-import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-import java.util.*;
-
-/**
- * @author Zheng Jie
- */
-//@Configuration
-//@EnableWebSecurity
-@RequiredArgsConstructor
-//@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
-public class SpringSecurityConfig2 extends WebSecurityConfigurerAdapter {
-
-	private final TokenProvider tokenProvider;
-	private final CorsFilter corsFilter;
-//    private final JwtAuthenticationEntryPoint authenticationErrorHandler;
-//    private final JwtAccessDeniedHandler jwtAccessDeniedHandler;
-	private final ApplicationContext applicationContext;
-	private final SecurityProperties properties;
-	private final OnlineUserService onlineUserService;
-	private final UserCacheClean userCacheClean;
-
-	@Bean
-	GrantedAuthorityDefaults grantedAuthorityDefaults() {
-		// 去除 ROLE_ 前缀
-		return new GrantedAuthorityDefaults("");
-	}
-
-	@Bean
-	public PasswordEncoder passwordEncoder() {
-		// 密码加密方式
-		return new BCryptPasswordEncoder();
-	}
-
-	@Override
-	protected void configure(HttpSecurity httpSecurity) throws Exception {
-		httpSecurity.authorizeRequests().anyRequest().authenticated().and().formLogin().loginPage("").permitAll().and()
-				.csrf().disable();
-	//	User.withUsername("")
-	}
-
-	private TokenConfigurer securityConfigurerAdapter() {
-		return new TokenConfigurer(tokenProvider, properties, onlineUserService, userCacheClean);
-	}
-
-	private Map<String, Set<String>> getAnonymousUrl(Map<RequestMappingInfo, HandlerMethod> handlerMethodMap) {
-		Map<String, Set<String>> anonymousUrls = new HashMap<>(8);
-		Set<String> get = new HashSet<>();
-		Set<String> post = new HashSet<>();
-		Set<String> put = new HashSet<>();
-		Set<String> patch = new HashSet<>();
-		Set<String> delete = new HashSet<>();
-		Set<String> all = new HashSet<>();
-		for (Map.Entry<RequestMappingInfo, HandlerMethod> infoEntry : handlerMethodMap.entrySet()) {
-			HandlerMethod handlerMethod = infoEntry.getValue();
-			AnonymousAccess anonymousAccess = handlerMethod.getMethodAnnotation(AnonymousAccess.class);
-			if (null != anonymousAccess) {
-				List<RequestMethod> requestMethods = new ArrayList<>(
-						infoEntry.getKey().getMethodsCondition().getMethods());
-				RequestMethodEnum request = RequestMethodEnum.find(
-						requestMethods.size() == 0 ? RequestMethodEnum.ALL.getType() : requestMethods.get(0).name());
-				switch (Objects.requireNonNull(request)) {
-				case GET:
-					get.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
-					break;
-				case POST:
-					post.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
-					break;
-				case PUT:
-					put.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
-					break;
-				case PATCH:
-					patch.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
-					break;
-				case DELETE:
-					delete.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
-					break;
-				default:
-					all.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
-					break;
-				}
-			}
-		}
-		anonymousUrls.put(RequestMethodEnum.GET.getType(), get);
-		anonymousUrls.put(RequestMethodEnum.POST.getType(), post);
-		anonymousUrls.put(RequestMethodEnum.PUT.getType(), put);
-		anonymousUrls.put(RequestMethodEnum.PATCH.getType(), patch);
-		anonymousUrls.put(RequestMethodEnum.DELETE.getType(), delete);
-		anonymousUrls.put(RequestMethodEnum.ALL.getType(), all);
-		return anonymousUrls;
-	}
-
-}

+ 0 - 53
eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserCacheClean.java

@@ -1,53 +0,0 @@
-/*
- * Copyright 2019-2020 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package me.zhengjie.modules.security.service;
-
-import lombok.AllArgsConstructor;
-import me.zhengjie.utils.StringUtils;
-import org.springframework.stereotype.Component;
-
-/**
- * @author: liaojinlong
- * @date: 2020/6/11 18:01
- * @apiNote: 用于清理 用户登录信息缓存,为防止Spring循环依赖与安全考虑 ,单独构成工具类
- */
-@Component
-@AllArgsConstructor
-public class UserCacheClean {
-
-    private final UserCacheManager userCacheManager;
-
-    /**
-     * 清理特定用户缓存信息<br>
-     * 用户信息变更时
-     *
-     * @param userName /
-     */
-    public void cleanUserCache(String userName) {
-        if (StringUtils.isNotEmpty(userName)) {
-            userCacheManager.remove(userName);
-        }
-    }
-
-    /**
-     * 清理所有用户的缓存信息<br>
-     * ,如发生角色授权信息变化,可以简便的全部失效缓存
-     */
-    public void cleanAll() {
-        userCacheManager.clear();
-    }
-}

+ 0 - 110
eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserCacheManager.java

@@ -1,110 +0,0 @@
-package me.zhengjie.modules.security.service;
-
-import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.modules.security.service.dto.JwtUserDto;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * 用户缓存
- *
- * @author TikiWong
- * @date 2022/1/27 8:23
- **/
-@Slf4j
-@Component
-public class UserCacheManager {
-
-    @Value("${user-cache.min-evictable-size}")
-    private int minEvictableSize;
-    @Value("${user-cache.min-evictable-interval}")
-    private long minEvictableInterval;
-    @Value("${user-cache.min-idle-time}")
-    private long minIdleTime;
-
-    private final Map<String, Node> cache = new ConcurrentHashMap<>();
-    private final AtomicBoolean expelLock = new AtomicBoolean(true);
-    private long nextMinEvictableTime = 0;
-
-    public Future<JwtUserDto> putIfAbsent(String username, Future<JwtUserDto> ft) {
-        Node tryNode = new Node(ft);
-        Node node = cache.putIfAbsent(username, tryNode);
-        expel();
-        return nodeToDate(node);
-    }
-
-    /**
-     * 缓存回收
-     * 为避免超过边界后回收热点数据设置了最小生存时间
-     * 回收时会保留在最小生存时间内的数据
-     **/
-    public void expel() {
-        long now = System.currentTimeMillis();
-        if (cache.size() < minEvictableSize ||
-                now < nextMinEvictableTime ||
-                !expelLock.compareAndSet(true, false)) {
-            return;
-        }
-        long oldestTime = now;
-        int evictedCount = 0;
-        try {
-            Iterator<Map.Entry<String, Node>> iterator = cache.entrySet().iterator();
-            while (iterator.hasNext()) {
-                Map.Entry<String, Node> entry = iterator.next();
-                long nodeTime = entry.getValue().getTime();
-                if (nodeTime + minIdleTime < now) {
-                    iterator.remove();
-                    evictedCount++;
-                }
-                oldestTime = Math.min(oldestTime, nodeTime);
-            }
-        } finally {
-            this.nextMinEvictableTime = Math.max(now + minEvictableInterval, oldestTime);
-            expelLock.set(true);
-            log.info("回收掉【{}】条用户缓存, 剩余缓存数为【{}】,下次可回收时间为【{}】秒后",
-                    evictedCount,
-                    cache.size(),
-                    (this.nextMinEvictableTime - now) / 1000);
-        }
-    }
-
-    public Future<JwtUserDto> get(String username) {
-        return nodeToDate(cache.get(username));
-    }
-
-    public void clear() {
-        cache.clear();
-    }
-
-    public void remove(String username) {
-        cache.remove(username);
-    }
-
-    private Future<JwtUserDto> nodeToDate(Node node) {
-        return node == null ? null : node.getData();
-    }
-
-    private static class Node {
-        private final Future<JwtUserDto> data;
-        private final long time;
-
-        public Node(Future<JwtUserDto> data) {
-            this.data = data;
-            this.time = System.currentTimeMillis();
-        }
-
-        public Future<JwtUserDto> getData() {
-            return data;
-        }
-
-        public long getTime() {
-            return time;
-        }
-    }
-}

+ 0 - 87
eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java

@@ -1,87 +0,0 @@
-/*
- *  Copyright 2019-2020 Zheng Jie
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package me.zhengjie.modules.security.service.dto;
-
-import com.alibaba.fastjson.annotation.JSONField;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import me.zhengjie.application.admin.service.dto.UserDto;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * @author Zheng Jie
- * @date 2018-11-23
- */
-@Getter
-@AllArgsConstructor
-public class JwtUserDto implements UserDetails {
-
-    /**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-
-	private final UserDto user;
-
-    private final List<Long> dataScopes;
-
-    @JSONField(serialize = false)
-    private final List<GrantedAuthority> authorities;
-
-    public Set<String> getRoles() {
-        return authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
-    }
-
-    @Override
-    @JSONField(serialize = false)
-    public String getPassword() {
-        return user.getPassword();
-    }
-
-    @Override
-    @JSONField(serialize = false)
-    public String getUsername() {
-        return user.getUsername();
-    }
-
-    @JSONField(serialize = false)
-    @Override
-    public boolean isAccountNonExpired() {
-        return true;
-    }
-
-    @JSONField(serialize = false)
-    @Override
-    public boolean isAccountNonLocked() {
-        return true;
-    }
-
-    @JSONField(serialize = false)
-    @Override
-    public boolean isCredentialsNonExpired() {
-        return true;
-    }
-
-    @Override
-    @JSONField(serialize = false)
-    public boolean isEnabled() {
-        return user.getEnabled();
-    }
-}

+ 0 - 90
eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/OnlineUserDto.java

@@ -1,90 +0,0 @@
-/*
- *  Copyright 2019-2020 Zheng Jie
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package me.zhengjie.modules.security.service.dto;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import me.zhengjie.application.admin.service.dto.RoleSmallDto;
-
-import java.util.Date;
-import java.util.Set;
-
-/**
- * 在线用户
- * @author Zheng Jie
- */
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-@Getter
-@Setter
-public class OnlineUserDto {
-    /**
-     * 用户角色
-     */
-    private Set<RoleSmallDto> roles;
-
-    /**
-     * 用户名
-     */
-    private String userName;
-
-    /**
-     * 昵称
-     */
-    private String nickName;
-
-    /**
-     * 岗位
-     */
-    private String dept;
-
-    /**
-     * 浏览器
-     */
-    private String browser;
-
-    /**
-     * IP
-     */
-    private String ip;
-
-    /**
-     * 地址
-     */
-    private String address;
-
-    /**
-     * token
-     */
-    private String key;
-
-    /**
-     * 登录时间
-     */
-    private Date loginTime;
-
-    /**
-     * 公证处
-     */
-    private String orgId;
-    
-    private String onlineToken;
-
-}