getviewstatuslogic.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. "log"
  9. "strings"
  10. "jyBXSubscribe/rpc/internal/svc"
  11. "jyBXSubscribe/rpc/type/bxsubscribe"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetViewStatusLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewGetViewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetViewStatusLogic {
  20. return &GetViewStatusLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. // 查看状态
  27. func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*bxsubscribe.ViewStatusResp, error) {
  28. // todo: add your logic here and delete this line
  29. user := model.EntInfo(common.IntAll(in.EntId), common.IntAll(in.EntUserId))
  30. var (
  31. users *[]*model.User
  32. ss []string
  33. finsql string
  34. )
  35. res := new(bxsubscribe.ViewStatusResp)
  36. finsql = `SELECT userid,isvisit,visittime,date FROM pushentniche where infoid =? and type in (2,3) order By date desc`
  37. if user.Role_admin_department {
  38. users = model.GetDisUsers(common.IntAll(in.EntId), user.Dept.Id)
  39. if users != nil && len(*users) > 0 {
  40. //获取所有部门和子部门员工
  41. for _, v := range *users {
  42. ss = append(ss, common.InterfaceToStr(v.Id))
  43. }
  44. } else {
  45. log.Println("部门管理员下为获取到员工", in.EntUserId)
  46. return &bxsubscribe.ViewStatusResp{}, nil
  47. }
  48. } else if user.Role_admin_system {
  49. //获取企业所有用户
  50. users = model.GetEntUsers(common.IntAll(in.EntId))
  51. }
  52. if len(ss) > 0 {
  53. finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date FROM pushentniche where infoid =? and type in (2,3) %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
  54. }
  55. data := IC.BaseServiceMysql.SelectBySql(finsql, in.InfoId)
  56. userMap := make(map[int]string)
  57. for _, u := range *users {
  58. userMap[u.Id] = u.Name
  59. }
  60. if data != nil && len(*data) > 0 {
  61. d := make(map[string]int)
  62. for _, v := range *data {
  63. userid := common.IntAll(v["userid"])
  64. if name, ok := userMap[userid]; ok && name != "" {
  65. var da bxsubscribe.UserStatus
  66. da.Name = name
  67. da.Isvisit = common.Int64All(v["Isvisit"])
  68. da.Visittime = common.Int64All(v["visittime"])
  69. da.Id = common.Int64All(userid)
  70. if v2, ok1 := d[common.InterfaceToStr(userid)]; !ok1 {
  71. res.Items = append(res.Items, &da)
  72. d[common.InterfaceToStr(userid)] = len(res.Items) - 1
  73. } else {
  74. res.Items[v2] = &da
  75. }
  76. }
  77. }
  78. }
  79. return res, nil
  80. }