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,8 +26,8 @@ var ( | ||||
| 	featureRowsExpectAutoSet   = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), ",") | ||||
| 	featureRowsWithPlaceHolder = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?" | ||||
|  | ||||
| 	cacheTydataFeatureIdPrefix    = "cache:tydata:feature:id:" | ||||
| 	cacheTydataFeatureApiIdPrefix = "cache:tydata:feature:apiId:" | ||||
| 	cacheQncFeatureIdPrefix    = "cache:qnc:feature:id:" | ||||
| 	cacheQncFeatureApiIdPrefix = "cache:qnc:feature:apiId:" | ||||
| ) | ||||
|  | ||||
| type ( | ||||
| @@ -76,21 +76,21 @@ func newFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultFeatureModel | ||||
|  | ||||
| func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *Feature) (sql.Result, error) { | ||||
| 	data.DelState = globalkey.DelStateNo | ||||
| 	tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId) | ||||
| 	tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, data.Id) | ||||
| 	qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId) | ||||
| 	qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id) | ||||
| 	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, featureRowsExpectAutoSet) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name) | ||||
| 	}, tydataFeatureApiIdKey, tydataFeatureIdKey) | ||||
| 	}, qncFeatureApiIdKey, qncFeatureIdKey) | ||||
| } | ||||
|  | ||||
| func (m *defaultFeatureModel) FindOne(ctx context.Context, id int64) (*Feature, error) { | ||||
| 	tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, id) | ||||
| 	qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id) | ||||
| 	var resp Feature | ||||
| 	err := m.QueryRowCtx(ctx, &resp, tydataFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | ||||
| 	err := m.QueryRowCtx(ctx, &resp, qncFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | ||||
| 		query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table) | ||||
| 		return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo) | ||||
| 	}) | ||||
| @@ -105,9 +105,9 @@ func (m *defaultFeatureModel) FindOne(ctx context.Context, id int64) (*Feature, | ||||
| } | ||||
|  | ||||
| func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string) (*Feature, error) { | ||||
| 	tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, apiId) | ||||
| 	qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, apiId) | ||||
| 	var resp Feature | ||||
| 	err := m.QueryRowIndexCtx(ctx, &resp, tydataFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | ||||
| 	err := m.QueryRowIndexCtx(ctx, &resp, qncFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | ||||
| 		query := fmt.Sprintf("select %s from %s where `api_id` = ? and del_state = ? limit 1", featureRows, m.table) | ||||
| 		if err := conn.QueryRowCtx(ctx, &resp, query, apiId, globalkey.DelStateNo); err != nil { | ||||
| 			return nil, err | ||||
| @@ -129,15 +129,15 @@ func (m *defaultFeatureModel) Update(ctx context.Context, session sqlx.Session, | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId) | ||||
| 	tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, data.Id) | ||||
| 	qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId) | ||||
| 	qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id) | ||||
| 	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, featureRowsWithPlaceHolder) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id) | ||||
| 	}, tydataFeatureApiIdKey, tydataFeatureIdKey) | ||||
| 	}, qncFeatureApiIdKey, qncFeatureIdKey) | ||||
| } | ||||
|  | ||||
| func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Feature) error { | ||||
| @@ -152,15 +152,15 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId) | ||||
| 	tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, data.Id) | ||||
| 	qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId) | ||||
| 	qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id) | ||||
| 	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, featureRowsWithPlaceHolder) | ||||
| 		if session != nil { | ||||
| 			return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion) | ||||
| 		} | ||||
| 		return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion) | ||||
| 	}, tydataFeatureApiIdKey, tydataFeatureIdKey) | ||||
| 	}, qncFeatureApiIdKey, qncFeatureIdKey) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| @@ -179,7 +179,7 @@ func (m *defaultFeatureModel) DeleteSoft(ctx context.Context, session sqlx.Sessi | ||||
| 	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 "), "FeatureModel delete err : %v", err) | ||||
| 		return errors.Wrapf(errors.New("delete soft failed "), "FeatureModel delete err : %+v", err) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| @@ -383,19 +383,19 @@ func (m *defaultFeatureModel) Delete(ctx context.Context, session sqlx.Session, | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId) | ||||
| 	tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, id) | ||||
| 	qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId) | ||||
| 	qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id) | ||||
| 	_, 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) | ||||
| 	}, tydataFeatureApiIdKey, tydataFeatureIdKey) | ||||
| 	}, qncFeatureApiIdKey, qncFeatureIdKey) | ||||
| 	return err | ||||
| } | ||||
| func (m *defaultFeatureModel) formatPrimary(primary interface{}) string { | ||||
| 	return fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, primary) | ||||
| 	return fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, primary) | ||||
| } | ||||
| func (m *defaultFeatureModel) 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", featureRows, m.table) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user