Selaa lähdekoodia

修复 没有匹配一级分类,二级有默认值的bug

wcc 1 vuosi sitten
vanhempi
commit
9c00ffc19a
2 muutettua tiedostoa jossa 77 lisäystä ja 20 poistoa
  1. 50 0
      src/task/task.go
  2. 27 20
      src/task/updatetask.go

+ 50 - 0
src/task/task.go

@@ -1,12 +1,16 @@
 package task
 
 import (
+	"bytes"
+	"context"
 	"encoding/csv"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"log"
 	mu "mfw/util"
 	"net"
+	"net/http"
 	"os"
 	"qfw/util"
 	"reflect"
@@ -1663,3 +1667,49 @@ func UdpRunProjectForecast(sid, eid string) {
 	}
 	tools.Udpclient.WriteUdp(by, mu.OP_TYPE_DATA, addr)
 }
+
+// SendAi 调用大模型招标分类
+func SendAi(data map[string]interface{}, url string) (res map[string]interface{}) {
+	// 设置 2 秒的超时
+	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+	defer cancel()
+
+	//url := "http://192.168.3.109:16688"
+	jsonData, err := json.Marshal(data)
+	if err != nil {
+		fmt.Println("JSON marshal error:", err)
+		return
+	}
+
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
+	if err != nil {
+		fmt.Println("Request error:", err)
+		return
+	}
+
+	req.Header.Set("Content-Type", "application/json")
+
+	// 将请求与上下文关联
+	req = req.WithContext(ctx)
+
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		// 使用 errors.Is 检查错误是否是超时错误
+		if errors.Is(err, context.DeadlineExceeded) {
+			fmt.Println("Request timed out")
+			return
+		}
+		fmt.Println("Request error:", err)
+		return
+	}
+	defer resp.Body.Close()
+
+	err = json.NewDecoder(resp.Body).Decode(&res)
+	if err != nil {
+		fmt.Println("Response decoding error:", err)
+		return
+	}
+
+	return
+}

+ 27 - 20
src/task/updatetask.go

@@ -32,7 +32,7 @@ type LuaScript struct {
 
 var s map[string]*LuaScript
 
-//加载lua
+// 加载lua
 func LoadLua() {
 	filepath.Walk("./lua", func(path string, info os.FileInfo, err error) error {
 		if err != nil {
@@ -79,7 +79,7 @@ func NewLuaScript(name, luafile string) (ls *LuaScript) {
 	return ls
 }
 
-//lua处理数据
+// lua处理数据
 func Dealdata(srcript *LuaScript, data map[string]interface{}, field string) map[string]interface{} {
 	tab := MapToLuaTable(srcript.L, data)
 	if err := srcript.L.CallByParam(lua.P{
@@ -159,7 +159,7 @@ func maptoarr(datamap map[string]interface{}) (dataarr []string) {
 	return dataarr
 }
 
-//NewAnalyTask 初始化任务mgo配置信息,共用加载任务
+// NewAnalyTask 初始化任务mgo配置信息,共用加载任务
 func NewAnalyTask(_id, s_mgourl, s_mgodb, s_coll string, i_poolsize int) (res bool, task *TTask, msg string) {
 	defer tools.Catch()
 	task = TaskMap[_id] //从加载好的任务集合中取单个任务
@@ -209,14 +209,15 @@ func NewAnalyTask(_id, s_mgourl, s_mgodb, s_coll string, i_poolsize int) (res bo
 	return
 }
 
-//NewClassificationRun 共用识别过程
+// NewClassificationRun 共用识别过程
 func NewClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap {
 	SMap := tools.NewSortMap()
 	//tmpSavefield := map[string]interface{}{}
-	fflag := map[string][]string{} //标志父类从属关系
-	rulval := map[string]string{}  //存储过滤记录
-	class := tt.Class              //获取任务中的多个分类
-
+	fflag := map[string][]string{}    //标志父类从属关系
+	rulval := map[string]string{}     //存储过滤记录
+	class := tt.Class                 //获取任务中的多个分类
+	topMap := make(map[string]string) //用来存储,表示一级是否有数据,为了解决不设置一级默认值,直接设置二级默认值导致没有一级有二级默认值
+	// topMap["top"]= "toptype"
 	if class != nil && len(class) > 0 {
 		/**
 		一级分类匹配到title,二级标题分类成功匹配到招标或者竞谈,并且detail中含有合同金额等其他字段,
@@ -254,8 +255,13 @@ func NewClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap
 					}
 				}
 			}
-			cid := c.Cid     //类id
-			s_pid := c.S_pid //父类id
+			cid := c.Cid       //类id
+			s_pid := c.S_pid   //父类id
+			if c.S_pid == "" { //表示一级分类字段
+				topMap["top"] = c.S_savefield
+			} else {
+				topMap["sub"] = c.S_savefield
+			}
 			//s_fields := c.S_fields     //识别字段
 			savefield := c.S_savefield //保存字段,toptype
 			// if tt.I_multiclass == 0 {  //单分类临时记录保存字段
@@ -432,7 +438,8 @@ func NewClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap
 			}
 			//设置默认值
 			//log.Println("smp", SMap.Map, SMap.Keys)
-			if savefield != "" && SMap.Map[savefield] == nil && c.S_default != "" {
+			//一级分类打上了,才会设置二级默认值
+			if savefield != "" && SMap.Map[savefield] == nil && c.S_default != "" && SMap.Map[topMap["top"]] != nil {
 				if tt.I_multiclass == 0 { //单分类
 					//if savefield == "buyerclass" && util.ObjToString(tmp["buyer"]) == "" { //buyer不存在时,无buyerclass字段
 					//	return SMap
@@ -708,7 +715,7 @@ func ReSub(tt *TTask, tmp map[string]interface{}, top string) *tools.SortMap {
 	return SMap
 }
 
-//标签识别过程
+// 标签识别过程
 func TagClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap {
 	SMap := tools.NewSortMap()
 	rulval := map[string]string{} //存储过滤记录
@@ -768,7 +775,7 @@ func TagClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap
 	return SMap
 }
 
-//附件识别过程
+// 附件识别过程
 func FileClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap {
 	SMap := tools.NewSortMap()
 	if tmp["projectinfo"] == nil { //没有附件字段直接return
@@ -938,7 +945,7 @@ func FileClassificationRun(tt *TTask, tmp map[string]interface{}) *tools.SortMap
 
 var rc *regexp.Regexp
 
-//前置过滤
+// 前置过滤
 func PreFilter(text, taskPrerule string) string {
 	defer tools.Catch()
 	if len(taskPrerule) > 0 && text != "" {
@@ -954,7 +961,7 @@ func PreFilter(text, taskPrerule string) string {
 	return text
 }
 
-//存放测试的数据
+// 存放测试的数据
 var UPDATE = &TestList{
 	Count: map[string][]int{},
 }
@@ -1128,7 +1135,7 @@ func LoadUpdateTask(_id, s_mgourl, s_mgodb, s_coll, i_poolsize, s_esurl, s_esdb,
 	return
 }
 
-//DFA识别规则
+// DFA识别规则
 func DFAAnalyRules(text string, rules []interface{}) (bool, []string) {
 	var arr []string
 	//log.Println("len===", len(rules))
@@ -1185,7 +1192,7 @@ func DFAAnalyRules(text string, rules []interface{}) (bool, []string) {
 	return false, arr
 }
 
-//单独的标签识别规则
+// 单独的标签识别规则
 func TagDFAAnalyRules(text string, rules []interface{}) (res []string) {
 	defer util.Catch()
 	//util.Debug("len===", len(rules))
@@ -1213,7 +1220,7 @@ func TagDFAAnalyRules(text string, rules []interface{}) (res []string) {
 	return
 }
 
-//满足所有情况的DFA识别规则
+// 满足所有情况的DFA识别规则
 func DFAAnalyRules_All(text string, rules []interface{}, multiple bool) (bool, []string) {
 	var res []string
 	success := false
@@ -1280,7 +1287,7 @@ func DFAAnalyRules_All(text string, rules []interface{}, multiple bool) (bool, [
 	return success, res
 }
 
-//规则测试,只匹配一个,匹配一个成功后返回
+// 规则测试,只匹配一个,匹配一个成功后返回
 func DFAAnalyRulesTest(text string, rules []interface{}) (bool, bool, [][]string, int) {
 	arr := make([][]string, len(rules))
 	for j, r := range rules {
@@ -1339,7 +1346,7 @@ func DFAAnalyRulesTest(text string, rules []interface{}) (bool, bool, [][]string
 	return false, false, arr, -1
 }
 
-//规则测试,返回所有匹配到的规则
+// 规则测试,返回所有匹配到的规则
 func DFAAnalyRulesTest2(text string, rules []interface{}) (bool, bool, [][]string, int) {
 	isok := false
 	arr := make([][]string, len(rules))