作者 tangxvhui

修改 异常记录操作边标记的记录方式

1 package adapter 1 package adapter
2 2
3 type AssessCycleDescResp struct { 3 type AssessCycleDescResp struct {
4 - CycleId int `json:"cycleId"` 4 + CycleId int `json:"cycleId,string"`
5 CycleName string `json:"cycleName"` //周期名称 5 CycleName string `json:"cycleName"` //周期名称
6 BeginDay string `json:"beginDay"` //开始的日期 6 BeginDay string `json:"beginDay"` //开始的日期
7 StepList []AssessTaskStep `json:"stepList"` //考评流程 7 StepList []AssessTaskStep `json:"stepList"` //考评流程
@@ -657,7 +657,7 @@ func (srv TaskService) MarkTaskAnomaly(param *command.MarkTaskAnomalyCommand) (m @@ -657,7 +657,7 @@ func (srv TaskService) MarkTaskAnomaly(param *command.MarkTaskAnomalyCommand) (m
657 } 657 }
658 if len(recordList) == 0 { 658 if len(recordList) == 0 {
659 result := map[string]interface{}{ 659 result := map[string]interface{}{
660 - "have": true, 660 + "have": false,
661 "cycleId": strconv.FormatInt(assessList[0].CycleId, 10), 661 "cycleId": strconv.FormatInt(assessList[0].CycleId, 10),
662 "beginDay": today, 662 "beginDay": today,
663 } 663 }
@@ -952,7 +952,7 @@ func (srv TaskService) TaskAnomalyInfo(param *command.GetTaskAnomalyCommand) (*a @@ -952,7 +952,7 @@ func (srv TaskService) TaskAnomalyInfo(param *command.GetTaskAnomalyCommand) (*a
952 952
953 // 任务列表中,对异常记录的操作标记 953 // 任务列表中,对异常记录的操作标记
954 // 按照任务id 实则操作标记 954 // 按照任务id 实则操作标记
955 -func (srv TaskService) MarkTaskAnomalyByTask(param command.MarkTaskAnomalyCommand) (map[string]interface{}, error) { 955 +func (srv TaskService) MarkTaskAnomalyByTask(param *command.MarkTaskAnomalyCommand) (map[string]interface{}, error) {
956 transactionContext, err := factory.CreateTransactionContext(nil) 956 transactionContext, err := factory.CreateTransactionContext(nil)
957 if err != nil { 957 if err != nil {
958 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 958 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -963,8 +963,88 @@ func (srv TaskService) MarkTaskAnomalyByTask(param command.MarkTaskAnomalyComman @@ -963,8 +963,88 @@ func (srv TaskService) MarkTaskAnomalyByTask(param command.MarkTaskAnomalyComman
963 defer func() { 963 defer func() {
964 _ = transactionContext.RollbackTransaction() 964 _ = transactionContext.RollbackTransaction()
965 }() 965 }()
  966 +
  967 + taskAnomalyRepo := factory.CreateTaskAnomalyRepository(map[string]interface{}{
  968 + "transactionContext": transactionContext,
  969 + })
  970 + taskRepo := factory.CreateTaskRepository(map[string]interface{}{
  971 + "transactionContext": transactionContext,
  972 + })
  973 + _, taskList, err := taskRepo.Find(map[string]interface{}{"id": param.Id, "limit": 1})
  974 + if err != nil {
  975 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  976 + }
  977 + if len(taskList) == 0 {
  978 + return map[string]interface{}{
  979 + "have": false,
  980 + }, nil
  981 + }
  982 + taskData := taskList[0]
  983 + _, anomalyList, err := taskAnomalyRepo.Find(map[string]interface{}{"isLast": 1, "companyId": param.CompanyId, "taskId": taskData.Id})
  984 + if err != nil {
  985 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  986 + }
  987 + if len(anomalyList) == 0 {
  988 + return map[string]interface{}{
  989 + "have": false,
  990 + }, nil
  991 + }
  992 + for _, val := range anomalyList {
  993 + switch param.MarkType {
  994 + case "a":
  995 + val.MarkA()
  996 + case "b":
  997 + val.MarkB()
  998 + case "c":
  999 + val.MarkC()
  1000 + case "d":
  1001 + val.MarkD()
  1002 + }
  1003 + err = taskAnomalyRepo.Save(val)
  1004 + if err != nil {
  1005 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1006 + }
  1007 + }
  1008 + // 检查今天是否有任务有没有对应的每日评估
  1009 + assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
  1010 + // 获取员工的评估
  1011 + today := time.Now().Format("2006-01-02")
  1012 + _, assessList, err := assessReps.Find(map[string]interface{}{
  1013 + "companyId": param.CompanyId,
  1014 + "executorId": taskData.Leader.Id,
  1015 + "beginDay": today,
  1016 + "typesList": []string{string(domain.AssessSelf)},
  1017 + "limit": 1,
  1018 + })
  1019 + if err != nil {
  1020 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
  1021 + }
  1022 + if len(assessList) == 0 {
  1023 + return map[string]interface{}{
  1024 + "have": false,
  1025 + }, nil
  1026 + }
  1027 + taskRecordReps := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext})
  1028 + _, recordList, err := taskRecordReps.Find(map[string]interface{}{"staffAssessId": assessList[0].Id, "taskId": taskData.Id})
  1029 + if err != nil {
  1030 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务的评估"+err.Error())
  1031 + }
  1032 + if len(recordList) == 0 {
  1033 + result := map[string]interface{}{
  1034 + "have": false,
  1035 + "cycleId": strconv.FormatInt(assessList[0].CycleId, 10),
  1036 + "beginDay": today,
  1037 + }
  1038 + return result, nil
  1039 + }
966 if err := transactionContext.CommitTransaction(); err != nil { 1040 if err := transactionContext.CommitTransaction(); err != nil {
967 return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1041 return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
968 } 1042 }
969 - return nil, nil 1043 + result := map[string]interface{}{
  1044 + "have": true,
  1045 + "cycleId": strconv.FormatInt(assessList[0].CycleId, 10),
  1046 + "beginDay": today,
  1047 + "taskRecordId": recordList[0].Id,
  1048 + }
  1049 + return result, nil
970 } 1050 }
  1 +package domain
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +// 对异常记录的操作标记
  8 +type TaskAnomalyMark struct {
  9 + Id int
  10 + CreatedAt time.Time `json:"createdAt"`
  11 + UpdatedAt time.Time `json:"updatedAt"`
  12 + CompanyId int `json:"companyId,string"` // 公司id
  13 + UserId int `json:"userId,string"` // 操作人id
  14 + TaskId int `json:"taskId,string"` // 任务id
  15 + TaskAnomalyId int `json:"taskAnomalyId,string"` // 异常记录id
  16 + Marks string `json:"marks"` // 已经操作的标记
  17 +
  18 +}
  19 +
  20 +// 已点击“去更新”
  21 +func (t *TaskAnomalyMark) MarkA() {
  22 + t.Marks = "已更新"
  23 +}
  24 +
  25 +// 已点击 "去反馈"
  26 +func (t *TaskAnomalyMark) MarkB() {
  27 + t.Marks = "已反馈"
  28 +}
  29 +
  30 +// 已点击 "找上级"
  31 +func (t *TaskAnomalyMark) MarkC() {
  32 + t.Marks = "已求助"
  33 +}
  34 +
  35 +// 已点击 "去辅导"
  36 +func (t *TaskAnomalyMark) MarkD() {
  37 + t.Marks = "已辅导"
  38 +}
  39 +
  40 +type TaskAnomalyMarkRepository interface {
  41 + Save(param *TaskAnomalyMark) error
  42 + FindOne(queryOptions map[string]interface{}) (*TaskAnomalyMark, error)
  43 + Find(queryOptions map[string]interface{}) (int, []*TaskAnomalyMark, error)
  44 +}
@@ -386,3 +386,20 @@ func (c *TaskController) TaskAnomalyInfo() { @@ -386,3 +386,20 @@ func (c *TaskController) TaskAnomalyInfo() {
386 resp, err := srv.TaskAnomalyInfo(paramReq) 386 resp, err := srv.TaskAnomalyInfo(paramReq)
387 c.Response(resp, err) 387 c.Response(resp, err)
388 } 388 }
  389 +
  390 +// 任务管理列表,对异常点击操作
  391 +func (c *TaskController) TaskAnomalyMarkByTask() {
  392 + srv := service.NewTaskService()
  393 + paramReq := &command.MarkTaskAnomalyCommand{}
  394 + err := c.BindJSON(paramReq)
  395 + if err != nil {
  396 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  397 + c.Response(nil, e)
  398 + return
  399 + }
  400 + userReq := middlewares.GetUser(c.Ctx)
  401 + paramReq.CompanyId = int(userReq.CompanyId)
  402 + resp, err := srv.MarkTaskAnomalyByTask(paramReq)
  403 + c.Response(resp, err)
  404 +
  405 +}
@@ -32,6 +32,7 @@ func init() { @@ -32,6 +32,7 @@ func init() {
32 web.NSCtrlPost("/info", (*controllers.TaskController).GetTaskInfo), 32 web.NSCtrlPost("/info", (*controllers.TaskController).GetTaskInfo),
33 web.NSCtrlPost("/ignore/list", (*controllers.TaskController).ListTaskIgnore), 33 web.NSCtrlPost("/ignore/list", (*controllers.TaskController).ListTaskIgnore),
34 web.NSCtrlPost("/ignore/cancel", (*controllers.TaskController).CancelIgnore), 34 web.NSCtrlPost("/ignore/cancel", (*controllers.TaskController).CancelIgnore),
  35 + web.NSCtrlPost("/mark_anomaly", (*controllers.TaskController).TaskAnomalyMarkByTask),
35 ) 36 )
36 web.AddNamespace(taskFontNS) 37 web.AddNamespace(taskFontNS)
37 taskAnomalyNS := web.NewNamespace("/v1/font/task_anomaly", 38 taskAnomalyNS := web.NewNamespace("/v1/font/task_anomaly",