|
|
package service
|
|
|
|
|
|
import (
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/adapter"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
)
|
...
|
...
|
@@ -107,6 +110,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskData, err := taskRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.Id,
|
|
|
})
|
...
|
...
|
@@ -116,19 +122,300 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
|
|
|
"taskId": param.Id,
|
|
|
})
|
|
|
_ = taskData
|
|
|
_ = stageList
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
leaderData, err := userRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.LeaderId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
taskData.Alias = param.Alias
|
|
|
taskData.Leader = domain.TaskLeader{
|
|
|
Id: leaderData.Id,
|
|
|
Account: leaderData.Account,
|
|
|
Name: leaderData.Name,
|
|
|
}
|
|
|
taskData.ApplyLevelName(param.LevelName)
|
|
|
|
|
|
nowTime := time.Now()
|
|
|
|
|
|
stageMap := map[int]*domain.TaskStage{}
|
|
|
for _, val := range stageList {
|
|
|
val.DeletedAt = &nowTime
|
|
|
stageMap[val.Id] = val
|
|
|
}
|
|
|
lastPlanCompletedAt := time.Time{}
|
|
|
newStageList := []*domain.TaskStage{}
|
|
|
for i, val2 := range param.StageList {
|
|
|
t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请填写里程碑完成时间")
|
|
|
}
|
|
|
if i > 0 {
|
|
|
if lastPlanCompletedAt.After(t) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误")
|
|
|
}
|
|
|
}
|
|
|
lastPlanCompletedAt = t
|
|
|
if val2.Id == 0 {
|
|
|
newStage := domain.TaskStage{
|
|
|
Id: 0,
|
|
|
TaskId: taskData.Id,
|
|
|
Name: val2.Name,
|
|
|
SortBy: i + 1,
|
|
|
Status: domain.TaskStageUncompleted,
|
|
|
PlanCompletedAt: t.Unix(),
|
|
|
RealCompletedAt: 0,
|
|
|
}
|
|
|
newStageList = append(newStageList, &newStage)
|
|
|
continue
|
|
|
}
|
|
|
oldStage, ok := stageMap[val2.Id]
|
|
|
if !ok {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数据被其他人变更")
|
|
|
}
|
|
|
oldStage.DeletedAt = nil
|
|
|
oldStage.SortBy = i + 1
|
|
|
oldStage.PlanCompletedAt = t.Unix()
|
|
|
oldStage.Name = val2.Name
|
|
|
}
|
|
|
stageList = append(stageList, newStageList...)
|
|
|
|
|
|
err = taskStageRepo.Save(stageList)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = taskRepo.Save(taskData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
return map[string]interface{}{
|
|
|
"id": param.Id,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func (srv TaskService) RunTask() error {
|
|
|
return nil
|
|
|
// 获取任务详情
|
|
|
func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.TaskInfoAdapter, 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()
|
|
|
}()
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskData, err := taskRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.TaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
|
|
|
"taskId": param.TaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
relatedUserId := taskData.RelatedUser
|
|
|
_, relatedUserList, err := userRepo.Find(map[string]interface{}{
|
|
|
"ids": relatedUserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取相关人员"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
result := adapter.TaskInfoAdapter{
|
|
|
Id: taskData.Id,
|
|
|
Name: taskData.Name,
|
|
|
Alias: taskData.Alias,
|
|
|
Leader: adapter.UserData{
|
|
|
Id: taskData.Leader.Id,
|
|
|
Account: taskData.Leader.Account,
|
|
|
Name: taskData.Leader.Name,
|
|
|
},
|
|
|
Status: int(taskData.Status),
|
|
|
Level: taskData.Level,
|
|
|
LevalName: taskData.LevalName,
|
|
|
RelatedUserId: []string{},
|
|
|
RelatedUser: []adapter.UserData{},
|
|
|
StageList: []adapter.TaskStage{},
|
|
|
}
|
|
|
for _, val := range relatedUserList {
|
|
|
idStr := strconv.Itoa(int(val.Id))
|
|
|
result.RelatedUserId = append(result.RelatedUserId, idStr)
|
|
|
result.RelatedUser = append(result.RelatedUser, adapter.UserData{
|
|
|
Id: val.Id,
|
|
|
Account: val.Account,
|
|
|
Name: val.Name,
|
|
|
})
|
|
|
}
|
|
|
for _, val := range stageList {
|
|
|
var t string
|
|
|
if val.PlanCompletedAt > 0 {
|
|
|
t = time.Unix(val.PlanCompletedAt, 0).Local().Format("2006-01-02")
|
|
|
}
|
|
|
result.StageList = append(result.StageList, adapter.TaskStage{
|
|
|
Id: val.Id,
|
|
|
Name: val.Name,
|
|
|
PlanCompletedAt: t,
|
|
|
})
|
|
|
}
|
|
|
return &result, nil
|
|
|
}
|
|
|
|
|
|
func (srv TaskService) StopTask() error {
|
|
|
return nil
|
|
|
// RunTask 启动任务
|
|
|
func (srv TaskService) RunTask(param *command.RunTaskCommand) (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()
|
|
|
}()
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskData, err := taskRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.TaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if taskData.Status == domain.TaskRunning {
|
|
|
return map[string]interface{}{"id": param.TaskId}, nil
|
|
|
}
|
|
|
|
|
|
taskData.Status = domain.TaskRunning
|
|
|
taskData.RunAt = time.Now().Unix()
|
|
|
err = taskRepo.Save(taskData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{"id": param.TaskId}, nil
|
|
|
}
|
|
|
|
|
|
// RunTask 停止任务
|
|
|
func (srv TaskService) StopTask(param *command.StopTaskCommand) (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()
|
|
|
}()
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskData, err := taskRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.TaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if taskData.Status == domain.TaskStop {
|
|
|
return map[string]interface{}{"id": param.TaskId}, nil
|
|
|
}
|
|
|
|
|
|
taskData.Status = domain.TaskStop
|
|
|
taskData.StopAt = time.Now().Unix()
|
|
|
err = taskRepo.Save(taskData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{"id": param.TaskId}, nil
|
|
|
}
|
|
|
|
|
|
// ListTask 任务列表
|
|
|
func (srv TaskService) ListTask(param *command.ListTaskCommand) (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()
|
|
|
}()
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//
|
|
|
condition := map[string]interface{}{
|
|
|
"offset": 0,
|
|
|
"limit": 20,
|
|
|
"companyId": param.CompanyId,
|
|
|
}
|
|
|
if len(param.SearchWord) > 0 {
|
|
|
condition["aliasOrLeader"] = "%" + param.SearchWord + "%"
|
|
|
}
|
|
|
if param.PageSize > 0 {
|
|
|
condition["limit"] = param.PageSize
|
|
|
if param.PageNumber > 0 {
|
|
|
condition["offset"] = (param.PageNumber - 1) * param.PageSize
|
|
|
}
|
|
|
}
|
|
|
|
|
|
taskCnt, taskList, err := taskRepo.Find(condition)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询任务数据"+err.Error())
|
|
|
}
|
|
|
taskIdList := []int{}
|
|
|
for _, val := range taskList {
|
|
|
taskIdList = append(taskIdList, val.Id)
|
|
|
}
|
|
|
|
|
|
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
|
|
|
"taskIdList": taskIdList,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询任务阶段数据"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
taskResult := []*adapter.TaskItem{}
|
|
|
_ = stageList
|
|
|
// taskMapResult := map[int]*adapter.TaskItem{}
|
|
|
// for _, val := range taskList {
|
|
|
|
|
|
// }
|
|
|
result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult)
|
|
|
return result, nil
|
|
|
} |
...
|
...
|
|