Merge pull request 'feat-IRONFANS-61-Robin' (#154) from feat-IRONFANS-61-Robin into test

Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/154
This commit is contained in:
chenhao 2024-02-29 11:23:45 +08:00
commit 20a97b8ba7
4 changed files with 47 additions and 9 deletions

View File

@ -37,6 +37,7 @@ type OpUpdateByIdsResp struct {
// op 查询所有未读 // op 查询所有未读
type OpListReq struct { type OpListReq struct {
base.BaseRequest base.BaseRequest
IsRead *int64 `json:"is_read"` //是否已读
CtUpperBound *int64 `json:"ct_upper_bound"` //创建时间上界,闭区间 CtUpperBound *int64 `json:"ct_upper_bound"` //创建时间上界,闭区间
CtLowerBound *int64 `json:"ct_lower_bound"` //创建时间下界开区间可为0 CtLowerBound *int64 `json:"ct_lower_bound"` //创建时间下界开区间可为0
} }

View File

@ -2438,6 +2438,9 @@ func (m *Mongo) GetContactCustomerServiceList(ctx *gin.Context, req *contact_cus
"predicate": consts.ContactCustomerService_FromUser, "predicate": consts.ContactCustomerService_FromUser,
"del_flag": 0, "del_flag": 0,
} }
if req.IsRead != nil {
query["is_read"] = util.DerefInt64(req.IsRead)
}
filterInClause := []qmgo.M{} filterInClause := []qmgo.M{}
if req.CtLowerBound != nil { if req.CtLowerBound != nil {
filterInClause = append(filterInClause, qmgo.M{ filterInClause = append(filterInClause, qmgo.M{
@ -2481,6 +2484,21 @@ func (m *Mongo) GetUnreadContactCustomerServiceList(ctx *gin.Context, req *conta
return list, err return list, err
} }
func (m *Mongo) GetUnreadContactCustomerServiceCount(ctx *gin.Context) (int64, error) {
col := m.getColContactCustomerService()
query := qmgo.M{
"is_read": consts.ContactCustomerService_NotRead,
"predicate": consts.ContactCustomerService_FromUser,
"del_flag": 0,
}
count, err := col.Find(ctx, query).Count()
if err == qmgo.ErrNoSuchDocuments {
err = nil
return 0, err
}
return count, err
}
func (m *Mongo) GetContactCustomerServiceListBySessionId(ctx *gin.Context, req *contact_customer_service_proto.OpListBySessionIdReq) ([]*dbstruct.ContactCustomerService, error) { func (m *Mongo) GetContactCustomerServiceListBySessionId(ctx *gin.Context, req *contact_customer_service_proto.OpListBySessionIdReq) ([]*dbstruct.ContactCustomerService, error) {
list := make([]*dbstruct.ContactCustomerService, 0) list := make([]*dbstruct.ContactCustomerService, 0)
col := m.getColContactCustomerService() col := m.getColContactCustomerService()

View File

@ -81,6 +81,15 @@ func (p *ContactCustomerService) OpListUnread(ctx *gin.Context, req *contact_cus
return list, nil return list, nil
} }
func (p *ContactCustomerService) OpCountUnread(ctx *gin.Context) (int64, error) {
count, err := p.store.GetUnreadContactCustomerServiceCount(ctx)
if err != nil {
logger.Error("GetUnreadContactCustomerServiceCount fail, err: %v", err)
return 0, err
}
return count, nil
}
func (p *ContactCustomerService) OpListBySessionId(ctx *gin.Context, req *contact_customer_serviceproto.OpListBySessionIdReq) ([]*dbstruct.ContactCustomerService, error) { func (p *ContactCustomerService) OpListBySessionId(ctx *gin.Context, req *contact_customer_serviceproto.OpListBySessionIdReq) ([]*dbstruct.ContactCustomerService, error) {
list, err := p.store.GetContactCustomerServiceListBySessionId(ctx, req) list, err := p.store.GetContactCustomerServiceListBySessionId(ctx, req)
if err != nil { if err != nil {

View File

@ -588,10 +588,23 @@ func (s *Service) utilStringifyContactCustomerServices(ctx *gin.Context, contact
return return
} }
countUnread, err := _DefaultContactCustomerService.OpCountUnread(ctx)
if err != nil {
logger.Error("OpCountUnread fail, err: %v", err)
return
}
msgBuilder := &strings.Builder{} msgBuilder := &strings.Builder{}
msgBuilder.WriteString("上分钟收到的联系客服消息:\n\n") msgBuilder.WriteString(fmt.Sprintf("上分钟收到的联系客服消息:%v\n", len(contactCustomerServices)))
msgBuilder.WriteString(fmt.Sprintf("当前总未读消息数:%v\n\n", countUnread))
msgBuilder.WriteString("新增未读消息:\n")
for i, contactCustomerService := range contactCustomerServices { for i, contactCustomerService := range contactCustomerServices {
isRead := util.DerefInt64(contactCustomerService.IsRead)
if isRead == consts.ContactCustomerService_Read {
continue
}
sessionId := util.DerefInt64(contactCustomerService.SessionId) sessionId := util.DerefInt64(contactCustomerService.SessionId)
account, err1 := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{ account, err1 := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: sessionMap[sessionId].SubMid, Mid: sessionMap[sessionId].SubMid,
@ -601,16 +614,13 @@ func (s *Service) utilStringifyContactCustomerServices(ctx *gin.Context, contact
err = err1 err = err1
return return
} }
isRead := util.DerefInt64(contactCustomerService.IsRead)
message := util.DerefString(contactCustomerService.Message)
ct := util.DerefInt64(contactCustomerService.Ct) ct := util.DerefInt64(contactCustomerService.Ct)
createtime := time.Unix(ct, 0).Format(time.DateTime) createtime := time.Unix(ct, 0).Format(time.DateTime)
if isRead == consts.ContactCustomerService_NotRead { msgBuilder.WriteString(fmt.Sprintf("%v\n", i+1))
msgBuilder.WriteString(fmt.Sprintf("%v. 接收到未读消息:\n", i)) msgBuilder.WriteString(fmt.Sprintf("用户id %v\n", util.DerefInt64(account.UserId)))
} else { msgBuilder.WriteString(fmt.Sprintf("发送内容: %v\n", util.DerefString(contactCustomerService.Message)))
msgBuilder.WriteString(fmt.Sprintf("%v. 该条消息已读:\n", i)) msgBuilder.WriteString(fmt.Sprintf("发送时间: %v\n\n", createtime))
}
msgBuilder.WriteString(fmt.Sprintf("user_id: %v, session_id: %v, message: \"%v\", ct: %v\n\n", util.DerefInt64(account.UserId), sessionId, message, createtime))
} }
msg = msgBuilder.String() msg = msgBuilder.String()