Browse Source

一键催课优化

wangxy 1 week ago
parent
commit
2182958b70

+ 13 - 0
fs-company-app/src/main/java/com/fs/app/controller/FsUserCourseVideoController.java

@@ -483,8 +483,21 @@ public class FsUserCourseVideoController extends AppBaseController {
     @ApiOperation("会员批量发送课程消息")
     @PostMapping("/batchUrgeCourseTaskCreate")
     public OpenImResponseDTO batchUrgeCourseTaskCreate(@RequestBody BatchUrgeCourseTaskDTO batchUrgeCourseTaskDTO) throws JsonProcessingException {
+        FsCourseLinkCreateParam createParam=new FsCourseLinkCreateParam();
+        BeanUtils.copyProperties(batchUrgeCourseTaskDTO, createParam);
+        R courseSortLink = fsUserCourseService.createAppCourseSortLink(createParam);
+        String url = courseSortLink.get("url").toString();
+        batchUrgeCourseTaskDTO.setUrl(url);
         return openIMService.batchUrgeCourseTaskCreate(batchUrgeCourseTaskDTO);
     }
 
+    @Login
+    @ApiOperation("统计销售当日指定催课任务类型次数")
+    @GetMapping("/countTodayUrgeCourseTask")
+        public ResponseResult<Integer> countTodayUrgeCourseTask(@RequestParam Integer taskType) {
+        Integer count = imMsgSendLogService.countTodayUrgeCourseTask(Long.parseLong(getUserId()), taskType);
+        return ResponseResult.ok(count);
+    }
+
 
 }

+ 3 - 0
fs-service/src/main/java/com/fs/course/dto/BatchSendCourseDTO.java

@@ -78,4 +78,7 @@ public class BatchSendCourseDTO implements Serializable {
 
     @ApiModelProperty(value = "催课内容")
     private String urgeContent;
+
+    @ApiModelProperty(value = "任务类型:1-未看课催课;2-未完课催课", required = true)
+    private Integer taskType;
 }

+ 4 - 0
fs-service/src/main/java/com/fs/im/domain/FsImMsgSendLog.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import com.fs.common.core.domain.BaseEntity;
 import lombok.EqualsAndHashCode;
@@ -103,4 +104,7 @@ public class FsImMsgSendLog extends BaseEntity{
     @Excel(name = "营期课程表id")
     private Long periodDaysId;
 
+    @Excel(name = "催课任务类型")
+    private Integer taskType;
+
 }

+ 9 - 0
fs-service/src/main/java/com/fs/im/mapper/FsImMsgSendLogMapper.java

@@ -72,4 +72,13 @@ public interface FsImMsgSendLogMapper extends BaseMapper<FsImMsgSendLog>{
 
     List<FsImMsgSendLog> selectSendLogListByDetailId(@Param("params") Map<String, Object> params);
 
+    /**
+     * 统计销售当日指定催课任务类型次数
+     *
+     * @param companyUserId 销售id
+     * @param taskType 催课任务类型:1-未看课催课;2-未完课催课
+     * @return 当日任务次数
+     */
+    int countTodayUrgeCourseTask(@Param("companyUserId") Long companyUserId, @Param("taskType") Integer taskType);
+
 }

+ 10 - 0
fs-service/src/main/java/com/fs/im/service/IFsImMsgSendLogService.java

@@ -91,4 +91,14 @@ public interface IFsImMsgSendLogService extends IService<FsImMsgSendLog>{
      */
     FsImMsgSendLogVO selectFsImMsgSendLogDetail(Long logId);
 
+    /**
+     * 统计销售当日指定催课任务类型次数
+     *
+     * @param companyUserId 销售id
+     * @param taskType 催课任务类型:1-未看课催课;2-未完课催课
+     * @return 当日任务次数
+     */
+    int countTodayUrgeCourseTask(Long companyUserId, Integer taskType);
+
+
 }

+ 5 - 0
fs-service/src/main/java/com/fs/im/service/impl/FsImMsgSendLogServiceImpl.java

@@ -190,4 +190,9 @@ public class FsImMsgSendLogServiceImpl extends ServiceImpl<FsImMsgSendLogMapper,
         fsImMsgSendLogVO.setDetailList(fsImMsgSendDetails);
         return fsImMsgSendLogVO;
     }
+
+    @Override
+    public int countTodayUrgeCourseTask(Long companyUserId, Integer taskType) {
+        return baseMapper.countTodayUrgeCourseTask(companyUserId, taskType);
+    }
 }

+ 65 - 27
fs-service/src/main/java/com/fs/im/service/impl/OpenIMServiceImpl.java

@@ -1347,7 +1347,6 @@ public class OpenIMServiceImpl implements OpenIMService {
     public OpenImResponseDTO batchUrgeCourseTaskCreate(BatchUrgeCourseTaskDTO batchUrgeCourseTaskDTO) throws JsonProcessingException {
         ObjectMapper objectMapper = new ObjectMapper();
         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
-
         Map<String, Object> param = new HashMap<>();
         param.put("companyUserId", batchUrgeCourseTaskDTO.getCompanyUserId());
         param.put("projectId", batchUrgeCourseTaskDTO.getProjectId());
@@ -1403,56 +1402,95 @@ public class OpenIMServiceImpl implements OpenIMService {
         if (CollectionUtils.isEmpty(userIds)) {
             throw new ServiceException("没有符合条件的催课用户");
         }
-
         BatchSendCourseDTO batchSendCourseDTO = new BatchSendCourseDTO();
         BeanUtils.copyProperties(batchUrgeCourseTaskDTO, batchSendCourseDTO);
         batchSendCourseDTO.setId(batchUrgeCourseTaskDTO.getPeriodDaysId());
         batchSendCourseDTO.setSendType(1);
         batchSendCourseDTO.setIsUrgeCourse(true);
         batchSendCourseDTO.setUrgeTime(batchUrgeCourseTaskDTO.getUrgeTime());
-        if (Boolean.TRUE.equals(batchUrgeCourseTaskDTO.getSendCourse())) {
-            batchSendCourseDTO.setTitle(batchUrgeCourseTaskDTO.getTitle());
-        } else {
-            batchSendCourseDTO.setTitle(batchUrgeCourseTaskDTO.getUrgeContent());
-        }
+        batchSendCourseDTO.setTitle(batchUrgeCourseTaskDTO.getTitle());
+        batchSendCourseDTO.setUrgeContent(batchUrgeCourseTaskDTO.getUrgeContent());
+
+        FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(batchUrgeCourseTaskDTO.getCourseId());
+        Long project = fsUserCourse != null ? fsUserCourse.getProject() : null;
+        String courseUrl = fsUserCourse != null ? fsUserCourse.getImgUrl() : null;
+        long planSendTimeStamp = batchUrgeCourseTaskDTO.getUrgeTime().getTime();
+        String sendUnionId = UUID.randomUUID().toString();
 
-        OpenImBatchMsgDTO openImBatchMsgDTO = makeOpenImBatchMsgDTO(
+        OpenImBatchMsgDTO urgeOpenImBatchMsgDTO = makeOpenImBatchMsgDTO(
                 batchSendCourseDTO,
-                null,
+                courseUrl,
                 objectMapper,
                 userIds,
-                batchUrgeCourseTaskDTO.getUrgeTime().getTime(),
+                planSendTimeStamp,
                 "催课"
         );
 
-        String sendUnionId = UUID.randomUUID().toString();
-        List<FsImMsgSendDetail> imMsgSendDetailList = createImMsgSendLog(
+        List<FsImMsgSendDetail> urgeImMsgSendDetailList = createImMsgSendLog(
                 "催课",
                 batchSendCourseDTO,
-                batchUrgeCourseTaskDTO.getUrgeTime().getTime(),
+                planSendTimeStamp,
                 1,
                 userIds,
                 sendUnionId
         );
 
-        String redisKey = "openIm:batchSendMsg:urgeCourse";
-        Map<String, Object> redisMap = redisCache.getCacheMap(redisKey);
-        if (redisMap == null) {
-            redisMap = new HashMap<>();
+        String urgeRedisKey = "openIm:batchSendMsg:urgeCourse";
+        Map<String, Object> urgeRedisMap = redisCache.getCacheMap(urgeRedisKey);
+        if (urgeRedisMap == null) {
+            urgeRedisMap = new HashMap<>();
         }
 
-        BatchSendCourseAllDTO batchSendCourseAllDTO = new BatchSendCourseAllDTO();
-        batchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO)
-                .setOpenImBatchMsgDTO(openImBatchMsgDTO)
-                .setImMsgSendDetailList(imMsgSendDetailList);
+        BatchSendCourseAllDTO urgeBatchSendCourseAllDTO = new BatchSendCourseAllDTO();
+        urgeBatchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO)
+                .setOpenImBatchMsgDTO(urgeOpenImBatchMsgDTO)
+                .setImMsgSendDetailList(urgeImMsgSendDetailList);
 
-        String batchKey = batchUrgeCourseTaskDTO.getCourseId() + ":"
-                + batchUrgeCourseTaskDTO.getVideoId() + ":"
-                + batchUrgeCourseTaskDTO.getUrgeTime().getTime() + ":"
-                + imMsgSendDetailList.get(0).getLogId();
-        redisMap.put(batchKey, batchSendCourseAllDTO);
-        redisCache.setCacheMap(redisKey, redisMap);
+        String urgeBatchKey = batchSendCourseDTO.getCourseId() + ":" +
+                batchSendCourseDTO.getVideoId() + ":" +
+                batchSendCourseDTO.getUrgeTime().getTime() + ":" +
+                urgeImMsgSendDetailList.get(0).getLogId();
+        urgeRedisMap.put(urgeBatchKey, urgeBatchSendCourseAllDTO);
+        redisCache.setCacheMap(urgeRedisKey, urgeRedisMap);
 
+        if (Boolean.TRUE.equals(batchUrgeCourseTaskDTO.getSendCourse())) {
+            OpenImBatchMsgDTO sendCourseOpenImBatchMsgDTO = makeOpenImBatchMsgDTO(
+                    batchSendCourseDTO,
+                    courseUrl,
+                    objectMapper,
+                    userIds,
+                    planSendTimeStamp,
+                    "发课"
+            );
+
+            List<FsImMsgSendDetail> sendCourseImMsgSendDetailList = createImMsgSendLog(
+                    "发课",
+                    batchSendCourseDTO,
+                    planSendTimeStamp,
+                    1,
+                    userIds,
+                    sendUnionId
+            );
+
+            String sendCourseRedisKey = "openIm:batchSendMsg:sendCourse";
+            Map<String, Object> sendCourseRedisMap = redisCache.getCacheMap(sendCourseRedisKey);
+            if (sendCourseRedisMap == null) {
+                sendCourseRedisMap = new HashMap<>();
+            }
+
+            BatchSendCourseAllDTO sendCourseBatchSendCourseAllDTO = new BatchSendCourseAllDTO();
+            sendCourseBatchSendCourseAllDTO.setBatchSendCourseDTO(batchSendCourseDTO)
+                    .setOpenImBatchMsgDTO(sendCourseOpenImBatchMsgDTO)
+                    .setProject(project)
+                    .setImMsgSendDetailList(sendCourseImMsgSendDetailList);
+
+            String sendCourseBatchKey = batchSendCourseDTO.getCourseId() + ":" +
+                    batchSendCourseDTO.getVideoId() + ":" +
+                    batchSendCourseDTO.getUrgeTime().getTime() + ":" +
+                    sendCourseImMsgSendDetailList.get(0).getLogId();
+            sendCourseRedisMap.put(sendCourseBatchKey, sendCourseBatchSendCourseAllDTO);
+            redisCache.setCacheMap(sendCourseRedisKey, sendCourseRedisMap);
+        }
         OpenImResponseDTO responseDTO = new OpenImResponseDTO();
         responseDTO.setErrCode(0);
         responseDTO.setErrMsg("催课任务创建成功,待消息发送");

+ 17 - 1
fs-service/src/main/resources/mapper/im/FsImMsgSendLogMapper.xml

@@ -28,11 +28,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="tagNames"    column="tag_names"    />
         <result property="projectId"    column="project_id"    />
         <result property="periodDaysId"    column="period_days_id"    />
+        <result property="taskType"    column="task_type"    />
     </resultMap>
 
     <sql id="selectFsImMsgSendLogVo">
         select log_id, company_user_id, company_id, course_id, course_name, video_id, video_name, period_id, send_title, plan_send_time, send_type, send_mode, send_status, is_urge_course, msg_type, create_time, create_by, update_time, send_union_id, tag_ids,
-               tag_names, project_id, period_days_id from fs_im_msg_send_log
+               tag_names, project_id, period_days_id, task_type from fs_im_msg_send_log
     </sql>
 
     <select id="selectFsImMsgSendLogList" parameterType="FsImMsgSendLog" resultMap="FsImMsgSendLogResult">
@@ -57,6 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="tagNames != null and tagNames != ''"> and tag_names = #{tagNames}</if>
             <if test="projectId != null and projectId != ''"> and project_id = #{projectId}</if>
             <if test="periodDaysId != null and periodDaysId != ''"> and period_days_id = #{periodDaysId}</if>
+            <if test="taskType != null"> and task_type = #{taskType}</if>
         </where>
     </select>
 
@@ -90,6 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="tagNames != null">tag_names,</if>
             <if test="projectId != null">project_id,</if>
             <if test="periodDaysId != null">period_days_id,</if>
+            <if test="taskType != null">task_type,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="companyUserId != null">#{companyUserId},</if>
@@ -114,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="tagNames != null">#{tagNames},</if>
             <if test="projectId != null">#{projectId},</if>
             <if test="periodDaysId != null">#{periodDaysId},</if>
+            <if test="taskType != null">#{taskType},</if>
          </trim>
     </insert>
 
@@ -142,6 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="tagNames != null">tag_names = #{tagNames},</if>
             <if test="projectId != null">project_id = #{projectId},</if>
             <if test="periodDaysId != null">period_days_id = #{periodDaysId},</if>
+            <if test="taskType != null">task_type = #{taskType},</if>
         </trim>
         where log_id = #{logId}
     </update>
@@ -209,4 +214,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
 
+    <select id="countTodayUrgeCourseTask" resultType="int">
+        SELECT COUNT(1)
+        FROM fs_im_msg_send_log
+        WHERE company_user_id = #{companyUserId}
+          AND msg_type = 2
+          AND is_urge_course = 1
+          AND task_type = #{taskType}
+          AND create_time &gt;= CURDATE()
+          AND create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
+    </select>
+
 </mapper>