You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
3.1 KiB
75 lines
3.1 KiB
package echomeet
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/pb"
|
|
"time"
|
|
)
|
|
|
|
// @Summary 批量获取会议记录
|
|
// @Description 根据 Ids 批量获取会议记录,若存在转写中的记录会触发一次状态轮询
|
|
// @Tags Echomeet
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param user body pb.EchomeetGetRecordsReq true "请求数据"
|
|
// @Success 200 {object} comm.HttpResult{data=pb.EchomeetGetRecordsResp} "响应数据"
|
|
// @Router /api/home/echomeet_getrecords [post]
|
|
func (this *apiComp) GetRecords(session comm.IUserSession, req *pb.EchomeetGetRecordsReq) (resp *pb.EchomeetGetRecordsResp, errdata *pb.ErrorData) {
|
|
records, err := this.module.model.getrecords(req.Ids)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
now := time.Now().Unix()
|
|
polled := make(map[uint64]bool)
|
|
for _, model := range records {
|
|
if model.State == pb.DBEchoMeetRecordState_Transcribing && model.Taskid != "" {
|
|
if model.Lastquerytime > 0 && now-model.Lastquerytime < TranscribeQueryMinInterval {
|
|
continue
|
|
}
|
|
model.Lastquerytime = now
|
|
this.module.model.saverecord(model)
|
|
this.module.tasks.PollTranscribe(model)
|
|
polled[model.Id] = true
|
|
}
|
|
}
|
|
hideHalfDoneTranscribe(polled, records)
|
|
resp = &pb.EchomeetGetRecordsResp{Records: records}
|
|
return
|
|
}
|
|
|
|
// hideHalfDoneTranscribe 把「转写刚完成、但翻译文本还没落库」的中间态对外降级回
|
|
// Transcribing,**只改这次响应,不落库**。
|
|
//
|
|
// ⚠️ 这不是偶发竞态,是每次首轮必中:PollTranscribe 成功后先把 State 推到
|
|
// AwaitSummarizing 并落库,随后 `go finishTranscribe(rec.Id, ...)` 才在后台写
|
|
// Translate——而且它**重新从库里读了一份记录**(那是刻意的,见 finishTranscribe
|
|
// 的注释:共用指针会和 HTTP 响应的序列化产生数据竞争)。于是调用方手上这个
|
|
// 即将被序列化的 rec,状态已经是「转写完成」而 Translate 仍是空串。
|
|
//
|
|
// 客户端据 state 判「转写完成」并立刻 jsonDecode(translate),空串直接抛异常;
|
|
// 真机上这一抛把它的轮询循环整个掀掉且再也起不来(_isTask 卡在 true),
|
|
// 表现就是「服务端早就跑完了,App 一直显示转写中」。
|
|
//
|
|
// 只对本次请求里真正触发过轮询的那些记录降级:不加这个限制的话,万一
|
|
// finishTranscribe 出错没写成 Translate,记录会被永久钉在「转写中」。
|
|
func hideHalfDoneTranscribe(polled map[uint64]bool, records []*pb.DBEchoMeetRecord) {
|
|
for _, m := range records {
|
|
if !polled[m.Id] {
|
|
continue
|
|
}
|
|
// ⚠️ 上界必须卡到 Readed:失败态 TranscribeFail=10002 / SummarizFail=10001
|
|
// 数值上也 >= AwaitSummarizing,而它们的 Translate 本来就是空的。
|
|
// 只写下界的话会把「转写失败」降级成「转写中」,客户端就永远轮询下去、
|
|
// 永远等不到那个失败提示。
|
|
if m.State >= pb.DBEchoMeetRecordState_AwaitSummarizing &&
|
|
m.State <= pb.DBEchoMeetRecordState_Readed &&
|
|
m.Translate == "" {
|
|
m.State = pb.DBEchoMeetRecordState_Transcribing
|
|
}
|
|
}
|
|
}
|
|
|