 CREATE TABLE `is_training_material_text` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `material_id` int(11) DEFAULT NULL COMMENT '素材id',
   `content` longtext DEFAULT NULL COMMENT '富文本',
   `enterprise_id` int(11) DEFAULT NULL COMMENT '企业id',
   `creater` int(11) DEFAULT NULL COMMENT '创建人id',
   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
   PRIMARY KEY (`id`),
   KEY `material_id` (`material_id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='素材富文本';

 ALTER TABLE `is_training_material`
  ADD COLUMN `cover_url` varchar(255) DEFAULT NULL COMMENT '封面url' AFTER `material_type_id`,
  ADD COLUMN `cover_type` int(2) DEFAULT NULL COMMENT '封面类型 1系统 2自定义 2素材类型' AFTER `cover_url`,
  ADD COLUMN `is_show` int(2) DEFAULT '1' COMMENT 'app是否显示：0-隐藏，1-显示' AFTER `is_using`,
  modify COLUMN `is_using` int(2) DEFAULT '1' COMMENT '启用状态：0-下架，1-上架，2-转码中',
  add column `show_name` varchar(100) DEFAULT NULL COMMENT '素材标题名称' AFTER `material_name`;

alter table is_training_material
add column read_type tinyint not null default '1' comment '查看类型 1 跟随分类 2 跟随分类&单独设置 0 未设置',
add column download_type tinyint not null default '1' comment '下载类型 1 跟随分类 2 跟随分类&单独设置 0 未设置',
add column shareable tinyint not null default '1' comment '允许分享 1 允许 0 不允许';

CREATE TABLE `is_training_unit`
(
    `id`            BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
    `biz_id`        varchar(32) NOT null default '0' comment '权限单元业务id 1:用户id, 2:标签id, 3:角色id, 4:组织',
    `biz_type`      INT(11)     not null DEFAULT '0' COMMENT '业务类型{1:用户, 2:标签, 3:角色, 4:组织}',
    `enterprise_id` INT(11)     not null DEFAULT '0' COMMENT '企业id',
    `create_time`   DATETIME             DEFAULT CURRENT_TIMESTAMP comment '创建时间',
    `update_time`   DATETIME             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间',
    UNIQUE KEY `unique_biz_id_biz_type_enterprise_id` (`biz_id`, `biz_type`, `enterprise_id`),
    KEY `idx_create_time` (`create_time`),
    KEY `idx_update_time` (`update_time`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 1
  DEFAULT CHARSET = utf8mb4 COMMENT ='权限单元表';

CREATE TABLE `is_training_material_permission`
(
    `id`                BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
    `material_id`       int(11)    NOT null default '0' comment '素材id',
    `material_type_id`  int(11)    NOT null default '0' comment '分类id',
    `permission_type`   tinyint(8) NOT null default '0' comment '权限类型 {1:查看,4:下载}',
    `permission_source` tinyint(8) NOT null default '0' comment '权限类型 {1:分类,2:素材单独权限}',
    `unit_id`           bigint(20) not null DEFAULT '0' COMMENT '单元id',
    `enterprise_id`     INT(11)    not null DEFAULT '0' COMMENT '企业id',
    `create_time`       DATETIME            DEFAULT CURRENT_TIMESTAMP comment '创建时间',
    `update_time`       DATETIME            DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间',
    KEY `idx_unit_id` (`unit_id`),
    KEY `idx_material_id` (`material_id`),
    KEY `idx_material_type_id` (`material_type_id`),
    KEY `idx_create_time` (`create_time`),
    KEY `idx_update_time` (`update_time`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 1
  DEFAULT CHARSET = utf8mb4 COMMENT ='素材单独权限配置表';
# 修改素材分类 删除该素材原有所有权限 重新根据分类等表设置权限 单独权限表



  CREATE TABLE `is_training_material_attach` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `create_time` datetime DEFAULT NULL,
  `enterprise_id` int(11) DEFAULT NULL,
  `material_id` int(11) DEFAULT NULL COMMENT '素材id',
  `name` varchar(128) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '附件名称',
  `url` varchar(512) CHARACTER SET utf8mb4 DEFAULT NULL,
  `size` int(11) DEFAULT NULL COMMENT '附件大小',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `is_training_message` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `object_id` int(11) DEFAULT NULL COMMENT '关联id',
  `object_type` varchar(64) DEFAULT NULL COMMENT '关联类型',
  `title` varchar(128) DEFAULT NULL COMMENT '标题',
  `content` varchar(512) DEFAULT NULL COMMENT '内容',
  `appoint_type` int(2) DEFAULT '1' COMMENT '通知：1-查询权限的用户，2-指定用户',
  `create_time` datetime DEFAULT NULL,
  `creater` int(11) DEFAULT NULL COMMENT '创建人id',
  `updater` int(11) DEFAULT NULL COMMENT '修改人',
  `update_time` datetime DEFAULT NULL COMMENT '修改时间',
  `enterprise_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `object_id` (`object_id`) USING BTREE,
  KEY `object_type` (`object_type`) USING BTREE,
  KEY `enterprise_id` (`enterprise_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='推送内容';

CREATE TABLE `is_training_message_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `message_id` int(11) DEFAULT NULL COMMENT '推送内容id',
  `unit_id` bigint(20) not null DEFAULT '0' COMMENT '单元id',
  `create_time` datetime DEFAULT NULL,
  `creater` int(11) DEFAULT NULL COMMENT '创建人id',
  `enterprise_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `message_id` (`message_id`) USING BTREE,
  KEY `unit_id` (`unit_id`) USING BTREE,
  KEY `enterprise_id` (`enterprise_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='推送内容指定用户';

 ALTER TABLE `is_training_work` ADD COLUMN `pass_fill` int(2) DEFAULT '1' COMMENT '合格点评是否必填：0-否，1-是' AFTER `review_type`,
 ADD COLUMN `fail_fill` int(2) DEFAULT '1' COMMENT '不合格点评是否必填：0-否，1-是' AFTER `pass_fill`;

 ALTER TABLE `is_training_work_document` ADD COLUMN `file_type` int(2) DEFAULT NULL COMMENT '文件类型:1-文档 2-图片 3-视频 4-音频 5-压缩文件 6-富文本 7-商品' AFTER `material_id`;
 
 UPDATE is_training_material
SET cover_type=1,cover_url='http://ovopark.oss-cn-hangzhou.aliyuncs.com/web/material/cover_setting_4.webp'
where cover_url is null