作者 tangxvhui

添加接口

@@ -1114,3 +1114,162 @@ func (srv TaskService) MarkTaskAnomalyByTask(param *command.MarkTaskAnomalyComma @@ -1114,3 +1114,162 @@ func (srv TaskService) MarkTaskAnomalyByTask(param *command.MarkTaskAnomalyComma
1114 } 1114 }
1115 return result, nil 1115 return result, nil
1116 } 1116 }
  1117 +
  1118 +// 搜索和我有关的异常列表
  1119 +func (srv TaskService) ListTaskAnomaly4(param *command.ListTaskAnomalyCommand) (map[string]interface{}, error) {
  1120 + param.TaskName = strings.TrimSpace(param.TaskName)
  1121 + if len(param.TaskName) == 0 {
  1122 + return tool_funs.SimpleWrapGridMap(0, []adapter.TaskAnomalyItem{}), nil
  1123 + }
  1124 + transactionContext, err := factory.CreateTransactionContext(nil)
  1125 + if err != nil {
  1126 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1127 + }
  1128 + if err := transactionContext.StartTransaction(); err != nil {
  1129 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1130 + }
  1131 + defer func() {
  1132 + _ = transactionContext.RollbackTransaction()
  1133 + }()
  1134 + taskAnomalyDao := dao.NewTaskAnomalyDao(map[string]interface{}{
  1135 + "transactionContext": transactionContext,
  1136 + })
  1137 + anomalyList, err := taskAnomalyDao.SearchForUser(param.UserId, param.CompanyId, param.TaskName)
  1138 + if err != nil {
  1139 + return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1140 + }
  1141 +
  1142 + if err := transactionContext.CommitTransaction(); err != nil {
  1143 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1144 + }
  1145 +
  1146 + listData := []adapter.TaskAnomalyItem{}
  1147 + for _, val := range anomalyList {
  1148 + item := adapter.TaskAnomalyItem{
  1149 + Id: val.Id,
  1150 + TaskId: val.TaskId,
  1151 + TaskRecordId: val.TaskRecordId,
  1152 + Category: val.Category,
  1153 + Leader: val.LeaderName,
  1154 + CurrentStage: adapter.TaskStage{
  1155 + Id: val.CurrentStage.Id,
  1156 + Name: val.CurrentStage.Name,
  1157 + StatusDescription: val.CurrentStage.StatusDescription(),
  1158 + SortBy: val.CurrentStage.SortBy,
  1159 + PlanCompletedAt: time.Unix(val.CurrentStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
  1160 + RealCompletedAt: "",
  1161 + },
  1162 + LastStage: adapter.TaskStage{
  1163 + Id: val.LastStage.Id,
  1164 + Name: val.LastStage.Name,
  1165 + StatusDescription: val.LastStage.StatusDescription(),
  1166 + SortBy: val.LastStage.SortBy,
  1167 + PlanCompletedAt: time.Unix(val.LastStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
  1168 + RealCompletedAt: "",
  1169 + },
  1170 + AssessFlag: val.AssessFlag,
  1171 + WarnFlag: val.WarnFlag,
  1172 + AssistFlag: val.AssistFlag,
  1173 + TaskLevel: val.LevelName,
  1174 + TaskName: val.TaskName,
  1175 + TaskAlias: val.TaskAlias,
  1176 + TaskEndTime: int64(val.TaskEndTime),
  1177 + TaskSortBy: val.TaskSortBy,
  1178 + CreatedAt: val.CreatedAt.Local().Format("2006-01-02"),
  1179 + RecordBegin: val.RecordBegin,
  1180 + MarkA: "",
  1181 + MarkB: "",
  1182 + MarkC: "",
  1183 + MarkD: "",
  1184 + AnomalyDesc2: map[string]string{},
  1185 + }
  1186 + if len(val.Marks) > 0 {
  1187 + item.MarkA = val.Marks["a"]
  1188 + item.MarkB = val.Marks["b"]
  1189 + item.MarkC = val.Marks["c"]
  1190 + item.MarkD = val.Marks["d"]
  1191 + }
  1192 + if val.CurrentStage.RealCompletedAt > 0 {
  1193 + item.CurrentStage.RealCompletedAt = time.Unix(val.CurrentStage.RealCompletedAt, 0).Local().Format("2006-01-02")
  1194 + }
  1195 + if val.LastStage.RealCompletedAt > 0 {
  1196 + item.LastStage.RealCompletedAt = time.Unix(val.LastStage.RealCompletedAt, 0).Local().Format("2006-01-02")
  1197 + }
  1198 + noticeWho := []string{}
  1199 + for _, val2 := range val.NoticeWho {
  1200 + if name, ok := val2["name"]; ok {
  1201 + noticeWho = append(noticeWho, name)
  1202 + }
  1203 + }
  1204 + switch val.Category {
  1205 + case domain.AnomalyCategoryType1:
  1206 + {
  1207 + //里程碑异常
  1208 + if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 {
  1209 + //逾期未完成
  1210 + planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
  1211 + subDay := xtime.SubDayAbs(val.CreatedAt, planCompletedAt)
  1212 + item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay)
  1213 + item.AnomalyDesc2 = map[string]string{
  1214 + "types": "10",
  1215 + "stageName": val.TaskStageCheck.Name,
  1216 + "interval": strconv.Itoa(subDay),
  1217 + "noticeWho": strings.Join(noticeWho, ","),
  1218 + }
  1219 +
  1220 + } else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 {
  1221 + //逾期完成
  1222 + planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
  1223 + realCompletedAt := time.Unix(val.TaskStageCheck.RealCompletedAt, 0)
  1224 + subDay := xtime.SubDayAbs(realCompletedAt, planCompletedAt)
  1225 + item.AnomalyDesc = fmt.Sprintf("里程碑%s逾期%d天完成", val.TaskStageCheck.Name, subDay)
  1226 + item.AnomalyDesc2 = map[string]string{
  1227 + "types": "11",
  1228 + "stageName": val.TaskStageCheck.Name,
  1229 + "interval": strconv.Itoa(subDay),
  1230 + "noticeWho": strings.Join(noticeWho, ","),
  1231 + }
  1232 + }
  1233 + }
  1234 + case domain.AnomalyCategoryType2:
  1235 + //反馈异常
  1236 + {
  1237 + recordBegin := time.Unix(val.RecordBegin, 0)
  1238 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
  1239 + item.AnomalyDesc = fmt.Sprintf(
  1240 + "本任务自%s未正常反馈项目进度,已异常%d天",
  1241 + recordBegin.Local().Format("2006-01-02"),
  1242 + subDay,
  1243 + )
  1244 + item.AnomalyDesc2 = map[string]string{
  1245 + "types": "2",
  1246 + "dayTime": recordBegin.Local().Format("2006-01-02"),
  1247 + "interval": strconv.Itoa(subDay),
  1248 + "noticeWho": strings.Join(noticeWho, ","),
  1249 + }
  1250 + }
  1251 + case domain.AnomalyCategoryType3:
  1252 + //辅导异常
  1253 + {
  1254 + recordBegin := time.Unix(val.RecordBegin, 0)
  1255 + subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
  1256 + item.AnomalyDesc = fmt.Sprintf(
  1257 + "本任务计划于%s完成辅导,已逾期%d天",
  1258 + recordBegin.Local().Format("2006-01-02"),
  1259 + subDay,
  1260 + )
  1261 + item.AnomalyDesc2 = map[string]string{
  1262 + "types": "3",
  1263 + "dayTime": recordBegin.Local().Format("2006-01-02"),
  1264 + "interval": strconv.Itoa(subDay),
  1265 + "noticeWho": strings.Join(noticeWho, ","),
  1266 + }
  1267 + }
  1268 + }
  1269 +
  1270 + listData = append(listData, item)
  1271 + }
  1272 +
  1273 + result := tool_funs.SimpleWrapGridMap(int64(len(listData)), listData)
  1274 + return result, nil
  1275 +}
@@ -369,7 +369,76 @@ func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, categ @@ -369,7 +369,76 @@ func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, categ
369 369
370 } 370 }
371 371
372 -func (srv TaskAnomalyDao) Search(userId int, companyId int, taskName string) []ListTaskAnomaly {  
373 -  
374 - return nil 372 +func (d TaskAnomalyDao) SearchForUser(userId int, companyId int, taskName string) ([]ListTaskAnomaly, error) {
  373 + sqlStr1 := `with
  374 + -- 人员自身以及全下级
  375 + recursive t_user as (
  376 + (
  377 + select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level"
  378 + from "user"
  379 + where "user".id=? and "user".deleted_at isnull
  380 + )
  381 + union
  382 + (
  383 + select "child_user".id,"child_user".parent_id,"child_user".account,"child_user".name,
  384 + "parent_user"."level"+1 as "level"
  385 + from "user" as "child_user"
  386 + join t_user as "parent_user" on "parent_user".id="child_user".parent_id
  387 + where "child_user".deleted_at isnull
  388 + )
  389 + ),
  390 + t_task_ignore as (
  391 + select task_ignore.id ,task_ignore.task_id
  392 + from task_ignore
  393 + where user_id = ?
  394 + ),
  395 + t_task as (
  396 + select
  397 + task.id as "task_id",
  398 + task.alias as "task_alias",
  399 + task."name" as "task_name",
  400 + task.end_time as "task_end_time",
  401 + task.sort_by as "task_sort_by",
  402 + task.leader->>'name' as "leader_name",
  403 + task.leader->>'id' as "leader_id",
  404 + task.level_name
  405 + from task
  406 + left join t_task_ignore on task.id=t_task_ignore.task_id
  407 + where task.company_id=?
  408 + and t_task_ignore.id isnull
  409 + and task.deleted_at isnull
  410 + and (
  411 + (task.leader ->>'id' in (select t_user.id::text from t_user))
  412 + or task.related_user@> ?)
  413 + )
  414 + select
  415 + t_task.task_alias,t_task.task_name,t_task.task_end_time,
  416 + t_task.task_sort_by,t_task.leader_name,t_task.leader_id,
  417 + t_task.level_name,
  418 + task_anomaly.id,
  419 + task_anomaly.task_id,
  420 + task_anomaly.task_record_id,
  421 + task_anomaly.category,
  422 + task_anomaly.current_stage,
  423 + task_anomaly.last_stage,
  424 + task_anomaly.task_stage_check,
  425 + task_anomaly.assess_flag,
  426 + task_anomaly.warn_flag,
  427 + task_anomaly.assist_flag,
  428 + task_anomaly.record_begin,
  429 + task_anomaly.marks,
  430 + task_anomaly.notice_who,
  431 + task_anomaly.created_at
  432 + from t_task
  433 + join task_anomaly on t_task.task_id= task_anomaly.task_id
  434 + where t_task.task_alias like ?`
  435 + condition := []interface{}{userId, userId, companyId, fmt.Sprintf("[%d]", userId)}
  436 + condition = append(condition, "%"+taskName+"%")
  437 + result := []ListTaskAnomaly{}
  438 + tx := d.transactionContext.PgTx
  439 + _, err := tx.Query(&result, sqlStr1, condition...)
  440 + if err != nil {
  441 + return result, err
  442 + }
  443 + return result, nil
375 } 444 }
@@ -403,3 +403,19 @@ func (c *TaskController) TaskAnomalyMarkByTask() { @@ -403,3 +403,19 @@ func (c *TaskController) TaskAnomalyMarkByTask() {
403 c.Response(resp, err) 403 c.Response(resp, err)
404 404
405 } 405 }
  406 +
  407 +func (c *TaskController) SearchTaskAnomaly() {
  408 + srv := service.NewTaskService()
  409 + paramReq := &command.ListTaskAnomalyCommand{}
  410 + err := c.BindJSON(paramReq)
  411 + if err != nil {
  412 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  413 + c.Response(nil, e)
  414 + return
  415 + }
  416 + userReq := middlewares.GetUser(c.Ctx)
  417 + paramReq.CompanyId = int(userReq.CompanyId)
  418 + paramReq.UserId = int(userReq.UserId)
  419 + resp, err := srv.ListTaskAnomaly4(paramReq)
  420 + c.Response(resp, err)
  421 +}
@@ -45,6 +45,7 @@ func init() { @@ -45,6 +45,7 @@ func init() {
45 web.NSCtrlPost("/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表 45 web.NSCtrlPost("/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
46 web.NSCtrlPost("/mark", (*controllers.TaskController).TaskAnomalyMark), // 46 web.NSCtrlPost("/mark", (*controllers.TaskController).TaskAnomalyMark), //
47 web.NSCtrlPost("/info", (*controllers.TaskController).TaskAnomalyInfo), //异常记录详情 47 web.NSCtrlPost("/info", (*controllers.TaskController).TaskAnomalyInfo), //异常记录详情
  48 + web.NSCtrlPost("/search_1", (*controllers.TaskController).SearchTaskAnomaly), //搜索异常列表
48 ) 49 )
49 web.AddNamespace(taskAnomalyNS) 50 web.AddNamespace(taskAnomalyNS)
50 } 51 }