作者 linmadan

重构任务验收方法

@@ -16,6 +16,8 @@ type AcceptanceTaskCommand struct { @@ -16,6 +16,8 @@ type AcceptanceTaskCommand struct {
16 Participators []int64 `json:"participators,omitempty"` 16 Participators []int64 `json:"participators,omitempty"`
17 // 任务贡献占比 17 // 任务贡献占比
18 TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"` 18 TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
  19 + // 引用资源解决分
  20 + ReferenceResourceScore []*domain.ReferenceResourceItem `json:"referenceResourceScore,omitempty"`
19 // 解决报告 21 // 解决报告
20 SolveReport string `json:"solveReport,omitempty"` 22 SolveReport string `json:"solveReport,omitempty"`
21 // 解决图片URL列表 23 // 解决图片URL列表
@@ -238,7 +238,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -238,7 +238,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
238 } else { 238 } else {
239 acceptanceTaskService = value 239 acceptanceTaskService = value
240 } 240 }
241 - if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil { 241 + if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil {
242 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 242 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
243 } else { 243 } else {
244 if err := transactionContext.CommitTransaction(); err != nil { 244 if err := transactionContext.CommitTransaction(); err != nil {
@@ -2,8 +2,16 @@ package domain @@ -2,8 +2,16 @@ package domain
2 2
3 // 引用资源项 3 // 引用资源项
4 type ReferenceResourceItem struct { 4 type ReferenceResourceItem struct {
  5 + // 引用资源ID
  6 + ReferenceResourceId int64 `json:"referenceResourceId"`
5 // 编号 7 // 编号
6 SerialNumber int64 `json:"serialNumber"` 8 SerialNumber int64 `json:"serialNumber"`
7 // 标题 9 // 标题
8 Title string `json:"title"` 10 Title string `json:"title"`
  11 + // 内容
  12 + Content string `json:"content"`
  13 + // 问题总分
  14 + IssueScore float64 `json:"issueScore"`
  15 + // 解决评分
  16 + SolveScore []*SolveScoreItem `json:"solveScore"`
9 } 17 }
@@ -3,5 +3,5 @@ package service @@ -3,5 +3,5 @@ package service
3 import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
4 4
5 type AcceptanceTaskService interface { 5 type AcceptanceTaskService interface {
6 - Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) 6 + Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string) (*domain.Task, error)
7 } 7 }
  1 +package domain
  2 +
  3 +// 解决评分项
  4 +type SolveScoreItem struct {
  5 + // 贡献者
  6 + Contributor *EmployeeInfo `json:"contributor"`
  7 + // 是否领取人
  8 + IsReceiver bool `json:"isReceiver"`
  9 + // 解决占比
  10 + Percentage int `json:"percentage"`
  11 + // 解决评分
  12 + Score float64 `json:"score"`
  13 +}
@@ -82,7 +82,7 @@ type TaskStatus interface { @@ -82,7 +82,7 @@ type TaskStatus interface {
82 ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error 82 ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error
83 ApplyComplete(task *Task) error 83 ApplyComplete(task *Task) error
84 Off(task *Task) error 84 Off(task *Task) error
85 - Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error 85 + Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error
86 } 86 }
87 87
88 type UnReleasedStatus struct{} 88 type UnReleasedStatus struct{}
@@ -156,7 +156,7 @@ func (status *UnReleasedStatus) Off(task *Task) error { @@ -156,7 +156,7 @@ func (status *UnReleasedStatus) Off(task *Task) error {
156 return fmt.Errorf("待发布的任务不允许关闭") 156 return fmt.Errorf("待发布的任务不允许关闭")
157 } 157 }
158 158
159 -func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { 159 +func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
160 return fmt.Errorf("待发布的任务不允许验收") 160 return fmt.Errorf("待发布的任务不允许验收")
161 } 161 }
162 162
@@ -234,7 +234,7 @@ func (status *UnClaimedStatus) Off(task *Task) error { @@ -234,7 +234,7 @@ func (status *UnClaimedStatus) Off(task *Task) error {
234 return nil 234 return nil
235 } 235 }
236 236
237 -func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { 237 +func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
238 return fmt.Errorf("待领取的任务不允许验收") 238 return fmt.Errorf("待领取的任务不允许验收")
239 } 239 }
240 240
@@ -272,7 +272,7 @@ func (status *UnderwayStatus) Off(task *Task) error { @@ -272,7 +272,7 @@ func (status *UnderwayStatus) Off(task *Task) error {
272 return nil 272 return nil
273 } 273 }
274 274
275 -func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { 275 +func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
276 return fmt.Errorf("进行中的任务不允许验收") 276 return fmt.Errorf("进行中的任务不允许验收")
277 } 277 }
278 278
@@ -308,11 +308,21 @@ func (status *UnAcceptanceStatus) Off(task *Task) error { @@ -308,11 +308,21 @@ func (status *UnAcceptanceStatus) Off(task *Task) error {
308 return nil 308 return nil
309 } 309 }
310 310
311 -func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { 311 +func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
312 task.Participators = participators 312 task.Participators = participators
313 task.TaskPercentage = taskPercentage 313 task.TaskPercentage = taskPercentage
314 task.SolveReport = solveReport 314 task.SolveReport = solveReport
315 task.SolvePictureUrls = solvePictureUrls 315 task.SolvePictureUrls = solvePictureUrls
  316 + if task.ReferenceResource != nil {
  317 + for _, referenceResourceItem := range task.ReferenceResource.ReferenceResourceItems {
  318 + for _, referenceResourceScoreItem := range referenceResourceScore {
  319 + if referenceResourceItem.ReferenceResourceId == referenceResourceScoreItem.ReferenceResourceId {
  320 + referenceResourceItem.IssueScore = referenceResourceScoreItem.IssueScore
  321 + referenceResourceItem.SolveScore = referenceResourceScoreItem.SolveScore
  322 + }
  323 + }
  324 + }
  325 + }
316 task.TaskStatus = TASK_STATUS_COMPLETED 326 task.TaskStatus = TASK_STATUS_COMPLETED
317 task.CurrentStatus = &CompletedStatus{} 327 task.CurrentStatus = &CompletedStatus{}
318 return nil 328 return nil
@@ -350,7 +360,7 @@ func (status *CompletedStatus) Off(task *Task) error { @@ -350,7 +360,7 @@ func (status *CompletedStatus) Off(task *Task) error {
350 return nil 360 return nil
351 } 361 }
352 362
353 -func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { 363 +func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
354 return fmt.Errorf("已完成的任务不允许验收") 364 return fmt.Errorf("已完成的任务不允许验收")
355 } 365 }
356 366
@@ -384,7 +394,7 @@ func (status *ClosedStatus) Off(task *Task) error { @@ -384,7 +394,7 @@ func (status *ClosedStatus) Off(task *Task) error {
384 return fmt.Errorf("已关闭的任务不允许关闭") 394 return fmt.Errorf("已关闭的任务不允许关闭")
385 } 395 }
386 396
387 -func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { 397 +func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
388 return fmt.Errorf("已关闭的任务不允许验收") 398 return fmt.Errorf("已关闭的任务不允许验收")
389 } 399 }
390 400
@@ -430,6 +440,6 @@ func (task *Task) Off() error { @@ -430,6 +440,6 @@ func (task *Task) Off() error {
430 return task.CurrentStatus.Off(task) 440 return task.CurrentStatus.Off(task)
431 } 441 }
432 442
433 -func (task *Task) Acceptance(participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {  
434 - return task.CurrentStatus.Acceptance(task, participators, taskPercentage, solveReport, solvePictureUrls) 443 +func (task *Task) Acceptance(participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
  444 + return task.CurrentStatus.Acceptance(task, participators, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls)
435 } 445 }
@@ -4,10 +4,10 @@ package domain @@ -4,10 +4,10 @@ package domain
4 type TaskPercentageItem struct { 4 type TaskPercentageItem struct {
5 // 贡献者 5 // 贡献者
6 Contributor *EmployeeInfo `json:"contributor"` 6 Contributor *EmployeeInfo `json:"contributor"`
  7 + // 是否领取人
  8 + IsReceiver bool `json:"isReceiver"`
7 // 任务贡献占比 9 // 任务贡献占比
8 Percentage int `json:"percentage"` 10 Percentage int `json:"percentage"`
9 // 分配到的奖励素币 11 // 分配到的奖励素币
10 SuMoney float64 `json:"suMoney"` 12 SuMoney float64 `json:"suMoney"`
11 - // 分配到的奖励素币  
12 - IssueScore float64 `json:"issueScore"`  
13 } 13 }
@@ -15,7 +15,7 @@ type AcceptanceTaskService struct { @@ -15,7 +15,7 @@ type AcceptanceTaskService struct {
15 transactionContext *pgTransaction.TransactionContext 15 transactionContext *pgTransaction.TransactionContext
16 } 16 }
17 17
18 -func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) { 18 +func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) {
19 var employeeRepository domain.EmployeeRepository 19 var employeeRepository domain.EmployeeRepository
20 var taskRepository domain.TaskRepository 20 var taskRepository domain.TaskRepository
21 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository 21 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
@@ -71,7 +71,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 @@ -71,7 +71,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
71 participatorInfos = append(participatorInfos, participator.EmployeeInfo) 71 participatorInfos = append(participatorInfos, participator.EmployeeInfo)
72 } 72 }
73 } 73 }
74 - if err := task.Acceptance(participatorInfos, taskPercentage, solveReport, solvePictureUrls); err != nil { 74 + if err := task.Acceptance(participatorInfos, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls); err != nil {
75 return nil, err 75 return nil, err
76 } 76 }
77 for _, taskPercentageItem := range taskPercentage { 77 for _, taskPercentageItem := range taskPercentage {
@@ -22,7 +22,17 @@ var _ = Describe("验收任务", func() { @@ -22,7 +22,17 @@ var _ = Describe("验收任务", func() {
22 "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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 22 "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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
23 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{ 23 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
24 Uid: 2499036607974745088, 24 Uid: 2499036607974745088,
25 - }, 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)) 25 + }, 4, &domain.ReferenceResource{
  26 + ReferenceResourceType: 1,
  27 + ReferenceResourceItems: []*domain.ReferenceResourceItem{
  28 + {
  29 + ReferenceResourceId: 1,
  30 + SerialNumber: 1,
  31 + Title: "问题1",
  32 + Content: "问题内容1",
  33 + },
  34 + },
  35 + }, pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
26 Expect(err).NotTo(HaveOccurred()) 36 Expect(err).NotTo(HaveOccurred())
27 _, err1 := pG.DB.QueryOne( 37 _, err1 := pG.DB.QueryOne(
28 pg.Scan(), 38 pg.Scan(),
@@ -65,6 +75,7 @@ var _ = Describe("验收任务", func() { @@ -65,6 +75,7 @@ var _ = Describe("验收任务", func() {
65 Contributor: &domain.EmployeeInfo{ 75 Contributor: &domain.EmployeeInfo{
66 Uid: 2499036607974745099, 76 Uid: 2499036607974745099,
67 }, 77 },
  78 + IsReceiver: true,
68 Percentage: 50, 79 Percentage: 50,
69 SuMoney: 500.00, 80 SuMoney: 500.00,
70 }, 81 },
@@ -83,6 +94,36 @@ var _ = Describe("验收任务", func() { @@ -83,6 +94,36 @@ var _ = Describe("验收任务", func() {
83 SuMoney: 250.00, 94 SuMoney: 250.00,
84 }, 95 },
85 }, 96 },
  97 + "referenceResourceScore": []*domain.ReferenceResourceItem{
  98 + {
  99 + ReferenceResourceId: 1,
  100 + IssueScore: 10,
  101 + SolveScore: []*domain.SolveScoreItem{
  102 + {
  103 + Contributor: &domain.EmployeeInfo{
  104 + Uid: 2499036607974745099,
  105 + },
  106 + IsReceiver: true,
  107 + Percentage: 50,
  108 + Score: 5,
  109 + },
  110 + {
  111 + Contributor: &domain.EmployeeInfo{
  112 + Uid: 2499036607974745077,
  113 + },
  114 + Percentage: 25,
  115 + Score: 2.5,
  116 + },
  117 + {
  118 + Contributor: &domain.EmployeeInfo{
  119 + Uid: 2499036607974745066,
  120 + },
  121 + Percentage: 25,
  122 + Score: 2.5,
  123 + },
  124 + },
  125 + },
  126 + },
86 "solveReport": "解决报告", 127 "solveReport": "解决报告",
87 "solvePictureUrls": []string{ 128 "solvePictureUrls": []string{
88 "url-1", 129 "url-1",
@@ -70,6 +70,27 @@ var _ = Describe("搜索任务", func() { @@ -70,6 +70,27 @@ var _ = Describe("搜索任务", func() {
70 ContainsKey("data").Value("data").Object() 70 ContainsKey("data").Value("data").Object()
71 }) 71 })
72 }) 72 })
  73 + Context("", func() {
  74 + It("", func() {
  75 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  76 + body := map[string]interface{}{
  77 + "companyId": 101,
  78 + "sponsor": 2499036607974745088,
  79 + "isFilterUnReleasedStatus": true,
  80 + "offset": 0,
  81 + "limit": 20,
  82 + }
  83 + httpExpect.POST("/tasks/search").
  84 + WithJSON(body).
  85 + Expect().
  86 + Status(http.StatusOK).
  87 + JSON().
  88 + Object().
  89 + ContainsKey("code").ValueEqual("code", 0).
  90 + ContainsKey("msg").ValueEqual("msg", "ok").
  91 + ContainsKey("data").Value("data").Object()
  92 + })
  93 + })
73 }) 94 })
74 AfterEach(func() { 95 AfterEach(func() {
75 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") 96 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true")