正在显示
14 个修改的文件
包含
282 行增加
和
46 行删除
| @@ -12,3 +12,11 @@ func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { | @@ -12,3 +12,11 @@ func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { | ||
| 12 | } | 12 | } |
| 13 | return dao.NewTaskDao(transactionContext) | 13 | return dao.NewTaskDao(transactionContext) |
| 14 | } | 14 | } |
| 15 | + | ||
| 16 | +func CreateEmployeeDao(options map[string]interface{}) (*dao.EmployeeDao, error) { | ||
| 17 | + var transactionContext *pg.TransactionContext | ||
| 18 | + if value, ok := options["transactionContext"]; ok { | ||
| 19 | + transactionContext = value.(*pg.TransactionContext) | ||
| 20 | + } | ||
| 21 | + return dao.NewEmployeeDao(transactionContext) | ||
| 22 | +} |
| @@ -53,3 +53,11 @@ func CreateApplyCompleteTaskService(options map[string]interface{}) (service.App | @@ -53,3 +53,11 @@ func CreateApplyCompleteTaskService(options map[string]interface{}) (service.App | ||
| 53 | } | 53 | } |
| 54 | return domainService.NewApplyCompleteTaskService(transactionContext) | 54 | return domainService.NewApplyCompleteTaskService(transactionContext) |
| 55 | } | 55 | } |
| 56 | + | ||
| 57 | +func CreateAcceptanceTaskService(options map[string]interface{}) (service.AcceptanceTaskService, error) { | ||
| 58 | + var transactionContext *pgTransaction.TransactionContext | ||
| 59 | + if value, ok := options["transactionContext"]; ok { | ||
| 60 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
| 61 | + } | ||
| 62 | + return domainService.NewAcceptanceTaskService(transactionContext) | ||
| 63 | +} |
| @@ -229,10 +229,22 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac | @@ -229,10 +229,22 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac | ||
| 229 | defer func() { | 229 | defer func() { |
| 230 | transactionContext.RollbackTransaction() | 230 | transactionContext.RollbackTransaction() |
| 231 | }() | 231 | }() |
| 232 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 233 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 232 | + var acceptanceTaskService service.AcceptanceTaskService |
| 233 | + if value, err := factory.CreateAcceptanceTaskService(map[string]interface{}{ | ||
| 234 | + "transactionContext": transactionContext, | ||
| 235 | + }); err != nil { | ||
| 236 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 237 | + } else { | ||
| 238 | + acceptanceTaskService = value | ||
| 239 | + } | ||
| 240 | + if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil { | ||
| 241 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 242 | + } else { | ||
| 243 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 244 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 245 | + } | ||
| 246 | + return task, nil | ||
| 234 | } | 247 | } |
| 235 | - return nil, nil | ||
| 236 | } | 248 | } |
| 237 | 249 | ||
| 238 | // 搜索任务 | 250 | // 搜索任务 |
pkg/domain/service/acceptance_task.go
0 → 100644
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
| 4 | + | ||
| 5 | +type AcceptanceTaskService interface { | ||
| 6 | + Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) | ||
| 7 | +} |
| @@ -2,6 +2,11 @@ package domain | @@ -2,6 +2,11 @@ package domain | ||
| 2 | 2 | ||
| 3 | import "time" | 3 | import "time" |
| 4 | 4 | ||
| 5 | +const ( | ||
| 6 | + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换 | ||
| 7 | + SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励 | ||
| 8 | +) | ||
| 9 | + | ||
| 5 | // 素币事务记录 | 10 | // 素币事务记录 |
| 6 | type SuMoneyTransactionRecord struct { | 11 | type SuMoneyTransactionRecord struct { |
| 7 | // 素币事务记录ID | 12 | // 素币事务记录ID |
| @@ -9,11 +14,11 @@ type SuMoneyTransactionRecord struct { | @@ -9,11 +14,11 @@ type SuMoneyTransactionRecord struct { | ||
| 9 | // 记录类型 | 14 | // 记录类型 |
| 10 | RecordType int `json:"recordType"` | 15 | RecordType int `json:"recordType"` |
| 11 | // 记录关联员工 | 16 | // 记录关联员工 |
| 12 | - Employee *EmployeeInfo `json:"employeeInfo"` | 17 | + Employee *EmployeeInfo `json:"employee"` |
| 13 | // 事务素币值 | 18 | // 事务素币值 |
| 14 | SuMoney float64 `json:"suMoney"` | 19 | SuMoney float64 `json:"suMoney"` |
| 15 | // 操作人 | 20 | // 操作人 |
| 16 | - Operator int64 `json:"operator"` | 21 | + Operator *EmployeeInfo `json:"operator"` |
| 17 | // 素币事务记录描述 | 22 | // 素币事务记录描述 |
| 18 | RecordDescription string `json:"recordDescription"` | 23 | RecordDescription string `json:"recordDescription"` |
| 19 | // 创建时间 | 24 | // 创建时间 |
| @@ -32,4 +37,4 @@ func (suMoneyTransactionRecord *SuMoneyTransactionRecord) Identify() interface{} | @@ -32,4 +37,4 @@ func (suMoneyTransactionRecord *SuMoneyTransactionRecord) Identify() interface{} | ||
| 32 | return nil | 37 | return nil |
| 33 | } | 38 | } |
| 34 | return suMoneyTransactionRecord.SuMoneyTransactionRecordId | 39 | return suMoneyTransactionRecord.SuMoneyTransactionRecordId |
| 35 | -} | ||
| 40 | +} |
| @@ -6,4 +6,6 @@ type TaskPercentageItem struct { | @@ -6,4 +6,6 @@ type TaskPercentageItem struct { | ||
| 6 | Contributor *EmployeeInfo `json:"contributor"` | 6 | Contributor *EmployeeInfo `json:"contributor"` |
| 7 | // 任务贡献占比 | 7 | // 任务贡献占比 |
| 8 | Percentage int `json:"percentage"` | 8 | Percentage int `json:"percentage"` |
| 9 | + // 分配到的奖励素币 | ||
| 10 | + SuMoney float64 `json:"suMoney"` | ||
| 9 | } | 11 | } |
pkg/infrastructure/dao/pg_employee_dao.go
0 → 100644
| 1 | +package dao | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg" | ||
| 6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type EmployeeDao struct { | ||
| 10 | + transactionContext *pgTransaction.TransactionContext | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { | ||
| 14 | + tx := dao.transactionContext.PgTx | ||
| 15 | + _, err := tx.QueryOne( | ||
| 16 | + pg.Scan(), | ||
| 17 | + "UPDATE employees SET su_money=su_money+? WHERE uid=?", | ||
| 18 | + suMoney, uid) | ||
| 19 | + return err | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) { | ||
| 23 | + if transactionContext == nil { | ||
| 24 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 25 | + } else { | ||
| 26 | + return &EmployeeDao{ | ||
| 27 | + transactionContext: transactionContext, | ||
| 28 | + }, nil | ||
| 29 | + } | ||
| 30 | +} |
| 1 | +package domain_service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
| 6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
| 8 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" | ||
| 9 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository" | ||
| 10 | + "time" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type AcceptanceTaskService struct { | ||
| 14 | + coreDomain.BaseEventPublisher | ||
| 15 | + transactionContext *pgTransaction.TransactionContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) { | ||
| 19 | + var employeeRepository domain.EmployeeRepository | ||
| 20 | + var taskRepository domain.TaskRepository | ||
| 21 | + var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository | ||
| 22 | + var employeeDao *dao.EmployeeDao | ||
| 23 | + if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil { | ||
| 24 | + return nil, err | ||
| 25 | + } else { | ||
| 26 | + employeeRepository = repository | ||
| 27 | + } | ||
| 28 | + if repository, err := repository.NewTaskRepository(service.transactionContext); err != nil { | ||
| 29 | + return nil, err | ||
| 30 | + } else { | ||
| 31 | + taskRepository = repository | ||
| 32 | + } | ||
| 33 | + if repository, err := repository.NewSuMoneyTransactionRecordRepository(service.transactionContext); err != nil { | ||
| 34 | + return nil, err | ||
| 35 | + } else { | ||
| 36 | + suMoneyTransactionRecordRepository = repository | ||
| 37 | + } | ||
| 38 | + if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil { | ||
| 39 | + return nil, err | ||
| 40 | + } else { | ||
| 41 | + employeeDao = dao | ||
| 42 | + } | ||
| 43 | + operator, err := employeeRepository.FindOne(map[string]interface{}{ | ||
| 44 | + "uid": operatorUid, | ||
| 45 | + }) | ||
| 46 | + if err != nil { | ||
| 47 | + return nil, err | ||
| 48 | + } | ||
| 49 | + if operator == nil { | ||
| 50 | + return nil, fmt.Errorf("无效的操作者") | ||
| 51 | + } | ||
| 52 | + task, err := taskRepository.FindOne(map[string]interface{}{ | ||
| 53 | + "taskId": taskId, | ||
| 54 | + }) | ||
| 55 | + if err != nil { | ||
| 56 | + return nil, err | ||
| 57 | + } | ||
| 58 | + if task == nil { | ||
| 59 | + return nil, fmt.Errorf("无效的任务") | ||
| 60 | + } | ||
| 61 | + var participatorInfos []*domain.EmployeeInfo | ||
| 62 | + for _, participatorUid := range participators { | ||
| 63 | + if participator, err := employeeRepository.FindOne(map[string]interface{}{ | ||
| 64 | + "uid": participatorUid, | ||
| 65 | + }); err != nil { | ||
| 66 | + return nil, err | ||
| 67 | + } else { | ||
| 68 | + if participator == nil { | ||
| 69 | + return nil, fmt.Errorf("无效的参与人") | ||
| 70 | + } | ||
| 71 | + participatorInfos = append(participatorInfos, participator.EmployeeInfo) | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + if err := task.Acceptance(participatorInfos, taskPercentage, solveReport, solvePictureUrls); err != nil { | ||
| 75 | + return nil, err | ||
| 76 | + } | ||
| 77 | + for _, taskPercentageItem := range taskPercentage { | ||
| 78 | + suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{ | ||
| 79 | + RecordType: domain.SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD, | ||
| 80 | + Employee: taskPercentageItem.Contributor, | ||
| 81 | + SuMoney: taskPercentageItem.SuMoney, | ||
| 82 | + Operator: operator.EmployeeInfo, | ||
| 83 | + RecordDescription: fmt.Sprintf("完成[%s]任务奖励", task.TaskName), | ||
| 84 | + CreateTime: time.Now(), | ||
| 85 | + } | ||
| 86 | + if _, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil { | ||
| 87 | + return nil, err | ||
| 88 | + } | ||
| 89 | + if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, task.SuMoney); err != nil { | ||
| 90 | + return nil, err | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + if task, err := taskRepository.Save(task); err != nil { | ||
| 94 | + return nil, err | ||
| 95 | + } else { | ||
| 96 | + return task, nil | ||
| 97 | + } | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +func NewAcceptanceTaskService(transactionContext *pgTransaction.TransactionContext) (*AcceptanceTaskService, error) { | ||
| 101 | + if transactionContext == nil { | ||
| 102 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 103 | + } else { | ||
| 104 | + return &AcceptanceTaskService{ | ||
| 105 | + transactionContext: transactionContext, | ||
| 106 | + }, nil | ||
| 107 | + } | ||
| 108 | +} |
| @@ -16,7 +16,7 @@ type SuMoneyTransactionRecord struct { | @@ -16,7 +16,7 @@ type SuMoneyTransactionRecord struct { | ||
| 16 | // 事务素币值 | 16 | // 事务素币值 |
| 17 | SuMoney float64 | 17 | SuMoney float64 |
| 18 | // 操作人 | 18 | // 操作人 |
| 19 | - Operator int64 | 19 | + Operator *domain.EmployeeInfo |
| 20 | // 素币事务记录描述 | 20 | // 素币事务记录描述 |
| 21 | RecordDescription string | 21 | RecordDescription string |
| 22 | // 创建时间 | 22 | // 创建时间 |
| @@ -65,7 +65,7 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ | @@ -65,7 +65,7 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ | ||
| 65 | } | 65 | } |
| 66 | if err := query.First(); err != nil { | 66 | if err := query.First(); err != nil { |
| 67 | if err.Error() == "pg: no rows in result set" { | 67 | if err.Error() == "pg: no rows in result set" { |
| 68 | - return nil, fmt.Errorf("没有此资源") | 68 | + return nil, fmt.Errorf("没有此员工") |
| 69 | } else { | 69 | } else { |
| 70 | return nil, err | 70 | return nil, err |
| 71 | } | 71 | } |
| @@ -13,16 +13,9 @@ type OffTaskRecordRepository struct { | @@ -13,16 +13,9 @@ type OffTaskRecordRepository struct { | ||
| 13 | transactionContext *pgTransaction.TransactionContext | 13 | transactionContext *pgTransaction.TransactionContext |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -func (repository *OffTaskRecordRepository) nextIdentify() (int64, error) { | ||
| 17 | - return 0, nil | ||
| 18 | -} | ||
| 19 | func (repository *OffTaskRecordRepository) Save(offTaskRecord *domain.OffTaskRecord) (*domain.OffTaskRecord, error) { | 16 | func (repository *OffTaskRecordRepository) Save(offTaskRecord *domain.OffTaskRecord) (*domain.OffTaskRecord, error) { |
| 20 | tx := repository.transactionContext.PgTx | 17 | tx := repository.transactionContext.PgTx |
| 21 | if offTaskRecord.Identify() == nil { | 18 | if offTaskRecord.Identify() == nil { |
| 22 | - _, err := repository.nextIdentify() | ||
| 23 | - if err != nil { | ||
| 24 | - return offTaskRecord, err | ||
| 25 | - } | ||
| 26 | if _, err := tx.QueryOne( | 19 | if _, err := tx.QueryOne( |
| 27 | pg.Scan(&offTaskRecord.OffTaskRecordId, &offTaskRecord.Task.TaskId, &offTaskRecord.Operator, &offTaskRecord.OffReason, &offTaskRecord.CreateTime), | 20 | pg.Scan(&offTaskRecord.OffTaskRecordId, &offTaskRecord.Task.TaskId, &offTaskRecord.Operator, &offTaskRecord.OffReason, &offTaskRecord.CreateTime), |
| 28 | "INSERT INTO off_task_records (task_id, operator, off_reason, create_time) VALUES (?, ?, ?, ?) RETURNING id, task_id, operator, off_reason, create_time", | 21 | "INSERT INTO off_task_records (task_id, operator, off_reason, create_time) VALUES (?, ?, ?, ?) RETURNING id, task_id, operator, off_reason, create_time", |
| @@ -57,7 +50,7 @@ func (repository *OffTaskRecordRepository) FindOne(queryOptions map[string]inter | @@ -57,7 +50,7 @@ func (repository *OffTaskRecordRepository) FindOne(queryOptions map[string]inter | ||
| 57 | } | 50 | } |
| 58 | if err := query.First(); err != nil { | 51 | if err := query.First(); err != nil { |
| 59 | if err.Error() == "pg: no rows in result set" { | 52 | if err.Error() == "pg: no rows in result set" { |
| 60 | - return nil, fmt.Errorf("没有此资源") | 53 | + return nil, fmt.Errorf("没有此关闭任务记录") |
| 61 | } else { | 54 | } else { |
| 62 | return nil, err | 55 | return nil, err |
| 63 | } | 56 | } |
| @@ -13,26 +13,19 @@ type SuMoneyTransactionRecordRepository struct { | @@ -13,26 +13,19 @@ type SuMoneyTransactionRecordRepository struct { | ||
| 13 | transactionContext *pgTransaction.TransactionContext | 13 | transactionContext *pgTransaction.TransactionContext |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -func (repository *SuMoneyTransactionRecordRepository) nextIdentify() (int64, error) { | ||
| 17 | - return 0, nil | ||
| 18 | -} | ||
| 19 | func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRecord *domain.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) { | 16 | func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRecord *domain.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) { |
| 20 | tx := repository.transactionContext.PgTx | 17 | tx := repository.transactionContext.PgTx |
| 21 | if suMoneyTransactionRecord.Identify() == nil { | 18 | if suMoneyTransactionRecord.Identify() == nil { |
| 22 | - _, err := repository.nextIdentify() | ||
| 23 | - if err != nil { | ||
| 24 | - return suMoneyTransactionRecord, err | ||
| 25 | - } | ||
| 26 | if _, err := tx.QueryOne( | 19 | if _, err := tx.QueryOne( |
| 27 | pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime), | 20 | pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime), |
| 28 | - "INSERT INTO su_money_transaction_records (id, record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING su_money_transaction_record_id, record_type, employee, su_money, operator, record_description, create_time", | ||
| 29 | - suMoneyTransactionRecord.SuMoneyTransactionRecordId, suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime); err != nil { | 21 | + "INSERT INTO su_money_transaction_records (record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?) RETURNING id, record_type, employee, su_money, operator, record_description, create_time", |
| 22 | + suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime); err != nil { | ||
| 30 | return suMoneyTransactionRecord, err | 23 | return suMoneyTransactionRecord, err |
| 31 | } | 24 | } |
| 32 | } else { | 25 | } else { |
| 33 | if _, err := tx.QueryOne( | 26 | if _, err := tx.QueryOne( |
| 34 | pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime), | 27 | pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime), |
| 35 | - "UPDATE su_money_transaction_records SET record_type=?, employee=?, su_money=?, operator=?, record_description=?, create_time=? WHERE id=? RETURNING su_money_transaction_record_id, record_type, employee, su_money, operator, record_description, create_time", | 28 | + "UPDATE su_money_transaction_records SET record_type=?, employee=?, su_money=?, operator=?, record_description=?, create_time=? WHERE id=? RETURNING id, record_type, employee, su_money, operator, record_description, create_time", |
| 36 | suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime, suMoneyTransactionRecord.SuMoneyTransactionRecordId); err != nil { | 29 | suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime, suMoneyTransactionRecord.SuMoneyTransactionRecordId); err != nil { |
| 37 | return suMoneyTransactionRecord, err | 30 | return suMoneyTransactionRecord, err |
| 38 | } | 31 | } |
| @@ -57,7 +50,7 @@ func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[s | @@ -57,7 +50,7 @@ func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[s | ||
| 57 | } | 50 | } |
| 58 | if err := query.First(); err != nil { | 51 | if err := query.First(); err != nil { |
| 59 | if err.Error() == "pg: no rows in result set" { | 52 | if err.Error() == "pg: no rows in result set" { |
| 60 | - return nil, fmt.Errorf("没有此资源") | 53 | + return nil, fmt.Errorf("没有此素币事务记录") |
| 61 | } else { | 54 | } else { |
| 62 | return nil, err | 55 | return nil, err |
| 63 | } | 56 | } |
| @@ -72,7 +72,7 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -72,7 +72,7 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | ||
| 72 | } | 72 | } |
| 73 | if err := query.First(); err != nil { | 73 | if err := query.First(); err != nil { |
| 74 | if err.Error() == "pg: no rows in result set" { | 74 | if err.Error() == "pg: no rows in result set" { |
| 75 | - return nil, fmt.Errorf("没有此资源") | 75 | + return nil, fmt.Errorf("没有此任务") |
| 76 | } else { | 76 | } else { |
| 77 | return nil, err | 77 | return nil, err |
| 78 | } | 78 | } |
| 1 | package task | 1 | package task |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "github.com/go-pg/pg" | ||
| 5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
| 4 | "net/http" | 6 | "net/http" |
| 7 | + "time" | ||
| 5 | 8 | ||
| 6 | "github.com/gavv/httpexpect" | 9 | "github.com/gavv/httpexpect" |
| 7 | - "github.com/go-pg/pg" | ||
| 8 | . "github.com/onsi/ginkgo" | 10 | . "github.com/onsi/ginkgo" |
| 9 | . "github.com/onsi/gomega" | 11 | . "github.com/onsi/gomega" |
| 10 | pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | 12 | pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" |
| 11 | ) | 13 | ) |
| 12 | 14 | ||
| 13 | var _ = Describe("验收任务", func() { | 15 | var _ = Describe("验收任务", func() { |
| 14 | - var taskId int64 | ||
| 15 | - BeforeEach(func() { | ||
| 16 | - _, err := pG.DB.QueryOne( | ||
| 17 | - pg.Scan(&taskId), | ||
| 18 | - "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", | ||
| 19 | - "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
| 20 | - Expect(err).NotTo(HaveOccurred()) | ||
| 21 | - }) | ||
| 22 | Describe("验收任务", func() { | 16 | Describe("验收任务", func() { |
| 23 | - Context("", func() { | ||
| 24 | - It("", func() { | 17 | + Context("操作人对待验收的任务进行验收", func() { |
| 18 | + BeforeEach(func() { | ||
| 19 | + dayAfter, _ := time.ParseDuration("72h") | ||
| 20 | + _, err := pG.DB.QueryOne( | ||
| 21 | + pg.Scan(), | ||
| 22 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
| 23 | + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{ | ||
| 24 | + Uid: 2499036607974745088, | ||
| 25 | + }, 4, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter)) | ||
| 26 | + Expect(err).NotTo(HaveOccurred()) | ||
| 27 | + _, err1 := pG.DB.QueryOne( | ||
| 28 | + pg.Scan(), | ||
| 29 | + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | ||
| 30 | + 1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0) | ||
| 31 | + Expect(err1).NotTo(HaveOccurred()) | ||
| 32 | + _, err2 := pG.DB.QueryOne( | ||
| 33 | + pg.Scan(), | ||
| 34 | + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | ||
| 35 | + 2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0) | ||
| 36 | + Expect(err2).NotTo(HaveOccurred()) | ||
| 37 | + _, err3 := pG.DB.QueryOne( | ||
| 38 | + pg.Scan(), | ||
| 39 | + "INSERT INTO rob_infos (id, task_id ,receiver) VALUES (?, ?, ?)", | ||
| 40 | + 1, 1, &domain.EmployeeInfo{ | ||
| 41 | + Uid: 2499036607974745099, | ||
| 42 | + }) | ||
| 43 | + Expect(err3).NotTo(HaveOccurred()) | ||
| 44 | + _, err4 := pG.DB.QueryOne( | ||
| 45 | + pg.Scan(), | ||
| 46 | + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | ||
| 47 | + 3, 101, 2499036607974745077, "testEmployeeName", "testEmployeeAccount", 0) | ||
| 48 | + Expect(err4).NotTo(HaveOccurred()) | ||
| 49 | + _, err5 := pG.DB.QueryOne( | ||
| 50 | + pg.Scan(), | ||
| 51 | + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | ||
| 52 | + 4, 101, 2499036607974745066, "testEmployeeName", "testEmployeeAccount", 0) | ||
| 53 | + Expect(err5).NotTo(HaveOccurred()) | ||
| 54 | + }) | ||
| 55 | + It("验收成功", func() { | ||
| 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 56 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 26 | body := map[string]interface{}{ | 57 | body := map[string]interface{}{ |
| 27 | - "operator": "int64", | ||
| 28 | - "participators": "array", | ||
| 29 | - "taskPercentage": "array", | ||
| 30 | - "solveReport": "string", | ||
| 31 | - "solvePictureUrls": "array", | 58 | + "operator": 2499036607974745077, |
| 59 | + "participators": []int64{ | ||
| 60 | + 2499036607974745077, | ||
| 61 | + 2499036607974745066, | ||
| 62 | + }, | ||
| 63 | + "taskPercentage": []*domain.TaskPercentageItem{ | ||
| 64 | + { | ||
| 65 | + Contributor: &domain.EmployeeInfo{ | ||
| 66 | + Uid: 2499036607974745099, | ||
| 67 | + }, | ||
| 68 | + Percentage: 50, | ||
| 69 | + SuMoney: 500.00, | ||
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + Contributor: &domain.EmployeeInfo{ | ||
| 73 | + Uid: 2499036607974745077, | ||
| 74 | + }, | ||
| 75 | + Percentage: 25, | ||
| 76 | + SuMoney: 250.00, | ||
| 77 | + }, | ||
| 78 | + { | ||
| 79 | + Contributor: &domain.EmployeeInfo{ | ||
| 80 | + Uid: 2499036607974745066, | ||
| 81 | + }, | ||
| 82 | + Percentage: 25, | ||
| 83 | + SuMoney: 250.00, | ||
| 84 | + }, | ||
| 85 | + }, | ||
| 86 | + "solveReport": "解决报告", | ||
| 87 | + "solvePictureUrls": []string{ | ||
| 88 | + "url-1", | ||
| 89 | + "url-2", | ||
| 90 | + }, | ||
| 32 | } | 91 | } |
| 33 | - httpExpect.POST("/tasks/{taskId}/acceptance"). | 92 | + httpExpect.POST("/tasks/1/acceptance"). |
| 34 | WithJSON(body). | 93 | WithJSON(body). |
| 35 | Expect(). | 94 | Expect(). |
| 36 | Status(http.StatusOK). | 95 | Status(http.StatusOK). |
| @@ -38,12 +97,23 @@ var _ = Describe("验收任务", func() { | @@ -38,12 +97,23 @@ var _ = Describe("验收任务", func() { | ||
| 38 | Object(). | 97 | Object(). |
| 39 | ContainsKey("code").ValueEqual("code", 0). | 98 | ContainsKey("code").ValueEqual("code", 0). |
| 40 | ContainsKey("msg").ValueEqual("msg", "ok"). | 99 | ContainsKey("msg").ValueEqual("msg", "ok"). |
| 41 | - ContainsKey("data").Value("data").Object() | 100 | + ContainsKey("data").Value("data").Object(). |
| 101 | + ContainsKey("taskStatus").ValueEqual("taskStatus", 5) | ||
| 42 | }) | 102 | }) |
| 43 | }) | 103 | }) |
| 44 | }) | 104 | }) |
| 45 | AfterEach(func() { | 105 | AfterEach(func() { |
| 46 | _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | 106 | _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") |
| 47 | Expect(err).NotTo(HaveOccurred()) | 107 | Expect(err).NotTo(HaveOccurred()) |
| 108 | + _, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true") | ||
| 109 | + Expect(err1).NotTo(HaveOccurred()) | ||
| 110 | + _, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true") | ||
| 111 | + Expect(err2).NotTo(HaveOccurred()) | ||
| 112 | + _, err3 := pG.DB.Exec("DELETE FROM employees WHERE true") | ||
| 113 | + Expect(err3).NotTo(HaveOccurred()) | ||
| 114 | + _, err4 := pG.DB.Exec("DELETE FROM rob_infos WHERE true") | ||
| 115 | + Expect(err4).NotTo(HaveOccurred()) | ||
| 116 | + _, err5 := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true") | ||
| 117 | + Expect(err5).NotTo(HaveOccurred()) | ||
| 48 | }) | 118 | }) |
| 49 | }) | 119 | }) |
-
请 注册 或 登录 后发表评论