publishinfologic.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
  4. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  5. "app.yhyue.com/moapp/jyInfo/rpc/model"
  6. "app.yhyue.com/moapp/jyInfo/rpc/util"
  7. "context"
  8. "fmt"
  9. "log"
  10. "strings"
  11. "time"
  12. se "app.yhyue.com/moapp/jybase/encrypt"
  13. mc "app.yhyue.com/moapp/jybase/common"
  14. "app.yhyue.com/moapp/jybase/redis"
  15. "github.com/zeromicro/go-zero/core/logx"
  16. )
  17. type PublishInfoLogic struct {
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. logx.Logger
  21. }
  22. func NewPublishInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishInfoLogic {
  23. return &PublishInfoLogic{
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. Logger: logx.WithContext(ctx),
  27. }
  28. }
  29. // 发布信息
  30. func (l *PublishInfoLogic) PublishInfo(in *consumerinfo.PublishInfoReq) (*consumerinfo.PublishInfoResp, error) {
  31. res := consumerinfo.PublishInfoResp{}
  32. log.Println("信息发布in数据:", in)
  33. if in.MsgType == 8 && in.DeliveryAddress == "" {
  34. res.ErrCode = -1
  35. res.ErrMsg = "缺少交付地址"
  36. return &res, nil
  37. }
  38. //信息类型1:招标信息 2:采购信息 3:供应信息
  39. publishData := make(map[string]interface{})
  40. publishData["user_id"] = in.UserId //发布人用户ID
  41. publishData["phone"] = in.Phone //注册手机号
  42. publishData["title"] = in.Title //信息标题
  43. publishData["province"] = in.Province //项目省份
  44. if v, ok := (*model.PublishCity)[in.Province]; ok && v != "" {
  45. publishData["city"] = v
  46. } else {
  47. publishData["city"] = in.City
  48. } //项目城市
  49. publishData["detail"] = util.NewCut().ClearHtml(in.Detail) //正文信息
  50. publishData["create_time"] = time.Now().Format("2006-01-02 15:04:05") //申请时间
  51. publishData["attach"] = in.Attach //附件(多个附件逗号分割)
  52. publishData["contact_person"] = in.Contact.Person //联系人
  53. publishData["contact_phone"] = in.Contact.Phone //联系人电话
  54. publishData["is_del"] = 1 // 0:全部;1:未删除;-1:删除
  55. publishData["published"] = 1 // 0:全部;1:未发布;2:已发布
  56. publishData["type"] = mc.IntAll(in.MsgType) //1:招标信息|2:采购信息|3:供应信息
  57. publishData["ent_id"] = mc.IntAll(in.EntId)
  58. publishData["app_id"] = in.AppId
  59. publishData["ent_name"] = in.EntName
  60. // 0:全部;1:待审核;2:待人工审核(敏感词审核不通过||敏感词审核通过);3:自动审核通过;4:人工审核通过;-1:自动审核不通过(机构冻结);-2:人工审核不通过;
  61. publishData["status"] = 1
  62. switch in.MsgType {
  63. case 3:
  64. publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
  65. if in.Deadline != "" {
  66. publishData["validity_time"] = in.Deadline //信息有效期
  67. }
  68. case 8: //阳光采购
  69. publishData["contact_overt"] = 1 //是否公开 默认不公开
  70. publishData["publishing_media"] = 1 //是否同意剑鱼发布平台 1 是 -1 否
  71. publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
  72. publishData["project_code"] = in.Code //项目编号
  73. publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
  74. publishData["buyer"] = in.Buyer //采购单位
  75. publishData["winner"] = in.Winner //中标单位
  76. if in.Budget != "" {
  77. publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
  78. }
  79. if in.Amount != "" {
  80. publishData["amount"] = mc.Float64All(in.Amount) //中标金额
  81. }
  82. default:
  83. if in.EntName == in.Buyer {
  84. publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
  85. } else {
  86. publishData["contact_overt"] = 0
  87. }
  88. publishData["publishing_media"] = in.JyPublishingMedia //是否同意剑鱼发布平台 1 是 -1 否
  89. publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
  90. publishData["related_id"] = mc.IntAll(se.SE.DecodeString(in.RelatedId)) //关联公告id
  91. publishData["project_code"] = in.Code //项目编号
  92. publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
  93. publishData["buyer"] = in.Buyer //采购单位
  94. publishData["winner"] = in.Winner //中标单位
  95. if in.Budget != "" {
  96. publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
  97. }
  98. if in.Amount != "" {
  99. publishData["amount"] = mc.Float64All(in.Amount) //中标金额
  100. }
  101. }
  102. id := model.Mysql.Insert("information", publishData)
  103. if id < 1 {
  104. res.ErrCode = -1
  105. res.ErrMsg = "信息保存失败"
  106. return &res, nil
  107. }
  108. var InfoId consumerinfo.PublishId
  109. InfoId.InformationId = se.SE.EncodeString(mc.InterfaceToStr(id)) //信息id加密
  110. res.PublishId = &InfoId
  111. appendInfo := make(map[string]interface{})
  112. if in.Title != "" {
  113. appendInfo["title"] = in.Title
  114. }
  115. if in.Detail != "" {
  116. appendInfo["detail"] = publishData["detail"]
  117. }
  118. if in.Attach != "" && in.Attach != "{}" {
  119. appendInfo["attach"] = mc.StringToMap(in.Attach)
  120. }
  121. log.Println("发送nsq敏感词信息", model.NsqConfig, appendInfo)
  122. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr(id), "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
  123. if err != nil {
  124. log.Println("初始化NSQ信息失败", err.Error())
  125. res.ErrCode = -1
  126. res.ErrMsg = "信息发布失败"
  127. return &res, nil
  128. }
  129. if err = nsq.NsqPushInfo(); err != nil {
  130. log.Println("发送nsq敏感词信息失败nsq++++++++++++", model.NsqConfig, appendInfo, err.Error())
  131. res.ErrCode = -1
  132. res.ErrMsg = "信息发布失败"
  133. return &res, nil
  134. }
  135. if in.MsgType == 3 {
  136. entNameKye := fmt.Sprintf("userEntName_%s_%d_%d", in.UserId, id, in.MsgType)
  137. redis.Put("other", entNameKye, in.EntName, 3*24*60*60)
  138. }
  139. return &res, nil
  140. }