get_api_employee_detail_logic.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package employee
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  6. "github.com/suyuan32/simple-admin-common/utils/pointy"
  7. "wechat-api/ent/employee"
  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 GetApiEmployeeDetailLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewGetApiEmployeeDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiEmployeeDetailLogic {
  19. return &GetApiEmployeeDetailLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx}
  23. }
  24. func (l *GetApiEmployeeDetailLogic) GetApiEmployeeDetail(req *types.IDReq) (*types.EmployeeInfoResp, error) {
  25. data, err := l.svcCtx.DB.Employee.Query().Where(employee.ID(req.Id)).Only(l.ctx)
  26. fmt.Printf("%v", data)
  27. if err != nil {
  28. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  29. }
  30. return &types.EmployeeInfoResp{
  31. BaseDataInfo: types.BaseDataInfo{
  32. Code: 0,
  33. Msg: errormsg.Success,
  34. },
  35. Data: types.EmployeeInfo{
  36. BaseIDInfo: types.BaseIDInfo{
  37. Id: &data.ID,
  38. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  39. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  40. },
  41. Title: &data.Title,
  42. Avatar: &data.Avatar,
  43. Tags: &data.Tags,
  44. HireCount: &data.HireCount,
  45. ServiceCount: &data.ServiceCount,
  46. AchievementCount: &data.AchievementCount,
  47. Intro: &data.Intro,
  48. Estimate: &data.Estimate,
  49. Skill: &data.Skill,
  50. AbilityType: &data.AbilityType,
  51. Scene: &data.Scene,
  52. SwitchIn: &data.SwitchIn,
  53. VideoUrl: &data.VideoURL,
  54. CategoryId: &data.CategoryID,
  55. },
  56. }, nil
  57. }