Bläddra i källkod

fix:修复福袋领取不了的问题

ct 1 vecka sedan
förälder
incheckning
e68fe33157

+ 216 - 12
fs-ipad-task/src/main/java/com/fs/app/service/IpadSendServer.java

@@ -1,5 +1,6 @@
 package com.fs.app.service;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -9,13 +10,13 @@ import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.date.DateUtil;
 import com.fs.common.utils.http.HttpUtils;
 import com.fs.common.utils.spring.SpringUtils;
+import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyMiniapp;
+import com.fs.company.mapper.CompanyMapper;
 import com.fs.company.service.ICompanyMiniappService;
 import com.fs.config.ai.AiHostProper;
-import com.fs.course.domain.FsCoursePlaySourceConfig;
-import com.fs.course.domain.FsCourseWatchLog;
-import com.fs.course.domain.FsUserCourseVideo;
-import com.fs.course.domain.LuckyBagCollectRecord;
+import com.fs.course.config.CourseConfig;
+import com.fs.course.domain.*;
 import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
 import com.fs.course.mapper.FsUserCourseVideoMapper;
 import com.fs.course.service.IFsCoursePlaySourceConfigService;
@@ -31,6 +32,7 @@ import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwUser;
 import com.fs.qw.domain.QwUserVideo;
 import com.fs.qw.mapper.LuckyBagCollectRecordMapper;
+import com.fs.qw.mapper.LuckyBagMapper;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.mapper.QwUserMapper;
 import com.fs.qw.service.IQwUserService;
@@ -40,6 +42,7 @@ import com.fs.qw.vo.QwSopCourseFinishTempSetting;
 import com.fs.sop.domain.QwSopLogs;
 import com.fs.sop.service.IQwSopLogsService;
 import com.fs.sop.service.impl.QwSopLogsServiceImpl;
+import com.fs.system.service.ISysConfigService;
 import com.fs.wxwork.dto.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -49,12 +52,15 @@ import org.json.JSONObject;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.*;
 import java.util.Optional;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -73,6 +79,9 @@ public class IpadSendServer {
     private final ICompanyMiniappService companyMiniappService;
     private final AiHookService aiHookService;
     private final AiHostProper aiHostProper;
+    private final ISysConfigService configService;
+    private final LuckyBagMapper luckyBagMapper;
+    private final CompanyMapper companyMapper;
     private final ExecutorService executor = new ThreadPoolExecutor(
             8, 32, 60L, TimeUnit.SECONDS,
             new LinkedBlockingQueue<>(1000),
@@ -759,7 +768,7 @@ public class IpadSendServer {
                     break;
                 case "14":
                     // 记录福袋发送记录
-                    addLuckyBagCollectRecord(vo, content,qwSopLogs);
+                    addLuckyBagCollectRecord(qwUser, content,qwSopLogs);
                     // 福袋
                     sendMiniProgram(vo, content, miniMap);
                     break;
@@ -777,14 +786,17 @@ public class IpadSendServer {
             content.setSendRemarks("发送失败:" + e.getMessage());
         }
     }
-    private void addLuckyBagCollectRecord(BaseVo vo,QwSopCourseFinishTempSetting.Setting content,QwSopLogs qwSopLogs) {
-        try {
-            // 写入福袋发放记录
-            LuckyBagCollectRecord luckyBagCollectRecord = luckyBagCollectRecordMapper.selectLuckyBagCollectRecordById(Long.valueOf(content.getBusinessId()));
-            luckyBagCollectRecord.setSendTime(new Date());
-            luckyBagCollectRecord.setCollectType("0");
-            luckyBagCollectRecordMapper.updateLuckyBagCollectRecord(luckyBagCollectRecord);
+    private void addLuckyBagCollectRecord(QwUser qwUser, QwSopCourseFinishTempSetting.Setting content, QwSopLogs qwSopLogs) {
 
+        try {
+            String json = configService.selectConfigByKey("course.config");
+            CourseConfig config = JSON.parseObject(json, CourseConfig.class);
+            Date updateTime = createUpdateTime(content, new Date(), config);
+            LuckyBag luckyBag = luckyBagMapper.selectLuckyBagById(content.getLuckyBagId());
+            String companyUserId = String.valueOf(qwUser.getCompanyUserId()).trim();
+            String companyId = String.valueOf(qwUser.getCompanyId()).trim();
+            Long businessId = addLuckyBagCollectRecord(qwUser,luckyBag,content,qwSopLogs,updateTime,companyUserId,companyId,content.getChatId());
+            content.setMiniprogramPage(quickProcess(content.getMiniprogramPage(),businessId));
         }catch (Exception e){
             log.error("ID:" + qwSopLogs.getId() + "-添加福袋记录失败", e);
         }
@@ -793,4 +805,196 @@ public class IpadSendServer {
     public void loginOut(QwUser user) {
         ipadSendUtils.loginOut(user.getUid(), user.getServerId());
     }
+
+    /**
+     * 过期时间
+     *
+     * @param setting
+     * @param sendTime
+     * @param config
+     * @return
+     */
+    private Date createUpdateTime(QwSopCourseFinishTempSetting.Setting setting, Date sendTime, CourseConfig config) {
+
+        Integer expireDays = (setting.getExpiresDays() == null || setting.getExpiresDays() == 0)
+                ? config.getVideoLinkExpireDate()
+                : setting.getExpiresDays();
+
+//         使用 Java 8 时间 API 计算过期时间
+        LocalDateTime sendDateTime = sendTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
+        LocalDateTime expireDateTime = sendDateTime.plusDays(expireDays - 1);
+        expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
+        Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
+
+        return updateTime;
+    }
+    private static final Pattern LINK_PATTERN =
+            Pattern.compile("link=([^&]*)");
+    /**
+     * 快速处理方法(使用fastjson)
+     */
+    public static String quickProcess(String miniprogramPage, Long businessId) {
+        if (miniprogramPage == null || businessId == null) {
+            return miniprogramPage;
+        }
+
+        try {
+            Matcher matcher = LINK_PATTERN.matcher(miniprogramPage);
+            if (matcher.find()) {
+                String encodedLink = matcher.group(1);
+                String decodedLink = java.net.URLDecoder.decode(encodedLink, "UTF-8");
+
+                // 解析JSON
+                com.alibaba.fastjson.JSONObject linkJson = JSON.parseObject(decodedLink);
+
+                // 检查并添加businessId
+                if (!linkJson.containsKey("businessId") ||
+                        linkJson.getString("businessId").isEmpty()) {
+                    linkJson.put("businessId", businessId);
+
+                    // 重新编码
+                    String updatedJson = linkJson.toJSONString();
+                    String updatedEncoded = java.net.URLEncoder.encode(updatedJson, "UTF-8");
+
+                    // 替换原link参数
+                    return miniprogramPage.replaceFirst(
+                            "link=" + Pattern.quote(encodedLink),
+                            "link=" + updatedEncoded
+                    );
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return miniprogramPage;
+    }
+
+
+    /**
+     * 增加福袋发放记录、领取记录
+     *
+     * @param companyId
+     * @param qwUser
+     * @param luckyBag
+     * @param content
+     * @param qwSopLogs
+     * @param sendTime
+     * @param companyUserId
+     * @param chatId
+     */
+    private Long addLuckyBagCollectRecord(QwUser qwUser, LuckyBag luckyBag, QwSopCourseFinishTempSetting.Setting content,
+                                          QwSopLogs qwSopLogs,
+                                          Date sendTime,
+                                          String companyUserId,
+                                          String companyId,
+                                          String chatId) {
+        try {
+            // 参数校验
+            if (content == null || qwSopLogs == null || sendTime == null) {
+                log.warn("添加福袋记录失败:必要参数为空 [content:{}, qwSopLogs:{}, sendTime:{}]",
+                        content, qwSopLogs, sendTime);
+                return null;
+            }
+
+            // 验证福袋ID
+            if (content.getLuckyBagId() == null) {
+                log.warn("福袋ID为空");
+                return null;
+            }
+
+            // 查询福袋信息
+            if (luckyBag == null) {
+                log.warn("未找到对应的福袋信息 [luckyBagId:{}]", content.getLuckyBagId());
+                return null;
+            }
+
+            // 检查福袋状态
+            if (luckyBag.getDataStatus() != null && luckyBag.getDataStatus().equals(0)) {
+                log.warn("福袋被禁用 [luckyBagId:{}]", content.getLuckyBagId());
+                return null;
+            }
+
+            // 查询公司信息
+            Company company = (Company)redisCache.getCacheObject("companyId:"+companyId);
+            if (company == null) {
+                company = companyMapper.selectCompanyById(Long.valueOf(companyId));
+                redisCache.setCacheObject("companyId:"+companyId, company, 1 , TimeUnit.DAYS);
+                log.warn("未找到对应的公司信息 [companyId:{}]", companyId);
+            }
+
+            // 构建福袋记录
+            LuckyBagCollectRecord luckyBagCollectRecord = buildLuckyBagRecord(qwUser,content, qwSopLogs, sendTime,
+                    companyUserId, companyId, chatId, company, luckyBag);
+            luckyBagCollectRecord.setSendTime(new Date());
+            luckyBagCollectRecord.setCollectType("0");
+            // 插入记录并返回ID
+            int result = luckyBagCollectRecordMapper.insertLuckyBagCollectRecord(luckyBagCollectRecord);
+            if (result <= 0) {
+                log.warn("福袋记录插入失败 [luckyBagId:{}]", content.getLuckyBagId());
+                return null;
+            }
+
+            // 返回新增记录的ID
+            Long recordId = luckyBagCollectRecord.getId();
+            if (recordId == null) {
+                log.warn("福袋记录插入成功但未返回ID [luckyBagId:{}]", content.getLuckyBagId());
+                return null;
+            }
+
+            log.info("福袋记录添加成功 [recordId:{}, luckyBagId:{}]", recordId, content.getLuckyBagId());
+            return recordId;
+
+        } catch (NumberFormatException e) {
+            log.error("ID转换失败 [companyId:{}, companyUserId:{}]", companyId, companyUserId, e);
+            return null;
+        } catch (Exception e) {
+            log.error("ID:" + (content != null ? content.getLuckyBagId() : "unknown") + "-添加福袋记录失败", e);
+            return null;
+        }
+    }
+
+    /**
+     * 构建福袋记录对象
+     */
+    private LuckyBagCollectRecord buildLuckyBagRecord(QwUser qwUser,QwSopCourseFinishTempSetting.Setting content,
+                                                      QwSopLogs qwSopLogs,
+                                                      Date sendTime,
+                                                      String companyUserId,
+                                                      String companyId,
+                                                      String chatId,
+                                                      Company company,
+                                                      LuckyBag luckyBag) {
+        LuckyBagCollectRecord record = new LuckyBagCollectRecord();
+        record.setQwUserId(qwUser.getQwUserId());
+        record.setQwUserName(qwUser.getQwUserName());
+        record.setLuckyBagId(content.getLuckyBagId());
+        record.setExpiryTime(sendTime);
+        record.setCollectType("3");
+        record.setCompanyId(Long.valueOf(companyId));
+        record.setUserId(qwSopLogs.getFsUserId());
+        if (ObjectUtil.isNotEmpty(qwSopLogs.getFsUserId())){
+            FsUser fsUser = fsUserMapper.selectFsUserByUserId(qwSopLogs.getFsUserId());
+            record.setUserName(ObjectUtil.isNotEmpty(fsUser)?fsUser.getNickName():null);
+        }
+        record.setCompanyName(company.getCompanyName());
+        record.setCompanyUserId(Long.valueOf(companyUserId));
+        record.setSendLink(content.getMiniprogramPage());
+
+        // 设置奖励类型和聊天信息
+        if (StringUtils.isNotEmpty(chatId)) {
+            record.setRewardType(1L);
+            record.setChatId(chatId);
+            record.setExternalUserName(qwSopLogs.getExternalUserName());
+        } else {
+            record.setRewardType(2L);
+        }
+
+        // 设置币种金额
+        if (luckyBag.getRewardType() != null && luckyBag.getRewardType().equals("1")) {
+            record.setCoinAmount(luckyBag.getAmount());
+        }
+
+        return record;
+    }
 }

+ 4 - 87
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -2836,10 +2836,11 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         link.setUpdateTime(updateTime);
         FsCourseRealLink courseMap = new FsCourseRealLink();
         BeanUtils.copyProperties(link, courseMap);
-        Long businessId = addLuckyBagCollectRecord(st,sopLogs,updateTime,companyUserId,companyId,chatId);
-        courseMap.setBusinessId(String.valueOf(businessId));
-        st.setBusinessId(String.valueOf(businessId));
+//        Long businessId = addLuckyBagCollectRecord(st,sopLogs,updateTime,companyUserId,companyId,chatId);
+//        courseMap.setBusinessId(String.valueOf(businessId));
+//        st.setBusinessId(String.valueOf(businessId));
         st.setExternalUserId(sopLogs.getExternalUserId());
+        st.setChatId(chatId);
         String json = configService.selectConfigByKey("luckyBag.config");
         Map<String, Object> luckyBagConfig = JSON.parseObject(json, Map.class);
         Object miniprogramPicUrl = luckyBagConfig.get("miniprogramPicUrl");
@@ -2882,90 +2883,6 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         return link;
     }
 
-    /**
-     * 增加福袋发放记录、领取记录
-     *
-     * @param content
-     * @param qwSopLogs
-     * @param sendTime
-     * @param companyUserId
-     * @param companyId
-     * @param chatId
-     */
-    private Long addLuckyBagCollectRecord(QwSopTempSetting.Content.Setting content,
-                                          QwSopLogs qwSopLogs,
-                                          Date sendTime,
-                                          String companyUserId,
-                                          String companyId,
-                                          String chatId) {
-        try {
-            // 参数校验
-            if (content == null || qwSopLogs == null || sendTime == null) {
-                log.warn("添加福袋记录失败:必要参数为空 [content:{}, qwSopLogs:{}, sendTime:{}]",
-                        content, qwSopLogs, sendTime);
-                return null;
-            }
-
-            if (StringUtils.isEmpty(companyId) || StringUtils.isEmpty(companyUserId)) {
-                log.warn("公司ID或用户ID为空 [companyId:{}, companyUserId:{}]", companyId, companyUserId);
-                return null;
-            }
-
-            // 验证福袋ID
-            if (content.getLuckyBagId() == null) {
-                log.warn("福袋ID为空");
-                return null;
-            }
-
-            // 查询福袋信息
-            LuckyBag luckyBag = luckyBagMapper.selectLuckyBagById(content.getLuckyBagId());
-            if (luckyBag == null) {
-                log.warn("未找到对应的福袋信息 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 检查福袋状态
-            if (luckyBag.getDataStatus() != null && luckyBag.getDataStatus().equals(0)) {
-                log.warn("福袋被禁用 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 查询公司信息
-            Company company = companyMapper.selectCompanyById(Long.valueOf(companyId));
-            if (company == null) {
-                log.warn("未找到对应的公司信息 [companyId:{}]", companyId);
-                return null;
-            }
-
-            // 构建福袋记录
-            LuckyBagCollectRecord luckyBagCollectRecord = buildLuckyBagRecord(content, qwSopLogs, sendTime,
-                    companyUserId, companyId, chatId, company, luckyBag);
-
-            // 插入记录并返回ID
-            int result = luckyBagCollectRecordMapper.insertLuckyBagCollectRecord(luckyBagCollectRecord);
-            if (result <= 0) {
-                log.warn("福袋记录插入失败 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 返回新增记录的ID
-            Long recordId = luckyBagCollectRecord.getId();
-            if (recordId == null) {
-                log.warn("福袋记录插入成功但未返回ID [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            log.info("福袋记录添加成功 [recordId:{}, luckyBagId:{}]", recordId, content.getLuckyBagId());
-            return recordId;
-
-        } catch (NumberFormatException e) {
-            log.error("ID转换失败 [companyId:{}, companyUserId:{}]", companyId, companyUserId, e);
-            return null;
-        } catch (Exception e) {
-            log.error("ID:" + (content != null ? content.getLuckyBagId() : "unknown") + "-添加福袋记录失败", e);
-            return null;
-        }
-    }
 
     /**
      * 构建福袋记录对象

+ 3 - 122
fs-service/src/main/java/com/fs/qw/service/AsyncQwAiChatSopService.java

@@ -321,9 +321,9 @@ public class AsyncQwAiChatSopService {
         link.setUpdateTime(updateTime);
         FsCourseRealLink courseMap = new FsCourseRealLink();
         BeanUtils.copyProperties(link, courseMap);
-        Long businessId = addLuckyBagCollectRecord(st,sopLogs,updateTime,companyUserId,companyId,chatId);
-        courseMap.setBusinessId(String.valueOf(businessId));
-        st.setBusinessId(String.valueOf(businessId));
+//        Long businessId = addLuckyBagCollectRecord(st,sopLogs,updateTime,companyUserId,companyId,chatId);
+//        courseMap.setBusinessId(String.valueOf(businessId));
+//        st.setBusinessId(String.valueOf(businessId));
         st.setExternalUserId(sopLogs.getExternalUserId());
         String json = configService.selectConfigByKey("luckyBag.config");
         Map<String, Object> luckyBagConfig = JSON.parseObject(json, Map.class);
@@ -518,125 +518,6 @@ public class AsyncQwAiChatSopService {
         return updateTime;
     }
 
-    private Long addLuckyBagCollectRecord(QwSopTempSetting.Content.Setting content,
-                                          QwSopLogs qwSopLogs,
-                                          Date sendTime,
-                                          String companyUserId,
-                                          String companyId,
-                                          String chatId) {
-        try {
-            // 参数校验
-            if (content == null || qwSopLogs == null || sendTime == null) {
-                log.warn("添加福袋记录失败:必要参数为空 [content:{}, qwSopLogs:{}, sendTime:{}]",
-                        content, qwSopLogs, sendTime);
-                return null;
-            }
-
-            if (StringUtils.isEmpty(companyId) || StringUtils.isEmpty(companyUserId)) {
-                log.warn("公司ID或用户ID为空 [companyId:{}, companyUserId:{}]", companyId, companyUserId);
-                return null;
-            }
-
-            // 验证福袋ID
-            if (content.getLuckyBagId() == null) {
-                log.warn("福袋ID为空");
-                return null;
-            }
-
-            // 查询福袋信息
-            LuckyBag luckyBag = luckyBagMapper.selectLuckyBagById(content.getLuckyBagId());
-            if (luckyBag == null) {
-                log.warn("未找到对应的福袋信息 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 检查福袋状态
-            if (luckyBag.getDataStatus() != null && luckyBag.getDataStatus().equals(0)) {
-                log.warn("福袋被禁用 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 查询公司信息
-            Company company = companyMapper.selectCompanyById(Long.valueOf(companyId));
-            if (company == null) {
-                log.warn("未找到对应的公司信息 [companyId:{}]", companyId);
-                return null;
-            }
-
-            // 构建福袋记录
-            LuckyBagCollectRecord luckyBagCollectRecord = buildLuckyBagRecord(content, qwSopLogs, sendTime,
-                    companyUserId, companyId, chatId, company, luckyBag);
-
-            // 插入记录并返回ID
-            int result = luckyBagCollectRecordMapper.insertLuckyBagCollectRecord(luckyBagCollectRecord);
-            if (result <= 0) {
-                log.warn("福袋记录插入失败 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 返回新增记录的ID
-            Long recordId = luckyBagCollectRecord.getId();
-            if (recordId == null) {
-                log.warn("福袋记录插入成功但未返回ID [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            log.info("福袋记录添加成功 [recordId:{}, luckyBagId:{}]", recordId, content.getLuckyBagId());
-            return recordId;
-
-        } catch (NumberFormatException e) {
-            log.error("ID转换失败 [companyId:{}, companyUserId:{}]", companyId, companyUserId, e);
-            return null;
-        } catch (Exception e) {
-            log.error("ID:" + (content != null ? content.getLuckyBagId() : "unknown") + "-添加福袋记录失败", e);
-            return null;
-        }
-    }
-
-    private LuckyBagCollectRecord buildLuckyBagRecord(QwSopTempSetting.Content.Setting content,
-                                                      QwSopLogs qwSopLogs,
-                                                      Date sendTime,
-                                                      String companyUserId,
-                                                      String companyId,
-                                                      String chatId,
-                                                      Company company,
-                                                      LuckyBag luckyBag) {
-        LuckyBagCollectRecord record = new LuckyBagCollectRecord();
-        if (luckyBag.getType().equals("1")) {
-            record.setCoinAmount(luckyBag.getAmount());
-        }
-        QwUser qwUser = qwUserMapper.selectQwUserEntityByQwUserIdAndCorId(qwSopLogs.getQwUserid(),qwSopLogs.getCorpId());
-        record.setQwUserId(qwUser.getQwUserId());
-        record.setQwUserName(qwUser.getQwUserName());
-        record.setLuckyBagId(content.getLuckyBagId());
-        record.setExpiryTime(sendTime);
-        record.setCollectType("3");
-        record.setCompanyId(Long.valueOf(companyId));
-        record.setUserId(qwSopLogs.getFsUserId());
-        if (ObjectUtil.isNotEmpty(qwSopLogs.getFsUserId())){
-            FsUser fsUser = fsUserMapper.selectFsUserByUserId(qwSopLogs.getFsUserId());
-            record.setUserName(ObjectUtil.isNotEmpty(fsUser)?fsUser.getNickName():null);
-        }
-        record.setCompanyName(company.getCompanyName());
-        record.setCompanyUserId(Long.valueOf(companyUserId));
-        record.setSendLink(content.getMiniprogramPage());
-
-        // 设置奖励类型和聊天信息
-        if (StringUtils.isNotEmpty(chatId)) {
-            record.setRewardType(1L);
-            record.setChatId(chatId);
-            record.setExternalUserName(qwSopLogs.getExternalUserName());
-        } else {
-            record.setRewardType(2L);
-        }
-
-        // 设置币种金额
-        if (luckyBag.getRewardType() != null && luckyBag.getRewardType().equals("1")) {
-            record.setCoinAmount(luckyBag.getAmount());
-        }
-
-        return record;
-    }
 
 
 }

+ 5 - 0
fs-service/src/main/java/com/fs/qw/vo/QwSopCourseFinishTempSetting.java

@@ -135,6 +135,11 @@ public class QwSopCourseFinishTempSetting implements Serializable,Cloneable{
          * 业务id
          */
         private String businessId;
+
+        /**
+         * 群id
+         */
+        private String chatId;
         @Override
         public Setting clone() {
             try {

+ 5 - 0
fs-service/src/main/java/com/fs/qw/vo/QwSopTempSetting.java

@@ -162,6 +162,11 @@ public class QwSopTempSetting implements Serializable{
              */
             private String businessId;
 
+            /**
+             * 群id
+             */
+            private String chatId;
+
 
             @Override
             public Setting clone() {

+ 9 - 92
fs-service/src/main/java/com/fs/sop/service/impl/SopUserLogsInfoServiceImpl.java

@@ -719,7 +719,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                             case "14":
 
                                 linkByMiniApp = createActivityLinkByMiniApp(st,sopLogs, qwGroupChat.getCorpId(), new Date(), param.getCourseId(), param.getVideoId(),
-                                        String.valueOf(qwUser.getId()), qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString(),null ,config, groupUser.getChatId());
+                                        String.valueOf(qwUser.getId()), qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString() ,config, groupUser.getChatId());
 
                                 miniAppId = null;
                                 if (!miniMap.isEmpty() && qwUser.getSendMsgType() == 1) {
@@ -922,7 +922,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                             case "14":
                                 String companyId = String.valueOf(qwUser.getCompanyId()).trim();
                                 linkByMiniApp = createActivityLinkByMiniApp(st,sopLogs, qwUser.getCorpId(), new Date(), param.getCourseId(), param.getVideoId(),
-                                        String.valueOf(qwUser.getId()), qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString(),null, config, groupChat.getChatId());
+                                        String.valueOf(qwUser.getId()), qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString(), config, groupChat.getChatId());
                                 miniAppId = null;
                                 if (!miniMap.isEmpty() && qwUser.getSendMsgType() == 1) {
                                     Map<Integer, List<CompanyMiniapp>> integerListMap = miniMap.get(Long.valueOf(companyId));
@@ -1241,7 +1241,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                                 }
                             }
                             linkByMiniApp = createActivityLinkByMiniApp(st,sopLogs, param.getCorpId(), createTime, param.getCourseId(), param.getVideoId(),
-                                    qwUserId, companyUserId, companyId, item.getExternalId(), config,null);
+                                    qwUserId, companyUserId, companyId, config,null);
 
                             miniAppId = null;
 
@@ -1876,7 +1876,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                     }
 
                     linkByMiniApp = createActivityLinkByMiniApp(st,sopLogs, param.getCorpId(), dataTime, param.getCourseId(), param.getVideoId(),
-                            String.valueOf(qwUser.getId()), companyUserId, companyId, item.getExternalId(), config,null);
+                            String.valueOf(qwUser.getId()), companyUserId, companyId,  config,null);
 
                     miniAppId = null;
 
@@ -1926,17 +1926,18 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
         return  list;
     }
 
-    public String createActivityLinkByMiniApp(QwSopCourseFinishTempSetting.Setting st, QwSopLogs sopLogs, String corpId, Date sendTime, Integer courseId, Integer videoId, String qwUserId, String companyUserId, String companyId, Long externalId, CourseConfig config, String chatId) {
+    public String createActivityLinkByMiniApp(QwSopCourseFinishTempSetting.Setting st, QwSopLogs sopLogs, String corpId, Date sendTime, Integer courseId, Integer videoId, String qwUserId, String companyUserId, String companyId,  CourseConfig config, String chatId) {
         FsCourseLink link = createFsCourseLink(corpId, sendTime, courseId, videoId, Long.valueOf(qwUserId),
                 companyUserId, companyId, null, 3, chatId);
         Date updateTime = createUpdateTime(st, sendTime, config);
         link.setUpdateTime(updateTime);
         FsCourseRealLink courseMap = new FsCourseRealLink();
         BeanUtils.copyProperties(link, courseMap);
-        Long businessId = addLuckyBagCollectRecord(st,sopLogs,updateTime,companyUserId,companyId,chatId);
-        courseMap.setBusinessId(String.valueOf(businessId));
-        st.setBusinessId(String.valueOf(businessId));
+//        Long businessId = addLuckyBagCollectRecord(qwUser,luckyBag,st,sopLogs,updateTime,companyUserId,companyId,chatId);
+//        courseMap.setBusinessId(String.valueOf(businessId));
+//        st.setBusinessId(String.valueOf(businessId));
         st.setExternalUserId(sopLogs.getExternalUserId());
+        st.setChatId(chatId);
         String json = configService.selectConfigByKey("luckyBag.config");
         Map<String, Object> luckyBagConfig = JSON.parseObject(json, Map.class);
         Object miniprogramPicUrl = luckyBagConfig.get("miniprogramPicUrl");
@@ -1953,90 +1954,6 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
         return link.getRealLink();
     }
 
-    /**
-     * 增加福袋发放记录、领取记录
-     *
-     * @param content
-     * @param qwSopLogs
-     * @param sendTime
-     * @param companyUserId
-     * @param companyId
-     * @param chatId
-     */
-    private Long addLuckyBagCollectRecord(QwSopCourseFinishTempSetting.Setting content,
-                                          QwSopLogs qwSopLogs,
-                                          Date sendTime,
-                                          String companyUserId,
-                                          String companyId,
-                                          String chatId) {
-        try {
-            // 参数校验
-            if (content == null || qwSopLogs == null || sendTime == null) {
-                log.warn("添加福袋记录失败:必要参数为空 [content:{}, qwSopLogs:{}, sendTime:{}]",
-                        content, qwSopLogs, sendTime);
-                return null;
-            }
-
-            if (StringUtils.isEmpty(companyId) || StringUtils.isEmpty(companyUserId)) {
-                log.warn("公司ID或用户ID为空 [companyId:{}, companyUserId:{}]", companyId, companyUserId);
-                return null;
-            }
-
-            // 验证福袋ID
-            if (content.getLuckyBagId() == null) {
-                log.warn("福袋ID为空");
-                return null;
-            }
-
-            // 查询福袋信息
-            LuckyBag luckyBag = luckyBagMapper.selectLuckyBagById(content.getLuckyBagId());
-            if (luckyBag == null) {
-                log.warn("未找到对应的福袋信息 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 检查福袋状态
-            if (luckyBag.getDataStatus() != null && luckyBag.getDataStatus().equals(0)) {
-                log.warn("福袋被禁用 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 查询公司信息
-            Company company = companyMapper.selectCompanyById(Long.valueOf(companyId));
-            if (company == null) {
-                log.warn("未找到对应的公司信息 [companyId:{}]", companyId);
-                return null;
-            }
-
-            // 构建福袋记录
-            LuckyBagCollectRecord luckyBagCollectRecord = buildLuckyBagRecord(content, qwSopLogs, sendTime,
-                    companyUserId, companyId, chatId, company, luckyBag);
-
-            // 插入记录并返回ID
-            int result = luckyBagCollectRecordMapper.insertLuckyBagCollectRecord(luckyBagCollectRecord);
-            if (result <= 0) {
-                log.warn("福袋记录插入失败 [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            // 返回新增记录的ID
-            Long recordId = luckyBagCollectRecord.getId();
-            if (recordId == null) {
-                log.warn("福袋记录插入成功但未返回ID [luckyBagId:{}]", content.getLuckyBagId());
-                return null;
-            }
-
-            log.info("福袋记录添加成功 [recordId:{}, luckyBagId:{}]", recordId, content.getLuckyBagId());
-            return recordId;
-
-        } catch (NumberFormatException e) {
-            log.error("ID转换失败 [companyId:{}, companyUserId:{}]", companyId, companyUserId, e);
-            return null;
-        } catch (Exception e) {
-            log.error("ID:" + (content != null ? content.getLuckyBagId() : "unknown") + "-添加福袋记录失败", e);
-            return null;
-        }
-    }
 
     private void createVoiceUrlToIm(QwSopCourseFinishTempSetting.Setting st, String companyUserId, QwSop qwSop) {
         QwSopTempVoice qwSopTempVoice = sopTempVoiceService.selectQwSopTempVoiceByCompanyUserIdAndVoiceTxt(Long.valueOf(companyUserId), st.getValue());