Browse Source

Merge branch 'master' into task_526_lichangdong_250424

lichangdong 1 tuần trước cách đây
mục cha
commit
d855be9bdc

+ 23 - 16
crontask/contact_form.go

@@ -131,7 +131,9 @@ func (l *CronTask) analyze() {
 	predicates = append(predicates, usagedetail.AppIn(1, 3, 4, 5))
 	//yesterdayStart := time.Now().AddDate(0, 0, -1).Truncate(24 * time.Hour)
 	//yesterdayEnd := yesterdayStart.Add(24 * time.Hour)
-	yesterdayEnd := time.Now().Truncate(24 * time.Hour)
+	loc, _ := time.LoadLocation("Asia/Shanghai")
+	now := time.Now().In(loc)
+	yesterdayEnd := now.Truncate(24 * time.Hour)
 	yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
 	predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
 	predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
@@ -147,15 +149,21 @@ func (l *CronTask) analyze() {
 		return
 	}
 
-	for _, u := range data {
-		if _, ok := contactFieldTemplates[u.BotID]; !ok {
-			c, _ := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.OrganizationID(u.OrganizationID)).First(l.ctx)
-			if c != nil {
-				contactFieldTemplates[u.BotID] = c.Template
-			} else {
-				contactFieldTemplates[u.BotID] = nil
-			}
+	wxs, err := l.svcCtx.DB.Wx.Query().All(l.ctx)
+	if err != nil {
+		return
+	}
+
+	for _, wx := range wxs {
+		c, _ := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.OrganizationID(wx.OrganizationID)).First(l.ctx)
+		if c != nil {
+			contactFieldTemplates[wx.Wxid] = c.Template
+		} else {
+			contactFieldTemplates[wx.Wxid] = nil
 		}
+	}
+
+	for _, u := range data {
 		if contactFieldTemplates[u.BotID] == nil {
 			continue
 		}
@@ -390,13 +398,12 @@ func (l *CronTask) UpdateContactFields(botID string, receiverID string, fields [
 			} else {
 				if field.Value != nil {
 					if len(field.Value) == 0 || field.Value[0] == "" {
-						continue
-					}
-					_, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
-						SetValue(field.Value).
-						Save(l.ctx)
-					if err != nil {
-						continue
+						_, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
+							SetValue(field.Value).
+							Save(l.ctx)
+						if err != nil {
+							continue
+						}
 					}
 				}
 			}

+ 18 - 1
desc/wechat/dashboard.api

@@ -31,7 +31,7 @@ type (
         ActiveUser *ChartsUint `json:"active_user"`
         NewUser *ChartsInt `json:"new_user"`
         LabelDist []LabelsData `json:"label_dist"`
-		ConsumeCoin *ChartsFloat `json:"consume_coin"`
+		ConsumeCoin *ChartsStr `json:"consume_coin"`
     }
 
     ChartsUint {
@@ -51,6 +51,23 @@ type (
 		LabelText string `json:"labelText"`
 		Tip *string `json:"tip"`
 	}
+	ChartsMix {
+        Count int64 `json:"count"`
+        Rate *float32 `json:"rate"`
+        Label []string `json:"label"`
+        Val []float64 `json:"val"`
+        LabelText string `json:"labelText"`
+        Tip *string `json:"tip"`
+    }
+
+    ChartsStr {
+        Count string `json:"count"`
+        Rate *float32 `json:"rate"`
+        Label []string `json:"label"`
+        Val []float64 `json:"val"`
+        LabelText string `json:"labelText"`
+        Tip *string `json:"tip"`
+    }
 
     ChartsInt {
         Count int64 `json:"count"`

+ 8 - 1
internal/logic/dashboard/get_charts_logic.go

@@ -500,6 +500,13 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 		}
 	}
 	accountBalance.Count = 0
+
+	consumeCoinInt := types.ChartsStr{}
+	consumeCoinInt.Count = fmt.Sprintf("%.6f", consumeCoin.Count)
+	consumeCoinInt.Val = consumeCoin.Val
+	consumeCoinInt.Label = consumeCoin.Label
+	consumeCoinInt.LabelText = consumeCoin.LabelText
+
 	chartsData := types.ChartsData{
 		AiResponse:     &aiResponse,
 		SopRun:         &sopRun,
@@ -507,7 +514,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 		TotalGroup:     &totalGroup,
 		AccountBalance: &accountBalance,
 		ConsumeToken:   &consumeToken,
-		ConsumeCoin:    &consumeCoin,
+		ConsumeCoin:    &consumeCoinInt,
 		ActiveUser:     &activeUser,
 		NewUser:        &newUser,
 		LabelDist:      labelsData,

+ 19 - 1
internal/types/types.go

@@ -3592,7 +3592,7 @@ type ChartsData struct {
 	ActiveUser     *ChartsUint  `json:"active_user"`
 	NewUser        *ChartsInt   `json:"new_user"`
 	LabelDist      []LabelsData `json:"label_dist"`
-	ConsumeCoin    *ChartsFloat `json:"consume_coin"`
+	ConsumeCoin    *ChartsStr   `json:"consume_coin"`
 }
 
 type ChartsUint struct {
@@ -3613,6 +3613,24 @@ type ChartsFloat struct {
 	Tip       *string   `json:"tip"`
 }
 
+type ChartsMix struct {
+	Count     int64     `json:"count"`
+	Rate      *float32  `json:"rate"`
+	Label     []string  `json:"label"`
+	Val       []float64 `json:"val"`
+	LabelText string    `json:"labelText"`
+	Tip       *string   `json:"tip"`
+}
+
+type ChartsStr struct {
+	Count     string    `json:"count"`
+	Rate      *float32  `json:"rate"`
+	Label     []string  `json:"label"`
+	Val       []float64 `json:"val"`
+	LabelText string    `json:"labelText"`
+	Tip       *string   `json:"tip"`
+}
+
 type ChartsInt struct {
 	Count     int64    `json:"count"`
 	Rate      *float32 `json:"rate"`

+ 3 - 1
internal/utils/compapi/form.go

@@ -37,6 +37,7 @@ type FormList struct {
 
 func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
+	weekday := time.Now().Weekday().String()
 	//bytes, err := json.Marshal(req.Variables["form_data"])
 	//if err != nil {
 	//	return err
@@ -49,7 +50,8 @@ func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
 请帮助user从通话记录中提取表单值,并返回一个JSON格式的表单值。
 
 # 背景信息
-` + nowTime + `
+当前时间是:` + nowTime + `
+当前星期是:` + weekday + `
 
 # 返回值示例
 * 如表单类型为 input、autoComplete、textarea,返回示例:["表单值"]