infolistlogic.go 3.9 KB

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