作者 陈志颖

feat:添加账期结算功能

正在显示 29 个修改的文件 包含 1457 行增加14 行删除
... ... @@ -29,22 +29,31 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
defer func() {
transactionContext.RollbackTransaction()
}()
userServiceGateway, err := factory.CreateUserServiceGateway(nil)
if err != nil {
fmt.Println(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//userServiceGateway.GetUser(createCooperationContractCommand.SponsorUid)
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber,
DepartmentNumber: createCooperationContractCommand.DepartmentNumber,
//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,
//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{}{
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateCreditAccountCommand struct {
// 公司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 (createCreditAccountCommand *CreateCreditAccountCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCreditAccountCommand *CreateCreditAccountCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCreditAccountCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCreditAccountCommand).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 PayCreditAccountCommand struct {
// 账期结算实付金额
ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" 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 (payCreditAccountCommand *PayCreditAccountCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (payCreditAccountCommand *PayCreditAccountCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(payCreditAccountCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(payCreditAccountCommand).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 RemoveCreditAccountCommand struct {
// 账期结算单ID
CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId,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 (removeCreditAccountCommand *RemoveCreditAccountCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCreditAccountCommand *RemoveCreditAccountCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCreditAccountCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeCreditAccountCommand).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 UpdateCreditAccountCommand struct {
// 账期结算单ID
CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId,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 (updateCreditAccountCommand *UpdateCreditAccountCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCreditAccountCommand *UpdateCreditAccountCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCreditAccountCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCreditAccountCommand).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 CreditAccountRankingQuery struct {
// 公司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"`
// 统计周期
Period string `cname:"统计周期" json:"period,omitempty"`
}
func (creditAccountRankingQuery *CreditAccountRankingQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (creditAccountRankingQuery *CreditAccountRankingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(creditAccountRankingQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(creditAccountRankingQuery).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 GetCreditAccountQuery struct {
// 账期结算单ID
CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId,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 (getCreditAccountQuery *GetCreditAccountQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCreditAccountQuery *GetCreditAccountQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCreditAccountQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getCreditAccountQuery).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 ListCreditAccountQuery 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 (listCreditAccountQuery *ListCreditAccountQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCreditAccountQuery *ListCreditAccountQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCreditAccountQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCreditAccountQuery).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"
"time"
"github.com/beego/beego/v2/core/validation"
)
type SearchCreditAccountQuery struct {
// 账期结算单号
CreditAccountOrderNum string `cname:"账期结算单号" json:"creditAccountOrderNum" valid:"Required"`
// 参与人姓名
ParticipatorName string `cname:"参与人姓名" json:"participatorName,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"`
// 账期结算支付状态,1待支付,2已支付,APP端结算记录返回已结算的账期结算单
PaymentStatus int32 `cname:"账期结算支付状态,1待支付,2已支付,APP端结算记录返回已结算的账期结算单" json:"paymentStatus" valid:"Required"`
// 结算周期,按年“2021”或者按月结算”2021-07“
Period time.Time `cname:"结算周期,按年“2021”或者按月结算”2021-07“" json:"period,omitempty"`
}
func (searchCreditAccountQuery *SearchCreditAccountQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCreditAccountQuery *SearchCreditAccountQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchCreditAccountQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchCreditAccountQuery).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/creditAccount/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// 账期结算单服务
type CreditAccountService struct {
}
// 创建账期结算单服务
func (creditAccountService *CreditAccountService) CreateCreditAccount(createCreditAccountCommand *command.CreateCreditAccountCommand) (interface{}, error) {
if err := createCreditAccountCommand.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()
}()
newCreditAccount := &domain.CreditAccount{
//CompanyId: createCreditAccountCommand.CompanyId,
//OrgId: createCreditAccountCommand.OrgId,
//UserId: createCreditAccountCommand.UserId,
}
var creditAccountRepository domain.CreditAccountRepository
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
creditAccountRepository = value
}
if creditAccount, err := creditAccountRepository.Save(newCreditAccount); 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 creditAccount, nil
}
}
// 账期结算单排名
func (creditAccountService *CreditAccountService) CreditAccountRanking(creditAccountRankingQuery *query.CreditAccountRankingQuery) (interface{}, error) {
if err := creditAccountRankingQuery.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 (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAccountQuery *query.GetCreditAccountQuery) (interface{}, error) {
if err := getCreditAccountQuery.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 creditAccountRepository domain.CreditAccountRepository
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
creditAccountRepository = value
}
creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": getCreditAccountQuery.CreditAccountId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if creditAccount == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCreditAccountQuery.CreditAccountId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return creditAccount, nil
}
}
// 返回账期结算单服务列表
func (creditAccountService *CreditAccountService) ListCreditAccount(listCreditAccountQuery *query.ListCreditAccountQuery) (interface{}, error) {
if err := listCreditAccountQuery.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 creditAccountRepository domain.CreditAccountRepository
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
creditAccountRepository = value
}
if count, creditAccounts, err := creditAccountRepository.Find(tool_funs.SimpleStructToMap(listCreditAccountQuery)); 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,
"creditAccounts": creditAccounts,
}, nil
}
}
// 支付账期结算(支付分红)
func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAccountCommand *command.PayCreditAccountCommand) (interface{}, error) {
if err := payCreditAccountCommand.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 (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCreditAccountCommand *command.RemoveCreditAccountCommand) (interface{}, error) {
if err := removeCreditAccountCommand.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 creditAccountRepository domain.CreditAccountRepository
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
creditAccountRepository = value
}
creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": removeCreditAccountCommand.CreditAccountId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if creditAccount == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCreditAccountCommand.CreditAccountId)))
}
if creditAccount, err := creditAccountRepository.Remove(creditAccount); 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 creditAccount, nil
}
}
// 查询账期结算单
func (creditAccountService *CreditAccountService) SearchCreditAccount(searchCreditAccountQuery *query.SearchCreditAccountQuery) (interface{}, error) {
if err := searchCreditAccountQuery.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 (creditAccountService *CreditAccountService) UpdateCreditAccount(updateCreditAccountCommand *command.UpdateCreditAccountCommand) (interface{}, error) {
if err := updateCreditAccountCommand.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 creditAccountRepository domain.CreditAccountRepository
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
creditAccountRepository = value
}
creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": updateCreditAccountCommand.CreditAccountId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if creditAccount == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCreditAccountCommand.CreditAccountId)))
}
if err := creditAccount.Update(tool_funs.SimpleStructToMap(updateCreditAccountCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if creditAccount, err := creditAccountRepository.Save(creditAccount); 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 creditAccount, nil
}
}
func NewCreditAccountService(options map[string]interface{}) *CreditAccountService {
newCreditAccountService := &CreditAccountService{}
return newCreditAccountService
}
... ...
... ... @@ -77,3 +77,11 @@ func CreateCooperationContractChangeLogRepository(options map[string]interface{}
}
return repository.NewCooperationContractChangeLogRepository(transactionContext)
}
func CreateCreditAccountRepository(options map[string]interface{}) (domain.CreditAccountRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewCreditAccountRepository(transactionContext)
}
... ...
package factory
import serviceGateway "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
func CreateUserServiceGateway(options map[string]interface{}) (serviceGateway.UserServiceGateway, error) {
return serviceGateway.NewHttplibUserServiceGateway(), nil
}
... ...
package domain
import "time"
// 账期结算单实体
type CreditAccount struct {
// 账期结算单ID
CreditAccountId int64 `json:"creditAccountId,string"`
// 账期结算实付金额
ActuallyPaidAmount float64 `json:"actuallyPaidAmount"`
// 账期结算单号
CreditAccountOrderNum string `json:"creditAccountOrderNum"`
// 账期结算支付状态,1待支付,2已支付
PaymentStatus int32 `json:"paymentStatus"`
// 共创账期结算支付时间
PaymentTime time.Time `json:"paymentTime"`
// 账期结算金额
SettlementAmount float64 `json:"settlementAmount"`
// 共创账期结算时间
SettlementTime time.Time `json:"settlementTime"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 参与人uid,包括承接人、推荐人、关联业务员
Participator []int64 `json:"participator"`
// 支付凭证附件
PaymentDocumentAttachment *Attachment `json:"paymentDocumentAttachment"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
Company *Company `json:"company"`
// 操作人
Operator *User `json:"operator"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
}
type CreditAccountRepository interface {
Save(creditAccount *CreditAccount) (*CreditAccount, error)
Remove(creditAccount *CreditAccount) (*CreditAccount, error)
FindOne(queryOptions map[string]interface{}) (*CreditAccount, error)
Find(queryOptions map[string]interface{}) (int64, []*CreditAccount, error)
}
func (creditAccount *CreditAccount) Identify() interface{} {
if creditAccount.CreditAccountId == 0 {
return nil
}
return creditAccount.CreditAccountId
}
func (creditAccount *CreditAccount) Update(data map[string]interface{}) error {
if actuallyPaidAmount, ok := data["actuallyPaidAmount"]; ok {
creditAccount.ActuallyPaidAmount = actuallyPaidAmount.(float64)
}
if creditAccountOrderNum, ok := data["creditAccountOrderNum"]; ok {
creditAccount.CreditAccountOrderNum = creditAccountOrderNum.(string)
}
if paymentStatus, ok := data["paymentStatus"]; ok {
creditAccount.PaymentStatus = paymentStatus.(int32)
}
return nil
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type CreditAccount struct {
tableName string `comment:"账期结算单实体" pg:"credit_accounts,alias:credit_account"`
// 账期结算单ID
CreditAccountId int64 `comment:"账期结算单ID" pg:"pk:credit_account_id"`
// 账期结算实付金额
ActuallyPaidAmount float64 `comment:"账期结算实付金额"`
// 账期结算单号
CreditAccountOrderNum string `comment:"账期结算单号"`
// 账期结算支付状态,1待支付,2已支付
PaymentStatus int32 `comment:"账期结算支付状态,1待支付,2已支付"`
// 共创账期结算支付时间
PaymentTime time.Time `comment:"共创账期结算支付时间"`
// 账期结算金额
SettlementAmount float64 `comment:"账期结算金额"`
// 共创账期结算时间
SettlementTime time.Time `comment:"共创账期结算时间"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 参与人uid,包括承接人、推荐人、关联业务员
Participator []int64 `comment:"参与人uid,包括承接人、推荐人、关联业务员" pg:",array"`
// 支付凭证附件
PaymentDocumentAttachment *domain.Attachment `comment:"支付凭证附件"`
// 数据所属组织机构
Org *domain.Org `comment:"数据所属组织机构"`
// 公司
Company *domain.Company `comment:"公司"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 操作时间
OperateTime time.Time `comment:"操作时间"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 更新时间
UpdatedAt 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 TransformToCreditAccountDomainModelFromPgModels(creditAccountModel *models.CreditAccount) (*domain.CreditAccount, error) {
return &domain.CreditAccount{
CreditAccountId: creditAccountModel.CreditAccountId,
ActuallyPaidAmount: creditAccountModel.ActuallyPaidAmount,
CreditAccountOrderNum: creditAccountModel.CreditAccountOrderNum,
PaymentStatus: creditAccountModel.PaymentStatus,
PaymentTime: creditAccountModel.PaymentTime,
SettlementAmount: creditAccountModel.SettlementAmount,
SettlementTime: creditAccountModel.SettlementTime,
CooperationContractNumber: creditAccountModel.CooperationContractNumber,
Participator: creditAccountModel.Participator,
PaymentDocumentAttachment: creditAccountModel.PaymentDocumentAttachment,
Org: creditAccountModel.Org,
Company: creditAccountModel.Company,
Operator: creditAccountModel.Operator,
OperateTime: creditAccountModel.OperateTime,
CreatedAt: creditAccountModel.CreatedAt,
DeletedAt: creditAccountModel.DeletedAt,
UpdatedAt: creditAccountModel.UpdatedAt,
}, nil
}
... ...
... ... @@ -2,6 +2,7 @@ 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"
... ... @@ -48,7 +49,7 @@ func (repository *ContractUndertakerFeedbackRepository) Save(contractUndertakerF
if err != nil {
return contractUndertakerFeedback, err
} else {
contractUndertakerFeedback.ContractUndertakerFeedbackId = contractUndertakerFeedbackId
contractUndertakerFeedback.FeedbackId = contractUndertakerFeedbackId
}
if _, err := tx.QueryOne(
pg.Scan(
... ... @@ -116,7 +117,7 @@ func (repository *ContractUndertakerFeedbackRepository) Save(contractUndertakerF
func (repository *ContractUndertakerFeedbackRepository) Remove(contractUndertakerFeedback *domain.ContractUndertakerFeedback) (*domain.ContractUndertakerFeedback, error) {
tx := repository.transactionContext.PgTx
contractUndertakerFeedbackModel := new(models.ContractUndertakerFeedback)
contractUndertakerFeedbackModel.ContractUndertakerFeedbackId = contractUndertakerFeedback.Identify().(int64)
contractUndertakerFeedbackModel.FeedbackId = contractUndertakerFeedback.Identify().(int64)
if _, err := tx.Model(contractUndertakerFeedbackModel).WherePK().Delete(); err != nil {
return contractUndertakerFeedback, err
}
... ... @@ -134,7 +135,7 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map
return nil, err
}
}
if contractUndertakerFeedbackModel.ContractUndertakerFeedbackId == 0 {
if contractUndertakerFeedbackModel.FeedbackId == 0 {
return nil, nil
} else {
return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel)
... ...
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 CreditAccountRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CreditAccountRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAccount) (*domain.CreditAccount, error) {
sqlBuildFields := []string{
"credit_account_id",
"actually_paid_amount",
"credit_account_order_num",
"payment_status",
"payment_time",
"settlement_amount",
"settlement_time",
"cooperation_contract_number",
"participator",
"payment_document_attachment",
"org",
"company",
"operator",
"operate_time",
"created_at",
"deleted_at",
"updated_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "creditAccount_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if creditAccount.Identify() == nil {
creditAccountId, err := repository.nextIdentify()
if err != nil {
return creditAccount, err
} else {
creditAccount.CreditAccountId = creditAccountId
}
if _, err := tx.QueryOne(
pg.Scan(
&creditAccount.CreditAccountId,
&creditAccount.ActuallyPaidAmount,
&creditAccount.CreditAccountOrderNum,
&creditAccount.PaymentStatus,
&creditAccount.PaymentTime,
&creditAccount.SettlementAmount,
&creditAccount.SettlementTime,
&creditAccount.CooperationContractNumber,
pg.Array(&creditAccount.Participator),
&creditAccount.PaymentDocumentAttachment,
&creditAccount.Org,
&creditAccount.Company,
&creditAccount.Operator,
&creditAccount.OperateTime,
&creditAccount.CreatedAt,
&creditAccount.DeletedAt,
&creditAccount.UpdatedAt,
),
fmt.Sprintf("INSERT INTO credit_accounts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
creditAccount.CreditAccountId,
creditAccount.ActuallyPaidAmount,
creditAccount.CreditAccountOrderNum,
creditAccount.PaymentStatus,
creditAccount.PaymentTime,
creditAccount.SettlementAmount,
creditAccount.SettlementTime,
creditAccount.CooperationContractNumber,
pg.Array(creditAccount.Participator),
creditAccount.PaymentDocumentAttachment,
creditAccount.Org,
creditAccount.Company,
creditAccount.Operator,
creditAccount.OperateTime,
creditAccount.CreatedAt,
creditAccount.DeletedAt,
creditAccount.UpdatedAt,
); err != nil {
return creditAccount, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&creditAccount.CreditAccountId,
&creditAccount.ActuallyPaidAmount,
&creditAccount.CreditAccountOrderNum,
&creditAccount.PaymentStatus,
&creditAccount.PaymentTime,
&creditAccount.SettlementAmount,
&creditAccount.SettlementTime,
&creditAccount.CooperationContractNumber,
pg.Array(&creditAccount.Participator),
&creditAccount.PaymentDocumentAttachment,
&creditAccount.Org,
&creditAccount.Company,
&creditAccount.Operator,
&creditAccount.OperateTime,
&creditAccount.CreatedAt,
&creditAccount.DeletedAt,
&creditAccount.UpdatedAt,
),
fmt.Sprintf("UPDATE credit_accounts SET %s WHERE credit_account_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
creditAccount.CreditAccountId,
creditAccount.ActuallyPaidAmount,
creditAccount.CreditAccountOrderNum,
creditAccount.PaymentStatus,
creditAccount.PaymentTime,
creditAccount.SettlementAmount,
creditAccount.SettlementTime,
creditAccount.CooperationContractNumber,
pg.Array(creditAccount.Participator),
creditAccount.PaymentDocumentAttachment,
creditAccount.Org,
creditAccount.Company,
creditAccount.Operator,
creditAccount.OperateTime,
creditAccount.CreatedAt,
creditAccount.DeletedAt,
creditAccount.UpdatedAt,
creditAccount.Identify(),
); err != nil {
return creditAccount, err
}
}
return creditAccount, nil
}
func (repository *CreditAccountRepository) Remove(creditAccount *domain.CreditAccount) (*domain.CreditAccount, error) {
tx := repository.transactionContext.PgTx
creditAccountModel := new(models.CreditAccount)
creditAccountModel.CreditAccountId = creditAccount.Identify().(int64)
if _, err := tx.Model(creditAccountModel).WherePK().Delete(); err != nil {
return creditAccount, err
}
return creditAccount, nil
}
func (repository *CreditAccountRepository) FindOne(queryOptions map[string]interface{}) (*domain.CreditAccount, error) {
tx := repository.transactionContext.PgTx
creditAccountModel := new(models.CreditAccount)
query := sqlbuilder.BuildQuery(tx.Model(creditAccountModel), queryOptions)
query.SetWhereByQueryOption("credit_account.credit_account_id = ?", "creditAccountId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if creditAccountModel.CreditAccountId == 0 {
return nil, nil
} else {
return transform.TransformToCreditAccountDomainModelFromPgModels(creditAccountModel)
}
}
func (repository *CreditAccountRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CreditAccount, error) {
tx := repository.transactionContext.PgTx
var creditAccountModels []*models.CreditAccount
creditAccounts := make([]*domain.CreditAccount, 0)
query := sqlbuilder.BuildQuery(tx.Model(&creditAccountModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("credit_account_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, creditAccounts, err
} else {
for _, creditAccountModel := range creditAccountModels {
if creditAccount, err := transform.TransformToCreditAccountDomainModelFromPgModels(creditAccountModel); err != nil {
return 0, creditAccounts, err
} else {
creditAccounts = append(creditAccounts, creditAccount)
}
}
return int64(count), creditAccounts, nil
}
}
func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionContext) (*CreditAccountRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CreditAccountRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -19,6 +19,7 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/service"
)
type CreditAccountController struct {
beego.BaseController
}
func (controller *CreditAccountController) CreateCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
createCreditAccountCommand := &command.CreateCreditAccountCommand{}
controller.Unmarshal(createCreditAccountCommand)
data, err := creditAccountService.CreateCreditAccount(createCreditAccountCommand)
controller.Response(data, err)
}
func (controller *CreditAccountController) UpdateCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
updateCreditAccountCommand := &command.UpdateCreditAccountCommand{}
controller.Unmarshal(updateCreditAccountCommand)
creditAccountId, _ := controller.GetInt64(":creditAccountId")
updateCreditAccountCommand.CreditAccountId = creditAccountId
data, err := creditAccountService.UpdateCreditAccount(updateCreditAccountCommand)
controller.Response(data, err)
}
func (controller *CreditAccountController) GetCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
getCreditAccountQuery := &query.GetCreditAccountQuery{}
creditAccountId, _ := controller.GetInt64(":creditAccountId")
getCreditAccountQuery.CreditAccountId = creditAccountId
data, err := creditAccountService.GetCreditAccount(getCreditAccountQuery)
controller.Response(data, err)
}
func (controller *CreditAccountController) RemoveCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
removeCreditAccountCommand := &command.RemoveCreditAccountCommand{}
controller.Unmarshal(removeCreditAccountCommand)
creditAccountId, _ := controller.GetInt64(":creditAccountId")
removeCreditAccountCommand.CreditAccountId = creditAccountId
data, err := creditAccountService.RemoveCreditAccount(removeCreditAccountCommand)
controller.Response(data, err)
}
func (controller *CreditAccountController) SearchCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
searchCreditAccountQuery := &query.SearchCreditAccountQuery{}
data, err := creditAccountService.SearchCreditAccount(searchCreditAccountQuery)
controller.Response(data, err)
}
func (controller *CreditAccountController) PayCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
payCreditAccountCommand := &command.PayCreditAccountCommand{}
controller.Unmarshal(payCreditAccountCommand)
data, err := creditAccountService.PayCreditAccount(payCreditAccountCommand)
controller.Response(data, err)
}
func (controller *CreditAccountController) ListCreditAccount() {
creditAccountService := service.NewCreditAccountService(nil)
listCreditAccountQuery := &query.ListCreditAccountQuery{}
offset, _ := controller.GetInt("offset")
listCreditAccountQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listCreditAccountQuery.Limit = limit
data, err := creditAccountService.ListCreditAccount(listCreditAccountQuery)
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("/credit-accounts/", &controllers.CreditAccountController{}, "Post:CreateCreditAccount")
web.Router("/credit-accounts/:creditAccountId", &controllers.CreditAccountController{}, "Put:UpdateCreditAccount")
web.Router("/credit-accounts/:creditAccountId", &controllers.CreditAccountController{}, "Get:GetCreditAccount")
web.Router("/credit-accounts/:creditAccountId", &controllers.CreditAccountController{}, "Delete:RemoveCreditAccount")
web.Router("/credit-accounts/search", &controllers.CreditAccountController{}, "Post:SearchCreditAccount")
web.Router("/credit-accounts/pay", &controllers.CreditAccountController{}, "Post:PayCreditAccount")
web.Router("/credit-accounts/", &controllers.CreditAccountController{}, "Get:ListCreditAccount")
}
... ...
package credit_account
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{}{
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/credit-accounts/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("creditAccountId").ValueNotEqual("creditAccountId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package credit_account
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 TestCreditAccount(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port CreditAccount 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 credit_account
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 creditAccountId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&creditAccountId),
"INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id",
"testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据creditAccountId参数返回账期结算单实体", func() {
Context("传入有效的creditAccountId", func() {
It("返回账期结算单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/credit-accounts/{creditAccountId}").
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 credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package credit_account
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 creditAccountId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&creditAccountId),
"INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id",
"testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "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("/credit-accounts/").
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("creditAccounts").Value("creditAccounts").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package credit_account
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 creditAccountId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&creditAccountId),
"INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id",
"testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "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{}{
"actuallyPaidAmount": "float64",
"remarks": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/credit-accounts/pay").
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 credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package credit_account
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 creditAccountId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&creditAccountId),
"INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id",
"testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除账期结算单服务", func() {
Context("传入有效的creditAccountId", func() {
It("返回被移除账期结算单实体的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/credit-accounts/{creditAccountId}").
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 credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package credit_account
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 creditAccountId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&creditAccountId),
"INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id",
"testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "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{}{
"creditAccountOrderNum": "string",
"participatorName": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
"paymentStatus": "int32",
"period": "datetime",
}
httpExpect.POST("/credit-accounts/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 credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package credit_account
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 creditAccountId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&creditAccountId),
"INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id",
"testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "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{}{
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.PUT("/credit-accounts/{creditAccountId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("creditAccountId").ValueEqual("creditAccountId", creditAccountId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...