作者 linmadan

完成任务关闭接口

... ... @@ -13,3 +13,11 @@ func CreateReleaseTaskService(options map[string]interface{}) (service.ReleaseTa
}
return domainService.NewReleaseTaskService(transactionContext)
}
func CreateOffTaskService(options map[string]interface{}) (service.OffTaskService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewOffTaskService(transactionContext)
}
... ...
... ... @@ -21,3 +21,11 @@ func CreateTaskRepository(options map[string]interface{}) (domain.TaskRepository
}
return repository.NewTaskRepository(transactionContext)
}
func CreateOffTaskRecordRepository(options map[string]interface{}) (domain.OffTaskRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewOffTaskRecordRepository(transactionContext)
}
... ...
package command
import (
"fmt"
"time"
"github.com/astaxie/beego/validation"
)
type SearchOffTaskRecordCommand struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 任务内容匹配
TaskContentMatch string `json:"taskContentMatch,omitempty"`
// 任务类型
TaskType int `json:"taskType,omitempty"`
// 客户价值
CustomerValue string `json:"customerValue,omitempty"`
// 任务性质
TaskNature string `json:"taskNature,omitempty"`
// 关闭任务时间区间-开始时间
OffStartTime time.Time `json:"offStartTime,omitempty"`
// 关闭任务时间区间-截止时间
OffEndTime time.Time `json:"offEndTime,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
Limit int `json:"limit,omitempty"`
}
func (searchOffTaskRecordCommand *SearchOffTaskRecordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(searchOffTaskRecordCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -147,10 +147,22 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand)
defer func() {
transactionContext.RollbackTransaction()
}()
var offTaskService service.OffTaskService
if value, err := factory.CreateOffTaskService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
offTaskService = value
}
if task, err := offTaskService.Off(offTaskCommand.TaskId, offTaskCommand.Operator, offTaskCommand.OffReason); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return task, nil
}
}
// 验收任务
... ... @@ -210,6 +222,42 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
}
}
// 搜索关闭任务记录
func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecord *command.SearchTaskCommand) (interface{}, error) {
if err := searchOffTaskRecord.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
}
if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchOffTaskRecord)); 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 (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) {
if err := createTaskCommand.ValidateCommand(); err != nil {
... ...
... ... @@ -4,10 +4,14 @@ package domain
type Employee struct {
// 员工ID
EmployeeId int64 `json:"employeeId"`
// 公司ID
CompanyId int64 `json:"companyId"`
// 员工信息
EmployeeInfo *EmployeeInfo `json:"employeeInfo"`
// 当前素币
SuMoney float64 `json:"suMoney"`
// 员工状态(启用或者禁用)
Status int `json:"status"`
}
type EmployeeRepository interface {
... ... @@ -31,6 +35,9 @@ func (employee *Employee) Update(data map[string]interface{}) error {
if employeeAccount, ok := data["employeeAccount"]; ok {
employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string)
}
if status, ok := data["status"]; ok {
employee.Status = status.(int)
}
return nil
}
... ...
package domain
import "time"
// 关闭任务记录
type OffTaskRecord struct {
// 关闭任务记录ID
OffTaskRecordId int64 `json:"offTaskRecordId"`
// 任务
Task *Task `json:"task"`
// 操作人
Operator *EmployeeInfo `json:"operator"`
// 关闭理由
OffReason string `json:"offReason"`
// 创建时间
CreateTime time.Time `json:"createTime"`
}
type OffTaskRecordRepository interface {
Save(offTaskRecord *OffTaskRecord) (*OffTaskRecord, error)
Remove(offTaskRecord *OffTaskRecord) (*OffTaskRecord, error)
FindOne(queryOptions map[string]interface{}) (*OffTaskRecord, error)
Find(queryOptions map[string]interface{}) (int64, []*OffTaskRecord, error)
}
func (offTaskRecord *OffTaskRecord) Identify() interface{} {
if offTaskRecord.OffTaskRecordId == 0 {
return nil
}
return offTaskRecord.OffTaskRecordId
}
func (offTaskRecord *OffTaskRecord) Update(data map[string]interface{}) error {
if offReason, ok := data["offReason"]; ok {
offTaskRecord.OffReason = offReason.(string)
}
return nil
}
... ...
package service
import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
type OffTaskService interface {
Off(taskId int64, operatorUid int64, offReason string) (*domain.Task, error)
}
... ...
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"
"time"
)
type OffTaskService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *OffTaskService) Off(taskId int64, operatorUid int64, offReason string) (*domain.Task, error) {
var employeeRepository domain.EmployeeRepository
var taskRepository domain.TaskRepository
var offTaskRecordRepository domain.OffTaskRecordRepository
if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
return nil, err
} else {
employeeRepository = repository
}
if repository, err := repository.NewTaskRepository(service.transactionContext); err != nil {
return nil, err
} else {
taskRepository = repository
}
if repository, err := repository.NewOffTaskRecordRepository(service.transactionContext); err != nil {
return nil, err
} else {
offTaskRecordRepository = 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.EmployeeInfo.Uid != task.Sponsor.Uid {
return nil, fmt.Errorf("无效的操作者")
}
if err := task.Off(); err != nil {
return nil, err
}
offTaskRecord := &domain.OffTaskRecord{
Task: task,
Operator: operator.EmployeeInfo,
OffReason: offReason,
CreateTime: time.Now(),
}
if _, err := offTaskRecordRepository.Save(offTaskRecord); err != nil {
return nil, err
}
if task, err := taskRepository.Save(task); err != nil {
return nil, err
} else {
return task, nil
}
}
func NewOffTaskService(transactionContext *pgTransaction.TransactionContext) (*OffTaskService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OffTaskService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -28,6 +28,7 @@ func init() {
(*models.BidderInfo)(nil),
(*models.BidInfo)(nil),
(*models.Task)(nil),
(*models.OffTaskRecord)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
... ... @@ -4,6 +4,8 @@ type Employee struct {
TableName string `pg:"employees,alias:employee"`
// 员工ID
Id int64 `pg:",pk"`
// 公司ID
CompanyId int64
// 统一用户UID
Uid int64
// 员工姓名
... ... @@ -12,4 +14,6 @@ type Employee struct {
EmployeeAccount string
// 当前素币
SuMoney float64
// 员工状态(启用或者禁用)
Status int
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type OffTaskRecord struct {
TableName string `pg:"off_task_records,alias:off_task_record"`
// 关闭任务记录ID
Id int64 `pg:",pk"`
// 任务
TaskId int64
// 操作人
Operator *domain.EmployeeInfo
// 关闭理由
OffReason string
// 创建时间
CreateTime time.Time
}
... ...
... ... @@ -30,16 +30,16 @@ func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.E
return employee, err
}
if _, err := tx.QueryOne(
pg.Scan(&employee.EmployeeId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.SuMoney),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id, uid, employee_name, employee_account, su_money",
employee.EmployeeId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.SuMoney); err != nil {
pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.SuMoney, &employee.Status),
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money, status) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, su_money, status",
employee.EmployeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.SuMoney, employee.Status); err != nil {
return employee, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&employee.EmployeeId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.SuMoney),
"UPDATE employees SET employee_name=?, employee_account=?, su_money=? WHERE uid=? RETURNING id, uid, employee_name, employee_account, su_money",
employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.SuMoney, employee.EmployeeInfo.Uid); err != nil {
pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.SuMoney, &employee.Status),
"UPDATE employees SET employee_name=?, employee_account=?, su_money=?, status=? WHERE uid=? RETURNING id, company_id, uid, employee_name, employee_account, su_money, status",
employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.SuMoney, employee.Status, employee.EmployeeInfo.Uid); err != nil {
return employee, err
}
}
... ... @@ -73,22 +73,14 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
if employeeModel.Id == 0 {
return nil, nil
} else {
return &domain.Employee{
EmployeeId: employeeModel.Id,
EmployeeInfo: &domain.EmployeeInfo{
Uid: employeeModel.Uid,
EmployeeName: employeeModel.EmployeeName,
EmployeeAccount: employeeModel.EmployeeAccount,
},
SuMoney: employeeModel.SuMoney,
}, nil
return repository.transformPgModelToDomainModel(employeeModel)
}
}
func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
tx := repository.transactionContext.PgTx
var employeeModels []*models.Employee
var employees []*domain.Employee
employees := make([]*domain.Employee, 0)
query := tx.Model(&employeeModels)
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
... ... @@ -107,21 +99,31 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
query = query.Limit(20)
}
if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
return 0, nil, err
return 0, employees, err
} else {
for _, employeeModel := range employeeModels {
employees = append(employees, &domain.Employee{
if employee, err := repository.transformPgModelToDomainModel(employeeModel); err != nil {
return 0, employees, err
} else {
employees = append(employees, employee)
}
}
return int64(count), employees, nil
}
}
func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) {
return &domain.Employee{
EmployeeId: employeeModel.Id,
CompanyId: employeeModel.CompanyId,
EmployeeInfo: &domain.EmployeeInfo{
Uid: employeeModel.Uid,
EmployeeName: employeeModel.EmployeeName,
EmployeeAccount: employeeModel.EmployeeAccount,
},
SuMoney: employeeModel.SuMoney,
})
}
return int64(count), employees, nil
}
Status: employeeModel.Status,
}, nil
}
func NewEmployeeRepository(transactionContext *pgTransaction.TransactionContext) (*EmployeeRepository, error) {
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
)
type OffTaskRecordRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *OffTaskRecordRepository) nextIdentify() (int64, error) {
return 0, nil
}
func (repository *OffTaskRecordRepository) Save(offTaskRecord *domain.OffTaskRecord) (*domain.OffTaskRecord, error) {
tx := repository.transactionContext.PgTx
if offTaskRecord.Identify() == nil {
_, err := repository.nextIdentify()
if err != nil {
return offTaskRecord, err
}
if _, err := tx.QueryOne(
pg.Scan(&offTaskRecord.OffTaskRecordId, &offTaskRecord.Task.TaskId, &offTaskRecord.Operator, &offTaskRecord.OffReason, &offTaskRecord.CreateTime),
"INSERT INTO off_task_records (task_id, operator, off_reason, create_time) VALUES (?, ?, ?, ?) RETURNING id, task_id, operator, off_reason, create_time",
offTaskRecord.Task.TaskId, offTaskRecord.Operator, offTaskRecord.OffReason, offTaskRecord.CreateTime); err != nil {
return offTaskRecord, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&offTaskRecord.OffTaskRecordId, &offTaskRecord.Task, &offTaskRecord.Operator, &offTaskRecord.OffReason, &offTaskRecord.CreateTime),
"UPDATE off_task_records SET task_id=?, operator=?, off_reason=?, create_time=? WHERE id=? RETURNING id, task_id, operator, off_reason, create_time",
offTaskRecord.Task.TaskId, offTaskRecord.Operator, offTaskRecord.OffReason, offTaskRecord.CreateTime, offTaskRecord.OffTaskRecordId); err != nil {
return offTaskRecord, err
}
}
return offTaskRecord, nil
}
func (repository *OffTaskRecordRepository) Remove(offTaskRecord *domain.OffTaskRecord) (*domain.OffTaskRecord, error) {
tx := repository.transactionContext.PgTx
offTaskRecordModel := new(models.OffTaskRecord)
offTaskRecordModel.Id = offTaskRecord.Identify().(int64)
if _, err := tx.Model(offTaskRecordModel).WherePK().Delete(); err != nil {
return offTaskRecord, err
}
return offTaskRecord, nil
}
func (repository *OffTaskRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.OffTaskRecord, error) {
tx := repository.transactionContext.PgTx
offTaskRecordModel := new(models.OffTaskRecord)
query := tx.Model(offTaskRecordModel)
if offTaskRecordId, ok := queryOptions["offTaskRecordId"]; ok {
query = query.Where("off_task_record.id = ?", offTaskRecordId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if offTaskRecordModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(offTaskRecordModel)
}
}
func (repository *OffTaskRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OffTaskRecord, error) {
tx := repository.transactionContext.PgTx
var offTaskRecordModels []*models.OffTaskRecord
offTaskRecords := make([]*domain.OffTaskRecord, 0)
query := tx.Model(&offTaskRecordModels)
if offTaskRecordIds, ok := queryOptions["offTaskRecordIds"]; ok {
query = query.Where(`off_task_record.task_id IN (?)`, pg.In(offTaskRecordIds.([]int64)))
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, offTaskRecords, err
} else {
for _, offTaskRecordModel := range offTaskRecordModels {
if offTaskRecord, err := repository.transformPgModelToDomainModel(offTaskRecordModel); err != nil {
return 0, offTaskRecords, err
} else {
offTaskRecords = append(offTaskRecords, offTaskRecord)
}
offTaskRecords = append(offTaskRecords, &domain.OffTaskRecord{})
}
return int64(count), offTaskRecords, nil
}
}
func (repository *OffTaskRecordRepository) transformPgModelToDomainModel(offTaskRecordModel *models.OffTaskRecord) (*domain.OffTaskRecord, error) {
return &domain.OffTaskRecord{
OffTaskRecordId: offTaskRecordModel.Id,
Task: &domain.Task{
TaskId: offTaskRecordModel.TaskId,
},
Operator: offTaskRecordModel.Operator,
OffReason: offTaskRecordModel.OffReason,
CreateTime: offTaskRecordModel.CreateTime,
}, nil
}
func NewOffTaskRecordRepository(transactionContext *pgTransaction.TransactionContext) (*OffTaskRecordRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OffTaskRecordRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -143,6 +143,16 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
if taskIds, ok := queryOptions["taskIds"]; ok {
query = query.Where(`task.task_id IN (?)`, pg.In(taskIds.([]int64)))
}
if offRangTime, ok := queryOptions["offRangTime"]; ok {
query = query.Join("JOIN off_task_records ON off_task_record.task_id = task.id")
if offStartTime, ok := offRangTime.(map[string]time.Time)["offStartTime"]; ok {
query = query.Where("off_task_record.create_time > ?", offStartTime)
}
if offEndTime, ok := offRangTime.(map[string]time.Time)["offEndTime"]; ok {
query = query.Where("off_task_record.create_time < ?", offEndTime)
}
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ...
... ... @@ -15,8 +15,10 @@ var _ = Describe("创建新员工", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"uid": 123456,
"companyId": 101,
"employeeName": "蔡晓生",
"employeeAccount": "13799999999",
"status": 1,
}
httpExpect.POST("/employees/").
WithJSON(body).
... ...
... ... @@ -14,8 +14,8 @@ var _ = Describe("返回员工", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&employeeId),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?) RETURNING id",
1, 101, 123456, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据uid参数返回员工", func() {
... ...
... ... @@ -14,8 +14,8 @@ var _ = Describe("返回员工列表", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&employeeId),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?) RETURNING id",
1, 101, 123456, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回员工列表", func() {
... ...
... ... @@ -15,8 +15,8 @@ var _ = Describe("移除员工", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&employeeId),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?) RETURNING id",
1, 101, 123456, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除员工", func() {
... ...
... ... @@ -15,8 +15,8 @@ var _ = Describe("更新员工", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&employeeId),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?) RETURNING id",
1, 101, 123456, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新员工", func() {
... ...
package task
import (
"github.com/go-pg/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("关闭任务", func() {
var taskId int64
Describe("关闭任务", func() {
Context("任务发起者关闭任务", func() {
BeforeEach(func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
pg.Scan(&taskId),
"INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime")
pg.Scan(),
"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 3, "null", 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, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
})
Describe("关闭任务", func() {
Context("", func() {
It("", func() {
It("返回被关闭的任务", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
"offReason": "string",
"operator": 2499036607974745088,
"offReason": "测试关闭任务",
}
httpExpect.POST("/tasks/{taskId}/dff").
httpExpect.POST("/tasks/1/dff").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -35,12 +51,60 @@ var _ = Describe("关闭任务", func() {
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
ContainsKey("data").Value("data").Object().
ContainsKey("taskStatus").ValueEqual("taskStatus", 6)
})
})
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,
}, 6, "null", 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, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
})
It("关闭失败", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": 2499036607974745088,
"offReason": "测试关闭任务",
}
httpExpect.POST("/tasks/1/dff").
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")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.Exec("DELETE FROM employees WHERE true")
Expect(err3).NotTo(HaveOccurred())
_, err4 := pG.DB.Exec("DELETE FROM off_task_records WHERE true")
Expect(err4).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -32,8 +32,8 @@ var _ = Describe("发布任务", func() {
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)
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
})
It("发布任务成功", func() {
... ... @@ -49,7 +49,8 @@ var _ = Describe("发布任务", func() {
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
ContainsKey("data").Value("data").Object().
ContainsKey("taskStatus").ValueEqual("taskStatus", 2)
})
})
Context("任务发起者发布不是待发布的任务", func() {
... ...