CREATE TABLE oa_project_operation_log
(
    log_id         BIGINT AUTO_INCREMENT COMMENT '主键ID' PRIMARY KEY,
    project_id     BIGINT                                   NOT NULL COMMENT '所属项目ID',
    target_type    TINYINT      DEFAULT 1                   NOT NULL COMMENT '操作对象类型: 1-项目进度(schedule) 2-进度步骤(step) 3-任务(task) 4-延期申请(delay)',
    target_id      BIGINT                                   NULL COMMENT '操作对象ID',
    target_name    VARCHAR(200) DEFAULT ''                  NOT NULL COMMENT '操作对象名称(冗余存储，便于展示)',
    operation_type TINYINT      DEFAULT 1                   NOT NULL COMMENT '操作类型: 1-新增 2-修改 3-删除 4-状态变更 5-完成 6-申请延期 7-审批通过 8-审批驳回',
    operation_desc VARCHAR(500) DEFAULT ''                  NOT NULL COMMENT '操作描述（可读文字）',
    before_value   TEXT                                     NULL COMMENT '操作前字段快照(JSON)',
    after_value    TEXT                                     NULL COMMENT '操作后字段快照(JSON)',
    operator       VARCHAR(64)  DEFAULT ''                  NOT NULL COMMENT '操作人昵称',
    operate_time   DATETIME     DEFAULT CURRENT_TIMESTAMP   NOT NULL COMMENT '操作时间',
    create_by      VARCHAR(64)  DEFAULT ''                  NOT NULL COMMENT '创建者',
    create_time    DATETIME     DEFAULT CURRENT_TIMESTAMP   NOT NULL COMMENT '创建时间',
    update_by      VARCHAR(64)  DEFAULT ''                  NOT NULL COMMENT '更新者',
    update_time    DATETIME     DEFAULT CURRENT_TIMESTAMP   NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    del_flag       TINYINT      DEFAULT 0                   NOT NULL COMMENT '删除标志: 0-正常 1-删除',
    remark         VARCHAR(500) DEFAULT ''                  NOT NULL COMMENT '备注'
) COMMENT='项目操作历史记录表' COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;

CREATE INDEX idx_project_id ON oa_project_operation_log (project_id);
CREATE INDEX idx_target ON oa_project_operation_log (target_type, target_id);
CREATE INDEX idx_operate_time ON oa_project_operation_log (operate_time);
CREATE INDEX idx_operator ON oa_project_operation_log (operator);
