infolistlogic.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/manager/internal/svc"
  4. "app.yhyue.com/moapp/jyInfo/rpc/manager/type/manager"
  5. "app.yhyue.com/moapp/jyInfo/rpc/model"
  6. "app.yhyue.com/moapp/jyInfo/rpc/util"
  7. se "app.yhyue.com/moapp/jybase/encrypt"
  8. "context"
  9. "fmt"
  10. "log"
  11. "strings"
  12. "app.yhyue.com/moapp/jybase/common"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type InfoListLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewInfoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoListLogic {
  21. return &InfoListLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. // InfoList 信息列表
  28. func (l *InfoListLogic) InfoList(in *manager.InfoListReq) (*manager.InfoListResp, error) {
  29. var (
  30. query []string
  31. queryInfo string
  32. count int64
  33. results []*manager.InfoList
  34. allData *[]map[string]interface{}
  35. )
  36. log.Println("管理平台信息发布列表查询参数:", in)
  37. if in.MsgType != 0 {
  38. if in.MsgType == 2 { //采购信息包含阳光采购
  39. query = append(query, `type in (2,8)`)
  40. } else {
  41. query = append(query, `type=`+common.InterfaceToStr(in.MsgType)+` `)
  42. }
  43. }
  44. if in.PhoneType != 0 {
  45. if in.PhoneType == 1 {
  46. query = append(query, ` phone LIKE '%`+in.Phone+`%' `)
  47. } else {
  48. query = append(query, ` contact_phone LIKE '%`+in.Phone+`%' `)
  49. }
  50. }
  51. if in.ApplyStartTime != "" {
  52. query = append(query, ` create_time >="`+in.ApplyStartTime+`"`)
  53. }
  54. if in.RecommendedService != 0 {
  55. query = append(query, ` recommended_service =`+common.InterfaceToStr(in.RecommendedService))
  56. }
  57. if in.JyPublishingMedia != 0 {
  58. query = append(query, ` publishing_media =`+common.InterfaceToStr(in.JyPublishingMedia))
  59. }
  60. if in.IsDel != 0 {
  61. query = append(query, ` is_del =`+common.InterfaceToStr(in.IsDel))
  62. }
  63. if in.Published != 0 {
  64. query = append(query, ` published =`+common.InterfaceToStr(in.Published))
  65. }
  66. if in.ApplyEndTime != "" {
  67. query = append(query, ` create_time <="`+in.ApplyEndTime+`"`)
  68. }
  69. if in.AppId != "" {
  70. query = append(query, ` app_id = `+util.StrFormat(in.AppId))
  71. }
  72. //supQuery := query
  73. if in.ReviewStatus != 0 {
  74. query = append(query, ` status =`+common.InterfaceToStr(in.ReviewStatus))
  75. //supQuery = append(supQuery, ` status =`+common.Str(in.ReviewStatus))
  76. }
  77. if len(query) > 0 {
  78. queryInfo = fmt.Sprintf(" where %s", strings.Join(query, " and "))
  79. //querySup = fmt.Sprintf(" where %s", strings.Join(supQuery, " and "))
  80. }
  81. if in.PageSize <= 0 {
  82. in.PageSize = 10
  83. }
  84. var offset int
  85. if in.PageIndex <= 1 {
  86. offset = 0
  87. } else {
  88. offset = common.IntAll((in.PageIndex - 1) * in.PageSize)
  89. }
  90. if in.RecommendedService != 0 || in.JyPublishingMedia != 0 {
  91. count = model.Mysql.CountBySql(`SELECT count(1) from information ` + queryInfo)
  92. allData = model.Mysql.SelectBySql(`SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information `+queryInfo+`
  93. order by create_time limit ?,? `, offset, in.PageSize)
  94. } else {
  95. count = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information ` + queryInfo + `
  96. union all
  97. SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info ` + queryInfo + ` ) a`)
  98. allData = model.Mysql.SelectBySql(`SELECT * from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information `+queryInfo+`
  99. union all
  100. SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info `+queryInfo+` ) a order by a.create_time limit ?,? `, offset, in.PageSize)
  101. }
  102. if allData != nil && len(*allData) > 0 {
  103. for _, v := range *allData {
  104. res := manager.InfoList{}
  105. var contact manager.Contact
  106. res.Id = se.SE.EncodeString(common.InterfaceToStr(v["id"])) //信息id加密
  107. res.Title = common.InterfaceToStr(v["title"])
  108. res.MsgType = common.Int64All(v["type"])
  109. res.Phone = common.InterfaceToStr(v["phone"])
  110. res.ReviewStatus = common.Int64All(v["status"])
  111. res.Published = common.Int64All(v["published"])
  112. res.IsDel = common.Int64All(v["is_del"])
  113. res.ApplyTime = common.InterfaceToStr(v["create_time"])
  114. contact.Name = common.InterfaceToStr(v["contact_person"])
  115. contact.Phone = common.InterfaceToStr(v["contact_phone"])
  116. res.Contact = &contact
  117. results = append(results, &res)
  118. }
  119. }
  120. data := manager.Data{}
  121. data.Count = count
  122. data.List = results
  123. return &manager.InfoListResp{
  124. ErrCode: 0,
  125. ErrMsg: "",
  126. Data: &data,
  127. }, nil
  128. }