Files
zyt/server/sql/1.9.20260709/add_qywx_contact_readd_flag.sql
T
2026-07-15 09:07:29 +08:00

18 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 企微客户表:新增「以前加过」标记
-- 语义:该客户本次添加之前就加过企业(被删除后重新添加,或已是企业客户又被其他员工添加)。
-- 写入:客户联系回调收到 add_external_contact 时,若本地已存在该 external_userid(含软删行)则置 1
-- 置 1 后不回退(历史事实)。全量同步不改此字段。
ALTER TABLE `zyt_qywx_external_contact`
ADD COLUMN `readd_flag` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '以前加过:1=本次添加前已加过企业(重加/多员工添加)' AFTER `external_first_add_time`;
-- 历史回填:事件流水中有 2 条及以上 add_external_contact 的客户,说明发生过重复添加
UPDATE `zyt_qywx_external_contact` c
INNER JOIN (
SELECT `external_userid`
FROM `zyt_qywx_external_contact_event`
WHERE `change_type` = 'add_external_contact' AND `external_userid` <> ''
GROUP BY `external_userid`
HAVING COUNT(*) >= 2
) e ON e.`external_userid` = c.`external_userid`
SET c.`readd_flag` = 1;