com.roncoo.pay.app.reconciliation.ReconciliationTask.java Source code

Java tutorial

Introduction

Here is the source code for com.roncoo.pay.app.reconciliation.ReconciliationTask.java

Source

/*
 * 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;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.roncoo.pay.app.reconciliation.biz.ReconciliationCheckBiz;
import com.roncoo.pay.app.reconciliation.biz.ReconciliationFileDownBiz;
import com.roncoo.pay.app.reconciliation.biz.ReconciliationFileParserBiz;
import com.roncoo.pay.app.reconciliation.biz.ReconciliationValidateBiz;
import com.roncoo.pay.app.reconciliation.utils.DateUtil;
import com.roncoo.pay.app.reconciliation.utils.SpringContextUtil;
import com.roncoo.pay.app.reconciliation.vo.ReconciliationInterface;
import com.roncoo.pay.reconciliation.entity.RpAccountCheckBatch;
import com.roncoo.pay.reconciliation.enums.BatchStatusEnum;
import com.roncoo.pay.reconciliation.service.RpAccountCheckBatchService;
import com.roncoo.pay.reconciliation.vo.ReconciliationEntityVo;
import com.roncoo.pay.user.service.BuildNoService;

/**
 * ?(???) .
 *
 * www.roncoo.com
 * 
 * @authorshenjialong
 */
public class ReconciliationTask {

    private static final Log LOG = LogFactory.getLog(ReconciliationTask.class);

    public static void main(String[] args) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        try {
            // Spring?
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                    new String[] { "spring-context.xml" });
            // ?SpringContextUtil
            final SpringContextUtil ctxUtil = new SpringContextUtil();
            ctxUtil.setApplicationContext(context);

            @SuppressWarnings("rawtypes")
            // ??(???????)
            List reconciliationInterList = ReconciliationInterface.getInterface();

            // ?biz
            ReconciliationFileDownBiz fileDownBiz = (ReconciliationFileDownBiz) SpringContextUtil
                    .getBean("reconciliationFileDownBiz");
            ReconciliationFileParserBiz parserBiz = (ReconciliationFileParserBiz) SpringContextUtil
                    .getBean("reconciliationFileParserBiz");
            ReconciliationCheckBiz checkBiz = (ReconciliationCheckBiz) SpringContextUtil
                    .getBean("reconciliationCheckBiz");
            ReconciliationValidateBiz validateBiz = (ReconciliationValidateBiz) SpringContextUtil
                    .getBean("reconciliationValidateBiz");
            RpAccountCheckBatchService batchService = (RpAccountCheckBatchService) SpringContextUtil
                    .getBean("rpAccountCheckBatchService");
            BuildNoService buildNoService = (BuildNoService) SpringContextUtil.getBean("buildNoService");

            // ?????
            for (int num = 0; num < reconciliationInterList.size(); num++) {
                // ??
                ReconciliationInterface reconciliationInter = (ReconciliationInterface) reconciliationInterList
                        .get(num);
                if (reconciliationInter == null) {
                    LOG.info("??" + reconciliationInter + "");
                    continue;
                }
                // ???
                Date billDate = DateUtil.addDay(new Date(), -reconciliationInter.getBillDay());
                // ??
                String interfaceCode = reconciliationInter.getInterfaceCode();

                /** step1:? **/
                RpAccountCheckBatch batch = new RpAccountCheckBatch();
                Boolean checked = validateBiz.isChecked(interfaceCode, billDate);
                if (checked) {
                    LOG.info("?[" + sdf.format(billDate) + "],?[" + interfaceCode
                            + "],????");
                    continue;
                }
                // 
                batch.setCreater("reconciliationSystem");
                batch.setCreateTime(new Date());
                batch.setBillDate(billDate);
                batch.setBatchNo(buildNoService.buildReconciliationNo());
                batch.setBankType(interfaceCode);

                /** step2: **/
                File file = null;
                try {
                    LOG.info("ReconciliationFileDownBiz,");
                    file = fileDownBiz.downReconciliationFile(interfaceCode, billDate);
                    if (file == null) {
                        continue;
                    }
                    LOG.info("?");
                } catch (Exception e) {
                    LOG.error(":", e);
                    batch.setStatus(BatchStatusEnum.FAIL.name());
                    batch.setRemark("");
                    batchService.saveData(batch);
                    continue;
                }

                /** step3:? **/
                List<ReconciliationEntityVo> bankList = null;
                try {
                    LOG.info("=ReconciliationFileParserBiz=>?>>>");

                    // ?
                    bankList = parserBiz.parser(batch, file, billDate, interfaceCode);
                    // 
                    if (BatchStatusEnum.ERROR.name().equals(batch.getStatus())) {
                        continue;
                    }
                    LOG.info("??");
                } catch (Exception e) {
                    LOG.error("?:", e);
                    batch.setStatus(BatchStatusEnum.FAIL.name());
                    batch.setRemark("?");
                    batchService.saveData(batch);
                    continue;
                }

                /** step4:? **/
                try {
                    checkBiz.check(bankList, interfaceCode, batch);
                } catch (Exception e) {
                    LOG.error(":", e);
                    batch.setStatus(BatchStatusEnum.FAIL.name());
                    batch.setRemark("");
                    batchService.saveData(batch);
                    continue;
                }

            }

            /** step5:? **/
            // ???
            validateBiz.validateScratchPool();
        } catch (Exception e) {
            LOG.error("roncoo-app-reconciliation error:", e);
        }

    }
}