作者 tangxvhui

暂存

... ... @@ -231,3 +231,11 @@ func CreateTaskStageRepository(options map[string]interface{}) domain.TaskStageR
}
return repository.NewTaskStageRepository(transactionContext)
}
func CreateTaskIgnoreRepository(options map[string]interface{}) domain.TaskIgnoreRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewTaskIgnoreRepository(transactionContext)
}
... ...
... ... @@ -22,7 +22,8 @@ type UserData struct {
type TaskStage struct {
Id int `json:"id,string"`
Name string `json:"name"` //里程碑名称
StatusCompleted string `json:"statusCompleted"` //里程碑的完成情况
StatusDescript string `json:"statusDescript"` //里程碑的完成情况
Status int `json:"status"` //里程碑名称状态
PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
RealCompletedAt string `json:"realCompletedAt"` //实际完成时间, 例:2006-01-02
}
... ...
package adapter
type TaskItem struct {
Id int `json:"id,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader string `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 优先级名称
StageA string `json:"stageA"` // 里程碑1
StageB string `json:"stageB"` // 里程碑2
StageC string `json:"stageC"` // 里程碑3
StageD string `json:"stageD"` // 里程碑4
StageE string `json:"stageE"` // 里程碑5
Id int `json:"id,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader string `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 优先级名称
StageA TaskStage `json:"stageA"` // 里程碑1
StageB TaskStage `json:"stageB"` // 里程碑2
StageC TaskStage `json:"stageC"` // 里程碑3
StageD TaskStage `json:"stageD"` // 里程碑4
StageE TaskStage `json:"stageE"` // 里程碑5
}
... ...
package command
type CreateTaskCommand struct {
Name string `json:"name"` //任务名称
LeaderId int `json:"leaderId"` //赋值人id
Name string `json:"name"` //任务名称
LeaderId int `json:"leaderId,string"` //赋值人id
}
... ...
... ... @@ -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,16 +65,40 @@ 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("")
err = taskRepo.Save(&newTask)
... ... @@ -297,7 +342,8 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
Name: val.Name,
PlanCompletedAt: t1,
RealCompletedAt: t2,
StatusCompleted: val.DescriptStatus(),
StatusDescript: val.StatusDescript(),
Status: int(val.Status),
})
}
return &result, nil
... ... @@ -441,11 +487,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 +501,23 @@ 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),
}
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)
... ... @@ -492,8 +544,19 @@ func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) erro
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//0
//0
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())
}
... ...
... ... @@ -32,7 +32,7 @@ type TaskStageRepository interface {
}
// 描述里程碑完成情况
func (t TaskStage) DescriptStatus() string {
func (t TaskStage) StatusDescript() string {
nowDay := time.Now().Format("2006-01-02")
nowTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local)
... ...
... ... @@ -19,6 +19,10 @@ type TaskIgnoreRepository struct {
var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil)
func NewTaskIgnoreRepository(transactionContext *pgTransaction.TransactionContext) *TaskIgnoreRepository {
return &TaskIgnoreRepository{transactionContext: transactionContext}
}
func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore {
return &domain.TaskIgnore{
Id: d.Id,
... ... @@ -31,7 +35,6 @@ func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domai
func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
if param.Id == 0 {
param.CreatedAt = time.Now()
return nil
}
m := models.TaskIgnore{
Id: param.Id,
... ...
... ... @@ -46,7 +46,6 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
param.UpdatedAt = time.Now()
if param.Id == 0 {
param.CreatedAt = time.Now()
return nil
}
m := models.Task{
Id: param.Id,
... ... @@ -124,7 +123,7 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d
}
if val, ok := queryOptions["leaderId"]; ok {
query.Where("task.leader->>'userId'='?'", val)
query.Where("task.leader->>'id'='?'", val)
}
if val, ok := queryOptions["aliasOrLeader"]; ok {
query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val)
... ...
package controllers
import (
"github.com/beego/beego/v2/server/web"
"os"
"github.com/beego/beego/v2/server/web"
)
type LoggerController struct {
... ...
... ... @@ -39,11 +39,26 @@ func (c *TaskController) UpdateTask() {
c.Response(nil, e)
return
}
// userReq := middlewares.GetUser(c.Ctx)
data, err := srv.UpdateTask(paramReq)
c.Response(data, err)
}
// 更新任务
func (c *TaskController) CreateTask() {
srv := service.NewTaskService()
paramReq := &command.CreateTaskCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
err = srv.CreateTaskTest(paramReq)
c.Response(nil, err)
}
// 启动任务
func (c *TaskController) RunTask() {
srv := service.NewTaskService()
... ... @@ -54,6 +69,8 @@ func (c *TaskController) RunTask() {
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.RunTask(paramReq)
c.Response(data, err)
}
... ... @@ -68,6 +85,8 @@ func (c *TaskController) StopTask() {
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.StopTask(paramReq)
c.Response(data, err)
}
... ... @@ -82,6 +101,24 @@ func (c *TaskController) ListTask() {
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.ListTask(paramReq)
c.Response(data, err)
}
// CancelAttention 取消关注的任务
func (c *TaskController) CancelAttention() {
srv := service.NewTaskService()
paramReq := &command.CancelAttentionCommand{}
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)
paramReq.CompanyId = int(userReq.CompanyId)
err = srv.CancelAttention(paramReq)
c.Response(nil, err)
}
... ...
... ... @@ -20,6 +20,14 @@ func init() {
web.AddNamespace(taskAdminNS)
taskFontNS := web.NewNamespace("/v1/font/task",
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()))
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
web.NSCtrlPost("/attention/cancel", (*controllers.TaskController).CancelAttention),
web.NSCtrlPost("/list", (*controllers.TaskController).ListTask), //TODO
)
web.AddNamespace(taskFontNS)
t := web.NewNamespace("/test/task",
web.NSCtrlPost("/", (*controllers.TaskController).CreateTask),
)
web.AddNamespace(t)
}
... ...