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 v02Request struct { IdCard string `json:"id_card"` Name string `json:"name"` } type v02Response struct { IsMatch int32 `json:"is_match"` UpdatedAt int64 `json:"updated_at"` } type ads20Response struct { Name string `json:"name"` UpdatedAt int64 `json:"updated_at"` } func V02(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 v02Request err = jsoniter.UnmarshalFromString(params, &req) if err != nil || (req.Name == "" || req.IdCard == "") { return nil, errors.ParamsError } var res v02Response var ads20 ads20Response //var name string //var updatedAt int64 db := database.DB() err = db.Raw("select name,updated_at from t_adm_ads20 where id_card = ?", req.IdCard).Find(&ads20).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, errors.DataNotExistError } return reply, errors.SystemError } res.UpdatedAt = ads20.UpdatedAt if ads20.Name == "" { return reply, errors.DataNotExistError } else { if ads20.Name == req.Name { // 姓名匹配为1 res.IsMatch = 1 reply.Data, _ = jsoniter.MarshalToString(res) } else { // 姓名不匹配为-1 res.IsMatch = -1 reply.Data, _ = jsoniter.MarshalToString(res) } } return reply, nil }