1
|
package repository
|
1
|
package repository
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "errors"
|
|
|
5
|
+ "fmt"
|
|
|
6
|
+ "time"
|
|
|
7
|
+
|
|
|
8
|
+ "github.com/go-pg/pg/v10"
|
4
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
9
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
|
6
|
)
|
12
|
)
|
7
|
|
13
|
|
8
|
//任务
|
14
|
//任务
|
|
@@ -13,18 +19,81 @@ type TaskIgnoreRepository struct { |
|
@@ -13,18 +19,81 @@ type TaskIgnoreRepository struct { |
13
|
|
19
|
|
14
|
var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil)
|
20
|
var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil)
|
15
|
|
21
|
|
|
|
22
|
+func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore {
|
|
|
23
|
+ return &domain.TaskIgnore{
|
|
|
24
|
+ Id: d.Id,
|
|
|
25
|
+ TaskId: d.TaskId,
|
|
|
26
|
+ UserId: d.UserId,
|
|
|
27
|
+ CreatedAt: d.CreatedAt,
|
|
|
28
|
+ }
|
|
|
29
|
+}
|
|
|
30
|
+
|
16
|
func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
|
31
|
func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
|
17
|
- panic("not implemented") // TODO: Implement
|
32
|
+ if param.Id == 0 {
|
|
|
33
|
+ param.CreatedAt = time.Now()
|
|
|
34
|
+ return nil
|
|
|
35
|
+ }
|
|
|
36
|
+ m := models.TaskIgnore{
|
|
|
37
|
+ Id: param.Id,
|
|
|
38
|
+ TaskId: param.TaskId,
|
|
|
39
|
+ UserId: param.UserId,
|
|
|
40
|
+ CreatedAt: param.CreatedAt,
|
|
|
41
|
+ }
|
|
|
42
|
+ db := repo.transactionContext.PgTx
|
|
|
43
|
+ if m.Id == 0 {
|
|
|
44
|
+ _, err := db.Model(&m).Insert()
|
|
|
45
|
+ if err != nil {
|
|
|
46
|
+ return err
|
|
|
47
|
+ }
|
|
|
48
|
+ } else {
|
|
|
49
|
+ _, err := db.Model(&m).WherePK().Update()
|
|
|
50
|
+ if err != nil {
|
|
|
51
|
+ return err
|
|
|
52
|
+ }
|
|
|
53
|
+ }
|
|
|
54
|
+ param.Id = m.Id
|
|
|
55
|
+ return nil
|
18
|
}
|
56
|
}
|
19
|
|
57
|
|
20
|
func (repo *TaskIgnoreRepository) Remove(id int) error {
|
58
|
func (repo *TaskIgnoreRepository) Remove(id int) error {
|
21
|
- panic("not implemented") // TODO: Implement
|
59
|
+ tx := repo.transactionContext.PgTx
|
|
|
60
|
+ _, err := tx.Model(&models.TaskIgnore{}).
|
|
|
61
|
+ Where("id=?", id).Delete()
|
|
|
62
|
+ return err
|
22
|
}
|
63
|
}
|
23
|
|
64
|
|
24
|
func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) {
|
65
|
func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) {
|
25
|
- panic("not implemented") // TODO: Implement
|
66
|
+ tx := repo.transactionContext.PgTx
|
|
|
67
|
+ m := new(models.TaskIgnore)
|
|
|
68
|
+ query := tx.Model(m)
|
|
|
69
|
+ query.Where("deleted_at isnull")
|
|
|
70
|
+ if id, ok := queryOptions["id"]; ok {
|
|
|
71
|
+ query.Where("id=?", id)
|
|
|
72
|
+ }
|
|
|
73
|
+ if err := query.First(); err != nil {
|
|
|
74
|
+ if errors.Is(err, pg.ErrNoRows) {
|
|
|
75
|
+ return nil, fmt.Errorf("没有找到 task_ignore 数据")
|
|
|
76
|
+ } else {
|
|
|
77
|
+ return nil, err
|
|
|
78
|
+ }
|
|
|
79
|
+ }
|
|
|
80
|
+ u := repo.TransformToDomain(m)
|
|
|
81
|
+ return u, nil
|
26
|
}
|
82
|
}
|
27
|
|
83
|
|
28
|
func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) {
|
84
|
func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) {
|
29
|
- panic("not implemented") // TODO: Implement
|
85
|
+ tx := repo.transactionContext.PgTx
|
|
|
86
|
+ var m []*models.TaskIgnore
|
|
|
87
|
+ query := tx.Model(&m)
|
|
|
88
|
+ query.Order("id desc")
|
|
|
89
|
+ count, err := query.SelectAndCount()
|
|
|
90
|
+ if err != nil {
|
|
|
91
|
+ return 0, nil, err
|
|
|
92
|
+ }
|
|
|
93
|
+ var datas []*domain.TaskIgnore
|
|
|
94
|
+ for _, v := range m {
|
|
|
95
|
+ d := repo.TransformToDomain(v)
|
|
|
96
|
+ datas = append(datas, d)
|
|
|
97
|
+ }
|
|
|
98
|
+ return count, datas, nil
|
30
|
} |
99
|
} |