Commit b7023845 authored by 赵文静's avatar 赵文静

增加删除sessionId

parent 4773dba7
Pipeline #5430 passed with stage
in 0 seconds
......@@ -10,6 +10,7 @@
- 修改播控
- 增加一个http的入口
- 增加国学
- 增加删除SessionId
## [0.0.1-beta.2] - 2025.5.29
### Changed
......
......@@ -5,7 +5,7 @@ Content-Type: application/json
"ip": "14.215.222.17",
"mac": "ece154a865eb",
"mid": "11011",
"query":"播放弟子规",
"query":"哈哈",
"requestId": "123456111"
}
......@@ -17,7 +17,7 @@ Content-Type: application/json
"ip": "14.215.222.17",
"mac": "ece154a865eb",
"mid": "11011",
"query":"播放弟子规",
"query":"天使的翅膀",
"requestId": "123456111"
}
......@@ -38,7 +38,7 @@ Content-Type: application/json
"trafficParameter": "mode=childxxx;macWifi=28b77c218ed1;mid=10f05;vender=7e000025;macVoice=testyuntiancloud;ver=3.0;scenario=smarthome;filterName=nlu;req_nlu_length=1;returnType=json;fullDuplex=true;appendLength=1;additionalService=geli_nlu2;version=0.5;filterUrl=https://testnlu.gree.com:443/semantic/unisoundc2c/querys;"
},
"nluRet": {
"text": "播放海来阿木的专辑"
"text": "天使的翅膀"
},
"postProc": {}
}
......@@ -57,7 +57,7 @@ Content-Type: application/json
},
"nluRet": {
"asr_recongize": "",
"text": "珠海在哪里"
"text": "播放歌曲大菠萝"
}
},
"version": "v0"
......@@ -79,7 +79,7 @@ Content-Type: application/json
"trafficParameter": "mode=childxx;macWifi=ece154a73d38;mid=11011;macVoice=testyuntiancloud;ver=3.0;scenario=smarthome;filterName=nlu;req_nlu_length=1;returnType=json;fullDuplex=true;appendLength=1;additionalService=geli_nlu2;version=0.5;filterUrl=https://testnlu.gree.com:443/semantic/unisoundc2c/querys;"
},
"nluRet": {
"text": "播放国学故事"
"text": "休息吧"
},
"postProc": {}
}
......
......@@ -66,6 +66,21 @@ func GetSession(mac string) (string, error) {
return sessionId, nil
}
// 删除 Session记录
func DeleteSession(mac string) error {
ctx := context.Background()
key := getSessionKey(mac)
// 删除Redis中的key
_, err := redisClient.Del(ctx, key).Result()
if err != nil {
global.Logger.Errorf("删除会话失败 (MAC: %s): %v", mac, err)
return fmt.Errorf("failed to delete session: %w", err)
}
return nil
}
// 获取会话并自动续期
func GetAndRefreshSession(mac string, expiration time.Duration) (string, bool) {
ctx := context.Background()
......
......@@ -56,6 +56,8 @@ func baseParse(params *model.SpeechDomainParams) (*model.ResponseBody, error) {
if !params.SpeechWsResp.Dm.ShouldEndSession {
fmt.Println("保存:", params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
} else {
database.DeleteSession(params.Mac)
}
//UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
......@@ -479,6 +481,8 @@ func alarmDomain(params *model.SpeechDomainParams) []byte {
//UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
return Marshal(params, &result)
} else {
database.DeleteSession(params.Mac)
}
if !params.CheckDm() || !params.CheckCommandParam() {
......@@ -796,6 +800,8 @@ func musicDomain(params *model.SpeechDomainParams) []byte {
if !params.SpeechWsResp.Dm.ShouldEndSession {
fmt.Println("保存:", params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
} else {
database.DeleteSession(params.Mac)
}
list, err := connect.MusicGrpc(params)
......@@ -899,6 +905,8 @@ func financeDomain(params *model.SpeechDomainParams) []byte {
if !params.SpeechWsResp.Dm.ShouldEndSession {
fmt.Println("保存:", params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
} else {
database.DeleteSession(params.Mac)
}
var result model.ResponseBody
......@@ -922,6 +930,8 @@ func convertDomain(params *model.SpeechDomainParams) []byte {
if !params.SpeechWsResp.Dm.ShouldEndSession {
fmt.Println("保存:", params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
} else {
database.DeleteSession(params.Mac)
}
var result model.ResponseBody
......@@ -945,6 +955,8 @@ func holidayDomain(params *model.SpeechDomainParams) []byte {
if !params.SpeechWsResp.Dm.ShouldEndSession {
fmt.Println("保存:", params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
} else {
database.DeleteSession(params.Mac)
}
var result model.ResponseBody
......@@ -968,6 +980,8 @@ func speechOtherDomain(params *model.SpeechDomainParams) []byte {
if !params.SpeechWsResp.Dm.ShouldEndSession {
fmt.Println("保存:", params.SpeechWsResp.SessionId)
database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
} else {
database.DeleteSession(params.Mac)
}
var result model.ResponseBody
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment