id, org_id, content, author,
to_char(memo_date, 'YYYY-MM-DD') as memo_date,
resolved,
(extract(epoch from created_at) * 1000)::bigint as created_at
insert into re_memo (org_id, content, author, memo_date, resolved, resolved_at)
values (#{orgId}, #{content}, #{author},
coalesce(cast(#{memoDate} as date), current_date),
#{resolved},
case when #{resolved} then now() else null end)
update re_memo set
content = #{content},
author = #{author},
memo_date = coalesce(cast(#{memoDate} as date), memo_date),
resolved = #{resolved},
resolved_at = case
when #{resolved} and resolved_at is null then now()
when not #{resolved} then null
else resolved_at
end,
updated_at = now()
where org_id = #{orgId} and id = #{id}
delete from re_memo where org_id = #{orgId} and id = #{id}
delete from re_memo where org_id = #{orgId}