new version qnc

This commit is contained in:
2025-04-11 13:10:17 +08:00
parent 91db6239d9
commit b0cbe2e81d
162 changed files with 1361 additions and 1556 deletions

View File

@@ -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,7 +26,7 @@ var (
globalNotificationsRowsExpectAutoSet = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
globalNotificationsRowsWithPlaceHolder = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
cacheTydataGlobalNotificationsIdPrefix = "cache:tydata:globalNotifications:id:"
cacheQncGlobalNotificationsIdPrefix = "cache:qnc:globalNotifications:id:"
)
type (
@@ -80,20 +80,20 @@ func newGlobalNotificationsModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultG
func (m *defaultGlobalNotificationsModel) Insert(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
data.DelState = globalkey.DelStateNo
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, data.Id)
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, 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, globalNotificationsRowsExpectAutoSet)
if session != nil {
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
}
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
}, tydataGlobalNotificationsIdKey)
}, qncGlobalNotificationsIdKey)
}
func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64) (*GlobalNotifications, error) {
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, id)
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
var resp GlobalNotifications
err := m.QueryRowCtx(ctx, &resp, tydataGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
err := m.QueryRowCtx(ctx, &resp, qncGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", globalNotificationsRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
})
@@ -108,14 +108,14 @@ func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64)
}
func (m *defaultGlobalNotificationsModel) Update(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, data.Id)
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, 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, globalNotificationsRowsWithPlaceHolder)
if session != nil {
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
}
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
}, tydataGlobalNotificationsIdKey)
}, qncGlobalNotificationsIdKey)
}
func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *GlobalNotifications) error {
@@ -126,14 +126,14 @@ func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context,
var sqlResult sql.Result
var err error
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, data.Id)
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, 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, globalNotificationsRowsWithPlaceHolder)
if session != nil {
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
}
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
}, tydataGlobalNotificationsIdKey)
}, qncGlobalNotificationsIdKey)
if err != nil {
return err
}
@@ -152,7 +152,7 @@ func (m *defaultGlobalNotificationsModel) DeleteSoft(ctx context.Context, sessio
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 "), "GlobalNotificationsModel delete err : %v", err)
return errors.Wrapf(errors.New("delete soft failed "), "GlobalNotificationsModel delete err : %+v", err)
}
return nil
}
@@ -351,18 +351,18 @@ func (m *defaultGlobalNotificationsModel) SelectBuilder() squirrel.SelectBuilder
return squirrel.Select().From(m.table)
}
func (m *defaultGlobalNotificationsModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, id)
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, 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)
}, tydataGlobalNotificationsIdKey)
}, qncGlobalNotificationsIdKey)
return err
}
func (m *defaultGlobalNotificationsModel) formatPrimary(primary interface{}) string {
return fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, primary)
return fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, primary)
}
func (m *defaultGlobalNotificationsModel) 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", globalNotificationsRows, m.table)