load_optionset_logic.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "git.i2edu.net/i2/i2-bill-erp/internal/svc"
  6. "git.i2edu.net/i2/i2-bill-erp/transform"
  7. "git.i2edu.net/i2/go-zero/core/logx"
  8. )
  9. type Options struct {
  10. Value interface{} `json:"value"`
  11. Text string `json:"text"`
  12. }
  13. type LoadOptionsetLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewLoadOptionsetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoadOptionsetLogic {
  19. return &LoadOptionsetLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. func (l *LoadOptionsetLogic) LoadOptionset(in *transform.OptionsetReq) (*transform.OptionsetRes, error) {
  26. var options struct {
  27. Value []*Options `json:"value"`
  28. }
  29. l.svcCtx.SqlConn.QueryRowPartial(&options, "select value from sys_optionset where code=?", in.Code)
  30. optionset := make(map[string]string)
  31. for _, opt := range options.Value {
  32. value := fmt.Sprintf("%v", opt.Value)
  33. optionset[value] = opt.Text
  34. }
  35. return &transform.OptionsetRes{MapList: optionset}, nil
  36. }