use energy;

drop table if exists bus_project;
create table `bus_project`
(
    `id`                 bigint                                not null auto_increment,
    `project_name`       varchar(64)                           null comment '项目名称',
    `short_name`         varchar(64)                           null comment '项目简称',
    `p_id`               bigint                                null comment '父项目id',
    `status`             char(1)     default '0'               null comment '状态（0正常 1停用）',
    `pic_url`            varchar(255)                          null comment '项目图片',
    `lng`                varchar(20)                           null comment '经度',
    `lat`                varchar(20)                           null comment '纬度',
    `remark`             varchar(500)                          null comment '备注',
    `type`               varchar(20)                           null comment '项目类型',
    `is_type`            char(1)                               null comment '项目类型（1光伏 2风电）',
    `project_site`       varchar(255)                          null comment '项目地址',
    `principal`          varchar(50)                           null comment '负责人',
    `principal_phone`    varchar(50)                           null comment '负责人电话',
    `actual`             varchar(64)                           null comment '实际容量',
    `plan`               varchar(64)                           null comment '计划容量',
    `on_stream_time`     varchar(64)                           null comment '开工时间',
    `punch_range`        varchar(30) default '09:00,18:00'     not null comment '打卡范围（09:00,18:00）',
    `design_total`       int         default 0                 not null comment '设计总量',
    `security_agreement` varchar(255)                          null comment '安全协议书',
    `sort`               bigint      default 0                 not null comment '排序字段',
    `show_hidden`        char(1)     default '0'               not null comment '显示隐藏（0显示 1隐藏）',
    `create_by`          bigint                                null comment '创建者',
    `update_by`          bigint                                null comment '更新者',
    `create_time`        datetime    default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`        datetime    default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`         datetime                              null comment '删除时间',
    `is_delete`          tinyint(4)  default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '项目表'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS bus_user_project_relevancy;
CREATE TABLE `bus_user_project_relevancy`
(
    `id`          bigint                             not null AUTO_INCREMENT comment '主键ID',
    `user_id`     bigint                             not null comment '用户ID',
    `project_id`  bigint                             not null comment '项目ID',
    `create_by`   varchar(50)                        null comment '创建人',
    `update_by`   varchar(50)                        null comment '更新人',
    `create_time` datetime default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time` datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_user_id` (`user_id` ASC) USING BTREE comment '用户id',
    INDEX `idx_project_id` (`project_id` ASC) USING BTREE comment '项目id'
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '系统用户与项目关联表'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_company`;
CREATE TABLE `bus_company`
(
    `id`            bigint                               not null auto_increment,
    `company_name`  varchar(64)                          null comment '公司名称',
    `project_id`    bigint                               null comment '项目id',
    `status`        char(1)    default '0'               null comment '帐号状态（0正常 1停用）',
    `remark`        varchar(255)                         null comment '备注',
    `qualification` varchar(255)                         null comment '资质情况',
    `create_by`     varchar(64)                          null comment '创建者',
    `update_by`     varchar(64)                          null comment '更新者',
    `create_time`   datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`   datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`    datetime                             null comment '删除时间',
    `is_delete`     tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_project_id` (`project_id` ASC) USING BTREE comment '项目id'
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '公司表'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_materials`;
CREATE TABLE `bus_materials`
(
    `id`                          bigint                               not null auto_increment,
    `materials_name`              varchar(64)                          null comment '材料名称',
    `company_id`                  bigint                               null comment '公司id',
    `project_id`                  bigint                               null comment '项目id',
    `type_specification_name`     varchar(64)                          null comment '规格型号名称',
    `type_specification_url`      varchar(255)                         null comment '规格型号文件路径',
    `certificate_conformity_name` varchar(64)                          null comment '合格证编号名称',
    `certificate_conformity_url`  varchar(255)                         null comment '合格证编号文件路径',
    `quality_name`                varchar(64)                          null comment '质量说明书编号',
    `quality_url`                 varchar(255)                         null comment '质量说明书文件路径',
    `inspection_report_name`      varchar(64)                          null comment '检验报告编号',
    `inspection_report_url`       varchar(255)                         null comment '检验报告文件路径',
    `reexamine_report_name`       varchar(64)                          null comment '复试报告编号',
    `reexamine_report_url`        varchar(255)                         null comment '复试报告文件路径',
    `use_part`                    varchar(64)                          null comment '使用部位',
    `weight_id`                   varchar(64)                          null comment '计量单位',
    `remark`                      varchar(255)                         null comment '备注',
    `quantity_count`              varchar(64)                          null comment '预计材料数量',
    `status`                      char(1)    default '0'               null comment '状态（0正常 1停用）',
    `create_by`                   varchar(64)                          null comment '创建者',
    `update_by`                   varchar(64)                          null comment '更新者',
    `create_time`                 datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`                 datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`                  datetime                             null comment '删除时间',
    `is_delete`                   tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_project_id` (`project_id` ASC) USING BTREE comment '项目id'
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '材料名称表'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_materials_inventory`;
CREATE TABLE `bus_materials_inventory`
(
    `id`           bigint                               not null auto_increment comment '主键id',
    `materials_id` bigint                               not null comment '材料id',
    `project_id`   bigint                               null comment '项目id',
    `out_put`      char(1)                              null comment '出入库状态',
    `number`       int        default 0                 null comment '出/入库的数量',
    `out_put_time` datetime                             null comment '出/入库操作时间',
    `residue`      int        default 0                 null comment '剩余库存数量（记录最后一次操作留下的库存数）',
    `operator`     varchar(255)                         null comment '操作人（入库人、领料人）',
    `path`         varchar(512)                         null comment '材料出入证明',
    `disposition`  varchar(255)                         null comment '处理方式',
    `recipient`    varchar(255)                         null comment '交接单位（班组）',
    `shipper`      varchar(255)                         null comment '领用人',
    `remark`       varchar(255)                         null comment '备注',
    `create_by`    varchar(64)                          null comment '创建者',
    `update_by`    varchar(64)                          null comment '更新者',
    `create_time`  datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`  datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`   datetime                             null comment '删除时间',
    `is_delete`    tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_project_id` (`project_id` ASC) USING BTREE comment '项目ID'
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '材料出/入库表'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_contractor`;
CREATE TABLE `bus_contractor`
(
    `id`              bigint                               not null auto_increment comment '主键id',
    `name`            varchar(50)                          null comment '公司名称',
    `principal`       varchar(20)                          null comment '负责人',
    `principal_phone` varchar(20)                          null comment '负责人联系电话',
    `custodian`       varchar(20)                          null comment '管理人',
    `custodian_phone` varchar(20)                          null comment '管理人联系电话',
    `remark`          varchar(512)                         null comment '备注',
    `create_by`       varchar(64)                          null comment '创建人',
    `update_by`       varchar(64)                          null comment '更新人',
    `create_time`     datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`     datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`      datetime                             null comment '删除时间',
    `is_delete`       tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '分包单位'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_construction_user`;
CREATE TABLE `bus_construction_user`
(
    `id`               bigint                                   not null auto_increment,
    `openid`           varchar(64)                              null comment '微信id',
    `nick_name`        varchar(64)                              null comment '微信名称',
    `pace_photo`       longtext                                 null comment '人脸照',
    `user_name`        varchar(32)                              null comment '人员姓名',
    `project_id`       bigint                                   null comment '项目id',
    `contractor_id`    bigint                                   null comment '分包公司id',
    `team_id`          bigint                                   null comment '班组id',
    `status`           tinyint                                  null comment '状态（0在职 1离职）',
    `is_pinch`         tinyint                                  null comment '是否代打',
    `phone`            varchar(24)                              null comment '联系电话',
    `sex`              tinyint        default 0                 not null comment '性别(0:保密 1:男 2女)',
    `nation`           varchar(20)                              null comment '民族',
    `sfz_number`       varchar(50)                              null comment '身份证号码',
    `sfz_start`        varchar(20)                              null comment '身份证有效开始期',
    `sfz_end`          varchar(20)                              null comment '身份证有效结束期',
    `sfz_site`         varchar(100)                             null comment '身份证地址',
    `sfz_birth`        varchar(255)                             null comment '身份证出生日期',
    `native_place`     varchar(20)                              null comment '籍贯',
    `yhk_number`       varchar(50)                              null comment '银行卡号',
    `yhk_opening_bank` varchar(50)                              null comment '开户行',
    `yhk_cardholder`   varchar(255)                             null comment '持卡人',
    `type_of_work`     char(1)                                  null comment '工种(字典type_of_work)',
    `clock`            char(1)        default '1'               not null comment '打卡(0启用打卡 1禁止打卡)',
    `entry_date`       varchar(255)                             null comment '入场时间',
    `leave_date`       varchar(255)                             null comment '离场时间',
    `salary`           decimal(10, 2) default 0.00              null comment '薪水',
    `remark`           varchar(512)                             null comment '备注',
    `create_by`        varchar(64)                              null comment '创建者',
    `update_by`        varchar(64)                              null comment '更新者',
    `create_time`      datetime       default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`      datetime       default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`       datetime                                 null comment '删除时间',
    `is_delete`        tinyint(4)     default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_subcontractor_id` (`contractor_id` ASC) USING BTREE comment '劳务公司id',
    INDEX `idx_openid` (`openid` ASC) USING BTREE comment '微信id',
    INDEX `idx_phone` (`phone` ASC) USING BTREE comment '电话'
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '施工人员表'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_project_team`;
CREATE TABLE `bus_project_team`
(
    `id`          bigint                               not null auto_increment comment '主键id',
    `project_id`  bigint                               null comment '项目id',
    `team_name`   varchar(50)                          null comment '班组名称',
    `is_clock_in` char(1)    default '1'               not null comment '范围内打卡（0范围内打卡 1任何地点打卡）默认为1',
    `remark`      varchar(512)                         null comment '备注',
    `create_by`   varchar(64)                          null comment '创建者',
    `update_by`   varchar(64)                          null comment '更新者',
    `create_time` datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time` datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`  datetime                             null comment '删除时间',
    `is_delete`   tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_project_id` (`project_id` ASC) USING BTREE comment '项目id'
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci comment = '项目班组'
  ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `bus_project_team_member`;
CREATE TABLE `bus_project_team_member`
(
    `id`          bigint                             not null auto_increment comment '主键id',
    `team_id`     bigint                             null comment '班组id',
    `project_id`  bigint                             null comment '项目id',
    `member_id`   bigint                             null comment '施工人员id',
    `post_id`     char(1)  default '0'               null comment '岗位（默认为0普通员工，1组长）',
    `remark`      varchar(512)                       null comment '备注',
    `create_time` datetime default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time` datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`  datetime                           null comment '删除时间',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_team_id` (`team_id` ASC) USING BTREE comment '班组id',
    INDEX `idx_project_id` (`project_id` ASC) USING BTREE comment '项目id',
    INDEX `idx_member_id` (`member_id` ASC) USING BTREE comment '施工人员id'
) comment = '项目班组下的成员' collate = utf8mb4_unicode_ci;

DROP TABLE IF EXISTS `bus_machinery`;
CREATE TABLE `bus_machinery`
(
    `id`               bigint                               not null auto_increment comment '主键id',
    `machinery_name`   varchar(16)                          null comment '机械名称',
    `machinery_number` varchar(64)                          null comment '机械型号',
    `project_id`       bigint                               null comment '项目id',
    `number`           int                                  null comment '数量',
    `principal`        varchar(20)                          null comment '负责人',
    `remark`           varchar(512)                         null comment '备注',
    `create_by`        varchar(64)                          null comment '创建者',
    `update_by`        varchar(64)                          null comment '更新者',
    `create_time`      datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`      datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`       datetime                             null comment '删除时间',
    `is_delete`        tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE
) comment = '机械表' collate = utf8mb4_unicode_ci;

DROP TABLE IF EXISTS `bus_machinery_detail`;
CREATE TABLE `bus_machinery_detail`
(
    `id`              bigint                               not null auto_increment comment '主键id',
    `checkout_number` varchar(64)                          null comment '检验证编号',
    `checkout_unit`   varchar(64)                          null comment '检验单位',
    `checkout_date`   varchar(64)                          null comment '检定日期/有效期',
    `status`          char(1)    default '0'               null comment '施工类型状态（0正常 1停用）',
    `type`            char(1)    default '0'               null null comment '0入场 1出场',
    `entry_time`      datetime                             null comment '入场时间',
    `remark`          varchar(512)                         null comment '备注',
    `picture`         varchar(512)                         null comment '图片(英文逗号分隔)',
    `machinery_id`    bigint                               null comment '机械主键id',
    `create_by`       varchar(64)                          null comment '创建者',
    `update_by`       varchar(64)                          null comment '更新者',
    `create_time`     datetime   default CURRENT_TIMESTAMP null comment '创建时间',
    `update_time`     datetime   default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
    `deleted_at`      datetime                             null comment '删除时间',
    `is_delete`       tinyint(4) default 0                 not null comment '是否删除（0正常 1删除）',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_machinery_id` (`machinery_id` ASC) USING BTREE comment '机械主键id'
) comment = '机械详情' collate = utf8mb4_unicode_ci;
