|
@@ -0,0 +1,40 @@
|
|
|
|
+package com.gxzc.zen.job.jobhandler
|
|
|
|
+
|
|
|
|
+import com.gxzc.zen.api.sys.model.SysDept
|
|
|
|
+import com.gxzc.zen.api.sys.service.ISysDeptService
|
|
|
|
+import com.xxl.job.core.biz.model.ReturnT
|
|
|
|
+import com.xxl.job.core.handler.IJobHandler
|
|
|
|
+import com.xxl.job.core.handler.annotation.JobHandler
|
|
|
|
+import com.xxl.job.core.log.XxlJobLogger
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired
|
|
|
|
+import org.springframework.stereotype.Component
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author: Create By liusen
|
|
|
|
+ * @Date: Create on 14:20 2018/4/8
|
|
|
|
+ * @Description:
|
|
|
|
+ * 任务Handler示例(Bean模式)
|
|
|
|
+ *
|
|
|
|
+ * 开发步骤:
|
|
|
|
+ * 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”;
|
|
|
|
+ * 2、注册到Spring容器:添加“@Component”注解,被Spring容器扫描为Bean实例;
|
|
|
|
+ * 3、注册到执行器工厂:添加“@JobHandler(value="自定义jobhandler名称")”注解,注解value值对应的是调度中心新建任务的JobHandler属性的值。
|
|
|
|
+ * 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+@JobHandler("insertJobHandler")
|
|
|
|
+@Component
|
|
|
|
+class InsertJobHandler : IJobHandler() {
|
|
|
|
+ @Autowired
|
|
|
|
+ private lateinit var deptService: ISysDeptService
|
|
|
|
+
|
|
|
|
+ override fun execute(param: String?): ReturnT<String> {
|
|
|
|
+ XxlJobLogger.log("测试插入开始=================")
|
|
|
|
+ deptService.insert(SysDept().apply {
|
|
|
|
+ name = "开发部"
|
|
|
|
+ principal = "ls"
|
|
|
|
+ })
|
|
|
|
+ XxlJobLogger.log("测试插入结束=================")
|
|
|
|
+ return SUCCESS
|
|
|
|
+ }
|
|
|
|
+}
|