作者 linmadan

完成选择竞标任务的中标人接口

... ... @@ -37,3 +37,11 @@ func CreateBidTaskService(options map[string]interface{}) (service.BidTaskServic
}
return domainService.NewBidTaskService(transactionContext)
}
func CreateChooseSuccessfulBidderService(options map[string]interface{}) (service.ChooseSuccessfulBidderService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewChooseSuccessfulBidderService(transactionContext)
}
... ...
... ... @@ -97,10 +97,22 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom
defer func() {
transactionContext.RollbackTransaction()
}()
var chooseSuccessfulBidderService service.ChooseSuccessfulBidderService
if value, err := factory.CreateChooseSuccessfulBidderService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
chooseSuccessfulBidderService = value
}
if task, err := chooseSuccessfulBidderService.Choose(chooseSuccessfulBidderCommand.TaskId, chooseSuccessfulBidderCommand.SuccessfulBidder, chooseSuccessfulBidderCommand.Operator); 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())
}
return nil, nil
return task, nil
}
}
// 申请完成任务
... ...
package service
import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
type ChooseSuccessfulBidderService interface {
Choose(taskId int64, successfulBidderUid int64, operatorUid int64) (*domain.Task, error)
}
... ...
... ... @@ -201,8 +201,6 @@ func (status *UnClaimedStatus) Bib(task *Task, bidder *EmployeeInfo) error {
Bidder: bidder,
BidTime: bidTime,
})
task.TaskStatus = TASK_STATUS_UNDERWAY
task.CurrentStatus = &UnderwayStatus{}
return nil
}
}
... ...
... ... @@ -26,7 +26,7 @@ func (dao *TaskDao) AddBidInfo(taskId int64, bidStartTime time.Time, bidEndTime
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
"INSERT INTO bid_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
taskId, bidStartTime, bidEndTime)
return err
}
... ... @@ -40,6 +40,15 @@ func (dao *TaskDao) AddBidderInfo(taskId int64, bidder *domain.EmployeeInfo) err
return err
}
func (dao *TaskDao) SetSuccessfulBidder(taskId int64, successfulBidder *domain.EmployeeInfo, winBidTime time.Time) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"UPDATE bid_infos SET successful_bidder=?, win_bid_time=? WHERE task_id=?",
successfulBidder, winBidTime, taskId)
return err
}
func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
package domain_service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
)
type ChooseSuccessfulBidderService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ChooseSuccessfulBidderService) Choose(taskId int64, successfulBidderUid int64, operatorUid int64) (*domain.Task, error) {
var employeeRepository domain.EmployeeRepository
var taskRepository domain.TaskRepository
var taskDao *dao.TaskDao
if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
return nil, err
} else {
employeeRepository = repository
}
if repository, err := repository.NewTaskRepository(service.transactionContext); err != nil {
return nil, err
} else {
taskRepository = repository
}
if dao, err := dao.NewTaskDao(service.transactionContext); err != nil {
return nil, err
} else {
taskDao = dao
}
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
if err != nil {
return nil, err
}
if operator == nil {
return nil, fmt.Errorf("无效的操作者")
}
task, err := taskRepository.FindOne(map[string]interface{}{
"taskId": taskId,
})
if err != nil {
return nil, err
}
if task == nil {
return nil, fmt.Errorf("无效的任务")
}
if operator.EmployeeInfo.Uid != task.Sponsor.Uid {
return nil, fmt.Errorf("无效的操作者")
}
successfulBidder, err := employeeRepository.FindOne(map[string]interface{}{
"uid": successfulBidderUid,
})
if err != nil {
return nil, err
}
if successfulBidder == nil {
return nil, fmt.Errorf("无效的中标人")
}
if err := task.ChooseSuccessfulBidder(successfulBidder.EmployeeInfo); err != nil {
return nil, err
}
if err := taskDao.SetSuccessfulBidder(taskId, task.BidInfo.SuccessfulBidder, task.BidInfo.WinBidTime); err != nil {
return nil, err
}
if task, err := taskRepository.Save(task); err != nil {
return nil, err
} else {
return task, nil
}
}
func NewChooseSuccessfulBidderService(transactionContext *pgTransaction.TransactionContext) (*ChooseSuccessfulBidderService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ChooseSuccessfulBidderService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -66,7 +66,7 @@ var _ = Describe("对任务进行竞标", func() {
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskStatus").ValueEqual("taskStatus", 3).
ContainsKey("taskStatus").ValueEqual("taskStatus", 2).
ContainsKey("bidInfo").Value("bidInfo").Object().
ContainsKey("bidderInfos").Value("bidderInfos").Array().Length().Equal(2)
})
... ...
package task
import (
"github.com/go-pg/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("选择竞标任务的中标人", func() {
var taskId int64
Describe("选择竞标任务的中标人", func() {
Context("任务发布者对已发布的竞标类型任务选择中标人", func() {
BeforeEach(func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
pg.Scan(&taskId),
"INSERT INTO tasks (task_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, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime")
pg.Scan(),
"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, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "竞标任务1", 2, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 2, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 0, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bid_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
1, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Date(2020, time.Month(4), 10, 8, 0, 0, 0, time.Now().Location()))
Expect(err3).NotTo(HaveOccurred())
_, err4 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bidder_infos (task_id, bidder) VALUES (?, ?)",
1, &domain.EmployeeInfo{
Uid: 2499036607974745099,
})
Describe("选择竞标任务的中标人", func() {
Context("", func() {
It("", func() {
Expect(err4).NotTo(HaveOccurred())
})
It("选择中标人成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
"successfulBidder": "int64",
"operator": 2499036607974745088,
"successfulBidder": 2499036607974745099,
}
httpExpect.POST("/tasks/{taskId}/choose-successful-bidder").
httpExpect.POST("/tasks/1/choose-successful-bidder").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -35,12 +68,22 @@ var _ = Describe("选择竞标任务的中标人", func() {
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
ContainsKey("data").Value("data").Object().
ContainsKey("taskStatus").ValueEqual("taskStatus", 3).
ContainsKey("bidInfo").Value("bidInfo").Object().
ContainsKey("successfulBidder").Value("successfulBidder").Object().
ContainsKey("uid").ValueEqual("uid", 2499036607974745099)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.Exec("DELETE FROM employees WHERE true")
Expect(err3).NotTo(HaveOccurred())
})
})
... ...