DROP TABLE mail_source_etl;

ALTER TABLE "mailbox"."mail_mark"
    ADD COLUMN "sign_timeout" bool DEFAULT false,
  ADD COLUMN "contact_writer_timeout" bool DEFAULT false,
  ADD COLUMN "process_timeout" bool DEFAULT false;

COMMENT ON COLUMN "mailbox"."mail_mark"."sign_timeout" IS '签收超时';

COMMENT ON COLUMN "mailbox"."mail_mark"."contact_writer_timeout" IS '联系群众超时';

COMMENT ON COLUMN "mailbox"."mail_mark"."process_timeout" IS '办理超时';

update mail_mark mm set mm.sign_timeout = true from mail_flow mf left join mail_flow mf2 on mf.mail_id = mf2.mail_id and mf2.flow_key = 'three_sign' where mm.mail_id = mf.mail_id and mf.flow_key = 'first_distribute' and
    EXTRACT(EPOCH FROM mf2.create_time - mf.create_time) > 600;

update mail_mark mm set mm.contact_writer_timeout = true from mail m where mm.mail_id = m.id and m.contact_duration > 1800;

ALTER TABLE "mailbox"."favorite"
    ADD COLUMN "role_id" int4,
  ADD COLUMN "dept_id" int4;

COMMENT ON COLUMN "mailbox"."favorite"."role_id" IS '角色ID';

COMMENT ON COLUMN "mailbox"."favorite"."dept_id" IS '部门ID';

