|
@@ -2,7 +2,9 @@ package dao |
|
@@ -2,7 +2,9 @@ package dao |
|
2
|
|
2
|
|
|
3
|
import (
|
3
|
import (
|
|
4
|
"fmt"
|
4
|
"fmt"
|
|
|
|
5
|
+ "time"
|
|
5
|
|
6
|
|
|
|
|
7
|
+ "github.com/go-pg/pg/v10"
|
|
6
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
8
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
7
|
)
|
9
|
)
|
|
8
|
|
10
|
|
|
@@ -27,7 +29,7 @@ func (d *TaskDao) catchTaskIdByPermission(userId int) string { |
|
@@ -27,7 +29,7 @@ func (d *TaskDao) catchTaskIdByPermission(userId int) string { |
|
27
|
(
|
29
|
(
|
|
28
|
select "user".id,"user".parent_id
|
30
|
select "user".id,"user".parent_id
|
|
29
|
from "user"
|
31
|
from "user"
|
|
30
|
- where company_id =233 and "user".id=%d
|
32
|
+ where "user".id=%d
|
|
31
|
)
|
33
|
)
|
|
32
|
union
|
34
|
union
|
|
33
|
(
|
35
|
(
|
|
@@ -67,11 +69,28 @@ type ListTaskCondition struct { |
|
@@ -67,11 +69,28 @@ type ListTaskCondition struct { |
|
67
|
LeaderId string //任务负责人id
|
69
|
LeaderId string //任务负责人id
|
|
68
|
}
|
70
|
}
|
|
69
|
|
71
|
|
|
|
|
72
|
+// 任务和里程碑列表
|
|
|
|
73
|
+type ListTaskStage struct {
|
|
|
|
74
|
+ TaskId string `pg:"task_id"`
|
|
|
|
75
|
+ TaskName string `pg:"task_name"`
|
|
|
|
76
|
+ LeaderName string `pg:"leader_name"`
|
|
|
|
77
|
+ LeaderId string `pg:"leader_id"`
|
|
|
|
78
|
+ LevelName string `pg:"level_name"`
|
|
|
|
79
|
+ Level int `pg:"level"`
|
|
|
|
80
|
+ Anomaly int `pg:"anomaly"`
|
|
|
|
81
|
+ UpdatedAt time.Time `pg:"updated_at"`
|
|
|
|
82
|
+ CreatedAt time.Time `pg:"created_at"`
|
|
|
|
83
|
+ StageName string `pg:"stage_name"`
|
|
|
|
84
|
+ StageSortBy int `pg:"stage_sort_by"`
|
|
|
|
85
|
+ StageStatus int `pg:"stage_status"`
|
|
|
|
86
|
+ PlanCompletedAt int `pg:"plan_completed_at"`
|
|
|
|
87
|
+}
|
|
|
|
88
|
+
|
|
70
|
// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
|
89
|
// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
|
|
71
|
// userid 谁要查看任务数据
|
90
|
// userid 谁要查看任务数据
|
|
72
|
// limit 分页
|
91
|
// limit 分页
|
|
73
|
// offset 分页
|
92
|
// offset 分页
|
|
74
|
-func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) {
|
93
|
+func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
|
|
75
|
task1 := d.catchTaskIdByPermission(param.UserId)
|
94
|
task1 := d.catchTaskIdByPermission(param.UserId)
|
|
76
|
withSql := task1 + `,
|
95
|
withSql := task1 + `,
|
|
77
|
-- 获取的里程碑数据,以及排序
|
96
|
-- 获取的里程碑数据,以及排序
|
|
@@ -143,11 +162,16 @@ func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) { |
|
@@ -143,11 +162,16 @@ func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) { |
|
143
|
condition = append(condition, param.LevelName)
|
162
|
condition = append(condition, param.LevelName)
|
|
144
|
whereSql += ` and t_task_tage_1.level_name like ? `
|
163
|
whereSql += ` and t_task_tage_1.level_name like ? `
|
|
145
|
}
|
164
|
}
|
|
146
|
- = withSql
|
165
|
+ condition = append(condition, param.Limit, param.Offset)
|
|
|
|
166
|
+ sqlStr := fmt.Sprintf(withSql, whereSql)
|
|
|
|
167
|
+ result := []ListTaskStage{}
|
|
|
|
168
|
+ tx := d.transactionContext.PgTx
|
|
|
|
169
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
|
170
|
+ return result, err
|
|
147
|
}
|
171
|
}
|
|
148
|
|
172
|
|
|
149
|
// 获取任务总数,用于页面展示; 有过滤查看权限
|
173
|
// 获取任务总数,用于页面展示; 有过滤查看权限
|
|
150
|
-func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) {
|
174
|
+func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) {
|
|
151
|
task1 := d.catchTaskIdByPermission(param.UserId)
|
175
|
task1 := d.catchTaskIdByPermission(param.UserId)
|
|
152
|
withSql := task1 + `select count(*) from task
|
176
|
withSql := task1 + `select count(*) from task
|
|
153
|
join t_task_1 on task.id =t_task_1.id
|
177
|
join t_task_1 on task.id =t_task_1.id
|
|
@@ -170,6 +194,127 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) { |
|
@@ -170,6 +194,127 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) { |
|
170
|
whereSql += ` and task.level_name like ? `
|
194
|
whereSql += ` and task.level_name like ? `
|
|
171
|
}
|
195
|
}
|
|
172
|
sqlStr := withSql + whereSql
|
196
|
sqlStr := withSql + whereSql
|
|
173
|
- _ = sqlStr
|
197
|
+ tx := d.transactionContext.PgTx
|
|
|
|
198
|
+ var cnt int
|
|
|
|
199
|
+ _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
|
|
|
|
200
|
+ return cnt, err
|
|
|
|
201
|
+}
|
|
|
|
202
|
+
|
|
|
|
203
|
+// 获取任务以及里程碑列表,用于页面展示; 无过滤查看权限
|
|
|
|
204
|
+// userid 谁要查看任务数据
|
|
|
|
205
|
+// limit 分页
|
|
|
|
206
|
+// offset 分页
|
|
|
|
207
|
+func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
|
|
|
|
208
|
+ withSql := `with
|
|
|
|
209
|
+ t_task_ignore as (
|
|
|
|
210
|
+ select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
|
|
|
|
211
|
+ ),
|
|
|
|
212
|
+ -- 获取的里程碑数据,以及排序
|
|
|
|
213
|
+ t_task_tage_1 as(
|
|
|
|
214
|
+ select
|
|
|
|
215
|
+ task.id as task_id,
|
|
|
|
216
|
+ task."name" as task_name,
|
|
|
|
217
|
+ task.leader ->>'name' as leader_name,
|
|
|
|
218
|
+ task.leader ->>'id' as leader_id,
|
|
|
|
219
|
+ task.level_name ,
|
|
|
|
220
|
+ task.anomaly ,
|
|
|
|
221
|
+ task.updated_at ,
|
|
|
|
222
|
+ task.created_at ,
|
|
|
|
223
|
+ task."level" ,
|
|
|
|
224
|
+ task_stage."name" as stage_name,
|
|
|
|
225
|
+ task_stage.sort_by as stage_sort_by,
|
|
|
|
226
|
+ task_stage.status as stage_status,
|
|
|
|
227
|
+ task_stage.plan_completed_at,
|
|
|
|
228
|
+ (case
|
|
|
|
229
|
+ when task_stage.real_completed_at =0
|
|
|
|
230
|
+ then task_stage.plan_completed_at - floor( extract(epoch from now()))
|
|
|
|
231
|
+ else task_stage.plan_completed_at - task_stage.real_completed_at
|
|
|
|
232
|
+ end) as diff_time
|
|
|
|
233
|
+ from task
|
|
|
|
234
|
+ join task_stage on task.id =task_stage.task_id
|
|
|
|
235
|
+ where 1=1
|
|
|
|
236
|
+ order by diff_time,task."level",task.created_at
|
|
|
|
237
|
+ ),
|
|
|
|
238
|
+ -- 按任务数据分页获取
|
|
|
|
239
|
+ t_task_page as (
|
|
|
|
240
|
+ select distinct t_task_tage_1.task_id
|
|
|
|
241
|
+ from t_task_tage_1
|
|
|
|
242
|
+ left join t_task_ignore on t_task_ignore.task_id=t_task_tage_1.task_id
|
|
|
|
243
|
+ where t_task_ignore.id isnull
|
|
|
|
244
|
+ %s
|
|
|
|
245
|
+ limit ? offset ?
|
|
|
|
246
|
+ )
|
|
|
|
247
|
+ select
|
|
|
|
248
|
+ t_task_tage_1.task_id,
|
|
|
|
249
|
+ t_task_tage_1.task_name,
|
|
|
|
250
|
+ t_task_tage_1.leader_name,
|
|
|
|
251
|
+ t_task_tage_1.level_name ,
|
|
|
|
252
|
+ t_task_tage_1.anomaly ,
|
|
|
|
253
|
+ t_task_tage_1.updated_at ,
|
|
|
|
254
|
+ t_task_tage_1.created_at ,
|
|
|
|
255
|
+ t_task_tage_1."level" ,
|
|
|
|
256
|
+ t_task_tage_1.plan_completed_at,
|
|
|
|
257
|
+ t_task_tage_1.stage_name,
|
|
|
|
258
|
+ t_task_tage_1.stage_sort_by,
|
|
|
|
259
|
+ t_task_tage_1.stage_status,
|
|
|
|
260
|
+ from t_task_tage_1
|
|
|
|
261
|
+ where t_task_tage_1.task_id in(
|
|
|
|
262
|
+ select t_task_page.task_id from t_task_page
|
|
|
|
263
|
+ )`
|
|
|
|
264
|
+ condition := []interface{}{}
|
|
|
|
265
|
+ whereSql := ``
|
|
|
|
266
|
+ if param.OnlyMy {
|
|
|
|
267
|
+ condition = append(condition, param.UserId)
|
|
|
|
268
|
+ whereSql += ` and task.leader ->>'id' = '?' `
|
|
|
|
269
|
+ } else if param.LeaderId != "" {
|
|
|
|
270
|
+ condition = append(condition, param.LeaderId)
|
|
|
|
271
|
+ whereSql += ` and task.leader ->>'id' = ? `
|
|
|
|
272
|
+ }
|
|
|
|
273
|
+ if len(param.TaskName) > 0 {
|
|
|
|
274
|
+ condition = append(condition, param.TaskName)
|
|
|
|
275
|
+ whereSql += ` and task.name like ? `
|
|
|
|
276
|
+ }
|
|
|
|
277
|
+ if len(param.LevelName) > 0 {
|
|
|
|
278
|
+ condition = append(condition, param.LevelName)
|
|
|
|
279
|
+ whereSql += ` and task.level_name like ? `
|
|
|
|
280
|
+ }
|
|
|
|
281
|
+ condition = append(condition, param.Limit, param.Offset)
|
|
|
|
282
|
+ sqlStr := fmt.Sprintf(withSql, whereSql)
|
|
|
|
283
|
+ result := []ListTaskStage{}
|
|
|
|
284
|
+ tx := d.transactionContext.PgTx
|
|
|
|
285
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
|
286
|
+ return result, err
|
|
|
|
287
|
+}
|
|
|
|
288
|
+
|
|
|
|
289
|
+// 获取任务总数,用于页面展示; 无过滤查看权限
|
|
|
|
290
|
+func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) {
|
|
|
|
291
|
+
|
|
|
|
292
|
+ withSql := `with
|
|
|
|
293
|
+ t_task_ignore as (
|
|
|
|
294
|
+ select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
|
|
|
|
295
|
+ )select count(*) from task
|
|
|
|
296
|
+ left join t_task_ignore on t_task_ignore.task_id=task.id
|
|
|
|
297
|
+ where 1=1 `
|
|
|
|
298
|
+ condition := []interface{}{}
|
|
|
|
299
|
+ whereSql := ``
|
|
|
|
300
|
+ if param.OnlyMy {
|
|
|
|
301
|
+ condition = append(condition, param.UserId)
|
|
|
|
302
|
+ whereSql += ` and task.leader ->>'id' = '?' `
|
|
|
|
303
|
+ } else if param.LeaderId != "" {
|
|
|
|
304
|
+ condition = append(condition, param.LeaderId)
|
|
|
|
305
|
+ whereSql += ` and task.leader ->>'id' = ? `
|
|
|
|
306
|
+ }
|
|
|
|
307
|
+ if len(param.TaskName) > 0 {
|
|
|
|
308
|
+ condition = append(condition, param.TaskName)
|
|
|
|
309
|
+ whereSql += ` and task.name like ? `
|
|
|
|
310
|
+ }
|
|
|
|
311
|
+ if len(param.LevelName) > 0 {
|
|
|
|
312
|
+ condition = append(condition, param.LevelName)
|
|
|
|
313
|
+ whereSql += ` and task.level_name like ? `
|
|
|
|
314
|
+ }
|
|
|
|
315
|
+ sqlStr := withSql + whereSql
|
|
|
|
316
|
+ tx := d.transactionContext.PgTx
|
|
|
|
317
|
+ var cnt int
|
|
|
|
318
|
+ _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
|
|
|
|
319
|
+ return cnt, err
|
|
174
|
} |
320
|
} |
|
175
|
-、、' |
|
|