作者 陈志颖

feat:添加共创申请管理功能

正在显示 22 个修改的文件 包含 1352 行增加0 行删除
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type AgreeCooperationApplicationCommand struct {
// 共创申请ID
CooperationApplicationId int64 `cname:"共创申请ID" json:"cooperationApplicationId,string" valid:"Required"`
// 共创申请审核描述
CooperationApplicationVerifyDescription string `cname:"共创申请审核描述" json:"cooperationApplicationVerifyDescription" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构id
OrgId int64 `cname:"组织机构id" json:"orgId,string" valid:"Required"`
// 菜单编码,APP端必须
Code string `cname:"菜单编码,APP端必须" json:"code" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (agreeCooperationApplicationCommand *AgreeCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (agreeCooperationApplicationCommand *AgreeCooperationApplicationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(agreeCooperationApplicationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(agreeCooperationApplicationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type ApplyForCooperationCommand struct {
// 共创申请描述附件
CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment" valid:"Required"`
// 共创申请描述
CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
// 用户基本id
UserBaseId int64 `cname:"用户基本id" json:"userBaseId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 组织名称
OrgName string `cname:"组织名称" json:"orgName" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 公司logo
CompanyLogo string `cname:"公司logo" json:"companyLogo" valid:"Required"`
// 公司名称
CompanyName string `cname:"公司名称" json:"companyName" valid:"Required"`
// 用户关联的组织机构
Orgs []*domain.Org `cname:"用户关联的组织机构" json:"orgs" valid:"Required"`
// 部门ID,通过REST集成上下文获取
DepartmentId int64 `cname:"部门ID,通过REST集成上下文获取" json:"departmentId,string" valid:"Required"`
// 部门名称
DepartmentName string `cname:"部门名称" json:"departmentName" valid:"Required"`
// 部门编码
DepartmentNumber string `cname:"部门编码" json:"departmentNumber" valid:"Required"`
// 是否组织机构标识,1为是,2为否,默认为否
IsOrganization bool `cname:"是否组织机构标识,1为是,2为否,默认为否" json:"isOrganization" valid:"Required"`
// 角色ID
RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"`
// 角色名称
RoleName string `cname:"角色名称" json:"roleName" valid:"Required"`
// 用户头像
UserAvatar string `cname:"用户头像" json:"userAvatar" valid:"Required"`
// 用户邮箱
UserEmail string `cname:"用户邮箱" json:"userEmail" valid:"Required"`
// 共创人员姓名
UserName string `cname:"共创人员姓名" json:"userName" valid:"Required"`
// 用户手机号
UserPhone string `cname:"用户手机号" json:"userPhone" valid:"Required"`
// 用户账号,区别于手机号,冗余字段
UserAccount string `cname:"用户账号,区别于手机号,冗余字段" json:"userAccount" valid:"Required"`
// 用户类型
UserType int32 `cname:"用户类型" json:"userType" valid:"Required"`
// 状态
Status int32 `cname:"状态" json:"status" valid:"Required"`
// 共创申请ID
CooperationApplicationId int64 `cname:"共创申请ID" json:"cooperationApplicationId,string" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationProjectNumber string `cname:"共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001" json:"cooperationProjectNumber" valid:"Required"`
// 共创申请时间
CooperationApplyTime time.Time `cname:"共创申请时间" json:"cooperationApplyTime" valid:"Required"`
}
func (applyForCooperationCommand *ApplyForCooperationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (applyForCooperationCommand *ApplyForCooperationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(applyForCooperationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(applyForCooperationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateCooperationApplicationCommand struct {
// 共创申请人uid
ApplicantUid string `cname:"共创申请人uid" json:"applicantUid" valid:"Required"`
// 共创申请描述
CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
// 共创申请描述附件
CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment,omitempty"`
// 关联的共创项目编号
CooperationProjectNumber string `cname:"关联的共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (createCooperationApplicationCommand *CreateCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperationApplicationCommand *CreateCooperationApplicationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCooperationApplicationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCooperationApplicationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RejectCooperationApplicationCommand struct {
// 共创申请ID
CooperationApplicationId int64 `cname:"共创申请ID" json:"cooperationApplicationId,string" valid:"Required"`
// 共创申请审核描述
CooperationApplicationVerifyDescription string `cname:"共创申请审核描述" json:"cooperationApplicationVerifyDescription" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构id
OrgId int64 `cname:"组织机构id" json:"orgId,string" valid:"Required"`
// 菜单模块编码,APP端必须
Code string `cname:"菜单模块编码,APP端必须" json:"code" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (rejectCooperationApplicationCommand *RejectCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (rejectCooperationApplicationCommand *RejectCooperationApplicationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(rejectCooperationApplicationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(rejectCooperationApplicationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveCooperationApplicationCommand struct {
// 共创申请ID
CooperationApplicationId int64 `cname:"共创申请ID" json:"cooperationApplicationId,string" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (removeCooperationApplicationCommand *RemoveCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCooperationApplicationCommand *RemoveCooperationApplicationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCooperationApplicationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeCooperationApplicationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateCooperationApplicationCommand struct {
// 共创申请id
CooperationApplicationId string `cname:"共创申请id" json:"cooperationApplicationId" valid:"Required"`
// 共创申请人uid
ApplicantUid string `cname:"共创申请人uid" json:"applicantUid" valid:"Required"`
// 共创申请描述
CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
// 共创申请描述附件
CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment,omitempty"`
// 关联的共创项目编号
CooperationProjectNumber string `cname:"关联的共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (updateCooperationApplicationCommand *UpdateCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationApplicationCommand *UpdateCooperationApplicationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCooperationApplicationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCooperationApplicationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetCooperationApplicationQuery struct {
// 共创申请ID
CooperationApplicationId int64 `cname:"共创申请ID" json:"cooperationApplicationId,string" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (getCooperationApplicationQuery *GetCooperationApplicationQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCooperationApplicationQuery *GetCooperationApplicationQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCooperationApplicationQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getCooperationApplicationQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListCooperationApplicationQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (listCooperationApplicationQuery *ListCooperationApplicationQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCooperationApplicationQuery *ListCooperationApplicationQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCooperationApplicationQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCooperationApplicationQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchCooperationApplicationQuery struct {
// 共创项目名称
CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"`
// 申请人姓名
ApplicantName string `cname:"申请人姓名" json:"applicantName,omitempty"`
// 共创申请审核状态,1待审核,2已同意,3已拒绝
CooperationApplicationStatus int32 `cname:"共创申请审核状态,1待审核,2已同意,3已拒绝" json:"cooperationApplicationStatus,omitempty"`
// 页面大小
PageSize int32 `cname:"页面大小" json:"pageSize,omitempty"`
// 页面大小
PageNumber int32 `cname:"页面大小" json:"pageNumber,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (searchCooperationApplicationQuery *SearchCooperationApplicationQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationApplicationQuery *SearchCooperationApplicationQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchCooperationApplicationQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchCooperationApplicationQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
)
// 共创申请服务
type CooperationApplicationService struct {
}
// 审核-同意共创申请
func (cooperationApplicationService *CooperationApplicationService) AgreeCooperationApplication(agreeCooperationApplicationCommand *command.AgreeCooperationApplicationCommand) (interface{}, error) {
if err := agreeCooperationApplicationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 申请共创
func (cooperationApplicationService *CooperationApplicationService) ApplyForCooperation(applyForCooperationCommand *command.ApplyForCooperationCommand) (interface{}, error) {
if err := applyForCooperationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 创建共创申请服务
func (cooperationApplicationService *CooperationApplicationService) CreateCooperationApplication(createCooperationApplicationCommand *command.CreateCooperationApplicationCommand) (interface{}, error) {
if err := createCooperationApplicationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
newCooperationApplication := &cooperationApplication.CooperationApplication{
ApplicantUid: createCooperationApplicationCommand.ApplicantUid,
CooperationApplicationDescription: createCooperationApplicationCommand.CooperationApplicationDescription,
CooperationApplicationAttachment: createCooperationApplicationCommand.CooperationApplicationAttachment,
CooperationProjectNumber: createCooperationApplicationCommand.CooperationProjectNumber,
CompanyId: createCooperationApplicationCommand.CompanyId,
OrgId: createCooperationApplicationCommand.OrgId,
UserId: createCooperationApplicationCommand.UserId,
}
var cooperationApplicationRepository cooperationApplication.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplication, nil
}
}
// 返回共创申请服务
func (cooperationApplicationService *CooperationApplicationService) GetCooperationApplication(getCooperationApplicationQuery *query.GetCooperationApplicationQuery) (interface{}, error) {
if err := getCooperationApplicationQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var cooperationApplicationRepository cooperationApplication.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": getCooperationApplicationQuery.CooperationApplicationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationApplication == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCooperationApplicationQuery.CooperationApplicationId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplication, nil
}
}
// 返回共创申请服务列表
func (cooperationApplicationService *CooperationApplicationService) ListCooperationApplication(listCooperationApplicationQuery *query.ListCooperationApplicationQuery) (interface{}, error) {
if err := listCooperationApplicationQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var cooperationApplicationRepository cooperationApplication.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(listCooperationApplicationQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"cooperationApplications": cooperationApplications,
}, nil
}
}
// 审核-拒绝共创申请
func (cooperationApplicationService *CooperationApplicationService) RejectCooperationApplication(rejectCooperationApplicationCommand *command.RejectCooperationApplicationCommand) (interface{}, error) {
if err := rejectCooperationApplicationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 移除共创申请服务
func (cooperationApplicationService *CooperationApplicationService) RemoveCooperationApplication(removeCooperationApplicationCommand *command.RemoveCooperationApplicationCommand) (interface{}, error) {
if err := removeCooperationApplicationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var cooperationApplicationRepository cooperationApplication.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": removeCooperationApplicationCommand.CooperationApplicationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationApplication == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCooperationApplicationCommand.CooperationApplicationId)))
}
if cooperationApplication, err := cooperationApplicationRepository.Remove(cooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplication, nil
}
}
// 查询共创申请
func (cooperationApplicationService *CooperationApplicationService) SearchCooperationApplication(searchCooperationApplicationQuery *query.SearchCooperationApplicationQuery) (interface{}, error) {
if err := searchCooperationApplicationQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 更新共创申请服务
func (cooperationApplicationService *CooperationApplicationService) UpdateCooperationApplication(updateCooperationApplicationCommand *command.UpdateCooperationApplicationCommand) (interface{}, error) {
if err := updateCooperationApplicationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var cooperationApplicationRepository cooperationApplication.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": updateCooperationApplicationCommand.CooperationApplicationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationApplication == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationApplicationCommand.CooperationApplicationId)))
}
if err := cooperationApplication.Update(tool_funs.SimpleStructToMap(updateCooperationApplicationCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationApplication, err := cooperationApplicationRepository.Save(cooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplication, nil
}
}
func NewCooperationApplicationService(options map[string]interface{}) *CooperationApplicationService {
newCooperationApplicationService := &CooperationApplicationService{}
return newCooperationApplicationService
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/service"
)
type CooperationApplicationController struct {
beego.BaseController
}
func (controller *CooperationApplicationController) ApplyForCooperation() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
applyForCooperationCommand := &command.ApplyForCooperationCommand{}
controller.Unmarshal(applyForCooperationCommand)
data, err := cooperationApplicationService.ApplyForCooperation(applyForCooperationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) AgreeCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
agreeCooperationApplicationCommand := &command.AgreeCooperationApplicationCommand{}
controller.Unmarshal(agreeCooperationApplicationCommand)
data, err := cooperationApplicationService.AgreeCooperationApplication(agreeCooperationApplicationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) RejectCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
rejectCooperationApplicationCommand := &command.RejectCooperationApplicationCommand{}
controller.Unmarshal(rejectCooperationApplicationCommand)
data, err := cooperationApplicationService.RejectCooperationApplication(rejectCooperationApplicationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) CreateCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
createCooperationApplicationCommand := &command.CreateCooperationApplicationCommand{}
controller.Unmarshal(createCooperationApplicationCommand)
data, err := cooperationApplicationService.CreateCooperationApplication(createCooperationApplicationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) UpdateCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
updateCooperationApplicationCommand := &command.UpdateCooperationApplicationCommand{}
controller.Unmarshal(updateCooperationApplicationCommand)
cooperationApplicationId := controller.GetString(":cooperationApplicationId")
updateCooperationApplicationCommand.CooperationApplicationId = cooperationApplicationId
data, err := cooperationApplicationService.UpdateCooperationApplication(updateCooperationApplicationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) GetCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
getCooperationApplicationQuery := &query.GetCooperationApplicationQuery{}
cooperationApplicationId, _ := controller.GetInt64(":cooperationApplicationId")
getCooperationApplicationQuery.CooperationApplicationId = cooperationApplicationId
data, err := cooperationApplicationService.GetCooperationApplication(getCooperationApplicationQuery)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) RemoveCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
removeCooperationApplicationCommand := &command.RemoveCooperationApplicationCommand{}
controller.Unmarshal(removeCooperationApplicationCommand)
cooperationApplicationId, _ := controller.GetInt64(":cooperationApplicationId")
removeCooperationApplicationCommand.CooperationApplicationId = cooperationApplicationId
data, err := cooperationApplicationService.RemoveCooperationApplication(removeCooperationApplicationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) SearchCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
searchCooperationApplicationQuery := &query.SearchCooperationApplicationQuery{}
data, err := cooperationApplicationService.SearchCooperationApplication(searchCooperationApplicationQuery)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) ListCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
listCooperationApplicationQuery := &query.ListCooperationApplicationQuery{}
offset, _ := controller.GetInt("offset")
listCooperationApplicationQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listCooperationApplicationQuery.Limit = limit
data, err := cooperationApplicationService.ListCooperationApplication(listCooperationApplicationQuery)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego/controllers"
)
func init() {
web.Router("/cooperation-applications/apply-for-cooperation", &controllers.CooperationApplicationController{}, "Post:ApplyForCooperation")
web.Router("/cooperation-applications/agree-cooperation-application", &controllers.CooperationApplicationController{}, "Post:AgreeCooperationApplication")
web.Router("/cooperation-applications/reject-cooperation-application", &controllers.CooperationApplicationController{}, "Post:RejectCooperationApplication")
web.Router("/cooperation-applications/", &controllers.CooperationApplicationController{}, "Post:CreateCooperationApplication")
web.Router("/cooperation-applications/:cooperationApplicationId", &controllers.CooperationApplicationController{}, "Put:UpdateCooperationApplication")
web.Router("/cooperation-applications/:cooperationApplicationId", &controllers.CooperationApplicationController{}, "Get:GetCooperationApplication")
web.Router("/cooperation-applications/:cooperationApplicationId", &controllers.CooperationApplicationController{}, "Delete:RemoveCooperationApplication")
web.Router("/cooperation-applications/search", &controllers.CooperationApplicationController{}, "Post:SearchCooperationApplication")
web.Router("/cooperation-applications/", &controllers.CooperationApplicationController{}, "Get:ListCooperationApplication")
}
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("审核-同意共创申请", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("审核-同意共创申请", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationApplicationId": "int64",
"cooperationApplicationVerifyDescription": "string",
"companyId": "int64",
"orgId": "int64",
"code": "string",
"userId": "int64",
}
httpExpect.POST("/cooperation-applications/agree-cooperation-application").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("申请共创", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("申请共创", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationApplicationAttachment": "array",
"cooperationApplicationDescription": "string",
"userId": "int64",
"userBaseId": "int64",
"orgId": "int64",
"orgName": "string",
"companyId": "int64",
"companyLogo": "string",
"companyName": "string",
"orgs": "array",
"departmentId": "int64",
"departmentName": "string",
"departmentNumber": "string",
"isOrganization": "boolean",
"roleId": "int64",
"roleName": "string",
"userAvatar": "string",
"userEmail": "string",
"userName": "string",
"userPhone": "string",
"userAccount": "string",
"userType": "int32",
"status": "int32",
"cooperationApplicationId": "int64",
"cooperationProjectNumber": "string",
"cooperationApplyTime": "datetime",
}
httpExpect.POST("/cooperation-applications/apply-for-cooperation").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
)
func TestCooperationApplication(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port CooperationApplication Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("创建共创申请服务", func() {
Describe("提交数据创建共创申请服务", func() {
Context("提交正确的新共创申请实体数据", func() {
It("返回共创申请实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"applicantUid": "string",
"cooperationApplicationDescription": "string",
"cooperationApplicationAttachment": "array",
"cooperationProjectNumber": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-applications/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("cooperationApplicationId").ValueNotEqual("cooperationApplicationId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("返回共创申请服务", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据cooperationApplicationId参数返回共创申请实体", func() {
Context("传入有效的cooperationApplicationId", func() {
It("返回共创申请实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cooperation-applications/{cooperationApplicationId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("返回共创申请服务列表", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回共创申请实体列表", func() {
Context("传入有效的参数", func() {
It("返回共创申请实体数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cooperation-applications/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("cooperationApplications").Value("cooperationApplications").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("审核-拒绝共创申请", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("审核-拒绝共创申请", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationApplicationId": "int64",
"cooperationApplicationVerifyDescription": "string",
"companyId": "int64",
"orgId": "int64",
"code": "string",
"userId": "int64",
}
httpExpect.POST("/cooperation-applications/reject-cooperation-application").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("移除共创申请服务", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除共创申请服务", func() {
Context("传入有效的cooperationApplicationId", func() {
It("返回被移除共创申请实体的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/cooperation-applications/{cooperationApplicationId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("查询共创申请", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("查询共创申请", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationProjectName": "string",
"applicantName": "string",
"cooperationApplicationStatus": "int32",
"pageSize": "int32",
"pageNumber": "int32",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-applications/search").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_application
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("更新共创申请服务", func() {
var cooperationApplicationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationApplicationId),
"INSERT INTO cooperation_applications (cooperation_application_id, cooperation_application_applicant, cooperation_application_attachment, cooperation_application_description, cooperation_application_status, cooperation_application_verifier, cooperation_application_verify_description, cooperation_application_verify_time, cooperation_apply_time, cooperation_project, org, company, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_application_id",
"testCooperationApplicationId", "testCooperationApplicationApplicant", "testCooperationApplicationAttachment", "testCooperationApplicationDescription", "testCooperationApplicationStatus", "testCooperationApplicationVerifier", "testCooperationApplicationVerifyDescription", "testCooperationApplicationVerifyTime", "testCooperationApplyTime", "testCooperationProject", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新共创申请服务", func() {
Context("提交正确的共创申请实体数据", func() {
It("返回更新后的共创申请实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"applicantUid": "string",
"cooperationApplicationDescription": "string",
"cooperationApplicationAttachment": "array",
"cooperationProjectNumber": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.PUT("/cooperation-applications/{cooperationApplicationId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("cooperationApplicationId").ValueEqual("cooperationApplicationId", cooperationApplicationId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_applications WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...