...
|
...
|
@@ -2,7 +2,7 @@ package repository |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
|
...
|
...
|
@@ -38,23 +38,7 @@ func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSett |
|
|
if err != nil {
|
|
|
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 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 {
|
...
|
...
|
@@ -67,27 +51,26 @@ func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSett |
|
|
func (repository *ColumnSettingRepository) Remove(columnSetting *domain.ColumnSetting, columnSettings []*domain.ColumnSetting) (*domain.ColumnSetting, []*domain.ColumnSetting, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
|
|
|
// 单个删除
|
|
|
if columnSetting != nil {
|
|
|
// 单个删除
|
|
|
columnSettingModel := new(models.ColumnSetting)
|
|
|
columnSettingModel.Id = columnSetting.Identify().(int64)
|
|
|
if _, err := tx.Model(columnSettingModel).WherePK().Delete(); err != nil {
|
|
|
if _, err := tx.Model(&columnSettingModel).WherePK().Delete(); err != nil {
|
|
|
return columnSetting, nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 批量删除
|
|
|
if len(columnSettings) > 0 {
|
|
|
var columnSettingModels []*models.ColumnSetting
|
|
|
var ids []int64
|
|
|
for _, setting := range columnSettings {
|
|
|
columnSettingModels = append(columnSettingModels, &models.ColumnSetting{
|
|
|
Id: setting.Identify().(int64),
|
|
|
})
|
|
|
ids = append(ids, setting.Identify().(int64))
|
|
|
}
|
|
|
if _, err := tx.Model(columnSettingModels).WherePK().Delete(); err != nil {
|
|
|
if _, err := tx.Model((*models.ColumnSetting)(nil)).Where("id IN (?)", pg.In(ids)).Delete(); err != nil {
|
|
|
return nil, columnSettings, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return columnSetting, columnSettings, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -118,33 +101,25 @@ func (repository *ColumnSettingRepository) FindOne(queryOptions map[string]inter |
|
|
}
|
|
|
}
|
|
|
|
|
|
func (repository *ColumnSettingRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ColumnSetting, error) {
|
|
|
func (repository *ColumnSettingRepository) Find(queryOptions domain.ColumnSettingFindQuery) (int64, []*domain.ColumnSetting, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
var columnSettingModels []*models.ColumnSetting
|
|
|
var columnSettingModels []models.ColumnSetting
|
|
|
columnSettings := make([]*domain.ColumnSetting, 0)
|
|
|
query := tx.Model(&columnSettingModels)
|
|
|
if ids, ok := queryOptions["ids"]; ok {
|
|
|
query = query.Where("column_setting.uid IN (?)", pg.In(ids.([]int64)))
|
|
|
if len(queryOptions.Ids) > 0 {
|
|
|
query = query.Where("column_setting.uid IN (?)", pg.In(queryOptions.Ids))
|
|
|
}
|
|
|
if uid, ok := queryOptions["uid"]; ok {
|
|
|
query = query.Where("column_setting.uid = ?", uid)
|
|
|
if queryOptions.Uid > 0 {
|
|
|
query = query.Where("column_setting.uid = ?", queryOptions.Uid)
|
|
|
}
|
|
|
if companyId, ok := queryOptions["companyId"]; ok {
|
|
|
query = query.Where("column_setting.company_id = ?", companyId)
|
|
|
if queryOptions.CompanyId > 0 {
|
|
|
query = query.Where("column_setting.company_id = ?", queryOptions.CompanyId)
|
|
|
}
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
queryOffset := offset.(int)
|
|
|
if queryOffset > -1 {
|
|
|
query = query.Offset(queryOffset)
|
|
|
}
|
|
|
} else {
|
|
|
query = query.Offset(0)
|
|
|
if queryOptions.Offset > -1 {
|
|
|
query = query.Offset(queryOptions.Offset)
|
|
|
}
|
|
|
if limit, ok := queryOptions["limit"]; ok {
|
|
|
queryLimit := limit.(int)
|
|
|
if queryLimit > -1 {
|
|
|
query = query.Limit(queryLimit)
|
|
|
}
|
|
|
if queryOptions.Limit > 0 {
|
|
|
query = query.Limit(queryOptions.Limit)
|
|
|
} else {
|
|
|
query = query.Limit(20)
|
|
|
}
|
...
|
...
|
@@ -152,7 +127,7 @@ func (repository *ColumnSettingRepository) Find(queryOptions map[string]interfac |
|
|
return 0, columnSettings, err
|
|
|
} else {
|
|
|
for _, columnSettingModel := range columnSettingModels {
|
|
|
if columnSetting, errTrans := repository.transformPgModelToDomainModel(columnSettingModel); errTrans != nil {
|
|
|
if columnSetting, errTrans := repository.transformPgModelToDomainModel(&columnSettingModel); errTrans != nil {
|
|
|
return 0, columnSettings, errTrans
|
|
|
} else {
|
|
|
columnSettings = append(columnSettings, columnSetting)
|
...
|
...
|
|