|
@@ -242,56 +242,108 @@ func (this *SpeechRecognitionMenuController) Remove() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 校验目录下是否有内容
|
|
|
- {
|
|
|
- speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
- cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.MenuId)
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, req.MenuId)
|
|
|
- count, e := speechOb.GetCountByCondition(cond, pars)
|
|
|
- if e != nil {
|
|
|
+ // 删除校验
|
|
|
+ checkResult, menuIds, e := services.CheckSpeechRecognitionMenuRemove(menuItem.SpeechRecognitionMenuId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "目录删除校验失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ switch checkResult.CheckResult {
|
|
|
+ case services.SpeechMenuCheckRemoveTypePass:
|
|
|
+ // 可删除
|
|
|
+ if e = menuItem.Del(); e != nil {
|
|
|
br.Msg = "操作失败"
|
|
|
- br.ErrMsg = "获取目录下的语音识别数失败, Err: " + e.Error()
|
|
|
+ br.ErrMsg = "删除目录失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
- if count > 0 {
|
|
|
- br.Msg = "该分类关联转写文件,删除失败!"
|
|
|
+ case services.SpeechMenuCheckRemoveTypeRefused:
|
|
|
+ // 不可删除
|
|
|
+ br.Msg = checkResult.Tips
|
|
|
+ return
|
|
|
+ case services.SpeechMenuCheckRemoveTypeWarning:
|
|
|
+ // 删除目录及子目录
|
|
|
+ if e = menuOb.MultiDel(menuIds); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "批量删除目录失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- cond = fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionMenuCols.ParentId)
|
|
|
- pars = make([]interface{}, 0)
|
|
|
- pars = append(pars, req.MenuId)
|
|
|
- count, e = menuOb.GetCountByCondition(cond, pars)
|
|
|
- if e != nil {
|
|
|
- br.Msg = "操作失败"
|
|
|
- br.ErrMsg = "获取下级目录数失败, Err: " + e.Error()
|
|
|
- return
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
+// RemoveCheck
|
|
|
+// @Title 删除校验
|
|
|
+// @Description 删除校验
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionMenuRemoveReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /menu/remove_check [post]
|
|
|
+func (this *SpeechRecognitionMenuController) RemoveCheck() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
}
|
|
|
- if count > 0 {
|
|
|
- br.Msg = "该分类含下级目录,删除失败!"
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req speech_recognition.SpeechRecognitionMenuRemoveReq
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.MenuId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, MenuId: %d", req.MenuId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ menuOb := new(speech_recognition.SpeechRecognitionMenu)
|
|
|
+ menuItem, e := menuOb.GetItemById(req.MenuId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
return
|
|
|
}
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取目录失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- if e = menuItem.Del(); e != nil {
|
|
|
+ resp, _, e := services.CheckSpeechRecognitionMenuRemove(menuItem.SpeechRecognitionMenuId)
|
|
|
+ if e != nil {
|
|
|
br.Msg = "操作失败"
|
|
|
- br.ErrMsg = "删除目录失败, Err: " + e.Error()
|
|
|
+ br.ErrMsg = "目录删除校验失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ br.Data = resp
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
|
}
|
|
|
|
|
|
-// Tree
|
|
|
-// @Title 目录树
|
|
|
-// @Description 目录树
|
|
|
+// List
|
|
|
+// @Title 目录列表
|
|
|
+// @Description 目录列表
|
|
|
// @Param ParentId query int false "父级ID"
|
|
|
// @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
|
|
|
-// @router /menu/tree [get]
|
|
|
-func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
+// @router /menu/list [get]
|
|
|
+func (this *SpeechRecognitionMenuController) List() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
|
if br.ErrMsg == "" {
|
|
@@ -307,14 +359,26 @@ func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
- // 前端采用懒加载, 所以只查询目录及当前目录下的语音识别
|
|
|
+ // 前端采用懒加载, 所以只查询子目录和内容
|
|
|
parentId, _ := this.GetInt("ParentId")
|
|
|
|
|
|
- // 获取所有目录
|
|
|
+ level := 0
|
|
|
+ menuOb := new(speech_recognition.SpeechRecognitionMenu)
|
|
|
+ if parentId > 0 {
|
|
|
+ parentMenu, e := menuOb.GetItemById(parentId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取父级目录失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ level = parentMenu.Level + 1
|
|
|
+ }
|
|
|
menus := make([]*speech_recognition.SpeechRecognitionMenu, 0)
|
|
|
{
|
|
|
- menuOb := new(speech_recognition.SpeechRecognitionMenu)
|
|
|
- list, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionMenuCols.Sort))
|
|
|
+ cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionMenuCols.ParentId)
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, parentId)
|
|
|
+ list, e := menuOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionMenuCols.Sort))
|
|
|
if e != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取目录列表失败, Err: " + e.Error()
|
|
@@ -323,19 +387,32 @@ func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
menus = list
|
|
|
}
|
|
|
|
|
|
- topMenus := make([]*speech_recognition.SpeechRecognitionMenu, 0) // 顶部节点
|
|
|
- menuChildren := make(map[int][]*speech_recognition.SpeechRecognitionMenuNodeItem) // 子目录节点
|
|
|
- menuIdLevel := make(map[int]int) // 目录对应层级
|
|
|
- for _, v := range menus {
|
|
|
- menuIdLevel[v.SpeechRecognitionMenuId] = v.Level
|
|
|
- if v.ParentId == parentId {
|
|
|
- topMenus = append(topMenus, v)
|
|
|
+ speeches := make([]*speech_recognition.SpeechRecognition, 0)
|
|
|
+ {
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
+ cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.MenuId)
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, parentId)
|
|
|
+ list, e := speechOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC, %s DESC", speech_recognition.SpeechRecognitionCols.Sort, speech_recognition.SpeechRecognitionCols.CreateTime))
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取语音识别列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
}
|
|
|
+ speeches = list
|
|
|
+ }
|
|
|
|
|
|
- if menuChildren[v.ParentId] == nil {
|
|
|
- menuChildren[v.ParentId] = make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
- }
|
|
|
- menuChildren[v.ParentId] = append(menuChildren[v.ParentId], &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
+ resp := make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
+ if len(menus) == 0 && len(speeches) == 0 {
|
|
|
+ br.Data = resp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range menus {
|
|
|
+ resp = append(resp, &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
UniqueCode: v.UniqueCode,
|
|
|
NodeType: speech_recognition.SpeechRecognitionMenuNodeTypeDefault,
|
|
|
MenuId: v.SpeechRecognitionMenuId,
|
|
@@ -346,76 +423,64 @@ func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime),
|
|
|
})
|
|
|
}
|
|
|
+ for _, v := range speeches {
|
|
|
+ resp = append(resp, &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
+ UniqueCode: v.UniqueCode,
|
|
|
+ NodeType: speech_recognition.SpeechRecognitionMenuNodeTypeSpeech,
|
|
|
+ SpeechRecognitionId: v.SpeechRecognitionId,
|
|
|
+ SpeechRecognitionName: v.FileName,
|
|
|
+ ParentId: v.MenuId,
|
|
|
+ Level: level,
|
|
|
+ Sort: v.Sort,
|
|
|
+ CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ sort.Slice(resp, func(i, j int) bool {
|
|
|
+ return resp[i].Sort < resp[j].Sort
|
|
|
+ })
|
|
|
|
|
|
- resp := make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
- if len(topMenus) == 0 {
|
|
|
- br.Data = resp
|
|
|
- br.Ret = 200
|
|
|
- br.Success = true
|
|
|
- br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|
|
|
+
|
|
|
+// Tree
|
|
|
+// @Title 目录树
|
|
|
+// @Description 目录树
|
|
|
+// @Success 200 {object} speech_recognition.SpeechRecognitionMenuItem
|
|
|
+// @router /menu/tree [get]
|
|
|
+func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 目录下的语音识别
|
|
|
- menuIds := make([]int, 0)
|
|
|
- for _, m := range topMenus {
|
|
|
- menuIds = append(menuIds, m.SpeechRecognitionMenuId)
|
|
|
- }
|
|
|
- speeches := make([]*speech_recognition.SpeechRecognition, 0)
|
|
|
+ menus := make([]*speech_recognition.SpeechRecognitionMenu, 0)
|
|
|
{
|
|
|
- speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
- cond := fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.MenuId, utils.GetOrmInReplace(len(menuIds)))
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, menuIds)
|
|
|
- list, e := speechOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC, %s DESC", speech_recognition.SpeechRecognitionCols.Sort, speech_recognition.SpeechRecognitionCols.CreateTime))
|
|
|
+ menuOb := new(speech_recognition.SpeechRecognitionMenu)
|
|
|
+ list, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, fmt.Sprintf("%s ASC, %s ASC", speech_recognition.SpeechRecognitionMenuCols.ParentId, speech_recognition.SpeechRecognitionMenuCols.Sort))
|
|
|
if e != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取语音识别列表失败, Err: " + e.Error()
|
|
|
+ br.ErrMsg = "获取目录列表失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
- speeches = list
|
|
|
- }
|
|
|
- menuSpeeches := make(map[int][]*speech_recognition.SpeechRecognitionMenuNodeItem)
|
|
|
- for _, s := range speeches {
|
|
|
- if menuSpeeches[s.MenuId] == nil {
|
|
|
- menuSpeeches[s.MenuId] = make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
- }
|
|
|
- menuSpeeches[s.MenuId] = append(menuSpeeches[s.MenuId], &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
- UniqueCode: s.UniqueCode,
|
|
|
- NodeType: speech_recognition.SpeechRecognitionMenuNodeTypeSpeech,
|
|
|
- SpeechRecognitionId: s.SpeechRecognitionId,
|
|
|
- SpeechRecognitionName: s.FileName,
|
|
|
- ParentId: s.MenuId,
|
|
|
- Level: menuIdLevel[s.MenuId] + 1,
|
|
|
- Sort: s.Sort,
|
|
|
- CreateTime: utils.TimeTransferString(utils.FormatDateTime, s.CreateTime),
|
|
|
- })
|
|
|
+ menus = list
|
|
|
}
|
|
|
|
|
|
- for _, m := range topMenus {
|
|
|
- child := make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
- if menuSpeeches[m.SpeechRecognitionMenuId] != nil {
|
|
|
- child = append(child, menuSpeeches[m.SpeechRecognitionMenuId]...)
|
|
|
- }
|
|
|
- if menuChildren[m.SpeechRecognitionMenuId] != nil {
|
|
|
- child = append(child, menuChildren[m.SpeechRecognitionMenuId]...)
|
|
|
- }
|
|
|
- sort.Slice(child, func(i, j int) bool {
|
|
|
- return child[i].Sort < child[j].Sort
|
|
|
- })
|
|
|
- t := &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
- UniqueCode: m.UniqueCode,
|
|
|
- NodeType: speech_recognition.SpeechRecognitionMenuNodeTypeDefault,
|
|
|
- MenuId: m.SpeechRecognitionMenuId,
|
|
|
- MenuName: m.MenuName,
|
|
|
- ParentId: m.ParentId,
|
|
|
- Level: m.Level,
|
|
|
- Sort: m.Sort,
|
|
|
- CreateTime: utils.TimeTransferString(utils.FormatDateTime, m.CreateTime),
|
|
|
- Children: child,
|
|
|
- }
|
|
|
- resp = append(resp, t)
|
|
|
- }
|
|
|
+ // 递归处理成目录树
|
|
|
+ resp := services.GetSpeechRecognitionMenuTreeRecursive(menus, 0)
|
|
|
|
|
|
br.Data = resp
|
|
|
br.Ret = 200
|