1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package query
- import (
- "context"
- "gd_adm_data/apis"
- "gd_adm_data/errors"
- "strings"
- jsoniter "github.com/json-iterator/go"
- "gorm.io/gorm"
- "git.getensh.com/common/gopkgsv2/database"
- )
- type p07ReqItem struct {
- Source string `json:"source"`
- ThirdStyleId string `json:"third_style_id"`
- }
- type p07Request struct {
- List []p07ReqItem `json:"list"`
- }
- type p07Item struct {
- Price string `json:"price"`
- BrandId string `json:"brand_id"`
- BrandName string `json:"brand_name"`
- ModelYear string `json:"model_year"`
- SeriesId string `json:"series_id"`
- MakerId string `json:"maker_id"`
- Maker string `json:"maker"`
- SeriesImg string `json:"series_img"`
- SeriesName string `json:"series_name"`
- StyleId string `json:"style_id"`
- StyleName string `json:"style_name"`
- }
- type p07Response struct {
- List []p07Item `json:"list"`
- }
- func P07(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
- reply = &apis.QueryResponse{}
- var req p07Request
- err = jsoniter.UnmarshalFromString(params, &req)
- if err != nil || len(req.List) == 0 {
- return nil, errors.ParamsError
- }
- 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 " +
- "FROM t_adm_ads11 as t1 LEFT JOIN `t_adm_ads5` AS t2 ON t1.style_id = t2.style_id WHERE"
- for _, v := range req.List {
- sql += " (t1.source = '" + v.Source + "' and t1.third_style_id = '" + v.ThirdStyleId + "') OR"
- }
- sql = strings.TrimRight(sql, "OR")
- var list []p07Item
- err = database.DB().Raw(sql).Find(&list).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, errors.DataNotExistError
- }
- return reply, errors.SystemError
- }
- res := p07Response{
- List: make([]p07Item, 0, len(list)),
- }
- for _, v := range list {
- if v.SeriesId != "" {
- //v.SeriesImg = parser.Conf.Oss.SeriesImage + v.SeriesId + ".png"
- }
- if v.StyleId != "" {
- res.List = append(res.List, v)
- }
- }
- if len(res.List) == 0 {
- return reply, errors.DataNotExistError
- }
- reply.Data, _ = jsoniter.MarshalToString(res)
- /*response := p07Response{}
- err = jsoniter.UnmarshalFromString(reply.Data, &response)
- err = insertTable("P07", "查询车型映射", "32,38", req, response)
- if err != nil {
- return nil, err
- }*/
- return reply, nil
- }
|