getviewstatuslogic.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. <<<<<<< HEAD
  41. finsql = `SELECT userid,isvisit,visittime,date FROM push.pushentniche where infoid =? and source in (2,3) order By date asc`
  42. =======
  43. finsql = `SELECT userid,isvisit,visittime,date,source FROM pushentniche where infoid =? order By date asc`
  44. >>>>>>> master
  45. if user.Role_admin_department {
  46. users = model.GetDisUsers(common.IntAll(in.EntId), user.Dept.Id)
  47. if users != nil && len(*users) > 0 {
  48. //获取所有部门和子部门员工
  49. for _, v := range *users {
  50. ss = append(ss, common.InterfaceToStr(v.Id))
  51. }
  52. } else {
  53. log.Println("部门管理员下为获取到员工", in.EntUserId)
  54. return &bxsubscribe.ViewStatusResp{}, nil
  55. }
  56. } else if user.Role_admin_system {
  57. //获取企业所有用户
  58. users = model.GetEntUsers(common.IntAll(in.EntId))
  59. }
  60. if len(ss) > 0 {
  61. <<<<<<< HEAD
  62. finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date FROM push.pushentniche where infoid =? and source in (2,3) %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
  63. =======
  64. finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date,source FROM pushentniche where infoid =? %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
  65. >>>>>>> master
  66. }
  67. data := IC.BaseServiceMysql.SelectBySql(finsql, in.InfoId)
  68. userMap := make(map[int]*model.User)
  69. for _, u := range *users {
  70. if u != nil {
  71. userMap[u.Id] = u
  72. }
  73. }
  74. if data != nil && len(*data) > 0 {
  75. //d := make(map[string]int)
  76. for _, v := range *data {
  77. userid := common.IntAll(v["userid"])
  78. if u, ok := userMap[userid]; ok && u != nil {
  79. var da bxsubscribe.UserStatus
  80. da.Name = u.Name
  81. da.Isvisit = common.Int64All(v["isvisit"])
  82. visittime := common.InterfaceToStr(v["visittime"])
  83. date := common.Int64All(v["date"])
  84. if date > 0 {
  85. da.Date = time.Unix(date, 0).Format("2006-01-02 15:04:05")
  86. }
  87. da.Visittime = visittime
  88. da.Id = common.Int64All(userid)
  89. da.Phone = u.Phone
  90. da.Source = common.Int64All(v["source"])
  91. res.Items = append(res.Items, &da)
  92. //if _, ok1 := d[common.InterfaceToStr(userid)]; !ok1 {
  93. // res.Items = append(res.Items, &da)
  94. // d[common.InterfaceToStr(userid)] = len(res.Items) - 1
  95. //}
  96. }
  97. }
  98. }
  99. log.Println("查看输出结果参数", res)
  100. //Reverse(&res.Items)
  101. return res, nil
  102. }
  103. // 数组倒序函数
  104. func Reverse(arr *[]*bxsubscribe.UserStatus) {
  105. var temp *bxsubscribe.UserStatus
  106. length := len(*arr)
  107. for i := 0; i < length/2; i++ {
  108. temp = (*arr)[i]
  109. (*arr)[i] = (*arr)[length-1-i]
  110. (*arr)[length-1-i] = temp
  111. }
  112. }