Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

yfh 3 dni temu
rodzic
commit
b120612bab

+ 1 - 2
fs-admin/src/main/java/com/fs/course/controller/FsUserCourseController.java

@@ -182,8 +182,7 @@ public class FsUserCourseController extends BaseController
     @PreAuthorize("@ss.hasPermi('course:userCourse:remove')")
     @Log(title = "课程", businessType = BusinessType.DELETE)
 	@DeleteMapping("/{courseIds}")
-    public AjaxResult remove(@PathVariable Long[] courseIds)
-    {
+    public AjaxResult remove(@PathVariable Long[] courseIds){
         fsUserCourseService.deleteFsUserCourseByCourseIds(courseIds);
         redisCacheUtil.delRedisKey("getCourseList");
         return toAjax(1);

+ 1 - 0
fs-admin/src/main/java/com/fs/course/controller/FsUserVideoController.java

@@ -207,6 +207,7 @@ public class FsUserVideoController extends BaseController
         try {
             extractFirstFrame(videoFile.getAbsolutePath(), frameFile.getAbsolutePath());
         } catch (Exception e) {
+            e.printStackTrace();
             // 记录错误日志
             return R.error("提取第一帧失败");
         }

+ 1 - 1
fs-admin/src/main/resources/logback.xml

@@ -3,7 +3,7 @@
     <!-- 日志存放路径 -->
 	<property name="log.path" value="/home/fs-admin/logs" />
     <!-- 日志输出格式 -->
-	<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
+    <property name="log.pattern" value="%replace([%X{traceId}] ){'\\[\\s*\\] ', ''}%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
 
 	<!-- 控制台输出 -->
 	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">

+ 40 - 0
fs-framework/src/main/java/com/fs/framework/config/LogInterceptor.java

@@ -0,0 +1,40 @@
+package com.fs.framework.config;
+
+
+
+import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.UUID;
+
+
+/**
+ * @description: 日志拦截器
+ * @author: xdd
+ * @date: 2025/3/13
+ */
+@Component
+public class LogInterceptor implements HandlerInterceptor {
+
+    private static final String traceId = "traceId";
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
+        String tid = UUID.randomUUID().toString().replace("-", "");
+        if (!StringUtils.isEmpty(request.getHeader("traceId"))) {
+            tid = request.getHeader("traceId");
+        }
+        MDC.put(traceId, tid);
+        return true;
+    }
+
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
+                                Exception ex) {
+        MDC.remove(traceId);
+    }
+}

+ 8 - 3
fs-framework/src/main/java/com/fs/framework/config/ResourcesConfig.java

@@ -19,8 +19,7 @@ import java.time.format.DateTimeFormatter;
 
 /**
  * 通用配置
- * 
-
+ *
  */
 @Configuration
 public class ResourcesConfig implements WebMvcConfigurer
@@ -28,6 +27,9 @@ public class ResourcesConfig implements WebMvcConfigurer
     @Autowired
     private RepeatSubmitInterceptor repeatSubmitInterceptor;
 
+    @Autowired
+    private LogInterceptor logInterceptor;
+
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry)
     {
@@ -45,6 +47,9 @@ public class ResourcesConfig implements WebMvcConfigurer
     public void addInterceptors(InterceptorRegistry registry)
     {
         registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
+
+        registry.addInterceptor(logInterceptor)
+                .addPathPatterns("/**");
     }
 
     /**
@@ -73,4 +78,4 @@ public class ResourcesConfig implements WebMvcConfigurer
         registrar.setDateFormatter(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // 统一日期格式
         registrar.registerFormatters(registry);
     }
-}
+}

+ 35 - 0
fs-framework/src/main/java/com/fs/framework/config/ThreadPoolTaskWrapExecutor.java

@@ -0,0 +1,35 @@
+package com.fs.framework.config;
+
+import com.fs.framework.util.ThreadMdcUtil;
+import org.slf4j.MDC;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+
+/**
+ * @description:
+ * @author: xdd
+ * @date: 2025/3/13
+ */
+public final class ThreadPoolTaskWrapExecutor extends ThreadPoolTaskExecutor {
+    public ThreadPoolTaskWrapExecutor() {
+        super();
+    }
+
+    @Override
+    public void execute(Runnable task) {
+        super.execute(ThreadMdcUtil.wrap(task, MDC.getCopyOfContextMap()));
+    }
+
+
+    @Override
+    public <T> Future<T> submit(Callable<T> task) {
+        return super.submit(ThreadMdcUtil.wrap(task, MDC.getCopyOfContextMap()));
+    }
+
+    @Override
+    public Future<?> submit(Runnable task) {
+        return super.submit(ThreadMdcUtil.wrap(task, MDC.getCopyOfContextMap()));
+    }
+}

+ 60 - 0
fs-framework/src/main/java/com/fs/framework/util/ThreadMdcUtil.java

@@ -0,0 +1,60 @@
+package com.fs.framework.util;
+
+
+import org.slf4j.MDC;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+/**
+ * @description:
+ * @author: xdd
+ * @date: 2025/3/13
+ * @Description:
+ */
+public final class ThreadMdcUtil {
+    private static final String traceId = "traceId";
+
+    public static String generateTraceId() {
+        return UUID.randomUUID().toString().replace("-", "");
+    }
+
+    public static void setTraceIdIfAbsent() {
+        if (MDC.get(traceId) == null) {
+            MDC.put(traceId, generateTraceId());
+        }
+    }
+
+    public static<T> Callable<T> wrap(final Callable<T> callable, final Map<String, String> context) {
+        return () -> {
+            if (context == null) {
+                MDC.clear();
+            } else {
+                MDC.setContextMap(context);
+            }
+            setTraceIdIfAbsent();
+            try {
+                return callable.call();
+            } finally {
+                MDC.clear();
+            }
+        };
+    }
+
+
+    public static Runnable wrap(final Runnable runnable, final Map<String, String> context) {
+        return () -> {
+            if (context == null) {
+                MDC.clear();
+            } else {
+                MDC.setContextMap(context);
+            }
+            setTraceIdIfAbsent();
+            try {
+                runnable.run();
+            } finally {
+                MDC.clear();
+            }
+        };
+    }
+}

+ 1 - 1
fs-service/src/main/java/com/fs/course/mapper/FsCourseRedPacketLogMapper.java

@@ -133,7 +133,7 @@ public interface FsCourseRedPacketLogMapper
 
     List<FsCourseRedPacketLogListPVO> selectFsCourseRedPacketLogListVONew(FsCourseRedPacketLogParam fsCourseRedPacketLog);
 
-    @Select("select * from fs_course_red_packet_log where video_id = #{videoId} and user_id = #{userId} limit 1")
+    @Select("select * from fs_course_red_packet_log where video_id = #{videoId} and user_id = #{userId} order by log_id desc limit 1")
     FsCourseRedPacketLog selectFsCourseRedPacketLogByTemporary(@Param("videoId") Long videoId, @Param("userId")Long userId);
 
     /**

+ 3 - 0
fs-service/src/main/java/com/fs/course/mapper/FsUserCompanyUserMapper.java

@@ -2,6 +2,7 @@ package com.fs.course.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.course.domain.FsUserCompanyUser;
+import com.fs.qw.dto.FsUserTransferParamDTO;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
@@ -76,4 +77,6 @@ public interface FsUserCompanyUserMapper extends BaseMapper<FsUserCompanyUser>{
      * @return
      */
     List<FsUserCompanyUser> selectRepeatCompanyUserName(@Param("userIds") List<Long> userIds);
+
+    void transfer(@Param("param") FsUserTransferParamDTO transferParam);
 }

+ 11 - 2
fs-service/src/main/java/com/fs/qw/service/impl/CustomerTransferApprovalServiceImpl.java

@@ -8,6 +8,7 @@ import com.fs.company.cache.ICompanyCacheService;
 import com.fs.company.cache.ICompanyUserCacheService;
 import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyUser;
+import com.fs.course.mapper.FsUserCompanyUserMapper;
 import com.fs.his.domain.FsUser;
 import com.fs.his.service.IFsUserService;
 import com.fs.qw.domain.CustomerTransferApproval;
@@ -17,6 +18,7 @@ import com.fs.qw.service.ICustomerTransferApprovalService;
 import com.fs.qw.vo.TransferCustomDTO;
 import com.fs.store.service.cache.IFsUserCacheService;
 import com.hc.openapi.tool.util.StringUtils;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.http.util.Asserts;
 import org.springframework.aop.framework.AopContext;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,7 +55,8 @@ public class CustomerTransferApprovalServiceImpl implements ICustomerTransferApp
 
     @Autowired
     private IFsUserService fsUserService;
-
+    @Autowired
+    private FsUserCompanyUserMapper fsUserCompanyUserMapper;
     /**
      * 查询客户转移审批
      *
@@ -233,7 +236,13 @@ public class CustomerTransferApprovalServiceImpl implements ICustomerTransferApp
             transferParam.setUserIds(customerIds);
             transferParam.setSourceCompanyUserId(item.getOriginalUserId());
 
-            fsUserService.transfer(transferParam);
+            if(CollectionUtils.isNotEmpty(transferParam.getUserIds())) {
+                fsUserService.transfer(transferParam);
+            }
+
+            if(CollectionUtils.isNotEmpty(transferParam.getUserIds())) {
+                fsUserCompanyUserMapper.transfer(transferParam);
+            }
         }
         List<Long> customerIds = JSON.parseArray(item.getCustomerIds(), Long.class);
         List<TransferCustomDTO> customerList = getCustomerList(customerIds, item);

+ 12 - 0
fs-service/src/main/resources/mapper/course/FsUserCompanyUserMapper.xml

@@ -87,4 +87,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY
             fs_user_company_user.user_id
     </select>
+
+    <update id="transfer">
+        update fs_user_company_user set company_user_id=#{targetCompanyUserId}
+        <where>
+            <if test="param.userIds != null and param.userIds.size() > 0">
+                user_id in
+                <foreach collection="param.userIds" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </update>
 </mapper>