123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- package logic
- import (
- md "app.yhyue.com/moapp/jyInfo/rpc/model"
- model "app.yhyue.com/moapp/jyInfo/rpc/model/es"
- "app.yhyue.com/moapp/jyInfo/rpc/util"
- mc "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/redis"
- "context"
- "fmt"
- "log"
- "strings"
- "time"
- "app.yhyue.com/moapp/jyInfo/rpc/common/commoninfo"
- "app.yhyue.com/moapp/jyInfo/rpc/common/internal/svc"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type SensitiveMethodLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewSensitiveMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SensitiveMethodLogic {
- return &SensitiveMethodLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- //数据组rpc回调,敏感词过滤后结果
- func (l *SensitiveMethodLogic) SensitiveMethod(in *commoninfo.SensitiveRequest) (*commoninfo.SensitiveResponse, error) {
- var (
- resp commoninfo.SensitiveResponse
- //isSensitive 是否有敏感词 isPublishInfo招标信息是否需要自动发布 isPublishSup 供应信息是否需要自动发布
- isSensitive, isPublishInfo, isPublishSup, isAttach bool
- )
- log.Println("接收到敏感词回调----------------------", in)
- upData := make(map[string]interface{})
- query := make(map[string]interface{})
- attachments := make(map[string]interface{})
- if in.Attachments != "" {
- attachments = mc.StringToMap(in.Attachments)
- }
- sensitiveAttach := make(map[string]interface{})
- for k, v := range attachments {
- vs := mc.StructToMapMore(v)
- var msg []string
- if mc.InterfaceToStr(vs["state"]) != "200" {
- if mc.InterfaceToStr(vs["state"]) == "300" {
- msg = append(msg, "敏感词校验附件下载错误")
- } else if mc.InterfaceToStr(vs["state"]) == "400" {
- msg = append(msg, "敏感词校验附件解析错误")
- } else if mc.InterfaceToStr(vs["state"]) == "500" {
- msg = append(msg, "敏感词校验附件类型不支持")
- } else {
- msg = append(msg, "敏感词识别失败")
- }
- } else if s, ok := vs["sensitive"]; ok && s != nil && len(s.([]interface{})) > 0 {
- msg = mc.ObjArrToStringArr(vs["sensitive"].([]interface{}))
- }
- msgStr := strings.Join(msg, ",")
- if msgStr != "" {
- isAttach = true
- log.Println("附件敏感词:", msgStr)
- }
- sensitiveAttach[k] = msgStr
- }
- if in.Title != nil || in.Detail != nil || isAttach {
- isSensitive = true
- }
- if !isSensitive && !md.Sensitive.Information {
- isPublishInfo = true
- }
- if !isSensitive && !md.Sensitive.SupplyInfo {
- isPublishSup = true
- }
- if in.Title != nil {
- upData["sensitive_title"] = strings.Join(in.Title, ",")
- }
- if in.Detail != nil {
- upData["sensitive_detail"] = strings.Join(in.Detail, ",")
- }
- if isAttach {
- upData["sensitive_attach"] = mc.MapToJson(sensitiveAttach)
- }
- if in.AttachTxt != "" && in.MsgType != "3" {
- upData["discern_attach"] = in.AttachTxt
- }
- //当前信息是否已被删除 默认:false;删除:true
- isDel := false
- query["id"] = in.Id
- upData["status"] = 2
- switch in.MsgType {
- case "1", "2", "4", "5", "6": //招标信息
- data := md.Mysql.FindOne("information", query, "", "")
- if data != nil && len(*data) > 0 {
- //是否已被删除
- isDel = mc.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 = -2
- resp.ErrMsg = "发布信息:信息入nsq消息队列失败"
- //break
- }
- }
- //修改此信息敏感词过滤结果
- if !md.Mysql.Update("information", query, upData) {
- log.Println("调用信息发布成功,更新信息失败", query, upData)
- resp.ErrCode = -1
- resp.ErrMsg = resp.ErrMsg + "敏感词过滤成功,更新库数据信息失败"
- }
- }
- case "3": //供应信息
- data := md.Mysql.FindOne("supply_info", query, "", "")
- if data != nil && len(*data) > 0 {
- //是否已被删除
- isDel = mc.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")
- upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
- upData["review_desc"] = "自动审批通过"
- //调用发布功能
- entNameKye := fmt.Sprintf("userEntName_%s_%s_%s", (*data)["user_id"], in.Id, in.MsgType)
- entName := redis.GetStr("other", entNameKye)
- supInfo := make(map[string]interface{})
- supInfo["id"] = (*data)["id"]
- supInfo["title"] = (*data)["title"]
- supInfo["detail"] = (*data)["detail"]
- supInfo["province"] = (*data)["province"]
- supInfo["city"] = (*data)["city"]
- supInfo["ent_id"] = (*data)["ent_id"]
- validityTime := time.Now().Unix()
- if (*data)["validity_time"] != nil && (*data)["validity_time"] != "" {
- validity, _ := time.ParseInLocation("2006-01-02 15:04:05", mc.InterfaceToStr((*data)["validity_time"]), time.Local)
- validityTime = validity.Unix()
- }
- supInfo["validity_time"] = validityTime
- if !model.SaveSupplyInfo(entName, supInfo) {
- log.Println("调用信息发布成功,更新信息失败", entName, supInfo)
- resp.ErrCode = -3
- resp.ErrMsg = "供应信息: 调用SaveSupplyInfo 信息发布失败"
- }
- }
- if !md.Mysql.Update("supply_info", query, upData) {
- log.Println("调用信息发布成功,更新信息失败", query, upData)
- resp.ErrCode = -1
- resp.ErrMsg = resp.ErrMsg + "供应信息:敏感词过滤成功,更新库信息状态失败"
- }
- }
- default:
- resp.ErrCode = -1
- resp.ErrMsg = "信息类型错误"
- }
- return &resp, nil
- }
|