Browse Source

添加 行业分类 默认值

wcc 1 năm trước cách đây
mục cha
commit
7ce363e7f3
3 tập tin đã thay đổi với 89 bổ sung11 xóa
  1. 36 0
      src/task/task.go
  2. 43 11
      src/util/charge_rule.go
  3. 10 0
      src/util/util_test.go

+ 36 - 0
src/task/task.go

@@ -844,6 +844,42 @@ func NewTaskRunAll(tt *TTask, budp bool, mapInfo map[string]interface{}) int {
 							SMap.Map["topscope_dy"] = u.RemoveDuplicateString(tops)
 						}
 					}
+					//3.针对行业分类,添加默认值
+					if mapInfo["stype"] == "hangye" || strings.TrimSpace(tt.S_name) == "行业分类" {
+						/**没有一级分类是,默认一级 '其它',二级'其它_其它'
+						**/
+						//tops := SMap.Map["topscopeclass"]
+						//subs := SMap.Map["subscopeclass"]
+						resultSubs := make([]string, 0)
+						resultTobs := make([]string, 0)
+						//存在行业一级分类
+						if tops, ok := SMap.Map["topscopeclass"]; ok {
+							if topps, ok2 := tops.([]string); ok2 {
+								for _, v := range topps {
+									top := util.ObjToString(v)
+									if top != "" {
+										resultTobs = append(resultTobs, top)
+									}
+								}
+							}
+							if subs, ok3 := SMap.Map["subscopeclass"]; ok3 {
+								if subbs, ok4 := subs.([]string); ok4 {
+									for _, v := range subbs {
+										sub := util.ObjToString(v)
+										if sub != "" {
+											resultSubs = append(resultSubs, sub)
+										}
+									}
+								}
+							}
+							newTops, newSubs := u.ProcessTopscopeclass(resultTobs, resultSubs)
+							SMap.Map["topscopeclass"] = newTops
+							SMap.Map["subscopeclass"] = newSubs
+						} else {
+							SMap.Map["topscopeclass"] = []string{"其它"}
+							SMap.Map["subscopeclass"] = []string{"其它"}
+						}
+					}
 
 					//追加时处理,//更新字段 I_fieldUpdate  0:覆盖 1:追加
 					if tt.I_fieldUpdate == 1 && tt.I_multiclass == 1 {

+ 43 - 11
src/util/charge_rule.go

@@ -9,7 +9,7 @@ import (
 // 审批数据判断字段,包含三个以上属于拟建
 //var spFields = []string{"approvecode", "owner", "projectaddr", "project_scale_info", "projectname"}
 
-//ChargeDetailResult 检测内容是否符合 toptype=结果
+// ChargeDetailResult 检测内容是否符合 toptype=结果
 func ChargeDetailResult(detail string) bool {
 	if ChargeDetailZB(detail) || ChargeDetailCJ(detail) {
 		return true
@@ -17,7 +17,7 @@ func ChargeDetailResult(detail string) bool {
 	return false
 }
 
-//ChargeDetailCJ 检测内容是否符合 toptype=结果;subtype=成交
+// ChargeDetailCJ 检测内容是否符合 toptype=结果;subtype=成交
 func ChargeDetailCJ(detail string) bool {
 	var reg = regexp.MustCompile("(成交单位|成交人|成交供应商)[::][\\s ]*(.{2,25}(公司))")
 	//含有 投标截止时间 关键词,代表不是结果,需要排除
@@ -35,7 +35,7 @@ func ChargeDetailCJ(detail string) bool {
 	return false
 }
 
-//ChargeDetailZB 检测内容是否符合 toptype=结果;subtype=中标
+// ChargeDetailZB 检测内容是否符合 toptype=结果;subtype=中标
 func ChargeDetailZB(detail string) bool {
 	var reg = regexp.MustCompile("(中标人单位名称|中标供应商|中标供应商名称|中标人名称|中签单位名称|中签单位|中标商家)[::][\\s ]*(.{2,25}(公司|单位|局|厅))")
 	var reg2 = regexp.MustCompile("(投标截止时间)")
@@ -48,7 +48,7 @@ func ChargeDetailZB(detail string) bool {
 	return false
 }
 
-//GetJyKey 免费订阅:o_jy.a_key.key/appendkey
+// GetJyKey 免费订阅:o_jy.a_key.key/appendkey
 func GetJyKey(data map[string]interface{}) (res []interface{}) {
 	// 获取o_jy.a_key.key的值
 	if ojy, ok := data["o_jy"].(map[string]interface{}); ok {
@@ -69,7 +69,7 @@ func GetJyKey(data map[string]interface{}) (res []interface{}) {
 	return
 }
 
-//GetVipKey 超级订阅:o_vipjy.a_items.a_key.key/appendkey
+// GetVipKey 超级订阅:o_vipjy.a_items.a_key.key/appendkey
 func GetVipKey(data map[string]interface{}) (res []interface{}) {
 	//o_vipjy.a_items.a_key.key
 	if o_vipjy, ok := data["o_vipjy"].(map[string]interface{}); ok {
@@ -96,7 +96,7 @@ func GetVipKey(data map[string]interface{}) (res []interface{}) {
 	return
 }
 
-//GetMemberKey 大会员订阅:o_member_jy.a_items.a_key.key/appendkey
+// GetMemberKey 大会员订阅:o_member_jy.a_items.a_key.key/appendkey
 func GetMemberKey(data map[string]interface{}) (res []interface{}) {
 	//o_member_jy.a_items.a_key.key
 	if o_member_jy, ok := data["o_member_jy"].(map[string]interface{}); ok {
@@ -123,7 +123,7 @@ func GetMemberKey(data map[string]interface{}) (res []interface{}) {
 	return
 }
 
-//RemoveDuplicates 过滤重复数据
+// RemoveDuplicates 过滤重复数据
 func RemoveDuplicates(elements []interface{}) []interface{} {
 	encountered := map[interface{}]bool{}
 	result := []interface{}{}
@@ -138,7 +138,7 @@ func RemoveDuplicates(elements []interface{}) []interface{} {
 	return result
 }
 
-//GetUserKeys 获取用户订阅关键词
+// GetUserKeys 获取用户订阅关键词
 func GetUserKeys(data map[string]interface{}) (res []interface{}) {
 	keys := GetJyKey(data)
 	vkeys := GetVipKey(data)
@@ -152,7 +152,7 @@ func GetUserKeys(data map[string]interface{}) (res []interface{}) {
 	return
 }
 
-//RemoveDuplicateString 去除重复字符串
+// RemoveDuplicateString 去除重复字符串
 func RemoveDuplicateString(arr []string) []string {
 	encountered := map[string]bool{}
 	result := []string{}
@@ -171,7 +171,7 @@ func RemoveDuplicateString(arr []string) []string {
 	return result
 }
 
-//DealYuce 处理一级是预告,符合条件到采购意向
+// DealYuce 处理一级是预告,符合条件到采购意向
 func DealYuce(data string) bool {
 	//标题含有招标计划,并且含有 预公告或者预公示,分类划分到采购意向
 	re1 := strings.Contains(data, "招标计划")
@@ -184,7 +184,7 @@ func DealYuce(data string) bool {
 	return false
 }
 
-//IsPurchasingIntent 采购意向判断处理,符合采购意向返回true
+// IsPurchasingIntent 采购意向判断处理,符合采购意向返回true
 func IsPurchasingIntent(data map[string]interface{}) bool {
 	if channel, ok := data["channel"]; ok {
 		if strings.Contains(channel.(string), "项目登记") {
@@ -203,3 +203,35 @@ func IsPurchasingIntent(data map[string]interface{}) bool {
 
 	return false
 }
+
+// ProcessTopscopeclass 处理行业分类
+func ProcessTopscopeclass(tops, subs []string) ([]string, []string) {
+	// 去除 tops 中每个元素末尾的不固定字符
+	cleanedTops := make([]string, 0)
+	for _, top := range tops {
+		parts := strings.Split(top, "")
+		cleanedTop := strings.Join(parts[:len(parts)-1], "")
+		cleanedTops = append(cleanedTops, cleanedTop)
+	}
+
+	// 用于标记 cleanedTops 中已存在于 subs 的元素
+	presentMap := make(map[string]bool)
+
+	// 遍历 subs 数组,标记已存在的 cleanedTops 元素
+	for _, sub := range subs {
+		for _, top := range cleanedTops {
+			if strings.Contains(sub, top) {
+				presentMap[top] = true
+			}
+		}
+	}
+
+	// 补充缺失的 cleanedTops 元素到 subs 中
+	for _, top := range cleanedTops {
+		if !presentMap[top] {
+			subs = append(subs, top+"_其它")
+		}
+	}
+
+	return tops, subs
+}

+ 10 - 0
src/util/util_test.go

@@ -295,3 +295,13 @@ func TestIsPurchasingIntent(t *testing.T) {
 	}
 	fmt.Println("data5", IsPurchasingIntent(data5))
 }
+
+func TestProcessTopscopeclass(t *testing.T) {
+	tops := []string{"建筑工程", "水利水电", "能源化工", "弱电安防"}
+	subs := []string{}
+
+	newTops, newSubs := ProcessTopscopeclass(tops, subs)
+
+	fmt.Println("Tops:", newTops)
+	fmt.Println("Subs:", newSubs)
+}