|
@@ -9,6 +9,7 @@ import (
|
|
|
"eta/eta_api/services/alarm_msg"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -101,6 +102,8 @@ func (this *SpeechRecognitionCommonController) RecTaskCallback() {
|
|
|
}
|
|
|
contents := make([]*speech_recognition.SpeechRecognitionContent, 0)
|
|
|
sorts := 0 // API返回的结果本身是已排过序的
|
|
|
+ var abstract string
|
|
|
+ var abstractLimit int
|
|
|
for _, v := range sentences {
|
|
|
sorts += 1
|
|
|
t := new(speech_recognition.SpeechRecognitionContent)
|
|
@@ -112,11 +115,17 @@ func (this *SpeechRecognitionCommonController) RecTaskCallback() {
|
|
|
t.CreateTime = nowTime
|
|
|
t.ModifyTime = nowTime
|
|
|
contents = append(contents, t)
|
|
|
+ // 取前几段作为摘要保存
|
|
|
+ if abstractLimit < 5 {
|
|
|
+ abstractLimit += 1
|
|
|
+ abstract += v.FinalSentence
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ speechItem.Abstract = abstract
|
|
|
speechItem.State = speech_recognition.SpeechRecognitionStateSuccess
|
|
|
speechItem.ModifyTime = nowTime
|
|
|
- speechCols := []string{speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
|
|
|
+ speechCols := []string{speech_recognition.SpeechRecognitionCols.Abstract, speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
|
|
|
|
|
|
apiLog.RequestCode = code
|
|
|
apiLog.RequestResult = detail
|
|
@@ -230,7 +239,7 @@ func (this *SpeechRecognitionController) ConvertList() {
|
|
|
// 仅取待转换和转换失败的
|
|
|
states := []int{speech_recognition.SpeechRecognitionStateWait, speech_recognition.SpeechRecognitionStateFail}
|
|
|
speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
- cond := fmt.Sprintf(` %s = ? AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, speech_recognition.SpeechRecognitionCols.State, utils.GetOrmInReplace(len(states)))
|
|
|
+ cond := fmt.Sprintf(` AND %s = ? AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, speech_recognition.SpeechRecognitionCols.State, utils.GetOrmInReplace(len(states)))
|
|
|
pars := make([]interface{}, 0)
|
|
|
pars = append(pars, sysUser.AdminId, states)
|
|
|
list, e := speechOb.GetItemsByCondition(cond, pars, []string{}, "")
|
|
@@ -250,7 +259,7 @@ func (this *SpeechRecognitionController) ConvertList() {
|
|
|
br.Msg = "获取成功"
|
|
|
}
|
|
|
|
|
|
-// TODO:Save
|
|
|
+// Save
|
|
|
// @Title 保存内容
|
|
|
// @Description 保存内容
|
|
|
// @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
|
|
@@ -278,6 +287,37 @@ func (this *SpeechRecognitionController) Save() {
|
|
|
br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
+ if req.SpeechRecognitionId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(req.Contents) == 0 {
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
+ _, e := speechOb.GetItemById(req.SpeechRecognitionId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "转写文件不存在,请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量修改内容
|
|
|
+ contentOb := new(speech_recognition.SpeechRecognitionContent)
|
|
|
+ if e = contentOb.BatchUpdateContents(req.Contents); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "批量修改内容失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
@@ -397,7 +437,7 @@ func (this *SpeechRecognitionController) Rename() {
|
|
|
|
|
|
// 重名校验
|
|
|
{
|
|
|
- cond := fmt.Sprintf(` %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
|
|
|
+ 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, "")
|
|
@@ -407,7 +447,7 @@ func (this *SpeechRecognitionController) Rename() {
|
|
|
return
|
|
|
}
|
|
|
if exists != nil && exists.SpeechRecognitionId > 0 {
|
|
|
- br.Msg = "分类名称已存在,请重新输入"
|
|
|
+ br.Msg = "文件名称已存在,请重新输入"
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -569,11 +609,15 @@ func (this *SpeechRecognitionController) SaveTag() {
|
|
|
br.Msg = "操作成功"
|
|
|
}
|
|
|
|
|
|
-// TODO:List
|
|
|
+// List
|
|
|
// @Title 语音识别列表
|
|
|
// @Description 语音识别列表
|
|
|
-// @Param ParentId query int false "父级ID"
|
|
|
-// @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
|
|
|
+// @Param FileName query string false "文件名称"
|
|
|
+// @Param StartTime query string false "开始时间"
|
|
|
+// @Param EndTime query string false "结束时间"
|
|
|
+// @Param CreateUserId query int false "创建人ID"
|
|
|
+// @Param TagId query int false "标签ID"
|
|
|
+// @Success 200 {object} speech_recognition.SpeechRecognitionListResp
|
|
|
// @router /list [get]
|
|
|
func (this *SpeechRecognitionController) List() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
@@ -591,19 +635,131 @@ func (this *SpeechRecognitionController) List() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
+ params := new(speech_recognition.SpeechRecognitionListReq)
|
|
|
+ if e := this.ParseForm(params); e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ params.FileName = strings.TrimSpace(params.FileName)
|
|
|
|
|
|
- // TODO:标签列表
|
|
|
+ dataResp := new(speech_recognition.SpeechRecognitionListResp)
|
|
|
+ cond := ``
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
|
|
|
+ // 筛选项
|
|
|
+ {
|
|
|
+ if params.FileName != "" {
|
|
|
+ cond += fmt.Sprintf(` AND %s LIKE ?`, speech_recognition.SpeechRecognitionCols.FileName)
|
|
|
+ pars = append(pars, fmt.Sprint("%", params.FileName, "%"))
|
|
|
+ }
|
|
|
+ if params.StartTime != "" && params.EndTime != "" {
|
|
|
+ _, e := time.Parse(utils.FormatDate, params.StartTime)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "开始时间格式有误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, e = time.Parse(utils.FormatDate, params.EndTime)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "结束时间格式有误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ st := fmt.Sprintf("%s 00:00:00", params.StartTime)
|
|
|
+ ed := fmt.Sprintf("%s 23:59:59", params.EndTime)
|
|
|
+ cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, speech_recognition.SpeechRecognitionCols.CreateTime)
|
|
|
+ pars = append(pars, st, ed)
|
|
|
+ }
|
|
|
+ if params.CreateUserId > 0 {
|
|
|
+ cond += fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.SysUserId)
|
|
|
+ pars = append(pars, params.CreateUserId)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标签筛选
|
|
|
+ if params.TagId > 0 {
|
|
|
+ mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
|
|
|
+ tagSpeechIds, e := mappingOb.GetSpeechIdsByTagId(params.TagId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取标签关联语音识别失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(tagSpeechIds) == 0 {
|
|
|
+ br.Data = dataResp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId, utils.GetOrmInReplace(len(tagSpeechIds)))
|
|
|
+ pars = append(pars, tagSpeechIds)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页列表
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
+ total, e := speechOb.GetCountByCondition(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取语音识别列表总数失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var startSize int
|
|
|
+ if params.PageSize <= 0 {
|
|
|
+ params.PageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if params.CurrentIndex <= 0 {
|
|
|
+ params.CurrentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
|
|
|
+ list, e := speechOb.GetPageItemsByCondition(cond, pars, []string{}, "", startSize, params.PageSize)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取语音识别列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取标签
|
|
|
+ speechIds := make([]int, 0)
|
|
|
+ for _, v := range list {
|
|
|
+ speechIds = append(speechIds, v.SpeechRecognitionId)
|
|
|
+ }
|
|
|
+ mappingTags, e := speech_recognition.GetSpeechRecognitionTagsBySpeechIds(speechIds)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取语音识别列表标签失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ speechDetailTags := make(map[int][]*speech_recognition.SpeechRecognitionDetailTag)
|
|
|
+ for _, v := range mappingTags {
|
|
|
+ if speechDetailTags[v.SpeechRecognitionId] == nil {
|
|
|
+ speechDetailTags[v.SpeechRecognitionId] = make([]*speech_recognition.SpeechRecognitionDetailTag, 0)
|
|
|
+ }
|
|
|
+ speechDetailTags[v.SpeechRecognitionId] = append(speechDetailTags[v.SpeechRecognitionId], &speech_recognition.SpeechRecognitionDetailTag{
|
|
|
+ TagId: v.TagId,
|
|
|
+ TagName: v.TagName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ respList := make([]*speech_recognition.SpeechRecognitionDetailItem, 0)
|
|
|
+ for _, v := range list {
|
|
|
+ t := speech_recognition.FormatSpeechRecognition2DetailItem(v, make([]*speech_recognition.SpeechRecognitionContentItem, 0), speechDetailTags[v.SpeechRecognitionId])
|
|
|
+ respList = append(respList, t)
|
|
|
+ }
|
|
|
+
|
|
|
+ page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
|
|
|
+ dataResp.Paging = page
|
|
|
+ dataResp.List = respList
|
|
|
+ br.Data = dataResp
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
}
|
|
|
|
|
|
-// TODO:Detail
|
|
|
+// Detail
|
|
|
// @Title 语音识别详情
|
|
|
// @Description 语音识别详情
|
|
|
// @Param SpeechRecognitionId query int true "语音识别ID"
|
|
|
-// @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
|
|
|
+// @Success 200 {object} speech_recognition.SpeechRecognitionDetailItem
|
|
|
// @router /detail [get]
|
|
|
func (this *SpeechRecognitionController) Detail() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
@@ -621,9 +777,53 @@ func (this *SpeechRecognitionController) Detail() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
+ speechId, _ := this.GetInt("SpeechRecognitionId")
|
|
|
+ if speechId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", speechId)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // TODO:标签详情
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
+ speechItem, e := speechOb.GetItemById(speechId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "转写文件不存在,请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取内容
|
|
|
+ contents := make([]*speech_recognition.SpeechRecognitionContentItem, 0)
|
|
|
+ {
|
|
|
+ contentOb := new(speech_recognition.SpeechRecognitionContent)
|
|
|
+ cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionContentCols.SpeechRecognitionId)
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, speechId)
|
|
|
+ list, e := contentOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionContentCols.Sort))
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取语音识别内容失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ contents = append(contents, speech_recognition.FormatSpeechRecognitionContent2Item(v))
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // 获取标签
|
|
|
+ tags, e := speech_recognition.GetSpeechRecognitionTagBySpeechId(speechId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取语音识别标签失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ detail := speech_recognition.FormatSpeechRecognition2DetailItem(speechItem, contents, tags)
|
|
|
+
|
|
|
+ br.Data = detail
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
@@ -658,57 +858,3 @@ func (this *SpeechRecognitionController) Move() {
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
|
}
|
|
|
-
|
|
|
-//// TestConvert
|
|
|
-//// @Title 转写测试
|
|
|
-//// @Description 转写测试
|
|
|
-//// @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
|
|
|
-//// @Success 200 string "操作成功"
|
|
|
-//// @router /test_convert [post]
|
|
|
-//func (this *SpeechRecognitionCommonController) TestConvert() {
|
|
|
-// 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.SpeechRecognitionSaveReq
|
|
|
-// if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
-// br.Msg = "参数有误"
|
|
|
-// br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// conf, e := models.GetBusinessConf()
|
|
|
-// if e != nil {
|
|
|
-// br.Msg = "操作失败"
|
|
|
-// br.ErrMsg = "获取配置失败, Err: " + e.Error()
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// var taskReq services.TencentRecTaskReq
|
|
|
-// taskReq.FileUrl = req.FileName
|
|
|
-// taskReq.SecretId = conf[models.BusinessConfTencentApiSecretId]
|
|
|
-// taskReq.SecretKey = conf[models.BusinessConfTencentApiSecretKey]
|
|
|
-// taskReq.CallbackUrl = conf[models.BusinessConfTencentApiRecTaskCallbackUrl]
|
|
|
-// taskId, e := services.TencentCreateRecTask(taskReq)
|
|
|
-// if e != nil {
|
|
|
-// br.Msg = "操作失败"
|
|
|
-// br.ErrMsg = fmt.Sprintf("TencentCreateRecTask err: %s", e.Error())
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// br.Data = taskId
|
|
|
-// br.Ret = 200
|
|
|
-// br.Success = true
|
|
|
-// br.Msg = "操作成功"
|
|
|
-//}
|