Browse Source

feat: 企微完课打标签

xdd 4 days ago
parent
commit
7438b82a62

+ 10 - 0
fs-company/src/main/java/com/fs/company/controller/course/FsUserCourseVideoController.java

@@ -86,7 +86,17 @@ public class FsUserCourseVideoController extends BaseController
         }
         return toAjax(fsUserCourseVideoService.insertFsUserCourseVideo(fsUserCourseVideo));
     }
+    /**
+     * 更新课堂视频
+     */
+    @PreAuthorize("@ss.hasPermi('course:userCourseVideo:update')")
+    @Log(title = "更新课堂视频", businessType = BusinessType.UPDATE)
+    @PostMapping("/update")
+    public AjaxResult update(@RequestBody FsUserCourseVideo fsUserCourseVideo)
+    {
 
+        return toAjax(fsUserCourseVideoService.updateFsUserCourseVideo(fsUserCourseVideo));
+    }
     /**
      * 修改课堂视频
      */

+ 26 - 0
fs-service/src/main/java/com/fs/course/domain/FsUserCourseVideo.java

@@ -113,4 +113,30 @@ public class FsUserCourseVideo extends BaseEntity
     private Long listingEndTime;//商品结束售卖时间
 
 
+    /**
+     * 看课中标签ID
+     */
+    private String watchingTagId;
+    /**
+     * 完课标签ID
+     */
+    private String watchedTagId;
+    /**
+     * 标签组ID
+     */
+    private String tagGroupId;
+
+    /**
+     * 标签组表中的ID
+     */
+    private Long tgId;
+    /**
+     * 看课标签 表中的ID
+     */
+    private Long watchingTgId;
+    /**
+     * 完课标签 表中的ID
+     */
+    private Long watchedTgId;
+
 }

+ 30 - 6
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -54,10 +54,7 @@ import com.fs.his.service.IFsUserWxService;
 import com.fs.his.utils.ConfigUtil;
 import com.fs.his.vo.OptionsVO;
 import com.fs.qw.domain.*;
-import com.fs.qw.mapper.QwExternalContactMapper;
-import com.fs.qw.mapper.QwGroupChatMapper;
-import com.fs.qw.mapper.QwGroupChatUserMapper;
-import com.fs.qw.mapper.QwUserMapper;
+import com.fs.qw.mapper.*;
 import com.fs.qw.param.FsUserCourseRedPageParam;
 import com.fs.qw.service.IQwCompanyService;
 import com.fs.qw.service.IQwExternalContactService;
@@ -256,7 +253,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 
     @Autowired
     private IFsUserIntegralLogsService iFsUserIntegralLogsService;
-
+    @Autowired
+    private QwTagGroupMapper qwTagGroupMapper;
+    @Autowired
+    private QwTagMapper qwTagMapper;
 
 
 
@@ -922,9 +922,33 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         return R.error(400,msg).put("qrcode",contactWay);
     }
 
+
     @Override
     public List<FsUserCourseVideoVO> selectFsUserCourseVideoListByCourseIdAndCompany(FsUserCourseVideoParam fsUserCourseVideo) {
-        return fsUserCourseVideoMapper.selectFsUserCourseVideoListByCourseIdAndCompany(fsUserCourseVideo);
+        List<FsUserCourseVideoVO> fsUserCourseVideoVOS = fsUserCourseVideoMapper.selectFsUserCourseVideoListByCourseIdAndCompany(fsUserCourseVideo);
+        for (FsUserCourseVideoVO item : fsUserCourseVideoVOS) {
+            if(ObjectUtils.isNotNull(item.getTgId())){
+                QwTagGroup qwTagGroup = qwTagGroupMapper.selectQwTagGroupById(item.getTgId());
+                if(ObjectUtils.isNotNull(qwTagGroup)){
+                    item.setTagGroupName(qwTagGroup.getName());
+                }
+            }
+
+            if(ObjectUtils.isNotNull(item.getWatchingTgId())){
+                QwTag qwTag = qwTagMapper.selectQwTagById(item.getWatchingTgId());
+                if(ObjectUtils.isNotNull(qwTag)){
+                    item.setWatchingTagName(qwTag.getName());
+                }
+            }
+
+            if(ObjectUtils.isNotNull(item.getWatchedTgId())) {
+                QwTag qwTag = qwTagMapper.selectQwTagById(item.getWatchedTgId());
+                if(ObjectUtils.isNotNull(qwTag)){
+                    item.setWatchedTagName(qwTag.getName());
+                }
+            }
+        }
+        return fsUserCourseVideoVOS;
     }
 
     @Override

+ 39 - 0
fs-service/src/main/java/com/fs/course/vo/FsUserCourseVideoVO.java

@@ -68,4 +68,43 @@ public class FsUserCourseVideoVO extends BaseEntity {
     private String redPacketMoney;
 
     private String companyRedPacketMoney;
+    /**
+     * 标签组表中的ID
+     */
+    private Long tgId;
+    /**
+     * 看课标签 表中的ID
+     */
+    private Long watchingTgId;
+    /**
+     * 完课标签 表中的ID
+     */
+    private Long watchedTgId;
+
+    /**
+     * 看课中标签ID
+     */
+    private String watchingTagId;
+    /**
+     * 完课标签ID
+     */
+    private String watchedTagId;
+    /**
+     * 标签组ID
+     */
+    private String tagGroupId;
+
+    /**
+     * 标签组名称
+     */
+    private String tagGroupName;
+    /**
+     * 看课标签
+     */
+    private String watchingTagName;
+    /**
+     * 完课标签
+     */
+    private String watchedTagName;
+
 }

+ 26 - 0
fs-service/src/main/java/com/fs/tag/domain/FsTagUpdateQueue.java

@@ -86,4 +86,30 @@ public class FsTagUpdateQueue {
      */
     private LocalDateTime nextExecuteTime;
 
+
+    /**
+     * 看课中标签ID
+     */
+    private String watchingTagId;
+    /**
+     * 完课标签ID
+     */
+    private String watchedTagId;
+    /**
+     * 标签组ID
+     */
+    private String tagGroupId;
+
+    /**
+     * 标签组表中的ID
+     */
+    private Long tgId;
+    /**
+     * 看课标签 表中的ID
+     */
+    private Long watchingTgId;
+    /**
+     * 完课标签 表中的ID
+     */
+    private Long watchedTgId;
 }

+ 3 - 2
fs-service/src/main/java/com/fs/tag/mapper/FsTagUpdateQueueMapper.java

@@ -87,12 +87,13 @@ public interface FsTagUpdateQueueMapper {
     @Insert("<script>" +
             "INSERT IGNORE INTO fs_tag_update_queue (" +
             "course_log_id, is_first, course_id, tag_id, tag_name, operation_type, video_id, status, retry_count, " +
-            "corp_id, qw_user_id, qw_external_contact_id, fail_msg, payload, response, create_time, update_time, update_by, create_by, log_type" +
+            "corp_id, qw_user_id, qw_external_contact_id, fail_msg, payload, response, create_time, update_time, update_by, create_by, log_type,tg_id,watching_tg_id,watched_tg_id,watching_tag_id,watched_tag_id,tag_group_id" +
             ") VALUES " +
             "<foreach collection='list' item='item' separator=','>" +
             "(" +
             "#{item.courseLogId}, #{item.isFirst}, #{item.courseId}, #{item.tagId}, #{item.tagName}, #{item.operationType}, #{item.videoId}, #{item.status}, #{item.retryCount}, " +
-            "#{item.corpId}, #{item.qwUserId}, #{item.qwExternalContactId}, #{item.failMsg}, #{item.payload}, #{item.response}, #{item.createTime}, #{item.updateTime}, #{item.updateBy}, #{item.createBy}, #{item.logType}" +
+            "#{item.corpId}, #{item.qwUserId}, #{item.qwExternalContactId}, #{item.failMsg}, #{item.payload}, #{item.response}, #{item.createTime}," +
+            " #{item.updateTime}, #{item.updateBy}, #{item.createBy}, #{item.logType},#{item.tgId},#{item.watchingTgId},#{item.watchedTgId},#{item.watchingTagId},#{item.watchedTagId},#{item.tagGroupId}" +
             ")" +
             "</foreach>" +
             "</script>")

+ 17 - 162
fs-service/src/main/java/com/fs/tag/service/impl/FsTagUpdateServiceImpl.java

@@ -132,11 +132,6 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
             task.setQwExternalContactId(item.getQwExternalContactId());
             task.setQwUserId(item.getQwUserId());
 
-            String corpId = qwUserCacheService.queryCorpIdByQwUserId(item.getQwUserId());
-            if(StringUtils.isNotNull(corpId)){
-                task.setCorpId(corpId);
-            }
-
             FsUserCourseVideo fsUserCourseVideo = courseVideoMap.get(task.getVideoId());
 
             if(ObjectUtils.isNull(fsUserCourseVideo)) {
@@ -148,6 +143,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 {
@@ -186,11 +188,6 @@ public class FsTagUpdateServiceImpl implements FsTagUpdateService {
             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 +198,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 +269,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 +283,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 +308,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;
-    }
 }

+ 6 - 0
fs-service/src/main/resources/mapper/course/FsUserCourseVideoMapper.xml

@@ -233,6 +233,12 @@
             <if test="listingEndTime != null">listing_end_time = #{listingEndTime},</if>
             <if test="projectId != null">project_id = #{projectId},</if>
             <if test="isFirst != null">is_first = #{isFirst},</if>
+            <if test="tagGroupId != null">tag_group_id = #{tagGroupId},</if>
+            <if test="watchingTagId != null">watching_tag_id = #{watchingTagId},</if>
+            <if test="watchedTagId != null">watched_tag_id = #{watchedTagId},</if>
+            <if test="tgId != null">tg_id = #{tgId},</if>
+            <if test="watchingTgId != null">watching_tg_id = #{watchingTgId},</if>
+            <if test="watchedTgId != null">watched_tg_id = #{watchedTgId},</if>
         </trim>
         where video_id = #{videoId}
     </update>