123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- package service
- import (
- "github.com/gogf/gf/v2/container/gvar"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/os/gctx"
- "github.com/gogf/gf/v2/util/gconv"
- "log"
- "regexp"
- "strings"
- )
- var (
- clearPatterns = g.Config().MustGet(gctx.New(), "clearPatterns").Strings()
- bidCommonwealth_blacklistPatterns = g.Config().MustGet(gctx.New(), "bidCommonwealth.blacklistPatterns").Strings()
- bidCommonwealth_whitelistPatterns = g.Config().MustGet(gctx.New(), "bidCommonwealth.whitelistPatterns").Strings()
- bidCommonwealth_modelPatterns = g.Config().MustGet(gctx.New(), "bidCommonwealth.modelPatterns").Strings()
- bidCommonwealth_firstWinnerOrder = g.Config().MustGet(gctx.New(), "bidCommonwealth.firstWinnerOrder").String()
- quoteModeRules = g.Config().MustGet(gctx.New(), "quoteMode.rules").Maps()
- quoteMode_modelPatterns = g.Config().MustGet(gctx.New(), "quoteMode.modelPatterns").Strings()
- allQuoteMode = map[string]bool{}
- showOnlyOnce = [][]string{}
- )
- func init() {
- for _, v := range g.Config().MustGet(gctx.New(), "bidCommonwealth.showOnlyOnce").Array() {
- showOnlyOnce = append(showOnlyOnce, gconv.Strings(v))
- }
- for _, v := range quoteModeRules {
- vv := gvar.New(v).MapStrVar()
- allQuoteMode[vv["mode"].String()] = true
- }
- }
- type Rule struct{}
- // 判断是否是联合体中标
- func (r *Rule) Execute(b *BidInfo) (bool, string, int, map[string]interface{}) {
- bc := r.bidCommonwealth(b)
- quoteMode := r.quoteMode(b)
- if bc == -2 && quoteMode == "大模型识别" {
- _, quoteMode, bc, _ = (&Model{}).Do(b, 2)
- } else if bc == -2 {
- _, _, bc, _ = (&Model{}).Do(b, 3)
- } else if quoteMode == "大模型识别" {
- _, quoteMode, _, _ = (&Model{}).Do(b, 1)
- }
- if (quoteMode == "" || quoteMode == "无法识别") && b.Bidamount > 0 {
- quoteMode = "整体报价模式"
- }
- log.Println(b.Id, "规则", "报价模式", quoteMode, "中标联合体", bc)
- return true, quoteMode, bc, nil
- }
- // 识别中标联合体
- func (r *Rule) quoteMode(b *BidInfo) string {
- for _, line := range strings.Split(b.Detail, "\n") {
- for _, v := range quoteModeRules {
- vv := gvar.New(v).MapStrVar()
- if r.matchAnyPattern(line, vv["patterns"].Strings()) {
- return vv["mode"].String()
- }
- }
- }
- if r.matchAnyPattern(b.Detail, quoteMode_modelPatterns) {
- return "大模型识别"
- }
- return ""
- }
- // 识别中标联合体
- func (r *Rule) bidCommonwealth(b *BidInfo) int {
- if len(b.WinnerOrder) > 0 {
- if regexp.MustCompile(bidCommonwealth_firstWinnerOrder).MatchString(b.WinnerOrder[0]) {
- return 1
- }
- return -1
- }
- for _, v := range strings.Split(b.KvText, "\n") {
- if r.matchAnyPattern(v, bidCommonwealth_whitelistPatterns) {
- return 1
- }
- }
- v := b.Detail
- // Step 1: 排除黑名单
- if r.matchAnyPattern(v, bidCommonwealth_blacklistPatterns) {
- return -1
- }
- if r.matchOnlyOnce(v) {
- return 1
- }
- // Step 2: 精准匹配白名单
- if r.matchAnyPattern(v, bidCommonwealth_whitelistPatterns) {
- return 1
- }
- // Step 3: 检查“中标”附近是否有“联合体”
- index := strings.Index(v, "中标")
- if index != -1 {
- start := max(0, index-50)
- end := min(len(v), index+50)
- contextAroundWin := v[start:end]
- if strings.Contains(contextAroundWin, "联合体") {
- return 1
- }
- }
- if r.matchAnyPattern(v, bidCommonwealth_modelPatterns) {
- return -2
- }
- return -1
- }
- // 匹配任意模式
- func (r *Rule) matchAnyPattern(text string, patterns []string) bool {
- for _, pattern := range patterns {
- if strings.HasPrefix(pattern, "全部包含:") {
- vs := strings.Split(strings.TrimPrefix(pattern, "全部包含:"), "+")
- index := 0
- for _, v := range vs {
- if strings.Contains(text, v) {
- index++
- }
- }
- if index == len(vs) {
- log.Println(pattern)
- return true
- }
- continue
- }
- if matched, _ := regexp.MatchString(pattern, text); matched {
- log.Println(pattern)
- return true
- }
- }
- return false
- }
- func (r *Rule) matchOnlyOnce(text string) bool {
- for _, v := range showOnlyOnce {
- count := 0
- for _, vv := range v {
- if len(regexp.MustCompile(vv).FindAllString(text, -1)) != 1 {
- break
- }
- count++
- }
- if count > 0 && count == len(v) {
- return true
- }
- }
- return false
- }
|