作者 linmadan

重构任务排序,添加任务创建与发布时对引用资源的检查

... ... @@ -36,15 +36,17 @@ type SearchTaskCommand struct {
//是否过滤待发布状态任务
IsFilterUnReleasedStatus bool `json:"isFilterUnReleasedStatus,omitempty"`
//按创建任务时间排序(ASC,DESC)
SortByCreateTime int `json:"sortByCreateTime,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
//按发布任务时间排序(ASC,DESC)
SortByReleaseTime int `json:"sortByReleaseTime,omitempty"`
SortByReleaseTime string `json:"sortByReleaseTime,omitempty"`
//按领取任务时间排序(ASC,DESC)
SortByReceiveTime int `json:"sortByReceiveTime,omitempty"`
SortByReceiveTime string `json:"sortByReceiveTime,omitempty"`
//按完成任务操作时间排序(ASC,DESC)
SortByCompleteTime int `json:"sortByCompleteTime,omitempty"`
SortByCompleteTime string `json:"sortByCompleteTime,omitempty"`
//按验收方验收时间排序(ASC,DESC)
SortByAcceptanceTime int `json:"sortByAcceptanceTime,omitempty"`
SortByAcceptanceTime string `json:"sortByAcceptanceTime,omitempty"`
//按参与竞标时间排序(ASC,DESC)
SortByBidTime string `json:"sortByBidTime,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
... ...
... ... @@ -38,15 +38,17 @@ type ListTaskQuery struct {
//是否过滤待发布状态任务
IsFilterUnReleasedStatus bool `json:"isFilterUnReleasedStatus,omitempty"`
//按创建任务时间排序(ASC,DESC)
SortByCreateTime int `json:"sortByCreateTime,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
//按发布任务时间排序(ASC,DESC)
SortByReleaseTime int `json:"sortByReleaseTime,omitempty"`
SortByReleaseTime string `json:"sortByReleaseTime,omitempty"`
//按领取任务时间排序(ASC,DESC)
SortByReceiveTime int `json:"sortByReceiveTime,omitempty"`
SortByReceiveTime string `json:"sortByReceiveTime,omitempty"`
//按完成任务操作时间排序(ASC,DESC)
SortByCompleteTime int `json:"sortByCompleteTime,omitempty"`
SortByCompleteTime string `json:"sortByCompleteTime,omitempty"`
//按验收方验收时间排序(ASC,DESC)
SortByAcceptanceTime int `json:"sortByAcceptanceTime,omitempty"`
SortByAcceptanceTime string `json:"sortByAcceptanceTime,omitempty"`
//按参与竞标时间排序(ASC,DESC)
SortByBidTime string `json:"sortByBidTime,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
... ...
... ... @@ -470,6 +470,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
}
queryOptions := make(map[string]interface{})
queryOptions["referenceResourceIds"] = referenceResourceIds
queryOptions["isFilterCloseStatus"] = true
queryOptions["isFilterUnReleasedStatus"] = true
if count, _, err := taskRepository.Find(queryOptions); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -575,6 +577,8 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
}
queryOptions := make(map[string]interface{})
queryOptions["referenceResourceIds"] = referenceResourceIds
queryOptions["isFilterCloseStatus"] = true
queryOptions["isFilterUnReleasedStatus"] = true
if count, tasks, err := taskRepository.Find(queryOptions); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -360,13 +360,11 @@ func (status *CompletedStatus) ChooseSuccessfulBidder(task *Task, successfulBidd
}
func (status *CompletedStatus) ApplyComplete(task *Task) error {
return fmt.Errorf("已完成的任务不允许申请完成任务")
return fmt.Errorf("已完成的任务不允许关闭")
}
func (status *CompletedStatus) Off(task *Task) error {
task.TaskStatus = TASK_STATUS_CLOSED
task.CurrentStatus = &ClosedStatus{}
return nil
return fmt.Errorf("已完成的任务不允许申请完成任务")
}
func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string) error {
... ...
... ... @@ -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"
... ... @@ -49,6 +50,28 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do
if operator.EmployeeInfo.Uid != task.Sponsor.Uid {
return nil, fmt.Errorf("无效的发布者")
}
if task.ReferenceResource != nil && len(task.ReferenceResource.ReferenceResourceItems) > 0 {
var referenceResourceIds []int64
for _, referenceResourceItem := range task.ReferenceResource.ReferenceResourceItems {
referenceResourceIds = append(referenceResourceIds, referenceResourceItem.ReferenceResourceId)
}
queryOptions := make(map[string]interface{})
queryOptions["referenceResourceIds"] = referenceResourceIds
queryOptions["isFilterCloseStatus"] = true
queryOptions["isFilterUnReleasedStatus"] = true
if count, tasks, err := taskRepository.Find(queryOptions); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 1 {
return nil, fmt.Errorf("问题资源已经被引用,发布任务失败")
}
if count == 1 {
if tasks[0].TaskId != task.TaskId {
return nil, fmt.Errorf("问题资源已经被引用,发布任务失败")
}
}
}
}
if err := task.Release(); err != nil {
return nil, err
}
... ...
... ... @@ -200,6 +200,10 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
query = query.Order(fmt.Sprintf("task.complete_time %s", sortByCompleteTime.(string)))
} else if sortByAcceptanceTime, ok := queryOptions["sortByAcceptanceTime"]; ok && (sortByAcceptanceTime == "ASC" || sortByAcceptanceTime == "DESC") {
query = query.Order(fmt.Sprintf("task.acceptance_time %s", sortByAcceptanceTime.(string)))
} else if sortByBidTime, ok := queryOptions["sortByBidTime"]; ok && (sortByBidTime == "ASC" || sortByBidTime == "DESC") {
if bidder, ok := queryOptions["bidder"]; ok && (bidder != int64(0)) {
query = query.Order(fmt.Sprintf("bidder_info.bid_time %s", sortByBidTime.(string)))
}
} else {
query = query.Order("task.id DESC")
}
... ...
... ... @@ -24,7 +24,7 @@ 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, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
2, 101, "抢单任务2", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, &domain.ReferenceResource{
}, 2, &domain.ReferenceResource{
ReferenceResourceType: 1,
ReferenceResourceItems: []*domain.ReferenceResourceItem{
{
... ...
... ... @@ -21,7 +21,14 @@ 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,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
}, 1, &domain.ReferenceResource{
ReferenceResourceType: 1,
ReferenceResourceItems: []*domain.ReferenceResourceItem{
{
ReferenceResourceId: 4,
},
},
}, pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
... ... @@ -59,7 +66,7 @@ var _ = Describe("发布任务", func() {
_, err := pG.DB.QueryOne(
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",1, &domain.EmployeeInfo{
1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 3, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
... ... @@ -91,6 +98,72 @@ var _ = Describe("发布任务", func() {
ContainsKey("msg").ValueEqual("msg", "内部服务出错:进行中的任务不允许重新发布")
})
})
Context("发布资源已经被引用的的任务", func() {
BeforeEach(func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
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", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 2, &domain.ReferenceResource{
ReferenceResourceType: 1,
ReferenceResourceItems: []*domain.ReferenceResourceItem{
{
ReferenceResourceId: 4,
},
},
}, pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?)",
1, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.QueryOne(
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
2, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 2, &domain.ReferenceResource{
ReferenceResourceType: 1,
ReferenceResourceItems: []*domain.ReferenceResourceItem{
{
ReferenceResourceId: 4,
},
},
}, pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err2).NotTo(HaveOccurred())
})
It("发布任务失败", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": 2499036607974745088,
}
httpExpect.POST("/tasks/1/release").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 501).
ContainsKey("msg").ValueEqual("msg", "内部服务出错:问题资源已经被引用,发布任务失败")
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
... ...
... ... @@ -46,8 +46,34 @@ var _ = Describe("搜索任务", func() {
_, 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.Now().Add(dayAfter))
3, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Now().Add(dayAfter))
Expect(err3).NotTo(HaveOccurred())
_, err4 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bidder_infos (id, bid_info_id, bidder, bid_time, task_id) VALUES (?, ?, ?, ?, ?)",
1, 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), 3)
Expect(err4).NotTo(HaveOccurred())
_, err5 := pG.DB.QueryOne(
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, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
Expect(err5).NotTo(HaveOccurred())
_, err6 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bid_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
4, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Now().Add(dayAfter))
Expect(err6).NotTo(HaveOccurred())
_, err7 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bidder_infos (id, bid_info_id, bidder, bid_time, task_id) VALUES (?, ?, ?, ?, ?)",
2, 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, time.Date(2020, time.Month(5), 5, 8, 0, 0, 0, time.Now().Location()), 4)
Expect(err7).NotTo(HaveOccurred())
})
Describe("搜索任务", func() {
Context("", func() {
... ... @@ -117,6 +143,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,
"bidder": 2499036607974745088,
"sortByBidTime": "ASC",
"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")
... ...