2.0.0.sql 2.0 KB
-- 增加任务记录字段
ALTER TABLE public.task_record
    ADD remark_content jsonb NULL;

COMMENT ON COLUMN public.task_record.remark_content IS '填写反馈进度';

-- 增加任务记录字段
ALTER TABLE public.task_record
    ADD task_created_by int NOT NULL DEFAULT 0;

COMMENT ON COLUMN public.task_record.task_created_by IS '任务的创建来源';

-- 增加任务记录字段
ALTER TABLE public.task_record
    ADD assist_state int NOT NULL DEFAULT 1;

COMMENT ON COLUMN public.task_record.assist_state IS '辅导异常状态';

-- 创建新表 task_anomaly 异常的任务记录
CREATE TABLE public.task_anomaly(
    id bigserial NOT NULL,
    created_at timestamptz NOT NULL,
    updated_at timestamptz NOT NULL,
    company_id int8 NOT NULL,
    task_id int8 NOT NULL,
    category int8 NOT NULL,
    current_stage jsonb NOT NULL,
    last_stage jsonb NOT NULL,
    task_stage_check jsonb NOT NULL,
    assess_flag int8 NOT NULL DEFAULT 0,
    warn_flag int8 NOT NULL DEFAULT 0,
    assist_flag int8 NOT NULL DEFAULT 0,
    is_last int8 NOT NULL DEFAULT 1,
    record_begin int8 NOT NULL DEFAULT 0,
    notice_who jsonb NOT NULL,
    marks jsonb NOT NULL,
    task_record_id int8 NOT NULL DEFAULT 0,
    remark text NOT NULL DEFAULT ''::text,
    CONSTRAINT task_anomaly_pkey PRIMARY KEY (id)
);

-- task_record 处理旧数据
WITH t_taff_assess_content AS (
    SELECT
        staff_assess_content.staff_assess_id,
        staff_assess_content.category,
        staff_assess_content."name",
        staff_assess_content.remark
    FROM
        task_record
        JOIN staff_assess_content ON task_record.staff_assess_id = staff_assess_content.staff_assess_id
            AND staff_assess_content."name" = task_record.task_name
    WHERE
        1 = 1)
UPDATE
    task_record
SET
    remark_content = t_taff_assess_content.remark
FROM
    t_taff_assess_content
WHERE
    task_record.staff_assess_id = t_taff_assess_content.staff_assess_id
    AND t_taff_assess_content."name" = task_record.task_name;