publishinfologic.go 6.7 KB

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