Browse Source

Merge branch 'feature/non_friends' into debug

* feature/non_friends:
  fixbug

# Conflicts:
#	crontask/contact_form.go
boweniac 2 days ago
parent
commit
739ea88b39
2 changed files with 26 additions and 26 deletions
  1. 23 24
      crontask/contact_form.go
  2. 3 2
      internal/utils/compapi/form.go

+ 23 - 24
crontask/contact_form.go

@@ -138,19 +138,10 @@ func (l *CronTask) analyze() {
 	predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
 	predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
 
-	//yesterdayEnd := time.Now().Truncate(24 * time.Hour)
-	//yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
-	//predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
-	//predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
-	//logx.Info("yesterdayEnd: ", yesterdayEnd)
-	//logx.Info("yesterdayStart: ", yesterdayStart)
-
-	todayStart := time.Now().AddDate(0, 0, 0).Truncate(24 * time.Hour)
-	todayEnd := todayStart.Add(24 * time.Hour)
-	predicates = append(predicates, usagedetail.CreatedAtGTE(todayStart))
-	predicates = append(predicates, usagedetail.CreatedAtLT(todayEnd))
-	logx.Info("todayStart: ", todayStart)
-	logx.Info("todayEnd: ", todayEnd)
+	//todayStart := time.Now().AddDate(0, 0, 0).Truncate(24 * time.Hour)
+	//todayEnd := todayStart.Add(24 * time.Hour)
+	//predicates = append(predicates, usagedetail.CreatedAtGTE(todayStart))
+	//predicates = append(predicates, usagedetail.CreatedAtLT(todayEnd))
 
 	data, err := l.svcCtx.DB.UsageDetail.Query().Where(predicates...).All(l.ctx)
 	logx.Info("usageDetails: ", data)
@@ -240,6 +231,7 @@ func (l *CronTask) openaiRequest(messages string, template []custom_types.Contac
 	if err == nil && resp != nil && len(resp.Choices) > 0 {
 		logx.Info("resp.Choices: ", resp.Choices[0].Message.Content)
 		// 尝试第一层解析成 string
+
 		items, err := parseContent(resp.Choices[0].Message.Content)
 		if err != nil {
 			return nil, err
@@ -405,15 +397,13 @@ func (l *CronTask) UpdateContactFields(botID string, receiverID string, fields [
 						continue
 					}
 				}
-			} else {
-				if field.Value != nil {
-					if len(field.Value) == 0 || field.Value[0] == "" {
-						_, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
-							SetValue(field.Value).
-							Save(l.ctx)
-						if err != nil {
-							continue
-						}
+			} else if len(f.Value) == 0 || f.Value[0] == "" {
+				if field.Value != nil && len(field.Value) > 0 && field.Value[0] != "" {
+					_, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
+						SetValue(field.Value).
+						Save(l.ctx)
+					if err != nil {
+						continue
 					}
 				}
 			}
@@ -461,7 +451,7 @@ func parseContent(content string) ([]ResponseItem, error) {
 		return parseContent(unq) // 尝试递归
 	}
 
-	// ② 数组形式
+	// ② 直接数组形式: [...]
 	if strings.HasPrefix(content, "[") {
 		var list []ResponseItem
 		if err := json.Unmarshal([]byte(content), &list); err == nil {
@@ -469,8 +459,17 @@ func parseContent(content string) ([]ResponseItem, error) {
 		}
 	}
 
-	// ③ 对象形式
+	// ③ 对象形式
 	if strings.HasPrefix(content, "{") {
+		// 3‑1 尝试对象包裹数组: {"values":[...]}
+		var wrapper struct {
+			Values []ResponseItem `json:"values"`
+		}
+		if err := json.Unmarshal([]byte(content), &wrapper); err == nil && len(wrapper.Values) > 0 {
+			return wrapper.Values, nil
+		}
+
+		// 3‑2 尝试单对象形式: {"dataIndex": ...}
 		var item ResponseItem
 		if err := json.Unmarshal([]byte(content), &item); err == nil {
 			return []ResponseItem{item}, nil

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

@@ -12,7 +12,7 @@ type FormClient struct {
 }
 
 // Generate the JSON schema at initialization time
-var FormResponseSchema = GenerateSchema[FormResponse]()
+var FormResponseSchema = GenerateSchema[FormList]()
 
 type FormResponse struct {
 	DataIndex string   `json:"dataIndex" jsonschema_description:"表单 id"`
@@ -58,7 +58,8 @@ func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
 * 如表单类型为 radio、select,返回示例:["值1"]
 * 如表单类型为 checkbox,返回示例:["值1", "值2"]
 * 如表单类型为 cascader,返回示例:["一级值1", "二级值3"]
-* 如表单类型为 date,返回示例:["2025-01-01"]`}
+* 如表单类型为 date,返回示例:["2025-01-01"]
+* 如没有找到某个表单相关的值,请不要返回该表单`}
 
 	newMessSlice[1] = types.StdCompMessage{Role: "user", Content: `# 表单数据
 ` + req.Variables["form_data"] + `