소스 검색

wip:账户id修改为职位id

wangkaiyue 2 년 전
부모
커밋
812a896caa

+ 3 - 3
internal/controller/chatHistory.go

@@ -18,16 +18,16 @@ type cChatHistory struct{}
 // Method 获取聊天记录
 // Method 获取聊天记录
 func (c *cChatHistory) Method(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
 func (c *cChatHistory) Method(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
 	session := model.SessionCtx.Get(ctx).JSession
 	session := model.SessionCtx.Get(ctx).JSession
-	if session.AccountId <= 0 {
+	if session.PositionId <= 0 {
 		return nil, fmt.Errorf("无用户身份")
 		return nil, fmt.Errorf("无用户身份")
 	}
 	}
 	res = &v1.ChatHistoryRes{}
 	res = &v1.ChatHistoryRes{}
 	if req.PrevId != "" {
 	if req.PrevId != "" {
 		req.PrevId = encrypt.SE.Decode4Hex(req.PrevId) //id解密
 		req.PrevId = encrypt.SE.Decode4Hex(req.PrevId) //id解密
 	}
 	}
-	history, hasNext, err := model.ChatHistory.GetMessage(model.SessionCtx.Get(ctx).JSession.AccountId, req.PageNum, req.PageSize, req.PrevId)
+	history, hasNext, err := model.ChatHistory.GetMessage(session.PositionId, req.PageNum, req.PageSize, req.PrevId)
 	if err != nil {
 	if err != nil {
-		glog.Error(ctx, "%d查询聊天记录异常,error:%s", model.SessionCtx.Get(ctx).JSession.AccountId, err)
+		glog.Error(ctx, "%d查询聊天记录异常,error:%s", session.PositionId, err)
 		res.ErrorCode = -1
 		res.ErrorCode = -1
 		res.ErrorMsg = "数据查询异常"
 		res.ErrorMsg = "数据查询异常"
 		return
 		return

+ 3 - 3
internal/controller/chatWs.go

@@ -17,10 +17,10 @@ var ChatWs = func(r *ghttp.Request) {
 	// 创建ws链接
 	// 创建ws链接
 	ws, err := r.WebSocket()
 	ws, err := r.WebSocket()
 	if err != nil {
 	if err != nil {
-		glog.Error(wsChat.Ctx, session.AccountId, "建立连接出错", err)
+		glog.Error(wsChat.Ctx, session.PositionId, "建立连接出错", err)
 		r.Exit()
 		r.Exit()
 	}
 	}
-	if session.AccountId == 0 {
+	if session.PositionId == 0 {
 		_ = ws.WriteJSON(g.Map{
 		_ = ws.WriteJSON(g.Map{
 			"error_code": -1,
 			"error_code": -1,
 			"error_msg":  "无用户身份",
 			"error_msg":  "无用户身份",
@@ -31,7 +31,7 @@ var ChatWs = func(r *ghttp.Request) {
 		// 接受客户端信息
 		// 接受客户端信息
 		_, msg, err := ws.ReadMessage()
 		_, msg, err := ws.ReadMessage()
 		if err != nil {
 		if err != nil {
-			glog.Info(wsChat.Ctx, session.AccountId, "接收消息出错", err)
+			glog.Info(wsChat.Ctx, session.PositionId, "接收消息出错", err)
 			_ = ws.Close()
 			_ = ws.Close()
 			return
 			return
 		}
 		}

+ 2 - 2
internal/controller/evaluate.go

@@ -18,11 +18,11 @@ func (c *cEvaluate) Method(ctx context.Context, req *v1.EvaluateReq) (res *v1.Ev
 	res = &v1.EvaluateRes{}
 	res = &v1.EvaluateRes{}
 	id := encrypt.SE.Decode4Hex(req.MessageId)
 	id := encrypt.SE.Decode4Hex(req.MessageId)
 	session := model.SessionCtx.Get(ctx).JSession
 	session := model.SessionCtx.Get(ctx).JSession
-	if session.AccountId <= 0 {
+	if session.PositionId <= 0 {
 		return nil, fmt.Errorf("无用户身份")
 		return nil, fmt.Errorf("无用户身份")
 	}
 	}
 
 
-	err = model.ChatHistory.Evaluate(session.AccountId, id, req.Evaluate)
+	err = model.ChatHistory.Evaluate(session.PositionId, id, req.Evaluate)
 	if err != nil {
 	if err != nil {
 		res.Data = false
 		res.Data = false
 		return
 		return

+ 1 - 1
internal/controller/usuallyProblem.go

@@ -16,7 +16,7 @@ type cUsuallyProblem struct{}
 
 
 func (c *cUsuallyProblem) Method(ctx context.Context, req *v1.UsuallyProblemReq) (res *v1.QuestionRes, err error) {
 func (c *cUsuallyProblem) Method(ctx context.Context, req *v1.UsuallyProblemReq) (res *v1.QuestionRes, err error) {
 	session := model.SessionCtx.Get(ctx).JSession
 	session := model.SessionCtx.Get(ctx).JSession
-	if session.AccountId <= 0 {
+	if session.PersonId <= 0 {
 		return nil, fmt.Errorf("无用户身份")
 		return nil, fmt.Errorf("无用户身份")
 	}
 	}
 	var list []string
 	var list []string

+ 2 - 2
internal/model/blackList.go

@@ -14,8 +14,8 @@ type cUserBlackList struct {
 }
 }
 
 
 // CheckBlackList 校验黑名单
 // CheckBlackList 校验黑名单
-func (l *cUserBlackList) CheckBlackList(ctx context.Context, accountId int64) bool {
-	v, e := g.Redis("black").Get(ctx, fmt.Sprintf("aiChat_black_%d", accountId))
+func (l *cUserBlackList) CheckBlackList(ctx context.Context, positionId int64) bool {
+	v, e := g.Redis("black").Get(ctx, fmt.Sprintf("aiChat_black_%d", positionId))
 	if e != nil {
 	if e != nil {
 		return false
 		return false
 	}
 	}

+ 5 - 5
internal/model/ws.go

@@ -32,7 +32,7 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
 
 
 	req := &QuestionReq{}
 	req := &QuestionReq{}
 	if err := gjson.Unmarshal(msg, req); err != nil {
 	if err := gjson.Unmarshal(msg, req); err != nil {
-		glog.Errorf(m.Ctx, "%d 接收消息Unmarshal出错:%v", jSession.AccountId, err)
+		glog.Errorf(m.Ctx, "%d 接收消息Unmarshal出错:%v", jSession.PositionId, err)
 		return
 		return
 	}
 	}
 
 
@@ -41,18 +41,18 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
 			Content:    req.Prompt,
 			Content:    req.Prompt,
 			Type:       1,
 			Type:       1,
 			Refer:      req.Href,
 			Refer:      req.Href,
-			PersonId:   jSession.AccountId,
+			PersonId:   jSession.PositionId,
 			CreateTime: time.Now().Format(date.Date_Full_Layout),
 			CreateTime: time.Now().Format(date.Date_Full_Layout),
 		})
 		})
 		// 校验是否在黑名单,黑名单不返回内容
 		// 校验是否在黑名单,黑名单不返回内容
-		if UserBlackList.CheckBlackList(m.Ctx, jSession.AccountId) {
+		if UserBlackList.CheckBlackList(m.Ctx, jSession.PositionId) {
 			return "", 0, nil
 			return "", 0, nil
 		}
 		}
 		var err error
 		var err error
 		reply, from := "", 0
 		reply, from := "", 0
 		errReply := func() string {
 		errReply := func() string {
 			// 校验问答频率
 			// 校验问答频率
-			if ChatLimit.GetBucket(m.Ctx, jSession.AccountId).TakeAvailable(1) == 0 {
+			if ChatLimit.GetBucket(m.Ctx, jSession.PositionId).TakeAvailable(1) == 0 {
 				return g.Cfg().MustGet(m.Ctx, "limit.exceedMsg").String()
 				return g.Cfg().MustGet(m.Ctx, "limit.exceedMsg").String()
 			}
 			}
 			// 问题敏感词过滤
 			// 问题敏感词过滤
@@ -79,7 +79,7 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
 			Type:       2,
 			Type:       2,
 			Actions:    gconv.Int(If(errReply == "", 1, 0)),
 			Actions:    gconv.Int(If(errReply == "", 1, 0)),
 			QuestionId: questionId,
 			QuestionId: questionId,
-			PersonId:   jSession.AccountId,
+			PersonId:   jSession.PositionId,
 			Item:       from,
 			Item:       from,
 			CreateTime: time.Now().Format(date.Date_Full_Layout),
 			CreateTime: time.Now().Format(date.Date_Full_Layout),
 		})
 		})