WH01243 3 år sedan
förälder
incheckning
375c2ee20c
5 ändrade filer med 570 tillägg och 247 borttagningar
  1. 6 4
      entity/util.go
  2. 103 97
      service/coverage
  3. 240 83
      service/coverage.html
  4. 201 59
      service/message_mail_box.go
  5. 20 4
      service/message_mail_box_test.go

+ 6 - 4
entity/util.go

@@ -3,10 +3,12 @@ package entity
 import quitl "app.yhyue.com/moapp/jybase/common"
 
 const (
-	Date_Full_Layout = "2006-01-02 15:04:05"
-	KNOWLEDGE        = "socialize_knowledge"
-	QUESTION         = "socialize_question"
-	ANSWER           = "socialize_answer"
+	Date_Full_Layout          = "2006-01-02 15:04:05"
+	SOCIALIZE_CHAT_SESSION    = "socialize_chat_session"
+	SOCIALIZE_MESSAGE         = "socialize_message"
+	SOCIALIZE_MESSAGE_MAILBOX = "socialize_message_mailbox"
+	SOCIALIZE_TENANT_ROBOT    = "socialize_tenant_robot"
+	BASE_USER                 = "base_user"
 )
 
 func SafeConvert2String(obj interface{}) string {

+ 103 - 97
service/coverage

@@ -1,99 +1,105 @@
 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
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:37.2,52.24 7 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:55.2,55.8 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:19.19,28.3 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:28.8,36.3 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:52.24,54.3 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:59.106,61.22 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:163.2,163.18 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:167.2,167.8 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:61.22,119.3 7 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:119.8,121.21 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:124.3,125.25 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:128.3,129.23 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:133.3,143.18 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:121.21,123.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:125.25,127.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:129.23,131.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:143.18,161.4 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:163.18,166.3 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:171.141,175.22 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:214.2,214.71 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:361.2,361.56 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:175.22,178.22 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:205.3,206.22 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:179.13,180.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:190.4,190.9 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:191.10,192.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:202.4,202.9 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:180.23,183.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:183.10,186.25 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:186.25,188.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:192.23,195.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:195.10,195.30 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:195.30,198.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:198.10,201.5 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:206.22,208.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:208.9,209.56 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:209.56,211.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:214.71,241.23 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:282.3,282.43 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:315.3,327.43 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:358.3,359.33 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:241.23,253.23 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:279.4,280.34 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:253.23,261.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:261.10,261.30 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:261.30,270.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:270.10,278.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:282.43,284.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:284.23,292.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:292.10,300.25 7 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:300.25,305.6 4 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:307.9,314.4 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:327.43,329.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:329.23,338.5 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:338.10,346.25 7 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:346.25,348.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:350.9,357.4 6 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:365.94,368.19 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:375.2,375.20 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:424.2,427.22 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:436.2,436.12 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:471.2,471.13 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:368.19,369.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:369.23,371.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:371.9,373.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:376.9,389.8 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:390.18,391.23 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:422.3,422.8 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:391.23,405.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:405.9,421.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:427.22,429.22 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:429.22,430.27 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:430.27,432.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:436.12,438.21 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:438.21,440.22 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:441.11,449.10 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:450.14,452.25 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:466.5,467.10 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:452.25,459.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:459.11,465.6 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:475.107,476.65 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:500.2,500.24 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:476.65,478.32 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:488.3,498.23 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:478.32,484.30 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:484.30,486.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:504.83,505.66 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:512.2,512.13 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:505.66,511.3 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:516.134,518.77 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:518.77,520.20 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:526.3,529.20 4 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:538.3,538.46 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:520.20,522.37 2 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:522.37,524.5 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:529.20,533.4 3 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:533.9,533.27 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:533.27,535.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:535.9,535.27 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:535.27,537.4 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:543.78,544.72 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:552.2,552.13 1 1
+bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service/message_mail_box.go:544.72,551.3 3 1

+ 240 - 83
service/coverage.html

@@ -72,91 +72,177 @@
 		<pre class="file" id="file0" style="display: none">package service
 
 import (
+        quitl "app.yhyue.com/moapp/jybase/common"
+        util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
+        "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
         "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)
+                sqlStr = fmt.Sprintf("select  count(b.id) from   %s a  "+
+                        "LEFT  JOIN  %s  b ON a.id=b.own_id "+
+                        "where  b.type=5 "+
+                        "AND   a.customer_service_id=%d   "+
+                        "AND  b.isread=0  "+
+                        "AND own_type = 1 "+
+                        "order by create_time", util.SOCIALIZE_CHAT_SESSION, util.SOCIALIZE_MESSAGE_MAILBOX, 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)
+                sqlStr = fmt.Sprintf("select  count(b.id) from    %s  b "+
+                        "where   b.send_user_id != %d    "+
+                        "AND   b.own_id=%d  "+
+                        "AND  b.isread=0 "+
+                        "AND own_type = 2 "+
+                        "order by create_time", util.SOCIALIZE_MESSAGE_MAILBOX, newUserId, newUserId)
+
         }</span>
-        <span class="cov8" title="1">fmt.Println(sqlStr, v)
+        <span class="cov8" title="1">log.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)
+        sqlStr=fmt.Sprintf("SELECT  c.* FROM %s  b   "+
+                "LEFT join %s c on  b.messag_id=c.id "+
+                "WHERE  b.send_user_id != %d   "+
+                "AND b.own_id = %d  "+
+                "AND   b.isread=0  "+
+                "AND own_type = 2  "+
+                "ORDER BY  create_time DESC   "+
+                "LIMIT 0,1",util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE,
+                newUserId, newUserId)
+        lastData := util.Mysql.SelectBySql(sqlStr)
         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)
+                userSql := fmt.Sprintf("SELECT  MAX( c.id )   as messageId  FROM  socialize_message_mailbox c "+
+                        "WHERE  c.own_id = %d   "+
+                        "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  ) ", in.NewUserId,
+                )
+                data = util.Mysql.SelectBySql(userSql)
                 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.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)
+                customerSql := fmt.Sprintf("SELECT   max( c.id )   as messageId  FROM   %s c "+
+                        "LEFT JOIN %s d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) "+
+                        "WHERE   c.own_id = %d  "+
+                        "AND ( c.type = 4 OR c.type = 5  or c.type=6 or  c.type=7 ) "+
+                        "AND c.own_type = 2 "+
+                        "AND   d.user_id=c.own_id "+
+                        "GROUP BY   d.ent_id  ", util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.NewUserId)
+                data = util.Mysql.SelectBySql(customerSql)
                 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)
+                sqlStr = fmt.Sprintf("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  %s h  "+
+                        "WHERE  h.type = 2  "+
+                        "AND h.own_id = %d  "+
+                        "AND h.own_type = 2  "+
+                        "AND   h.send_user_id=b.id   "+
+                        "AND h.isread = 0  ) AS number  FROM  %s a "+
+                        "LEFT JOIN  %s b ON  b.id = a.receive_user_id or  b.id = a.send_user_id  "+
+                        "LEFT JOIN  %s e ON e.id = a.messag_id  "+
+                        "WHERE a.id IN ( %s )  AND b.id != %d "+
+                        "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    %s h   WHERE   ( h.type = 4 OR h.type = 5  )    AND h.own_id = %d    AND h.own_type = 2   AND  h.send_user_type = 1 AND  h.receive_user_id = %d    AND h.isread = 0   ) AS number "+
+                        "FROM  %s a  "+
+                        "LEFT JOIN %s b ON IF  ( a.send_user_type = 1, b.id = a.send_user_id, b.id = a.receive_user_id )  "+
+                        "LEFT JOIN %s e ON e.id = a.messag_id  "+
+                        "LEFT join %s  f on f.ent_id=b.ent_id   "+
+                        "WHERE  a.id IN (  %s )  "+
+                        "ORDER BY create_time DESC",
+                        util.SOCIALIZE_MESSAGE_MAILBOX,
+                        in.NewUserId,
+                        util.SOCIALIZE_MESSAGE_MAILBOX,
+                        util.BASE_USER,
+                        util.SOCIALIZE_MESSAGE,
+                        userMessageId,
+                        in.NewUserId,
+                        util.SOCIALIZE_MESSAGE_MAILBOX,
+                        in.NewUserId,
+                        in.NewUserId,
+                        util.SOCIALIZE_MESSAGE_MAILBOX,
+                        util.SOCIALIZE_CHAT_SESSION,
+                        util.SOCIALIZE_MESSAGE,
+                        util.SOCIALIZE_TENANT_ROBOT,
+                        customerMessageId)
         }</span> else<span class="cov8" title="1"> {
                 phoneSql := ""
                 if in.Phone != "" </span><span class="cov8" title="1">{
-                        phoneSql = "and  b.phone='" + in.Phone + "'"
+                        phoneSql = "AND  b.phone like '% " + 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 + "' "
+                        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 + "' "
+                        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 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)
-                log.Println(userSql, v)
-                data = util.Mysql.SelectBySql(userSql, v...)
+                <span class="cov8" title="1">userSql := fmt.Sprintf("SELECT   MAX( c.id ) as messageId   FROM  %s c   "+
+                        "LEFT JOIN %s d ON   c.own_type=1 AND  c.own_id=d.id   "+
+                        "WHERE   c.own_type = 1    "+
+                        "AND d.customer_service_id = %d   "+
+                        "AND ( c.type = 4 OR c.type = 5 or  c.type=6 or  c.type=7 )   "+
+                        "AND d.customer_service_id !=0   %s %s  "+
+                        "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  ) ",
+                        util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
+                        in.EntUserId, startTimeSql, endTimeSql)
+                data = util.Mysql.SelectBySql(userSql)
                 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 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)
-                        v = make([]interface{}, 0)
+                        sqlStr = fmt.Sprintf("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   %s h   "+
+                                "LEFT JOIN %s i ON h.own_type = 1 AND h.own_id = i.id     "+
+                                "WHERE  h.own_type = 1  "+
+                                "AND i.ent_id=f.ent_id "+
+                                "AND  i.user_id=f.user_id    "+
+                                "AND h.isread = 0    "+
+                                "AND  i.customer_service_id= %d "+
+                                "FROM  %s a  "+
+                                "LEFT JOIN %s b ON if (a.send_user_type=1 ,a.receive_user_id=b.id,a.send_user_id=b.id)  "+
+                                "LEFT JOIN %s e ON e.id = a.messag_id  "+
+                                "LEFT JOIN %s f ON a.own_type=1 AND  a.own_id=f.id   "+
+                                "WHERE  a.id IN  ( %s) %s ORDER BY  a.create_time DESC",
+                                util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
+                                in.EntUserId, util.SOCIALIZE_MESSAGE_MAILBOX, util.BASE_USER, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, customerMessageId, phoneSql)
                 }</span>
-
         }
         <span class="cov8" title="1">if sqlStr != "" </span><span class="cov8" title="1">{
-                fmt.Println(sqlStr, v)
-                data = util.Mysql.SelectBySql(sqlStr, v...)
+                log.Println(sqlStr)
+                data = util.Mysql.SelectBySql(sqlStr)
         }</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">{
+
+//消息保存
+func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) <span class="cov8" title="1">{
         //先插入信息表
         //判断会话标识是否属于本人
+        nowForm := time.Now().Local()
         if in.ItemType != 2 </span><span class="cov8" title="1">{
                 userId := int64(0)
                 sessionId := int64(0)
@@ -177,19 +263,22 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                         if in.OwnType == 1 </span><span class="cov8" title="1">{
                                 sessionId = in.ReceiveId
                                 userId = in.NewUserId
-                        }</span> else<span class="cov8" title="1"> {
+                        }</span> else<span class="cov8" title="1"> if in.OwnType == 2 </span><span class="cov8" title="1">{
                                 sessionId = in.SendId
                                 userId = in.ReceiveId
+                        }</span> else<span class="cov8" title="1"> {
+                                sessionId = in.ReceiveId
+                                userId = in.NewUserId
                         }</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", "")
+                <span class="cov8" title="1">chatJson := util.Mysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id", "")
                 if chatJson == nil </span><span class="cov8" title="1">{
-                        return false, "会话标识不存在", "", 0
+                        return false, "会话标识不存在", "", 0, nowForm.Unix()
                 }</span> else<span class="cov8" title="1"> {
                         if userId != quitl.Int64All((*chatJson)["user_id"]) </span><span class="cov8" title="1">{
-                                return false, "会话标识不属于此用户", "", 0
+                                return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
                         }</span>
                 }
         }
@@ -199,13 +288,13 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                         "appid":         in.Appid,
                         "title":         in.Title,
                         "content":       in.Content,
-                        "item":          in.ItemType,
+                        "item":          in.Item,
                         "type":          in.Type,
                         "link":          in.Link,
-                        "create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+                        "create_time":   nowForm.Format(util.Date_Full_Layout),
                         "create_person": in.SendId,
                 }
-                ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
+                ok := util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
                 receiveOk := int64(0)
                 messageId = ok
                 //在插入邮箱表socialize_message_mailbox
@@ -213,7 +302,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                         "appid":         in.Appid,
                         "messag_id":     ok,
                         "type":          in.ItemType,
-                        "create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+                        "create_time":   nowForm.Format(util.Date_Full_Layout),
                         "isread":        0,
                         "send_isdel":    0,
                         "receive_isdel": 0,
@@ -225,8 +314,8 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                                 "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),
+                                "create_time":   nowForm.Format(util.Date_Full_Layout),
+                                "read_time":     nowForm.Format(util.Date_Full_Layout),
                                 "isread":        1,
                                 "send_isdel":    0,
                                 "receive_isdel": 0,
@@ -240,7 +329,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                                 messageMailBox["own_id"] = in.NewUserId
                                 messageMailBox["send_user_id"] = in.ReceiveId
                                 messageMailBox["receive_user_id"] = in.NewUserId
-                        }</span> else<span class="cov8" title="1"> {
+                        }</span> else<span class="cov8" title="1"> if in.OwnType == 2 </span><span class="cov8" title="1">{
                                 //客服接受系统信息
                                 messageMailBox["own_type"] = 1
                                 messageMailBox["send_user_type"] = 2
@@ -248,8 +337,17 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                                 messageMailBox["own_id"] = in.SendId
                                 messageMailBox["send_user_id"] = in.ReceiveId
                                 messageMailBox["receive_user_id"] = in.SendId
+
+                        }</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.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)
+                        <span class="cov8" title="1">receiveOk = util.Mysql.InsertByTx(tx, util.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">{
@@ -273,6 +371,8 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                                 if in.ItemType == 4 </span><span class="cov8" title="1">{
                                         messageMailBox["receive_user_id"] = in.NewUserId
                                         messageMailBox["own_id"] = in.NewUserId
+                                        messageMailBox["isread"] = 1
+                                        messageMailBox["read_time"] = nowForm.Format(util.Date_Full_Layout)
                                 }</span>
                         }
                 } else<span class="cov8" title="1"> {
@@ -283,13 +383,13 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                         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)
+                <span class="cov8" title="1">receiveOk = util.Mysql.InsertByTx(tx, util.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),
+                        "create_time":   nowForm.Format(util.Date_Full_Layout),
+                        "read_time":     nowForm.Format(util.Date_Full_Layout),
                         "isread":        1,
                         "send_isdel":    0,
                         "receive_isdel": 0,
@@ -326,43 +426,77 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
                         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)
+                <span class="cov8" title="1">receiveOk = util.Mysql.InsertByTx(tx, util.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>
-
+        <span class="cov8" title="1">return fool, "", in.Content, messageId, nowForm.Unix()</span>
 }
-func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) <span class="cov8" title="1">{
+
+//历史信息查询
+func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} <span class="cov8" title="1">{
         sqlStr := ""
-        countSql := ""
-        lastStr := "  "
+        lastStr := ""
         if in.LastId &gt; 0 </span><span class="cov8" title="1">{
-                lastStr = " and  a.messag_id &lt; " + quitl.InterfaceToStr(in.LastId)
-        }</span>
+                if in.Sort == "asc" </span><span class="cov8" title="1">{
+                        lastStr = fmt.Sprintf("AND  a.messag_id &gt; %d ", in.LastId)
+                }</span> else<span class="cov8" title="1"> {
+                        lastStr = fmt.Sprintf("AND  a.messag_id &lt; %d ", 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
+                sqlStr = fmt.Sprintf("SELECT  a.messag_id as messageId,b.* ,if(a.own_id = a.send_user_id,1,2) as fool  "+
+                        "FROM  %s a  "+
+                        "LEFT JOIN %s b on  a.messag_id=b.id  "+
+                        "LEFT  JOIN  %s c on  c.id=a.send_user_id   "+
+                        "LEFT JOIN  %s d on  d.id=a.receive_user_id  "+
+                        "where  a.own_id=  %d "+
+                        "AND ((a.send_user_id=   %d AND   a.receive_user_id=   %d) or (a.send_user_id=  %d AND  a.receive_user_id=  %d)) "+
+                        "AND  a.type=2  %s "+
+                        "ORDER BY a.create_time desc ,a.id   asc "+
+                        "limit 0 ,  %d ",
+                        util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.BASE_USER, util.BASE_USER,
+                        in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId, lastStr, in.PageSize)
                 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=6 or  a.type=7)  " + lastStr
+                        sqlStr = fmt.Sprintf("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,   '' AS robotName,   '' AS robotImg,   c.customer_service_name AS setName ,   c.user_id   "+
+                                "FROM   %s a   "+
+                                "LEFT JOIN %s b ON a.messag_id = b.id   "+
+                                "LEFT JOIN %s c ON   a.own_type = 1  AND  a.own_id=c.id    "+
+                                "WHERE   a.own_type = 1   "+
+                                "AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)   "+
+                                "AND c.ent_id =   %d "+
+                                "AND c.user_id =   %d  %s "+
+                                "ORDER BY a.create_time desc ,a.id   asc "+
+                                "limit 0 ,  %d ",
+                                util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION,
+                                in.EntId, in.SendId, lastStr, in.PageSize)
                 }</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
+                        sqlStr = fmt.Sprintf("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   %s a   "+
+                                "LEFT JOIN %s b ON a.messag_id = b.id   "+
+                                "LEFT JOIN %s c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) AND  c.ent_id = %d AND c.user_id = %d "+
+                                "LEFT JOIN  %s d on  c.ent_id=d.ent_id    "+
+                                "WHERE   a.own_type = 2    "+
+                                "AND a.own_id =  %d "+
+                                "AND  c.ent_id = %d "+
+                                "AND c.user_id =  %d "+
+                                "AND ( a.type = 4 OR a.type = 5 or a.type=6 or  a.type=7)  %s "+
+                                "ORDER BY a.create_time desc ,a.id   asc "+
+                                "limit 0 ,   %d ",
+                                util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, in.SendId, in.NewUserId, util.SOCIALIZE_TENANT_ROBOT,
+                                in.NewUserId, in.SendId, in.NewUserId, lastStr, in.PageSize)
                 }</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 in.UserType == 2 </span><span class="cov8" title="1">{
+                userData := util.Mysql.FindOne(util.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"]
@@ -382,25 +516,42 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
                                         "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)})
+                                util.Mysql.Update(util.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">
+                                sqlStr := ""
                                 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)
+                                        sqlStr = fmt.Sprintf("UPDATE %s 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 %s b WHERE   b.customer_service_id=%d AND    b.user_id=%d  )",
+                                                util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, 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)
+                                        sqlStr = fmt.Sprintf("UPDATE %s 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 =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
                                 }</span>
-                                <span class="cov8" title="1">break</span>
+                                <span class="cov8" title="1">util.Mysql.UpdateOrDeleteBySql(sqlStr)
+                                break</span>
                         }
                 }
         }()
-        <span class="cov8" title="1">return data, count</span>
+        <span class="cov8" title="1">return data</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))
+                        sqlStr:=fmt.Sprintf("select  customer_service_name from  %s "+
+                                "where  ent_id= %d "+
+                                "AND customer_service_id= %d ",
+                                util.SOCIALIZE_CHAT_SESSION, in.EntId, in.CustomerServiceId)
+                        customerList := util.Mysql.SelectBySql(sqlStr)
                         if len(*customerList) &gt; 0 </span><span class="cov8" title="1">{
                                 customerserviceName = quitl.InterfaceToStr((*customerList)[0]["customer_service_name"])
                         }</span>
@@ -414,53 +565,59 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fo
                         "user_id":               in.UserId,
                         "customer_service_name": customerserviceName,
                 }
-                sessionId = util.Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
+                sessionId = util.Mysql.InsertByTx(tx, util.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)})
+                fool := util.Mysql.Update(util.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">{
+//创建会话并保存信息
+func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) (bool, int64) <span class="cov8" title="1">{
+        messageId := int64(0)
         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)
+                        list := util.Mysql.SelectBySql(`select ? from socialize_tenant_seat where appid=? AND ent_id=? AND customer_service_id=?`, util.SOCIALIZE_CHAT_SESSION, 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)
+                <span class="cov8" title="1">messageId = util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE, appId, content, 8, 1, nowFormat, "admin")
+                sessionId := util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, util.SOCIALIZE_CHAT_SESSION, 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
+                        ok1 := util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) &gt; 0
+                        ok2 := util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, 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
+                        ok = util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 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
+                        ok = util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, 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>
-        })
+        }), messageId
 }
+
+//修改未读状态
 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})
+                fool := util.Mysql.Update(util.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>

+ 201 - 59
service/message_mail_box.go

@@ -1,86 +1,173 @@
 package service
 
 import (
+	quitl "app.yhyue.com/moapp/jybase/common"
+	util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
 	"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) {
 	v := make([]interface{}, 0)
 	sqlStr := ""
 	if userType == 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)
+		sqlStr = fmt.Sprintf("select  count(b.id) from   %s a  "+
+			"LEFT  JOIN  %s  b ON a.id=b.own_id "+
+			"where  b.type=5 "+
+			"AND   a.customer_service_id=%d   "+
+			"AND  b.isread=0  "+
+			"AND own_type = 1 "+
+			"order by create_time", util.SOCIALIZE_CHAT_SESSION, util.SOCIALIZE_MESSAGE_MAILBOX, entUserId)
+
 	} else {
-		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)
+		sqlStr = fmt.Sprintf("select  count(b.id) from    %s  b "+
+			"where   b.send_user_id != %d    "+
+			"AND   b.own_id=%d  "+
+			"AND  b.isread=0 "+
+			"AND own_type = 2 "+
+			"order by create_time", util.SOCIALIZE_MESSAGE_MAILBOX, newUserId, newUserId)
+
 	}
-	fmt.Println(sqlStr, v)
+	log.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)
+	sqlStr = fmt.Sprintf("SELECT  c.* FROM %s  b   "+
+		"LEFT join %s c on  b.messag_id=c.id "+
+		"WHERE  b.send_user_id != %d   "+
+		"AND b.own_id = %d  "+
+		"AND   b.isread=0  "+
+		"AND own_type = 2  "+
+		"ORDER BY  create_time DESC   "+
+		"LIMIT 0,1", util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE,
+		newUserId, newUserId)
+	lastData := util.Mysql.SelectBySql(sqlStr)
 	if len(*lastData) > 0 {
 		last = (*lastData)[0]
 	}
 	return
 }
+
+//用户列表查询
 func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string]interface{}, err error) {
-	v := make([]interface{}, 0)
 	sqlStr := ""
 	if in.UserType == 2 {
 		//用户最后一次信息查询
-		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 > c.receive_user_id THEN    CONCAT( c.send_user_id, c.receive_user_id )     WHEN c.send_user_id < c.receive_user_id THEN    CONCAT( c.receive_user_id, c.send_user_id )    END    )  "
-		data = util.Mysql.SelectBySql(userSql, in.NewUserId)
+		userSql := fmt.Sprintf("SELECT  MAX( c.id )   as messageId  FROM  socialize_message_mailbox c "+
+			"WHERE  c.own_id = %d   "+
+			"AND c.type = 2   "+
+			"AND c.own_type = 2 "+
+			"GROUP BY  (  CASE  WHEN c.send_user_id > c.receive_user_id "+
+			"THEN    CONCAT( c.send_user_id, c.receive_user_id )  "+
+			"WHEN c.send_user_id < c.receive_user_id "+
+			"THEN  CONCAT( c.receive_user_id, c.send_user_id )  END  ) ", in.NewUserId,
+		)
+		data = util.Mysql.SelectBySql(userSql)
 		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  or 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)
+		customerSql := fmt.Sprintf("SELECT   max( c.id )   as messageId  FROM   %s c "+
+			"LEFT JOIN %s d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) "+
+			"WHERE   c.own_id = %d  "+
+			"AND ( c.type = 4 OR c.type = 5  or c.type=6 or  c.type=7 ) "+
+			"AND c.own_type = 2 "+
+			"AND   d.user_id=c.own_id "+
+			"GROUP BY   d.ent_id  ", util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.NewUserId)
+		data = util.Mysql.SelectBySql(customerSql)
 		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.own_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)
+		sqlStr = fmt.Sprintf("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  %s h  "+
+			"WHERE  h.type = 2  "+
+			"AND h.own_id = %d  "+
+			"AND h.own_type = 2  "+
+			"AND   h.send_user_id=b.id   "+
+			"AND h.isread = 0  ) AS number  FROM  %s a "+
+			"LEFT JOIN  %s b ON  b.id = a.receive_user_id or  b.id = a.send_user_id  "+
+			"LEFT JOIN  %s e ON e.id = a.messag_id  "+
+			"WHERE a.id IN ( %s )  AND b.id != %d "+
+			"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    %s h   WHERE   ( h.type = 4 OR h.type = 5  )    AND h.own_id = %d    AND h.own_type = 2   AND  h.send_user_type = 1 AND  h.receive_user_id = %d    AND h.isread = 0   ) AS number "+
+			"FROM  %s a  "+
+			"LEFT JOIN %s b ON IF  ( a.send_user_type = 1, b.id = a.send_user_id, b.id = a.receive_user_id )  "+
+			"LEFT JOIN %s e ON e.id = a.messag_id  "+
+			"LEFT join %s  f on f.ent_id=b.ent_id   "+
+			"WHERE  a.id IN (  %s )  "+
+			"ORDER BY create_time DESC",
+			util.SOCIALIZE_MESSAGE_MAILBOX,
+			in.NewUserId,
+			util.SOCIALIZE_MESSAGE_MAILBOX,
+			util.BASE_USER,
+			util.SOCIALIZE_MESSAGE,
+			userMessageId,
+			in.NewUserId,
+			util.SOCIALIZE_MESSAGE_MAILBOX,
+			in.NewUserId,
+			in.NewUserId,
+			util.SOCIALIZE_MESSAGE_MAILBOX,
+			util.SOCIALIZE_CHAT_SESSION,
+			util.SOCIALIZE_MESSAGE,
+			util.SOCIALIZE_TENANT_ROBOT,
+			customerMessageId)
 	} else {
 		phoneSql := ""
 		if in.Phone != "" {
-			phoneSql = "and  b.phone like '%" + in.Phone + "%'"
+			phoneSql = "AND  b.phone like '% " + in.Phone + "%'"
 		}
 		startTimeSql := ""
 		if in.StartTime != "" {
-			startTimeSql = " and  DATE_FORMAT(c.create_time,'%Y-%m-%d') >= '" + in.StartTime + "' "
+			startTimeSql = "AND  DATE_FORMAT(c.create_time,'%Y-%m-%d') >= ' " + in.StartTime + "' "
 		}
 		endTimeSql := ""
 		if in.EndTime != "" {
-			endTimeSql = " and DATE_FORMAT(c.create_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
+			endTimeSql = "AND DATE_FORMAT(c.create_time,'%Y-%m-%d') <= ' " + in.EndTime + "' "
 		}
 		//先获取每个用户最后聊天记录
-		userSql := " SELECT   MAX( c.id ) as messageId   FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON   c.own_type=1 and  c.own_id=d.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)
-		log.Println(userSql, v)
-		data = util.Mysql.SelectBySql(userSql, v...)
+		userSql := fmt.Sprintf("SELECT   MAX( c.id ) as messageId   FROM  %s c   "+
+			"LEFT JOIN %s d ON   c.own_type=1 AND  c.own_id=d.id   "+
+			"WHERE   c.own_type = 1    "+
+			"AND d.customer_service_id = %d   "+
+			"AND ( c.type = 4 OR c.type = 5 or  c.type=6 or  c.type=7 )   "+
+			"AND d.customer_service_id !=0   %s %s  "+
+			"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  ) ",
+			util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
+			in.EntUserId, startTimeSql, endTimeSql)
+		data = util.Mysql.SelectBySql(userSql)
 		if data != nil {
 			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  left join socialize_chat_session i ON h.own_type = 1 AND h.own_id = i.id     WHERE     h.own_type = 1     AND i.ent_id=f.ent_id and  i.user_id=f.user_id       AND h.isread = 0    and  i.customer_service_id=" + quitl.InterfaceToStr(in.EntUserId) + " ) AS number   FROM  socialize_message_mailbox a  LEFT JOIN base_user b ON if (a.send_user_type=1 ,a.receive_user_id=b.id,a.send_user_id=b.id)   LEFT JOIN socialize_message e ON e.id = a.messag_id  LEFT JOIN socialize_chat_session f ON a.own_type=1 and  a.own_id=f.id   WHERE  a.id IN  (" + customerMessageId + ")" + phoneSql + "   ORDER BY  a.create_time DESC"
-			fmt.Println(in.EntUserId)
-			v = make([]interface{}, 0)
+			sqlStr = fmt.Sprintf("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   %s h   "+
+				"LEFT JOIN %s i ON h.own_type = 1 AND h.own_id = i.id     "+
+				"WHERE  h.own_type = 1  "+
+				"AND i.ent_id=f.ent_id "+
+				"AND  i.user_id=f.user_id    "+
+				"AND h.isread = 0    "+
+				"AND  i.customer_service_id= %d "+
+				"FROM  %s a  "+
+				"LEFT JOIN %s b ON if (a.send_user_type=1 ,a.receive_user_id=b.id,a.send_user_id=b.id)  "+
+				"LEFT JOIN %s e ON e.id = a.messag_id  "+
+				"LEFT JOIN %s f ON a.own_type=1 AND  a.own_id=f.id   "+
+				"WHERE  a.id IN  ( %s) %s ORDER BY  a.create_time DESC",
+				util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
+				in.EntUserId, util.SOCIALIZE_MESSAGE_MAILBOX, util.BASE_USER, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, customerMessageId, phoneSql)
 		}
 	}
 	if sqlStr != "" {
-		fmt.Println(sqlStr, v)
-		data = util.Mysql.SelectBySql(sqlStr, v...)
+		log.Println(sqlStr)
+		data = util.Mysql.SelectBySql(sqlStr)
 	}
 	return
 }
+
+//消息保存
 func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
 	//先插入信息表
 	//判断会话标识是否属于本人
@@ -115,7 +202,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			break
 		}
 		//查找会话信息
-		chatJson := util.Mysql.FindOne("socialize_chat_session", map[string]interface{}{"id": sessionId}, "user_id", "")
+		chatJson := util.Mysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id", "")
 		if chatJson == nil {
 			return false, "会话标识不存在", "", 0, nowForm.Unix()
 		} else {
@@ -136,7 +223,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			"create_time":   nowForm.Format(util.Date_Full_Layout),
 			"create_person": in.SendId,
 		}
-		ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
+		ok := util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
 		receiveOk := int64(0)
 		messageId = ok
 		//在插入邮箱表socialize_message_mailbox
@@ -189,11 +276,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 				messageMailBox["send_user_id"] = in.NewUserId
 				messageMailBox["receive_user_id"] = in.ReceiveId
 			}
-			if in.ItemType == 4 {
-				messageMailBox["isread"] = 1
-				messageMailBox["read_time"] = nowForm.Format(util.Date_Full_Layout)
-			}
-			receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+			receiveOk = util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
 			return ok > 1 && receiveOk > 1
 		}
 		if in.ItemType == 4 || in.ItemType == 5 {
@@ -229,7 +312,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			messageMailBox["send_user_id"] = in.NewUserId
 			messageMailBox["receive_user_id"] = in.ReceiveId
 		}
-		receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+		receiveOk = util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
 		messageMailBox = map[string]interface{}{
 			"appid":         in.Appid,
 			"messag_id":     ok,
@@ -272,32 +355,69 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			messageMailBox["send_user_id"] = in.NewUserId
 			messageMailBox["receive_user_id"] = in.ReceiveId
 		}
-		receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
+		receiveOk = util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
 		return ok > 1 && receiveOk > 1
 	})
 	return fool, "", in.Content, messageId, nowForm.Unix()
 }
+
+//历史信息查询
 func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} {
 	sqlStr := ""
-	lastStr := "  "
+	lastStr := ""
 	if in.LastId > 0 {
 		if in.Sort == "asc" {
-			lastStr = " and  a.messag_id > " + quitl.InterfaceToStr(in.LastId)
+			lastStr = fmt.Sprintf("AND  a.messag_id > %d ", in.LastId)
 		} else {
-			lastStr = " and  a.messag_id < " + quitl.InterfaceToStr(in.LastId)
+			lastStr = fmt.Sprintf("AND  a.messag_id < %d ", in.LastId)
 		}
 	}
 	switch in.MsgType {
 	case 2: //点对点聊天
-		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)
+		sqlStr = fmt.Sprintf("SELECT  a.messag_id as messageId,b.* ,if(a.own_id = a.send_user_id,1,2) as fool  "+
+			"FROM  %s a  "+
+			"LEFT JOIN %s b on  a.messag_id=b.id  "+
+			"LEFT  JOIN  %s c on  c.id=a.send_user_id   "+
+			"LEFT JOIN  %s d on  d.id=a.receive_user_id  "+
+			"where  a.own_id=  %d "+
+			"AND ((a.send_user_id=   %d AND   a.receive_user_id=   %d) or (a.send_user_id=  %d AND  a.receive_user_id=  %d)) "+
+			"AND  a.type=2  %s "+
+			"ORDER BY a.create_time desc ,a.id   asc "+
+			"limit 0 ,  %d ",
+			util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.BASE_USER, util.BASE_USER,
+			in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId, lastStr, in.PageSize)
 		break
 	case 4, 5, 6, 7: //客服聊天
 		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,   '' AS robotName,   '' 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      a.own_type = 1  and  a.own_id=c.id    WHERE   a.own_type = 1      AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)   AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + lastStr + "  ORDER BY a.create_time desc ,a.id   asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
+			sqlStr = fmt.Sprintf("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,   '' AS robotName,   '' AS robotImg,   c.customer_service_name AS setName ,   c.user_id   "+
+				"FROM   %s a   "+
+				"LEFT JOIN %s b ON a.messag_id = b.id   "+
+				"LEFT JOIN %s c ON   a.own_type = 1  AND  a.own_id=c.id    "+
+				"WHERE   a.own_type = 1   "+
+				"AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)   "+
+				"AND c.ent_id =   %d "+
+				"AND c.user_id =   %d  %s "+
+				"ORDER BY a.create_time desc ,a.id   asc "+
+				"limit 0 ,  %d ",
+				util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION,
+				in.EntId, in.SendId, lastStr, in.PageSize)
 		} 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 ) and  c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND c.user_id = " + quitl.InterfaceToStr(in.NewUserId) + "     left join  socialize_tenant_robot d on  c.ent_id=d.ent_id    WHERE   a.own_type = 2    AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + "  and  c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND c.user_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 = fmt.Sprintf("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   %s a   "+
+				"LEFT JOIN %s b ON a.messag_id = b.id   "+
+				"LEFT JOIN %s c ON   IF   ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) AND  c.ent_id = %d AND c.user_id = %d "+
+				"LEFT JOIN  %s d on  c.ent_id=d.ent_id    "+
+				"WHERE   a.own_type = 2    "+
+				"AND a.own_id =  %d "+
+				"AND  c.ent_id = %d "+
+				"AND c.user_id =  %d "+
+				"AND ( a.type = 4 OR a.type = 5 or a.type=6 or  a.type=7)  %s "+
+				"ORDER BY a.create_time desc ,a.id   asc "+
+				"limit 0 ,   %d ",
+				util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, in.SendId, in.NewUserId, util.SOCIALIZE_TENANT_ROBOT,
+				in.NewUserId, in.SendId, in.NewUserId, lastStr, in.PageSize)
 		}
 		break
 	}
@@ -305,7 +425,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
 	data := util.Mysql.SelectBySql(sqlStr)
 	//自己头像处理
 	if in.UserType == 2 {
-		userData := util.Mysql.FindOne("base_user", map[string]interface{}{"id": in.NewUserId}, "headimg", "")
+		userData := util.Mysql.FindOne(util.BASE_USER, map[string]interface{}{"id": in.NewUserId}, "headimg", "")
 		if userData != nil {
 			for key := range *data {
 				(*data)[key]["ownImg"] = (*userData)["headimg"]
@@ -325,25 +445,42 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
 					"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)})
+				util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
 				break
 			case 4, 5:
+				sqlStr := ""
 				if in.UserType == 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)
+					sqlStr = fmt.Sprintf("UPDATE %s 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 %s b WHERE   b.customer_service_id=%d AND    b.user_id=%d  )",
+						util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, in.SendId)
 				} else {
-					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)
+					sqlStr = fmt.Sprintf("UPDATE %s 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 =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
 				}
+				util.Mysql.UpdateOrDeleteBySql(sqlStr)
 				break
 			}
 		}
 	}()
 	return data
 }
+
+//创建会话
 func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
 	fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
 		customerserviceName := in.CustomerserviceName
 		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))
+			sqlStr := fmt.Sprintf("select  customer_service_name from  %s "+
+				"where  ent_id= %d "+
+				"AND customer_service_id= %d ",
+				util.SOCIALIZE_CHAT_SESSION, in.EntId, in.CustomerServiceId)
+			customerList := util.Mysql.SelectBySql(sqlStr)
 			if len(*customerList) > 0 {
 				customerserviceName = quitl.InterfaceToStr((*customerList)[0]["customer_service_name"])
 			}
@@ -357,54 +494,59 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fo
 			"user_id":               in.UserId,
 			"customer_service_name": customerserviceName,
 		}
-		sessionId = util.Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
+		sessionId = util.Mysql.InsertByTx(tx, util.SOCIALIZE_CHAT_SESSION, chatMession)
 		return sessionId > 0
 	})
 	return fool, sessionId
 }
+
+//结束会话
 func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool {
 	fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
 		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)})
+		fool := util.Mysql.Update(util.SOCIALIZE_CHAT_SESSION, updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
 		return fool
 	})
 	return fool
 }
 
+//创建会话并保存信息
 func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) (bool, int64) {
 	messageId := int64(0)
 	return util.Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
 		entUserName := ""
 		if entUserId > 0 {
-			list := util.Mysql.SelectBySql(`select customer_service_name from socialize_tenant_seat where appid=? and ent_id=? and customer_service_id=?`, appId, entId, entUserId)
+			list := util.Mysql.SelectBySql(`select ? from socialize_tenant_seat where appid=? AND ent_id=? AND customer_service_id=?`, util.SOCIALIZE_CHAT_SESSION, appId, entId, entUserId)
 			if list != nil && len(*list) > 0 {
 				entUserName, _ = (*list)[0]["customer_service_name"].(string)
 			}
 		}
-		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)
+		messageId = util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE, appId, content, 8, 1, nowFormat, "admin")
+		sessionId := util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, util.SOCIALIZE_CHAT_SESSION, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
 		ok := false
 		if userType == 0 {
-			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,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 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) > 0
+			ok1 := util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
+			ok2 := util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
 			ok = ok1 && ok2
 		} else if userType == 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,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
+			ok = util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
 		} else if userType == 2 {
-			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) > 0
+			ok = util.Mysql.InsertBySqlByTx(tx, `insert into ? (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, util.SOCIALIZE_MESSAGE_MAILBOX, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
 		}
 		return messageId > 0 && sessionId > 0 && ok
 	}), messageId
 }
+
+//修改未读状态
 func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
 	fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
 		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})
+		fool := util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
 		return fool
 	})
 	return fool

+ 20 - 4
service/message_mail_box_test.go

@@ -435,7 +435,7 @@ func TestMessaggeService_SaveMessage(t *testing.T) {
 					NewUserId: 10,
 				},
 			}},
-		{name: "7、机器人给用户发送信息",
+		{name: "8、机器人给用户发送信息",
 			args: args{
 				in: &messagecenter.MessageEntity{
 					Title:     "11",
@@ -450,7 +450,7 @@ func TestMessaggeService_SaveMessage(t *testing.T) {
 					NewUserId: 10,
 				},
 			}},
-		{name: "7、机器人给用户发送信息",
+		{name: "9、机器人给用户发送信息",
 			args: args{
 				in: &messagecenter.MessageEntity{
 					Title:     "11",
@@ -466,7 +466,23 @@ func TestMessaggeService_SaveMessage(t *testing.T) {
 				},
 			},
 		},
-		{name: "会话标识不存在",
+		{name: "10、机器人接受系统信息",
+			args: args{
+				in: &messagecenter.MessageEntity{
+					Title:     "11",
+					Content:   "问在吗?",
+					Item:      8,
+					ItemType:  6,
+					Link:      "1111",
+					Appid:     "10000",
+					NewUserId: 10,
+					OwnType:   int64(3),
+					Type:      1,
+					ReceiveId: 514,
+				},
+			},
+		},
+		{name: "11会话标识不存在",
 			args: args{
 				in: &messagecenter.MessageEntity{
 					Title:     "11",
@@ -482,7 +498,7 @@ func TestMessaggeService_SaveMessage(t *testing.T) {
 				},
 			},
 		},
-		{name: "会话标识不属于此用户",
+		{name: "12会话标识不属于此用户",
 			args: args{
 				in: &messagecenter.MessageEntity{
 					Title:     "11",