id, org_id, seq, site_name, category, board_path, board_name, post_title, url, post_registered, produced_date, published_date, has_attachment, kogl_attached, kogl_type, ai_type, surveyor_note, openable, review_major, review_minor, review_result, judged_kogl_type, judged_ai_type, opinion, lawyer_note, needs_processing, (extract(epoch from web_edited_at) * 1000)::bigint as web_edited_at, (extract(epoch from created_at) * 1000)::bigint as created_at, (extract(epoch from updated_at) * 1000)::bigint as updated_at and (site_name ilike concat('%', #{keyword}, '%') or board_name ilike concat('%', #{keyword}, '%') or post_title ilike concat('%', #{keyword}, '%')) and site_name ilike concat('%', #{site}, '%') and board_name ilike concat('%', #{board}, '%') and post_title ilike concat('%', #{title}, '%') insert into review_item ( org_id, seq, site_name, category, board_path, board_name, post_title, url, post_registered, produced_date, published_date, has_attachment, kogl_attached, kogl_type, ai_type, surveyor_note, openable, review_major, review_minor, review_result, judged_kogl_type, judged_ai_type, opinion, lawyer_note, needs_processing ) values ( #{orgId}, #{seq}, #{siteName}, #{category}, #{boardPath}, #{boardName}, #{postTitle}, #{url}, #{postRegistered}, #{producedDate}, #{publishedDate}, #{hasAttachment}, #{koglAttached}, #{koglType}, #{aiType}, #{surveyorNote}, #{openable}, #{reviewMajor}, #{reviewMinor}, #{reviewResult}, #{judgedKoglType}, #{judgedAiType}, #{opinion}, #{lawyerNote}, #{needsProcessing} ) on conflict (org_id, seq) do update set site_name = excluded.site_name, category = excluded.category, board_path = excluded.board_path, board_name = excluded.board_name, post_title = excluded.post_title, url = excluded.url, post_registered = excluded.post_registered, produced_date = excluded.produced_date, published_date = excluded.published_date, has_attachment = case when review_item.web_edited_at is null then excluded.has_attachment else review_item.has_attachment end, kogl_attached = case when review_item.web_edited_at is null then excluded.kogl_attached else review_item.kogl_attached end, kogl_type = case when review_item.web_edited_at is null then excluded.kogl_type else review_item.kogl_type end, ai_type = case when review_item.web_edited_at is null then excluded.ai_type else review_item.ai_type end, surveyor_note = excluded.surveyor_note, openable = case when review_item.web_edited_at is null then excluded.openable else review_item.openable end, review_major = case when review_item.web_edited_at is null then excluded.review_major else review_item.review_major end, review_minor = case when review_item.web_edited_at is null then excluded.review_minor else review_item.review_minor end, review_result = case when review_item.web_edited_at is null then excluded.review_result else review_item.review_result end, judged_kogl_type = case when review_item.web_edited_at is null then excluded.judged_kogl_type else review_item.judged_kogl_type end, judged_ai_type = case when review_item.web_edited_at is null then excluded.judged_ai_type else review_item.judged_ai_type end, opinion = case when review_item.web_edited_at is null then excluded.opinion else review_item.opinion end, lawyer_note = case when review_item.web_edited_at is null then excluded.lawyer_note else review_item.lawyer_note end, needs_processing = case when review_item.web_edited_at is null then excluded.needs_processing else review_item.needs_processing end, updated_at = now() update review_item set has_attachment = #{hasAttachment}, kogl_attached = #{koglAttached}, kogl_type = #{koglType}, ai_type = #{aiType}, openable = #{openable}, review_major = #{reviewMajor}, review_minor = #{reviewMinor}, review_result = #{reviewResult}, judged_kogl_type = #{judgedKoglType}, judged_ai_type = #{judgedAiType}, opinion = #{opinion}, lawyer_note = #{lawyerNote}, needs_processing = #{needsProcessing}, web_edited_at = now(), updated_at = now() where org_id = #{orgId} and id = #{id} update review_item set review_result = coalesce(#{reviewResult}, review_result), judged_kogl_type = coalesce(#{judgedKoglType}, judged_kogl_type), opinion = coalesce(#{opinion}, opinion), lawyer_note = coalesce(#{lawyerNote}, lawyer_note), web_edited_at = now(), updated_at = now() where org_id = #{orgId} and id in #{id} delete from review_item where org_id = #{orgId} and id in #{id} delete from review_item where org_id = #{orgId} and id = #{id} delete from review_item where org_id = #{orgId}