ai_predict_model_classify.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "eta/eta_forum_admin/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // AI预测模型分类项
  7. type AiPredictModelClassifyItems struct {
  8. AiPredictModelClassifyId int `json:"ai_predict_model_classify_id" orm:"column(ai_predict_model_classify_id)"`
  9. ClassifyName string `json:"classify_name"` // 分类名称
  10. ParentId int `json:"parent_id"` // 父级ID
  11. LevelPath string `json:"level_path"` // 层级路径
  12. Sort int `json:"sort"` // 排序
  13. }
  14. // AI预测模型分类列表
  15. type AiPredictModelClassifyItemList []*AiPredictModelClassifyItems
  16. // 实现sort.Interface接口
  17. func (s AiPredictModelClassifyItemList) Len() int { return len(s) }
  18. func (s AiPredictModelClassifyItemList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  19. func (s AiPredictModelClassifyItemList) Less(i, j int) bool { return s[i].Sort < s[j].Sort }
  20. // 商家AI预测模型分类响应
  21. type BusinessAiPredictModelClassifyResp struct {
  22. List []*AiPredictModelClassifyItems `json:"list"` // 分类列表
  23. CheckList []int `json:"check_list"` // 已选中的分类ID列表
  24. }
  25. // 根据关键字获取AI预测模型分类列表
  26. func GetAiPredictModelClassifyListByKeyword(keyword string) (list []*AiPredictModelClassifyItems, err error) {
  27. o := orm.NewOrmUsingDB("data")
  28. sql := `SELECT * FROM ai_predict_model_classify WHERE classify_name LIKE ?`
  29. _, err = o.Raw(sql, "%"+keyword+"%").QueryRows(&list)
  30. return
  31. }
  32. // 根据ID列表获取AI预测模型分类列表
  33. func GetAiPredictModelClassifyItemsByIdList(ids []int) (list []*AiPredictModelClassifyItems, err error) {
  34. if len(ids) == 0 {
  35. return
  36. }
  37. o := orm.NewOrmUsingDB("data")
  38. sql := `SELECT * FROM ai_predict_model_classify WHERE ai_predict_model_classify_id IN (`+utils.GetOrmInReplace(len(ids))+`)`
  39. _, err = o.Raw(sql, ids).QueryRows(&list)
  40. return
  41. }
  42. // 获取所有AI预测模型分类
  43. func GetAiPredictModelClassify() (list []*AiPredictModelClassifyItems, err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. sql := `SELECT * FROM ai_predict_model_classify ORDER BY sort ASC, ai_predict_model_classify_id ASC`
  46. _, err = o.Raw(sql).QueryRows(&list)
  47. return
  48. }