/*
 Navicat Premium Data Transfer

 Source Server         : 47.99.83.75（v3生产）
 Source Server Type    : PostgreSQL
 Source Server Version : 120009
 Source Host           : 47.99.83.75:30433
 Source Catalog        : hsiotdb
 Source Schema         : public

 Target Server Type    : PostgreSQL
 Target Server Version : 120009
 File Encoding         : 65001

 Date: 28/11/2022 22:27:44
*/


-- ----------------------------
-- Table structure for tcode_base
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_base";
CREATE TABLE "public"."tcode_base" (
  "id" uuid NOT NULL,
  "item" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "val" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "def" varchar(255) COLLATE "pg_catalog"."default",
  "descript" varchar(255) COLLATE "pg_catalog"."default",
  "sort" varchar(255) COLLATE "pg_catalog"."default",
  "halt" varchar(255) COLLATE "pg_catalog"."default",
  "created_user" uuid,
  "updated_user" uuid,
  "tenant_id" uuid NOT NULL,
  "created_time" int8 DEFAULT 0,
  "updated_time" int8 DEFAULT 0
)
;
ALTER TABLE "public"."tcode_base" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_base"."item" IS '项目';
COMMENT ON COLUMN "public"."tcode_base"."code" IS '代码';
COMMENT ON COLUMN "public"."tcode_base"."val" IS '参数值';
COMMENT ON COLUMN "public"."tcode_base"."def" IS '默认值';
COMMENT ON COLUMN "public"."tcode_base"."descript" IS '描述';
COMMENT ON COLUMN "public"."tcode_base"."halt" IS '是否停用（T-是；F-否）';

-- ----------------------------
-- Table structure for tcode_device
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_device";
CREATE TABLE "public"."tcode_device" (
  "id" uuid NOT NULL,
  "gid" uuid,
  "did" uuid NOT NULL,
  "dname" varchar(255) COLLATE "pg_catalog"."default",
  "knumb" int8,
  "kcnt" int8,
  "sort" varchar(255) COLLATE "pg_catalog"."default",
  "halt" varchar(50) COLLATE "pg_catalog"."default",
  "htime" timestamp(6),
  "created_time" int8 DEFAULT 0,
  "updated_time" int8 DEFAULT 0,
  "created_user" uuid,
  "updated_user" uuid,
  "tenant_id" uuid NOT NULL,
  "mcode" varchar(255) COLLATE "pg_catalog"."default" NOT NULL
)
;
ALTER TABLE "public"."tcode_device" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_device"."id" IS '主键';
COMMENT ON COLUMN "public"."tcode_device"."gid" IS '网关ID';
COMMENT ON COLUMN "public"."tcode_device"."did" IS '设备ID';
COMMENT ON COLUMN "public"."tcode_device"."dname" IS '设备名称';
COMMENT ON COLUMN "public"."tcode_device"."knumb" IS '设备属性数量';
COMMENT ON COLUMN "public"."tcode_device"."kcnt" IS '属性采集总量';
COMMENT ON COLUMN "public"."tcode_device"."sort" IS '排序';
COMMENT ON COLUMN "public"."tcode_device"."halt" IS '停用：默认F,T为停用';
COMMENT ON COLUMN "public"."tcode_device"."htime" IS '心跳时间';
COMMENT ON COLUMN "public"."tcode_device"."mcode" IS '物模型代码';

-- ----------------------------
-- Table structure for tcode_group
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_group";
CREATE TABLE "public"."tcode_group" (
  "tid" uuid NOT NULL,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "descript" varchar(255) COLLATE "pg_catalog"."default",
  "arr" time(6),
  "dep" time(6),
  "tdays" int4 DEFAULT 0
)
;
ALTER TABLE "public"."tcode_group" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_group"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."tcode_group"."code" IS '代码';
COMMENT ON COLUMN "public"."tcode_group"."descript" IS '班组描述';
COMMENT ON COLUMN "public"."tcode_group"."arr" IS '开始时间';
COMMENT ON COLUMN "public"."tcode_group"."dep" IS '结束时间';
COMMENT ON COLUMN "public"."tcode_group"."tdays" IS '是否跨日';

-- ----------------------------
-- Table structure for tcode_group_days
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_group_days";
CREATE TABLE "public"."tcode_group_days" (
  "tid" uuid NOT NULL,
  "arr" time(6),
  "dep" time(6),
  "tdays" int4 DEFAULT 0
)
;
ALTER TABLE "public"."tcode_group_days" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_group_days"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."tcode_group_days"."arr" IS '每日开始时间';
COMMENT ON COLUMN "public"."tcode_group_days"."dep" IS '每日结束时间';
COMMENT ON COLUMN "public"."tcode_group_days"."tdays" IS '是否跨日';

-- ----------------------------
-- Table structure for tcode_group_electric
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_group_electric";
CREATE TABLE "public"."tcode_group_electric" (
  "tid" uuid NOT NULL,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "arr" time(6),
  "dep" time(6),
  "tdays" int4
)
;
ALTER TABLE "public"."tcode_group_electric" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_group_electric"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."tcode_group_electric"."code" IS '峰电peak，谷电valley';
COMMENT ON COLUMN "public"."tcode_group_electric"."arr" IS '开始时间';
COMMENT ON COLUMN "public"."tcode_group_electric"."dep" IS '结束时间';
COMMENT ON COLUMN "public"."tcode_group_electric"."tdays" IS '是否跨日，1为跨日';

-- ----------------------------
-- Table structure for tcode_model
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_model";
CREATE TABLE "public"."tcode_model" (
  "id" uuid NOT NULL,
  "gid" uuid,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "name" varchar(255) COLLATE "pg_catalog"."default",
  "created_user" uuid,
  "updated_user" uuid,
  "driver_version" varchar(255) COLLATE "pg_catalog"."default",
  "tenant_id" uuid NOT NULL,
  "updated_time" int8,
  "created_time" int8
)
;
ALTER TABLE "public"."tcode_model" OWNER TO "postgres";

-- ----------------------------
-- Table structure for tcode_model_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_model_detail";
CREATE TABLE "public"."tcode_model_detail" (
  "id" uuid NOT NULL,
  "gid" uuid,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "base_id" uuid,
  "unit_id" uuid,
  "kup" varchar(255) COLLATE "pg_catalog"."default",
  "kdwn" varchar(255) COLLATE "pg_catalog"."default",
  "ksetup" varchar(255) COLLATE "pg_catalog"."default",
  "sort" varchar(255) COLLATE "pg_catalog"."default" DEFAULT '1000'::character varying,
  "halt" char(1) COLLATE "pg_catalog"."default" DEFAULT 'F'::bpchar,
  "ex_s1" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s2" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s3" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s4" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s5" varchar(255) COLLATE "pg_catalog"."default",
  "created_user" uuid,
  "updated_user" uuid,
  "standard" varchar(255) COLLATE "pg_catalog"."default",
  "hour" bool,
  "day" bool,
  "change" bool,
  "tenant_id" uuid NOT NULL,
  "val" varchar(255) COLLATE "pg_catalog"."default",
  "created_time" int8,
  "updated_time" int8,
  "kup_time" int8,
  "ksetup_time" int8,
  "kdwn_time" int8
)
;
ALTER TABLE "public"."tcode_model_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_model_detail"."id" IS '属性ID';
COMMENT ON COLUMN "public"."tcode_model_detail"."gid" IS '网关ID';
COMMENT ON COLUMN "public"."tcode_model_detail"."code" IS '模型代码';
COMMENT ON COLUMN "public"."tcode_model_detail"."key" IS '属性key';
COMMENT ON COLUMN "public"."tcode_model_detail"."base_id" IS '分组ID(base)';
COMMENT ON COLUMN "public"."tcode_model_detail"."unit_id" IS '单位ID';
COMMENT ON COLUMN "public"."tcode_model_detail"."kup" IS '上限值';
COMMENT ON COLUMN "public"."tcode_model_detail"."kdwn" IS '下限值';
COMMENT ON COLUMN "public"."tcode_model_detail"."ksetup" IS '设定值';
COMMENT ON COLUMN "public"."tcode_model_detail"."sort" IS '排序';
COMMENT ON COLUMN "public"."tcode_model_detail"."halt" IS '是否停用';
COMMENT ON COLUMN "public"."tcode_model_detail"."ex_s1" IS '扩展字段1';
COMMENT ON COLUMN "public"."tcode_model_detail"."ex_s2" IS '扩展字段2';
COMMENT ON COLUMN "public"."tcode_model_detail"."ex_s3" IS '扩展字段3';
COMMENT ON COLUMN "public"."tcode_model_detail"."ex_s4" IS '扩展字段4';
COMMENT ON COLUMN "public"."tcode_model_detail"."ex_s5" IS '扩展字段5';
COMMENT ON COLUMN "public"."tcode_model_detail"."standard" IS '标准值';
COMMENT ON COLUMN "public"."tcode_model_detail"."hour" IS '每小时存储';
COMMENT ON COLUMN "public"."tcode_model_detail"."day" IS '每天存储';
COMMENT ON COLUMN "public"."tcode_model_detail"."change" IS '属性值变化存储';
COMMENT ON COLUMN "public"."tcode_model_detail"."val" IS '属性名';
COMMENT ON COLUMN "public"."tcode_model_detail"."kup_time" IS '上限值时间';
COMMENT ON COLUMN "public"."tcode_model_detail"."ksetup_time" IS '设定值更新时间';
COMMENT ON COLUMN "public"."tcode_model_detail"."kdwn_time" IS '下限值设定时间';

-- ----------------------------
-- Table structure for tcode_model_detail_ex
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_model_detail_ex";
CREATE TABLE "public"."tcode_model_detail_ex" (
  "tid" uuid NOT NULL,
  "gid" uuid,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "grpcode" varchar(255) COLLATE "pg_catalog"."default",
  "unit_id" varchar(255) COLLATE "pg_catalog"."default",
  "kup" varchar(255) COLLATE "pg_catalog"."default",
  "kup_time" timestamp(6),
  "kdwn" varchar(255) COLLATE "pg_catalog"."default",
  "kdwn_time" timestamp(6),
  "ksetup" varchar(255) COLLATE "pg_catalog"."default",
  "ksetup_time" timestamp(6),
  "sort" varchar(255) COLLATE "pg_catalog"."default" DEFAULT '1000'::character varying,
  "halt" char(1) COLLATE "pg_catalog"."default" DEFAULT 'F'::bpchar,
  "ex_s1" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s2" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s3" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s4" varchar(255) COLLATE "pg_catalog"."default",
  "ex_s5" varchar(255) COLLATE "pg_catalog"."default",
  "ctime" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "mtime" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "name" varchar(255) COLLATE "pg_catalog"."default"
)
;
ALTER TABLE "public"."tcode_model_detail_ex" OWNER TO "postgres";
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."gid" IS '网关ID';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."code" IS '模型代码';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."key" IS '属性名称';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."grpcode" IS '分组ID';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."unit_id" IS '单位ID';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."kup" IS '上限值';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."kup_time" IS '上限值时间';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."kdwn" IS '下限值';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."kdwn_time" IS '下限值时间';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ksetup" IS '设定值';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ksetup_time" IS '设定值更新时间';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."sort" IS '排序';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."halt" IS '是否停用';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ex_s1" IS '扩展字段1';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ex_s2" IS '扩展字段2';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ex_s3" IS '扩展字段3';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ex_s4" IS '扩展字段4';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ex_s5" IS '扩展字段5';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."ctime" IS '创建时间';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."mtime" IS '修改时间';
COMMENT ON COLUMN "public"."tcode_model_detail_ex"."name" IS '显示名称';

-- ----------------------------
-- Table structure for tcode_model_ex
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_model_ex";
CREATE TABLE "public"."tcode_model_ex" (
  "tid" uuid NOT NULL,
  "gid" uuid,
  "code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "name" varchar(255) COLLATE "pg_catalog"."default",
  "ctime" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "mtime" timestamp(6) DEFAULT CURRENT_TIMESTAMP
)
;
ALTER TABLE "public"."tcode_model_ex" OWNER TO "postgres";

-- ----------------------------
-- Table structure for tcode_unit
-- ----------------------------
DROP TABLE IF EXISTS "public"."tcode_unit";
CREATE TABLE "public"."tcode_unit" (
  "id" uuid NOT NULL,
  "descript" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "created_user" uuid,
  "updated_user" uuid,
  "tenant_id" uuid NOT NULL,
  "created_time" int8 DEFAULT 0,
  "updated_time" int8 DEFAULT 0
)
;
ALTER TABLE "public"."tcode_unit" OWNER TO "postgres";

-- ----------------------------
-- Table structure for trep_day_sta_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_day_sta_detail";
CREATE TABLE "public"."trep_day_sta_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "bdate" date NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "val" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "cron" int8 DEFAULT 20,
  "len" int8,
  "time" int8,
  "ctime" timestamp(6),
  "mtime" timestamp(6),
  "created_time" int8,
  "updated_time" int8
)
;
ALTER TABLE "public"."trep_day_sta_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_day_sta_detail"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."did" IS '设备ID';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."bdate" IS '营业日期';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."key" IS '属性名称';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."val" IS '属性值';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."cron" IS '更新频率';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."len" IS '计数器';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."time" IS '累计时间单位秒';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."ctime" IS '创建时间';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."mtime" IS '修改时间';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."created_time" IS '创建时间long类型';
COMMENT ON COLUMN "public"."trep_day_sta_detail"."updated_time" IS '修改时间long类型';

-- ----------------------------
-- Table structure for trep_dkey_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_dkey_detail";
CREATE TABLE "public"."trep_dkey_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "bdate" date NOT NULL,
  "val" varchar(255) COLLATE "pg_catalog"."default",
  "ctime" timestamp(6),
  "mtime" timestamp(6),
  "val_arr" varchar(255) COLLATE "pg_catalog"."default",
  "val_dep" varchar(255) COLLATE "pg_catalog"."default",
  "peak" varchar(255) COLLATE "pg_catalog"."default",
  "valley" varchar(255) COLLATE "pg_catalog"."default"
)
;
ALTER TABLE "public"."trep_dkey_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_dkey_detail"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."trep_dkey_detail"."did" IS '设备ID';
COMMENT ON COLUMN "public"."trep_dkey_detail"."key" IS '属性';
COMMENT ON COLUMN "public"."trep_dkey_detail"."bdate" IS '营业日期';
COMMENT ON COLUMN "public"."trep_dkey_detail"."val" IS '最新遥测值-废弃';
COMMENT ON COLUMN "public"."trep_dkey_detail"."ctime" IS '创建时间';
COMMENT ON COLUMN "public"."trep_dkey_detail"."mtime" IS '修改时间';
COMMENT ON COLUMN "public"."trep_dkey_detail"."val_arr" IS '遥测值开始';
COMMENT ON COLUMN "public"."trep_dkey_detail"."val_dep" IS '遥测值结束';
COMMENT ON COLUMN "public"."trep_dkey_detail"."peak" IS '峰电-电能属性有效';
COMMENT ON COLUMN "public"."trep_dkey_detail"."valley" IS '谷电-电能属性有效';

-- ----------------------------
-- Table structure for trep_group_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_group_detail";
CREATE TABLE "public"."trep_group_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "bdate" date NOT NULL,
  "grpcode" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "val_arr" varchar(255) COLLATE "pg_catalog"."default",
  "val_dep" varchar(255) COLLATE "pg_catalog"."default",
  "ctime" timestamp(6) DEFAULT now(),
  "mtime" timestamp(6) DEFAULT now()
)
;
ALTER TABLE "public"."trep_group_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_group_detail"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."trep_group_detail"."did" IS '设备ID';
COMMENT ON COLUMN "public"."trep_group_detail"."key" IS '属性';
COMMENT ON COLUMN "public"."trep_group_detail"."bdate" IS '营业日期';
COMMENT ON COLUMN "public"."trep_group_detail"."grpcode" IS '班组code';
COMMENT ON COLUMN "public"."trep_group_detail"."val_arr" IS '遥测值开始';
COMMENT ON COLUMN "public"."trep_group_detail"."val_dep" IS '遥测值结束';
COMMENT ON COLUMN "public"."trep_group_detail"."ctime" IS '创建时间';
COMMENT ON COLUMN "public"."trep_group_detail"."mtime" IS '修改时间';

-- ----------------------------
-- Table structure for trep_group_sta_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_group_sta_detail";
CREATE TABLE "public"."trep_group_sta_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "bdate" date NOT NULL,
  "grpcode" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "val" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "cron" int8 DEFAULT 20,
  "len" int8 DEFAULT 1,
  "time" int8 DEFAULT 20,
  "ctime" timestamp(6),
  "mtime" timestamp(6),
  "created_time" int8,
  "updated_time" int8
)
;
ALTER TABLE "public"."trep_group_sta_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_group_sta_detail"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."did" IS '设备ID';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."bdate" IS '营业日期';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."grpcode" IS '班组代码';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."key" IS '属性名称';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."val" IS '属性值';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."cron" IS '执行频率';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."len" IS '计数器';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."time" IS '累计时间单位秒';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."ctime" IS '创建时间';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."mtime" IS '修改时间';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."created_time" IS '创建时间long类型';
COMMENT ON COLUMN "public"."trep_group_sta_detail"."updated_time" IS '修改时间long类型';

-- ----------------------------
-- Table structure for trep_hkey_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_hkey_detail";
CREATE TABLE "public"."trep_hkey_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "bdate" date NOT NULL,
  "hours" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "val" varchar(255) COLLATE "pg_catalog"."default",
  "ctime" timestamp(6),
  "mtime" timestamp(6),
  "val_arr" varchar(255) COLLATE "pg_catalog"."default",
  "val_dep" varchar(255) COLLATE "pg_catalog"."default",
  "peak" varchar(255) COLLATE "pg_catalog"."default",
  "valley" varchar(255) COLLATE "pg_catalog"."default"
)
;
ALTER TABLE "public"."trep_hkey_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_hkey_detail"."peak" IS '峰电';
COMMENT ON COLUMN "public"."trep_hkey_detail"."valley" IS '谷电';

-- ----------------------------
-- Table structure for trep_hours_sta_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_hours_sta_detail";
CREATE TABLE "public"."trep_hours_sta_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "bdate" date NOT NULL,
  "hours" int4 NOT NULL,
  "cron" int8 DEFAULT 20,
  "len" int8 DEFAULT 1,
  "ctime" timestamp(6),
  "mtime" timestamp(6),
  "val" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "time" int8,
  "created_time" int8,
  "updated_time" int8
)
;
ALTER TABLE "public"."trep_hours_sta_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."tid" IS '租户ID';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."did" IS '设备ID';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."key" IS '属性';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."bdate" IS '营业日期';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."hours" IS '小时';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."cron" IS '统计周期，耗时算法：20s执行周期cron*len为当前状态持续时长';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."len" IS '计数器默认1';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."ctime" IS '开始时间';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."mtime" IS '结束时间';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."val" IS '状态值';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."time" IS '时长s';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."created_time" IS '开始时间long类型';
COMMENT ON COLUMN "public"."trep_hours_sta_detail"."updated_time" IS '结束时间long类型';

-- ----------------------------
-- Table structure for trep_hsta_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_hsta_detail";
CREATE TABLE "public"."trep_hsta_detail" (
  "aid" int8,
  "tid" uuid,
  "did" uuid,
  "key" varchar(255) COLLATE "pg_catalog"."default",
  "val" varchar(255) COLLATE "pg_catalog"."default",
  "arr" timestamp(6) DEFAULT now(),
  "dep" timestamp(6) DEFAULT now()
)
;
ALTER TABLE "public"."trep_hsta_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_hsta_detail"."aid" IS '自增长id';
COMMENT ON COLUMN "public"."trep_hsta_detail"."tid" IS '租户id';
COMMENT ON COLUMN "public"."trep_hsta_detail"."did" IS '设备id';
COMMENT ON COLUMN "public"."trep_hsta_detail"."key" IS '属性';
COMMENT ON COLUMN "public"."trep_hsta_detail"."val" IS '属性值';
COMMENT ON COLUMN "public"."trep_hsta_detail"."arr" IS '开始时间';
COMMENT ON COLUMN "public"."trep_hsta_detail"."dep" IS '结束时间';

-- ----------------------------
-- Table structure for trep_sta_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."trep_sta_detail";
CREATE TABLE "public"."trep_sta_detail" (
  "tid" uuid NOT NULL,
  "did" uuid NOT NULL,
  "key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "val_arr" varchar(255) COLLATE "pg_catalog"."default",
  "val_dep" varchar(255) COLLATE "pg_catalog"."default",
  "ctime" timestamp(6) DEFAULT now(),
  "mtime" timestamp(6) DEFAULT now()
)
;
ALTER TABLE "public"."trep_sta_detail" OWNER TO "postgres";
COMMENT ON COLUMN "public"."trep_sta_detail"."tid" IS '租户id';
COMMENT ON COLUMN "public"."trep_sta_detail"."did" IS '设备id';
COMMENT ON COLUMN "public"."trep_sta_detail"."key" IS '属性key';
COMMENT ON COLUMN "public"."trep_sta_detail"."val_arr" IS '首次统计属性值';
COMMENT ON COLUMN "public"."trep_sta_detail"."val_dep" IS '最后统计属性值';
COMMENT ON COLUMN "public"."trep_sta_detail"."ctime" IS '创建时间';
COMMENT ON COLUMN "public"."trep_sta_detail"."mtime" IS '修改时间';

-- ----------------------------
-- Indexes structure for table tcode_base
-- ----------------------------
CREATE UNIQUE INDEX "tcode_base_item_code_val_tenant_id_idx" ON "public"."tcode_base" USING btree (
  "item" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "code" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "val" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" "pg_catalog"."uuid_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table tcode_base
-- ----------------------------
ALTER TABLE "public"."tcode_base" ADD CONSTRAINT "tcode_base_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table tcode_device
-- ----------------------------
CREATE UNIQUE INDEX "tcode_device_index" ON "public"."tcode_device" USING btree (
  "id" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "did" "pg_catalog"."uuid_ops" ASC NULLS LAST
);

-- ----------------------------
-- Uniques structure for table tcode_device
-- ----------------------------
ALTER TABLE "public"."tcode_device" ADD CONSTRAINT "tcode_device_mcode_tenant_id_did_key" UNIQUE ("mcode", "tenant_id", "did");

-- ----------------------------
-- Primary Key structure for table tcode_device
-- ----------------------------
ALTER TABLE "public"."tcode_device" ADD CONSTRAINT "tcode_device_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Primary Key structure for table tcode_group
-- ----------------------------
ALTER TABLE "public"."tcode_group" ADD CONSTRAINT "tcode_group_pkey" PRIMARY KEY ("tid", "code");

-- ----------------------------
-- Primary Key structure for table tcode_group_days
-- ----------------------------
ALTER TABLE "public"."tcode_group_days" ADD CONSTRAINT "tcode_group_days_pkey" PRIMARY KEY ("tid");

-- ----------------------------
-- Primary Key structure for table tcode_group_electric
-- ----------------------------
ALTER TABLE "public"."tcode_group_electric" ADD CONSTRAINT "tcode_group_electric_pkey" PRIMARY KEY ("tid", "code");

-- ----------------------------
-- Indexes structure for table tcode_model
-- ----------------------------
CREATE UNIQUE INDEX "tcode_model_index" ON "public"."tcode_model" USING btree (
  "id" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "code" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Uniques structure for table tcode_model
-- ----------------------------
ALTER TABLE "public"."tcode_model" ADD CONSTRAINT "tcode_model_tenant_id_code_key" UNIQUE ("tenant_id", "code");

-- ----------------------------
-- Primary Key structure for table tcode_model
-- ----------------------------
ALTER TABLE "public"."tcode_model" ADD CONSTRAINT "tcode_model_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Uniques structure for table tcode_model_detail
-- ----------------------------
ALTER TABLE "public"."tcode_model_detail" ADD CONSTRAINT "tcode_model_detail_code_key_tenant_id_key" UNIQUE ("code", "key", "tenant_id");

-- ----------------------------
-- Primary Key structure for table tcode_model_detail
-- ----------------------------
ALTER TABLE "public"."tcode_model_detail" ADD CONSTRAINT "tcode_model_detail_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table tcode_model_ex
-- ----------------------------
CREATE UNIQUE INDEX "tcode_model_ex_index" ON "public"."tcode_model_ex" USING btree (
  "tid" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "code" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Indexes structure for table tcode_unit
-- ----------------------------
CREATE INDEX "tcode_unit_descript_tenant_id_idx" ON "public"."tcode_unit" USING btree (
  "descript" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" "pg_catalog"."uuid_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table tcode_unit
-- ----------------------------
ALTER TABLE "public"."tcode_unit" ADD CONSTRAINT "tcode_unit_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Primary Key structure for table trep_day_sta_detail
-- ----------------------------
ALTER TABLE "public"."trep_day_sta_detail" ADD CONSTRAINT "trep_day_sta_detail_pkey" PRIMARY KEY ("tid", "did", "bdate", "key", "val");

-- ----------------------------
-- Indexes structure for table trep_dkey_detail
-- ----------------------------
CREATE UNIQUE INDEX "trep_dkey_detail_index" ON "public"."trep_dkey_detail" USING btree (
  "tid" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "did" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "key" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "bdate" "pg_catalog"."date_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table trep_dkey_detail
-- ----------------------------
ALTER TABLE "public"."trep_dkey_detail" ADD CONSTRAINT "trep_dkey_detail_pkey" PRIMARY KEY ("tid", "did", "key", "bdate");

-- ----------------------------
-- Indexes structure for table trep_group_detail
-- ----------------------------
CREATE UNIQUE INDEX "trep_group_detail_index" ON "public"."trep_group_detail" USING btree (
  "tid" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "did" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "key" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "bdate" "pg_catalog"."date_ops" ASC NULLS LAST,
  "grpcode" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table trep_group_detail
-- ----------------------------
ALTER TABLE "public"."trep_group_detail" ADD CONSTRAINT "trep_group_detail_pkey" PRIMARY KEY ("tid", "did", "key", "bdate", "grpcode");

-- ----------------------------
-- Primary Key structure for table trep_group_sta_detail
-- ----------------------------
ALTER TABLE "public"."trep_group_sta_detail" ADD CONSTRAINT "trep_group_sta_detail_pkey" PRIMARY KEY ("tid", "did", "bdate", "grpcode", "key", "val");

-- ----------------------------
-- Indexes structure for table trep_hkey_detail
-- ----------------------------
CREATE UNIQUE INDEX "trep_hkey_detail_index1" ON "public"."trep_hkey_detail" USING btree (
  "tid" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "did" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "key" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "bdate" "pg_catalog"."date_ops" ASC NULLS LAST,
  "hours" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "val" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table trep_hkey_detail
-- ----------------------------
ALTER TABLE "public"."trep_hkey_detail" ADD CONSTRAINT "trep_hkey_detail_pkey" PRIMARY KEY ("tid", "did", "key", "bdate", "hours");

-- ----------------------------
-- Primary Key structure for table trep_hours_sta_detail
-- ----------------------------
ALTER TABLE "public"."trep_hours_sta_detail" ADD CONSTRAINT "trep_hours_sta_detail_pkey" PRIMARY KEY ("tid", "did", "key", "bdate", "hours", "val");

-- ----------------------------
-- Primary Key structure for table trep_hsta_detail
-- ----------------------------
ALTER TABLE "public"."trep_hsta_detail" ADD CONSTRAINT "trep_sta_hdetail_pkey" PRIMARY KEY ("aid");

-- ----------------------------
-- Indexes structure for table trep_sta_detail
-- ----------------------------
CREATE UNIQUE INDEX "trep_sta_detail_index1" ON "public"."trep_sta_detail" USING btree (
  "tid" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "did" "pg_catalog"."uuid_ops" ASC NULLS LAST,
  "key" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table trep_sta_detail
-- ----------------------------
ALTER TABLE "public"."trep_sta_detail" ADD CONSTRAINT "trep_sta_detail_pkey" PRIMARY KEY ("tid", "did", "key");


CREATE SEQUENCE trep_sta_hdetail_aid_seq
  START WITH 1
  INCREMENT BY 1
  NO MINVALUE
  NO MAXVALUE
  CACHE 1;

alter table trep_hsta_detail alter column aid set default nextval('trep_sta_hdetail_aid_seq');