get_xunji_logic.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package xunji
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/suyuan32/simple-admin-common/utils/pointy"
  6. "wechat-api/ent"
  7. "wechat-api/ent/xunji"
  8. "wechat-api/internal/utils/dberrorhandler"
  9. "wechat-api/internal/svc"
  10. "wechat-api/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type GetXunjiLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewGetXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiLogic {
  19. return &GetXunjiLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx}
  23. }
  24. func (l *GetXunjiLogic) GetXunji() (resp *types.XunjiInfoResp, err error) {
  25. organizationId := l.ctx.Value("organizationId").(uint64)
  26. data, err := l.svcCtx.DB.Xunji.Query().Where(
  27. xunji.OrganizationID(organizationId),
  28. ).Order(ent.Desc(xunji.FieldCreatedAt)).First(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
  31. }
  32. return &types.XunjiInfoResp{
  33. BaseDataInfo: types.BaseDataInfo{
  34. Code: 0,
  35. Msg: errormsg.Success,
  36. },
  37. Data: types.XunjiInfo{
  38. BaseIDInfo: types.BaseIDInfo{
  39. Id: &data.ID,
  40. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  41. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  42. },
  43. Status: &data.Status,
  44. AppKey: &data.AppKey,
  45. AppSecret: &data.AppSecret,
  46. Token: &data.Token,
  47. EncodingKey: &data.EncodingKey,
  48. OrganizationId: &data.OrganizationID,
  49. },
  50. }, nil
  51. }