CREATE DATABASE `saas_account` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use `saas_account`;

create table `ac_company` (
  id int unsigned primary key not null auto_increment,
  name varchar(500) not null comment '名称',
  business_code varchar(100) comment '商业登记证号',
  address varchar(500) comment '注册地址',
  logo_url varchar(500) comment 'Logo',
  creator_id int unsigned,
  create_time datetime,
  updater_id int unsigned,
  update_time datetime
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='公司';

create table `ac_account` (
  id int unsigned primary key not null auto_increment,
  username varchar(100) not null comment '账号',
  password varchar(100) not null comment '加密密码',
  salt varchar(100) not null comment '加密盐值',
  realname varchar(100) comment '真实姓名',
  email varchar(100) comment '邮箱',
  mobile varchar(100) not null comment '手机号',
  type int comment '账户类型 0, 1',
  creator_id int unsigned,
  create_time datetime,
  updater_id int unsigned,
  update_time datetime
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='个人账户';

create table `ac_account_company` (
  company_id int unsigned,
  account_id int unsigned
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='账户绑定企业';

create table `ac_role` (
  id int unsigned primary key not null auto_increment,
  code varchar(100) not null comment '编号',
  name varchar(300) not null comment '名称',
  description varchar(1000) comment '描述',
  company_id int unsigned,
  creator_id int unsigned,
  create_time datetime,
  updater_id int unsigned,
  update_time datetime
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色';

create table `ac_account_role` (
  account_id int unsigned,
  role_id int unsigned
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='账户绑定角色';

create table `ac_resource` (
  id int unsigned primary key not null auto_increment,
  code varchar(100) not null comment '编号',
  name varchar(300) not null comment '名称',
  description varchar(1000) comment '描述',
  type varchar(100) comment '类型 MENU,BUTTON,API',
  url varchar(300) comment 'URL',
  method varchar(10) comment 'Http Method: POST/GET/PUT/DELETE',
  order_num int,
  company_id int unsigned,
  creator_id int unsigned,
  create_time datetime,
  updater_id int unsigned,
  update_time datetime
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色';

create table `ac_role_resource` (
  role_id int unsigned,
  resource_id int unsigned
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色绑定资源';

insert into ac_account(id,username,password,salt,realname,email,mobile,type,
                       creator_id,create_time,updater_id,update_time)
values (1,'18888888888','3e8451e274a8ee847872194e584a4145','18888888888','Administrator',
          'admin@usoftchina.com', '18888888888', 0, 1, now(), 1, now());

insert into ac_company(name, business_code, address, logo_url, creator_id, create_time, updater_id, update_time)
values ('测试账套', '000000000000000000','深圳市南山区粤海街道高新技术产业园科技南五路英唐大厦六楼',
        'https://co-image.qichacha.com/CompanyImage/104eb3c232bbac93393a5e204d6a47d1.jpg?x-oss-process=style/qcc_cmp',
        1, now(), 1, now());
