P07.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package query
  2. import (
  3. "context"
  4. "gd_adm_data/apis"
  5. "gd_adm_data/errors"
  6. "strings"
  7. jsoniter "github.com/json-iterator/go"
  8. "gorm.io/gorm"
  9. "git.getensh.com/common/gopkgsv2/database"
  10. )
  11. type p07ReqItem struct {
  12. Source string `json:"source"`
  13. ThirdStyleId string `json:"third_style_id"`
  14. }
  15. type p07Request struct {
  16. List []p07ReqItem `json:"list"`
  17. }
  18. type p07Item struct {
  19. Price string `json:"price"`
  20. BrandId string `json:"brand_id"`
  21. BrandName string `json:"brand_name"`
  22. ModelYear string `json:"model_year"`
  23. SeriesId string `json:"series_id"`
  24. MakerId string `json:"maker_id"`
  25. Maker string `json:"maker"`
  26. SeriesImg string `json:"series_img"`
  27. SeriesName string `json:"series_name"`
  28. StyleId string `json:"style_id"`
  29. StyleName string `json:"style_name"`
  30. }
  31. type p07Response struct {
  32. List []p07Item `json:"list"`
  33. }
  34. func P07(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
  35. reply = &apis.QueryResponse{}
  36. var req p07Request
  37. err = jsoniter.UnmarshalFromString(params, &req)
  38. if err != nil || len(req.List) == 0 {
  39. return nil, errors.ParamsError
  40. }
  41. sql := "SELECT t2.price,t2.brand_id,t2.brand_name,t2.model_year,t2.series_id,t2.maker_id,t2.maker,t2.series_name,t1.style_id,t2.style_name " +
  42. "FROM t_adm_ads11 as t1 LEFT JOIN `t_adm_ads5` AS t2 ON t1.style_id = t2.style_id WHERE"
  43. for _, v := range req.List {
  44. sql += " (t1.source = '" + v.Source + "' and t1.third_style_id = '" + v.ThirdStyleId + "') OR"
  45. }
  46. sql = strings.TrimRight(sql, "OR")
  47. var list []p07Item
  48. err = database.DB().Raw(sql).Find(&list).Error
  49. if err != nil {
  50. if err == gorm.ErrRecordNotFound {
  51. return reply, errors.DataNotExistError
  52. }
  53. return reply, errors.SystemError
  54. }
  55. res := p07Response{
  56. List: make([]p07Item, 0, len(list)),
  57. }
  58. for _, v := range list {
  59. if v.SeriesId != "" {
  60. //v.SeriesImg = parser.Conf.Oss.SeriesImage + v.SeriesId + ".png"
  61. }
  62. if v.StyleId != "" {
  63. res.List = append(res.List, v)
  64. }
  65. }
  66. if len(res.List) == 0 {
  67. return reply, errors.DataNotExistError
  68. }
  69. reply.Data, _ = jsoniter.MarshalToString(res)
  70. /*response := p07Response{}
  71. err = jsoniter.UnmarshalFromString(reply.Data, &response)
  72. err = insertTable("P07", "查询车型映射", "32,38", req, response)
  73. if err != nil {
  74. return nil, err
  75. }*/
  76. return reply, nil
  77. }