Răsfoiți Sursa

未读状态修改

WH01243 3 ani în urmă
părinte
comite
fb9209417f

+ 8 - 3
rpc/messagecenter/internal/logic/closechatsessionlogic.go

@@ -28,10 +28,15 @@ func NewCloseChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 func (l *CloseChatSessionLogic) CloseChatSession(in *messagecenter.CloseSessionReq) (*messagecenter.ChatSessionResp, error) {
 func (l *CloseChatSessionLogic) CloseChatSession(in *messagecenter.CloseSessionReq) (*messagecenter.ChatSessionResp, error) {
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	error_code := m.CloseChatSession(in)
-	error_message := "修改失败"
-	if error_code == 0 {
+	fool := m.CloseChatSession(in)
+	error_message := ""
+	error_code := int64(0)
+	if fool {
+		error_code = int64(0)
 		error_message = ""
 		error_message = ""
+	} else {
+		error_code = int64(1)
+		error_message = "修改失败"
 	}
 	}
 	return &messagecenter.ChatSessionResp{
 	return &messagecenter.ChatSessionResp{
 		ErrorCode: error_code,
 		ErrorCode: error_code,

+ 8 - 3
rpc/messagecenter/internal/logic/createchatsessionlogic.go

@@ -30,10 +30,15 @@ func NewCreateChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 func (l *CreateChatSessionLogic) CreateChatSession(in *messagecenter.ChatSessionReq) (*messagecenter.ChatSessionResp, error) {
 func (l *CreateChatSessionLogic) CreateChatSession(in *messagecenter.ChatSessionReq) (*messagecenter.ChatSessionResp, error) {
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	error_code, sessionId := m.CreateChatSession(in)
-	error_message := "创建失败"
-	if error_code == 0 {
+	fool, sessionId := m.CreateChatSession(in)
+	error_message := ""
+	error_code := int64(0)
+	if fool {
+		error_code = int64(0)
 		error_message = ""
 		error_message = ""
+	} else {
+		error_code = int64(1)
+		error_message = "修改失败"
 	}
 	}
 	return &messagecenter.ChatSessionResp{
 	return &messagecenter.ChatSessionResp{
 		ErrorCode: error_code,
 		ErrorCode: error_code,

+ 7 - 2
rpc/messagecenter/internal/logic/savemessagelogic.go

@@ -28,9 +28,14 @@ func NewSaveMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveM
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	error_code, error_message, content, messageId := m.SaveMessage(in)
-	if error_code == 0 {
+	fool, error_message, content, messageId := m.SaveMessage(in)
+	error_code := int64(0)
+	if fool {
+		error_code = int64(0)
 		error_message = ""
 		error_message = ""
+	} else {
+		error_code = int64(1)
+		error_message = "修改失败"
 	}
 	}
 	return &messagecenter.SaveMessageResp{
 	return &messagecenter.SaveMessageResp{
 		ErrorCode: error_code,
 		ErrorCode: error_code,

+ 8 - 3
rpc/messagecenter/internal/logic/updatereadbyidlogic.go

@@ -29,10 +29,15 @@ func (l *UpdateReadByIdLogic) UpdateReadById(in *messagecenter.ReadStateReq) (*m
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 
 
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	error_code := m.UpdateReadById(in)
-	error_message := "修改失败"
-	if error_code == 0 {
+	fool := m.UpdateReadById(in)
+	error_message := ""
+	error_code := int64(0)
+	if fool {
+		error_code = int64(0)
 		error_message = ""
 		error_message = ""
+	} else {
+		error_code = int64(1)
+		error_message = "修改失败"
 	}
 	}
 	return &messagecenter.CurrencyResp{
 	return &messagecenter.CurrencyResp{
 		ErrorCode: error_code,
 		ErrorCode: error_code,

+ 99 - 0
service/coverage

@@ -0,0 +1,99 @@
+mode: set
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:16.122,19.19 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:26.2,32.24 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:35.2,35.8 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:19.19,22.3 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:22.8,25.3 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:32.24,34.3 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:37.106,40.22 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:80.2,80.18 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:84.2,84.8 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:40.22,52.3 8 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:52.8,54.21 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:57.3,58.25 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:61.3,62.23 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:67.3,71.18 5 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:54.21,56.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:58.25,60.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:62.23,64.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:71.18,77.4 4 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:80.18,83.3 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:86.133,89.22 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:125.2,125.71 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:261.2,261.40 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:89.22,92.22 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:116.3,117.22 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:93.13,94.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:104.4,104.9 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:105.10,106.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:113.4,113.9 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:94.23,97.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:97.10,100.25 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:100.25,102.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:106.23,109.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:109.10,112.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:117.22,119.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:119.9,120.56 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:120.56,122.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:125.71,152.23 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:184.3,184.43 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:215.3,227.43 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:258.3,259.33 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:152.23,164.23 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:181.4,182.34 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:164.23,172.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:172.10,180.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:184.43,186.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:186.23,194.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:194.10,202.25 7 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:202.25,205.6 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:207.9,214.4 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:227.43,229.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:229.23,238.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:238.10,246.25 7 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:246.25,248.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:250.9,257.4 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:264.103,268.19 4 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:271.2,271.20 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:288.2,293.35 5 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:302.2,302.12 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:326.2,326.20 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:268.19,270.3 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:272.9,275.8 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:276.18,277.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:286.3,286.8 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:277.23,281.4 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:281.9,285.4 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:293.35,295.22 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:295.22,296.27 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:296.27,298.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:302.12,304.21 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:304.21,306.22 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:307.11,315.10 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:316.14,317.25 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:322.5,322.10 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:317.25,319.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:319.11,321.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:328.107,329.65 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:349.2,349.24 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:329.65,331.32 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:337.3,347.23 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:331.32,333.30 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:333.30,335.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:351.83,352.66 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:359.2,359.13 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:352.66,358.3 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:362.125,363.77 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:363.77,365.20 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:371.3,374.20 4 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:383.3,383.46 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:365.20,367.37 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:367.37,369.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:374.20,378.4 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:378.9,378.27 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:378.27,380.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:380.9,380.27 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:380.27,382.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:386.78,387.72 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:395.2,395.13 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:387.72,394.3 3 1

+ 499 - 0
service/coverage.html

@@ -0,0 +1,499 @@
+
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+		<title>service: Go Coverage Report</title>
+		<style>
+			body {
+				background: black;
+				color: rgb(80, 80, 80);
+			}
+			body, pre, #legend span {
+				font-family: Menlo, monospace;
+				font-weight: bold;
+			}
+			#topbar {
+				background: black;
+				position: fixed;
+				top: 0; left: 0; right: 0;
+				height: 42px;
+				border-bottom: 1px solid rgb(80, 80, 80);
+			}
+			#content {
+				margin-top: 50px;
+			}
+			#nav, #legend {
+				float: left;
+				margin-left: 10px;
+			}
+			#legend {
+				margin-top: 12px;
+			}
+			#nav {
+				margin-top: 10px;
+			}
+			#legend span {
+				margin: 0 5px;
+			}
+			.cov0 { color: rgb(192, 0, 0) }
+.cov1 { color: rgb(128, 128, 128) }
+.cov2 { color: rgb(116, 140, 131) }
+.cov3 { color: rgb(104, 152, 134) }
+.cov4 { color: rgb(92, 164, 137) }
+.cov5 { color: rgb(80, 176, 140) }
+.cov6 { color: rgb(68, 188, 143) }
+.cov7 { color: rgb(56, 200, 146) }
+.cov8 { color: rgb(44, 212, 149) }
+.cov9 { color: rgb(32, 224, 152) }
+.cov10 { color: rgb(20, 236, 155) }
+
+		</style>
+	</head>
+	<body>
+		<div id="topbar">
+			<div id="nav">
+				<select id="files">
+				
+				<option value="file0">bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go (100.0%)</option>
+				
+				</select>
+			</div>
+			<div id="legend">
+				<span>not tracked</span>
+			
+				<span class="cov0">not covered</span>
+				<span class="cov8">covered</span>
+			
+			</div>
+		</div>
+		<div id="content">
+		
+		<pre class="file" id="file0" style="display: none">package service
+
+import (
+        "database/sql"
+        "fmt"
+        "log"
+        "time"
+
+        quitl "app.yhyue.com/moapp/jybase/common"
+        util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
+        "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
+)
+
+type MessaggeService struct{}
+
+func (b MessaggeService) Count(newUserId, userType, entUserId int64) (count int, last map[string]interface{}, err error) <span class="cov8" title="1">{
+        v := make([]interface{}, 0)
+        sqlStr := ""
+        if userType == 1 </span><span class="cov8" title="1">{
+                sqlStr = "select  count(b.id) from   socialize_chat_session a  left  join  socialize_message_mailbox  b ON a.id=b.own_id  where  b.type=5 and   a.customer_service_id=?   and  b.isread=0  and own_type = 1 order by create_time"
+                v = append(v, entUserId)
+        }</span> else<span class="cov8" title="1"> {
+                sqlStr = "select  count(b.id) from    socialize_message_mailbox  b  where   b.send_user_id !=?    and   b.own_id=?  and  b.isread=0 and own_type = 2 order by create_time"
+                v = append(v, newUserId, newUserId)
+        }</span>
+        <span class="cov8" title="1">fmt.Println(sqlStr, v)
+        rs := util.Mysql.CountBySql(sqlStr, v...)
+        log.Println(rs)
+        count = int(rs)
+        //最后一条信息查询
+        lastData := util.Mysql.SelectBySql("SELECT  c.* FROM  socialize_message_mailbox b   left join socialize_message c on  b.messag_id=c.id WHERE  b.send_user_id != ?   AND b.own_id = ?  and   b.isread=0  AND own_type = 2  ORDER BY  create_time DESC   LIMIT 0,1", newUserId, newUserId)
+        if len(*lastData) &gt; 0 </span><span class="cov8" title="1">{
+                last = (*lastData)[0]
+        }</span>
+        <span class="cov8" title="1">return</span>
+}
+func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string]interface{}, err error) <span class="cov8" title="1">{
+        v := make([]interface{}, 0)
+        sqlStr := ""
+        if in.UserType == 2 </span><span class="cov8" title="1">{
+                //用户最后一次信息查询
+                userSql := "SELECT  MAX( c.id )   as messageId  FROM  socialize_message_mailbox c  WHERE  c.own_id = ?   AND c.type = 2   AND c.own_type = 2  GROUP BY  (  CASE        WHEN c.send_user_id &gt; c.receive_user_id THEN    CONCAT( c.send_user_id, c.receive_user_id )     WHEN c.send_user_id &lt; c.receive_user_id THEN    CONCAT( c.receive_user_id, c.send_user_id )    END    )  "
+                data = util.Mysql.SelectBySql(userSql, in.NewUserId)
+                userMessageId := util.Inhandle(data)
+                //客服最后一次信息查询
+                customerSql := " SELECT   max( c.id )   as messageId  FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id )   WHERE   c.own_id = ?    AND ( c.type = 4 OR c.type = 5  )    AND c.own_type = 2  and   d.user_id=c.own_id  GROUP BY   d.ent_id  "
+                data = util.Mysql.SelectBySql(customerSql, in.NewUserId)
+                customerMessageId := util.Inhandle(data)
+                //用户的列表
+                sqlStr = "SELECT IF ( b.nickname = '', CONCAT(SUBSTR( b.phone, 1, 3 ),'****',SUBSTR( b.phone, 8, 11)), b.nickname ) AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, 2 AS userType, a.create_time, a.type AS itemType, ( SELECT  count( h.id )  FROM  socialize_message_mailbox h  WHERE  h.type = 2   AND h.own_id = ?   AND h.own_type = 2   AND  h.receive_user_id = ? and   h.send_user_id=b.id   AND h.isread = 0  ) AS number  FROM socialize_message_mailbox a LEFT JOIN base_user b ON  b.id = a.receive_user_id or  b.id = a.send_user_id  LEFT JOIN socialize_message e ON e.id = a.messag_id  WHERE a.id IN ( " + userMessageId + " )   AND b.id != ? UNION ALL SELECT  f.nickname AS name,    b.ent_id AS id,  e.title,f.headimage AS headimg,  e.type,  e.link,  e.content,  1 AS userType,  a.create_time,  a.type AS itemType,  (  SELECT   count( h.id )   FROM   socialize_message_mailbox h   WHERE   ( h.type = 4 OR h.type = 5  )    AND h.own_id = ?    AND h.own_type = 2   AND  h.send_user_type = 1 and  h.receive_user_id = ?    AND h.isread = 0   ) AS number  FROM  socialize_message_mailbox a  LEFT JOIN socialize_chat_session b ON IF  ( a.send_user_type = 1, b.id = a.send_user_id, b.id = a.receive_user_id )  LEFT JOIN socialize_message e ON e.id = a.messag_id  left join socialize_tenant_robot  f on f.ent_id=b.ent_id   WHERE  a.id IN (  " + customerMessageId + " )  ORDER BY create_time DESC"
+                v = append(v, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId)
+        }</span> else<span class="cov8" title="1"> {
+                phoneSql := ""
+                if in.Phone != "" </span><span class="cov8" title="1">{
+                        phoneSql = "and  b.phone='" + in.Phone + "'"
+                }</span>
+                <span class="cov8" title="1">startTimeSql := ""
+                if in.StartTime != "" </span><span class="cov8" title="1">{
+                        startTimeSql = " and  DATE_FORMAT(c.create_time,'%Y-%m-%d') &gt;= '" + in.StartTime + "' "
+                }</span>
+                <span class="cov8" title="1">endTimeSql := ""
+                if in.EndTime != "" </span><span class="cov8" title="1">{
+                        endTimeSql = " and DATE_FORMAT(c.create_time,'%Y-%m-%d') &lt;= '" + in.EndTime + "' "
+                }</span>
+
+                //先获取每个用户最后聊天记录
+                <span class="cov8" title="1">userSql := " SELECT   MAX( c.id ) as messageId   FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id )   WHERE   c.own_type = 1    AND d.customer_service_id = ?   and ( c.type = 4 OR c.type = 5 )   AND d.customer_service_id !=0    " + startTimeSql + endTimeSql + "   GROUP BY   (   CASE          WHEN  c.send_user_type =2 THEN  CONCAT( c.send_user_id )   WHEN c.send_user_type =1 THEN  CONCAT( c.receive_user_id )     END     ) "
+                v = append(v, in.EntUserId)
+                log.Println(userSql, v)
+                data = util.Mysql.SelectBySql(userSql, v...)
+                if data != nil </span><span class="cov8" title="1">{
+                        customerMessageId := util.Inhandle(data)
+                        //客服的用户列表
+                        sqlStr = "SELECT  IF  ( b.nickname = '', CONCAT(SUBSTR( b.phone, 1, 3 ),'****',SUBSTR( b.phone, 8, 11)), b.nickname ) AS name,  b.id,  e.title,  b.headimg,  e.type,  e.link,  e.content,  a.create_time,  (  SELECT   count( h.id )   FROM   socialize_message_mailbox h   WHERE   ( h.type = 4 OR h.type = 5 )    AND h.own_type = 1   AND  IF   ( h.send_user_type = 1, h.send_user_id = f.id, h.receive_user_id = f.id )    AND h.isread = 0   ) AS number   FROM  socialize_message_mailbox a  LEFT JOIN base_user b ON  IF  ( a.send_user_type = 1, b.id = a.receive_user_id, b.id = a.send_user_id )  LEFT JOIN socialize_message e ON e.id = a.messag_id  LEFT JOIN socialize_chat_session f ON  IF  ( a.send_user_type = 1, f.id = a.send_user_id, f.id = a.receive_user_id )   WHERE  a.id IN  (" + customerMessageId + ")" + phoneSql + "   ORDER BY  a.create_time DESC"
+                        fmt.Println(in.EntUserId)
+                        v = make([]interface{}, 0)
+                }</span>
+
+        }
+        <span class="cov8" title="1">if sqlStr != "" </span><span class="cov8" title="1">{
+                fmt.Println(sqlStr, v)
+                data = util.Mysql.SelectBySql(sqlStr, v...)
+        }</span>
+        <span class="cov8" title="1">return</span>
+}
+func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId int64) <span class="cov8" title="1">{
+        //先插入信息表
+        //判断会话标识是否属于本人
+        if in.ItemType != 2 </span><span class="cov8" title="1">{
+                userId := int64(0)
+                sessionId := int64(0)
+                switch in.ItemType </span>{
+                case 4, 5:<span class="cov8" title="1">
+                        if in.OwnType == 1 </span><span class="cov8" title="1">{
+                                sessionId = in.ReceiveId
+                                userId = in.NewUserId
+                        }</span> else<span class="cov8" title="1"> {
+                                sessionId = in.SendId
+                                userId = in.ReceiveId
+                                if in.ItemType == 4 </span><span class="cov8" title="1">{
+                                        userId = in.NewUserId
+                                }</span>
+                        }
+                        <span class="cov8" title="1">break</span>
+                case 6:<span class="cov8" title="1">
+                        if in.OwnType == 1 </span><span class="cov8" title="1">{
+                                sessionId = in.ReceiveId
+                                userId = in.NewUserId
+                        }</span> else<span class="cov8" title="1"> {
+                                sessionId = in.SendId
+                                userId = in.ReceiveId
+                        }</span>
+                        <span class="cov8" title="1">break</span>
+                }
+                //查找会话信息
+                <span class="cov8" title="1">chatJson := util.Mysql.FindOne("socialize_chat_session", map[string]interface{}{"id": sessionId}, "user_id", "")
+                if chatJson == nil </span><span class="cov8" title="1">{
+                        return false, "会话标识不存在", "", 0
+                }</span> else<span class="cov8" title="1"> {
+                        if userId != quitl.Int64All((*chatJson)["user_id"]) </span><span class="cov8" title="1">{
+                                return false, "会话标识不属于此用户", "", 0
+                        }</span>
+                }
+        }
+        <span class="cov8" title="1">fool = util.Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool </span><span class="cov8" title="1">{
+                //先插入信息表
+                message := map[string]interface{}{
+                        "appid":         in.Appid,
+                        "title":         in.Title,
+                        "content":       in.Content,
+                        "item":          in.ItemType,
+                        "type":          in.Type,
+                        "link":          in.Link,
+                        "create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+                        "create_person": in.SendId,
+                }
+                ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
+                receiveOk := int64(0)
+                messageId = ok
+                //在插入邮箱表socialize_message_mailbox
+                messageMailBox := map[string]interface{}{
+                        "appid":         in.Appid,
+                        "messag_id":     ok,
+                        "type":          in.ItemType,
+                        "create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+                        "isread":        0,
+                        "send_isdel":    0,
+                        "receive_isdel": 0,
+                        "iswithdraw":    0,
+                }
+                //系统信息处理
+                if in.ItemType == 6 </span><span class="cov8" title="1">{
+                        messageMailBox = map[string]interface{}{
+                                "appid":         in.Appid,
+                                "messag_id":     ok,
+                                "type":          in.ItemType,
+                                "create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+                                "read_time":     time.Now().Local().Format(util.Date_Full_Layout),
+                                "isread":        1,
+                                "send_isdel":    0,
+                                "receive_isdel": 0,
+                                "iswithdraw":    0,
+                        }
+                        if in.OwnType == 1 </span><span class="cov8" title="1">{
+                                //用户接受系统信息
+                                messageMailBox["own_type"] = 2
+                                messageMailBox["send_user_type"] = 1
+                                messageMailBox["receive_user_type"] = 2
+                                messageMailBox["own_id"] = in.NewUserId
+                                messageMailBox["send_user_id"] = in.ReceiveId
+                                messageMailBox["receive_user_id"] = in.NewUserId
+                        }</span> else<span class="cov8" title="1"> {
+                                //客服接受系统信息
+                                messageMailBox["own_type"] = 1
+                                messageMailBox["send_user_type"] = 2
+                                messageMailBox["receive_user_type"] = 1
+                                messageMailBox["own_id"] = in.SendId
+                                messageMailBox["send_user_id"] = in.ReceiveId
+                                messageMailBox["receive_user_id"] = in.SendId
+                        }</span>
+                        <span class="cov8" title="1">receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+                        return ok &gt; 1 &amp;&amp; receiveOk &gt; 1</span>
+                }
+                <span class="cov8" title="1">if in.ItemType == 4 || in.ItemType == 5 </span><span class="cov8" title="1">{
+                        //客服或者机器人聊天
+                        if in.OwnType == 1 </span><span class="cov8" title="1">{
+                                // (用户发送)客服接受
+                                messageMailBox["own_type"] = 1
+                                messageMailBox["send_user_type"] = 2
+                                messageMailBox["receive_user_type"] = 1
+                                messageMailBox["own_id"] = in.ReceiveId
+                                messageMailBox["send_user_id"] = in.NewUserId
+                                messageMailBox["receive_user_id"] = in.ReceiveId
+                        }</span> else<span class="cov8" title="1"> {
+                                //客服发送(用户接收信息)
+                                messageMailBox["own_type"] = 2
+                                messageMailBox["send_user_type"] = 1
+                                messageMailBox["receive_user_type"] = 2
+                                messageMailBox["own_id"] = in.ReceiveId
+                                messageMailBox["send_user_id"] = in.SendId
+                                messageMailBox["receive_user_id"] = in.ReceiveId
+                                if in.ItemType == 4 </span><span class="cov8" title="1">{
+                                        messageMailBox["receive_user_id"] = in.NewUserId
+                                        messageMailBox["own_id"] = in.NewUserId
+                                }</span>
+                        }
+                } else<span class="cov8" title="1"> {
+                        messageMailBox["own_type"] = 2
+                        messageMailBox["send_user_type"] = 2
+                        messageMailBox["receive_user_type"] = 2
+                        messageMailBox["own_id"] = in.ReceiveId
+                        messageMailBox["send_user_id"] = in.NewUserId
+                        messageMailBox["receive_user_id"] = in.ReceiveId
+                }</span>
+                <span class="cov8" title="1">receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+                messageMailBox = map[string]interface{}{
+                        "appid":         in.Appid,
+                        "messag_id":     ok,
+                        "type":          in.ItemType,
+                        "create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+                        "read_time":     time.Now().Local().Format(util.Date_Full_Layout),
+                        "isread":        1,
+                        "send_isdel":    0,
+                        "receive_isdel": 0,
+                        "iswithdraw":    0,
+                }
+                if in.ItemType == 4 || in.ItemType == 5 </span><span class="cov8" title="1">{
+                        //客服或者机器人聊天
+                        if in.OwnType == 1 </span><span class="cov8" title="1">{
+                                //用户发送(用户接受)
+                                messageMailBox["own_type"] = 2
+                                messageMailBox["send_user_type"] = 2
+                                messageMailBox["receive_user_type"] = 1
+                                messageMailBox["own_id"] = in.NewUserId
+                                messageMailBox["send_user_id"] = in.NewUserId
+                                messageMailBox["receive_user_id"] = in.ReceiveId
+
+                        }</span> else<span class="cov8" title="1"> {
+                                //客服发送信息(用户接受)
+                                messageMailBox["own_type"] = 1
+                                messageMailBox["send_user_type"] = 1
+                                messageMailBox["receive_user_type"] = 2
+                                messageMailBox["own_id"] = in.SendId
+                                messageMailBox["send_user_id"] = in.SendId
+                                messageMailBox["receive_user_id"] = in.ReceiveId
+                                if in.ItemType == 4 </span><span class="cov8" title="1">{
+                                        messageMailBox["receive_user_id"] = in.NewUserId
+                                }</span>
+                        }
+                } else<span class="cov8" title="1"> {
+                        messageMailBox["own_type"] = 2
+                        messageMailBox["send_user_type"] = 2
+                        messageMailBox["receive_user_type"] = 2
+                        messageMailBox["own_id"] = in.NewUserId
+                        messageMailBox["send_user_id"] = in.NewUserId
+                        messageMailBox["receive_user_id"] = in.ReceiveId
+                }</span>
+                <span class="cov8" title="1">receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+                return ok &gt; 1 &amp;&amp; receiveOk &gt; 1</span>
+        })
+        <span class="cov8" title="1">return fool, "", in.Content, messageId</span>
+
+}
+func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) <span class="cov8" title="1">{
+        sqlStr := ""
+        countSql := ""
+        lastStr := "  "
+        if in.LastId &gt; 0 </span><span class="cov8" title="1">{
+                lastStr = " and  a.messag_id &lt; " + quitl.InterfaceToStr(in.LastId)
+        }</span>
+        <span class="cov8" title="1">switch in.MsgType </span>{
+        case 2:<span class="cov8" title="1"> //点对点聊天
+                sqlStr = "SELECT     a.messag_id as messageId,b.* ,if(a.own_id = a.send_user_id,1,2) as fool     FROM     socialize_message_mailbox a     LEFT JOIN socialize_message b on  a.messag_id=b.id     left  join  base_user c on  c.id=a.send_user_id      left join  base_user d on  d.id=a.receive_user_id     where  a.own_id= " + quitl.InterfaceToStr(in.NewUserId) + " and ((a.send_user_id= " + quitl.InterfaceToStr(in.NewUserId) + " and   a.receive_user_id= " + quitl.InterfaceToStr(in.SendId) + ") or (a.send_user_id= " + quitl.InterfaceToStr(in.SendId) + " and  a.receive_user_id= " + quitl.InterfaceToStr(in.NewUserId) + ")) and  a.type=2 " + lastStr + "  ORDER BY a.create_time desc ,a.id   asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
+                countSql = "SELECT     count(b.id)     FROM     socialize_message_mailbox a     LEFT JOIN socialize_message b on  a.messag_id=b.id     left  join  base_user c on  c.id=a.send_user_id      left join  base_user d on  d.id=a.receive_user_id     where  a.own_id=" + quitl.InterfaceToStr(in.NewUserId) + " and ((a.send_user_id=" + quitl.InterfaceToStr(in.NewUserId) + " and   a.receive_user_id=" + quitl.InterfaceToStr(in.SendId) + ") or (a.send_user_id=" + quitl.InterfaceToStr(in.SendId) + " and  a.receive_user_id=" + quitl.InterfaceToStr(in.NewUserId) + ")) and  a.type=2 " + lastStr
+                break</span>
+        case 4, 5, 6, 7:<span class="cov8" title="1"> //客服聊天
+                if in.UserType == 1 </span><span class="cov8" title="1">{
+                        //客服聊天记录查看
+                        sqlStr = "SELECT   a.messag_id as messageId,b.*,   IF   ( a.own_id = a.send_user_id, 1, 2 ) AS fool,   a.send_user_type,   a.type AS itemType,   d.nickname AS robotName,   d.headimage AS robotImg,   c.customer_service_name AS setName ,   c.user_id   FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id      WHERE   a.own_type = 1    AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + "    AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)  " + lastStr + "  ORDER BY a.create_time desc ,a.id   asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
+                        countSql = "SELECT  count(b.id)  FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id       WHERE   a.own_type = 1    AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + "    AND (a.type = 5 or a.type=4 or a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)  " + lastStr
+                }</span> else<span class="cov8" title="1"> {
+                        //用户聊天记录查看
+                        sqlStr = "SELECT a.messag_id as messageId,  b.*,   IF   ( a.own_id = a.send_user_id, 1, 2 ) AS fool ,   a.send_user_type,   a.type as  itemType,   d.nickname as  robotName,   d.headimage as  robotImg,   c.customer_service_name as  setName   FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )    left join  socialize_tenant_robot d on  c.ent_id=d.ent_id    WHERE   a.own_type = 2    AND c.ent_id = " + quitl.InterfaceToStr(in.SendId) + "    AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + "     AND ( a.type = 4 OR a.type = 5 or a.type=6 or  a.type=7) " + lastStr + "    ORDER BY a.create_time desc ,a.id   asc limit 0 ,  " + quitl.InterfaceToStr(in.PageSize)
+                        countSql = "SELECT   count(a.id)  FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )    left join  socialize_tenant_robot d on  c.ent_id=d.ent_id      WHERE   a.own_type = 2    AND c.ent_id =" + quitl.InterfaceToStr(in.SendId) + "    AND a.own_id =" + quitl.InterfaceToStr(in.NewUserId) + "    AND ( a.type = 4 OR a.type = 5  or a.type=6 or  a.type=7) " + lastStr
+                }</span>
+                <span class="cov8" title="1">break</span>
+        }
+        <span class="cov8" title="1">log.Println(sqlStr)
+        log.Println(countSql)
+        data := util.Mysql.SelectBySql(sqlStr)
+        count := util.Mysql.CountBySql(countSql)
+        //自己头像处理
+        if in.UserType == 2 &amp;&amp; count &gt; 0 </span><span class="cov8" title="1">{
+                userData := util.Mysql.FindOne("base_user", map[string]interface{}{"id": in.NewUserId}, "headimg", "")
+                if userData != nil </span><span class="cov8" title="1">{
+                        for key := range *data </span><span class="cov8" title="1">{
+                                (*data)[key]["ownImg"] = (*userData)["headimg"]
+                        }</span>
+                }
+
+        }
+        <span class="cov8" title="1">go func() </span><span class="cov8" title="1">{
+                updateMap := map[string]interface{}{}
+                if len(*data) &gt; 0 </span><span class="cov8" title="1">{
+                        //未读信息修改
+                        switch in.MsgType </span>{
+                        case 2:<span class="cov8" title="1"> //点对点聊天
+                                updateMap = map[string]interface{}{
+                                        "own_type": 2,
+                                        "own_id":   in.NewUserId,
+                                        "type":     2,
+                                        "isread":   0,
+                                }
+                                util.Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
+                                break</span>
+                        case 4, 5:<span class="cov8" title="1">
+                                if in.UserType == 1 </span><span class="cov8" title="1">{
+                                        util.Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a     SET a.isread = 1,    a.read_time = now( )     WHERE    a.own_type = 1     AND a.type IN ( 4, 5,6,7)     AND a.isread = 0    AND a.own_id IN ( SELECT b.id FROM socialize_chat_session b WHERE   b.customer_service_id=? and    b.user_id=?  )", in.EntUserId, in.SendId)
+                                }</span> else<span class="cov8" title="1"> {
+                                        util.Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a     SET a.isread = 1,    a.read_time = now( )     WHERE    a.own_type = 2     AND a.type IN ( 4, 5,6,7 )     AND a.isread = 0    AND a.own_id =?", in.NewUserId)
+                                }</span>
+                                <span class="cov8" title="1">break</span>
+                        }
+                }
+        }()
+        <span class="cov8" title="1">return data, count</span>
+}
+func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) <span class="cov8" title="1">{
+        fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool </span><span class="cov8" title="1">{
+                customerserviceName := in.CustomerserviceName
+                if in.CustomerServiceId != 0 </span><span class="cov8" title="1">{
+                        customerList := util.Mysql.SelectBySql("select  customer_service_name from  socialize_tenant_seat  where  ent_id=" + quitl.InterfaceToStr(in.EntId) + " and customer_service_id=" + quitl.InterfaceToStr(in.CustomerServiceId))
+                        if len(*customerList) &gt; 0 </span><span class="cov8" title="1">{
+                                customerserviceName = quitl.InterfaceToStr((*customerList)[0]["customer_service_name"])
+                        }</span>
+                }
+                <span class="cov8" title="1">chatMession := map[string]interface{}{
+                        "handle_status":         0,
+                        "start_time":            time.Now().Local().Format(util.Date_Full_Layout),
+                        "appid":                 in.AppId,
+                        "ent_id":                in.EntId,
+                        "customer_service_id":   in.CustomerServiceId,
+                        "user_id":               in.UserId,
+                        "customer_service_name": customerserviceName,
+                }
+                sessionId = util.Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
+                return sessionId &gt; 0</span>
+        })
+        <span class="cov8" title="1">return fool, sessionId</span>
+}
+func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool <span class="cov8" title="1">{
+        fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool </span><span class="cov8" title="1">{
+                updateMap := map[string]interface{}{
+                        "id": in.SessionId,
+                }
+                fool := util.Mysql.Update("socialize_chat_session", updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
+                return fool
+        }</span>)
+        <span class="cov8" title="1">return fool</span>
+}
+
+func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) bool <span class="cov8" title="1">{
+        return util.Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool </span><span class="cov8" title="1">{
+                entUserName := ""
+                if entUserId &gt; 0 </span><span class="cov8" title="1">{
+                        list := util.Mysql.SelectBySql(`select customer_service_name from socialize_tenant_seat where appid=? and ent_id=? and customer_service_id=?`, appId, entId, entUserId)
+                        if list != nil &amp;&amp; len(*list) &gt; 0 </span><span class="cov8" title="1">{
+                                entUserName, _ = (*list)[0]["customer_service_name"].(string)
+                        }</span>
+                }
+                <span class="cov8" title="1">messageId := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, appId, content, 8, 1, nowFormat, "admin")
+                sessionId := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_chat_session (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
+                ok := false
+                if userType == 0 </span><span class="cov8" title="1">{
+                        ok1 := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat) &gt; 0
+                        ok2 := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) &gt; 0
+                        ok = ok1 &amp;&amp; ok2
+                }</span> else<span class="cov8" title="1"> if userType == 1 </span><span class="cov8" title="1">{
+                        ok = util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat) &gt; 0
+                }</span> else<span class="cov8" title="1"> if userType == 2 </span><span class="cov8" title="1">{
+                        ok = util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) &gt; 0
+                }</span>
+                <span class="cov8" title="1">return messageId &gt; 0 &amp;&amp; sessionId &gt; 0 &amp;&amp; ok</span>
+        })
+}
+func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool <span class="cov8" title="1">{
+        fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool </span><span class="cov8" title="1">{
+                updateMap := map[string]interface{}{
+                        "messag_id": in.MessageId,
+                        "isread":    0,
+                }
+                fool := util.Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
+                return fool
+        }</span>)
+        <span class="cov8" title="1">return fool</span>
+}
+</pre>
+		
+		</div>
+	</body>
+	<script>
+	(function() {
+		var files = document.getElementById('files');
+		var visible;
+		files.addEventListener('change', onChange, false);
+		function select(part) {
+			if (visible)
+				visible.style.display = 'none';
+			visible = document.getElementById(part);
+			if (!visible)
+				return;
+			files.value = part;
+			visible.style.display = 'block';
+			location.hash = part;
+		}
+		function onChange() {
+			select(files.value);
+			window.scrollTo(0, 0);
+		}
+		if (location.hash != "") {
+			select(location.hash.substr(1));
+		}
+		if (!visible) {
+			select("file0");
+		}
+	})();
+	</script>
+</html>

+ 24 - 52
service/message_mail_box.go

@@ -43,7 +43,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		data = util.Mysql.SelectBySql(userSql, in.NewUserId)
 		data = util.Mysql.SelectBySql(userSql, in.NewUserId)
 		userMessageId := util.Inhandle(data)
 		userMessageId := util.Inhandle(data)
 		//客服最后一次信息查询
 		//客服最后一次信息查询
-		customerSql := " SELECT   max( c.id )   as messageId  FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id )   WHERE   c.own_id = ?    AND ( c.type = 4 OR c.type = 5  )    AND c.own_type = 2  and   d.user_id=c.own_id  GROUP BY   d.ent_id  "
+		customerSql := " SELECT   max( c.id )   as messageId  FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id )   WHERE   c.own_id = ?    AND ( c.type = 4 OR c.type = 5  and c.type=6 or  c.type=7 )    AND c.own_type = 2  and   d.user_id=c.own_id  GROUP BY   d.ent_id  "
 		data = util.Mysql.SelectBySql(customerSql, in.NewUserId)
 		data = util.Mysql.SelectBySql(customerSql, in.NewUserId)
 		customerMessageId := util.Inhandle(data)
 		customerMessageId := util.Inhandle(data)
 		//用户的列表
 		//用户的列表
@@ -64,14 +64,14 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		}
 		}
 
 
 		//先获取每个用户最后聊天记录
 		//先获取每个用户最后聊天记录
-		userSql := " SELECT   MAX( c.id ) as messageId   FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id )   WHERE   c.own_type = 1    AND d.customer_service_id = ?   and ( c.type = 4 OR c.type = 5 )   AND d.customer_service_id !=0    " + startTimeSql + endTimeSql + "   GROUP BY   (   CASE          WHEN  c.send_user_type =2 THEN  CONCAT( c.send_user_id )   WHEN c.send_user_type =1 THEN  CONCAT( c.receive_user_id )     END     ) "
+		userSql := " SELECT   MAX( c.id ) as messageId   FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id )   WHERE   c.own_type = 1    AND d.customer_service_id = ?   and ( c.type = 4 OR c.type = 5 or  c.type=6 or  c.type=7 )   AND d.customer_service_id !=0    " + startTimeSql + endTimeSql + "   GROUP BY   (   CASE          WHEN  c.send_user_type =2 THEN  CONCAT( c.send_user_id )   WHEN c.send_user_type =1 THEN  CONCAT( c.receive_user_id )     END     ) "
 		v = append(v, in.EntUserId)
 		v = append(v, in.EntUserId)
 		log.Println(userSql, v)
 		log.Println(userSql, v)
 		data = util.Mysql.SelectBySql(userSql, v...)
 		data = util.Mysql.SelectBySql(userSql, v...)
 		if data != nil {
 		if data != nil {
 			customerMessageId := util.Inhandle(data)
 			customerMessageId := util.Inhandle(data)
 			//客服的用户列表
 			//客服的用户列表
-			sqlStr = "SELECT  IF  ( b.nickname = '', CONCAT(SUBSTR( b.phone, 1, 3 ),'****',SUBSTR( b.phone, 8, 11)), b.nickname ) AS name,  b.id,  e.title,  b.headimg,  e.type,  e.link,  e.content,  a.create_time,  (  SELECT   count( h.id )   FROM   socialize_message_mailbox h   WHERE   ( h.type = 4 OR h.type = 5 )    AND h.own_type = 1   AND  IF   ( h.send_user_type = 1, h.send_user_id = f.id, h.receive_user_id = f.id )    AND h.isread = 0   ) AS number   FROM  socialize_message_mailbox a  LEFT JOIN base_user b ON  IF  ( a.send_user_type = 1, b.id = a.receive_user_id, b.id = a.send_user_id )  LEFT JOIN socialize_message e ON e.id = a.messag_id  LEFT JOIN socialize_chat_session f ON  IF  ( a.send_user_type = 1, f.id = a.send_user_id, f.id = a.receive_user_id )   WHERE  a.id IN  (" + customerMessageId + ")" + phoneSql + "   ORDER BY  a.create_time DESC"
+			sqlStr = "SELECT  IF  ( b.nickname = '', CONCAT(SUBSTR( b.phone, 1, 3 ),'****',SUBSTR( b.phone, 8, 11)), b.nickname ) AS name,  b.id,  e.title,  b.headimg,  e.type,  e.link,  e.content,  a.create_time,  (  SELECT   count( h.id )   FROM   socialize_message_mailbox h   WHERE   (  h.type = 4 OR h.type = 5 or  h.type=6 or  h.type=7 )    AND h.own_type = 1   AND  IF   ( h.send_user_type = 1, h.send_user_id = f.id, h.receive_user_id = f.id )    AND h.isread = 0   ) AS number   FROM  socialize_message_mailbox a  LEFT JOIN base_user b ON  IF  ( a.send_user_type = 1, b.id = a.receive_user_id, b.id = a.send_user_id )  LEFT JOIN socialize_message e ON e.id = a.messag_id  LEFT JOIN socialize_chat_session f ON  IF  ( a.send_user_type = 1, f.id = a.send_user_id, f.id = a.receive_user_id )   WHERE  a.id IN  (" + customerMessageId + ")" + phoneSql + "   ORDER BY  a.create_time DESC"
 			fmt.Println(in.EntUserId)
 			fmt.Println(in.EntUserId)
 			v = make([]interface{}, 0)
 			v = make([]interface{}, 0)
 		}
 		}
@@ -83,7 +83,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 	}
 	}
 	return
 	return
 }
 }
-func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode int64, errorMsg string, content string, messageId int64) {
+func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId int64) {
 	//先插入信息表
 	//先插入信息表
 	//判断会话标识是否属于本人
 	//判断会话标识是否属于本人
 	if in.ItemType != 2 {
 	if in.ItemType != 2 {
@@ -115,14 +115,14 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
 		//查找会话信息
 		//查找会话信息
 		chatJson := util.Mysql.FindOne("socialize_chat_session", map[string]interface{}{"id": sessionId}, "user_id", "")
 		chatJson := util.Mysql.FindOne("socialize_chat_session", map[string]interface{}{"id": sessionId}, "user_id", "")
 		if chatJson == nil {
 		if chatJson == nil {
-			return 1, "会话标识不存在", "", 0
+			return false, "会话标识不存在", "", 0
 		} else {
 		} else {
 			if userId != quitl.Int64All((*chatJson)["user_id"]) {
 			if userId != quitl.Int64All((*chatJson)["user_id"]) {
-				return 1, "会话标识不属于此用户", "", 0
+				return false, "会话标识不属于此用户", "", 0
 			}
 			}
 		}
 		}
 	}
 	}
-	fool := util.Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
+	fool = util.Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
 		//先插入信息表
 		//先插入信息表
 		message := map[string]interface{}{
 		message := map[string]interface{}{
 			"appid":         in.Appid,
 			"appid":         in.Appid,
@@ -135,9 +135,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
 			"create_person": in.SendId,
 			"create_person": in.SendId,
 		}
 		}
 		ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
 		ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
-		if ok <= 0 {
-			return false
-		}
+		receiveOk := int64(0)
 		messageId = ok
 		messageId = ok
 		//在插入邮箱表socialize_message_mailbox
 		//在插入邮箱表socialize_message_mailbox
 		messageMailBox := map[string]interface{}{
 		messageMailBox := map[string]interface{}{
@@ -180,14 +178,9 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
 				messageMailBox["send_user_id"] = in.ReceiveId
 				messageMailBox["send_user_id"] = in.ReceiveId
 				messageMailBox["receive_user_id"] = in.SendId
 				messageMailBox["receive_user_id"] = in.SendId
 			}
 			}
-			receiveOk := util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
-			if receiveOk == 0 {
-				return false
-			} else {
-				return true
-			}
+			receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+			return ok > 1 && receiveOk > 1
 		}
 		}
-
 		if in.ItemType == 4 || in.ItemType == 5 {
 		if in.ItemType == 4 || in.ItemType == 5 {
 			//客服或者机器人聊天
 			//客服或者机器人聊天
 			if in.OwnType == 1 {
 			if in.OwnType == 1 {
@@ -219,10 +212,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
 			messageMailBox["send_user_id"] = in.NewUserId
 			messageMailBox["send_user_id"] = in.NewUserId
 			messageMailBox["receive_user_id"] = in.ReceiveId
 			messageMailBox["receive_user_id"] = in.ReceiveId
 		}
 		}
-		sendOk := util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
-		if sendOk == 0 {
-			return false
-		}
+		receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
 		messageMailBox = map[string]interface{}{
 		messageMailBox = map[string]interface{}{
 			"appid":         in.Appid,
 			"appid":         in.Appid,
 			"messag_id":     ok,
 			"messag_id":     ok,
@@ -265,17 +255,11 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
 			messageMailBox["send_user_id"] = in.NewUserId
 			messageMailBox["send_user_id"] = in.NewUserId
 			messageMailBox["receive_user_id"] = in.ReceiveId
 			messageMailBox["receive_user_id"] = in.ReceiveId
 		}
 		}
-		receiveOk := util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
-		if receiveOk == 0 {
-			return false
-		}
-		return true
+		receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+		return ok > 1 && receiveOk > 1
 	})
 	})
-	if fool {
-		return 0, "", in.Content, messageId
-	} else {
-		return 1, "保存失败", "", 0
-	}
+	return fool, "", in.Content, messageId
+
 }
 }
 func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) {
 func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) {
 	sqlStr := ""
 	sqlStr := ""
@@ -293,7 +277,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
 		if in.UserType == 1 {
 		if in.UserType == 1 {
 			//客服聊天记录查看
 			//客服聊天记录查看
 			sqlStr = "SELECT   a.messag_id as messageId,b.*,   IF   ( a.own_id = a.send_user_id, 1, 2 ) AS fool,   a.send_user_type,   a.type AS itemType,   d.nickname AS robotName,   d.headimage AS robotImg,   c.customer_service_name AS setName ,   c.user_id   FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id      WHERE   a.own_type = 1    AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + "    AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)  " + lastStr + "  ORDER BY a.create_time desc ,a.id   asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
 			sqlStr = "SELECT   a.messag_id as messageId,b.*,   IF   ( a.own_id = a.send_user_id, 1, 2 ) AS fool,   a.send_user_type,   a.type AS itemType,   d.nickname AS robotName,   d.headimage AS robotImg,   c.customer_service_name AS setName ,   c.user_id   FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id      WHERE   a.own_type = 1    AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + "    AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)  " + lastStr + "  ORDER BY a.create_time desc ,a.id   asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
-			countSql = "SELECT  count(b.id)  FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id       WHERE   a.own_type = 1    AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + "    AND (a.type = 5 or a.type=4 or a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)  " + lastStr
+			countSql = "SELECT  count(b.id)  FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id       WHERE   a.own_type = 1    AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + "    AND (a.type = 5 or a.type=4 or a.type = 5  or  a.type=6 or  a.type=7)  " + lastStr
 		} else {
 		} else {
 			//用户聊天记录查看
 			//用户聊天记录查看
 			sqlStr = "SELECT a.messag_id as messageId,  b.*,   IF   ( a.own_id = a.send_user_id, 1, 2 ) AS fool ,   a.send_user_type,   a.type as  itemType,   d.nickname as  robotName,   d.headimage as  robotImg,   c.customer_service_name as  setName   FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )    left join  socialize_tenant_robot d on  c.ent_id=d.ent_id    WHERE   a.own_type = 2    AND c.ent_id = " + quitl.InterfaceToStr(in.SendId) + "    AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + "     AND ( a.type = 4 OR a.type = 5 or a.type=6 or  a.type=7) " + lastStr + "    ORDER BY a.create_time desc ,a.id   asc limit 0 ,  " + quitl.InterfaceToStr(in.PageSize)
 			sqlStr = "SELECT a.messag_id as messageId,  b.*,   IF   ( a.own_id = a.send_user_id, 1, 2 ) AS fool ,   a.send_user_type,   a.type as  itemType,   d.nickname as  robotName,   d.headimage as  robotImg,   c.customer_service_name as  setName   FROM   socialize_message_mailbox a   LEFT JOIN socialize_message b ON a.messag_id = b.id   LEFT JOIN socialize_chat_session c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id )    left join  socialize_tenant_robot d on  c.ent_id=d.ent_id    WHERE   a.own_type = 2    AND c.ent_id = " + quitl.InterfaceToStr(in.SendId) + "    AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + "     AND ( a.type = 4 OR a.type = 5 or a.type=6 or  a.type=7) " + lastStr + "    ORDER BY a.create_time desc ,a.id   asc limit 0 ,  " + quitl.InterfaceToStr(in.PageSize)
@@ -341,8 +325,8 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
 	}()
 	}()
 	return data, count
 	return data, count
 }
 }
-func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (errorCode, sessionId int64) {
-	fool := util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
+func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
+	fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
 		customerserviceName := in.CustomerserviceName
 		customerserviceName := in.CustomerserviceName
 		if in.CustomerServiceId != 0 {
 		if in.CustomerServiceId != 0 {
 			customerList := util.Mysql.SelectBySql("select  customer_service_name from  socialize_tenant_seat  where  ent_id=" + quitl.InterfaceToStr(in.EntId) + " and customer_service_id=" + quitl.InterfaceToStr(in.CustomerServiceId))
 			customerList := util.Mysql.SelectBySql("select  customer_service_name from  socialize_tenant_seat  where  ent_id=" + quitl.InterfaceToStr(in.EntId) + " and customer_service_id=" + quitl.InterfaceToStr(in.CustomerServiceId))
@@ -362,13 +346,9 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (er
 		sessionId = util.Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
 		sessionId = util.Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
 		return sessionId > 0
 		return sessionId > 0
 	})
 	})
-	if fool {
-		return 0, sessionId
-	} else {
-		return 1, sessionId
-	}
+	return fool, sessionId
 }
 }
-func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) (errorCode int64) {
+func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool {
 	fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
 	fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
 		updateMap := map[string]interface{}{
 		updateMap := map[string]interface{}{
 			"id": in.SessionId,
 			"id": in.SessionId,
@@ -376,14 +356,10 @@ func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) (er
 		fool := util.Mysql.Update("socialize_chat_session", updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
 		fool := util.Mysql.Update("socialize_chat_session", updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
 		return fool
 		return fool
 	})
 	})
-	if fool {
-		return 0
-	} else {
-		return 1
-	}
+	return fool
 }
 }
 
 
-func (m *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) bool {
+func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) bool {
 	return util.Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
 	return util.Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
 		entUserName := ""
 		entUserName := ""
 		if entUserId > 0 {
 		if entUserId > 0 {
@@ -407,7 +383,7 @@ func (m *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
 		return messageId > 0 && sessionId > 0 && ok
 		return messageId > 0 && sessionId > 0 && ok
 	})
 	})
 }
 }
-func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) (errorCode int64) {
+func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
 	fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
 	fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
 		updateMap := map[string]interface{}{
 		updateMap := map[string]interface{}{
 			"messag_id": in.MessageId,
 			"messag_id": in.MessageId,
@@ -416,9 +392,5 @@ func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) (errorCo
 		fool := util.Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
 		fool := util.Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
 		return fool
 		return fool
 	})
 	})
-	if fool {
-		return 0
-	} else {
-		return 1
-	}
+	return fool
 }
 }

+ 38 - 9
service/message_mail_box_test.go

@@ -29,7 +29,7 @@ func TestMessaggeService_CloseChatSession(t *testing.T) {
 	tests := []struct {
 	tests := []struct {
 		name          string
 		name          string
 		args          args
 		args          args
-		wantErrorCode int64
+		wantErrorCode bool
 	}{
 	}{
 		// TODO: Add test cases.
 		// TODO: Add test cases.
 		{
 		{
@@ -108,7 +108,7 @@ func TestMessaggeService_CreateChatSession(t *testing.T) {
 	tests := []struct {
 	tests := []struct {
 		name          string
 		name          string
 		args          args
 		args          args
-		wantErrorCode int64
+		wantErrorCode bool
 		wantSessionId int64
 		wantSessionId int64
 	}{
 	}{
 		// TODO: Add test cases.
 		// TODO: Add test cases.
@@ -118,13 +118,13 @@ func TestMessaggeService_CreateChatSession(t *testing.T) {
 				in: &messagecenter.ChatSessionReq{
 				in: &messagecenter.ChatSessionReq{
 					EntId:               14184,
 					EntId:               14184,
 					UserId:              4962,
 					UserId:              4962,
-					CustomerServiceId:   121,
+					CustomerServiceId:   3,
 					AppId:               "10000",
 					AppId:               "10000",
 					CustomerserviceName: "客服1",
 					CustomerserviceName: "客服1",
 				},
 				},
 			},
 			},
 			wantSessionId: 0,
 			wantSessionId: 0,
-			wantErrorCode: 0,
+			wantErrorCode: true,
 		},
 		},
 	}
 	}
 	for _, tt := range tests {
 	for _, tt := range tests {
@@ -169,7 +169,7 @@ func TestMessaggeService_FindMessage(t *testing.T) {
 			args: args{in: &messagecenter.MessageReq{
 			args: args{in: &messagecenter.MessageReq{
 				MsgType:   4,
 				MsgType:   4,
 				UserType:  2,
 				UserType:  2,
-				SendId:    10,
+				SendId:    1,
 				PageSize:  10,
 				PageSize:  10,
 				NewUserId: 10,
 				NewUserId: 10,
 				EntId:     1,
 				EntId:     1,
@@ -205,7 +205,8 @@ func TestMessaggeService_FindMessage(t *testing.T) {
 				SendId:    57683,
 				SendId:    57683,
 				PageSize:  10,
 				PageSize:  10,
 				NewUserId: 10,
 				NewUserId: 10,
-				LastId:    57683000,
+				EntId:     1,
+				LastId:    200000,
 			}},
 			}},
 			want1: 0,
 			want1: 0,
 		},
 		},
@@ -264,6 +265,18 @@ func TestMessaggeService_SaveAutoReplyMsg(t *testing.T) {
 				nowFormat: "2022-08-02 12:12:12",
 				nowFormat: "2022-08-02 12:12:12",
 			},
 			},
 		},
 		},
+		{
+			name: "会话保存以及消息保存",
+			args: args{
+				userType:  0,
+				entId:     14184,
+				entUserId: 3,
+				userId:    831,
+				content:   "你与用户创建会话",
+				appId:     "10000",
+				nowFormat: "2022-08-02 12:12:12",
+			},
+		},
 	}
 	}
 	for _, tt := range tests {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
@@ -282,7 +295,7 @@ func TestMessaggeService_SaveMessage(t *testing.T) {
 	tests := []struct {
 	tests := []struct {
 		name          string
 		name          string
 		args          args
 		args          args
-		wantErrorCode int64
+		wantErrorCode bool
 		wantErrorMsg  string
 		wantErrorMsg  string
 		wantContent   string
 		wantContent   string
 		wantMessageId int64
 		wantMessageId int64
@@ -443,6 +456,22 @@ func TestMessaggeService_SaveMessage(t *testing.T) {
 				},
 				},
 			},
 			},
 		},
 		},
+		{name: "会话标识不属于此用户",
+			args: args{
+				in: &messagecenter.MessageEntity{
+					Title:     "11",
+					Content:   "问在吗?",
+					Item:      8,
+					ItemType:  4,
+					Link:      "1111",
+					Appid:     "10000",
+					ReceiveId: 514,
+					OwnType:   int64(1),
+					Type:      1,
+					NewUserId: 20,
+				},
+			},
+		},
 	}
 	}
 	for _, tt := range tests {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
@@ -523,7 +552,7 @@ func TestMessaggeService_UpdateReadById(t *testing.T) {
 	tests := []struct {
 	tests := []struct {
 		name          string
 		name          string
 		args          args
 		args          args
-		wantErrorCode int64
+		wantErrorCode bool
 	}{
 	}{
 		// TODO: Add test cases.
 		// TODO: Add test cases.
 		{
 		{
@@ -533,7 +562,7 @@ func TestMessaggeService_UpdateReadById(t *testing.T) {
 					MessageId: 11612,
 					MessageId: 11612,
 				},
 				},
 			},
 			},
-			wantErrorCode: 0,
+			wantErrorCode: true,
 		},
 		},
 	}
 	}
 	for _, tt := range tests {
 	for _, tt := range tests {