Commit ad39a360 authored by 吴文龙's avatar 吴文龙

Update hsiotdb_pgsql_02.sql

parent 2c4a35e1
...@@ -280,37 +280,185 @@ ALTER TABLE "public"."hs_level_role" ADD CONSTRAINT "fkkn8ks2krh0ktkoxf0itq8yx9a ...@@ -280,37 +280,185 @@ ALTER TABLE "public"."hs_level_role" ADD CONSTRAINT "fkkn8ks2krh0ktkoxf0itq8yx9a
SELECT setval('"public"."ts_kv_dictionary_key_id_seq"', 543, true); SELECT setval('"public"."ts_kv_dictionary_key_id_seq"', 543, true);
CREATE VIEW "public"."vcode_key_detail" AS SELECT hs.tenant_id AS tid, CREATE VIEW "public"."vcode_key_detail" AS SELECT hs.tenant_id AS tid,
hs.factory_id AS fid, hs.factory_id AS fid,
hs.factory_name AS fname, hs.factory_name AS fname,
hs.workshop_id AS wid, hs.workshop_id AS wid,
hs.workshop_name AS wname, hs.workshop_name AS wname,
hs.group_id AS grpid, hs.group_id AS grpid,
hs.group_name AS grpname, hs.group_name AS grpname,
hs.gateway_id AS gid, hs.gateway_id AS gid,
hs.gateway_name AS gname, hs.gateway_name AS gname,
hs.key, hs.key,
hs.key_id, hs.key_id,
hs.entity_id AS did, hs.entity_id AS did,
hs.enable, hs.enable,
hs.device_name AS dname, hs.device_name AS dname,
hs.device_type, hs.device_type,
hs.history_lower, hs.history_lower,
hs.history_upper, hs.history_upper,
hs.volume_on_day, hs.volume_on_day,
concat(ts1.dbl_v, ts1.long_v, ts1.str_v) AS val, concat(ts1.dbl_v, ts1.long_v, ts1.str_v) AS val,
ts1.dbl_v, ts1.dbl_v,
ts1.long_v, ts1.long_v,
ts1.str_v, ts1.str_v,
ts1.bool_v, ts1.bool_v,
ts1.json_v, to_jsonb(ts1.json_v) AS json_v,
ts1.ts, ts1.ts,
to_char(timezone('UTC-8'::text, to_timestamp((ts1.ts / 1000)::double precision)), 'yyyy-MM-dd HH24:MI:SS'::text) AS update_time to_char(timezone('UTC-8'::text, to_timestamp((ts1.ts / 1000)::double precision)), 'yyyy-MM-dd HH24:MI:SS'::text) AS update_time
FROM ts_kv_latest ts1, FROM ts_kv_latest ts1,
hs_last_expand_extension hs hs_last_expand_extension hs
WHERE ts1.entity_id = hs.entity_id AND ts1.key = hs.key_id; WHERE ts1.entity_id = hs.entity_id AND ts1.key = hs.key_id AND NOT ((hs.entity_id, hs.key::text) IN ( SELECT ak.entity_id,
ak.attribute_key
FROM attribute_kv ak
WHERE ak.attribute_type::text = 'CLIENT_SCOPE'::text AND ak.entity_type::text = 'DEVICE'::text))
UNION
SELECT hde.tenant_id AS tid,
hde.factory_id AS fid,
c.title AS fname,
hde.workshop_id AS wid,
a.name AS wname,
hde.group_id AS grpid,
a1.name AS grpname,
NULL::uuid AS gid,
NULL::character varying AS gname,
ak.attribute_key AS key,
NULL::integer AS key_id,
ak.entity_id AS did,
NULL::boolean AS enable,
d.name AS dname,
NULL::character varying AS device_type,
NULL::character varying AS history_lower,
NULL::character varying AS history_upper,
NULL::bigint AS volume_on_day,
concat(ak.dbl_v, ak.long_v, ak.str_v) AS val,
ak.dbl_v,
ak.long_v,
ak.str_v,
ak.bool_v,
to_jsonb(ak.json_v) AS json_v,
ak.last_update_ts AS ts,
to_char(timezone('UTC-8'::text, to_timestamp((ak.last_update_ts / 1000)::double precision)), 'yyyy-MM-dd HH24:MI:SS'::text) AS update_time
FROM attribute_kv ak
LEFT JOIN hs_device_extension hde ON hde.id = ak.entity_id
JOIN device d ON hde.id = d.id
LEFT JOIN customer c ON hde.factory_id = c.id
LEFT JOIN asset a ON hde.workshop_id = a.id AND a.type::text = 'workshop'::text
LEFT JOIN asset a1 ON hde.group_id = a1.id AND a.type::text = 'group'::text
WHERE ak.attribute_type::text = 'CLIENT_SCOPE'::text AND ak.entity_type::text = 'DEVICE'::text;
ALTER TABLE "public"."vcode_key_detail" OWNER TO "postgres"; ALTER TABLE "public"."vcode_key_detail" OWNER TO "postgres";
CREATE VIEW "public"."v_device" AS SELECT c.id,
c.name,
c.tenant_id,
c.group_id,
c.group_name,
c.workshop_id,
c.workshop_name,
CASE
WHEN c.gateway = 'false'::text THEN c.factory_id
ELSE d.id
END AS factory_id,
CASE
WHEN c.gateway = 'false'::text THEN c.factory_name
ELSE d.title
END AS factory_name,
c.gateway,
c.created_time,
c.created_time_format
FROM ( SELECT a.id,
a.name,
a.tenant_id,
b.id AS group_id,
b.name AS group_name,
c_1.id AS workshop_id,
c_1.name AS workshop_name,
d_1.id AS factory_id,
d_1.title AS factory_name,
CASE
WHEN (a.additional_info::jsonb ->> 'gateway'::text) IS NOT NULL THEN a.additional_info::jsonb ->> 'gateway'::text
ELSE 'false'::text
END AS gateway,
a.created_time,
to_char(to_timestamp((a.created_time / 1000)::double precision), 'YYYY-MM-DD HH24:MI:SS'::text) AS created_time_format
FROM device a
LEFT JOIN relation ab ON ab.to_id = a.id AND ab.to_type::text = 'DEVICE'::text AND ab.from_type::text = 'ASSET'::text AND ab.relation_type_group::text = 'COMMON'::text AND ab.relation_type::text = 'Contains'::text
LEFT JOIN ( SELECT b_1.id,
b_1.created_time,
b_1.additional_info,
b_1.customer_id,
b_1.name,
b_1.label,
b_1.search_text,
b_1.tenant_id,
b_1.type,
b_1.external_id,
b_1.asset_profile_id
FROM asset b_1
WHERE b_1.type::text = 'group'::text) b ON b.id = ab.from_id
LEFT JOIN relation bc ON bc.to_id = b.id AND bc.to_type::text = 'ASSET'::text AND bc.from_type::text = 'ASSET'::text AND bc.relation_type_group::text = 'COMMON'::text AND bc.relation_type::text = 'Contains'::text
LEFT JOIN ( SELECT b_1.id,
b_1.created_time,
b_1.additional_info,
b_1.customer_id,
b_1.name,
b_1.label,
b_1.search_text,
b_1.tenant_id,
b_1.type,
b_1.external_id,
b_1.asset_profile_id
FROM asset b_1
WHERE b_1.type::text = 'workshop'::text) c_1 ON c_1.id = bc.from_id
LEFT JOIN relation cd_1 ON cd_1.to_id = c_1.id AND cd_1.to_type::text = 'ASSET'::text AND cd_1.from_type::text = 'CUSTOMER'::text AND cd_1.relation_type_group::text = 'COMMON'::text AND cd_1.relation_type::text = 'Contains'::text
LEFT JOIN customer d_1 ON d_1.id = cd_1.from_id) c
LEFT JOIN relation cd ON cd.to_id = c.id AND c.gateway = 'true'::text AND cd.to_type::text = 'DEVICE'::text AND cd.from_type::text = 'CUSTOMER'::text AND cd.relation_type_group::text = 'COMMON'::text AND cd.relation_type::text = 'Contains'::text
LEFT JOIN customer d ON d.id = cd.from_id;
ALTER TABLE "public"."v_device" OWNER TO "postgres";
CREATE VIEW "public"."v_device_from_gateway" AS SELECT a.id,
a.name,
a.tenant_id,
a.factory_id,
a.factory_name,
a.workshop_id,
a.workshop_name,
a.group_id,
a.group_name,
a.created_time,
a.created_time_format,
a.gid::uuid AS gid,
b.name AS gname,
c.factory_id AS g_factory_id,
c.factory_name AS g_factory_name
FROM ( SELECT a_1.id,
a_1.name,
a_1.tenant_id,
a_1.factory_id,
a_1.factory_name,
a_1.workshop_id,
a_1.workshop_name,
a_1.group_id,
a_1.group_name,
a_1.gateway,
a_1.created_time,
a_1.created_time_format,
CASE
WHEN (b_1.additional_info::jsonb ->> 'lastConnectedGateway'::text) IS NOT NULL THEN b_1.additional_info::jsonb ->> 'lastConnectedGateway'::text
ELSE NULL::text
END AS gid
FROM v_device a_1,
device b_1
WHERE a_1.id = b_1.id AND a_1.gateway <> 'true'::text) a
LEFT JOIN device b ON a.gid = b.id::text
LEFT JOIN v_device c ON b.id = c.id AND c.gateway = 'true'::text;
ALTER TABLE "public"."v_device_from_gateway" OWNER TO "postgres";
CREATE UNIQUE INDEX "tcode_model_index" ON "public"."tcode_model" USING btree ( CREATE UNIQUE INDEX "tcode_model_index" ON "public"."tcode_model" USING btree (
"id" "pg_catalog"."uuid_ops" ASC NULLS LAST, "id" "pg_catalog"."uuid_ops" ASC NULLS LAST,
"code" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST "code" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment