|
|
@@ -132,13 +132,11 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
task.setQwExternalContactId(item.getQwExternalContactId());
|
|
|
task.setQwUserId(item.getQwUserId());
|
|
|
|
|
|
+ FsUserCourseVideo fsUserCourseVideo = courseVideoMap.get(task.getVideoId());
|
|
|
String corpId = qwUserCacheService.queryCorpIdByQwUserId(item.getQwUserId());
|
|
|
if(StringUtils.isNotNull(corpId)){
|
|
|
task.setCorpId(corpId);
|
|
|
}
|
|
|
-
|
|
|
- FsUserCourseVideo fsUserCourseVideo = courseVideoMap.get(task.getVideoId());
|
|
|
-
|
|
|
if(ObjectUtils.isNull(fsUserCourseVideo)) {
|
|
|
String errorMsg = String.format("该条记录 %d 找不到对应的课堂视频", task.getVideoId());
|
|
|
log.error(errorMsg);
|
|
|
@@ -148,6 +146,13 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
batchData.add(task);
|
|
|
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());
|
|
|
+
|
|
|
if(ObjectUtil.equal(fsUserCourseVideo.getIsFirst(),1)) {
|
|
|
task.setIsFirst(1);
|
|
|
} else {
|
|
|
@@ -185,12 +190,10 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
task.setQwExternalContactId(item.getQwExternalContactId());
|
|
|
task.setQwUserId(item.getQwUserId());
|
|
|
task.setLogType(1);
|
|
|
-
|
|
|
String corpId = qwUserCacheService.queryCorpIdByQwUserId(item.getQwUserId());
|
|
|
if(StringUtils.isNotNull(corpId)){
|
|
|
task.setCorpId(corpId);
|
|
|
}
|
|
|
-
|
|
|
FsUserCourseVideo fsUserCourseVideo = courseVideoMap.get(task.getVideoId());
|
|
|
if(ObjectUtils.isNull(fsUserCourseVideo)) {
|
|
|
String errorMsg = String.format("该条记录 %d 找不到对应的课堂视频", task.getVideoId());
|
|
|
@@ -201,6 +204,13 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
batchData.add(task);
|
|
|
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());
|
|
|
+
|
|
|
if(ObjectUtil.equal(fsUserCourseVideo.getIsFirst(),1)) {
|
|
|
task.setIsFirst(1);
|
|
|
} else {
|
|
|
@@ -265,63 +275,6 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
|
|
|
private void processSingleTask(FsTagUpdateQueue fsTagUpdateQueue) {
|
|
|
try {
|
|
|
- String courseName = getCourseName(fsTagUpdateQueue.getCourseId());
|
|
|
- String tagGroupName = String.format("%s-看课标签组(自动创建)",courseName);
|
|
|
- String tagName01 = String.format("%d上", fsTagUpdateQueue.getVideoId());
|
|
|
- String tagName02 = String.format("%d完", fsTagUpdateQueue.getVideoId());
|
|
|
- String corpId = fsTagUpdateQueue.getCorpId();
|
|
|
-
|
|
|
- // 是否存在该标签
|
|
|
- QwTagVO qwTagVO = qwTagMapper.selectQwTagByName(tagName01, corpId);
|
|
|
- if(ObjectUtil.isNull(qwTagVO)){
|
|
|
- // 是否存在标签组
|
|
|
- QwTagGroup qwTagGroup = qwTagGroupMapper.selectQwTagGroupByName(tagGroupName, corpId);
|
|
|
- // 创建标签组 & 标签
|
|
|
- if(ObjectUtil.isNull(qwTagGroup)) {
|
|
|
- log.info("当前标签组不存在 建标签组 & 标签");
|
|
|
- QwTagGroupAddParam qwTagGroupAddParam = buildQwTagGroupAndTags(tagGroupName, fsTagUpdateQueue);
|
|
|
- qwTagGroupService.insertQwTagGroupParam(qwTagGroupAddParam);
|
|
|
-
|
|
|
- } else {
|
|
|
- // 这个标签组满了吗?
|
|
|
- List<QwTagVO> qwTags = getQwTags(qwTagGroup);
|
|
|
- // 如果满了,找下一个标签
|
|
|
- if(CollectionUtils.isNotEmpty(qwTags) && qwTags.size() >= TAG_MAX_NUM){
|
|
|
- log.info("标签组1 {}满了,查找标签组2",tagGroupName);
|
|
|
- tagGroupName = String.format("%s-看课标签组2(自动创建)",courseName);
|
|
|
- qwTagGroup = qwTagGroupMapper.selectQwTagGroupByName(tagGroupName, corpId);
|
|
|
- // 判断是否满了
|
|
|
- if(ObjectUtil.isNotNull(qwTagGroup)) {
|
|
|
- List<QwTagVO> qwTags1 = getQwTags(qwTagGroup);
|
|
|
- if(CollectionUtils.isNotEmpty(qwTags1) && qwTags1.size() >= TAG_MAX_NUM){
|
|
|
- log.info("标签组2 {} 满了,查找标签组3",courseName);
|
|
|
- tagGroupName = String.format("%s-看课标签组3(自动创建)",courseName);
|
|
|
- qwTagGroup = qwTagGroupMapper.selectQwTagGroupByName(tagGroupName, corpId);
|
|
|
- List<QwTagVO> qwTags2 = getQwTags(qwTagGroup);
|
|
|
- if(CollectionUtils.isNotEmpty(qwTags2) && qwTags2.size() >= TAG_MAX_NUM){
|
|
|
- log.error("最大支持3个标签组! tagGroupName={}",tagGroupName);
|
|
|
- throw new UnsupportedOperationException("最大支持分成3个组!");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 创建标签
|
|
|
- log.info("当前标签 {}、{} 在标签组 {}不存在,正在创建标签",tagName01,tagName02,qwTagGroup);
|
|
|
- createNotExistLabel(fsTagUpdateQueue, qwTagGroup, tagName01, tagName02);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- QwTagVO qwTagVO1 = qwTagMapper.selectQwTagByName(tagName01, corpId);
|
|
|
- QwTagVO qwTagVO2 = qwTagMapper.selectQwTagByName(tagName02, corpId);
|
|
|
-
|
|
|
- if(ObjectUtil.isNull(qwTagVO1)){
|
|
|
- throw new IllegalArgumentException(String.format("标签 %s-%s 未添加成功!",tagName01,corpId));
|
|
|
- }
|
|
|
- if(ObjectUtil.isNull(qwTagVO2)){
|
|
|
- throw new IllegalArgumentException(String.format("标签 %s-%s 未添加成功!",tagName02,corpId));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
// 调用企微API更新标签
|
|
|
QwEditUserTagParam qwEditUserTagParam = new QwEditUserTagParam();
|
|
|
QwExternalContact qwExternalContact = qwExternalContactMapper
|
|
|
@@ -336,17 +289,16 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
|
|
|
// 如果是看课中
|
|
|
if(ObjectUtil.equal(fsTagUpdateQueue.getLogType(),0)){
|
|
|
- qwEditUserTagParam.setAdd_tag(Collections.singletonList(qwTagVO1.getTagId()));
|
|
|
+ qwEditUserTagParam.setAdd_tag(Collections.singletonList(fsTagUpdateQueue.getWatchingTagId()));
|
|
|
} else {
|
|
|
// 已完课
|
|
|
- qwEditUserTagParam.setAdd_tag(Collections.singletonList(qwTagVO2.getTagId()));
|
|
|
+ qwEditUserTagParam.setAdd_tag(Collections.singletonList(fsTagUpdateQueue.getWatchedTagId()));
|
|
|
+ qwEditUserTagParam.setRemove_tag(Collections.singletonList(fsTagUpdateQueue.getWatchingTagId()));
|
|
|
}
|
|
|
|
|
|
QwResult qwResult = qwApiService.editUserTag(qwEditUserTagParam, fsTagUpdateQueue.getCorpId());
|
|
|
fsTagUpdateQueue.setPayload(JSON.toJSONString(qwEditUserTagParam));
|
|
|
fsTagUpdateQueue.setResponse(JSON.toJSONString(qwResult));
|
|
|
- fsTagUpdateQueue.setTagName(tagGroupName);
|
|
|
- fsTagUpdateQueue.setTagId(qwTagVO1.getGroupId());
|
|
|
// 打标签成功
|
|
|
if(ObjectUtil.equal(qwResult.getErrcode(),0)) {
|
|
|
fsTagUpdateQueue.setStatus(2);
|
|
|
@@ -362,96 +314,5 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void createNotExistLabel(FsTagUpdateQueue fsTagUpdateQueue, QwTagGroup qwTagGroup, String tagName01, String tagName02) {
|
|
|
- QwAddTagParam qwAddTagParam = buildQwTagGroupAndTags(qwTagGroup, tagName01, tagName02);
|
|
|
- QwAddTagResult qwAddTagResult = qwApiService.addTag(qwAddTagParam, fsTagUpdateQueue.getCorpId());
|
|
|
- if(ObjectUtil.equal(qwAddTagResult.getErrcode(),0)){
|
|
|
- List<InTag> addTag = qwAddTagResult.getTag_group().getTag();
|
|
|
- if (CollectionUtils.isNotEmpty(addTag)) {
|
|
|
- for (InTag inTag : addTag) {
|
|
|
- QwTag addQwTag = new QwTag();
|
|
|
- addQwTag.setGroupId(qwTagGroup.getGroupId());
|
|
|
- addQwTag.setTagId(inTag.getId());
|
|
|
- addQwTag.setOrder(inTag.getOrder());
|
|
|
- addQwTag.setName(inTag.getName());
|
|
|
- addQwTag.setCorpId(qwTagGroup.getCorpId());
|
|
|
- addQwTag.setCreateTime(new Date(inTag.getCreate_time()));
|
|
|
- addQwTag.setTagFrom(1);
|
|
|
- qwTagMapper.insertQwTag(addQwTag);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("创建标签完成 {}",JSON.toJSON(qwAddTagResult));
|
|
|
- } else {
|
|
|
- throw new RuntimeException(String.format("创建标签失败!%s",JSON.toJSONString(qwAddTagResult)));
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private List<QwTagVO> getQwTags(QwTagGroup qwTagGroup) {
|
|
|
- QwTag qwTag = new QwTag();
|
|
|
- qwTag.setGroupId(qwTagGroup.getGroupId());
|
|
|
- qwTag.setCompanyId(qwTagGroup.getCompanyId());
|
|
|
- List<QwTagVO> qwTags = qwTagMapper.selectQwTagListVO(qwTag);
|
|
|
- return qwTags;
|
|
|
- }
|
|
|
-
|
|
|
- private QwAddTagParam buildQwTagGroupAndTags(QwTagGroup qwTagGroup, String tagName01, String tagName02) {
|
|
|
- QwAddTagParam qwTagGroupAddParam = new QwAddTagParam();
|
|
|
- qwTagGroupAddParam.setGroup_name(qwTagGroup.getName());
|
|
|
- qwTagGroupAddParam.setOrder(qwTagGroup.getOrder());
|
|
|
- qwTagGroupAddParam.setStrategy_id(1);
|
|
|
- qwTagGroupAddParam.setGroup_id(qwTagGroup.getGroupId());
|
|
|
- List<TagData> tags = new ArrayList<>();
|
|
|
-
|
|
|
- TagData qwTag1 = new TagData();
|
|
|
- qwTag1.setName(tagName01);
|
|
|
- qwTag1.setOrder(0);
|
|
|
- tags.add(qwTag1);
|
|
|
-
|
|
|
- TagData qwTag2 = new TagData();
|
|
|
- qwTag2.setName(tagName02);
|
|
|
- qwTag2.setOrder(0);
|
|
|
- tags.add(qwTag2);
|
|
|
-
|
|
|
- qwTagGroupAddParam.setTag(tags);
|
|
|
-
|
|
|
- return qwTagGroupAddParam;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private QwTagGroupAddParam buildQwTagGroupAndTags(String tagGroupName, FsTagUpdateQueue fsTagUpdateQueue) {
|
|
|
- QwTagGroupAddParam qwTagGroupAddParam = new QwTagGroupAddParam();
|
|
|
- qwTagGroupAddParam.setCorpId(fsTagUpdateQueue.getCorpId());
|
|
|
- qwTagGroupAddParam.setName(tagGroupName);
|
|
|
- qwTagGroupAddParam.setOrder(0);
|
|
|
-
|
|
|
-
|
|
|
- List<QwTag> tags = new ArrayList<>();
|
|
|
- QwTag qwTag = new QwTag();
|
|
|
- qwTag.setName(String.format("%d上",fsTagUpdateQueue.getVideoId()));
|
|
|
- qwTag.setTagFrom(1);
|
|
|
- qwTag.setOrder(0);
|
|
|
- tags.add(qwTag);
|
|
|
-
|
|
|
- QwTag qwTagFinish = new QwTag();
|
|
|
- qwTagFinish.setName(String.format("%d完",fsTagUpdateQueue.getVideoId()));
|
|
|
- qwTagFinish.setTagFrom(1);
|
|
|
- qwTagFinish.setOrder(0);
|
|
|
- tags.add(qwTagFinish);
|
|
|
-
|
|
|
- qwTagGroupAddParam.setTag(tags);
|
|
|
- return qwTagGroupAddParam;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取课程名称
|
|
|
- * @param courseId 课程id
|
|
|
- * @return 课程名称
|
|
|
- */
|
|
|
- private String getCourseName(Long courseId){
|
|
|
- FsUserCourse course = fsUserCourseMapper.selectFsUserCourseByCourseId(courseId);
|
|
|
- if(ObjectUtil.isNotNull(course)){
|
|
|
- return course.getCourseName();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
}
|