作者 tangxvhui

更新

@@ -147,7 +147,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont @@ -147,7 +147,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
147 if err != nil { 147 if err != nil {
148 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) 148 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
149 } 149 }
150 - newTask.CurrentStage = *newTaskStage[0] 150 + //记录待执行的里程碑
  151 + newTask.SetCurrentStage(newTaskStage)
151 err = taskRepo.Save(&newTask) 152 err = taskRepo.Save(&newTask)
152 if err != nil { 153 if err != nil {
153 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务失败:"+err.Error()) 154 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务失败:"+err.Error())
@@ -291,12 +292,13 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] @@ -291,12 +292,13 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
291 if err != nil { 292 if err != nil {
292 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 293 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
293 } 294 }
294 - for _, val := range stageList {  
295 - if val.RealCompletedAt == 0 {  
296 - taskData.CurrentStage = *val  
297 - break  
298 - }  
299 - } 295 + // for _, val := range stageList {
  296 + // if val.RealCompletedAt == 0 {
  297 + // taskData.CurrentStage = *val
  298 + // break
  299 + // }
  300 + // }
  301 + taskData.SetCurrentStage(stageList)
300 err = taskRepo.Save(taskData) 302 err = taskRepo.Save(taskData)
301 if err != nil { 303 if err != nil {
302 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 304 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -920,7 +922,7 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction @@ -920,7 +922,7 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction
920 taskData.Anomaly = 0 922 taskData.Anomaly = 0
921 } 923 }
922 for _, val2 := range stageList { 924 for _, val2 := range stageList {
923 - if val2.Id == val.TaskStageCheck.Id { 925 + if val2.Id != val.TaskStageCheck.Id {
924 continue 926 continue
925 } 927 }
926 val2.RealCompletedAt = val.TaskStageCheck.RealCompletedAt 928 val2.RealCompletedAt = val.TaskStageCheck.RealCompletedAt
@@ -931,18 +933,11 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction @@ -931,18 +933,11 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction
931 } 933 }
932 break 934 break
933 } 935 }
934 - taskData.CurrentStage = domain.TaskStage{}  
935 - //设置下一个 待执行的里程碑  
936 - for _, val2 := range stageList {  
937 - if val2.RealCompletedAt == 0 {  
938 - taskData.CurrentStage = *val2  
939 - break  
940 - }  
941 - }  
942 err = taskStageRepo.Save(stageList) 936 err = taskStageRepo.Save(stageList)
943 if err != nil { 937 if err != nil {
944 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error()) 938 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
945 } 939 }
  940 + taskData.SetCurrentStage(stageList)
946 err = taskRepo.Save(taskData) 941 err = taskRepo.Save(taskData)
947 if err != nil { 942 if err != nil {
948 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error()) 943 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
@@ -1133,3 +1128,236 @@ func (srv TaskService) ConditionForListTask2(param *command.GetSelcetCommand) (m @@ -1133,3 +1128,236 @@ func (srv TaskService) ConditionForListTask2(param *command.GetSelcetCommand) (m
1133 } 1128 }
1134 return result, nil 1129 return result, nil
1135 } 1130 }
  1131 +
  1132 +// 员工绩效-任务管理-列表 (新)
  1133 +func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]interface{}, error) {
  1134 + transactionContext, err := factory.CreateTransactionContext(nil)
  1135 + if err != nil {
  1136 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1137 + }
  1138 + if err := transactionContext.StartTransaction(); err != nil {
  1139 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1140 + }
  1141 + defer func() {
  1142 + _ = transactionContext.RollbackTransaction()
  1143 + }()
  1144 + hrbpFlag, err := roleService.GetHrBp(transactionContext, int(param.CompanyId), int(param.UserId))
  1145 + if err != nil {
  1146 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息"+err.Error())
  1147 + }
  1148 + if len(param.SearchWord) > 0 {
  1149 + param.SearchWord = "%" + param.SearchWord + "%"
  1150 + }
  1151 + if hrbpFlag == domain.RoleTypeSystem {
  1152 + listData, err := srv.listTask3ForHrbp(param)
  1153 + return listData, err
  1154 + }
  1155 + var limit = 20
  1156 + var offset = 0
  1157 + if param.PageSize > 0 {
  1158 + limit = param.PageSize
  1159 + if param.PageNumber > 0 {
  1160 + offset = (param.PageNumber - 1) * param.PageSize
  1161 + }
  1162 + }
  1163 + condition := dao.ListTaskCondition{
  1164 + Limit: limit,
  1165 + Offset: offset,
  1166 + UserId: param.UserId,
  1167 + CompanyId: param.CompanyId,
  1168 + OnlyMy: param.OnlyMy,
  1169 + SearchWord: param.SearchWord,
  1170 + }
  1171 +
  1172 + taskDao := dao.NewTaskDao(map[string]interface{}{
  1173 + "transactionContext": transactionContext,
  1174 + })
  1175 + //任务列表数据
  1176 + taskListData, err := taskDao.ListTaskNotHrbpV2(condition)
  1177 + if err != nil {
  1178 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
  1179 + }
  1180 + //查到的任务数据总数
  1181 + taskCount, err := taskDao.CountTaskStageNotHrbp(condition)
  1182 + if err != nil {
  1183 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
  1184 + }
  1185 + //
  1186 + taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
  1187 + if err != nil {
  1188 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  1189 + }
  1190 + taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
  1191 + if err != nil {
  1192 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  1193 + }
  1194 +
  1195 + taskResult := []*adapter.TaskItem{}
  1196 + taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
  1197 + "transactionContext": transactionContext,
  1198 + })
  1199 + for _, val := range taskListData {
  1200 + tk := adapter.TaskItem{
  1201 + Id: val.TaskId,
  1202 + Name: "",
  1203 + Alias: val.Alias,
  1204 + Leader: val.LeaderName,
  1205 + Status: val.Status,
  1206 + Level: val.Level,
  1207 + LevelName: val.LevelName,
  1208 + UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
  1209 + Anomaly: val.Anomaly,
  1210 + WarnFlag: 0,
  1211 + }
  1212 + _, stageList, err := taskStageRepo.Find(map[string]interface{}{
  1213 + "taskId": val.TaskId,
  1214 + })
  1215 + if err != nil {
  1216 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务里程碑"+err.Error())
  1217 + }
  1218 +
  1219 + for _, val2 := range stageList {
  1220 + stage := adapter.TaskStage{
  1221 + Id: val2.Id,
  1222 + Name: val2.Name,
  1223 + SortBy: val2.SortBy,
  1224 + PlanCompletedAt: time.Unix(int64(val2.PlanCompletedAt), 0).Local().Format("2006-01-02"),
  1225 + RealCompletedAt: "",
  1226 + }
  1227 + if val2.RealCompletedAt > 0 {
  1228 + stage.RealCompletedAt = time.Unix(int64(val2.RealCompletedAt), 0).Local().Format("2006-01-02")
  1229 + }
  1230 + switch val2.SortBy {
  1231 + case 1:
  1232 + tk.StageA = stage
  1233 + case 2:
  1234 + tk.StageB = stage
  1235 + case 3:
  1236 + tk.StageC = stage
  1237 + case 4:
  1238 + tk.StageD = stage
  1239 + case 5:
  1240 + tk.StageE = stage
  1241 + }
  1242 + }
  1243 + taskResult = append(taskResult, &tk)
  1244 + }
  1245 + result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
  1246 + result["taskStageAnomaly"] = taskStageAnomalyCnt
  1247 + result["taskAnomalyCnt"] = taskAnomalyCnt
  1248 + if err := transactionContext.CommitTransaction(); err != nil {
  1249 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1250 + }
  1251 + return result, nil
  1252 +}
  1253 +
  1254 +// 员工绩效-任务管理-列表 (新)
  1255 +func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[string]interface{}, error) {
  1256 + transactionContext, err := factory.CreateTransactionContext(nil)
  1257 + if err != nil {
  1258 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1259 + }
  1260 + if err := transactionContext.StartTransaction(); err != nil {
  1261 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1262 + }
  1263 + defer func() {
  1264 + _ = transactionContext.RollbackTransaction()
  1265 + }()
  1266 + var limit = 20
  1267 + var offset = 0
  1268 + if param.PageSize > 0 {
  1269 + limit = param.PageSize
  1270 + if param.PageNumber > 0 {
  1271 + offset = (param.PageNumber - 1) * param.PageSize
  1272 + }
  1273 + }
  1274 + condition := dao.ListTaskCondition{
  1275 + Limit: limit,
  1276 + Offset: offset,
  1277 + UserId: param.UserId,
  1278 + CompanyId: param.CompanyId,
  1279 + OnlyMy: param.OnlyMy,
  1280 + SearchWord: param.SearchWord,
  1281 + }
  1282 +
  1283 + taskDao := dao.NewTaskDao(map[string]interface{}{
  1284 + "transactionContext": transactionContext,
  1285 + })
  1286 + //任务列表数据
  1287 + taskListData, err := taskDao.ListTaskByHrbpV2(condition)
  1288 + if err != nil {
  1289 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
  1290 + }
  1291 + //查到的任务数据总数
  1292 + taskCount, err := taskDao.CountTaskStageNotHrbp(condition)
  1293 + if err != nil {
  1294 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
  1295 + }
  1296 + //
  1297 + taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
  1298 + if err != nil {
  1299 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  1300 + }
  1301 + taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
  1302 + if err != nil {
  1303 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  1304 + }
  1305 +
  1306 + taskResult := []*adapter.TaskItem{}
  1307 + taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
  1308 + "transactionContext": transactionContext,
  1309 + })
  1310 + for _, val := range taskListData {
  1311 + tk := adapter.TaskItem{
  1312 + Id: val.TaskId,
  1313 + Name: "",
  1314 + Alias: val.Alias,
  1315 + Leader: val.LeaderName,
  1316 + Status: val.Status,
  1317 + Level: val.Level,
  1318 + LevelName: val.LevelName,
  1319 + UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
  1320 + Anomaly: val.Anomaly,
  1321 + WarnFlag: 0,
  1322 + }
  1323 + _, stageList, err := taskStageRepo.Find(map[string]interface{}{
  1324 + "taskId": val.TaskId,
  1325 + })
  1326 + if err != nil {
  1327 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务里程碑"+err.Error())
  1328 + }
  1329 +
  1330 + for _, val2 := range stageList {
  1331 + stage := adapter.TaskStage{
  1332 + Id: val2.Id,
  1333 + Name: val2.Name,
  1334 + SortBy: val2.SortBy,
  1335 + PlanCompletedAt: time.Unix(int64(val2.PlanCompletedAt), 0).Local().Format("2006-01-02"),
  1336 + RealCompletedAt: "",
  1337 + }
  1338 + if val2.RealCompletedAt > 0 {
  1339 + stage.RealCompletedAt = time.Unix(int64(val2.RealCompletedAt), 0).Local().Format("2006-01-02")
  1340 + }
  1341 + switch val2.SortBy {
  1342 + case 1:
  1343 + tk.StageA = stage
  1344 + case 2:
  1345 + tk.StageB = stage
  1346 + case 3:
  1347 + tk.StageC = stage
  1348 + case 4:
  1349 + tk.StageD = stage
  1350 + case 5:
  1351 + tk.StageE = stage
  1352 + }
  1353 + }
  1354 + taskResult = append(taskResult, &tk)
  1355 + }
  1356 + result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
  1357 + result["taskStageAnomaly"] = taskStageAnomalyCnt
  1358 + result["taskAnomalyCnt"] = taskAnomalyCnt
  1359 + if err := transactionContext.CommitTransaction(); err != nil {
  1360 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1361 + }
  1362 + return result, nil
  1363 +}
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "sort"
  5 + "time"
  6 +)
4 7
5 type TaskState int 8 type TaskState int
6 9
@@ -36,6 +39,7 @@ type Task struct { @@ -36,6 +39,7 @@ type Task struct {
36 Anomaly int `json:"anomaly"` // 异常反馈的次数 39 Anomaly int `json:"anomaly"` // 异常反馈的次数
37 WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记 40 WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
38 CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑 41 CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑
  42 + LastStage TaskStage `json:"lastStage"` // 上一个完成的里程碑
39 } 43 }
40 44
41 type TaskLeader struct { 45 type TaskLeader struct {
@@ -73,6 +77,21 @@ func (t *Task) StatusDescription() string { @@ -73,6 +77,21 @@ func (t *Task) StatusDescription() string {
73 return "" 77 return ""
74 } 78 }
75 79
  80 +// 记录待执行的里程碑,和上一个执行的里程碑
  81 +func (t *Task) SetCurrentStage(stageList []*TaskStage) {
  82 + sort.Slice(stageList, func(i, j int) bool {
  83 + return stageList[i].SortBy < stageList[j].SortBy
  84 + })
  85 + t.CurrentStage = TaskStage{}
  86 + for _, val := range stageList {
  87 + t.LastStage = t.CurrentStage
  88 + t.CurrentStage = *val
  89 + if val.RealCompletedAt == 0 {
  90 + break
  91 + }
  92 + }
  93 +}
  94 +
76 type TaskRepository interface { 95 type TaskRepository interface {
77 Save(param *Task) error 96 Save(param *Task) error
78 Remove(id int) error 97 Remove(id int) error
@@ -89,7 +89,7 @@ type ListTaskStage struct { @@ -89,7 +89,7 @@ type ListTaskStage struct {
89 RealCompletedAt int `pg:"real_completed_at"` 89 RealCompletedAt int `pg:"real_completed_at"`
90 } 90 }
91 91
92 -// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限 92 +// (弃用) 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
93 // userid 谁要查看任务数据 93 // userid 谁要查看任务数据
94 // limit 分页 94 // limit 分页
95 // offset 分页 95 // offset 分页
@@ -197,7 +197,7 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) { @@ -197,7 +197,7 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) {
197 return cnt, err 197 return cnt, err
198 } 198 }
199 199
200 -// 获取任务以及里程碑列表,用于页面展示; 无过滤查看权限 200 +// (弃用)获取任务以及里程碑列表,用于页面展示; 无过滤查看权限
201 // userid 谁要查看任务数据 201 // userid 谁要查看任务数据
202 // limit 分页 202 // limit 分页
203 // offset 分页 203 // offset 分页
@@ -292,7 +292,7 @@ func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) { @@ -292,7 +292,7 @@ func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) {
292 select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =? 292 select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
293 )select count(*) from task 293 )select count(*) from task
294 left join t_task_ignore on t_task_ignore.task_id=task.id 294 left join t_task_ignore on t_task_ignore.task_id=task.id
295 - where 1=1 and task.company_id=?` 295 + where 1=1 and t_task_ignore.id isnull and task.company_id=?`
296 condition := []interface{}{param.UserId, param.CompanyId} 296 condition := []interface{}{param.UserId, param.CompanyId}
297 whereSql := `` 297 whereSql := ``
298 if param.OnlyMy { 298 if param.OnlyMy {
@@ -606,3 +606,156 @@ func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) { @@ -606,3 +606,156 @@ func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
606 _, err := tx.Query(&result, sqlStr, companyId) 606 _, err := tx.Query(&result, sqlStr, companyId)
607 return result, err 607 return result, err
608 } 608 }
  609 +
  610 +type ListTask struct {
  611 + CPlanCompletedAt int `pg:"c_plan_completed_at"`
  612 + LastStageDiff int `pg:"last_stage_diff"`
  613 + TaskId int `pg:"task_id"`
  614 + Alias string `pg:"alias"`
  615 + LeaderName string `pg:"leader_name"`
  616 + Level int `pg:"level"`
  617 + LevelName string `pg:"level_name"`
  618 + Anomaly int `pg:"anomaly"`
  619 + Status int `pg:"status"`
  620 + UpdatedAt time.Time `pg:"updated_at"`
  621 + CreatedAt time.Time `pg:"created_at"`
  622 +}
  623 +
  624 +// (新)获取任务,用于页面展示; 无过滤查看权限
  625 +// userid 谁要查看任务数据
  626 +// limit 分页
  627 +// offset 分页
  628 +func (d *TaskDao) ListTaskByHrbpV2(param ListTaskCondition) ([]ListTask, error) {
  629 + sqlStr := `
  630 + with
  631 + t_task_ignore as (
  632 + select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
  633 + ),
  634 + t_task as (
  635 + select
  636 + cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) as c_plan_completed_at,
  637 + cast(COALESCE(task.last_stage ->>'plan_completed_at','0') as int) as l_plan_completed_at,
  638 + cast(COALESCE(task.last_stage ->>'real_completed_at','0') as int) as l_real_completed_at,
  639 + task.id ,
  640 + task.alias ,
  641 + task.leader ->>'name' as leader_name,
  642 + task."level",
  643 + task.level_name ,
  644 + task.anomaly ,
  645 + task.status ,
  646 + task.updated_at,
  647 + task.created_at
  648 + from task
  649 + left join t_task_ignore on t_task_ignore.task_id=task.id
  650 + where 1=1 and t_task_ignore.id isnull
  651 + %s
  652 + ),
  653 + t_task_1 as (
  654 + select
  655 + (case
  656 + when t_task.c_plan_completed_at=0 then 1
  657 + when t_task.c_plan_completed_at-now_time>0 then 0
  658 + else t_task.c_plan_completed_at-now_time
  659 + end) as sort_by_1,
  660 + t_task.c_plan_completed_at ,
  661 + t_task.l_plan_completed_at-t_task.l_real_completed_at as last_stage_diff,
  662 + t_task.id ,
  663 + t_task.alias ,
  664 + t_task.leader_name,
  665 + t_task."level",
  666 + t_task.level_name ,
  667 + t_task.anomaly ,
  668 + t_task.status ,
  669 + t_task.updated_at ,
  670 + t_task.created_at
  671 + from t_task
  672 + where 1=1
  673 + )select *
  674 + from t_task_1
  675 + order by t_task_1.sort_by_1,t_task_1.last_stage_diff,
  676 + t_task_1."level",t_task_1."created_at"
  677 + limit ? offset ?
  678 + `
  679 + condition := []interface{}{param.UserId, param.CompanyId}
  680 + whereSql := ``
  681 + if param.OnlyMy {
  682 + condition = append(condition, param.UserId)
  683 + whereSql += ` and task.leader ->>'id' = '?' `
  684 + }
  685 + if param.SearchWord != "" {
  686 + condition = append(condition, param.SearchWord, param.SearchWord)
  687 + whereSql += ` and (task.leader->>'name' like ? or task.alias like ?)`
  688 + }
  689 + strSql2 := fmt.Sprintf(sqlStr, whereSql)
  690 + condition = append(condition, param.Limit, param.Offset)
  691 + result := []ListTask{}
  692 + tx := d.transactionContext.PgTx
  693 + _, err := tx.Query(&result, strSql2, condition...)
  694 + return result, err
  695 +}
  696 +
  697 +func (d *TaskDao) ListTaskNotHrbpV2(param ListTaskCondition) ([]ListTask, error) {
  698 + withsql := d.catchTaskIdByPermission(param.UserId)
  699 + strSql := withsql + `
  700 + ,t_task as (
  701 + select
  702 + cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) as c_plan_completed_at,
  703 + cast(COALESCE(task.last_stage ->>'plan_completed_at','0') as int) as l_plan_completed_at,
  704 + cast(COALESCE(task.last_stage ->>'real_completed_at','0') as int) as l_real_completed_at,
  705 + task.id ,
  706 + task.alias ,
  707 + task.leader ->>'name' as leader_name,
  708 + task."level",
  709 + task.level_name ,
  710 + task.anomaly ,
  711 + task.status ,
  712 + task.updated_at,
  713 + task.created_at
  714 + from task
  715 + join t_task_1 on t_task_1.id=task.id
  716 + where 1=1
  717 + %s
  718 + ),
  719 + t_task_1 as (
  720 + select
  721 + (case
  722 + when t_task.c_plan_completed_at=0 then 1
  723 + when t_task.c_plan_completed_at-now_time>0 then 0
  724 + else t_task.c_plan_completed_at-now_time
  725 + end) as sort_by_1,
  726 + t_task.c_plan_completed_at ,
  727 + t_task.l_plan_completed_at-t_task.l_real_completed_at as last_stage_diff,
  728 + t_task.id ,
  729 + t_task.alias ,
  730 + t_task.leader_name,
  731 + t_task."level",
  732 + t_task.level_name ,
  733 + t_task.anomaly ,
  734 + t_task.status ,
  735 + t_task.updated_at ,
  736 + t_task.created_at
  737 + from t_task
  738 + where 1=1
  739 + )select *
  740 + from t_task_1
  741 + order by t_task_1.sort_by_1,t_task_1.last_stage_diff,
  742 + t_task_1."level",t_task_1."created_at"
  743 + limit ? offset ?
  744 + `
  745 + condition := []interface{}{param.CompanyId}
  746 + whereSql := ``
  747 + if param.OnlyMy {
  748 + condition = append(condition, param.UserId)
  749 + whereSql += ` and task.leader ->>'id' = '?' `
  750 + }
  751 + if param.SearchWord != "" {
  752 + condition = append(condition, param.SearchWord, param.SearchWord)
  753 + whereSql += ` and (task.leader->>'name' like ? or task.alias like ?)`
  754 + }
  755 + strSql2 := fmt.Sprintf(strSql, whereSql)
  756 + condition = append(condition, param.Limit, param.Offset)
  757 + result := []ListTask{}
  758 + tx := d.transactionContext.PgTx
  759 + _, err := tx.Query(&result, strSql2, condition...)
  760 + return result, err
  761 +}
@@ -26,4 +26,5 @@ type Task struct { @@ -26,4 +26,5 @@ type Task struct {
26 Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量 26 Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
27 WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记 27 WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
28 CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑 28 CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑
  29 + LastStage domain.TaskStage `pg:"lastStage"` // 上一个完成的里程碑
29 } 30 }
@@ -43,6 +43,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { @@ -43,6 +43,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
43 Anomaly: d.Anomaly, 43 Anomaly: d.Anomaly,
44 WarnFlag: domain.TaskWarnFlag(d.WarnFlag), 44 WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
45 CurrentStage: d.CurrentStage, 45 CurrentStage: d.CurrentStage,
  46 + LastStage: d.LastStage,
46 } 47 }
47 } 48 }
48 49
@@ -69,6 +70,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error { @@ -69,6 +70,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
69 Anomaly: param.Anomaly, 70 Anomaly: param.Anomaly,
70 WarnFlag: int(param.WarnFlag), 71 WarnFlag: int(param.WarnFlag),
71 CurrentStage: param.CurrentStage, 72 CurrentStage: param.CurrentStage,
  73 + LastStage: param.LastStage,
72 } 74 }
73 db := repo.transactionContext.PgTx 75 db := repo.transactionContext.PgTx
74 if m.Id == 0 { 76 if m.Id == 0 {