作者 tangxvhui

清理代码

... ... @@ -746,237 +746,237 @@ func (srv TaskService) CancelAttention(param *command.CancelAttentionCommand) er
}
// 员工绩效-任务管理-列表
func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
hrbpFlag, err := roleService.GetHrBp(transactionContext, int(param.CompanyId), int(param.UserId))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息"+err.Error())
}
if len(param.SearchWord) > 0 {
param.SearchWord = "%" + param.SearchWord + "%"
}
if hrbpFlag == domain.RoleTypeSystem {
listData, err := srv.listTask2ForHrbp(param)
return listData, err
}
var limit = 20
var offset = 0
if param.PageSize > 0 {
limit = param.PageSize
if param.PageNumber > 0 {
offset = (param.PageNumber - 1) * param.PageSize
}
}
condition := dao.ListTaskCondition{
Limit: limit,
Offset: offset,
UserId: param.UserId,
CompanyId: param.CompanyId,
OnlyMy: param.OnlyMy,
SearchWord: param.SearchWord,
}
// func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]interface{}, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// hrbpFlag, err := roleService.GetHrBp(transactionContext, int(param.CompanyId), int(param.UserId))
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息"+err.Error())
// }
// if len(param.SearchWord) > 0 {
// param.SearchWord = "%" + param.SearchWord + "%"
// }
// if hrbpFlag == domain.RoleTypeSystem {
// listData, err := srv.listTask2ForHrbp(param)
// return listData, err
// }
// var limit = 20
// var offset = 0
// if param.PageSize > 0 {
// limit = param.PageSize
// if param.PageNumber > 0 {
// offset = (param.PageNumber - 1) * param.PageSize
// }
// }
// condition := dao.ListTaskCondition{
// Limit: limit,
// Offset: offset,
// UserId: param.UserId,
// CompanyId: param.CompanyId,
// OnlyMy: param.OnlyMy,
// SearchWord: param.SearchWord,
// }
taskDao := dao.NewTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
})
//任务列表数据
tasklistData, err := taskDao.ListTaskStageNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
}
//查到的任务数据总数
taskCount, err := taskDao.CountTaskNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
}
//
taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// taskDao := dao.NewTaskDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// //任务列表数据
// tasklistData, err := taskDao.ListTaskStageNotHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
// }
// //查到的任务数据总数
// taskCount, err := taskDao.CountTaskNotHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
// }
// //
// taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
// }
// taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
taskResult := []*adapter.TaskItem{}
taskMapResult := map[int]*adapter.TaskItem{}
for _, val := range tasklistData {
if _, ok := taskMapResult[val.TaskId]; ok {
continue
}
tk := adapter.TaskItem{
Id: val.TaskId,
Name: val.TaskName,
Alias: val.TaskAliasName,
Leader: val.LeaderName,
Status: val.TaskStatus,
Level: val.Level,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
WarnFlag: val.WarnFlag,
}
taskMapResult[val.TaskId] = &tk
taskResult = append(taskResult, &tk)
}
for _, val := range tasklistData {
taskData, ok := taskMapResult[val.TaskId]
if !ok {
continue
}
stage := adapter.TaskStage{
Id: val.StageId,
Name: val.StageName,
SortBy: val.StageSortBy,
PlanCompletedAt: time.Unix(int64(val.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
}
if val.RealCompletedAt > 0 {
stage.RealCompletedAt = time.Unix(int64(val.RealCompletedAt), 0).Local().Format("2006-01-02")
}
switch val.StageSortBy {
case 1:
taskData.StageA = stage
case 2:
taskData.StageB = stage
case 3:
taskData.StageC = stage
case 4:
taskData.StageD = stage
case 5:
taskData.StageE = stage
}
// taskResult := []*adapter.TaskItem{}
// taskMapResult := map[int]*adapter.TaskItem{}
// for _, val := range tasklistData {
// if _, ok := taskMapResult[val.TaskId]; ok {
// continue
// }
// tk := adapter.TaskItem{
// Id: val.TaskId,
// Name: val.TaskName,
// Alias: val.TaskAliasName,
// Leader: val.LeaderName,
// Status: val.TaskStatus,
// Level: val.Level,
// LevelName: val.LevelName,
// UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
// Anomaly: val.Anomaly,
// WarnFlag: val.WarnFlag,
// }
// taskMapResult[val.TaskId] = &tk
// taskResult = append(taskResult, &tk)
// }
// for _, val := range tasklistData {
// taskData, ok := taskMapResult[val.TaskId]
// if !ok {
// continue
// }
// stage := adapter.TaskStage{
// Id: val.StageId,
// Name: val.StageName,
// SortBy: val.StageSortBy,
// PlanCompletedAt: time.Unix(int64(val.PlanCompletedAt), 0).Local().Format("2006-01-02"),
// RealCompletedAt: "",
// }
// if val.RealCompletedAt > 0 {
// stage.RealCompletedAt = time.Unix(int64(val.RealCompletedAt), 0).Local().Format("2006-01-02")
// }
// switch val.StageSortBy {
// case 1:
// taskData.StageA = stage
// case 2:
// taskData.StageB = stage
// case 3:
// taskData.StageC = stage
// case 4:
// taskData.StageD = stage
// case 5:
// taskData.StageE = stage
// }
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
result["taskStageAnomaly"] = taskStageAnomalyCnt
result["taskAnomalyCnt"] = taskAnomalyCnt
return result, nil
}
// }
// result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
// result["taskStageAnomaly"] = taskStageAnomalyCnt
// result["taskAnomalyCnt"] = taskAnomalyCnt
// return result, nil
// }
// 以hrbp角色权限获取任务列表
// 统计里程碑异常数,反馈异常数
func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[string]interface{}, error) {
var limit = 20
var offset = 0
if param.PageSize > 0 {
limit = param.PageSize
if param.PageNumber > 0 {
offset = (param.PageNumber - 1) * param.PageSize
}
}
condition := dao.ListTaskCondition{
Limit: limit,
Offset: offset,
UserId: param.UserId,
CompanyId: param.CompanyId,
OnlyMy: param.OnlyMy,
SearchWord: param.SearchWord,
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
taskDao := dao.NewTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
})
tasklistData, err := taskDao.ListTaskStageByHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
}
taskCount, err := taskDao.CountTaskByHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
}
taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyByHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
taskAnomalyCnt, err := taskDao.CountTaskAnomalyByHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
taskResult := []*adapter.TaskItem{}
taskMapResult := map[int]*adapter.TaskItem{}
for _, val := range tasklistData {
if _, ok := taskMapResult[val.TaskId]; ok {
continue
}
tk := adapter.TaskItem{
Id: val.TaskId,
Name: val.TaskName,
Alias: val.TaskAliasName,
Leader: val.LeaderName,
Status: val.TaskStatus,
Level: val.Level,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
WarnFlag: val.WarnFlag,
// StageA: adapter.TaskStage{},
// StageB: adapter.TaskStage{},
// StageC: adapter.TaskStage{},
// StageD: adapter.TaskStage{},
// StageE: adapter.TaskStage{},
}
taskMapResult[val.TaskId] = &tk
taskResult = append(taskResult, &tk)
}
for _, val := range tasklistData {
taskData, ok := taskMapResult[val.TaskId]
if !ok {
continue
}
stage := adapter.TaskStage{
Id: val.StageId,
Name: val.StageName,
SortBy: val.StageSortBy,
PlanCompletedAt: time.Unix(int64(val.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
}
if val.RealCompletedAt > 0 {
stage.RealCompletedAt = time.Unix(int64(val.RealCompletedAt), 0).Local().Format("2006-01-02")
}
switch val.StageSortBy {
case 1:
taskData.StageA = stage
case 2:
taskData.StageB = stage
case 3:
taskData.StageC = stage
case 4:
taskData.StageD = stage
case 5:
taskData.StageE = stage
}
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
result["taskStageAnomaly"] = taskStageAnomalyCnt
result["taskAnomalyCnt"] = taskAnomalyCnt
return result, nil
}
// func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[string]interface{}, error) {
// var limit = 20
// var offset = 0
// if param.PageSize > 0 {
// limit = param.PageSize
// if param.PageNumber > 0 {
// offset = (param.PageNumber - 1) * param.PageSize
// }
// }
// condition := dao.ListTaskCondition{
// Limit: limit,
// Offset: offset,
// UserId: param.UserId,
// CompanyId: param.CompanyId,
// OnlyMy: param.OnlyMy,
// SearchWord: param.SearchWord,
// }
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// taskDao := dao.NewTaskDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// tasklistData, err := taskDao.ListTaskStageByHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
// }
// taskCount, err := taskDao.CountTaskByHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
// }
// taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyByHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
// }
// taskAnomalyCnt, err := taskDao.CountTaskAnomalyByHrbp(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// taskResult := []*adapter.TaskItem{}
// taskMapResult := map[int]*adapter.TaskItem{}
// for _, val := range tasklistData {
// if _, ok := taskMapResult[val.TaskId]; ok {
// continue
// }
// tk := adapter.TaskItem{
// Id: val.TaskId,
// Name: val.TaskName,
// Alias: val.TaskAliasName,
// Leader: val.LeaderName,
// Status: val.TaskStatus,
// Level: val.Level,
// LevelName: val.LevelName,
// UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
// Anomaly: val.Anomaly,
// WarnFlag: val.WarnFlag,
// // StageA: adapter.TaskStage{},
// // StageB: adapter.TaskStage{},
// // StageC: adapter.TaskStage{},
// // StageD: adapter.TaskStage{},
// // StageE: adapter.TaskStage{},
// }
// taskMapResult[val.TaskId] = &tk
// taskResult = append(taskResult, &tk)
// }
// for _, val := range tasklistData {
// taskData, ok := taskMapResult[val.TaskId]
// if !ok {
// continue
// }
// stage := adapter.TaskStage{
// Id: val.StageId,
// Name: val.StageName,
// SortBy: val.StageSortBy,
// PlanCompletedAt: time.Unix(int64(val.PlanCompletedAt), 0).Local().Format("2006-01-02"),
// RealCompletedAt: "",
// }
// if val.RealCompletedAt > 0 {
// stage.RealCompletedAt = time.Unix(int64(val.RealCompletedAt), 0).Local().Format("2006-01-02")
// }
// switch val.StageSortBy {
// case 1:
// taskData.StageA = stage
// case 2:
// taskData.StageB = stage
// case 3:
// taskData.StageC = stage
// case 4:
// taskData.StageD = stage
// case 5:
// taskData.StageE = stage
// }
// }
// result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
// result["taskStageAnomaly"] = taskStageAnomalyCnt
// result["taskAnomalyCnt"] = taskAnomalyCnt
// return result, nil
// }
// ReplyTaskStage 根据每日的任务反馈 ,更新任务里程碑
func (srv TaskService) ReplyTaskStage(transactionContext application.TransactionContext, param []*domain.TaskRecord, isFirstSubmit bool) error {
... ...
... ... @@ -95,85 +95,85 @@ type ListTaskStage struct {
// userid 谁要查看任务数据
// limit 分页
// offset 分页
func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
task1 := d.catchTaskIdByPermission(param.UserId)
withSql := task1 + `,
-- 获取的里程碑数据,以及排序
t_task_tage_1 as(
select
task.id as task_id,
task."name" as task_name,
task."alias" as task_alias_name,
task.leader ->>'name' as leader_name,
task.leader ->>'id' as leader_id,
task.level_name ,
task.anomaly ,
task.updated_at ,
task.created_at ,
task."level" ,
task."warn_flag",
task."status" as task_status,
task_stage."id" as stage_id,
task_stage."name" as stage_name,
task_stage.sort_by as stage_sort_by,
task_stage.plan_completed_at,
task_stage.real_completed_at,
(case
when task_stage.real_completed_at =0
then task_stage.plan_completed_at - floor( extract(epoch from now()))
else task_stage.plan_completed_at - task_stage.real_completed_at
end) as diff_time
from task
join t_task_1 on task.id=t_task_1.id
join task_stage on task.id =task_stage.task_id
where 1=1 and task.company_id=?
order by diff_time,task."level",task.created_at desc
),
-- 按任务数据分页获取
t_task_page as (
select distinct t_task_tage_1.task_id
from t_task_tage_1
where 1=1
%s
limit ? offset ?
)
select
t_task_tage_1.task_id,
t_task_tage_1.task_name,
t_task_tage_1.task_alias_name,
t_task_tage_1.leader_name,
t_task_tage_1.level_name ,
t_task_tage_1.anomaly ,
t_task_tage_1.updated_at ,
t_task_tage_1.created_at ,
t_task_tage_1."level" ,
t_task_tage_1.plan_completed_at,
t_task_tage_1.real_completed_at,
t_task_tage_1.stage_name,
t_task_tage_1.stage_id,
t_task_tage_1.stage_sort_by,
t_task_tage_1."warn_flag"
from t_task_tage_1
where t_task_tage_1.task_id in(
select t_task_page.task_id from t_task_page
)`
condition := []interface{}{param.CompanyId}
whereSql := ``
if param.OnlyMy {
condition = append(condition, param.UserId)
whereSql += ` and t_task_tage_1.leader_id = '?' `
}
if param.SearchWord != "" {
condition = append(condition, param.SearchWord, param.SearchWord)
whereSql += ` and (t_task_tage_1.leader_name like ? or t_task_tage_1.task_alias_name like ?)`
}
condition = append(condition, param.Limit, param.Offset)
sqlStr := fmt.Sprintf(withSql, whereSql)
result := []ListTaskStage{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
// task1 := d.catchTaskIdByPermission(param.UserId)
// withSql := task1 + `,
// -- 获取的里程碑数据,以及排序
// t_task_tage_1 as(
// select
// task.id as task_id,
// task."name" as task_name,
// task."alias" as task_alias_name,
// task.leader ->>'name' as leader_name,
// task.leader ->>'id' as leader_id,
// task.level_name ,
// task.anomaly ,
// task.updated_at ,
// task.created_at ,
// task."level" ,
// task."warn_flag",
// task."status" as task_status,
// task_stage."id" as stage_id,
// task_stage."name" as stage_name,
// task_stage.sort_by as stage_sort_by,
// task_stage.plan_completed_at,
// task_stage.real_completed_at,
// (case
// when task_stage.real_completed_at =0
// then task_stage.plan_completed_at - floor( extract(epoch from now()))
// else task_stage.plan_completed_at - task_stage.real_completed_at
// end) as diff_time
// from task
// join t_task_1 on task.id=t_task_1.id
// join task_stage on task.id =task_stage.task_id
// where 1=1 and task.company_id=?
// order by diff_time,task."level",task.created_at desc
// ),
// -- 按任务数据分页获取
// t_task_page as (
// select distinct t_task_tage_1.task_id
// from t_task_tage_1
// where 1=1
// %s
// limit ? offset ?
// )
// select
// t_task_tage_1.task_id,
// t_task_tage_1.task_name,
// t_task_tage_1.task_alias_name,
// t_task_tage_1.leader_name,
// t_task_tage_1.level_name ,
// t_task_tage_1.anomaly ,
// t_task_tage_1.updated_at ,
// t_task_tage_1.created_at ,
// t_task_tage_1."level" ,
// t_task_tage_1.plan_completed_at,
// t_task_tage_1.real_completed_at,
// t_task_tage_1.stage_name,
// t_task_tage_1.stage_id,
// t_task_tage_1.stage_sort_by,
// t_task_tage_1."warn_flag"
// from t_task_tage_1
// where t_task_tage_1.task_id in(
// select t_task_page.task_id from t_task_page
// )`
// condition := []interface{}{param.CompanyId}
// whereSql := ``
// if param.OnlyMy {
// condition = append(condition, param.UserId)
// whereSql += ` and t_task_tage_1.leader_id = '?' `
// }
// if param.SearchWord != "" {
// condition = append(condition, param.SearchWord, param.SearchWord)
// whereSql += ` and (t_task_tage_1.leader_name like ? or t_task_tage_1.task_alias_name like ?)`
// }
// condition = append(condition, param.Limit, param.Offset)
// sqlStr := fmt.Sprintf(withSql, whereSql)
// result := []ListTaskStage{}
// tx := d.transactionContext.PgTx
// _, err := tx.Query(&result, sqlStr, condition...)
// return result, err
// }
// 获取任务总数,用于页面展示; 有过滤查看权限
func (d *TaskDao) CountTaskNotHrbp(param ListTaskCondition) (int, error) {
... ... @@ -203,88 +203,88 @@ func (d *TaskDao) CountTaskNotHrbp(param ListTaskCondition) (int, error) {
// userid 谁要查看任务数据
// limit 分页
// offset 分页
func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
withSql := `with
t_task_ignore as (
select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
),
-- 获取的里程碑数据,以及排序
t_task_tage_1 as(
select
task.id as task_id,
task."name" as task_name,
task."alias" as task_alias_name,
task."status" as task_status,
task.leader ->>'name' as leader_name,
task.leader ->>'id' as leader_id,
task.level_name ,
task.anomaly ,
task.updated_at ,
task."warn_flag",
task.created_at ,
task."level" ,
task_stage."id" as stage_id,
task_stage."name" as stage_name,
task_stage.sort_by as stage_sort_by,
task_stage.plan_completed_at,
task_stage.real_completed_at,
(case
when task_stage.real_completed_at =0
then task_stage.plan_completed_at - floor( extract(epoch from now()))
else task_stage.plan_completed_at - task_stage.real_completed_at
end) as diff_time
from task
join task_stage on task.id =task_stage.task_id
where 1=1 and task.company_id=?
order by diff_time,task."level",task.created_at desc
),
-- 按任务数据分页获取
t_task_page as (
select distinct t_task_tage_1.task_id
from t_task_tage_1
left join t_task_ignore on t_task_ignore.task_id=t_task_tage_1.task_id
where t_task_ignore.id isnull
%s
limit ? offset ?
)
select
t_task_tage_1.task_id,
t_task_tage_1.task_name,
t_task_tage_1.task_alias_name,
t_task_tage_1.task_status,
t_task_tage_1.leader_name,
t_task_tage_1.level_name ,
t_task_tage_1.anomaly ,
t_task_tage_1.updated_at ,
t_task_tage_1.created_at ,
t_task_tage_1."level" ,
t_task_tage_1.plan_completed_at,
t_task_tage_1.real_completed_at,
t_task_tage_1.stage_name,
t_task_tage_1.stage_id,
t_task_tage_1."warn_flag",
t_task_tage_1.stage_sort_by
from t_task_tage_1
where t_task_tage_1.task_id in(
select t_task_page.task_id from t_task_page
)`
condition := []interface{}{param.UserId, param.CompanyId}
whereSql := ``
if param.OnlyMy {
condition = append(condition, param.UserId)
whereSql += ` and t_task_tage_1.leader_id = '?' `
}
if param.SearchWord != "" {
condition = append(condition, param.SearchWord, param.SearchWord)
whereSql += ` and (t_task_tage_1.leader_name like ? or t_task_tage_1.task_alias_name like ?) `
}
condition = append(condition, param.Limit, param.Offset)
sqlStr := fmt.Sprintf(withSql, whereSql)
result := []ListTaskStage{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
// withSql := `with
// t_task_ignore as (
// select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
// ),
// -- 获取的里程碑数据,以及排序
// t_task_tage_1 as(
// select
// task.id as task_id,
// task."name" as task_name,
// task."alias" as task_alias_name,
// task."status" as task_status,
// task.leader ->>'name' as leader_name,
// task.leader ->>'id' as leader_id,
// task.level_name ,
// task.anomaly ,
// task.updated_at ,
// task."warn_flag",
// task.created_at ,
// task."level" ,
// task_stage."id" as stage_id,
// task_stage."name" as stage_name,
// task_stage.sort_by as stage_sort_by,
// task_stage.plan_completed_at,
// task_stage.real_completed_at,
// (case
// when task_stage.real_completed_at =0
// then task_stage.plan_completed_at - floor( extract(epoch from now()))
// else task_stage.plan_completed_at - task_stage.real_completed_at
// end) as diff_time
// from task
// join task_stage on task.id =task_stage.task_id
// where 1=1 and task.company_id=?
// order by diff_time,task."level",task.created_at desc
// ),
// -- 按任务数据分页获取
// t_task_page as (
// select distinct t_task_tage_1.task_id
// from t_task_tage_1
// left join t_task_ignore on t_task_ignore.task_id=t_task_tage_1.task_id
// where t_task_ignore.id isnull
// %s
// limit ? offset ?
// )
// select
// t_task_tage_1.task_id,
// t_task_tage_1.task_name,
// t_task_tage_1.task_alias_name,
// t_task_tage_1.task_status,
// t_task_tage_1.leader_name,
// t_task_tage_1.level_name ,
// t_task_tage_1.anomaly ,
// t_task_tage_1.updated_at ,
// t_task_tage_1.created_at ,
// t_task_tage_1."level" ,
// t_task_tage_1.plan_completed_at,
// t_task_tage_1.real_completed_at,
// t_task_tage_1.stage_name,
// t_task_tage_1.stage_id,
// t_task_tage_1."warn_flag",
// t_task_tage_1.stage_sort_by
// from t_task_tage_1
// where t_task_tage_1.task_id in(
// select t_task_page.task_id from t_task_page
// )`
// condition := []interface{}{param.UserId, param.CompanyId}
// whereSql := ``
// if param.OnlyMy {
// condition = append(condition, param.UserId)
// whereSql += ` and t_task_tage_1.leader_id = '?' `
// }
// if param.SearchWord != "" {
// condition = append(condition, param.SearchWord, param.SearchWord)
// whereSql += ` and (t_task_tage_1.leader_name like ? or t_task_tage_1.task_alias_name like ?) `
// }
// condition = append(condition, param.Limit, param.Offset)
// sqlStr := fmt.Sprintf(withSql, whereSql)
// result := []ListTaskStage{}
// tx := d.transactionContext.PgTx
// _, err := tx.Query(&result, sqlStr, condition...)
// return result, err
// }
// 获取任务总数,用于页面展示; 无过滤查看权限
func (d *TaskDao) CountTaskByHrbp(param ListTaskCondition) (int, error) {
... ...