You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Global-sales/doc/运维语句.sql

92 lines
2.6 KiB
SQL

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//
SELECT group_concat(opi_sn separator ',') as 'sn_list' FROM (
SELECT
opi_sn,COUNT(*)
FROM whatsapp_session
where opi_sn is not null and opi_sn not in (29,383,404,227)
GROUP by opi_sn
) session_count
SELECT
OPI_SN, OPI_Code,OPI_Name,OPI_DEI_SN,OPI_FirstName,OPI_RealName
FROM
dbo.OperatorInfo
where
DeleteFlag = 0 and
OPI_SN in (162,31,32,33,34,599,600,353,352,350,351,35,606,495,293,525,114,587,585,519,522,476,354,451,216,143,586,539,370,512)
// HT
SELECT opi.OPI_Code,
opi.OPI_Name, tpa.* FROM dbo.ThirdPlatformAccount_Bind tpa
left join OperatorInfo opi
on opi.opi_sn = tpa.TPA_OPI_SN
where opi.DeleteFlag = 0
//
SELECT *
FROM whatsapp_session
WHERE coli_sn = 0 AND last_received_time IS NOT NULL ## AND opi_sn = 599
ORDER BY last_received_time DESC
// WA
SELECT *
FROM whatsapp_session
WHERE whatsapp_phone_number_bak IS not NULL
/**
* ---------------------------------------------------------
* 分配会话到某个订单
*/
UPDATE whatsapp_session
SET coli_sn = 1074885
WHERE sn = 47
AND msg.froms = @S_WAID;
UPDATE whatsapp_inboundmessage msg
INNER JOIN whatsapp_session s ON s.whatsapp_phone_number = msg.froms
AND msg.msg_direction = 'inbound'
SET msg.coli_sn = s.coli_sn
WHERE ifnull(msg.coli_sn, 0) = 0
AND msg.msg_direction = 'inbound'
AND msg.froms = '393343998897';
UPDATE whatsapp_inboundmessage msg
INNER JOIN whatsapp_session s ON s.whatsapp_phone_number = msg.tos
AND msg.msg_direction = 'outbound'
SET msg.coli_sn = s.coli_sn
WHERE ifnull(msg.coli_sn, 0) = 0
AND msg.msg_direction = 'outbound'
AND msg.tos = '393343998897';
/**
* end 分配会话到某个订单
* ---------------------------------------------------------
*/
/**
* ---------------------------------------------------------
* 未分配会话 - 处理
*/
-- 查找未分配顾问的会话
SELECT s.sn as S_SN, s.whatsapp_phone_number as S_WAID, s.*
FROM whatsapp_session s
WHERE opi_sn IS NULL OR opi_sn = 0
-- 更新 会话表顾问
UPDATE sale_system.whatsapp_session
SET opi_sn = @OPI_SN
,coli_sn = @COLI_SN
WHERE sn = @S_SN;
-- 更新 消息表顾问
UPDATE sale_system.whatsapp_inboundmessage msg
SET opi_sn = @OPI_SN
,coli_sn = @COLI_SN
WHERE IFNULL(msg.opi_sn, 0) <= 0
AND msg.msg_direction = 'inbound'
AND msg.froms = @S_WAID;
/**
* end 未分配会话 - 处理
* ---------------------------------------------------------
*/