作者 tangxvhui

更新

... ... @@ -147,7 +147,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
}
newTask.CurrentStage = *newTaskStage[0]
//记录待执行的里程碑
newTask.SetCurrentStage(newTaskStage)
err = taskRepo.Save(&newTask)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务失败:"+err.Error())
... ... @@ -291,12 +292,13 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range stageList {
if val.RealCompletedAt == 0 {
taskData.CurrentStage = *val
break
}
}
// for _, val := range stageList {
// if val.RealCompletedAt == 0 {
// taskData.CurrentStage = *val
// break
// }
// }
taskData.SetCurrentStage(stageList)
err = taskRepo.Save(taskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -920,7 +922,7 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction
taskData.Anomaly = 0
}
for _, val2 := range stageList {
if val2.Id == val.TaskStageCheck.Id {
if val2.Id != val.TaskStageCheck.Id {
continue
}
val2.RealCompletedAt = val.TaskStageCheck.RealCompletedAt
... ... @@ -931,18 +933,11 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction
}
break
}
taskData.CurrentStage = domain.TaskStage{}
//设置下一个 待执行的里程碑
for _, val2 := range stageList {
if val2.RealCompletedAt == 0 {
taskData.CurrentStage = *val2
break
}
}
err = taskStageRepo.Save(stageList)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
}
taskData.SetCurrentStage(stageList)
err = taskRepo.Save(taskData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
... ... @@ -1133,3 +1128,236 @@ func (srv TaskService) ConditionForListTask2(param *command.GetSelcetCommand) (m
}
return result, nil
}
// 员工绩效-任务管理-列表 (新)
func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
hrbpFlag, err := roleService.GetHrBp(transactionContext, int(param.CompanyId), int(param.UserId))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息"+err.Error())
}
if len(param.SearchWord) > 0 {
param.SearchWord = "%" + param.SearchWord + "%"
}
if hrbpFlag == domain.RoleTypeSystem {
listData, err := srv.listTask3ForHrbp(param)
return listData, err
}
var limit = 20
var offset = 0
if param.PageSize > 0 {
limit = param.PageSize
if param.PageNumber > 0 {
offset = (param.PageNumber - 1) * param.PageSize
}
}
condition := dao.ListTaskCondition{
Limit: limit,
Offset: offset,
UserId: param.UserId,
CompanyId: param.CompanyId,
OnlyMy: param.OnlyMy,
SearchWord: param.SearchWord,
}
taskDao := dao.NewTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
})
//任务列表数据
taskListData, err := taskDao.ListTaskNotHrbpV2(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
}
//查到的任务数据总数
taskCount, err := taskDao.CountTaskStageNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
}
//
taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
taskResult := []*adapter.TaskItem{}
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for _, val := range taskListData {
tk := adapter.TaskItem{
Id: val.TaskId,
Name: "",
Alias: val.Alias,
Leader: val.LeaderName,
Status: val.Status,
Level: val.Level,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
WarnFlag: 0,
}
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
"taskId": val.TaskId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务里程碑"+err.Error())
}
for _, val2 := range stageList {
stage := adapter.TaskStage{
Id: val2.Id,
Name: val2.Name,
SortBy: val2.SortBy,
PlanCompletedAt: time.Unix(int64(val2.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
}
if val2.RealCompletedAt > 0 {
stage.RealCompletedAt = time.Unix(int64(val2.RealCompletedAt), 0).Local().Format("2006-01-02")
}
switch val2.SortBy {
case 1:
tk.StageA = stage
case 2:
tk.StageB = stage
case 3:
tk.StageC = stage
case 4:
tk.StageD = stage
case 5:
tk.StageE = stage
}
}
taskResult = append(taskResult, &tk)
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
result["taskStageAnomaly"] = taskStageAnomalyCnt
result["taskAnomalyCnt"] = taskAnomalyCnt
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return result, nil
}
// 员工绩效-任务管理-列表 (新)
func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var limit = 20
var offset = 0
if param.PageSize > 0 {
limit = param.PageSize
if param.PageNumber > 0 {
offset = (param.PageNumber - 1) * param.PageSize
}
}
condition := dao.ListTaskCondition{
Limit: limit,
Offset: offset,
UserId: param.UserId,
CompanyId: param.CompanyId,
OnlyMy: param.OnlyMy,
SearchWord: param.SearchWord,
}
taskDao := dao.NewTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
})
//任务列表数据
taskListData, err := taskDao.ListTaskByHrbpV2(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
}
//查到的任务数据总数
taskCount, err := taskDao.CountTaskStageNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
}
//
taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
}
taskResult := []*adapter.TaskItem{}
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for _, val := range taskListData {
tk := adapter.TaskItem{
Id: val.TaskId,
Name: "",
Alias: val.Alias,
Leader: val.LeaderName,
Status: val.Status,
Level: val.Level,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
WarnFlag: 0,
}
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
"taskId": val.TaskId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务里程碑"+err.Error())
}
for _, val2 := range stageList {
stage := adapter.TaskStage{
Id: val2.Id,
Name: val2.Name,
SortBy: val2.SortBy,
PlanCompletedAt: time.Unix(int64(val2.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
}
if val2.RealCompletedAt > 0 {
stage.RealCompletedAt = time.Unix(int64(val2.RealCompletedAt), 0).Local().Format("2006-01-02")
}
switch val2.SortBy {
case 1:
tk.StageA = stage
case 2:
tk.StageB = stage
case 3:
tk.StageC = stage
case 4:
tk.StageD = stage
case 5:
tk.StageE = stage
}
}
taskResult = append(taskResult, &tk)
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
result["taskStageAnomaly"] = taskStageAnomalyCnt
result["taskAnomalyCnt"] = taskAnomalyCnt
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return result, nil
}
... ...
package domain
import "time"
import (
"sort"
"time"
)
type TaskState int
... ... @@ -36,6 +39,7 @@ type Task struct {
Anomaly int `json:"anomaly"` // 异常反馈的次数
WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑
LastStage TaskStage `json:"lastStage"` // 上一个完成的里程碑
}
type TaskLeader struct {
... ... @@ -73,6 +77,21 @@ func (t *Task) StatusDescription() string {
return ""
}
// 记录待执行的里程碑,和上一个执行的里程碑
func (t *Task) SetCurrentStage(stageList []*TaskStage) {
sort.Slice(stageList, func(i, j int) bool {
return stageList[i].SortBy < stageList[j].SortBy
})
t.CurrentStage = TaskStage{}
for _, val := range stageList {
t.LastStage = t.CurrentStage
t.CurrentStage = *val
if val.RealCompletedAt == 0 {
break
}
}
}
type TaskRepository interface {
Save(param *Task) error
Remove(id int) error
... ...
... ... @@ -89,7 +89,7 @@ type ListTaskStage struct {
RealCompletedAt int `pg:"real_completed_at"`
}
// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
// (弃用) 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
// userid 谁要查看任务数据
// limit 分页
// offset 分页
... ... @@ -197,7 +197,7 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) {
return cnt, err
}
// 获取任务以及里程碑列表,用于页面展示; 无过滤查看权限
// (弃用)获取任务以及里程碑列表,用于页面展示; 无过滤查看权限
// userid 谁要查看任务数据
// limit 分页
// offset 分页
... ... @@ -291,8 +291,8 @@ func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) {
t_task_ignore as (
select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
)select count(*) from task
left join t_task_ignore on t_task_ignore.task_id=task.id
where 1=1 and task.company_id=?`
left join t_task_ignore on t_task_ignore.task_id=task.id
where 1=1 and t_task_ignore.id isnull and task.company_id=?`
condition := []interface{}{param.UserId, param.CompanyId}
whereSql := ``
if param.OnlyMy {
... ... @@ -606,3 +606,156 @@ func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
_, err := tx.Query(&result, sqlStr, companyId)
return result, err
}
type ListTask struct {
CPlanCompletedAt int `pg:"c_plan_completed_at"`
LastStageDiff int `pg:"last_stage_diff"`
TaskId int `pg:"task_id"`
Alias string `pg:"alias"`
LeaderName string `pg:"leader_name"`
Level int `pg:"level"`
LevelName string `pg:"level_name"`
Anomaly int `pg:"anomaly"`
Status int `pg:"status"`
UpdatedAt time.Time `pg:"updated_at"`
CreatedAt time.Time `pg:"created_at"`
}
// (新)获取任务,用于页面展示; 无过滤查看权限
// userid 谁要查看任务数据
// limit 分页
// offset 分页
func (d *TaskDao) ListTaskByHrbpV2(param ListTaskCondition) ([]ListTask, error) {
sqlStr := `
with
t_task_ignore as (
select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
),
t_task as (
select
cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) as c_plan_completed_at,
cast(COALESCE(task.last_stage ->>'plan_completed_at','0') as int) as l_plan_completed_at,
cast(COALESCE(task.last_stage ->>'real_completed_at','0') as int) as l_real_completed_at,
task.id ,
task.alias ,
task.leader ->>'name' as leader_name,
task."level",
task.level_name ,
task.anomaly ,
task.status ,
task.updated_at,
task.created_at
from task
left join t_task_ignore on t_task_ignore.task_id=task.id
where 1=1 and t_task_ignore.id isnull
%s
),
t_task_1 as (
select
(case
when t_task.c_plan_completed_at=0 then 1
when t_task.c_plan_completed_at-now_time>0 then 0
else t_task.c_plan_completed_at-now_time
end) as sort_by_1,
t_task.c_plan_completed_at ,
t_task.l_plan_completed_at-t_task.l_real_completed_at as last_stage_diff,
t_task.id ,
t_task.alias ,
t_task.leader_name,
t_task."level",
t_task.level_name ,
t_task.anomaly ,
t_task.status ,
t_task.updated_at ,
t_task.created_at
from t_task
where 1=1
)select *
from t_task_1
order by t_task_1.sort_by_1,t_task_1.last_stage_diff,
t_task_1."level",t_task_1."created_at"
limit ? offset ?
`
condition := []interface{}{param.UserId, param.CompanyId}
whereSql := ``
if param.OnlyMy {
condition = append(condition, param.UserId)
whereSql += ` and task.leader ->>'id' = '?' `
}
if param.SearchWord != "" {
condition = append(condition, param.SearchWord, param.SearchWord)
whereSql += ` and (task.leader->>'name' like ? or task.alias like ?)`
}
strSql2 := fmt.Sprintf(sqlStr, whereSql)
condition = append(condition, param.Limit, param.Offset)
result := []ListTask{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, strSql2, condition...)
return result, err
}
func (d *TaskDao) ListTaskNotHrbpV2(param ListTaskCondition) ([]ListTask, error) {
withsql := d.catchTaskIdByPermission(param.UserId)
strSql := withsql + `
,t_task as (
select
cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) as c_plan_completed_at,
cast(COALESCE(task.last_stage ->>'plan_completed_at','0') as int) as l_plan_completed_at,
cast(COALESCE(task.last_stage ->>'real_completed_at','0') as int) as l_real_completed_at,
task.id ,
task.alias ,
task.leader ->>'name' as leader_name,
task."level",
task.level_name ,
task.anomaly ,
task.status ,
task.updated_at,
task.created_at
from task
join t_task_1 on t_task_1.id=task.id
where 1=1
%s
),
t_task_1 as (
select
(case
when t_task.c_plan_completed_at=0 then 1
when t_task.c_plan_completed_at-now_time>0 then 0
else t_task.c_plan_completed_at-now_time
end) as sort_by_1,
t_task.c_plan_completed_at ,
t_task.l_plan_completed_at-t_task.l_real_completed_at as last_stage_diff,
t_task.id ,
t_task.alias ,
t_task.leader_name,
t_task."level",
t_task.level_name ,
t_task.anomaly ,
t_task.status ,
t_task.updated_at ,
t_task.created_at
from t_task
where 1=1
)select *
from t_task_1
order by t_task_1.sort_by_1,t_task_1.last_stage_diff,
t_task_1."level",t_task_1."created_at"
limit ? offset ?
`
condition := []interface{}{param.CompanyId}
whereSql := ``
if param.OnlyMy {
condition = append(condition, param.UserId)
whereSql += ` and task.leader ->>'id' = '?' `
}
if param.SearchWord != "" {
condition = append(condition, param.SearchWord, param.SearchWord)
whereSql += ` and (task.leader->>'name' like ? or task.alias like ?)`
}
strSql2 := fmt.Sprintf(strSql, whereSql)
condition = append(condition, param.Limit, param.Offset)
result := []ListTask{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, strSql2, condition...)
return result, err
}
... ...
... ... @@ -26,4 +26,5 @@ type Task struct {
Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑
LastStage domain.TaskStage `pg:"lastStage"` // 上一个完成的里程碑
}
... ...
... ... @@ -43,6 +43,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
}
}
... ... @@ -69,6 +70,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
CurrentStage: param.CurrentStage,
LastStage: param.LastStage,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ...