index_task_record.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package models
  2. import (
  3. "database/sql"
  4. "eta/eta_index_lib/global"
  5. "fmt"
  6. "time"
  7. )
  8. // IndexTaskRecord AI任务的子记录
  9. type IndexTaskRecord struct {
  10. IndexTaskRecordID int `gorm:"primaryKey;column:index_task_record_id" description:"任务记录id"`
  11. IndexTaskID int `gorm:"column:index_task_id" description:"任务id"`
  12. Parameters string `gorm:"column:parameters" description:"子任务参数"`
  13. Status string `gorm:"column:status" description:"状态,枚举值:待处理,处理成功,处理失败,暂停处理"`
  14. Remark string `gorm:"column:remark" description:"备注"`
  15. ModifyTime time.Time `gorm:"column:modify_time" description:"最后一次修改时间"`
  16. CreateTime time.Time `gorm:"column:create_time" description:"任务创建时间"`
  17. }
  18. // TableName get sql table name.获取数据库表名
  19. func (m *IndexTaskRecord) TableName() string {
  20. return "index_task_record"
  21. }
  22. // IndexTaskRecordColumns get sql column name.获取数据库列名
  23. var IndexTaskRecordColumns = struct {
  24. IndexTaskRecordID string
  25. IndexTaskID string
  26. Parameters string
  27. Status string
  28. Remark string
  29. ModifyTime string
  30. CreateTime string
  31. }{
  32. IndexTaskRecordID: "index_task_record_id",
  33. IndexTaskID: "index_task_id",
  34. Parameters: "parameters",
  35. Status: "status",
  36. Remark: "remark",
  37. ModifyTime: "modify_time",
  38. CreateTime: "create_time",
  39. }
  40. func (m *IndexTaskRecord) Create() (err error) {
  41. err = global.DEFAULT_DB.Create(&m).Error
  42. return
  43. }
  44. func (m *IndexTaskRecord) Update(updateCols []string) (err error) {
  45. err = global.DEFAULT_DB.Select(updateCols).Updates(&m).Error
  46. return
  47. }
  48. func (m *IndexTaskRecord) Del() (err error) {
  49. err = global.DEFAULT_DB.Delete(&m).Error
  50. return
  51. }
  52. func (m *IndexTaskRecord) GetByID(id int) (item *IndexTaskRecord, err error) {
  53. err = global.DEFAULT_DB.Where(fmt.Sprintf("%s = ?", IndexTaskRecordColumns.IndexTaskRecordID), id).First(&item).Error
  54. return
  55. }
  56. func (m *IndexTaskRecord) GetByCondition(condition string, pars []interface{}) (item *IndexTaskRecord, err error) {
  57. sqlStr := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  58. err = global.DEFAULT_DB.Raw(sqlStr, pars...).First(&item).Error
  59. return
  60. }
  61. func (m *IndexTaskRecord) GetAllListByCondition(field, condition string, pars []interface{}) (items []*IndexTaskRecord, err error) {
  62. if field == "" {
  63. field = "*"
  64. }
  65. sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s order by index_task_record_id desc `, field, m.TableName(), condition)
  66. err = global.DEFAULT_DB.Raw(sqlStr, pars...).Find(&items).Error
  67. return
  68. }
  69. func (m *IndexTaskRecord) GetListByCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*IndexTaskRecord, err error) {
  70. if field == "" {
  71. field = "*"
  72. }
  73. sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s order by index_task_record_id desc LIMIT ?,?`, field, m.TableName(), condition)
  74. pars = append(pars, startSize, pageSize)
  75. err = global.DEFAULT_DB.Raw(sqlStr, pars...).Find(&items).Error
  76. return
  77. }
  78. func (m *IndexTaskRecord) GetCountByCondition(condition string, pars []interface{}) (total int, err error) {
  79. var intNull sql.NullInt64
  80. sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  81. err = global.DEFAULT_DB.Raw(sqlStr, pars...).Scan(&intNull).Error
  82. if err == nil && intNull.Valid {
  83. total = int(intNull.Int64)
  84. }
  85. return
  86. }
  87. // QuestionGenerateAbstractParam
  88. // @Description:
  89. type QuestionGenerateAbstractParam struct {
  90. QuestionId int `json:"questionId"`
  91. ArticleType string `json:"articleType"`
  92. ArticleId int `json:"articleId"`
  93. }