|
@@ -57,6 +57,40 @@ func ChartClassifyItemsMakeTree(sysUser *system.Admin, allNode []*data_manage.Ch
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func ChartClassifyItemsMakeTreeV2(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ childs, _ := chartClassifyHaveChild(allNode, node)
|
|
|
+ if len(childs) > 0 {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ node.Children = append(node.Children, childs[0:]...)
|
|
|
+ for _, v := range childs {
|
|
|
+
|
|
|
+
|
|
|
+ _, has := chartClassifyHaveChild(allNode, v)
|
|
|
+ if has {
|
|
|
+ ChartClassifyItemsMakeTreeV2(allNode, v)
|
|
|
+ } else {
|
|
|
+ childrenArr := make([]*data_manage.ChartClassifyItems, 0)
|
|
|
+ v.Children = childrenArr
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ childrenArr := make([]*data_manage.ChartClassifyItems, 0)
|
|
|
+ node.Children = childrenArr
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func GetChartClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.ChartClassifyItemsButton) {
|
|
|
|
|
@@ -76,17 +110,22 @@ func GetChartClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOpera
|
|
|
}
|
|
|
|
|
|
|
|
|
-func GetChartOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.ChartClassifyItemsButton) {
|
|
|
+func GetChartOpButton(sysUser *system.Admin, belongUserId, chartInfoId int, haveOperaAuth bool, editShareChartMap map[int]bool) (button data_manage.ChartClassifyItemsButton) {
|
|
|
|
|
|
if !haveOperaAuth {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
|
|
|
- button.AddButton = true
|
|
|
+
|
|
|
+ if sysUser.AdminId == belongUserId {
|
|
|
+
|
|
|
button.OpButton = true
|
|
|
button.DeleteButton = true
|
|
|
button.MoveButton = true
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if _, ok := editShareChartMap[chartInfoId]; ok {
|
|
|
+ button.OpButton = true
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -175,26 +214,26 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
isSendEmail = true
|
|
|
errMsg = "保存分类失败"
|
|
|
|
|
|
-
|
|
|
- {
|
|
|
- var count int
|
|
|
- switch lang {
|
|
|
- case utils.EnLangVersion:
|
|
|
- count, err = data_manage.GetChartClassifyEnCount(chartClassifyName, parentId, source)
|
|
|
- default:
|
|
|
- count, err = data_manage.GetChartClassifyCount(chartClassifyName, parentId, source)
|
|
|
- }
|
|
|
- if err != nil {
|
|
|
- errMsg = "判断名称是否已存在失败"
|
|
|
- return
|
|
|
- }
|
|
|
- if count > 0 {
|
|
|
- errMsg = "分类名称已存在,请重新输入"
|
|
|
- err = errors.New(errMsg)
|
|
|
- isSendEmail = false
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if level > 6 {
|
|
|
errMsg = `最高只支持添加6级分类`
|
|
@@ -210,6 +249,7 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
}
|
|
|
|
|
|
rootId := 0
|
|
|
+ var classifyNamePath, classifyIdPath string
|
|
|
if parentId > 0 {
|
|
|
parentClassify, tErr := data_manage.GetChartClassifyById(parentId)
|
|
|
if tErr != nil {
|
|
@@ -223,6 +263,10 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
return
|
|
|
}
|
|
|
rootId = parentClassify.RootId
|
|
|
+ classifyNamePath = fmt.Sprint(parentClassify.ChartClassifyNamePath, "|", chartClassifyName)
|
|
|
+ classifyIdPath = fmt.Sprint(parentClassify.ChartClassifyIdPath, ",")
|
|
|
+ } else {
|
|
|
+ classifyNamePath = chartClassifyName
|
|
|
}
|
|
|
|
|
|
classifyInfo = new(data_manage.ChartClassify)
|
|
@@ -236,29 +280,35 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
classifyInfo.SysUserRealName = sysUser.RealName
|
|
|
classifyInfo.Level = level + 1
|
|
|
timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
- classifyInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
|
|
|
+ classifyInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
|
|
|
classifyInfo.Sort = maxSort + 1
|
|
|
classifyInfo.Source = source
|
|
|
classifyInfo.RootId = rootId
|
|
|
+ classifyInfo.ChartClassifyNamePath = classifyNamePath
|
|
|
|
|
|
- newId, err := data_manage.AddChartClassify(classifyInfo)
|
|
|
+ err = data_manage.AddChartClassify(classifyInfo)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ updateCols := []string{"ClassifyIdPath"}
|
|
|
+ classifyInfo.ChartClassifyIdPath = fmt.Sprint(classifyIdPath, classifyInfo.ChartClassifyId)
|
|
|
if parentId == 0 {
|
|
|
- classifyInfo.RootId = int(newId)
|
|
|
- err = classifyInfo.Update([]string{"RootId"})
|
|
|
- if err != nil {
|
|
|
- errMsg = "更新分类失败"
|
|
|
- return
|
|
|
- }
|
|
|
+ classifyInfo.RootId = classifyInfo.ChartClassifyId
|
|
|
+ updateCols = append(updateCols, "RootId")
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if classifyInfo.Source == utils.CHART_SOURCE_DEFAULT {
|
|
|
- go data_manage_permission.InheritParentClassify(5, classifyInfo.Source, classifyInfo.ChartClassifyId, classifyInfo.ParentId, classifyInfo.ChartClassifyName)
|
|
|
+ err = classifyInfo.Update(updateCols)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "更新分类失败"
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -295,6 +345,8 @@ func EditChartClassify(chartClassifyId, source int, chartClassifyName, lang stri
|
|
|
|
|
|
|
|
|
updateCols := make([]string, 0)
|
|
|
+
|
|
|
+ var oldClassifyNamePath, newClassifyNamePath string
|
|
|
|
|
|
|
|
|
switch lang {
|
|
@@ -319,27 +371,41 @@ func EditChartClassify(chartClassifyId, source int, chartClassifyName, lang stri
|
|
|
}
|
|
|
default:
|
|
|
if classifyInfo.ChartClassifyName != chartClassifyName {
|
|
|
- count, tmpErr := data_manage.GetChartClassifyCount(chartClassifyName, classifyInfo.ParentId, source)
|
|
|
- if tmpErr != nil {
|
|
|
- errMsg = "判断名称是否已存在失败"
|
|
|
- err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- if count > 0 {
|
|
|
- errMsg = "分类名称已存在,请重新输入"
|
|
|
- err = errors.New(errMsg)
|
|
|
- isSendEmail = false
|
|
|
- return
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ oldClassifyNamePath = classifyInfo.ChartClassifyNamePath
|
|
|
+
|
|
|
+ if classifyInfo.ParentId > 0 {
|
|
|
+ parentItem, tmpErr := data_manage.GetChartClassifyById(classifyInfo.ParentId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newClassifyNamePath = fmt.Sprint(parentItem.ChartClassifyNamePath, "|", chartClassifyName)
|
|
|
+ } else {
|
|
|
+ newClassifyNamePath = chartClassifyName
|
|
|
}
|
|
|
|
|
|
classifyInfo.ChartClassifyName = chartClassifyName
|
|
|
classifyInfo.ModifyTime = time.Now()
|
|
|
- updateCols = append(updateCols, "ChartClassifyName", "ModifyTime")
|
|
|
+ classifyInfo.ChartClassifyNamePath = newClassifyNamePath
|
|
|
+ updateCols = append(updateCols, "ChartClassifyName", "ModifyTime", "ChartClassifyNamePath")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(updateCols) > 0 {
|
|
|
- err = classifyInfo.Update(updateCols)
|
|
|
+ err = classifyInfo.UpdateClassifyNameAndNamePath(updateCols, oldClassifyNamePath, newClassifyNamePath)
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -465,8 +531,15 @@ func MoveChartClassify(req data_manage.MoveChartClassifyReq, sysUser *system.Adm
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ editShareChartInfoIdMap, tmpErr := GetAllEditSharedChartInfoIdMapByReceivedUserIdAndChartInfoIdList(sysUser.AdminId, []int{chartInfo.ChartInfoId})
|
|
|
+ if tmpErr != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取所有有编辑权限的分享图表失败,Err:" + tmpErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- button := GetChartOpButton(sysUser, chartInfo.SysUserId, haveOperaAuth)
|
|
|
+ button := GetChartOpButton(sysUser, chartInfo.SysUserId, chartInfo.ChartInfoId, haveOperaAuth, editShareChartInfoIdMap)
|
|
|
if !button.MoveButton {
|
|
|
errMsg = "无操作权限"
|
|
|
err = errors.New(errMsg)
|
|
@@ -512,12 +585,11 @@ func MoveChartClassify(req data_manage.MoveChartClassifyReq, sysUser *system.Adm
|
|
|
nextSort = nextChartInfo.Sort
|
|
|
}
|
|
|
|
|
|
- err, errMsg = moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify, chartInfo, prevChartInfo, nextChartInfo, parentClassifyId, prevSort, nextSort, source)
|
|
|
+ err, errMsg = moveChartOrClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify, chartInfo, prevChartInfo, nextChartInfo, parentClassifyId, prevSort, nextSort, source)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, chartInfo, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
|
|
|
+func moveChartOrClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, chartInfo, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
|
|
|
updateCol := make([]string, 0)
|
|
|
|
|
|
|
|
@@ -804,6 +876,472 @@ func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+func moveChart(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, chartInfo, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
|
|
|
+ updateCol := make([]string, 0)
|
|
|
+
|
|
|
+
|
|
|
+ if chartClassifyInfo != nil {
|
|
|
+ oldParentId := chartClassifyInfo.ParentId
|
|
|
+ oldLevel := chartClassifyInfo.Level
|
|
|
+ var classifyIds []int
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+
|
|
|
+ childList, e, m := GetChildChartClassifyByClassifyId(chartClassifyInfo.ChartClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询子分类失败,Err:" + e.Error() + m)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(childList) > 0 {
|
|
|
+ for _, v := range childList {
|
|
|
+ if v.ChartClassifyId == chartClassifyInfo.ChartClassifyId {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ classifyIds = append(classifyIds, v.ChartClassifyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
|
|
|
+ if chartClassifyInfo.Level != parentChartClassifyInfo.Level+1 {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("不支持目录层级变更")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
|
|
|
+ chartClassifyInfo.RootId = parentChartClassifyInfo.RootId
|
|
|
+ chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
|
|
|
+ } else if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("不支持目录层级变更")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if prevSort > 0 {
|
|
|
+
|
|
|
+ if nextSort > 0 {
|
|
|
+
|
|
|
+
|
|
|
+ if prevSort == nextSort || prevSort == chartClassifyInfo.Sort {
|
|
|
+
|
|
|
+ updateSortStr := `sort + 2`
|
|
|
+
|
|
|
+
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if prevChartInfo != nil {
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if nextSort-prevSort == 1 {
|
|
|
+
|
|
|
+ updateSortStr := `sort + 1`
|
|
|
+
|
|
|
+
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if prevChartInfo != nil {
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ chartClassifyInfo.Sort = prevSort + 1
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
|
|
|
+
|
|
|
+ var maxSort int
|
|
|
+ maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询组内排序信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartClassifyInfo.Sort = maxSort + 1
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else {
|
|
|
+
|
|
|
+ firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
|
|
|
+ if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
|
|
|
+ if tErr != nil && !utils.IsErrNoRow(tErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if firstEdb != nil && firstEdb.ChartClassifyId > 0 && firstEdb.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ chartClassifyInfo.Sort = 0
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if len(updateCol) > 0 {
|
|
|
+ err = chartClassifyInfo.Update(updateCol)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("修改失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+ if len(classifyIds) > 0 {
|
|
|
+ levelStep := chartClassifyInfo.Level - oldLevel
|
|
|
+ err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, chartClassifyInfo.RootId, levelStep)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("更新子分类失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if chartInfo == nil {
|
|
|
+ errMsg = "当前图表不存在"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if chartInfo.ChartClassifyId != parentClassifyId {
|
|
|
+ chartInfo.ChartClassifyId = parentClassifyId
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "ChartClassifyId", "ModifyTime")
|
|
|
+ }
|
|
|
+ if prevSort > 0 {
|
|
|
+
|
|
|
+ if nextSort > 0 {
|
|
|
+
|
|
|
+
|
|
|
+ if prevSort == nextSort || prevSort == chartInfo.Sort {
|
|
|
+
|
|
|
+ updateSortStr := `sort + 2`
|
|
|
+
|
|
|
+
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if prevChartInfo != nil {
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if nextSort-prevSort == 1 {
|
|
|
+
|
|
|
+ updateSortStr := `sort + 1`
|
|
|
+
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if prevChartInfo != nil {
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ chartInfo.Sort = prevSort + 1
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
|
|
|
+
|
|
|
+ var maxSort int
|
|
|
+ maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询组内排序信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartInfo.Sort = maxSort + 1
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else {
|
|
|
+
|
|
|
+ firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
|
|
|
+ if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
|
|
|
+ if tErr != nil && !utils.IsErrNoRow(tErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if firstEdb != nil && firstEdb.ChartClassifyId > 0 && firstEdb.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ chartInfo.Sort = 0
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if len(updateCol) > 0 {
|
|
|
+ err = chartInfo.Update(updateCol)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("修改失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
|
|
|
+ updateCol := make([]string, 0)
|
|
|
+
|
|
|
+ oldParentId := chartClassifyInfo.ParentId
|
|
|
+ oldLevel := chartClassifyInfo.Level
|
|
|
+ var classifyIds []int
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+
|
|
|
+ childList, e, m := GetChildChartClassifyByClassifyId(chartClassifyInfo.ChartClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询子分类失败,Err:" + e.Error() + m)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(childList) > 0 {
|
|
|
+ for _, v := range childList {
|
|
|
+ if v.ChartClassifyId == chartClassifyInfo.ChartClassifyId {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ classifyIds = append(classifyIds, v.ChartClassifyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
|
|
|
+ if chartClassifyInfo.Level != parentChartClassifyInfo.Level+1 {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("不支持目录层级变更")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
|
|
|
+ chartClassifyInfo.RootId = parentChartClassifyInfo.RootId
|
|
|
+ chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
|
|
|
+ } else if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("不支持目录层级变更")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if prevSort > 0 {
|
|
|
+
|
|
|
+ if nextSort > 0 {
|
|
|
+
|
|
|
+
|
|
|
+ if prevSort == nextSort || prevSort == chartClassifyInfo.Sort {
|
|
|
+
|
|
|
+ updateSortStr := `sort + 2`
|
|
|
+
|
|
|
+
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if prevChartInfo != nil {
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if nextSort-prevSort == 1 {
|
|
|
+
|
|
|
+ updateSortStr := `sort + 1`
|
|
|
+
|
|
|
+
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if prevChartInfo != nil {
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ chartClassifyInfo.Sort = prevSort + 1
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
|
|
|
+
|
|
|
+ var maxSort int
|
|
|
+ maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询组内排序信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartClassifyInfo.Sort = maxSort + 1
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else {
|
|
|
+
|
|
|
+ firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
|
|
|
+ if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
|
|
|
+
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
|
|
|
+ if tErr != nil && !utils.IsErrNoRow(tErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if firstEdb != nil && firstEdb.ChartClassifyId > 0 && firstEdb.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ chartClassifyInfo.Sort = 0
|
|
|
+ chartClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ }
|
|
|
+
|
|
|
+ oldClassifyIdPath := chartClassifyInfo.ChartClassifyIdPath
|
|
|
+ oldClassifyNamePath := chartClassifyInfo.ChartClassifyNamePath
|
|
|
+ newClassifyNamePath := fmt.Sprint(chartClassifyInfo.ChartClassifyNamePath, `|`, chartClassifyInfo.ChartClassifyName)
|
|
|
+ newClassifyIdPath := fmt.Sprint(chartClassifyInfo.ChartClassifyIdPath, `,`, chartClassifyInfo.ChartClassifyId)
|
|
|
+
|
|
|
+
|
|
|
+ if len(updateCol) > 0 {
|
|
|
+ err = chartClassifyInfo.Update(updateCol)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("修改失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+ if len(classifyIds) > 0 {
|
|
|
+ levelStep := chartClassifyInfo.Level - oldLevel
|
|
|
+ err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, chartClassifyInfo.RootId, levelStep)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("更新子分类失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tmpErr := data_manage.UpdateChartClassifyNameAndNamePathByOldClassifyIdPath(oldClassifyIdPath, newClassifyIdPath, oldClassifyNamePath, newClassifyNamePath)
|
|
|
+ if tmpErr != nil {
|
|
|
+ utils.FileLog.Error(fmt.Sprintf("更新图表分类全路径失败,分类id:%d;失败原因Err:%s", chartClassifyInfo.ChartClassifyId, tmpErr.Error()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
|
|
|
func GetChildChartClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.ChartClassifyIdItems, err error, errMsg string) {
|
|
|
|
|
@@ -884,6 +1422,49 @@ func GetChartClassifyTreeRecursive(list []*data_manage.ChartClassifyItems, paren
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func GetChartClassifyTreeRecursiveAndInsert(list []*data_manage.ChartClassifyItems, parentId int, chartClassifyItemListMap map[int][]*data_manage.ChartClassifyItems) []*data_manage.ChartClassifyItems {
|
|
|
+
|
|
|
+ list = GetChartClassifyTreeRecursive(list, parentId)
|
|
|
+
|
|
|
+
|
|
|
+ InsertChartClassifyItemsToClassifyTree(list, chartClassifyItemListMap)
|
|
|
+
|
|
|
+ return list
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func InsertChartClassifyItemsToClassifyTree(list []*data_manage.ChartClassifyItems, chartClassifyItemListMap map[int][]*data_manage.ChartClassifyItems) []*data_manage.ChartClassifyItems {
|
|
|
+ for k, v := range list {
|
|
|
+ children := v.Children
|
|
|
+ if children != nil {
|
|
|
+ children = InsertChartClassifyItemsToClassifyTree(children, chartClassifyItemListMap)
|
|
|
+ } else {
|
|
|
+ children = make([]*data_manage.ChartClassifyItems, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ if chartClassifyItemList, ok := chartClassifyItemListMap[v.ChartClassifyId]; ok {
|
|
|
+ children = append(children, chartClassifyItemList...)
|
|
|
+ }
|
|
|
+ list[k].Children = children
|
|
|
+ }
|
|
|
+
|
|
|
+ return list
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func GetChartClassifyParentRecursive(list []*data_manage.ChartClassifyItems, classifyId int) []*data_manage.ChartClassifyItems {
|
|
|
res := make([]*data_manage.ChartClassifyItems, 0)
|
|
@@ -906,3 +1487,31 @@ func GetChartClassifyChildIds(classifyId int, classifymap map[int]*data_manage.C
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func GetAllChartChildClassifyByParentId(parentId int) (targetList []*data_manage.ChartClassifyItems, err error, errMsg string) {
|
|
|
+
|
|
|
+ parentClassify, err := data_manage.GetChartClassifyById(parentId)
|
|
|
+ if err != nil {
|
|
|
+ if utils.IsErrNoRow(err) {
|
|
|
+ errMsg = "当前分类不存在"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ errMsg = "获取失败"
|
|
|
+ err = errors.New("获取分类信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ orderStr := ` order by level asc, sort asc, chart_classify_id asc`
|
|
|
+
|
|
|
+ targetList, err = data_manage.GetChildChartClassifyListByParentId(fmt.Sprint(parentClassify.ChartClassifyIdPath, ",%"), orderStr)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|