get_erp_school_logic.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package logic
  2. import (
  3. "context"
  4. "git.i2edu.net/i2/i2-bill-erp/internal/svc"
  5. "git.i2edu.net/i2/i2-bill-erp/transform"
  6. "git.i2edu.net/i2/go-zero/core/logx"
  7. )
  8. type GetErpSchoolLogic struct {
  9. ctx context.Context
  10. svcCtx *svc.ServiceContext
  11. logx.Logger
  12. }
  13. func NewGetErpSchoolLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetErpSchoolLogic {
  14. return &GetErpSchoolLogic{
  15. ctx: ctx,
  16. svcCtx: svcCtx,
  17. Logger: logx.WithContext(ctx),
  18. }
  19. }
  20. func (l *GetErpSchoolLogic) GetErpSchool(in *transform.Empty) (*transform.GetErpSchoolRes, error) {
  21. // todo: add your logic here and delete this line
  22. type Sch struct {
  23. Name string `json:"name"`
  24. OrganId int64 `json:"organ_id"`
  25. Id int64 `json:"id"`
  26. }
  27. sch := new([]*Sch)
  28. schools := new([]*transform.OrganSchool)
  29. sql := `
  30. SELECT
  31. sch.name,sch.organ_id,sch.id
  32. FROM
  33. base_organ_school sch
  34. `
  35. err := l.svcCtx.DB.SQL(sql).Find(sch)
  36. if err != nil {
  37. logx.Error(err.Error())
  38. return nil, err
  39. }
  40. for _, s := range *sch {
  41. school := new(transform.OrganSchool)
  42. school.Id = s.Id
  43. school.Name = s.Name
  44. school.OrganId = s.OrganId
  45. *schools = append(*schools, school)
  46. }
  47. return &transform.GetErpSchoolRes{School: *schools}, nil
  48. }