wangshan hace 3 años
padre
commit
c7292802dd
Se han modificado 2 ficheros con 59 adiciones y 21 borrados
  1. 20 21
      rpc/common/internal/logic/sensitivemethodlogic.go
  2. 39 0
      rpc/util/infofilter.go

+ 20 - 21
rpc/common/internal/logic/sensitivemethodlogic.go

@@ -65,42 +65,42 @@ func (l *SensitiveMethodLogic) SensitiveMethod(in *common.SensitiveRequest) (*co
 	if in.AttachTxt != "" {
 		upData["discern_attach"] = in.AttachTxt
 	}
+	//当前信息是否已被删除 默认:false;删除:true
+	isDel := false
 	query["id"] = in.Id
 	upData["status"] = 2
 	switch in.MsgType {
 	case "1", "2": //招标信息
 		data := md.Mysql.FindOne("information", query, "", "")
 		if data != nil && len(*data) > 0 {
-			isDel := cm.IntAll((*data)["is_del"]) == 1
-			//感觉没有必要
-			if !isDel {
-				delete(upData, "status")
-			} else if isPublishInfo {
+			//是否已被删除
+			isDel = cm.IntAll((*data)["is_del"]) == -1
+			//未删除 且 不用人工审核 直接入消息队列 进行发布流程
+			if !isDel && isPublishInfo {
 				upData["status"] = 3
 				upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
 				upData["review_desc"] = "自动审批通过"
 				//调用发布功能
 				nsq, err := util.NewNsqInfo(md.NsqConfig.Ip, md.NsqConfig.Topic, in.Id, "2", in.MsgType, false, *data)
 				if err != nil || nsq.NsqPushInfo() != nil {
-					resp.ErrCode = 1
-					resp.ErrMsg = "发布nsq失败"
-					break
+					resp.ErrCode = -2
+					resp.ErrMsg = "发布信息:信息入nsq消息队列失败"
+					//break
 				}
 			}
-
+			//修改此信息敏感词过滤结果
 			if !md.Mysql.Update("information", query, upData) {
-				resp.ErrCode = 1
-				resp.ErrMsg = "调用nsq发布信息成功,更新信息失败"
+				resp.ErrCode = -1
+				resp.ErrMsg = resp.ErrMsg + "敏感词过滤成功,更新库数据信息失败"
 			}
 		}
 	case "3": //供应信息
 		data := md.Mysql.FindOne("supply_info", query, "", "")
 		if data != nil && len(*data) > 0 {
-			isDel := cm.IntAll((*data)["is_del"]) == 1
-			//感觉没有必要
-			if !isDel {
-				delete(upData, "status")
-			} else if isPublishSup {
+			//是否已被删除
+			isDel = cm.IntAll((*data)["is_del"]) == -1
+			//信息未被删除 且 不用人工审核 直接进入es 发布信息
+			if !isDel && isPublishSup {
 				upData["status"] = 3
 				upData["published"] = 2
 				upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
@@ -116,19 +116,18 @@ func (l *SensitiveMethodLogic) SensitiveMethod(in *common.SensitiveRequest) (*co
 				supInfo["province"] = (*data)["province"]
 				supInfo["city"] = (*data)["city"]
 				if !model.SaveSupplyInfo(entName, supInfo) {
-					resp.ErrCode = -1
-					resp.ErrMsg = "调用SaveSupplyInfo失败,供应信息发布失败"
-					break
+					resp.ErrCode = -3
+					resp.ErrMsg = "供应信息: 调用SaveSupplyInfo 信息发布失败"
 				}
 			}
 
 			if !md.Mysql.Update("supply_info", query, upData) {
 				resp.ErrCode = -1
-				resp.ErrMsg = "调用信息发布成功,更新信息失败"
+				resp.ErrMsg = resp.ErrMsg + "供应信息:敏感词过滤成功,更新库信息状态失败"
 			}
 		}
 	default:
-		resp.ErrCode = -2
+		resp.ErrCode = -1
 		resp.ErrMsg = "信息类型错误"
 	}
 

+ 39 - 0
rpc/util/infofilter.go

@@ -0,0 +1,39 @@
+package util
+
+import "time"
+
+type InfoFilterStruct struct {
+	FType int    //1:敏感词过滤;2:信息发布
+	FId   string //信息id
+}
+
+var InfoFilterC chan *InfoFilterStruct
+
+//初始化协程信息 守护协程数量   通道缓存大小
+func initFilter(processNum, chanLen int) {
+	InfoFilterC = make(chan *InfoFilterStruct, chanLen)
+	for i := 0; i < processNum; i++ {
+		go infoHandle()
+	}
+}
+
+//信息处理逻辑
+func infoHandle() {
+	for {
+		select {
+		case data := <-InfoFilterC:
+			switch data.FType {
+			case 1:
+				//信息入nsq 敏感词过滤通道失败
+			case 2:
+				//敏感词过滤成功 但敏感词结果未入库
+			case 3:
+				//信息入nsq 发布通道失败
+			}
+		case <-time.After(30 * time.Second):
+			//半分钟未处理  休眠半小时后再处理
+			time.Sleep(30 * 60 * time.Second)
+			continue
+		}
+	}
+}