...
|
...
|
@@ -8,13 +8,16 @@ import ( |
|
|
"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"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 账期结算单服务
|
|
|
// CreditAccountService 账期结算单服务
|
|
|
type CreditAccountService struct {
|
|
|
}
|
|
|
|
|
|
// 创建账期结算单服务
|
|
|
// CreateCreditAccount 创建账期结算单服务
|
|
|
func (creditAccountService *CreditAccountService) CreateCreditAccount(createCreditAccountCommand *command.CreateCreditAccountCommand) (interface{}, error) {
|
|
|
if err := createCreditAccountCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -27,13 +30,76 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(createCreditAccountCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
|
|
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organizationService = value
|
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(createCreditAccountCommand.CompanyId, createCreditAccountCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取操作人
|
|
|
var operator *domain.User
|
|
|
if data, err := userService.OperatorFrom(createCreditAccountCommand.CompanyId, createCreditAccountCommand.OrgId, createCreditAccountCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
newCreditAccount := &domain.CreditAccount{
|
|
|
//CompanyId: createCreditAccountCommand.CompanyId,
|
|
|
//OrgId: createCreditAccountCommand.OrgId,
|
|
|
//UserId: createCreditAccountCommand.UserId,
|
|
|
ActuallyPaidAmount: 0,
|
|
|
CreditAccountOrderNum: "",
|
|
|
PaymentStatus: 0,
|
|
|
PaymentTime: time.Time{},
|
|
|
SettlementAmount: 0,
|
|
|
SettlementTime: time.Time{},
|
|
|
CooperationContractNumber: "",
|
|
|
Participator: nil,
|
|
|
PaymentDocumentAttachment: nil,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Now(),
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -52,7 +118,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 账期结算单排名
|
|
|
// CreditAccountRanking 账期结算单排名
|
|
|
func (creditAccountService *CreditAccountService) CreditAccountRanking(creditAccountRankingQuery *query.CreditAccountRankingQuery) (interface{}, error) {
|
|
|
if err := creditAccountRankingQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -65,7 +131,7 @@ func (creditAccountService *CreditAccountService) CreditAccountRanking(creditAcc |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -73,7 +139,7 @@ func (creditAccountService *CreditAccountService) CreditAccountRanking(creditAcc |
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 返回账期结算单服务
|
|
|
// GetCreditAccount 返回账期结算单服务
|
|
|
func (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAccountQuery *query.GetCreditAccountQuery) (interface{}, error) {
|
|
|
if err := getCreditAccountQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -86,7 +152,7 @@ func (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAcco |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
...
|
...
|
@@ -101,7 +167,7 @@ func (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAcco |
|
|
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)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCreditAccountQuery.CreditAccountId, 10)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -110,7 +176,7 @@ func (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAcco |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回账期结算单服务列表
|
|
|
// ListCreditAccount 返回账期结算单服务列表
|
|
|
func (creditAccountService *CreditAccountService) ListCreditAccount(listCreditAccountQuery *query.ListCreditAccountQuery) (interface{}, error) {
|
|
|
if err := listCreditAccountQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -123,7 +189,7 @@ func (creditAccountService *CreditAccountService) ListCreditAccount(listCreditAc |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
...
|
...
|
@@ -146,7 +212,7 @@ func (creditAccountService *CreditAccountService) ListCreditAccount(listCreditAc |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 支付账期结算(支付分红)
|
|
|
// PayCreditAccount 支付账期结算(支付分红)
|
|
|
func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAccountCommand *command.PayCreditAccountCommand) (interface{}, error) {
|
|
|
if err := payCreditAccountCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -159,7 +225,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -167,7 +233,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco |
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 移除账期结算单服务
|
|
|
// RemoveCreditAccount 移除账期结算单服务
|
|
|
func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCreditAccountCommand *command.RemoveCreditAccountCommand) (interface{}, error) {
|
|
|
if err := removeCreditAccountCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -180,7 +246,7 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
...
|
...
|
@@ -195,7 +261,7 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred |
|
|
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)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeCreditAccountCommand.CreditAccountId, 10)))
|
|
|
}
|
|
|
if creditAccount, err := creditAccountRepository.Remove(creditAccount); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -207,7 +273,7 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询账期结算单
|
|
|
// SearchCreditAccount 查询账期结算单
|
|
|
func (creditAccountService *CreditAccountService) SearchCreditAccount(searchCreditAccountQuery *query.SearchCreditAccountQuery) (interface{}, error) {
|
|
|
if err := searchCreditAccountQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -220,7 +286,7 @@ func (creditAccountService *CreditAccountService) SearchCreditAccount(searchCred |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -228,7 +294,7 @@ func (creditAccountService *CreditAccountService) SearchCreditAccount(searchCred |
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 更新账期结算单服务
|
|
|
// UpdateCreditAccount 更新账期结算单服务
|
|
|
func (creditAccountService *CreditAccountService) UpdateCreditAccount(updateCreditAccountCommand *command.UpdateCreditAccountCommand) (interface{}, error) {
|
|
|
if err := updateCreditAccountCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -241,7 +307,7 @@ func (creditAccountService *CreditAccountService) UpdateCreditAccount(updateCred |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
...
|
...
|
@@ -256,7 +322,7 @@ func (creditAccountService *CreditAccountService) UpdateCreditAccount(updateCred |
|
|
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)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCreditAccountCommand.CreditAccountId, 10)))
|
|
|
}
|
|
|
if err := creditAccount.Update(tool_funs.SimpleStructToMap(updateCreditAccountCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
|