|
@@ -71,7 +71,7 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
|
|
|
isCurrentDay = endTime.Year() == now.Year() && endTime.Month() == now.Month() && endTime.Day() == now.Day()
|
|
|
}
|
|
|
|
|
|
- wxs, err := l.svcCtx.DB.Wx.Query().Where(wx.OrganizationID(organizationId)).Page(l.ctx, req.Page, req.PageSize)
|
|
|
+ wxs, err := l.svcCtx.DB.Wx.Query().Where(wx.OrganizationID(organizationId)).All(l.ctx)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
@@ -79,11 +79,10 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
|
|
|
|
|
|
resp = &types.WxResp{}
|
|
|
resp.Msg = errormsg.Success
|
|
|
- resp.Data.Total = wxs.PageDetails.Total
|
|
|
|
|
|
var wxIds []string
|
|
|
wxSet := make(map[string]*ent.Wx)
|
|
|
- for _, w := range wxs.List {
|
|
|
+ for _, w := range wxs {
|
|
|
wxIds = append(wxIds, w.Wxid)
|
|
|
wxSet[w.Wxid] = w
|
|
|
}
|
|
@@ -110,17 +109,20 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
|
|
|
usagestatistichour.OrganizationID(organizationId),
|
|
|
usagestatistichour.BotIDIn(wxIds...),
|
|
|
usagestatistichour.Addtime(lastHourData.Addtime),
|
|
|
- ).All(l.ctx)
|
|
|
+ ).Page(l.ctx, req.Page, req.PageSize)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- for _, hourData := range usageStatisticHour {
|
|
|
- wxList = append(wxList, types.WxData{
|
|
|
- Nickname: wxSet[hourData.BotID].Nickname,
|
|
|
- InteractionRate: float32(hourData.ActiveUser) / float32(hourData.TotalFriend),
|
|
|
- TotalFriend: hourData.TotalFriend,
|
|
|
- TotalGroup: hourData.TotalGroup,
|
|
|
- })
|
|
|
+ if usageStatisticHour != nil && usageStatisticHour.List != nil {
|
|
|
+ resp.Data.Total = usageStatisticHour.PageDetails.Total
|
|
|
+ for _, hourData := range usageStatisticHour.List {
|
|
|
+ wxList = append(wxList, types.WxData{
|
|
|
+ Nickname: wxSet[hourData.BotID].Nickname,
|
|
|
+ InteractionRate: float32(hourData.ActiveUser) / float32(hourData.TotalFriend),
|
|
|
+ TotalFriend: hourData.TotalFriend,
|
|
|
+ TotalGroup: hourData.TotalGroup,
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
// 返回当日每小时的数据
|
|
@@ -131,7 +133,6 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
|
|
|
).
|
|
|
Order(ent.Desc(usagestatisticday.FieldAddtime)).
|
|
|
First(l.ctx)
|
|
|
- l.Infof("----------------lastDayData--------------: %+v", lastDayData)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -143,25 +144,26 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
|
|
|
usagestatisticday.OrganizationID(organizationId),
|
|
|
usagestatisticday.BotIDIn(wxIds...),
|
|
|
usagestatisticday.Addtime(lastDayData.Addtime),
|
|
|
- ).All(l.ctx)
|
|
|
+ ).Page(l.ctx, req.Page, req.PageSize)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- for _, dayData := range usageStatisticDay {
|
|
|
- l.Infof("----------------dayData--------------: %+v", dayData)
|
|
|
- rate := float32(0)
|
|
|
- if dayData.TotalFriend != 0 {
|
|
|
- rate = float32(dayData.ActiveUser) / float32(dayData.TotalFriend)
|
|
|
+ if usageStatisticDay != nil && usageStatisticDay.List != nil {
|
|
|
+ resp.Data.Total = usageStatisticDay.PageDetails.Total
|
|
|
+ for _, dayData := range usageStatisticDay.List {
|
|
|
+ rate := float32(0)
|
|
|
+ if dayData.TotalFriend != 0 {
|
|
|
+ rate = float32(dayData.ActiveUser) / float32(dayData.TotalFriend)
|
|
|
+ }
|
|
|
+ wxList = append(wxList, types.WxData{
|
|
|
+ Nickname: wxSet[dayData.BotID].Nickname,
|
|
|
+ InteractionRate: rate,
|
|
|
+ TotalFriend: dayData.TotalFriend,
|
|
|
+ TotalGroup: dayData.TotalGroup,
|
|
|
+ })
|
|
|
}
|
|
|
- wxList = append(wxList, types.WxData{
|
|
|
- Nickname: wxSet[dayData.BotID].Nickname,
|
|
|
- InteractionRate: rate,
|
|
|
- TotalFriend: dayData.TotalFriend,
|
|
|
- TotalGroup: dayData.TotalGroup,
|
|
|
- })
|
|
|
}
|
|
|
}
|
|
|
- l.Infof("----------------wxList--------------: %+v", wxList)
|
|
|
resp.Data.Data = wxList
|
|
|
|
|
|
return resp, nil
|