infolistlogic.go 3.8 KB

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