作者 郑周

Merge branch 'dev-tangxvhui' into dev-zhengzhou

... ... @@ -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)
}
... ...
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 {
... ... @@ -21,8 +23,10 @@ type UserData struct {
type TaskStage struct {
Id int `json:"id,string"`
Name string `json:"name"` //里程碑名称
StatusCompleted string `json:"statusCompleted"` //里程碑的完成情况
Name string `json:"name"` //里程碑名称
StatusDescript string `json:"statusDescript"` //里程碑的完成情况
Status int `json:"status"` //里程碑状态
SortBy int `json:"sortBy"`
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 CancelAttentionCommand struct {
TaskId int `json:"taskId,string"`
UserId int `json:"-"`
CompanyId int `json:"-"`
}
... ...
package command
type CreateTaskCommand struct {
Name string `json:"name"` //任务名称
LeaderId int `json:"leaderId"` //赋值人id
Name string `json:"name"` //任务名称
LeaderId int `json:"leaderId,string"` //赋值人id
}
... ...
... ... @@ -2,6 +2,6 @@ package command
// 获取任务
type GetTaskCommand struct {
TaskId int `json:"taskId"`
TaskId int `json:"taskId,string"`
CompanyId int `json:"-"`
}
... ...
package command
type UpdateTaskCommand struct {
Id int `json:"id,string"`
Alias string `json:"alias"` //任务名称
LeaderId int `json:"leaderId,string"` //负责id
LevelName string `json:"levelName"` //优先级
StageList []struct {
Id int `json:"id,string"`
Alias string `json:"alias"` //任务名称
LevelName string `json:"levelName"` //优先级
RelatedUserId []string `json:"relatedUserId"` //相关人员id
StageList []struct {
Id int `json:"id,string"`
Name string `json:"name"` //里程碑名称
PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
... ...
... ... @@ -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,18 +65,42 @@ 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("")
newTask.ApplyLevelName("战略任务")
err = taskRepo.Save(&newTask)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
... ... @@ -99,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
return nil
}
// 更新任务
// TODO 检查是否可以修改,和通知
func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -110,13 +157,23 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if len(param.StageList) < 3 {
return map[string]interface{}{
"id": param.Id,
}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量至少3个")
}
if len(param.StageList) > 5 {
return map[string]interface{}{
"id": param.Id,
}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量太多")
}
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
taskData, err := taskRepo.FindOne(map[string]interface{}{
... ... @@ -131,6 +188,21 @@ 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)
relatedUserIds = append(relatedUserIds, id)
}
var relatedUser []*domain.User
if len(relatedUserIds) > 0 {
_, relatedUser, err = userRepo.Find(map[string]interface{}{
"ids": relatedUserIds,
})
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
... ... @@ -138,22 +210,15 @@ 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.RelatedUser = []int{}
for _, val := range relatedUser {
taskData.RelatedUser = append(taskData.RelatedUser, int(val.Id))
}
//更新任务名称
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
... ... @@ -168,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
if i > 0 {
if lastPlanCompletedAt.After(t) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑["+val2.Name+"]完成时间填写错误")
}
}
lastPlanCompletedAt = t
... ... @@ -191,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
oldStage.DeletedAt = nil
oldStage.SortBy = i + 1
oldStage.PlanCompletedAt = t.Unix()
oldStage.Name = val2.Name
oldStage.PlanCompletedAt = t.Unix()
//TODO 修改里程碑计划完成时间,特殊处理
}
stageList = append(stageList, newStageList...)
... ... @@ -247,31 +313,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))
... ... @@ -297,7 +368,9 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
Name: val.Name,
PlanCompletedAt: t1,
RealCompletedAt: t2,
StatusCompleted: val.DescriptStatus(),
SortBy: val.SortBy,
StatusDescript: val.StatusDescript(),
Status: int(val.Status),
})
}
return &result, nil
... ... @@ -441,11 +514,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 +528,24 @@ 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),
SortBy: val.SortBy,
}
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)
... ... @@ -475,3 +555,38 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte
func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.TaskStage) (bool, error) {
return true, nil
}
func (t TaskService) ListTask2() error {
return nil
}
// CancelAttention 用户取消关注某个任务
func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) 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()
}()
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())
}
return nil
}
... ...
... ... @@ -26,6 +26,7 @@ type Task struct {
RelatedUser []int `json:"relatedUser"` // 相关的员工id
RunAt int64 `json:"runAt"` // 启动的时间戳,秒
StopAt int64 `json:"stopAt"` // 停止的时间戳,秒
Anomaly int `json:"anomaly"` //异常反馈的次数
}
type TaskLeader struct {
... ... @@ -49,6 +50,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
... ...
package domain
import "time"
// 任务反馈情况记录
type TaskRecord struct {
Id int // id
CreatedAt time.Time //
UpdatedAt time.Time //
StaffAssessId int // 每日评估的id
TaskId int // 里程碑任务的id
Name string // 任务名称
Alias string // 任务别名
TaskLeader TaskLeader // 里程碑完成情况填写人
Rating int // 上级辅导情况
RatingContent string // 上级辅导内容
}
... ...
... ... @@ -6,8 +6,9 @@ type TaskStageState int
const (
TaskStageUncompleted TaskStageState = 1 //里程碑未完成
TaskStageCompleted TaskStageState = 2 //里程碑完成
TaskStageCompletedOverdue TaskStageState = 3 //里程碑预期完成
TaskStageCompletedOverdue TaskStageState = 2 //里程碑逾期完成
TaskStageCompleted TaskStageState = 3 //里程碑完成
)
// 任务阶段
... ... @@ -31,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)
... ...
... ... @@ -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{
... ...
... ... @@ -23,4 +23,5 @@ type Task struct {
RelatedUser []int `pg:"related_user"` //
RunAt int64 `pg:"run_at"` // 启动的时间
StopAt int64 `pg:"stop_at"` // 停止的时间
Anomaly int `json:"anomaly"` // 异常反馈的数量
}
... ...
... ... @@ -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"` //时间完成时间
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
//任务
... ... @@ -13,18 +19,84 @@ 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,
TaskId: d.TaskId,
UserId: d.UserId,
CreatedAt: d.CreatedAt,
}
}
func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
panic("not implemented") // TODO: Implement
if param.Id == 0 {
param.CreatedAt = time.Now()
}
m := models.TaskIgnore{
Id: param.Id,
TaskId: param.TaskId,
UserId: param.UserId,
CreatedAt: param.CreatedAt,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
_, err := db.Model(&m).Insert()
if err != nil {
return err
}
} else {
_, err := db.Model(&m).WherePK().Update()
if err != nil {
return err
}
}
param.Id = m.Id
return nil
}
func (repo *TaskIgnoreRepository) Remove(id int) error {
panic("not implemented") // TODO: Implement
tx := repo.transactionContext.PgTx
_, err := tx.Model(&models.TaskIgnore{}).
Where("id=?", id).Delete()
return err
}
func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) {
panic("not implemented") // TODO: Implement
tx := repo.transactionContext.PgTx
m := new(models.TaskIgnore)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有找到 task_ignore 数据")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) {
panic("not implemented") // TODO: Implement
tx := repo.transactionContext.PgTx
var m []*models.TaskIgnore
query := tx.Model(&m)
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.TaskIgnore
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...
... ... @@ -29,6 +29,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
... ... @@ -38,7 +39,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
CompanyId: d.CompanyId,
Anomaly: d.Anomaly,
}
}
... ... @@ -46,7 +47,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,
... ... @@ -63,6 +63,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
RunAt: param.RunAt,
CompanyId: param.CompanyId,
StopAt: param.StopAt,
Anomaly: param.Anomaly,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ... @@ -120,11 +121,11 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d
query.Where("task.name like ?", val)
}
if val, ok := queryOptions["companyId"]; ok {
query.Where("task.company_id like ?", val)
query.Where("task.company_id = ?", val)
}
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)
... ...
... ... @@ -26,7 +26,7 @@ func NewTaskStageRepository(transactionContext *pgTransaction.TransactionContext
func (repo *TaskStageRepository) TransformToDomain(d *models.TaskStage) *domain.TaskStage {
return &domain.TaskStage{
Id: d.Id,
TaskId: 0,
TaskId: d.TaskId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
... ...
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)
}
... ...