作者 tangxvhui

日常保存

  1 +package adapter
  2 +
  3 +// 人员选择列表
  4 +type UserItem struct {
  5 + Id int64 `json:"id,string"`
  6 + Name string `json:"name"`
  7 + Level int `json:"level"`
  8 +}
  1 +package command
  2 +
  3 +type MarkTaskAnomalyCommand struct {
  4 + Id int `json:"id,string"`
  5 + CompanyId int `json:"-"`
  6 + MarkType string `json:"markType"`
  7 +}
  1 +package command
  2 +
  3 +type UserSelectCommand struct {
  4 + UserId int `json:"-"`
  5 + CompanyId int `json:"-"`
  6 + SubLevel int `json:"subLevel"`
  7 +}
@@ -392,7 +392,61 @@ func (srv TaskService) ListTaskAnomaly3(param *command.ListTaskAnomalyCommand) ( @@ -392,7 +392,61 @@ func (srv TaskService) ListTaskAnomaly3(param *command.ListTaskAnomalyCommand) (
392 return result, nil 392 return result, nil
393 } 393 }
394 394
  395 +func (srv TaskService) UserSelect(param *command.UserSelectCommand) []adapter.UserItem {
  396 + transactionContext, err := factory.CreateTransactionContext(nil)
  397 + if err != nil {
  398 + return nil
  399 + }
  400 + if err := transactionContext.StartTransaction(); err != nil {
  401 + return nil
  402 + }
  403 + defer func() {
  404 + _ = transactionContext.RollbackTransaction()
  405 + }()
  406 +
  407 + if param.SubLevel == 0 {
  408 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  409 + "transactionContext": transactionContext,
  410 + })
  411 + _, userList, err := userRepo.Find(map[string]interface{}{
  412 + "companyId": param.CompanyId,
  413 + })
  414 + selectList := []adapter.UserItem{}
  415 + if err != nil {
  416 + return selectList
  417 + }
  418 + for _, val := range userList {
  419 + selectList = append(selectList, adapter.UserItem{
  420 + Id: val.Id,
  421 + Name: val.Name,
  422 + })
  423 + }
  424 + return selectList
  425 + }
  426 +
  427 + userDao := dao.NewUserDao(map[string]interface{}{
  428 + "transactionContext": transactionContext,
  429 + })
  430 + userList, err := userDao.AllChildUser(param.UserId)
  431 + selectList := []adapter.UserItem{}
  432 + if err != nil {
  433 + return selectList
  434 + }
  435 + for _, val := range userList {
  436 + selectList = append(selectList, adapter.UserItem{
  437 + Id: int64(val.Id),
  438 + Name: val.Name,
  439 + Level: val.Level,
  440 + })
  441 + }
  442 + if err := transactionContext.CommitTransaction(); err != nil {
  443 + return selectList
  444 + }
  445 + return selectList
  446 +}
  447 +
395 // 对异常记录的操作标记 448 // 对异常记录的操作标记
396 -func (srv TaskService) MarkTaskAnomaly() error {  
397 - return nil 449 +func (srv TaskService) MarkTaskAnomaly(param *command.MarkTaskAnomalyCommand) (map[string]string, error) {
  450 +
  451 + return nil, nil
398 } 452 }
@@ -301,3 +301,37 @@ func (c *TaskController) TaskAnomalyList2() { @@ -301,3 +301,37 @@ func (c *TaskController) TaskAnomalyList2() {
301 resp, err := srv.ListTaskAnomaly2(paramReq) 301 resp, err := srv.ListTaskAnomaly2(paramReq)
302 c.Response(resp, err) 302 c.Response(resp, err)
303 } 303 }
  304 +
  305 +func (c *TaskController) UserSelect() {
  306 + srv := service.NewTaskService()
  307 + paramReq := &command.UserSelectCommand{}
  308 + err := c.BindJSON(paramReq)
  309 + if err != nil {
  310 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  311 + c.Response(nil, e)
  312 + return
  313 + }
  314 + userReq := middlewares.GetUser(c.Ctx)
  315 + paramReq.CompanyId = int(userReq.CompanyId)
  316 + paramReq.UserId = int(userReq.UserId)
  317 + resp := srv.UserSelect(paramReq)
  318 + c.Response(resp, nil)
  319 +
  320 +}
  321 +
  322 +// 点击操作
  323 +func (c *TaskController) TaskAnomalyMark() {
  324 + srv := service.NewTaskService()
  325 + paramReq := &command.MarkTaskAnomalyCommand{}
  326 + err := c.BindJSON(paramReq)
  327 + if err != nil {
  328 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  329 + c.Response(nil, e)
  330 + return
  331 + }
  332 + userReq := middlewares.GetUser(c.Ctx)
  333 + paramReq.CompanyId = int(userReq.CompanyId)
  334 + resp, err := srv.MarkTaskAnomaly(paramReq)
  335 + c.Response(resp, err)
  336 +
  337 +}
@@ -39,6 +39,8 @@ func init() { @@ -39,6 +39,8 @@ func init() {
39 web.NSCtrlPost("/task_anomaly/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务 39 web.NSCtrlPost("/task_anomaly/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务
40 web.NSCtrlPost("/task_anomaly/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务 40 web.NSCtrlPost("/task_anomaly/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务
41 web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务 41 web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务
  42 + web.NSCtrlPost("/task_anomaly/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
  43 + web.NSCtrlPost("/task_anomaly/marks", (*controllers.TaskController).TaskAnomalyMark),
42 ) 44 )
43 web.AddNamespace(taskAnomalyNS) 45 web.AddNamespace(taskAnomalyNS)
44 } 46 }