Преглед на файлове

Merge branch 'hotfix/bug8241_ai_move' of eta_server/eta_api into master

xyxie преди 5 дни
родител
ревизия
4fa83d1edf
променени са 3 файла, в които са добавени 34 реда и са изтрити 6 реда
  1. 20 0
      models/ai_predict_model/ai_predict_model_index.go
  2. 5 5
      services/ai_predict_model_classify.go
  3. 9 1
      services/ai_predict_model_index.go

+ 20 - 0
models/ai_predict_model/ai_predict_model_index.go

@@ -444,3 +444,23 @@ type AiPredictModelIndexExtraConfig struct {
 		PredictLegendName string `description:"预测图例的名称(通常为Predicted)"`
 	}
 }
+
+func (m *AiPredictModelIndex) GetSortMax() (sort int, err error) {
+	o := global.DbMap[utils.DbNameIndex]
+	sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM ai_predict_model_index`
+	err = o.Raw(sql).Scan(&sort).Error
+	if err != nil {
+		return
+	}
+	// 查询分类的最大排序
+	sql = `SELECT COALESCE(MAX(sort), 0) AS sort FROM ai_predict_model_classify`
+	var classifySort int
+	err = o.Raw(sql).Scan(&classifySort).Error
+	if err != nil {
+		return
+	}
+	if classifySort > sort {
+		sort = classifySort
+	}
+	return
+}

+ 5 - 5
services/ai_predict_model_classify.go

@@ -156,7 +156,7 @@ func moveAiPredictModelClassify(parentClassify, edbClassifyInfo, prevClassify, n
 	updateCol := make([]string, 0)
 
 	// 移动对象为分类, 判断分类是否存在
-	if edbClassifyInfo != nil {
+	if edbClassifyInfo != nil && edbClassifyInfo.AiPredictModelClassifyId > 0 {
 		oldParentId := edbClassifyInfo.ParentId
 		oldLevel := edbClassifyInfo.Level
 		var classifyIds []int
@@ -271,7 +271,7 @@ func moveAiPredictModelClassify(parentClassify, edbClassifyInfo, prevClassify, n
 			}
 
 			//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
-			if firstClassify != nil && firstClassify.Sort == 0 {
+			if firstClassify != nil && firstClassify.AiPredictModelClassifyId > 0 && firstClassify.Sort == 0 {
 				updateSortStr := ` sort + 1 `
 				_ = aiPredictModel.UpdateAiPredictModelClassifySortByParentId(parentClassifyId, firstClassify.AiPredictModelClassifyId-1, 0, updateSortStr)
 				//该分类下的所有指标也需要+1
@@ -286,7 +286,7 @@ func moveAiPredictModelClassify(parentClassify, edbClassifyInfo, prevClassify, n
 				}
 
 				//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
-				if firstEdb != nil && firstEdb.Sort == 0 {
+				if firstEdb != nil && firstEdb.AiPredictModelIndexId > 0 && firstEdb.Sort == 0 {
 					updateSortStr := ` sort + 1 `
 					_ = aiPredictModel.UpdateAiPredictModelIndexSortByClassifyId(parentClassifyId, 0, firstEdb.AiPredictModelIndexId-1, updateSortStr)
 					_ = aiPredictModel.UpdateAiPredictModelClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr)
@@ -403,7 +403,7 @@ func moveAiPredictModelClassify(parentClassify, edbClassifyInfo, prevClassify, n
 			}
 
 			//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
-			if firstClassify != nil && firstClassify.Sort == 0 {
+			if firstClassify != nil && firstClassify.AiPredictModelClassifyId> 0 && firstClassify.Sort == 0 {
 				updateSortStr := ` sort + 1 `
 				_ = aiPredictModel.UpdateAiPredictModelClassifySortByParentId(parentClassifyId, firstClassify.AiPredictModelClassifyId-1, 0, updateSortStr)
 				//该分类下的所有指标也需要+1
@@ -418,7 +418,7 @@ func moveAiPredictModelClassify(parentClassify, edbClassifyInfo, prevClassify, n
 				}
 
 				//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
-				if firstEdb != nil && firstEdb.Sort == 0 {
+				if firstEdb != nil && firstEdb.AiPredictModelIndexId > 0 && firstEdb.Sort == 0 {
 					updateSortStr := ` sort + 1 `
 					_ = aiPredictModel.UpdateAiPredictModelIndexSortByClassifyId(parentClassifyId, 0, firstEdb.AiPredictModelIndexId-1, updateSortStr)
 					_ = aiPredictModel.UpdateAiPredictModelClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr)

+ 9 - 1
services/ai_predict_model_index.go

@@ -34,6 +34,12 @@ func ImportAiPredictModelIndexAndData(imports []*aiPredictModel.AiPredictModelIm
 	updateCols := []string{indexOb.Cols().ClassifyId, indexOb.Cols().ModelFramework, indexOb.Cols().PredictDate, indexOb.Cols().PredictValue, indexOb.Cols().DirectionAccuracy, indexOb.Cols().AbsoluteDeviation, indexOb.Cols().ExtraConfig, indexOb.Cols().SysUserId, indexOb.Cols().SysUserRealName, indexOb.Cols().ModifyTime}
 	updateIndexes := make([]*aiPredictModel.AiPredictModelImportData, 0)
 	createIndexes := make([]*aiPredictModel.AiPredictModelImportData, 0)
+
+	maxSort, err := indexOb.GetSortMax()
+	if err != nil {
+		err = fmt.Errorf("获取标的最大排序失败, %v", err)
+		return
+	}
 	for _, v := range imports {
 		exist := indexNameItem[v.Index.IndexName]
 		// 编辑
@@ -53,7 +59,7 @@ func ImportAiPredictModelIndexAndData(imports []*aiPredictModel.AiPredictModelIm
 				b, _ := json.Marshal(oldConfig)
 				v.Index.ExtraConfig = string(b)
 			}
-
+			
 			v.Index.AiPredictModelIndexId = exist.AiPredictModelIndexId
 			v.Index.IndexCode = exist.IndexCode
 			updateIndexes = append(updateIndexes, v)
@@ -68,6 +74,8 @@ func ImportAiPredictModelIndexAndData(imports []*aiPredictModel.AiPredictModelIm
 		}
 		v.Index.IndexCode = indexCode
 		v.Charts = GetAiPredictCharts(v.Index.IndexName, adminId, adminRealName)
+		maxSort = maxSort + 1
+		v.Index.Sort = maxSort
 		createIndexes = append(createIndexes, v)
 	}