P09.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package query
  2. import (
  3. "context"
  4. jsoniter "github.com/json-iterator/go"
  5. "gd_adm_data/apis"
  6. "gd_adm_data/errors"
  7. "gd_adm_data/model"
  8. "git.getensh.com/common/gopkgsv2/database"
  9. )
  10. type p09Reqeust struct {
  11. StyleId string `json:"style_id"`
  12. }
  13. type p09Config struct {
  14. Useage string `json:"useage"`
  15. Detail string `json:"detail"`
  16. AttributeRule string `json:"attribute_rule"`
  17. }
  18. type p09Data struct {
  19. Config p09Config `json:"config"`
  20. C2Name string `json:"c2_name"`
  21. C2Id int64 `json:"c2_id"`
  22. }
  23. type p09Response struct {
  24. List []p09Data `json:"list"`
  25. }
  26. func P09(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
  27. reply = &apis.QueryResponse{}
  28. var req p09Reqeust
  29. err = jsoniter.UnmarshalFromString(params, &req)
  30. if err != nil && req.StyleId == "" {
  31. return nil, errors.ParamsError
  32. }
  33. list, err := model.NewAds14Model().List(database.DB().Where("style_id = ?", req.StyleId))
  34. if err != nil {
  35. return reply, errors.DataNotExistError
  36. }
  37. res := p09Response{
  38. List: make([]p09Data, 0, len(list)),
  39. }
  40. for _, v := range list {
  41. res.List = append(res.List, p09Data{
  42. C2Name: v.C2Name,
  43. C2Id: v.C2Id,
  44. Config: p09Config{
  45. Useage: v.Useage,
  46. Detail: v.Detail,
  47. AttributeRule: v.AttributeRule,
  48. },
  49. })
  50. }
  51. reply.Data, _ = jsoniter.MarshalToString(res)
  52. return reply, nil
  53. }