new version qnc
This commit is contained in:
		| @@ -17,7 +17,7 @@ import ( | ||||
| 	"github.com/zeromicro/go-zero/core/stores/sqlc" | ||||
| 	"github.com/zeromicro/go-zero/core/stores/sqlx" | ||||
| 	"github.com/zeromicro/go-zero/core/stringx" | ||||
| 	"tydata-server/common/globalkey" | ||||
| 	"qnc-server/common/globalkey" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| @@ -26,9 +26,9 @@ var ( | ||||
| 	userAuthRowsExpectAutoSet   = strings.Join(stringx.Remove(userAuthFieldNames, "`id`", "`create_time`", "`update_time`"), ",") | ||||
| 	userAuthRowsWithPlaceHolder = strings.Join(stringx.Remove(userAuthFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?" | ||||
|  | ||||
| 	cacheTydataUserAuthIdPrefix              = "cache:tydata:userAuth:id:" | ||||
| 	cacheTydataUserAuthAuthTypeAuthKeyPrefix = "cache:tydata:userAuth:authType:authKey:" | ||||
| 	cacheTydataUserAuthUserIdAuthTypePrefix  = "cache:tydata:userAuth:userId:authType:" | ||||
| 	cacheQncUserAuthIdPrefix              = "cache:qnc:userAuth:id:" | ||||
| 	cacheQncUserAuthAuthTypeAuthKeyPrefix = "cache:qnc:userAuth:authType:authKey:" | ||||
| 	cacheQncUserAuthUserIdAuthTypePrefix  = "cache:qnc:userAuth:userId:authType:" | ||||
| ) | ||||
|  | ||||
| type ( | ||||
| @@ -79,22 +79,22 @@ func newUserAuthModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserAuthMode | ||||
|  | ||||
| func (m *defaultUserAuthModel) Insert(ctx context.Context, session sqlx.Session, data *UserAuth) (sql.Result, error) { | ||||
| 	data.DelState = globalkey.DelStateNo | ||||
| 	tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, data.Id) | ||||
| 	tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id) | ||||
| 	qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | ||||
| 		query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, userAuthRowsExpectAutoSet) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.UserId, data.AuthKey, data.AuthType) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.UserId, data.AuthKey, data.AuthType) | ||||
| 	}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey) | ||||
| 	}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey) | ||||
| } | ||||
|  | ||||
| func (m *defaultUserAuthModel) FindOne(ctx context.Context, id int64) (*UserAuth, error) { | ||||
| 	tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, id) | ||||
| 	qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, id) | ||||
| 	var resp UserAuth | ||||
| 	err := m.QueryRowCtx(ctx, &resp, tydataUserAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | ||||
| 	err := m.QueryRowCtx(ctx, &resp, qncUserAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | ||||
| 		query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userAuthRows, m.table) | ||||
| 		return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo) | ||||
| 	}) | ||||
| @@ -109,9 +109,9 @@ func (m *defaultUserAuthModel) FindOne(ctx context.Context, id int64) (*UserAuth | ||||
| } | ||||
|  | ||||
| func (m *defaultUserAuthModel) FindOneByAuthTypeAuthKey(ctx context.Context, authType string, authKey string) (*UserAuth, error) { | ||||
| 	tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, authType, authKey) | ||||
| 	qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, authType, authKey) | ||||
| 	var resp UserAuth | ||||
| 	err := m.QueryRowIndexCtx(ctx, &resp, tydataUserAuthAuthTypeAuthKeyKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | ||||
| 	err := m.QueryRowIndexCtx(ctx, &resp, qncUserAuthAuthTypeAuthKeyKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | ||||
| 		query := fmt.Sprintf("select %s from %s where `auth_type` = ? and `auth_key` = ? and del_state = ? limit 1", userAuthRows, m.table) | ||||
| 		if err := conn.QueryRowCtx(ctx, &resp, query, authType, authKey, globalkey.DelStateNo); err != nil { | ||||
| 			return nil, err | ||||
| @@ -129,9 +129,9 @@ func (m *defaultUserAuthModel) FindOneByAuthTypeAuthKey(ctx context.Context, aut | ||||
| } | ||||
|  | ||||
| func (m *defaultUserAuthModel) FindOneByUserIdAuthType(ctx context.Context, userId int64, authType string) (*UserAuth, error) { | ||||
| 	tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, userId, authType) | ||||
| 	qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, userId, authType) | ||||
| 	var resp UserAuth | ||||
| 	err := m.QueryRowIndexCtx(ctx, &resp, tydataUserAuthUserIdAuthTypeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | ||||
| 	err := m.QueryRowIndexCtx(ctx, &resp, qncUserAuthUserIdAuthTypeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | ||||
| 		query := fmt.Sprintf("select %s from %s where `user_id` = ? and `auth_type` = ? and del_state = ? limit 1", userAuthRows, m.table) | ||||
| 		if err := conn.QueryRowCtx(ctx, &resp, query, userId, authType, globalkey.DelStateNo); err != nil { | ||||
| 			return nil, err | ||||
| @@ -153,16 +153,16 @@ func (m *defaultUserAuthModel) Update(ctx context.Context, session sqlx.Session, | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, data.Id) | ||||
| 	tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id) | ||||
| 	qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | ||||
| 		query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userAuthRowsWithPlaceHolder) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id) | ||||
| 	}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey) | ||||
| 	}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey) | ||||
| } | ||||
|  | ||||
| func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *UserAuth) error { | ||||
| @@ -177,16 +177,16 @@ func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sq | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, data.Id) | ||||
| 	tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id) | ||||
| 	qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | ||||
| 		query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, userAuthRowsWithPlaceHolder) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id, oldVersion) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id, oldVersion) | ||||
| 	}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey) | ||||
| 	}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| @@ -205,7 +205,7 @@ func (m *defaultUserAuthModel) DeleteSoft(ctx context.Context, session sqlx.Sess | ||||
| 	data.DelState = globalkey.DelStateYes | ||||
| 	data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true} | ||||
| 	if err := m.UpdateWithVersion(ctx, session, data); err != nil { | ||||
| 		return errors.Wrapf(errors.New("delete soft failed "), "UserAuthModel delete err : %v", err) | ||||
| 		return errors.Wrapf(errors.New("delete soft failed "), "UserAuthModel delete err : %+v", err) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| @@ -409,20 +409,20 @@ func (m *defaultUserAuthModel) Delete(ctx context.Context, session sqlx.Session, | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, id) | ||||
| 	tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey) | ||||
| 	qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, id) | ||||
| 	qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType) | ||||
| 	_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | ||||
| 		query := fmt.Sprintf("delete from %s where `id` = ?", m.table) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, id) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, id) | ||||
| 	}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey) | ||||
| 	}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey) | ||||
| 	return err | ||||
| } | ||||
| func (m *defaultUserAuthModel) formatPrimary(primary interface{}) string { | ||||
| 	return fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, primary) | ||||
| 	return fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, primary) | ||||
| } | ||||
| func (m *defaultUserAuthModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | ||||
| 	query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userAuthRows, m.table) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user