Parcourir la source

fix: yzt bug修复

xdd il y a 1 mois
Parent
commit
e4834a5d71

+ 4 - 3
fs-common/src/main/java/com/fs/common/utils/SecurityUtils.java

@@ -9,7 +9,7 @@ import com.fs.common.exception.ServiceException;
 
 /**
  * 安全服务工具类
- * 
+ *
 
  */
 public class SecurityUtils
@@ -43,7 +43,7 @@ public class SecurityUtils
             throw new ServiceException("获取部门ID异常", HttpStatus.UNAUTHORIZED);
         }
     }
-    
+
     /**
      * 获取用户账户
      **/
@@ -70,6 +70,7 @@ public class SecurityUtils
         }
         catch (Exception e)
         {
+            e.printStackTrace();
             throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
         }
     }
@@ -109,7 +110,7 @@ public class SecurityUtils
 
     /**
      * 是否为管理员
-     * 
+     *
      * @param userId 用户ID
      * @return 结果
      */

+ 18 - 0
fs-framework/src/main/java/com/fs/framework/config/ThreadPoolConfig.java

@@ -6,8 +6,11 @@ import java.util.concurrent.ThreadPoolExecutor;
 import org.apache.commons.lang3.concurrent.BasicThreadFactory;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.task.TaskDecorator;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import com.fs.common.utils.Threads;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
 
 /**
  * 线程池配置
@@ -37,6 +40,7 @@ public class ThreadPoolConfig
         executor.setCorePoolSize(corePoolSize);
         executor.setQueueCapacity(queueCapacity);
         executor.setKeepAliveSeconds(keepAliveSeconds);
+        executor.setTaskDecorator(new ContextCopyingDecorator());
         // 线程池对拒绝任务(无线程可用)的处理策略
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
         return executor;
@@ -59,4 +63,18 @@ public class ThreadPoolConfig
             }
         };
     }
+    private static class ContextCopyingDecorator implements TaskDecorator {
+        @Override
+        public Runnable decorate(Runnable runnable) {
+            SecurityContext context = SecurityContextHolder.getContext();
+            return () -> {
+                try {
+                    SecurityContextHolder.setContext(context);
+                    runnable.run();
+                } finally {
+                    SecurityContextHolder.clearContext();
+                }
+            };
+        }
+    }
 }

+ 2 - 0
fs-qw-api-msg/src/main/resources/application.yml

@@ -7,3 +7,5 @@ spring:
 #    active: druid-jzzx
 #    active: druid-hdt
 #    active: druid-sxjz
+
+

+ 1 - 1
fs-service/src/main/java/com/fs/his/mapper/FsArticleMapper.java

@@ -67,7 +67,7 @@ public interface FsArticleMapper
     public int deleteFsArticleByArticleIds(Long[] articleIds);
     @Select({"<script> " +
             "select a.*  from fs_article a    " +
-            "LEFT JOIN fs_article_cate ac ON ac.cate_id = a.cate_id" +
+            "LEFT JOIN fs_article_cate ac ON ac.cate_id = a.cate_id " +
             "where ac.status != 0  " +
             "<if test = 'maps.keyword != null     '> " +
             "and a.title like CONCAT(#{maps.keyword},'%')" +

+ 28 - 28
fs-service/src/main/java/com/fs/his/service/impl/FsExportTaskServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.his.service.impl;
 
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
@@ -16,10 +17,12 @@ import com.fs.his.mapper.FsStorePaymentMapper;
 import com.fs.his.param.FsStoreOrderParam;
 import com.fs.his.param.FsStorePaymentParam;
 import com.fs.his.service.IFsStoreOrderService;
+import com.fs.his.utils.PhoneUtil;
 import com.fs.his.vo.FsStoreOrderExcelVO;
 import com.fs.his.vo.FsStoreOrderExportVO;
 import com.fs.his.vo.FsStorePaymentExcelVO;
 import com.fs.system.service.ISysMenuService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -34,6 +37,7 @@ import com.fs.his.service.IFsExportTaskService;
  * @date 2024-11-19
  */
 @Service
+@Slf4j
 public class FsExportTaskServiceImpl implements IFsExportTaskService
 {
     @Autowired
@@ -126,46 +130,42 @@ public class FsExportTaskServiceImpl implements IFsExportTaskService
         return fsExportTaskMapper.isExportType1(userId);
     }
 
-    @Async
+    @Async(value = "threadPoolTaskExecutor")
     @Override
     public void exportStore1Data(FsStoreOrderParam fsStoreOrder) {
         List<FsStoreOrderExportVO> list = fsStoreOrderMapper.selectFsStoreOrderListVOByExport(fsStoreOrder);
         //对手机号脱敏
         if (list != null) {
-
-
+            LoginUser loginUser = SecurityUtils.getLoginUser();
+            boolean isAdmin = loginUser.getUser().isAdmin();
+            // 获取用户权限
+            boolean hasPhonePermission = isAdmin;
+            boolean hasAddressPermission = isAdmin;
+
+            if (!isAdmin) {
+                Set<String> perms = menuService.selectMenuPermsByUserId(loginUser.getUserId());
+                log.info("当前用户登录权限: {}", perms);
+                hasPhonePermission = perms.contains("his:storeOrder:queryPhone");
+                hasAddressPermission = perms.contains("his:storeOrder:queryAddress");
+            }
             for (FsStoreOrderExportVO vo : list) {
                 vo.setFollowFrequency(6);
                 if (vo.getCycle()!=null){
                     vo.setFollowCount(vo.getCycle()/ vo.getFollowFrequency());
                 }
-                boolean isPhoneEncodeFlag = true;
-                boolean isAddressEncodeFlag = true;
-                LoginUser loginUser = SecurityUtils.getLoginUser();
-                List<SysRole> admin = loginUser.getUser().getRoles().stream().filter(item -> item.getRoleKey().equals("admin")).collect(Collectors.toList());
-                if (!admin.isEmpty()) {
-                    //超级管理员
-                    isAddressEncodeFlag = false;
-                    isPhoneEncodeFlag = false;
-                } else {
-                    //非超级管理员
-                    Set<String> perms = menuService.selectMenuPermsByUserId(loginUser.getUserId());
-                    boolean phoneContains = perms.contains("his:storeOrder:queryPhone");
-                    boolean addressContains = perms.contains("his:storeOrder:queryAddress");
-                    if (addressContains) {
-                        isAddressEncodeFlag = false;
-                    }
-                    if (phoneContains) {
-                        isPhoneEncodeFlag = false;
-                    }
-                }
-                if (isPhoneEncodeFlag) {
-                    if (vo.getUserPhone() != null) {
-                        vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
+
+                // 处理手机号
+                if (vo.getUserPhone() != null) {
+                    String decryptedPhone = PhoneUtil.decryptPhone(vo.getUserPhone());
+                    if (hasPhonePermission) {
+                        vo.setUserPhone(decryptedPhone);
+                    } else {
+                        vo.setUserPhone(decryptedPhone.replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                     }
                 }
-                if (isAddressEncodeFlag) {
-                    if (vo.getUserAddress() != null) {
+                // 处理地址
+                if (vo.getUserAddress() != null) {
+                    if (!hasAddressPermission) {
                         vo.setUserAddress(ParseUtils.parseAddress(vo.getUserAddress()));
                     }
                 }

+ 2 - 0
fs-service/src/main/resources/application-config-druid-yzt.yml

@@ -99,3 +99,5 @@ erp:
 openIM:
   secret: openIM123
   userID: imAdmin
+  url: ''
+  prefix: ''