作者 陈志颖

feat:账期结算增加结算功能

... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
... ... @@ -9,10 +10,14 @@ import (
)
type PayCreditAccountCommand struct {
// 账期结算单ID
CreditAccountId string `cname:"账期结算单ID" json:"creditAccountId" valid:"Required"`
// 账期结算实付金额
ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 支付凭证附件
PaymentDocumentAttachment *domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构ID
... ...
... ... @@ -229,10 +229,34 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 参数类型转换
creditAccountId, _ := strconv.ParseInt(payCreditAccountCommand.CreditAccountId, 10, 64)
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": 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", strconv.FormatInt(creditAccountId, 10)))
}
if err := creditAccount.Update(tool_funs.SimpleStructToMap(payCreditAccountCommand)); 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
}
return nil, nil
}
// RemoveCreditAccount 移除账期结算单服务
... ...
... ... @@ -42,6 +42,8 @@ type CreditAccount struct {
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
//备注
Remarks string `json:"remarks"`
}
type CreditAccountRepository interface {
... ... @@ -68,5 +70,14 @@ func (creditAccount *CreditAccount) Update(data map[string]interface{}) error {
if paymentStatus, ok := data["paymentStatus"]; ok {
creditAccount.PaymentStatus = paymentStatus.(int32)
}
if paymentDocumentAttachment, ok := data["paymentDocumentAttachment"]; ok {
creditAccount.PaymentDocumentAttachment = paymentDocumentAttachment.(*Attachment)
}
if remarks, ok := data["remarks"]; ok {
creditAccount.Remarks = remarks.(string)
}
if actuallyPaidAmount, ok := data["actuallyPaidAmount"]; ok {
creditAccount.ActuallyPaidAmount = actuallyPaidAmount.(float64)
}
return nil
}
... ...
... ... @@ -45,4 +45,6 @@ type CreditAccount struct {
DeletedAt time.Time `comment:"删除时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 备注
Remarks string `comment:"备注"`
}
... ...
... ... @@ -26,5 +26,6 @@ func TransformToCreditAccountDomainModelFromPgModels(creditAccountModel *models.
CreatedAt: creditAccountModel.CreatedAt,
DeletedAt: creditAccountModel.DeletedAt,
UpdatedAt: creditAccountModel.UpdatedAt,
Remarks: creditAccountModel.Remarks,
}, nil
}
... ...
... ... @@ -46,6 +46,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
"created_at",
"deleted_at",
"updated_at",
"remarks",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -81,6 +82,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
&creditAccount.CreatedAt,
&creditAccount.DeletedAt,
&creditAccount.UpdatedAt,
&creditAccount.Remarks,
),
fmt.Sprintf("INSERT INTO credit_accounts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
creditAccount.CreditAccountId,
... ... @@ -100,8 +102,9 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
creditAccount.Operator,
creditAccount.OperateTime,
creditAccount.CreatedAt,
creditAccount.DeletedAt,
nil,
creditAccount.UpdatedAt,
creditAccount.Remarks,
); err != nil {
return creditAccount, err
}
... ... @@ -127,6 +130,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
&creditAccount.CreatedAt,
&creditAccount.DeletedAt,
&creditAccount.UpdatedAt,
&creditAccount.Remarks,
),
fmt.Sprintf("UPDATE credit_accounts SET %s WHERE credit_account_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
creditAccount.CreditAccountId,
... ... @@ -146,8 +150,9 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
creditAccount.Operator,
creditAccount.OperateTime,
creditAccount.CreatedAt,
creditAccount.DeletedAt,
nil,
creditAccount.UpdatedAt,
creditAccount.Remarks,
creditAccount.Identify(),
); err != nil {
return creditAccount, err
... ...