作者 linmadan

添加任务相关接口

正在显示 42 个修改的文件 包含 2504 行增加47 行删除
package factory
import (
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
)
func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewTaskDao(transactionContext)
}
... ...
package factory
import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
domainService "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/domain_service"
)
func CreateReleaseTaskService(options map[string]interface{}) (service.ReleaseTaskService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewReleaseTaskService(transactionContext)
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"github.com/astaxie/beego/validation"
)
type AcceptanceTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 操作人uid
Operator int64 `json:"operator" valid:"Required"`
// 任务参与者UID列表
Participators []int64 `json:"participators,omitempty"`
// 任务贡献占比
TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
// 解决报告
SolveReport string `json:"solveReport,omitempty"`
// 解决图片URL列表
SolvePictureUrls []string `json:"solvePictureUrls,omitempty"`
}
//func (acceptanceTaskCommand *AcceptanceTaskCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (acceptanceTaskCommand *AcceptanceTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(acceptanceTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ApplyCompleteTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 领取人或者中标人uid
Receiver int64 `json:"receiver" valid:"Required"`
}
//func (applyCompleteTaskCommand *ApplyCompleteTaskCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (applyCompleteTaskCommand *ApplyCompleteTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(applyCompleteTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type BidTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 竞标人uid
Bidder int64 `json:"bidder" valid:"Required"`
}
//func (bidTaskCommand *BidTaskCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (bidTaskCommand *BidTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(bidTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ChooseSuccessfulBidderCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 操作人uid
Operator int64 `json:"operator" valid:"Required"`
// 中标者uid
SuccessfulBidder int64 `json:"successfulBidder" valid:"Required"`
}
//func (chooseSuccessfulBidderCommand *ChooseSuccessfulBidderCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (chooseSuccessfulBidderCommand *ChooseSuccessfulBidderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(chooseSuccessfulBidderCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
"github.com/astaxie/beego/validation"
)
type CreateTaskCommand struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 任务名称
TaskName string `json:"taskName" valid:"Required"`
// 任务类型
TaskType int `json:"taskType" valid:"Required"`
// 任务发起者uid
Sponsor int64 `json:"sponsor" valid:"Required"`
// 引用类型
ReferenceResourceType int `json:"referenceResourceType,omitempty"`
// 引用资源项列表
ReferenceResourceItems []*domain.ReferenceResourceItem `json:"referenceResourceItems,omitempty"`
// 客户价值列表
CustomerValue []string `json:"customerValue" valid:"Required"`
// 任务性质
TaskNature string `json:"taskNature" valid:"Required"`
// 奖励素币
SuMoney float64 `json:"suMoney,omitempty"`
// 验收标准
AcceptanceStandard string `json:"acceptanceStandard" valid:"Required"`
// 任务描述
TaskDescription string `json:"taskDescription" valid:"Required"`
// 任务图片URL列表
TaskPictureUrls []string `json:"taskPictureUrls,omitempty"`
// 是否悬赏任务
IsRewardTake bool `json:"isRewardTake,omitempty"`
// 竞标开始时间
BidStartTime time.Time `json:"bidStartTime,omitempty"`
// 竞标结束时间
BidEndTime time.Time `json:"bidEndTime,omitempty"`
}
//func (createTaskCommand *CreateTaskCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (createTaskCommand *CreateTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type OffTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 操作人uid
Operator int64 `json:"operator" valid:"Required"`
// 关闭理由
OffReason string `json:"offReason" valid:"Required"`
}
//func (offTaskCommand *OffTaskCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (offTaskCommand *OffTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(offTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ReleaseTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 操作人uid
Operator int64 `json:"operator" valid:"Required"`
}
func (releaseTaskCommand *ReleaseTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(releaseTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RemoveTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
}
func (removeTaskCommand *RemoveTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RobTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 领取人uid
Receiver int64 `json:"receiver" valid:"Required"`
}
func (robTaskCommand *RobTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(robTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
"github.com/astaxie/beego/validation"
)
type UpdateTaskCommand struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
// 任务名称
TaskName string `json:"taskName,omitempty"`
// 引用类型
ReferenceResourceType int `json:"referenceResourceType,omitempty"`
// 引用资源项列表
ReferenceResourceItems []*domain.ReferenceResourceItem `json:"referenceResourceItems,omitempty"`
// 客户价值列表
CustomerValue []string `json:"customerValue,omitempty"`
// 任务性质
TaskNature string `json:"taskNature,omitempty"`
// 奖励素币
SuMoney float64 `json:"suMoney,omitempty"`
// 验收标准
AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
// 任务描述
TaskDescription string `json:"taskDescription,omitempty"`
// 任务图片URL列表
TaskPictureUrls []string `json:"taskPictureUrls,omitempty"`
// 是否悬赏任务
IsRewardTake bool `json:"isRewardTake,omitempty"`
// 竞标开始时间
BidStartTime time.Time `json:"bidStartTime,omitempty"`
// 竞标结束时间
BidEndTime time.Time `json:"bidEndTime,omitempty"`
}
//func (updateTaskCommand *UpdateTaskCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (updateTaskCommand *UpdateTaskCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateTaskCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetTaskQuery struct {
// 任务ID
TaskId int64 `json:"taskId" valid:"Required"`
}
func (getTaskQuery *GetTaskQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getTaskQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListTaskQuery struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 任务发起者
Sponsor int64 `json:"sponsor,omitempty"`
// 任务内容匹配
TaskContentMatch string `json:"taskContentMatch,omitempty"`
// 任务类型
TaskType int `json:"taskType,omitempty"`
// 统一用户UID
Uid int64 `json:"uid,omitempty"`
// 任务状态
TaskStatus int `json:"taskStatus,omitempty"`
// 客户价值
CustomerValue string `json:"customerValue,omitempty"`
// 任务性质
TaskNature string `json:"taskNature,omitempty"`
// 是否悬赏任务
IsRewardTake bool `json:"isRewardTake,omitempty"`
// 竞标时间(1全部,2已截止,3未截止)
BidTimeMatch int `json:"bidTimeMatch,omitempty"`
// 任务领取人
Receiver int64 `json:"receiver,omitempty"`
// 任务参与者
Participator int64 `json:"participator,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
Limit int `json:"limit,omitempty"`
}
func (listTaskQuery *ListTaskQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listTaskQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
// 任务服务
type TaskService struct {
}
// 对任务进行抢单
func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) (interface{}, error) {
if err := robTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 对任务进行竞标
func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) (interface{}, error) {
if err := bidTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 选择竞标任务的中标人
func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCommand *command.ChooseSuccessfulBidderCommand) (interface{}, error) {
if err := chooseSuccessfulBidderCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 申请完成任务
func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *command.ApplyCompleteTaskCommand) (interface{}, error) {
if err := applyCompleteTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 发布任务
func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseTaskCommand) (interface{}, error) {
if err := releaseTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 关闭任务
func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) (interface{}, error) {
if err := offTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 验收任务
func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.AcceptanceTaskCommand) (interface{}, error) {
if err := acceptanceTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 创建新任务
func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) {
if err := createTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, err
} else {
employeeRepository = value
}
sponsor, err := employeeRepository.FindOne(map[string]interface{}{
"uid": createTaskCommand.Sponsor,
})
if err != nil {
return nil, err
}
if sponsor == nil {
return nil, fmt.Errorf("无效的发布者")
}
var bidInfo *domain.BidInfo
if createTaskCommand.TaskType == domain.TASK_TYPE_BID {
bidInfo = &domain.BidInfo{
BidStartTime: createTaskCommand.BidStartTime,
BidEndTime: createTaskCommand.BidEndTime,
}
} else {
bidInfo = nil
}
newTask := &domain.Task{
TaskStatus: domain.TASK_STATUS_UNRELEASED,
CompanyId: createTaskCommand.CompanyId,
TaskName: createTaskCommand.TaskName,
TaskType: createTaskCommand.TaskType,
Sponsor: sponsor.EmployeeInfo,
ReferenceResource: &domain.ReferenceResource{
ReferenceResourceType: createTaskCommand.ReferenceResourceType,
ReferenceResourceItems: createTaskCommand.ReferenceResourceItems,
},
CustomerValue: createTaskCommand.CustomerValue,
TaskNature: createTaskCommand.TaskNature,
SuMoney: createTaskCommand.SuMoney,
AcceptanceStandard: createTaskCommand.AcceptanceStandard,
TaskDescription: createTaskCommand.TaskDescription,
TaskPictureUrls: createTaskCommand.TaskPictureUrls,
IsRewardTake: createTaskCommand.IsRewardTake,
BidInfo: bidInfo,
}
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskRepository = value
}
if task, err := taskRepository.Save(newTask); 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 task, nil
}
}
// 返回任务
func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (interface{}, error) {
if err := getTaskQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskRepository = value
}
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return task, nil
}
}
// 更新任务
func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) {
if err := updateTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskRepository = value
}
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": updateTaskCommand.TaskId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskCommand.TaskId)))
}
if err := task.Update(tool_funs.SimpleStructToMap(updateTaskCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if task, err := taskRepository.Save(task); 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 task, nil
}
}
// 移除任务
func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTaskCommand) (interface{}, error) {
if err := removeTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskRepository = value
}
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": removeTaskCommand.TaskId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeTaskCommand.TaskId)))
}
if task, err := taskRepository.Remove(task); 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 task, nil
}
}
// 返回任务列表
func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (interface{}, error) {
if err := listTaskQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskRepository = value
}
if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(listTaskQuery)); 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 map[string]interface{}{
"count": count,
"tasks": tasks,
}, nil
}
}
func NewTaskService(options map[string]interface{}) *TaskService {
newTaskService := &TaskService{}
return newTaskService
}
... ...
... ... @@ -5,7 +5,7 @@ import "time"
// 竞标任务信息
type BidInfo struct {
// 竞标人员列表
Bidders []*EmployeeInfo `json:"bidders"`
BidderInfos []*BidderInfo `json:"bidderInfos"`
// 中标人
SuccessfulBidder *EmployeeInfo `json:"successfulBidder"`
// 竞标开始时间
... ...
package domain
import "time"
// 竞标人员信息
type BidderInfo struct {
// 竞标人员
Bidder *EmployeeInfo `json:"bidder"`
// 竞标时间
BidTime time.Time `json:"bidTime"`
}
... ...
package service
import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
type ReleaseTaskService interface {
Release(taskId int64, operatorUid int64) (*domain.Task, error)
}
... ...
package domain
import "time"
import (
"fmt"
"time"
)
const (
TASK_TYPE_ROB = iota + 1 //抢单任务
TASK_TYPE_BID //竞标任务
)
const (
TASK_TYPE_TO_BE_RELEASED = iota + 1 //待发布
REFERENCE_RESOURCE_TYPE_ISSUE = iota + 1 //问题引用类型
REFERENCE_RESOURCE_TYPE_CHANCE //机会引用类型
)
const (
TASK_STATUS_UNRELEASED = iota + 1 //待发布
TASK_STATUS_UNCLAIMED //待领取
TASK_STATUS_UNDERWAY //进行中
TASK_STATUS_UNACCEPTANCE //待验收
TASK_STATUS_COMPLETED //已完成
TASK_STATUS_CLOSED //关闭
)
// 任务
type Task struct {
// 任务ID
TakeId int64 `json:"takeId"`
TaskId int64 `json:"taskId"`
// 公司ID
CompanyId int64 `json:"companyId"`
// 任务名称
TaskName string `json:"taskName"`
// 任务类型Type
... ... @@ -34,42 +54,48 @@ type Task struct {
TaskPictureUrls []string `json:"taskPictureUrls"`
// 是否悬赏任务
IsRewardTake bool `json:"isRewardTake"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 抢单任务信息
RobInfo *RobInfo `json:"robInfo"`
// 竞标任务信息
BidInfo *BidInfo `json:"bidInfo"`
// 任务参与者列表
Participants []*EmployeeInfo `json:"participants"`
Participators []*EmployeeInfo `json:"participators"`
// 任务贡献占比
TaskPercentage []*TaskPercentageItem `json:"taskPercentage"`
// 解决报告
SolveReport string `json:"solveReport"`
// 解决图片URL列表
SolvePictureUrls []string `json:"solvePictureUrls"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 发布时间
ReleaseTime time.Time `json:"releaseTime"`
//当前状态
CurrentStatus TaskStatus `json:"-"`
}
type TaskRepository interface {
Save(task *Task) (*Task, error)
Remove(task *Task) (*Task, error)
FindOne(queryOptions map[string]interface{}) (*Task, error)
Find(queryOptions map[string]interface{}) (int64, []*Task, error)
type TaskStatus interface {
Update(task *Task, data map[string]interface{}) error
Release(task *Task) error
Rob(task *Task, receiver *EmployeeInfo) error
Bib(task *Task, bidder *EmployeeInfo) error
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
}
func (task *Task) Identify() interface{} {
if task.TakeId == 0 {
return nil
}
return task.TakeId
}
type UnReleasedStatus struct{}
func (task *Task) Update(data map[string]interface{}) error {
func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) error {
if taskName, ok := data["taskName"]; ok {
task.TaskName = taskName.(string)
}
if taskType, ok := data["taskType"]; ok {
task.TaskType = taskType.(int)
if referenceResourceType, ok := data["referenceResourceType"]; ok {
task.ReferenceResource.ReferenceResourceType = referenceResourceType.(int)
}
if referenceResourceItems, ok := data["referenceResourceItems"]; ok {
task.ReferenceResource.ReferenceResourceItems = referenceResourceItems.([]*ReferenceResourceItem)
}
if customerValue, ok := data["customerValue"]; ok {
task.CustomerValue = customerValue.([]string)
... ... @@ -80,6 +106,14 @@ func (task *Task) Update(data map[string]interface{}) error {
if suMoney, ok := data["suMoney"]; ok {
task.SuMoney = suMoney.(float64)
}
if task.TaskType == TASK_TYPE_BID {
if bidStartTime, ok := data["bidStartTime"]; ok {
task.BidInfo.BidStartTime = bidStartTime.(time.Time)
}
if bidEndTime, ok := data["bidEndTime"]; ok {
task.BidInfo.BidEndTime = bidEndTime.(time.Time)
}
}
if acceptanceStandard, ok := data["acceptanceStandard"]; ok {
task.AcceptanceStandard = acceptanceStandard.(string)
}
... ... @@ -94,3 +128,308 @@ func (task *Task) Update(data map[string]interface{}) error {
}
return nil
}
func (status *UnReleasedStatus) Release(task *Task) error {
task.ReleaseTime = time.Now()
task.TaskStatus = TASK_STATUS_UNCLAIMED
task.CurrentStatus = &UnClaimedStatus{}
return nil
}
func (status *UnReleasedStatus) Rob(task *Task, receiver *EmployeeInfo) error {
return fmt.Errorf("待发布的任务不允许抢单")
}
func (status *UnReleasedStatus) Bib(task *Task, bidder *EmployeeInfo) error {
return fmt.Errorf("待发布的任务不允许竞标")
}
func (status *UnReleasedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error {
return fmt.Errorf("待发布的任务不允许选择竞标任务的中标人")
}
func (status *UnReleasedStatus) ApplyComplete(task *Task) error {
return fmt.Errorf("待发布的任务不允许申请完成任务")
}
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 {
return fmt.Errorf("待发布的任务不允许验收")
}
type UnClaimedStatus struct{}
func (status *UnClaimedStatus) Update(task *Task, data map[string]interface{}) error {
return fmt.Errorf("待领取的任务不允许编辑")
}
func (status *UnClaimedStatus) Release(task *Task) error {
return fmt.Errorf("待领取的任务不允许重新发布")
}
func (status *UnClaimedStatus) Rob(task *Task, receiver *EmployeeInfo) error {
if task.TaskType != TASK_TYPE_ROB {
return fmt.Errorf("类型不符合的任务不允许抢单")
}
task.RobInfo = &RobInfo{
Receiver: receiver,
ReceiveTime: time.Now(),
}
task.TaskStatus = TASK_STATUS_UNDERWAY
task.CurrentStatus = &UnderwayStatus{}
return nil
}
func (status *UnClaimedStatus) Bib(task *Task, bidder *EmployeeInfo) error {
if task.TaskType != TASK_TYPE_BID {
return fmt.Errorf("类型不符合的任务不允许竞标")
}
if task.BidInfo == nil {
return fmt.Errorf("无效的竞标信息")
} else {
bidTime := time.Now()
if bidTime.Before(task.BidInfo.BidStartTime) {
return fmt.Errorf("竞标还没开始")
}
if bidTime.After(task.BidInfo.BidEndTime) {
return fmt.Errorf("竞标已经结束")
}
task.BidInfo.BidderInfos = append(task.BidInfo.BidderInfos, &BidderInfo{
Bidder: bidder,
BidTime: bidTime,
})
return nil
}
}
func (status *UnClaimedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error {
if task.TaskType != TASK_TYPE_BID {
return fmt.Errorf("类型不符合的任务不允许选择竞中标人")
}
if task.BidInfo == nil {
return fmt.Errorf("无效的竞标信息")
} else {
winBidTime := time.Now()
if winBidTime.Before(task.BidInfo.BidEndTime) {
return fmt.Errorf("竞标还没有结束")
}
task.BidInfo.SuccessfulBidder = successfulBidder
task.BidInfo.WinBidTime = winBidTime
task.TaskStatus = TASK_STATUS_UNDERWAY
task.CurrentStatus = &UnderwayStatus{}
return nil
}
}
func (status *UnClaimedStatus) ApplyComplete(task *Task) error {
return fmt.Errorf("待领取的任务不允许申请完成任务")
}
func (status *UnClaimedStatus) Off(task *Task) error {
task.TaskStatus = TASK_STATUS_CLOSED
task.CurrentStatus = &ClosedStatus{}
return nil
}
func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("待领取的任务不允许验收")
}
type UnderwayStatus struct{}
func (status *UnderwayStatus) Update(task *Task, data map[string]interface{}) error {
return fmt.Errorf("进行中的任务不允许编辑")
}
func (status *UnderwayStatus) Release(task *Task) error {
return fmt.Errorf("进行中的任务不允许重新发布")
}
func (status *UnderwayStatus) Rob(task *Task, receiver *EmployeeInfo) error {
return fmt.Errorf("进行中的任务不允许抢单")
}
func (status *UnderwayStatus) Bib(task *Task, bidder *EmployeeInfo) error {
return fmt.Errorf("进行中的任务不允许竞标")
}
func (status *UnderwayStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error {
return fmt.Errorf("进行中的任务不允许选择竞标任务的中标人")
}
func (status *UnderwayStatus) ApplyComplete(task *Task) error {
task.TaskStatus = TASK_STATUS_UNACCEPTANCE
task.CurrentStatus = &UnAcceptanceStatus{}
return nil
}
func (status *UnderwayStatus) Off(task *Task) error {
task.TaskStatus = TASK_STATUS_CLOSED
task.CurrentStatus = &ClosedStatus{}
return nil
}
func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("进行中的任务不允许验收")
}
type UnAcceptanceStatus struct{}
func (status *UnAcceptanceStatus) Update(task *Task, data map[string]interface{}) error {
return fmt.Errorf("待验收的任务不允许编辑")
}
func (status *UnAcceptanceStatus) Release(task *Task) error {
return fmt.Errorf("待验收的任务不允许重新发布")
}
func (status *UnAcceptanceStatus) Rob(task *Task, receiver *EmployeeInfo) error {
return fmt.Errorf("待验收的任务不允许抢单")
}
func (status *UnAcceptanceStatus) Bib(task *Task, bidder *EmployeeInfo) error {
return fmt.Errorf("待验收的任务不允许竞标")
}
func (status *UnAcceptanceStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error {
return fmt.Errorf("待验收的任务不允许选择竞标任务的中标人")
}
func (status *UnAcceptanceStatus) ApplyComplete(task *Task) error {
return fmt.Errorf("待验收的任务不允许申请完成任务")
}
func (status *UnAcceptanceStatus) Off(task *Task) error {
task.TaskStatus = TASK_STATUS_CLOSED
task.CurrentStatus = &ClosedStatus{}
return nil
}
func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
task.Participators = participators
task.TaskPercentage = taskPercentage
task.SolveReport = solveReport
task.SolvePictureUrls = solvePictureUrls
task.TaskStatus = TASK_STATUS_COMPLETED
task.CurrentStatus = &CompletedStatus{}
return nil
}
type CompletedStatus struct{}
func (status *CompletedStatus) Update(task *Task, data map[string]interface{}) error {
return fmt.Errorf("已完成的任务不允许编辑")
}
func (status *CompletedStatus) Release(task *Task) error {
return fmt.Errorf("已完成的任务不允许重新发布")
}
func (status *CompletedStatus) Rob(task *Task, receiver *EmployeeInfo) error {
return fmt.Errorf("已完成的任务不允许抢单")
}
func (status *CompletedStatus) Bib(task *Task, bidder *EmployeeInfo) error {
return fmt.Errorf("已完成的任务不允许竞标")
}
func (status *CompletedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error {
return fmt.Errorf("已完成的任务不允许选择竞标任务的中标人")
}
func (status *CompletedStatus) ApplyComplete(task *Task) error {
return fmt.Errorf("已完成的任务不允许申请完成任务")
}
func (status *CompletedStatus) Off(task *Task) error {
task.TaskStatus = TASK_STATUS_CLOSED
task.CurrentStatus = &ClosedStatus{}
return nil
}
func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error {
return fmt.Errorf("已完成的任务不允许验收")
}
type ClosedStatus struct{}
func (status *ClosedStatus) Update(task *Task, data map[string]interface{}) error {
return fmt.Errorf("已关闭的任务不允许编辑")
}
func (status *ClosedStatus) Release(task *Task) error {
return fmt.Errorf("已关闭的任务不允许重新发布")
}
func (status *ClosedStatus) Rob(task *Task, receiver *EmployeeInfo) error {
return fmt.Errorf("已关闭的任务不允许抢单")
}
func (status *ClosedStatus) Bib(task *Task, bidder *EmployeeInfo) error {
return fmt.Errorf("已关闭的任务不允许竞标")
}
func (status *ClosedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error {
return fmt.Errorf("已关闭的任务不允许选择竞标任务的中标人")
}
func (status *ClosedStatus) ApplyComplete(task *Task) error {
return fmt.Errorf("已关闭的任务不允许申请完成任务")
}
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 {
return fmt.Errorf("已关闭的任务不允许验收")
}
type TaskRepository interface {
Save(task *Task) (*Task, error)
Remove(task *Task) (*Task, error)
FindOne(queryOptions map[string]interface{}) (*Task, error)
Find(queryOptions map[string]interface{}) (int64, []*Task, error)
}
func (task *Task) Identify() interface{} {
if task.TaskId == 0 {
return nil
}
return task.TaskId
}
func (task *Task) Update(data map[string]interface{}) error {
return task.CurrentStatus.Update(task, data)
}
func (task *Task) Release() error {
return task.CurrentStatus.Release(task)
}
func (task *Task) Rob(receiver *EmployeeInfo) error {
return task.CurrentStatus.Rob(task, receiver)
}
func (task *Task) Bib(bidder *EmployeeInfo) error {
return task.CurrentStatus.Bib(task, bidder)
}
func (task *Task) ChooseSuccessfulBidder(successfulBidder *EmployeeInfo) error {
return task.CurrentStatus.ChooseSuccessfulBidder(task, successfulBidder)
}
func (task *Task) ApplyComplete() error {
return task.CurrentStatus.ApplyComplete(task)
}
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)
}
... ...
package dao
import (
"fmt"
"time"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type TaskDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *TaskDao) addRobInfo(taskId int64, receiver *domain.EmployeeInfo) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?) RETURNING id",
taskId, receiver, time.Now())
return err
}
func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &TaskDao{
transactionContext: 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/repository"
)
type ReleaseTaskService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*domain.Task, error) {
var employeeRepository domain.EmployeeRepository
var taskRepository domain.TaskRepository
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
}
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.EmployeeId != task.Sponsor.Uid {
return nil, fmt.Errorf("无效的发布者")
}
if err := task.Release(); err != nil {
return nil, err
}
if task, err := taskRepository.Save(task); err != nil {
return nil, err
} else {
return task, nil
}
}
func NewReleaseTaskService(transactionContext *pgTransaction.TransactionContext) (*ReleaseTaskService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ReleaseTaskService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -24,6 +24,9 @@ func init() {
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{
(*models.Employee)(nil),
(*models.RobInfo)(nil),
(*models.BidderInfo)(nil),
(*models.BidInfo)(nil),
(*models.Task)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
... ...
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type BidInfo struct {
TableName string `pg:"bid_infos,alias:bid_info"`
Id int64 `pg:",pk"`
// 竞标人员列表
BidderInfos []*BidderInfo
// 中标人
SuccessfulBidder *domain.EmployeeInfo
// 竞标开始时间
BidStartTime time.Time
// 竞标结束时间
BidEndTime time.Time
// 中标时间
WinBidTime time.Time
TaskId int64 `pg:",unique"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type BidderInfo struct {
TableName string `pg:"bidder_infos,alias:bidder_info"`
Id int64 `pg:",pk"`
// 竞标人员
Bidder *domain.EmployeeInfo
// 竞标时间
BidTime time.Time
BidInfoId int64
TaskId int64
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type RobInfo struct {
TableName string `pg:"rob_infos,alias:rob_info"`
Id int64 `pg:",pk"`
// 领取人
Receiver *domain.EmployeeInfo
// 领取时间
ReceiveTime time.Time
TaskId int64 `pg:",unique"`
}
... ...
... ... @@ -9,6 +9,8 @@ type Task struct {
TableName string `pg:"tasks,alias:task"`
// 任务ID
Id int64 `pg:",pk"`
// 公司ID
CompanyId int64
// 任务名称
TaskName string
// 任务类型
... ... @@ -33,19 +35,20 @@ type Task struct {
TaskPictureUrls []string `pg:",array"`
// 是否悬赏任务
IsRewardTake bool
// 创建时间
CreateTime time.Time
// 抢单任务信息
RobInfo *domain.RobInfo
// 竞标任务信息
BidInfo *domain.BidInfo
// 任务参与者列表
Participants []*domain.EmployeeInfo
Participators []*domain.EmployeeInfo
// 任务贡献占比
TaskPercentage []*domain.TaskPercentageItem
// 解决报告
SolveReport string
// 解决图片URL列表
SolvePictureUrls []string `pg:",array"`
RemoveTime time.Time `pg:",soft_delete"`
SolvePictureUrls []string `pg:",array"`
// 抢单任务信息
RobInfo *RobInfo
// 竞标任务信息
BidInfo *BidInfo
// 创建时间
CreateTime time.Time
ReleaseTime time.Time
RemoveTime time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -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
... ...
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/service"
)
type TaskController struct {
beego.Controller
}
func (controller *TaskController) RobTask() {
taskService := service.NewTaskService(nil)
robTaskCommand := &command.RobTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), robTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
robTaskCommand.TaskId = taskId
data, err := taskService.RobTask(robTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) BidTask() {
taskService := service.NewTaskService(nil)
bidTaskCommand := &command.BidTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), bidTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
bidTaskCommand.TaskId = taskId
data, err := taskService.BidTask(bidTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) ApplyCompleteTask() {
taskService := service.NewTaskService(nil)
applyCompleteTaskCommand := &command.ApplyCompleteTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), applyCompleteTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
applyCompleteTaskCommand.TaskId = taskId
data, err := taskService.ApplyCompleteTask(applyCompleteTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) ReleaseTask() {
taskService := service.NewTaskService(nil)
releaseTaskCommand := &command.ReleaseTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), releaseTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
releaseTaskCommand.TaskId = taskId
data, err := taskService.ReleaseTask(releaseTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) ChooseSuccessfulBidder() {
taskService := service.NewTaskService(nil)
chooseSuccessfulBidderCommand := &command.ChooseSuccessfulBidderCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), chooseSuccessfulBidderCommand)
taskId, _ := controller.GetInt64(":taskId")
chooseSuccessfulBidderCommand.TaskId = taskId
data, err := taskService.ChooseSuccessfulBidder(chooseSuccessfulBidderCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) OffTask() {
taskService := service.NewTaskService(nil)
offTaskCommand := &command.OffTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), offTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
offTaskCommand.TaskId = taskId
data, err := taskService.OffTask(offTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) AcceptanceTask() {
taskService := service.NewTaskService(nil)
acceptanceTaskCommand := &command.AcceptanceTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), acceptanceTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
acceptanceTaskCommand.TaskId = taskId
data, err := taskService.AcceptanceTask(acceptanceTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) CreateTask() {
taskService := service.NewTaskService(nil)
createTaskCommand := &command.CreateTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createTaskCommand)
data, err := taskService.CreateTask(createTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) UpdateTask() {
taskService := service.NewTaskService(nil)
updateTaskCommand := &command.UpdateTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskCommand)
taskId, _ := controller.GetInt64(":taskId")
updateTaskCommand.TaskId = taskId
data, err := taskService.UpdateTask(updateTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) GetTask() {
taskService := service.NewTaskService(nil)
getTaskQuery := &query.GetTaskQuery{}
taskId, _ := controller.GetInt64(":taskId")
getTaskQuery.TaskId = taskId
data, err := taskService.GetTask(getTaskQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) RemoveTask() {
taskService := service.NewTaskService(nil)
removeTaskCommand := &command.RemoveTaskCommand{}
taskId, _ := controller.GetInt64(":taskId")
removeTaskCommand.TaskId = taskId
data, err := taskService.RemoveTask(removeTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) ListTask() {
taskService := service.NewTaskService(nil)
listTaskQuery := &query.ListTaskQuery{}
companyId, _ := controller.GetInt64("companyId")
listTaskQuery.CompanyId = companyId
sponsor, _ := controller.GetInt64("sponsor")
listTaskQuery.Sponsor = sponsor
taskContentMatch := controller.GetString("taskContentMatch")
listTaskQuery.TaskContentMatch = taskContentMatch
taskType, _ := controller.GetInt("taskType")
listTaskQuery.TaskType = taskType
taskStatus, _ := controller.GetInt("taskStatus")
listTaskQuery.TaskStatus = taskStatus
customerValue := controller.GetString("customerValue")
listTaskQuery.CustomerValue = customerValue
taskNature := controller.GetString("taskNature")
listTaskQuery.TaskNature = taskNature
isRewardTake, _ := controller.GetBool("isRewardTake")
listTaskQuery.IsRewardTake = isRewardTake
bidTimeMatch, _ := controller.GetInt("bidTimeMatch")
listTaskQuery.BidTimeMatch = bidTimeMatch
receiver, _ := controller.GetInt64("receiver")
listTaskQuery.Receiver = receiver
participator, _ := controller.GetInt64("participator")
listTaskQuery.Participator = participator
offset, _ := controller.GetInt("offset")
listTaskQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listTaskQuery.Limit = limit
data, err := taskService.ListTask(listTaskQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
)
func init() {
beego.Router("/tasks/:taskId/rob", &controllers.TaskController{}, "Post:RobTask")
beego.Router("/tasks/:taskId/bid", &controllers.TaskController{}, "Post:BidTask")
beego.Router("/tasks/:taskId/apply-complete", &controllers.TaskController{}, "Post:ApplyCompleteTask")
beego.Router("/tasks/:taskId/release", &controllers.TaskController{}, "Post:ReleaseTask")
beego.Router("/tasks/:taskId/choose-successful-bidder", &controllers.TaskController{}, "Post:ChooseSuccessfulBidder")
beego.Router("/tasks/:taskId/dff", &controllers.TaskController{}, "Post:OffTask")
beego.Router("/tasks/:taskId/acceptance", &controllers.TaskController{}, "Post:AcceptanceTask")
beego.Router("/tasks/", &controllers.TaskController{}, "Post:CreateTask")
beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Put:UpdateTask")
beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask")
beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask")
beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask")
}
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("验收任务", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
"participators": "array",
"taskPercentage": "array",
"solveReport": "string",
"solvePictureUrls": "array",
}
httpExpect.POST("/tasks/{taskId}/acceptance").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("申请完成任务", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"receiver": "int64",
}
httpExpect.POST("/tasks/{taskId}/apply-complete").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("对任务进行竞标", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"bidder": "int64",
}
httpExpect.POST("/tasks/{taskId}/bid").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("选择竞标任务的中标人", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
"successfulBidder": "int64",
}
httpExpect.POST("/tasks/{taskId}/choose-successful-bidder").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"github.com/go-pg/pg"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("创建新任务", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?)",
1, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据创建新任务", func() {
Context("提交正确的抢单类型任务数据", func() {
It("返回抢单类型任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"taskName": "抢单任务",
"taskType": 1,
"sponsor": 2499036607974745088,
"referenceResourceType": 1,
"referenceResourceItems": []map[string]interface{}{
{"serialNumber": 1, "title": "问题标题1"},
{"serialNumber": 2, "title": "问题标题2"},
{"serialNumber": 3, "title": "问题标题3"},
},
"customerValue": []string{
"口味",
"色泽",
"商务服务",
},
"taskNature": "线",
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": false,
}
httpExpect.POST("/tasks/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueNotEqual("taskId", BeZero())
})
})
Context("提交正确的竞标类型任务数据", func() {
It("返回竞标类型任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
dayAfter, _ := time.ParseDuration("72h")
body := map[string]interface{}{
"companyId": 101,
"taskName": "竞标任务",
"taskType": 2,
"sponsor": 2499036607974745088,
"referenceResourceType": 2,
"referenceResourceItems": []map[string]interface{}{
{"serialNumber": 1, "title": "机会标题1"},
{"serialNumber": 2, "title": "机会标题2"},
{"serialNumber": 3, "title": "机会标题3"},
},
"customerValue": []string{
"口味",
"色泽",
"商务服务",
},
"taskNature": "线",
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": true,
"bidStartTime": time.Now(),
"bidEndTime": time.Now().Add( dayAfter),
}
httpExpect.POST("/tasks/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueNotEqual("taskId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM employees WHERE true")
Expect(err1).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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() {
BeforeEach(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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据taskId参数返回任务", func() {
Context("传入有效的taskId", func() {
It("返回任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/1").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回任务列表", func() {
Context("传入有效的参数", func() {
It("返回任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", "int64").
WithQuery("sponsor", "int64").
WithQuery("taskContentMatch", "string").
WithQuery("taskType", "int").
WithQuery("taskStatus", "int").
WithQuery("customerValue", "string").
WithQuery("taskNature", "string").
WithQuery("isRewardTake", "boolean").
WithQuery("bidTimeMatch", "int").
WithQuery("receiver", "int64").
WithQuery("participator", "int64").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("tasks").Value("tasks").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("关闭任务", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
"offReason": "string",
}
httpExpect.POST("/tasks/{taskId}/dff").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("发布任务", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
}
httpExpect.POST("/tasks/{taskId}/release").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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() {
BeforeEach(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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除任务", func() {
Context("传入有效的taskId", func() {
It("返回被移除任务的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/tasks/1").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"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
BeforeEach(func() {
_, 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")
Expect(err).NotTo(HaveOccurred())
})
Describe("对任务进行抢单", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"receiver": "int64",
}
httpExpect.POST("/tasks/{taskId}/rob").
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")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
)
func TestTask(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port Task Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package task
import (
"github.com/go-pg/pg"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("更新任务", func() {
Describe("提交数据更新任务", func() {
Context("任务未发布状态下提交正确的任务数据", func() {
BeforeEach(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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "testTaskName", 1, "{}", 1, "{}", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
Expect(err).NotTo(HaveOccurred())
})
It("返回更新后的任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"taskName": "抢单任务",
"taskType": 1,
"sponsor": 2499036607974745088,
"referenceResourceType": 1,
"referenceResourceItems": []map[string]interface{}{
{"serialNumber": 1, "title": "问题标题1"},
{"serialNumber": 2, "title": "问题标题2"},
{"serialNumber": 3, "title": "问题标题3"},
},
"customerValue": []string{
"口味",
"色泽",
"商务服务",
},
"taskNature": "线",
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": false,
}
httpExpect.PUT("/tasks/1").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueEqual("taskId", 1)
})
})
Context("任务不在未发布状态下提交正确的任务数据", func() {
BeforeEach(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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
Expect(err).NotTo(HaveOccurred())
})
It("返回当前状态不能进行编辑操作的提示", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"taskName": "抢单任务",
"taskType": 1,
"sponsor": 2499036607974745088,
"referenceResourceType": 1,
"referenceResourceItems": []map[string]interface{}{
{"serialNumber": 1, "title": "问题标题1"},
{"serialNumber": 2, "title": "问题标题2"},
{"serialNumber": 3, "title": "问题标题3"},
},
"customerValue": []string{
"口味",
"色泽",
"商务服务",
},
"taskNature": "线",
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": false,
}
httpExpect.PUT("/tasks/1").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 506).
ContainsKey("msg").ValueEqual("msg", "业务逻辑错误:进行中的任务不允许编辑")
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...