Merge branch 'dev-tangxvhui' into dev-zhengzhou
正在显示
22 个修改的文件
包含
390 行增加
和
103 行删除
| @@ -231,3 +231,11 @@ func CreateTaskStageRepository(options map[string]interface{}) domain.TaskStageR | @@ -231,3 +231,11 @@ func CreateTaskStageRepository(options map[string]interface{}) domain.TaskStageR | ||
| 231 | } | 231 | } |
| 232 | return repository.NewTaskStageRepository(transactionContext) | 232 | return repository.NewTaskStageRepository(transactionContext) |
| 233 | } | 233 | } |
| 234 | + | ||
| 235 | +func CreateTaskIgnoreRepository(options map[string]interface{}) domain.TaskIgnoreRepository { | ||
| 236 | + var transactionContext *pg.TransactionContext | ||
| 237 | + if value, ok := options["transactionContext"]; ok { | ||
| 238 | + transactionContext = value.(*pg.TransactionContext) | ||
| 239 | + } | ||
| 240 | + return repository.NewTaskIgnoreRepository(transactionContext) | ||
| 241 | +} |
| 1 | package adapter | 1 | package adapter |
| 2 | 2 | ||
| 3 | type TaskInfoAdapter struct { | 3 | type TaskInfoAdapter struct { |
| 4 | - Id int `json:"id,string"` | ||
| 5 | - Name string `json:"name"` // 任务名称 | ||
| 6 | - Alias string `json:"alias"` // 任务别名 | ||
| 7 | - Leader UserData `json:"leader"` // 任务负责人 | ||
| 8 | - Status int `json:"status"` // 任务的状态 | ||
| 9 | - Level int `json:"level"` // 优先级,值越小优先级越高 | ||
| 10 | - LevalName string `json:"levalName"` // 优先级名称 | ||
| 11 | - RelatedUserId []string `json:"relatedUserId"` // 相关的员工id | ||
| 12 | - RelatedUser []UserData `json:"relatedUser"` // 相关的员工id | ||
| 13 | - StageList []TaskStage `json:"stageList"` | 4 | + Id int `json:"id,string"` |
| 5 | + Name string `json:"name"` // 任务名称 | ||
| 6 | + Alias string `json:"alias"` // 任务别名 | ||
| 7 | + LeaderId int64 `json:"leaderId,string"` // | ||
| 8 | + Leader UserData `json:"leader"` // 任务负责人 | ||
| 9 | + Status int `json:"status"` // 任务的状态 | ||
| 10 | + StatusDescript string `json:"statusDescript"` // | ||
| 11 | + Level int `json:"level"` // 优先级,值越小优先级越高 | ||
| 12 | + LevalName string `json:"levalName"` // 优先级名称 | ||
| 13 | + RelatedUserId []string `json:"relatedUserId"` // 相关的员工id | ||
| 14 | + RelatedUser []UserData `json:"relatedUser"` // 相关的员工id | ||
| 15 | + StageList []TaskStage `json:"stageList"` | ||
| 14 | } | 16 | } |
| 15 | 17 | ||
| 16 | type UserData struct { | 18 | type UserData struct { |
| @@ -21,8 +23,10 @@ type UserData struct { | @@ -21,8 +23,10 @@ type UserData struct { | ||
| 21 | 23 | ||
| 22 | type TaskStage struct { | 24 | type TaskStage struct { |
| 23 | Id int `json:"id,string"` | 25 | Id int `json:"id,string"` |
| 24 | - Name string `json:"name"` //里程碑名称 | ||
| 25 | - StatusCompleted string `json:"statusCompleted"` //里程碑的完成情况 | 26 | + Name string `json:"name"` //里程碑名称 |
| 27 | + StatusDescript string `json:"statusDescript"` //里程碑的完成情况 | ||
| 28 | + Status int `json:"status"` //里程碑状态 | ||
| 29 | + SortBy int `json:"sortBy"` | ||
| 26 | PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 | 30 | PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 |
| 27 | RealCompletedAt string `json:"realCompletedAt"` //实际完成时间, 例:2006-01-02 | 31 | RealCompletedAt string `json:"realCompletedAt"` //实际完成时间, 例:2006-01-02 |
| 28 | } | 32 | } |
| 1 | package adapter | 1 | package adapter |
| 2 | 2 | ||
| 3 | type TaskItem struct { | 3 | type TaskItem struct { |
| 4 | - Id int `json:"id,string"` | ||
| 5 | - Name string `json:"name"` // 任务名称 | ||
| 6 | - Alias string `json:"alias"` // 任务别名 | ||
| 7 | - Leader string `json:"leader"` // 任务负责人 | ||
| 8 | - Status int `json:"status"` // 任务的状态 | ||
| 9 | - Level int `json:"level"` // 优先级,值越小优先级越高 | ||
| 10 | - LevelName string `json:"levelName"` // 优先级名称 | ||
| 11 | - StageA string `json:"stageA"` // 里程碑1 | ||
| 12 | - StageB string `json:"stageB"` // 里程碑2 | ||
| 13 | - StageC string `json:"stageC"` // 里程碑3 | ||
| 14 | - StageD string `json:"stageD"` // 里程碑4 | ||
| 15 | - StageE string `json:"stageE"` // 里程碑5 | 4 | + Id int `json:"id,string"` |
| 5 | + Name string `json:"name"` // 任务名称 | ||
| 6 | + Alias string `json:"alias"` // 任务别名 | ||
| 7 | + Leader string `json:"leader"` // 任务负责人 | ||
| 8 | + Status int `json:"status"` // 任务的状态 | ||
| 9 | + Level int `json:"level"` // 优先级,值越小优先级越高 | ||
| 10 | + LevelName string `json:"levelName"` // 优先级名称 | ||
| 11 | + StageA TaskStage `json:"stageA"` // 里程碑1 | ||
| 12 | + StageB TaskStage `json:"stageB"` // 里程碑2 | ||
| 13 | + StageC TaskStage `json:"stageC"` // 里程碑3 | ||
| 14 | + StageD TaskStage `json:"stageD"` // 里程碑4 | ||
| 15 | + StageE TaskStage `json:"stageE"` // 里程碑5 | ||
| 16 | } | 16 | } |
| 1 | package command | 1 | package command |
| 2 | 2 | ||
| 3 | type UpdateTaskCommand struct { | 3 | type UpdateTaskCommand struct { |
| 4 | - Id int `json:"id,string"` | ||
| 5 | - Alias string `json:"alias"` //任务名称 | ||
| 6 | - LeaderId int `json:"leaderId,string"` //负责id | ||
| 7 | - LevelName string `json:"levelName"` //优先级 | ||
| 8 | - StageList []struct { | 4 | + Id int `json:"id,string"` |
| 5 | + Alias string `json:"alias"` //任务名称 | ||
| 6 | + LevelName string `json:"levelName"` //优先级 | ||
| 7 | + RelatedUserId []string `json:"relatedUserId"` //相关人员id | ||
| 8 | + StageList []struct { | ||
| 9 | Id int `json:"id,string"` | 9 | Id int `json:"id,string"` |
| 10 | Name string `json:"name"` //里程碑名称 | 10 | Name string `json:"name"` //里程碑名称 |
| 11 | PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 | 11 | PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 |
| @@ -25,6 +25,27 @@ func dayEndTime(t time.Time) time.Time { | @@ -25,6 +25,27 @@ func dayEndTime(t time.Time) time.Time { | ||
| 25 | return t2 | 25 | return t2 |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | +func (srv TaskService) CreateTaskTest(param *command.CreateTaskCommand) error { | ||
| 29 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 30 | + if err != nil { | ||
| 31 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 32 | + } | ||
| 33 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 34 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 35 | + } | ||
| 36 | + defer func() { | ||
| 37 | + _ = transactionContext.RollbackTransaction() | ||
| 38 | + }() | ||
| 39 | + err = srv.CreateTask(transactionContext, param) | ||
| 40 | + if err != nil { | ||
| 41 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | ||
| 42 | + } | ||
| 43 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 44 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 45 | + } | ||
| 46 | + return nil | ||
| 47 | +} | ||
| 48 | + | ||
| 28 | func (srv TaskService) CreateTask(transactionContext application.TransactionContext, param *command.CreateTaskCommand) error { | 49 | func (srv TaskService) CreateTask(transactionContext application.TransactionContext, param *command.CreateTaskCommand) error { |
| 29 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ | 50 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ |
| 30 | "transactionContext": transactionContext, | 51 | "transactionContext": transactionContext, |
| @@ -44,18 +65,42 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont | @@ -44,18 +65,42 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont | ||
| 44 | //任务已存在 | 65 | //任务已存在 |
| 45 | return nil | 66 | return nil |
| 46 | } | 67 | } |
| 68 | + userRepo := factory.CreateUserRepository(map[string]interface{}{ | ||
| 69 | + "transactionContext": transactionContext, | ||
| 70 | + }) | ||
| 71 | + | ||
| 72 | + _, leaderList, err := userRepo.Find(map[string]interface{}{ | ||
| 73 | + "id": param.LeaderId, | ||
| 74 | + }) | ||
| 75 | + if err != nil { | ||
| 76 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询人员失败:"+err.Error()) | ||
| 77 | + } | ||
| 78 | + if len(leaderList) == 0 { | ||
| 79 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有查询到人员") | ||
| 80 | + } | ||
| 81 | + leaderData := leaderList[0] | ||
| 47 | nowTime := time.Now() | 82 | nowTime := time.Now() |
| 48 | newTask := domain.Task{ | 83 | newTask := domain.Task{ |
| 49 | - Id: 0, | ||
| 50 | - Name: param.Name, | ||
| 51 | - Alias: param.Name, | 84 | + Id: 0, |
| 85 | + CreatedAt: time.Time{}, | ||
| 86 | + UpdatedAt: time.Time{}, | ||
| 87 | + DeletedAt: nil, | ||
| 88 | + CompanyId: int(leaderData.CompanyId), | ||
| 89 | + Name: param.Name, | ||
| 90 | + Alias: param.Name, | ||
| 91 | + Leader: domain.TaskLeader{ | ||
| 92 | + Id: leaderData.Id, | ||
| 93 | + Account: leaderData.Account, | ||
| 94 | + Name: leaderData.Name, | ||
| 95 | + }, | ||
| 52 | Status: domain.TaskWait, | 96 | Status: domain.TaskWait, |
| 53 | Level: 0, | 97 | Level: 0, |
| 54 | LevelName: "", | 98 | LevelName: "", |
| 55 | RelatedUser: []int{}, | 99 | RelatedUser: []int{}, |
| 56 | RunAt: nowTime.Unix(), | 100 | RunAt: nowTime.Unix(), |
| 101 | + StopAt: 0, | ||
| 57 | } | 102 | } |
| 58 | - newTask.ApplyLevelName("") | 103 | + newTask.ApplyLevelName("战略任务") |
| 59 | err = taskRepo.Save(&newTask) | 104 | err = taskRepo.Save(&newTask) |
| 60 | if err != nil { | 105 | if err != nil { |
| 61 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | 106 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) |
| @@ -99,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont | @@ -99,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont | ||
| 99 | return nil | 144 | return nil |
| 100 | } | 145 | } |
| 101 | 146 | ||
| 147 | +// 更新任务 | ||
| 148 | +// TODO 检查是否可以修改,和通知 | ||
| 102 | func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) { | 149 | func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) { |
| 103 | transactionContext, err := factory.CreateTransactionContext(nil) | 150 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 104 | if err != nil { | 151 | if err != nil { |
| @@ -110,13 +157,23 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -110,13 +157,23 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
| 110 | defer func() { | 157 | defer func() { |
| 111 | _ = transactionContext.RollbackTransaction() | 158 | _ = transactionContext.RollbackTransaction() |
| 112 | }() | 159 | }() |
| 160 | + if len(param.StageList) < 3 { | ||
| 161 | + return map[string]interface{}{ | ||
| 162 | + "id": param.Id, | ||
| 163 | + }, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量至少3个") | ||
| 164 | + } | ||
| 165 | + if len(param.StageList) > 5 { | ||
| 166 | + return map[string]interface{}{ | ||
| 167 | + "id": param.Id, | ||
| 168 | + }, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量太多") | ||
| 169 | + } | ||
| 113 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ | 170 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ |
| 114 | "transactionContext": transactionContext, | 171 | "transactionContext": transactionContext, |
| 115 | }) | 172 | }) |
| 116 | - taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ | 173 | + userRepo := factory.CreateUserRepository(map[string]interface{}{ |
| 117 | "transactionContext": transactionContext, | 174 | "transactionContext": transactionContext, |
| 118 | }) | 175 | }) |
| 119 | - userRepo := factory.CreateUserRepository(map[string]interface{}{ | 176 | + taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ |
| 120 | "transactionContext": transactionContext, | 177 | "transactionContext": transactionContext, |
| 121 | }) | 178 | }) |
| 122 | taskData, err := taskRepo.FindOne(map[string]interface{}{ | 179 | taskData, err := taskRepo.FindOne(map[string]interface{}{ |
| @@ -131,6 +188,21 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -131,6 +188,21 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
| 131 | if err != nil { | 188 | if err != nil { |
| 132 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 189 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 133 | } | 190 | } |
| 191 | + //任务的相关人员 | ||
| 192 | + relatedUserIds := []int{} | ||
| 193 | + for _, val := range param.RelatedUserId { | ||
| 194 | + id, _ := strconv.Atoi(val) | ||
| 195 | + relatedUserIds = append(relatedUserIds, id) | ||
| 196 | + } | ||
| 197 | + var relatedUser []*domain.User | ||
| 198 | + if len(relatedUserIds) > 0 { | ||
| 199 | + _, relatedUser, err = userRepo.Find(map[string]interface{}{ | ||
| 200 | + "ids": relatedUserIds, | ||
| 201 | + }) | ||
| 202 | + if err != nil { | ||
| 203 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务的相关人员"+err.Error()) | ||
| 204 | + } | ||
| 205 | + } | ||
| 134 | ok, err := srv.canUpdateTask(taskData, stageList) | 206 | ok, err := srv.canUpdateTask(taskData, stageList) |
| 135 | if err != nil { | 207 | if err != nil { |
| 136 | return nil, err | 208 | return nil, err |
| @@ -138,22 +210,15 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -138,22 +210,15 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
| 138 | if !ok { | 210 | if !ok { |
| 139 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "日评数据已生成,任务不能再被编辑") | 211 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "日评数据已生成,任务不能再被编辑") |
| 140 | } | 212 | } |
| 141 | - leaderData, err := userRepo.FindOne(map[string]interface{}{ | ||
| 142 | - "id": param.LeaderId, | ||
| 143 | - }) | ||
| 144 | - if err != nil { | ||
| 145 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 213 | + //更新相关人员 |
| 214 | + taskData.RelatedUser = []int{} | ||
| 215 | + for _, val := range relatedUser { | ||
| 216 | + taskData.RelatedUser = append(taskData.RelatedUser, int(val.Id)) | ||
| 146 | } | 217 | } |
| 218 | + //更新任务名称 | ||
| 147 | taskData.Alias = param.Alias | 219 | taskData.Alias = param.Alias |
| 148 | - taskData.Leader = domain.TaskLeader{ | ||
| 149 | - Id: leaderData.Id, | ||
| 150 | - Account: leaderData.Account, | ||
| 151 | - Name: leaderData.Name, | ||
| 152 | - } | ||
| 153 | taskData.ApplyLevelName(param.LevelName) | 220 | taskData.ApplyLevelName(param.LevelName) |
| 154 | - | ||
| 155 | nowTime := time.Now() | 221 | nowTime := time.Now() |
| 156 | - | ||
| 157 | stageMap := map[int]*domain.TaskStage{} | 222 | stageMap := map[int]*domain.TaskStage{} |
| 158 | for _, val := range stageList { | 223 | for _, val := range stageList { |
| 159 | val.DeletedAt = &nowTime | 224 | val.DeletedAt = &nowTime |
| @@ -168,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -168,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
| 168 | } | 233 | } |
| 169 | if i > 0 { | 234 | if i > 0 { |
| 170 | if lastPlanCompletedAt.After(t) { | 235 | if lastPlanCompletedAt.After(t) { |
| 171 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误") | 236 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑["+val2.Name+"]完成时间填写错误") |
| 172 | } | 237 | } |
| 173 | } | 238 | } |
| 174 | lastPlanCompletedAt = t | 239 | lastPlanCompletedAt = t |
| @@ -191,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -191,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
| 191 | } | 256 | } |
| 192 | oldStage.DeletedAt = nil | 257 | oldStage.DeletedAt = nil |
| 193 | oldStage.SortBy = i + 1 | 258 | oldStage.SortBy = i + 1 |
| 194 | - oldStage.PlanCompletedAt = t.Unix() | ||
| 195 | oldStage.Name = val2.Name | 259 | oldStage.Name = val2.Name |
| 260 | + oldStage.PlanCompletedAt = t.Unix() | ||
| 261 | + //TODO 修改里程碑计划完成时间,特殊处理 | ||
| 196 | } | 262 | } |
| 197 | stageList = append(stageList, newStageList...) | 263 | stageList = append(stageList, newStageList...) |
| 198 | 264 | ||
| @@ -247,31 +313,36 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task | @@ -247,31 +313,36 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task | ||
| 247 | } | 313 | } |
| 248 | 314 | ||
| 249 | relatedUserId := taskData.RelatedUser | 315 | relatedUserId := taskData.RelatedUser |
| 250 | - _, relatedUserList, err := userRepo.Find(map[string]interface{}{ | ||
| 251 | - "ids": relatedUserId, | ||
| 252 | - }) | ||
| 253 | - if err != nil { | ||
| 254 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取相关人员"+err.Error()) | 316 | + var relatedUserList []*domain.User |
| 317 | + if len(relatedUserId) > 0 { | ||
| 318 | + _, relatedUserList, err = userRepo.Find(map[string]interface{}{ | ||
| 319 | + "ids": relatedUserId, | ||
| 320 | + }) | ||
| 321 | + if err != nil { | ||
| 322 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取相关人员"+err.Error()) | ||
| 323 | + } | ||
| 255 | } | 324 | } |
| 256 | if err := transactionContext.CommitTransaction(); err != nil { | 325 | if err := transactionContext.CommitTransaction(); err != nil { |
| 257 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 326 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 258 | } | 327 | } |
| 259 | 328 | ||
| 260 | result := adapter.TaskInfoAdapter{ | 329 | result := adapter.TaskInfoAdapter{ |
| 261 | - Id: taskData.Id, | ||
| 262 | - Name: taskData.Name, | ||
| 263 | - Alias: taskData.Alias, | 330 | + Id: taskData.Id, |
| 331 | + Name: taskData.Name, | ||
| 332 | + Alias: taskData.Alias, | ||
| 333 | + LeaderId: taskData.Leader.Id, | ||
| 264 | Leader: adapter.UserData{ | 334 | Leader: adapter.UserData{ |
| 265 | Id: taskData.Leader.Id, | 335 | Id: taskData.Leader.Id, |
| 266 | Account: taskData.Leader.Account, | 336 | Account: taskData.Leader.Account, |
| 267 | Name: taskData.Leader.Name, | 337 | Name: taskData.Leader.Name, |
| 268 | }, | 338 | }, |
| 269 | - Status: int(taskData.Status), | ||
| 270 | - Level: taskData.Level, | ||
| 271 | - LevalName: taskData.LevelName, | ||
| 272 | - RelatedUserId: []string{}, | ||
| 273 | - RelatedUser: []adapter.UserData{}, | ||
| 274 | - StageList: []adapter.TaskStage{}, | 339 | + Status: int(taskData.Status), |
| 340 | + StatusDescript: taskData.StatusDescript(), | ||
| 341 | + Level: taskData.Level, | ||
| 342 | + LevalName: taskData.LevelName, | ||
| 343 | + RelatedUserId: []string{}, | ||
| 344 | + RelatedUser: []adapter.UserData{}, | ||
| 345 | + StageList: []adapter.TaskStage{}, | ||
| 275 | } | 346 | } |
| 276 | for _, val := range relatedUserList { | 347 | for _, val := range relatedUserList { |
| 277 | idStr := strconv.Itoa(int(val.Id)) | 348 | idStr := strconv.Itoa(int(val.Id)) |
| @@ -297,7 +368,9 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task | @@ -297,7 +368,9 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task | ||
| 297 | Name: val.Name, | 368 | Name: val.Name, |
| 298 | PlanCompletedAt: t1, | 369 | PlanCompletedAt: t1, |
| 299 | RealCompletedAt: t2, | 370 | RealCompletedAt: t2, |
| 300 | - StatusCompleted: val.DescriptStatus(), | 371 | + SortBy: val.SortBy, |
| 372 | + StatusDescript: val.StatusDescript(), | ||
| 373 | + Status: int(val.Status), | ||
| 301 | }) | 374 | }) |
| 302 | } | 375 | } |
| 303 | return &result, nil | 376 | return &result, nil |
| @@ -441,11 +514,11 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | @@ -441,11 +514,11 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | ||
| 441 | Status: int(val.Status), | 514 | Status: int(val.Status), |
| 442 | Level: val.Level, | 515 | Level: val.Level, |
| 443 | LevelName: val.LevelName, | 516 | LevelName: val.LevelName, |
| 444 | - StageA: "", | ||
| 445 | - StageB: "", | ||
| 446 | - StageC: "", | ||
| 447 | - StageD: "", | ||
| 448 | - StageE: "", | 517 | + // StageA: adapter.TaskStage{}, |
| 518 | + // StageB: adapter.TaskStage{}, | ||
| 519 | + // StageC: adapter.TaskStage{}, | ||
| 520 | + // StageD: adapter.TaskStage{}, | ||
| 521 | + // StageE: adapter.TaskStage{}, | ||
| 449 | } | 522 | } |
| 450 | taskResult = append(taskResult, &tk) | 523 | taskResult = append(taskResult, &tk) |
| 451 | taskMapResult[val.Id] = &tk | 524 | taskMapResult[val.Id] = &tk |
| @@ -455,17 +528,24 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | @@ -455,17 +528,24 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | ||
| 455 | if !ok { | 528 | if !ok { |
| 456 | continue | 529 | continue |
| 457 | } | 530 | } |
| 531 | + stage := adapter.TaskStage{ | ||
| 532 | + Id: val.Id, | ||
| 533 | + Name: val.Name, | ||
| 534 | + StatusDescript: val.StatusDescript(), | ||
| 535 | + Status: int(val.Status), | ||
| 536 | + SortBy: val.SortBy, | ||
| 537 | + } | ||
| 458 | switch val.SortBy { | 538 | switch val.SortBy { |
| 459 | case 1: | 539 | case 1: |
| 460 | - taskData.StageA = val.Name | 540 | + taskData.StageA = stage |
| 461 | case 2: | 541 | case 2: |
| 462 | - taskData.StageB = val.Name | 542 | + taskData.StageB = stage |
| 463 | case 3: | 543 | case 3: |
| 464 | - taskData.StageC = val.Name | 544 | + taskData.StageC = stage |
| 465 | case 4: | 545 | case 4: |
| 466 | - taskData.StageD = val.Name | 546 | + taskData.StageD = stage |
| 467 | case 5: | 547 | case 5: |
| 468 | - taskData.StageE = val.Name | 548 | + taskData.StageE = stage |
| 469 | } | 549 | } |
| 470 | } | 550 | } |
| 471 | result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult) | 551 | result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult) |
| @@ -475,3 +555,38 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | @@ -475,3 +555,38 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | ||
| 475 | func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.TaskStage) (bool, error) { | 555 | func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.TaskStage) (bool, error) { |
| 476 | return true, nil | 556 | return true, nil |
| 477 | } | 557 | } |
| 558 | + | ||
| 559 | +func (t TaskService) ListTask2() error { | ||
| 560 | + return nil | ||
| 561 | +} | ||
| 562 | + | ||
| 563 | +// CancelAttention 用户取消关注某个任务 | ||
| 564 | +func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) error { | ||
| 565 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 566 | + if err != nil { | ||
| 567 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 568 | + } | ||
| 569 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 570 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 571 | + } | ||
| 572 | + defer func() { | ||
| 573 | + _ = transactionContext.RollbackTransaction() | ||
| 574 | + }() | ||
| 575 | + taskIgnoreRepo := factory.CreateTaskIgnoreRepository(map[string]interface{}{ | ||
| 576 | + "transactionContext": transactionContext, | ||
| 577 | + }) | ||
| 578 | + taskIgnore := domain.TaskIgnore{ | ||
| 579 | + Id: 0, | ||
| 580 | + TaskId: param.TaskId, | ||
| 581 | + UserId: param.UserId, | ||
| 582 | + CreatedAt: time.Time{}, | ||
| 583 | + } | ||
| 584 | + err = taskIgnoreRepo.Save(&taskIgnore) | ||
| 585 | + if err != nil { | ||
| 586 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 587 | + } | ||
| 588 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 589 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 590 | + } | ||
| 591 | + return nil | ||
| 592 | +} |
| @@ -26,6 +26,7 @@ type Task struct { | @@ -26,6 +26,7 @@ type Task struct { | ||
| 26 | RelatedUser []int `json:"relatedUser"` // 相关的员工id | 26 | RelatedUser []int `json:"relatedUser"` // 相关的员工id |
| 27 | RunAt int64 `json:"runAt"` // 启动的时间戳,秒 | 27 | RunAt int64 `json:"runAt"` // 启动的时间戳,秒 |
| 28 | StopAt int64 `json:"stopAt"` // 停止的时间戳,秒 | 28 | StopAt int64 `json:"stopAt"` // 停止的时间戳,秒 |
| 29 | + Anomaly int `json:"anomaly"` //异常反馈的次数 | ||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | type TaskLeader struct { | 32 | type TaskLeader struct { |
| @@ -49,6 +50,19 @@ func (t *Task) ApplyLevelName(name string) { | @@ -49,6 +50,19 @@ func (t *Task) ApplyLevelName(name string) { | ||
| 49 | } | 50 | } |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 53 | +// StatusDescript | ||
| 54 | +func (t *Task) StatusDescript() string { | ||
| 55 | + switch t.Status { | ||
| 56 | + case TaskWait: | ||
| 57 | + return "待启动" | ||
| 58 | + case TaskRunning: | ||
| 59 | + return "启动中" | ||
| 60 | + case TaskStop: | ||
| 61 | + return "停止" | ||
| 62 | + } | ||
| 63 | + return "" | ||
| 64 | +} | ||
| 65 | + | ||
| 52 | type TaskRepository interface { | 66 | type TaskRepository interface { |
| 53 | Save(param *Task) error | 67 | Save(param *Task) error |
| 54 | Remove(id int) error | 68 | Remove(id int) error |
pkg/domain/task_record.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 任务反馈情况记录 | ||
| 6 | +type TaskRecord struct { | ||
| 7 | + Id int // id | ||
| 8 | + CreatedAt time.Time // | ||
| 9 | + UpdatedAt time.Time // | ||
| 10 | + StaffAssessId int // 每日评估的id | ||
| 11 | + TaskId int // 里程碑任务的id | ||
| 12 | + Name string // 任务名称 | ||
| 13 | + Alias string // 任务别名 | ||
| 14 | + TaskLeader TaskLeader // 里程碑完成情况填写人 | ||
| 15 | + Rating int // 上级辅导情况 | ||
| 16 | + RatingContent string // 上级辅导内容 | ||
| 17 | +} |
| @@ -6,8 +6,9 @@ type TaskStageState int | @@ -6,8 +6,9 @@ type TaskStageState int | ||
| 6 | 6 | ||
| 7 | const ( | 7 | const ( |
| 8 | TaskStageUncompleted TaskStageState = 1 //里程碑未完成 | 8 | TaskStageUncompleted TaskStageState = 1 //里程碑未完成 |
| 9 | - TaskStageCompleted TaskStageState = 2 //里程碑完成 | ||
| 10 | - TaskStageCompletedOverdue TaskStageState = 3 //里程碑预期完成 | 9 | + TaskStageCompletedOverdue TaskStageState = 2 //里程碑逾期完成 |
| 10 | + TaskStageCompleted TaskStageState = 3 //里程碑完成 | ||
| 11 | + | ||
| 11 | ) | 12 | ) |
| 12 | 13 | ||
| 13 | // 任务阶段 | 14 | // 任务阶段 |
| @@ -31,7 +32,7 @@ type TaskStageRepository interface { | @@ -31,7 +32,7 @@ type TaskStageRepository interface { | ||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | // 描述里程碑完成情况 | 34 | // 描述里程碑完成情况 |
| 34 | -func (t TaskStage) DescriptStatus() string { | 35 | +func (t TaskStage) StatusDescript() string { |
| 35 | nowDay := time.Now().Format("2006-01-02") | 36 | nowDay := time.Now().Format("2006-01-02") |
| 36 | nowTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) | 37 | nowTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) |
| 37 | 38 |
| @@ -8,10 +8,10 @@ import ( | @@ -8,10 +8,10 @@ import ( | ||
| 8 | 8 | ||
| 9 | func TestGenerateToken(t *testing.T) { | 9 | func TestGenerateToken(t *testing.T) { |
| 10 | ut := UserAuth{ | 10 | ut := UserAuth{ |
| 11 | - CompanyId: 1, | ||
| 12 | - UserId: 3245763368183552, | ||
| 13 | - Phone: "18650060951", | ||
| 14 | - PlatformId: 29, | 11 | + CompanyId: 233, |
| 12 | + UserId: 3240357405361920, | ||
| 13 | + Phone: "13459147023", | ||
| 14 | + PlatformId: 28, | ||
| 15 | AdminType: 1, | 15 | AdminType: 1, |
| 16 | } | 16 | } |
| 17 | tk, _ := ut.CreateAccessToken() | 17 | tk, _ := ut.CreateAccessToken() |
| @@ -54,6 +54,7 @@ func init() { | @@ -54,6 +54,7 @@ func init() { | ||
| 54 | &models.MessagePersonal{}, | 54 | &models.MessagePersonal{}, |
| 55 | &models.Task{}, | 55 | &models.Task{}, |
| 56 | &models.TaskStage{}, | 56 | &models.TaskStage{}, |
| 57 | + &models.TaskIgnore{}, | ||
| 57 | } | 58 | } |
| 58 | for _, model := range tables { | 59 | for _, model := range tables { |
| 59 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 60 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
| @@ -23,4 +23,5 @@ type Task struct { | @@ -23,4 +23,5 @@ type Task struct { | ||
| 23 | RelatedUser []int `pg:"related_user"` // | 23 | RelatedUser []int `pg:"related_user"` // |
| 24 | RunAt int64 `pg:"run_at"` // 启动的时间 | 24 | RunAt int64 `pg:"run_at"` // 启动的时间 |
| 25 | StopAt int64 `pg:"stop_at"` // 停止的时间 | 25 | StopAt int64 `pg:"stop_at"` // 停止的时间 |
| 26 | + Anomaly int `json:"anomaly"` // 异常反馈的数量 | ||
| 26 | } | 27 | } |
| @@ -5,7 +5,7 @@ import "time" | @@ -5,7 +5,7 @@ import "time" | ||
| 5 | // 不关注的任务列表 | 5 | // 不关注的任务列表 |
| 6 | type TaskIgnore struct { | 6 | type TaskIgnore struct { |
| 7 | tableName struct{} `comment:"不关注的任务列表" pg:"task_ignore"` | 7 | tableName struct{} `comment:"不关注的任务列表" pg:"task_ignore"` |
| 8 | - Id int `pg:"id"` | 8 | + Id int `pg:"id,pk"` |
| 9 | TaskId int `pg:"task_id"` | 9 | TaskId int `pg:"task_id"` |
| 10 | UserId int `pg:"user_id"` | 10 | UserId int `pg:"user_id"` |
| 11 | CreatedAt time.Time `pg:"created_at"` | 11 | CreatedAt time.Time `pg:"created_at"` |
| @@ -5,14 +5,14 @@ import "time" | @@ -5,14 +5,14 @@ import "time" | ||
| 5 | // 任务阶段 | 5 | // 任务阶段 |
| 6 | type TaskStage struct { | 6 | type TaskStage struct { |
| 7 | tableName struct{} `comment:"任务阶段" pg:"task_stage"` | 7 | tableName struct{} `comment:"任务阶段" pg:"task_stage"` |
| 8 | - Id int `pg:"id"` | 8 | + Id int `pg:"id,pk"` |
| 9 | TaskId int `pg:"task_id"` | 9 | TaskId int `pg:"task_id"` |
| 10 | CreatedAt time.Time `pg:"created_at"` | 10 | CreatedAt time.Time `pg:"created_at"` |
| 11 | UpdatedAt time.Time `pg:"updated_at"` | 11 | UpdatedAt time.Time `pg:"updated_at"` |
| 12 | DeletedAt *time.Time `pg:"deleted_at"` | 12 | DeletedAt *time.Time `pg:"deleted_at"` |
| 13 | - Name string `pg:"name"` //里程碑名称 | ||
| 14 | - SortBy int `pg:"sort_by"` //排序 | ||
| 15 | - Status int `pg:"status"` //里程碑完成情况 | ||
| 16 | - PlanCompletedAt int64 `pg:"plan_completed_at"` //计划完成时间 | ||
| 17 | - RealCompletedAt int64 `pg:"real_completed_at"` //时间完成时间 | 13 | + Name string `pg:"name"` //里程碑名称 |
| 14 | + SortBy int `pg:"sort_by"` //排序 | ||
| 15 | + Status int `pg:"status"` //里程碑完成情况 | ||
| 16 | + PlanCompletedAt int64 `pg:"plan_completed_at,use_zero"` //计划完成时间 | ||
| 17 | + RealCompletedAt int64 `pg:"real_completed_at,use_zero"` //时间完成时间 | ||
| 18 | } | 18 | } |
| 1 | package repository | 1 | package repository |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "errors" | ||
| 5 | + "fmt" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/go-pg/pg/v10" | ||
| 4 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 9 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 5 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
| 6 | ) | 12 | ) |
| 7 | 13 | ||
| 8 | //任务 | 14 | //任务 |
| @@ -13,18 +19,84 @@ type TaskIgnoreRepository struct { | @@ -13,18 +19,84 @@ type TaskIgnoreRepository struct { | ||
| 13 | 19 | ||
| 14 | var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil) | 20 | var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil) |
| 15 | 21 | ||
| 22 | +func NewTaskIgnoreRepository(transactionContext *pgTransaction.TransactionContext) *TaskIgnoreRepository { | ||
| 23 | + return &TaskIgnoreRepository{transactionContext: transactionContext} | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore { | ||
| 27 | + return &domain.TaskIgnore{ | ||
| 28 | + Id: d.Id, | ||
| 29 | + TaskId: d.TaskId, | ||
| 30 | + UserId: d.UserId, | ||
| 31 | + CreatedAt: d.CreatedAt, | ||
| 32 | + } | ||
| 33 | +} | ||
| 34 | + | ||
| 16 | func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error { | 35 | func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error { |
| 17 | - panic("not implemented") // TODO: Implement | 36 | + if param.Id == 0 { |
| 37 | + param.CreatedAt = time.Now() | ||
| 38 | + } | ||
| 39 | + m := models.TaskIgnore{ | ||
| 40 | + Id: param.Id, | ||
| 41 | + TaskId: param.TaskId, | ||
| 42 | + UserId: param.UserId, | ||
| 43 | + CreatedAt: param.CreatedAt, | ||
| 44 | + } | ||
| 45 | + db := repo.transactionContext.PgTx | ||
| 46 | + if m.Id == 0 { | ||
| 47 | + _, err := db.Model(&m).Insert() | ||
| 48 | + if err != nil { | ||
| 49 | + return err | ||
| 50 | + } | ||
| 51 | + } else { | ||
| 52 | + _, err := db.Model(&m).WherePK().Update() | ||
| 53 | + if err != nil { | ||
| 54 | + return err | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + param.Id = m.Id | ||
| 58 | + return nil | ||
| 18 | } | 59 | } |
| 19 | 60 | ||
| 20 | func (repo *TaskIgnoreRepository) Remove(id int) error { | 61 | func (repo *TaskIgnoreRepository) Remove(id int) error { |
| 21 | - panic("not implemented") // TODO: Implement | 62 | + tx := repo.transactionContext.PgTx |
| 63 | + _, err := tx.Model(&models.TaskIgnore{}). | ||
| 64 | + Where("id=?", id).Delete() | ||
| 65 | + return err | ||
| 22 | } | 66 | } |
| 23 | 67 | ||
| 24 | func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) { | 68 | func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) { |
| 25 | - panic("not implemented") // TODO: Implement | 69 | + tx := repo.transactionContext.PgTx |
| 70 | + m := new(models.TaskIgnore) | ||
| 71 | + query := tx.Model(m) | ||
| 72 | + query.Where("deleted_at isnull") | ||
| 73 | + if id, ok := queryOptions["id"]; ok { | ||
| 74 | + query.Where("id=?", id) | ||
| 75 | + } | ||
| 76 | + if err := query.First(); err != nil { | ||
| 77 | + if errors.Is(err, pg.ErrNoRows) { | ||
| 78 | + return nil, fmt.Errorf("没有找到 task_ignore 数据") | ||
| 79 | + } else { | ||
| 80 | + return nil, err | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + u := repo.TransformToDomain(m) | ||
| 84 | + return u, nil | ||
| 26 | } | 85 | } |
| 27 | 86 | ||
| 28 | func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) { | 87 | func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) { |
| 29 | - panic("not implemented") // TODO: Implement | 88 | + tx := repo.transactionContext.PgTx |
| 89 | + var m []*models.TaskIgnore | ||
| 90 | + query := tx.Model(&m) | ||
| 91 | + query.Order("id desc") | ||
| 92 | + count, err := query.SelectAndCount() | ||
| 93 | + if err != nil { | ||
| 94 | + return 0, nil, err | ||
| 95 | + } | ||
| 96 | + var datas []*domain.TaskIgnore | ||
| 97 | + for _, v := range m { | ||
| 98 | + d := repo.TransformToDomain(v) | ||
| 99 | + datas = append(datas, d) | ||
| 100 | + } | ||
| 101 | + return count, datas, nil | ||
| 30 | } | 102 | } |
| @@ -29,6 +29,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | @@ -29,6 +29,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | ||
| 29 | CreatedAt: d.CreatedAt, | 29 | CreatedAt: d.CreatedAt, |
| 30 | UpdatedAt: d.UpdatedAt, | 30 | UpdatedAt: d.UpdatedAt, |
| 31 | DeletedAt: d.DeletedAt, | 31 | DeletedAt: d.DeletedAt, |
| 32 | + CompanyId: d.CompanyId, | ||
| 32 | Name: d.Name, | 33 | Name: d.Name, |
| 33 | Alias: d.Alias, | 34 | Alias: d.Alias, |
| 34 | Leader: d.Leader, | 35 | Leader: d.Leader, |
| @@ -38,7 +39,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | @@ -38,7 +39,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { | ||
| 38 | RelatedUser: d.RelatedUser, | 39 | RelatedUser: d.RelatedUser, |
| 39 | RunAt: d.RunAt, | 40 | RunAt: d.RunAt, |
| 40 | StopAt: d.StopAt, | 41 | StopAt: d.StopAt, |
| 41 | - CompanyId: d.CompanyId, | 42 | + Anomaly: d.Anomaly, |
| 42 | } | 43 | } |
| 43 | } | 44 | } |
| 44 | 45 | ||
| @@ -46,7 +47,6 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | @@ -46,7 +47,6 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | ||
| 46 | param.UpdatedAt = time.Now() | 47 | param.UpdatedAt = time.Now() |
| 47 | if param.Id == 0 { | 48 | if param.Id == 0 { |
| 48 | param.CreatedAt = time.Now() | 49 | param.CreatedAt = time.Now() |
| 49 | - return nil | ||
| 50 | } | 50 | } |
| 51 | m := models.Task{ | 51 | m := models.Task{ |
| 52 | Id: param.Id, | 52 | Id: param.Id, |
| @@ -63,6 +63,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | @@ -63,6 +63,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | ||
| 63 | RunAt: param.RunAt, | 63 | RunAt: param.RunAt, |
| 64 | CompanyId: param.CompanyId, | 64 | CompanyId: param.CompanyId, |
| 65 | StopAt: param.StopAt, | 65 | StopAt: param.StopAt, |
| 66 | + Anomaly: param.Anomaly, | ||
| 66 | } | 67 | } |
| 67 | db := repo.transactionContext.PgTx | 68 | db := repo.transactionContext.PgTx |
| 68 | if m.Id == 0 { | 69 | if m.Id == 0 { |
| @@ -120,11 +121,11 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d | @@ -120,11 +121,11 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d | ||
| 120 | query.Where("task.name like ?", val) | 121 | query.Where("task.name like ?", val) |
| 121 | } | 122 | } |
| 122 | if val, ok := queryOptions["companyId"]; ok { | 123 | if val, ok := queryOptions["companyId"]; ok { |
| 123 | - query.Where("task.company_id like ?", val) | 124 | + query.Where("task.company_id = ?", val) |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | if val, ok := queryOptions["leaderId"]; ok { | 127 | if val, ok := queryOptions["leaderId"]; ok { |
| 127 | - query.Where("task.leader->>'userId'='?'", val) | 128 | + query.Where("task.leader->>'id'='?'", val) |
| 128 | } | 129 | } |
| 129 | if val, ok := queryOptions["aliasOrLeader"]; ok { | 130 | if val, ok := queryOptions["aliasOrLeader"]; ok { |
| 130 | query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val) | 131 | query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val) |
| @@ -26,7 +26,7 @@ func NewTaskStageRepository(transactionContext *pgTransaction.TransactionContext | @@ -26,7 +26,7 @@ func NewTaskStageRepository(transactionContext *pgTransaction.TransactionContext | ||
| 26 | func (repo *TaskStageRepository) TransformToDomain(d *models.TaskStage) *domain.TaskStage { | 26 | func (repo *TaskStageRepository) TransformToDomain(d *models.TaskStage) *domain.TaskStage { |
| 27 | return &domain.TaskStage{ | 27 | return &domain.TaskStage{ |
| 28 | Id: d.Id, | 28 | Id: d.Id, |
| 29 | - TaskId: 0, | 29 | + TaskId: d.TaskId, |
| 30 | CreatedAt: d.CreatedAt, | 30 | CreatedAt: d.CreatedAt, |
| 31 | UpdatedAt: d.UpdatedAt, | 31 | UpdatedAt: d.UpdatedAt, |
| 32 | DeletedAt: d.DeletedAt, | 32 | DeletedAt: d.DeletedAt, |
| @@ -39,11 +39,26 @@ func (c *TaskController) UpdateTask() { | @@ -39,11 +39,26 @@ func (c *TaskController) UpdateTask() { | ||
| 39 | c.Response(nil, e) | 39 | c.Response(nil, e) |
| 40 | return | 40 | return |
| 41 | } | 41 | } |
| 42 | - // userReq := middlewares.GetUser(c.Ctx) | 42 | + |
| 43 | data, err := srv.UpdateTask(paramReq) | 43 | data, err := srv.UpdateTask(paramReq) |
| 44 | c.Response(data, err) | 44 | c.Response(data, err) |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | +// 更新任务 | ||
| 48 | +func (c *TaskController) CreateTask() { | ||
| 49 | + srv := service.NewTaskService() | ||
| 50 | + paramReq := &command.CreateTaskCommand{} | ||
| 51 | + err := c.BindJSON(paramReq) | ||
| 52 | + if err != nil { | ||
| 53 | + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) | ||
| 54 | + c.Response(nil, e) | ||
| 55 | + return | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + err = srv.CreateTaskTest(paramReq) | ||
| 59 | + c.Response(nil, err) | ||
| 60 | +} | ||
| 61 | + | ||
| 47 | // 启动任务 | 62 | // 启动任务 |
| 48 | func (c *TaskController) RunTask() { | 63 | func (c *TaskController) RunTask() { |
| 49 | srv := service.NewTaskService() | 64 | srv := service.NewTaskService() |
| @@ -54,6 +69,8 @@ func (c *TaskController) RunTask() { | @@ -54,6 +69,8 @@ func (c *TaskController) RunTask() { | ||
| 54 | c.Response(nil, e) | 69 | c.Response(nil, e) |
| 55 | return | 70 | return |
| 56 | } | 71 | } |
| 72 | + userReq := middlewares.GetUser(c.Ctx) | ||
| 73 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
| 57 | data, err := srv.RunTask(paramReq) | 74 | data, err := srv.RunTask(paramReq) |
| 58 | c.Response(data, err) | 75 | c.Response(data, err) |
| 59 | } | 76 | } |
| @@ -68,6 +85,8 @@ func (c *TaskController) StopTask() { | @@ -68,6 +85,8 @@ func (c *TaskController) StopTask() { | ||
| 68 | c.Response(nil, e) | 85 | c.Response(nil, e) |
| 69 | return | 86 | return |
| 70 | } | 87 | } |
| 88 | + userReq := middlewares.GetUser(c.Ctx) | ||
| 89 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
| 71 | data, err := srv.StopTask(paramReq) | 90 | data, err := srv.StopTask(paramReq) |
| 72 | c.Response(data, err) | 91 | c.Response(data, err) |
| 73 | } | 92 | } |
| @@ -82,6 +101,24 @@ func (c *TaskController) ListTask() { | @@ -82,6 +101,24 @@ func (c *TaskController) ListTask() { | ||
| 82 | c.Response(nil, e) | 101 | c.Response(nil, e) |
| 83 | return | 102 | return |
| 84 | } | 103 | } |
| 104 | + userReq := middlewares.GetUser(c.Ctx) | ||
| 105 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
| 85 | data, err := srv.ListTask(paramReq) | 106 | data, err := srv.ListTask(paramReq) |
| 86 | c.Response(data, err) | 107 | c.Response(data, err) |
| 87 | } | 108 | } |
| 109 | + | ||
| 110 | +// CancelAttention 取消关注的任务 | ||
| 111 | +func (c *TaskController) CancelAttention() { | ||
| 112 | + srv := service.NewTaskService() | ||
| 113 | + paramReq := &command.CancelAttentionCommand{} | ||
| 114 | + err := c.BindJSON(paramReq) | ||
| 115 | + if err != nil { | ||
| 116 | + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) | ||
| 117 | + c.Response(nil, e) | ||
| 118 | + return | ||
| 119 | + } | ||
| 120 | + userReq := middlewares.GetUser(c.Ctx) | ||
| 121 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
| 122 | + err = srv.CancelAttention(paramReq) | ||
| 123 | + c.Response(nil, err) | ||
| 124 | +} |
| @@ -20,6 +20,14 @@ func init() { | @@ -20,6 +20,14 @@ func init() { | ||
| 20 | web.AddNamespace(taskAdminNS) | 20 | web.AddNamespace(taskAdminNS) |
| 21 | 21 | ||
| 22 | taskFontNS := web.NewNamespace("/v1/font/task", | 22 | taskFontNS := web.NewNamespace("/v1/font/task", |
| 23 | - web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken())) | 23 | + web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), |
| 24 | + web.NSCtrlPost("/attention/cancel", (*controllers.TaskController).CancelAttention), | ||
| 25 | + web.NSCtrlPost("/list", (*controllers.TaskController).ListTask), //TODO | ||
| 26 | + ) | ||
| 24 | web.AddNamespace(taskFontNS) | 27 | web.AddNamespace(taskFontNS) |
| 28 | + | ||
| 29 | + t := web.NewNamespace("/test/task", | ||
| 30 | + web.NSCtrlPost("/", (*controllers.TaskController).CreateTask), | ||
| 31 | + ) | ||
| 32 | + web.AddNamespace(t) | ||
| 25 | } | 33 | } |
-
请 注册 或 登录 后发表评论