drop table if exists public.p_user;
create table public.p_user (
	user_id varchar(32) null,
	login_name varchar(500) null,
	login_password varchar(500) null,
	user_name varchar(500) null,
	mobile_number varchar(500) null,
	police_number varchar(500) not null,
	id_number varchar(500) null,
	effective varchar(1) null default 1,
	department_id varchar(500) null,
	create_time timestamp(6) null default now(),
	update_time timestamp(6) null,
	job_title varchar(200) null,
	role_level varchar(10) not null default 1,
	id int8 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
	roles varchar(255) null,
	constraint p_user_pkey primary key (id)
);
create index idx_dep on public.p_user using btree (department_id);
create index idx_dep_branch on public.p_user using btree (substr((department_id)::text, 1, 6));
create index idx_dep_station on public.p_user using btree (substr((department_id)::text, 1, 8));
create index idx_uid on public.p_user using btree (user_id);
comment on column public.p_user.user_id is '用户编号';
comment on column public.p_user.login_name is '用户名(登录账号)';
comment on column public.p_user.login_password is '用户密码(登录密码)';
comment on column public.p_user.user_name is '用户姓名';
comment on column public.p_user.mobile_number is '手机号';
comment on column public.p_user.police_number is '警员编号(警号)';
comment on column public.p_user.id_number is '身份证号';
comment on column public.p_user.effective is '是否启用:0 无效 1有效 默认 1';
comment on column public.p_user.department_id is '所属单位编号';
comment on column public.p_user.create_time is '创建时间';
comment on column public.p_user.update_time is '更新时间';
comment on column public.p_user.job_title is '职称';
comment on column public.p_user.role_level is '等级：0运营 1派出所 2分局';
comment on column public.p_user.roles is 'role id以逗号拼接';

drop table if exists public.p_role;
create table public.p_role (
	id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
	role_type varchar(10) null,
	role_name varchar(255) null,
	role_desc varchar(255) null,
	create_at date null,
	create_by varchar(255) null,
	update_at date null,
	update_by varchar(255) null,
	deleted int2 null,
	data_scope int4 null
);
comment on column public.p_role.role_type is '角色类型-字典表jslx';
comment on column public.p_role.role_name is '角色名';
comment on column public.p_role.role_desc is '角色描述';
comment on column public.p_role.create_at is '创建时间';
comment on column public.p_role.create_by is '创建人';
comment on column public.p_role.update_at is '修改时间';
comment on column public.p_role.update_by is '修改人';
comment on column public.p_role.deleted is '删除标记 0-未删除 1-已删除';
comment on column public.p_role.data_scope is '数据权限定义 1-全部权限 2-本部门及以下部门  3-本部门 4-本人 5-自定义';

drop table if exists public.p_scene;
create table public.p_scene (
	id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
	scene_name varchar(255) null,
	scene_remark varchar(500) null,
	roles varchar(100) null,
	model_notes varchar(1000) null,
	file_url varchar(255) null,
	"version" varchar(20) null,
	contribution_name varchar(255) null,
	scene_type int2 null,
	scene_url varchar(255) null,
	scene_skin varchar(16) null,
	icon_url varchar(255) null,
	create_at date null,
	create_by varchar(255) null,
	update_at date null,
	update_by varchar(255) null,
	deleted int2 null,
	scene_operation varchar(255) null,
	scene_order int4 null,
	scene_code varchar(255) null,
	scene_tag varchar(200) null
);
comment on column public.p_scene.scene_name is '场景名称';
comment on column public.p_scene.scene_remark is '场景说明';
comment on column public.p_scene.roles is '适用角色 逗号拼接串';
comment on column public.p_scene.model_notes is '模型逻辑说明';
comment on column public.p_scene.file_url is '文件上传路径';
comment on column public.p_scene."version" is '版本';
comment on column public.p_scene.contribution_name is '贡献者姓名';
comment on column public.p_scene.scene_type is '1：定制 2：永洪编排';
comment on column public.p_scene.scene_url is '场景url';
comment on column public.p_scene.icon_url is 'icon图片地址';
comment on column public.p_scene.create_at is '创建时间';
comment on column public.p_scene.create_by is '创建人';
comment on column public.p_scene.update_at is '修改时间';
comment on column public.p_scene.update_by is '更新人';
comment on column public.p_scene.deleted is '删除标记：0-未删除 1-已删除';
comment on column public.p_scene.scene_operation is '智能脑，聪明口，灵活手，千里眼';
comment on column public.p_scene.scene_order is '排序';
comment on column public.p_scene.scene_code is '场景编码';
comment on column public.p_scene.scene_tag is '技能标签';
