作者 linmadan

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

正在显示 54 个修改的文件 包含 2745 行增加0 行删除
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type CreateCustomerValueCommand struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 + // 客户价值名称
  13 + CustomerValueName string `json:"customerValueName" valid:"Required"`
  14 +}
  15 +
  16 +func (createCustomerValueCommand *CreateCustomerValueCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(createCustomerValueCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type RemoveCustomerValueCommand struct {
  10 + // 客户价值ID
  11 + CustomerValueId int `json:"customerValueId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeCustomerValueCommand *RemoveCustomerValueCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(removeCustomerValueCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type UpdateCustomerValueCommand struct {
  10 + // 客户价值ID
  11 + CustomerValueId int `json:"customerValueId,omitempty"`
  12 + // 客户价值名称
  13 + CustomerValueName string `json:"customerValueName,omitempty"`
  14 +}
  15 +
  16 +func (updateCustomerValueCommand *UpdateCustomerValueCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(updateCustomerValueCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetCustomerValueQuery struct {
  10 + // 客户价值ID
  11 + CustomerValueId int `json:"customerValueId" valid:"Required"`
  12 +}
  13 +
  14 +func (getCustomerValueQuery *GetCustomerValueQuery) ValidateQuery() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(getCustomerValueQuery)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type ListCustomerValueQuery struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 + // 客户价值名称
  13 + CustomerValueName string `json:"customerValueName,omitempty"`
  14 + // 客户价值名称匹配
  15 + CustomerValueNameMatch string `json:"customerValueNameMatch,omitempty"`
  16 + // 查询偏离量
  17 + Offset int `json:"offset,omitempty"`
  18 + // 查询限制
  19 + Limit int `json:"limit,omitempty"`
  20 +}
  21 +
  22 +func (listCustomerValueQuery *ListCustomerValueQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listCustomerValueQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + for _, validErr := range valid.Errors {
  30 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  31 + }
  32 + }
  33 + return nil
  34 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/query"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 +)
  12 +
  13 +// 客户价值服务
  14 +type CustomerValueService struct {
  15 +}
  16 +
  17 +// 创建客户价值
  18 +func (customerValueService *CustomerValueService) CreateCustomerValue(createCustomerValueCommand *command.CreateCustomerValueCommand) (interface{}, error) {
  19 + if err := createCustomerValueCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newCustomerValue := &domain.CustomerValue{
  33 + CompanyId: createCustomerValueCommand.CompanyId,
  34 + CustomerValueName: createCustomerValueCommand.CustomerValueName,
  35 + }
  36 + var customerValueRepository domain.CustomerValueRepository
  37 + if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
  38 + "transactionContext": transactionContext,
  39 + }); err != nil {
  40 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  41 + } else {
  42 + customerValueRepository = value
  43 + }
  44 + if count, _, err := customerValueRepository.Find(map[string]interface{}{
  45 + "customerValueName": createCustomerValueCommand.CustomerValueName,
  46 + }); err != nil {
  47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 + } else {
  49 + if count > 0 {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
  51 + }
  52 + }
  53 + if customerValue, err := customerValueRepository.Save(newCustomerValue); err != nil {
  54 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  55 + } else {
  56 + if err := transactionContext.CommitTransaction(); err != nil {
  57 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  58 + }
  59 + return customerValue, nil
  60 + }
  61 +}
  62 +
  63 +// 返回客户价值
  64 +func (customerValueService *CustomerValueService) GetCustomerValue(getCustomerValueQuery *query.GetCustomerValueQuery) (interface{}, error) {
  65 + if err := getCustomerValueQuery.ValidateQuery(); err != nil {
  66 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  67 + }
  68 + transactionContext, err := factory.CreateTransactionContext(nil)
  69 + if err != nil {
  70 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  71 + }
  72 + if err := transactionContext.StartTransaction(); err != nil {
  73 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  74 + }
  75 + defer func() {
  76 + transactionContext.RollbackTransaction()
  77 + }()
  78 + var customerValueRepository domain.CustomerValueRepository
  79 + if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
  80 + "transactionContext": transactionContext,
  81 + }); err != nil {
  82 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  83 + } else {
  84 + customerValueRepository = value
  85 + }
  86 + customerValue, err := customerValueRepository.FindOne(map[string]interface{}{"customerValueId": getCustomerValueQuery.CustomerValueId})
  87 + if err != nil {
  88 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  89 + }
  90 + if customerValue == nil {
  91 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCustomerValueQuery.CustomerValueId)))
  92 + } else {
  93 + if err := transactionContext.CommitTransaction(); err != nil {
  94 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  95 + }
  96 + return customerValue, nil
  97 + }
  98 +}
  99 +
  100 +// 更新客户价值
  101 +func (customerValueService *CustomerValueService) UpdateCustomerValue(updateCustomerValueCommand *command.UpdateCustomerValueCommand) (interface{}, error) {
  102 + if err := updateCustomerValueCommand.ValidateCommand(); err != nil {
  103 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  104 + }
  105 + transactionContext, err := factory.CreateTransactionContext(nil)
  106 + if err != nil {
  107 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  108 + }
  109 + if err := transactionContext.StartTransaction(); err != nil {
  110 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  111 + }
  112 + defer func() {
  113 + transactionContext.RollbackTransaction()
  114 + }()
  115 + var customerValueRepository domain.CustomerValueRepository
  116 + if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
  117 + "transactionContext": transactionContext,
  118 + }); err != nil {
  119 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  120 + } else {
  121 + customerValueRepository = value
  122 + }
  123 + customerValue, err := customerValueRepository.FindOne(map[string]interface{}{"customerValueId": updateCustomerValueCommand.CustomerValueId})
  124 + if err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + }
  127 + if customerValue == nil {
  128 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCustomerValueCommand.CustomerValueId)))
  129 + }
  130 + if count, customerValues, err := customerValueRepository.Find(map[string]interface{}{
  131 + "customerValueName": updateCustomerValueCommand.CustomerValueName,
  132 + }); err != nil {
  133 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  134 + } else {
  135 + if count > 0 && customerValues[0].CustomerValueId != customerValue.CustomerValueId {
  136 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
  137 + }
  138 + }
  139 + if err := customerValue.Update(tool_funs.SimpleStructToMap(updateCustomerValueCommand)); err != nil {
  140 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  141 + }
  142 + if customerValue, err := customerValueRepository.Save(customerValue); err != nil {
  143 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  144 + } else {
  145 + if err := transactionContext.CommitTransaction(); err != nil {
  146 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + return customerValue, nil
  149 + }
  150 +}
  151 +
  152 +// 移除客户价值
  153 +func (customerValueService *CustomerValueService) RemoveCustomerValue(removeCustomerValueCommand *command.RemoveCustomerValueCommand) (interface{}, error) {
  154 + if err := removeCustomerValueCommand.ValidateCommand(); err != nil {
  155 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  156 + }
  157 + transactionContext, err := factory.CreateTransactionContext(nil)
  158 + if err != nil {
  159 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  160 + }
  161 + if err := transactionContext.StartTransaction(); err != nil {
  162 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  163 + }
  164 + defer func() {
  165 + transactionContext.RollbackTransaction()
  166 + }()
  167 + var customerValueRepository domain.CustomerValueRepository
  168 + if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
  169 + "transactionContext": transactionContext,
  170 + }); err != nil {
  171 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  172 + } else {
  173 + customerValueRepository = value
  174 + }
  175 + customerValue, err := customerValueRepository.FindOne(map[string]interface{}{"customerValueId": removeCustomerValueCommand.CustomerValueId})
  176 + if err != nil {
  177 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  178 + }
  179 + if customerValue == nil {
  180 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCustomerValueCommand.CustomerValueId)))
  181 + }
  182 + if customerValue, err := customerValueRepository.Remove(customerValue); err != nil {
  183 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  184 + } else {
  185 + if err := transactionContext.CommitTransaction(); err != nil {
  186 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  187 + }
  188 + return customerValue, nil
  189 + }
  190 +}
  191 +
  192 +// 返回客户价值列表
  193 +func (customerValueService *CustomerValueService) ListCustomerValue(listCustomerValueQuery *query.ListCustomerValueQuery) (interface{}, error) {
  194 + if err := listCustomerValueQuery.ValidateQuery(); err != nil {
  195 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  196 + }
  197 + transactionContext, err := factory.CreateTransactionContext(nil)
  198 + if err != nil {
  199 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  200 + }
  201 + if err := transactionContext.StartTransaction(); err != nil {
  202 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  203 + }
  204 + defer func() {
  205 + transactionContext.RollbackTransaction()
  206 + }()
  207 + var customerValueRepository domain.CustomerValueRepository
  208 + if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
  209 + "transactionContext": transactionContext,
  210 + }); err != nil {
  211 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  212 + } else {
  213 + customerValueRepository = value
  214 + }
  215 + if count, customerValues, err := customerValueRepository.Find(tool_funs.SimpleStructToMap(listCustomerValueQuery)); err != nil {
  216 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  217 + } else {
  218 + if err := transactionContext.CommitTransaction(); err != nil {
  219 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  220 + }
  221 + return map[string]interface{}{
  222 + "count": count,
  223 + "customerValues": customerValues,
  224 + }, nil
  225 + }
  226 +}
  227 +
  228 +func NewCustomerValueService(options map[string]interface{}) *CustomerValueService {
  229 + newCustomerValueService := &CustomerValueService{}
  230 + return newCustomerValueService
  231 +}
@@ -37,3 +37,27 @@ func CreateSuMoneyTransactionRecordRepository(options map[string]interface{}) (d @@ -37,3 +37,27 @@ func CreateSuMoneyTransactionRecordRepository(options map[string]interface{}) (d
37 } 37 }
38 return repository.NewSuMoneyTransactionRecordRepository(transactionContext) 38 return repository.NewSuMoneyTransactionRecordRepository(transactionContext)
39 } 39 }
  40 +
  41 +func CreateCustomerValueRepository(options map[string]interface{}) (domain.CustomerValueRepository, error) {
  42 + var transactionContext *pg.TransactionContext
  43 + if value, ok := options["transactionContext"]; ok {
  44 + transactionContext = value.(*pg.TransactionContext)
  45 + }
  46 + return repository.NewCustomerValueRepository(transactionContext)
  47 +}
  48 +
  49 +func CreateTaskNatureRepository(options map[string]interface{}) (domain.TaskNatureRepository, error) {
  50 + var transactionContext *pg.TransactionContext
  51 + if value, ok := options["transactionContext"]; ok {
  52 + transactionContext = value.(*pg.TransactionContext)
  53 + }
  54 + return repository.NewTaskNatureRepository(transactionContext)
  55 +}
  56 +
  57 +func CreateProjectBelongRepository(options map[string]interface{}) (domain.ProjectBelongRepository, error) {
  58 + var transactionContext *pg.TransactionContext
  59 + if value, ok := options["transactionContext"]; ok {
  60 + transactionContext = value.(*pg.TransactionContext)
  61 + }
  62 + return repository.NewProjectBelongRepository(transactionContext)
  63 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type CreateProjectBelongCommand struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 + // 项目归属名称
  13 + ProjectBelongName string `json:"projectBelongName" valid:"Required"`
  14 +}
  15 +
  16 +func (createProjectBelongCommand *CreateProjectBelongCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(createProjectBelongCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type RemoveProjectBelongCommand struct {
  10 + // 项目归属ID
  11 + ProjectBelongId int `json:"projectBelongId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeProjectBelongCommand *RemoveProjectBelongCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(removeProjectBelongCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type UpdateProjectBelongCommand struct {
  10 + // 项目归属ID
  11 + ProjectBelongId int `json:"projectBelongId,omitempty"`
  12 + // 项目归属名称
  13 + ProjectBelongName string `json:"projectBelongName,omitempty"`
  14 +}
  15 +
  16 +func (updateProjectBelongCommand *UpdateProjectBelongCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(updateProjectBelongCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetProjectBelongQuery struct {
  10 + // 项目归属ID
  11 + ProjectBelongId int `json:"projectBelongId" valid:"Required"`
  12 +}
  13 +
  14 +func (getProjectBelongQuery *GetProjectBelongQuery) ValidateQuery() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(getProjectBelongQuery)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type ListProjectBelongQuery struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 + // 项目归属名称
  13 + ProjectBelongName string `json:"projectBelongName,omitempty"`
  14 + // 项目归属名称匹配
  15 + ProjectBelongNameMatch string `json:"projectBelongNameMatch,omitempty"`
  16 + // 查询偏离量
  17 + Offset int `json:"offset,omitempty"`
  18 + // 查询限制
  19 + Limit int `json:"limit,omitempty"`
  20 +}
  21 +
  22 +func (listProjectBelongQuery *ListProjectBelongQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProjectBelongQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + for _, validErr := range valid.Errors {
  30 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  31 + }
  32 + }
  33 + return nil
  34 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 +)
  12 +
  13 +// 项目归属服务
  14 +type ProjectBelongService struct {
  15 +}
  16 +
  17 +// 创建项目归属
  18 +func (projectBelongService *ProjectBelongService) CreateProjectBelong(createProjectBelongCommand *command.CreateProjectBelongCommand) (interface{}, error) {
  19 + if err := createProjectBelongCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProjectBelong := &domain.ProjectBelong{
  33 + CompanyId: createProjectBelongCommand.CompanyId,
  34 + ProjectBelongName: createProjectBelongCommand.ProjectBelongName,
  35 + }
  36 + var projectBelongRepository domain.ProjectBelongRepository
  37 + if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
  38 + "transactionContext": transactionContext,
  39 + }); err != nil {
  40 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  41 + } else {
  42 + projectBelongRepository = value
  43 + }
  44 + if count, _, err := projectBelongRepository.Find(map[string]interface{}{
  45 + "projectBelongName": createProjectBelongCommand.ProjectBelongName,
  46 + }); err != nil {
  47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 + } else {
  49 + if count > 0 {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
  51 + }
  52 + }
  53 + if projectBelong, err := projectBelongRepository.Save(newProjectBelong); err != nil {
  54 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  55 + } else {
  56 + if err := transactionContext.CommitTransaction(); err != nil {
  57 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  58 + }
  59 + return projectBelong, nil
  60 + }
  61 +}
  62 +
  63 +// 返回项目归属
  64 +func (projectBelongService *ProjectBelongService) GetProjectBelong(getProjectBelongQuery *query.GetProjectBelongQuery) (interface{}, error) {
  65 + if err := getProjectBelongQuery.ValidateQuery(); err != nil {
  66 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  67 + }
  68 + transactionContext, err := factory.CreateTransactionContext(nil)
  69 + if err != nil {
  70 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  71 + }
  72 + if err := transactionContext.StartTransaction(); err != nil {
  73 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  74 + }
  75 + defer func() {
  76 + transactionContext.RollbackTransaction()
  77 + }()
  78 + var projectBelongRepository domain.ProjectBelongRepository
  79 + if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
  80 + "transactionContext": transactionContext,
  81 + }); err != nil {
  82 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  83 + } else {
  84 + projectBelongRepository = value
  85 + }
  86 + projectBelong, err := projectBelongRepository.FindOne(map[string]interface{}{"projectBelongId": getProjectBelongQuery.ProjectBelongId})
  87 + if err != nil {
  88 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  89 + }
  90 + if projectBelong == nil {
  91 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectBelongQuery.ProjectBelongId)))
  92 + } else {
  93 + if err := transactionContext.CommitTransaction(); err != nil {
  94 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  95 + }
  96 + return projectBelong, nil
  97 + }
  98 +}
  99 +
  100 +// 更新项目归属
  101 +func (projectBelongService *ProjectBelongService) UpdateProjectBelong(updateProjectBelongCommand *command.UpdateProjectBelongCommand) (interface{}, error) {
  102 + if err := updateProjectBelongCommand.ValidateCommand(); err != nil {
  103 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  104 + }
  105 + transactionContext, err := factory.CreateTransactionContext(nil)
  106 + if err != nil {
  107 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  108 + }
  109 + if err := transactionContext.StartTransaction(); err != nil {
  110 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  111 + }
  112 + defer func() {
  113 + transactionContext.RollbackTransaction()
  114 + }()
  115 + var projectBelongRepository domain.ProjectBelongRepository
  116 + if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
  117 + "transactionContext": transactionContext,
  118 + }); err != nil {
  119 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  120 + } else {
  121 + projectBelongRepository = value
  122 + }
  123 + projectBelong, err := projectBelongRepository.FindOne(map[string]interface{}{"projectBelongId": updateProjectBelongCommand.ProjectBelongId})
  124 + if err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + }
  127 + if projectBelong == nil {
  128 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectBelongCommand.ProjectBelongId)))
  129 + }
  130 + if count, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
  131 + "projectBelongName": updateProjectBelongCommand.ProjectBelongName,
  132 + }); err != nil {
  133 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  134 + } else {
  135 + if count > 0 && projectBelongs[0].ProjectBelongId != projectBelong.ProjectBelongId {
  136 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
  137 + }
  138 + }
  139 + if err := projectBelong.Update(tool_funs.SimpleStructToMap(updateProjectBelongCommand)); err != nil {
  140 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  141 + }
  142 + if projectBelong, err := projectBelongRepository.Save(projectBelong); err != nil {
  143 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  144 + } else {
  145 + if err := transactionContext.CommitTransaction(); err != nil {
  146 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + return projectBelong, nil
  149 + }
  150 +}
  151 +
  152 +// 移除项目归属
  153 +func (projectBelongService *ProjectBelongService) RemoveProjectBelong(removeProjectBelongCommand *command.RemoveProjectBelongCommand) (interface{}, error) {
  154 + if err := removeProjectBelongCommand.ValidateCommand(); err != nil {
  155 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  156 + }
  157 + transactionContext, err := factory.CreateTransactionContext(nil)
  158 + if err != nil {
  159 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  160 + }
  161 + if err := transactionContext.StartTransaction(); err != nil {
  162 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  163 + }
  164 + defer func() {
  165 + transactionContext.RollbackTransaction()
  166 + }()
  167 + var projectBelongRepository domain.ProjectBelongRepository
  168 + if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
  169 + "transactionContext": transactionContext,
  170 + }); err != nil {
  171 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  172 + } else {
  173 + projectBelongRepository = value
  174 + }
  175 + projectBelong, err := projectBelongRepository.FindOne(map[string]interface{}{"projectBelongId": removeProjectBelongCommand.ProjectBelongId})
  176 + if err != nil {
  177 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  178 + }
  179 + if projectBelong == nil {
  180 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectBelongCommand.ProjectBelongId)))
  181 + }
  182 + if projectBelong, err := projectBelongRepository.Remove(projectBelong); err != nil {
  183 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  184 + } else {
  185 + if err := transactionContext.CommitTransaction(); err != nil {
  186 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  187 + }
  188 + return projectBelong, nil
  189 + }
  190 +}
  191 +
  192 +// 返回项目归属列表
  193 +func (projectBelongService *ProjectBelongService) ListProjectBelong(listProjectBelongQuery *query.ListProjectBelongQuery) (interface{}, error) {
  194 + if err := listProjectBelongQuery.ValidateQuery(); err != nil {
  195 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  196 + }
  197 + transactionContext, err := factory.CreateTransactionContext(nil)
  198 + if err != nil {
  199 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  200 + }
  201 + if err := transactionContext.StartTransaction(); err != nil {
  202 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  203 + }
  204 + defer func() {
  205 + transactionContext.RollbackTransaction()
  206 + }()
  207 + var projectBelongRepository domain.ProjectBelongRepository
  208 + if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
  209 + "transactionContext": transactionContext,
  210 + }); err != nil {
  211 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  212 + } else {
  213 + projectBelongRepository = value
  214 + }
  215 + if count, projectBelongs, err := projectBelongRepository.Find(tool_funs.SimpleStructToMap(listProjectBelongQuery)); err != nil {
  216 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  217 + } else {
  218 + if err := transactionContext.CommitTransaction(); err != nil {
  219 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  220 + }
  221 + return map[string]interface{}{
  222 + "count": count,
  223 + "projectBelongs": projectBelongs,
  224 + }, nil
  225 + }
  226 +}
  227 +
  228 +func NewProjectBelongService(options map[string]interface{}) *ProjectBelongService {
  229 + newProjectBelongService := &ProjectBelongService{}
  230 + return newProjectBelongService
  231 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type CreateTaskNatureCommand struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 + // 任务性质名称
  13 + TaskNatureName string `json:"taskNatureName" valid:"Required"`
  14 +}
  15 +
  16 +func (createTaskNatureCommand *CreateTaskNatureCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(createTaskNatureCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type RemoveTaskNatureCommand struct {
  10 + // 任务性质ID
  11 + TaskNatureId int `json:"taskNatureId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeTaskNatureCommand *RemoveTaskNatureCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(removeTaskNatureCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type UpdateTaskNatureCommand struct {
  10 + // 任务性质ID
  11 + TaskNatureId int `json:"taskNatureId,omitempty"`
  12 + // 任务性质名称
  13 + TaskNatureName string `json:"taskNatureName,omitempty"`
  14 +}
  15 +
  16 +func (updateTaskNatureCommand *UpdateTaskNatureCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(updateTaskNatureCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetTaskNatureQuery struct {
  10 + // 任务性质ID
  11 + TaskNatureId int `json:"taskNatureId" valid:"Required"`
  12 +}
  13 +
  14 +func (getTaskNatureQuery *GetTaskNatureQuery) ValidateQuery() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(getTaskNatureQuery)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type ListTaskNatureQuery struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 + // 任务性质名称
  13 + TaskNatureName string `json:"taskNatureName,omitempty"`
  14 + // 任务性质名称匹配
  15 + TaskNatureNameMatch string `json:"taskNatureNameMatch,omitempty"`
  16 + // 查询偏离量
  17 + Offset int `json:"offset,omitempty"`
  18 + // 查询限制
  19 + Limit int `json:"limit,omitempty"`
  20 +}
  21 +
  22 +func (listTaskNatureQuery *ListTaskNatureQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listTaskNatureQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + for _, validErr := range valid.Errors {
  30 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  31 + }
  32 + }
  33 + return nil
  34 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 +)
  12 +
  13 +// 任务性质服务
  14 +type TaskNatureService struct {
  15 +}
  16 +
  17 +// 创建任务性质
  18 +func (taskNatureService *TaskNatureService) CreateTaskNature(createTaskNatureCommand *command.CreateTaskNatureCommand) (interface{}, error) {
  19 + if err := createTaskNatureCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newTaskNature := &domain.TaskNature{
  33 + CompanyId: createTaskNatureCommand.CompanyId,
  34 + TaskNatureName: createTaskNatureCommand.TaskNatureName,
  35 + }
  36 + var taskNatureRepository domain.TaskNatureRepository
  37 + if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
  38 + "transactionContext": transactionContext,
  39 + }); err != nil {
  40 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  41 + } else {
  42 + taskNatureRepository = value
  43 + }
  44 + if count, _, err := taskNatureRepository.Find(map[string]interface{}{
  45 + "taskNatureName": createTaskNatureCommand.TaskNatureName,
  46 + }); err != nil {
  47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 + } else {
  49 + if count > 0 {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
  51 + }
  52 + }
  53 + if taskNature, err := taskNatureRepository.Save(newTaskNature); err != nil {
  54 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  55 + } else {
  56 + if err := transactionContext.CommitTransaction(); err != nil {
  57 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  58 + }
  59 + return taskNature, nil
  60 + }
  61 +}
  62 +
  63 +// 返回任务性质
  64 +func (taskNatureService *TaskNatureService) GetTaskNature(getTaskNatureQuery *query.GetTaskNatureQuery) (interface{}, error) {
  65 + if err := getTaskNatureQuery.ValidateQuery(); err != nil {
  66 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  67 + }
  68 + transactionContext, err := factory.CreateTransactionContext(nil)
  69 + if err != nil {
  70 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  71 + }
  72 + if err := transactionContext.StartTransaction(); err != nil {
  73 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  74 + }
  75 + defer func() {
  76 + transactionContext.RollbackTransaction()
  77 + }()
  78 + var taskNatureRepository domain.TaskNatureRepository
  79 + if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
  80 + "transactionContext": transactionContext,
  81 + }); err != nil {
  82 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  83 + } else {
  84 + taskNatureRepository = value
  85 + }
  86 + taskNature, err := taskNatureRepository.FindOne(map[string]interface{}{"taskNatureId": getTaskNatureQuery.TaskNatureId})
  87 + if err != nil {
  88 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  89 + }
  90 + if taskNature == nil {
  91 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskNatureQuery.TaskNatureId)))
  92 + } else {
  93 + if err := transactionContext.CommitTransaction(); err != nil {
  94 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  95 + }
  96 + return taskNature, nil
  97 + }
  98 +}
  99 +
  100 +// 更新任务性质
  101 +func (taskNatureService *TaskNatureService) UpdateTaskNature(updateTaskNatureCommand *command.UpdateTaskNatureCommand) (interface{}, error) {
  102 + if err := updateTaskNatureCommand.ValidateCommand(); err != nil {
  103 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  104 + }
  105 + transactionContext, err := factory.CreateTransactionContext(nil)
  106 + if err != nil {
  107 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  108 + }
  109 + if err := transactionContext.StartTransaction(); err != nil {
  110 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  111 + }
  112 + defer func() {
  113 + transactionContext.RollbackTransaction()
  114 + }()
  115 + var taskNatureRepository domain.TaskNatureRepository
  116 + if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
  117 + "transactionContext": transactionContext,
  118 + }); err != nil {
  119 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  120 + } else {
  121 + taskNatureRepository = value
  122 + }
  123 + taskNature, err := taskNatureRepository.FindOne(map[string]interface{}{"taskNatureId": updateTaskNatureCommand.TaskNatureId})
  124 + if err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + }
  127 + if taskNature == nil {
  128 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskNatureCommand.TaskNatureId)))
  129 + }
  130 + if count, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
  131 + "taskNatureName": updateTaskNatureCommand.TaskNatureName,
  132 + }); err != nil {
  133 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  134 + } else {
  135 + if count > 0 && taskNatures[0].TaskNatureId != taskNature.TaskNatureId {
  136 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
  137 + }
  138 + }
  139 + if err := taskNature.Update(tool_funs.SimpleStructToMap(updateTaskNatureCommand)); err != nil {
  140 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  141 + }
  142 + if taskNature, err := taskNatureRepository.Save(taskNature); err != nil {
  143 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  144 + } else {
  145 + if err := transactionContext.CommitTransaction(); err != nil {
  146 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + return taskNature, nil
  149 + }
  150 +}
  151 +
  152 +// 移除任务性质
  153 +func (taskNatureService *TaskNatureService) RemoveTaskNature(removeTaskNatureCommand *command.RemoveTaskNatureCommand) (interface{}, error) {
  154 + if err := removeTaskNatureCommand.ValidateCommand(); err != nil {
  155 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  156 + }
  157 + transactionContext, err := factory.CreateTransactionContext(nil)
  158 + if err != nil {
  159 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  160 + }
  161 + if err := transactionContext.StartTransaction(); err != nil {
  162 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  163 + }
  164 + defer func() {
  165 + transactionContext.RollbackTransaction()
  166 + }()
  167 + var taskNatureRepository domain.TaskNatureRepository
  168 + if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
  169 + "transactionContext": transactionContext,
  170 + }); err != nil {
  171 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  172 + } else {
  173 + taskNatureRepository = value
  174 + }
  175 + taskNature, err := taskNatureRepository.FindOne(map[string]interface{}{"taskNatureId": removeTaskNatureCommand.TaskNatureId})
  176 + if err != nil {
  177 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  178 + }
  179 + if taskNature == nil {
  180 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeTaskNatureCommand.TaskNatureId)))
  181 + }
  182 + if taskNature, err := taskNatureRepository.Remove(taskNature); err != nil {
  183 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  184 + } else {
  185 + if err := transactionContext.CommitTransaction(); err != nil {
  186 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  187 + }
  188 + return taskNature, nil
  189 + }
  190 +}
  191 +
  192 +// 返回任务性质列表
  193 +func (taskNatureService *TaskNatureService) ListTaskNature(listTaskNatureQuery *query.ListTaskNatureQuery) (interface{}, error) {
  194 + if err := listTaskNatureQuery.ValidateQuery(); err != nil {
  195 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  196 + }
  197 + transactionContext, err := factory.CreateTransactionContext(nil)
  198 + if err != nil {
  199 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  200 + }
  201 + if err := transactionContext.StartTransaction(); err != nil {
  202 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  203 + }
  204 + defer func() {
  205 + transactionContext.RollbackTransaction()
  206 + }()
  207 + var taskNatureRepository domain.TaskNatureRepository
  208 + if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
  209 + "transactionContext": transactionContext,
  210 + }); err != nil {
  211 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  212 + } else {
  213 + taskNatureRepository = value
  214 + }
  215 + if count, taskNatures, err := taskNatureRepository.Find(tool_funs.SimpleStructToMap(listTaskNatureQuery)); err != nil {
  216 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  217 + } else {
  218 + if err := transactionContext.CommitTransaction(); err != nil {
  219 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  220 + }
  221 + return map[string]interface{}{
  222 + "count": count,
  223 + "taskNatures": taskNatures,
  224 + }, nil
  225 + }
  226 +}
  227 +
  228 +func NewTaskNatureService(options map[string]interface{}) *TaskNatureService {
  229 + newTaskNatureService := &TaskNatureService{}
  230 + return newTaskNatureService
  231 +}
  1 +package domain
  2 +
  3 +// 客户价值
  4 +type CustomerValue struct {
  5 + // 客户价值ID
  6 + CustomerValueId int `json:"customerValueId"`
  7 + // 客户价值名称
  8 + CustomerValueName string `json:"customerValueName"`
  9 + // 公司ID
  10 + CompanyId int64 `json:"companyId"`
  11 +}
  12 +
  13 +type CustomerValueRepository interface {
  14 + Save(customerValue *CustomerValue) (*CustomerValue, error)
  15 + Remove(customerValue *CustomerValue) (*CustomerValue, error)
  16 + FindOne(queryOptions map[string]interface{}) (*CustomerValue, error)
  17 + Find(queryOptions map[string]interface{}) (int64, []*CustomerValue, error)
  18 +}
  19 +
  20 +func (customerValue *CustomerValue) Identify() interface{} {
  21 + if customerValue.CustomerValueId == 0 {
  22 + return nil
  23 + }
  24 + return customerValue.CustomerValueId
  25 +}
  26 +
  27 +func (customerValue *CustomerValue) Update(data map[string]interface{}) error {
  28 + if customerValueName, ok := data["customerValueName"]; ok {
  29 + customerValue.CustomerValueName = customerValueName.(string)
  30 + }
  31 + return nil
  32 +}
  1 +package domain
  2 +
  3 +// 项目归属
  4 +type ProjectBelong struct {
  5 + // 项目归属ID
  6 + ProjectBelongId int `json:"projectBelongId"`
  7 + // 项目归属名称
  8 + ProjectBelongName string `json:"projectBelongName"`
  9 + // 公司ID
  10 + CompanyId int64 `json:"companyId"`
  11 +}
  12 +
  13 +type ProjectBelongRepository interface {
  14 + Save(projectBelong *ProjectBelong) (*ProjectBelong, error)
  15 + Remove(projectBelong *ProjectBelong) (*ProjectBelong, error)
  16 + FindOne(queryOptions map[string]interface{}) (*ProjectBelong, error)
  17 + Find(queryOptions map[string]interface{}) (int64, []*ProjectBelong, error)
  18 +}
  19 +
  20 +func (projectBelong *ProjectBelong) Identify() interface{} {
  21 + if projectBelong.ProjectBelongId == 0 {
  22 + return nil
  23 + }
  24 + return projectBelong.ProjectBelongId
  25 +}
  26 +
  27 +func (projectBelong *ProjectBelong) Update(data map[string]interface{}) error {
  28 + if projectBelongName, ok := data["projectBelongName"]; ok {
  29 + projectBelong.ProjectBelongName = projectBelongName.(string)
  30 + }
  31 + return nil
  32 +}
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 const ( 8 const (
9 TASK_TYPE_ROB = iota + 1 //抢单任务 9 TASK_TYPE_ROB = iota + 1 //抢单任务
10 TASK_TYPE_BID //竞标任务 10 TASK_TYPE_BID //竞标任务
  11 + TASK_TYPE_DESIGNATE //指派任务
11 ) 12 )
12 13
13 const ( 14 const (
@@ -22,6 +23,7 @@ const ( @@ -22,6 +23,7 @@ const (
22 TASK_STATUS_UNACCEPTANCE //待验收 23 TASK_STATUS_UNACCEPTANCE //待验收
23 TASK_STATUS_COMPLETED //已完成 24 TASK_STATUS_COMPLETED //已完成
24 TASK_STATUS_CLOSED //关闭 25 TASK_STATUS_CLOSED //关闭
  26 + TASK_STATUS_UNCONFIRMED //待确认
25 ) 27 )
26 28
27 // 任务 29 // 任务
  1 +package domain
  2 +
  3 +// 任务性质
  4 +type TaskNature struct {
  5 + // 任务性质ID
  6 + TaskNatureId int `json:"taskNatureId"`
  7 + // 任务性质名称
  8 + TaskNatureName string `json:"taskNatureName"`
  9 + // 公司ID
  10 + CompanyId int64 `json:"companyId"`
  11 +}
  12 +
  13 +type TaskNatureRepository interface {
  14 + Save(taskNature *TaskNature) (*TaskNature, error)
  15 + Remove(taskNature *TaskNature) (*TaskNature, error)
  16 + FindOne(queryOptions map[string]interface{}) (*TaskNature, error)
  17 + Find(queryOptions map[string]interface{}) (int64, []*TaskNature, error)
  18 +}
  19 +
  20 +func (taskNature *TaskNature) Identify() interface{} {
  21 + if taskNature.TaskNatureId == 0 {
  22 + return nil
  23 + }
  24 + return taskNature.TaskNatureId
  25 +}
  26 +
  27 +func (taskNature *TaskNature) Update(data map[string]interface{}) error {
  28 + if taskNatureName, ok := data["taskNatureName"]; ok {
  29 + taskNature.TaskNatureName = taskNatureName.(string)
  30 + }
  31 + return nil
  32 +}
@@ -30,6 +30,9 @@ func init() { @@ -30,6 +30,9 @@ func init() {
30 (*models.Task)(nil), 30 (*models.Task)(nil),
31 (*models.OffTaskRecord)(nil), 31 (*models.OffTaskRecord)(nil),
32 (*models.SuMoneyTransactionRecord)(nil), 32 (*models.SuMoneyTransactionRecord)(nil),
  33 + (*models.CustomerValue)(nil),
  34 + (*models.TaskNature)(nil),
  35 + (*models.ProjectBelong)(nil),
33 } { 36 } {
34 err := DB.CreateTable(model, &orm.CreateTableOptions{ 37 err := DB.CreateTable(model, &orm.CreateTableOptions{
35 Temp: false, 38 Temp: false,
  1 +package models
  2 +
  3 +type CustomerValue struct {
  4 + TableName string `pg:"customer_values,alias:customer_value"`
  5 + // 客户价值ID
  6 + Id int
  7 + // 客户价值名称
  8 + CustomerValueName string
  9 + // 公司ID
  10 + CompanyId int64
  11 +}
  1 +package models
  2 +
  3 +type ProjectBelong struct {
  4 + TableName string `pg:"project_belongs,alias:project_belong"`
  5 + // 项目归属ID
  6 + Id int
  7 + // 项目归属名称
  8 + ProjectBelongName string
  9 + // 公司ID
  10 + CompanyId int64
  11 +}
  1 +package models
  2 +
  3 +type TaskNature struct {
  4 + TableName string `pg:"task_natures,alias:task_nature"`
  5 + // 任务性质ID
  6 + Id int
  7 + // 任务性质名称
  8 + TaskNatureName string
  9 + // 公司ID
  10 + CompanyId int64
  11 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type CustomerValueRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *CustomerValueRepository) Save(customerValue *domain.CustomerValue) (*domain.CustomerValue, error) {
  17 + tx := repository.transactionContext.PgTx
  18 + if customerValue.Identify() == nil {
  19 + if _, err := tx.QueryOne(
  20 + pg.Scan(&customerValue.CustomerValueId, &customerValue.CustomerValueName, &customerValue.CompanyId),
  21 + "INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id, customer_value_name, company_id",
  22 + customerValue.CustomerValueName, customerValue.CompanyId); err != nil {
  23 + return customerValue, err
  24 + }
  25 + } else {
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&customerValue.CustomerValueId, &customerValue.CustomerValueName, &customerValue.CompanyId),
  28 + "UPDATE customer_values SET customer_value_name=?, company_id=? WHERE id=? RETURNING id, customer_value_name, company_id",
  29 + customerValue.CustomerValueName, customerValue.CompanyId, customerValue.Identify()); err != nil {
  30 + return customerValue, err
  31 + }
  32 + }
  33 + return customerValue, nil
  34 +}
  35 +func (repository *CustomerValueRepository) Remove(customerValue *domain.CustomerValue) (*domain.CustomerValue, error) {
  36 + tx := repository.transactionContext.PgTx
  37 + customerValueModel := new(models.CustomerValue)
  38 + customerValueModel.Id = customerValue.CustomerValueId
  39 + if _, err := tx.Model(customerValueModel).WherePK().Delete(); err != nil {
  40 + return customerValue, err
  41 + }
  42 + return customerValue, nil
  43 +}
  44 +func (repository *CustomerValueRepository) FindOne(queryOptions map[string]interface{}) (*domain.CustomerValue, error) {
  45 + tx := repository.transactionContext.PgTx
  46 + customerValueModel := new(models.CustomerValue)
  47 + query := tx.Model(customerValueModel)
  48 + if customerValueId, ok := queryOptions["customerValueId"]; ok {
  49 + query = query.Where("customer_value.id = ?", customerValueId)
  50 + }
  51 + if err := query.First(); err != nil {
  52 + if err.Error() == "pg: no rows in result set" {
  53 + return nil, fmt.Errorf("没有此资源")
  54 + } else {
  55 + return nil, err
  56 + }
  57 + }
  58 + if customerValueModel.Id == 0 {
  59 + return nil, nil
  60 + } else {
  61 + return repository.transformPgModelToDomainModel(customerValueModel)
  62 + }
  63 +}
  64 +func (repository *CustomerValueRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CustomerValue, error) {
  65 + tx := repository.transactionContext.PgTx
  66 + var customerValueModels []*models.CustomerValue
  67 + customerValues := make([]*domain.CustomerValue, 0)
  68 + query := tx.Model(&customerValueModels)
  69 + if companyId, ok := queryOptions["companyId"]; ok {
  70 + query = query.Where("customer_value.company_id = ?", companyId)
  71 + }
  72 + if customerValueName, ok := queryOptions["customerValueName"]; ok && (customerValueName != "") {
  73 + query = query.Where(`customer_value.customer_value_name = ?`, customerValueName)
  74 + }
  75 + if customerValueNameMatch, ok := queryOptions["customerValueNameMatch"]; ok && (customerValueNameMatch != "") {
  76 + query = query.Where(`customer_value.customer_value_name LIKE ?`, fmt.Sprintf("%%%s%%", customerValueNameMatch.(string)))
  77 + }
  78 + if offset, ok := queryOptions["offset"]; ok {
  79 + offset := offset.(int)
  80 + if offset > -1 {
  81 + query = query.Offset(offset)
  82 + }
  83 + } else {
  84 + query = query.Offset(0)
  85 + }
  86 + if limit, ok := queryOptions["limit"]; ok {
  87 + limit := limit.(int)
  88 + if limit > -1 {
  89 + query = query.Limit(limit)
  90 + }
  91 + } else {
  92 + query = query.Limit(20)
  93 + }
  94 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  95 + return 0, customerValues, err
  96 + } else {
  97 + for _, customerValueModel := range customerValueModels {
  98 + if customerValue, err := repository.transformPgModelToDomainModel(customerValueModel); err != nil {
  99 + return 0, customerValues, err
  100 + } else {
  101 + customerValues = append(customerValues, customerValue)
  102 + }
  103 + customerValues = append(customerValues, &domain.CustomerValue{})
  104 + }
  105 + return int64(count), customerValues, nil
  106 + }
  107 +}
  108 +func (repository *CustomerValueRepository) transformPgModelToDomainModel(customerValueModel *models.CustomerValue) (*domain.CustomerValue, error) {
  109 + return &domain.CustomerValue{
  110 + CustomerValueId: customerValueModel.Id,
  111 + CustomerValueName: customerValueModel.CustomerValueName,
  112 + CompanyId: customerValueModel.CompanyId,
  113 + }, nil
  114 +}
  115 +func NewCustomerValueRepository(transactionContext *pgTransaction.TransactionContext) (*CustomerValueRepository, error) {
  116 + if transactionContext == nil {
  117 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  118 + } else {
  119 + return &CustomerValueRepository{
  120 + transactionContext: transactionContext,
  121 + }, nil
  122 + }
  123 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type ProjectBelongRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *ProjectBelongRepository) Save(projectBelong *domain.ProjectBelong) (*domain.ProjectBelong, error) {
  17 + tx := repository.transactionContext.PgTx
  18 + if projectBelong.Identify() == nil {
  19 + if _, err := tx.QueryOne(
  20 + pg.Scan(&projectBelong.ProjectBelongId, &projectBelong.ProjectBelongName, &projectBelong.CompanyId),
  21 + "INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id, project_belong_name, company_id",
  22 + projectBelong.ProjectBelongName, projectBelong.CompanyId); err != nil {
  23 + return projectBelong, err
  24 + }
  25 + } else {
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&projectBelong.ProjectBelongId, &projectBelong.ProjectBelongName, &projectBelong.CompanyId),
  28 + "UPDATE project_belongs SET project_belong_name=?, company_id=? WHERE id=? RETURNING id, project_belong_name, company_id",
  29 + projectBelong.ProjectBelongName, projectBelong.CompanyId, projectBelong.Identify()); err != nil {
  30 + return projectBelong, err
  31 + }
  32 + }
  33 + return projectBelong, nil
  34 +}
  35 +func (repository *ProjectBelongRepository) Remove(projectBelong *domain.ProjectBelong) (*domain.ProjectBelong, error) {
  36 + tx := repository.transactionContext.PgTx
  37 + projectBelongModel := new(models.ProjectBelong)
  38 + projectBelongModel.Id = projectBelong.Identify().(int)
  39 + if _, err := tx.Model(projectBelongModel).WherePK().Delete(); err != nil {
  40 + return projectBelong, err
  41 + }
  42 + return projectBelong, nil
  43 +}
  44 +func (repository *ProjectBelongRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectBelong, error) {
  45 + tx := repository.transactionContext.PgTx
  46 + projectBelongModel := new(models.ProjectBelong)
  47 + query := tx.Model(projectBelongModel)
  48 + if projectBelongId, ok := queryOptions["projectBelongId"]; ok {
  49 + query = query.Where("project_belong.id = ?", projectBelongId)
  50 + }
  51 + if err := query.First(); err != nil {
  52 + if err.Error() == "pg: no rows in result set" {
  53 + return nil, fmt.Errorf("没有此资源")
  54 + } else {
  55 + return nil, err
  56 + }
  57 + }
  58 + if projectBelongModel.Id == 0 {
  59 + return nil, nil
  60 + } else {
  61 + return repository.transformPgModelToDomainModel(projectBelongModel)
  62 + }
  63 +}
  64 +func (repository *ProjectBelongRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectBelong, error) {
  65 + tx := repository.transactionContext.PgTx
  66 + var projectBelongModels []*models.ProjectBelong
  67 + projectBelongs := make([]*domain.ProjectBelong, 0)
  68 + query := tx.Model(&projectBelongModels)
  69 + if companyId, ok := queryOptions["companyId"]; ok {
  70 + query = query.Where("project_belong.company_id = ?", companyId)
  71 + }
  72 + if projectBelongName, ok := queryOptions["projectBelongName"]; ok && (projectBelongName != "") {
  73 + query = query.Where(`project_belong.project_belong_name = ?`, projectBelongName)
  74 + }
  75 + if projectBelongNameMatch, ok := queryOptions["projectBelongNameMatch"]; ok && (projectBelongNameMatch != "") {
  76 + query = query.Where(`project_belong.project_belong_name LIKE ?`, fmt.Sprintf("%%%s%%", projectBelongNameMatch.(string)))
  77 + }
  78 + if offset, ok := queryOptions["offset"]; ok {
  79 + offset := offset.(int)
  80 + if offset > -1 {
  81 + query = query.Offset(offset)
  82 + }
  83 + } else {
  84 + query = query.Offset(0)
  85 + }
  86 + if limit, ok := queryOptions["limit"]; ok {
  87 + limit := limit.(int)
  88 + if limit > -1 {
  89 + query = query.Limit(limit)
  90 + }
  91 + } else {
  92 + query = query.Limit(20)
  93 + }
  94 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  95 + return 0, projectBelongs, err
  96 + } else {
  97 + for _, projectBelongModel := range projectBelongModels {
  98 + if projectBelong, err := repository.transformPgModelToDomainModel(projectBelongModel); err != nil {
  99 + return 0, projectBelongs, err
  100 + } else {
  101 + projectBelongs = append(projectBelongs, projectBelong)
  102 + }
  103 + projectBelongs = append(projectBelongs, &domain.ProjectBelong{})
  104 + }
  105 + return int64(count), projectBelongs, nil
  106 + }
  107 +}
  108 +func (repository *ProjectBelongRepository) transformPgModelToDomainModel(projectBelongModel *models.ProjectBelong) (*domain.ProjectBelong, error) {
  109 + return &domain.ProjectBelong{
  110 + ProjectBelongId: projectBelongModel.Id,
  111 + ProjectBelongName: projectBelongModel.ProjectBelongName,
  112 + CompanyId: projectBelongModel.CompanyId,
  113 + }, nil
  114 +}
  115 +func NewProjectBelongRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectBelongRepository, error) {
  116 + if transactionContext == nil {
  117 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  118 + } else {
  119 + return &ProjectBelongRepository{
  120 + transactionContext: transactionContext,
  121 + }, nil
  122 + }
  123 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type TaskNatureRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *TaskNatureRepository) Save(taskNature *domain.TaskNature) (*domain.TaskNature, error) {
  17 + tx := repository.transactionContext.PgTx
  18 + if taskNature.Identify() == nil {
  19 + if _, err := tx.QueryOne(
  20 + pg.Scan(&taskNature.TaskNatureId, &taskNature.TaskNatureName, &taskNature.CompanyId),
  21 + "INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id, task_nature_name, company_id",
  22 + taskNature.TaskNatureName, taskNature.CompanyId); err != nil {
  23 + return taskNature, err
  24 + }
  25 + } else {
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&taskNature.TaskNatureId, &taskNature.TaskNatureName, &taskNature.CompanyId),
  28 + "UPDATE task_natures SET task_nature_name=?, company_id=? WHERE id=? RETURNING id, task_nature_name, company_id",
  29 + taskNature.TaskNatureName, taskNature.CompanyId, taskNature.Identify()); err != nil {
  30 + return taskNature, err
  31 + }
  32 + }
  33 + return taskNature, nil
  34 +}
  35 +func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*domain.TaskNature, error) {
  36 + tx := repository.transactionContext.PgTx
  37 + taskNatureModel := new(models.TaskNature)
  38 + taskNatureModel.Id = taskNature.Identify().(int)
  39 + if _, err := tx.Model(taskNatureModel).WherePK().Delete(); err != nil {
  40 + return taskNature, err
  41 + }
  42 + return taskNature, nil
  43 +}
  44 +func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskNature, error) {
  45 + tx := repository.transactionContext.PgTx
  46 + taskNatureModel := new(models.TaskNature)
  47 + query := tx.Model(taskNatureModel)
  48 + if taskNatureId, ok := queryOptions["taskNatureId"]; ok {
  49 + query = query.Where("task_nature.id = ?", taskNatureId)
  50 + }
  51 + if err := query.First(); err != nil {
  52 + if err.Error() == "pg: no rows in result set" {
  53 + return nil, fmt.Errorf("没有此资源")
  54 + } else {
  55 + return nil, err
  56 + }
  57 + }
  58 + if taskNatureModel.Id == 0 {
  59 + return nil, nil
  60 + } else {
  61 + return repository.transformPgModelToDomainModel(taskNatureModel)
  62 + }
  63 +}
  64 +func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.TaskNature, error) {
  65 + tx := repository.transactionContext.PgTx
  66 + var taskNatureModels []*models.TaskNature
  67 + taskNatures := make([]*domain.TaskNature, 0)
  68 + query := tx.Model(&taskNatureModels)
  69 + if companyId, ok := queryOptions["companyId"]; ok {
  70 + query = query.Where("task_nature.company_id = ?", companyId)
  71 + }
  72 + if taskNatureName, ok := queryOptions["taskNatureName"]; ok && (taskNatureName != "") {
  73 + query = query.Where(`task_nature.task_nature_name = ?`, taskNatureName)
  74 + }
  75 + if taskNatureNameMatch, ok := queryOptions["taskNatureNameMatch"]; ok && (taskNatureNameMatch != "") {
  76 + query = query.Where(`task_nature.task_nature_name LIKE ?`, fmt.Sprintf("%%%s%%", taskNatureNameMatch.(string)))
  77 + }
  78 + if offset, ok := queryOptions["offset"]; ok {
  79 + offset := offset.(int)
  80 + if offset > -1 {
  81 + query = query.Offset(offset)
  82 + }
  83 + } else {
  84 + query = query.Offset(0)
  85 + }
  86 + if limit, ok := queryOptions["limit"]; ok {
  87 + limit := limit.(int)
  88 + if limit > -1 {
  89 + query = query.Limit(limit)
  90 + }
  91 + } else {
  92 + query = query.Limit(20)
  93 + }
  94 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  95 + return 0, taskNatures, err
  96 + } else {
  97 + for _, taskNatureModel := range taskNatureModels {
  98 + if taskNature, err := repository.transformPgModelToDomainModel(taskNatureModel); err != nil {
  99 + return 0, taskNatures, err
  100 + } else {
  101 + taskNatures = append(taskNatures, taskNature)
  102 + }
  103 + taskNatures = append(taskNatures, &domain.TaskNature{})
  104 + }
  105 + return int64(count), taskNatures, nil
  106 + }
  107 +}
  108 +func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNatureModel *models.TaskNature) (*domain.TaskNature, error) {
  109 + return &domain.TaskNature{
  110 + TaskNatureId: taskNatureModel.Id,
  111 + TaskNatureName: taskNatureModel.TaskNatureName,
  112 + CompanyId: taskNatureModel.CompanyId,
  113 + }, nil
  114 +}
  115 +func NewTaskNatureRepository(transactionContext *pgTransaction.TransactionContext) (*TaskNatureRepository, error) {
  116 + if transactionContext == nil {
  117 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  118 + } else {
  119 + return &TaskNatureRepository{
  120 + transactionContext: transactionContext,
  121 + }, nil
  122 + }
  123 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/customerValue/service"
  11 +)
  12 +
  13 +type CustomerValueController struct {
  14 + beego.Controller
  15 +}
  16 +
  17 +func (controller *CustomerValueController) CreateCustomerValue() {
  18 + customerValueService := service.NewCustomerValueService(nil)
  19 + createCustomerValueCommand := &command.CreateCustomerValueCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createCustomerValueCommand)
  21 + data, err := customerValueService.CreateCustomerValue(createCustomerValueCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +func (controller *CustomerValueController) UpdateCustomerValue() {
  33 + customerValueService := service.NewCustomerValueService(nil)
  34 + updateCustomerValueCommand := &command.UpdateCustomerValueCommand{}
  35 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateCustomerValueCommand)
  36 + customerValueId, _ := controller.GetInt(":customerValueId")
  37 + updateCustomerValueCommand.CustomerValueId = customerValueId
  38 + data, err := customerValueService.UpdateCustomerValue(updateCustomerValueCommand)
  39 + var response utils.JsonResponse
  40 + if err != nil {
  41 + response = utils.ResponseError(controller.Ctx, err)
  42 + } else {
  43 + response = utils.ResponseData(controller.Ctx, data)
  44 + }
  45 + controller.Data["json"] = response
  46 + controller.ServeJSON()
  47 +}
  48 +
  49 +func (controller *CustomerValueController) GetCustomerValue() {
  50 + customerValueService := service.NewCustomerValueService(nil)
  51 + getCustomerValueQuery := &query.GetCustomerValueQuery{}
  52 + customerValueId, _ := controller.GetInt(":customerValueId")
  53 + getCustomerValueQuery.CustomerValueId = customerValueId
  54 + data, err := customerValueService.GetCustomerValue(getCustomerValueQuery)
  55 + var response utils.JsonResponse
  56 + if err != nil {
  57 + response = utils.ResponseError(controller.Ctx, err)
  58 + } else {
  59 + response = utils.ResponseData(controller.Ctx, data)
  60 + }
  61 + controller.Data["json"] = response
  62 + controller.ServeJSON()
  63 +}
  64 +
  65 +func (controller *CustomerValueController) RemoveCustomerValue() {
  66 + customerValueService := service.NewCustomerValueService(nil)
  67 + removeCustomerValueCommand := &command.RemoveCustomerValueCommand{}
  68 + customerValueId, _ := controller.GetInt(":customerValueId")
  69 + removeCustomerValueCommand.CustomerValueId = customerValueId
  70 + data, err := customerValueService.RemoveCustomerValue(removeCustomerValueCommand)
  71 + var response utils.JsonResponse
  72 + if err != nil {
  73 + response = utils.ResponseError(controller.Ctx, err)
  74 + } else {
  75 + response = utils.ResponseData(controller.Ctx, data)
  76 + }
  77 + controller.Data["json"] = response
  78 + controller.ServeJSON()
  79 +}
  80 +
  81 +func (controller *CustomerValueController) ListCustomerValue() {
  82 + customerValueService := service.NewCustomerValueService(nil)
  83 + listCustomerValueQuery := &query.ListCustomerValueQuery{}
  84 + companyId, _ := controller.GetInt64("companyId")
  85 + listCustomerValueQuery.CompanyId = companyId
  86 + customerValueName := controller.GetString("customerValueName")
  87 + listCustomerValueQuery.CustomerValueName = customerValueName
  88 + customerValueNameMatch := controller.GetString("customerValueNameMatch")
  89 + listCustomerValueQuery.CustomerValueNameMatch = customerValueNameMatch
  90 + offset, _ := controller.GetInt("offset")
  91 + listCustomerValueQuery.Offset = offset
  92 + limit, _ := controller.GetInt("limit")
  93 + listCustomerValueQuery.Limit = limit
  94 + data, err := customerValueService.ListCustomerValue(listCustomerValueQuery)
  95 + var response utils.JsonResponse
  96 + if err != nil {
  97 + response = utils.ResponseError(controller.Ctx, err)
  98 + } else {
  99 + response = utils.ResponseData(controller.Ctx, data)
  100 + }
  101 + controller.Data["json"] = response
  102 + controller.ServeJSON()
  103 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/projectBelong/service"
  11 +)
  12 +
  13 +type ProjectBelongController struct {
  14 + beego.Controller
  15 +}
  16 +
  17 +func (controller *ProjectBelongController) CreateProjectBelong() {
  18 + projectBelongService := service.NewProjectBelongService(nil)
  19 + createProjectBelongCommand := &command.CreateProjectBelongCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectBelongCommand)
  21 + data, err := projectBelongService.CreateProjectBelong(createProjectBelongCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +func (controller *ProjectBelongController) UpdateProjectBelong() {
  33 + projectBelongService := service.NewProjectBelongService(nil)
  34 + updateProjectBelongCommand := &command.UpdateProjectBelongCommand{}
  35 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectBelongCommand)
  36 + projectBelongId, _ := controller.GetInt(":projectBelongId")
  37 + updateProjectBelongCommand.ProjectBelongId = projectBelongId
  38 + data, err := projectBelongService.UpdateProjectBelong(updateProjectBelongCommand)
  39 + var response utils.JsonResponse
  40 + if err != nil {
  41 + response = utils.ResponseError(controller.Ctx, err)
  42 + } else {
  43 + response = utils.ResponseData(controller.Ctx, data)
  44 + }
  45 + controller.Data["json"] = response
  46 + controller.ServeJSON()
  47 +}
  48 +
  49 +func (controller *ProjectBelongController) GetProjectBelong() {
  50 + projectBelongService := service.NewProjectBelongService(nil)
  51 + getProjectBelongQuery := &query.GetProjectBelongQuery{}
  52 + projectBelongId, _ := controller.GetInt(":projectBelongId")
  53 + getProjectBelongQuery.ProjectBelongId = projectBelongId
  54 + data, err := projectBelongService.GetProjectBelong(getProjectBelongQuery)
  55 + var response utils.JsonResponse
  56 + if err != nil {
  57 + response = utils.ResponseError(controller.Ctx, err)
  58 + } else {
  59 + response = utils.ResponseData(controller.Ctx, data)
  60 + }
  61 + controller.Data["json"] = response
  62 + controller.ServeJSON()
  63 +}
  64 +
  65 +func (controller *ProjectBelongController) RemoveProjectBelong() {
  66 + projectBelongService := service.NewProjectBelongService(nil)
  67 + removeProjectBelongCommand := &command.RemoveProjectBelongCommand{}
  68 + projectBelongId, _ := controller.GetInt(":projectBelongId")
  69 + removeProjectBelongCommand.ProjectBelongId = projectBelongId
  70 + data, err := projectBelongService.RemoveProjectBelong(removeProjectBelongCommand)
  71 + var response utils.JsonResponse
  72 + if err != nil {
  73 + response = utils.ResponseError(controller.Ctx, err)
  74 + } else {
  75 + response = utils.ResponseData(controller.Ctx, data)
  76 + }
  77 + controller.Data["json"] = response
  78 + controller.ServeJSON()
  79 +}
  80 +
  81 +func (controller *ProjectBelongController) ListProjectBelong() {
  82 + projectBelongService := service.NewProjectBelongService(nil)
  83 + listProjectBelongQuery := &query.ListProjectBelongQuery{}
  84 + companyId, _ := controller.GetInt64("companyId")
  85 + listProjectBelongQuery.CompanyId = companyId
  86 + projectBelongName := controller.GetString("projectBelongName")
  87 + listProjectBelongQuery.ProjectBelongName = projectBelongName
  88 + projectBelongNameMatch := controller.GetString("projectBelongNameMatch")
  89 + listProjectBelongQuery.ProjectBelongNameMatch = projectBelongNameMatch
  90 + offset, _ := controller.GetInt("offset")
  91 + listProjectBelongQuery.Offset = offset
  92 + limit, _ := controller.GetInt("limit")
  93 + listProjectBelongQuery.Limit = limit
  94 + data, err := projectBelongService.ListProjectBelong(listProjectBelongQuery)
  95 + var response utils.JsonResponse
  96 + if err != nil {
  97 + response = utils.ResponseError(controller.Ctx, err)
  98 + } else {
  99 + response = utils.ResponseData(controller.Ctx, data)
  100 + }
  101 + controller.Data["json"] = response
  102 + controller.ServeJSON()
  103 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/service"
  11 +)
  12 +
  13 +type TaskNatureController struct {
  14 + beego.Controller
  15 +}
  16 +
  17 +func (controller *TaskNatureController) CreateTaskNature() {
  18 + taskNatureService := service.NewTaskNatureService(nil)
  19 + createTaskNatureCommand := &command.CreateTaskNatureCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createTaskNatureCommand)
  21 + data, err := taskNatureService.CreateTaskNature(createTaskNatureCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +func (controller *TaskNatureController) UpdateTaskNature() {
  33 + taskNatureService := service.NewTaskNatureService(nil)
  34 + updateTaskNatureCommand := &command.UpdateTaskNatureCommand{}
  35 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskNatureCommand)
  36 + taskNatureId, _ := controller.GetInt(":taskNatureId")
  37 + updateTaskNatureCommand.TaskNatureId = taskNatureId
  38 + data, err := taskNatureService.UpdateTaskNature(updateTaskNatureCommand)
  39 + var response utils.JsonResponse
  40 + if err != nil {
  41 + response = utils.ResponseError(controller.Ctx, err)
  42 + } else {
  43 + response = utils.ResponseData(controller.Ctx, data)
  44 + }
  45 + controller.Data["json"] = response
  46 + controller.ServeJSON()
  47 +}
  48 +
  49 +func (controller *TaskNatureController) GetTaskNature() {
  50 + taskNatureService := service.NewTaskNatureService(nil)
  51 + getTaskNatureQuery := &query.GetTaskNatureQuery{}
  52 + taskNatureId, _ := controller.GetInt(":taskNatureId")
  53 + getTaskNatureQuery.TaskNatureId = taskNatureId
  54 + data, err := taskNatureService.GetTaskNature(getTaskNatureQuery)
  55 + var response utils.JsonResponse
  56 + if err != nil {
  57 + response = utils.ResponseError(controller.Ctx, err)
  58 + } else {
  59 + response = utils.ResponseData(controller.Ctx, data)
  60 + }
  61 + controller.Data["json"] = response
  62 + controller.ServeJSON()
  63 +}
  64 +
  65 +func (controller *TaskNatureController) RemoveTaskNature() {
  66 + taskNatureService := service.NewTaskNatureService(nil)
  67 + removeTaskNatureCommand := &command.RemoveTaskNatureCommand{}
  68 + taskNatureId, _ := controller.GetInt(":taskNatureId")
  69 + removeTaskNatureCommand.TaskNatureId = taskNatureId
  70 + data, err := taskNatureService.RemoveTaskNature(removeTaskNatureCommand)
  71 + var response utils.JsonResponse
  72 + if err != nil {
  73 + response = utils.ResponseError(controller.Ctx, err)
  74 + } else {
  75 + response = utils.ResponseData(controller.Ctx, data)
  76 + }
  77 + controller.Data["json"] = response
  78 + controller.ServeJSON()
  79 +}
  80 +
  81 +func (controller *TaskNatureController) ListTaskNature() {
  82 + taskNatureService := service.NewTaskNatureService(nil)
  83 + listTaskNatureQuery := &query.ListTaskNatureQuery{}
  84 + companyId, _ := controller.GetInt64("companyId")
  85 + listTaskNatureQuery.CompanyId = companyId
  86 + taskNatureName := controller.GetString("taskNatureName")
  87 + listTaskNatureQuery.TaskNatureName = taskNatureName
  88 + taskNatureNameMatch := controller.GetString("taskNatureNameMatch")
  89 + listTaskNatureQuery.TaskNatureNameMatch = taskNatureNameMatch
  90 + offset, _ := controller.GetInt("offset")
  91 + listTaskNatureQuery.Offset = offset
  92 + limit, _ := controller.GetInt("limit")
  93 + listTaskNatureQuery.Limit = limit
  94 + data, err := taskNatureService.ListTaskNature(listTaskNatureQuery)
  95 + var response utils.JsonResponse
  96 + if err != nil {
  97 + response = utils.ResponseError(controller.Ctx, err)
  98 + } else {
  99 + response = utils.ResponseData(controller.Ctx, data)
  100 + }
  101 + controller.Data["json"] = response
  102 + controller.ServeJSON()
  103 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/customer-values/", &controllers.CustomerValueController{}, "Post:CreateCustomerValue")
  10 + beego.Router("/customer-values/:customerValueId", &controllers.CustomerValueController{}, "Put:UpdateCustomerValue")
  11 + beego.Router("/customer-values/:customerValueId", &controllers.CustomerValueController{}, "Get:GetCustomerValue")
  12 + beego.Router("/customer-values/:customerValueId", &controllers.CustomerValueController{}, "Delete:RemoveCustomerValue")
  13 + beego.Router("/customer-values/", &controllers.CustomerValueController{}, "Get:ListCustomerValue")
  14 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/project-belongs/", &controllers.ProjectBelongController{}, "Post:CreateProjectBelong")
  10 + beego.Router("/project-belongs/:projectBelongId", &controllers.ProjectBelongController{}, "Put:UpdateProjectBelong")
  11 + beego.Router("/project-belongs/:projectBelongId", &controllers.ProjectBelongController{}, "Get:GetProjectBelong")
  12 + beego.Router("/project-belongs/:projectBelongId", &controllers.ProjectBelongController{}, "Delete:RemoveProjectBelong")
  13 + beego.Router("/project-belongs/", &controllers.ProjectBelongController{}, "Get:ListProjectBelong")
  14 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/task-natures/", &controllers.TaskNatureController{}, "Post:CreateTaskNature")
  10 + beego.Router("/task-natures/:taskNatureId", &controllers.TaskNatureController{}, "Put:UpdateTaskNature")
  11 + beego.Router("/task-natures/:taskNatureId", &controllers.TaskNatureController{}, "Get:GetTaskNature")
  12 + beego.Router("/task-natures/:taskNatureId", &controllers.TaskNatureController{}, "Delete:RemoveTaskNature")
  13 + beego.Router("/task-natures/", &controllers.TaskNatureController{}, "Get:ListTaskNature")
  14 +}
  1 +package customer_value
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建客户价值", func() {
  13 + Describe("提交数据创建客户价值", func() {
  14 + Context("提交正确的新客户价值数据", func() {
  15 + It("返回客户价值数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "companyId": 101,
  19 + "customerValueName": "口味",
  20 + }
  21 + httpExpect.POST("/customer-values/").
  22 + WithJSON(body).
  23 + Expect().
  24 + Status(http.StatusOK).
  25 + JSON().
  26 + Object().
  27 + ContainsKey("code").ValueEqual("code", 0).
  28 + ContainsKey("msg").ValueEqual("msg", "ok").
  29 + ContainsKey("data").Value("data").Object().
  30 + ContainsKey("customerValueId").ValueNotEqual("customerValueId", BeZero())
  31 + })
  32 + })
  33 + })
  34 + AfterEach(func() {
  35 + _, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
  36 + Expect(err).NotTo(HaveOccurred())
  37 + })
  38 +})
  1 +package customer_value
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestCustomerValue(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port CustomerValue Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package customer_value
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("返回客户价值", func() {
  16 + var customerValueId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&customerValueId),
  20 + "INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "口味", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("根据customerValueId参数返回客户价值", func() {
  25 + Context("传入有效的customerValueId", func() {
  26 + It("返回客户价值数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + httpExpect.GET(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object()
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package customer_value
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回客户价值列表", func() {
  14 + var customerValueId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&customerValueId),
  18 + "INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
  19 + "口味", 101)
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回客户价值列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回客户价值数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/customer-values/").
  27 + WithQuery("companyId", 101).
  28 + WithQuery("customerValueNameMatch", "口").
  29 + WithQuery("offset", 0).
  30 + WithQuery("limit", 20).
  31 + Expect().
  32 + Status(http.StatusOK).
  33 + JSON().
  34 + Object().
  35 + ContainsKey("code").ValueEqual("code", 0).
  36 + ContainsKey("msg").ValueEqual("msg", "ok").
  37 + ContainsKey("data").Value("data").Object().
  38 + ContainsKey("count").ValueEqual("count", 1).
  39 + ContainsKey("customerValues").Value("customerValues").Array()
  40 + })
  41 + })
  42 + })
  43 + AfterEach(func() {
  44 + _, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
  45 + Expect(err).NotTo(HaveOccurred())
  46 + })
  47 +})
  1 +package customer_value
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("移除客户价值", func() {
  16 + var customerValueId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&customerValueId),
  20 + "INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "口味", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("根据参数移除客户价值", func() {
  25 + Context("传入有效的customerValueId", func() {
  26 + It("返回被移除客户价值的数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + httpExpect.DELETE(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object()
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package customer_value
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("更新客户价值", func() {
  16 + var customerValueId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&customerValueId),
  20 + "INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "口感", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("提交数据更新客户价值", func() {
  25 + Context("提交正确的客户价值数据", func() {
  26 + It("返回更新后的客户价值数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + body := map[string]interface{}{
  29 + "customerValueName": "口味",
  30 + }
  31 + httpExpect.PUT(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
  32 + WithJSON(body).
  33 + Expect().
  34 + Status(http.StatusOK).
  35 + JSON().
  36 + Object().
  37 + ContainsKey("code").ValueEqual("code", 0).
  38 + ContainsKey("msg").ValueEqual("msg", "ok").
  39 + ContainsKey("data").Value("data").Object().
  40 + ContainsKey("customerValueId").ValueEqual("customerValueId", customerValueId).
  41 + ContainsKey("customerValueName").ValueEqual("customerValueName", "口味")
  42 + })
  43 + })
  44 + })
  45 + AfterEach(func() {
  46 + _, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
  47 + Expect(err).NotTo(HaveOccurred())
  48 + })
  49 +})
  1 +package project_belong
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建项目归属", func() {
  13 + Describe("提交数据创建项目归属", func() {
  14 + Context("提交正确的新项目归属数据", func() {
  15 + It("返回项目归属数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "companyId": 101,
  19 + "projectBelongName": "能力展示",
  20 + }
  21 + httpExpect.POST("/project-belongs/").
  22 + WithJSON(body).
  23 + Expect().
  24 + Status(http.StatusOK).
  25 + JSON().
  26 + Object().
  27 + ContainsKey("code").ValueEqual("code", 0).
  28 + ContainsKey("msg").ValueEqual("msg", "ok").
  29 + ContainsKey("data").Value("data").Object().
  30 + ContainsKey("projectBelongId").ValueNotEqual("projectBelongId", BeZero())
  31 + })
  32 + })
  33 + })
  34 + AfterEach(func() {
  35 + _, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
  36 + Expect(err).NotTo(HaveOccurred())
  37 + })
  38 +})
  1 +package project_belong
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("返回项目归属", func() {
  16 + var projectBelongId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&projectBelongId),
  20 + "INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "能力展示", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("根据projectBelongId参数返回项目归属", func() {
  25 + Context("传入有效的projectBelongId", func() {
  26 + It("返回项目归属数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + httpExpect.GET(fmt.Sprintf("/project-belongs/%s", strconv.FormatInt(projectBelongId, 10))).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object()
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package project_belong
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回项目归属列表", func() {
  14 + var projectBelongId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectBelongId),
  18 + "INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
  19 + "能力展示", 101)
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回项目归属列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回项目归属数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-belongs/").
  27 + WithQuery("companyId", 101).
  28 + WithQuery("projectBelongNameMatch", "力").
  29 + WithQuery("offset", "int").
  30 + WithQuery("limit", "int").
  31 + Expect().
  32 + Status(http.StatusOK).
  33 + JSON().
  34 + Object().
  35 + ContainsKey("code").ValueEqual("code", 0).
  36 + ContainsKey("msg").ValueEqual("msg", "ok").
  37 + ContainsKey("data").Value("data").Object().
  38 + ContainsKey("count").ValueEqual("count", 1).
  39 + ContainsKey("projectBelongs").Value("projectBelongs").Array()
  40 + })
  41 + })
  42 + })
  43 + AfterEach(func() {
  44 + _, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
  45 + Expect(err).NotTo(HaveOccurred())
  46 + })
  47 +})
  1 +package project_belong
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestProjectBelong(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port ProjectBelong Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package project_belong
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("移除项目归属", func() {
  16 + var projectBelongId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&projectBelongId),
  20 + "INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "能力展示", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("根据参数移除项目归属", func() {
  25 + Context("传入有效的projectBelongId", func() {
  26 + It("返回被移除项目归属的数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + httpExpect.DELETE(fmt.Sprintf("/project-belongs/%s", strconv.FormatInt(projectBelongId, 10))).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object()
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package project_belong
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("更新项目归属", func() {
  16 + var projectBelongId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&projectBelongId),
  20 + "INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "能力展示", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("提交数据更新项目归属", func() {
  25 + Context("提交正确的项目归属数据", func() {
  26 + It("返回更新后的项目归属数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + body := map[string]interface{}{
  29 + "projectBelongName": "销售导航",
  30 + }
  31 + httpExpect.PUT(fmt.Sprintf("/project-belongs/%s", strconv.FormatInt(projectBelongId, 10))).
  32 + WithJSON(body).
  33 + Expect().
  34 + Status(http.StatusOK).
  35 + JSON().
  36 + Object().
  37 + ContainsKey("code").ValueEqual("code", 0).
  38 + ContainsKey("msg").ValueEqual("msg", "ok").
  39 + ContainsKey("data").Value("data").Object().
  40 + ContainsKey("projectBelongId").ValueEqual("projectBelongId", projectBelongId)
  41 + })
  42 + })
  43 + })
  44 + AfterEach(func() {
  45 + _, err := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
  46 + Expect(err).NotTo(HaveOccurred())
  47 + })
  48 +})
  1 +package task_nature
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建任务性质", func() {
  13 + Describe("提交数据创建任务性质", func() {
  14 + Context("提交正确的新任务性质数据", func() {
  15 + It("返回任务性质数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "companyId": 101,
  19 + "taskNatureName": "点",
  20 + }
  21 + httpExpect.POST("/task-natures/").
  22 + WithJSON(body).
  23 + Expect().
  24 + Status(http.StatusOK).
  25 + JSON().
  26 + Object().
  27 + ContainsKey("code").ValueEqual("code", 0).
  28 + ContainsKey("msg").ValueEqual("msg", "ok").
  29 + ContainsKey("data").Value("data").Object().
  30 + ContainsKey("taskNatureId").ValueNotEqual("taskNatureId", BeZero())
  31 + })
  32 + })
  33 + })
  34 + AfterEach(func() {
  35 + _, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
  36 + Expect(err).NotTo(HaveOccurred())
  37 + })
  38 +})
  1 +package task_nature
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("返回任务性质", func() {
  16 + var taskNatureId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&taskNatureId),
  20 + "INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "点", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("根据taskNatureId参数返回任务性质", func() {
  25 + Context("传入有效的taskNatureId", func() {
  26 + It("返回任务性质数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + httpExpect.GET(fmt.Sprintf("/task-natures/%s", strconv.FormatInt(taskNatureId, 10))).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object()
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package task_nature
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回任务性质列表", func() {
  14 + var taskNatureId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&taskNatureId),
  18 + "INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
  19 + "点", 101)
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回任务性质列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回任务性质数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/task-natures/").
  27 + WithQuery("companyId", 101).
  28 + WithQuery("taskNatureNameMatch", "面").
  29 + WithQuery("offset", 0).
  30 + WithQuery("limit", 20).
  31 + Expect().
  32 + Status(http.StatusOK).
  33 + JSON().
  34 + Object().
  35 + ContainsKey("code").ValueEqual("code", 0).
  36 + ContainsKey("msg").ValueEqual("msg", "ok").
  37 + ContainsKey("data").Value("data").Object().
  38 + ContainsKey("count").ValueEqual("count", 0).
  39 + ContainsKey("taskNatures").Value("taskNatures").Array()
  40 + })
  41 + })
  42 + })
  43 + AfterEach(func() {
  44 + _, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
  45 + Expect(err).NotTo(HaveOccurred())
  46 + })
  47 +})
  1 +package task_nature
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("移除任务性质", func() {
  16 + var taskNatureId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&taskNatureId),
  20 + "INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "点", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("根据参数移除任务性质", func() {
  25 + Context("传入有效的taskNatureId", func() {
  26 + It("返回被移除任务性质的数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + httpExpect.DELETE(fmt.Sprintf("/task-natures/%s", strconv.FormatInt(taskNatureId, 10))).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object()
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package task_nature
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestTaskNature(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port TaskNature Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package task_nature
  2 +
  3 +import (
  4 + "fmt"
  5 + "net/http"
  6 + "strconv"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("更新任务性质", func() {
  16 + var taskNatureId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&taskNatureId),
  20 + "INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
  21 + "点", 101)
  22 + Expect(err).NotTo(HaveOccurred())
  23 + })
  24 + Describe("提交数据更新任务性质", func() {
  25 + Context("提交正确的任务性质数据", func() {
  26 + It("返回更新后的任务性质数据", func() {
  27 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  28 + body := map[string]interface{}{
  29 + "taskNatureName": "面",
  30 + }
  31 + httpExpect.PUT(fmt.Sprintf("/task-natures/%s", strconv.FormatInt(taskNatureId, 10))).
  32 + WithJSON(body).
  33 + Expect().
  34 + Status(http.StatusOK).
  35 + JSON().
  36 + Object().
  37 + ContainsKey("code").ValueEqual("code", 0).
  38 + ContainsKey("msg").ValueEqual("msg", "ok").
  39 + ContainsKey("data").Value("data").Object().
  40 + ContainsKey("taskNatureId").ValueEqual("taskNatureId", taskNatureId)
  41 + })
  42 + })
  43 + })
  44 + AfterEach(func() {
  45 + _, err := pG.DB.Exec("DELETE FROM task_natures WHERE true")
  46 + Expect(err).NotTo(HaveOccurred())
  47 + })
  48 +})