|
@@ -288,6 +288,7 @@ func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8
|
|
|
}
|
|
|
//查询顶级rootId
|
|
|
rootId := 0
|
|
|
+ var classifyNamePath, classifyIdPath string
|
|
|
if parentId > 0 {
|
|
|
parentClassify, tErr := data_manage.GetEdbClassifyById(parentId)
|
|
|
if tErr != nil {
|
|
@@ -301,30 +302,39 @@ func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8
|
|
|
return
|
|
|
}
|
|
|
rootId = parentClassify.RootId
|
|
|
+
|
|
|
+ classifyNamePath = fmt.Sprint(parentClassify.ClassifyNamePath, "|", classifyName)
|
|
|
+ classifyIdPath = fmt.Sprint(parentClassify.ClassifyIdPath, ",")
|
|
|
+ } else {
|
|
|
+ classifyNamePath = classifyName
|
|
|
}
|
|
|
|
|
|
timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
classifyInfo = &data_manage.EdbClassify{
|
|
|
//ClassifyId: 0,
|
|
|
- ClassifyType: classifyType,
|
|
|
- ClassifyName: classifyName,
|
|
|
- ClassifyNameEn: classifyName,
|
|
|
- ParentId: parentId,
|
|
|
- RootId: rootId,
|
|
|
- HasData: 0,
|
|
|
- CreateTime: time.Now(),
|
|
|
- ModifyTime: time.Now(),
|
|
|
- SysUserId: sysUserId,
|
|
|
- SysUserRealName: sysUserName,
|
|
|
- Level: level + 1,
|
|
|
- UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
|
|
|
- Sort: maxSort + 1,
|
|
|
+ ClassifyType: classifyType,
|
|
|
+ ClassifyName: classifyName,
|
|
|
+ ClassifyNameEn: classifyName,
|
|
|
+ ParentId: parentId,
|
|
|
+ RootId: rootId,
|
|
|
+ HasData: 0,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ SysUserId: sysUserId,
|
|
|
+ SysUserRealName: sysUserName,
|
|
|
+ Level: level + 1,
|
|
|
+ UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
|
|
|
+ Sort: maxSort + 1,
|
|
|
+ ClassifyNamePath: classifyNamePath,
|
|
|
}
|
|
|
- newId, err := data_manage.AddEdbClassify(classifyInfo)
|
|
|
+ err = data_manage.AddEdbClassify(classifyInfo)
|
|
|
if err != nil {
|
|
|
errMsg = "保存分类失败"
|
|
|
return
|
|
|
}
|
|
|
+ // 更改分类id完整路径path
|
|
|
+ classifyInfo.ClassifyIdPath = fmt.Sprint(classifyIdPath, classifyInfo.ClassifyId)
|
|
|
+ _ = classifyInfo.Update([]string{"ClassifyIdPath"})
|
|
|
|
|
|
// 继承分类权限
|
|
|
{
|
|
@@ -335,17 +345,22 @@ func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8
|
|
|
if classifyType == utils.EdbClassifyTypeCalculate {
|
|
|
source = utils.EdbPermissionSourceCalculate
|
|
|
}
|
|
|
- go data_manage_permission.InheritParentClassify(source, int(classifyType), int(newId), classifyInfo.ParentId, classifyInfo.ClassifyName)
|
|
|
+ go data_manage_permission.InheritParentClassify(source, int(classifyType), classifyInfo.ClassifyId, classifyInfo.ParentId, classifyInfo.ClassifyName)
|
|
|
}
|
|
|
|
|
|
+ // 更改分类id完整路径path
|
|
|
+ updateCols := []string{"ClassifyIdPath"}
|
|
|
+ classifyInfo.ClassifyIdPath = fmt.Sprint(classifyIdPath, classifyInfo.ClassifyId)
|
|
|
+
|
|
|
if parentId == 0 { //一级目录的rootId等于自己本身
|
|
|
- classifyInfo.ClassifyId = int(newId)
|
|
|
- classifyInfo.RootId = int(newId)
|
|
|
- err = classifyInfo.Update([]string{"RootId"})
|
|
|
- if err != nil {
|
|
|
- errMsg = "更新分类失败"
|
|
|
- return
|
|
|
- }
|
|
|
+ classifyInfo.RootId = classifyInfo.ClassifyId
|
|
|
+ updateCols = append(updateCols, "RootId")
|
|
|
+
|
|
|
+ }
|
|
|
+ err = classifyInfo.Update(updateCols)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "更新分类失败"
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -392,6 +407,9 @@ func EditEdbClassify(classifyId int, classifyName, lang string, sysUser *system.
|
|
|
// 需要变更的字段
|
|
|
updateCols := make([]string, 0)
|
|
|
|
|
|
+ // 旧完整路径 , 新的完整路径
|
|
|
+ var oldClassifyNamePath, newClassifyNamePath string
|
|
|
+
|
|
|
switch lang {
|
|
|
case utils.EnLangVersion:
|
|
|
// 名字相同,那么就直接返回
|
|
@@ -434,15 +452,32 @@ func EditEdbClassify(classifyId int, classifyName, lang string, sysUser *system.
|
|
|
err = errors.New(errMsg)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 旧完整路径
|
|
|
+ oldClassifyNamePath = item.ClassifyNamePath
|
|
|
+
|
|
|
+ if item.ParentId > 0 {
|
|
|
+ parentItem, tmpErr := data_manage.GetEdbClassifyById(item.ParentId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newClassifyNamePath = fmt.Sprint(parentItem.ClassifyNamePath, "|", classifyName)
|
|
|
+ } else {
|
|
|
+ newClassifyNamePath = classifyName
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新自己的信息
|
|
|
item.ClassifyName = classifyName
|
|
|
+ item.ClassifyNamePath = newClassifyNamePath
|
|
|
item.LastModifyUserId = sysUser.AdminId
|
|
|
item.LastModifyUserRealName = sysUser.RealName
|
|
|
- updateCols = append(updateCols, "ClassifyName", "LastModifyUserId", "LastModifyUserRealName")
|
|
|
+ updateCols = append(updateCols, "ClassifyName", "ClassifyNamePath", "LastModifyUserId", "LastModifyUserRealName")
|
|
|
}
|
|
|
|
|
|
// 修改数据
|
|
|
if len(updateCols) > 0 {
|
|
|
- err = item.Update(updateCols)
|
|
|
+ err = item.UpdateEdbClassifyNameAndNamePath(updateCols, oldClassifyNamePath, newClassifyNamePath)
|
|
|
if err != nil {
|
|
|
errMsg = "保存失败"
|
|
|
}
|