Bläddra i källkod

Merge branch 'feature/eta_1.6.9' into debug

hsun 1 år sedan
förälder
incheckning
7dde11ea7e

+ 71 - 3
controllers/speech_recognition/speech_recognition.go

@@ -11,6 +11,7 @@ import (
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"os"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -309,9 +310,14 @@ func (this *SpeechRecognitionController) Save() {
 		br.Msg = "操作成功"
 		return
 	}
+	req.FileName = strings.TrimSpace(req.FileName)
+	if req.FileName == "" {
+		br.Msg = "请输入文件名称"
+		return
+	}
 
 	speechOb := new(speech_recognition.SpeechRecognition)
-	_, e := speechOb.GetItemById(req.SpeechRecognitionId)
+	speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
 	if e != nil {
 		if e.Error() == utils.ErrNoRow() {
 			br.Msg = "转写文件不存在,请刷新页面"
@@ -321,6 +327,32 @@ func (this *SpeechRecognitionController) Save() {
 		br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
 		return
 	}
+	if req.FileName != speechItem.FileName {
+		// 校验重名
+		{
+			cond := fmt.Sprintf(` AND %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
+			pars := make([]interface{}, 0)
+			pars = append(pars, req.FileName, req.SpeechRecognitionId)
+			exists, e := speechOb.GetItemByCondition(cond, pars, "")
+			if e != nil && e.Error() != utils.ErrNoRow() {
+				br.Msg = "操作失败"
+				br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
+				return
+			}
+			if exists != nil && exists.SpeechRecognitionId > 0 {
+				br.Msg = "文件名称已存在,请重新输入"
+				return
+			}
+		}
+		speechItem.FileName = req.FileName
+		speechItem.ModifyTime = time.Now().Local()
+		updateCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.ModifyTime}
+		if e = speechItem.Update(updateCols); e != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "更新转写文件名称失败, Err: " + e.Error()
+			return
+		}
+	}
 
 	// 批量修改内容
 	contentOb := new(speech_recognition.SpeechRecognitionContent)
@@ -330,6 +362,26 @@ func (this *SpeechRecognitionController) Save() {
 		return
 	}
 
+	// 更新标签
+	mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
+	if e = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "清除语音识别标签失败, Err: " + e.Error()
+		return
+	}
+	tagMappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
+	for _, v := range req.TagIds {
+		tagMappings = append(tagMappings, &speech_recognition.SpeechRecognitionTagMapping{
+			SpeechRecognitionId: req.SpeechRecognitionId,
+			TagId:               v,
+		})
+	}
+	if e = mappingOb.CreateMulti(tagMappings); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "批量新增语音识别标签失败, Err: " + e.Error()
+		return
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
@@ -841,7 +893,7 @@ func (this *SpeechRecognitionController) List() {
 
 	respList := make([]*speech_recognition.SpeechRecognitionDetailItem, 0)
 	for _, v := range list {
-		t := speech_recognition.FormatSpeechRecognition2DetailItem(v, make([]*speech_recognition.SpeechRecognitionContentItem, 0), speechDetailTags[v.SpeechRecognitionId])
+		t := speech_recognition.FormatSpeechRecognition2DetailItem(v, make([]*speech_recognition.SpeechRecognitionContentItem, 0), speechDetailTags[v.SpeechRecognitionId], make([]*speech_recognition.SpeechRecognitionMenuItem, 0))
 		respList = append(respList, t)
 	}
 
@@ -916,6 +968,22 @@ func (this *SpeechRecognitionController) Detail() {
 		}
 	}
 
+	// 跟踪目录路径
+	menuPath := make([]*speech_recognition.SpeechRecognitionMenuItem, 0)
+	{
+		menuOb := new(speech_recognition.SpeechRecognitionMenu)
+		menus, 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()
+			return
+		}
+		menuPath = services.GetSpeechRecognitionMenuPathRecursive(menus, speechItem.MenuId)
+		sort.Slice(menuPath, func(i, j int) bool {
+			return menuPath[i].Level < menuPath[j].Level
+		})
+	}
+
 	// 获取标签
 	tags, e := speech_recognition.GetSpeechRecognitionTagBySpeechId(speechId)
 	if e != nil {
@@ -923,7 +991,7 @@ func (this *SpeechRecognitionController) Detail() {
 		br.ErrMsg = "获取语音识别标签失败, Err: " + e.Error()
 		return
 	}
-	detail := speech_recognition.FormatSpeechRecognition2DetailItem(speechItem, contents, tags)
+	detail := speech_recognition.FormatSpeechRecognition2DetailItem(speechItem, contents, tags, menuPath)
 
 	br.Data = detail
 	br.Ret = 200

+ 14 - 2
models/speech_recognition/speech_recognition.go

@@ -224,6 +224,8 @@ func FormatSpeechRecognition2Item(origin *SpeechRecognition) (item *SpeechRecogn
 // SpeechRecognitionSaveReq 保存请求体
 type SpeechRecognitionSaveReq struct {
 	SpeechRecognitionId int                               `description:"语音识别ID"`
+	FileName            string                            `description:"文件名称"`
+	TagIds              []int                             `description:"标签IDs"`
 	Contents            []SpeechRecognitionSaveContentReq `description:"保存内容"`
 }
 
@@ -343,8 +345,10 @@ type SpeechRecognitionDetailItem struct {
 	SpeechRecognitionId int
 	UniqueCode          string                          `description:"唯一编码"`
 	FileName            string                          `description:"文件名称"`
-	ResourceUrl         string                          `description:"文件路径"`
+	FileExt             string                          `description:"文件后缀名"`
+	ResourceUrl         string                          `description:"文件地址"`
 	MenuId              int                             `description:"目录ID"`
+	MenuPath            []*SpeechRecognitionMenuItem    `description:"目录全路径, 多级并列为一个数组"`
 	SysUserId           int                             `description:"创建人ID"`
 	SysUserName         string                          `description:"创建人姓名"`
 	Abstract            string                          `description:"摘要,取前几段内容"`
@@ -357,7 +361,7 @@ type SpeechRecognitionDetailItem struct {
 	Tags                []*SpeechRecognitionDetailTag   `description:"标签"`
 }
 
-func FormatSpeechRecognition2DetailItem(origin *SpeechRecognition, contents []*SpeechRecognitionContentItem, tags []*SpeechRecognitionDetailTag) (item *SpeechRecognitionDetailItem) {
+func FormatSpeechRecognition2DetailItem(origin *SpeechRecognition, contents []*SpeechRecognitionContentItem, tags []*SpeechRecognitionDetailTag, menuPath []*SpeechRecognitionMenuItem) (item *SpeechRecognitionDetailItem) {
 	if origin == nil {
 		return
 	}
@@ -366,10 +370,18 @@ func FormatSpeechRecognition2DetailItem(origin *SpeechRecognition, contents []*S
 	item.UniqueCode = origin.UniqueCode
 	item.FileName = origin.FileName
 	item.ResourceUrl = origin.ResourceUrl
+	if item.ResourceUrl != "" {
+		pointArr := strings.Split(item.ResourceUrl, ".")
+		if len(pointArr) > 0 {
+			item.FileExt = pointArr[len(pointArr)-1]
+		}
+	}
+	item.ResourceUrl = origin.ResourceUrl
 	if origin.FileState == SpeechRecognitionFileRemoveFlag {
 		item.ResourceUrl = ""
 	}
 	item.MenuId = origin.MenuId
+	item.MenuPath = menuPath
 	item.SysUserId = origin.SysUserId
 	item.SysUserName = origin.SysUserName
 	item.Abstract = origin.Abstract

+ 4 - 0
models/speech_recognition/speech_recognition_content.go

@@ -155,8 +155,11 @@ type SpeechRecognitionContentItem struct {
 	Content                    string `description:"段落内容"`
 	StartMs                    int    `description:"单句开始时间(毫秒)"`
 	EndMs                      int    `description:"单句结束时间(毫秒)"`
+	StartTime                  string `description:"开始时间, 格式HH:MM:SS"`
 	CreateTime                 string `description:"创建时间"`
 	ModifyTime                 string `description:"修改时间"`
+	HideTimestamp              bool   `description:"前端用的, 默认false就行"`
+	IsHover                    bool   `description:"前端用的, 默认false就行"`
 }
 
 func FormatSpeechRecognitionContent2Item(origin *SpeechRecognitionContent) (item *SpeechRecognitionContentItem) {
@@ -170,6 +173,7 @@ func FormatSpeechRecognitionContent2Item(origin *SpeechRecognitionContent) (item
 	item.Content = origin.Content
 	item.StartMs = origin.StartMs
 	item.EndMs = origin.EndMs
+	item.StartTime = utils.MillisecondsToHHMMSS(origin.StartMs)
 	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
 	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
 	return

+ 22 - 0
services/speech_recognition.go

@@ -1380,3 +1380,25 @@ func CheckSpeechRecognitionTagMenuRemove(menuId int) (result *speech_recognition
 	result.Tips = "校验通过,可以删除"
 	return
 }
+
+// GetSpeechRecognitionMenuPathRecursive 根据子目录递归获取目录树
+func GetSpeechRecognitionMenuPathRecursive(list []*speech_recognition.SpeechRecognitionMenu, menuId int) []*speech_recognition.SpeechRecognitionMenuItem {
+	res := make([]*speech_recognition.SpeechRecognitionMenuItem, 0)
+	for _, v := range list {
+		if v.SpeechRecognitionMenuId == menuId {
+			t := new(speech_recognition.SpeechRecognitionMenuItem)
+			t.UniqueCode = v.UniqueCode
+			t.MenuId = v.SpeechRecognitionMenuId
+			t.MenuName = v.MenuName
+			t.ParentId = v.ParentId
+			t.Level = v.Level
+			t.Sort = v.Sort
+			t.CreateTime = utils.TimeTransferString(utils.FormatDateTime, v.CreateTime)
+			if v.ParentId > 0 {
+				res = GetSpeechRecognitionMenuPathRecursive(list, v.ParentId)
+			}
+			res = append(res, t)
+		}
+	}
+	return res
+}