Przeglądaj źródła

wip:常见问题增加条件过滤

wangkaiyue 2 lat temu
rodzic
commit
e20030fb8f

+ 3 - 1
internal/controller/usuallyProblem.go

@@ -20,6 +20,8 @@ func (c *cUsuallyProblem) Method(ctx context.Context, req *v1.UsuallyProblemReq)
 		return nil, fmt.Errorf("无用户身份")
 	}
 	var list []string
-	list, err = model.Question.GetUsuallyProblem(ctx, model.GetScenario(req.Href), g.Config().MustGet(ctx, "chat.usuallyProblem", 5).Int())
+	req.Href = "https://jybx3-webtest.jydev.jianyu360.com/page_workDesktop/work-bench/page?aside=0&link=https%3A%2F%2Fjybx3-webtest.jydev.jianyu360.com%2Farticle%2Fcontent%2FABCY1xJfjwFLDYvRH95c3I%252FIjA%252FCj1gR2hxKzhQKyEeYGhzfRlUClI%253D.html%3Faside%3D0%26kds%3D%25E4%25BF%25A1%25E6%2581%25AF"
+
+	list, err = model.Question.GetUsuallyProblem(ctx, req.Href, g.Config().MustGet(ctx, "chat.usuallyProblem", 5).Int())
 	return &v1.QuestionRes{Data: list}, nil
 }

+ 49 - 2
internal/model/question.go

@@ -4,6 +4,7 @@ import (
 	"aiChat/utility"
 	"aiChat/utility/fsw"
 	"context"
+	"encoding/json"
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
@@ -52,20 +53,66 @@ func (r *BaseQuestion) ParseHistoryFsw() {
 	r.History = newHistory
 }
 
+type questionFilter struct {
+	HasBuyer  bool     `json:"hasBuyer" dc:"有采购单位"`
+	HasWinner bool     `json:"hasWinner" dc:"有中标单位"`
+	InfoType  InfoType `json:"infoType" dc:"信息类型"`
+}
+type InfoType map[string]bool
+
+func (t InfoType) Check(infoType string) bool {
+	if len(t) == 0 {
+		return false
+	}
+	if _, ok := t[infoType]; ok {
+		return true
+	}
+	return false
+}
+
 // GetUsuallyProblem 获取常见问题
-func (q *cQuestion) GetUsuallyProblem(ctx context.Context, scenario, limit int) (list []string, err error) {
+func (q *cQuestion) GetUsuallyProblem(ctx context.Context, href string, limit int) (list []string, err error) {
+	scenario, infoId := GetScenarioAndInfoId(href)
 	list = make([]string, 0, limit)
-	res, err := g.Model("ai_question_list").Ctx(ctx).Fields("question").
+	res, err := g.Model("ai_question_list").Ctx(ctx).Fields("question", "filter").
 		Where("status = 1 and source = ?", scenario).OrderDesc("create_time").OrderAsc("id").Limit(limit).All()
 	if err != nil {
 		return nil, err
 	}
+	hasWinner, hasBuyer, infoTypes := getInfo(infoId)
 	for _, m := range res.List() {
+		if m["filter"] != nil {
+			tFilter := questionFilter{}
+			if json.Unmarshal(gconv.Bytes(m["filter"]), &tFilter) != nil {
+				continue
+			}
+			if !((hasBuyer && tFilter.HasBuyer) ||
+				(hasWinner && tFilter.HasWinner) ||
+				len(infoTypes) > 0 && tFilter.InfoType.Check(infoTypes)) {
+				continue
+			}
+		}
 		list = append(list, gconv.String(m["question"]))
 	}
 	return
 }
 
+func getInfo(infoId string) (hasWinner, hasBuyer bool, infoTypes string) {
+	if infoId == "" {
+		return
+	}
+	res, ok := utility.MgoBidding.FindById(utility.BiddingConf.Collection, infoId, `{"buyer":1,"winner":1,"toptype":1}`)
+	if ok && res == nil || len(*res) == 0 {
+		res, _ = utility.MgoBidding.FindById(utility.BiddingConf.Collection, infoId, `{"buyer":1,"winner":1,"toptype":1}`)
+	}
+	if res != nil && len(*res) > 0 {
+		hasWinner = (*res)["winner"] != nil
+		hasBuyer = (*res)["winner"] != nil
+		infoTypes = gconv.String((*res)["toptype"])
+	}
+	return
+}
+
 type BusinessRes struct {
 	CheckMember int    `json:"check_member" dc:"是否校验大会员权限"`
 	Answer      string `json:"answer" dc:"答案"`

+ 1 - 0
internal/model/ws.go

@@ -35,6 +35,7 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
 		glog.Errorf(m.Ctx, "%d 接收消息Unmarshal出错:%v", jSession.PositionId, err)
 		return
 	}
+	req.Href = "https://jybx3-webtest.jydev.jianyu360.com/page_workDesktop/work-bench/page?aside=0&link=https%3A%2F%2Fjybx3-webtest.jydev.jianyu360.com%2Farticle%2Fcontent%2FABCY1xJfjwFLDYvRH95c3I%252FIjA%252FCj1gR2hxKzhQKyEeYGhzfRlUClI%253D.html%3Faside%3D0%26kds%3D%25E4%25BF%25A1%25E6%2581%25AF"
 	reply, replyId, errMsg := func() (string, int64, error) {
 		questionId := ChatHistory.Save(m.Ctx, &ChatRecord{
 			Content:    req.Prompt,

+ 10 - 0
manifest/config/config.yaml

@@ -37,6 +37,16 @@ redis:
   black:
     address: 192.168.3.149:1712
 
+mongodb:
+  address: "192.168.3.206:27002"
+  size: 5
+  dbName: "qfw_data"
+  replSet: ""
+  collection: "bidding"
+  collection_back": "bidding_back"
+  userName: "jyDevGroup"
+  password: "jy@DevGroup"
+
 database:
   default:
     link: "mysql:root:=PDT49#80Z!RVv52_z@tcp(192.168.3.217:4000)/base_service"

+ 39 - 0
utility/mongodb.go

@@ -0,0 +1,39 @@
+package utility
+
+import (
+	m "app.yhyue.com/moapp/jybase/mongodb"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gctx"
+)
+
+var (
+	MgoBidding  m.MongodbSim
+	BiddingConf mgoConf
+)
+
+type mgoConf struct {
+	Address         string
+	Size            int
+	DbName          string
+	ReplSet         string
+	UserName        string
+	Password        string
+	Collection      string
+	Collection_back string
+}
+
+func init() {
+	ctx := gctx.New()
+	_ = g.Cfg().MustGet(ctx, "mongodb").Struct(&BiddingConf)
+	MgoBidding = m.MongodbSim{
+		MongodbAddr: BiddingConf.Address,
+		Size:        BiddingConf.Size,
+		DbName:      BiddingConf.DbName,
+		ReplSet:     BiddingConf.ReplSet,
+		UserName:    BiddingConf.UserName,
+		Password:    BiddingConf.Password,
+	}
+	MgoBidding.InitPool()
+	g.Log().Info(ctx, "初始化mongodb")
+
+}