正在显示
7 个修改的文件
包含
287 行增加
和
15 行删除
@@ -11,16 +11,15 @@ const ( | @@ -11,16 +11,15 @@ const ( | ||
11 | 11 | ||
12 | // 任务 | 12 | // 任务 |
13 | type Task struct { | 13 | type Task struct { |
14 | - Id int `json:"id"` | ||
15 | - CreatedAt time.Time `json:"createdAt"` | ||
16 | - UpdatedAt time.Time `json:"updatedAt"` | ||
17 | - DeletedAt time.Time `json:"deletedAt"` | ||
18 | - Name string `json:"name"` // 任务名称 | ||
19 | - Leader TaskLeader `json:"leader"` // 任务负责人 | ||
20 | - Status TaskState `json:"status"` // 任务的状态 | ||
21 | - StageList []TaskStage `json:"stageList"` // 里程碑 | ||
22 | - Level int `json:"level"` // 优先级,值越小优先级越高 | ||
23 | - LevalName string `json:"levalName"` // 优先级名称 | 14 | + Id int `json:"id"` |
15 | + CreatedAt time.Time `json:"createdAt"` | ||
16 | + UpdatedAt time.Time `json:"updatedAt"` | ||
17 | + DeletedAt time.Time `json:"deletedAt"` | ||
18 | + Name string `json:"name"` // 任务名称 | ||
19 | + Leader TaskLeader `json:"leader"` // 任务负责人 | ||
20 | + Status TaskState `json:"status"` // 任务的状态 | ||
21 | + Level int `json:"level"` // 优先级,值越小优先级越高 | ||
22 | + LevalName string `json:"levalName"` // 优先级名称 | ||
24 | } | 23 | } |
25 | 24 | ||
26 | type TaskLeader struct { | 25 | type TaskLeader struct { |
@@ -49,5 +48,4 @@ type TaskRepository interface { | @@ -49,5 +48,4 @@ type TaskRepository interface { | ||
49 | Remove(id int) error | 48 | Remove(id int) error |
50 | FindOne(queryOptions map[string]interface{}) (*Task, error) | 49 | FindOne(queryOptions map[string]interface{}) (*Task, error) |
51 | Find(queryOptions map[string]interface{}) (int, []*Task, error) | 50 | Find(queryOptions map[string]interface{}) (int, []*Task, error) |
52 | - RemoveStage(stageData TaskStage) | ||
53 | } | 51 | } |
@@ -9,3 +9,10 @@ type TaskIgnore struct { | @@ -9,3 +9,10 @@ type TaskIgnore struct { | ||
9 | UserId int `json:"userId"` | 9 | UserId int `json:"userId"` |
10 | CreatedAt time.Time `json:"-"` | 10 | CreatedAt time.Time `json:"-"` |
11 | } | 11 | } |
12 | + | ||
13 | +type TaskIgnoreRepository interface { | ||
14 | + Save(param *TaskIgnore) error | ||
15 | + Remove(id int) error | ||
16 | + FindOne(queryOptions map[string]interface{}) (*TaskIgnore, error) | ||
17 | + Find(queryOptions map[string]interface{}) (int, []*TaskIgnore, error) | ||
18 | +} |
@@ -19,6 +19,12 @@ type TaskStage struct { | @@ -19,6 +19,12 @@ type TaskStage struct { | ||
19 | Name string `json:"name"` //里程碑名称 | 19 | Name string `json:"name"` //里程碑名称 |
20 | SortBy int `json:"sortBy"` //排序 | 20 | SortBy int `json:"sortBy"` //排序 |
21 | Status TaskStageState `json:"status"` //里程碑完成情况 | 21 | Status TaskStageState `json:"status"` //里程碑完成情况 |
22 | - PlanCompletedAt time.Time `json:"planCompletedAt"` //计划完成时间 | ||
23 | - RealCompletedAt time.Time `json:"realCompletedAt"` //时间完成时间 | 22 | + PlanCompletedAt int `json:"planCompletedAt"` //计划完成时间 |
23 | + RealCompletedAt int `json:"realCompletedAt"` //时间完成时间 | ||
24 | +} | ||
25 | +type TaskStageRepository interface { | ||
26 | + Save(param []*TaskStage) error | ||
27 | + Remove(id int) error | ||
28 | + FindOne(queryOptions map[string]interface{}) (*TaskStage, error) | ||
29 | + Find(queryOptions map[string]interface{}) (int, []*TaskStage, error) | ||
24 | } | 30 | } |
@@ -13,6 +13,6 @@ type TaskStage struct { | @@ -13,6 +13,6 @@ type TaskStage struct { | ||
13 | Name string `pg:"name"` //里程碑名称 | 13 | Name string `pg:"name"` //里程碑名称 |
14 | SortBy int `pg:"sort_by"` //排序 | 14 | SortBy int `pg:"sort_by"` //排序 |
15 | Status int `pg:"status"` //里程碑完成情况 | 15 | Status int `pg:"status"` //里程碑完成情况 |
16 | - PlanCompletedAt time.Time `pg:"plan_completed_at"` //计划完成时间 | ||
17 | - RealCompletedAt time.Time `pg:"real_completed_at"` //时间完成时间 | 16 | + PlanCompletedAt int `pg:"plan_completed_at"` //计划完成时间 |
17 | + RealCompletedAt int `pg:"real_completed_at"` //时间完成时间 | ||
18 | } | 18 | } |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +//任务 | ||
9 | + | ||
10 | +type TaskIgnoreRepository struct { | ||
11 | + transactionContext *pgTransaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil) | ||
15 | + | ||
16 | +func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error { | ||
17 | + panic("not implemented") // TODO: Implement | ||
18 | +} | ||
19 | + | ||
20 | +func (repo *TaskIgnoreRepository) Remove(id int) error { | ||
21 | + panic("not implemented") // TODO: Implement | ||
22 | +} | ||
23 | + | ||
24 | +func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) { | ||
25 | + panic("not implemented") // TODO: Implement | ||
26 | +} | ||
27 | + | ||
28 | +func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) { | ||
29 | + panic("not implemented") // TODO: Implement | ||
30 | +} |
1 | package repository | 1 | package repository |
2 | 2 | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/go-pg/pg/v10" | ||
9 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
12 | +) | ||
13 | + | ||
3 | //任务 | 14 | //任务 |
15 | + | ||
16 | +type TaskRepository struct { | ||
17 | + transactionContext *pgTransaction.TransactionContext | ||
18 | +} | ||
19 | + | ||
20 | +var _ domain.TaskRepository = (*TaskRepository)(nil) | ||
21 | + | ||
22 | +func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | ||
23 | + return &domain.Task{ | ||
24 | + Id: d.Id, | ||
25 | + CreatedAt: d.CreatedAt, | ||
26 | + UpdatedAt: d.UpdatedAt, | ||
27 | + DeletedAt: d.DeletedAt, | ||
28 | + Name: d.Name, | ||
29 | + Leader: d.Leader, | ||
30 | + Status: domain.TaskState(d.Status), | ||
31 | + Level: d.Level, | ||
32 | + LevalName: d.LevalName, | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | +func (repo *TaskRepository) Save(param *domain.Task) error { | ||
37 | + param.UpdatedAt = time.Now() | ||
38 | + if param.Id == 0 { | ||
39 | + param.CreatedAt = time.Now() | ||
40 | + return nil | ||
41 | + } | ||
42 | + m := models.Task{ | ||
43 | + Id: param.Id, | ||
44 | + CreatedAt: param.CreatedAt, | ||
45 | + UpdatedAt: param.UpdatedAt, | ||
46 | + DeletedAt: param.DeletedAt, | ||
47 | + Name: param.Name, | ||
48 | + Leader: param.Leader, | ||
49 | + Status: int(param.Status), | ||
50 | + Level: param.Level, | ||
51 | + LevalName: param.LevalName, | ||
52 | + } | ||
53 | + db := repo.transactionContext.PgTx | ||
54 | + if m.Id == 0 { | ||
55 | + _, err := db.Model(&m).Insert() | ||
56 | + if err != nil { | ||
57 | + return err | ||
58 | + } | ||
59 | + } else { | ||
60 | + _, err := db.Model(&m).WherePK().Update() | ||
61 | + if err != nil { | ||
62 | + return err | ||
63 | + } | ||
64 | + } | ||
65 | + param.Id = m.Id | ||
66 | + return nil | ||
67 | +} | ||
68 | + | ||
69 | +func (repo *TaskRepository) Remove(id int) error { | ||
70 | + tx := repo.transactionContext.PgTx | ||
71 | + nowTime := time.Now() | ||
72 | + _, err := tx.Model(&models.Task{}). | ||
73 | + Where("id=?", id). | ||
74 | + Set("deleted_at=?", nowTime). | ||
75 | + Update() | ||
76 | + return err | ||
77 | + | ||
78 | +} | ||
79 | + | ||
80 | +func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) { | ||
81 | + tx := repo.transactionContext.PgTx | ||
82 | + m := new(models.Task) | ||
83 | + query := tx.Model(m) | ||
84 | + query.Where("deleted_at isnull") | ||
85 | + if id, ok := queryOptions["id"]; ok { | ||
86 | + query.Where("id=?", id) | ||
87 | + } | ||
88 | + if err := query.First(); err != nil { | ||
89 | + if errors.Is(err, pg.ErrNoRows) { | ||
90 | + return nil, fmt.Errorf("没有找到task数据") | ||
91 | + } else { | ||
92 | + return nil, err | ||
93 | + } | ||
94 | + } | ||
95 | + u := repo.TransformToDomain(m) | ||
96 | + return u, nil | ||
97 | +} | ||
98 | + | ||
99 | +func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Task, error) { | ||
100 | + tx := repo.transactionContext.PgTx | ||
101 | + var m []*models.Task | ||
102 | + query := tx.Model(&m). | ||
103 | + Where("deleted_at isnull"). | ||
104 | + Limit(20) | ||
105 | + | ||
106 | + query.Order("id desc") | ||
107 | + count, err := query.SelectAndCount() | ||
108 | + if err != nil { | ||
109 | + return 0, nil, err | ||
110 | + } | ||
111 | + var datas []*domain.Task | ||
112 | + for _, v := range m { | ||
113 | + d := repo.TransformToDomain(v) | ||
114 | + datas = append(datas, d) | ||
115 | + } | ||
116 | + return count, datas, nil | ||
117 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/go-pg/pg/v10" | ||
9 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
12 | +) | ||
13 | + | ||
14 | +//任务 | ||
15 | + | ||
16 | +type TaskStageRepository struct { | ||
17 | + transactionContext *pgTransaction.TransactionContext | ||
18 | +} | ||
19 | + | ||
20 | +var _ domain.TaskStageRepository = (*TaskStageRepository)(nil) | ||
21 | + | ||
22 | +func (repo *TaskStageRepository) TransformToDomain(d *models.TaskStage) *domain.TaskStage { | ||
23 | + return &domain.TaskStage{ | ||
24 | + Id: d.Id, | ||
25 | + TaskId: 0, | ||
26 | + CreatedAt: d.CreatedAt, | ||
27 | + UpdatedAt: d.UpdatedAt, | ||
28 | + DeletedAt: d.DeletedAt, | ||
29 | + Name: d.Name, | ||
30 | + SortBy: d.SortBy, | ||
31 | + Status: domain.TaskStageState(d.Status), | ||
32 | + PlanCompletedAt: d.PlanCompletedAt, | ||
33 | + RealCompletedAt: d.RealCompletedAt, | ||
34 | + } | ||
35 | +} | ||
36 | + | ||
37 | +func (repo *TaskStageRepository) Save(param []*domain.TaskStage) error { | ||
38 | + db := repo.transactionContext.PgTx | ||
39 | + nowTime := time.Now() | ||
40 | + for _, val := range param { | ||
41 | + m := models.TaskStage{ | ||
42 | + Id: val.Id, | ||
43 | + TaskId: val.TaskId, | ||
44 | + CreatedAt: val.CreatedAt, | ||
45 | + UpdatedAt: nowTime, | ||
46 | + DeletedAt: val.DeletedAt, | ||
47 | + Name: val.Name, | ||
48 | + SortBy: val.SortBy, | ||
49 | + Status: int(val.Status), | ||
50 | + PlanCompletedAt: val.PlanCompletedAt, | ||
51 | + RealCompletedAt: val.RealCompletedAt, | ||
52 | + } | ||
53 | + if m.Id == 0 { | ||
54 | + m.CreatedAt = nowTime | ||
55 | + _, err := db.Model(&m).Insert() | ||
56 | + if err != nil { | ||
57 | + return err | ||
58 | + } | ||
59 | + } else { | ||
60 | + _, err := db.Model(&m).WherePK().Update() | ||
61 | + if err != nil { | ||
62 | + return err | ||
63 | + } | ||
64 | + } | ||
65 | + val.Id = m.Id | ||
66 | + } | ||
67 | + return nil | ||
68 | +} | ||
69 | + | ||
70 | +func (repo *TaskStageRepository) Remove(id int) error { | ||
71 | + tx := repo.transactionContext.PgTx | ||
72 | + nowTime := time.Now() | ||
73 | + _, err := tx.Model(&models.TaskStage{}). | ||
74 | + Where("id=?", id). | ||
75 | + Set("deleted_at=?", nowTime). | ||
76 | + Update() | ||
77 | + return err | ||
78 | +} | ||
79 | + | ||
80 | +func (repo *TaskStageRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskStage, error) { | ||
81 | + tx := repo.transactionContext.PgTx | ||
82 | + m := new(models.TaskStage) | ||
83 | + query := tx.Model(m) | ||
84 | + query.Where("deleted_at isnull") | ||
85 | + if id, ok := queryOptions["id"]; ok { | ||
86 | + query.Where("id=?", id) | ||
87 | + } | ||
88 | + if err := query.First(); err != nil { | ||
89 | + if errors.Is(err, pg.ErrNoRows) { | ||
90 | + return nil, fmt.Errorf("没有找到task数据") | ||
91 | + } else { | ||
92 | + return nil, err | ||
93 | + } | ||
94 | + } | ||
95 | + u := repo.TransformToDomain(m) | ||
96 | + return u, nil | ||
97 | +} | ||
98 | + | ||
99 | +func (repo *TaskStageRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskStage, error) { | ||
100 | + tx := repo.transactionContext.PgTx | ||
101 | + var m []*models.TaskStage | ||
102 | + query := tx.Model(&m). | ||
103 | + Where("deleted_at isnull"). | ||
104 | + Limit(20) | ||
105 | + | ||
106 | + query.Order("id desc") | ||
107 | + count, err := query.SelectAndCount() | ||
108 | + if err != nil { | ||
109 | + return 0, nil, err | ||
110 | + } | ||
111 | + var datas []*domain.TaskStage | ||
112 | + for _, v := range m { | ||
113 | + d := repo.TransformToDomain(v) | ||
114 | + datas = append(datas, d) | ||
115 | + } | ||
116 | + return count, datas, nil | ||
117 | +} |
-
请 注册 或 登录 后发表评论