...
|
...
|
@@ -24,21 +24,21 @@ func (repository *TaskRepository) nextIdentify() (int64, error) { |
|
|
func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
if task.Identify() == nil {
|
|
|
_, err := repository.nextIdentify()
|
|
|
takeId, err := repository.nextIdentify()
|
|
|
if err != nil {
|
|
|
return task, err
|
|
|
}
|
|
|
if _, err := tx.QueryOne(
|
|
|
pg.Scan(&task.TakeId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.RobInfo, &task.BidInfo, pg.Array(&task.Participants), pg.Array(&task.TaskPercentage), &task.SolveReport, pg.Array(&task.SolvePictureUrls)),
|
|
|
"INSERT INTO tasks (id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls",
|
|
|
task.TakeId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.RobInfo, task.BidInfo, pg.Array(task.Participants), pg.Array(task.TaskPercentage), task.SolveReport, pg.Array(task.SolvePictureUrls)); err != nil {
|
|
|
pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime, &task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls)),
|
|
|
"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls",
|
|
|
takeId, task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls)); err != nil {
|
|
|
return task, err
|
|
|
}
|
|
|
} else {
|
|
|
if _, err := tx.QueryOne(
|
|
|
pg.Scan(&task.TakeId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.RobInfo, &task.BidInfo, pg.Array(&task.Participants), pg.Array(&task.TaskPercentage), &task.SolveReport, pg.Array(&task.SolvePictureUrls)),
|
|
|
"UPDATE tasks SET task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, customer_value=?, task_nature=?, su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, create_time=?, rob_info=?, bid_info=?, participants=?, task_percentage=?, solve_report=?, solve_picture_urls=? WHERE id=? RETURNING id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls",
|
|
|
task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.RobInfo, task.BidInfo, pg.Array(task.Participants), pg.Array(task.TaskPercentage), task.SolveReport, pg.Array(task.SolvePictureUrls), task.Identify()); err != nil {
|
|
|
pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime,&task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls)),
|
|
|
"UPDATE tasks SET company_id=?, task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, customer_value=?, task_nature=?, su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, create_time=?, release_time=?, participators=?, task_percentage=?, solve_report=?, solve_picture_urls=? WHERE id=? RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls",
|
|
|
task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.Identify()); err != nil {
|
|
|
return task, err
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -56,7 +56,7 @@ func (repository *TaskRepository) Remove(task *domain.Task) (*domain.Task, error |
|
|
func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
taskModel := new(models.Task)
|
|
|
query := tx.Model(taskModel)
|
|
|
query := tx.Model(taskModel).Relation("RobInfo").Relation("BidInfo")
|
|
|
if taskId, ok := queryOptions["taskId"]; ok {
|
|
|
query = query.Where("task.id = ?", taskId)
|
|
|
}
|
...
|
...
|
@@ -66,8 +66,48 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( |
|
|
if taskModel.Id == 0 {
|
|
|
return nil, nil
|
|
|
} else {
|
|
|
//robInfo := &domain.RobInfo{
|
|
|
// Receiver: taskModel.RobInfo.Receiver,
|
|
|
// ReceiveTime: taskModel.RobInfo.ReceiveTime,
|
|
|
//}
|
|
|
//bidderInfos := make([]*domain.BidderInfo, len(taskModel.BidInfo.BidderInfos))
|
|
|
//for _, bidderInfo := range taskModel.BidInfo.BidderInfos {
|
|
|
// bidderInfos = append(bidderInfos, &domain.BidderInfo{
|
|
|
// Bidder: bidderInfo.Bidder,
|
|
|
// BidTime: bidderInfo.BidTime,
|
|
|
// })
|
|
|
//}
|
|
|
//bidInfo := &domain.BidInfo{
|
|
|
// BidderInfos: bidderInfos,
|
|
|
// BidStartTime: taskModel.BidInfo.BidStartTime,
|
|
|
// BidEndTime: taskModel.BidInfo.BidEndTime,
|
|
|
// SuccessfulBidder: taskModel.BidInfo.SuccessfulBidder,
|
|
|
// WinBidTime: taskModel.BidInfo.WinBidTime,
|
|
|
//}
|
|
|
var currentStatus domain.TaskStatus
|
|
|
switch taskModel.TaskStatus {
|
|
|
case domain.TASK_STATUS_UNRELEASED:
|
|
|
currentStatus = &domain.UnReleasedStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_UNCLAIMED:
|
|
|
currentStatus = &domain.UnClaimedStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_UNDERWAY:
|
|
|
currentStatus = &domain.UnderwayStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_UNACCEPTANCE:
|
|
|
currentStatus = &domain.UnAcceptanceStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_COMPLETED:
|
|
|
currentStatus = &domain.CompletedStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_CLOSED:
|
|
|
currentStatus = &domain.ClosedStatus{}
|
|
|
break
|
|
|
}
|
|
|
return &domain.Task{
|
|
|
TakeId: taskModel.Id,
|
|
|
TaskId: taskModel.Id,
|
|
|
CompanyId: taskModel.CompanyId,
|
|
|
TaskName: taskModel.TaskName,
|
|
|
TaskType: taskModel.TaskType,
|
|
|
Sponsor: taskModel.Sponsor,
|
...
|
...
|
@@ -81,12 +121,13 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( |
|
|
TaskPictureUrls: taskModel.TaskPictureUrls,
|
|
|
IsRewardTake: taskModel.IsRewardTake,
|
|
|
CreateTime: taskModel.CreateTime,
|
|
|
RobInfo: taskModel.RobInfo,
|
|
|
BidInfo: taskModel.BidInfo,
|
|
|
Participants: taskModel.Participants,
|
|
|
//RobInfo: robInfo,
|
|
|
//BidInfo: bidInfo,
|
|
|
Participators: taskModel.Participators,
|
|
|
TaskPercentage: taskModel.TaskPercentage,
|
|
|
SolveReport: taskModel.SolveReport,
|
|
|
SolvePictureUrls: taskModel.SolvePictureUrls,
|
|
|
CurrentStatus: currentStatus,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -94,7 +135,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int |
|
|
tx := repository.transactionContext.PgTx
|
|
|
var taskModels []*models.Task
|
|
|
var tasks []*domain.Task
|
|
|
query := tx.Model(&taskModels)
|
|
|
query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo")
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
...
|
...
|
@@ -115,8 +156,48 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int |
|
|
return 0, nil, err
|
|
|
} else {
|
|
|
for _, taskModel := range taskModels {
|
|
|
robInfo := &domain.RobInfo{
|
|
|
Receiver: taskModel.RobInfo.Receiver,
|
|
|
ReceiveTime: taskModel.RobInfo.ReceiveTime,
|
|
|
}
|
|
|
bidderInfos := make([]*domain.BidderInfo, len(taskModel.BidInfo.BidderInfos))
|
|
|
for _, bidderInfo := range taskModel.BidInfo.BidderInfos {
|
|
|
bidderInfos = append(bidderInfos, &domain.BidderInfo{
|
|
|
Bidder: bidderInfo.Bidder,
|
|
|
BidTime: bidderInfo.BidTime,
|
|
|
})
|
|
|
}
|
|
|
bidInfo := &domain.BidInfo{
|
|
|
BidderInfos: bidderInfos,
|
|
|
BidStartTime: taskModel.BidInfo.BidStartTime,
|
|
|
BidEndTime: taskModel.BidInfo.BidEndTime,
|
|
|
SuccessfulBidder: taskModel.BidInfo.SuccessfulBidder,
|
|
|
WinBidTime: taskModel.BidInfo.WinBidTime,
|
|
|
}
|
|
|
var currentStatus domain.TaskStatus
|
|
|
switch taskModel.TaskStatus {
|
|
|
case domain.TASK_STATUS_UNRELEASED:
|
|
|
currentStatus = &domain.UnReleasedStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_UNCLAIMED:
|
|
|
currentStatus = &domain.UnClaimedStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_UNDERWAY:
|
|
|
currentStatus = &domain.UnderwayStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_UNACCEPTANCE:
|
|
|
currentStatus = &domain.UnAcceptanceStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_COMPLETED:
|
|
|
currentStatus = &domain.CompletedStatus{}
|
|
|
break
|
|
|
case domain.TASK_STATUS_CLOSED:
|
|
|
currentStatus = &domain.ClosedStatus{}
|
|
|
break
|
|
|
}
|
|
|
tasks = append(tasks, &domain.Task{
|
|
|
TakeId: taskModel.Id,
|
|
|
TaskId: taskModel.Id,
|
|
|
CompanyId: taskModel.CompanyId,
|
|
|
TaskName: taskModel.TaskName,
|
|
|
TaskType: taskModel.TaskType,
|
|
|
Sponsor: taskModel.Sponsor,
|
...
|
...
|
@@ -130,12 +211,13 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int |
|
|
TaskPictureUrls: taskModel.TaskPictureUrls,
|
|
|
IsRewardTake: taskModel.IsRewardTake,
|
|
|
CreateTime: taskModel.CreateTime,
|
|
|
RobInfo: taskModel.RobInfo,
|
|
|
BidInfo: taskModel.BidInfo,
|
|
|
Participants: taskModel.Participants,
|
|
|
RobInfo: robInfo,
|
|
|
BidInfo: bidInfo,
|
|
|
Participators: taskModel.Participators,
|
|
|
TaskPercentage: taskModel.TaskPercentage,
|
|
|
SolveReport: taskModel.SolveReport,
|
|
|
SolvePictureUrls: taskModel.SolvePictureUrls,
|
|
|
CurrentStatus: currentStatus,
|
|
|
})
|
|
|
}
|
|
|
return int64(count), tasks, nil
|
...
|
...
|
|