/*
 Navicat Premium Data Transfer

 Source Server         : 测试
 Source Server Type    : MariaDB
 Source Server Version : 100318
 Source Host           : test.tall.wiki:3306
 Source Schema         : wisdomcar

 Target Server Type    : MariaDB
 Target Server Version : 100318
 File Encoding         : 65001

 Date: 13/05/2021 15:13:25
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for t_first_aid
-- ----------------------------
DROP TABLE IF EXISTS `t_first_aid`;
CREATE TABLE `t_first_aid`  (
  `id` bigint(20) NOT NULL,
  `car_id` bigint(20) NULL DEFAULT 0 COMMENT '平车id',
  `hospital_id` bigint(20) NULL DEFAULT 0 COMMENT '医院id',
  `begin_time` bigint(20) NULL DEFAULT 0 COMMENT '开始时间',
  `end_time` bigint(20) NULL DEFAULT 0 COMMENT '结束时间',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `aid_car_index`(`car_id`) USING BTREE,
  INDEX `aid_hospital_index`(`hospital_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '急救表' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_first_aid_record
-- ----------------------------
DROP TABLE IF EXISTS `t_first_aid_record`;
CREATE TABLE `t_first_aid_record`  (
  `id` bigint(20) NOT NULL,
  `first_aid_id` bigint(20) NULL DEFAULT 0 COMMENT '急救表id',
  `type` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '类型 0开始 1体重 2rfid, 3称重一 4称重二 5称重三 6称重四 7震动 8剂量',
  `value` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '该类型对应的值',
  `begin_time` bigint(20) NULL DEFAULT 0 COMMENT '开始时间',
  `step_id` bigint(20) NULL DEFAULT 0 COMMENT '环节id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `record_first_aid_index`(`first_aid_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '急救记录表' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_first_aid_standard
-- ----------------------------
DROP TABLE IF EXISTS `t_first_aid_standard`;
CREATE TABLE `t_first_aid_standard`  (
  `id` bigint(20) NOT NULL,
  `type` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '类型 0国际 1医院本身',
  `hospital_id` bigint(20) NULL DEFAULT 0 COMMENT '医院id',
  `step_id` bigint(20) NULL DEFAULT 0 COMMENT '环节id',
  `duration` bigint(20) NULL DEFAULT 0 COMMENT '该环节的时长',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `standard_hospital_index`(`hospital_id`) USING BTREE,
  INDEX `standard_step_index`(`step_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '急救标准表' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_rfid
-- ----------------------------
DROP TABLE IF EXISTS `t_rfid`;
CREATE TABLE `t_rfid`  (
  `id` bigint(20) NOT NULL,
  `rfid` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT 'rfid',
  `type` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '类型 0医生 1采血车 2门禁',
  `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '名字',
  `step_id` bigint(20) NULL DEFAULT 0 COMMENT '环节id',
  `hospital_id` bigint(20) NULL DEFAULT 0 COMMENT '医院id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `rfid_step_index`(`step_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'rfid表' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_screen
-- ----------------------------
DROP TABLE IF EXISTS `t_screen`;
CREATE TABLE `t_screen`  (
  `id` bigint(20) NOT NULL,
  `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '名字',
  `hospital_id` bigint(20) NULL DEFAULT 0 COMMENT '医院id',
  `show_type` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '大屏显示类型 0主屏 当前默认全是0',
  `user_id` bigint(20) NULL DEFAULT 0 COMMENT '用户id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '平车信息' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_statistics_month
-- ----------------------------
DROP TABLE IF EXISTS `t_statistics_month`;
CREATE TABLE `t_statistics_month`  (
  `id` bigint(20) NOT NULL,
  `name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '月份名',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '统计月份表 1至12月' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_step
-- ----------------------------
DROP TABLE IF EXISTS `t_step`;
CREATE TABLE `t_step`  (
  `id` bigint(20) NOT NULL,
  `name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '环节名称',
  `code` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '环节code',
  `sequence` int(11) NULL DEFAULT 0 COMMENT '顺序',
  `step_type` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '环节类型。0真正的环节，1rfid的环节',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '环节表' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_wisdom_car
-- ----------------------------
DROP TABLE IF EXISTS `t_wisdom_car`;
CREATE TABLE `t_wisdom_car`  (
  `id` bigint(20) NOT NULL,
  `car_number` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '平车编号',
  `time` bigint(20) NULL DEFAULT 0 COMMENT '入库时间',
  `hospital_id` bigint(20) NULL DEFAULT 0 COMMENT '医院id',
  `screen_id` bigint(20) NULL DEFAULT 0 COMMENT '大屏id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '平车信息' ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for t_wisdom_car_record
-- ----------------------------
DROP TABLE IF EXISTS `t_wisdom_car_record`;
CREATE TABLE `t_wisdom_car_record`  (
  `id` bigint(20) NOT NULL,
  `car_id` bigint(20) NULL DEFAULT 0 COMMENT '平车id',
  `type` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '类型 0开始 1体重 2rfid, 3称重一 4称重二 5称重三 6称重四 7震动 8剂量',
  `value` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '该类型对应的值',
  `time` bigint(20) NULL DEFAULT 0 COMMENT '时间',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP,
  `rec_status` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `wisdom_car_index`(`car_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据记录表' ROW_FORMAT = Compact;

-- ----------------------------
-- Procedure structure for u_head_and_low_pro
-- ----------------------------
DROP PROCEDURE IF EXISTS `u_head_and_low_pro`;
delimiter ;;
CREATE PROCEDURE `u_head_and_low_pro`()
begin
  DECLARE n int DEFAULT 1;
  DECLARE m int DEFAULT 1;
	
  set @exesql = 'insert into t_first_aid (id,car_id,begin_time) values ';
  set @exedata = '';

WHILE m < 13 DO
	set @y = "";
	select @y:=unix_timestamp(STR_TO_DATE(concat("2020-",m,"-01"),"%Y-%m-%d")) * 1000;
	
	set @d = "";
	select @d:= RAND() * 200 + 150;
	
	  WHILE n < @d DO
			set @exedata = concat(@exedata,"(2020",if(m <10,concat("0",m),m),n,",","1,",@y,")");
			if n < @d -1
			then
				set @exedata = concat(@exedata,',');
			end if;
				set n = n + 1;
				
		END WHILE;
			set @exesql = concat(@exesql,@exedata,";");
				SELECT @exesql;
			prepare stmt from @exesql;
	
			execute stmt;
			DEALLOCATE prepare stmt;
			commit;  

			set @exesql = 'insert into t_first_aid (id,car_id,begin_time) values ';
			set @exedata = "";
			set m = m + 1;
			set n = 1;
END WHILE;

end
;;
delimiter ;

SET FOREIGN_KEY_CHECKS = 1;
