Parcourir la source

添加执行动态标签定时任务接口

zoujiajian il y a 3 ans
Parent
commit
75b3759d1a

+ 9 - 0
netflix-common/src/main/java/com/cyksj/xxljob/XxlJobInfo.java

@@ -34,6 +34,11 @@ public class XxlJobInfo {
 		this.triggerStatus = 1;
 	}
 
+	public XxlJobInfo(int id, String executorParam) {
+		this.id = id;
+		this.executorParam = executorParam;
+	}
+
 	private int id;
 	/**
 	 * 执行器主键ID
@@ -132,6 +137,10 @@ public class XxlJobInfo {
 		return new XxlJobInfo(id, "周期群发任务", URLEncoder.createQuery().encode(corn, Charset.defaultCharset()), jobGroups, author.getName(), author.email, "yh_corp_msg_bulk_task_cycle_job", executorParam);
 	}
 
+	public static XxlJobInfo getExecuteTaskInstance(int id, String executorParam) {
+		return new XxlJobInfo(id, executorParam);
+	}
+
 	@Getter
 	public enum AUTHOR {
 

+ 15 - 0
netflix-common/src/main/java/com/cyksj/xxljob/XxlJobUtil.java

@@ -107,6 +107,21 @@ public class XxlJobUtil {
 		return Jsons.parseObject(execute.body(), JSONObject.class);
 	}
 
+	/**
+	 * 立即执行某一定时任务
+	 * @param jobParam
+	 */
+	public static XxlJobResult executeMarkDynamicRuleTagJob(String jobParam) throws Exception {
+		String path = "/jobinfo/trigger";
+		String targetUrl = BASE_URL + path + jobParam;
+
+		HttpResponse execute = HttpUtil.createPost(targetUrl)
+				.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
+				.header("Cookie", getCookie())
+				.execute();
+		return Jsons.parseObject(execute.body(), XxlJobResult.class);
+	}
+
 
 	/**
 	 * 获取登录cookie

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CorpTagBackView.java

@@ -30,6 +30,11 @@ public class CorpTagBackView {
 
 	private Long tagId;
 
+	/**
+	 * 标签所属类型 1普通,2动态
+	 */
+	private Integer type;
+
 	private String tagIdStr;
 
 	/**

+ 1 - 0
netflix-dao/src/main/resources/mapper/CorpTagMapper.xml

@@ -14,6 +14,7 @@
         select * from (select ct.id as tagId,
         ct.tag_id as tagIdStr,
         ct.group_id groupIdStr,
+        ct.type,
         ct.group_name,
         ct.name as tagName,
         count(cut.id) as numOfCustomer,

+ 1 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -622,6 +622,7 @@ public class RedisService {
         //企业微信欢迎语 临时素材 mediaId
         CORP_WECLOME_MEDIA("corp:%s:weclome:media:","临时素材 mediaId",60*60*24*3 - 60*60*1L),
         CORP_UPLOAD_ATTACHMENTS("corp:%s:upload:attachments:","临时附件",60*60*24*3 - 60*60*1L),
+        CORP_DYNAMIC_RULE_TAG_KEY("corp_dynamic_rule_tag_key:", "企业微信动态标签key", 60 * 60L),
         ;
 
         private String name;

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/CorpMsgBulkTaskService.java

@@ -19,4 +19,6 @@ public interface CorpMsgBulkTaskService extends IService<CorpMsgBulkTask> {
 	void remindBulkTask(String msgid);
 
 	Map<String, List<CorpTag>> getTagDetail(Long id) throws Exception;
+
+	void executeDynamicRuleTagTask(Long tagId) throws Exception;
 }

+ 19 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpMsgBulkTaskServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
@@ -22,6 +23,7 @@ import com.cyksj.model.request.corp.Attachments;
 import com.cyksj.model.request.corp.CorpMsgTemplate;
 import com.cyksj.model.request.corp.Text;
 import com.cyksj.model.response.corp.CorpMsgTemplateAddResult;
+import com.cyksj.redis.RedisService;
 import com.cyksj.service.corp.CorpMsgBulkTaskService;
 import com.cyksj.service.corp.CorpService;
 import com.cyksj.service.corp.CorpUserSendRecordService;
@@ -72,6 +74,8 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
 
 	private final CorpMsgBulkTaskTagRelationMapper corpMsgBulkTaskTagRelationMapper;
 
+	private final RedisService redisService;
+
 	private final int LIMIT = 10000;
 
 	private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
@@ -127,6 +131,21 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
 		return collect;
 	}
 
+	@Override
+	public void executeDynamicRuleTagTask(Long tagId) throws Exception {
+		CorpTag corpTag = corpTagMapper.selectById(tagId);
+		Assert.notNull(corpTag, "标签不存在");
+		if (corpTag.getType() != 2) {
+			Assert.notNull(corpTag, "非动态标签");
+		}
+		//执行动态标签标记任务id
+		int taskId = 100;
+		if (!redisService.setNx(RedisService.key.CORP_DYNAMIC_RULE_TAG_KEY.getName() + tagId, tagId, RedisService.key.CORP_DYNAMIC_RULE_TAG_KEY.getTimeout())) {
+			throw BusinessRuntimeException.getInstance("该动态标签标记正在执行中..");
+		}
+		XxlJobResult xxlJobResult = XxlJobUtil.executeMarkDynamicRuleTagJob(XxlJobInfo.getExecuteTaskInstance(taskId, String.valueOf(tagId)).toString());
+	}
+
 	/**
 	 * 创建企业群发
 	 */

+ 9 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/CorpMsgBulkTaskController.java

@@ -168,4 +168,13 @@ public class CorpMsgBulkTaskController {
 		corpMsgBulkTaskService.remindBulkTask(msgid);
 		return GatewayResponse.SUCCESS.newBuilder().toResult("提醒群发成功");
 	}
+
+	/**
+	 * 立即执行 打动态标签
+	 */
+	@PostMapping("/execute/dynamicRuleTag/{tagId}")
+	public Result<String> executeDynamicRuleTagTask(@PathVariable Long tagId) throws Exception {
+		corpMsgBulkTaskService.executeDynamicRuleTagTask(tagId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }