正在显示
10 个修改的文件
包含
464 行增加
和
173 行删除
@@ -485,6 +485,7 @@ func (srv StaffAssessServeice) buildTaskRecord(staffAssess *domain.StaffAssess) | @@ -485,6 +485,7 @@ func (srv StaffAssessServeice) buildTaskRecord(staffAssess *domain.StaffAssess) | ||
485 | AnomalyState: domain.AnomalyStateInit, | 485 | AnomalyState: domain.AnomalyStateInit, |
486 | TaskStages: []domain.TaskStage{}, | 486 | TaskStages: []domain.TaskStage{}, |
487 | TaskStageCheck: domain.TaskStage{}, | 487 | TaskStageCheck: domain.TaskStage{}, |
488 | + TaskCreatedBy: taskList[0].CreatedBy, | ||
488 | } | 489 | } |
489 | sort.Slice(taskStageList, func(i, j int) bool { | 490 | sort.Slice(taskStageList, func(i, j int) bool { |
490 | return taskStageList[i].SortBy < taskStageList[j].SortBy | 491 | return taskStageList[i].SortBy < taskStageList[j].SortBy |
@@ -11,6 +11,8 @@ import ( | @@ -11,6 +11,8 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +//TODO 检查任务里程碑反馈, 记录异常情况 | ||
15 | + | ||
14 | // 检查昨日提交的任务里程碑反馈 | 16 | // 检查昨日提交的任务里程碑反馈 |
15 | func CheckYesterdayTaskRecord() { | 17 | func CheckYesterdayTaskRecord() { |
16 | nowTime := time.Now() | 18 | nowTime := time.Now() |
@@ -90,10 +92,8 @@ func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) { | @@ -90,10 +92,8 @@ func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) { | ||
90 | _ = transactionContext.RollbackTransaction() | 92 | _ = transactionContext.RollbackTransaction() |
91 | }() | 93 | }() |
92 | 94 | ||
93 | - // nowDay := time.Now().Format("2006-01-02") | ||
94 | nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) | 95 | nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) |
95 | yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02") | 96 | yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02") |
96 | - | ||
97 | taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{ | 97 | taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{ |
98 | "transactionContext": transactionContext, | 98 | "transactionContext": transactionContext, |
99 | }) | 99 | }) |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +func checkTaskRecordV2(param *domain.TaskRecord) error { | ||
11 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
12 | + if err != nil { | ||
13 | + return err | ||
14 | + } | ||
15 | + if err := transactionContext.StartTransaction(); err != nil { | ||
16 | + return err | ||
17 | + } | ||
18 | + defer func() { | ||
19 | + _ = transactionContext.RollbackTransaction() | ||
20 | + }() | ||
21 | + taskRepo := factory.CreateTaskRepository(map[string]interface{}{ | ||
22 | + "transactionContext": transactionContext, | ||
23 | + }) | ||
24 | + | ||
25 | + _, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId}) | ||
26 | + if err != nil { | ||
27 | + return fmt.Errorf("获取任务数据失败:%s", err) | ||
28 | + } | ||
29 | + if len(taskDataList) == 0 { | ||
30 | + return nil | ||
31 | + } | ||
32 | + taskData := taskDataList[0] | ||
33 | + anomalyDataTmp := domain.TaskAnomaly{ | ||
34 | + Id: taskData.Id, | ||
35 | + CreatedAt: taskData.CreatedAt, | ||
36 | + UpdatedAt: taskData.UpdatedAt, | ||
37 | + CompanyId: taskData.CompanyId, | ||
38 | + TaskId: taskData.Id, | ||
39 | + Category: 0, | ||
40 | + CurrentStage: taskData.CurrentStage, | ||
41 | + LastStage: taskData.LastStage, | ||
42 | + AssessFlag: 0, | ||
43 | + WarnFlag: 0, | ||
44 | + AssistFlag: 0, | ||
45 | + IsLast: 1, | ||
46 | + TaskLevel: taskData.LevelName, | ||
47 | + TaskName: taskData.Name, | ||
48 | + TaskAlias: taskData.Alias, | ||
49 | + TaskSortBy: taskData.SortBy, | ||
50 | + TaskEndTime: taskData.EndTime, | ||
51 | + RecordBegin: 0, | ||
52 | + NoticeWho: []int64{}, | ||
53 | + Marks: map[string]string{ | ||
54 | + "a": "", "b": "", "c": "", "d": "", | ||
55 | + }, | ||
56 | + } | ||
57 | + var anomalyList []domain.TaskAnomaly | ||
58 | + | ||
59 | + // 检查反馈异常 | ||
60 | + if param.IsRemarkAnomaly() { | ||
61 | + taskData.Anomaly += 1 | ||
62 | + anomalyDataTmp.Category = 2 | ||
63 | + anomalyList = append(anomalyList, anomalyDataTmp) | ||
64 | + } else { | ||
65 | + taskData.Anomaly = 0 | ||
66 | + } | ||
67 | + // 检查里程碑异常 | ||
68 | + if param.IsTaskStageAnomaly() { | ||
69 | + taskData.WarnFlag = domain.TaskWarn | ||
70 | + } else { | ||
71 | + taskData.WarnFlag = domain.TaskWarnNull | ||
72 | + } | ||
73 | + // 检查辅导异常 | ||
74 | + if param.IsAssistAnomaly() { | ||
75 | + taskData.AssistFlag += 1 | ||
76 | + } else { | ||
77 | + taskData.AssistFlag = 0 | ||
78 | + } | ||
79 | + | ||
80 | + err = taskRepo.Save(taskData) | ||
81 | + if err != nil { | ||
82 | + return fmt.Errorf("保存任务数据:%s", err) | ||
83 | + } | ||
84 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
85 | + return err | ||
86 | + } | ||
87 | + return nil | ||
88 | +} |
@@ -29,41 +29,20 @@ func dayEndTime(t time.Time) time.Time { | @@ -29,41 +29,20 @@ func dayEndTime(t time.Time) time.Time { | ||
29 | return t2 | 29 | return t2 |
30 | } | 30 | } |
31 | 31 | ||
32 | -// func dayZeroTime(t time.Time) time.Time { | ||
33 | -// y, m, d := t.Local().Date() | ||
34 | -// t2 := time.Date(y, m, d, 0, 0, 0, 0, time.Local) | ||
35 | -// return t2 | ||
36 | -// } | ||
37 | - | ||
38 | -// func (srv TaskService) CreateTaskTest(param *command.CreateTaskCommand) error { | ||
39 | -// transactionContext, err := factory.CreateTransactionContext(nil) | ||
40 | -// if err != nil { | ||
41 | -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
42 | -// } | ||
43 | -// if err := transactionContext.StartTransaction(); err != nil { | ||
44 | -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
45 | -// } | ||
46 | -// defer func() { | ||
47 | -// _ = transactionContext.RollbackTransaction() | ||
48 | -// }() | ||
49 | -// err = srv.CreateTask(transactionContext, param) | ||
50 | -// if err != nil { | ||
51 | -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | ||
52 | -// } | ||
53 | -// if err := transactionContext.CommitTransaction(); err != nil { | ||
54 | -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
55 | -// } | ||
56 | -// return nil | ||
57 | -// } | 32 | +func dayZeroTime(t time.Time) time.Time { |
33 | + y, m, d := t.Local().Date() | ||
34 | + t2 := time.Date(y, m, d, 0, 0, 0, 0, time.Local) | ||
35 | + return t2 | ||
36 | +} | ||
58 | 37 | ||
59 | // CreateTask 重评估模板中创建 | 38 | // CreateTask 重评估模板中创建 |
60 | func (srv TaskService) CreateTaskByProject(transactionContext application.TransactionContext, param *command.CreateTaskByProjectCommand) error { | 39 | func (srv TaskService) CreateTaskByProject(transactionContext application.TransactionContext, param *command.CreateTaskByProjectCommand) error { |
61 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ | 40 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ |
62 | "transactionContext": transactionContext, | 41 | "transactionContext": transactionContext, |
63 | }) | 42 | }) |
64 | - taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ | ||
65 | - "transactionContext": transactionContext, | ||
66 | - }) | 43 | + // taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ |
44 | + // "transactionContext": transactionContext, | ||
45 | + // }) | ||
67 | cnt, _, err := taskRepo.Find(map[string]interface{}{ | 46 | cnt, _, err := taskRepo.Find(map[string]interface{}{ |
68 | "name": param.Name, | 47 | "name": param.Name, |
69 | "leaderId": strconv.Itoa(param.LeaderId), | 48 | "leaderId": strconv.Itoa(param.LeaderId), |
@@ -123,36 +102,11 @@ func (srv TaskService) CreateTaskByProject(transactionContext application.Transa | @@ -123,36 +102,11 @@ func (srv TaskService) CreateTaskByProject(transactionContext application.Transa | ||
123 | if err != nil { | 102 | if err != nil { |
124 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | 103 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) |
125 | } | 104 | } |
126 | - newTaskStage := []*domain.TaskStage{ | ||
127 | - // { | ||
128 | - // Id: 0, | ||
129 | - // TaskId: newTask.Id, | ||
130 | - // Name: "里程碑1", | ||
131 | - // SortBy: 1, | ||
132 | - // PlanCompletedAt: nowEndTime.Add(30 * 24 * time.Hour).Unix(), | ||
133 | - // RealCompletedAt: 0, | ||
134 | - // }, | ||
135 | - // { | ||
136 | - // Id: 0, | ||
137 | - // TaskId: newTask.Id, | ||
138 | - // Name: "里程碑2", | ||
139 | - // SortBy: 2, | ||
140 | - // PlanCompletedAt: nowEndTime.Add(60 * 24 * time.Hour).Unix(), | ||
141 | - // RealCompletedAt: 0, | ||
142 | - // }, | ||
143 | - // { | ||
144 | - // Id: 0, | ||
145 | - // TaskId: newTask.Id, | ||
146 | - // Name: "里程碑3", | ||
147 | - // SortBy: 3, | ||
148 | - // PlanCompletedAt: nowEndTime.Add(90 * 24 * time.Hour).Unix(), | ||
149 | - // RealCompletedAt: 0, | ||
150 | - // }, | ||
151 | - } | ||
152 | - err = taskStageRepo.Save(newTaskStage) | ||
153 | - if err != nil { | ||
154 | - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | ||
155 | - } | 105 | + newTaskStage := []*domain.TaskStage{} |
106 | + // err = taskStageRepo.Save(newTaskStage) | ||
107 | + // if err != nil { | ||
108 | + // return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | ||
109 | + // } | ||
156 | //记录待执行的里程碑 | 110 | //记录待执行的里程碑 |
157 | newTask.SetCurrentStage(newTaskStage) | 111 | newTask.SetCurrentStage(newTaskStage) |
158 | err = taskRepo.Save(&newTask) | 112 | err = taskRepo.Save(&newTask) |
pkg/application/task/service/service2.go
0 → 100644
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | +import "time" | ||
4 | + | ||
3 | // 任务的异常记录 | 5 | // 任务的异常记录 |
4 | type TaskAnomaly struct { | 6 | type TaskAnomaly struct { |
5 | - Id int | ||
6 | - TaskId int | ||
7 | - Types int | 7 | + Id int |
8 | + CreatedAt time.Time `json:"createdAt"` | ||
9 | + UpdatedAt time.Time `json:"updatedAt"` | ||
10 | + CompanyId int `json:"companyId,string"` | ||
11 | + TaskId int `jsom:"taskId,string"` // 任务id | ||
12 | + Category int `json:"category"` // 异常记录的分类 1 里程碑异常;2反馈异常 ;3 辅导异常 | ||
13 | + CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑 | ||
14 | + LastStage TaskStage `json:"lastStage"` // 上一个完成的里程碑 | ||
15 | + AssessFlag int `json:"anomaly"` // 异常反馈的次数 | ||
16 | + WarnFlag int `json:"warnFlag"` // 里程碑异常次数 | ||
17 | + AssistFlag int `json:"assistFlag"` // 辅导异常次数 | ||
18 | + IsLast int `json:"isLast"` // 是否是最新的一条记录 1 是最新的记录 2 不是最新的记录 | ||
19 | + TaskLevel string `json:"taskLevel"` // 任务类型 | ||
20 | + TaskName string `json:"taskName"` // 任务名称 | ||
21 | + TaskAlias string `json:"taskAlias"` // 任务别名 | ||
22 | + TaskSortBy TaskSortBy `json:"taskSortBy"` // 优先级排序;值越小优先级越高 | ||
23 | + TaskEndTime int64 `json:"taskEndTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间 | ||
24 | + RecordBegin int `json:"recordBegin"` // 异常记录的开始时间 | ||
25 | + NoticeWho []int64 `json:"noticeWho"` // 异常记录消息通知的人 | ||
26 | + Marks map[string]string `json:"marks"` // 已经操作的标记 | ||
27 | +} | ||
28 | + | ||
29 | +// 已点击“去更新” | ||
30 | +func (t *TaskAnomaly) MarkA() { | ||
31 | + t.Marks["a"] = "已更新" | ||
32 | +} | ||
33 | + | ||
34 | +// 已点击 "去反馈" | ||
35 | +func (t *TaskAnomaly) MarkB() { | ||
36 | + t.Marks["b"] = "已反馈" | ||
37 | +} | ||
38 | + | ||
39 | +// 已点击 "找上级" | ||
40 | +func (t *TaskAnomaly) MarkC() { | ||
41 | + t.Marks["c"] = "已求助" | ||
42 | +} | ||
43 | + | ||
44 | +// 已点击 "去辅导" | ||
45 | +func (t *TaskAnomaly) MarkD() { | ||
46 | + t.Marks["d"] = "已辅导" | ||
47 | +} | ||
48 | + | ||
49 | +// 存储 | ||
50 | +type TaskAnomalyRepository interface { | ||
51 | + Save(param *TaskAnomaly) error | ||
52 | + FindOne(queryOptions map[string]interface{}) (*TaskAnomaly, error) | ||
53 | + Find(queryOptions map[string]interface{}) (int, []*TaskAnomaly, error) | ||
8 | } | 54 | } |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "strings" | ||
4 | "time" | 5 | "time" |
5 | ) | 6 | ) |
6 | 7 | ||
@@ -46,14 +47,42 @@ type TaskRecordRepository interface { | @@ -46,14 +47,42 @@ type TaskRecordRepository interface { | ||
46 | Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error) | 47 | Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error) |
47 | } | 48 | } |
48 | 49 | ||
49 | -// 是否取消任务的里程碑反馈异常记录 | ||
50 | -// func (record *TaskRecord) CanTaskAnomaly() bool { | ||
51 | -// trimSpace := strings.TrimLeft(record.AssistContent, "\n") // 去掉前换行符 | ||
52 | -// trimSpace = strings.TrimRight(trimSpace, "\n") // 去掉后换行符 | ||
53 | -// trimSpace = strings.TrimSpace(trimSpace) // 去掉前后空格符 | ||
54 | -// // 上级填写内容有值,选项是已辅导,变为正常 | ||
55 | -// if !(len(trimSpace) == 0 || trimSpace == "无") && record.AssistLevel != AssistLevel1 { | ||
56 | -// return true | ||
57 | -// } | ||
58 | -// return false | ||
59 | -// } | 50 | +// 是否是辅导异常 |
51 | +func (r *TaskRecord) IsAssistAnomaly() bool { | ||
52 | + r.AssistContent = strings.TrimSpace(r.AssistContent) | ||
53 | + if r.AssistLevel == AssistLevel1 || r.AssistContent == "无" { | ||
54 | + return true | ||
55 | + } | ||
56 | + return false | ||
57 | +} | ||
58 | + | ||
59 | +// 是否是里程碑异常 | ||
60 | +func (r *TaskRecord) IsTaskStageAnomaly() bool { | ||
61 | + if r.TaskStageCheck.Id == 0 { | ||
62 | + return false | ||
63 | + } | ||
64 | + realCompletedAt := r.TaskStageCheck.RealCompletedAt | ||
65 | + if realCompletedAt == 0 { | ||
66 | + //假设现在完成 | ||
67 | + realCompletedAt = time.Now().Unix() | ||
68 | + } | ||
69 | + if r.TaskStageCheck.PlanCompletedAt < realCompletedAt { | ||
70 | + //逾期完成,或者预期未完成 | ||
71 | + return true | ||
72 | + } | ||
73 | + | ||
74 | + return false | ||
75 | +} | ||
76 | + | ||
77 | +// 是否是反馈异常 | ||
78 | +func (r *TaskRecord) IsRemarkAnomaly() bool { | ||
79 | + all := "" | ||
80 | + for _, val := range r.RemarkContent { | ||
81 | + txt := strings.TrimSpace(val.RemarkText) | ||
82 | + all += txt | ||
83 | + } | ||
84 | + if len(all) == 0 || all == "无" { | ||
85 | + return true | ||
86 | + } | ||
87 | + return false | ||
88 | +} |
pkg/infrastructure/pg/models/task_anomaly.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "time" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
7 | +) | ||
8 | + | ||
9 | +// 任务的异常记录 | ||
10 | +type TaskAnomaly struct { | ||
11 | + tableName struct{} `comment:"任务的异常记录" pg:"task_anomaly"` | ||
12 | + Id int `pg:"id"` | ||
13 | + CreatedAt time.Time `pg:"created_at"` | ||
14 | + UpdatedAt time.Time `pg:"updated_at"` | ||
15 | + CompanyId int `pg:"company_id"` | ||
16 | + TaskId int `pg:"task_id"` // 任务id | ||
17 | + Category int `pg:"category"` // 异常任务的分类 | ||
18 | + CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑 | ||
19 | + LastStage domain.TaskStage `pg:"last_stage"` // 上一个完成的里程碑 | ||
20 | + AssessFlag int `pg:"assess_flag,use_zero"` // 异常反馈的次数 | ||
21 | + WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常次数 | ||
22 | + AssistFlag int `pg:"assist_flag,use_zero"` // 辅导异常次数 | ||
23 | + IsLast int `pg:"is_last"` // 是否是最新的一条记录 1 是最新的记录 2 不是最新的记录 | ||
24 | + TaskLevel string `pg:"task_level"` // 任务类型 | ||
25 | + TaskName string `pg:"task_name"` // 任务名称 | ||
26 | + TaskAlias string `pg:"task_alias"` // 任务别名 | ||
27 | + TaskSortBy int `pg:"task_sort_by"` // 优先级排序;值越小优先级越高 | ||
28 | + TaskEndTime int64 `pg:"task_end_time,use_zero"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间 | ||
29 | + RecordBegin int `pg:"record_begin"` // 异常记录的开始时间 | ||
30 | + NoticeWho []int64 `pg:"notice_who"` // 异常记录消息通知的人 | ||
31 | + Marks map[string]string `pg:"marks"` // 已经操作的标记 | ||
32 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "strconv" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/go-pg/pg/v10" | ||
10 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
13 | +) | ||
14 | + | ||
15 | +//任务 | ||
16 | + | ||
17 | +type TaskRepository struct { | ||
18 | + transactionContext *pgTransaction.TransactionContext | ||
19 | +} | ||
20 | + | ||
21 | +var _ domain.TaskRepository = (*TaskRepository)(nil) | ||
22 | + | ||
23 | +func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *TaskRepository { | ||
24 | + return &TaskRepository{transactionContext: transactionContext} | ||
25 | +} | ||
26 | + | ||
27 | +func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | ||
28 | + return &domain.Task{ | ||
29 | + Id: d.Id, | ||
30 | + CreatedAt: d.CreatedAt, | ||
31 | + UpdatedAt: d.UpdatedAt, | ||
32 | + DeletedAt: d.DeletedAt, | ||
33 | + CompanyId: d.CompanyId, | ||
34 | + Name: d.Name, | ||
35 | + Alias: d.Alias, | ||
36 | + Leader: d.Leader, | ||
37 | + Status: domain.TaskState(d.Status), | ||
38 | + Level: d.Level, | ||
39 | + LevelName: d.LevelName, | ||
40 | + SortBy: domain.TaskSortBy(d.SortBy), | ||
41 | + EndTime: d.EndTime, | ||
42 | + UseEndTime: d.UseEndTime, | ||
43 | + RelatedUser: d.RelatedUser, | ||
44 | + RunAt: d.RunAt, | ||
45 | + StopAt: d.StopAt, | ||
46 | + Anomaly: d.Anomaly, | ||
47 | + WarnFlag: domain.TaskWarnFlag(d.WarnFlag), | ||
48 | + AssistFlag: d.AssistFlag, | ||
49 | + AssistFlagMax: d.AssistFlagMax, | ||
50 | + CurrentStage: d.CurrentStage, | ||
51 | + LastStage: d.LastStage, | ||
52 | + CreatedBy: d.CreatedBy, | ||
53 | + } | ||
54 | +} | ||
55 | + | ||
56 | +func (repo *TaskRepository) Save(param *domain.Task) error { | ||
57 | + param.UpdatedAt = time.Now() | ||
58 | + if param.Id == 0 { | ||
59 | + param.CreatedAt = time.Now() | ||
60 | + } | ||
61 | + m := models.Task{ | ||
62 | + Id: param.Id, | ||
63 | + CreatedAt: param.CreatedAt, | ||
64 | + UpdatedAt: param.UpdatedAt, | ||
65 | + DeletedAt: param.DeletedAt, | ||
66 | + Name: param.Name, | ||
67 | + Alias: param.Alias, | ||
68 | + CompanyId: param.CompanyId, | ||
69 | + Leader: param.Leader, | ||
70 | + Status: int(param.Status), | ||
71 | + Level: param.Level, | ||
72 | + LevelName: param.LevelName, | ||
73 | + RelatedUser: param.RelatedUser, | ||
74 | + LastStage: param.LastStage, | ||
75 | + RunAt: param.RunAt, | ||
76 | + StopAt: param.StopAt, | ||
77 | + Anomaly: param.Anomaly, | ||
78 | + WarnFlag: int(param.WarnFlag), | ||
79 | + CurrentStage: param.CurrentStage, | ||
80 | + SortBy: int(param.SortBy), | ||
81 | + EndTime: param.EndTime, | ||
82 | + UseEndTime: param.UseEndTime, | ||
83 | + AssistFlag: param.AssistFlag, | ||
84 | + AssistFlagMax: param.AssistFlagMax, | ||
85 | + CreatedBy: param.CreatedBy, | ||
86 | + } | ||
87 | + db := repo.transactionContext.PgTx | ||
88 | + if m.Id == 0 { | ||
89 | + _, err := db.Model(&m).Insert() | ||
90 | + if err != nil { | ||
91 | + return err | ||
92 | + } | ||
93 | + } else { | ||
94 | + _, err := db.Model(&m).WherePK().Update() | ||
95 | + if err != nil { | ||
96 | + return err | ||
97 | + } | ||
98 | + } | ||
99 | + param.Id = m.Id | ||
100 | + return nil | ||
101 | +} | ||
102 | + | ||
103 | +func (repo *TaskRepository) Remove(id int) error { | ||
104 | + tx := repo.transactionContext.PgTx | ||
105 | + nowTime := time.Now() | ||
106 | + _, err := tx.Model(&models.Task{}). | ||
107 | + Where("id=?", id). | ||
108 | + Set("deleted_at=?", nowTime). | ||
109 | + Update() | ||
110 | + return err | ||
111 | + | ||
112 | +} | ||
113 | + | ||
114 | +func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) { | ||
115 | + tx := repo.transactionContext.PgTx | ||
116 | + m := new(models.Task) | ||
117 | + query := tx.Model(m) | ||
118 | + query.Where("deleted_at isnull") | ||
119 | + if id, ok := queryOptions["id"]; ok { | ||
120 | + query.Where("id=?", id) | ||
121 | + } | ||
122 | + if err := query.First(); err != nil { | ||
123 | + if errors.Is(err, pg.ErrNoRows) { | ||
124 | + return nil, fmt.Errorf("没有找到task数据") | ||
125 | + } else { | ||
126 | + return nil, err | ||
127 | + } | ||
128 | + } | ||
129 | + u := repo.TransformToDomain(m) | ||
130 | + return u, nil | ||
131 | +} | ||
132 | + | ||
133 | +func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Task, error) { | ||
134 | + tx := repo.transactionContext.PgTx | ||
135 | + var m []*models.Task | ||
136 | + query := tx.Model(&m). | ||
137 | + Where("deleted_at isnull"). | ||
138 | + Limit(20) | ||
139 | + if val, ok := queryOptions["name"]; ok { | ||
140 | + query.Where("task.name like ?", val) | ||
141 | + } | ||
142 | + if val, ok := queryOptions["companyId"]; ok { | ||
143 | + query.Where("task.company_id = ?", val) | ||
144 | + } | ||
145 | + if val, ok := queryOptions["id"]; ok { | ||
146 | + query.Where("task.id=?", val) | ||
147 | + } | ||
148 | + if val, ok := queryOptions["leaderId"]; ok { | ||
149 | + query.Where("task.leader->>'id'=?", val) | ||
150 | + } | ||
151 | + if val, ok := queryOptions["aliasOrLeader"]; ok { | ||
152 | + query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val) | ||
153 | + } | ||
154 | + if val, ok := queryOptions["status"]; ok { | ||
155 | + query.Where("task.status=?", val) | ||
156 | + } | ||
157 | + if val, ok := queryOptions["createdBy"]; ok { | ||
158 | + query.Where("created_by = ?", val) | ||
159 | + } | ||
160 | + if val, ok := queryOptions["limit"]; ok { | ||
161 | + if limit, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil { | ||
162 | + query.Limit(limit) | ||
163 | + } | ||
164 | + } | ||
165 | + if val, ok := queryOptions["offset"]; ok { | ||
166 | + if offset, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil { | ||
167 | + query.Offset(offset) | ||
168 | + } | ||
169 | + } | ||
170 | + query.Order("id desc") | ||
171 | + count, err := query.SelectAndCount() | ||
172 | + if err != nil { | ||
173 | + return 0, nil, err | ||
174 | + } | ||
175 | + var datas []*domain.Task | ||
176 | + for _, v := range m { | ||
177 | + d := repo.TransformToDomain(v) | ||
178 | + datas = append(datas, d) | ||
179 | + } | ||
180 | + return count, datas, nil | ||
181 | +} |
@@ -14,75 +14,67 @@ import ( | @@ -14,75 +14,67 @@ import ( | ||
14 | 14 | ||
15 | //任务 | 15 | //任务 |
16 | 16 | ||
17 | -type TaskRepository struct { | 17 | +type TaskAnomalyRepository struct { |
18 | transactionContext *pgTransaction.TransactionContext | 18 | transactionContext *pgTransaction.TransactionContext |
19 | } | 19 | } |
20 | 20 | ||
21 | -var _ domain.TaskRepository = (*TaskRepository)(nil) | 21 | +var _ domain.TaskAnomalyRepository = (*TaskAnomalyRepository)(nil) |
22 | 22 | ||
23 | -func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *TaskRepository { | ||
24 | - return &TaskRepository{transactionContext: transactionContext} | 23 | +func NewTaskAnomalyRepository(transactionContext *pgTransaction.TransactionContext) *TaskAnomalyRepository { |
24 | + return &TaskAnomalyRepository{transactionContext: transactionContext} | ||
25 | } | 25 | } |
26 | 26 | ||
27 | -func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | ||
28 | - return &domain.Task{ | ||
29 | - Id: d.Id, | ||
30 | - CreatedAt: d.CreatedAt, | ||
31 | - UpdatedAt: d.UpdatedAt, | ||
32 | - DeletedAt: d.DeletedAt, | ||
33 | - CompanyId: d.CompanyId, | ||
34 | - Name: d.Name, | ||
35 | - Alias: d.Alias, | ||
36 | - Leader: d.Leader, | ||
37 | - Status: domain.TaskState(d.Status), | ||
38 | - Level: d.Level, | ||
39 | - LevelName: d.LevelName, | ||
40 | - SortBy: domain.TaskSortBy(d.SortBy), | ||
41 | - EndTime: d.EndTime, | ||
42 | - UseEndTime: d.UseEndTime, | ||
43 | - RelatedUser: d.RelatedUser, | ||
44 | - RunAt: d.RunAt, | ||
45 | - StopAt: d.StopAt, | ||
46 | - Anomaly: d.Anomaly, | ||
47 | - WarnFlag: domain.TaskWarnFlag(d.WarnFlag), | ||
48 | - AssistFlag: d.AssistFlag, | ||
49 | - AssistFlagMax: d.AssistFlagMax, | ||
50 | - CurrentStage: d.CurrentStage, | ||
51 | - LastStage: d.LastStage, | ||
52 | - CreatedBy: d.CreatedBy, | 27 | +func (repo *TaskAnomalyRepository) TransformToDomain(d *models.TaskAnomaly) *domain.TaskAnomaly { |
28 | + return &domain.TaskAnomaly{ | ||
29 | + Id: d.Id, | ||
30 | + CreatedAt: d.CreatedAt, | ||
31 | + UpdatedAt: d.UpdatedAt, | ||
32 | + CompanyId: d.CompanyId, | ||
33 | + TaskId: d.TaskId, | ||
34 | + Category: d.Category, | ||
35 | + CurrentStage: d.CurrentStage, | ||
36 | + LastStage: d.LastStage, | ||
37 | + AssessFlag: d.AssessFlag, | ||
38 | + WarnFlag: d.WarnFlag, | ||
39 | + AssistFlag: d.AssistFlag, | ||
40 | + IsLast: d.IsLast, | ||
41 | + TaskLevel: d.TaskLevel, | ||
42 | + TaskName: d.TaskName, | ||
43 | + TaskAlias: d.TaskAlias, | ||
44 | + TaskSortBy: domain.TaskSortBy(d.TaskSortBy), | ||
45 | + TaskEndTime: d.TaskEndTime, | ||
46 | + RecordBegin: d.RecordBegin, | ||
47 | + NoticeWho: d.NoticeWho, | ||
48 | + Marks: d.Marks, | ||
53 | } | 49 | } |
54 | } | 50 | } |
55 | 51 | ||
56 | -func (repo *TaskRepository) Save(param *domain.Task) error { | 52 | +func (repo *TaskAnomalyRepository) Save(param *domain.TaskAnomaly) error { |
57 | param.UpdatedAt = time.Now() | 53 | param.UpdatedAt = time.Now() |
58 | if param.Id == 0 { | 54 | if param.Id == 0 { |
59 | param.CreatedAt = time.Now() | 55 | param.CreatedAt = time.Now() |
60 | } | 56 | } |
61 | - m := models.Task{ | ||
62 | - Id: param.Id, | ||
63 | - CreatedAt: param.CreatedAt, | ||
64 | - UpdatedAt: param.UpdatedAt, | ||
65 | - DeletedAt: param.DeletedAt, | ||
66 | - Name: param.Name, | ||
67 | - Alias: param.Alias, | ||
68 | - CompanyId: param.CompanyId, | ||
69 | - Leader: param.Leader, | ||
70 | - Status: int(param.Status), | ||
71 | - Level: param.Level, | ||
72 | - LevelName: param.LevelName, | ||
73 | - RelatedUser: param.RelatedUser, | ||
74 | - LastStage: param.LastStage, | ||
75 | - RunAt: param.RunAt, | ||
76 | - StopAt: param.StopAt, | ||
77 | - Anomaly: param.Anomaly, | ||
78 | - WarnFlag: int(param.WarnFlag), | ||
79 | - CurrentStage: param.CurrentStage, | ||
80 | - SortBy: int(param.SortBy), | ||
81 | - EndTime: param.EndTime, | ||
82 | - UseEndTime: param.UseEndTime, | ||
83 | - AssistFlag: param.AssistFlag, | ||
84 | - AssistFlagMax: param.AssistFlagMax, | ||
85 | - CreatedBy: param.CreatedBy, | 57 | + m := models.TaskAnomaly{ |
58 | + Id: param.Id, | ||
59 | + CreatedAt: param.CreatedAt, | ||
60 | + UpdatedAt: param.UpdatedAt, | ||
61 | + CompanyId: param.CompanyId, | ||
62 | + TaskId: param.TaskId, | ||
63 | + Category: param.Category, | ||
64 | + CurrentStage: param.CurrentStage, | ||
65 | + LastStage: param.LastStage, | ||
66 | + AssessFlag: param.AssessFlag, | ||
67 | + WarnFlag: param.WarnFlag, | ||
68 | + AssistFlag: param.AssistFlag, | ||
69 | + IsLast: param.IsLast, | ||
70 | + TaskLevel: param.TaskLevel, | ||
71 | + TaskName: param.TaskName, | ||
72 | + TaskAlias: param.TaskAlias, | ||
73 | + TaskSortBy: int(param.TaskSortBy), | ||
74 | + TaskEndTime: param.TaskEndTime, | ||
75 | + RecordBegin: param.RecordBegin, | ||
76 | + NoticeWho: param.NoticeWho, | ||
77 | + Marks: param.Marks, | ||
86 | } | 78 | } |
87 | db := repo.transactionContext.PgTx | 79 | db := repo.transactionContext.PgTx |
88 | if m.Id == 0 { | 80 | if m.Id == 0 { |
@@ -100,28 +92,16 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | @@ -100,28 +92,16 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | ||
100 | return nil | 92 | return nil |
101 | } | 93 | } |
102 | 94 | ||
103 | -func (repo *TaskRepository) Remove(id int) error { | 95 | +func (repo *TaskAnomalyRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskAnomaly, error) { |
104 | tx := repo.transactionContext.PgTx | 96 | tx := repo.transactionContext.PgTx |
105 | - nowTime := time.Now() | ||
106 | - _, err := tx.Model(&models.Task{}). | ||
107 | - Where("id=?", id). | ||
108 | - Set("deleted_at=?", nowTime). | ||
109 | - Update() | ||
110 | - return err | ||
111 | - | ||
112 | -} | ||
113 | - | ||
114 | -func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) { | ||
115 | - tx := repo.transactionContext.PgTx | ||
116 | - m := new(models.Task) | 97 | + m := new(models.TaskAnomaly) |
117 | query := tx.Model(m) | 98 | query := tx.Model(m) |
118 | - query.Where("deleted_at isnull") | ||
119 | if id, ok := queryOptions["id"]; ok { | 99 | if id, ok := queryOptions["id"]; ok { |
120 | query.Where("id=?", id) | 100 | query.Where("id=?", id) |
121 | } | 101 | } |
122 | if err := query.First(); err != nil { | 102 | if err := query.First(); err != nil { |
123 | if errors.Is(err, pg.ErrNoRows) { | 103 | if errors.Is(err, pg.ErrNoRows) { |
124 | - return nil, fmt.Errorf("没有找到task数据") | 104 | + return nil, fmt.Errorf("没有找到TaskAnomaly数据") |
125 | } else { | 105 | } else { |
126 | return nil, err | 106 | return nil, err |
127 | } | 107 | } |
@@ -130,33 +110,10 @@ func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domai | @@ -130,33 +110,10 @@ func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domai | ||
130 | return u, nil | 110 | return u, nil |
131 | } | 111 | } |
132 | 112 | ||
133 | -func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Task, error) { | 113 | +func (repo *TaskAnomalyRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskAnomaly, error) { |
134 | tx := repo.transactionContext.PgTx | 114 | tx := repo.transactionContext.PgTx |
135 | - var m []*models.Task | ||
136 | - query := tx.Model(&m). | ||
137 | - Where("deleted_at isnull"). | ||
138 | - Limit(20) | ||
139 | - if val, ok := queryOptions["name"]; ok { | ||
140 | - query.Where("task.name like ?", val) | ||
141 | - } | ||
142 | - if val, ok := queryOptions["companyId"]; ok { | ||
143 | - query.Where("task.company_id = ?", val) | ||
144 | - } | ||
145 | - if val, ok := queryOptions["id"]; ok { | ||
146 | - query.Where("task.id=?", val) | ||
147 | - } | ||
148 | - if val, ok := queryOptions["leaderId"]; ok { | ||
149 | - query.Where("task.leader->>'id'=?", val) | ||
150 | - } | ||
151 | - if val, ok := queryOptions["aliasOrLeader"]; ok { | ||
152 | - query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val) | ||
153 | - } | ||
154 | - if val, ok := queryOptions["status"]; ok { | ||
155 | - query.Where("task.status=?", val) | ||
156 | - } | ||
157 | - if val, ok := queryOptions["createdBy"]; ok { | ||
158 | - query.Where("created_by = ?", val) | ||
159 | - } | 115 | + var m []*models.TaskAnomaly |
116 | + query := tx.Model(&m) | ||
160 | if val, ok := queryOptions["limit"]; ok { | 117 | if val, ok := queryOptions["limit"]; ok { |
161 | if limit, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil { | 118 | if limit, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil { |
162 | query.Limit(limit) | 119 | query.Limit(limit) |
@@ -172,7 +129,7 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d | @@ -172,7 +129,7 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d | ||
172 | if err != nil { | 129 | if err != nil { |
173 | return 0, nil, err | 130 | return 0, nil, err |
174 | } | 131 | } |
175 | - var datas []*domain.Task | 132 | + var datas []*domain.TaskAnomaly |
176 | for _, v := range m { | 133 | for _, v := range m { |
177 | d := repo.TransformToDomain(v) | 134 | d := repo.TransformToDomain(v) |
178 | datas = append(datas, d) | 135 | datas = append(datas, d) |
-
请 注册 或 登录 后发表评论