infolistlogic.go 3.9 KB

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