作者 陈志颖

feat:添加共创项目功能

正在显示 52 个修改的文件 包含 2669 行增加217 行删除
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateCooperationContractCommand struct {
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationProjectNumber string `cname:"共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001" json:"cooperationProjectNumber" valid:"Required"`
// 共创合约发起部门编码
DepartmentNumber string `cname:"共创合约发起部门编码" json:"departmentNumber" valid:"Required"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int32 `cname:"共创合约承接对象,1员工,2共创用户,3公开" json:"cooperationContractUndertakerType" valid:"Required"`
// 共创合约名称
CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"`
// 共创模式编码,手动输入,唯一确定
CooperationModeNumber string `cname:"共创模式编码,手动输入,唯一确定" json:"cooperationModeNumber" valid:"Required"`
// 共创合约发起人uid
SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"`
// 业绩分红激励规则列表
DividendsIncentivesRules []*domain.DividendsIncentivesRule `cname:"业绩分红激励规则列表" json:"dividendsIncentivesRules,omitempty"`
// 金额激励规则列表
MoneyIncentivesRules []*domain.MoneyIncentivesRule `cname:"金额激励规则列表" json:"moneyIncentivesRules,omitempty"`
// 承接方列表
Undertakers []*domain.Undertaker `cname:"承接方列表" json:"undertakers,omitempty"`
// 相关人列表
Relevants []*domain.Relevant `cname:"相关人列表" json:"relevants,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 (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCooperationContractCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCooperationContractCommand).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 RemoveCooperationContractCommand struct {
// 共创合约ID
CooperationContractId int64 `cname:"共创合约ID" json:"cooperationContractId,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 (removeCooperationContractCommand *RemoveCooperationContractCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCooperationContractCommand *RemoveCooperationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCooperationContractCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeCooperationContractCommand).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 UpdateCooperationContractCommand struct {
// 共创合约id
CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationProjectNumber string `cname:"共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001" json:"cooperationProjectNumber" valid:"Required"`
// 部门编码
DepartmentNumber string `cname:"部门编码" json:"departmentNumber" valid:"Required"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int32 `cname:"共创合约承接对象,1员工,2共创用户,3公开" json:"cooperationContractUndertakerType" valid:"Required"`
// 共创合约名称
CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"`
// 共创模式编码,手动输入,唯一确定
CooperationModeNumber string `cname:"共创模式编码,手动输入,唯一确定" json:"cooperationModeNumber" valid:"Required"`
// 共创合约发起人uid
SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,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 (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCooperationContractCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCooperationContractCommand).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 GetCooperationContractQuery struct {
// 共创合约ID
CooperationContractId int64 `cname:"共创合约ID" json:"cooperationContractId,string" valid:"Required"`
// 发起人uid
SponsorUid string `cname:"发起人uid" json:"sponsorUid,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 (getCooperationContractQuery *GetCooperationContractQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCooperationContractQuery *GetCooperationContractQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCooperationContractQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getCooperationContractQuery).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 ListCooperationContractQuery 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 (listCooperationContractQuery *ListCooperationContractQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCooperationContractQuery *ListCooperationContractQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCooperationContractQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCooperationContractQuery).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 SearchCooperationContractQuery struct {
// 页面大小
PageSize int32 `cname:"页面大小" json:"pageSize" valid:"Required"`
// 页面大小
PageNumber int32 `cname:"页面大小" json:"pageNumber" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 发起人姓名
SponsorName string `cname:"发起人姓名" json:"sponsorName,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 (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchCooperationContractQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchCooperationContractQuery).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 SearchCooperationContractByUndertakerQuery struct {
// 共创合约名称
CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName,omitempty"`
// 项目发起人姓名
SponsorName string `cname:"项目发起人姓名" json:"sponsorName,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 (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchCooperationContractByUndertakerQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchCooperationContractByUndertakerQuery).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 (
"fmt"
"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/cooperationContract/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// 共创合约服务
type CooperationContractService struct {
}
// 创建共创合约服务
func (cooperationContractService *CooperationContractService) CreateCooperationContract(createCooperationContractCommand *command.CreateCooperationContractCommand) (interface{}, error) {
if err := createCooperationContractCommand.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()
}()
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber,
DepartmentNumber: createCooperationContractCommand.DepartmentNumber,
CooperationContractUndertakerType: createCooperationContractCommand.CooperationContractUndertakerType,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
CooperationModeNumber: createCooperationContractCommand.CooperationModeNumber,
SponsorUid: createCooperationContractCommand.SponsorUid,
DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules,
MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules,
Undertakers: createCooperationContractCommand.Undertakers,
Relevants: createCooperationContractCommand.Relevants,
CompanyId: createCooperationContractCommand.CompanyId,
OrgId: createCooperationContractCommand.OrgId,
UserId: createCooperationContractCommand.UserId,
}
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); 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 cooperationContract, nil
}
}
// 返回共创合约服务
func (cooperationContractService *CooperationContractService) GetCooperationContract(getCooperationContractQuery *query.GetCooperationContractQuery) (interface{}, error) {
if err := getCooperationContractQuery.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 cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": getCooperationContractQuery.CooperationContractId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCooperationContractQuery.CooperationContractId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationContract, nil
}
}
// 返回共创合约服务列表
func (cooperationContractService *CooperationContractService) ListCooperationContract(listCooperationContractQuery *query.ListCooperationContractQuery) (interface{}, error) {
if err := listCooperationContractQuery.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 cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(listCooperationContractQuery)); 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,
"cooperationContracts": cooperationContracts,
}, nil
}
}
// 移除共创合约服务
func (cooperationContractService *CooperationContractService) RemoveCooperationContract(removeCooperationContractCommand *command.RemoveCooperationContractCommand) (interface{}, error) {
if err := removeCooperationContractCommand.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 cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": removeCooperationContractCommand.CooperationContractId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCooperationContractCommand.CooperationContractId)))
}
if cooperationContract, err := cooperationContractRepository.Remove(cooperationContract); 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 cooperationContract, nil
}
}
// 查询共创合约
func (cooperationContractService *CooperationContractService) SearchCooperationContract(searchCooperationContractQuery *query.SearchCooperationContractQuery) (interface{}, error) {
if err := searchCooperationContractQuery.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 (cooperationContractService *CooperationContractService) SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery *query.SearchCooperationContractByUndertakerQuery) (interface{}, error) {
if err := searchCooperationContractByUndertakerQuery.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 (cooperationContractService *CooperationContractService) UpdateCooperationContract(updateCooperationContractCommand *command.UpdateCooperationContractCommand) (interface{}, error) {
if err := updateCooperationContractCommand.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 cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
}
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); 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 cooperationContract, nil
}
}
func NewCooperationContractService(options map[string]interface{}) *CooperationContractService {
newCooperationContractService := &CooperationContractService{}
return newCooperationContractService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateCooperationContractChangeLogCommand struct {
// 激励规则
IncentivesRule string `cname:"激励规则" json:"incentivesRule" valid:"Required"`
// 激励规则明细
IncentivesRuleDetail string `cname:"激励规则明细" json:"incentivesRuleDetail" valid:"Required"`
// 合约变更操作类型,1编辑、2暂停、3恢复
OperationType int32 `cname:"合约变更操作类型,1编辑、2暂停、3恢复" json:"operationType" valid:"Required"`
// 承接人
Undertakers string `cname:"承接人" json:"undertakers" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" 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 (createCooperationContractChangeLogCommand *CreateCooperationContractChangeLogCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperationContractChangeLogCommand *CreateCooperationContractChangeLogCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCooperationContractChangeLogCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCooperationContractChangeLogCommand).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 RemoveCooperationContractChangeLogCommand struct {
// 合约变更记录ID
CooperationContractChangeLogId int64 `cname:"合约变更记录ID" json:"cooperationContractChangeLogId,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 (removeCooperationContractChangeLogCommand *RemoveCooperationContractChangeLogCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCooperationContractChangeLogCommand *RemoveCooperationContractChangeLogCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCooperationContractChangeLogCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeCooperationContractChangeLogCommand).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 UpdateCooperationContractChangeLogCommand struct {
// 共创合约修改记录id
CooperationContractChangeLogId string `cname:"共创合约修改记录id" json:"cooperationContractChangeLogId" valid:"Required"`
// 激励规则
IncentivesRule string `cname:"激励规则" json:"incentivesRule" valid:"Required"`
// 激励规则明细
IncentivesRuleDetail string `cname:"激励规则明细" json:"incentivesRuleDetail" valid:"Required"`
// 合约变更操作类型,1编辑、2暂停、3恢复
OperationType int32 `cname:"合约变更操作类型,1编辑、2暂停、3恢复" json:"operationType" valid:"Required"`
// 承接人
Undertakers string `cname:"承接人" json:"undertakers" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" 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 (updateCooperationContractChangeLogCommand *UpdateCooperationContractChangeLogCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationContractChangeLogCommand *UpdateCooperationContractChangeLogCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCooperationContractChangeLogCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCooperationContractChangeLogCommand).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 GetCooperationContractChangeLogQuery struct {
// 合约变更记录ID
CooperationContractChangeLogId int64 `cname:"合约变更记录ID" json:"cooperationContractChangeLogId,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 (getCooperationContractChangeLogQuery *GetCooperationContractChangeLogQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCooperationContractChangeLogQuery *GetCooperationContractChangeLogQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCooperationContractChangeLogQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getCooperationContractChangeLogQuery).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 ListCooperationContractChangeLogQuery 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 (listCooperationContractChangeLogQuery *ListCooperationContractChangeLogQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCooperationContractChangeLogQuery *ListCooperationContractChangeLogQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCooperationContractChangeLogQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCooperationContractChangeLogQuery).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 SearchCooperationContractChangeLogQuery struct {
// 合约变更操作类型,1编辑、2暂停、3恢复
OperationType int32 `cname:"合约变更操作类型,1编辑、2暂停、3恢复" json:"operationType,omitempty"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber,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 (searchCooperationContractChangeLogQuery *SearchCooperationContractChangeLogQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractChangeLogQuery *SearchCooperationContractChangeLogQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchCooperationContractChangeLogQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchCooperationContractChangeLogQuery).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 (
"fmt"
"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/cooperationContractChangeLog/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContractChangeLog/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// 共创合约变更日志
type CooperationContractChangeLogService struct {
}
// 创建共创合约变更日志
func (cooperationContractChangeLogService *CooperationContractChangeLogService) CreateCooperationContractChangeLog(createCooperationContractChangeLogCommand *command.CreateCooperationContractChangeLogCommand) (interface{}, error) {
if err := createCooperationContractChangeLogCommand.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()
}()
newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
IncentivesRule: createCooperationContractChangeLogCommand.IncentivesRule,
IncentivesRuleDetail: createCooperationContractChangeLogCommand.IncentivesRuleDetail,
OperationType: createCooperationContractChangeLogCommand.OperationType,
Undertakers: createCooperationContractChangeLogCommand.Undertakers,
CooperationContractNumber: createCooperationContractChangeLogCommand.CooperationContractNumber,
//CompanyId: createCooperationContractChangeLogCommand.CompanyId,
//OrgId: createCooperationContractChangeLogCommand.OrgId,
//UserId: createCooperationContractChangeLogCommand.UserId,
}
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
if cooperationContractChangeLog, err := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); 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 cooperationContractChangeLog, nil
}
}
// 返回共创合约变更日志
func (cooperationContractChangeLogService *CooperationContractChangeLogService) GetCooperationContractChangeLog(getCooperationContractChangeLogQuery *query.GetCooperationContractChangeLogQuery) (interface{}, error) {
if err := getCooperationContractChangeLogQuery.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 cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
cooperationContractChangeLog, err := cooperationContractChangeLogRepository.FindOne(map[string]interface{}{"cooperationContractChangeLogId": getCooperationContractChangeLogQuery.CooperationContractChangeLogId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContractChangeLog == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCooperationContractChangeLogQuery.CooperationContractChangeLogId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationContractChangeLog, nil
}
}
// 返回共创合约变更日志列表
func (cooperationContractChangeLogService *CooperationContractChangeLogService) ListCooperationContractChangeLog(listCooperationContractChangeLogQuery *query.ListCooperationContractChangeLogQuery) (interface{}, error) {
if err := listCooperationContractChangeLogQuery.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 cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
if count, cooperationContractChangeLogs, err := cooperationContractChangeLogRepository.Find(tool_funs.SimpleStructToMap(listCooperationContractChangeLogQuery)); 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,
"cooperationContractChangeLogs": cooperationContractChangeLogs,
}, nil
}
}
// 移除共创合约变更日志
func (cooperationContractChangeLogService *CooperationContractChangeLogService) RemoveCooperationContractChangeLog(removeCooperationContractChangeLogCommand *command.RemoveCooperationContractChangeLogCommand) (interface{}, error) {
if err := removeCooperationContractChangeLogCommand.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 cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
cooperationContractChangeLog, err := cooperationContractChangeLogRepository.FindOne(map[string]interface{}{"cooperationContractChangeLogId": removeCooperationContractChangeLogCommand.CooperationContractChangeLogId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContractChangeLog == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCooperationContractChangeLogCommand.CooperationContractChangeLogId)))
}
if cooperationContractChangeLog, err := cooperationContractChangeLogRepository.Remove(cooperationContractChangeLog); 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 cooperationContractChangeLog, nil
}
}
// 共创合约变更记录搜索
func (cooperationContractChangeLogService *CooperationContractChangeLogService) SearchCooperationContractChangeLog(searchCooperationContractChangeLogQuery *query.SearchCooperationContractChangeLogQuery) (interface{}, error) {
if err := searchCooperationContractChangeLogQuery.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 (cooperationContractChangeLogService *CooperationContractChangeLogService) UpdateCooperationContractChangeLog(updateCooperationContractChangeLogCommand *command.UpdateCooperationContractChangeLogCommand) (interface{}, error) {
if err := updateCooperationContractChangeLogCommand.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 cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
cooperationContractChangeLog, err := cooperationContractChangeLogRepository.FindOne(map[string]interface{}{"cooperationContractChangeLogId": updateCooperationContractChangeLogCommand.CooperationContractChangeLogId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContractChangeLog == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractChangeLogCommand.CooperationContractChangeLogId)))
}
if err := cooperationContractChangeLog.Update(tool_funs.SimpleStructToMap(updateCooperationContractChangeLogCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationContractChangeLog, err := cooperationContractChangeLogRepository.Save(cooperationContractChangeLog); 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 cooperationContractChangeLog, nil
}
}
func NewCooperationContractChangeLogService(options map[string]interface{}) *CooperationContractChangeLogService {
newCooperationContractChangeLogService := &CooperationContractChangeLogService{}
return newCooperationContractChangeLogService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateCooperationProjectCommand struct {
// 共创项目名称
CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"`
// 承接对象,1员工,2共创用户,3公开,可以多选
CooperationProjectUndertakerType []int32 `cname:"承接对象,1员工,2共创用户,3公开,可以多选" json:"cooperationProjectUndertakerType" valid:"Required"`
// 共创项目发起人uid
SponsorUid string `cname:"共创项目发起人uid" json:"sponsorUid" valid:"Required"`
// 共创项目发布人uid
PublisherUid string `cname:"共创项目发布人uid" json:"publisherUid" valid:"Required"`
// 共创项目描述
CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription,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 (createCooperationProjectCommand *CreateCooperationProjectCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperationProjectCommand *CreateCooperationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCooperationProjectCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCooperationProjectCommand).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 ReleaseCooperationProjectCommand struct {
// 共创项目名称
CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"`
// 共创模式ID
CooperationModeId int64 `cname:"共创模式ID" json:"cooperationModeId,string" 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"`
// 共创项目承接对象,1员工,2共创用户,3公开,可以多选
CooperationProjectUndertakerType []int32 `cname:"共创项目承接对象,1员工,2共创用户,3公开,可以多选" json:"cooperationProjectUndertakerType" valid:"Required"`
// 共创项目描述
CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription" valid:"Required"`
}
func (releaseCooperationProjectCommand *ReleaseCooperationProjectCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (releaseCooperationProjectCommand *ReleaseCooperationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(releaseCooperationProjectCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(releaseCooperationProjectCommand).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 RemoveCooperationProjectCommand struct {
// 共创项目ID
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId,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 (removeCooperationProjectCommand *RemoveCooperationProjectCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCooperationProjectCommand *RemoveCooperationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCooperationProjectCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeCooperationProjectCommand).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 UpdateCooperationProjectCommand struct {
// 共创项目ID
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId,string" valid:"Required"`
// 共创项目名称
CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"`
// 承接对象,1员工,2共创用户,3公开,可以多选
CooperationProjectUndertakerType []int32 `cname:"承接对象,1员工,2共创用户,3公开,可以多选" json:"cooperationProjectUndertakerType" valid:"Required"`
// 共创项目发起人uid
SponsorUid string `cname:"共创项目发起人uid" json:"sponsorUid" valid:"Required"`
// 共创项目发布人uid
PublisherUid string `cname:"共创项目发布人uid" json:"publisherUid" valid:"Required"`
// 共创项目描述
CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription,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 (updateCooperationProjectCommand *UpdateCooperationProjectCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCooperationProjectCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCooperationProjectCommand).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 CheckUndertakerQuery struct {
// 共创项目承接对象,1员工,2共创用户,3公开,可以多选
CooperationProjectUndertakerType []int32 `cname:"共创项目承接对象,1员工,2共创用户,3公开,可以多选" json:"cooperationProjectUndertakerType" valid:"Required"`
// 共创项目ID
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId,string" valid:"Required"`
}
func (checkUndertakerQuery *CheckUndertakerQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (checkUndertakerQuery *CheckUndertakerQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(checkUndertakerQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(checkUndertakerQuery).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 GetCooperationProjectQuery struct {
// 共创项目ID
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId,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 (getCooperationProjectQuery *GetCooperationProjectQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCooperationProjectQuery *GetCooperationProjectQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCooperationProjectQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getCooperationProjectQuery).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 ListCooperationProjectQuery 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 (listCooperationProjectQuery *ListCooperationProjectQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCooperationProjectQuery *ListCooperationProjectQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCooperationProjectQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCooperationProjectQuery).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 SearchCooperationProjectQuery struct {
// 页面大小
PageNumber int32 `cname:"页面大小" json:"pageNumber,omitempty"`
// 页面大小
PageSize int32 `cname:"页面大小" json:"pageSize,omitempty"`
// 共创项目名称
CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName,omitempty"`
// 部门名称
DepartmentName string `cname:"部门名称" json:"departmentName,omitempty"`
// 共创项目状态,根据共创项目状态筛选项目数据
Status int32 `cname:"共创项目状态,根据共创项目状态筛选项目数据" json:"status,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 (searchCooperationProjectQuery *SearchCooperationProjectQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationProjectQuery *SearchCooperationProjectQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchCooperationProjectQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchCooperationProjectQuery).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 (
"fmt"
"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/cooperationProject/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// 共创项目服务
type CooperationProjectService struct {
}
// 判断当前勾选的承接对象是否存在用户
func (cooperationProjectService *CooperationProjectService) CheckUndertaker(checkUndertakerQuery *query.CheckUndertakerQuery) (interface{}, error) {
if err := checkUndertakerQuery.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 (cooperationProjectService *CooperationProjectService) CreateCooperationProject(createCooperationProjectCommand *command.CreateCooperationProjectCommand) (interface{}, error) {
if err := createCooperationProjectCommand.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()
}()
newCooperationProject := &domain.CooperationProject{
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
CooperationProjectUndertakerType: createCooperationProjectCommand.CooperationProjectUndertakerType,
SponsorUid: createCooperationProjectCommand.SponsorUid,
PublisherUid: createCooperationProjectCommand.PublisherUid,
CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
CompanyId: createCooperationProjectCommand.CompanyId,
OrgId: createCooperationProjectCommand.OrgId,
UserId: createCooperationProjectCommand.UserId,
}
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
if cooperationProject, err := cooperationProjectRepository.Save(newCooperationProject); 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 cooperationProject, nil
}
}
// 返回共创项目服务
func (cooperationProjectService *CooperationProjectService) GetCooperationProject(getCooperationProjectQuery *query.GetCooperationProjectQuery) (interface{}, error) {
if err := getCooperationProjectQuery.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 cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": getCooperationProjectQuery.CooperationProjectId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCooperationProjectQuery.CooperationProjectId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationProject, nil
}
}
// 返回共创项目服务列表
func (cooperationProjectService *CooperationProjectService) ListCooperationProject(listCooperationProjectQuery *query.ListCooperationProjectQuery) (interface{}, error) {
if err := listCooperationProjectQuery.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 cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
if count, cooperationProjects, err := cooperationProjectRepository.Find(tool_funs.SimpleStructToMap(listCooperationProjectQuery)); 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,
"cooperationProjects": cooperationProjects,
}, nil
}
}
// 发布共创项目
func (cooperationProjectService *CooperationProjectService) ReleaseCooperationProject(releaseCooperationProjectCommand *command.ReleaseCooperationProjectCommand) (interface{}, error) {
if err := releaseCooperationProjectCommand.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 (cooperationProjectService *CooperationProjectService) RemoveCooperationProject(removeCooperationProjectCommand *command.RemoveCooperationProjectCommand) (interface{}, error) {
if err := removeCooperationProjectCommand.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 cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": removeCooperationProjectCommand.CooperationProjectId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCooperationProjectCommand.CooperationProjectId)))
}
if cooperationProject, err := cooperationProjectRepository.Remove(cooperationProject); 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 cooperationProject, nil
}
}
// 查询共创项目
func (cooperationProjectService *CooperationProjectService) SearchCooperationProject(searchCooperationProjectQuery *query.SearchCooperationProjectQuery) (interface{}, error) {
if err := searchCooperationProjectQuery.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 (cooperationProjectService *CooperationProjectService) UpdateCooperationProject(updateCooperationProjectCommand *command.UpdateCooperationProjectCommand) (interface{}, error) {
if err := updateCooperationProjectCommand.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 cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": updateCooperationProjectCommand.CooperationProjectId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId)))
}
if err := cooperationProject.Update(tool_funs.SimpleStructToMap(updateCooperationProjectCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); 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 cooperationProject, nil
}
}
func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService {
newCooperationProjectService := &CooperationProjectService{}
return newCooperationProjectService
}
... ...
... ... @@ -69,3 +69,11 @@ func CreateMoneyIncentivesRuleRepository(options map[string]interface{}) (domain
}
return repository.NewMoneyIncentivesRuleRepository(transactionContext)
}
func CreateCooperationContractChangeLogRepository(options map[string]interface{}) (domain.CooperationContractChangeLogRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewCooperationContractChangeLogRepository(transactionContext)
}
... ...
... ... @@ -52,78 +52,6 @@ func (contractUndertakerFeedback *ContractUndertakerFeedback) Update(data map[st
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
contractUndertakerFeedback.CooperationContractNumber = cooperationContractNumber.(string)
}
if userId, ok := data["userId"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
contractUndertakerFeedback.ContractUndertaker.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
contractUndertakerFeedback.ContractUndertaker.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
contractUndertakerFeedback.ContractUndertaker.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
contractUndertakerFeedback.ContractUndertaker.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
contractUndertakerFeedback.ContractUndertaker.Org.Company.CompanyName = companyName.(string)
}
if orgs, ok := data["orgs"]; ok {
contractUndertakerFeedback.ContractUndertaker.Orgs = orgs.([]*Org)
}
if departmentId, ok := data["departmentId"]; ok {
contractUndertakerFeedback.ContractUndertaker.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
contractUndertakerFeedback.ContractUndertaker.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
contractUndertakerFeedback.ContractUndertaker.Department.DepartmentNumber = departmentNumber.(string)
}
if isOrganization, ok := data["isOrganization"]; ok {
contractUndertakerFeedback.ContractUndertaker.Department.IsOrganization = isOrganization.(bool)
}
if roleId, ok := data["roleId"]; ok {
contractUndertakerFeedback.ContractUndertaker.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
contractUndertakerFeedback.ContractUndertaker.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
contractUndertakerFeedback.ContractUndertaker.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
contractUndertakerFeedback.ContractUndertaker.Status = status.(int32)
}
if cooperationModeId, ok := data["cooperationModeId"]; ok {
contractUndertakerFeedback.CooperationMode.CooperationModeId = cooperationModeId.(int64)
}
if cooperationModeNumber, ok := data["cooperationModeNumber"]; ok {
contractUndertakerFeedback.CooperationMode.CooperationModeNumber = cooperationModeNumber.(string)
}
if cooperationModeName, ok := data["cooperationModeName"]; ok {
contractUndertakerFeedback.CooperationMode.CooperationModeName = cooperationModeName.(string)
}
if status, ok := data["status"]; ok {
contractUndertakerFeedback.CooperationMode.Status = status.(int32)
}
... ...
... ... @@ -57,60 +57,9 @@ func (cooperationApplication *CooperationApplication) Update(data map[string]int
if userBaseId, ok := data["userBaseId"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
cooperationApplication.CooperationApplicationApplicant.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationApplication.CooperationApplicationApplicant.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationApplication.CooperationApplicationApplicant.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationApplication.CooperationApplicationApplicant.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationApplication.CooperationApplicationApplicant.Org.Company.CompanyName = companyName.(string)
}
if orgs, ok := data["orgs"]; ok {
cooperationApplication.CooperationApplicationApplicant.Orgs = orgs.([]*Org)
}
if departmentId, ok := data["departmentId"]; ok {
cooperationApplication.CooperationApplicationApplicant.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
cooperationApplication.CooperationApplicationApplicant.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
cooperationApplication.CooperationApplicationApplicant.Department.DepartmentNumber = departmentNumber.(string)
}
if isOrganization, ok := data["isOrganization"]; ok {
cooperationApplication.CooperationApplicationApplicant.Department.IsOrganization = isOrganization.(bool)
}
if roleId, ok := data["roleId"]; ok {
cooperationApplication.CooperationApplicationApplicant.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
cooperationApplication.CooperationApplicationApplicant.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
cooperationApplication.CooperationApplicationApplicant.Status = status.(int32)
}
... ...
... ... @@ -55,9 +55,6 @@ func (cooperationContract *CooperationContract) Identify() interface{} {
}
func (cooperationContract *CooperationContract) Update(data map[string]interface{}) error {
if cooperationContractId, ok := data["cooperationContractId"]; ok {
cooperationContract.CooperationContractId = cooperationContractId.(int64)
}
if cooperationContractDescription, ok := data["cooperationContractDescription"]; ok {
cooperationContract.CooperationContractDescription = cooperationContractDescription.(string)
}
... ... @@ -73,107 +70,20 @@ func (cooperationContract *CooperationContract) Update(data map[string]interface
if userBaseId, ok := data["userBaseId"]; ok {
cooperationContract.CooperationContractReferrer.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
cooperationContract.CooperationContractReferrer.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationContract.CooperationContractReferrer.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationContract.CooperationContractReferrer.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationContract.CooperationContractReferrer.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationContract.CooperationContractReferrer.Org.Company.CompanyName = companyName.(string)
}
if orgs, ok := data["orgs"]; ok {
cooperationContract.CooperationContractReferrer.Orgs = orgs.([]*Org)
}
if departmentId, ok := data["departmentId"]; ok {
cooperationContract.CooperationContractReferrer.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
cooperationContract.CooperationContractReferrer.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
cooperationContract.CooperationContractReferrer.Department.DepartmentNumber = departmentNumber.(string)
}
if isOrganization, ok := data["isOrganization"]; ok {
cooperationContract.CooperationContractReferrer.Department.IsOrganization = isOrganization.(bool)
}
if roleId, ok := data["roleId"]; ok {
cooperationContract.CooperationContractReferrer.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
cooperationContract.CooperationContractReferrer.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationContract.CooperationContractReferrer.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
cooperationContract.CooperationContractReferrer.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
cooperationContract.CooperationContractReferrer.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
cooperationContract.CooperationContractReferrer.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
cooperationContract.CooperationContractReferrer.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
cooperationContract.CooperationContractReferrer.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
cooperationContract.CooperationContractReferrer.Status = status.(int32)
}
if cooperationContractUndertakerType, ok := data["cooperationContractUndertakerType"]; ok {
cooperationContract.CooperationContractUndertakerType = cooperationContractUndertakerType.([]int32)
}
if cooperationModeId, ok := data["cooperationModeId"]; ok {
cooperationContract.CooperationMode.CooperationModeId = cooperationModeId.(int64)
}
if cooperationModeNumber, ok := data["cooperationModeNumber"]; ok {
cooperationContract.CooperationMode.CooperationModeNumber = cooperationModeNumber.(string)
}
if cooperationModeName, ok := data["cooperationModeName"]; ok {
cooperationContract.CooperationMode.CooperationModeName = cooperationModeName.(string)
}
if status, ok := data["status"]; ok {
cooperationContract.CooperationMode.Status = status.(int32)
}
if remarks, ok := data["remarks"]; ok {
cooperationContract.CooperationMode.Remarks = remarks.(string)
}
if operateTime, ok := data["operateTime"]; ok {
cooperationContract.CooperationMode.OperateTime = operateTime.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
cooperationContract.CooperationMode.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
cooperationContract.CooperationMode.DeletedAt = deletedAt.(time.Time)
}
if createdAt, ok := data["createdAt"]; ok {
cooperationContract.CooperationMode.CreatedAt = createdAt.(time.Time)
}
if status, ok := data["status"]; ok {
cooperationContract.Status = status.(int32)
}
if operateTime, ok := data["operateTime"]; ok {
cooperationContract.OperateTime = operateTime.(time.Time)
}
if createdAt, ok := data["createdAt"]; ok {
cooperationContract.CreatedAt = createdAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
cooperationContract.DeletedAt = deletedAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
cooperationContract.UpdatedAt = updatedAt.(time.Time)
}
return nil
}
... ...
package domain
import "time"
// 共创合约变更日志
type CooperationContractChangeLog struct {
// 共创合约变更日志
CooperationContractChangeLogId int64 `json:"cooperationContractChangeLogId,string"`
// 激励规则
IncentivesRule string `json:"incentivesRule"`
// 激励规则明细
IncentivesRuleDetail string `json:"incentivesRuleDetail"`
// 合约变更操作类型,1编辑、2暂停、3恢复
OperationType int32 `json:"operationType"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 承接人
Undertakers string `json:"undertakers"`
// 公司
Company *Company `json:"company"`
// 操作人
Operator *User `json:"operator"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
}
type CooperationContractChangeLogRepository interface {
Save(cooperationContractChangeLog *CooperationContractChangeLog) (*CooperationContractChangeLog, error)
Remove(cooperationContractChangeLog *CooperationContractChangeLog) (*CooperationContractChangeLog, error)
FindOne(queryOptions map[string]interface{}) (*CooperationContractChangeLog, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationContractChangeLog, error)
}
func (cooperationContractChangeLog *CooperationContractChangeLog) Identify() interface{} {
if cooperationContractChangeLog.CooperationContractChangeLogId == 0 {
return nil
}
return cooperationContractChangeLog.CooperationContractChangeLogId
}
func (cooperationContractChangeLog *CooperationContractChangeLog) Update(data map[string]interface{}) error {
if incentivesRule, ok := data["incentivesRule"]; ok {
cooperationContractChangeLog.IncentivesRule = incentivesRule.(string)
}
if incentivesRuleDetail, ok := data["incentivesRuleDetail"]; ok {
cooperationContractChangeLog.IncentivesRuleDetail = incentivesRuleDetail.(string)
}
if operationType, ok := data["operationType"]; ok {
cooperationContractChangeLog.OperationType = operationType.(int32)
}
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
cooperationContractChangeLog.CooperationContractNumber = cooperationContractNumber.(string)
}
if undertakers, ok := data["undertakers"]; ok {
cooperationContractChangeLog.Undertakers = undertakers.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationContractChangeLog.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationContractChangeLog.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationContractChangeLog.Company.CompanyName = companyName.(string)
}
if userId, ok := data["userId"]; ok {
cooperationContractChangeLog.Operator.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
cooperationContractChangeLog.Operator.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
cooperationContractChangeLog.Operator.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationContractChangeLog.Operator.Org.OrgName = orgName.(string)
}
if departmentId, ok := data["departmentId"]; ok {
cooperationContractChangeLog.Operator.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
cooperationContractChangeLog.Operator.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
cooperationContractChangeLog.Operator.Department.DepartmentNumber = departmentNumber.(string)
}
if roleId, ok := data["roleId"]; ok {
cooperationContractChangeLog.Operator.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
cooperationContractChangeLog.Operator.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
cooperationContractChangeLog.Operator.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
cooperationContractChangeLog.Operator.Status = status.(int32)
}
return nil
}
... ...
... ... @@ -45,9 +45,6 @@ func (cooperationMode *CooperationMode) Identify() interface{} {
}
func (cooperationMode *CooperationMode) Update(data map[string]interface{}) error {
if cooperationModeId, ok := data["cooperationModeId"]; ok {
cooperationMode.CooperationModeId = cooperationModeId.(int64)
}
if cooperationModeNumber, ok := data["cooperationModeNumber"]; ok {
cooperationMode.CooperationModeNumber = cooperationModeNumber.(string)
}
... ...
... ... @@ -8,7 +8,7 @@ import (
type ContractUndertakerFeedback struct {
tableName string `comment:"承接人反馈信息" pg:"contract_undertaker_feedbacks,alias:contract_undertaker_feedback"`
// 合约承接方反馈记录ID
FeedbackId int64 `comment:"合约承接方反馈记录ID" pg:",pk"`
FeedbackId int64 `comment:"合约承接方反馈记录ID" pg:",pk:feedback_id"`
// 合约承接方反馈内容附件
FeedbackAttachment []*domain.Attachment `comment:"合约承接方反馈内容附件"`
// 合约承接方反馈内容
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type CooperationContractChangeLog struct {
tableName string `comment:"共创合约变更日志" pg:"cooperation_contract_change_logs,alias:cooperation_contract_change_log"`
// 共创合约变更记录id
CooperationContractChangeLogId int64 `comment:"共创合约变更记录id" pg:",pk:cooperation_contract_change_log_id"`
// 激励规则
IncentivesRule string `comment:"激励规则"`
// 激励规则明细
IncentivesRuleDetail string `comment:"激励规则明细"`
// 合约变更操作类型,1编辑、2暂停、3恢复
OperationType int32 `comment:"合约变更操作类型,1编辑、2暂停、3恢复"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 承接人
Undertakers string `comment:"承接人"`
// 公司
Company *domain.Company `comment:"公司"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationContractChangeLogModel *models.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
return &domain.CooperationContractChangeLog{
IncentivesRule: cooperationContractChangeLogModel.IncentivesRule,
IncentivesRuleDetail: cooperationContractChangeLogModel.IncentivesRuleDetail,
OperationType: cooperationContractChangeLogModel.OperationType,
CooperationContractNumber: cooperationContractChangeLogModel.CooperationContractNumber,
Undertakers: cooperationContractChangeLogModel.Undertakers,
Company: cooperationContractChangeLogModel.Company,
Operator: cooperationContractChangeLogModel.Operator,
UpdatedAt: cooperationContractChangeLogModel.UpdatedAt,
DeletedAt: cooperationContractChangeLogModel.DeletedAt,
CreatedAt: cooperationContractChangeLogModel.CreatedAt,
}, nil
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type CooperationContractChangeLogRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *CooperationContractChangeLogRepository) Save(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
sqlBuildFields := []string{
"incentives_rule",
"incentives_rule_detail",
"operation_type",
"cooperation_contract_number",
"undertakers",
"company",
"operator",
"updated_at",
"deleted_at",
"created_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContractChangeLog_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if cooperationContractChangeLog.Identify() == nil {
cooperationContractChangeLogId, err := repository.nextIdentify()
if err != nil {
return cooperationContractChangeLog, err
} else {
cooperationContractChangeLog.CooperationContractChangeLogId = cooperationContractChangeLogId
}
if _, err := tx.QueryOne(
pg.Scan(
&cooperationContractChangeLog.IncentivesRule,
&cooperationContractChangeLog.IncentivesRuleDetail,
&cooperationContractChangeLog.OperationType,
&cooperationContractChangeLog.CooperationContractNumber,
&cooperationContractChangeLog.Undertakers,
&cooperationContractChangeLog.Company,
&cooperationContractChangeLog.Operator,
&cooperationContractChangeLog.UpdatedAt,
&cooperationContractChangeLog.DeletedAt,
&cooperationContractChangeLog.CreatedAt,
),
fmt.Sprintf("INSERT INTO cooperation_contract_change_logs (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationContractChangeLog.IncentivesRule,
cooperationContractChangeLog.IncentivesRuleDetail,
cooperationContractChangeLog.OperationType,
cooperationContractChangeLog.CooperationContractNumber,
cooperationContractChangeLog.Undertakers,
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.UpdatedAt,
cooperationContractChangeLog.DeletedAt,
cooperationContractChangeLog.CreatedAt,
); err != nil {
return cooperationContractChangeLog, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&cooperationContractChangeLog.IncentivesRule,
&cooperationContractChangeLog.IncentivesRuleDetail,
&cooperationContractChangeLog.OperationType,
&cooperationContractChangeLog.CooperationContractNumber,
&cooperationContractChangeLog.Undertakers,
&cooperationContractChangeLog.Company,
&cooperationContractChangeLog.Operator,
&cooperationContractChangeLog.UpdatedAt,
&cooperationContractChangeLog.DeletedAt,
&cooperationContractChangeLog.CreatedAt,
),
fmt.Sprintf("UPDATE cooperation_contract_change_logs SET %s WHERE cooperation_contract_change_log_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationContractChangeLog.IncentivesRule,
cooperationContractChangeLog.IncentivesRuleDetail,
cooperationContractChangeLog.OperationType,
cooperationContractChangeLog.CooperationContractNumber,
cooperationContractChangeLog.Undertakers,
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.UpdatedAt,
cooperationContractChangeLog.DeletedAt,
cooperationContractChangeLog.CreatedAt,
cooperationContractChangeLog.Identify(),
); err != nil {
return cooperationContractChangeLog, err
}
}
return cooperationContractChangeLog, nil
}
func (repository *CooperationContractChangeLogRepository) Remove(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
tx := repository.transactionContext.PgTx
cooperationContractChangeLogModel := new(models.CooperationContractChangeLog)
cooperationContractChangeLogModel.CooperationContractChangeLogId = cooperationContractChangeLog.Identify().(int64)
if _, err := tx.Model(cooperationContractChangeLogModel).WherePK().Delete(); err != nil {
return cooperationContractChangeLog, err
}
return cooperationContractChangeLog, nil
}
func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractChangeLog, error) {
tx := repository.transactionContext.PgTx
cooperationContractChangeLogModel := new(models.CooperationContractChangeLog)
query := sqlbuilder.BuildQuery(tx.Model(cooperationContractChangeLogModel), queryOptions)
query.SetWhereByQueryOption("cooperation_contract_change_log.cooperation_contract_change_log_id = ?", "cooperationContractChangeLogId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if cooperationContractChangeLogModel.CooperationContractChangeLogId == 0 {
return nil, nil
} else {
return transform.TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationContractChangeLogModel)
}
}
func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractChangeLog, error) {
tx := repository.transactionContext.PgTx
var cooperationContractChangeLogModels []*models.CooperationContractChangeLog
cooperationContractChangeLogs := make([]*domain.CooperationContractChangeLog, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractChangeLogModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("cooperation_contract_change_log_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractChangeLogs, err
} else {
for _, cooperationContractChangeLogModel := range cooperationContractChangeLogModels {
if cooperationContractChangeLog, err := transform.TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationContractChangeLogModel); err != nil {
return 0, cooperationContractChangeLogs, err
} else {
cooperationContractChangeLogs = append(cooperationContractChangeLogs, cooperationContractChangeLog)
}
}
return int64(count), cooperationContractChangeLogs, nil
}
}
func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractChangeLogRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationContractChangeLogRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/service"
)
type CooperationContractController struct {
beego.BaseController
}
func (controller *CooperationContractController) CreateCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
createCooperationContractCommand := &command.CreateCooperationContractCommand{}
controller.Unmarshal(createCooperationContractCommand)
data, err := cooperationContractService.CreateCooperationContract(createCooperationContractCommand)
controller.Response(data, err)
}
func (controller *CooperationContractController) UpdateCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
updateCooperationContractCommand := &command.UpdateCooperationContractCommand{}
controller.Unmarshal(updateCooperationContractCommand)
cooperationContractId := controller.GetString(":cooperationContractId")
updateCooperationContractCommand.CooperationContractId = cooperationContractId
data, err := cooperationContractService.UpdateCooperationContract(updateCooperationContractCommand)
controller.Response(data, err)
}
func (controller *CooperationContractController) GetCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
getCooperationContractQuery := &query.GetCooperationContractQuery{}
cooperationContractId, _ := controller.GetInt64(":cooperationContractId")
getCooperationContractQuery.CooperationContractId = cooperationContractId
data, err := cooperationContractService.GetCooperationContract(getCooperationContractQuery)
controller.Response(data, err)
}
func (controller *CooperationContractController) RemoveCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
removeCooperationContractCommand := &command.RemoveCooperationContractCommand{}
controller.Unmarshal(removeCooperationContractCommand)
cooperationContractId, _ := controller.GetInt64(":cooperationContractId")
removeCooperationContractCommand.CooperationContractId = cooperationContractId
data, err := cooperationContractService.RemoveCooperationContract(removeCooperationContractCommand)
controller.Response(data, err)
}
func (controller *CooperationContractController) SearchCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
searchCooperationContractQuery := &query.SearchCooperationContractQuery{}
data, err := cooperationContractService.SearchCooperationContract(searchCooperationContractQuery)
controller.Response(data, err)
}
func (controller *CooperationContractController) SearchCooperationContractByUndertaker() {
cooperationContractService := service.NewCooperationContractService(nil)
searchCooperationContractByUndertakerQuery := &query.SearchCooperationContractByUndertakerQuery{}
data, err := cooperationContractService.SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery)
controller.Response(data, err)
}
func (controller *CooperationContractController) ListCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
listCooperationContractQuery := &query.ListCooperationContractQuery{}
offset, _ := controller.GetInt("offset")
listCooperationContractQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listCooperationContractQuery.Limit = limit
data, err := cooperationContractService.ListCooperationContract(listCooperationContractQuery)
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-contracts/", &controllers.CooperationContractController{}, "Post:CreateCooperationContract")
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Put:UpdateCooperationContract")
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Get:GetCooperationContract")
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Delete:RemoveCooperationContract")
web.Router("/cooperation-contracts/search", &controllers.CooperationContractController{}, "Post:SearchCooperationContract")
web.Router("/cooperation-contracts/search-by-undertaker", &controllers.CooperationContractController{}, "Post:SearchCooperationContractByUndertaker")
web.Router("/cooperation-contracts/", &controllers.CooperationContractController{}, "Get:ListCooperationContract")
}
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_application
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
... ...
package cooperation_contract
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 TestCooperationContract(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port CooperationContract 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_contract
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{}{
"cooperationContractDescription": "string",
"cooperationContractNumber": "string",
"cooperationProjectNumber": "string",
"departmentNumber": "string",
"cooperationContractUndertakerType": "array",
"cooperationContractName": "string",
"cooperationModeNumber": "string",
"sponsorUid": "string",
"dividendsIncentivesRules": "array",
"moneyIncentivesRules": "array",
"undertakers": "array",
"relevants": "array",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-contracts/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("cooperationContractId").ValueNotEqual("cooperationContractId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_contract
import (
"github.com/go-pg/pg/v10"
"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 cooperationContractId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationContractId),
"INSERT INTO cooperation_contracts (cooperation_contract_id, cooperation_contract_description, cooperation_contract_name, cooperation_contract_number, cooperation_contract_referrer, cooperation_contract_salesman, cooperation_contract_undertaker_type, cooperation_contract_sponsor, cooperation_mode, status, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_contract_id",
"testCooperationContractId", "testCooperationContractDescription", "testCooperationContractName", "testCooperationContractNumber", "testCooperationContractReferrer", "testCooperationContractSalesman", "testCooperationContractUndertakerType", "testCooperationContractSponsor", "testCooperationMode", "testStatus", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据cooperationContractId参数返回共创项目合约实体", func() {
Context("传入有效的cooperationContractId", func() {
It("返回共创项目合约实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cooperation-contracts/{cooperationContractId}").
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_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_contract
import (
"github.com/go-pg/pg/v10"
"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 cooperationContractId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationContractId),
"INSERT INTO cooperation_contracts (cooperation_contract_id, cooperation_contract_description, cooperation_contract_name, cooperation_contract_number, cooperation_contract_referrer, cooperation_contract_salesman, cooperation_contract_undertaker_type, cooperation_contract_sponsor, cooperation_mode, status, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_contract_id",
"testCooperationContractId", "testCooperationContractDescription", "testCooperationContractName", "testCooperationContractNumber", "testCooperationContractReferrer", "testCooperationContractSalesman", "testCooperationContractUndertakerType", "testCooperationContractSponsor", "testCooperationMode", "testStatus", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回共创项目合约实体列表", func() {
Context("传入有效的参数", func() {
It("返回共创项目合约实体数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cooperation-contracts/").
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("cooperationContracts").Value("cooperationContracts").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_contract
import (
"github.com/go-pg/pg/v10"
"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 cooperationContractId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationContractId),
"INSERT INTO cooperation_contracts (cooperation_contract_id, cooperation_contract_description, cooperation_contract_name, cooperation_contract_number, cooperation_contract_referrer, cooperation_contract_salesman, cooperation_contract_undertaker_type, cooperation_contract_sponsor, cooperation_mode, status, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_contract_id",
"testCooperationContractId", "testCooperationContractDescription", "testCooperationContractName", "testCooperationContractNumber", "testCooperationContractReferrer", "testCooperationContractSalesman", "testCooperationContractUndertakerType", "testCooperationContractSponsor", "testCooperationMode", "testStatus", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除共创合约服务", func() {
Context("传入有效的cooperationContractId", func() {
It("返回被移除共创项目合约实体的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/cooperation-contracts/{cooperationContractId}").
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_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_contract
import (
"github.com/go-pg/pg/v10"
"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 cooperationContractId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationContractId),
"INSERT INTO cooperation_contracts (cooperation_contract_id, cooperation_contract_description, cooperation_contract_name, cooperation_contract_number, cooperation_contract_referrer, cooperation_contract_salesman, cooperation_contract_undertaker_type, cooperation_contract_sponsor, cooperation_mode, status, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_contract_id",
"testCooperationContractId", "testCooperationContractDescription", "testCooperationContractName", "testCooperationContractNumber", "testCooperationContractReferrer", "testCooperationContractSalesman", "testCooperationContractUndertakerType", "testCooperationContractSponsor", "testCooperationMode", "testStatus", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据承接人返回共创项目合约", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationContractName": "string",
"sponsorName": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-contracts/search-by-undertaker").
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_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_contract
import (
"github.com/go-pg/pg/v10"
"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 cooperationContractId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationContractId),
"INSERT INTO cooperation_contracts (cooperation_contract_id, cooperation_contract_description, cooperation_contract_name, cooperation_contract_number, cooperation_contract_referrer, cooperation_contract_salesman, cooperation_contract_undertaker_type, cooperation_contract_sponsor, cooperation_mode, status, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_contract_id",
"testCooperationContractId", "testCooperationContractDescription", "testCooperationContractName", "testCooperationContractNumber", "testCooperationContractReferrer", "testCooperationContractSalesman", "testCooperationContractUndertakerType", "testCooperationContractSponsor", "testCooperationMode", "testStatus", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("查询共创合约", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"pageSize": "int32",
"pageNumber": "int32",
"cooperationContractNumber": "string",
"sponsorName": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-contracts/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_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_contract
import (
"github.com/go-pg/pg/v10"
"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 cooperationContractId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationContractId),
"INSERT INTO cooperation_contracts (cooperation_contract_id, cooperation_contract_description, cooperation_contract_name, cooperation_contract_number, cooperation_contract_referrer, cooperation_contract_salesman, cooperation_contract_undertaker_type, cooperation_contract_sponsor, cooperation_mode, status, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_contract_id",
"testCooperationContractId", "testCooperationContractDescription", "testCooperationContractName", "testCooperationContractNumber", "testCooperationContractReferrer", "testCooperationContractSalesman", "testCooperationContractUndertakerType", "testCooperationContractSponsor", "testCooperationMode", "testStatus", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新共创合约服务", func() {
Context("提交正确的共创项目合约实体数据", func() {
It("返回更新后的共创项目合约实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationContractDescription": "string",
"cooperationContractNumber": "string",
"cooperationProjectNumber": "string",
"departmentNumber": "string",
"cooperationContractUndertakerType": "array",
"cooperationContractName": "string",
"cooperationModeNumber": "string",
"sponsorUid": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.PUT("/cooperation-contracts/{cooperationContractId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("cooperationContractId").ValueEqual("cooperationContractId", cooperationContractId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_contracts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...