|
|
package repository
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
|
|
|
)
|
|
|
|
|
|
//任务
|
...
|
...
|
@@ -13,18 +19,81 @@ type TaskIgnoreRepository struct { |
|
|
|
|
|
var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil)
|
|
|
|
|
|
func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore {
|
|
|
return &domain.TaskIgnore{
|
|
|
Id: d.Id,
|
|
|
TaskId: d.TaskId,
|
|
|
UserId: d.UserId,
|
|
|
CreatedAt: d.CreatedAt,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
|
|
|
panic("not implemented") // TODO: Implement
|
|
|
if param.Id == 0 {
|
|
|
param.CreatedAt = time.Now()
|
|
|
return nil
|
|
|
}
|
|
|
m := models.TaskIgnore{
|
|
|
Id: param.Id,
|
|
|
TaskId: param.TaskId,
|
|
|
UserId: param.UserId,
|
|
|
CreatedAt: param.CreatedAt,
|
|
|
}
|
|
|
db := repo.transactionContext.PgTx
|
|
|
if m.Id == 0 {
|
|
|
_, err := db.Model(&m).Insert()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
|
_, err := db.Model(&m).WherePK().Update()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
param.Id = m.Id
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (repo *TaskIgnoreRepository) Remove(id int) error {
|
|
|
panic("not implemented") // TODO: Implement
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
_, err := tx.Model(&models.TaskIgnore{}).
|
|
|
Where("id=?", id).Delete()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) {
|
|
|
panic("not implemented") // TODO: Implement
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
m := new(models.TaskIgnore)
|
|
|
query := tx.Model(m)
|
|
|
query.Where("deleted_at isnull")
|
|
|
if id, ok := queryOptions["id"]; ok {
|
|
|
query.Where("id=?", id)
|
|
|
}
|
|
|
if err := query.First(); err != nil {
|
|
|
if errors.Is(err, pg.ErrNoRows) {
|
|
|
return nil, fmt.Errorf("没有找到 task_ignore 数据")
|
|
|
} else {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
u := repo.TransformToDomain(m)
|
|
|
return u, nil
|
|
|
}
|
|
|
|
|
|
func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) {
|
|
|
panic("not implemented") // TODO: Implement
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
var m []*models.TaskIgnore
|
|
|
query := tx.Model(&m)
|
|
|
query.Order("id desc")
|
|
|
count, err := query.SelectAndCount()
|
|
|
if err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
|
|
var datas []*domain.TaskIgnore
|
|
|
for _, v := range m {
|
|
|
d := repo.TransformToDomain(v)
|
|
|
datas = append(datas, d)
|
|
|
}
|
|
|
return count, datas, nil
|
|
|
} |
...
|
...
|
|