ソースを参照

跳过sop任务

luolinsong 14 時間 前
コミット
a709032020

+ 15 - 0
fs-company/src/main/java/com/fs/company/controller/qw/QwSopController.java

@@ -1,5 +1,6 @@
 package com.fs.company.controller.qw;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.annotation.Log;
 import com.fs.common.annotation.RepeatSubmit;
@@ -16,6 +17,7 @@ import com.fs.course.mapper.FsUserCourseVideoMapper;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
 import com.fs.his.vo.OptionsVO;
+import com.fs.qw.domain.QwSopParam;
 import com.fs.qw.domain.QwSopUpdateStatus;
 import com.fs.qw.service.IQwUserService;
 import com.fs.qw.vo.QwUserVO;
@@ -432,4 +434,17 @@ public class QwSopController extends BaseController
         List<QwSop> qwSops = qwSopService.selectAllQwSopInfo(qwSop);
         return getDataTable(qwSops);
     }
+
+    /**
+     * 跳过sop
+     * @param param
+     * @return
+     */
+    @PostMapping("/handleSkipSop")
+    @RepeatSubmit
+    public R handleSkipSop(@RequestBody QwSopParam param) {
+        String sopParamStr = JSON.toJSONString(param.getParamList());
+        qwSopService.updateSkipSopJson(sopParamStr, param.getSopId());
+        return R.ok();
+}
 }

+ 27 - 2
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -42,6 +42,7 @@ import com.fs.sop.vo.SopUserLogsVo;
 import com.fs.system.service.ISysConfigService;
 import com.fs.voice.utils.StringUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.retry.annotation.Backoff;
@@ -63,6 +64,7 @@ import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static com.fs.course.utils.LinkUtil.generateRandomStringWithLock;
 
@@ -573,8 +575,19 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                     return;
                 }
             }
-
-
+            List<SopParam> paramList = ruleTimeVO.getSkipSopJson() == null ? new ArrayList<>() : JSON.parseArray(ruleTimeVO.getSkipSopJson(), SopParam.class);
+            List<SopParam> dayList = paramList.stream().filter(e -> e.getDayNum() != null && e.getStartDate() == null && e.getEndDate() == null).collect(Collectors.toList());
+            List<SopParam> timeList = paramList.stream().filter(e -> e.getDayNum() != null && e.getStartDate() != null && e.getEndDate() != null).collect(Collectors.toList());
+            Map<String, List<SopParam>> timeMap = PubFun.listToMapByGroupList(timeList, e -> e.getDayNum());
+            if (CollectionUtils.isNotEmpty(dayList)) {
+                for (SopParam sopParam : dayList) {
+                    String dayNum = sopParam.getDayNum();
+                    if (day == Long.valueOf(dayNum)) {
+                        log.info("跳过当前sop任务,任务id:{},跳过第:{}天", ruleTimeVO.getId(), dayNum);
+                        return;
+                    }
+                }
+            }
             // 只有整倍数才做事
             if (daysBetween % tempGap != 0) {
                 log.error("天数差 {} 不是 tempGap {} 的整数倍,跳过操作,SopId {} ", daysBetween, tempGap,logVo.getSopId());
@@ -588,6 +601,18 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                     LocalTime elementLocalTime = LocalTime.parse(content.getTime());
                     LocalDateTime elementDateTime = LocalDateTime.of(currentTime.toLocalDate(), elementLocalTime);
 
+                    List<SopParam> dayTimeList = timeMap.get(day + "");
+                    if (CollectionUtils.isNotEmpty(dayTimeList)) {
+                        for (SopParam sopParam : dayTimeList) {
+                            LocalTime start = LocalTime.parse(sopParam.getStartDate());
+                            LocalTime end = LocalTime.parse(sopParam.getEndDate());
+                            if (elementLocalTime.isAfter(start) && elementLocalTime.isBefore(end)) {
+                                log.info("跳过当前sop任务,任务id:{},跳过时间段:{}-{}", ruleTimeVO.getId(), start, end);
+                                return;
+                            }
+                        }
+                    }
+
                     // 动态调整 elementDateTime 的日期
                     if (elementLocalTime.isBefore(currentTime.toLocalTime())) {
                         elementDateTime = elementDateTime.plusDays(1);

+ 13 - 0
fs-service/src/main/java/com/fs/qw/domain/QwSopParam.java

@@ -0,0 +1,13 @@
+package com.fs.qw.domain;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Data
+public class QwSopParam {
+    @NotNull(message = "sop任务id不能为空")
+    private String sopId;
+    private List<SopParam> paramList;    
+}

+ 21 - 0
fs-service/src/main/java/com/fs/qw/domain/SopParam.java

@@ -0,0 +1,21 @@
+package com.fs.qw.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class SopParam implements Serializable {
+    private String dayNum;
+    private String startDate;
+    private String endDate;
+    
+     public SopParam(String dayNum, String startDate, String endDate) {
+        this.dayNum = dayNum;
+        this.startDate = startDate;
+        this.endDate = endDate;
+    }
+    
+     public SopParam() {
+    }    
+}

+ 2 - 1
fs-service/src/main/java/com/fs/qw/vo/QwSopRuleTimeVO.java

@@ -91,5 +91,6 @@ public class QwSopRuleTimeVO extends BaseEntity {
 
     // 是否固定营期
     private Integer isFixed;
-
+    //跳过sop数据
+    private String skipSopJson;
 }

+ 3 - 0
fs-service/src/main/java/com/fs/sop/domain/QwSop.java

@@ -154,4 +154,7 @@ public class QwSop implements Serializable
     private Integer autoUserReg;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String pullTime;
+    
+    private String skipSopJson;
+
 }

+ 2 - 0
fs-service/src/main/java/com/fs/sop/mapper/QwSopMapper.java

@@ -434,4 +434,6 @@ public interface QwSopMapper extends BaseMapper<QwSop> {
 
     @DataSource(DataSourceType.SOP)
     void updateSopGroupIds(@Param("id") String id, @Param("chatId") String chatId);
+
+    void updateSkipSopJson(@Param("sopParamStr") String sopParamStr,@Param("id") String id);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/sop/service/IQwSopService.java

@@ -114,4 +114,6 @@ public interface IQwSopService
 
     //看课足迹--侧边栏
     List<FsCourseWatchLogStatisticsListVO> externalWatchRecordStatsList (QwSidebarStatsParam qwParam);
+
+    void updateSkipSopJson(String sopParamStr, String id);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/sop/service/impl/QwSopServiceImpl.java

@@ -1361,6 +1361,11 @@ public class QwSopServiceImpl implements IQwSopService
         return list;
     }
 
+    @Override
+    public void updateSkipSopJson(String sopParamStr, String id) {
+        qwSopMapper.updateSkipSopJson(sopParamStr, id);
+    }
+
     /**
      *  获取外部联系人信息
      * */

+ 8 - 0
fs-service/src/main/resources/mapper/sop/QwSopMapper.xml

@@ -41,6 +41,7 @@
         <result property="autoGroup"    column="auto_group"    />
         <result property="autoGroupLevel"    column="auto_group_level"    />
         <result property="groupName"    column="group_name"    />
+        <result property="skipSopJson"    column="skip_sop_json"    />
     </resultMap>
 
     <sql id="selectQwSopVo">
@@ -295,6 +296,7 @@
             <if test="data.autoGroupLevel != null">auto_group_level,</if>
             <if test="data.groupName != null">group_name,</if>
             <if test="data.isFixed != null">is_fixed,</if>
+            <if test="data.skipSopJson != null">skip_sop_json,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="data.name != null">#{data.name},</if>
@@ -328,6 +330,7 @@
             <if test="data.autoGroupLevel != null">#{data.autoGroupLevel},</if>
             <if test="data.groupName != null">#{data.groupName},</if>
             <if test="data.isFixed != null">#{data.isFixed},</if>
+            <if test="data.skipSopJson != null">#{data.skipSopJson},</if>
         </trim>
     </insert>
 
@@ -412,6 +415,7 @@
             <if test="liveTempId != null "> and live_temp_id = #{liveTempId}</if>
             <if test="liveTempSendTime != null "> and live_temp_send_time = #{liveTempSendTime}</if>
             <if test="groupName != null "> and group_name = #{groupName}</if>
+            <if test="skipSopJson != null "> and skip_sop_json = #{skipSopJson}</if>
             <!-- 加入固定条件 -->
             and status != 6
         </where>
@@ -508,6 +512,7 @@
             <if test="data.autoGroupLevel != null">auto_group_level = #{data.autoGroupLevel},</if>
             <if test="data.groupName != null">group_name = #{data.groupName},</if>
             <if test="data.isFixed != null">is_fixed = #{data.isFixed},</if>
+            <if test="data.skipSopJson != null">skip_sop_Json = #{data.skipSopJson},</if>
         </trim>
         where id = #{data.id}
     </update>
@@ -607,5 +612,8 @@
     <update id="updateSopGroupIds">
         update qw_sop set chat_id = #{chatId},pull_time = now() where id = #{id}
     </update>
+    <update id="updateSkipSopJson">
+        update qw_sop set skip_sop_json = #{sopParamStr} where id = #{id}
+    </update>
 
 </mapper>