|
@@ -493,3 +493,69 @@ func (m *SpeechRecognition) GetFirstByMenuId(menuId int) (item *SpeechRecognitio
|
|
|
type SpeechRecognitionConvertCheckNameReq struct {
|
|
|
FileName string `description:"文件名称"`
|
|
|
}
|
|
|
+
|
|
|
+// SpeechSave 更新内容、摘要及标签
|
|
|
+func (m *SpeechRecognition) SpeechSave(speechItem *SpeechRecognition, speechCols []string, contents []SpeechRecognitionSaveContentReq, tagMappings []*SpeechRecognitionTagMapping) (err error) {
|
|
|
+ if speechItem == nil {
|
|
|
+ err = fmt.Errorf("speech nil")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ o := orm.NewOrm()
|
|
|
+ tx, e := o.Begin()
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("transaction begin err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ _ = tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _ = tx.Commit()
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 转写文件
|
|
|
+ if len(speechCols) > 0 {
|
|
|
+ _, e = tx.Update(speechItem, speechCols...)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("update speech err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转写内容
|
|
|
+ if len(contents) > 0 {
|
|
|
+ sql := fmt.Sprintf(`UPDATE %s SET %s = ?, %s = 1, %s = NOW() WHERE %s = ?`, "speech_recognition_content", SpeechRecognitionContentCols.Content, SpeechRecognitionContentCols.IsUpdate, SpeechRecognitionContentCols.ModifyTime, SpeechRecognitionContentCols.SpeechRecognitionContentId)
|
|
|
+ p, e := tx.Raw(sql).Prepare()
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("update prepare err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ _ = p.Close()
|
|
|
+ }()
|
|
|
+ for _, v := range contents {
|
|
|
+ _, e = p.Exec(v.Content, v.SpeechRecognitionContentId)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("update exec err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标签
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ?`, "speech_recognition_tag_mapping", SpeechRecognitionTagMappingCols.SpeechRecognitionId)
|
|
|
+ _, e = tx.Raw(sql, speechItem.SpeechRecognitionId).Exec()
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("remove tag mappings err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(tagMappings) > 0 {
|
|
|
+ _, e = tx.InsertMulti(len(tagMappings), tagMappings)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("insert tag mappings err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|