作者 tangxvhui

异常中心

@@ -8,5 +8,5 @@ type ListTaskAnomalyCommand struct { @@ -8,5 +8,5 @@ type ListTaskAnomalyCommand struct {
8 TaskName string `json:"taskName"` 8 TaskName string `json:"taskName"`
9 DayTime string `json:"dayTime"` //发生异常的日期 9 DayTime string `json:"dayTime"` //发生异常的日期
10 Category int `json:"category"` //异常分类 10 Category int `json:"category"` //异常分类
11 - leaderId string `json:"leaderId"` //任务负责人id 11 + LeaderId string `json:"leaderId"` //任务负责人id
12 } 12 }
@@ -42,7 +42,6 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) ( @@ -42,7 +42,6 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
42 } 42 }
43 43
44 listData := []adapter.TaskAnomalyItem{} 44 listData := []adapter.TaskAnomalyItem{}
45 - nowTime := time.Now()  
46 for _, val := range anomalyList { 45 for _, val := range anomalyList {
47 item := adapter.TaskAnomalyItem{ 46 item := adapter.TaskAnomalyItem{
48 Id: val.Id, 47 Id: val.Id,
@@ -99,7 +98,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) ( @@ -99,7 +98,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
99 if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 { 98 if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 {
100 //逾期未完成 99 //逾期未完成
101 planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0) 100 planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
102 - subDay := xtime.SubDayAbs(nowTime, planCompletedAt) 101 + subDay := xtime.SubDayAbs(val.CreatedAt, planCompletedAt)
103 item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay) 102 item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay)
104 } else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 { 103 } else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 {
105 //逾期完成 104 //逾期完成
@@ -113,7 +112,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) ( @@ -113,7 +112,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
113 //反馈异常 112 //反馈异常
114 { 113 {
115 recordBegin := time.Unix(val.RecordBegin, 0) 114 recordBegin := time.Unix(val.RecordBegin, 0)
116 - subDay := xtime.SubDayAbs(nowTime, recordBegin) 115 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
117 item.AnomalyDesc = fmt.Sprintf( 116 item.AnomalyDesc = fmt.Sprintf(
118 "本任务自%s未正常反馈项目进度,已异常%d天", 117 "本任务自%s未正常反馈项目进度,已异常%d天",
119 recordBegin.Local().Format("2006-01-02"), 118 recordBegin.Local().Format("2006-01-02"),
@@ -124,7 +123,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) ( @@ -124,7 +123,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
124 //辅导异常 123 //辅导异常
125 { 124 {
126 recordBegin := time.Unix(val.RecordBegin, 0) 125 recordBegin := time.Unix(val.RecordBegin, 0)
127 - subDay := xtime.SubDayAbs(nowTime, recordBegin) 126 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
128 item.AnomalyDesc = fmt.Sprintf( 127 item.AnomalyDesc = fmt.Sprintf(
129 "本任务计划于%s完成辅导,已逾期%d天", 128 "本任务计划于%s完成辅导,已逾期%d天",
130 recordBegin.Local().Format("2006-01-02"), 129 recordBegin.Local().Format("2006-01-02"),
@@ -141,13 +140,253 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) ( @@ -141,13 +140,253 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
141 } 140 }
142 141
143 // 我的下级负责任务,异常列表 142 // 我的下级负责任务,异常列表
144 -func (srv TaskService) ListTaskAnomaly2() error {  
145 - return nil 143 +func (srv TaskService) ListTaskAnomaly2(param *command.ListTaskAnomalyCommand) (map[string]interface{}, error) {
  144 + transactionContext, err := factory.CreateTransactionContext(nil)
  145 + if err != nil {
  146 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + if err := transactionContext.StartTransaction(); err != nil {
  149 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  150 + }
  151 + defer func() {
  152 + _ = transactionContext.RollbackTransaction()
  153 + }()
  154 + taskAnomalyDao := dao.NewTaskAnomalyDao(map[string]interface{}{
  155 + "transactionContext": transactionContext,
  156 + })
  157 + limit := 500
  158 + offset := 0
  159 + cnt, anomalyList, err := taskAnomalyDao.List2(param.UserId, param.CompanyId, param.TaskName, param.Category, param.DayTime, param.LeaderId, limit, offset)
  160 + if err != nil {
  161 + return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  162 + }
  163 +
  164 + if err := transactionContext.CommitTransaction(); err != nil {
  165 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  166 + }
  167 +
  168 + listData := []adapter.TaskAnomalyItem{}
  169 +
  170 + for _, val := range anomalyList {
  171 + item := adapter.TaskAnomalyItem{
  172 + Id: val.Id,
  173 + TaskId: val.TaskId,
  174 + TaskRecordId: val.TaskRecordId,
  175 + Category: val.Category,
  176 + Leader: val.LeaderName,
  177 + CurrentStage: adapter.TaskStage{
  178 + Id: val.CurrentStage.Id,
  179 + Name: val.CurrentStage.Name,
  180 + StatusDescription: val.CurrentStage.StatusDescription(),
  181 + SortBy: val.CurrentStage.SortBy,
  182 + PlanCompletedAt: time.Unix(val.CurrentStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
  183 + RealCompletedAt: "",
  184 + },
  185 + LastStage: adapter.TaskStage{
  186 + Id: val.LastStage.Id,
  187 + Name: val.LastStage.Name,
  188 + StatusDescription: val.LastStage.StatusDescription(),
  189 + SortBy: val.LastStage.SortBy,
  190 + PlanCompletedAt: time.Unix(val.LastStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
  191 + RealCompletedAt: "",
  192 + },
  193 + AssessFlag: val.AssessFlag,
  194 + WarnFlag: val.WarnFlag,
  195 + AssistFlag: val.AssistFlag,
  196 + TaskLevel: val.LevelName,
  197 + TaskName: val.TaskName,
  198 + TaskAlias: val.TaskAlias,
  199 + TaskEndTime: int64(val.TaskEndTime),
  200 + TaskSortBy: val.TaskSortBy,
  201 + RecordBegin: val.RecordBegin,
  202 + MarkA: "",
  203 + MarkB: "",
  204 + MarkC: "",
  205 + MarkD: "",
  206 + }
  207 + if len(val.Marks) > 0 {
  208 + item.MarkA = val.Marks["a"]
  209 + item.MarkB = val.Marks["b"]
  210 + item.MarkC = val.Marks["c"]
  211 + item.MarkD = val.Marks["d"]
  212 + }
  213 + if val.CurrentStage.RealCompletedAt > 0 {
  214 + item.CurrentStage.RealCompletedAt = time.Unix(val.CurrentStage.RealCompletedAt, 0).Local().Format("2006-01-02")
  215 + }
  216 + if val.LastStage.RealCompletedAt > 0 {
  217 + item.LastStage.RealCompletedAt = time.Unix(val.LastStage.RealCompletedAt, 0).Local().Format("2006-01-02")
  218 + }
  219 + switch val.Category {
  220 + case 1:
  221 + {
  222 + //里程碑异常
  223 + if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 {
  224 + //逾期未完成
  225 + planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
  226 + subDay := xtime.SubDayAbs(val.CreatedAt, planCompletedAt)
  227 + item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay)
  228 + } else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 {
  229 + //逾期完成
  230 + planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
  231 + realCompletedAt := time.Unix(val.TaskStageCheck.RealCompletedAt, 0)
  232 + subDay := xtime.SubDayAbs(realCompletedAt, planCompletedAt)
  233 + item.AnomalyDesc = fmt.Sprintf("里程碑%s逾期%d天完成", val.TaskStageCheck.Name, subDay)
  234 + }
  235 + }
  236 + case 2:
  237 + //反馈异常
  238 + {
  239 + recordBegin := time.Unix(val.RecordBegin, 0)
  240 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
  241 + item.AnomalyDesc = fmt.Sprintf(
  242 + "本任务自%s未正常反馈项目进度,已异常%d天",
  243 + recordBegin.Local().Format("2006-01-02"),
  244 + subDay,
  245 + )
  246 + }
  247 + case 3:
  248 + //辅导异常
  249 + {
  250 + recordBegin := time.Unix(val.RecordBegin, 0)
  251 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
  252 + item.AnomalyDesc = fmt.Sprintf(
  253 + "本任务计划于%s完成辅导,已逾期%d天",
  254 + recordBegin.Local().Format("2006-01-02"),
  255 + subDay,
  256 + )
  257 + }
  258 + }
  259 +
  260 + listData = append(listData, item)
  261 + }
  262 +
  263 + result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
  264 + return result, nil
146 } 265 }
147 266
148 // 与我有关的任务,异常列表 267 // 与我有关的任务,异常列表
149 -func (srv TaskService) ListTaskAnomaly3() error {  
150 - return nil 268 +func (srv TaskService) ListTaskAnomaly3(param *command.ListTaskAnomalyCommand) (map[string]interface{}, error) {
  269 + transactionContext, err := factory.CreateTransactionContext(nil)
  270 + if err != nil {
  271 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  272 + }
  273 + if err := transactionContext.StartTransaction(); err != nil {
  274 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  275 + }
  276 + defer func() {
  277 + _ = transactionContext.RollbackTransaction()
  278 + }()
  279 + taskAnomalyDao := dao.NewTaskAnomalyDao(map[string]interface{}{
  280 + "transactionContext": transactionContext,
  281 + })
  282 + limit := 500
  283 + offset := 0
  284 + cnt, anomalyList, err := taskAnomalyDao.List3(param.UserId, param.CompanyId, param.TaskName, param.Category, param.DayTime, param.LeaderId, limit, offset)
  285 + if err != nil {
  286 + return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  287 + }
  288 +
  289 + if err := transactionContext.CommitTransaction(); err != nil {
  290 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  291 + }
  292 +
  293 + listData := []adapter.TaskAnomalyItem{}
  294 +
  295 + for _, val := range anomalyList {
  296 + item := adapter.TaskAnomalyItem{
  297 + Id: val.Id,
  298 + TaskId: val.TaskId,
  299 + TaskRecordId: val.TaskRecordId,
  300 + Category: val.Category,
  301 + Leader: val.LeaderName,
  302 + CurrentStage: adapter.TaskStage{
  303 + Id: val.CurrentStage.Id,
  304 + Name: val.CurrentStage.Name,
  305 + StatusDescription: val.CurrentStage.StatusDescription(),
  306 + SortBy: val.CurrentStage.SortBy,
  307 + PlanCompletedAt: time.Unix(val.CurrentStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
  308 + RealCompletedAt: "",
  309 + },
  310 + LastStage: adapter.TaskStage{
  311 + Id: val.LastStage.Id,
  312 + Name: val.LastStage.Name,
  313 + StatusDescription: val.LastStage.StatusDescription(),
  314 + SortBy: val.LastStage.SortBy,
  315 + PlanCompletedAt: time.Unix(val.LastStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
  316 + RealCompletedAt: "",
  317 + },
  318 + AssessFlag: val.AssessFlag,
  319 + WarnFlag: val.WarnFlag,
  320 + AssistFlag: val.AssistFlag,
  321 + TaskLevel: val.LevelName,
  322 + TaskName: val.TaskName,
  323 + TaskAlias: val.TaskAlias,
  324 + TaskEndTime: int64(val.TaskEndTime),
  325 + TaskSortBy: val.TaskSortBy,
  326 + RecordBegin: val.RecordBegin,
  327 + MarkA: "",
  328 + MarkB: "",
  329 + MarkC: "",
  330 + MarkD: "",
  331 + }
  332 + if len(val.Marks) > 0 {
  333 + item.MarkA = val.Marks["a"]
  334 + item.MarkB = val.Marks["b"]
  335 + item.MarkC = val.Marks["c"]
  336 + item.MarkD = val.Marks["d"]
  337 + }
  338 + if val.CurrentStage.RealCompletedAt > 0 {
  339 + item.CurrentStage.RealCompletedAt = time.Unix(val.CurrentStage.RealCompletedAt, 0).Local().Format("2006-01-02")
  340 + }
  341 + if val.LastStage.RealCompletedAt > 0 {
  342 + item.LastStage.RealCompletedAt = time.Unix(val.LastStage.RealCompletedAt, 0).Local().Format("2006-01-02")
  343 + }
  344 + switch val.Category {
  345 + case 1:
  346 + {
  347 + //里程碑异常
  348 + if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 {
  349 + //逾期未完成
  350 + planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
  351 + subDay := xtime.SubDayAbs(val.CreatedAt, planCompletedAt)
  352 + item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay)
  353 + } else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 {
  354 + //逾期完成
  355 + planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
  356 + realCompletedAt := time.Unix(val.TaskStageCheck.RealCompletedAt, 0)
  357 + subDay := xtime.SubDayAbs(realCompletedAt, planCompletedAt)
  358 + item.AnomalyDesc = fmt.Sprintf("里程碑%s逾期%d天完成", val.TaskStageCheck.Name, subDay)
  359 + }
  360 + }
  361 + case 2:
  362 + //反馈异常
  363 + {
  364 + recordBegin := time.Unix(val.RecordBegin, 0)
  365 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
  366 + item.AnomalyDesc = fmt.Sprintf(
  367 + "本任务自%s未正常反馈项目进度,已异常%d天",
  368 + recordBegin.Local().Format("2006-01-02"),
  369 + subDay,
  370 + )
  371 + }
  372 + case 3:
  373 + //辅导异常
  374 + {
  375 + recordBegin := time.Unix(val.RecordBegin, 0)
  376 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
  377 + item.AnomalyDesc = fmt.Sprintf(
  378 + "本任务计划于%s完成辅导,已逾期%d天",
  379 + recordBegin.Local().Format("2006-01-02"),
  380 + subDay,
  381 + )
  382 + }
  383 + }
  384 +
  385 + listData = append(listData, item)
  386 + }
  387 +
  388 + result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
  389 + return result, nil
151 } 390 }
152 391
153 // 对异常记录的操作标记 392 // 对异常记录的操作标记
@@ -2,6 +2,7 @@ package dao @@ -2,6 +2,7 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -31,6 +32,7 @@ type ListTaskAnomaly struct { @@ -31,6 +32,7 @@ type ListTaskAnomaly struct {
31 CurrentStage domain.TaskStage `pg:"current_stage"` // 计划执行的里程碑 32 CurrentStage domain.TaskStage `pg:"current_stage"` // 计划执行的里程碑
32 LastStage domain.TaskStage `pg:"last_stage"` // 上一个完成的里程碑 33 LastStage domain.TaskStage `pg:"last_stage"` // 上一个完成的里程碑
33 TaskStageCheck domain.TaskStage `pg:"task_stage_check"` // 34 TaskStageCheck domain.TaskStage `pg:"task_stage_check"` //
  35 + CreatedAt time.Time `pg:"created_at"`
34 AssessFlag int `pg:"assess_flag"` 36 AssessFlag int `pg:"assess_flag"`
35 WarnFlag int `pg:"warn_flag"` 37 WarnFlag int `pg:"warn_flag"`
36 AssistFlag int `pg:"assist_flag"` 38 AssistFlag int `pg:"assist_flag"`
@@ -70,6 +72,7 @@ func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, categ @@ -70,6 +72,7 @@ func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, categ
70 task_anomaly.record_begin, 72 task_anomaly.record_begin,
71 task_anomaly.marks, 73 task_anomaly.marks,
72 task_anomaly.notice_who, 74 task_anomaly.notice_who,
  75 + task_anomaly.created_at,
73 task.alias as "task_alias", 76 task.alias as "task_alias",
74 task."name" as "task_name", 77 task."name" as "task_name",
75 task.end_time as "task_end_time", 78 task.end_time as "task_end_time",
@@ -131,9 +134,138 @@ func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, categ @@ -131,9 +134,138 @@ func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, categ
131 // dayTime 搜索条件日期 ,例:"2006-01-02" 134 // dayTime 搜索条件日期 ,例:"2006-01-02"
132 // pageSize 分页大小 135 // pageSize 分页大小
133 // pageNumber 分页页码 136 // pageNumber 分页页码
134 -func (d *TaskAnomalyDao) List2(userId int, companyId int, leaderId string, dayTime string, pageSize int, pageNumber int) error { 137 +func (d *TaskAnomalyDao) List2(userId int, companyId int, taskName string, category int, leaderId string, dayTime string, limit int, offset int) (int, []ListTaskAnomaly, error) {
  138 + sqlStr1 := `with
  139 + -- 人员自身以及全下级
  140 + recursive t_user as (
  141 + (
  142 + select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level"
  143 + from "user"
  144 + where "user".id=? and "user".deleted_at isnull
  145 + )
  146 + union
  147 + (
  148 + select "child_user".id,"child_user".parent_id,"child_user".account,"child_user".name,
  149 + "parent_user"."level"+1 as "level"
  150 + from "user" as "child_user"
  151 + join t_user as "parent_user" on "parent_user".id="child_user".parent_id
  152 + where "child_user".deleted_at isnull
  153 + )
  154 + ),
  155 + t_task_ignore as (
  156 + select task_ignore.id ,task_ignore.task_id
  157 + from task_ignore
  158 + where user_id = ?
  159 + ),
  160 + t_task as (
  161 + select
  162 + task.id as "task_id",
  163 + task.alias as "task_alias",
  164 + task."name" as "task_name",
  165 + task.end_time as "task_end_time",
  166 + task.sort_by as "task_sort_by",
  167 + task.leader->>'name' as "leader_name",
  168 + task.level_name
  169 + from task
  170 + left join t_task_ignore on task.id=t_task_ignore.task_id
  171 + where task.company_id=?
  172 + and t_task_ignore.id isnull
  173 + and task.deleted_at isnull
  174 + and task.leader ->>'id' in (
  175 + select t_user.id::text from t_user where t_user."level">0
  176 + )
  177 + )
  178 + select
  179 + t_task.task_alias,t_task.task_name,t_task.task_end_time,
  180 + t_task.task_sort_by,t_task.leader_name,t_task.level_name,
  181 + task_anomaly.id,
  182 + task_anomaly.task_id,
  183 + task_anomaly.task_record_id,
  184 + task_anomaly.category,
  185 + task_anomaly.current_stage,
  186 + task_anomaly.last_stage,
  187 + task_anomaly.task_stage_check,
  188 + task_anomaly.assess_flag,
  189 + task_anomaly.warn_flag,
  190 + task_anomaly.assist_flag,
  191 + task_anomaly.record_begin,
  192 + task_anomaly.marks,
  193 + task_anomaly.notice_who,
  194 + task_anomaly.created_at
  195 + from t_task
  196 + join task_anomaly on t_task.task_id= task_anomaly.task_id `
  197 +
  198 + sqlStr2 := `with
  199 + -- 人员自身以及全下级
  200 + recursive t_user as (
  201 + (
  202 + select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level"
  203 + from "user"
  204 + where "user".id=? and "user".deleted_at isnull
  205 + )
  206 + union
  207 + (
  208 + select "child_user".id,"child_user".parent_id,"child_user".account,"child_user".name,
  209 + "parent_user"."level"+1 as "level"
  210 + from "user" as "child_user"
  211 + join t_user as "parent_user" on "parent_user".id="child_user".parent_id
  212 + where "child_user".deleted_at isnull
  213 + )
  214 + ),
  215 + t_task_ignore as (
  216 + select task_ignore.id ,task_ignore.task_id
  217 + from task_ignore
  218 + where user_id = ?
  219 + ),
  220 + t_task as (
  221 + select
  222 + task.id as "task_id",
  223 + task.alias as "task_alias",
  224 + task."name" as "task_name",
  225 + task.end_time as "task_end_time",
  226 + task.sort_by as "task_sort_by",
  227 + task.leader->>'name' as "leader_name",
  228 + task.level_name
  229 + from task
  230 + left join t_task_ignore on task.id=t_task_ignore.task_id
  231 + where task.company_id=?
  232 + and t_task_ignore.id isnull
  233 + and task.deleted_at isnull
  234 + and task.leader ->>'id' in (
  235 + select t_user.id::text from t_user where t_user."level">0
  236 + )
  237 + )
  238 + select count(*) as cnt
  239 + from t_task
  240 + join task_anomaly on t_task.task_id= task_anomaly.task_id `
  241 + condition := []interface{}{userId, userId, companyId}
  242 + if len(dayTime) > 0 {
  243 + condition = append(condition, dayTime)
  244 + sqlStr2 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
  245 + sqlStr1 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
  246 + }
  247 + if len(taskName) > 0 {
  248 + condition = append(condition, "%"+taskName+"%")
  249 + sqlStr2 += ` and t_task.task_alias like ? `
  250 + sqlStr1 += ` and t_task.task_alias like ? `
  251 + }
  252 + if category > 0 {
  253 + condition = append(condition, category)
  254 + sqlStr1 += ` and task_anomaly.category=? `
  255 + sqlStr2 += ` and task_anomaly.category=? `
  256 + }
  257 + condition = append(condition, limit, offset)
  258 + sqlStr1 += ` order by task_anomaly.id desc limit ? offset ? `
135 259
136 - return nil 260 + result := []ListTaskAnomaly{}
  261 + tx := d.transactionContext.PgTx
  262 + _, err := tx.Query(&result, sqlStr1, condition...)
  263 + if err != nil {
  264 + return 0, result, err
  265 + }
  266 + var cnt int
  267 + _, err = tx.QueryOne(pg.Scan(&cnt), sqlStr2, condition...)
  268 + return cnt, result, err
137 } 269 }
138 270
139 // 异常的任务记录,我作为相关人的任务 271 // 异常的任务记录,我作为相关人的任务
@@ -161,6 +293,7 @@ func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, categ @@ -161,6 +293,7 @@ func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, categ
161 task_anomaly.record_begin, 293 task_anomaly.record_begin,
162 task_anomaly.marks, 294 task_anomaly.marks,
163 task_anomaly.notice_who, 295 task_anomaly.notice_who,
  296 + task_anomaly.created_at,
164 task.alias as "task_alias", 297 task.alias as "task_alias",
165 task."name" as "task_name", 298 task."name" as "task_name",
166 task.end_time as "task_end_time", 299 task.end_time as "task_end_time",
@@ -251,6 +251,7 @@ func (c *TaskController) CancelIgnore() { @@ -251,6 +251,7 @@ func (c *TaskController) CancelIgnore() {
251 251
252 } 252 }
253 253
  254 +// 我负责的任务,异常列表
254 func (c *TaskController) TaskAnomalyList1() { 255 func (c *TaskController) TaskAnomalyList1() {
255 srv := service.NewTaskService() 256 srv := service.NewTaskService()
256 paramReq := &command.ListTaskAnomalyCommand{} 257 paramReq := &command.ListTaskAnomalyCommand{}
@@ -266,3 +267,37 @@ func (c *TaskController) TaskAnomalyList1() { @@ -266,3 +267,37 @@ func (c *TaskController) TaskAnomalyList1() {
266 resp, err := srv.ListTaskAnomaly1(paramReq) 267 resp, err := srv.ListTaskAnomaly1(paramReq)
267 c.Response(resp, err) 268 c.Response(resp, err)
268 } 269 }
  270 +
  271 +// 我负责的任务,异常列表
  272 +func (c *TaskController) TaskAnomalyList3() {
  273 + srv := service.NewTaskService()
  274 + paramReq := &command.ListTaskAnomalyCommand{}
  275 + err := c.BindJSON(paramReq)
  276 + if err != nil {
  277 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  278 + c.Response(nil, e)
  279 + return
  280 + }
  281 + userReq := middlewares.GetUser(c.Ctx)
  282 + paramReq.CompanyId = int(userReq.CompanyId)
  283 + paramReq.UserId = int(userReq.UserId)
  284 + resp, err := srv.ListTaskAnomaly3(paramReq)
  285 + c.Response(resp, err)
  286 +}
  287 +
  288 +// 我的下级负责任务,异常列表
  289 +func (c *TaskController) TaskAnomalyList2() {
  290 + srv := service.NewTaskService()
  291 + paramReq := &command.ListTaskAnomalyCommand{}
  292 + err := c.BindJSON(paramReq)
  293 + if err != nil {
  294 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  295 + c.Response(nil, e)
  296 + return
  297 + }
  298 + userReq := middlewares.GetUser(c.Ctx)
  299 + paramReq.CompanyId = int(userReq.CompanyId)
  300 + paramReq.UserId = int(userReq.UserId)
  301 + resp, err := srv.ListTaskAnomaly2(paramReq)
  302 + c.Response(resp, err)
  303 +}
@@ -37,6 +37,8 @@ func init() { @@ -37,6 +37,8 @@ func init() {
37 taskAnomalyNS := web.NewNamespace("/v1/font", 37 taskAnomalyNS := web.NewNamespace("/v1/font",
38 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), 38 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
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),
  41 + web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2),
40 ) 42 )
41 web.AddNamespace(taskAnomalyNS) 43 web.AddNamespace(taskAnomalyNS)
42 } 44 }