浏览代码

Merge remote-tracking branch 'origin/debug' into debug

Roc 1 年之前
父节点
当前提交
54949d8058

+ 2 - 2
controllers/data_manage/edb_classify.go

@@ -487,9 +487,9 @@ func (this *EdbClassifyController) EdbClassifyMove() {
 		return
 	}
 
-	if req.ClassifyId <= 0 {
+	if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
 		br.Msg = "参数错误"
-		br.ErrMsg = "分类id小于等于0"
+		br.ErrMsg = "请选择拖动目标,分类目录或者指标"
 		return
 	}
 

+ 177 - 2
controllers/data_manage/predict_edb_classify.go

@@ -8,6 +8,7 @@ import (
 	"eta/eta_api/models/system"
 	"eta/eta_api/services/data"
 	"eta/eta_api/utils"
+	"sort"
 )
 
 // PredictEdbClassifyController 数据管理-预测指标分类模块
@@ -387,9 +388,9 @@ func (this *PredictEdbClassifyController) Move() {
 		return
 	}
 
-	if req.ClassifyId <= 0 {
+	if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
 		br.Msg = "参数错误"
-		br.ErrMsg = "分类id小于等于0"
+		br.ErrMsg = "请选择拖动目标,分类目录或者指标"
 		return
 	}
 
@@ -653,3 +654,177 @@ func (this *PredictEdbClassifyController) ListV2() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// SimpleList
+// @Title 单层分类列表
+// @Description 单层分类列表
+// @Success 200 {object} data_manage.EdbClassifyListResp
+// @router /predict_classify/simple [get]
+func (this *PredictEdbClassifyController) SimpleList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	// 默认查一级分类和一级分类下的指标信息,
+	// 如果是 子级分类,查询该子级分类的下一级分类和指标信息
+	// 增加标识判断是文件夹还是指标列表
+	parentId, _ := this.GetInt("ParentId")
+	isOnlyMe, _ := this.GetBool("IsOnlyMe")
+	// 如果选择了只看我的,那么只查询归属于我的账号
+	sysUserId := 0
+	if isOnlyMe {
+		sysUserId = this.SysUser.AdminId
+	}
+
+	rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 1)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	nodeAll := make([]*data_manage.EdbClassifyItems, 0)
+
+	var sortList data_manage.EdbClassifyItemList
+	if parentId > 0 {
+		// 查询挂在当前分类上的指标列表
+		// 获取当前账号的不可见指标
+		obj := data_manage.EdbInfoNoPermissionAdmin{}
+		confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
+			return
+		}
+		noPermissionEdbInfoIdMap := make(map[int]bool)
+		for _, v := range confList {
+			noPermissionEdbInfoIdMap[v.EdbInfoId] = true
+		}
+		allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 1, sysUserId)
+		if err != nil {
+			br.Msg = "获取指标数据失败"
+			br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range allEdbInfo {
+			// 如果指标不可见,那么就不返回该指标
+			if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
+				continue
+			}
+			button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId)
+			button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
+			button.OpButton = false
+			button.DeleteButton = false
+			v.Button = button
+			v.Children = make([]*data_manage.EdbClassifyItems, 0)
+			v.ParentId = parentId
+			nodeAll = append(nodeAll, v)
+		}
+	}
+	if len(rootList) > 0 {
+		for _, v := range rootList {
+			button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
+			v.Button = button
+			v.Children = make([]*data_manage.EdbClassifyItems, 0)
+			nodeAll = append(nodeAll, v)
+		}
+	}
+	if len(nodeAll) > 0 {
+		//根据sort值排序
+		sortList = nodeAll
+		sort.Sort(sortList)
+	}
+
+	// 是否允许添加一级分类
+	canOpClassify := true
+	button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
+	if !button.AddButton {
+		canOpClassify = false
+	}
+
+	language := `CN`
+	// 指标显示的语言
+	{
+		configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
+		if configDetail != nil {
+			language = configDetail.ConfigValue
+		} else {
+			configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
+			if configDetail != nil {
+				language = configDetail.ConfigValue
+			}
+		}
+	}
+
+	resp := new(data_manage.EdbClassifyListResp)
+	resp.AllNodes = sortList
+	resp.Language = language
+	resp.CanOpClassify = canOpClassify
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// ClassifyTree
+// @Title 多层分类列表树
+// @Description 多层分类列表树
+// @Success 200 {object} data_manage.EdbClassifyListResp
+// @router /predict_classify/tree [get]
+func (this *PredictEdbClassifyController) ClassifyTree() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	allList, err := data_manage.GetPredictEdbClassifyAll()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	nodeAll := make([]*data_manage.EdbClassifyItems, 0)
+	var sortList data_manage.EdbClassifyItemList
+
+	if len(allList) > 0 {
+		for k, v := range allList {
+			button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
+			allList[k].Button = button
+		}
+		nodeAll = data.GetClassifyTreeRecursive(allList, 0)
+		//根据sort值排序
+		sortList = nodeAll
+		sort.Sort(sortList)
+	}
+	// 是否允许添加一级分类
+	canOpClassify := true
+	button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
+	if !button.AddButton {
+		canOpClassify = false
+	}
+
+	language := `CN`
+	// 指标显示的语言
+	{
+		configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
+		if configDetail != nil {
+			language = configDetail.ConfigValue
+		} else {
+			configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
+			if configDetail != nil {
+				language = configDetail.ConfigValue
+			}
+		}
+	}
+
+	resp := new(data_manage.EdbClassifyListResp)
+	resp.AllNodes = sortList
+	resp.Language = language
+	resp.CanOpClassify = canOpClassify
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 20 - 3
controllers/data_manage/predict_edb_info.go

@@ -970,6 +970,15 @@ func (this *PredictEdbInfoController) Detail() {
 			calculateList[k] = v
 		}
 	}
+	fullEdb := new(data_manage.EdbInfoFullClassify)
+	classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
+	if err != nil {
+		br.Msg = err.Error()
+		br.ErrMsg = errMsg
+		return
+	}
+	fullEdb.EdbInfo = edbInfo
+	fullEdb.ClassifyList = classifyList
 
 	// 拟合残差计算相关系数
 	var correlationStr string
@@ -1015,7 +1024,7 @@ func (this *PredictEdbInfoController) Detail() {
 	}
 
 	resp := response.PredictEdbInfo{
-		EdbInfo:        *edbInfo,
+		EdbInfo:        *fullEdb,
 		RuleType:       ruleType,
 		FixedValue:     fixedValue,
 		CalculateList:  calculateList,
@@ -1342,9 +1351,17 @@ func (this *PredictEdbInfoController) DataList() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-
+	fullEdb := new(data_manage.EdbInfoFullClassify)
+	classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
+	if err != nil {
+		br.Msg = err.Error()
+		br.ErrMsg = errMsg
+		return
+	}
+	fullEdb.EdbInfo = edbInfo
+	fullEdb.ClassifyList = classifyList
 	resp := response.PredictEdbInfoDataResp{
-		EdbInfo:  edbInfo,
+		EdbInfo:  fullEdb,
 		DataList: resultDataList,
 		Button:   button,
 	}

+ 2 - 2
models/data_manage/response/predit_edb_info.go

@@ -19,14 +19,14 @@ type PredictEdbInfoListResp struct {
 
 // PredictEdbInfoDataResp 预测指标数据返回
 type PredictEdbInfoDataResp struct {
-	EdbInfo  *data_manage.EdbInfo
+	EdbInfo  *data_manage.EdbInfoFullClassify
 	Button   data_manage.EdbClassifyItemsButton
 	DataList interface{}
 }
 
 // PredictEdbInfo 预测指标详情
 type PredictEdbInfo struct {
-	data_manage.EdbInfo
+	EdbInfo        data_manage.EdbInfoFullClassify
 	RuleType       int                                   `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值"`
 	FixedValue     float64                               `description:"固定值"`
 	CalculateList  []*data_manage.EdbInfoCalculateDetail `description:"关联指标"`

+ 18 - 0
routers/commentsRouter.go

@@ -3328,6 +3328,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:PredictEdbClassifyController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:PredictEdbClassifyController"],
+        beego.ControllerComments{
+            Method: "SimpleList",
+            Router: `/predict_classify/simple`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:PredictEdbClassifyController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:PredictEdbClassifyController"],
+        beego.ControllerComments{
+            Method: "ClassifyTree",
+            Router: `/predict_classify/tree`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:PredictEdbInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:PredictEdbInfoController"],
         beego.ControllerComments{
             Method: "Add",

+ 26 - 2
services/data/edb_classify.go

@@ -723,12 +723,12 @@ func MoveEdbClassify(req data_manage.MoveEdbClassifyReq, sysUser *system.Admin,
 		nextSort = nextEdbInfo.Sort
 	}
 
-	err, errMsg = moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, edbInfo, prevEdbInfo, parentClassifyId, prevSort, nextSort, classifyType)
+	err, errMsg = moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify, edbInfo, prevEdbInfo, nextEdbInfo, parentClassifyId, prevSort, nextSort, classifyType)
 	return
 }
 
 // moveEdbClassify 移动指标分类
-func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify *data_manage.EdbClassify, edbInfo, prevEdbInfo *data_manage.EdbInfo, parentClassifyId int, prevSort, nextSort int, classifyType uint8) (err error, errMsg string) {
+func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify *data_manage.EdbClassify, edbInfo, prevEdbInfo, nextEdbInfo *data_manage.EdbInfo, parentClassifyId int, prevSort, nextSort int, classifyType uint8) (err error, errMsg string) {
 	updateCol := make([]string, 0)
 	// 移动对象为分类, 判断分类是否存在
 	if edbClassifyInfo != nil {
@@ -778,6 +778,18 @@ func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify *data_
 			edbClassifyInfo.Sort = prevClassify.Sort + 1
 			edbClassifyInfo.ModifyTime = time.Now()
 			updateCol = append(updateCol, "Sort", "ModifyTime")
+		} else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
+			//处理只拖动到目录里,默认放到目录底部的情况
+			var maxSort int
+			maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
+			if err != nil {
+				errMsg = "移动失败"
+				err = errors.New("查询组内排序信息失败,Err:" + err.Error())
+				return
+			}
+			edbClassifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
+			edbClassifyInfo.ModifyTime = time.Now()
+			updateCol = append(updateCol, "Sort", "ModifyTime")
 		} else {
 			// 拖动到父级分类的第一位
 			firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
@@ -873,6 +885,18 @@ func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify *data_
 			edbInfo.Sort = prevEdbInfo.Sort + 1
 			edbInfo.ModifyTime = time.Now()
 			updateCol = append(updateCol, "Sort", "ModifyTime")
+		} else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
+			//处理只拖动到目录里,默认放到目录底部的情况
+			var maxSort int
+			maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
+			if err != nil {
+				errMsg = "移动失败"
+				err = errors.New("查询组内排序信息失败,Err:" + err.Error())
+				return
+			}
+			edbInfo.Sort = maxSort + 1 //那就是排在组内最后一位
+			edbInfo.ModifyTime = time.Now()
+			updateCol = append(updateCol, "Sort", "ModifyTime")
 		} else {
 			// 拖动到父级分类的第一位
 			firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)