-- 10.1.init.sql

/*
将 paas.example.com 替换为 paas.学校域名.edu.cn
*/


-- 以下脚本为可选操作

/*
 * 若部署了流程平台、门户的产品
 * 可默认创建几个管理员帐号，以及初始授权
 */


-- 创建管理帐号

use user;

-- flowadmin
INSERT INTO `TB_B_USER` (`ID`, `DELETED`, 
  `UID`, `PASSWORD`, `NAME`, `NAME_SPELLING`, `FULL_NAME_SPELLING`, 
  `CERTIFICATE_TYPE_ID`, `CERTIFICATE_NUMBER`, `PHONE_NUMBER`, `EMAIL`,
  `GENDER_ID`, `NATION_ID`, `COUNTRY_ID`, `ADDRESS_ID`)
VALUES ('50', 0, 
  '50', 'flowadmin', '流程表单管理员', 'flowadmin', 'flowadmin', 
  '20001', '50', null, 'flowadmin@supwisdom.com',
  '30001', '40001', '50156', '310000');

INSERT INTO `TB_B_ACCOUNT` (`ID`, `DELETED`, `USER_ID`, 
  `ACCOUNT_NAME`, `ACCOUNT_EXPIRY_DATE`, `ORGANIZATION_ID`, `IDENTITY_TYPE_ID`, 
  `ACTIVATION`, `STATE`, `IS_DATA_CENTER`)
VALUES ('50', 0, '50', 
  'flowadmin', null, '1', '1',
  1, 'NORMAL', 0);

INSERT INTO `TB_B_SAFETY`(`ID`, `DELETED`, `USER_ID`, `SCORE`, `PASSWORD_SCORE`, `SECURE_EMAIL`, `SECURE_PHONE`)
VALUES ('50', 0, '50', '0', '0', null, null);

INSERT INTO `TB_B_ACCOUNT_ORGANIZATION` (`ID`, `DELETED`, 
  `ROOT_ORGANIZATION_ID`, `ACCOUNT_ID`, `ORGANIZATION_ID`)
VALUES ('50_1', 0, 
  '0', '50', '1');

INSERT INTO `TB_B_ACCOUNT_LABEL`(`ID`, `DELETED`, 
  `ACCOUNT_ID`, `LABEL_ID`)
VALUES ('50_1', 0, '50', '1');

commit;


-- 创建管理帐号的授权

use user_authz;

-- flow
INSERT INTO `TB_ROLE` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`, `APPLICATION_ID`, `CODE`, `NAME`, `DESCRIPTION`, `ENABLED`, `EXTERNAL_ID`)
VALUES ('50', '1', 0, 'admin', '2019-07-01 00:00:00', '1', 'flow-admin', '流程管理员', '流程管理员', 1, '50');
INSERT INTO `TB_ROLE` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`, `APPLICATION_ID`, `CODE`, `NAME`, `DESCRIPTION`, `ENABLED`, `EXTERNAL_ID`)
VALUES ('51', '1', 0, 'admin', '2019-07-01 00:00:00', '1', 'flow-biz', '流程业务员', '流程业务员', 1, '51');

INSERT INTO `TB_GRANTED_ACCOUNT_ROLE` (`ID`, `COMPANY_ID`, `DELETED`,
  `ACCOUNT_ID`, `ROLE_ID`, 
  `GRANT_EXPIRED_DATE`)
VALUES ('50_50', '1', 0, 
  '50', '50',
  NULL);

INSERT INTO `TB_ROLE_USER` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`,
  `ORIGIN_TYPE`, `ORIGIN_PK`, 
  `APPLICATION_ID`, `ROLE_ID`, `ACCOUNT_ID`, 
  `GRANT_EXPIRED_DATE`)
VALUES ('50_50', '1', 0, 'admin', '2019-07-01 00:00:00',
  NULL, NULL, 
  '1', '50', '50', 
  NULL);

commit;


-- 创建认证帐号、认证对接

use cas_server;

-- flow

INSERT INTO `TB_ACCOUNT` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`, 
  `USERNAME`, `PASSWORD`, `DESCRIPTION`, `ENABLED`, `ACCOUNT_NON_EXPIRED`, `ACCOUNT_NON_LOCKED`, `CREDENTIALS_NON_EXPIRED`,
  `IDENTITY`, `USER_NO`, `NAME`, `MOBILE`, `EMAIL_ADDRESS`, `IDENTITY_TYPE`, `IDENTITY_NO`, 
  `EXTERNAL_ID`)
VALUES ('50', '1', 0, 'admin', '2019-07-01 00:00:00',
  'flowadmin', 'flowadmin', '流程管理员', 1, 1, 1, 1,
  'admin', '50', '流程管理员', '', 'flowadmin@supwisdom.com', '20001', '', 
  '50');

commit;

INSERT INTO `TB_SERVICE` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`, 
  `NAME`, `DESCRIPTION`, `INFORMATION_URL`, `LOGOUT_URL`, 
  `RESPONSE_TYPE`, `LOGOUT_TYPE`, 
  `EVALUATION_ORDER`, `FRIENDLY_NAME`, `REGISTERED_SERVICE_ID`, `SERVICE_ID`, 
  `ENABLED`, `SSO_ENABLED`, `REQUIRE_ALL_ATTRIBUTES`, 
  `APPLICATION_ID`, `EXTERNAL_ID`)
VALUES ('50', '1', 0, 'admin', '2019-07-01 00:00:00',
  '流程平台', '流程平台', 'https://formflow.paas.example.com', 'https://formflow.paas.example.com/formflow/cas/authen/logout', 
  'REDIRECT', 'FRONT_CHANNEL', 
  50, '流程平台', 50, 'https://formflow.paas.example.com/(.*)', 
  1, 1, 1, 
  '50', '50');

commit;

update TB_SERVICE 
set 
  INFORMATION_URL='http://formflow.paas.example.com', 
  LOGOUT_URL='http://formflow.paas.example.com/formflow/cas/authen/logout', 
  SERVICE_ID='http://formflow.paas.example.com/(.*)', 
  ID_TOKEN_ENABLED=1 
where ID='50';  -- todo, modify

commit;

