作者 tangxvhui

更新

... ... @@ -7,7 +7,7 @@ type TaskItem struct {
Leader UserData `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevalName string `json:"levalName"` // 优先级名称
LevelName string `json:"levelName"` // 优先级名称
StageA string `json:"stageA"` // 里程碑1
StageB string `json:"stageB"` // 里程碑2
StageC string `json:"stageC"` // 里程碑3
... ...
... ... @@ -49,9 +49,9 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
Id: 0,
Name: param.Name,
Alias: param.Name,
Status: domain.TaskRunning,
Status: domain.TaskWait,
Level: 0,
LevalName: "",
LevelName: "",
RelatedUser: []int{},
RunAt: nowTime.Unix(),
}
... ... @@ -70,8 +70,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
Name: "里程碑1",
SortBy: 1,
Status: domain.TaskStageUncompleted,
PlanCompletedAt: nowEndTime.Add(30 * 24 * time.Hour).Format("2006-01-02"),
RealCompletedAt: "",
PlanCompletedAt: nowEndTime.Add(30 * 24 * time.Hour).Unix(),
RealCompletedAt: 0,
},
{
Id: 0,
... ... @@ -79,8 +79,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
Name: "里程碑2",
SortBy: 2,
Status: domain.TaskStageUncompleted,
PlanCompletedAt: nowEndTime.Add(60 * 24 * time.Hour).Format("2006-01-02"),
RealCompletedAt: "",
PlanCompletedAt: nowEndTime.Add(60 * 24 * time.Hour).Unix(),
RealCompletedAt: 0,
},
{
Id: 0,
... ... @@ -88,8 +88,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
Name: "里程碑3",
SortBy: 3,
Status: domain.TaskStageUncompleted,
PlanCompletedAt: nowEndTime.Add(90 * 24 * time.Hour).Format("2006-01-02"),
RealCompletedAt: "",
PlanCompletedAt: nowEndTime.Add(90 * 24 * time.Hour).Unix(),
RealCompletedAt: 0,
},
}
err = taskStageRepo.Save(newTaskStage)
... ... @@ -131,6 +131,13 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
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
}
if !ok {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "日评数据已生成,任务不能再被编辑")
}
leaderData, err := userRepo.FindOne(map[string]interface{}{
"id": param.LeaderId,
})
... ... @@ -172,8 +179,8 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
Name: val2.Name,
SortBy: i + 1,
Status: domain.TaskStageUncompleted,
PlanCompletedAt: val2.PlanCompletedAt,
RealCompletedAt: "",
PlanCompletedAt: t.Unix(),
RealCompletedAt: 0,
}
newStageList = append(newStageList, &newStage)
continue
... ... @@ -184,7 +191,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
oldStage.DeletedAt = nil
oldStage.SortBy = i + 1
oldStage.PlanCompletedAt = val2.PlanCompletedAt
oldStage.PlanCompletedAt = t.Unix()
oldStage.Name = val2.Name
}
stageList = append(stageList, newStageList...)
... ... @@ -261,7 +268,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
},
Status: int(taskData.Status),
Level: taskData.Level,
LevalName: taskData.LevalName,
LevalName: taskData.LevelName,
RelatedUserId: []string{},
RelatedUser: []adapter.UserData{},
StageList: []adapter.TaskStage{},
... ... @@ -275,12 +282,22 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
Name: val.Name,
})
}
for _, val := range stageList {
t1 := ""
t2 := ""
if val.PlanCompletedAt > 0 {
t1 = time.Unix(val.PlanCompletedAt, 0).Local().Format("2006-01-02")
}
if val.RealCompletedAt > 0 {
t2 = time.Unix(val.RealCompletedAt, 0).Local().Format("2006-01-02")
}
result.StageList = append(result.StageList, adapter.TaskStage{
Id: val.Id,
Name: val.Name,
PlanCompletedAt: val.PlanCompletedAt,
RealCompletedAt: val.RealCompletedAt,
PlanCompletedAt: t1,
RealCompletedAt: t2,
StatusCompleted: val.DescriptStatus(),
})
}
return &result, nil
... ... @@ -427,7 +444,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte
},
Status: int(val.Status),
Level: val.Level,
LevalName: val.LevalName,
LevelName: val.LevelName,
StageA: "",
StageB: "",
StageC: "",
... ... @@ -458,3 +475,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte
result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult)
return result, nil
}
func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.TaskStage) (bool, error) {
return true, nil
}
... ...
... ... @@ -5,8 +5,9 @@ import "time"
type TaskState int
const (
TaskRunning TaskState = 1 //任务启动中
TaskStop TaskState = 2 //任务停止
TaskWait TaskState = 1 //任务待启动
TaskRunning TaskState = 2 //任务启动中
TaskStop TaskState = 3 //任务停止
)
// 任务
... ... @@ -21,7 +22,7 @@ type Task struct {
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevalName string `json:"levalName"` // 优先级名称
LevelName string `json:"levelName"` // 优先级名称
RelatedUser []int `json:"relatedUser"` // 相关的员工id
RunAt int64 `json:"runAt"` // 启动的时间戳,秒
StopAt int64 `json:"stopAt"` // 停止的时间戳,秒
... ... @@ -35,16 +36,16 @@ type TaskLeader struct {
// 设置任务的优先级
func (t *Task) ApplyLevelName(name string) {
t.LevalName = name
t.LevelName = name
switch name {
case "战略任务":
t.Level = 1
t.Level = 100
case "重点任务":
t.Level = 2
t.Level = 200
case "常规任务":
t.Level = 3
t.Level = 300
default:
t.Level = 999
t.Level = 9999
}
}
... ...
... ... @@ -5,8 +5,9 @@ import "time"
type TaskStageState int
const (
TaskStageUncompleted TaskStageState = 1 //里程碑未完成
TaskStageCompleted TaskStageState = 2 //里程碑完成
TaskStageUncompleted TaskStageState = 1 //里程碑未完成
TaskStageCompleted TaskStageState = 2 //里程碑完成
TaskStageCompletedOverdue TaskStageState = 3 //里程碑预期完成
)
// 任务阶段
... ... @@ -19,8 +20,8 @@ type TaskStage struct {
Name string `json:"name"` //里程碑名称
SortBy int `json:"sortBy"` //排序
Status TaskStageState `json:"status"` //里程碑完成情况
PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间戳,秒
RealCompletedAt string `json:"realCompletedAt"` //时间完成时间戳,秒
PlanCompletedAt int64 `json:"planCompletedAt"` //计划完成时间戳,秒
RealCompletedAt int64 `json:"realCompletedAt"` //时间完成时间戳,秒
}
type TaskStageRepository interface {
Save(param []*TaskStage) error
... ... @@ -31,10 +32,22 @@ type TaskStageRepository interface {
// 描述里程碑完成情况
func (t TaskStage) DescriptStatus() string {
// nowTime := time.Now().Unix()
// if t.RealCompletedAt != "" && t.PlanCompletedAt != "" {
nowDay := time.Now().Format("2006-01-02")
nowTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local)
// }
str := ""
switch t.Status {
case TaskStageUncompleted:
if nowTime.Unix() > t.PlanCompletedAt {
str = "已逾期"
} else {
str = "未完成"
}
case TaskStageCompleted:
str = "已完成"
case TaskStageCompletedOverdue:
str = "逾期完成"
}
return ""
return str
}
... ...
... ... @@ -19,7 +19,7 @@ type Task struct {
Leader domain.TaskLeader `pg:"leader"` // 任务负责人
Status int `pg:"status"` // 任务的状态
Level int `pg:"level"` // 优先级,值越小优先级越高
LevalName string `pg:"leval_name"` // 优先级名称
LevelName string `pg:"level_name"` // 优先级名称
RelatedUser []int `pg:"related_user"` //
RunAt int64 `pg:"run_at"` // 启动的时间
StopAt int64 `pg:"stop_at"` // 停止的时间
... ...
... ... @@ -13,6 +13,6 @@ type TaskStage struct {
Name string `pg:"name"` //里程碑名称
SortBy int `pg:"sort_by"` //排序
Status int `pg:"status"` //里程碑完成情况
PlanCompletedAt string `pg:"plan_completed_at"` //计划完成时间
RealCompletedAt string `pg:"real_completed_at"` //时间完成时间
PlanCompletedAt int64 `pg:"plan_completed_at"` //计划完成时间
RealCompletedAt int64 `pg:"real_completed_at"` //时间完成时间
}
... ...
... ... @@ -34,7 +34,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevalName: d.LevalName,
LevelName: d.LevelName,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
... ... @@ -58,7 +58,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevalName: param.LevalName,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
RunAt: param.RunAt,
CompanyId: param.CompanyId,
... ...
... ... @@ -12,6 +12,7 @@ type TaskController struct {
beego.BaseController
}
// 获取任务
func (c *TaskController) GetTaskInfo() {
srv := service.NewTaskService()
paramReq := &command.GetTaskCommand{}
... ... @@ -27,3 +28,60 @@ func (c *TaskController) GetTaskInfo() {
data, err := srv.GetTaskInfo(paramReq)
c.Response(data, err)
}
// 更新任务
func (c *TaskController) UpdateTask() {
srv := service.NewTaskService()
paramReq := &command.UpdateTaskCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
// userReq := middlewares.GetUser(c.Ctx)
data, err := srv.UpdateTask(paramReq)
c.Response(data, err)
}
// 启动任务
func (c *TaskController) RunTask() {
srv := service.NewTaskService()
paramReq := &command.RunTaskCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
data, err := srv.RunTask(paramReq)
c.Response(data, err)
}
// 启动任务
func (c *TaskController) StopTask() {
srv := service.NewTaskService()
paramReq := &command.StopTaskCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
data, err := srv.StopTask(paramReq)
c.Response(data, err)
}
// 任务列表
func (c *TaskController) ListTask() {
srv := service.NewTaskService()
paramReq := &command.ListTaskCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
data, err := srv.ListTask(paramReq)
c.Response(data, err)
}
... ...
... ... @@ -3,13 +3,20 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
//绩效管理模块
taskAdminNS := web.NewNamespace("/v1/admin/task",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()))
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSCtrlPost("/info", (*controllers.TaskController).GetTaskInfo),
web.NSCtrlPut("/", (*controllers.TaskController).UpdateTask),
web.NSCtrlPost("/run", (*controllers.TaskController).RunTask),
web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask),
web.NSCtrlPost("/list", (*controllers.TaskController).ListTask),
)
web.AddNamespace(taskAdminNS)
taskFontNS := web.NewNamespace("/v1/font/task",
... ...