作者 tangxvhui

添加 异常详情接口

@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "sort"
5 "strconv" 6 "strconv"
6 "strings" 7 "strings"
7 "time" 8 "time"
@@ -732,7 +733,7 @@ func (srv TaskService) ListTreeTaskAnomaly3(param *command.ListTaskAnomalyComman @@ -732,7 +733,7 @@ func (srv TaskService) ListTreeTaskAnomaly3(param *command.ListTaskAnomalyComman
732 } 733 }
733 734
734 // 异常任务记录的详情 735 // 异常任务记录的详情
735 -func (srv TaskService) TaskAnomalyInfo(param command.GetTaskAnomalyCommand) (*adapter.TaskAnomalyInfo, error) { 736 +func (srv TaskService) TaskAnomalyInfo(param *command.GetTaskAnomalyCommand) (*adapter.TaskAnomalyInfo, error) {
736 transactionContext, err := factory.CreateTransactionContext(nil) 737 transactionContext, err := factory.CreateTransactionContext(nil)
737 if err != nil { 738 if err != nil {
738 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 739 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -823,14 +824,97 @@ func (srv TaskService) TaskAnomalyInfo(param command.GetTaskAnomalyCommand) (*ad @@ -823,14 +824,97 @@ func (srv TaskService) TaskAnomalyInfo(param command.GetTaskAnomalyCommand) (*ad
823 TaskSortBy: int(taskData.SortBy), 824 TaskSortBy: int(taskData.SortBy),
824 RecordBegin: anomalyData.RecordBegin, 825 RecordBegin: anomalyData.RecordBegin,
825 CreatedAt: anomalyData.CreatedAt.Local().Format("066-017"), 826 CreatedAt: anomalyData.CreatedAt.Local().Format("066-017"),
826 - MarkA: "",  
827 - MarkB: "",  
828 - MarkC: "",  
829 - MarkD: "", 827 + MarkA: anomalyData.Marks["a"],
  828 + MarkB: anomalyData.Marks["b"],
  829 + MarkC: anomalyData.Marks["c"],
  830 + MarkD: anomalyData.Marks["d"],
830 AnomalyDesc: "", 831 AnomalyDesc: "",
831 AnomalyDesc2: map[string]string{ 832 AnomalyDesc2: map[string]string{
832 "": "", 833 "": "",
833 }, 834 },
834 } 835 }
  836 + noticeWho := []string{}
  837 + for _, val2 := range anomalyData.NoticeWho {
  838 + if name, ok := val2["name"]; ok {
  839 + noticeWho = append(noticeWho, name)
  840 + }
  841 + }
  842 + switch anomalyData.Category {
  843 + case domain.AnomalyCategoryType1:
  844 + {
  845 + //里程碑异常
  846 + if anomalyData.TaskStageCheck.RealCompletedAt == 0 && anomalyData.TaskStageCheck.Id > 0 {
  847 + //逾期未完成
  848 + planCompletedAt := time.Unix(anomalyData.TaskStageCheck.PlanCompletedAt, 0)
  849 + subDay := xtime.SubDayAbs(anomalyData.CreatedAt, planCompletedAt)
  850 + result.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", anomalyData.TaskStageCheck.Name, subDay)
  851 + result.AnomalyDesc2 = map[string]string{
  852 + "types": "10",
  853 + "stageName": anomalyData.TaskStageCheck.Name,
  854 + "interval": strconv.Itoa(subDay),
  855 + "noticeWho": strings.Join(noticeWho, ","),
  856 + }
  857 +
  858 + } else if anomalyData.TaskStageCheck.RealCompletedAt > 0 && anomalyData.TaskStageCheck.Id > 0 {
  859 + //逾期完成
  860 + planCompletedAt := time.Unix(anomalyData.TaskStageCheck.PlanCompletedAt, 0)
  861 + realCompletedAt := time.Unix(anomalyData.TaskStageCheck.RealCompletedAt, 0)
  862 + subDay := xtime.SubDayAbs(realCompletedAt, planCompletedAt)
  863 + result.AnomalyDesc = fmt.Sprintf("里程碑%s逾期%d天完成", anomalyData.TaskStageCheck.Name, subDay)
  864 + result.AnomalyDesc2 = map[string]string{
  865 + "types": "11",
  866 + "stageName": anomalyData.TaskStageCheck.Name,
  867 + "interval": strconv.Itoa(subDay),
  868 + "noticeWho": strings.Join(noticeWho, ","),
  869 + }
  870 + }
  871 + }
  872 + case domain.AnomalyCategoryType2:
  873 + //反馈异常
  874 + {
  875 + recordBegin := time.Unix(anomalyData.RecordBegin, 0)
  876 + subDay := xtime.SubDayAbs(anomalyData.CreatedAt, recordBegin)
  877 + result.AnomalyDesc = fmt.Sprintf(
  878 + "本任务自%s未正常反馈项目进度,已异常%d天",
  879 + recordBegin.Local().Format("2006-01-02"),
  880 + subDay,
  881 + )
  882 + result.AnomalyDesc2 = map[string]string{
  883 + "types": "2",
  884 + "dayTime": recordBegin.Local().Format("2006-01-02"),
  885 + "interval": strconv.Itoa(subDay),
  886 + "noticeWho": strings.Join(noticeWho, ","),
  887 + }
  888 + }
  889 + case domain.AnomalyCategoryType3:
  890 + //辅导异常
  891 + {
  892 + recordBegin := time.Unix(anomalyData.RecordBegin, 0)
  893 + subDay := xtime.SubDayAbs(anomalyData.CreatedAt, recordBegin)
  894 + result.AnomalyDesc = fmt.Sprintf(
  895 + "本任务计划于%s完成辅导,已逾期%d天",
  896 + recordBegin.Local().Format("2006-01-02"),
  897 + subDay,
  898 + )
  899 + result.AnomalyDesc2 = map[string]string{
  900 + "types": "3",
  901 + "dayTime": recordBegin.Local().Format("2006-01-02"),
  902 + "interval": strconv.Itoa(subDay),
  903 + "noticeWho": strings.Join(noticeWho, ","),
  904 + }
  905 + }
  906 + }
  907 + sort.Slice(stageList, func(i, j int) bool {
  908 + return stageList[i].SortBy < stageList[j].SortBy
  909 + })
  910 + for _, val := range stageList {
  911 + result.ListStage = append(result.ListStage, adapter.TaskStage{
  912 + Id: val.Id,
  913 + Name: val.Name,
  914 + StatusDescription: val.StatusDescription(),
  915 + SortBy: val.SortBy,
  916 + PlanCompletedAt: time.Unix(val.PlanCompletedAt, 0).Format("2006-01-02"),
  917 + })
  918 + }
835 return result, nil 919 return result, nil
836 } 920 }
@@ -370,3 +370,19 @@ func (c *TaskController) TaskAnomalyList3Tree() { @@ -370,3 +370,19 @@ func (c *TaskController) TaskAnomalyList3Tree() {
370 resp, err := srv.ListTreeTaskAnomaly2(paramReq) 370 resp, err := srv.ListTreeTaskAnomaly2(paramReq)
371 c.Response(resp, err) 371 c.Response(resp, err)
372 } 372 }
  373 +
  374 +// TaskAnomalyInfo 任务异常记录详情
  375 +func (c *TaskController) TaskAnomalyInfo() {
  376 + srv := service.NewTaskService()
  377 + paramReq := &command.GetTaskAnomalyCommand{}
  378 + err := c.BindJSON(paramReq)
  379 + if err != nil {
  380 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  381 + c.Response(nil, e)
  382 + return
  383 + }
  384 + userReq := middlewares.GetUser(c.Ctx)
  385 + paramReq.CompanyId = int(userReq.CompanyId)
  386 + resp, err := srv.TaskAnomalyInfo(paramReq)
  387 + c.Response(resp, err)
  388 +}
@@ -34,15 +34,16 @@ func init() { @@ -34,15 +34,16 @@ func init() {
34 web.NSCtrlPost("/ignore/cancel", (*controllers.TaskController).CancelIgnore), 34 web.NSCtrlPost("/ignore/cancel", (*controllers.TaskController).CancelIgnore),
35 ) 35 )
36 web.AddNamespace(taskFontNS) 36 web.AddNamespace(taskFontNS)
37 - taskAnomalyNS := web.NewNamespace("/v1/font", 37 + taskAnomalyNS := web.NewNamespace("/v1/font/task_anomaly",
38 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), 38 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
39 - web.NSCtrlPost("/task_anomaly/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务  
40 - web.NSCtrlPost("/task_anomaly/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务  
41 - web.NSCtrlPost("/task_anomaly/my_relation_1", (*controllers.TaskController).TaskAnomalyList3Tree), //和我有关的任务  
42 - web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务  
43 - web.NSCtrlPost("/task_anomaly/my_sub_1", (*controllers.TaskController).TaskAnomalyList2Tree), //我的下级负责的任务  
44 - web.NSCtrlPost("/task_anomaly/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表  
45 - web.NSCtrlPost("/task_anomaly/marks", (*controllers.TaskController).TaskAnomalyMark), 39 + web.NSCtrlPost("/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务
  40 + web.NSCtrlPost("/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务
  41 + web.NSCtrlPost("/my_relation_1", (*controllers.TaskController).TaskAnomalyList3Tree), //和我有关的任务
  42 + web.NSCtrlPost("/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务
  43 + web.NSCtrlPost("/my_sub_1", (*controllers.TaskController).TaskAnomalyList2Tree), //我的下级负责的任务
  44 + web.NSCtrlPost("/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
  45 + web.NSCtrlPost("/marks", (*controllers.TaskController).TaskAnomalyMark), //
  46 + web.NSCtrlPost("/info", (*controllers.TaskController).TaskAnomalyInfo), //异常记录详情
46 ) 47 )
47 web.AddNamespace(taskAnomalyNS) 48 web.AddNamespace(taskAnomalyNS)
48 } 49 }