creatYeWeiHui.sql 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. -- 新建临时表,用来记录用户信息,减少步骤
  2. DROP TABLE IF EXISTS tp_user;
  3. CREATE TABLE tp_user (
  4. user_id bigint(20) NOT NULL DEFAULT 0 COMMENT '用户ID',
  5. uptown_id bigint(20) NOT NULL DEFAULT 0 COMMENT '小区ID',
  6. linkman varchar(10) NOT NULL DEFAULT '' COMMENT '联系人名称',
  7. phone varchar(20) NOT NULL DEFAULT '' COMMENT '联系人电话',
  8. time_create datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '新增时间',
  9. time_update datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间',
  10. PRIMARY KEY (user_id) USING BTREE
  11. ) ENGINE = InnoDB default charset=utf8 comment = '用户ID临时表';
  12. -- 在临时表插入user_id,之后直接使用插入的user_id
  13. insert into tp_user
  14. (select ur.user_id,u.uptown_id,aa.linkman,aa.phone,now(),now() from sys_user_role ur
  15. left join sys_uptown_house up on up.house_id = ur.property_id
  16. left join sys_uptown_unit uu on uu.unit_id = up.unit_id
  17. left join sys_uptown u on u.uptown_id = uu.uptown_id
  18. left join (
  19. select ur.user_id,up.linkman,up.phone from sys_user_role ur
  20. left join sys_uptown_home up on up.house_id = ur.property_id
  21. where ur.role_id = 1 and up.phone = '17771809480') aa on aa.user_id = ur.user_id
  22. where ur.role_id = 1 and ur.user_id = (select user_id from sys_user_role where property_id = (select house_id from sys_uptown_home where phone = '17771809480') and role_id = 1))
  23. -- 插入业委会表,根据已有的最大ID加1生成新的ID
  24. insert into sys_owner
  25. select (select owner_id from (
  26. (select ifnull(max(owner_id+0)+1,1) as owner_id from sys_owner)
  27. ) as tmp),uptown_id,linkman,phone,user_id,now(),user_id,now() from tp_user order by time_create desc limit 1;
  28. -- 插入权限表(不需要任何修改),根据已有的最大ID加1生成新的ID
  29. insert into sys_user_role
  30. select (select ur_id from (
  31. (select ifnull(max(ur_id+0)+1,1) as ur_id from sys_user_role)
  32. ) as tmp),user_id, 2,
  33. (select owner_id from sys_owner where user_create = (select user_id from tp_user order by time_create desc limit 1))
  34. ,user_id,now(),user_id,now() from tp_user order by time_create desc limit 1;