|
@@ -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
|
|
|
|
+}
|