|
@@ -1047,17 +1047,15 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
|
|
|
fieids := []string{"appid", "messag_id", "type", "send_user_id", "send_user_type", "receive_user_id", "receive_user_type", "own_type", "own_id", "create_time", "chat_group_id", "isread"}
|
|
|
for _, v := range in.GroupIds {
|
|
|
args := []interface{}{}
|
|
|
- summaryArgs := []interface{}{}
|
|
|
args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
|
|
|
groupUser := GetUserByGroupId(tx, v, in.SendId)
|
|
|
for _, vv := range groupUser {
|
|
|
log.Println("获取到群组下员工:", vv)
|
|
|
args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, vv, 2, 2, vv, nowTime, v, 0)
|
|
|
}
|
|
|
- summaryArgs = append(summaryArgs, in.SendId, nil, nil, v, messageId, nil, isCustomerServiceAccess, nowTime)
|
|
|
MessageMailBoxAdd(tx, fieids, args)
|
|
|
//最后一次聊天
|
|
|
- SocializeSummaryAdd(tx, summaryArgs)
|
|
|
+ SocializeSummaryAddOrUpdate(tx, v, 0, 0, messageId, isCustomerServiceAccess, nowTime)
|
|
|
//更新未读消息
|
|
|
GroupUserUnReadUpdate(tx, groupUser)
|
|
|
}
|
|
@@ -1066,18 +1064,15 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
|
|
|
if isOneToOne {
|
|
|
fieids := []string{"appid", "messag_id", "type", "send_user_id", "send_user_type", "receive_user_id", "receive_user_type", "own_type", "own_id", "create_time", "isread"}
|
|
|
args := []interface{}{}
|
|
|
- summaryArgs := []interface{}{}
|
|
|
args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, 1)
|
|
|
for _, v := range in.ReceiverIds {
|
|
|
args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, v, 2, 2, v, nowTime, 0)
|
|
|
- //发送方,未读消息应该是0
|
|
|
- summaryArgs = append(summaryArgs, in.SendId, v, nil, nil, messageId, 0, isCustomerServiceAccess, nowTime)
|
|
|
- //接收方,未读消息应该是1
|
|
|
- summaryArgs = append(summaryArgs, v, in.SendId, nil, nil, messageId, 1, isCustomerServiceAccess, nowTime)
|
|
|
+
|
|
|
+ //最后一次聊天
|
|
|
+ SocializeSummaryAddOrUpdate(tx, 0, in.SendId, v, messageId, isCustomerServiceAccess, nowTime)
|
|
|
+ SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
|
|
|
}
|
|
|
MessageMailBoxAdd(tx, fieids, args)
|
|
|
- //最后一次聊天
|
|
|
- SocializeSummaryAdd(tx, summaryArgs)
|
|
|
}
|
|
|
return true
|
|
|
})
|
|
@@ -1113,7 +1108,6 @@ func MessageMailBoxAdd(tx *sql.Tx, fieids []string, args []interface{}) (int64,
|
|
|
func GetUserByGroupId(tx *sql.Tx, groupId, sendId int64) []int64 {
|
|
|
arr := []int64{}
|
|
|
data := IC.BaseMysql.SelectBySqlByTx(tx, "select position_id from "+util.SOCIALIZE_CHAT_GROUP_PERSON+" where status = 1 and chat_group_id = ? AND position_id != ? ", groupId, sendId)
|
|
|
- log.Println("~~~~", data)
|
|
|
if data == nil || len(*data) <= 0 {
|
|
|
return arr
|
|
|
}
|
|
@@ -1128,14 +1122,75 @@ func GetUserByGroupId(tx *sql.Tx, groupId, sendId int64) []int64 {
|
|
|
}
|
|
|
|
|
|
// 最后一次聊天存储
|
|
|
-func SocializeSummaryAdd(tx *sql.Tx, args []interface{}) (int64, int64) {
|
|
|
- fieids := []string{"my_position_id", "your_position_id", "ent_id", "chat_group_id", "message_id", "unread", "customer_service_access", "timestamp"}
|
|
|
-
|
|
|
- length, lastId := IC.BaseMysql.InsertBatchByTx(tx, util.SOCIALIZE_SUMMARY, fieids, args)
|
|
|
-
|
|
|
- log.Println("SocializeSummaryAdd length:", length, "SocializeSummaryAdd lastId:", lastId)
|
|
|
-
|
|
|
- return length, lastId
|
|
|
+func SocializeSummaryAddOrUpdate(tx *sql.Tx, groupId, myPositionId, yourPositionId, messageId int64, isCustomerServiceAccess int, timestamp string) bool {
|
|
|
+ //判断是否存在
|
|
|
+ if groupId > 0 {
|
|
|
+ if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where chat_group_id =?`, util.SOCIALIZE_SUMMARY), groupId) > 0 {
|
|
|
+ //存在更新
|
|
|
+ return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "chat_group_id": groupId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "chat_group_id": groupId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if yourPositionId > 0 {
|
|
|
+ ok_my := true
|
|
|
+ ok_your := true
|
|
|
+ //发送方
|
|
|
+ if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), myPositionId, yourPositionId) > 0 {
|
|
|
+ //存在更新
|
|
|
+ ok_my = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": myPositionId,
|
|
|
+ "your_position_id": yourPositionId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ ok_my = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": myPositionId,
|
|
|
+ "your_position_id": yourPositionId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 0,
|
|
|
+ "customer_service_access": isCustomerServiceAccess,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
+ //接收方
|
|
|
+ if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), yourPositionId, myPositionId) > 0 {
|
|
|
+ //存在更新
|
|
|
+ ok_your = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": yourPositionId,
|
|
|
+ "your_position_id": myPositionId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 1,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ ok_your = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": yourPositionId,
|
|
|
+ "your_position_id": myPositionId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 1,
|
|
|
+ "customer_service_access": isCustomerServiceAccess,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
+ return ok_my && ok_your
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
// 群组人员未读消息更新
|