...
|
...
|
@@ -5,37 +5,61 @@ import ( |
|
|
"github.com/go-pg/pg"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
|
|
|
)
|
|
|
|
|
|
type ColumnSettingRepository struct {
|
|
|
transactionContext *pgTransaction.TransactionContext
|
|
|
transactionContext *transaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
func (repository *ColumnSettingRepository) nextIdentify() (int64, error) {
|
|
|
return 0, nil
|
|
|
}
|
|
|
//func (repository *ColumnSettingRepository) nextIdentify() (int64, error) {
|
|
|
// return 0, nil
|
|
|
//}
|
|
|
|
|
|
func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSetting) (*domain.ColumnSetting, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
|
|
|
columnSettingModel := &models.ColumnSetting{
|
|
|
Id: columnSetting.Id,
|
|
|
CompanyId: columnSetting.CompanyId,
|
|
|
CreatedAt: columnSetting.CreatedAt,
|
|
|
Description: columnSetting.Description,
|
|
|
Key: columnSetting.Key,
|
|
|
Uid: columnSetting.Uid,
|
|
|
UpdatedAt: columnSetting.UpdatedAt,
|
|
|
UserName: columnSetting.UserName,
|
|
|
Value: columnSetting.Value,
|
|
|
InvalidValue: columnSetting.InvalidValue,
|
|
|
}
|
|
|
|
|
|
if columnSetting.Identify() == nil {
|
|
|
_, err := repository.nextIdentify()
|
|
|
_, err := tx.Model(columnSettingModel).Insert()
|
|
|
if err != nil {
|
|
|
return columnSetting, err
|
|
|
}
|
|
|
if _, errInsert := tx.QueryOne(
|
|
|
pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
|
|
|
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
|
|
|
columnSetting.Id, columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue)); errInsert != nil {
|
|
|
return columnSetting, errInsert
|
|
|
return nil, err
|
|
|
}
|
|
|
return nil, err
|
|
|
//_, err := repository.nextIdentify()
|
|
|
//if err != nil {
|
|
|
// return columnSetting, err
|
|
|
//}
|
|
|
//if _, errInsert := tx.QueryOne(
|
|
|
// pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
|
|
|
// "INSERT INTO column_settings (company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
|
|
|
// columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue)); errInsert != nil {
|
|
|
// return columnSetting, errInsert
|
|
|
//}
|
|
|
} else {
|
|
|
if _, errUpdate := tx.QueryOne(
|
|
|
pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
|
|
|
"UPDATE column_settings SET column_setting_id=?, company_id=?, created_at=?, description=?, key=?, uid=?, updated_at=?, user_name=?, value=?, invalid_value=? WHERE id=? RETURNING column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
|
|
|
columnSetting.Id, columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue), columnSetting.Identify()); errUpdate != nil {
|
|
|
return columnSetting, errUpdate
|
|
|
//if _, errUpdate := tx.QueryOne(
|
|
|
// pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
|
|
|
// "UPDATE column_settings SET company_id=?, created_at=?, description=?, key=?, uid=?, updated_at=?, user_name=?, value=?, invalid_value=? WHERE id=? RETURNING id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
|
|
|
// columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue), columnSetting.Identify()); errUpdate != nil {
|
|
|
// return columnSetting, errUpdate
|
|
|
//}
|
|
|
_, err := tx.Model(columnSettingModel).WherePK().
|
|
|
Column("company_id", "created_at", "description", "key", "uid", "updated_at", "user_name", "value", "invalid_value").Update()
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
return columnSetting, nil
|
...
|
...
|
@@ -150,7 +174,7 @@ func (repository *ColumnSettingRepository) transformPgModelToDomainModel(columnS |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func NewColumnSettingRepository(transactionContext *pgTransaction.TransactionContext) (*ColumnSettingRepository, error) {
|
|
|
func NewColumnSettingRepository(transactionContext *transaction.TransactionContext) (*ColumnSettingRepository, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
} else {
|
...
|
...
|
|