三七 1 週間 前
コミット
72f4da7747

+ 1 - 0
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -724,6 +724,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         sopLogs.setExternalUserId(externalId);
         sopLogs.setExternalUserName(externalUserName);
         sopLogs.setFsUserId(fsUserId);
+        sopLogs.setUserLogsId(logVo.getId());
 
         return sopLogs;
     }

+ 4 - 16
fs-qwhook-sop/src/main/java/com/fs/app/controller/testController.java

@@ -8,6 +8,7 @@ import com.fs.course.mapper.FsCourseSopMapper;
 import com.fs.course.mapper.FsCourseWatchLogMapper;
 import com.fs.course.service.IFsCourseLinkService;
 import com.fs.crm.mapper.CrmCustomerMapper;
+import com.fs.sop.service.ISopUserLogsInfoService;
 import com.fs.store.mapper.FsUserMapper;
 import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwUser;
@@ -57,27 +58,14 @@ public class testController {
     testService testService;
     @Autowired
     private RedisCache redisCache;
+    @Autowired
+    private ISopUserLogsInfoService iSopUserLogsInfoService;
 
     @GetMapping("/qwHookNotify")
     public R qwHookNotify() {
 
-//        redisCache.setCacheObject("qwUserRd:"+12313+":"+12313 ,JSON.toJSONString(null),1, TimeUnit.HOURS);
-
-//
-//        List<QwUser> qwUserAllKey = qwUserMapper.getQwUserAllKey();
-//
-//
-//        int i=1;
-//
-//        for (QwUser qwUser : qwUserAllKey) {
-//            System.out.println(qwUser);
-//            i++;
-//            System.out.println("执行到第:"+i);
-//            testService.add(qwUser);
-//
-//        }
-
 
+        iSopUserLogsInfoService.updateSopUserInfoByExternalId(218L,123456L);
         return  R.ok();
     }
 

+ 5 - 0
fs-service-system/src/main/java/com/fs/sop/domain/QwSopLogs.java

@@ -70,6 +70,11 @@ public class QwSopLogs implements Serializable {
     */
     private String sopId;
 
+    /**
+     * 营期主键
+     */
+    private String userLogsId;
+
     /**
      * 备注
      */

+ 0 - 1
fs-service-system/src/main/java/com/fs/sop/mapper/SopUserLogsInfoMapper.java

@@ -189,7 +189,6 @@ public interface SopUserLogsInfoMapper {
     int updateQwExternalContactUnBindUserId(@Param("externalId") Long externalId);
 
     @DataSource(DataSourceType.SOP)
-    @Update("update sop_user_logs_info set fs_user_id=#{fsUserId} where external_id =#{externalId}")
     int updateQwExternalContactChangeUserId(@Param("externalId") Long externalId,@Param("fsUserId") Long fsUserId);
 
 

+ 2 - 0
fs-service-system/src/main/java/com/fs/sop/service/impl/SopUserLogsInfoServiceImpl.java

@@ -2,7 +2,9 @@ package com.fs.sop.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
+import com.fs.common.annotation.DataSource;
 import com.fs.common.core.domain.R;
+import com.fs.common.enums.DataSourceType;
 import com.fs.common.exception.base.BaseException;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.date.DateUtil;

+ 3 - 0
fs-service-system/src/main/resources/mapper/sop/SopUserLogsInfoMapper.xml

@@ -338,6 +338,9 @@
             #{id}
         </foreach>
     </update>
+    <update id="updateQwExternalContactChangeUserId">
+        update sop_user_logs_info set fs_user_id=#{fsUserId} where external_id =#{externalId}
+    </update>
 
     <select id="selectEerGroup"  resultMap="SopUserLogsInfoResult">
         select s.user_logs_id,ANY_VALUE(s.sop_id) sop_id,ANY_VALUE(s.qw_user_id) qw_user_id,ANY_VALUE(s.corp_id) corp_id  from sop_user_logs_info s LEFT JOIN sop_user_logs ss ON s.user_logs_id=ss.id where create_time='2025-02-11' and ss.id is null GROUP BY s.user_logs_id

+ 9 - 4
fs-user-app/src/main/java/com/fs/app/controller/WxPayController.java

@@ -7,6 +7,7 @@ import com.fs.common.core.domain.R;
 import com.fs.course.config.RedPacketConfig;
 import com.fs.course.service.IFsCourseRedPacketLogService;
 import com.fs.his.param.WxSendRedPacketParam;
+import com.fs.sop.service.ISopUserLogsInfoService;
 import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsUser;
 import com.fs.store.enums.*;
@@ -30,10 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -65,6 +63,9 @@ public class WxPayController {
     private IFsCourseRedPacketLogService redPacketLogService;
     @Autowired
     private ISysConfigService configService;
+    @Autowired
+    private ISopUserLogsInfoService iSopUserLogsInfoService;
+
     /**
      * 微信回调
      * 回调接口代码内部自动校验结果签名和业务代码
@@ -121,4 +122,8 @@ public class WxPayController {
         return storePaymentService.v3TransferNotify(notifyData,request);
     }
 
+    @GetMapping("/test")
+    public void test(){
+        iSopUserLogsInfoService.updateSopUserInfoByExternalId(218L,123456L);
+    }
 }

+ 14 - 0
fs-user-app/src/main/java/com/fs/core/aspectj/DataScopeAspect.java

@@ -77,6 +77,7 @@ public class DataScopeAspect
     @Before("dataScopePointCut()")
     public void doBefore(JoinPoint point) throws Throwable
     {
+        clearDataScope(point);
         handleDataScope(point);
     }
 
@@ -185,4 +186,17 @@ public class DataScopeAspect
         }
         return null;
     }
+
+    /**
+     * 拼接权限sql前先清空params.dataScope参数防止注入
+     */
+    private void clearDataScope(final JoinPoint joinPoint)
+    {
+        Object params = joinPoint.getArgs()[0];
+        if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
+        {
+            BaseEntity baseEntity = (BaseEntity) params;
+            baseEntity.getParams().put(DATA_SCOPE, "");
+        }
+    }
 }

+ 117 - 116
fs-user-app/src/main/java/com/fs/core/aspectj/RateLimiterAspect.java

@@ -1,116 +1,117 @@
-//package com.fs.core.aspectj;
-//
-//import com.fs.common.annotation.RateLimiter;
-//import com.fs.common.enums.LimitType;
-//import com.fs.common.exception.ServiceException;
-//import com.fs.common.utils.ServletUtils;
-//import com.fs.common.utils.StringUtils;
-//import com.fs.common.utils.ip.IpUtils;
-//import org.aspectj.lang.JoinPoint;
-//import org.aspectj.lang.Signature;
-//import org.aspectj.lang.annotation.Aspect;
-//import org.aspectj.lang.annotation.Before;
-//import org.aspectj.lang.annotation.Pointcut;
-//import org.aspectj.lang.reflect.MethodSignature;
-//import org.slf4j.Logger;
-//import org.slf4j.LoggerFactory;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.data.redis.core.RedisTemplate;
-//import org.springframework.data.redis.core.script.RedisScript;
-//import org.springframework.stereotype.Component;
-//
-//import java.lang.reflect.Method;
-//import java.util.Collections;
-//import java.util.List;
-//
-///**
-// * 限流处理
-// *
-//
-// */
-//@Aspect
-//@Component
-//public class RateLimiterAspect
-//{
-//    private static final Logger log = LoggerFactory.getLogger(RateLimiterAspect.class);
-//
-//    private RedisTemplate<Object, Object> redisTemplate;
-//
-//    private RedisScript<Long> limitScript;
-//
-//    @Autowired
-//    public void setRedisTemplate1(RedisTemplate<Object, Object> redisTemplate)
-//    {
-//        this.redisTemplate = redisTemplate;
-//    }
-//
-//    @Autowired
-//    public void setLimitScript(RedisScript<Long> limitScript)
-//    {
-//        this.limitScript = limitScript;
-//    }
-//    // 配置织入点
-//    @Pointcut("@annotation(com.fs.common.annotation.RateLimiter)")
-//    public void rateLimiterPointCut()
-//    {
-//    }
-//
-//    @Before("rateLimiterPointCut()")
-//    public void doBefore(JoinPoint point) throws Throwable
-//    {
-//        RateLimiter rateLimiter = getAnnotationRateLimiter(point);
-//        String key = rateLimiter.key();
-//        int time = rateLimiter.time();
-//        int count = rateLimiter.count();
-//
-//        String combineKey = getCombineKey(rateLimiter, point);
-//        List<Object> keys = Collections.singletonList(combineKey);
-//        try
-//        {
-//            Long number = redisTemplate.execute(limitScript, keys, count, time);
-//            if (StringUtils.isNull(number) || number.intValue() > count)
-//            {
-//                throw new ServiceException("访问过于频繁,请稍后再试");
-//            }
-//            log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), key);
-//        }
-//        catch (ServiceException e)
-//        {
-//            throw e;
-//        }
-//        catch (Exception e)
-//        {
-//            throw new RuntimeException("服务器限流异常,请稍后再试");
-//        }
-//    }
-//
-//    /**
-//     * 是否存在注解,如果存在就获取
-//     */
-//    private RateLimiter getAnnotationRateLimiter(JoinPoint joinPoint)
-//    {
-//        Signature signature = joinPoint.getSignature();
-//        MethodSignature methodSignature = (MethodSignature) signature;
-//        Method method = methodSignature.getMethod();
-//
-//        if (method != null)
-//        {
-//            return method.getAnnotation(RateLimiter.class);
-//        }
-//        return null;
-//    }
-//
-//    public String getCombineKey(RateLimiter rateLimiter, JoinPoint point)
-//    {
-//        StringBuffer stringBuffer = new StringBuffer(rateLimiter.key());
-//        if (rateLimiter.limitType() == LimitType.IP)
-//        {
-//            stringBuffer.append(IpUtils.getIpAddr(ServletUtils.getRequest()));
-//        }
-//        MethodSignature signature = (MethodSignature) point.getSignature();
-//        Method method = signature.getMethod();
-//        Class<?> targetClass = method.getDeclaringClass();
-//        stringBuffer.append("-").append(targetClass.getName()).append("- ").append(method.getName());
-//        return stringBuffer.toString();
-//    }
-//}
+package com.fs.framework.aspectj;
+
+import com.fs.common.annotation.RateLimiter;
+import com.fs.common.enums.LimitType;
+import com.fs.common.exception.ServiceException;
+import com.fs.common.utils.ServletUtils;
+import com.fs.common.utils.StringUtils;
+import com.fs.common.utils.ip.IpUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.script.RedisScript;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 限流处理
+ *
+
+ */
+@Aspect
+@Component
+public class RateLimiterAspect
+{
+    private static final Logger log = LoggerFactory.getLogger(RateLimiterAspect.class);
+
+    private RedisTemplate<Object, Object> redisTemplate;
+
+    private RedisScript<Long> limitScript;
+
+    @Autowired
+    public void setRedisTemplate1(RedisTemplate<Object, Object> redisTemplate)
+    {
+        this.redisTemplate = redisTemplate;
+    }
+
+    @Autowired
+    public void setLimitScript(RedisScript<Long> limitScript)
+    {
+        this.limitScript = limitScript;
+    }
+
+    // 配置织入点
+    @Pointcut("@annotation(com.fs.common.annotation.RateLimiter)")
+    public void rateLimiterPointCut()
+    {
+    }
+
+    @Before("rateLimiterPointCut()")
+    public void doBefore(JoinPoint point) throws Throwable
+    {
+        RateLimiter rateLimiter = getAnnotationRateLimiter(point);
+        String key = rateLimiter.key();
+        int time = rateLimiter.time();
+        int count = rateLimiter.count();
+
+        String combineKey = getCombineKey(rateLimiter, point);
+        List<Object> keys = Collections.singletonList(combineKey);
+        try
+        {
+            Long number = redisTemplate.execute(limitScript, keys, count, time);
+            if (StringUtils.isNull(number) || number.intValue() > count)
+            {
+                throw new ServiceException("访问过于频繁,请稍后再试");
+            }
+            log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), key);
+        }
+        catch (ServiceException e)
+        {
+            throw e;
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException("服务器限流异常,请稍后再试");
+        }
+    }
+
+    /**
+     * 是否存在注解,如果存在就获取
+     */
+    private RateLimiter getAnnotationRateLimiter(JoinPoint joinPoint)
+    {
+        Signature signature = joinPoint.getSignature();
+        MethodSignature methodSignature = (MethodSignature) signature;
+        Method method = methodSignature.getMethod();
+
+        if (method != null)
+        {
+            return method.getAnnotation(RateLimiter.class);
+        }
+        return null;
+    }
+
+    public String getCombineKey(RateLimiter rateLimiter, JoinPoint point)
+    {
+        StringBuffer stringBuffer = new StringBuffer(rateLimiter.key());
+        if (rateLimiter.limitType() == LimitType.IP)
+        {
+            stringBuffer.append(IpUtils.getIpAddr(ServletUtils.getRequest()));
+        }
+        MethodSignature signature = (MethodSignature) point.getSignature();
+        Method method = signature.getMethod();
+        Class<?> targetClass = method.getDeclaringClass();
+        stringBuffer.append("-").append(targetClass.getName()).append("- ").append(method.getName());
+        return stringBuffer.toString();
+    }
+}

+ 29 - 0
fs-user-app/src/main/java/com/fs/core/config/RedisConfig.java

@@ -9,6 +9,7 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.connection.RedisConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.script.DefaultRedisScript;
 import org.springframework.data.redis.serializer.GenericToStringSerializer;
 import org.springframework.data.redis.serializer.StringRedisSerializer;
 
@@ -82,4 +83,32 @@ public class RedisConfig extends CachingConfigurerSupport
         template.afterPropertiesSet();
         return template;
     }
+
+    @Bean
+    public DefaultRedisScript<Long> limitScript()
+    {
+        DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
+        redisScript.setScriptText(limitScriptText());
+        redisScript.setResultType(Long.class);
+        return redisScript;
+    }
+
+    /**
+     * 限流脚本
+     */
+    private String limitScriptText()
+    {
+        return "local key = KEYS[1]\n" +
+                "local count = tonumber(ARGV[1])\n" +
+                "local time = tonumber(ARGV[2])\n" +
+                "local current = redis.call('get', key);\n" +
+                "if current and tonumber(current) > count then\n" +
+                "    return current;\n" +
+                "end\n" +
+                "current = redis.call('incr', key)\n" +
+                "if tonumber(current) == 1 then\n" +
+                "    redis.call('expire', key, time)\n" +
+                "end\n" +
+                "return current;";
+    }
 }

+ 3 - 3
fs-user-app/src/main/java/com/fs/core/datasource/DynamicDataSourceContextHolder.java

@@ -23,7 +23,7 @@ public class DynamicDataSourceContextHolder
      */
     public static void setDataSourceType(String dsType)
     {
-//        log.info("切换到{}数据源", dsType);
+        log.info("切换到{}", dsType);
         CONTEXT_HOLDER.set(dsType);
     }
 
@@ -38,8 +38,8 @@ public class DynamicDataSourceContextHolder
     /**
      * 清空数据源变量
      */
-    public static void clearDataSourceType()
-    {
+    public static void clearDataSourceType(){
+        log.info("销毁切换");
         CONTEXT_HOLDER.remove();
     }
 }