getviewstatuslogic.go 2.6 KB

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