...
|
...
|
@@ -2,6 +2,8 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
...
|
...
|
@@ -13,7 +15,6 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 任务服务
|
...
|
...
|
@@ -25,6 +26,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co |
|
|
if err := confirmRobTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -35,6 +37,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var confirmRobTaskService service.ConfirmRobTaskService
|
|
|
if value, err := factory.CreateConfirmRobTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -46,6 +49,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co |
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if task, err := confirmRobTaskService.Confirm(confirmRobTaskCommand.TaskId, confirmRobTaskCommand.Operator, confirmRobTaskCommand.PlannedCompletionTime); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -61,6 +65,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co |
|
|
if err := rejectTaskReceiverCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -71,6 +76,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var rejectTaskReceiverService service.RejectTaskReceiverService
|
|
|
if value, err := factory.CreateRejectTaskReceiverService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -82,6 +88,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co |
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if task, err := rejectTaskReceiverService.Reject(rejectTaskReceiverCommand.TaskId, rejectTaskReceiverCommand.Operator, rejectTaskReceiverCommand.RejectReason); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -97,6 +104,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) |
|
|
if err := robTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -107,6 +115,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var robTaskService service.RobTaskService
|
|
|
if value, err := factory.CreateRobTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -119,6 +128,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) |
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if task, err := robTaskService.Rob(robTaskCommand.TaskId, robTaskCommand.Receiver); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -134,6 +144,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) |
|
|
if err := bidTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -144,6 +155,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var bidTaskService service.BidTaskService
|
|
|
if value, err := factory.CreateBidTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -152,6 +164,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) |
|
|
} else {
|
|
|
bidTaskService = value
|
|
|
}
|
|
|
|
|
|
if task, err := bidTaskService.Bid(bidTaskCommand.TaskId, bidTaskCommand.Bidder); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -167,6 +180,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom |
|
|
if err := chooseSuccessfulBidderCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -177,6 +191,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var chooseSuccessfulBidderService service.ChooseSuccessfulBidderService
|
|
|
if value, err := factory.CreateChooseSuccessfulBidderService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -186,6 +201,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom |
|
|
chooseSuccessfulBidderService = value
|
|
|
chooseSuccessfulBidderService.Subscribe(&subscriber.AbilityServiceSubscriber{})
|
|
|
}
|
|
|
|
|
|
if task, err := chooseSuccessfulBidderService.Choose(chooseSuccessfulBidderCommand.TaskId, chooseSuccessfulBidderCommand.SuccessfulBidder, chooseSuccessfulBidderCommand.Operator, chooseSuccessfulBidderCommand.PlannedCompletionTime); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -201,6 +217,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm |
|
|
if err := applyCompleteTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -211,6 +228,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var applyCompleteTaskService service.ApplyCompleteTaskService
|
|
|
if value, err := factory.CreateApplyCompleteTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -219,6 +237,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm |
|
|
} else {
|
|
|
applyCompleteTaskService = value
|
|
|
}
|
|
|
|
|
|
if task, err := applyCompleteTaskService.ApplyComplete(applyCompleteTaskCommand.TaskId, applyCompleteTaskCommand.Receiver); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -234,6 +253,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT |
|
|
if err := releaseTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -244,6 +264,8 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 发布任务服务初始化
|
|
|
var releaseTaskService service.ReleaseTaskService
|
|
|
if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -256,6 +278,8 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT |
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 关闭任务
|
|
|
if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -271,6 +295,7 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) |
|
|
if err := offTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -281,6 +306,8 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 关闭任务服务初始化
|
|
|
var offTaskService service.OffTaskService
|
|
|
if value, err := factory.CreateOffTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -290,6 +317,8 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) |
|
|
offTaskService = value
|
|
|
offTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
|
|
|
}
|
|
|
|
|
|
// 关闭任务
|
|
|
if task, err := offTaskService.Off(offTaskCommand.TaskId, offTaskCommand.Operator, offTaskCommand.OffReason); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -305,6 +334,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac |
|
|
if err := acceptanceTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -315,6 +345,8 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 验收服务初始化
|
|
|
var acceptanceTaskService service.AcceptanceTaskService
|
|
|
if value, err := factory.CreateAcceptanceTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -324,7 +356,50 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac |
|
|
acceptanceTaskService = value
|
|
|
acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
|
|
|
}
|
|
|
if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil {
|
|
|
|
|
|
// 员工仓储初始化
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
// 填充百分比员工信息
|
|
|
for i, taskPercentage := range acceptanceTaskCommand.TaskPercentage {
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": taskPercentage.Contributor.Uid,
|
|
|
}
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employeeFound == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
|
|
}
|
|
|
acceptanceTaskCommand.TaskPercentage[i].Contributor = employeeFound.EmployeeInfo
|
|
|
}
|
|
|
|
|
|
// 填充评分员工信息
|
|
|
for i, referenceResourceScore := range acceptanceTaskCommand.ReferenceResourceScore {
|
|
|
for j, solveScore := range referenceResourceScore.SolveScore {
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": solveScore.Contributor.Uid,
|
|
|
}
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employeeFound == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
|
|
}
|
|
|
acceptanceTaskCommand.ReferenceResourceScore[i].SolveScore[j].Contributor = employeeFound.EmployeeInfo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.SuMoney, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -336,10 +411,11 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac |
|
|
|
|
|
// 搜索任务
|
|
|
func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTaskCommand) (interface{}, error) {
|
|
|
if err := searchTaskCommand.ValidateCommand(); err != nil {
|
|
|
if err := searchTaskCommand.ValidateCommand(); err != nil { // 校验搜索命令
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil) // 工厂类创建事务上下文
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -349,6 +425,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -357,6 +434,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
var projectBelongRepository domain.ProjectBelongRepository
|
|
|
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -365,6 +443,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
} else {
|
|
|
projectBelongRepository = value
|
|
|
}
|
|
|
|
|
|
projectBelongMap := make(map[int]*domain.ProjectBelong)
|
|
|
if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchTaskCommand.CompanyId,
|
...
|
...
|
@@ -375,6 +454,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var customerValueRepository domain.CustomerValueRepository
|
|
|
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -383,6 +463,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
} else {
|
|
|
customerValueRepository = value
|
|
|
}
|
|
|
|
|
|
customerValueMap := make(map[int]*domain.CustomerValue)
|
|
|
if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchTaskCommand.CompanyId,
|
...
|
...
|
@@ -393,6 +474,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
customerValueMap[customerValue.CustomerValueId] = customerValue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var taskNatureRepository domain.TaskNatureRepository
|
|
|
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -401,6 +483,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
} else {
|
|
|
taskNatureRepository = value
|
|
|
}
|
|
|
|
|
|
taskNatureMap := make(map[int]*domain.TaskNature)
|
|
|
if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchTaskCommand.CompanyId,
|
...
|
...
|
@@ -411,6 +494,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask |
|
|
taskNatureMap[taskNature.TaskNatureId] = taskNature
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -437,6 +521,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
if err := searchOffTaskRecordCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -447,6 +532,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var projectBelongRepository domain.ProjectBelongRepository
|
|
|
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -455,6 +541,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
} else {
|
|
|
projectBelongRepository = value
|
|
|
}
|
|
|
|
|
|
projectBelongMap := make(map[int]*domain.ProjectBelong)
|
|
|
if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchOffTaskRecordCommand.CompanyId,
|
...
|
...
|
@@ -465,6 +552,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var customerValueRepository domain.CustomerValueRepository
|
|
|
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -473,6 +561,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
} else {
|
|
|
customerValueRepository = value
|
|
|
}
|
|
|
|
|
|
customerValueMap := make(map[int]*domain.CustomerValue)
|
|
|
if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchOffTaskRecordCommand.CompanyId,
|
...
|
...
|
@@ -483,6 +572,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
customerValueMap[customerValue.CustomerValueId] = customerValue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var taskNatureRepository domain.TaskNatureRepository
|
|
|
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -491,6 +581,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
} else {
|
|
|
taskNatureRepository = value
|
|
|
}
|
|
|
|
|
|
taskNatureMap := make(map[int]*domain.TaskNature)
|
|
|
if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchOffTaskRecordCommand.CompanyId,
|
...
|
...
|
@@ -501,6 +592,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
taskNatureMap[taskNature.TaskNatureId] = taskNature
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -509,6 +601,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
var offTaskRecordRepository domain.OffTaskRecordRepository
|
|
|
if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -517,6 +610,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * |
|
|
} else {
|
|
|
offTaskRecordRepository = value
|
|
|
}
|
|
|
|
|
|
_, tasks, err := taskRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchOffTaskRecordCommand.CompanyId,
|
|
|
"taskStatus": domain.TASK_STATUS_CLOSED,
|
...
|
...
|
@@ -570,6 +664,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge |
|
|
if err := getOffTaskRecordQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -580,6 +675,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var offTaskRecordRepository domain.OffTaskRecordRepository
|
|
|
if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -588,6 +684,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge |
|
|
} else {
|
|
|
offTaskRecordRepository = value
|
|
|
}
|
|
|
|
|
|
offTaskRecord, err := offTaskRecordRepository.FindOne(map[string]interface{}{"offTaskRecordId": getOffTaskRecordQuery.OffTaskRecordId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -607,6 +704,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
if err := searchRejectTaskRecordCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -617,6 +715,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var projectBelongRepository domain.ProjectBelongRepository
|
|
|
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -625,6 +724,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
} else {
|
|
|
projectBelongRepository = value
|
|
|
}
|
|
|
|
|
|
projectBelongMap := make(map[int]*domain.ProjectBelong)
|
|
|
if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchRejectTaskRecordCommand.CompanyId,
|
...
|
...
|
@@ -635,6 +735,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var customerValueRepository domain.CustomerValueRepository
|
|
|
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -643,6 +744,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
} else {
|
|
|
customerValueRepository = value
|
|
|
}
|
|
|
|
|
|
customerValueMap := make(map[int]*domain.CustomerValue)
|
|
|
if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchRejectTaskRecordCommand.CompanyId,
|
...
|
...
|
@@ -653,6 +755,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
customerValueMap[customerValue.CustomerValueId] = customerValue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var taskNatureRepository domain.TaskNatureRepository
|
|
|
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -661,6 +764,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
} else {
|
|
|
taskNatureRepository = value
|
|
|
}
|
|
|
|
|
|
taskNatureMap := make(map[int]*domain.TaskNature)
|
|
|
if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchRejectTaskRecordCommand.CompanyId,
|
...
|
...
|
@@ -671,6 +775,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
taskNatureMap[taskNature.TaskNatureId] = taskNature
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -679,6 +784,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
var rejectTaskRecordRepository domain.RejectTaskRecordRepository
|
|
|
if value, err := factory.CreateRejectTaskRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -687,6 +793,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
} else {
|
|
|
rejectTaskRecordRepository = value
|
|
|
}
|
|
|
|
|
|
_, tasks, err := taskRepository.Find(map[string]interface{}{
|
|
|
"companyId": searchRejectTaskRecordCommand.CompanyId,
|
|
|
"taskContentMatch": searchRejectTaskRecordCommand.TaskContentMatch,
|
...
|
...
|
@@ -702,6 +809,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom |
|
|
for _, task := range tasks {
|
|
|
taskIds = append(taskIds, task.TaskId)
|
|
|
}
|
|
|
|
|
|
if count, rejectTaskRecords, err := rejectTaskRecordRepository.Find(map[string]interface{}{
|
|
|
"taskIds": taskIds,
|
|
|
"rejectStartTime": searchRejectTaskRecordCommand.RejectStartTime,
|
...
|
...
|
@@ -739,6 +847,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu |
|
|
if err := getRejectTaskRecordQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -749,6 +858,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var rejectTaskRecordRepository domain.RejectTaskRecordRepository
|
|
|
if value, err := factory.CreateRejectTaskRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -757,6 +867,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu |
|
|
} else {
|
|
|
rejectTaskRecordRepository = value
|
|
|
}
|
|
|
|
|
|
rejectTaskRecord, err := rejectTaskRecordRepository.FindOne(map[string]interface{}{"rejectTaskRecordId": getRejectTaskRecordQuery.RejectTaskRecordId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -776,6 +887,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
if err := createTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -786,6 +898,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var taskDao *dao.TaskDao
|
|
|
if value, err := factory.CreateTaskDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -794,6 +907,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
} else {
|
|
|
taskDao = value
|
|
|
}
|
|
|
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -802,28 +916,54 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
} else {
|
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
sponsor, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": createTaskCommand.Sponsor,
|
|
|
"status": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if sponsor == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
|
|
|
// 获取无效的发布人员信息
|
|
|
sponsorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": createTaskCommand.AssignedPerson,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if sponsorInvalid == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
|
|
|
}
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者:"+ sponsorInvalid.EmployeeInfo.EmployeeName)
|
|
|
}
|
|
|
|
|
|
// 获取任务指派人
|
|
|
var assignedPerson *domain.EmployeeInfo
|
|
|
if createTaskCommand.AssignedPerson != 0 {
|
|
|
employee, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": createTaskCommand.AssignedPerson,
|
|
|
"status": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employee == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
|
|
|
// 获取无效的指派人员信息
|
|
|
employeeInvalid, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": createTaskCommand.AssignedPerson,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employeeInvalid == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
|
|
|
}
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员:" + employeeInvalid.EmployeeInfo.EmployeeName)
|
|
|
}
|
|
|
assignedPerson = employee.EmployeeInfo
|
|
|
}
|
|
|
|
|
|
newTask := &domain.Task{
|
|
|
TaskStatus: domain.TASK_STATUS_UNRELEASED,
|
|
|
CompanyId: createTaskCommand.CompanyId,
|
...
|
...
|
@@ -838,6 +978,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
CustomerValues: createTaskCommand.CustomerValues,
|
|
|
TaskNature: createTaskCommand.TaskNature,
|
|
|
SuMoney: createTaskCommand.SuMoney,
|
|
|
MinSuMoney: createTaskCommand.MinSuMoney,
|
|
|
MaxSuMoney: createTaskCommand.MaxSuMoney,
|
|
|
AcceptanceStandard: createTaskCommand.AcceptanceStandard,
|
|
|
TaskDescription: createTaskCommand.TaskDescription,
|
|
|
TaskPictureUrls: createTaskCommand.TaskPictureUrls,
|
...
|
...
|
@@ -846,6 +988,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
PlannedCompletionTime: createTaskCommand.PlannedCompletionTime,
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -854,6 +997,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
if createTaskCommand.ReferenceResourceItems != nil && len(createTaskCommand.ReferenceResourceItems) > 0 {
|
|
|
var referenceResourceIds []int64
|
|
|
for _, referenceResourceItem := range createTaskCommand.ReferenceResourceItems {
|
...
|
...
|
@@ -871,6 +1015,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if task, err := taskRepository.Save(newTask); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -908,6 +1053,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
if err := getTaskQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -918,6 +1064,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -926,6 +1073,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -941,6 +1089,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
} else {
|
|
|
projectBelongRepository = value
|
|
|
}
|
|
|
|
|
|
projectBelongMap := make(map[int]*domain.ProjectBelong)
|
|
|
if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
|
|
|
"companyId": task.CompanyId,
|
...
|
...
|
@@ -951,6 +1100,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var customerValueRepository domain.CustomerValueRepository
|
|
|
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -959,6 +1109,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
} else {
|
|
|
customerValueRepository = value
|
|
|
}
|
|
|
|
|
|
customerValueMap := make(map[int]*domain.CustomerValue)
|
|
|
if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
|
|
|
"companyId": task.CompanyId,
|
...
|
...
|
@@ -969,6 +1120,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
customerValueMap[customerValue.CustomerValueId] = customerValue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var taskNatureRepository domain.TaskNatureRepository
|
|
|
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -977,6 +1129,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
} else {
|
|
|
taskNatureRepository = value
|
|
|
}
|
|
|
|
|
|
taskNatureMap := make(map[int]*domain.TaskNature)
|
|
|
if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
|
|
|
"companyId": task.CompanyId,
|
...
|
...
|
@@ -987,6 +1140,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
taskNatureMap[taskNature.TaskNatureId] = taskNature
|
|
|
}
|
|
|
}
|
|
|
|
|
|
taskDto := &dto.TaskDto{}
|
|
|
if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -994,15 +1148,55 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 返回任务素币奖励范围
|
|
|
if taskDto.TaskStatus != 5 && task.MinSuMoney == 0 && task.MaxSuMoney == 0 {
|
|
|
taskDto.MinSuMoney = 0
|
|
|
taskDto.MaxSuMoney = task.SuMoney
|
|
|
}
|
|
|
|
|
|
return taskDto, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 更新过期任务状态
|
|
|
func (taskService *TaskService) UpdateTaskStatus() (interface{}, 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()
|
|
|
}()
|
|
|
|
|
|
var taskDao *dao.TaskDao
|
|
|
if value, err := factory.CreateTaskDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
taskDao = value
|
|
|
}
|
|
|
|
|
|
if err := taskDao.UpdateExpiredPlannedCompletionTimeBidTask(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 更新任务
|
|
|
func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) {
|
|
|
if err := updateTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -1013,6 +1207,7 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1021,6 +1216,7 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
var taskDao *dao.TaskDao
|
|
|
if value, err := factory.CreateTaskDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1029,13 +1225,34 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask |
|
|
} else {
|
|
|
taskDao = value
|
|
|
}
|
|
|
|
|
|
var releaseTaskService service.ReleaseTaskService
|
|
|
if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
releaseTaskService = value
|
|
|
releaseTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
|
|
|
releaseTaskService.Subscribe(&subscriber.MmmOpenApiServiceServiceSubscriber{
|
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
var taskBidEndTime time.Time
|
|
|
// 找到当前任务
|
|
|
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": updateTaskCommand.TaskId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if task == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskCommand.TaskId)))
|
|
|
} else {
|
|
|
if task.TaskStatus == domain.TASK_STATUS_EXPIRED {
|
|
|
taskBidEndTime = task.BidInfo.BidEndTime
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if updateTaskCommand.ReferenceResourceItems != nil && len(updateTaskCommand.ReferenceResourceItems) > 0 {
|
|
|
var referenceResourceIds []int64
|
|
|
for _, referenceResourceItem := range updateTaskCommand.ReferenceResourceItems {
|
...
|
...
|
@@ -1058,8 +1275,11 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
updateData := tool_funs.SimpleStructToMap(updateTaskCommand)
|
|
|
|
|
|
fmt.Println(updateTaskCommand.AssignedPerson != int64(0))
|
|
|
|
|
|
if task.TaskType == domain.TASK_TYPE_DESIGNATE {
|
|
|
if updateTaskCommand.AssignedPerson != int64(0) {
|
|
|
var employeeRepository domain.EmployeeRepository
|
...
|
...
|
@@ -1072,18 +1292,30 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask |
|
|
}
|
|
|
employee, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": updateTaskCommand.AssignedPerson,
|
|
|
"status": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employee == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
|
|
|
// 获取无效的发布人员信息
|
|
|
employeeInvalid, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": updateTaskCommand.AssignedPerson,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employeeInvalid == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
|
|
|
}
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员:" + employeeInvalid.EmployeeInfo.EmployeeName)
|
|
|
}
|
|
|
updateData["assignedPerson"] = employee.EmployeeInfo
|
|
|
} else {
|
|
|
updateData["assignedPerson"] = &domain.EmployeeInfo{}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := task.Update(updateData); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1095,6 +1327,18 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if task.TaskStatus == domain.TASK_STATUS_EXPIRED {
|
|
|
// 未修改时间或者修改的时间小于当前时间
|
|
|
if updateTaskCommand.BidEndTime.Local().Equal(taskBidEndTime.Local()) || updateTaskCommand.BidEndTime.Local().Before(time.Date(time.Now().Local().Year(), time.Now().Local().Month(), time.Now().Local().Day(), 23, 59, 59, 0, time.Local)) {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "请重新修改竞标时间")
|
|
|
} else {
|
|
|
if _, err := releaseTaskService.Release(task.TaskId, task.Sponsor.Uid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1124,6 +1368,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask |
|
|
if err := removeTaskCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -1134,6 +1379,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1142,6 +1388,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": removeTaskCommand.TaskId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1181,6 +1428,7 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in |
|
|
if err := listTaskQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -1191,6 +1439,7 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var taskRepository domain.TaskRepository
|
|
|
if value, err := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1199,15 +1448,24 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in |
|
|
} else {
|
|
|
taskRepository = value
|
|
|
}
|
|
|
|
|
|
if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(listTaskQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
var retTasks []*domain.Task
|
|
|
for _, task := range tasks {
|
|
|
if task.TaskStatus != 5 && task.MinSuMoney == 0 && task.MaxSuMoney == 0 {
|
|
|
task.MinSuMoney = 0
|
|
|
task.MaxSuMoney = task.SuMoney
|
|
|
}
|
|
|
retTasks = append(retTasks, task)
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"tasks": tasks,
|
|
|
"tasks": retTasks,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
|