作者 tangxvhui

Merge branch 'dev-tangxvhui' into test

... ... @@ -655,7 +655,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
if principalId == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请选择任务负责人")
}
err := projectTaskService.CreateTask(transactionContext, &taskCommand.CreateTaskCommand{
err := projectTaskService.CreateTaskByProject(transactionContext, &taskCommand.CreateTaskByProjectCommand{
Name: content.Name,
LeaderId: principalId,
})
... ...
package adapter
type TaskInfoAdapter struct {
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"` // 任务的状态
StatusDescription string `json:"statusDescription"` //
// Level int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 任务类别名称
SortBy int `json:"sortBy"` // 优先级排序;值越小优先级越高
EndTime int64 `json:"endTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
UseEndtime int `json:"useEndTime"` // 是否应用任务截止的时间;默认值0:不应用,1:应用
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"` // 任务的状态
StatusDescription string `json:"statusDescription"` //
LevelName string `json:"levelName"` // 任务类别名称
SortBy int `json:"sortBy"` // 优先级排序;值越小优先级越高
EndTime int64 `json:"endTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
UseEndtime int `json:"useEndTime"` // 是否应用任务截止的时间;默认值0:不应用,1:应用
AssistFlagMax int `json:"assist_flag_max"` // 辅导异常标记最大值
RelatedUserId []string `json:"relatedUserId"` // 相关的员工id
RelatedUser []UserData `json:"relatedUser"` // 相关的员工id
StageList []TaskStage `json:"stageList"`
}
type UserData struct {
... ...
package command
type CreateTaskCommand struct {
type CreateTaskByProjectCommand struct {
Name string `json:"name"` //任务名称
LeaderId int `json:"leaderId,string"` //赋值人id
}
type CreateTaskCommand struct {
CompanyId int `json:"-"`
LeaderId int `json:"leaderId,string"`
Alias string `json:"alias"` //任务名称
LevelName string `json:"levelName"` //优先级
RelatedUserId []string `json:"relatedUserId"` //相关人员id
SortBy int `json:"sortBy"` // 优先级排序;值越小优先级越高
EndTime int64 `json:"endTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
}
... ...
... ... @@ -14,4 +14,5 @@ type UpdateTaskCommand struct {
Name string `json:"name"` //里程碑名称
PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
} `json:"stageList"`
AssistFlagMax int `json:"assistFlagMax"` // 辅导异常标记最大值
}
... ...
package service
import (
"encoding/json"
"fmt"
"strconv"
"strings"
... ... @@ -36,28 +35,29 @@ 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) 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 {
// CreateTask 重评估模板中创建
func (srv TaskService) CreateTaskByProject(transactionContext application.TransactionContext, param *command.CreateTaskByProjectCommand) error {
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
... ... @@ -65,9 +65,10 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
"transactionContext": transactionContext,
})
cnt, _, err := taskRepo.Find(map[string]interface{}{
"name": param.Name,
"leaderId": strconv.Itoa(param.LeaderId),
"limit": 1,
"name": param.Name,
"leaderId": strconv.Itoa(param.LeaderId),
"createdBy": 0,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询任务失败:"+err.Error())
... ... @@ -112,6 +113,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
RunAt: nowTime.Unix(),
StopAt: 0,
SortBy: domain.TaskSortNull,
CreatedBy: 0,
}
if int(leaderData.ParentId) != 0 {
newTask.RelatedUser = append(newTask.RelatedUser, int(leaderData.ParentId))
... ... @@ -160,6 +162,113 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
return nil
}
// 创建任务
func (srv TaskService) CreateTask(param *command.CreateTaskCommand) (map[string]interface{}, error) {
sortNamed := domain.TaskSortBy(param.SortBy)
if sortNamed.Named() == "" {
return nil, application.ThrowError(application.TRANSACTION_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,
})
cnt, _, err := taskRepo.Find(map[string]interface{}{
"name": param.Alias,
"leaderId": strconv.Itoa(param.LeaderId),
"createdBy": 1,
"limit": 1,
})
if err != nil {
return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
}
if cnt > 0 {
return map[string]interface{}{}, application.ThrowError(application.BUSINESS_ERROR, "已经存在相同的任务")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, leaderList, err := userRepo.Find(map[string]interface{}{
"id": param.LeaderId,
"companyId": param.CompanyId,
})
if err != nil {
return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询人员失败:"+err.Error())
}
if len(leaderList) == 0 {
return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_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,
"companyId": param.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务的相关人员"+err.Error())
}
}
leaderData := leaderList[0]
nowTime := time.Now()
newTask := domain.Task{
Id: 0,
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
DeletedAt: nil,
CompanyId: int(leaderData.CompanyId),
Name: param.Alias,
Alias: param.Alias,
Leader: domain.TaskLeader{
Id: leaderData.Id,
Account: leaderData.Account,
Name: leaderData.Name,
},
Status: domain.TaskRunning,
Level: 0,
LevelName: "",
RelatedUser: []int{int(leaderData.Id)},
RunAt: nowTime.Unix(),
StopAt: 0,
SortBy: domain.TaskSortBy(param.SortBy),
CreatedBy: 1,
AssistFlagMax: 0,
}
//处理endTime
if param.EndTime == 0 {
newTask.EndTime = 0
} else {
newTask.EndTime = dayEndTime(time.Unix(param.EndTime, 10)).Unix()
}
newTask.ApplyLevelName(param.LevelName)
newTask.RelatedUser = []int{}
for _, val := range relatedUser {
newTask.RelatedUser = append(newTask.RelatedUser, int(val.Id))
}
err = taskRepo.Save(&newTask)
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": newTask.Id}, nil
}
// 更新任务
func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -198,7 +307,7 @@ 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)
... ... @@ -218,10 +327,12 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
for _, val := range relatedUser {
taskData.RelatedUser = append(taskData.RelatedUser, int(val.Id))
}
//更新任务名称
//更新任务名称,任务分类
taskData.Alias = param.Alias
taskData.ApplyLevelName(param.LevelName)
nowTime := time.Now()
//更新里程碑数据
stageMap := map[int]*domain.TaskStage{}
for _, val := range stageList {
val.DeletedAt = &nowTime
... ... @@ -229,8 +340,8 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
lastPlanCompletedAt := time.Time{}
newStageList := []*domain.TaskStage{}
//标记完成时间变更的里程碑
markStage := []domain.TaskStage{}
//标记 变更完成时间的 里程碑
//markStage := []domain.TaskStage{}
for i, val2 := range param.StageList {
t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local)
if err != nil {
... ... @@ -262,9 +373,10 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
oldStage.DeletedAt = nil
oldStage.SortBy = i + 1
oldStage.Name = val2.Name
if ok := oldStage.SetPlanCompleted(t); ok {
markStage = append(markStage, *oldStage)
}
oldStage.SetPlanCompleted(t)
//if ok := oldStage.SetPlanCompleted(t); ok {
//markStage = append(markStage, *oldStage)
// }
}
stageList = append(stageList, newStageList...)
... ... @@ -303,39 +415,40 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
taskData.UseEndTime = param.UseEndtime
taskData.AssistFlagMax = param.AssistFlagMax
err = taskRepo.Save(taskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
//根据markStage 记录的里程碑数据生成通知
for _, val := range markStage {
for _, val2 := range taskData.RelatedUser {
t1 := time.Unix(val.PlanCompletedAt, 0).Format("2006-01-02")
s := fmt.Sprintf(`%s 负责的任务 %s 的里程碑 %s 计划完成时间变更为 %s,请知晓!`, taskData.Leader.Name, taskData.Alias, val.Name, t1)
payload := map[string]string{
"id": strconv.Itoa(val.Id),
"taskName": taskData.Name,
"taskStageName": val.Name,
}
payloadStr, _ := json.Marshal(payload)
newMessage := domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesTaskModify,
TargetUserId: val2,
ReadFlag: domain.MessageUnread,
Title: s,
Content: s,
Payload: string(payloadStr),
}
err = messageRepo.Save(&newMessage)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
// for _, val := range markStage {
// for _, val2 := range taskData.RelatedUser {
// t1 := time.Unix(val.PlanCompletedAt, 0).Format("2006-01-02")
// s := fmt.Sprintf(`%s 负责的任务 %s 的里程碑 %s 计划完成时间变更为 %s,请知晓!`, taskData.Leader.Name, taskData.Alias, val.Name, t1)
// payload := map[string]string{
// "id": strconv.Itoa(val.Id),
// "taskName": taskData.Name,
// "taskStageName": val.Name,
// }
// payloadStr, _ := json.Marshal(payload)
// newMessage := domain.MessagePersonal{
// Id: 0,
// Types: domain.MessageTypesTaskModify,
// TargetUserId: val2,
// ReadFlag: domain.MessageUnread,
// Title: s,
// Content: s,
// Payload: string(payloadStr),
// }
// err = messageRepo.Save(&newMessage)
// 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())
}
... ... @@ -449,13 +562,6 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// cnt, _, err := taskRecordRepo.Find(map[string]interface{}{
// "taskId": param.TaskId,
// "limit": 1,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "相关联的任务反馈信息"+err.Error())
// }
result := adapter.TaskInfoAdapter{
Id: taskData.Id,
Name: taskData.Name,
... ... @@ -477,6 +583,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
RelatedUserId: []string{},
RelatedUser: []adapter.UserData{},
StageList: []adapter.TaskStage{},
AssistFlagMax: taskData.AssistFlagMax,
}
for _, val := range relatedUserList {
idStr := strconv.Itoa(int(val.Id))
... ... @@ -487,6 +594,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
Name: val.Name,
ParentId: val.ParentId,
})
}
for _, val := range stageList {
... ...
... ... @@ -43,38 +43,45 @@ const (
)
func (t TaskSortBy) Named() string {
nameMap := map[TaskSortBy]string{
TaskSortHight: "高",
TaskSortMiddle: "中",
TaskSortLow: "低",
TaskSortNull: "无",
switch t {
case TaskSortHight:
return "高"
case TaskSortMiddle:
return "中"
case TaskSortLow:
return "低"
case TaskSortNull:
return "无"
}
return nameMap[t]
return ""
}
// 任务
type Task struct {
Id int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
CompanyId int `json:"companyId,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级 (优先级字段表示的意义变更,不再需要这个字段,仅数据保留)
LevelName string `json:"levelName"` // 字段表示的意义变更; 原来 (“优先级名称“)=> 现在 (“任务类型“)
SortBy TaskSortBy `json:"sortBy"` // 优先级排序;值越小优先级越高
EndTime int64 `json:"endTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
UseEndTime int `json:"useEndTime"` // 是否应用任务截止的时间;默认值0:不应用,1:应用
RelatedUser []int `json:"relatedUser"` // 相关的员工id
RunAt int64 `json:"runAt"` // 启动的时间戳,单位:秒
StopAt int64 `json:"stopAt"` // 停止的时间戳,单位:秒
Anomaly int `json:"anomaly"` // 异常反馈的次数
WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑
LastStage TaskStage `json:"lastStage"` // 上一个完成的里程碑
Id int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
CompanyId int `json:"companyId,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级 (优先级字段表示的意义变更,不再需要这个字段,仅数据保留)
LevelName string `json:"levelName"` // 字段表示的意义变更; 原来 (“优先级名称“)=> 现在 (“任务类型“)
SortBy TaskSortBy `json:"sortBy"` // 优先级排序;值越小优先级越高
EndTime int64 `json:"endTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
UseEndTime int `json:"useEndTime"` // 是否应用任务截止的时间;默认值0:不应用,1:应用
RelatedUser []int `json:"relatedUser"` // 相关的员工id
RunAt int64 `json:"runAt"` // 启动的时间戳,单位:秒
StopAt int64 `json:"stopAt"` // 停止的时间戳,单位:秒
Anomaly int `json:"anomaly"` // 异常反馈的次数
WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
AssistFlag int `json:"assistFlag"` // 辅导异常标记
AssistFlagMax int `json:"assistFlagMax"` // 辅导异常标记最大值
CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑
LastStage TaskStage `json:"lastStage"` // 上一个完成的里程碑
CreatedBy int `json:"createdBy"` // 任务的创建方式 0: 根据模板中的任务创建,1:页面主动直接创建
}
type TaskLeader struct {
... ...
package domain
// 任务的异常记录
type TaskAnomaly struct {
Id int
TaskId int
Types int
}
... ...
package domain
// 任务有优先级
// 任务的新建分类
type TaskLevel struct {
Id int `json:"id"`
LevelName string `json:"levelName"`
... ...
... ... @@ -19,23 +19,23 @@ const (
// TaskRecord 任务反馈情况记录
type TaskRecord struct {
Id int `json:"id,string" comment:"记录ID"`
CompanyId int `json:"companyId,string" comment:"公司ID"`
StaffAssessId int `json:"staffAssessId,string" comment:"每日评估的ID"`
TaskId int `json:"taskId,string" comment:"任务ID"`
TaskCategory string `json:"taskCategory" comment:"任务类别"`
TaskName string `json:"taskName" comment:"任务名称"`
TaskAlias string `json:"taskAlias" comment:"任务别名"`
TaskLeader TaskLeader `json:"taskLeader" comment:"任务负责人"`
AssistLevel int `json:"assistLevel" comment:"上级辅导情况"`
AssistContent string `json:"assistContent" comment:"上级辅导内容"`
RemarkContent []RemarkText `json:"remarkContent" comment:"填写反馈"`
AnomalyState int `json:"anomalyState" comment:"异常是否反馈状态(-1初始状态、0异常、1正常)"`
TaskStages []TaskStage `json:"taskStages" comment:"里程碑列表"`
TaskStageCheck TaskStage `json:"taskStageCheck" comment:"提交的里程碑"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
Id int `json:"id,string" comment:"记录ID"`
CompanyId int `json:"companyId,string" comment:"公司ID"`
StaffAssessId int `json:"staffAssessId,string" comment:"每日评估的ID"`
TaskId int `json:"taskId,string" comment:"任务ID"`
TaskCategory string `json:"taskCategory" comment:"任务类别"`
TaskName string `json:"taskName" comment:"任务名称"`
TaskAlias string `json:"taskAlias" comment:"任务别名"`
TaskLeader TaskLeader `json:"taskLeader" comment:"任务负责人"`
AssistLevel int `json:"assistLevel" comment:"上级辅导情况"`
AssistContent string `json:"assistContent" comment:"上级辅导内容"`
AnomalyState int `json:"anomalyState" comment:"异常是否反馈状态(-1初始状态、0异常、1正常)"`
TaskStages []TaskStage `json:"taskStages" comment:"里程碑列表"`
TaskStageCheck TaskStage `json:"taskStageCheck" comment:"提交的里程碑"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
TaskCreatedBy int `json:"taskCreatedBy" comment:"任务的创建方式"` // 任务的创建方式 0: 根据模板中的任务创建,1:页面主动直接创建
}
type TaskRecordRepository interface {
... ...
... ... @@ -8,26 +8,29 @@ import (
// 任务
type Task struct {
tableName struct{} `comment:"任务" pg:"task"`
Id int `pg:"id,pk"` //
CreatedAt time.Time `pg:"created_at"` //
UpdatedAt time.Time `pg:"updated_at"` //
DeletedAt *time.Time `pg:"deleted_at"` //
Name string `pg:"name"` // 任务名称
Alias string `pg:"alias"` //
CompanyId int `pg:"company_id"` //
Leader domain.TaskLeader `pg:"leader,type:jsonb"` // 任务负责人
Status int `pg:"status,use_zero"` // 任务的状态
Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高
LevelName string `pg:"level_name"` // 优先级名称
RelatedUser []int `pg:"related_user"` //
LastStage domain.TaskStage `pg:"last_stage,type:jsonb"` // 上一个完成的里程碑,添加type:jsonb 防止orm生成sql时字段丢失
RunAt int64 `pg:"run_at,use_zero"` // 启动的时间
StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间
Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
CurrentStage domain.TaskStage `pg:"current_stage,type:jsonb"` // 添加type:jsonb 防止orm(可能是特性)生成sql时字段丢失
SortBy int `pg:"sort_by,use_zero"` // 优先级排序;值越小优先级越高
EndTime int64 `pg:"end_time,use_zero"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
UseEndTime int `pg:"use_end_time,use_zero"` // 是否应用任务截止的时间;默认值0:不应用,1:应用
tableName struct{} `comment:"任务" pg:"task"`
Id int `pg:"id,pk"` //
CreatedAt time.Time `pg:"created_at"` //
UpdatedAt time.Time `pg:"updated_at"` //
DeletedAt *time.Time `pg:"deleted_at"` //
Name string `pg:"name"` // 任务名称
Alias string `pg:"alias"` //
CompanyId int `pg:"company_id"` //
Leader domain.TaskLeader `pg:"leader,type:jsonb"` // 任务负责人
Status int `pg:"status,use_zero"` // 任务的状态
Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高
LevelName string `pg:"level_name"` // 优先级名称
RelatedUser []int `pg:"related_user"` //
LastStage domain.TaskStage `pg:"last_stage,type:jsonb"` // 上一个完成的里程碑,添加type:jsonb 防止orm生成sql时字段丢失
RunAt int64 `pg:"run_at,use_zero"` // 启动的时间
StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间
Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
CurrentStage domain.TaskStage `pg:"current_stage,type:jsonb"` // 添加type:jsonb 防止orm(可能是特性)生成sql时字段丢失
SortBy int `pg:"sort_by,use_zero"` // 优先级排序;值越小优先级越高
EndTime int64 `pg:"end_time,use_zero"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
UseEndTime int `pg:"use_end_time,use_zero"` // 是否应用任务截止的时间;默认值0:不应用,1:应用
AssistFlag int `pg:"assist_flag,use_zero"` // 辅导异常标记
AssistFlagMax int `pg:"assist_flag_max,use_zero"` // 辅导异常标记最大值
CreatedBy int `pg:"created_by,use_zero"`
}
... ...
... ... @@ -26,27 +26,30 @@ func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *Ta
func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
return &domain.Task{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevelName: d.LevelName,
SortBy: domain.TaskSortBy(d.SortBy),
EndTime: d.EndTime,
UseEndTime: d.UseEndTime,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevelName: d.LevelName,
SortBy: domain.TaskSortBy(d.SortBy),
EndTime: d.EndTime,
UseEndTime: d.UseEndTime,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
AssistFlag: d.AssistFlag,
AssistFlagMax: d.AssistFlagMax,
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
CreatedBy: d.CreatedBy,
}
}
... ... @@ -56,27 +59,30 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
param.CreatedAt = time.Now()
}
m := models.Task{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Alias: param.Alias,
CompanyId: param.CompanyId,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
LastStage: param.LastStage,
RunAt: param.RunAt,
StopAt: param.StopAt,
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
CurrentStage: param.CurrentStage,
SortBy: int(param.SortBy),
EndTime: param.EndTime,
UseEndTime: param.UseEndTime,
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Alias: param.Alias,
CompanyId: param.CompanyId,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
LastStage: param.LastStage,
RunAt: param.RunAt,
StopAt: param.StopAt,
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
CurrentStage: param.CurrentStage,
SortBy: int(param.SortBy),
EndTime: param.EndTime,
UseEndTime: param.UseEndTime,
AssistFlag: param.AssistFlag,
AssistFlagMax: param.AssistFlagMax,
CreatedBy: param.CreatedBy,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ... @@ -148,6 +154,9 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d
if val, ok := queryOptions["status"]; ok {
query.Where("task.status=?", val)
}
if val, ok := queryOptions["createdBy"]; ok {
query.Where("created_by = ?", val)
}
if val, ok := queryOptions["limit"]; ok {
if limit, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil {
query.Limit(limit)
... ...
... ... @@ -56,8 +56,8 @@ func (c *TaskController) CreateTask() {
return
}
err = srv.CreateTaskTest(paramReq)
c.Response(nil, err)
resp, err := srv.CreateTask(paramReq)
c.Response(resp, err)
}
// 启动任务
... ...
... ... @@ -12,6 +12,7 @@ func init() {
taskAdminNS := web.NewNamespace("/v1/admin/task",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSCtrlPost("/info", (*controllers.TaskController).GetTaskInfo),
web.NSCtrlPost("/", (*controllers.TaskController).CreateTask),
web.NSCtrlPut("/", (*controllers.TaskController).UpdateTask),
web.NSCtrlPut("/delete", (*controllers.TaskController).DeleteTask),
web.NSCtrlPost("/run", (*controllers.TaskController).RunTask),
... ...