领域驱动设计 用DDD重构会计凭证生成(下)( 三 )


public class PayVoucherRuleBuilder implements VoucherRuleBuilder {@Overridepublic VoucherTypeEnum ableToCreateVoucherType() {return VoucherTypeEnum.PAY;}private final VoucherRuleHolder expenseRuleHolder = voucherRuleHolder().addRule(voucherRule(BANK, COST, billAggregation -> "报账", billAggregation -> "报账")).addVoucherAmount(voucherAmount(ableToCreateVoucherType()).totalAmount(billAggregation -> billAggregation.getBill().getPAYMENT_AMOUNT()).amountItems(billAggregation -> billAggregation.getItems().stream().map(item -> {ExpenseItem expenseItem = (ExpenseItem) item;return amountItem().setAmount(expenseItem.getAMOUNT());}).collect(Collectors.toList())));private final VoucherRuleHolder purchaseRuleHolder = voucherRuleHolder().addRule(voucherRule(COST, billAggregation -> "采购", BANK, billAggregation -> "采购")).addVoucherAmount(voucherAmount(ableToCreateVoucherType()).totalAmount(billAggregation -> billAggregation.getBill().getPAYMENT_AMOUNT()).amountItems(billAggregation -> billAggregation.getItems().stream().map(item -> {PurchaseItem purchaseItem = (PurchaseItem) item;return amountItem().setAmount(purchaseItem.getTAX_AMOUNT());}).collect(Collectors.toList())));private final VoucherRuleHolder payRuleHolder = voucherRuleHolder().addRule(voucherRule(FIXED_ASSETS, SHOULD_RECEIPT_SETTLE, billAggregation -> MessageFormat.format("{0}支付{1}", billAggregation.getCompanyName(), billAggregation.getSupplierName()), billAggregation -> MessageFormat.format("{0}收到{1}", billAggregation.getSupplierName(), billAggregation.getCompanyName()))).addVoucherAmount(voucherAmount(ableToCreateVoucherType()).totalAmount(billAggregation -> billAggregation.getBill().getPAYMENT_AMOUNT()).amountItems(billAggregation -> billAggregation.getItems().stream().map(item -> {PaymentItem paymentItem = (PaymentItem) item;return amountItem().setAmount(paymentItem.getPAYMENT_AMOUNT());}).collect(Collectors.toList())));private final VoucherRuleHolder fingertipsRuleHolder = voucherRuleHolder().addRule(voucherRule(COST, BANK, billAggregation -> MessageFormat.format("{0}付{1}个人报销", billAggregation.getCompanyName(), billAggregation.getProposerName()), billAggregation -> MessageFormat.format("{0}收到{1}个人报销", billAggregation.getProposerName(), billAggregation.getCompanyName()))).addVoucherAmount(voucherAmount(ableToCreateVoucherType()).totalAmount(billAggregation -> billAggregation.getBill().getPAYMENT_AMOUNT()).amountItems(billAggregation -> billAggregation.getItems().stream().map(item -> {FingertipItem fingertipItem = (FingertipItem) item;return amountItem().setAmount(fingertipItem.getAMOUNT()).setProjectCode(fingertipItem.getPROJECT_CODE()).setAssistedAccountingCode(fingertipItem.getASSIST_CODE());}).collect(Collectors.toList())));private final VoucherRuleHolder borrowRuleHolder = voucherRuleHolder().addRule(voucherRule(BANK, COST, billAggregation -> billAggregation.getProposerName()+ billAggregation.getBill().getBIZ_DATE() + "申请借款"+ billAggregation.getBill().getTOTAL_AMOUNT(), billAggregation -> billAggregation.getCompanyName() + "借款"));private final VoucherRuleHolder purchaseRelatedTransactionRuleHolder = voucherRuleHolder().addRule(voucherRule(FIXED_ASSETS, RMB, billAggregation -> billAggregation.getProposerName() + "申请" + billAggregation.getBill().getTOTAL_AMOUNT() + "关联交易采购", billAggregation -> "供应商" + billAggregation.getSupplierName())).addVoucherAmount(voucherAmount(ableToCreateVoucherType()).totalAmount(billAggregation -> billAggregation.getBill().getPAYMENT_AMOUNT()).amountItems(billAggregation -> billAggregation.getItems().stream().map(item -> {PurchaseItem purchaseItem = (PurchaseItem) item;return amountItem().setAmount(purchaseItem.getTAX_AMOUNT());}).collect(Collectors.toList())));private final VoucherRuleHolderMap ruleHolder = voucherRuleHolderMap().put(billSpecification(FINGERTIP, N, N), fingertipsRuleHolder).put(billSpecification(PAYMENT_PURCHASE, N, N), payRuleHolder).put(billSpecification(PAYMENT_PURCHASE, N, Y), payRuleHolder).put(billSpecification(PAYMENT_SUPPLIER_G1, N, N), payRuleHolder).put(billSpecification(PAYMENT_SUPPLIER_G1, N, Y), payRuleHolder).put(billSpecification(PAYMENT_SUPPLIER_G2, N, N), payRuleHolder).put(billSpecification(PAYMENT_SUPPLIER_G2, N, Y), payRuleHolder).put(billSpecification(PURCHASE_APPLY_G2, N, N), purchaseRuleHolder).put(billSpecification(PURCHASE_APPLY_RELATED_TRANSACTION, N, N), purchaseRuleHolder).put(billSpecification(EXPENSE_SUPPLIER_G2, N, N), expenseRuleHolder).put(billSpecification(EXPENSE_SUPPLIER_G1, N, N), expenseRuleHolder).put(billSpecification(EXPENSE_SUPPLIER_G1, N, Y), expenseRuleHolder).put(billSpecification(EXPENSE_SUPPLIER_G1, N, null), expenseRuleHolder).put(billSpecification(PAYMENT_RELATED_DERIVE, N, null), payRuleHolder).put(billSpecification(PAYMENT_RELATED_DERIVE, N, N), payRuleHolder).put(billSpecification(EXPENSE_PURCHASE, N, Y), expenseRuleHolder).put(billSpecification(PAYMENT_DERIVE, N, N), payRuleHolder).put(billSpecification(BORROW_MONEY_APPLY, N, Y), borrowRuleHolder).put(billSpecification(PURCHASE_APPLY_RELATED_TRANSACTION, N, N), purchaseRelatedTransactionRuleHolder);@Overridepublic VoucherRuleHolderMap getRuleHolderMap() {return ruleHolder;}}