-- 项目审批配置表
CREATE TABLE FM_PROJECT_APPROVAL_CONFIG (
    ID NUMBER(20) NOT NULL,
    NODE_CODE VARCHAR2(50) NOT NULL,        -- 节点编码：EXECUTE_CHECK(执行-核查), CHECK_APPROVE(核查-核准)
    NODE_NAME VARCHAR2(100) NOT NULL,       -- 节点名称：执行核查、核查核准
    ROLE_ID VARCHAR2(200) NOT NULL,         -- 角色ID（多个角色用逗号分隔）
    ROLE_NAME VARCHAR2(500),                -- 角色名称（冗余字段，便于展示）
    REMARK VARCHAR2(500),                   -- 备注说明
    CREATE_USER NUMBER(20),                 -- 创建人
    CREATE_DEPT NUMBER(20),                 -- 创建部门
    CREATE_TIME DATE DEFAULT SYSDATE,       -- 创建时间
    UPDATE_USER NUMBER(20),                 -- 更新人
    UPDATE_TIME DATE DEFAULT SYSDATE,       -- 更新时间
    STATUS NUMBER(2) DEFAULT 1,             -- 状态：0-禁用，1-启用
    IS_DELETED NUMBER(2) DEFAULT 0,         -- 是否删除：0-未删除，1-已删除
    CONSTRAINT PK_FM_PROJECT_APPROVAL_CONFIG PRIMARY KEY (ID)
);

-- 添加注释
COMMENT ON TABLE FM_PROJECT_APPROVAL_CONFIG IS '项目审批配置表';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.ID IS '主键ID';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.NODE_CODE IS '节点编码：EXECUTE_CHECK(执行-核查), CHECK_APPROVE(核查-核准)';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.NODE_NAME IS '节点名称';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.ROLE_ID IS '角色ID（多个角色用逗号分隔）';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.ROLE_NAME IS '角色名称（冗余字段，便于展示）';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.REMARK IS '备注说明';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.CREATE_USER IS '创建人';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.CREATE_DEPT IS '创建部门';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.UPDATE_USER IS '更新人';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.UPDATE_TIME IS '更新时间';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.STATUS IS '状态：0-禁用，1-启用';
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.IS_DELETED IS '是否删除：0-未删除，1-已删除';

-- 创建索引
CREATE INDEX IDX_CONFIG_NODE_CODE ON FM_PROJECT_APPROVAL_CONFIG(NODE_CODE);
CREATE INDEX IDX_CONFIG_STATUS ON FM_PROJECT_APPROVAL_CONFIG(STATUS);

-- 插入默认配置数据
INSERT INTO FM_PROJECT_APPROVAL_CONFIG (ID, NODE_CODE, NODE_NAME, ROLE_ID, ROLE_NAME, REMARK, STATUS)
VALUES (1, 'PROJECT_APPROVAL', '立项-审批', '', '', '里程碑执行完成后，进入核查环节的审批角色配置', 1);

INSERT INTO FM_PROJECT_APPROVAL_CONFIG (ID, NODE_CODE, NODE_NAME, ROLE_ID, ROLE_NAME, REMARK, STATUS) 
VALUES (1, 'EXECUTE_CHECK', '执行-核查', '', '', '里程碑执行完成后，进入核查环节的审批角色配置', 1);

INSERT INTO FM_PROJECT_APPROVAL_CONFIG (ID, NODE_CODE, NODE_NAME, ROLE_ID, ROLE_NAME, REMARK, STATUS) 
VALUES (2, 'CHECK_APPROVE', '核查-核准', '', '', '里程碑核查通过后，进入核准环节的审批角色配置', 1);

COMMIT;



ALTER TABLE JONHON_MES.FM_PROJECT_MILESTONE ADD NEXT_APPROVER_ID VARCHAR2(100) NULL;
COMMENT ON COLUMN JONHON_MES.FM_PROJECT_MILESTONE.NEXT_APPROVER_ID IS '下一节点审批人ID';
ALTER TABLE JONHON_MES.FM_PROJECT_MILESTONE ADD NEXT_APPROVER_NAME VARCHAR2(100) NULL;
COMMENT ON COLUMN JONHON_MES.FM_PROJECT_MILESTONE.NEXT_APPROVER_NAME IS '下一节点审批人名称';



-- 1. 添加排序字段 SORT_ORDER
ALTER TABLE FM_PROJECT_APPROVAL_CONFIG ADD (SORT_ORDER NUMBER(20));

-- 添加字段注释
COMMENT ON COLUMN FM_PROJECT_APPROVAL_CONFIG.SORT_ORDER IS '排序字段';

-- 2. 将现有数据的排序字段更新为与 ID 一致
UPDATE FM_PROJECT_APPROVAL_CONFIG SET SORT_ORDER = ID;

COMMIT;

ALTER TABLE JONHON_MES.FM_PROJECT_APPLICATION ADD APPROVAL_MAN VARCHAR2(100) NULL;
COMMENT ON COLUMN JONHON_MES.FM_PROJECT_APPLICATION.APPROVAL_MAN IS '审批人';
ALTER TABLE JONHON_MES.FM_PROJECT_APPLICATION ADD APPROVAL_MAN_NAME VARCHAR2(100) NULL;
COMMENT ON COLUMN JONHON_MES.FM_PROJECT_APPLICATION.APPROVAL_MAN_NAME IS '审批人名称';


ALTER TABLE JONHON_MES.FM_PROJECT_APPLICATION MODIFY APPROVAL_MAN NUMBER(38,0);


ALTER TABLE JONHON_MES.FM_PROJECT_MILESTONE MODIFY NEXT_APPROVER_ID NUMBER(38,0);

ALTER TABLE JONHON_MES.FM_PROJECT_MILESTONE ADD GRADE_MAN_ID NUMBER(38,0) NULL;
