-- -----------------------------------
-- 新增任务表
-- -----------------------------------
CREATE TABLE "ENERGYX"."ENERGY_JOB_SERVER" (
  "ID" NUMBER(20) NOT NULL ,
  "JOB_SERVER_NAME" VARCHAR2(50) ,
  "JOB_SERVER_URL" VARCHAR2(255) ,
  "JOB_APP_NAME" VARCHAR2(20) ,
  "JOB_APP_PASSWORD" VARCHAR2(100) ,
  "JOB_REMARK" VARCHAR2(255) ,
  "CREATE_USER" NUMBER(20) ,
  "CREATE_DEPT" NUMBER(20) ,
  "CREATE_TIME" DATE ,
  "UPDATE_USER" NUMBER(20) ,
  "UPDATE_TIME" DATE ,
  "STATUS" NUMBER(11) ,
  "IS_DELETED" NUMBER(11) ,
  PRIMARY KEY ("ID")
)
;

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."ID" IS '主键';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."JOB_SERVER_NAME" IS '任务服务名称';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."JOB_SERVER_URL" IS '任务服务地址';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."JOB_APP_NAME" IS '任务应用名称';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."JOB_APP_PASSWORD" IS '任务应用密码';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."JOB_REMARK" IS '任务说明';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."CREATE_USER" IS '创建人';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."CREATE_DEPT" IS '创建部门';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."CREATE_TIME" IS '创建时间';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."UPDATE_USER" IS '修改人';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."UPDATE_TIME" IS '修改时间';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."STATUS" IS '状态';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_SERVER"."IS_DELETED" IS '是否已删除';

COMMENT ON TABLE "ENERGYX"."ENERGY_JOB_SERVER" IS '任务服务表';

INSERT INTO "ENERGY_JOB_SERVER"("ID", "JOB_SERVER_NAME", "JOB_SERVER_URL", "JOB_APP_NAME", "JOB_APP_PASSWORD", "JOB_REMARK", "CREATE_USER", "CREATE_DEPT", "CREATE_TIME", "UPDATE_USER", "UPDATE_TIME", "STATUS", "IS_DELETED")
(1741512022505590785, '任务调度服务器', '127.0.0.1:7700', 'energy-job', 'energy-job', '基础服务', 1123598821738675201, 1123598813738675201, TO_DATE('2024-01-01 01:29:57', 'SYYYY-MM-DD HH24:MI:SS'), 1123598821738675201, TO_DATE('2024-01-01 01:29:57', 'SYYYY-MM-DD HH24:MI:SS'), 1, 0);

-- -----------------------------------
-- 新增任务信息表
-- -----------------------------------
CREATE TABLE "ENERGYX"."ENERGY_JOB_INFO" (
 "ID" NUMBER(20) NOT NULL ,
 "JOB_SERVER_ID" NUMBER(20) ,
 "JOB_ID" NUMBER(20) ,
 "JOB_NAME" VARCHAR2(50) ,
 "JOB_DESCRIPTION" VARCHAR2(255) ,
 "JOB_PARAMS" NCLOB ,
 "TIME_EXPRESSION_TYPE" NUMBER(11) ,
 "TIME_EXPRESSION" VARCHAR2(255) ,
 "EXECUTE_TYPE" NUMBER(11) ,
 "PROCESSOR_TYPE" NUMBER(11) ,
 "PROCESSOR_INFO" VARCHAR2(255) ,
 "MAX_INSTANCE_NUM" NUMBER(11) ,
 "CONCURRENCY" NUMBER(11) ,
 "INSTANCE_TIME_LIMIT" NUMBER(11) ,
 "INSTANCE_RETRY_NUM" NUMBER(11) ,
 "TASK_RETRY_NUM" NUMBER(11) ,
 "MIN_CPU_CORES" BINARY_DOUBLE ,
 "MIN_MEMORY_SPACE" BINARY_DOUBLE ,
 "MIN_DISK_SPACE" BINARY_DOUBLE ,
 "DESIGNATED_WORKERS" VARCHAR2(255) ,
 "MAX_WORKER_COUNT" NUMBER(11) ,
 "NOTIFY_USER_IDS" VARCHAR2(2000) ,
 "ENABLE" NUMBER(11) ,
 "DISPATCH_STRATEGY" NUMBER(11) ,
 "LIFECYCLE" VARCHAR2(255) ,
 "ALERT_THRESHOLD" NUMBER(11),
 "STATISTIC_WINDOW_LEN" NUMBER(11),
 "SILENCE_WINDOW_LEN" NUMBER(11),
 "LOG_TYPE" NUMBER(11),
 "LOG_LEVEL" NUMBER(11),
 "EXTRA" VARCHAR2(255) ,
 "CREATE_USER" NUMBER(20) ,
 "CREATE_DEPT" NUMBER(20) ,
 "CREATE_TIME" DATE ,
 "UPDATE_USER" NUMBER(20) ,
 "UPDATE_TIME" DATE ,
 "STATUS" NUMBER(11) ,
 "IS_DELETED" NUMBER(11) ,
 PRIMARY KEY ("ID")
)
;

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."ID" IS '主键';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."JOB_SERVER_ID" IS '任务服务ID';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."JOB_ID" IS '任务 ID，可选，null 代表创建任务，否则填写需要修改的任务 ID';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."JOB_NAME" IS '任务名称';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."JOB_DESCRIPTION" IS '任务描述';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."JOB_PARAMS" IS '任务参数，Processor#process 方法入参 TaskContext对象的 jobParams 字段';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."TIME_EXPRESSION_TYPE" IS '时间表达式类型，枚举值';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."TIME_EXPRESSION" IS '时间表达式，填写类型由 timeExpressionType 决定，比如 CRON 需要填写 CRON 表达式';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."EXECUTE_TYPE" IS '执行类型，枚举值';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."PROCESSOR_TYPE" IS '处理器类型，枚举值';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."PROCESSOR_INFO" IS '处理器参数，填写类型由 processorType 决定，如Java 处理器需要填写全限定类名，如：com.github.kfcfans.oms.processors.demo.MapReduceProcessorDemo';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."MAX_INSTANCE_NUM" IS '最大实例数，该任务同时执行的数量（任务和实例就像是类和对象的关系，任务被调度执行后被称为实例）';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."CONCURRENCY" IS '单机线程并发数，表示该实例执行过程中每个Worker 使用的线程数量';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."INSTANCE_TIME_LIMIT" IS '任务实例运行时间限制，0 代表无任何限制，超时会被打断并判定为执行失败';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."INSTANCE_RETRY_NUM" IS '任务实例重试次数，整个任务失败时重试，代价大，不推荐使用';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."TASK_RETRY_NUM" IS 'Task 重试次数，每个子 Task 失败后单独重试，代价小，推荐使用';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."MIN_CPU_CORES" IS '最小可用 CPU 核心数，CPU 可用核心数小于该值的 Worker 将不会执行该任务，0 代表无任何限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."MIN_MEMORY_SPACE" IS '最小内存大小（GB），可用内存小于该值的Worker 将不会执行该任务，0 代表无任何限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."MIN_DISK_SPACE" IS '最小磁盘大小（GB），可用磁盘空间小于该值的Worker 将不会执行该任务，0 代表无任何限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."DESIGNATED_WORKERS" IS '指定机器执行，设置该参数后只有列表中的机器允许执行该任务，空代表不指定机器';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."MAX_WORKER_COUNT" IS '最大执行机器数量，限定调动执行的机器数量，0代表无限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."NOTIFY_USER_IDS" IS '接收报警的用户 ID 列表';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."ENABLE" IS '是否启用该任务，未启用的任务不会被调度';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."DISPATCH_STRATEGY" IS '调度策略，枚举，目前支持随机（RANDOM）和 健康度优先（HEALTH_FIRST）';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."LIFECYCLE" IS '生命周期（预留，用于指定定时调度任务的生效时间范围）';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."ALERT_THRESHOLD" IS '错误阈值，0代表不限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."STATISTIC_WINDOW_LEN" IS '统计的窗口长度(s)，0代表不限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."SILENCE_WINDOW_LEN" IS '沉默时间窗口(s)，0代表不限制';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."LOG_TYPE" IS '日志配置';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."LOG_LEVEL" IS '日志级别';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."EXTRA" IS '扩展字段（供开发者使用，用于功能扩展，powerjob 自身不会使用该字段）';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."CREATE_USER" IS '创建人';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."CREATE_DEPT" IS '创建部门';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."CREATE_TIME" IS '创建时间';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."UPDATE_USER" IS '修改人';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."UPDATE_TIME" IS '修改时间';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."STATUS" IS '状态';

COMMENT ON COLUMN "ENERGYX"."ENERGY_JOB_INFO"."IS_DELETED" IS '是否已删除';

COMMENT ON TABLE "ENERGYX"."ENERGY_JOB_INFO" IS '任务信息表';

-- -----------------------------------
-- 新增任务菜单信息
-- -----------------------------------
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "COMPONENT", "REMARK", "IS_DELETED")
VALUES ('1164733399669962401', 0, 'job', '任务管理', 'job', '/job', 'iconfont iconicon_cspace', 5, 1, 0, 1, '', NULL, 0);

INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962501', '1164733399669962401', 'jobserver', '任务应用', 'menu', '/job/jobserver', 'iconfont icon-shouji', 1, 1, 0, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962502', '1164733399669962501', 'jobserver_add', '新增', 'add', '/job/jobserver/add', 'plus', 1, 2, 1, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962503', '1164733399669962501', 'jobserver_edit', '修改', 'edit', '/job/jobserver/edit', 'form', 2, 2, 2, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962504', '1164733399669962501', 'jobserver_delete', '删除', 'delete', '/api/energy-job/jobserver/remove', 'delete', 3, 2, 3, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962505', '1164733399669962501', 'jobserver_view', '查看', 'view', '/job/jobserver/view', 'file-text', 4, 2, 2, 1, NULL, 0);


INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962601', '1164733399669962401', 'jobinfo', '任务配置', 'menu', '/job/jobinfo', 'iconfont icon-dongtai', 1, 1, 0, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962602', '1164733399669962601', 'jobinfo_add', '新增', 'add', '/job/jobinfo/add', 'plus', 1, 2, 1, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962603', '1164733399669962601', 'jobinfo_edit', '修改', 'edit', '/job/jobinfo/edit', 'form', 2, 2, 2, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962604', '1164733399669962601', 'jobinfo_delete', '删除', 'delete', '/api/energy-job/jobinfo/remove', 'delete', 3, 2, 3, 1, NULL, 0);
INSERT INTO "ENERGY_MENU"("ID", "PARENT_ID", "CODE", "NAME", "ALIAS", "PATH", "SOURCE", "SORT", "CATEGORY", "ACTION", "IS_OPEN", "REMARK", "IS_DELETED")
VALUES ('1164733399669962605', '1164733399669962601', 'jobinfo_view', '查看', 'view', '/job/jobinfo/view', 'file-text', 4, 2, 2, 1, NULL, 0);
