getviewstatuslogic.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "fmt"
  6. IC "jyBXSubscribe/rpc/init"
  7. "jyBXSubscribe/rpc/model"
  8. "jyBXSubscribe/rpc/util"
  9. "log"
  10. "strings"
  11. "time"
  12. "jyBXSubscribe/rpc/internal/svc"
  13. "jyBXSubscribe/rpc/type/bxsubscribe"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. type GetViewStatusLogic struct {
  17. ctx context.Context
  18. svcCtx *svc.ServiceContext
  19. logx.Logger
  20. }
  21. func NewGetViewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetViewStatusLogic {
  22. return &GetViewStatusLogic{
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. Logger: logx.WithContext(ctx),
  26. }
  27. }
  28. // 查看状态
  29. func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*bxsubscribe.ViewStatusResp, error) {
  30. // todo: add your logic here and delete this line
  31. user := model.EntInfo(common.IntAll(in.EntId), common.IntAll(in.EntUserId))
  32. var (
  33. users *[]*model.User
  34. ss []string
  35. finsql string
  36. )
  37. in.InfoId = util.DecodeId(in.InfoId)
  38. log.Println("查看状态参数", in)
  39. res := new(bxsubscribe.ViewStatusResp)
  40. finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date,source FROM push.pushentniche where entid = %s and infoid =? order By date asc`, in.EntId)
  41. if user.Role_admin_department {
  42. users = model.GetDisUsers(common.IntAll(in.EntId), user.Dept.Id)
  43. if users != nil && len(*users) > 0 {
  44. //获取所有部门和子部门员工
  45. for _, v := range *users {
  46. ss = append(ss, common.InterfaceToStr(v.Id))
  47. }
  48. } else {
  49. log.Println("部门管理员下为获取到员工", in.EntUserId)
  50. return &bxsubscribe.ViewStatusResp{}, nil
  51. }
  52. } else if user.Role_admin_system {
  53. //获取企业所有用户
  54. users = model.GetEntUsers(common.IntAll(in.EntId))
  55. }
  56. if len(ss) > 0 {
  57. finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date,source FROM push.pushentniche where %s infoid =? order By date asc`, fmt.Sprintf(` userid in (%s) and `, strings.Join(ss, ",")))
  58. }
  59. data := IC.BaseServiceMysql.SelectBySql(finsql, in.InfoId)
  60. userMap := make(map[int]*model.User)
  61. for _, u := range *users {
  62. if u != nil {
  63. userMap[u.Id] = u
  64. }
  65. }
  66. if data != nil && len(*data) > 0 {
  67. //d := make(map[string]int)
  68. for _, v := range *data {
  69. userid := common.IntAll(v["userid"])
  70. if u, ok := userMap[userid]; ok && u != nil {
  71. var da bxsubscribe.UserStatus
  72. da.Name = u.Name
  73. da.Isvisit = common.Int64All(v["isvisit"])
  74. visittime := common.InterfaceToStr(v["visittime"])
  75. date := common.Int64All(v["date"])
  76. if date > 0 {
  77. da.Date = time.Unix(date, 0).Format("2006-01-02 15:04:05")
  78. }
  79. da.Visittime = visittime
  80. da.Id = common.Int64All(userid)
  81. da.Phone = u.Phone
  82. da.Source = common.Int64All(v["source"])
  83. res.Items = append(res.Items, &da)
  84. //if _, ok1 := d[common.InterfaceToStr(userid)]; !ok1 {
  85. // res.Items = append(res.Items, &da)
  86. // d[common.InterfaceToStr(userid)] = len(res.Items) - 1
  87. //}
  88. }
  89. }
  90. }
  91. log.Println("查看输出结果参数", res)
  92. //Reverse(&res.Items)
  93. return res, nil
  94. }
  95. // 数组倒序函数
  96. func Reverse(arr *[]*bxsubscribe.UserStatus) {
  97. var temp *bxsubscribe.UserStatus
  98. length := len(*arr)
  99. for i := 0; i < length/2; i++ {
  100. temp = (*arr)[i]
  101. (*arr)[i] = (*arr)[length-1-i]
  102. (*arr)[length-1-i] = temp
  103. }
  104. }