Java tutorial
/* * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.roncoo.pay.app.reconciliation.biz; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.roncoo.pay.reconciliation.entity.RpAccountCheckBatch; import com.roncoo.pay.reconciliation.entity.RpAccountCheckMistake; import com.roncoo.pay.reconciliation.entity.RpAccountCheckMistakeScratchPool; import com.roncoo.pay.reconciliation.enums.MistakeHandleStatusEnum; import com.roncoo.pay.reconciliation.enums.ReconciliationMistakeTypeEnum; import com.roncoo.pay.reconciliation.service.RpAccountCheckMistakeScratchPoolService; import com.roncoo.pay.reconciliation.service.RpAccountCheckTransactionService; import com.roncoo.pay.reconciliation.vo.ReconciliationEntityVo; import com.roncoo.pay.trade.entity.RpTradePaymentRecord; import com.roncoo.pay.trade.enums.TradeStatusEnum; /** * biz. * * www.roncoo.com * * @authorshenjialong */ @Component("reconciliationCheckBiz") public class ReconciliationCheckBiz { private static final Log LOG = LogFactory.getLog(ReconciliationCheckBiz.class); @Autowired private RpAccountCheckMistakeScratchPoolService rpAccountCheckMistakeScratchPoolService; @Autowired private RpAccountCheckTransactionService rpAccountCheckTransactionService; @Autowired private ReconciliationDataGetBiz reconciliationDataGetBiz; /** * * * @param bankList * ??? * @param interfaceCode * ? * @param batch * */ public void check(List<ReconciliationEntityVo> bankList, String interfaceCode, RpAccountCheckBatch batch) { // bankList? if (bankList == null) { bankList = new ArrayList<ReconciliationEntityVo>(); } // ?bill_date,interfaceCode? List<RpTradePaymentRecord> platSucessDateList = reconciliationDataGetBiz .getSuccessPlatformDateByBillDate(batch.getBillDate(), interfaceCode); // ?bill_date,interfaceCode List<RpTradePaymentRecord> platAllDateList = reconciliationDataGetBiz .getAllPlatformDateByBillDate(batch.getBillDate(), interfaceCode); // ?? List<RpAccountCheckMistakeScratchPool> platScreatchRecordList = rpAccountCheckMistakeScratchPoolService .listScratchPoolRecord(null); // list List<RpAccountCheckMistake> mistakeList = new ArrayList<RpAccountCheckMistake>(); // ??list List<RpAccountCheckMistakeScratchPool> insertScreatchRecordList = new ArrayList<RpAccountCheckMistakeScratchPool>(); // ?? List<RpAccountCheckMistakeScratchPool> removeScreatchRecordList = new ArrayList<RpAccountCheckMistakeScratchPool>(); LOG.info(" ??,?"); baseOnPaltForm(platSucessDateList, bankList, mistakeList, insertScreatchRecordList, batch); LOG.info("???"); LOG.info(" ??"); baseOnBank(platAllDateList, bankList, platScreatchRecordList, mistakeList, batch, removeScreatchRecordList); LOG.info(" ???"); // ?? rpAccountCheckTransactionService.saveDatasaveDate(batch, mistakeList, insertScreatchRecordList, removeScreatchRecordList); } /** * ?? * * @param platformDateList * ?dilldate?? * @param bankList * ??? * * @param misTakeList * list * @param screatchRecordList * ??list * * @param batch * */ private void baseOnPaltForm(List<RpTradePaymentRecord> platformDateList, List<ReconciliationEntityVo> bankList, List<RpAccountCheckMistake> misTakeList, List<RpAccountCheckMistakeScratchPool> screatchRecordList, RpAccountCheckBatch batch) { BigDecimal platTradeAmount = BigDecimal.ZERO;// ?? BigDecimal platFee = BigDecimal.ZERO;// ? Integer tradeCount = 0;// ?? Integer mistakeCount = 0; for (RpTradePaymentRecord record : platformDateList) { Boolean flag = false;// ?? // ?? platTradeAmount = platTradeAmount.add(record.getOrderAmount()); platFee = platFee.add(record.getPlatCost() == null ? BigDecimal.ZERO : record.getPlatCost()); tradeCount++; for (ReconciliationEntityVo bankRecord : bankList) { // ???? if (record.getBankOrderNo().equalsIgnoreCase(bankRecord.getBankOrderNo())) { flag = true;// ?? /** step1:??? **/ // ?? if (record.getOrderAmount().compareTo(bankRecord.getBankAmount()) == 1) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_OVER_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } // ?? else if (record.getOrderAmount().compareTo(bankRecord.getBankAmount()) == -1) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step2:?? **/ if (record.getPlatCost().compareTo(bankRecord.getBankFee()) != 0) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.FEE_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } } } // ?? if (!flag) { RpAccountCheckMistakeScratchPool screatchRecord = getScratchRecord(record, batch); screatchRecordList.add(screatchRecord); } } // ?? batch.setTradeAmount(platTradeAmount); batch.setTradeCount(tradeCount); batch.setFee(platFee); batch.setMistakeCount(mistakeCount); } /** * ? * * @param bankList * ?? * * @param misTakeList * list * * @param platScreatchRecordList * ?? * * @param batch * */ private void baseOnBank(List<RpTradePaymentRecord> platAllDateList, List<ReconciliationEntityVo> bankList, List<RpAccountCheckMistakeScratchPool> platScreatchRecordList, List<RpAccountCheckMistake> misTakeList, RpAccountCheckBatch batch, List<RpAccountCheckMistakeScratchPool> removeScreatchRecordList) { BigDecimal platTradeAmount = BigDecimal.ZERO;// ?? BigDecimal platFee = BigDecimal.ZERO;// ? Integer tradeCount = 0;// ?? Integer mistakeCount = 0; // ? for (ReconciliationEntityVo bankRecord : bankList) { boolean flag = false;// ?? for (RpTradePaymentRecord record : platAllDateList) { /** step1 ?? **/ if (bankRecord.getBankOrderNo().equals(record.getBankOrderNo())) { flag = true; /** step2 ???? **/ /** ????????????? **/ // ?? if (!TradeStatusEnum.SUCCESS.name().equals(record.getStatus())) { RpAccountCheckMistake misktake1 = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_STATUS_MISMATCH, batch); misTakeList.add(misktake1); mistakeCount++; // break; /** ???????????? **/ // ?? /** step1:??? **/ // ?? if (record.getOrderAmount().compareTo(bankRecord.getBankAmount()) == 1) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_OVER_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } // ?? else if (record.getOrderAmount().compareTo(bankRecord.getBankAmount()) == -1) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step2:?? **/ if (record.getPlatCost().compareTo(bankRecord.getBankFee()) != 0) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.FEE_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } } } } /** step3 ?? **/ if (!flag) { // (?????) if (platScreatchRecordList != null) for (RpAccountCheckMistakeScratchPool scratchRecord : platScreatchRecordList) { // ? if (scratchRecord.getBankOrderNo().equals(bankRecord.getBankOrderNo())) { // ?? platTradeAmount = platTradeAmount.add(scratchRecord.getOrderAmount()); platFee = platFee.add(scratchRecord.getPlatCost() == null ? BigDecimal.ZERO : scratchRecord.getPlatCost()); tradeCount++; flag = true; // ?? /** step1:??? **/ // ?? if (scratchRecord.getOrderAmount().compareTo(bankRecord.getBankAmount()) == 1) { // ??? RpAccountCheckMistake misktake = createMisktake(scratchRecord, null, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_OVER_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } // ?? else if (scratchRecord.getOrderAmount().compareTo(bankRecord.getBankAmount()) == -1) { // ??? RpAccountCheckMistake misktake = createMisktake(scratchRecord, null, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step2:?? **/ if (scratchRecord.getPlatCost().compareTo(bankRecord.getBankFee()) != 0) { // ??? RpAccountCheckMistake misktake = createMisktake(scratchRecord, null, bankRecord, ReconciliationMistakeTypeEnum.FEE_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step3:? **/ removeScreatchRecordList.add(scratchRecord); } } } // ?, PLATFORM_MISS("???") if (!flag) { RpAccountCheckMistake misktake = createMisktake(null, null, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_MISS, batch); misTakeList.add(misktake); mistakeCount++; } } // ?? batch.setTradeAmount(batch.getTradeAmount().add(platTradeAmount)); batch.setTradeCount(batch.getTradeCount() + tradeCount); batch.setFee(batch.getFee().add(platFee)); batch.setMistakeCount(batch.getMistakeCount() + mistakeCount); } /** * * * @param scratchRecord * ?? * @param record * ?? * @param bankRecord * ? * @param mistakeType * * @return ?scratchRecordrecord */ private RpAccountCheckMistake createMisktake(RpAccountCheckMistakeScratchPool scratchRecord, RpTradePaymentRecord record, ReconciliationEntityVo bankRecord, ReconciliationMistakeTypeEnum mistakeType, RpAccountCheckBatch batch) { RpAccountCheckMistake mistake = new RpAccountCheckMistake(); mistake.setAccountCheckBatchNo(batch.getBatchNo()); mistake.setBillDate(batch.getBillDate()); mistake.setErrType(mistakeType.name()); mistake.setHandleStatus(MistakeHandleStatusEnum.NOHANDLE.name()); mistake.setBankType(batch.getBankType()); if (record != null) { mistake.setMerchantName(record.getMerchantName()); mistake.setMerchantNo(record.getMerchantNo()); mistake.setOrderNo(record.getMerchantOrderNo()); mistake.setTradeTime(record.getPaySuccessTime()); mistake.setTrxNo(record.getTrxNo()); mistake.setOrderAmount(record.getOrderAmount()); mistake.setRefundAmount(record.getSuccessRefundAmount()); mistake.setTradeStatus(record.getStatus()); mistake.setFee(record.getPlatCost()); } if (scratchRecord != null) { mistake.setOrderNo(scratchRecord.getMerchantOrderNo()); mistake.setTradeTime(scratchRecord.getPaySuccessTime()); mistake.setTrxNo(scratchRecord.getTrxNo()); mistake.setOrderAmount(scratchRecord.getOrderAmount()); mistake.setRefundAmount(scratchRecord.getSuccessRefundAmount()); mistake.setTradeStatus(scratchRecord.getStatus()); mistake.setFee(scratchRecord.getPlatCost()); } if (bankRecord != null) { mistake.setBankAmount(bankRecord.getBankAmount()); mistake.setBankFee(bankRecord.getBankFee()); mistake.setBankOrderNo(bankRecord.getBankOrderNo()); mistake.setBankRefundAmount(bankRecord.getBankRefundAmount()); mistake.setBankTradeStatus(bankRecord.getBankTradeStatus()); mistake.setBankTradeTime(bankRecord.getBankTradeTime()); mistake.setBankTrxNo(bankRecord.getBankTrxNo()); } return mistake; } /** * * * @param record * * @param batch * * @return */ private RpAccountCheckMistakeScratchPool getScratchRecord(RpTradePaymentRecord record, RpAccountCheckBatch batch) { RpAccountCheckMistakeScratchPool scratchRecord = new RpAccountCheckMistakeScratchPool(); scratchRecord.setBankOrderNo(record.getBankOrderNo()); scratchRecord.setBankTrxNo(record.getBankTrxNo()); scratchRecord.setCompleteTime(record.getCompleteTime()); scratchRecord.setPaySuccessTime(record.getPaySuccessTime()); scratchRecord.setMerchantOrderNo(record.getMerchantOrderNo()); scratchRecord.setOrderAmount(record.getOrderAmount()); scratchRecord.setPlatCost(record.getPlatCost()); scratchRecord.setPayWayCode(record.getPayWayCode()); scratchRecord.setTrxNo(record.getTrxNo()); scratchRecord.setStatus(TradeStatusEnum.SUCCESS.name()); scratchRecord.setBatchNo(batch.getBatchNo()); scratchRecord.setBillDate(batch.getBillDate()); return scratchRecord; } }