mypublishlistlogic.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerclient"
  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. se "app.yhyue.com/moapp/jybase/encrypt"
  8. "context"
  9. "log"
  10. mc "app.yhyue.com/moapp/jybase/common"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type MyPublishListLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewMyPublishListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyPublishListLogic {
  19. return &MyPublishListLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // MyPublishList 我的发布列表
  26. func (l *MyPublishListLogic) MyPublishList(in *consumerclient.MyPublishListReq) (*consumerclient.MyPublishListResp, error) {
  27. // todo: add your logic here and delete this line
  28. var (
  29. queryName string
  30. data consumerclient.MyPublishListResp
  31. amount, inReview, approved, auditFailed, total int64
  32. ListData consumerclient.MyPublishListData
  33. )
  34. log.Println("我的发布列表", in)
  35. if in.Match != "" {
  36. queryName = ` and title LIKE '%` + in.Match + `%' `
  37. }
  38. if in.MsgType != 0 {
  39. queryName = queryName + ` and type=` + mc.InterfaceToStr(in.MsgType)
  40. }
  41. if in.AppId != "" {
  42. queryName = queryName + ` and app_id = ` + util.StrFormat(in.AppId)
  43. }
  44. if in.EntId != 0 {
  45. queryName = queryName + ` and ent_id = ` + mc.InterfaceToStr(in.EntId)
  46. }
  47. if in.PageIndex == 1 {
  48. //全部
  49. amount = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `
  50. union all
  51. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `) a`)
  52. //审核中
  53. inReview = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (0,1,2,3,4) and published = 1
  54. union all
  55. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (0,1,2,3,4) and published = 1) a`)
  56. //审核通过
  57. approved = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and published = 2
  58. union all
  59. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and published = 2) a`)
  60. //审核不通过
  61. auditFailed = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (-1,-2) and published = 1` + `
  62. union all
  63. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (-1,-2) and published = 1) a`)
  64. }
  65. if in.ReviewStatus != 0 {
  66. if in.ReviewStatus == 1 {
  67. queryName = queryName + ` and status in (0,1,2,3,4) and published = 1`
  68. } else if in.ReviewStatus == 2 {
  69. queryName = queryName + ` and published = 2`
  70. } else if in.ReviewStatus == 3 {
  71. queryName = queryName + ` and status in (-1,-2)`
  72. }
  73. }
  74. if in.PageSize <= 0 {
  75. in.PageSize = 10
  76. }
  77. var offset int
  78. if in.PageIndex <= 1 {
  79. offset = 0
  80. } else {
  81. offset = mc.IntAll((in.PageIndex - 1) * in.PageSize)
  82. }
  83. if in.PageIndex == 1 {
  84. count := model.Mysql.CountBySql(`SELECT count(1) from (SELECT id,type,title,create_time,status,published from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `
  85. union all
  86. SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` ) a`)
  87. total = mc.Int64All(mc.MathCeil(mc.Float64All(count) / mc.Float64All(in.PageSize)))
  88. }
  89. allData := model.Mysql.SelectBySql(`SELECT a.id,a.type,a.title,a.create_time,a.published,a.status from (SELECT id,type,title,create_time,status,published from information WHERE is_del = 1 and user_id= "`+in.UserId+`" `+queryName+`
  90. union all
  91. SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "`+in.UserId+`" `+queryName+` ) a order by a.create_time desc limit ?,?`, offset, in.PageSize)
  92. if allData != nil && len(*allData) > 0 {
  93. for _, v := range *allData {
  94. var vs = consumerclient.ListResp{}
  95. vs.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //信息id加密
  96. vs.ReviewStatus = 1
  97. status := mc.IntAll(v["status"])
  98. published := mc.IntAll(v["published"])
  99. //1 审核中 2 已发布(审核通过)3 status(-1,-2) 审核不通过
  100. if published == 2 {
  101. vs.ReviewStatus = 2
  102. } else if status == -2 || status == -1 {
  103. vs.ReviewStatus = 3
  104. }
  105. ListData.Total = total
  106. vs.MsgType = mc.Int64All(v["type"])
  107. vs.CreateTime = mc.InterfaceToStr(v["create_time"])
  108. vs.Title = mc.InterfaceToStr(v["title"])
  109. ListData.List = append(ListData.List, &vs)
  110. }
  111. }
  112. ListData.Amount = amount
  113. ListData.Approved = approved
  114. ListData.InReview = inReview
  115. ListData.AuditFailed = auditFailed
  116. data.Results = &ListData
  117. return &data, nil
  118. }