task_anomaly.go
7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 异常的任务记录
type TaskAnomalyDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewTaskAnomalyDao(options map[string]interface{}) *TaskAnomalyDao {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return &TaskAnomalyDao{
transactionContext: transactionContext,
}
}
type ListTaskAnomaly struct {
Id int `pg:"id"`
TaskId int `pg:"task_id"`
TaskRecordId int `pg:"task_record_id"`
Category int `pg:"category"`
CurrentStage domain.TaskStage `pg:"current_stage"` // 计划执行的里程碑
LastStage domain.TaskStage `pg:"last_stage"` // 上一个完成的里程碑
TaskStageCheck domain.TaskStage `pg:"task_stage_check"` //
AssessFlag int `pg:"assess_flag"`
WarnFlag int `pg:"warn_flag"`
AssistFlag int `pg:"assist_flag"`
RecordBegin int64 `pg:"record_begin"`
Marks map[string]string `pg:"marks"`
NoticeWho []map[string]string `pg:"notice_who"`
TaskAlias string `pg:"task_alias"`
TaskName string `pg:"task_name"`
TaskEndTime int `pg:"task_end_time"`
TaskSortBy int `pg:"task_sort_by"`
LeaderName string `pg:"leader_name"`
LevelName string `pg:"level_name"`
}
// 异常的任务记录, 获取我负责的任务
// userId 谁要查看数据
// companyId 公司id
// dayTime 搜索条件日期 ,例:"2006-01-02"
// pageSize 分页大小
// pageNumber 分页页码
func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, category int, dayTime string, limit int, offset int) (int, []ListTaskAnomaly, error) {
sqlStr1 := ` with t_task_ignore as (
select task_ignore.id ,task_ignore.task_id
from task_ignore
where user_id = ?
)select
task_anomaly.id,
task_anomaly.task_id,
task_anomaly.task_record_id,
task_anomaly.category,
task_anomaly.current_stage,
task_anomaly.last_stage,
task_anomaly.task_stage_check,
task_anomaly.assess_flag,
task_anomaly.warn_flag,
task_anomaly.assist_flag,
task_anomaly.record_begin,
task_anomaly.marks,
task_anomaly.notice_who,
task.alias as "task_alias",
task."name" as "task_name",
task.end_time as "task_end_time",
task.sort_by as "task_sort_by",
task.leader->>'name' as "leader_name",
task.level_name
from task_anomaly
join task on task.id = task_anomaly.task_id
left join t_task_ignore on task_anomaly.task_id=t_task_ignore.task_id
where t_task_ignore.id isnull and task.deleted_at isnull
and task_anomaly.company_id = ?
and task.leader->>'id'='?' `
sqlStr2 := ` with t_task_ignore as (
select task_ignore.id ,task_ignore.task_id
from task_ignore
where user_id = ?
)select count(*) as cnt
from task_anomaly
join task on task.id = task_anomaly.task_id
left join t_task_ignore on task_anomaly.task_id=t_task_ignore.task_id
where t_task_ignore.id isnull and task.deleted_at isnull
and task_anomaly.company_id = ?
and task.leader->>'id'='?' `
condition := []interface{}{userId, companyId, userId}
if len(dayTime) > 0 {
condition = append(condition, dayTime)
sqlStr2 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
sqlStr1 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
}
if len(taskName) > 0 {
condition = append(condition, "%"+taskName+"%")
sqlStr2 += ` and task.alias like ? `
sqlStr1 += ` and task.alias like ? `
}
if category > 0 {
condition = append(condition, category)
sqlStr1 += ` and task_anomaly.category=? `
sqlStr2 += ` and task_anomaly.category=? `
}
condition = append(condition, limit, offset)
sqlStr1 += ` order by task_anomaly.id desc limit ? offset ? `
result := []ListTaskAnomaly{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr1, condition...)
if err != nil {
return 0, result, err
}
var cnt int
_, err = tx.QueryOne(pg.Scan(&cnt), sqlStr2, condition...)
return cnt, result, err
}
// 异常的任务记录,获取我的下级负责的任务
// userId 谁要查看数据
// companyId 公司id
// dayTime 搜索条件日期 ,例:"2006-01-02"
// pageSize 分页大小
// pageNumber 分页页码
func (d *TaskAnomalyDao) List2(userId int, companyId int, leaderId string, dayTime string, pageSize int, pageNumber int) error {
return nil
}
// 异常的任务记录,我作为相关人的任务
// userId 谁要查看数据
// companyId 公司id
// dayTime 搜索条件日期 ,例:"2006-01-02"
// pageSize 分页大小
// pageNumber 分页页码
func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, category int, dayTime string, leaderId string, limit int, offset int) (int, []ListTaskAnomaly, error) {
sqlStr1 := ` with t_task_ignore as (
select task_ignore.id ,task_ignore.task_id
from task_ignore
where user_id = ?
)select
task_anomaly.id,
task_anomaly.task_id,
task_anomaly.task_record_id,
task_anomaly.category,
task_anomaly.current_stage,
task_anomaly.last_stage,
task_anomaly.task_stage_check,
task_anomaly.assess_flag,
task_anomaly.warn_flag,
task_anomaly.assist_flag,
task_anomaly.record_begin,
task_anomaly.marks,
task_anomaly.notice_who,
task.alias as "task_alias",
task."name" as "task_name",
task.end_time as "task_end_time",
task.sort_by as "task_sort_by",
task.leader->>'name' as "leader_name",
task.level_name
from task_anomaly
join task on task.id = task_anomaly.task_id
left join t_task_ignore on task_anomaly.task_id=t_task_ignore.task_id
where t_task_ignore.id isnull and task.deleted_at isnull
and task_anomaly.company_id = ?
and task.related_user@> ? `
sqlStr2 := ` with t_task_ignore as (
select task_ignore.id ,task_ignore.task_id
from task_ignore
where user_id = ?
)select count(*) as cnt
from task_anomaly
join task on task.id = task_anomaly.task_id
left join t_task_ignore on task_anomaly.task_id=t_task_ignore.task_id
where t_task_ignore.id isnull and task.deleted_at isnull
and task_anomaly.company_id = ?
and task.related_user@> ? `
condition := []interface{}{userId, companyId, fmt.Sprintf("[%d]", userId)}
if len(dayTime) > 0 {
condition = append(condition, dayTime)
sqlStr2 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
sqlStr1 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
}
if len(taskName) > 0 {
condition = append(condition, "%"+taskName+"%")
sqlStr2 += ` and task.alias like ? `
sqlStr1 += ` and task.alias like ? `
}
if category > 0 {
condition = append(condition, category)
sqlStr1 += ` and task_anomaly.category=? `
sqlStr2 += ` and task_anomaly.category=? `
}
if len(leaderId) > 0 {
condition = append(condition, fmt.Sprintf(`{"id":"%s"}`, leaderId))
sqlStr1 += ` and task.leader@>? `
sqlStr2 += ` and task.leader@>? `
}
condition = append(condition, limit, offset)
sqlStr1 += ` order by task_anomaly.id desc limit ? offset ? `
result := []ListTaskAnomaly{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr1, condition...)
if err != nil {
return 0, result, err
}
var cnt int
_, err = tx.QueryOne(pg.Scan(&cnt), sqlStr2, condition...)
return cnt, result, err
}