DROP TABLE IF EXISTS "blade_check_record";
CREATE TABLE "blade_check_record"
(
    "id"                 BIGINT NOT NULL,
    "status"             INT,
    "is_deleted"         INT,
    "create_user"        BIGINT,
    "create_dept"        BIGINT,
    "create_time"        TIMESTAMP(0),
    "update_user"        BIGINT,
    "update_time"        TIMESTAMP(0),
    "tenant_id"          VARCHAR(12),
    "check_code"         VARCHAR(128),
    "device_id"          BIGINT,
    "device_type_id"     BIGINT,
    "check_user_id"      BIGINT,
    "check_time"         TIMESTAMP(0),
    "check_result"       INT DEFAULT 1,
    "check_project_id"   BIGINT,
    "remark"             VARCHAR(255),
    "device_code"        VARCHAR(255),
    "device_name"        VARCHAR(255),
    "device_type_name"   VARCHAR(255),
    "check_user_name"    VARCHAR(255),
    "check_project_code" VARCHAR(255),
    "check_project_name" VARCHAR(255),
    "machine_model"      VARCHAR(64),
    NOT                  CLUSTER PRIMARY KEY ("id"),
    UNIQUE ("check_code", "is_deleted"),
    CHECK ("status" >= 0),
    CHECK ("check_result" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_check_record" IS '点检记录';
COMMENT
ON COLUMN "blade_check_record"."check_code" IS '点检记录编码';
COMMENT
ON COLUMN "blade_check_record"."check_project_code" IS '点检项目编码';
COMMENT
ON COLUMN "blade_check_record"."check_project_id" IS '点检项目id';
COMMENT
ON COLUMN "blade_check_record"."check_project_name" IS '点检项目名称';
COMMENT
ON COLUMN "blade_check_record"."check_result" IS '点检结果：0-不正常，1-正常';
COMMENT
ON COLUMN "blade_check_record"."check_time" IS '点检时间';
COMMENT
ON COLUMN "blade_check_record"."check_user_id" IS '检验人员id';
COMMENT
ON COLUMN "blade_check_record"."check_user_name" IS '检验人员名称';
COMMENT
ON COLUMN "blade_check_record"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_check_record"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_check_record"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_check_record"."device_code" IS '机器编码';
COMMENT
ON COLUMN "blade_check_record"."device_id" IS '机器id';
COMMENT
ON COLUMN "blade_check_record"."device_name" IS '机器名称';
COMMENT
ON COLUMN "blade_check_record"."device_type_id" IS '机器类型id';
COMMENT
ON COLUMN "blade_check_record"."device_type_name" IS '机器类型名称';
COMMENT
ON COLUMN "blade_check_record"."id" IS '主键';
COMMENT
ON COLUMN "blade_check_record"."machine_model" IS '机器规格';
COMMENT
ON COLUMN "blade_check_record"."remark" IS '备注';
COMMENT
ON COLUMN "blade_check_record"."status" IS '状态';
COMMENT
ON COLUMN "blade_check_record"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_check_record"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_check_record"."update_user" IS '更新人';


DROP TABLE IF EXISTS "blade_check_record_file";
CREATE TABLE "blade_check_record_file"
(
    "id"              BIGINT NOT NULL,
    "status"          INT,
    "is_deleted"      INT,
    "create_user"     BIGINT,
    "create_dept"     BIGINT,
    "create_time"     TIMESTAMP(0),
    "update_user"     BIGINT,
    "update_time"     TIMESTAMP(0),
    "tenant_id"       VARCHAR(12),
    "check_record_id" BIGINT,
    "file_name"       VARCHAR(255),
    "object_key"      VARCHAR(255),
    "link"            VARCHAR(255),
    "content_type"    VARCHAR(255),
    "file_size"       VARCHAR(100),
    "upload_time"     TIMESTAMP(0),
    "file_type"       INT,
    NOT               CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_check_record_file" IS '点检记录点检项';
COMMENT
ON COLUMN "blade_check_record_file"."check_record_id" IS '点检记录id';
COMMENT
ON COLUMN "blade_check_record_file"."content_type" IS '文件类型';
COMMENT
ON COLUMN "blade_check_record_file"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_check_record_file"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_check_record_file"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_check_record_file"."file_name" IS '文件名称';
COMMENT
ON COLUMN "blade_check_record_file"."id" IS '主键';
COMMENT
ON COLUMN "blade_check_record_file"."link" IS '文件link';
COMMENT
ON COLUMN "blade_check_record_file"."object_key" IS '文件key';
COMMENT
ON COLUMN "blade_check_record_file"."status" IS '状态';
COMMENT
ON COLUMN "blade_check_record_file"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_check_record_file"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_check_record_file"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_check_record_file"."file_size" IS '文件大小';
COMMENT
ON COLUMN "blade_check_record_file"."upload_time" IS '上传时间';
COMMENT
ON COLUMN "blade_check_record_file"."file_type" IS '文件类型(1:图片 2 附件)';

DROP TABLE IF EXISTS "blade_check_record_item";
CREATE TABLE "blade_check_record_item"
(
    "id"              BIGINT NOT NULL,
    "status"          INT,
    "is_deleted"      INT,
    "create_user"     BIGINT,
    "create_dept"     BIGINT,
    "create_time"     TIMESTAMP(0),
    "update_user"     BIGINT,
    "update_time"     TIMESTAMP(0),
    "tenant_id"       VARCHAR(12),
    "check_record_id" BIGINT,
    "item_id"         BIGINT,
    "check_value"     VARCHAR(255),
    "name"            VARCHAR(64),
    "value_type"      VARCHAR(64),
    "requirement"     VARCHAR(255),
    "standard_value"  VARCHAR(64),
    NOT               CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_check_record_item" IS '点检记录点检项';
COMMENT
ON COLUMN "blade_check_record_item"."check_record_id" IS '点检记录id';
COMMENT
ON COLUMN "blade_check_record_item"."check_value" IS '检验数值';
COMMENT
ON COLUMN "blade_check_record_item"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_check_record_item"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_check_record_item"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_check_record_item"."id" IS '主键';
COMMENT
ON COLUMN "blade_check_record_item"."item_id" IS '点检项id';
COMMENT
ON COLUMN "blade_check_record_item"."name" IS '点检项';
COMMENT
ON COLUMN "blade_check_record_item"."requirement" IS '点检要求';
COMMENT
ON COLUMN "blade_check_record_item"."standard_value" IS '标准数值';
COMMENT
ON COLUMN "blade_check_record_item"."status" IS '状态';
COMMENT
ON COLUMN "blade_check_record_item"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_check_record_item"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_check_record_item"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_check_record_item"."value_type" IS '数值类型';


DROP TABLE IF EXISTS "blade_maintain_plan";
CREATE TABLE "blade_maintain_plan"
(
    "id"                 BIGINT NOT NULL,
    "status"             INT,
    "is_deleted"         INT,
    "create_user"        BIGINT,
    "create_dept"        BIGINT,
    "create_time"        TIMESTAMP(0),
    "update_user"        BIGINT,
    "update_time"        TIMESTAMP(0),
    "tenant_id"          VARCHAR(12),
    "code"               VARCHAR(128),
    "device_id"          BIGINT,
    "device_code"        VARCHAR(128),
    "device_name"        VARCHAR(64),
    "device_type_id"     BIGINT,
    "device_type_name"   VARCHAR(64),
    "project_id"         VARCHAR(32),
    "project_code"       VARCHAR(128),
    "project_name"       VARCHAR(64),
    "maintain_date"      TIMESTAMP(0),
    "pre_warning_days"   INT,
    "plan_status"        INT,
    "is_auto"            INT,
    "interval_time"      INT,
    "pre_maintain_time"  TIMESTAMP(0),
    "machine_model"      VARCHAR(128),
    "usage_time"         TIMESTAMP(0),
    "remark"             VARCHAR(255),
    "maintain_nature"    VARCHAR(255),
    "maintain_user_id"   BIGINT,
    "maintain_user_name" VARCHAR(255),
    NOT                  CLUSTER PRIMARY KEY ("id"),
    UNIQUE ("code", "is_deleted"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_maintain_plan" IS '保养计划';
COMMENT
ON COLUMN "blade_maintain_plan"."code" IS '计划任务编码';
COMMENT
ON COLUMN "blade_maintain_plan"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_maintain_plan"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_maintain_plan"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_maintain_plan"."device_code" IS '机器编码';
COMMENT
ON COLUMN "blade_maintain_plan"."device_id" IS '机器Id';
COMMENT
ON COLUMN "blade_maintain_plan"."device_name" IS '机器名称';
COMMENT
ON COLUMN "blade_maintain_plan"."device_type_id" IS '机器类型Id';
COMMENT
ON COLUMN "blade_maintain_plan"."device_type_name" IS '机器类型名称';
COMMENT
ON COLUMN "blade_maintain_plan"."id" IS '主键';
COMMENT
ON COLUMN "blade_maintain_plan"."interval_time" IS '周期（天）';
COMMENT
ON COLUMN "blade_maintain_plan"."is_auto" IS '是否自动生成计划（0：否；1：是）';
COMMENT
ON COLUMN "blade_maintain_plan"."machine_model" IS '机器规格';
COMMENT
ON COLUMN "blade_maintain_plan"."maintain_date" IS '下次保养日期';
COMMENT
ON COLUMN "blade_maintain_plan"."maintain_nature" IS '保养性质(1:厂内;2:委外)';
COMMENT
ON COLUMN "blade_maintain_plan"."maintain_user_id" IS '保养负责人';
COMMENT
ON COLUMN "blade_maintain_plan"."maintain_user_name" IS '保养负责人';
COMMENT
ON COLUMN "blade_maintain_plan"."plan_status" IS '计划状态（1：正常；2：待执行；3：执行中；4：待确认；5：已确认）';
COMMENT
ON COLUMN "blade_maintain_plan"."pre_maintain_time" IS '上一次保养时间';
COMMENT
ON COLUMN "blade_maintain_plan"."pre_warning_days" IS '保养预警提示（天）';
COMMENT
ON COLUMN "blade_maintain_plan"."project_code" IS '保养项目编号';
COMMENT
ON COLUMN "blade_maintain_plan"."project_id" IS '保养项目id';
COMMENT
ON COLUMN "blade_maintain_plan"."project_name" IS '保养项目名称';
COMMENT
ON COLUMN "blade_maintain_plan"."remark" IS '备注';
COMMENT
ON COLUMN "blade_maintain_plan"."status" IS '状态';
COMMENT
ON COLUMN "blade_maintain_plan"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_maintain_plan"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_maintain_plan"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_maintain_plan"."usage_time" IS '使用时间';


DROP TABLE IF EXISTS "blade_maintain_plan_item";
CREATE TABLE "blade_maintain_plan_item"
(
    "id"          BIGINT NOT NULL,
    "status"      INT,
    "is_deleted"  INT,
    "create_user" BIGINT,
    "create_dept" BIGINT,
    "create_time" TIMESTAMP(0),
    "update_user" BIGINT,
    "update_time" TIMESTAMP(0),
    "tenant_id"   VARCHAR(12),
    "plan_id"     BIGINT,
    "item_id"     BIGINT,
    NOT           CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_maintain_plan_item" IS '保养计划保养项';
COMMENT
ON COLUMN "blade_maintain_plan_item"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_maintain_plan_item"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_maintain_plan_item"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_maintain_plan_item"."id" IS '主键';
COMMENT
ON COLUMN "blade_maintain_plan_item"."item_id" IS '保养项id';
COMMENT
ON COLUMN "blade_maintain_plan_item"."plan_id" IS '保养计划id';
COMMENT
ON COLUMN "blade_maintain_plan_item"."status" IS '状态';
COMMENT
ON COLUMN "blade_maintain_plan_item"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_maintain_plan_item"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_maintain_plan_item"."update_user" IS '更新人';


DROP TABLE IF EXISTS "blade_maintain_record";
CREATE TABLE "blade_maintain_record"
(
    "id"                 BIGINT NOT NULL,
    "status"             INT,
    "is_deleted"         INT,
    "create_user"        BIGINT,
    "create_dept"        BIGINT,
    "create_time"        TIMESTAMP(0),
    "update_user"        BIGINT,
    "update_time"        TIMESTAMP(0),
    "tenant_id"          VARCHAR(12),
    "record_code"        VARCHAR(128),
    "plan_id"            BIGINT,
    "start_time"         TIMESTAMP(0),
    "end_time"           TIMESTAMP(0),
    "is_delay"           INT DEFAULT 0,
    "delay_days"         INT,
    "maintain_user_id"   BIGINT,
    "maintain_user_name" VARCHAR(64),
    "delay_reason"       VARCHAR(255),
    "record_status"      INT,
    "plan_code"          VARCHAR(128),
    "device_id"          BIGINT,
    "device_code"        VARCHAR(128),
    "device_name"        VARCHAR(64),
    "device_type_id"     BIGINT,
    "device_type_name"   VARCHAR(64),
    "project_id"         VARCHAR(32),
    "project_code"       VARCHAR(128),
    "project_name"       VARCHAR(64),
    "remark"             VARCHAR(255),
    "maintain_nature"    VARCHAR(255),
    NOT                  CLUSTER PRIMARY KEY ("id"),
    UNIQUE ("record_code", "is_deleted"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_maintain_record" IS '保养记录表';
COMMENT
ON COLUMN "blade_maintain_record"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_maintain_record"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_maintain_record"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_maintain_record"."delay_days" IS '延期天数';
COMMENT
ON COLUMN "blade_maintain_record"."delay_reason" IS '延期原因';
COMMENT
ON COLUMN "blade_maintain_record"."device_code" IS '机器编码';
COMMENT
ON COLUMN "blade_maintain_record"."device_id" IS '机器Id';
COMMENT
ON COLUMN "blade_maintain_record"."device_name" IS '机器名称';
COMMENT
ON COLUMN "blade_maintain_record"."device_type_id" IS '机器类型Id';
COMMENT
ON COLUMN "blade_maintain_record"."device_type_name" IS '机器类型名称';
COMMENT
ON COLUMN "blade_maintain_record"."end_time" IS '结束时间';
COMMENT
ON COLUMN "blade_maintain_record"."id" IS '主键';
COMMENT
ON COLUMN "blade_maintain_record"."is_delay" IS '是否延期（0：未延期；1：已延期）';
COMMENT
ON COLUMN "blade_maintain_record"."maintain_nature" IS '保养性质(1:厂内;2:委外)';
COMMENT
ON COLUMN "blade_maintain_record"."maintain_user_id" IS '保养负责人Id';
COMMENT
ON COLUMN "blade_maintain_record"."maintain_user_name" IS '保养负责人名称';
COMMENT
ON COLUMN "blade_maintain_record"."plan_code" IS '计划单号';
COMMENT
ON COLUMN "blade_maintain_record"."plan_id" IS '计划任务Id';
COMMENT
ON COLUMN "blade_maintain_record"."project_code" IS '保养项目编号';
COMMENT
ON COLUMN "blade_maintain_record"."project_id" IS '保养项目id';
COMMENT
ON COLUMN "blade_maintain_record"."project_name" IS '保养项目名称';
COMMENT
ON COLUMN "blade_maintain_record"."record_code" IS '保养记录单号';
COMMENT
ON COLUMN "blade_maintain_record"."record_status" IS '保养记录状态（1：待确认；2：已确认）';
COMMENT
ON COLUMN "blade_maintain_record"."remark" IS '备注';
COMMENT
ON COLUMN "blade_maintain_record"."start_time" IS '开始时间';
COMMENT
ON COLUMN "blade_maintain_record"."status" IS '状态';
COMMENT
ON COLUMN "blade_maintain_record"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_maintain_record"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_maintain_record"."update_user" IS '更新人';


DROP TABLE IF EXISTS "blade_maintain_record_item";
CREATE TABLE "blade_maintain_record_item"
(
    "id"          BIGINT NOT NULL,
    "status"      INT,
    "is_deleted"  INT,
    "create_user" BIGINT,
    "create_dept" BIGINT,
    "create_time" TIMESTAMP(0),
    "update_user" BIGINT,
    "update_time" TIMESTAMP(0),
    "tenant_id"   VARCHAR(12),
    "record_id"   BIGINT,
    "item_id"     BIGINT,
    "code"        VARCHAR(128),
    "name"        VARCHAR(64),
    "requirement" VARCHAR(255),
    "remark"      VARCHAR(255),
    "is_execute"  INT,
    "is_default"  INT,
    NOT           CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_maintain_record_item" IS '保养记录保养项';
COMMENT
ON COLUMN "blade_maintain_record_item"."code" IS '保养编码';
COMMENT
ON COLUMN "blade_maintain_record_item"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_maintain_record_item"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_maintain_record_item"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_maintain_record_item"."id" IS '主键';
COMMENT
ON COLUMN "blade_maintain_record_item"."is_default" IS '是否默认（0：否，1：是）';
COMMENT
ON COLUMN "blade_maintain_record_item"."is_execute" IS '保养判定（0：否，1：是）';
COMMENT
ON COLUMN "blade_maintain_record_item"."item_id" IS '保养项Id';
COMMENT
ON COLUMN "blade_maintain_record_item"."name" IS '保养项';
COMMENT
ON COLUMN "blade_maintain_record_item"."record_id" IS '保养记录单号';
COMMENT
ON COLUMN "blade_maintain_record_item"."remark" IS '备注';
COMMENT
ON COLUMN "blade_maintain_record_item"."requirement" IS '保养要求';
COMMENT
ON COLUMN "blade_maintain_record_item"."status" IS '状态';
COMMENT
ON COLUMN "blade_maintain_record_item"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_maintain_record_item"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_maintain_record_item"."update_user" IS '更新人';


DROP TABLE IF EXISTS "blade_repair_apply";
CREATE TABLE "blade_repair_apply"
(
    "id"               BIGINT NOT NULL,
    "status"           INT,
    "is_deleted"       INT,
    "create_user"      BIGINT,
    "create_dept"      BIGINT,
    "create_time"      TIMESTAMP(0),
    "update_user"      BIGINT,
    "update_time"      TIMESTAMP(0),
    "tenant_id"        VARCHAR(12),
    "apply_code"       VARCHAR(128),
    "device_id"        BIGINT,
    "device_code"      VARCHAR(128),
    "device_name"      VARCHAR(64),
    "device_type_id"   BIGINT,
    "device_type_name" VARCHAR(64),
    "apply_user_id"    BIGINT,
    "apply_user_name"  VARCHAR(64),
    "repair_user_id"   BIGINT,
    "repair_user_name" VARCHAR(64),
    "is_affect"        INT,
    "malfunction_time" TIMESTAMP(0),
    "urgency"          INT,
    "description"      VARCHAR(255),
    "apply_status"     INT,
    "malfunction_id"   BIGINT,
    "malfunction_code" VARCHAR(128),
    "malfunction_name" VARCHAR(64),
    "repair_nature"    INT,
    "start_time"       TIMESTAMP(0),
    "remark"           VARCHAR(255),
    "apply_time"       DATETIME(6),
    NOT                CLUSTER PRIMARY KEY ("id"),
    UNIQUE ("apply_code", "is_deleted"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_repair_apply" IS '维修申请信息';
COMMENT
ON COLUMN "blade_repair_apply"."apply_code" IS '维修申请编号';
COMMENT
ON COLUMN "blade_repair_apply"."apply_status" IS '申请单状态：待执行-1，执行中-2，待确认-3，已确认-4';
COMMENT
ON COLUMN "blade_repair_apply"."apply_user_id" IS '维修申请人id';
COMMENT
ON COLUMN "blade_repair_apply"."apply_user_name" IS '维修申请人姓名';
COMMENT
ON COLUMN "blade_repair_apply"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_repair_apply"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_repair_apply"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_repair_apply"."description" IS '故障描述';
COMMENT
ON COLUMN "blade_repair_apply"."device_code" IS '设备编码';
COMMENT
ON COLUMN "blade_repair_apply"."device_id" IS '设备id';
COMMENT
ON COLUMN "blade_repair_apply"."device_name" IS '设备名称';
COMMENT
ON COLUMN "blade_repair_apply"."device_type_id" IS '设备类型id';
COMMENT
ON COLUMN "blade_repair_apply"."device_type_name" IS '设备类型名称';
COMMENT
ON COLUMN "blade_repair_apply"."id" IS '主键';
COMMENT
ON COLUMN "blade_repair_apply"."is_affect" IS '影响生产：是-1，否-2';
COMMENT
ON COLUMN "blade_repair_apply"."malfunction_code" IS '故障类型编码';
COMMENT
ON COLUMN "blade_repair_apply"."malfunction_id" IS '所属故障类型';
COMMENT
ON COLUMN "blade_repair_apply"."malfunction_name" IS '故障类型';
COMMENT
ON COLUMN "blade_repair_apply"."malfunction_time" IS '故障发生时间';
COMMENT
ON COLUMN "blade_repair_apply"."remark" IS '备注';
COMMENT
ON COLUMN "blade_repair_apply"."repair_nature" IS '维修性质(1:厂内;2:委外)';
COMMENT
ON COLUMN "blade_repair_apply"."repair_user_id" IS '维修负责人id';
COMMENT
ON COLUMN "blade_repair_apply"."repair_user_name" IS '维修负责人姓名';
COMMENT
ON COLUMN "blade_repair_apply"."start_time" IS '执行开始时间';
COMMENT
ON COLUMN "blade_repair_apply"."status" IS '状态';
COMMENT
ON COLUMN "blade_repair_apply"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_repair_apply"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_repair_apply"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_repair_apply"."urgency" IS '紧急度：高-3，中-2，低-1';


DROP TABLE IF EXISTS "blade_repair_apply_file";
CREATE TABLE "blade_repair_apply_file"
(
    "id"              BIGINT NOT NULL,
    "status"          INT,
    "is_deleted"      INT,
    "create_user"     BIGINT,
    "create_dept"     BIGINT,
    "create_time"     TIMESTAMP(0),
    "update_user"     BIGINT,
    "update_time"     TIMESTAMP(0),
    "tenant_id"       VARCHAR(12),
    "repair_apply_id" BIGINT,
    "file_name"       VARCHAR(100),
    "object_key"      VARCHAR(100),
    "content_type"    VARCHAR(100),
    "link"            VARCHAR(100),
    "file_size"       VARCHAR(100),
    "upload_time"     TIMESTAMP(0),
    NOT               CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_repair_apply_file" IS '维修申请单关联的附件信息';
COMMENT
ON COLUMN "blade_repair_apply_file"."content_type" IS '文件mini类型';
COMMENT
ON COLUMN "blade_repair_apply_file"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_repair_apply_file"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_repair_apply_file"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_repair_apply_file"."file_name" IS '文件名称';
COMMENT
ON COLUMN "blade_repair_apply_file"."id" IS '主键';
COMMENT
ON COLUMN "blade_repair_apply_file"."link" IS '文件外链';
COMMENT
ON COLUMN "blade_repair_apply_file"."file_size" IS '文件大小';
COMMENT
ON COLUMN "blade_repair_apply_file"."object_key" IS '文件key';
COMMENT
ON COLUMN "blade_repair_apply_file"."repair_apply_id" IS '维修申请id';
COMMENT
ON COLUMN "blade_repair_apply_file"."status" IS '状态';
COMMENT
ON COLUMN "blade_repair_apply_file"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_repair_apply_file"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_repair_apply_file"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_repair_apply_file"."upload_time" IS '上传时间';


DROP TABLE IF EXISTS "blade_repair_record";
CREATE TABLE "blade_repair_record"
(
    "id"                    BIGINT NOT NULL,
    "status"                INT,
    "is_deleted"            INT,
    "create_user"           BIGINT,
    "create_dept"           BIGINT,
    "create_time"           TIMESTAMP(0),
    "update_user"           BIGINT,
    "update_time"           TIMESTAMP(0),
    "tenant_id"             VARCHAR(12),
    "repair_apply_id"       BIGINT,
    "record_code"           VARCHAR(128),
    "record_status"         INT,
    "record_type"           INT,
    "error_code"            VARCHAR(32),
    "repair_start_time"     TIMESTAMP(0),
    "repair_end_time"       TIMESTAMP(0),
    "repair_time"           INT,
    "repair_user_id"        BIGINT,
    "repair_user_name"      VARCHAR(64),
    "malfunction_details"   VARCHAR(255),
    "malfunction_time"      TIMESTAMP(0),
    "is_affect"             INT,
    "device_id"             BIGINT,
    "device_code"           VARCHAR(128),
    "device_name"           VARCHAR(64),
    "device_type_id"        BIGINT,
    "device_type_name"      VARCHAR(64),
    "malfunction_id"        BIGINT,
    "malfunction_code"      VARCHAR(128),
    "malfunction_name"      VARCHAR(64),
    "urgency"               INT,
    "repair_nature"         INT,
    "real_malfunction_id"   BIGINT,
    "real_malfunction_code" VARCHAR(128),
    "real_malfunction_name" VARCHAR(64),
    "remark"                VARCHAR(255),
    "apply_time"            TIMESTAMP(0),
    NOT                     CLUSTER PRIMARY KEY ("id"),
    CONSTRAINT "codeIndex" UNIQUE ("record_code"),
    UNIQUE ("record_code", "is_deleted"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_repair_record" IS '维修记录信息';
COMMENT
ON COLUMN "blade_repair_record"."apply_time" IS '需要删除';
COMMENT
ON COLUMN "blade_repair_record"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_repair_record"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_repair_record"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_repair_record"."device_code" IS '设备编码';
COMMENT
ON COLUMN "blade_repair_record"."device_id" IS '设备id';
COMMENT
ON COLUMN "blade_repair_record"."device_name" IS '设备名称';
COMMENT
ON COLUMN "blade_repair_record"."device_type_id" IS '设备类型id';
COMMENT
ON COLUMN "blade_repair_record"."device_type_name" IS '设备类型名称';
COMMENT
ON COLUMN "blade_repair_record"."error_code" IS '故障码';
COMMENT
ON COLUMN "blade_repair_record"."id" IS '主键';
COMMENT
ON COLUMN "blade_repair_record"."is_affect" IS '影响生产：是 1   否 2（例行维修）';
COMMENT
ON COLUMN "blade_repair_record"."malfunction_code" IS '类型编码';
COMMENT
ON COLUMN "blade_repair_record"."malfunction_details" IS '故障详情';
COMMENT
ON COLUMN "blade_repair_record"."malfunction_id" IS '所属故障类型';
COMMENT
ON COLUMN "blade_repair_record"."malfunction_name" IS '故障类型';
COMMENT
ON COLUMN "blade_repair_record"."malfunction_time" IS '发生时间(例行维修)';
COMMENT
ON COLUMN "blade_repair_record"."real_malfunction_code" IS '实际故障类型编码';
COMMENT
ON COLUMN "blade_repair_record"."real_malfunction_id" IS '实际所属故障类型';
COMMENT
ON COLUMN "blade_repair_record"."real_malfunction_name" IS '实际故障类型';
COMMENT
ON COLUMN "blade_repair_record"."record_code" IS '维修记录编号';
COMMENT
ON COLUMN "blade_repair_record"."record_status" IS '维修记录状态：待确认-1 已确认-2';
COMMENT
ON COLUMN "blade_repair_record"."record_type" IS '维修记录类型：临时-1 例行-2';
COMMENT
ON COLUMN "blade_repair_record"."remark" IS '备注';
COMMENT
ON COLUMN "blade_repair_record"."repair_apply_id" IS '维修申请id';
COMMENT
ON COLUMN "blade_repair_record"."repair_end_time" IS '维修完成时间';
COMMENT
ON COLUMN "blade_repair_record"."repair_nature" IS '维修性质(1:厂内;2:委外)';
COMMENT
ON COLUMN "blade_repair_record"."repair_start_time" IS '维修开始时间';
COMMENT
ON COLUMN "blade_repair_record"."repair_time" IS '维修用时（分钟）';
COMMENT
ON COLUMN "blade_repair_record"."repair_user_id" IS '维修负责人id';
COMMENT
ON COLUMN "blade_repair_record"."repair_user_name" IS '维修负责人姓名';
COMMENT
ON COLUMN "blade_repair_record"."status" IS '状态';
COMMENT
ON COLUMN "blade_repair_record"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_repair_record"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_repair_record"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_repair_record"."urgency" IS '紧急度：高-3，中-2，低-1';


DROP TABLE IF EXISTS "blade_repair_record_file";
CREATE TABLE "blade_repair_record_file"
(
    "id"               BIGINT NOT NULL,
    "status"           INT,
    "is_deleted"       INT,
    "create_user"      BIGINT,
    "create_dept"      BIGINT,
    "create_time"      TIMESTAMP(0),
    "update_user"      BIGINT,
    "update_time"      TIMESTAMP(0),
    "tenant_id"        VARCHAR(12),
    "repair_record_id" BIGINT,
    "file_name"        VARCHAR(100),
    "object_key"       VARCHAR(100),
    "content_type"     VARCHAR(100),
    "link"             VARCHAR(100),
    "file_size"        VARCHAR(100),
    "upload_time"      TIMESTAMP(0),
    NOT                CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_repair_record_file" IS '维修记录关联的附件信息';
COMMENT
ON COLUMN "blade_repair_record_file"."content_type" IS '文件mini类型';
COMMENT
ON COLUMN "blade_repair_record_file"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_repair_record_file"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_repair_record_file"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_repair_record_file"."file_name" IS '文件名称';
COMMENT
ON COLUMN "blade_repair_record_file"."id" IS '主键';
COMMENT
ON COLUMN "blade_repair_record_file"."link" IS '文件外链';
COMMENT
ON COLUMN "blade_repair_record_file"."object_key" IS '文件key';
COMMENT
ON COLUMN "blade_repair_record_file"."repair_record_id" IS '维修记录id';
COMMENT
ON COLUMN "blade_repair_record_file"."status" IS '状态';
COMMENT
ON COLUMN "blade_repair_record_file"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_repair_record_file"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_repair_record_file"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_repair_record_file"."file_size" IS '文件大小';
COMMENT
ON COLUMN "blade_repair_record_file"."upload_time" IS '上传时间';


DROP TABLE IF EXISTS "blade_device_material_record";
CREATE TABLE "blade_device_material_record"
(
    "id"            BIGINT NOT NULL,
    "status"        INT,
    "is_deleted"    INT,
    "create_user"   BIGINT,
    "create_dept"   BIGINT,
    "create_time"   TIMESTAMP(0),
    "update_user"   BIGINT,
    "update_time"   TIMESTAMP(0),
    "tenant_id"     VARCHAR(12),
    "record_id"     BIGINT,
    "material_id"   BIGINT,
    "material_code" VARCHAR(128),
    "material_name" VARCHAR(64),
    "record_number" INT,
    "biz_type"      INT,
    "device_id"     BIGINT,
    "user_id"       BIGINT,
    "user_name"     VARCHAR(64),
    "usage_time"    TIMESTAMP(0),
    NOT             CLUSTER PRIMARY KEY ("id"),
    CHECK ("status" >= 0)
) STORAGE(ON "MAIN", CLUSTERBTR);

COMMENT
ON TABLE "blade_device_material_record" IS '备品工况记录表';
COMMENT
ON COLUMN "blade_device_material_record"."biz_type" IS '数据来源（1：维修单；2：保养记录）';
COMMENT
ON COLUMN "blade_device_material_record"."create_dept" IS '创建部门';
COMMENT
ON COLUMN "blade_device_material_record"."create_time" IS '创建时间';
COMMENT
ON COLUMN "blade_device_material_record"."create_user" IS '创建人';
COMMENT
ON COLUMN "blade_device_material_record"."device_id" IS '设备Id';
COMMENT
ON COLUMN "blade_device_material_record"."id" IS '主键';
COMMENT
ON COLUMN "blade_device_material_record"."material_code" IS '备件编码';
COMMENT
ON COLUMN "blade_device_material_record"."material_id" IS '备件Id';
COMMENT
ON COLUMN "blade_device_material_record"."material_name" IS '备件名称';
COMMENT
ON COLUMN "blade_device_material_record"."record_number" IS '数量';
COMMENT
ON COLUMN "blade_device_material_record"."record_id" IS '保养记录Id/维修单Id';
COMMENT
ON COLUMN "blade_device_material_record"."status" IS '状态';
COMMENT
ON COLUMN "blade_device_material_record"."tenant_id" IS '所属租户';
COMMENT
ON COLUMN "blade_device_material_record"."update_time" IS '更新时间';
COMMENT
ON COLUMN "blade_device_material_record"."update_user" IS '更新人';
COMMENT
ON COLUMN "blade_device_material_record"."usage_time" IS '使用时间（维修单或保养记录的结束时间）';
COMMENT
ON COLUMN "blade_device_material_record"."user_id" IS '使用人员id';
COMMENT
ON COLUMN "blade_device_material_record"."user_name" IS '使用人员姓名';



-- 菜单脚本
INSERT INTO blade_menu(id, parent_id, code, name, alias, path, source, sort,
                       category, action, is_open, remark, is_deleted, belong_application, keep_alive)
VALUES (1483604280849457153, 0, 'tpm', '维护保养', 'tpm', '/tpm', 'iconfont saber-weixiubaoyang', 3, 0, 0, 1, '', 0,
        'CPS',
        1),
       (1491221708245405697, 1504059536042172417, 'check_record', '点检记录', 'check_record', '/tpm/check/record/index',
        'iconfont iconicon_savememo', 2, 1, 0, 1, '', 0, 'CPS', 1),
       (1491282994091601922, 1504060956569051137, 'repair_apply', '维修申请', 'repair_apply', '/tpm/repair/apply/index',
        'iconfont iconicon_setting', 1, 1, 0, 1, '', 0, 'CPS', 1),
       (1491309591410286594, 1504030750424768514, 'maintain_plan', '保养计划', 'maintain_plan', '/tpm/maintain/plan/index',
        'iconfont iconicon_work', 1, 1, 0, 1, '', 0, 'CPS', 1),
       (1491940085082005505, 1504030750424768514, 'maintain_record', '保养记录', 'maintain_record',
        '/tpm/maintain/record/index',
        'iconfont icon-caidan', 2, 1, 0, 1, '', 0, 'CPS', 1),
       (1491959985118347265, 1504060956569051137, 'repair_record', '维修记录', 'repair_record', '/tpm/repair/record/index',
        'iconfont iconicon_compile', 2, 1, 0, 1, '', 0, 'CPS', 1),
       (1493780574536388609, 1483604280849457153, 'tpm_notice', '通知待办', 'tpm_notice', '/tpm/notice/index',
        'iconfont iconicon_notice', 9, 1, 0, 1, '', 0, 'CPS', 1),
       (1504030750424768514, 1483604280849457153, 'maintenance', '保养', 'maintenance', '/tpm/maintenance',
        'iconfont iconicon_notice', 1, 1, 0, 1, '', 0, 'CPS', 1),
       (1504059536042172417, 1483604280849457153, 'fixed_point_inspect', '点检', 'fixed_point_inspect',
        '/tpm/fixed-point-inspect', 'iconfont iconicon_sms', 2, 1, 0, 1, '', 0, 'CPS', 1),
       (1504060956569051137, 1483604280849457153, 'repair', '维修', 'repair', '/tpm/service',
        'iconfont iconicon_setting', 3, 1, 0, 1, '', 0, 'CPS', 1),
       (1519861848982163458, 1483604280849457153, 'tpmMaintenance', '保养、维修待确认', 'card', '',
        'iconfont iconicon_send', 11, 3, 0, 1, '', 0, 'CPS', 1),
       (1519862507798269953, 1483604280849457153, 'tpmTheBeyond', '保养计划超期及预警', 'card', '',
        'iconfont iconicon_send', 12, 3, 0, 1, '', 0, 'CPS', 1),
       (1519862661901193218, 1483604280849457153, 'tpmTodayMaintenance', '今日保养、点检及维修', 'card', '',
        'iconfont iconicon_send', 13, 3, 0, 1, '', 0, 'CPS', 1),
       (1595225500642377729, 0, 'hmi_tpm', '维护保养', 'hmi_tpm', '/tpm', '', 1, 1, 0, 1, '', 0, 'HMI', 1);

