浏览代码

营期定时任务处理销售链接及fsUserId

Long 2 月之前
父节点
当前提交
00bd6c24c3

+ 56 - 17
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -2,10 +2,13 @@ package com.fs.app.taskService.impl;
 
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fs.app.taskService.SopLogsTaskService;
 import com.fs.app.taskService.SopLogsTaskService;
 import com.fs.common.utils.BatchUtils;
 import com.fs.common.utils.BatchUtils;
 import com.fs.common.utils.PubFun;
 import com.fs.common.utils.PubFun;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.company.domain.CompanyUser;
+import com.fs.company.service.ICompanyUserService;
 import com.fs.course.config.CourseConfig;
 import com.fs.course.config.CourseConfig;
 import com.fs.course.domain.*;
 import com.fs.course.domain.*;
 import com.fs.course.mapper.FsCourseDomainNameMapper;
 import com.fs.course.mapper.FsCourseDomainNameMapper;
@@ -17,6 +20,7 @@ import com.fs.fastgptApi.vo.AudioVO;
 import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.mapper.QwUserMapper;
 import com.fs.qw.mapper.QwUserMapper;
+import com.fs.qw.service.IQwExternalContactService;
 import com.fs.qw.vo.QwSopCourseFinishTempSetting;
 import com.fs.qw.vo.QwSopCourseFinishTempSetting;
 import com.fs.qw.vo.QwSopRuleTimeVO;
 import com.fs.qw.vo.QwSopRuleTimeVO;
 import com.fs.qw.vo.QwSopTempSetting;
 import com.fs.qw.vo.QwSopTempSetting;
@@ -122,6 +126,10 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
     @Autowired
     @Autowired
     private QwSopTempMapper qwSopTempMapper;
     private QwSopTempMapper qwSopTempMapper;
 
 
+    @Autowired
+    private ICompanyUserService companyUserService;
+    @Autowired
+    private IQwExternalContactService qwExternalContactService;
 
 
     @PostConstruct
     @PostConstruct
     public void init() {
     public void init() {
@@ -244,7 +252,35 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
             return;
             return;
         }
         }
 
 
+        // 查询销售二级域名
+        Set<Long> ids = sopUserLogsVos.stream().map(s -> {
+            String[] userKey = s.getUserId().split("\\|");
+            if (userKey.length < 3) {
+                return null;
+            }
+            return Long.parseLong(userKey[1]);
+        }).filter(Objects::nonNull).collect(Collectors.toSet());
+        List<CompanyUser> companyUserList;
+        if (ids.isEmpty()) {
+            companyUserList = new ArrayList<>();
+        } else {
+            companyUserList = companyUserService.selectCompanyUserByIds(ids);
+        }
+
         Map<String, List<SopUserLogsVo>> sopLogsGroupedById = sopUserLogsVos.stream()
         Map<String, List<SopUserLogsVo>> sopLogsGroupedById = sopUserLogsVos.stream()
+                .peek(s -> {
+                    String[] userKey = s.getUserId().split("\\|");
+                    if (userKey.length < 3) {
+                        return;
+                    }
+
+                    // 销售ID
+                    Long companyUserId = Long.parseLong(userKey[1]);
+                    CompanyUser companyUser = companyUserList.stream().filter(cu -> Objects.equals(cu.getUserId(), companyUserId)).findFirst().orElse(null);
+                    if (Objects.nonNull(companyUser)) {
+                        s.setDomain(companyUser.getDomain());
+                    }
+                })
                 .collect(Collectors.groupingBy(SopUserLogsVo::getSopId));
                 .collect(Collectors.groupingBy(SopUserLogsVo::getSopId));
 
 
         log.info("共分组 {} 个 SOP ID 进行处理。", sopLogsGroupedById.size());
         log.info("共分组 {} 个 SOP ID 进行处理。", sopLogsGroupedById.size());
@@ -466,6 +502,18 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
 
 
                         List<SopUserLogsInfo> sopUserLogsInfos = sopUserLogsInfoMapper.selectSopUserLogsInfoList(userLogsInfo);
                         List<SopUserLogsInfo> sopUserLogsInfos = sopUserLogsInfoMapper.selectSopUserLogsInfoList(userLogsInfo);
 
 
+                        // 获取fsUserId
+                        Set<Long> externalIds = sopUserLogsInfos.stream().map(SopUserLogsInfo::getExternalId).collect(Collectors.toSet());
+                        if (!externalIds.isEmpty()) {
+                            List<QwExternalContact> externalContactList = qwExternalContactService.list(Wrappers.<QwExternalContact>lambdaQuery().in(QwExternalContact::getId, externalIds));
+                            sopUserLogsInfos.forEach(s -> {
+                                QwExternalContact qwExternalContact = externalContactList.stream().filter(e -> Objects.equals(s.getExternalId(), e.getId())).findFirst().orElse(null);
+                                if (Objects.nonNull(qwExternalContact)) {
+                                    s.setFsUserId(qwExternalContact.getFsUserId());
+                                }
+                            });
+                        }
+
                         insertSopUserLogs(sopUserLogsInfos, logVo, sendTime, ruleTimeVO, content);
                         insertSopUserLogs(sopUserLogsInfos, logVo, sendTime, ruleTimeVO, content);
 
 
                     }
                     }
@@ -570,7 +618,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                 Long fsUserId = contactId.getFsUserId();
                 Long fsUserId = contactId.getFsUserId();
                 QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, contactId.getExternalContactId(), externalUserName, fsUserId);
                 QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, contactId.getExternalContactId(), externalUserName, fsUserId);
                 handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
                 handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
-                        type, qwUserId, companyUserId, companyId, externalId);
+                        type, qwUserId, companyUserId, companyId, externalId, fsUserId);
             } catch (Exception e) {
             } catch (Exception e) {
                 log.error("处理 externalContactId {} 时发生异常: {}", contactId, e.getMessage(), e);
                 log.error("处理 externalContactId {} 时发生异常: {}", contactId, e.getMessage(), e);
             }
             }
@@ -622,14 +670,14 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
     private void handleLogBasedOnType(QwSopLogs sopLogs, QwSopTempSetting.Content content,
     private void handleLogBasedOnType(QwSopLogs sopLogs, QwSopTempSetting.Content content,
                                       SopUserLogsVo logVo, Date sendTime, Long courseId,
                                       SopUserLogsVo logVo, Date sendTime, Long courseId,
                                       Long videoId, int type, String qwUserId,
                                       Long videoId, int type, String qwUserId,
-                                      String companyUserId, String companyId, String externalId) {
+                                      String companyUserId, String companyId, String externalId, Long fsUserId) {
         switch (type) {
         switch (type) {
             case 1:
             case 1:
                 handleNormalMessage(sopLogs, content,companyUserId);
                 handleNormalMessage(sopLogs, content,companyUserId);
                 break;
                 break;
             case 2:
             case 2:
                 handleCourseMessage(sopLogs, content, logVo, sendTime, courseId, videoId,
                 handleCourseMessage(sopLogs, content, logVo, sendTime, courseId, videoId,
-                        qwUserId, companyUserId, companyId, externalId);
+                        qwUserId, companyUserId, companyId, externalId, fsUserId);
                 break;
                 break;
             case 3:
             case 3:
                 handleOrderMessage(sopLogs, content);
                 handleOrderMessage(sopLogs, content);
@@ -661,7 +709,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
     private void handleCourseMessage(QwSopLogs sopLogs, QwSopTempSetting.Content content,
     private void handleCourseMessage(QwSopLogs sopLogs, QwSopTempSetting.Content content,
                                      SopUserLogsVo logVo, Date sendTime, Long courseId,
                                      SopUserLogsVo logVo, Date sendTime, Long courseId,
                                      Long videoId, String qwUserId, String companyUserId,
                                      Long videoId, String qwUserId, String companyUserId,
-                                     String companyId, String externalId) {
+                                     String companyId, String externalId, Long fsUserId) {
         // 深拷贝 Content 对象,避免使用 JSON
         // 深拷贝 Content 对象,避免使用 JSON
         QwSopTempSetting.Content clonedContent = deepCopyContent(content);
         QwSopTempSetting.Content clonedContent = deepCopyContent(content);
         if (clonedContent == null) {
         if (clonedContent == null) {
@@ -684,7 +732,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
             if ("1".equals(setting.getIsBindUrl())&&("3".equals(setting.getContentType())||"1".equals(setting.getContentType()))) {
             if ("1".equals(setting.getIsBindUrl())&&("3".equals(setting.getContentType())||"1".equals(setting.getContentType()))) {
                 addWatchLogIfNeeded(sopLogs, videoId, courseId, sendTime, qwUserId, companyUserId, companyId, externalId,logVo);
                 addWatchLogIfNeeded(sopLogs, videoId, courseId, sendTime, qwUserId, companyUserId, companyId, externalId,logVo);
                 String sortLink = generateShortLink(setting, logVo, sendTime, courseId, videoId,
                 String sortLink = generateShortLink(setting, logVo, sendTime, courseId, videoId,
-                        qwUserId, companyUserId, companyId, externalId);
+                        qwUserId, companyUserId, companyId, externalId, fsUserId);
                 if (StringUtils.isNotEmpty(sortLink)) {
                 if (StringUtils.isNotEmpty(sortLink)) {
                     if ("3".equals(setting.getContentType())) {
                     if ("3".equals(setting.getContentType())) {
                         setting.setLinkUrl(sortLink);
                         setting.setLinkUrl(sortLink);
@@ -725,7 +773,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
 
 
     private String generateShortLink(QwSopTempSetting.Content.Setting setting, SopUserLogsVo logVo, Date sendTime,
     private String generateShortLink(QwSopTempSetting.Content.Setting setting, SopUserLogsVo logVo, Date sendTime,
                                      Long courseId, Long videoId, String qwUserId,
                                      Long courseId, Long videoId, String qwUserId,
-                                     String companyUserId, String companyId, String externalId) {
+                                     String companyUserId, String companyId, String externalId, Long fsUserId) {
         // 获取缓存的配置
         // 获取缓存的配置
         CourseConfig config;
         CourseConfig config;
         synchronized(configLock) {
         synchronized(configLock) {
@@ -757,6 +805,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         courseMap.setCourseId(link.getCourseId());
         courseMap.setCourseId(link.getCourseId());
         courseMap.setQwExternalId(link.getQwExternalId());
         courseMap.setQwExternalId(link.getQwExternalId());
         courseMap.setLinkType(0);
         courseMap.setLinkType(0);
+        courseMap.setFsUserId(fsUserId);
 
 
         String courseJson = JSON.toJSONString(courseMap);
         String courseJson = JSON.toJSONString(courseMap);
         String realLinkFull = REAL_LINK_PREFIX + courseJson;
         String realLinkFull = REAL_LINK_PREFIX + courseJson;
@@ -777,17 +826,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
         Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
         link.setUpdateTime(updateTime);
         link.setUpdateTime(updateTime);
 
 
-        // 从缓存中随机选择一个域名
-        FsCourseDomainName fsCourseDomainName;
-        if (cachedDomainNames == null || cachedDomainNames.isEmpty()) {
-            log.error("No domain names available for short link generation.");
-            return "";
-        }
-
-        int randomIndex = ThreadLocalRandom.current().nextInt(cachedDomainNames.size());
-        fsCourseDomainName = cachedDomainNames.get(randomIndex);
-
-        String sortLink = "https://" + fsCourseDomainName.getDomainName() + "/s/" + link.getLink();
+        String sortLink = "https://" + logVo.getDomain() + "/s/" + link.getLink();
         enqueueCourseLink(link);
         enqueueCourseLink(link);
         return sortLink;
         return sortLink;
     }
     }

+ 8 - 0
fs-service-system/src/main/java/com/fs/company/mapper/CompanyUserMapper.java

@@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 import org.apache.ibatis.annotations.Update;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Set;
 
 
 /**
 /**
  * 物业公司管理员信息Mapper接口
  * 物业公司管理员信息Mapper接口
@@ -247,4 +248,11 @@ public interface CompanyUserMapper
 
 
     @Select("select * from company_user where company_id=#{companyId} and del_flag=0")
     @Select("select * from company_user where company_id=#{companyId} and del_flag=0")
     List<CompanyUser> selectCompanyUserByCompanyId(Long companyId);
     List<CompanyUser> selectCompanyUserByCompanyId(Long companyId);
+
+    /**
+     * 查询公司销售列表
+     * @param ids 销售ID集合
+     * @return  list
+     */
+    List<CompanyUser> selectCompanyUserByIds(Set<Long> ids);
 }
 }

+ 8 - 0
fs-service-system/src/main/java/com/fs/company/service/ICompanyUserService.java

@@ -12,6 +12,7 @@ import com.fs.his.vo.OptionsVO;;
 
 
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.Set;
 
 
 /**
 /**
  * 物业公司管理员信息Service接口
  * 物业公司管理员信息Service接口
@@ -126,4 +127,11 @@ public interface ICompanyUserService {
     List<CompanyQwUserByIdsVo> selectCompanyQwUserByIds(List<Long> qwUserIdList);
     List<CompanyQwUserByIdsVo> selectCompanyQwUserByIds(List<Long> qwUserIdList);
 
 
     CompanyUser selectCompanyUserByUserId(Long userId);
     CompanyUser selectCompanyUserByUserId(Long userId);
+
+    /**
+     * 查询公司销售列表
+     * @param ids 销售ID集合
+     * @return  list
+     */
+    List<CompanyUser> selectCompanyUserByIds(Set<Long> ids);
 }
 }

+ 10 - 0
fs-service-system/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -386,4 +386,14 @@ public class CompanyUserServiceImpl implements ICompanyUserService
         return companyUserMapper.selectCompanyUserByUserId(userId);
         return companyUserMapper.selectCompanyUserByUserId(userId);
     }
     }
 
 
+    /**
+     * 查询公司销售列表
+     * @param ids 销售ID集合
+     * @return  list
+     */
+    @Override
+    public List<CompanyUser> selectCompanyUserByIds(Set<Long> ids) {
+        return companyUserMapper.selectCompanyUserByIds(ids);
+    }
+
 }
 }

+ 5 - 0
fs-service-system/src/main/java/com/fs/course/domain/FsCourseRealLink.java

@@ -29,4 +29,9 @@ public class FsCourseRealLink implements Serializable
 
 
     private Long linkId;
     private Long linkId;
 
 
+    /**
+     * 用户ID (fs_user表)
+     */
+    private Long fsUserId;
+
 }
 }

+ 5 - 0
fs-service-system/src/main/java/com/fs/sop/vo/SopUserLogsVo.java

@@ -29,4 +29,9 @@ public class SopUserLogsVo  {
      */
      */
     private Integer status;
     private Integer status;
 
 
+    /**
+     * 销售二级域名
+     */
+    private String domain;
+
 }
 }

+ 10 - 0
fs-service-system/src/main/resources/mapper/company/CompanyUserMapper.xml

@@ -328,6 +328,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         and b.voice_print_url is not null
         and b.voice_print_url is not null
     </select>
     </select>
 
 
+    <select id="selectCompanyUserByIds" resultType="com.fs.company.domain.CompanyUser">
+        select cu.*
+        from company_user cu
+        where cu.user_id in
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+
+    </select>
+
 
 
     <resultMap type="com.fs.company.vo.CompanyUserVO" id="CompanyUserVOResult">
     <resultMap type="com.fs.company.vo.CompanyUserVO" id="CompanyUserVOResult">
         <result property="userId"    column="user_id"    />
         <result property="userId"    column="user_id"    />