作者 tangxvhui

新建任务优先级

  1 +package command
  2 +
  3 +type CreateTaskLevelCommand struct {
  4 + LevelName string `json:"levelName"`
  5 + CompanyId int `json:"-"`
  6 +}
@@ -354,19 +354,15 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] @@ -354,19 +354,15 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
354 if err := transactionContext.CommitTransaction(); err != nil { 354 if err := transactionContext.CommitTransaction(); err != nil {
355 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 355 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
356 } 356 }
357 - err = srv.SaveTaskLevel(param.LevelName, param.CompanyId)  
358 - if err != nil {  
359 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务等级"+err.Error())  
360 - }  
361 return map[string]interface{}{ 357 return map[string]interface{}{
362 "id": param.Id, 358 "id": param.Id,
363 }, nil 359 }, nil
364 } 360 }
365 361
366 -func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error { 362 +func (srv TaskService) SaveTaskLevel(param *command.CreateTaskLevelCommand) error {
367 defalutLevel := domain.DefaultTaskLevel() 363 defalutLevel := domain.DefaultTaskLevel()
368 for _, val := range defalutLevel { 364 for _, val := range defalutLevel {
369 - if val.LevelName == levelName { 365 + if val.LevelName == param.LevelName {
370 return nil 366 return nil
371 } 367 }
372 } 368 }
@@ -384,8 +380,8 @@ func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error { @@ -384,8 +380,8 @@ func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error {
384 "transactionContext": transactionContext, 380 "transactionContext": transactionContext,
385 }) 381 })
386 cnt, _, err := taskLevelRepo.Find(map[string]interface{}{ 382 cnt, _, err := taskLevelRepo.Find(map[string]interface{}{
387 - "companyId": companyId,  
388 - "levelName": levelName, 383 + "companyId": param.CompanyId,
  384 + "levelName": param.LevelName,
389 "limit": 1, 385 "limit": 1,
390 }) 386 })
391 if err != nil { 387 if err != nil {
@@ -396,8 +392,8 @@ func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error { @@ -396,8 +392,8 @@ func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error {
396 } 392 }
397 newTaskLevel := domain.TaskLevel{ 393 newTaskLevel := domain.TaskLevel{
398 Id: 0, 394 Id: 0,
399 - LevelName: levelName,  
400 - CompanyId: companyId, 395 + LevelName: param.LevelName,
  396 + CompanyId: param.CompanyId,
401 } 397 }
402 err = taskLevelRepo.Save(&newTaskLevel) 398 err = taskLevelRepo.Save(&newTaskLevel)
403 if err != nil { 399 if err != nil {
@@ -191,6 +191,7 @@ func (c *TaskController) SelectCondition() { @@ -191,6 +191,7 @@ func (c *TaskController) SelectCondition() {
191 c.Response(data, err) 191 c.Response(data, err)
192 } 192 }
193 193
  194 +// 优先级
194 func (c *TaskController) LevelList() { 195 func (c *TaskController) LevelList() {
195 srv := service.NewTaskService() 196 srv := service.NewTaskService()
196 userReq := middlewares.GetUser(c.Ctx) 197 userReq := middlewares.GetUser(c.Ctx)
@@ -198,3 +199,19 @@ func (c *TaskController) LevelList() { @@ -198,3 +199,19 @@ func (c *TaskController) LevelList() {
198 data, err := srv.ListTaskLevel(companyId) 199 data, err := srv.ListTaskLevel(companyId)
199 c.Response(data, err) 200 c.Response(data, err)
200 } 201 }
  202 +
  203 +// 新建任务优先级
  204 +func (c *TaskController) SaveTaskLevel() {
  205 + srv := service.NewTaskService()
  206 + paramReq := &command.CreateTaskLevelCommand{}
  207 + err := c.BindJSON(paramReq)
  208 + if err != nil {
  209 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  210 + c.Response(nil, e)
  211 + return
  212 + }
  213 + userReq := middlewares.GetUser(c.Ctx)
  214 + paramReq.CompanyId = int(userReq.CompanyId)
  215 + err = srv.SaveTaskLevel(paramReq)
  216 + c.Response(nil, err)
  217 +}
@@ -18,6 +18,7 @@ func init() { @@ -18,6 +18,7 @@ func init() {
18 web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask), 18 web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask),
19 web.NSCtrlPost("/list", (*controllers.TaskController).ListTask), 19 web.NSCtrlPost("/list", (*controllers.TaskController).ListTask),
20 web.NSCtrlGet("/level/list", (*controllers.TaskController).LevelList), 20 web.NSCtrlGet("/level/list", (*controllers.TaskController).LevelList),
  21 + web.NSCtrlPost("/level", (*controllers.TaskController).SaveTaskLevel),
21 ) 22 )
22 web.AddNamespace(taskAdminNS) 23 web.AddNamespace(taskAdminNS)
23 // 员工绩效模块 24 // 员工绩效模块