From d7bc4d8946ec846e8cbfa710e50c9ce6ccb9bd52 Mon Sep 17 00:00:00 2001 From: tangxvhui <you@example.com> Date: Tue, 25 Apr 2023 19:31:50 +0800 Subject: [PATCH] 更新 --- pkg/application/notify/service/message_personal.go | 2 +- pkg/application/staff_assess/service/create_staff_assess.go | 11 +++++++---- pkg/application/task/adapter/condition_selecet.go | 5 +++++ pkg/application/task/command/get_select.go | 7 +++++++ pkg/application/task/command/search_task.go | 2 +- pkg/application/task/service/service.go | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- pkg/domain/task_record.go | 2 +- pkg/infrastructure/dao/task_dao.go | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- pkg/infrastructure/pg/models/task.go | 32 ++++++++++++++++---------------- pkg/port/beego/controllers/task_controller.go | 17 +++++++++++++++++ pkg/port/beego/routers/task_router.go | 1 + 11 files changed, 209 insertions(+), 67 deletions(-) create mode 100644 pkg/application/task/adapter/condition_selecet.go create mode 100644 pkg/application/task/command/get_select.go diff --git a/pkg/application/notify/service/message_personal.go b/pkg/application/notify/service/message_personal.go index ea77400..b95dac5 100644 --- a/pkg/application/notify/service/message_personal.go +++ b/pkg/application/notify/service/message_personal.go @@ -204,7 +204,7 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G } } for _, val := range taskStageList2 { - s := fmt.Sprintf("您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。", val.LeaderName, val.Name) + s := fmt.Sprintf("【您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.Name) msgList = append(msgList, adapter.MessageListAdapter{ Content: s, }) diff --git a/pkg/application/staff_assess/service/create_staff_assess.go b/pkg/application/staff_assess/service/create_staff_assess.go index 821ef4c..8c9e470 100644 --- a/pkg/application/staff_assess/service/create_staff_assess.go +++ b/pkg/application/staff_assess/service/create_staff_assess.go @@ -134,6 +134,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext}) // 保存 员工的需要填写的每日任务型 指标项 taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext}) + + newTaskIdList := []int{} for i := range assessList { assessList[i].StaffAssessTaskId = assessTaskData.Id _, err = assessRepo.Save(&assessList[i]) @@ -156,13 +158,14 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat if err != nil { return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人任务型指标项"+err.Error()) } - err = taskDao.IncreaseAnomaly([]int{val2.TaskId}, 1) - if err != nil { - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人任务型指标项"+err.Error()) - } + newTaskIdList = append(newTaskIdList, val2.TaskId) } } } + err = taskDao.IncreaseAnomaly(newTaskIdList, 1) + if err != nil { + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人任务型指标项"+err.Error()) + } return map[string]interface{}{ "assessTaskId": assessTaskData.Id, }, nil diff --git a/pkg/application/task/adapter/condition_selecet.go b/pkg/application/task/adapter/condition_selecet.go new file mode 100644 index 0000000..5f330e1 --- /dev/null +++ b/pkg/application/task/adapter/condition_selecet.go @@ -0,0 +1,5 @@ +package adapter + +type ConditionSelect struct { + Name string +} diff --git a/pkg/application/task/command/get_select.go b/pkg/application/task/command/get_select.go new file mode 100644 index 0000000..c50ec02 --- /dev/null +++ b/pkg/application/task/command/get_select.go @@ -0,0 +1,7 @@ +package command + +type GetSelcetCommand struct { + Cmd string `json:"cmd"` // 任务名称,负责人,优先级 + UserId int `json:"-"` //当前用户id + CompanyId int `json:"-"` //当前公司id +} diff --git a/pkg/application/task/command/search_task.go b/pkg/application/task/command/search_task.go index 4ea6f35..7745d93 100644 --- a/pkg/application/task/command/search_task.go +++ b/pkg/application/task/command/search_task.go @@ -8,5 +8,5 @@ type SearchTaskCommand struct { TaskName string `json:"taskName"` //任务名称 LevelName string `json:"levelName"` //优先级 OnlyMy bool `json:"onlyMy"` //只查看我负责的任务 - LeaderId string `json:"leaderId"` //任务负责人id + LeaderName string `json:"leaderId"` //任务负责人id } diff --git a/pkg/application/task/service/service.go b/pkg/application/task/service/service.go index 74f9f0b..2c6b774 100644 --- a/pkg/application/task/service/service.go +++ b/pkg/application/task/service/service.go @@ -681,13 +681,13 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i } } condition := dao.ListTaskCondition{ - Limit: limit, - Offset: offset, - UserId: param.UserId, - TaskName: param.TaskName, - LevelName: param.LevelName, - OnlyMy: param.OnlyMy, - LeaderId: param.LeaderId, + Limit: limit, + Offset: offset, + UserId: param.UserId, + TaskName: param.TaskName, + LevelName: param.LevelName, + OnlyMy: param.OnlyMy, + LeaderName: param.LeaderName, } taskDao := dao.NewTaskDao(map[string]interface{}{ @@ -780,13 +780,13 @@ func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[s } } condition := dao.ListTaskCondition{ - Limit: limit, - Offset: offset, - UserId: param.UserId, - TaskName: param.TaskName, - LevelName: param.LevelName, - OnlyMy: param.OnlyMy, - LeaderId: param.LeaderId, + Limit: limit, + Offset: offset, + UserId: param.UserId, + TaskName: param.TaskName, + LevelName: param.LevelName, + OnlyMy: param.OnlyMy, + LeaderName: param.LeaderName, } transactionContext, err := factory.CreateTransactionContext(nil) if err != nil { @@ -987,7 +987,7 @@ func (srv TaskService) ListTaskRecord(param *command.ListTaskRecordCommand) (map return result, nil } -// 获取任务详情 +// 删除任务 func (srv TaskService) DeleteTaskInfo(param *command.GetTaskCommand) (*adapter.TaskInfoAdapter, error) { transactionContext, err := factory.CreateTransactionContext(nil) if err != nil { @@ -1022,3 +1022,70 @@ func (srv TaskService) DeleteTaskInfo(param *command.GetTaskCommand) (*adapter.T } return nil, nil } + +// 员工绩效-任务管理-列表筛选项 +func (srv TaskService) ConditionForListTask2(param *command.GetSelcetCommand) (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() + }() + taskDao := dao.NewTaskDao(map[string]interface{}{ + "transactionContext": transactionContext, + }) + hrbpFlag, err := roleService.GetHrBp(transactionContext, int(param.CompanyId), int(param.UserId)) + if err != nil { + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息"+err.Error()) + } + var tasklistData []dao.TaskData1 + if hrbpFlag == domain.RoleTypeSystem { + tasklistData, err = taskDao.ListTask2ForHrbp(param.UserId) + if err != nil { + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error()) + } + } else { + tasklistData, err = taskDao.ListTask2(param.UserId) + 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()) + } + selectList := []adapter.ConditionSelect{} + uniqueMap := map[string]struct{}{} + // 任务名称,负责人,优先级 + switch param.Cmd { + case "任务名称": + for _, val := range tasklistData { + selectList = append(selectList, adapter.ConditionSelect{Name: val.Name}) + } + case "负责人": + for _, val := range tasklistData { + if _, ok := uniqueMap[val.LeaderName]; ok { + continue + } + uniqueMap[val.LeaderName] = struct{}{} + selectList = append(selectList, adapter.ConditionSelect{Name: val.LeaderName}) + } + case "优先级": + for _, val := range tasklistData { + if _, ok := uniqueMap[val.LevelName]; ok { + continue + } + uniqueMap[val.LevelName] = struct{}{} + if len(val.LevelName) > 0 { + selectList = append(selectList, adapter.ConditionSelect{Name: val.LevelName}) + } + } + } + result := map[string]interface{}{ + "list": selectList, + } + return result, nil +} diff --git a/pkg/domain/task_record.go b/pkg/domain/task_record.go index d35eda8..93c0e65 100644 --- a/pkg/domain/task_record.go +++ b/pkg/domain/task_record.go @@ -26,7 +26,7 @@ type TaskRecord struct { TaskLeader TaskLeader `json:"taskLeader" comment:"任务负责人"` AssistLevel int `json:"assistLevel" comment:"上级辅导情况"` AssistContent string `json:"assistContent" comment:"上级辅导内容"` - AnomalyState int `json:"anomalyState" comment:"异常反馈状态(0异常、1正常)"` + AnomalyState int `json:"anomalyState" comment:"异常是否反馈状态(0异常、1正常)"` TaskStages []TaskStage `json:"taskStages" comment:"里程碑列表"` TaskStageCheck TaskStage `json:"taskStageCheck" comment:"提交的里程碑"` CreatedAt time.Time `json:"createdAt" comment:"创建时间"` diff --git a/pkg/infrastructure/dao/task_dao.go b/pkg/infrastructure/dao/task_dao.go index 155dd6b..4fbff66 100644 --- a/pkg/infrastructure/dao/task_dao.go +++ b/pkg/infrastructure/dao/task_dao.go @@ -60,13 +60,13 @@ func (d *TaskDao) catchTaskIdByPermission(userId int) string { } type ListTaskCondition struct { - Limit int //分页 - Offset int //分页 - UserId int //谁要查看任务数据 - TaskName string //任务名称 - LevelName string //优先级 - OnlyMy bool //只查看我负责的任务 - LeaderId string //任务负责人id + Limit int //分页 + Offset int //分页 + UserId int //谁要查看任务数据 + TaskName string //任务名称 + LevelName string //优先级 + OnlyMy bool //只查看我负责的任务 + LeaderName string //任务负责人名称 } // 任务和里程碑列表 @@ -161,9 +161,9 @@ func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and t_task_tage_1.leader_id = '?' ` - } else if param.LeaderId != "" && param.LeaderId != "0" { - condition = append(condition, param.LeaderId) - whereSql += ` and t_task_tage_1.leader_id = ? ` + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) + whereSql += ` and t_task_tage_1.leader_name = ? ` } if len(param.TaskName) > 0 { condition = append(condition, param.TaskName) @@ -192,9 +192,9 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) { if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and task.leader ->>'id' = '?' ` - } else if param.LeaderId != "" && param.LeaderId != "0" { - condition = append(condition, param.LeaderId) - whereSql += ` and task.leader ->>'id' = ? ` + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) + whereSql += ` and task.leader ->>'name' = ? ` } if len(param.TaskName) > 0 { condition = append(condition, param.TaskName) @@ -285,9 +285,9 @@ func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and t_task_tage_1.leader_id = '?' ` - } else if param.LeaderId != "" && param.LeaderId != "0" { - condition = append(condition, param.LeaderId) - whereSql += ` and t_task_tage_1.leader_id = ? ` + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) + whereSql += ` and t_task_tage_1.leader_name = ? ` } if len(param.TaskName) > 0 { condition = append(condition, param.TaskName) @@ -319,9 +319,9 @@ func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) { if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and task.leader ->>'id' = '?' ` - } else if param.LeaderId != "" && param.LeaderId != "0" { - condition = append(condition, param.LeaderId) - whereSql += ` and task.leader ->>'id' = ? ` + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) + whereSql += ` and task.leader ->>'name' = ? ` } if len(param.TaskName) > 0 { condition = append(condition, param.TaskName) @@ -356,9 +356,9 @@ func (d *TaskDao) CountTaskStageAnomalyNotHrbp(param ListTaskCondition) (int, er if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and task.leader ->>'id' = '?' ` - } else if param.LeaderId != "" && param.LeaderId != "0" { - condition = append(condition, param.LeaderId) - whereSql += ` and task.leader ->>'id' = ? ` + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) + whereSql += ` and task.leader ->>'name' = ? ` } if len(param.TaskName) > 0 { condition = append(condition, param.TaskName) @@ -395,9 +395,9 @@ func (d *TaskDao) CountTaskStageAnomalyByHrbp(param ListTaskCondition) (int, err if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and task.leader ->>'id' = '?' ` - } else if param.LeaderId != "" && param.LeaderId != "0" { - condition = append(condition, param.LeaderId) - whereSql += ` and task.leader ->>'id' = ? ` + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) + whereSql += ` and task.leader ->>'name' = ? ` } if len(param.TaskName) > 0 { condition = append(condition, param.TaskName) @@ -474,8 +474,8 @@ func (d *TaskDao) CountTaskAnomalyNotHrbp(param ListTaskCondition) (int, error) if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and task.leader ->>'id' = '?' ` - } else if param.LeaderId != "" { - condition = append(condition, param.LeaderId) + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) whereSql += ` and task.leader ->>'id' = ? ` } if len(param.TaskName) > 0 { @@ -507,8 +507,8 @@ func (d *TaskDao) CountTaskAnomalyByHrbp(param ListTaskCondition) (int, error) { if param.OnlyMy { condition = append(condition, param.UserId) whereSql += ` and task.leader ->>'id' = '?' ` - } else if param.LeaderId != "" { - condition = append(condition, param.LeaderId) + } else if param.LeaderName != "" { + condition = append(condition, param.LeaderName) whereSql += ` and task.leader ->>'id' = ? ` } if len(param.TaskName) > 0 { @@ -525,3 +525,45 @@ func (d *TaskDao) CountTaskAnomalyByHrbp(param ListTaskCondition) (int, error) { _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...) return cnt, err } + +// 任务数据 +type TaskData1 struct { + Name string `pg:"name"` + Alias string `pg:"alias"` + LeaderId string `pg:"leader_id"` + LeaderName string `pg:"leader_name"` + LevelName string `pg:"level_name"` +} + +// 获取任务列表 +func (d *TaskDao) ListTask2(userId int) ([]TaskData1, error) { + task1 := d.catchTaskIdByPermission(userId) + sqlStr := task1 + ` select task."name" ,task.alias , + task.leader ->>'id' as leader_id, + task.leader ->>'name' as leaer_name, + task.level_name + from task ` + result := []TaskData1{} + tx := d.transactionContext.PgTx + _, err := tx.Query(&result, sqlStr) + return result, err +} + +// 获取任务列表 +func (d *TaskDao) ListTask2ForHrbp(userId int) ([]TaskData1, error) { + sqlStr := `with + t_task_ignore as ( + select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =? + )select task."name" ,task.alias , + task.leader ->>'id' as leader_id, + task.leader ->>'name' as leaer_name, + task.level_name + from task + left join t_task_ignore on t_task_ignore.task_id=task.id + where 1=1 ` + result := []TaskData1{} + tx := d.transactionContext.PgTx + _, err := tx.Query(&result, sqlStr, userId) + return result, err + +} diff --git a/pkg/infrastructure/pg/models/task.go b/pkg/infrastructure/pg/models/task.go index 51828ef..3bd623f 100644 --- a/pkg/infrastructure/pg/models/task.go +++ b/pkg/infrastructure/pg/models/task.go @@ -9,20 +9,20 @@ import ( // 任务 type Task struct { tableName struct{} `comment:"任务" pg:"task"` - Id int `pg:"id,pk"` // - CreatedAt time.Time `pg:"created_at"` // - UpdatedAt time.Time `pg:"updated_at"` // - DeletedAt *time.Time `pg:"deleted_at"` // - Name string `pg:"name"` // 任务名称 - Alias string `pg:"alias"` // - CompanyId int `pg:"company_id"` // - Leader domain.TaskLeader `pg:"leader"` // 任务负责人 - Status int `pg:"status"` // 任务的状态 - Level int `pg:"level"` // 优先级,值越小优先级越高 - LevelName string `pg:"level_name"` // 优先级名称 - RelatedUser []int `pg:"related_user"` // - RunAt int64 `pg:"run_at"` // 启动的时间 - StopAt int64 `pg:"stop_at"` // 停止的时间 - Anomaly int `pg:"anomaly"` // 异常反馈的数量 - WarnFlag int `pg:"warn_flag"` // 里程碑异常标记 + Id int `pg:"id,pk"` // + CreatedAt time.Time `pg:"created_at"` // + UpdatedAt time.Time `pg:"updated_at"` // + DeletedAt *time.Time `pg:"deleted_at"` // + Name string `pg:"name"` // 任务名称 + Alias string `pg:"alias"` // + CompanyId int `pg:"company_id"` // + Leader domain.TaskLeader `pg:"leader"` // 任务负责人 + Status int `pg:"status,use_zero"` // 任务的状态 + Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高 + LevelName string `pg:"level_name"` // 优先级名称 + RelatedUser []int `pg:"related_user"` // + RunAt int64 `pg:"run_at,use_zero"` // 启动的时间 + StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间 + Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量 + WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记 } diff --git a/pkg/port/beego/controllers/task_controller.go b/pkg/port/beego/controllers/task_controller.go index 028b9d4..a438607 100644 --- a/pkg/port/beego/controllers/task_controller.go +++ b/pkg/port/beego/controllers/task_controller.go @@ -172,3 +172,20 @@ func (c *TaskController) DeleteTask() { data, err := srv.DeleteTaskInfo(paramReq) c.Response(data, err) } + +// SelectCondition 员工绩效-任务管理-任务列表-筛选条件 +func (c *TaskController) SelectCondition() { + srv := service.NewTaskService() + paramReq := &command.GetSelcetCommand{} + err := c.BindJSON(paramReq) + if err != nil { + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) + c.Response(nil, e) + return + } + userReq := middlewares.GetUser(c.Ctx) + paramReq.CompanyId = int(userReq.CompanyId) + paramReq.UserId = int(userReq.UserId) + data, err := srv.ConditionForListTask2(paramReq) + c.Response(data, err) +} diff --git a/pkg/port/beego/routers/task_router.go b/pkg/port/beego/routers/task_router.go index 5fc7ac9..dcf91d2 100644 --- a/pkg/port/beego/routers/task_router.go +++ b/pkg/port/beego/routers/task_router.go @@ -24,6 +24,7 @@ func init() { web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), web.NSCtrlPost("/attention/cancel", (*controllers.TaskController).CancelAttention), web.NSCtrlPost("/list", (*controllers.TaskController).ListTask2), + web.NSCtrlPost("/list/select", (*controllers.TaskController).SelectCondition), web.NSCtrlPost("/task_record/list", (*controllers.TaskController).ListTaskRecord), web.NSCtrlPost("/info", (*controllers.TaskController).GetTaskInfo), ) -- libgit2 0.24.0