实现员工规则排班设置
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
-- 员工排班规则和例外,保留 t_artist_schedule 作为预约校验使用的具体日期排班表。
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_index_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_fd_add_index_if_not_exists(
|
||||
IN p_table_name varchar(128),
|
||||
IN p_index_name varchar(128),
|
||||
IN p_index_sql varchar(1000)
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = p_table_name
|
||||
AND index_name = p_index_name
|
||||
) THEN
|
||||
SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD INDEX ', p_index_name, ' ', p_index_sql);
|
||||
PREPARE fd_stmt FROM @fd_sql;
|
||||
EXECUTE fd_stmt;
|
||||
DEALLOCATE PREPARE fd_stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_unique_index_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_fd_add_unique_index_if_not_exists(
|
||||
IN p_table_name varchar(128),
|
||||
IN p_index_name varchar(128),
|
||||
IN p_index_sql varchar(1000)
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = p_table_name
|
||||
AND index_name = p_index_name
|
||||
) THEN
|
||||
SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD UNIQUE INDEX ', p_index_name, ' ', p_index_sql);
|
||||
PREPARE fd_stmt FROM @fd_sql;
|
||||
EXECUTE fd_stmt;
|
||||
DEALLOCATE PREPARE fd_stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS t_artist_schedule_rule
|
||||
(
|
||||
id bigint unsigned NOT NULL COMMENT '排班规则ID',
|
||||
shop_id bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID',
|
||||
preset_type varchar(32) NOT NULL COMMENT '预设类型',
|
||||
work_days varchar(32) NOT NULL COMMENT '工作星期,1-7逗号分隔',
|
||||
start_time time NOT NULL COMMENT '常规开始时间',
|
||||
end_time time NOT NULL COMMENT '常规结束时间',
|
||||
slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟',
|
||||
capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量',
|
||||
status tinyint NOT NULL DEFAULT 1 COMMENT '状态:1启用,0停用',
|
||||
remark varchar(255) NULL COMMENT '备注',
|
||||
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='美甲师常规排班规则表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS t_artist_schedule_exception
|
||||
(
|
||||
id bigint unsigned NOT NULL COMMENT '排班例外ID',
|
||||
shop_id bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID',
|
||||
work_date date NOT NULL COMMENT '例外日期',
|
||||
exception_type varchar(32) NOT NULL COMMENT '例外类型:REST/EXTRA_WORK/CHANGE_SHIFT',
|
||||
start_time time NULL COMMENT '例外开始时间',
|
||||
end_time time NULL COMMENT '例外结束时间',
|
||||
slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟',
|
||||
capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量',
|
||||
remark varchar(255) NULL COMMENT '备注',
|
||||
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='美甲师排班例外表';
|
||||
|
||||
CALL sp_fd_add_unique_index_if_not_exists('t_artist_schedule_rule', 'uk_artist_schedule_rule_artist', '(`shop_id`, `artist_id`, `is_delete`)');
|
||||
CALL sp_fd_add_index_if_not_exists('t_artist_schedule_rule', 'idx_artist_schedule_rule_shop_status', '(`shop_id`, `status`, `is_delete`)');
|
||||
CALL sp_fd_add_unique_index_if_not_exists('t_artist_schedule_exception', 'uk_artist_schedule_exception_date', '(`shop_id`, `artist_id`, `work_date`, `is_delete`)');
|
||||
CALL sp_fd_add_index_if_not_exists('t_artist_schedule_exception', 'idx_artist_schedule_exception_artist_date', '(`artist_id`, `work_date`, `is_delete`)');
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_index_if_not_exists;
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_unique_index_if_not_exists;
|
||||
Reference in New Issue
Block a user