123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package logic
- import (
- "app.yhyue.com/moapp/jybase/common"
- "context"
- "fmt"
- IC "jyBXSubscribe/rpc/init"
- "jyBXSubscribe/rpc/model"
- "log"
- "strings"
- "jyBXSubscribe/rpc/internal/svc"
- "jyBXSubscribe/rpc/type/bxsubscribe"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type GetViewStatusLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewGetViewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetViewStatusLogic {
- return &GetViewStatusLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 查看状态
- func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*bxsubscribe.ViewStatusResp, error) {
- // todo: add your logic here and delete this line
- user := model.EntInfo(common.IntAll(in.EntId), common.IntAll(in.EntUserId))
- var (
- users *[]*model.User
- ss []string
- finsql string
- )
- res := new(bxsubscribe.ViewStatusResp)
- finsql = `SELECT userid,isvisit,visittime,date FROM pushentniche where infoid =? and type in (2,3) order By date desc`
- if user.Role_admin_department {
- users = model.GetDisUsers(common.IntAll(in.EntId), user.Dept.Id)
- if users != nil && len(*users) > 0 {
- //获取所有部门和子部门员工
- for _, v := range *users {
- ss = append(ss, common.InterfaceToStr(v.Id))
- }
- } else {
- log.Println("部门管理员下为获取到员工", in.EntUserId)
- return &bxsubscribe.ViewStatusResp{}, nil
- }
- } else if user.Role_admin_system {
- //获取企业所有用户
- users = model.GetEntUsers(common.IntAll(in.EntId))
- }
- if len(ss) > 0 {
- 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, ",")))
- }
- data := IC.BaseServiceMysql.SelectBySql(finsql, in.InfoId)
- userMap := make(map[int]string)
- for _, u := range *users {
- userMap[u.Id] = u.Name
- }
- if data != nil && len(*data) > 0 {
- d := make(map[string]int)
- for _, v := range *data {
- userid := common.IntAll(v["userid"])
- if name, ok := userMap[userid]; ok && name != "" {
- var da bxsubscribe.UserStatus
- da.Name = name
- da.Isvisit = common.Int64All(v["Isvisit"])
- da.Visittime = common.Int64All(v["visittime"])
- da.Id = common.Int64All(userid)
- if v2, ok1 := d[common.InterfaceToStr(userid)]; !ok1 {
- res.Items = append(res.Items, &da)
- d[common.InterfaceToStr(userid)] = len(res.Items) - 1
- } else {
- res.Items[v2] = &da
- }
- }
- }
- }
- return res, nil
- }
|