作者 tangxvhui

暂存

  1 +package adapter
  2 +
  3 +type TaskInfoAdapter struct {
  4 + Id int `json:"id"`
  5 + Name string `json:"name"` // 任务名称
  6 + Alias string `json:"alias"` // 任务别名
  7 + Leader UserData `json:"leader"` // 任务负责人
  8 + Status int `json:"status"` // 任务的状态
  9 + Level int `json:"level"` // 优先级,值越小优先级越高
  10 + LevalName string `json:"levalName"` // 优先级名称
  11 + RelatedUserId []string `json:"relatedUserId"` // 相关的员工id
  12 + RelatedUser []UserData `json:"relatedUser"` // 相关的员工id
  13 + StageList []TaskStage `json:"stageList"`
  14 +}
  15 +
  16 +type UserData struct {
  17 + Id int64 `json:"id,string"` // 用户Id
  18 + Account string `json:"account"` // 用户账号
  19 + Name string `json:"name"` // 用户姓名
  20 +}
  21 +
  22 +type TaskStage struct {
  23 + Id int `json:"id"`
  24 + Name string `json:"name"` //里程碑名称
  25 + PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
  26 +
  27 +}
  1 +package adapter
  2 +
  3 +type TaskItem struct {
  4 + Id int `json:"id"`
  5 + Name string `json:"name"` // 任务名称
  6 + Alias string `json:"alias"` // 任务别名
  7 + Leader UserData `json:"leader"` // 任务负责人
  8 + Status int `json:"status"` // 任务的状态
  9 + Level int `json:"level"` // 优先级,值越小优先级越高
  10 + LevalName string `json:"levalName"` // 优先级名称
  11 + StageA string `json:"stageA"` // 里程碑1
  12 + StageB string `json:"stageB"` // 里程碑2
  13 + StageC string `json:"stageC"` // 里程碑3
  14 + StageD string `json:"stageD"` // 里程碑4
  15 + StageE string `json:"stageE"` // 里程碑5
  16 +}
  1 +package command
  2 +
  3 +// 获取任务
  4 +type GetTaskCommand struct {
  5 + TaskId int `json:"taskId"`
  6 + CompanyId int `json:"-"`
  7 +}
  1 +package command
  2 +
  3 +type ListTaskCommand struct {
  4 + PageSize int `json:"pageSize"`
  5 + PageNumber int `json:"pageNumber"`
  6 + CompanyId int `json:"-"`
  7 + SearchWord string `json:"searchWord"`
  8 +}
1 package command 1 package command
2 2
3 -type RunTaskCommand struct{} 3 +type RunTaskCommand struct {
  4 + TaskId int `json:"taskId"`
  5 + CompanyId int `json:"-"`
  6 +}
1 package command 1 package command
2 2
3 -type StopTaskCommand struct{} 3 +type StopTaskCommand struct {
  4 + TaskId int `json:"taskId"`
  5 + CompanyId int `json:"-"`
  6 +}
@@ -2,7 +2,7 @@ package command @@ -2,7 +2,7 @@ package command
2 2
3 type UpdateTaskCommand struct { 3 type UpdateTaskCommand struct {
4 Id int `json:"id"` 4 Id int `json:"id"`
5 - Name string `json:"name"` //任务名称 5 + Alias string `json:"alias"` //任务名称
6 LeaderId int `json:"leaderId"` //赋值人id 6 LeaderId int `json:"leaderId"` //赋值人id
7 LevelName string `json:"levelName"` //优先级 7 LevelName string `json:"levelName"` //优先级
8 StageList []struct { 8 StageList []struct {
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "strconv"
4 "time" 5 "time"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
  8 + "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/adapter"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/command" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/command"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
10 ) 13 )
@@ -107,6 +110,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] @@ -107,6 +110,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
107 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ 110 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
108 "transactionContext": transactionContext, 111 "transactionContext": transactionContext,
109 }) 112 })
  113 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  114 + "transactionContext": transactionContext,
  115 + })
110 taskData, err := taskRepo.FindOne(map[string]interface{}{ 116 taskData, err := taskRepo.FindOne(map[string]interface{}{
111 "id": param.Id, 117 "id": param.Id,
112 }) 118 })
@@ -116,19 +122,300 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] @@ -116,19 +122,300 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
116 _, stageList, err := taskStageRepo.Find(map[string]interface{}{ 122 _, stageList, err := taskStageRepo.Find(map[string]interface{}{
117 "taskId": param.Id, 123 "taskId": param.Id,
118 }) 124 })
119 - _ = taskData  
120 - _ = stageList 125 + if err != nil {
  126 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  127 + }
  128 + leaderData, err := userRepo.FindOne(map[string]interface{}{
  129 + "id": param.LeaderId,
  130 + })
  131 + if err != nil {
  132 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  133 + }
  134 + taskData.Alias = param.Alias
  135 + taskData.Leader = domain.TaskLeader{
  136 + Id: leaderData.Id,
  137 + Account: leaderData.Account,
  138 + Name: leaderData.Name,
  139 + }
  140 + taskData.ApplyLevelName(param.LevelName)
  141 +
  142 + nowTime := time.Now()
  143 +
  144 + stageMap := map[int]*domain.TaskStage{}
  145 + for _, val := range stageList {
  146 + val.DeletedAt = &nowTime
  147 + stageMap[val.Id] = val
  148 + }
  149 + lastPlanCompletedAt := time.Time{}
  150 + newStageList := []*domain.TaskStage{}
  151 + for i, val2 := range param.StageList {
  152 + t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local)
  153 + if err != nil {
  154 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请填写里程碑完成时间")
  155 + }
  156 + if i > 0 {
  157 + if lastPlanCompletedAt.After(t) {
  158 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误")
  159 + }
  160 + }
  161 + lastPlanCompletedAt = t
  162 + if val2.Id == 0 {
  163 + newStage := domain.TaskStage{
  164 + Id: 0,
  165 + TaskId: taskData.Id,
  166 + Name: val2.Name,
  167 + SortBy: i + 1,
  168 + Status: domain.TaskStageUncompleted,
  169 + PlanCompletedAt: t.Unix(),
  170 + RealCompletedAt: 0,
  171 + }
  172 + newStageList = append(newStageList, &newStage)
  173 + continue
  174 + }
  175 + oldStage, ok := stageMap[val2.Id]
  176 + if !ok {
  177 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数据被其他人变更")
  178 + }
  179 + oldStage.DeletedAt = nil
  180 + oldStage.SortBy = i + 1
  181 + oldStage.PlanCompletedAt = t.Unix()
  182 + oldStage.Name = val2.Name
  183 + }
  184 + stageList = append(stageList, newStageList...)
121 185
  186 + err = taskStageRepo.Save(stageList)
  187 + if err != nil {
  188 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  189 + }
  190 + err = taskRepo.Save(taskData)
  191 + if err != nil {
  192 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  193 + }
122 if err := transactionContext.CommitTransaction(); err != nil { 194 if err := transactionContext.CommitTransaction(); err != nil {
123 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
124 } 196 }
125 - return nil, nil 197 + return map[string]interface{}{
  198 + "id": param.Id,
  199 + }, nil
126 } 200 }
127 201
128 -func (srv TaskService) RunTask() error {  
129 - return nil 202 +// 获取任务详情
  203 +func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.TaskInfoAdapter, error) {
  204 + transactionContext, err := factory.CreateTransactionContext(nil)
  205 + if err != nil {
  206 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  207 + }
  208 + if err := transactionContext.StartTransaction(); err != nil {
  209 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  210 + }
  211 + defer func() {
  212 + _ = transactionContext.RollbackTransaction()
  213 + }()
  214 + taskRepo := factory.CreateTaskRepository(map[string]interface{}{
  215 + "transactionContext": transactionContext,
  216 + })
  217 + taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
  218 + "transactionContext": transactionContext,
  219 + })
  220 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  221 + "transactionContext": transactionContext,
  222 + })
  223 + taskData, err := taskRepo.FindOne(map[string]interface{}{
  224 + "id": param.TaskId,
  225 + })
  226 + if err != nil {
  227 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  228 + }
  229 + _, stageList, err := taskStageRepo.Find(map[string]interface{}{
  230 + "taskId": param.TaskId,
  231 + })
  232 + if err != nil {
  233 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  234 + }
  235 +
  236 + relatedUserId := taskData.RelatedUser
  237 + _, relatedUserList, err := userRepo.Find(map[string]interface{}{
  238 + "ids": relatedUserId,
  239 + })
  240 + if err != nil {
  241 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取相关人员"+err.Error())
  242 + }
  243 + if err := transactionContext.CommitTransaction(); err != nil {
  244 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  245 + }
  246 +
  247 + result := adapter.TaskInfoAdapter{
  248 + Id: taskData.Id,
  249 + Name: taskData.Name,
  250 + Alias: taskData.Alias,
  251 + Leader: adapter.UserData{
  252 + Id: taskData.Leader.Id,
  253 + Account: taskData.Leader.Account,
  254 + Name: taskData.Leader.Name,
  255 + },
  256 + Status: int(taskData.Status),
  257 + Level: taskData.Level,
  258 + LevalName: taskData.LevalName,
  259 + RelatedUserId: []string{},
  260 + RelatedUser: []adapter.UserData{},
  261 + StageList: []adapter.TaskStage{},
  262 + }
  263 + for _, val := range relatedUserList {
  264 + idStr := strconv.Itoa(int(val.Id))
  265 + result.RelatedUserId = append(result.RelatedUserId, idStr)
  266 + result.RelatedUser = append(result.RelatedUser, adapter.UserData{
  267 + Id: val.Id,
  268 + Account: val.Account,
  269 + Name: val.Name,
  270 + })
  271 + }
  272 + for _, val := range stageList {
  273 + var t string
  274 + if val.PlanCompletedAt > 0 {
  275 + t = time.Unix(val.PlanCompletedAt, 0).Local().Format("2006-01-02")
  276 + }
  277 + result.StageList = append(result.StageList, adapter.TaskStage{
  278 + Id: val.Id,
  279 + Name: val.Name,
  280 + PlanCompletedAt: t,
  281 + })
  282 + }
  283 + return &result, nil
130 } 284 }
131 285
132 -func (srv TaskService) StopTask() error {  
133 - return nil 286 +// RunTask 启动任务
  287 +func (srv TaskService) RunTask(param *command.RunTaskCommand) (map[string]interface{}, error) {
  288 + transactionContext, err := factory.CreateTransactionContext(nil)
  289 + if err != nil {
  290 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  291 + }
  292 + if err := transactionContext.StartTransaction(); err != nil {
  293 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  294 + }
  295 + defer func() {
  296 + _ = transactionContext.RollbackTransaction()
  297 + }()
  298 + taskRepo := factory.CreateTaskRepository(map[string]interface{}{
  299 + "transactionContext": transactionContext,
  300 + })
  301 + taskData, err := taskRepo.FindOne(map[string]interface{}{
  302 + "id": param.TaskId,
  303 + })
  304 + if err != nil {
  305 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  306 + }
  307 + if taskData.Status == domain.TaskRunning {
  308 + return map[string]interface{}{"id": param.TaskId}, nil
  309 + }
  310 +
  311 + taskData.Status = domain.TaskRunning
  312 + taskData.RunAt = time.Now().Unix()
  313 + err = taskRepo.Save(taskData)
  314 + if err != nil {
  315 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
  316 + }
  317 + if err := transactionContext.CommitTransaction(); err != nil {
  318 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  319 + }
  320 + return map[string]interface{}{"id": param.TaskId}, nil
  321 +}
  322 +
  323 +// RunTask 停止任务
  324 +func (srv TaskService) StopTask(param *command.StopTaskCommand) (map[string]interface{}, error) {
  325 + transactionContext, err := factory.CreateTransactionContext(nil)
  326 + if err != nil {
  327 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  328 + }
  329 + if err := transactionContext.StartTransaction(); err != nil {
  330 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  331 + }
  332 + defer func() {
  333 + _ = transactionContext.RollbackTransaction()
  334 + }()
  335 + taskRepo := factory.CreateTaskRepository(map[string]interface{}{
  336 + "transactionContext": transactionContext,
  337 + })
  338 + taskData, err := taskRepo.FindOne(map[string]interface{}{
  339 + "id": param.TaskId,
  340 + })
  341 + if err != nil {
  342 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  343 + }
  344 + if taskData.Status == domain.TaskStop {
  345 + return map[string]interface{}{"id": param.TaskId}, nil
  346 + }
  347 +
  348 + taskData.Status = domain.TaskStop
  349 + taskData.StopAt = time.Now().Unix()
  350 + err = taskRepo.Save(taskData)
  351 + if err != nil {
  352 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
  353 + }
  354 + if err := transactionContext.CommitTransaction(); err != nil {
  355 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  356 + }
  357 + return map[string]interface{}{"id": param.TaskId}, nil
  358 +}
  359 +
  360 +// ListTask 任务列表
  361 +func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]interface{}, error) {
  362 + transactionContext, err := factory.CreateTransactionContext(nil)
  363 + if err != nil {
  364 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  365 + }
  366 + if err := transactionContext.StartTransaction(); err != nil {
  367 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  368 + }
  369 + defer func() {
  370 + _ = transactionContext.RollbackTransaction()
  371 + }()
  372 + taskRepo := factory.CreateTaskRepository(map[string]interface{}{
  373 + "transactionContext": transactionContext,
  374 + })
  375 + taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
  376 + "transactionContext": transactionContext,
  377 + })
  378 + //
  379 + condition := map[string]interface{}{
  380 + "offset": 0,
  381 + "limit": 20,
  382 + "companyId": param.CompanyId,
  383 + }
  384 + if len(param.SearchWord) > 0 {
  385 + condition["aliasOrLeader"] = "%" + param.SearchWord + "%"
  386 + }
  387 + if param.PageSize > 0 {
  388 + condition["limit"] = param.PageSize
  389 + if param.PageNumber > 0 {
  390 + condition["offset"] = (param.PageNumber - 1) * param.PageSize
  391 + }
  392 + }
  393 +
  394 + taskCnt, taskList, err := taskRepo.Find(condition)
  395 + if err != nil {
  396 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询任务数据"+err.Error())
  397 + }
  398 + taskIdList := []int{}
  399 + for _, val := range taskList {
  400 + taskIdList = append(taskIdList, val.Id)
  401 + }
  402 +
  403 + _, stageList, err := taskStageRepo.Find(map[string]interface{}{
  404 + "taskIdList": taskIdList,
  405 + })
  406 + if err != nil {
  407 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询任务阶段数据"+err.Error())
  408 + }
  409 + if err := transactionContext.CommitTransaction(); err != nil {
  410 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  411 + }
  412 +
  413 + taskResult := []*adapter.TaskItem{}
  414 + _ = stageList
  415 + // taskMapResult := map[int]*adapter.TaskItem{}
  416 + // for _, val := range taskList {
  417 +
  418 + // }
  419 + result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult)
  420 + return result, nil
134 } 421 }
@@ -15,6 +15,7 @@ type Task struct { @@ -15,6 +15,7 @@ type Task struct {
15 CreatedAt time.Time `json:"createdAt"` 15 CreatedAt time.Time `json:"createdAt"`
16 UpdatedAt time.Time `json:"updatedAt"` 16 UpdatedAt time.Time `json:"updatedAt"`
17 DeletedAt *time.Time `json:"deletedAt"` 17 DeletedAt *time.Time `json:"deletedAt"`
  18 + CompanyId int `json:"companyId,string"`
18 Name string `json:"name"` // 任务名称 19 Name string `json:"name"` // 任务名称
19 Alias string `json:"alias"` // 任务别名 20 Alias string `json:"alias"` // 任务别名
20 Leader TaskLeader `json:"leader"` // 任务负责人 21 Leader TaskLeader `json:"leader"` // 任务负责人
@@ -5,8 +5,8 @@ import "time" @@ -5,8 +5,8 @@ import "time"
5 type TaskStageState int 5 type TaskStageState int
6 6
7 const ( 7 const (
8 - TaskStageComplated TaskStageState = 1 //里程碑未完成  
9 - TaskStageUncompleted TaskStageState = 2 //里程碑完成 8 + TaskStageUncompleted TaskStageState = 1 //里程碑未完成
  9 + TaskStageCompleted TaskStageState = 2 //里程碑完成
10 ) 10 )
11 11
12 // 任务阶段 12 // 任务阶段
@@ -52,6 +52,8 @@ func init() { @@ -52,6 +52,8 @@ func init() {
52 &models.Permission{}, 52 &models.Permission{},
53 &models.LogSms{}, 53 &models.LogSms{},
54 &models.MessagePersonal{}, 54 &models.MessagePersonal{},
  55 + &models.Task{},
  56 + &models.TaskStage{},
55 } 57 }
56 for _, model := range tables { 58 for _, model := range tables {
57 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ 59 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
@@ -9,12 +9,13 @@ import ( @@ -9,12 +9,13 @@ import (
9 // 任务 9 // 任务
10 type Task struct { 10 type Task struct {
11 tableName struct{} `comment:"任务" pg:"task"` 11 tableName struct{} `comment:"任务" pg:"task"`
12 - Id int `pg:"id,pk"`  
13 - CreatedAt time.Time `pg:"created_at"`  
14 - UpdatedAt time.Time `pg:"updated_at"`  
15 - DeletedAt *time.Time `pg:"deleted_at"` 12 + Id int `pg:"id,pk"` //
  13 + CreatedAt time.Time `pg:"created_at"` //
  14 + UpdatedAt time.Time `pg:"updated_at"` //
  15 + DeletedAt *time.Time `pg:"deleted_at"` //
16 Name string `pg:"name"` // 任务名称 16 Name string `pg:"name"` // 任务名称
17 - Alias string `pg:"alias"` 17 + Alias string `pg:"alias"` //
  18 + CompanyId int `pg:"company_id"` //
18 Leader domain.TaskLeader `pg:"leader"` // 任务负责人 19 Leader domain.TaskLeader `pg:"leader"` // 任务负责人
19 Status int `pg:"status"` // 任务的状态 20 Status int `pg:"status"` // 任务的状态
20 Level int `pg:"level"` // 优先级,值越小优先级越高 21 Level int `pg:"level"` // 优先级,值越小优先级越高
@@ -38,6 +38,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { @@ -38,6 +38,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
38 RelatedUser: d.RelatedUser, 38 RelatedUser: d.RelatedUser,
39 RunAt: d.RunAt, 39 RunAt: d.RunAt,
40 StopAt: d.StopAt, 40 StopAt: d.StopAt,
  41 + CompanyId: d.CompanyId,
41 } 42 }
42 } 43 }
43 44
@@ -60,6 +61,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error { @@ -60,6 +61,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
60 LevalName: param.LevalName, 61 LevalName: param.LevalName,
61 RelatedUser: param.RelatedUser, 62 RelatedUser: param.RelatedUser,
62 RunAt: param.RunAt, 63 RunAt: param.RunAt,
  64 + CompanyId: param.CompanyId,
63 StopAt: param.StopAt, 65 StopAt: param.StopAt,
64 } 66 }
65 db := repo.transactionContext.PgTx 67 db := repo.transactionContext.PgTx
@@ -117,9 +119,16 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d @@ -117,9 +119,16 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d
117 if val, ok := queryOptions["name"]; ok { 119 if val, ok := queryOptions["name"]; ok {
118 query.Where("task.name like ?", val) 120 query.Where("task.name like ?", val)
119 } 121 }
  122 + if val, ok := queryOptions["companyId"]; ok {
  123 + query.Where("task.company_id like ?", val)
  124 + }
  125 +
120 if val, ok := queryOptions["leaderId"]; ok { 126 if val, ok := queryOptions["leaderId"]; ok {
121 query.Where("task.leader->>'userId'='?'", val) 127 query.Where("task.leader->>'userId'='?'", val)
122 } 128 }
  129 + if val, ok := queryOptions["aliasOrLeader"]; ok {
  130 + query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val)
  131 + }
123 query.Order("id desc") 132 query.Order("id desc")
124 count, err := query.SelectAndCount() 133 count, err := query.SelectAndCount()
125 if err != nil { 134 if err != nil {
@@ -106,9 +106,14 @@ func (repo *TaskStageRepository) Find(queryOptions map[string]interface{}) (int, @@ -106,9 +106,14 @@ func (repo *TaskStageRepository) Find(queryOptions map[string]interface{}) (int,
106 query := tx.Model(&m). 106 query := tx.Model(&m).
107 Where("deleted_at isnull"). 107 Where("deleted_at isnull").
108 Limit(20) 108 Limit(20)
  109 +
109 if val, ok := queryOptions["taskId"]; ok { 110 if val, ok := queryOptions["taskId"]; ok {
110 query.Where("task_stage.task_id = ?", val) 111 query.Where("task_stage.task_id = ?", val)
111 } 112 }
  113 +
  114 + if val, ok := queryOptions["taskIdList"]; ok {
  115 + query.Where("task_stage.task_id in(?)", pg.In(val))
  116 + }
112 query.Order("sort_by") 117 query.Order("sort_by")
113 count, err := query.SelectAndCount() 118 count, err := query.SelectAndCount()
114 if err != nil { 119 if err != nil {
1 package repository 1 package repository
2 2
3 import ( 3 import (
  4 + "errors"
4 "fmt" 5 "fmt"
5 6
6 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
@@ -92,8 +93,8 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai @@ -92,8 +93,8 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
92 query.Where("company_id = ?", v) 93 query.Where("company_id = ?", v)
93 } 94 }
94 err := query.First() 95 err := query.First()
95 - if err == pg.ErrNoRows {  
96 - return nil, ErrNoRows 96 + if errors.Is(err, pg.ErrNoRows) {
  97 + return nil, fmt.Errorf("没有找到user数据")
97 } 98 }
98 if err != nil { 99 if err != nil {
99 return nil, err 100 return nil, err