作者 linmadan

添加客户价值,任务性质,项目归属相关API

正在显示 54 个修改的文件 包含 2747 行增加2 行删除
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateCustomerValueCommand struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 客户价值名称
CustomerValueName string `json:"customerValueName" valid:"Required"`
}
func (createCustomerValueCommand *CreateCustomerValueCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCustomerValueCommand)
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 RemoveCustomerValueCommand struct {
// 客户价值ID
CustomerValueId int `json:"customerValueId" valid:"Required"`
}
func (removeCustomerValueCommand *RemoveCustomerValueCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCustomerValueCommand)
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 UpdateCustomerValueCommand struct {
// 客户价值ID
CustomerValueId int `json:"customerValueId,omitempty"`
// 客户价值名称
CustomerValueName string `json:"customerValueName,omitempty"`
}
func (updateCustomerValueCommand *UpdateCustomerValueCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCustomerValueCommand)
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 GetCustomerValueQuery struct {
// 客户价值ID
CustomerValueId int `json:"customerValueId" valid:"Required"`
}
func (getCustomerValueQuery *GetCustomerValueQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCustomerValueQuery)
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 ListCustomerValueQuery struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 客户价值名称
CustomerValueName string `json:"customerValueName,omitempty"`
// 客户价值名称匹配
CustomerValueNameMatch string `json:"customerValueNameMatch,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
Limit int `json:"limit,omitempty"`
}
func (listCustomerValueQuery *ListCustomerValueQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCustomerValueQuery)
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/customerValue/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
// 客户价值服务
type CustomerValueService struct {
}
// 创建客户价值
func (customerValueService *CustomerValueService) CreateCustomerValue(createCustomerValueCommand *command.CreateCustomerValueCommand) (interface{}, error) {
if err := createCustomerValueCommand.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()
}()
newCustomerValue := &domain.CustomerValue{
CompanyId: createCustomerValueCommand.CompanyId,
CustomerValueName: createCustomerValueCommand.CustomerValueName,
}
var customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
customerValueRepository = value
}
if count, _, err := customerValueRepository.Find(map[string]interface{}{
"customerValueName": createCustomerValueCommand.CustomerValueName,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
}
}
if customerValue, err := customerValueRepository.Save(newCustomerValue); 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 customerValue, nil
}
}
// 返回客户价值
func (customerValueService *CustomerValueService) GetCustomerValue(getCustomerValueQuery *query.GetCustomerValueQuery) (interface{}, error) {
if err := getCustomerValueQuery.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 customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
customerValueRepository = value
}
customerValue, err := customerValueRepository.FindOne(map[string]interface{}{"customerValueId": getCustomerValueQuery.CustomerValueId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if customerValue == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCustomerValueQuery.CustomerValueId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return customerValue, nil
}
}
// 更新客户价值
func (customerValueService *CustomerValueService) UpdateCustomerValue(updateCustomerValueCommand *command.UpdateCustomerValueCommand) (interface{}, error) {
if err := updateCustomerValueCommand.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 customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
customerValueRepository = value
}
customerValue, err := customerValueRepository.FindOne(map[string]interface{}{"customerValueId": updateCustomerValueCommand.CustomerValueId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if customerValue == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCustomerValueCommand.CustomerValueId)))
}
if count, customerValues, err := customerValueRepository.Find(map[string]interface{}{
"customerValueName": updateCustomerValueCommand.CustomerValueName,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 && customerValues[0].CustomerValueId != customerValue.CustomerValueId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
}
}
if err := customerValue.Update(tool_funs.SimpleStructToMap(updateCustomerValueCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if customerValue, err := customerValueRepository.Save(customerValue); 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 customerValue, nil
}
}
// 移除客户价值
func (customerValueService *CustomerValueService) RemoveCustomerValue(removeCustomerValueCommand *command.RemoveCustomerValueCommand) (interface{}, error) {
if err := removeCustomerValueCommand.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 customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
customerValueRepository = value
}
customerValue, err := customerValueRepository.FindOne(map[string]interface{}{"customerValueId": removeCustomerValueCommand.CustomerValueId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if customerValue == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCustomerValueCommand.CustomerValueId)))
}
if customerValue, err := customerValueRepository.Remove(customerValue); 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 customerValue, nil
}
}
// 返回客户价值列表
func (customerValueService *CustomerValueService) ListCustomerValue(listCustomerValueQuery *query.ListCustomerValueQuery) (interface{}, error) {
if err := listCustomerValueQuery.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 customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
customerValueRepository = value
}
if count, customerValues, err := customerValueRepository.Find(tool_funs.SimpleStructToMap(listCustomerValueQuery)); 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,
"customerValues": customerValues,
}, nil
}
}
func NewCustomerValueService(options map[string]interface{}) *CustomerValueService {
newCustomerValueService := &CustomerValueService{}
return newCustomerValueService
}
... ...
... ... @@ -37,3 +37,27 @@ func CreateSuMoneyTransactionRecordRepository(options map[string]interface{}) (d
}
return repository.NewSuMoneyTransactionRecordRepository(transactionContext)
}
func CreateCustomerValueRepository(options map[string]interface{}) (domain.CustomerValueRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewCustomerValueRepository(transactionContext)
}
func CreateTaskNatureRepository(options map[string]interface{}) (domain.TaskNatureRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewTaskNatureRepository(transactionContext)
}
func CreateProjectBelongRepository(options map[string]interface{}) (domain.ProjectBelongRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewProjectBelongRepository(transactionContext)
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateProjectBelongCommand struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 项目归属名称
ProjectBelongName string `json:"projectBelongName" valid:"Required"`
}
func (createProjectBelongCommand *CreateProjectBelongCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProjectBelongCommand)
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 RemoveProjectBelongCommand struct {
// 项目归属ID
ProjectBelongId int `json:"projectBelongId" valid:"Required"`
}
func (removeProjectBelongCommand *RemoveProjectBelongCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProjectBelongCommand)
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 UpdateProjectBelongCommand struct {
// 项目归属ID
ProjectBelongId int `json:"projectBelongId,omitempty"`
// 项目归属名称
ProjectBelongName string `json:"projectBelongName,omitempty"`
}
func (updateProjectBelongCommand *UpdateProjectBelongCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProjectBelongCommand)
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 GetProjectBelongQuery struct {
// 项目归属ID
ProjectBelongId int `json:"projectBelongId" valid:"Required"`
}
func (getProjectBelongQuery *GetProjectBelongQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProjectBelongQuery)
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 ListProjectBelongQuery struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 项目归属名称
ProjectBelongName string `json:"projectBelongName,omitempty"`
// 项目归属名称匹配
ProjectBelongNameMatch string `json:"projectBelongNameMatch,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
Limit int `json:"limit,omitempty"`
}
func (listProjectBelongQuery *ListProjectBelongQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProjectBelongQuery)
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/projectBelong/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
// 项目归属服务
type ProjectBelongService struct {
}
// 创建项目归属
func (projectBelongService *ProjectBelongService) CreateProjectBelong(createProjectBelongCommand *command.CreateProjectBelongCommand) (interface{}, error) {
if err := createProjectBelongCommand.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()
}()
newProjectBelong := &domain.ProjectBelong{
CompanyId: createProjectBelongCommand.CompanyId,
ProjectBelongName: createProjectBelongCommand.ProjectBelongName,
}
var projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectBelongRepository = value
}
if count, _, err := projectBelongRepository.Find(map[string]interface{}{
"projectBelongName": createProjectBelongCommand.ProjectBelongName,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
}
}
if projectBelong, err := projectBelongRepository.Save(newProjectBelong); 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 projectBelong, nil
}
}
// 返回项目归属
func (projectBelongService *ProjectBelongService) GetProjectBelong(getProjectBelongQuery *query.GetProjectBelongQuery) (interface{}, error) {
if err := getProjectBelongQuery.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 projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectBelongRepository = value
}
projectBelong, err := projectBelongRepository.FindOne(map[string]interface{}{"projectBelongId": getProjectBelongQuery.ProjectBelongId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectBelong == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectBelongQuery.ProjectBelongId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectBelong, nil
}
}
// 更新项目归属
func (projectBelongService *ProjectBelongService) UpdateProjectBelong(updateProjectBelongCommand *command.UpdateProjectBelongCommand) (interface{}, error) {
if err := updateProjectBelongCommand.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 projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectBelongRepository = value
}
projectBelong, err := projectBelongRepository.FindOne(map[string]interface{}{"projectBelongId": updateProjectBelongCommand.ProjectBelongId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectBelong == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectBelongCommand.ProjectBelongId)))
}
if count, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
"projectBelongName": updateProjectBelongCommand.ProjectBelongName,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 && projectBelongs[0].ProjectBelongId != projectBelong.ProjectBelongId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
}
}
if err := projectBelong.Update(tool_funs.SimpleStructToMap(updateProjectBelongCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if projectBelong, err := projectBelongRepository.Save(projectBelong); 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 projectBelong, nil
}
}
// 移除项目归属
func (projectBelongService *ProjectBelongService) RemoveProjectBelong(removeProjectBelongCommand *command.RemoveProjectBelongCommand) (interface{}, error) {
if err := removeProjectBelongCommand.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 projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectBelongRepository = value
}
projectBelong, err := projectBelongRepository.FindOne(map[string]interface{}{"projectBelongId": removeProjectBelongCommand.ProjectBelongId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectBelong == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectBelongCommand.ProjectBelongId)))
}
if projectBelong, err := projectBelongRepository.Remove(projectBelong); 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 projectBelong, nil
}
}
// 返回项目归属列表
func (projectBelongService *ProjectBelongService) ListProjectBelong(listProjectBelongQuery *query.ListProjectBelongQuery) (interface{}, error) {
if err := listProjectBelongQuery.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 projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectBelongRepository = value
}
if count, projectBelongs, err := projectBelongRepository.Find(tool_funs.SimpleStructToMap(listProjectBelongQuery)); 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,
"projectBelongs": projectBelongs,
}, nil
}
}
func NewProjectBelongService(options map[string]interface{}) *ProjectBelongService {
newProjectBelongService := &ProjectBelongService{}
return newProjectBelongService
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateTaskNatureCommand struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 任务性质名称
TaskNatureName string `json:"taskNatureName" valid:"Required"`
}
func (createTaskNatureCommand *CreateTaskNatureCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createTaskNatureCommand)
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 RemoveTaskNatureCommand struct {
// 任务性质ID
TaskNatureId int `json:"taskNatureId" valid:"Required"`
}
func (removeTaskNatureCommand *RemoveTaskNatureCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeTaskNatureCommand)
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 UpdateTaskNatureCommand struct {
// 任务性质ID
TaskNatureId int `json:"taskNatureId,omitempty"`
// 任务性质名称
TaskNatureName string `json:"taskNatureName,omitempty"`
}
func (updateTaskNatureCommand *UpdateTaskNatureCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateTaskNatureCommand)
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 GetTaskNatureQuery struct {
// 任务性质ID
TaskNatureId int `json:"taskNatureId" valid:"Required"`
}
func (getTaskNatureQuery *GetTaskNatureQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getTaskNatureQuery)
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 ListTaskNatureQuery struct {
// 公司ID
CompanyId int64 `json:"companyId" valid:"Required"`
// 任务性质名称
TaskNatureName string `json:"taskNatureName,omitempty"`
// 任务性质名称匹配
TaskNatureNameMatch string `json:"taskNatureNameMatch,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
// 查询限制
Limit int `json:"limit,omitempty"`
}
func (listTaskNatureQuery *ListTaskNatureQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listTaskNatureQuery)
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/taskNature/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
// 任务性质服务
type TaskNatureService struct {
}
// 创建任务性质
func (taskNatureService *TaskNatureService) CreateTaskNature(createTaskNatureCommand *command.CreateTaskNatureCommand) (interface{}, error) {
if err := createTaskNatureCommand.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()
}()
newTaskNature := &domain.TaskNature{
CompanyId: createTaskNatureCommand.CompanyId,
TaskNatureName: createTaskNatureCommand.TaskNatureName,
}
var taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskNatureRepository = value
}
if count, _, err := taskNatureRepository.Find(map[string]interface{}{
"taskNatureName": createTaskNatureCommand.TaskNatureName,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
}
}
if taskNature, err := taskNatureRepository.Save(newTaskNature); 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 taskNature, nil
}
}
// 返回任务性质
func (taskNatureService *TaskNatureService) GetTaskNature(getTaskNatureQuery *query.GetTaskNatureQuery) (interface{}, error) {
if err := getTaskNatureQuery.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 taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskNatureRepository = value
}
taskNature, err := taskNatureRepository.FindOne(map[string]interface{}{"taskNatureId": getTaskNatureQuery.TaskNatureId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if taskNature == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskNatureQuery.TaskNatureId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return taskNature, nil
}
}
// 更新任务性质
func (taskNatureService *TaskNatureService) UpdateTaskNature(updateTaskNatureCommand *command.UpdateTaskNatureCommand) (interface{}, error) {
if err := updateTaskNatureCommand.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 taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskNatureRepository = value
}
taskNature, err := taskNatureRepository.FindOne(map[string]interface{}{"taskNatureId": updateTaskNatureCommand.TaskNatureId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if taskNature == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskNatureCommand.TaskNatureId)))
}
if count, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
"taskNatureName": updateTaskNatureCommand.TaskNatureName,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 && taskNatures[0].TaskNatureId != taskNature.TaskNatureId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
}
}
if err := taskNature.Update(tool_funs.SimpleStructToMap(updateTaskNatureCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if taskNature, err := taskNatureRepository.Save(taskNature); 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 taskNature, nil
}
}
// 移除任务性质
func (taskNatureService *TaskNatureService) RemoveTaskNature(removeTaskNatureCommand *command.RemoveTaskNatureCommand) (interface{}, error) {
if err := removeTaskNatureCommand.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 taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskNatureRepository = value
}
taskNature, err := taskNatureRepository.FindOne(map[string]interface{}{"taskNatureId": removeTaskNatureCommand.TaskNatureId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if taskNature == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeTaskNatureCommand.TaskNatureId)))
}
if taskNature, err := taskNatureRepository.Remove(taskNature); 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 taskNature, nil
}
}
// 返回任务性质列表
func (taskNatureService *TaskNatureService) ListTaskNature(listTaskNatureQuery *query.ListTaskNatureQuery) (interface{}, error) {
if err := listTaskNatureQuery.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 taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskNatureRepository = value
}
if count, taskNatures, err := taskNatureRepository.Find(tool_funs.SimpleStructToMap(listTaskNatureQuery)); 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,
"taskNatures": taskNatures,
}, nil
}
}
func NewTaskNatureService(options map[string]interface{}) *TaskNatureService {
newTaskNatureService := &TaskNatureService{}
return newTaskNatureService
}
... ...
package domain
// 客户价值
type CustomerValue struct {
// 客户价值ID
CustomerValueId int `json:"customerValueId"`
// 客户价值名称
CustomerValueName string `json:"customerValueName"`
// 公司ID
CompanyId int64 `json:"companyId"`
}
type CustomerValueRepository interface {
Save(customerValue *CustomerValue) (*CustomerValue, error)
Remove(customerValue *CustomerValue) (*CustomerValue, error)
FindOne(queryOptions map[string]interface{}) (*CustomerValue, error)
Find(queryOptions map[string]interface{}) (int64, []*CustomerValue, error)
}
func (customerValue *CustomerValue) Identify() interface{} {
if customerValue.CustomerValueId == 0 {
return nil
}
return customerValue.CustomerValueId
}
func (customerValue *CustomerValue) Update(data map[string]interface{}) error {
if customerValueName, ok := data["customerValueName"]; ok {
customerValue.CustomerValueName = customerValueName.(string)
}
return nil
}
... ...
package domain
// 项目归属
type ProjectBelong struct {
// 项目归属ID
ProjectBelongId int `json:"projectBelongId"`
// 项目归属名称
ProjectBelongName string `json:"projectBelongName"`
// 公司ID
CompanyId int64 `json:"companyId"`
}
type ProjectBelongRepository interface {
Save(projectBelong *ProjectBelong) (*ProjectBelong, error)
Remove(projectBelong *ProjectBelong) (*ProjectBelong, error)
FindOne(queryOptions map[string]interface{}) (*ProjectBelong, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectBelong, error)
}
func (projectBelong *ProjectBelong) Identify() interface{} {
if projectBelong.ProjectBelongId == 0 {
return nil
}
return projectBelong.ProjectBelongId
}
func (projectBelong *ProjectBelong) Update(data map[string]interface{}) error {
if projectBelongName, ok := data["projectBelongName"]; ok {
projectBelong.ProjectBelongName = projectBelongName.(string)
}
return nil
}
... ...
... ... @@ -6,8 +6,9 @@ import (
)
const (
TASK_TYPE_ROB = iota + 1 //抢单任务
TASK_TYPE_BID //竞标任务
TASK_TYPE_ROB = iota + 1 //抢单任务
TASK_TYPE_BID //竞标任务
TASK_TYPE_DESIGNATE //指派任务
)
const (
... ... @@ -22,6 +23,7 @@ const (
TASK_STATUS_UNACCEPTANCE //待验收
TASK_STATUS_COMPLETED //已完成
TASK_STATUS_CLOSED //关闭
TASK_STATUS_UNCONFIRMED //待确认
)
// 任务
... ...
package domain
// 任务性质
type TaskNature struct {
// 任务性质ID
TaskNatureId int `json:"taskNatureId"`
// 任务性质名称
TaskNatureName string `json:"taskNatureName"`
// 公司ID
CompanyId int64 `json:"companyId"`
}
type TaskNatureRepository interface {
Save(taskNature *TaskNature) (*TaskNature, error)
Remove(taskNature *TaskNature) (*TaskNature, error)
FindOne(queryOptions map[string]interface{}) (*TaskNature, error)
Find(queryOptions map[string]interface{}) (int64, []*TaskNature, error)
}
func (taskNature *TaskNature) Identify() interface{} {
if taskNature.TaskNatureId == 0 {
return nil
}
return taskNature.TaskNatureId
}
func (taskNature *TaskNature) Update(data map[string]interface{}) error {
if taskNatureName, ok := data["taskNatureName"]; ok {
taskNature.TaskNatureName = taskNatureName.(string)
}
return nil
}
... ...
... ... @@ -30,6 +30,9 @@ func init() {
(*models.Task)(nil),
(*models.OffTaskRecord)(nil),
(*models.SuMoneyTransactionRecord)(nil),
(*models.CustomerValue)(nil),
(*models.TaskNature)(nil),
(*models.ProjectBelong)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
package models
type CustomerValue struct {
TableName string `pg:"customer_values,alias:customer_value"`
// 客户价值ID
Id int
// 客户价值名称
CustomerValueName string
// 公司ID
CompanyId int64
}
... ...
package models
type ProjectBelong struct {
TableName string `pg:"project_belongs,alias:project_belong"`
// 项目归属ID
Id int
// 项目归属名称
ProjectBelongName string
// 公司ID
CompanyId int64
}
... ...
package models
type TaskNature struct {
TableName string `pg:"task_natures,alias:task_nature"`
// 任务性质ID
Id int
// 任务性质名称
TaskNatureName string
// 公司ID
CompanyId int64
}
... ...
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 CustomerValueRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CustomerValueRepository) Save(customerValue *domain.CustomerValue) (*domain.CustomerValue, error) {
tx := repository.transactionContext.PgTx
if customerValue.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(&customerValue.CustomerValueId, &customerValue.CustomerValueName, &customerValue.CompanyId),
"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id, customer_value_name, company_id",
customerValue.CustomerValueName, customerValue.CompanyId); err != nil {
return customerValue, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&customerValue.CustomerValueId, &customerValue.CustomerValueName, &customerValue.CompanyId),
"UPDATE customer_values SET customer_value_name=?, company_id=? WHERE id=? RETURNING id, customer_value_name, company_id",
customerValue.CustomerValueName, customerValue.CompanyId, customerValue.Identify()); err != nil {
return customerValue, err
}
}
return customerValue, nil
}
func (repository *CustomerValueRepository) Remove(customerValue *domain.CustomerValue) (*domain.CustomerValue, error) {
tx := repository.transactionContext.PgTx
customerValueModel := new(models.CustomerValue)
customerValueModel.Id = customerValue.CustomerValueId
if _, err := tx.Model(customerValueModel).WherePK().Delete(); err != nil {
return customerValue, err
}
return customerValue, nil
}
func (repository *CustomerValueRepository) FindOne(queryOptions map[string]interface{}) (*domain.CustomerValue, error) {
tx := repository.transactionContext.PgTx
customerValueModel := new(models.CustomerValue)
query := tx.Model(customerValueModel)
if customerValueId, ok := queryOptions["customerValueId"]; ok {
query = query.Where("customer_value.id = ?", customerValueId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if customerValueModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(customerValueModel)
}
}
func (repository *CustomerValueRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CustomerValue, error) {
tx := repository.transactionContext.PgTx
var customerValueModels []*models.CustomerValue
customerValues := make([]*domain.CustomerValue, 0)
query := tx.Model(&customerValueModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("customer_value.company_id = ?", companyId)
}
if customerValueName, ok := queryOptions["customerValueName"]; ok && (customerValueName != "") {
query = query.Where(`customer_value.customer_value_name = ?`, customerValueName)
}
if customerValueNameMatch, ok := queryOptions["customerValueNameMatch"]; ok && (customerValueNameMatch != "") {
query = query.Where(`customer_value.customer_value_name LIKE ?`, fmt.Sprintf("%%%s%%", customerValueNameMatch.(string)))
}
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, customerValues, err
} else {
for _, customerValueModel := range customerValueModels {
if customerValue, err := repository.transformPgModelToDomainModel(customerValueModel); err != nil {
return 0, customerValues, err
} else {
customerValues = append(customerValues, customerValue)
}
customerValues = append(customerValues, &domain.CustomerValue{})
}
return int64(count), customerValues, nil
}
}
func (repository *CustomerValueRepository) transformPgModelToDomainModel(customerValueModel *models.CustomerValue) (*domain.CustomerValue, error) {
return &domain.CustomerValue{
CustomerValueId: customerValueModel.Id,
CustomerValueName: customerValueModel.CustomerValueName,
CompanyId: customerValueModel.CompanyId,
}, nil
}
func NewCustomerValueRepository(transactionContext *pgTransaction.TransactionContext) (*CustomerValueRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CustomerValueRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
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 ProjectBelongRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ProjectBelongRepository) Save(projectBelong *domain.ProjectBelong) (*domain.ProjectBelong, error) {
tx := repository.transactionContext.PgTx
if projectBelong.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(&projectBelong.ProjectBelongId, &projectBelong.ProjectBelongName, &projectBelong.CompanyId),
"INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id, project_belong_name, company_id",
projectBelong.ProjectBelongName, projectBelong.CompanyId); err != nil {
return projectBelong, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&projectBelong.ProjectBelongId, &projectBelong.ProjectBelongName, &projectBelong.CompanyId),
"UPDATE project_belongs SET project_belong_name=?, company_id=? WHERE id=? RETURNING id, project_belong_name, company_id",
projectBelong.ProjectBelongName, projectBelong.CompanyId, projectBelong.Identify()); err != nil {
return projectBelong, err
}
}
return projectBelong, nil
}
func (repository *ProjectBelongRepository) Remove(projectBelong *domain.ProjectBelong) (*domain.ProjectBelong, error) {
tx := repository.transactionContext.PgTx
projectBelongModel := new(models.ProjectBelong)
projectBelongModel.Id = projectBelong.Identify().(int)
if _, err := tx.Model(projectBelongModel).WherePK().Delete(); err != nil {
return projectBelong, err
}
return projectBelong, nil
}
func (repository *ProjectBelongRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectBelong, error) {
tx := repository.transactionContext.PgTx
projectBelongModel := new(models.ProjectBelong)
query := tx.Model(projectBelongModel)
if projectBelongId, ok := queryOptions["projectBelongId"]; ok {
query = query.Where("project_belong.id = ?", projectBelongId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if projectBelongModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(projectBelongModel)
}
}
func (repository *ProjectBelongRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectBelong, error) {
tx := repository.transactionContext.PgTx
var projectBelongModels []*models.ProjectBelong
projectBelongs := make([]*domain.ProjectBelong, 0)
query := tx.Model(&projectBelongModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("project_belong.company_id = ?", companyId)
}
if projectBelongName, ok := queryOptions["projectBelongName"]; ok && (projectBelongName != "") {
query = query.Where(`project_belong.project_belong_name = ?`, projectBelongName)
}
if projectBelongNameMatch, ok := queryOptions["projectBelongNameMatch"]; ok && (projectBelongNameMatch != "") {
query = query.Where(`project_belong.project_belong_name LIKE ?`, fmt.Sprintf("%%%s%%", projectBelongNameMatch.(string)))
}
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, projectBelongs, err
} else {
for _, projectBelongModel := range projectBelongModels {
if projectBelong, err := repository.transformPgModelToDomainModel(projectBelongModel); err != nil {
return 0, projectBelongs, err
} else {
projectBelongs = append(projectBelongs, projectBelong)
}
projectBelongs = append(projectBelongs, &domain.ProjectBelong{})
}
return int64(count), projectBelongs, nil
}
}
func (repository *ProjectBelongRepository) transformPgModelToDomainModel(projectBelongModel *models.ProjectBelong) (*domain.ProjectBelong, error) {
return &domain.ProjectBelong{
ProjectBelongId: projectBelongModel.Id,
ProjectBelongName: projectBelongModel.ProjectBelongName,
CompanyId: projectBelongModel.CompanyId,
}, nil
}
func NewProjectBelongRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectBelongRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProjectBelongRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
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 TaskNatureRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *TaskNatureRepository) Save(taskNature *domain.TaskNature) (*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
if taskNature.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(&taskNature.TaskNatureId, &taskNature.TaskNatureName, &taskNature.CompanyId),
"INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id, task_nature_name, company_id",
taskNature.TaskNatureName, taskNature.CompanyId); err != nil {
return taskNature, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&taskNature.TaskNatureId, &taskNature.TaskNatureName, &taskNature.CompanyId),
"UPDATE task_natures SET task_nature_name=?, company_id=? WHERE id=? RETURNING id, task_nature_name, company_id",
taskNature.TaskNatureName, taskNature.CompanyId, taskNature.Identify()); err != nil {
return taskNature, err
}
}
return taskNature, nil
}
func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
taskNatureModel := new(models.TaskNature)
taskNatureModel.Id = taskNature.Identify().(int)
if _, err := tx.Model(taskNatureModel).WherePK().Delete(); err != nil {
return taskNature, err
}
return taskNature, nil
}
func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
taskNatureModel := new(models.TaskNature)
query := tx.Model(taskNatureModel)
if taskNatureId, ok := queryOptions["taskNatureId"]; ok {
query = query.Where("task_nature.id = ?", taskNatureId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if taskNatureModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(taskNatureModel)
}
}
func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
var taskNatureModels []*models.TaskNature
taskNatures := make([]*domain.TaskNature, 0)
query := tx.Model(&taskNatureModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("task_nature.company_id = ?", companyId)
}
if taskNatureName, ok := queryOptions["taskNatureName"]; ok && (taskNatureName != "") {
query = query.Where(`task_nature.task_nature_name = ?`, taskNatureName)
}
if taskNatureNameMatch, ok := queryOptions["taskNatureNameMatch"]; ok && (taskNatureNameMatch != "") {
query = query.Where(`task_nature.task_nature_name LIKE ?`, fmt.Sprintf("%%%s%%", taskNatureNameMatch.(string)))
}
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, taskNatures, err
} else {
for _, taskNatureModel := range taskNatureModels {
if taskNature, err := repository.transformPgModelToDomainModel(taskNatureModel); err != nil {
return 0, taskNatures, err
} else {
taskNatures = append(taskNatures, taskNature)
}
taskNatures = append(taskNatures, &domain.TaskNature{})
}
return int64(count), taskNatures, nil
}
}
func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNatureModel *models.TaskNature) (*domain.TaskNature, error) {
return &domain.TaskNature{
TaskNatureId: taskNatureModel.Id,
TaskNatureName: taskNatureModel.TaskNatureName,
CompanyId: taskNatureModel.CompanyId,
}, nil
}
func NewTaskNatureRepository(transactionContext *pgTransaction.TransactionContext) (*TaskNatureRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &TaskNatureRepository{
transactionContext: transactionContext,
}, 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/customerValue/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/service"
)
type CustomerValueController struct {
beego.Controller
}
func (controller *CustomerValueController) CreateCustomerValue() {
customerValueService := service.NewCustomerValueService(nil)
createCustomerValueCommand := &command.CreateCustomerValueCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createCustomerValueCommand)
data, err := customerValueService.CreateCustomerValue(createCustomerValueCommand)
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 *CustomerValueController) UpdateCustomerValue() {
customerValueService := service.NewCustomerValueService(nil)
updateCustomerValueCommand := &command.UpdateCustomerValueCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateCustomerValueCommand)
customerValueId, _ := controller.GetInt(":customerValueId")
updateCustomerValueCommand.CustomerValueId = customerValueId
data, err := customerValueService.UpdateCustomerValue(updateCustomerValueCommand)
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 *CustomerValueController) GetCustomerValue() {
customerValueService := service.NewCustomerValueService(nil)
getCustomerValueQuery := &query.GetCustomerValueQuery{}
customerValueId, _ := controller.GetInt(":customerValueId")
getCustomerValueQuery.CustomerValueId = customerValueId
data, err := customerValueService.GetCustomerValue(getCustomerValueQuery)
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 *CustomerValueController) RemoveCustomerValue() {
customerValueService := service.NewCustomerValueService(nil)
removeCustomerValueCommand := &command.RemoveCustomerValueCommand{}
customerValueId, _ := controller.GetInt(":customerValueId")
removeCustomerValueCommand.CustomerValueId = customerValueId
data, err := customerValueService.RemoveCustomerValue(removeCustomerValueCommand)
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 *CustomerValueController) ListCustomerValue() {
customerValueService := service.NewCustomerValueService(nil)
listCustomerValueQuery := &query.ListCustomerValueQuery{}
companyId, _ := controller.GetInt64("companyId")
listCustomerValueQuery.CompanyId = companyId
customerValueName := controller.GetString("customerValueName")
listCustomerValueQuery.CustomerValueName = customerValueName
customerValueNameMatch := controller.GetString("customerValueNameMatch")
listCustomerValueQuery.CustomerValueNameMatch = customerValueNameMatch
offset, _ := controller.GetInt("offset")
listCustomerValueQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listCustomerValueQuery.Limit = limit
data, err := customerValueService.ListCustomerValue(listCustomerValueQuery)
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 controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/service"
)
type ProjectBelongController struct {
beego.Controller
}
func (controller *ProjectBelongController) CreateProjectBelong() {
projectBelongService := service.NewProjectBelongService(nil)
createProjectBelongCommand := &command.CreateProjectBelongCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectBelongCommand)
data, err := projectBelongService.CreateProjectBelong(createProjectBelongCommand)
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 *ProjectBelongController) UpdateProjectBelong() {
projectBelongService := service.NewProjectBelongService(nil)
updateProjectBelongCommand := &command.UpdateProjectBelongCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectBelongCommand)
projectBelongId, _ := controller.GetInt(":projectBelongId")
updateProjectBelongCommand.ProjectBelongId = projectBelongId
data, err := projectBelongService.UpdateProjectBelong(updateProjectBelongCommand)
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 *ProjectBelongController) GetProjectBelong() {
projectBelongService := service.NewProjectBelongService(nil)
getProjectBelongQuery := &query.GetProjectBelongQuery{}
projectBelongId, _ := controller.GetInt(":projectBelongId")
getProjectBelongQuery.ProjectBelongId = projectBelongId
data, err := projectBelongService.GetProjectBelong(getProjectBelongQuery)
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 *ProjectBelongController) RemoveProjectBelong() {
projectBelongService := service.NewProjectBelongService(nil)
removeProjectBelongCommand := &command.RemoveProjectBelongCommand{}
projectBelongId, _ := controller.GetInt(":projectBelongId")
removeProjectBelongCommand.ProjectBelongId = projectBelongId
data, err := projectBelongService.RemoveProjectBelong(removeProjectBelongCommand)
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 *ProjectBelongController) ListProjectBelong() {
projectBelongService := service.NewProjectBelongService(nil)
listProjectBelongQuery := &query.ListProjectBelongQuery{}
companyId, _ := controller.GetInt64("companyId")
listProjectBelongQuery.CompanyId = companyId
projectBelongName := controller.GetString("projectBelongName")
listProjectBelongQuery.ProjectBelongName = projectBelongName
projectBelongNameMatch := controller.GetString("projectBelongNameMatch")
listProjectBelongQuery.ProjectBelongNameMatch = projectBelongNameMatch
offset, _ := controller.GetInt("offset")
listProjectBelongQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProjectBelongQuery.Limit = limit
data, err := projectBelongService.ListProjectBelong(listProjectBelongQuery)
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 controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/service"
)
type TaskNatureController struct {
beego.Controller
}
func (controller *TaskNatureController) CreateTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
createTaskNatureCommand := &command.CreateTaskNatureCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createTaskNatureCommand)
data, err := taskNatureService.CreateTaskNature(createTaskNatureCommand)
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 *TaskNatureController) UpdateTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
updateTaskNatureCommand := &command.UpdateTaskNatureCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskNatureCommand)
taskNatureId, _ := controller.GetInt(":taskNatureId")
updateTaskNatureCommand.TaskNatureId = taskNatureId
data, err := taskNatureService.UpdateTaskNature(updateTaskNatureCommand)
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 *TaskNatureController) GetTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
getTaskNatureQuery := &query.GetTaskNatureQuery{}
taskNatureId, _ := controller.GetInt(":taskNatureId")
getTaskNatureQuery.TaskNatureId = taskNatureId
data, err := taskNatureService.GetTaskNature(getTaskNatureQuery)
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 *TaskNatureController) RemoveTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
removeTaskNatureCommand := &command.RemoveTaskNatureCommand{}
taskNatureId, _ := controller.GetInt(":taskNatureId")
removeTaskNatureCommand.TaskNatureId = taskNatureId
data, err := taskNatureService.RemoveTaskNature(removeTaskNatureCommand)
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 *TaskNatureController) ListTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
listTaskNatureQuery := &query.ListTaskNatureQuery{}
companyId, _ := controller.GetInt64("companyId")
listTaskNatureQuery.CompanyId = companyId
taskNatureName := controller.GetString("taskNatureName")
listTaskNatureQuery.TaskNatureName = taskNatureName
taskNatureNameMatch := controller.GetString("taskNatureNameMatch")
listTaskNatureQuery.TaskNatureNameMatch = taskNatureNameMatch
offset, _ := controller.GetInt("offset")
listTaskNatureQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listTaskNatureQuery.Limit = limit
data, err := taskNatureService.ListTaskNature(listTaskNatureQuery)
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("/customer-values/", &controllers.CustomerValueController{}, "Post:CreateCustomerValue")
beego.Router("/customer-values/:customerValueId", &controllers.CustomerValueController{}, "Put:UpdateCustomerValue")
beego.Router("/customer-values/:customerValueId", &controllers.CustomerValueController{}, "Get:GetCustomerValue")
beego.Router("/customer-values/:customerValueId", &controllers.CustomerValueController{}, "Delete:RemoveCustomerValue")
beego.Router("/customer-values/", &controllers.CustomerValueController{}, "Get:ListCustomerValue")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project-belongs/", &controllers.ProjectBelongController{}, "Post:CreateProjectBelong")
beego.Router("/project-belongs/:projectBelongId", &controllers.ProjectBelongController{}, "Put:UpdateProjectBelong")
beego.Router("/project-belongs/:projectBelongId", &controllers.ProjectBelongController{}, "Get:GetProjectBelong")
beego.Router("/project-belongs/:projectBelongId", &controllers.ProjectBelongController{}, "Delete:RemoveProjectBelong")
beego.Router("/project-belongs/", &controllers.ProjectBelongController{}, "Get:ListProjectBelong")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
)
func init() {
beego.Router("/task-natures/", &controllers.TaskNatureController{}, "Post:CreateTaskNature")
beego.Router("/task-natures/:taskNatureId", &controllers.TaskNatureController{}, "Put:UpdateTaskNature")
beego.Router("/task-natures/:taskNatureId", &controllers.TaskNatureController{}, "Get:GetTaskNature")
beego.Router("/task-natures/:taskNatureId", &controllers.TaskNatureController{}, "Delete:RemoveTaskNature")
beego.Router("/task-natures/", &controllers.TaskNatureController{}, "Get:ListTaskNature")
}
... ...
package customer_value
import (
"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() {
It("返回客户价值数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"customerValueName": "口味",
}
httpExpect.POST("/customer-values/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("customerValueId").ValueNotEqual("customerValueId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package customer_value
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 TestCustomerValue(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port CustomerValue 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 customer_value
import (
"fmt"
"net/http"
"strconv"
"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 customerValueId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&customerValueId),
"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
"口味", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据customerValueId参数返回客户价值", func() {
Context("传入有效的customerValueId", func() {
It("返回客户价值数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
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 customer_values WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package customer_value
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 customerValueId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&customerValueId),
"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
"口味", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回客户价值列表", func() {
Context("传入有效的参数", func() {
It("返回客户价值数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/customer-values/").
WithQuery("companyId", 101).
WithQuery("customerValueNameMatch", "口").
WithQuery("offset", 0).
WithQuery("limit", 20).
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("customerValues").Value("customerValues").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package customer_value
import (
"fmt"
"net/http"
"strconv"
"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 customerValueId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&customerValueId),
"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
"口味", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除客户价值", func() {
Context("传入有效的customerValueId", func() {
It("返回被移除客户价值的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
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 customer_values WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package customer_value
import (
"fmt"
"net/http"
"strconv"
"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 customerValueId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&customerValueId),
"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
"口感", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新客户价值", func() {
Context("提交正确的客户价值数据", func() {
It("返回更新后的客户价值数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"customerValueName": "口味",
}
httpExpect.PUT(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("customerValueId").ValueEqual("customerValueId", customerValueId).
ContainsKey("customerValueName").ValueEqual("customerValueName", "口味")
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_belong
import (
"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() {
It("返回项目归属数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"projectBelongName": "能力展示",
}
httpExpect.POST("/project-belongs/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("projectBelongId").ValueNotEqual("projectBelongId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_belong
import (
"fmt"
"net/http"
"strconv"
"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 projectBelongId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectBelongId),
"INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
"能力展示", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据projectBelongId参数返回项目归属", func() {
Context("传入有效的projectBelongId", func() {
It("返回项目归属数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET(fmt.Sprintf("/project-belongs/%s", strconv.FormatInt(projectBelongId, 10))).
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 project_belongs WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_belong
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 projectBelongId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectBelongId),
"INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
"能力展示", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回项目归属列表", func() {
Context("传入有效的参数", func() {
It("返回项目归属数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-belongs/").
WithQuery("companyId", 101).
WithQuery("projectBelongNameMatch", "力").
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("projectBelongs").Value("projectBelongs").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_belong
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 TestProjectBelong(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port ProjectBelong 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 project_belong
import (
"fmt"
"net/http"
"strconv"
"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 projectBelongId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectBelongId),
"INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
"能力展示", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除项目归属", func() {
Context("传入有效的projectBelongId", func() {
It("返回被移除项目归属的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE(fmt.Sprintf("/project-belongs/%s", strconv.FormatInt(projectBelongId, 10))).
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 project_belongs WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_belong
import (
"fmt"
"net/http"
"strconv"
"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 projectBelongId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectBelongId),
"INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
"能力展示", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新项目归属", func() {
Context("提交正确的项目归属数据", func() {
It("返回更新后的项目归属数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"projectBelongName": "销售导航",
}
httpExpect.PUT(fmt.Sprintf("/project-belongs/%s", strconv.FormatInt(projectBelongId, 10))).
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("projectBelongId").ValueEqual("projectBelongId", projectBelongId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task_nature
import (
"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() {
It("返回任务性质数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"taskNatureName": "点",
}
httpExpect.POST("/task-natures/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskNatureId").ValueNotEqual("taskNatureId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task_nature
import (
"fmt"
"net/http"
"strconv"
"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 taskNatureId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&taskNatureId),
"INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
"点", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据taskNatureId参数返回任务性质", func() {
Context("传入有效的taskNatureId", func() {
It("返回任务性质数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET(fmt.Sprintf("/task-natures/%s", strconv.FormatInt(taskNatureId, 10))).
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 task_natures WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task_nature
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 taskNatureId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&taskNatureId),
"INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
"点", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回任务性质列表", func() {
Context("传入有效的参数", func() {
It("返回任务性质数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/task-natures/").
WithQuery("companyId", 101).
WithQuery("taskNatureNameMatch", "面").
WithQuery("offset", 0).
WithQuery("limit", 20).
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", 0).
ContainsKey("taskNatures").Value("taskNatures").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task_nature
import (
"fmt"
"net/http"
"strconv"
"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 taskNatureId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&taskNatureId),
"INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
"点", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除任务性质", func() {
Context("传入有效的taskNatureId", func() {
It("返回被移除任务性质的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE(fmt.Sprintf("/task-natures/%s", strconv.FormatInt(taskNatureId, 10))).
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 task_natures WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package task_nature
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 TestTaskNature(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port TaskNature 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_nature
import (
"fmt"
"net/http"
"strconv"
"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 taskNatureId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&taskNatureId),
"INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
"点", 101)
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新任务性质", func() {
Context("提交正确的任务性质数据", func() {
It("返回更新后的任务性质数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"taskNatureName": "面",
}
httpExpect.PUT(fmt.Sprintf("/task-natures/%s", strconv.FormatInt(taskNatureId, 10))).
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskNatureId").ValueEqual("taskNatureId", taskNatureId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...