作者 linmadan

重构任务验收方法

... ... @@ -16,6 +16,8 @@ type AcceptanceTaskCommand struct {
Participators []int64 `json:"participators,omitempty"`
// 任务贡献占比
TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
// 引用资源解决分
ReferenceResourceScore []*domain.ReferenceResourceItem `json:"referenceResourceScore,omitempty"`
// 解决报告
SolveReport string `json:"solveReport,omitempty"`
// 解决图片URL列表
... ...
... ... @@ -238,7 +238,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
} else {
acceptanceTaskService = value
}
if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil {
if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -2,8 +2,16 @@ package domain
// 引用资源项
type ReferenceResourceItem struct {
// 引用资源ID
ReferenceResourceId int64 `json:"referenceResourceId"`
// 编号
SerialNumber int64 `json:"serialNumber"`
// 标题
Title string `json:"title"`
// 内容
Content string `json:"content"`
// 问题总分
IssueScore float64 `json:"issueScore"`
// 解决评分
SolveScore []*SolveScoreItem `json:"solveScore"`
}
... ...
... ... @@ -3,5 +3,5 @@ package service
import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
type AcceptanceTaskService interface {
Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, solveReport string, solvePictureUrls []string) (*domain.Task, error)
Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string) (*domain.Task, error)
}
... ...
package domain
// 解决评分项
type SolveScoreItem struct {
// 贡献者
Contributor *EmployeeInfo `json:"contributor"`
// 是否领取人
IsReceiver bool `json:"isReceiver"`
// 解决占比
Percentage int `json:"percentage"`
// 解决评分
Score float64 `json:"score"`
}
... ...
... ... @@ -82,7 +82,7 @@ type TaskStatus interface {
ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error
ApplyComplete(task *Task) error
Off(task *Task) error
Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error
Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error
}
type UnReleasedStatus struct{}
... ... @@ -156,7 +156,7 @@ func (status *UnReleasedStatus) Off(task *Task) error {
return fmt.Errorf("待发布的任务不允许关闭")
}
func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("待发布的任务不允许验收")
}
... ... @@ -234,7 +234,7 @@ func (status *UnClaimedStatus) Off(task *Task) error {
return nil
}
func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("待领取的任务不允许验收")
}
... ... @@ -272,7 +272,7 @@ func (status *UnderwayStatus) Off(task *Task) error {
return nil
}
func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("进行中的任务不允许验收")
}
... ... @@ -308,11 +308,21 @@ func (status *UnAcceptanceStatus) Off(task *Task) error {
return nil
}
func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
task.Participators = participators
task.TaskPercentage = taskPercentage
task.SolveReport = solveReport
task.SolvePictureUrls = solvePictureUrls
if task.ReferenceResource != nil {
for _, referenceResourceItem := range task.ReferenceResource.ReferenceResourceItems {
for _, referenceResourceScoreItem := range referenceResourceScore {
if referenceResourceItem.ReferenceResourceId == referenceResourceScoreItem.ReferenceResourceId {
referenceResourceItem.IssueScore = referenceResourceScoreItem.IssueScore
referenceResourceItem.SolveScore = referenceResourceScoreItem.SolveScore
}
}
}
}
task.TaskStatus = TASK_STATUS_COMPLETED
task.CurrentStatus = &CompletedStatus{}
return nil
... ... @@ -350,7 +360,7 @@ func (status *CompletedStatus) Off(task *Task) error {
return nil
}
func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("已完成的任务不允许验收")
}
... ... @@ -384,7 +394,7 @@ func (status *ClosedStatus) Off(task *Task) error {
return fmt.Errorf("已关闭的任务不允许关闭")
}
func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("已关闭的任务不允许验收")
}
... ... @@ -430,6 +440,6 @@ func (task *Task) Off() error {
return task.CurrentStatus.Off(task)
}
func (task *Task) Acceptance(participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
return task.CurrentStatus.Acceptance(task, participators, taskPercentage, solveReport, solvePictureUrls)
func (task *Task) Acceptance(participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
return task.CurrentStatus.Acceptance(task, participators, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls)
}
... ...
... ... @@ -4,10 +4,10 @@ package domain
type TaskPercentageItem struct {
// 贡献者
Contributor *EmployeeInfo `json:"contributor"`
// 是否领取人
IsReceiver bool `json:"isReceiver"`
// 任务贡献占比
Percentage int `json:"percentage"`
// 分配到的奖励素币
SuMoney float64 `json:"suMoney"`
// 分配到的奖励素币
IssueScore float64 `json:"issueScore"`
}
... ...
... ... @@ -15,7 +15,7 @@ type AcceptanceTaskService struct {
transactionContext *pgTransaction.TransactionContext
}
func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) {
func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) {
var employeeRepository domain.EmployeeRepository
var taskRepository domain.TaskRepository
var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
... ... @@ -71,7 +71,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
participatorInfos = append(participatorInfos, participator.EmployeeInfo)
}
}
if err := task.Acceptance(participatorInfos, taskPercentage, solveReport, solvePictureUrls); err != nil {
if err := task.Acceptance(participatorInfos, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls); err != nil {
return nil, err
}
for _, taskPercentageItem := range taskPercentage {
... ...
... ... @@ -22,7 +22,17 @@ var _ = Describe("验收任务", func() {
"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", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 4, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
}, 4, &domain.ReferenceResource{
ReferenceResourceType: 1,
ReferenceResourceItems: []*domain.ReferenceResourceItem{
{
ReferenceResourceId: 1,
SerialNumber: 1,
Title: "问题1",
Content: "问题内容1",
},
},
}, pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(),
... ... @@ -65,6 +75,7 @@ var _ = Describe("验收任务", func() {
Contributor: &domain.EmployeeInfo{
Uid: 2499036607974745099,
},
IsReceiver: true,
Percentage: 50,
SuMoney: 500.00,
},
... ... @@ -83,6 +94,36 @@ var _ = Describe("验收任务", func() {
SuMoney: 250.00,
},
},
"referenceResourceScore": []*domain.ReferenceResourceItem{
{
ReferenceResourceId: 1,
IssueScore: 10,
SolveScore: []*domain.SolveScoreItem{
{
Contributor: &domain.EmployeeInfo{
Uid: 2499036607974745099,
},
IsReceiver: true,
Percentage: 50,
Score: 5,
},
{
Contributor: &domain.EmployeeInfo{
Uid: 2499036607974745077,
},
Percentage: 25,
Score: 2.5,
},
{
Contributor: &domain.EmployeeInfo{
Uid: 2499036607974745066,
},
Percentage: 25,
Score: 2.5,
},
},
},
},
"solveReport": "解决报告",
"solvePictureUrls": []string{
"url-1",
... ...
... ... @@ -70,6 +70,27 @@ var _ = Describe("搜索任务", func() {
ContainsKey("data").Value("data").Object()
})
})
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"sponsor": 2499036607974745088,
"isFilterUnReleasedStatus": true,
"offset": 0,
"limit": 20,
}
httpExpect.POST("/tasks/search").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
... ...