1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package query
- import (
- "adm-data/errors"
- v1 "adm-data/pb/v1"
- "context"
- "encoding/json"
- "fmt"
- jsoniter "github.com/json-iterator/go"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- type a05Request struct {
- Vin string `json:"vin"`
- PlateNo string `json:"plate_no"`
- PlateType string `json:"plate_type"`
- }
- type a05Response struct {
- PlateNo string `json:"plate_no"`
- PlateNoPrex string `json:"plate_no_prex"`
- PlateType string `json:"plate_type"`
- Vin string `json:"vin"`
- SaleTime string `json:"sale_time"`
- Province string `json:"province"`
- City string `json:"city"`
- District string `json:"district"`
- UsePropertyDetail string `json:"use_property_detail"`
- BrandName string `json:"brand_name"`
- EngineNo string `json:"engine_no"`
- EngineType string `json:"engine_type"`
- Displacement string `json:"displacement"`
- DisplacementL string `json:"displacement_l"`
- ReleaseDate string `json:"release_date"`
- VehicleBodyColorDetail string `json:"vehicle_body_color_detail"`
- VehicleBodyColor string `json:"vehicle_body_color"`
- LastCompulsoryInsuranceDate string `json:"last_compulsory_insurance_date"`
- }
- func a05(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
- reply = &v1.QueryResponse{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- var req a05Request
- err = jsoniter.UnmarshalFromString(params, &req)
- if err != nil {
- return nil, errors.ParamsError
- }
- if req.Vin == "" {
- return nil, errors.ParamsError
- }
- a05Rsp := a05Response{}
- sql := `SELECT
- *
- FROM
- v_adm_vehicle_destination
- WHERE
- vin = ?`
- err = database.DB().Raw(sql, req.Vin).Find(&a05Rsp).Error
- if err != nil {
- return nil, errors.DataNotExistError
- }
- sql1 := `SELECT insurance_date as last_compulsory_insurance_date FROM t_adm_ads17 WHERE vin = ? ORDER BY insurance_date desc LIMIT 1`
- err = database.DB().Raw(sql1, req.Vin).Find(&a05Rsp).Error
- a05Str, _ := jsoniter.MarshalToString(a05Rsp)
- a05Map := make(map[string]interface{})
- jsoniter.Unmarshal([]byte(a05Str), &a05Map)
- formatData(a05Map)
- reply.Data, _ = jsoniter.MarshalToString(a05Map)
- return reply, nil
- }
|