|
@@ -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:"答案"`
|