...
|
...
|
@@ -19,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())
|
...
|
...
|
@@ -28,8 +28,8 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
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())
|
|
|
if err1 := transactionContext.StartTransaction(); err1 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err1.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
...
|
...
|
@@ -37,78 +37,78 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
|
|
|
// 公司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())
|
|
|
if value, err2 := factory.CreateCompanyService(map[string]interface{}{}); err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.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())
|
|
|
if data, err3 := companyService.CompanyFrom(createCreditAccountCommand.CompanyId); err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_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())
|
|
|
if value, err4 := factory.CreateOrganizationService(map[string]interface{}{}); err4 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.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())
|
|
|
if data, err5 := organizationService.OrgFrom(createCreditAccountCommand.CompanyId, createCreditAccountCommand.OrgId); err5 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_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())
|
|
|
if value, err6 := factory.CreateUserService(map[string]interface{}{}); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.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())
|
|
|
if data, err7 := userService.OperatorFrom(createCreditAccountCommand.CompanyId, createCreditAccountCommand.OrgId, createCreditAccountCommand.UserId); err7 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取操作人失败")
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 账期结算单仓储初始化
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
|
|
if value, err8 := factory.CreateCreditAccountRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}); err8 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err8.Error())
|
|
|
} else {
|
|
|
creditAccountRepository = value
|
|
|
}
|
|
|
|
|
|
// 账期结算单DAO初始化
|
|
|
var creditAccountDao *dao.CreditAccountDao
|
|
|
if value, err := factory.CreateCreditAccountDao(map[string]interface{}{
|
|
|
if value, err9 := factory.CreateCreditAccountDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}); err9 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err9.Error())
|
|
|
} else {
|
|
|
creditAccountDao = value
|
|
|
}
|
|
|
|
|
|
// 分红预算单仓储初始化
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
if value, err10 := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}); err10 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err10.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
...
|
...
|
@@ -116,13 +116,14 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
// 批量转换分红预算单号列表
|
|
|
dividendsEstimateIds, err := utils.SliceAtoi(createCreditAccountCommand.DividendsEstimateIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红预算单号错误")
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红预算单号类型错误")
|
|
|
}
|
|
|
|
|
|
// 获取所选分红预算单
|
|
|
if _, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
if _, dividendsEstimates, err11 := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"dividendsEstimateIds": dividendsEstimateIds,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}); err11 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err11.Error())
|
|
|
} else {
|
|
|
// 校验共创用户是否一致
|
|
|
if len(dividendsEstimates) > 0 {
|
...
|
...
|
@@ -143,59 +144,64 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 预算操作
|
|
|
// 预算明细
|
|
|
var creditAccounts []*domain.CreditAccount
|
|
|
var accountDetail []*domain.AccountDetail
|
|
|
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: creditAccountNumber,
|
|
|
PaymentStatus: 1,
|
|
|
PaymentTime: time.Time{},
|
|
|
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,
|
|
|
},
|
|
|
AccountDetail: &domain.AccountDetail{
|
|
|
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
|
|
|
DividendsType: dividendsEstimate.DividendsType,
|
|
|
DividendsAmount: dividendsEstimate.DividendsAmount,
|
|
|
},
|
|
|
PaymentDocumentAttachment: nil,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Now(),
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
if creditAccount, err := creditAccountRepository.Save(newCreditAccount); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
creditAccounts = append(creditAccounts, creditAccount)
|
|
|
}
|
|
|
accountDetail = append(accountDetail, &domain.AccountDetail{
|
|
|
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
|
|
|
DividendsType: dividendsEstimate.DividendsType,
|
|
|
DividendsAmount: dividendsEstimate.DividendsAmount,
|
|
|
})
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
|
|
|
// 生成账期结算单号
|
|
|
creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber()
|
|
|
if err12 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "生成账期结算单号错误")
|
|
|
}
|
|
|
|
|
|
// 生成账期结算单
|
|
|
newCreditAccount := &domain.CreditAccount{
|
|
|
ActuallyPaidAmount: 0,
|
|
|
CreditAccountOrderNum: creditAccountNumber,
|
|
|
PaymentStatus: 1,
|
|
|
PaymentTime: time.Time{},
|
|
|
SettlementAmount: dividendsEstimates[0].DividendsAmount,
|
|
|
SettlementTime: time.Now(),
|
|
|
Participator: &domain.Participator{ // 共创参与
|
|
|
UserId: dividendsEstimates[0].DividendsUser.UserId,
|
|
|
UserBaseId: dividendsEstimates[0].DividendsUser.UserBaseId,
|
|
|
Org: dividendsEstimates[0].DividendsUser.Org,
|
|
|
Orgs: dividendsEstimates[0].DividendsUser.Orgs,
|
|
|
Department: dividendsEstimates[0].DividendsUser.Department,
|
|
|
Roles: dividendsEstimates[0].DividendsUser.Roles,
|
|
|
UserInfo: dividendsEstimates[0].DividendsUser.UserInfo,
|
|
|
UserName: dividendsEstimates[0].DividendsUser.UserName,
|
|
|
UserPhone: dividendsEstimates[0].DividendsUser.UserPhone,
|
|
|
UserType: dividendsEstimates[0].DividendsUser.UserType,
|
|
|
Status: dividendsEstimates[0].DividendsUser.Status,
|
|
|
Company: dividendsEstimates[0].DividendsUser.Company,
|
|
|
},
|
|
|
AccountDetail: accountDetail,
|
|
|
PaymentDocumentAttachment: nil,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Now(),
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
if creditAccount, err13 := creditAccountRepository.Save(newCreditAccount); err13 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error())
|
|
|
} else {
|
|
|
creditAccounts = append(creditAccounts, creditAccount)
|
|
|
}
|
|
|
|
|
|
if err14 := transactionContext.CommitTransaction(); err14 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err14.Error())
|
|
|
}
|
|
|
return creditAccounts, nil
|
|
|
}
|
...
|
...
|
@@ -315,13 +321,14 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco |
|
|
// 参数类型转换
|
|
|
creditAccountId, _ := strconv.ParseInt(payCreditAccountCommand.CreditAccountId, 10, 64)
|
|
|
var creditAccountRepository domain.CreditAccountRepository
|
|
|
if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
|
|
|
if value, err1 := factory.CreateCreditAccountRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}); err1 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err1.Error())
|
|
|
} else {
|
|
|
creditAccountRepository = value
|
|
|
}
|
|
|
// 获取待支付的账期结算单
|
|
|
creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": creditAccountId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -329,16 +336,18 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco |
|
|
if creditAccount == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(creditAccountId, 10)))
|
|
|
}
|
|
|
if err := creditAccount.Update(tool_funs.SimpleStructToMap(payCreditAccountCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
if err2 := creditAccount.Update(tool_funs.SimpleStructToMap(payCreditAccountCommand)); err2 != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err2.Error())
|
|
|
}
|
|
|
if creditAccount, err := creditAccountRepository.Save(creditAccount); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// 支付状态设置
|
|
|
creditAccount.PaymentStatus = 2
|
|
|
if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
if err3 := transactionContext.CommitTransaction(); err3 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
|
|
|
}
|
|
|
return creditAccount, nil
|
|
|
return creditAccountSaved, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|