初始脚本

This commit is contained in:
attiya 2025-09-01 22:22:49 +08:00
parent 41a692d690
commit 1419a05f01
4 changed files with 285 additions and 83 deletions

View File

@ -11,7 +11,7 @@ spring:
sql:
init:
platform: postgis
mode: never
mode: always
schema-locations: classpath:db/init.sql
data-locations: classpath:db/data.sql
jackson:

View File

@ -1 +1,28 @@
INSERT INTO `ebike_organizations` VALUES (258106438092689408, '测试组织', '2025-03-14 10:43:49');
/*
Navicat Premium Dump SQL
Source Server : nas-postgis
Source Server Type : PostgreSQL
Source Server Version : 160009 (160009)
Source Host : 192.168.1.31:5433
Source Catalog : ebike_staff
Source Schema : public
Target Server Type : PostgreSQL
Target Server Version : 160009 (160009)
File Encoding : 65001
Date: 01/09/2025 22:02:21
*/
-- ----------------------------
-- Table structure for ebike_operator
-- ----------------------------
INSERT INTO "public"."ebike_operator" VALUES (311460622768435200, '卓景出行', '四川省成都市西部智谷B区', '15008231529', NULL, '2025-08-09 00:14:44.550027', NULL, NULL, 'f');
INSERT INTO "public"."ebike_operator_staff" VALUES (1, 'admin', 'b98b43d0eef6480daf4bdb7793aa8b7d557c85bdac52e4f814c5e9ba424baa6f:mT5Y0iBQJg9YtHUW38whlw==', 312523146360233984, 311460622768435200, 1, NULL, NULL, '2025-08-11 22:38:56.561597', NULL, NULL, 'f', 'mT5Y0iBQJg9YtHUW38whlw==');
INSERT INTO "public"."ebike_role" VALUES (312523146360233984, '超级管理员', 311460622768435200, '系统默认角色', NULL, '2025-08-11 22:36:51.219978', NULL, NULL, 'f', 't', 'f');

View File

@ -1,108 +1,282 @@
/*
Navicat Premium Dump SQL
Source Server : cdzy
Source Server Type : MySQL
Source Server Version : 90200 (9.2.0)
Source Host : wwdd.duia.ro:6008
Source Schema : ebike_user
Source Server : nas-postgis
Source Server Type : PostgreSQL
Source Server Version : 160009 (160009)
Source Host : 192.168.1.31:5433
Source Catalog : ebike_staff
Source Schema : public
Target Server Type : MySQL
Target Server Version : 90200 (9.2.0)
Target Server Type : PostgreSQL
Target Server Version : 160009 (160009)
File Encoding : 65001
Date: 14/03/2025 21:51:11
Date: 01/09/2025 22:10:34
*/
-- 批量创建所有序列
-- 创建 ebike_operator_operator_id_seq 序列
CREATE SEQUENCE IF NOT EXISTS ebike_operator_operator_id_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- 创建 ebike_permission_permission_id_seq 序列
CREATE SEQUENCE IF NOT EXISTS ebike_permission_permission_id_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- 创建 ebike_role_role_id_seq 序列
CREATE SEQUENCE IF NOT EXISTS ebike_role_role_id_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- 创建 ebike_role_permission_role_permission_id_seq 序列
CREATE SEQUENCE IF NOT EXISTS ebike_role_permission_role_permission_id_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- 创建 ebike_operator_staff_staff_id_seq 序列
CREATE SEQUENCE IF NOT EXISTS ebike_operator_staff_staff_id_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- 创建 ebike_staff_role_staff_role_id_seq 序列
CREATE SEQUENCE IF NOT EXISTS ebike_staff_role_staff_role_id_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- ----------------------------
-- Table structure for ebike_operator
-- ----------------------------
DROP TABLE IF EXISTS "public"."ebike_operator";
CREATE TABLE "public"."ebike_operator" (
"operator_id" int8 NOT NULL DEFAULT nextval('ebike_operator_operator_id_seq'::regclass),
"name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
"address" text COLLATE "pg_catalog"."default",
"contact_phone" varchar(20) COLLATE "pg_catalog"."default",
"create_by" int8,
"create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
"update_by" int8,
"update_time" timestamp(6),
"is_deleted" bool NOT NULL DEFAULT false
)
;
COMMENT ON COLUMN "public"."ebike_operator"."create_by" IS '创建人IDebike_operator_staff.staff_id';
COMMENT ON COLUMN "public"."ebike_operator"."create_time" IS '创建时间';
COMMENT ON COLUMN "public"."ebike_operator"."update_by" IS '最后修改人ID';
COMMENT ON COLUMN "public"."ebike_operator"."update_time" IS '最后修改时间';
COMMENT ON TABLE "public"."ebike_operator" IS '运营商信息表';
-- ----------------------------
-- Table structure for ebike_organizations
-- Table structure for ebike_operator_staff
-- ----------------------------
DROP TABLE IF EXISTS `ebike_organizations`;
CREATE TABLE `ebike_organizations` (
`org_id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
`org_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`org_id`) USING BTREE,
UNIQUE INDEX `org_name`(`org_name` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 258106438092689410 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
DROP TABLE IF EXISTS "public"."ebike_operator_staff";
CREATE TABLE "public"."ebike_operator_staff" (
"staff_id" int8 NOT NULL DEFAULT nextval('ebike_operator_staff_staff_id_seq'::regclass),
"username" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"password" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"role_id" int8 NOT NULL,
"operator_id" int8 NOT NULL,
"status" int2 DEFAULT 1,
"last_login" timestamp(6),
"create_by" int8,
"create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
"update_by" int8,
"update_time" timestamp(6),
"is_deleted" bool NOT NULL DEFAULT false,
"salt" varchar(30) COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."ebike_operator_staff"."username" IS '用户名';
COMMENT ON COLUMN "public"."ebike_operator_staff"."password" IS '密码(加密后';
COMMENT ON COLUMN "public"."ebike_operator_staff"."role_id" IS '角色id';
COMMENT ON COLUMN "public"."ebike_operator_staff"."operator_id" IS '运营商id';
COMMENT ON COLUMN "public"."ebike_operator_staff"."status" IS '状态';
COMMENT ON COLUMN "public"."ebike_operator_staff"."last_login" IS '上次登陆时间';
COMMENT ON COLUMN "public"."ebike_operator_staff"."create_by" IS '创建人ID引用ebike_operator_staff.staff_id';
COMMENT ON COLUMN "public"."ebike_operator_staff"."create_time" IS '创建时间';
COMMENT ON COLUMN "public"."ebike_operator_staff"."update_by" IS '修改人';
COMMENT ON COLUMN "public"."ebike_operator_staff"."update_time" IS '修改时间';
COMMENT ON COLUMN "public"."ebike_operator_staff"."is_deleted" IS '逻辑删';
COMMENT ON COLUMN "public"."ebike_operator_staff"."salt" IS '盐值';
COMMENT ON TABLE "public"."ebike_operator_staff" IS '运营商员工账户表';
-- ----------------------------
-- Table structure for ebike_permissions
-- Table structure for ebike_permission
-- ----------------------------
DROP TABLE IF EXISTS `ebike_permissions`;
CREATE TABLE `ebike_permissions` (
`perm_id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '权限id',
`perm_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '权限码',
`description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '权限码',
`level` int NOT NULL COMMENT '等级',
`parent_id` bigint NULL DEFAULT NULL COMMENT '父级id',
PRIMARY KEY (`perm_id`) USING BTREE,
UNIQUE INDEX `perm_code`(`perm_code` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
DROP TABLE IF EXISTS "public"."ebike_permission";
CREATE TABLE "public"."ebike_permission" (
"permission_id" int8 NOT NULL DEFAULT nextval('ebike_permission_permission_id_seq'::regclass),
"code" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"name" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"type" int2 NOT NULL,
"create_by" int8,
"create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
"update_by" int8,
"update_time" timestamp(6),
"is_deleted" bool NOT NULL DEFAULT false
)
;
COMMENT ON TABLE "public"."ebike_permission" IS '系统权限表';
-- ----------------------------
-- Table structure for ebike_role_permissions
-- Records of ebike_permission
-- ----------------------------
DROP TABLE IF EXISTS `ebike_role_permissions`;
CREATE TABLE `ebike_role_permissions` (
`role_id` bigint UNSIGNED NOT NULL,
`perm_id` bigint UNSIGNED NOT NULL,
PRIMARY KEY (`role_id`, `perm_id`) USING BTREE,
INDEX `perm_id`(`perm_id` ASC) USING BTREE,
CONSTRAINT `ebike_role_permissions_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `ebike_roles` (`role_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `ebike_role_permissions_ibfk_2` FOREIGN KEY (`perm_id`) REFERENCES `ebike_permissions` (`perm_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for ebike_roles
-- Table structure for ebike_role
-- ----------------------------
DROP TABLE IF EXISTS `ebike_roles`;
CREATE TABLE `ebike_roles` (
`role_id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
`role_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`org_id` bigint UNSIGNED NULL DEFAULT NULL,
`is_system_role` tinyint(1) NULL DEFAULT 0,
`created_staff` bigint UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`role_id`) USING BTREE,
INDEX `org_id`(`org_id` ASC) USING BTREE,
INDEX `created_staff`(`created_staff` ASC) USING BTREE,
CONSTRAINT `ebike_roles_ibfk_1` FOREIGN KEY (`org_id`) REFERENCES `ebike_organizations` (`org_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `ebike_roles_ibfk_2` FOREIGN KEY (`created_staff`) REFERENCES `ebike_staff` (`staff_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
DROP TABLE IF EXISTS "public"."ebike_role";
CREATE TABLE "public"."ebike_role" (
"role_id" int8 NOT NULL DEFAULT nextval('ebike_role_role_id_seq'::regclass),
"role_name" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"operator_id" int8 NOT NULL,
"description" text COLLATE "pg_catalog"."default",
"create_by" int8,
"create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
"update_by" int8,
"update_time" timestamp(6),
"is_deleted" bool NOT NULL DEFAULT false,
"sys_admin" bool,
"operator_admin" bool
)
;
COMMENT ON COLUMN "public"."ebike_role"."sys_admin" IS '是否超级管理员';
COMMENT ON COLUMN "public"."ebike_role"."operator_admin" IS '是否运营商管理员';
COMMENT ON TABLE "public"."ebike_role" IS '员工角色表';
-- ----------------------------
-- Table structure for ebike_staff
-- Table structure for ebike_role_permission
-- ----------------------------
DROP TABLE IF EXISTS `ebike_staff`;
CREATE TABLE `ebike_staff` (
`staff_id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
`username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`pohone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`password_hash` char(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`org_id` bigint UNSIGNED NULL DEFAULT NULL,
`is_superadmin` tinyint(1) NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`staff_id`) USING BTREE,
UNIQUE INDEX `username`(`username` ASC) USING BTREE,
INDEX `org_id`(`org_id` ASC) USING BTREE,
CONSTRAINT `ebike_staff_ibfk_1` FOREIGN KEY (`org_id`) REFERENCES `ebike_organizations` (`org_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 258108517645389825 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
DROP TABLE IF EXISTS "public"."ebike_role_permission";
CREATE TABLE "public"."ebike_role_permission" (
"role_permission_id" int8 NOT NULL DEFAULT nextval('ebike_role_permission_role_permission_id_seq'::regclass),
"role_id" int8 NOT NULL,
"permission_id" int8 NOT NULL,
"create_by" int8,
"create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
"update_by" int8,
"update_time" timestamp(6),
"is_deleted" bool NOT NULL DEFAULT false
)
;
COMMENT ON TABLE "public"."ebike_role_permission" IS '角色-权限映射表';
-- ----------------------------
-- Table structure for ebike_staff_roles
-- Records of ebike_role_permission
-- ----------------------------
DROP TABLE IF EXISTS `ebike_staff_roles`;
CREATE TABLE `ebike_staff_roles` (
`staff_id` bigint UNSIGNED NOT NULL,
`role_id` bigint UNSIGNED NOT NULL,
`assigned_at` datetime NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`staff_id`, `role_id`) USING BTREE,
INDEX `role_id`(`role_id` ASC) USING BTREE,
CONSTRAINT `ebike_staff_roles_ibfk_1` FOREIGN KEY (`staff_id`) REFERENCES `ebike_staff` (`staff_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `ebike_staff_roles_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `ebike_roles` (`role_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
SET FOREIGN_KEY_CHECKS = 1;
-- ----------------------------
-- Table structure for ebike_staff_role
-- ----------------------------
DROP TABLE IF EXISTS "public"."ebike_staff_role";
CREATE TABLE "public"."ebike_staff_role" (
"staff_role_id" int8 NOT NULL DEFAULT nextval('ebike_staff_role_staff_role_id_seq'::regclass),
"staff_id" int8 NOT NULL,
"role_id" int8 NOT NULL,
"create_by" int8,
"create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
"update_by" int8,
"update_time" timestamp(6),
"is_deleted" bool NOT NULL DEFAULT false
)
;
COMMENT ON TABLE "public"."ebike_staff_role" IS '员工-角色映射表';
-- ----------------------------
-- Records of ebike_staff_role
-- ----------------------------
-- ----------------------------
-- Uniques structure for table ebike_operator
-- ----------------------------
ALTER TABLE "public"."ebike_operator" ADD CONSTRAINT "ebike_operator_name_key" UNIQUE ("name");
-- ----------------------------
-- Primary Key structure for table ebike_operator
-- ----------------------------
ALTER TABLE "public"."ebike_operator" ADD CONSTRAINT "ebike_operator_pkey" PRIMARY KEY ("operator_id");
-- ----------------------------
-- Uniques structure for table ebike_operator_staff
-- ----------------------------
ALTER TABLE "public"."ebike_operator_staff" ADD CONSTRAINT "ebike_operator_staff_username_key" UNIQUE ("username");
-- ----------------------------
-- Primary Key structure for table ebike_operator_staff
-- ----------------------------
ALTER TABLE "public"."ebike_operator_staff" ADD CONSTRAINT "ebike_operator_staff_pkey" PRIMARY KEY ("staff_id");
-- ----------------------------
-- Uniques structure for table ebike_permission
-- ----------------------------
ALTER TABLE "public"."ebike_permission" ADD CONSTRAINT "ebike_permission_code_key" UNIQUE ("code");
-- ----------------------------
-- Primary Key structure for table ebike_permission
-- ----------------------------
ALTER TABLE "public"."ebike_permission" ADD CONSTRAINT "ebike_permission_pkey" PRIMARY KEY ("permission_id");
-- ----------------------------
-- Primary Key structure for table ebike_role
-- ----------------------------
ALTER TABLE "public"."ebike_role" ADD CONSTRAINT "ebike_role_pkey" PRIMARY KEY ("role_id");
-- ----------------------------
-- Uniques structure for table ebike_role_permission
-- ----------------------------
ALTER TABLE "public"."ebike_role_permission" ADD CONSTRAINT "ebike_role_permission_role_id_permission_id_key" UNIQUE ("role_id", "permission_id");
-- ----------------------------
-- Primary Key structure for table ebike_role_permission
-- ----------------------------
ALTER TABLE "public"."ebike_role_permission" ADD CONSTRAINT "ebike_role_permission_pkey" PRIMARY KEY ("role_permission_id");
-- ----------------------------
-- Uniques structure for table ebike_staff_role
-- ----------------------------
ALTER TABLE "public"."ebike_staff_role" ADD CONSTRAINT "ebike_staff_role_staff_id_role_id_key" UNIQUE ("staff_id", "role_id");
-- ----------------------------
-- Primary Key structure for table ebike_staff_role
-- ----------------------------
ALTER TABLE "public"."ebike_staff_role" ADD CONSTRAINT "ebike_staff_role_pkey" PRIMARY KEY ("staff_role_id");
-- ----------------------------
-- Foreign Keys structure for table ebike_operator_staff
-- ----------------------------
ALTER TABLE "public"."ebike_operator_staff" ADD CONSTRAINT "ebike_operator_staff_operator_id_fkey" FOREIGN KEY ("operator_id") REFERENCES "public"."ebike_operator" ("operator_id") ON DELETE CASCADE ON UPDATE NO ACTION;
-- ----------------------------
-- Foreign Keys structure for table ebike_role
-- ----------------------------
ALTER TABLE "public"."ebike_role" ADD CONSTRAINT "ebike_role_operator_id_fkey" FOREIGN KEY ("operator_id") REFERENCES "public"."ebike_operator" ("operator_id") ON DELETE CASCADE ON UPDATE NO ACTION;
-- ----------------------------
-- Foreign Keys structure for table ebike_role_permission
-- ----------------------------
ALTER TABLE "public"."ebike_role_permission" ADD CONSTRAINT "ebike_role_permission_permission_id_fkey" FOREIGN KEY ("permission_id") REFERENCES "public"."ebike_permission" ("permission_id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."ebike_role_permission" ADD CONSTRAINT "ebike_role_permission_role_id_fkey" FOREIGN KEY ("role_id") REFERENCES "public"."ebike_role" ("role_id") ON DELETE CASCADE ON UPDATE NO ACTION;
-- ----------------------------
-- Foreign Keys structure for table ebike_staff_role
-- ----------------------------
ALTER TABLE "public"."ebike_staff_role" ADD CONSTRAINT "ebike_staff_role_role_id_fkey" FOREIGN KEY ("role_id") REFERENCES "public"."ebike_role" ("role_id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."ebike_staff_role" ADD CONSTRAINT "ebike_staff_role_staff_id_fkey" FOREIGN KEY ("staff_id") REFERENCES "public"."ebike_operator_staff" ("staff_id") ON DELETE CASCADE ON UPDATE NO ACTION;

View File

@ -11,6 +11,7 @@ public class PasswordTest {
public void test() {
String salt = SHA256WithSaltUtil.generateSalt();
System.out.println(salt);
System.out.println(salt.length());
String password = "123456";
String encrypt = SHA256WithSaltUtil.encrypt(password, salt);
System.out.println(encrypt);