|
@@ -2,6 +2,7 @@ package com.fs.tag.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
@@ -28,7 +29,9 @@ import com.fs.qwApi.param.QwAddTagParam;
|
|
|
import com.fs.qwApi.param.QwEditUserTagParam;
|
|
import com.fs.qwApi.param.QwEditUserTagParam;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
import com.fs.tag.domain.FsTagUpdateQueue;
|
|
import com.fs.tag.domain.FsTagUpdateQueue;
|
|
|
|
|
+import com.fs.tag.domain.FsVideoCourseTag;
|
|
|
import com.fs.tag.mapper.FsTagUpdateQueueMapper;
|
|
import com.fs.tag.mapper.FsTagUpdateQueueMapper;
|
|
|
|
|
+import com.fs.tag.mapper.FsVideoCourseTagMapper;
|
|
|
import com.fs.tag.service.FsTagUpdateService;
|
|
import com.fs.tag.service.FsTagUpdateService;
|
|
|
import com.google.common.util.concurrent.RateLimiter;
|
|
import com.google.common.util.concurrent.RateLimiter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -65,17 +68,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
private QwApiService qwApiService;
|
|
private QwApiService qwApiService;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private QwTagMapper qwTagMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private QwTagGroupMapper qwTagGroupMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IQwTagGroupService qwTagGroupService;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private FsUserCourseMapper fsUserCourseMapper;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private FsVideoCourseTagMapper fsVideoCourseTagMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
|
|
|
|
|
@@ -84,10 +77,6 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
|
|
|
|
|
@Value("${tag.rate.limit:30}")
|
|
@Value("${tag.rate.limit:30}")
|
|
|
private Integer RATE_LIMIT_NUM;
|
|
private Integer RATE_LIMIT_NUM;
|
|
|
- /**
|
|
|
|
|
- * 标签组最大数量
|
|
|
|
|
- */
|
|
|
|
|
- private static final Integer TAG_MAX_NUM = 100;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 接口限流
|
|
* 接口限流
|
|
@@ -97,7 +86,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
/**
|
|
/**
|
|
|
* 看课自动打标签开关
|
|
* 看课自动打标签开关
|
|
|
*/
|
|
*/
|
|
|
- @Value("${qw.enableAutoTag:0}")
|
|
|
|
|
|
|
+ @Value("${qw.enableAutoTag:1}")
|
|
|
private Integer enableAutoTag;
|
|
private Integer enableAutoTag;
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
@@ -115,6 +104,8 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
Map<Long, FsUserCourseVideo> courseVideoMap = fsUserCourseVideoMapper.selectAllMap();
|
|
Map<Long, FsUserCourseVideo> courseVideoMap = fsUserCourseVideoMapper.selectAllMap();
|
|
|
// 用户(这里用户用的是企微外部联系人ID)+videoId+status 唯一
|
|
// 用户(这里用户用的是企微外部联系人ID)+videoId+status 唯一
|
|
|
|
|
|
|
|
|
|
+ Map<String, FsVideoCourseTag> fsVideoCourseTagMap = fsVideoCourseTagMapper.selectAll();
|
|
|
|
|
+
|
|
|
// 先导课看课记录
|
|
// 先导课看课记录
|
|
|
List<FsTagUpdateQueue> batchData = new ArrayList<>();
|
|
List<FsTagUpdateQueue> batchData = new ArrayList<>();
|
|
|
for (FsCourseWatchLog item : logs) {
|
|
for (FsCourseWatchLog item : logs) {
|
|
@@ -122,8 +113,6 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
task.setCourseId(item.getCourseId());
|
|
task.setCourseId(item.getCourseId());
|
|
|
task.setVideoId(item.getVideoId());
|
|
task.setVideoId(item.getVideoId());
|
|
|
task.setCourseLogId(item.getLogId());
|
|
task.setCourseLogId(item.getLogId());
|
|
|
- task.setTagId(null);
|
|
|
|
|
- task.setTagName(null);
|
|
|
|
|
|
|
|
|
|
task.setLogType(0);
|
|
task.setLogType(0);
|
|
|
task.setOperationType(0);
|
|
task.setOperationType(0);
|
|
@@ -150,12 +139,31 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
batchData.add(task);
|
|
batchData.add(task);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- task.setTagGroupId(fsUserCourseVideo.getTagGroupId());
|
|
|
|
|
- task.setTgId(fsUserCourseVideo.getTgId());
|
|
|
|
|
- task.setWatchingTagId(fsUserCourseVideo.getWatchingTagId());
|
|
|
|
|
- task.setWatchedTagId(fsUserCourseVideo.getWatchedTagId());
|
|
|
|
|
- task.setWatchingTgId(fsUserCourseVideo.getWatchingTgId());
|
|
|
|
|
- task.setWatchedTgId(fsUserCourseVideo.getWatchedTgId());
|
|
|
|
|
|
|
+ String compositeKey = String.format("%s_%s", corpId, fsUserCourseVideo.getVideoId());
|
|
|
|
|
+
|
|
|
|
|
+ FsVideoCourseTag fsVideoCourseTag = fsVideoCourseTagMap.get(compositeKey);
|
|
|
|
|
+ if(ObjectUtil.isNull(fsVideoCourseTag)) {
|
|
|
|
|
+ log.info("{},对应记录不存在!",compositeKey);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 看课中-标签ID(表中的)
|
|
|
|
|
+ task.setWatchingTgId(fsVideoCourseTag.getWatchingTgId());
|
|
|
|
|
+ // 看课中-标签组ID(表中的)
|
|
|
|
|
+ task.setWatchingGroupId(fsVideoCourseTag.getWatchingGroupId());
|
|
|
|
|
+ // 完课-标签组ID(表中的)
|
|
|
|
|
+ task.setWatchedGroupId(fsVideoCourseTag.getWatchedGroupId());
|
|
|
|
|
+ // 完课-完课ID(表中的)
|
|
|
|
|
+ task.setWatchedTgId(fsVideoCourseTag.getWatchedTgId());
|
|
|
|
|
+
|
|
|
|
|
+ // 看课中-标签ID(企微)
|
|
|
|
|
+ task.setWatchingTagId(fsVideoCourseTag.getWatchingTagId());
|
|
|
|
|
+ // 看课中-标签组ID(企微)
|
|
|
|
|
+ task.setWatchingTgGroupId(fsVideoCourseTag.getWatchingGroupTgId());
|
|
|
|
|
+
|
|
|
|
|
+ // 完课-完课标签ID(企微)
|
|
|
|
|
+ task.setWatchedTagId(fsVideoCourseTag.getWatchedTagId());
|
|
|
|
|
+ // 完课-标签组ID(企微)
|
|
|
|
|
+ task.setWatchedTgGroupId(fsVideoCourseTag.getWatchedGroupTgId());
|
|
|
|
|
|
|
|
if(ObjectUtil.equal(fsUserCourseVideo.getIsFirst(),1)) {
|
|
if(ObjectUtil.equal(fsUserCourseVideo.getIsFirst(),1)) {
|
|
|
task.setIsFirst(1);
|
|
task.setIsFirst(1);
|
|
@@ -178,6 +186,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
Map<Long, FsUserCourseVideo> courseVideoMap = fsUserCourseVideoMapper.selectAllMap();
|
|
Map<Long, FsUserCourseVideo> courseVideoMap = fsUserCourseVideoMapper.selectAllMap();
|
|
|
|
|
+ Map<String, FsVideoCourseTag> fsVideoCourseTagMap = fsVideoCourseTagMapper.selectAll();
|
|
|
|
|
|
|
|
// 先导课看课记录
|
|
// 先导课看课记录
|
|
|
List<FsTagUpdateQueue> batchData = new ArrayList<>();
|
|
List<FsTagUpdateQueue> batchData = new ArrayList<>();
|
|
@@ -186,8 +195,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
task.setCourseId(item.getCourseId());
|
|
task.setCourseId(item.getCourseId());
|
|
|
task.setVideoId(item.getVideoId());
|
|
task.setVideoId(item.getVideoId());
|
|
|
task.setCourseLogId(item.getLogId());
|
|
task.setCourseLogId(item.getLogId());
|
|
|
- task.setTagId(null);
|
|
|
|
|
- task.setTagName(null);
|
|
|
|
|
|
|
+
|
|
|
task.setOperationType(0);
|
|
task.setOperationType(0);
|
|
|
task.setStatus(0);
|
|
task.setStatus(0);
|
|
|
task.setRetryCount(0);
|
|
task.setRetryCount(0);
|
|
@@ -213,12 +221,31 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
batchData.add(task);
|
|
batchData.add(task);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- task.setTagGroupId(fsUserCourseVideo.getTagGroupId());
|
|
|
|
|
- task.setTgId(fsUserCourseVideo.getTgId());
|
|
|
|
|
- task.setWatchingTagId(fsUserCourseVideo.getWatchingTagId());
|
|
|
|
|
- task.setWatchedTagId(fsUserCourseVideo.getWatchedTagId());
|
|
|
|
|
- task.setWatchingTgId(fsUserCourseVideo.getWatchingTgId());
|
|
|
|
|
- task.setWatchedTgId(fsUserCourseVideo.getWatchedTgId());
|
|
|
|
|
|
|
+ String compositeKey = String.format("%s_%s", corpId, fsUserCourseVideo.getVideoId());
|
|
|
|
|
+
|
|
|
|
|
+ FsVideoCourseTag fsVideoCourseTag = fsVideoCourseTagMap.get(compositeKey);
|
|
|
|
|
+ if(ObjectUtil.isNull(fsVideoCourseTag)) {
|
|
|
|
|
+ log.info("{},对应记录不存在!",compositeKey);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 看课中-标签ID(表中的)
|
|
|
|
|
+ task.setWatchingTgId(fsVideoCourseTag.getWatchingTgId());
|
|
|
|
|
+ // 看课中-标签组ID(表中的)
|
|
|
|
|
+ task.setWatchingGroupId(fsVideoCourseTag.getWatchingGroupId());
|
|
|
|
|
+ // 完课-标签组ID(表中的)
|
|
|
|
|
+ task.setWatchedGroupId(fsVideoCourseTag.getWatchedGroupId());
|
|
|
|
|
+ // 完课-完课ID(表中的)
|
|
|
|
|
+ task.setWatchedTgId(fsVideoCourseTag.getWatchedTgId());
|
|
|
|
|
+
|
|
|
|
|
+ // 看课中-标签ID(企微)
|
|
|
|
|
+ task.setWatchingTagId(fsVideoCourseTag.getWatchingTagId());
|
|
|
|
|
+ // 看课中-标签组ID(企微)
|
|
|
|
|
+ task.setWatchingTgGroupId(fsVideoCourseTag.getWatchingGroupTgId());
|
|
|
|
|
+
|
|
|
|
|
+ // 完课-完课标签ID(企微)
|
|
|
|
|
+ task.setWatchedTagId(fsVideoCourseTag.getWatchedTagId());
|
|
|
|
|
+ // 完课-标签组ID(企微)
|
|
|
|
|
+ task.setWatchedTgGroupId(fsVideoCourseTag.getWatchedGroupTgId());
|
|
|
|
|
|
|
|
if(ObjectUtil.equal(fsUserCourseVideo.getIsFirst(),1)) {
|
|
if(ObjectUtil.equal(fsUserCourseVideo.getIsFirst(),1)) {
|
|
|
task.setIsFirst(1);
|
|
task.setIsFirst(1);
|
|
@@ -236,7 +263,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
@Override
|
|
@Override
|
|
|
public void handleData() {
|
|
public void handleData() {
|
|
|
List<FsTagUpdateQueue> tasks = fsTagUpdateQueueMapper.selectPending();
|
|
List<FsTagUpdateQueue> tasks = fsTagUpdateQueueMapper.selectPending();
|
|
|
- if(CollectionUtils.isEmpty(tasks)){
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(tasks)) {
|
|
|
log.info("找不到可处理的任务,已跳过!");
|
|
log.info("找不到可处理的任务,已跳过!");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -276,7 +303,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
Thread.currentThread().interrupt();
|
|
Thread.currentThread().interrupt();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(CollectionUtils.isNotEmpty(tasks)){
|
|
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(tasks)) {
|
|
|
fsTagUpdateQueueMapper.batchUpdateSelective(tasks);
|
|
fsTagUpdateQueueMapper.batchUpdateSelective(tasks);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -288,7 +315,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
QwEditUserTagParam qwEditUserTagParam = new QwEditUserTagParam();
|
|
QwEditUserTagParam qwEditUserTagParam = new QwEditUserTagParam();
|
|
|
QwExternalContact qwExternalContact = qwExternalContactMapper
|
|
QwExternalContact qwExternalContact = qwExternalContactMapper
|
|
|
.selectQwExternalContactById(fsTagUpdateQueue.getQwExternalContactId());
|
|
.selectQwExternalContactById(fsTagUpdateQueue.getQwExternalContactId());
|
|
|
- if(qwExternalContact == null) {
|
|
|
|
|
|
|
+ if (qwExternalContact == null) {
|
|
|
throw new IllegalArgumentException(String.format("企微外部联系人 %s 未找到!", fsTagUpdateQueue.getQwExternalContactId()));
|
|
throw new IllegalArgumentException(String.format("企微外部联系人 %s 未找到!", fsTagUpdateQueue.getQwExternalContactId()));
|
|
|
}
|
|
}
|
|
|
qwEditUserTagParam.setUserid(qwExternalContact.getUserId());
|
|
qwEditUserTagParam.setUserid(qwExternalContact.getUserId());
|
|
@@ -297,7 +324,7 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
rateLimiter.acquire();
|
|
rateLimiter.acquire();
|
|
|
|
|
|
|
|
// 如果是看课中
|
|
// 如果是看课中
|
|
|
- if(ObjectUtil.equal(fsTagUpdateQueue.getLogType(),0)){
|
|
|
|
|
|
|
+ if (ObjectUtil.equal(fsTagUpdateQueue.getLogType(), 0)) {
|
|
|
qwEditUserTagParam.setAdd_tag(Collections.singletonList(fsTagUpdateQueue.getWatchingTagId()));
|
|
qwEditUserTagParam.setAdd_tag(Collections.singletonList(fsTagUpdateQueue.getWatchingTagId()));
|
|
|
} else {
|
|
} else {
|
|
|
// 已完课
|
|
// 已完课
|
|
@@ -305,19 +332,23 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
qwEditUserTagParam.setRemove_tag(Collections.singletonList(fsTagUpdateQueue.getWatchingTagId()));
|
|
qwEditUserTagParam.setRemove_tag(Collections.singletonList(fsTagUpdateQueue.getWatchingTagId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (ObjectUtil.isNull(fsTagUpdateQueue.getCorpId())) {
|
|
|
|
|
+ throw new IllegalArgumentException("corpId为空!请检查一下");
|
|
|
|
|
+ }
|
|
|
QwResult qwResult = qwApiService.editUserTag(qwEditUserTagParam, fsTagUpdateQueue.getCorpId());
|
|
QwResult qwResult = qwApiService.editUserTag(qwEditUserTagParam, fsTagUpdateQueue.getCorpId());
|
|
|
|
|
+ log.info("返回结果: {}", JSON.toJSONString(qwResult));
|
|
|
fsTagUpdateQueue.setPayload(JSON.toJSONString(qwEditUserTagParam));
|
|
fsTagUpdateQueue.setPayload(JSON.toJSONString(qwEditUserTagParam));
|
|
|
fsTagUpdateQueue.setResponse(JSON.toJSONString(qwResult));
|
|
fsTagUpdateQueue.setResponse(JSON.toJSONString(qwResult));
|
|
|
// 打标签成功
|
|
// 打标签成功
|
|
|
- if(ObjectUtil.equal(qwResult.getErrcode(),0)) {
|
|
|
|
|
|
|
+ if (ObjectUtil.equal(qwResult.getErrcode(), 0)) {
|
|
|
fsTagUpdateQueue.setStatus(2);
|
|
fsTagUpdateQueue.setStatus(2);
|
|
|
- fsTagUpdateQueue.setRetryCount(0);
|
|
|
|
|
|
|
+ fsTagUpdateQueue.setFailMsg("");
|
|
|
} else {
|
|
} else {
|
|
|
throw new RuntimeException(String.format("打标签失败 原因: %s", JSON.toJSONString(qwResult)));
|
|
throw new RuntimeException(String.format("打标签失败 原因: %s", JSON.toJSONString(qwResult)));
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
fsTagUpdateQueue.setStatus(3);
|
|
fsTagUpdateQueue.setStatus(3);
|
|
|
- fsTagUpdateQueue.setRetryCount(fsTagUpdateQueue.getRetryCount()+1);
|
|
|
|
|
|
|
+ fsTagUpdateQueue.setRetryCount(fsTagUpdateQueue.getRetryCount() + 1);
|
|
|
fsTagUpdateQueue.setFailMsg(ExceptionUtils.getFullStackTrace(e));
|
|
fsTagUpdateQueue.setFailMsg(ExceptionUtils.getFullStackTrace(e));
|
|
|
fsTagUpdateQueue.setNextExecuteTime(LocalDateTime.now().plusHours(1));
|
|
fsTagUpdateQueue.setNextExecuteTime(LocalDateTime.now().plusHours(1));
|
|
|
}
|
|
}
|