|
@@ -7,6 +7,8 @@ import (
|
|
|
"eta/eta_api/models/speech_recognition"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "sort"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -69,6 +71,7 @@ func (this *SpeechRecognitionMenuController) Add() {
|
|
|
|
|
|
// 获取目录层级
|
|
|
level := 1
|
|
|
+ rootId := 0
|
|
|
{
|
|
|
if req.ParentId > 0 {
|
|
|
parentMenu, e := menuOb.GetItemById(req.ParentId)
|
|
@@ -78,12 +81,16 @@ func (this *SpeechRecognitionMenuController) Add() {
|
|
|
return
|
|
|
}
|
|
|
level += parentMenu.Level
|
|
|
+ rootId = parentMenu.RootId
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
+ menuOb.UniqueCode = utils.MD5(fmt.Sprintf("%s_%s", menuOb.TableName(), timestamp))
|
|
|
menuOb.MenuName = req.MenuName
|
|
|
menuOb.ParentId = req.ParentId
|
|
|
menuOb.Level = level
|
|
|
+ menuOb.RootId = rootId
|
|
|
menuOb.CreateTime = time.Now().Local()
|
|
|
menuOb.ModifyTime = time.Now().Local()
|
|
|
e := menuOb.Create()
|
|
@@ -296,13 +303,11 @@ func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
// 前端采用懒加载, 所以只查询目录及当前目录下的语音识别
|
|
|
parentId, _ := this.GetInt("ParentId")
|
|
|
|
|
|
+ // 获取所有目录
|
|
|
menus := make([]*speech_recognition.SpeechRecognitionMenu, 0)
|
|
|
{
|
|
|
menuOb := new(speech_recognition.SpeechRecognitionMenu)
|
|
|
- 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))
|
|
|
+ list, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionMenuCols.Sort))
|
|
|
if e != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取目录列表失败, Err: " + e.Error()
|
|
@@ -311,50 +316,44 @@ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ if menuChildren[v.ParentId] == nil {
|
|
|
+ menuChildren[v.ParentId] = make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
+ }
|
|
|
+ menuChildren[v.ParentId] = append(menuChildren[v.ParentId], &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
+ UniqueCode: v.UniqueCode,
|
|
|
+ NodeType: speech_recognition.SpeechRecognitionMenuNodeTypeDefault,
|
|
|
+ MenuId: v.SpeechRecognitionMenuId,
|
|
|
+ MenuName: v.MenuName,
|
|
|
+ ParentId: v.ParentId,
|
|
|
+ Level: v.Level,
|
|
|
+ Sort: v.Sort,
|
|
|
+ CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
resp := make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
- if len(menus) == 0 {
|
|
|
+ if len(topMenus) == 0 {
|
|
|
br.Data = resp
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 目录下的语音识别
|
|
|
menuIds := make([]int, 0)
|
|
|
- for _, m := range menus {
|
|
|
+ for _, m := range topMenus {
|
|
|
menuIds = append(menuIds, m.SpeechRecognitionMenuId)
|
|
|
}
|
|
|
-
|
|
|
- // 子目录
|
|
|
- childMenus := make([]*speech_recognition.SpeechRecognitionMenu, 0)
|
|
|
- {
|
|
|
- menuOb := new(speech_recognition.SpeechRecognitionMenu)
|
|
|
- cond := fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionMenuCols.ParentId, utils.GetOrmInReplace(len(menuIds)))
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, menuIds)
|
|
|
- list, e := menuOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC, %s ASC", speech_recognition.SpeechRecognitionMenuCols.Sort, speech_recognition.SpeechRecognitionMenuCols.ParentId))
|
|
|
- if e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取子目录列表失败, Err: " + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- childMenus = list
|
|
|
- }
|
|
|
- menuChildren := make(map[int][]*speech_recognition.SpeechRecognitionMenuNodeItem)
|
|
|
- for _, m := range childMenus {
|
|
|
- if menuChildren[m.ParentId] == nil {
|
|
|
- menuChildren[m.ParentId] = make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0)
|
|
|
- }
|
|
|
- menuChildren[m.ParentId] = append(menuChildren[m.ParentId], &speech_recognition.SpeechRecognitionMenuNodeItem{
|
|
|
- NodeType: speech_recognition.SpeechRecognitionMenuNodeTypeDefault,
|
|
|
- MenuId: m.SpeechRecognitionMenuId,
|
|
|
- MenuName: m.MenuName,
|
|
|
- ParentId: m.ParentId,
|
|
|
- Sort: m.Sort,
|
|
|
- CreateTime: utils.TimeTransferString(utils.FormatDateTime, m.CreateTime),
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 目录下的语音识别
|
|
|
speeches := make([]*speech_recognition.SpeechRecognition, 0)
|
|
|
{
|
|
|
speechOb := new(speech_recognition.SpeechRecognition)
|
|
@@ -375,30 +374,38 @@ func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
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),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- for _, m := range menus {
|
|
|
+ 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: make([]*speech_recognition.SpeechRecognitionMenuNodeItem, 0),
|
|
|
- }
|
|
|
- if menuSpeeches[m.SpeechRecognitionMenuId] != nil {
|
|
|
- t.Children = append(t.Children, menuSpeeches[m.SpeechRecognitionMenuId]...)
|
|
|
- }
|
|
|
- if menuChildren[m.SpeechRecognitionMenuId] != nil {
|
|
|
- t.Children = append(t.Children, menuChildren[m.SpeechRecognitionMenuId]...)
|
|
|
+ Children: child,
|
|
|
}
|
|
|
resp = append(resp, t)
|
|
|
}
|
|
@@ -408,3 +415,43 @@ func (this *SpeechRecognitionMenuController) Tree() {
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
}
|
|
|
+
|
|
|
+// Move
|
|
|
+// @Title 移动目录/语音识别
|
|
|
+// @Description 移动目录/语音识别
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionMenuMoveReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /move [post]
|
|
|
+func (this *SpeechRecognitionMenuController) Move() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ var req speech_recognition.SpeechRecognitionMenuMoveReq
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.MenuId <= 0 && req.SpeechId <= 0 {
|
|
|
+ br.Msg = "请选择目录或语音识别"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO:移动
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|