Roc 6 dagen geleden
bovenliggende
commit
a59212dfbb
2 gewijzigde bestanden met toevoegingen van 270 en 0 verwijderingen
  1. 155 0
      models/data_manage/index_task.go
  2. 115 0
      models/data_manage/index_task_record.go

+ 155 - 0
models/data_manage/index_task.go

@@ -0,0 +1,155 @@
+package data_manage
+
+import (
+	"database/sql"
+	"eta/eta_api/global"
+	"eta/eta_api/utils"
+	"fmt"
+	"time"
+)
+
+// IndexTask index这边的任务表
+type IndexTask struct {
+	IndexTaskID     int       `gorm:"primaryKey;column:index_task_id" description:"-"`
+	TaskName        string    `gorm:"column:task_name" description:"任务名称"`
+	TaskType        string    `gorm:"column:task_type" description:"任务类型"`
+	Status          string    `gorm:"column:status" description:"任务状态"`
+	StartTime       time.Time `gorm:"column:start_time" description:"开始时间"`
+	EndTime         time.Time `gorm:"column:end_time" description:"结束时间"`
+	CreateTime      time.Time `gorm:"column:create_time" description:"创建时间"`
+	UpdateTime      time.Time `gorm:"column:update_time" description:"更新时间"`
+	Logs            string    `gorm:"column:logs" description:"日志"`
+	Errormessage    string    `gorm:"column:ErrorMessage" description:"错误信息"`
+	Priority        int       `gorm:"column:priority" description:"优先级"`
+	RetryCount      int       `gorm:"column:retry_count" description:"重试次数"`
+	Remark          string    `gorm:"column:remark" description:"备注"`
+	SysUserID       int       `gorm:"column:sys_user_id" description:"任务创建人id"`
+	SysUserRealName string    `gorm:"column:sys_user_real_name" description:"任务创建人名称"`
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *IndexTask) TableName() string {
+	return "index_task"
+}
+
+// IndexTaskColumns get sql column name.获取数据库列名
+var IndexTaskColumns = struct {
+	IndexTaskID     string
+	TaskName        string
+	TaskType        string
+	Status          string
+	StartTime       string
+	EndTime         string
+	CreateTime      string
+	UpdateTime      string
+	Logs            string
+	Errormessage    string
+	Priority        string
+	RetryCount      string
+	Remark          string
+	SysUserID       string
+	SysUserRealName string
+}{
+	IndexTaskID:     "index_task_id",
+	TaskName:        "task_name",
+	TaskType:        "task_type",
+	Status:          "status",
+	StartTime:       "start_time",
+	EndTime:         "end_time",
+	CreateTime:      "create_time",
+	UpdateTime:      "update_time",
+	Logs:            "logs",
+	Errormessage:    "ErrorMessage",
+	Priority:        "priority",
+	RetryCount:      "retry_count",
+	Remark:          "remark",
+	SysUserID:       "sys_user_id",
+	SysUserRealName: "sys_user_real_name",
+}
+
+func (m *IndexTask) Create() (err error) {
+	err = global.DbMap[utils.DbNameAI].Create(&m).Error
+
+	return
+}
+
+func (m *IndexTask) Update(updateCols []string) (err error) {
+	err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error
+
+	return
+}
+
+func (m *IndexTask) Del() (err error) {
+	err = global.DbMap[utils.DbNameAI].Delete(&m).Error
+
+	return
+}
+
+func (m *IndexTask) GetByID(id int) (item *IndexTask, err error) {
+	err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", IndexTaskColumns.IndexTaskID), id).First(&item).Error
+
+	return
+}
+
+func (m *IndexTask) GetByCondition(condition string, pars []interface{}) (item *IndexTask, err error) {
+	sqlStr := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).First(&item).Error
+
+	return
+}
+
+func (m *IndexTask) GetListByCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*IndexTask, err error) {
+	if field == "" {
+		field = "*"
+	}
+	sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s order by index_task_id desc LIMIT ?,?`, field, m.TableName(), condition)
+	pars = append(pars, startSize, pageSize)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
+
+	return
+}
+
+func (m *IndexTask) GetCountByCondition(condition string, pars []interface{}) (total int, err error) {
+	var intNull sql.NullInt64
+	sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
+	if err == nil && intNull.Valid {
+		total = int(intNull.Int64)
+	}
+
+	return
+}
+
+// AddIndexTask
+// @Description: 添加Index模块的任务
+// @author: Roc
+// @datetime 2025-04-16 16:55:36
+// @param indexTask *IndexTask
+// @param indexRecordList []*IndexTaskRecord
+// @return err error
+func AddIndexTask(indexTask *IndexTask, indexRecordList []*IndexTaskRecord) (err error) {
+	to := global.DbMap[utils.DbNameAI].Begin()
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	err = to.Create(indexTask).Error
+	if err != nil {
+		return
+	}
+
+	for _, indexTaskRecord := range indexRecordList {
+		indexTaskRecord.IndexTaskID = indexTask.IndexTaskID
+	}
+
+	err = to.CreateInBatches(indexRecordList, utils.MultiAddNum).Error
+	if err != nil {
+		return
+	}
+
+	return
+}

+ 115 - 0
models/data_manage/index_task_record.go

@@ -0,0 +1,115 @@
+package data_manage
+
+import (
+	"database/sql"
+	"eta/eta_api/global"
+	"eta/eta_api/utils"
+	"fmt"
+	"time"
+)
+
+// IndexTaskRecord AI任务的子记录
+type IndexTaskRecord struct {
+	IndexTaskRecordID int       `gorm:"primaryKey;column:index_task_record_id" json:"-"` // 任务记录id
+	IndexTaskID       int       `gorm:"column:index_task_id" json:"indexTaskId"`         // 任务id
+	Parameters        string    `gorm:"column:parameters" json:"parameters"`             // 子任务参数
+	Status            string    `gorm:"column:status" json:"status"`                     // 状态
+	Remark            string    `gorm:"column:remark" json:"remark"`                     // 备注
+	ModifyTime        time.Time `gorm:"column:modify_time" json:"modifyTime"`            // 最后一次修改时间
+	CreateTime        time.Time `gorm:"column:create_time" json:"createTime"`            // 任务创建时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *IndexTaskRecord) TableName() string {
+	return "index_task_record"
+}
+
+// IndexTaskRecordColumns get sql column name.获取数据库列名
+var IndexTaskRecordColumns = struct {
+	IndexTaskRecordID string
+	IndexTaskID       string
+	Parameters        string
+	Status            string
+	Remark            string
+	ModifyTime        string
+	CreateTime        string
+}{
+	IndexTaskRecordID: "index_task_record_id",
+	IndexTaskID:       "index_task_id",
+	Parameters:        "parameters",
+	Status:            "status",
+	Remark:            "remark",
+	ModifyTime:        "modify_time",
+	CreateTime:        "create_time",
+}
+
+func (m *IndexTaskRecord) Create() (err error) {
+	err = global.DbMap[utils.DbNameAI].Create(&m).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) Update(updateCols []string) (err error) {
+	err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) Del() (err error) {
+	err = global.DbMap[utils.DbNameAI].Delete(&m).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) GetByID(id int) (item *IndexTaskRecord, err error) {
+	err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", IndexTaskRecordColumns.IndexTaskRecordID), id).First(&item).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) GetByCondition(condition string, pars []interface{}) (item *IndexTaskRecord, err error) {
+	sqlStr := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).First(&item).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) GetAllListByCondition(field, condition string, pars []interface{}) (items []*IndexTaskRecord, err error) {
+	if field == "" {
+		field = "*"
+	}
+	sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s order by index_task_record_id desc `, field, m.TableName(), condition)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) GetListByCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*IndexTaskRecord, err error) {
+	if field == "" {
+		field = "*"
+	}
+	sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s order by index_task_record_id desc LIMIT ?,?`, field, m.TableName(), condition)
+	pars = append(pars, startSize, pageSize)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
+
+	return
+}
+
+func (m *IndexTaskRecord) GetCountByCondition(condition string, pars []interface{}) (total int, err error) {
+	var intNull sql.NullInt64
+	sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
+	if err == nil && intNull.Valid {
+		total = int(intNull.Int64)
+	}
+
+	return
+}
+
+// QuestionGenerateAbstractParam
+// @Description:
+type QuestionGenerateAbstractParam struct {
+	QuestionId  int    `json:"questionId"`
+	ArticleType string `json:"articleType"`
+	ArticleId   int    `json:"articleId"`
+}