...
|
...
|
@@ -25,6 +25,27 @@ func dayEndTime(t time.Time) time.Time { |
|
|
return t2
|
|
|
}
|
|
|
|
|
|
func (srv TaskService) CreateTaskTest(param *command.CreateTaskCommand) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
err = srv.CreateTask(transactionContext, param)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (srv TaskService) CreateTask(transactionContext application.TransactionContext, param *command.CreateTaskCommand) error {
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -44,18 +65,42 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
|
|
//任务已存在
|
|
|
return nil
|
|
|
}
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
_, leaderList, err := userRepo.Find(map[string]interface{}{
|
|
|
"id": param.LeaderId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询人员失败:"+err.Error())
|
|
|
}
|
|
|
if len(leaderList) == 0 {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有查询到人员")
|
|
|
}
|
|
|
leaderData := leaderList[0]
|
|
|
nowTime := time.Now()
|
|
|
newTask := domain.Task{
|
|
|
Id: 0,
|
|
|
Name: param.Name,
|
|
|
Alias: param.Name,
|
|
|
Id: 0,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: nil,
|
|
|
CompanyId: int(leaderData.CompanyId),
|
|
|
Name: param.Name,
|
|
|
Alias: param.Name,
|
|
|
Leader: domain.TaskLeader{
|
|
|
Id: leaderData.Id,
|
|
|
Account: leaderData.Account,
|
|
|
Name: leaderData.Name,
|
|
|
},
|
|
|
Status: domain.TaskWait,
|
|
|
Level: 0,
|
|
|
LevelName: "",
|
|
|
RelatedUser: []int{},
|
|
|
RunAt: nowTime.Unix(),
|
|
|
StopAt: 0,
|
|
|
}
|
|
|
newTask.ApplyLevelName("")
|
|
|
newTask.ApplyLevelName("战略任务")
|
|
|
err = taskRepo.Save(&newTask)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
|
...
|
...
|
@@ -99,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 更新任务
|
|
|
// TODO 检查是否可以修改,和通知
|
|
|
func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
...
|
...
|
@@ -110,13 +157,23 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if len(param.StageList) < 3 {
|
|
|
return map[string]interface{}{
|
|
|
"id": param.Id,
|
|
|
}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量至少3个")
|
|
|
}
|
|
|
if len(param.StageList) > 5 {
|
|
|
return map[string]interface{}{
|
|
|
"id": param.Id,
|
|
|
}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量太多")
|
|
|
}
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskData, err := taskRepo.FindOne(map[string]interface{}{
|
...
|
...
|
@@ -131,6 +188,21 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//任务的相关人员
|
|
|
relatedUserIds := []int{}
|
|
|
for _, val := range param.RelatedUserId {
|
|
|
id, _ := strconv.Atoi(val)
|
|
|
relatedUserIds = append(relatedUserIds, id)
|
|
|
}
|
|
|
var relatedUser []*domain.User
|
|
|
if len(relatedUserIds) > 0 {
|
|
|
_, relatedUser, err = userRepo.Find(map[string]interface{}{
|
|
|
"ids": relatedUserIds,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务的相关人员"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
ok, err := srv.canUpdateTask(taskData, stageList)
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -138,22 +210,15 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
if !ok {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_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.RelatedUser = []int{}
|
|
|
for _, val := range relatedUser {
|
|
|
taskData.RelatedUser = append(taskData.RelatedUser, int(val.Id))
|
|
|
}
|
|
|
//更新任务名称
|
|
|
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
|
...
|
...
|
@@ -168,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
}
|
|
|
if i > 0 {
|
|
|
if lastPlanCompletedAt.After(t) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误")
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑["+val2.Name+"]完成时间填写错误")
|
|
|
}
|
|
|
}
|
|
|
lastPlanCompletedAt = t
|
...
|
...
|
@@ -191,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
}
|
|
|
oldStage.DeletedAt = nil
|
|
|
oldStage.SortBy = i + 1
|
|
|
oldStage.PlanCompletedAt = t.Unix()
|
|
|
oldStage.Name = val2.Name
|
|
|
oldStage.PlanCompletedAt = t.Unix()
|
|
|
//TODO 修改里程碑计划完成时间,特殊处理
|
|
|
}
|
|
|
stageList = append(stageList, newStageList...)
|
|
|
|
...
|
...
|
@@ -247,31 +313,36 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task |
|
|
}
|
|
|
|
|
|
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())
|
|
|
var relatedUserList []*domain.User
|
|
|
if len(relatedUserId) > 0 {
|
|
|
_, 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,
|
|
|
Id: taskData.Id,
|
|
|
Name: taskData.Name,
|
|
|
Alias: taskData.Alias,
|
|
|
LeaderId: taskData.Leader.Id,
|
|
|
Leader: adapter.UserData{
|
|
|
Id: taskData.Leader.Id,
|
|
|
Account: taskData.Leader.Account,
|
|
|
Name: taskData.Leader.Name,
|
|
|
},
|
|
|
Status: int(taskData.Status),
|
|
|
Level: taskData.Level,
|
|
|
LevalName: taskData.LevelName,
|
|
|
RelatedUserId: []string{},
|
|
|
RelatedUser: []adapter.UserData{},
|
|
|
StageList: []adapter.TaskStage{},
|
|
|
Status: int(taskData.Status),
|
|
|
StatusDescript: taskData.StatusDescript(),
|
|
|
Level: taskData.Level,
|
|
|
LevalName: taskData.LevelName,
|
|
|
RelatedUserId: []string{},
|
|
|
RelatedUser: []adapter.UserData{},
|
|
|
StageList: []adapter.TaskStage{},
|
|
|
}
|
|
|
for _, val := range relatedUserList {
|
|
|
idStr := strconv.Itoa(int(val.Id))
|
...
|
...
|
@@ -297,7 +368,9 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task |
|
|
Name: val.Name,
|
|
|
PlanCompletedAt: t1,
|
|
|
RealCompletedAt: t2,
|
|
|
StatusCompleted: val.DescriptStatus(),
|
|
|
SortBy: val.SortBy,
|
|
|
StatusDescript: val.StatusDescript(),
|
|
|
Status: int(val.Status),
|
|
|
})
|
|
|
}
|
|
|
return &result, nil
|
...
|
...
|
@@ -441,11 +514,11 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte |
|
|
Status: int(val.Status),
|
|
|
Level: val.Level,
|
|
|
LevelName: val.LevelName,
|
|
|
StageA: "",
|
|
|
StageB: "",
|
|
|
StageC: "",
|
|
|
StageD: "",
|
|
|
StageE: "",
|
|
|
// StageA: adapter.TaskStage{},
|
|
|
// StageB: adapter.TaskStage{},
|
|
|
// StageC: adapter.TaskStage{},
|
|
|
// StageD: adapter.TaskStage{},
|
|
|
// StageE: adapter.TaskStage{},
|
|
|
}
|
|
|
taskResult = append(taskResult, &tk)
|
|
|
taskMapResult[val.Id] = &tk
|
...
|
...
|
@@ -455,17 +528,24 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte |
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
stage := adapter.TaskStage{
|
|
|
Id: val.Id,
|
|
|
Name: val.Name,
|
|
|
StatusDescript: val.StatusDescript(),
|
|
|
Status: int(val.Status),
|
|
|
SortBy: val.SortBy,
|
|
|
}
|
|
|
switch val.SortBy {
|
|
|
case 1:
|
|
|
taskData.StageA = val.Name
|
|
|
taskData.StageA = stage
|
|
|
case 2:
|
|
|
taskData.StageB = val.Name
|
|
|
taskData.StageB = stage
|
|
|
case 3:
|
|
|
taskData.StageC = val.Name
|
|
|
taskData.StageC = stage
|
|
|
case 4:
|
|
|
taskData.StageD = val.Name
|
|
|
taskData.StageD = stage
|
|
|
case 5:
|
|
|
taskData.StageE = val.Name
|
|
|
taskData.StageE = stage
|
|
|
}
|
|
|
}
|
|
|
result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult)
|
...
|
...
|
@@ -475,3 +555,38 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte |
|
|
func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.TaskStage) (bool, error) {
|
|
|
return true, nil
|
|
|
}
|
|
|
|
|
|
func (t TaskService) ListTask2() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// CancelAttention 用户取消关注某个任务
|
|
|
func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
taskIgnoreRepo := factory.CreateTaskIgnoreRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskIgnore := domain.TaskIgnore{
|
|
|
Id: 0,
|
|
|
TaskId: param.TaskId,
|
|
|
UserId: param.UserId,
|
|
|
CreatedAt: time.Time{},
|
|
|
}
|
|
|
err = taskIgnoreRepo.Save(&taskIgnore)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|