123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package logic
- import (
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
- "app.yhyue.com/moapp/jyInfo/rpc/model"
- "app.yhyue.com/moapp/jyInfo/rpc/util"
- "context"
- "fmt"
- "log"
- "strings"
- "time"
- se "app.yhyue.com/moapp/jybase/encrypt"
- mc "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/redis"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type PublishInfoLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewPublishInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishInfoLogic {
- return &PublishInfoLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 发布信息
- func (l *PublishInfoLogic) PublishInfo(in *consumerinfo.PublishInfoReq) (*consumerinfo.PublishInfoResp, error) {
- res := consumerinfo.PublishInfoResp{}
- log.Println("信息发布in数据:", in)
- if in.MsgType == 8 && in.DeliveryAddress == "" {
- res.ErrCode = -1
- res.ErrMsg = "缺少交付地址"
- return &res, nil
- }
- //信息类型1:招标信息 2:采购信息 3:供应信息
- publishData := make(map[string]interface{})
- publishData["user_id"] = in.UserId //发布人用户ID
- publishData["phone"] = in.Phone //注册手机号
- publishData["title"] = in.Title //信息标题
- publishData["province"] = in.Province //项目省份
- if v, ok := (*model.PublishCity)[in.Province]; ok && v != "" {
- publishData["city"] = v
- } else {
- publishData["city"] = in.City
- } //项目城市
- publishData["detail"] = util.NewCut().ClearHtml(in.Detail) //正文信息
- publishData["create_time"] = time.Now().Format("2006-01-02 15:04:05") //申请时间
- publishData["attach"] = in.Attach //附件(多个附件逗号分割)
- publishData["contact_person"] = in.Contact.Person //联系人
- publishData["contact_phone"] = in.Contact.Phone //联系人电话
- publishData["is_del"] = 1 // 0:全部;1:未删除;-1:删除
- publishData["published"] = 1 // 0:全部;1:未发布;2:已发布
- publishData["type"] = mc.IntAll(in.MsgType) //1:招标信息|2:采购信息|3:供应信息
- publishData["ent_id"] = mc.IntAll(in.EntId)
- publishData["app_id"] = in.AppId
- publishData["ent_name"] = in.EntName
- // 0:全部;1:待审核;2:待人工审核(敏感词审核不通过||敏感词审核通过);3:自动审核通过;4:人工审核通过;-1:自动审核不通过(机构冻结);-2:人工审核不通过;
- publishData["status"] = 1
- switch in.MsgType {
- case 3:
- publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
- if in.Deadline != "" {
- publishData["validity_time"] = in.Deadline //信息有效期
- }
- case 8: //阳光采购
- publishData["contact_overt"] = 1 //是否公开 默认不公开
- publishData["publishing_media"] = 1 //是否同意剑鱼发布平台 1 是 -1 否
- publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
- publishData["project_code"] = in.Code //项目编号
- publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
- publishData["buyer"] = in.Buyer //采购单位
- publishData["winner"] = in.Winner //中标单位
- if in.Budget != "" {
- publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
- }
- if in.Amount != "" {
- publishData["amount"] = mc.Float64All(in.Amount) //中标金额
- }
- default:
- if in.EntName == in.Buyer {
- publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
- } else {
- publishData["contact_overt"] = 0
- }
- publishData["publishing_media"] = in.JyPublishingMedia //是否同意剑鱼发布平台 1 是 -1 否
- publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
- publishData["related_id"] = mc.IntAll(se.SE.DecodeString(in.RelatedId)) //关联公告id
- publishData["project_code"] = in.Code //项目编号
- publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
- publishData["buyer"] = in.Buyer //采购单位
- publishData["winner"] = in.Winner //中标单位
- if in.Budget != "" {
- publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
- }
- if in.Amount != "" {
- publishData["amount"] = mc.Float64All(in.Amount) //中标金额
- }
- }
- id := model.Mysql.Insert("information", publishData)
- if id < 1 {
- res.ErrCode = -1
- res.ErrMsg = "信息保存失败"
- return &res, nil
- }
- var InfoId consumerinfo.PublishId
- InfoId.InformationId = se.SE.EncodeString(mc.InterfaceToStr(id)) //信息id加密
- res.PublishId = &InfoId
- appendInfo := make(map[string]interface{})
- if in.Title != "" {
- appendInfo["title"] = in.Title
- }
- if in.Detail != "" {
- appendInfo["detail"] = publishData["detail"]
- }
- if in.Attach != "" && in.Attach != "{}" {
- appendInfo["attach"] = mc.StringToMap(in.Attach)
- }
- log.Println("发送nsq敏感词信息", model.NsqConfig, appendInfo)
- nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr(id), "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
- if err != nil {
- log.Println("初始化NSQ信息失败", err.Error())
- res.ErrCode = -1
- res.ErrMsg = "信息发布失败"
- return &res, nil
- }
- if err = nsq.NsqPushInfo(); err != nil {
- log.Println("发送nsq敏感词信息失败nsq++++++++++++", model.NsqConfig, appendInfo, err.Error())
- res.ErrCode = -1
- res.ErrMsg = "信息发布失败"
- return &res, nil
- }
- if in.MsgType == 3 {
- entNameKye := fmt.Sprintf("userEntName_%s_%d_%d", in.UserId, id, in.MsgType)
- redis.Put("other", entNameKye, in.EntName, 3*24*60*60)
- }
- return &res, nil
- }
|