123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- 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/internal/svc"
- "app.yhyue.com/moapp/jyInfo/rpc/common/type/common"
- cm "app.yhyue.com/moapp/jybase/common"
- "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),
- }
- }
- func (l *SensitiveMethodLogic) SensitiveMethod(in *common.SensitiveRequest) (*common.SensitiveResponse, error) {
- var (
- resp common.SensitiveResponse
- //isSensitive 是否有敏感词 isPublishInfo招标信息是否需要自动发布 isPublishSup 供应信息是否需要自动发布
- isSensitive, isPublishInfo, isPublishSup bool
- )
- upData := make(map[string]interface{})
- query := make(map[string]interface{})
- 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["status"]) != "200" {
- msg = append(msg, "附件校验敏感词失败")
- } else if s, ok := vs["sensitive"]; ok && s != nil && len(s.([]string)) > 0 {
- sensitives, _ := vs["sensitive"].([]string)
- msg = sensitives
- } else {
- continue
- }
- sensitiveAttach[k] = msg
- }
- if in.Title != nil || in.Detail != nil || sensitiveAttach != nil {
- 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 sensitiveAttach != nil {
- upData["sensitive_attach"] = mc.MapToJson(sensitiveAttach)
- }
- if in.AttachTxt != "" {
- upData["discern_attach"] = in.AttachTxt
- }
- log.Println("敏感词回调参数in:", in)
- 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 {
- 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
- }
- }
- if !md.Mysql.Update("information", query, upData) {
- log.Println("调用信息发布成功,更新信息失败", query, upData)
- resp.ErrCode = 1
- resp.ErrMsg = "调用nsq发布信息成功,更新信息失败"
- }
- }
- 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 {
- 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"]
- if !model.SaveSupplyInfo(entName, supInfo) {
- resp.ErrCode = 1
- resp.ErrMsg = "调用SaveSupplyInfo失败,供应信息发布失败"
- break
- }
- }
- if !md.Mysql.Update("supply_info", query, upData) {
- log.Println("调用信息发布成功,更新信息失败", query, upData)
- resp.ErrCode = 1
- resp.ErrMsg = "调用信息发布成功,更新信息失败"
- }
- }
- default:
- resp.ErrCode = 1
- resp.ErrMsg = "信息类型错误"
- }
- return &resp, nil
- }
|