作者 tangxvhui

更新

package adapter
type TaskInfoAdapter struct {
Id int `json:"id,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader UserData `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevalName string `json:"levalName"` // 优先级名称
RelatedUserId []string `json:"relatedUserId"` // 相关的员工id
RelatedUser []UserData `json:"relatedUser"` // 相关的员工id
StageList []TaskStage `json:"stageList"`
Id int `json:"id,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
LeaderId int64 `json:"leaderId,string"` //
Leader UserData `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
StatusDescript string `json:"statusDescript"` //
Level int `json:"level"` // 优先级,值越小优先级越高
LevalName string `json:"levalName"` // 优先级名称
RelatedUserId []string `json:"relatedUserId"` // 相关的员工id
RelatedUser []UserData `json:"relatedUser"` // 相关的员工id
StageList []TaskStage `json:"stageList"`
}
type UserData struct {
... ...
... ... @@ -2,6 +2,6 @@ package command
// 获取任务
type GetTaskCommand struct {
TaskId int `json:"taskId"`
TaskId int `json:"taskId,string"`
CompanyId int `json:"-"`
}
... ...
... ... @@ -2,9 +2,8 @@ package command
type UpdateTaskCommand struct {
Id int `json:"id,string"`
Alias string `json:"alias"` //任务名称
LeaderId int `json:"leaderId,string"` //负责id
LevelName string `json:"levelName"` //优先级
Alias string `json:"alias"` //任务名称
LevelName string `json:"levelName"` //优先级
StageList []struct {
Id int `json:"id,string"`
Name string `json:"name"` //里程碑名称
... ...
... ... @@ -161,9 +161,6 @@ 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,
})
... ... @@ -183,22 +180,9 @@ 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.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
... ... @@ -292,31 +276,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))
... ...
... ... @@ -49,6 +49,19 @@ func (t *Task) ApplyLevelName(name string) {
}
}
// StatusDescript
func (t *Task) StatusDescript() string {
switch t.Status {
case TaskWait:
return "待启动"
case TaskRunning:
return "启动中"
case TaskStop:
return "停止"
}
return ""
}
type TaskRepository interface {
Save(param *Task) error
Remove(id int) error
... ...
... ... @@ -8,10 +8,10 @@ import (
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 1,
UserId: 3245763368183552,
Phone: "18650060951",
PlatformId: 29,
CompanyId: 233,
UserId: 3240357405361920,
Phone: "13459147023",
PlatformId: 28,
AdminType: 1,
}
tk, _ := ut.CreateAccessToken()
... ...
... ... @@ -54,6 +54,7 @@ func init() {
&models.MessagePersonal{},
&models.Task{},
&models.TaskStage{},
&models.TaskIgnore{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
... ... @@ -5,7 +5,7 @@ import "time"
// 不关注的任务列表
type TaskIgnore struct {
tableName struct{} `comment:"不关注的任务列表" pg:"task_ignore"`
Id int `pg:"id"`
Id int `pg:"id,pk"`
TaskId int `pg:"task_id"`
UserId int `pg:"user_id"`
CreatedAt time.Time `pg:"created_at"`
... ...
... ... @@ -5,14 +5,14 @@ import "time"
// 任务阶段
type TaskStage struct {
tableName struct{} `comment:"任务阶段" pg:"task_stage"`
Id int `pg:"id"`
Id int `pg:"id,pk"`
TaskId int `pg:"task_id"`
CreatedAt time.Time `pg:"created_at"`
UpdatedAt time.Time `pg:"updated_at"`
DeletedAt *time.Time `pg:"deleted_at"`
Name string `pg:"name"` //里程碑名称
SortBy int `pg:"sort_by"` //排序
Status int `pg:"status"` //里程碑完成情况
PlanCompletedAt int64 `pg:"plan_completed_at"` //计划完成时间
RealCompletedAt int64 `pg:"real_completed_at"` //时间完成时间
Name string `pg:"name"` //里程碑名称
SortBy int `pg:"sort_by"` //排序
Status int `pg:"status"` //里程碑完成情况
PlanCompletedAt int64 `pg:"plan_completed_at,use_zero"` //计划完成时间
RealCompletedAt int64 `pg:"real_completed_at,use_zero"` //时间完成时间
}
... ...