package query import ( "context" "encoding/json" "fmt" jsoniter "github.com/json-iterator/go" "adm-data/errors" v1 "adm-data/pb/v1" "git.getensh.com/common/gopkgsv2/database" "git.getensh.com/common/gopkgsv2/logger" "go.uber.org/zap" "google.golang.org/grpc/status" "gorm.io/gorm" ) type v01Request struct { PlateNo string `json:"plate_no"` PlateType string `json:"plate_type"` Owner string `json:"owner"` } type v01Response struct { IsMatch int32 `json:"is_match"` UpdatedAt int64 `json:"updated_at"` } type ads3Response struct { Owner string `json:"owner"` UpdatedAt int64 `json:"updated_at"` } func PlateOwner(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 v01Request err = jsoniter.UnmarshalFromString(params, &req) if err != nil || (req.PlateNo == "" || req.PlateType == "" || req.Owner == "") { return nil, errors.ParamsError } var res v01Response //var owner string var ads3 ads3Response //var updatedAt int64 db := database.DB() err = db.Raw("select owner,updated_at from t_adm_ads3 where plate_no = ? and plate_type = ?", req.PlateNo, req.PlateType).Find(&ads3).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, errors.DataNotExistError } return reply, errors.SystemError } res.UpdatedAt = ads3.UpdatedAt if ads3.Owner == "" { return reply, errors.DataNotExistError // 无记录为0 /*res.IsMatch = 0 reply.Data, _ = jsoniter.MarshalToString(res)*/ } else { if ads3.Owner == req.Owner { // 姓名匹配为1 res.IsMatch = 1 reply.Data, _ = jsoniter.MarshalToString(res) } else { // 姓名不匹配为-1 res.IsMatch = -1 reply.Data, _ = jsoniter.MarshalToString(res) } } return reply, nil }