作者 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,
})
... ...
... ... @@ -8,11 +8,11 @@ type TaskInfoAdapter struct {
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:应用
AssistFlagMax int `json:"assist_flag_max"` // 辅导异常标记最大值
RelatedUserId []string `json:"relatedUserId"` // 相关的员工id
RelatedUser []UserData `json:"relatedUser"` // 相关的员工id
StageList []TaskStage `json:"stageList"`
... ...
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,
})
... ... @@ -67,6 +67,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
cnt, _, err := taskRepo.Find(map[string]interface{}{
"name": param.Name,
"leaderId": strconv.Itoa(param.LeaderId),
"createdBy": 0,
"limit": 1,
})
if err != nil {
... ... @@ -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,13 +43,17 @@ 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 ""
}
// 任务
... ... @@ -73,8 +77,11 @@ type Task struct {
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"`
... ...
... ... @@ -29,13 +29,13 @@ type TaskRecord struct {
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正常)"`
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 {
... ...
... ... @@ -30,4 +30,7 @@ type Task struct {
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"`
}
... ...
... ... @@ -45,8 +45,11 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
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,
}
}
... ... @@ -77,6 +80,9 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
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),
... ...