-- MySQL Script generated by MySQL Workbench
-- Mon Apr 15 09:33:45 2019
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema aroad
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema aroad
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `aroad` DEFAULT CHARACTER SET utf8 ;
USE `aroad` ;

-- -----------------------------------------------------
-- Table `aroad`.`attendance_templates`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `aroad`.`attendance_templates` ;

CREATE TABLE `attendance_templates` (
  `shift_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '班次id',
  `shift_name` varchar(100) NOT NULL COMMENT '模板名称',
  `start_time` time NOT NULL COMMENT '开始时间',
  `end_time` time NOT NULL COMMENT '结束时间',
  `shift_type` varchar(20) NOT NULL COMMENT '班次类型：白班/夜班/全天/领导带班',
  `attendance_type` varchar(20) NOT NULL COMMENT '值班类型',
  `is_cross_day` varchar(1) NOT NULL COMMENT '是否跨日',
  `position` varchar(20) NOT NULL COMMENT '所属岗位',  
  `unit_id` int(11) unsigned NOT NULL COMMENT '单位部门id',
  `remark` varchar(50) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`shift_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='班次表';


-- -----------------------------------------------------
-- Table `aroad`.`attendance`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `aroad`.`attendance` ;

CREATE TABLE `attendance` (
  `attendance_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '排班id',
  `shift_id` int(11) NOT NULL COMMENT '班次表主键',
  `time` date NOT NULL COMMENT '排班日期',
  `unit_id` int(11) NOT NULL COMMENT '排班部门id',
  PRIMARY KEY (`attendance_id`),
  KEY `shift_id_index` (`shift_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='排班表';
ALTER TABLE `attendance` ADD UNIQUE `unique_index` (shift_id, time, unit_id);

-- -----------------------------------------------------
-- Table `aroad`.`attendance_members`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `aroad`.`attendance_members` ;

CREATE TABLE `attendance_members` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `attendance_id` int(11) NOT NULL,
  `name` varchar(10) NOT NULL COMMENT '值班人员姓名',
  `phone` varchar(15) NOT NULL COMMENT '手机号',
  PRIMARY KEY (`id`),
  KEY `attendance_id_index` (`attendance_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='值班人员表';



-- -----------------------------------------------------
-- Table `aroad`.`attendance_logs`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `aroad`.`attendance_logs` ;

CREATE TABLE `attendance_logs` (
  `log_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '日志id',
  `duty_person` varchar(10) NOT NULL COMMENT '值班人',
  `attendance_shift` varchar(45) NOT NULL COMMENT '值班班次',
  `attendance_date` date NOT NULL COMMENT '值班日期',
  `content` text NOT NULL COMMENT '日志内容',
  `write_id` int(11) NOT NULL COMMENT '填写人id',
  `write_person` varchar(10) NOT NULL COMMENT '填写人',
  `write_time` datetime NOT NULL COMMENT '填写时间',
  `dept_id` int(11) NOT NULL COMMENT '部门id',
  PRIMARY KEY (`log_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='值班日志表';




SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;


INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'-1',
		'',
		'',
		'0',
		'/attendance',
		'icon-bangzhushouji',
		'8000',
		'0',
		'2018-01-20 13:17:19',
		'9',
		'2018-07-29 13:38:19',
		'值班管理'
	);

-- 菜单SQL
INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'8000',
		'views/attendance/attendance/index',
		'',
		'0',
		'/attendance',
		'icon-bangzhushouji',
		'8100',
		'0',
		'2018-01-20 13:17:19',
		'2',
		'2018-07-29 13:38:19',
		'排班管理'
	);

-- 菜单SQL
INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'8000',
		'views/attendance/attendancetemplates/index',
		'',
		'0',
		'/attendancetemplates',
		'icon-bangzhushouji',
		'8200',
		'0',
		'2018-01-20 13:17:19',
		'1',
		'2018-07-29 13:38:19',
		'班次管理'
	);
	
-- 值班日志
INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'8000',
		'views/attendance/attendancelogs/index',
		'',
		'0',
		'/attendancelogs',
		'icon-bangzhushouji',
		'8300',
		'0',
		'2018-01-20 13:17:19',
		'1',
		'2018-07-29 13:38:19',
		'值班日志'
	);	
	
-- 添加排班
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8100', null, 'attendance_add', '1', null, '1', '8101', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '添加排班');
-- 撤销排班
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8100', null, 'attendance_remove', '1', null, '1', '8102', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '撤销排班');	
	
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8200', null, 'attendancetemplates_add', '1', null, '1', '8201', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '新增');
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8200', null, 'attendancetemplates_edit', '1', null, '1', '8202', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '修改');
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8200', null, 'attendancetemplates_del', '1', null, '1', '8203', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '删除');

-- 值班日志操作权限	
INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'8300',
		NULL,
		'logs_add',
		'1',
		NULL,
		'1',
		'8301',
		'0',
		'2018-05-15 21:35:18',
		'0',
		'2018-07-29 13:38:59',
		'新增'
	);

INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'8300',
		NULL,
		'logs_edit',
		'1',
		NULL,
		'1',
		'8302',
		'0',
		'2018-05-15 21:35:18',
		'1',
		'2018-07-29 13:38:59',
		'修改'
	);

INSERT INTO `sys_menu` (
	`parent_id`,
	`component`,
	`permission`,
	`type`,
	`path`,
	`icon`,
	`menu_id`,
	`del_flag`,
	`create_time`,
	`sort`,
	`update_time`,
	`name`
)
VALUES
	(
		'8300',
		NULL,
		'logs_del',
		'1',
		NULL,
		'1',
		'8303',
		'0',
		'2018-05-15 21:35:18',
		'2',
		'2018-07-29 13:38:59',
		'删除'
	);	
	
	
	
-- 菜单SQL
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8000', 'views/attendance/attendancerecords/index_manage', '', '0', '/recordsmanage', 'icon-bangzhushouji', '8400', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '通讯录管理');

-- 菜单对应按钮SQL
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8400', null, 'attendancerecords_add', '1', null, '1', '8401', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '新增');
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8400', null, 'attendancerecords_edit', '1', null, '1', '8402', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '修改');
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
    values ( '8400', null, 'attendancerecords_del', '1', null, '1', '8403', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '删除');

