...
|
...
|
@@ -9,6 +9,8 @@ import ( |
|
|
"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"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -17,7 +19,7 @@ import ( |
|
|
type CreditAccountService struct {
|
|
|
}
|
|
|
|
|
|
// CreateCreditAccount 创建账期结算单服务
|
|
|
// 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())
|
...
|
...
|
@@ -81,15 +83,72 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 账期结算单仓储初始化
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 账期结算单DAO初始化
|
|
|
var creditAccountDao *dao.CreditAccountDao
|
|
|
if value, err := factory.CreateCreditAccountDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
creditAccountDao = value
|
|
|
}
|
|
|
|
|
|
// 分红预算单仓储初始化
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
dividendsEstimateIds, _ := utils.SliceAtoi(createCreditAccountCommand.DividendsEstimateIds)
|
|
|
// 获取所选分红预算单
|
|
|
if _, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"dividendsEstimateIds": dividendsEstimateIds,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
var creditAccounts []*domain.CreditAccount
|
|
|
for _, dividendsEstimate := range dividendsEstimates {
|
|
|
// 生成账期结算单号
|
|
|
creditAccountNumber, err := creditAccountDao.GenerateCreditAccountNumber()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
// 生成账期结算单
|
|
|
newCreditAccount := &domain.CreditAccount{
|
|
|
ActuallyPaidAmount: 0,
|
|
|
CreditAccountOrderNum: "",
|
|
|
PaymentStatus: 0,
|
|
|
CreditAccountOrderNum: creditAccountNumber,
|
|
|
PaymentStatus: 1,
|
|
|
PaymentTime: time.Time{},
|
|
|
SettlementAmount: 0,
|
|
|
SettlementTime: time.Time{},
|
|
|
CooperationContractNumber: "",
|
|
|
Participator: nil,
|
|
|
SettlementAmount: dividendsEstimate.DividendsAmount,
|
|
|
SettlementTime: time.Now(),
|
|
|
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
|
|
|
Participator: &domain.Participator{
|
|
|
UserId: dividendsEstimate.DividendsUser.UserId,
|
|
|
UserBaseId: dividendsEstimate.DividendsUser.UserBaseId,
|
|
|
Org: dividendsEstimate.DividendsUser.Org,
|
|
|
Orgs: dividendsEstimate.DividendsUser.Orgs,
|
|
|
Department: dividendsEstimate.DividendsUser.Department,
|
|
|
Roles: dividendsEstimate.DividendsUser.Roles,
|
|
|
UserInfo: dividendsEstimate.DividendsUser.UserInfo,
|
|
|
UserName: dividendsEstimate.DividendsUser.UserName,
|
|
|
UserPhone: dividendsEstimate.DividendsUser.UserPhone,
|
|
|
UserType: dividendsEstimate.DividendsUser.UserType,
|
|
|
Status: dividendsEstimate.DividendsUser.Status,
|
|
|
Company: dividendsEstimate.DividendsUser.Company,
|
|
|
},
|
|
|
PaymentDocumentAttachment: nil,
|
|
|
Org: organization,
|
|
|
Company: company,
|
...
|
...
|
@@ -99,22 +158,16 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
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 {
|
|
|
creditAccounts = append(creditAccounts, creditAccount)
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return creditAccount, nil
|
|
|
return creditAccounts, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -139,7 +192,7 @@ func (creditAccountService *CreditAccountService) CreditAccountRanking(creditAcc |
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// GetCreditAccount 返回账期结算单服务
|
|
|
// 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())
|
...
|
...
|
@@ -176,7 +229,7 @@ func (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAcco |
|
|
}
|
|
|
}
|
|
|
|
|
|
// ListCreditAccount 返回账期结算单服务列表
|
|
|
// 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())
|
...
|
...
|
@@ -259,7 +312,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco |
|
|
}
|
|
|
}
|
|
|
|
|
|
// RemoveCreditAccount 移除账期结算单服务
|
|
|
// 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())
|
...
|
...
|
@@ -337,7 +390,7 @@ func (creditAccountService *CreditAccountService) SearchCreditAccount(searchCred |
|
|
}
|
|
|
}
|
|
|
|
|
|
// UpdateCreditAccount 更新账期结算单服务
|
|
|
// 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())
|
...
|
...
|
|