CareAlterLogTest.go 2.3 KB
Newer Older
Ford committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
package main

import (
	"fmt"
)

// 假设GetTodayCareAlertLogs已经定义并实现,返回([]CareAlertLog, error)
type CareAlertLogs struct {
	ID              int      `xorm:"'id' pk autoincr" json:"id"`
	UserID          int64    `xorm:"user_id" json:"userId"`
	ClassNo         string   `xorm:"class_no" json:"classNo"`
	AppID           int64    `xorm:"app_id" json:"appId"`
	OverIndexes     []string `xorm:"'over_indexes' json " json:"over_indexes"`
	MeasurementTime int64    `xorm:"measurement_time" json:"measurementTime"`
}

// 模拟函数返回结果
func GetTodayCareAlertLogs() ([]CareAlertLogs, error) {
	return []CareAlertLogs{
		{ID: 22, UserID: 1, ClassNo: "oilstc", AppID: 6, OverIndexes: []string{"冲动倾向", "孤独倾向", "学习焦虑", "对人焦虑", "恐怖倾向", "自责倾向", "身体症状", "过敏倾向"}, MeasurementTime: 1716969608},
		{ID: 23, UserID: 411, ClassNo: "oilstc", AppID: 6, OverIndexes: []string{"身体症状", "过敏倾向", "冲动倾向", "孤独倾向", "学习焦虑", "对人焦虑", "恐怖倾向", "自责倾向"}, MeasurementTime: 1716969663},
		{ID: 24, UserID: 410, ClassNo: "oilstc", AppID: 6, OverIndexes: []string{"孤独倾向", "学习焦虑", "对人焦虑", "恐怖倾向", "自责倾向", "身体症状", "过敏倾向", "冲动倾向"}, MeasurementTime: 1716969792},
		{ID: 39, UserID: 12, ClassNo: "", AppID: 6, OverIndexes: []string{"身体症状", "冲动倾向", "对人焦虑"}, MeasurementTime: 1716973512},
	}, nil
}

// 处理查询结果的函数
func ProcessCareAlertLogs() ([]int64, []string, error) {
	logs, err := GetTodayCareAlertLogs()
	if err != nil {
		return nil, nil, fmt.Errorf("failed to get care alert logs: %w", err)
	}

	userIDs := make([]int64, 0)
	classSet := make(map[string]struct{}) // 使用map来去重
	classNos := make([]string, 0)

	for _, log := range logs {
		userIDs = append(userIDs, log.UserID)
		if log.ClassNo != "" {
			if _, exists := classSet[log.ClassNo]; !exists {
				classSet[log.ClassNo] = struct{}{}
				classNos = append(classNos, log.ClassNo)
			}
		}
	}

	return userIDs, classNos, nil
}

func main() {
	userIDs, classNos, err := ProcessCareAlertLogs()
	if err != nil {
		fmt.Printf("Error processing care alert logs: %s\n", err)
		return
	}

	fmt.Printf("User IDs: %v\n", userIDs)
	fmt.Printf("Class Nos: %v\n", classNos)
}