作者 陈志颖

refactor:限制离职人员操作任务

... ... @@ -26,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())
... ... @@ -36,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,
... ... @@ -47,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 {
... ... @@ -62,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())
... ... @@ -72,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,
... ... @@ -83,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 {
... ... @@ -98,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())
... ... @@ -108,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,
... ... @@ -120,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 {
... ... @@ -135,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())
... ... @@ -145,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,
... ... @@ -153,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 {
... ... @@ -168,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())
... ... @@ -178,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,
... ... @@ -187,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 {
... ... @@ -202,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())
... ... @@ -212,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,
... ... @@ -220,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 {
... ... @@ -247,6 +265,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
transactionContext.RollbackTransaction()
}()
// 发布任务服务初始化
var releaseTaskService service.ReleaseTaskService
if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -260,6 +279,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
})
}
// 关闭任务
if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -275,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())
... ... @@ -285,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,
... ... @@ -294,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 {
... ... @@ -356,6 +381,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
}
acceptanceTaskCommand.TaskPercentage[i].Contributor = employeeFound.EmployeeInfo
}
// 填充评分员工信息
for i, referenceResourceScore := range acceptanceTaskCommand.ReferenceResourceScore {
for j, solveScore := range referenceResourceScore.SolveScore {
... ... @@ -495,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())
... ... @@ -505,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,
... ... @@ -513,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,
... ... @@ -523,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,
... ... @@ -531,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,
... ... @@ -541,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,
... ... @@ -549,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,
... ... @@ -559,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,
... ... @@ -567,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,
... ... @@ -575,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,
... ... @@ -628,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())
... ... @@ -638,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,
... ... @@ -646,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())
... ... @@ -665,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())
... ... @@ -675,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,
... ... @@ -683,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,
... ... @@ -693,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,
... ... @@ -701,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,
... ... @@ -711,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,
... ... @@ -719,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,
... ... @@ -729,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,
... ... @@ -737,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,
... ... @@ -745,6 +793,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
} else {
rejectTaskRecordRepository = value
}
_, tasks, err := taskRepository.Find(map[string]interface{}{
"companyId": searchRejectTaskRecordCommand.CompanyId,
"taskContentMatch": searchRejectTaskRecordCommand.TaskContentMatch,
... ... @@ -760,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,
... ... @@ -797,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())
... ... @@ -807,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,
... ... @@ -815,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())
... ... @@ -834,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())
... ... @@ -844,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,
... ... @@ -852,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,
... ... @@ -860,29 +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,
... ... @@ -907,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,
... ... @@ -915,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 {
... ... @@ -932,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 {
... ... @@ -969,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())
... ... @@ -979,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,
... ... @@ -987,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())
... ... @@ -1002,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,
... ... @@ -1012,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,
... ... @@ -1020,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,
... ... @@ -1030,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,
... ... @@ -1038,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,
... ... @@ -1048,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())
... ... @@ -1055,11 +1148,13 @@ 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
}
}
... ... @@ -1262,6 +1357,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())
... ... @@ -1272,6 +1368,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,
... ... @@ -1280,6 +1377,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())
... ... @@ -1319,6 +1417,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())
... ... @@ -1329,6 +1428,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,
... ... @@ -1337,6 +1437,7 @@ 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 {
... ...
... ... @@ -2,6 +2,7 @@ package domain_service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
... ... @@ -20,7 +21,6 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
var employeeRepository domain.EmployeeRepository
var taskRepository domain.TaskRepository
var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
//var cashPoolRepository domain.CashPoolRepository
var employeeDao *dao.EmployeeDao
if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
... ... @@ -38,11 +38,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
} else {
suMoneyTransactionRecordRepository = repository
}
//if repository, err := repository.NewCashPoolRepository(service.transactionContext); err != nil {
// return nil, err
//} else {
// cashPoolRepository = repository
//}
if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil {
return nil, err
} else {
... ... @@ -51,12 +47,23 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
"status": 1,
})
if err != nil {
return nil, err
}
if operator == nil {
return nil, fmt.Errorf("无效的操作者")
// 获取无效的发布人员信息
operatorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if operatorInvalid == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的操作者")
}
return nil, fmt.Errorf("无效的操作者:" + operatorInvalid.EmployeeInfo.EmployeeName)
}
task, err := taskRepository.FindOne(map[string]interface{}{
"taskId": taskId,
... ... @@ -73,11 +80,22 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
for _, participatorUid := range participators {
if participator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": participatorUid,
"status": 1,
}); err != nil {
return nil, err
} else {
if participator == nil {
return nil, fmt.Errorf("无效的参与人")
// 获取无效的发布人员信息
participatorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
"uid": participatorUid,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if participatorInvalid == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的参与人")
}
return nil, fmt.Errorf("无效的参与人:" + participatorInvalid.EmployeeInfo.EmployeeName)
}
participatorMap[participator.EmployeeInfo.Uid] = participator
participatorInfos = append(participatorInfos, participator.EmployeeInfo)
... ... @@ -102,12 +120,23 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
if taskPercentageItem.IsReceiver {
receiver, err := employeeRepository.FindOne(map[string]interface{}{
"uid": taskPercentageItem.Contributor.Uid,
"status": 1,
})
if err != nil {
return nil, err
}
if receiver == nil {
return nil, fmt.Errorf("无效的任务领取者")
// 获取无效的任务领取人员信息
receiverInvalid, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if receiverInvalid == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的任务领取者")
}
return nil, fmt.Errorf("无效的任务领取者:" + receiverInvalid.EmployeeInfo.EmployeeName)
}
employee = receiver
} else {
... ... @@ -133,41 +162,6 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, taskPercentageItem.SuMoney); err != nil {
return nil, err
}
//// 更新现金池未兑换素币
//cashPoolFound, err := cashPoolRepository.FindOne(map[string]interface{}{
// "companyId": task.CompanyId,
//})
//if err != nil {
// return nil, err
//}
//if cashPoolFound != nil {
// // 获取平台素币兑换情况
// systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(task.CompanyId)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if systemSuMoneyStatistics == nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
// }
// systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
// cashPool := &domain.CashPool{
// Cash: cashPoolFound.Cash,
// CompanyId: cashPoolFound.CompanyId,
// ExchangedCash: cashPoolFound.ExchangedCash,
// UnExchangeCash: cashPoolFound.UnExchangeCash,
// ExchangedSuMoney: cashPoolFound.ExchangedSuMoney,
// UnExchangeSuMoney: systemUnExchangeSuMoney,
// Rate: cashPoolFound.Rate,
// LastRate: cashPoolFound.LastRate,
// }
// if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(cashPool)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if _, err := cashPoolRepository.Save(cashPool); err != nil {
// return nil, err
// }
//}
}
if task, err := taskRepository.Save(task); err != nil {
return nil, err
... ...
... ... @@ -31,12 +31,23 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do
}
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
"status": 1,
})
if err != nil {
return nil, err
}
if operator == nil {
return nil, fmt.Errorf("无效的发布者")
// 获取无效的发布人员信息
operatorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if operatorInvalid == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
}
return nil, fmt.Errorf("无效的发布者:" + operatorInvalid.EmployeeInfo.EmployeeName)
}
task, err := taskRepository.FindOne(map[string]interface{}{
"taskId": taskId,
... ...