12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package logic
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.i2edu.net/i2/i2-bill-erp/internal/svc"
- "git.i2edu.net/i2/i2-bill-erp/transform"
- "git.i2edu.net/i2/go-zero/core/logx"
- )
- type Options struct {
- Value interface{} `json:"value"`
- Text string `json:"text"`
- }
- type LoadOptionsetLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewLoadOptionsetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoadOptionsetLogic {
- return &LoadOptionsetLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *LoadOptionsetLogic) LoadOptionset(in *transform.OptionsetReq) (*transform.OptionsetRes, error) {
- values := []*Options{}
- var options struct {
- Value string `db:"value"`
- }
- l.svcCtx.SqlConn.QueryRowPartial(&options, "select value from sys_optionset where code=?", in.Code)
- json.Unmarshal([]byte(options.Value), &values)
- optionset := make(map[string]string)
- for _, opt := range values {
- value := fmt.Sprintf("%v", opt.Value)
- optionset[value] = opt.Text
- }
- return &transform.OptionsetRes{MapList: optionset}, nil
- }
|