Commit 7e86c522 authored by Java-刘 彧阳's avatar Java-刘 彧阳

init

parent 0190c3be
...@@ -13,19 +13,17 @@ import cn.gq.financial.model.bill.UMPayBill; ...@@ -13,19 +13,17 @@ import cn.gq.financial.model.bill.UMPayBill;
import cn.gq.financial.model.bill.WXBill; import cn.gq.financial.model.bill.WXBill;
import cn.gq.financial.model.bill.YeepayBill; import cn.gq.financial.model.bill.YeepayBill;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public class RepayFinancialAPP { public class RepayFinancialAPP {
private static final Logger LOGGER = LoggerFactory.getLogger(RepayFinancialAPP.class); private static final Logger LOGGER = LoggerFactory.getLogger(RepayFinancialAPP.class);
static final String CONFIG_LOCAL = "applicationContext.xml"; static final String CONFIG_LOCAL="applicationContext.xml";
static Integer month = 9; static Integer month = 9;
static String SRC_BILL_PATH = "E:\\wx_bill_baitiao"; static String SRC_BILL_PATH ="E:\\WX_BILL_BAITIAO";
static String payAprroach = "微信"; // static String SRC_BILL_PATH ="E:\\WX_BILL\\GBK";
static String payAprroach="微信";
static String payAccount = "微信-现金贷账户"; static String payAccount = "微信-白条账户";
private static ClassPathXmlApplicationContext context = null; private static ClassPathXmlApplicationContext context = null;
...@@ -55,6 +53,7 @@ public class RepayFinancialAPP { ...@@ -55,6 +53,7 @@ public class RepayFinancialAPP {
if (Constants.result.size() != 0) { if (Constants.result.size() != 0) {
repayDetailService.saveDetails(Constants.result); repayDetailService.saveDetails(Constants.result);
} }
LOGGER.info("总还款明细数量-->{}",Constants.result.size());
context.close(); context.close();
LOGGER.info("======结束处理还款账单======"); LOGGER.info("======结束处理还款账单======");
LOGGER.info("总计耗时--->{}mm", (System.currentTimeMillis() - begin)); LOGGER.info("总计耗时--->{}mm", (System.currentTimeMillis() - begin));
......
...@@ -6,6 +6,9 @@ import java.util.List; ...@@ -6,6 +6,9 @@ import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import cn.gq.financial.db.local.dao.FinancialRepayDetailMapper; import cn.gq.financial.db.local.dao.FinancialRepayDetailMapper;
import cn.gq.financial.model.db.RepayDetailFinancial;
import cn.gq.financial.service.FinancialRepayDetailService;
import cn.gq.financial.utils.Constants;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
...@@ -31,6 +34,9 @@ public class RepayHandler { ...@@ -31,6 +34,9 @@ public class RepayHandler {
@Autowired @Autowired
private FinancialRepayDetailMapper repayDetailMapper; private FinancialRepayDetailMapper repayDetailMapper;
@Autowired
private FinancialRepayDetailService financialRepayDetailService;
private CountDownLatch count = null; private CountDownLatch count = null;
public void repayBillDetailHandler(final String srcPaht,final Class<? extends Bill> clazz, String payAccount, Integer month) throws Exception { public void repayBillDetailHandler(final String srcPaht,final Class<? extends Bill> clazz, String payAccount, Integer month) throws Exception {
...@@ -38,6 +44,7 @@ public class RepayHandler { ...@@ -38,6 +44,7 @@ public class RepayHandler {
if(!CollectionUtils.isEmpty(bills)){ if(!CollectionUtils.isEmpty(bills)){
asyncHandlerRepayData(clazz, bills); asyncHandlerRepayData(clazz, bills);
count.await(); //等待所有线程结束 count.await(); //等待所有线程结束
}else{ }else{
throw new RuntimeException("没有读入任何账单"); throw new RuntimeException("没有读入任何账单");
} }
...@@ -48,7 +55,7 @@ public class RepayHandler { ...@@ -48,7 +55,7 @@ public class RepayHandler {
List<Bill> bills) { List<Bill> bills) {
if (bills.size()<ITEM_SIZE) { if (bills.size()<ITEM_SIZE) {
count = new CountDownLatch(1); count = new CountDownLatch(1);
threadPoolTaskExecutor.execute(new RepayHandlerAsync(bills,clazz,paycenterService,bizRepayDetailService,count, repayDetailMapper)); threadPoolTaskExecutor.execute(new RepayHandlerAsync(bills,clazz,paycenterService,bizRepayDetailService,count, repayDetailMapper,financialRepayDetailService));
}else{ }else{
int group = bills.size()/ITEM_SIZE; int group = bills.size()/ITEM_SIZE;
int cnt = group; int cnt = group;
...@@ -59,11 +66,11 @@ public class RepayHandler { ...@@ -59,11 +66,11 @@ public class RepayHandler {
int i = 0; int i = 0;
for (i = 0; i < group; i++) { for (i = 0; i < group; i++) {
List<Bill> subList = bills.subList(i*ITEM_SIZE, (i+1)*ITEM_SIZE); List<Bill> subList = bills.subList(i*ITEM_SIZE, (i+1)*ITEM_SIZE);
threadPoolTaskExecutor.execute(new RepayHandlerAsync(subList,clazz,paycenterService,bizRepayDetailService,count, repayDetailMapper)); threadPoolTaskExecutor.execute(new RepayHandlerAsync(subList,clazz,paycenterService,bizRepayDetailService,count, repayDetailMapper,financialRepayDetailService));
} }
if(bills.size()%ITEM_SIZE != 0 ){ if(bills.size()%ITEM_SIZE != 0 ){
List<Bill> subList = bills.subList(i*ITEM_SIZE, bills.size()); List<Bill> subList = bills.subList(i*ITEM_SIZE, bills.size());
threadPoolTaskExecutor.execute(new RepayHandlerAsync(subList,clazz,paycenterService,bizRepayDetailService,count, repayDetailMapper)); threadPoolTaskExecutor.execute(new RepayHandlerAsync(subList,clazz,paycenterService,bizRepayDetailService,count, repayDetailMapper,financialRepayDetailService));
} }
} }
} }
......
...@@ -9,6 +9,7 @@ import java.util.Set; ...@@ -9,6 +9,7 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import cn.gq.financial.db.local.dao.FinancialRepayDetailMapper; import cn.gq.financial.db.local.dao.FinancialRepayDetailMapper;
import cn.gq.financial.service.FinancialRepayDetailService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -37,10 +38,12 @@ public class RepayHandlerAsync implements Runnable { ...@@ -37,10 +38,12 @@ public class RepayHandlerAsync implements Runnable {
private FinancialRepayDetailMapper repayDetailMapper; private FinancialRepayDetailMapper repayDetailMapper;
private FinancialRepayDetailService financialRepayDetailService;
static BigDecimal MINUS_ONE = new BigDecimal("-1"); static BigDecimal MINUS_ONE = new BigDecimal("-1");
public RepayHandlerAsync(List<Bill> bills, Class<? extends Bill> clazz, PaycenterService paycenterService,BizRepayDetailService bizRepayDetailService, public RepayHandlerAsync(List<Bill> bills, Class<? extends Bill> clazz, PaycenterService paycenterService,BizRepayDetailService bizRepayDetailService,
CountDownLatch count, FinancialRepayDetailMapper repayDetailMapper) { CountDownLatch count, FinancialRepayDetailMapper repayDetailMapper,FinancialRepayDetailService financialRepayDetailService) {
super(); super();
this.bills = bills; this.bills = bills;
this.clazz = clazz; this.clazz = clazz;
...@@ -48,6 +51,7 @@ public class RepayHandlerAsync implements Runnable { ...@@ -48,6 +51,7 @@ public class RepayHandlerAsync implements Runnable {
this.bizRepayDetailService = bizRepayDetailService; this.bizRepayDetailService = bizRepayDetailService;
this.count = count; this.count = count;
this.repayDetailMapper = repayDetailMapper; this.repayDetailMapper = repayDetailMapper;
this.financialRepayDetailService = financialRepayDetailService;
} }
...@@ -58,7 +62,6 @@ public class RepayHandlerAsync implements Runnable { ...@@ -58,7 +62,6 @@ public class RepayHandlerAsync implements Runnable {
List<RepayOrderEntity> payCenterRepayOrderList = paycenterService.queryRepayOrdersByOrderIds(payCenterOrderIds); //支付中心的还款记录 List<RepayOrderEntity> payCenterRepayOrderList = paycenterService.queryRepayOrdersByOrderIds(payCenterOrderIds); //支付中心的还款记录
List<RepayDetailFinancial> all = bizRepayDetailService.getDetailByPayCenterRepayOrder(payCenterRepayOrderList); List<RepayDetailFinancial> all = bizRepayDetailService.getDetailByPayCenterRepayOrder(payCenterRepayOrderList);
balanceBillAndDetail(bills,all); balanceBillAndDetail(bills,all);
//saveDetails(all);
addToResult(all); addToResult(all);
LOGGER.info("##Thread-->{}结束处理账单##",Thread.currentThread().getName()); LOGGER.info("##Thread-->{}结束处理账单##",Thread.currentThread().getName());
}catch(Exception e){ }catch(Exception e){
...@@ -74,12 +77,6 @@ public class RepayHandlerAsync implements Runnable { ...@@ -74,12 +77,6 @@ public class RepayHandlerAsync implements Runnable {
Constants.result.addAll(all); Constants.result.addAll(all);
} }
private void saveDetails(List<RepayDetailFinancial> all) {
int count = repayDetailMapper.insert(all);
LOGGER.info("待插入记录数为{}条, 成功插入{}条", all.size(), count);
}
private void balanceBillAndDetail(List<Bill> bills, List<RepayDetailFinancial> all) { private void balanceBillAndDetail(List<Bill> bills, List<RepayDetailFinancial> all) {
Map<String, Bill> billMap = new HashMap<String, Bill>(); Map<String, Bill> billMap = new HashMap<String, Bill>();
Map<String,List<RepayDetailFinancial>> detailMap = new HashMap<String, List<RepayDetailFinancial>>(); Map<String,List<RepayDetailFinancial>> detailMap = new HashMap<String, List<RepayDetailFinancial>>();
......
package cn.gq.financial.service; package cn.gq.financial.service;
import cn.gq.financial.app.handler.RepayHandlerAsync;
import cn.gq.financial.db.local.dao.FinancialRepayDetailMapper; import cn.gq.financial.db.local.dao.FinancialRepayDetailMapper;
import cn.gq.financial.model.db.RepayDetailFinancial; import cn.gq.financial.model.db.RepayDetailFinancial;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Condition;
/** /**
* @author zhyong.fan * @author zhyong.fan
...@@ -24,7 +21,7 @@ public class FinancialRepayDetailService { ...@@ -24,7 +21,7 @@ public class FinancialRepayDetailService {
private static final Logger LOGGER = LoggerFactory.getLogger(FinancialRepayDetailService.class); private static final Logger LOGGER = LoggerFactory.getLogger(FinancialRepayDetailService.class);
private static final int BATCH_COUNT = 500; public static final int BATCH_COUNT = 200;
@Autowired @Autowired
private FinancialRepayDetailMapper repayDetailMapper; private FinancialRepayDetailMapper repayDetailMapper;
...@@ -39,22 +36,21 @@ public class FinancialRepayDetailService { ...@@ -39,22 +36,21 @@ public class FinancialRepayDetailService {
int totalCount = records.size(); int totalCount = records.size();
if (totalCount <= BATCH_COUNT) { if (totalCount <= BATCH_COUNT) {
latch = new CountDownLatch(1); latch = new CountDownLatch(1);
succCount = repayDetailMapper.insert(records); taskExecutor.execute(new BatchInsertThread(repayDetailMapper, records, latch));
} else { } else {
int loopCount = totalCount / BATCH_COUNT == 0 ? (totalCount / BATCH_COUNT) : (totalCount / BATCH_COUNT + 1); int loopCount = totalCount / BATCH_COUNT == 0 ? (totalCount / BATCH_COUNT) : (totalCount / BATCH_COUNT + 1);
latch = new CountDownLatch(loopCount); latch = new CountDownLatch(loopCount);
for (int i = 0; i < loopCount; i++) { for (int i = 0; i < loopCount; i++) {
int startIndex = i * BATCH_COUNT; int startIndex = i * BATCH_COUNT;
int endIndex = ((i + 1) * BATCH_COUNT < totalCount) ? (i + 1) * BATCH_COUNT : totalCount; int endIndex = ((i + 1) * BATCH_COUNT < totalCount) ? (i + 1) * BATCH_COUNT : totalCount;
succCount += repayDetailMapper.insert(records); taskExecutor.execute(new BatchInsertThread(repayDetailMapper, records.subList(startIndex, endIndex), latch));
// taskExecutor.execute(new BatchInsertThread(repayDetailMapper, records.subList(startIndex, endIndex), latch));
} }
} }
//taskExecutor.execute(new BatchInsertThread(repayDetailMapper, records, latch)); latch.await();
//latch.await();
LOGGER.info("待插入记录数为{}条, 成功插入{}条", records.size(), succCount); LOGGER.info("待插入记录数为{}条, 成功插入{}条", records.size(), succCount);
} }
class BatchInsertThread implements Runnable { class BatchInsertThread implements Runnable {
private FinancialRepayDetailMapper repayDetailMapper; private FinancialRepayDetailMapper repayDetailMapper;
......
...@@ -7,6 +7,7 @@ import java.io.IOException; ...@@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
...@@ -98,7 +99,7 @@ public class BillParsers { ...@@ -98,7 +99,7 @@ public class BillParsers {
BufferedReader reader = null; BufferedReader reader = null;
List<WXBill> bills = new ArrayList<WXBill>(); List<WXBill> bills = new ArrayList<WXBill>();
try { try {
reader = new BufferedReader(new InputStreamReader(inputStream)); reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
String line = reader.readLine(); //越过第一行,同时判断该日是否有账单 String line = reader.readLine(); //越过第一行,同时判断该日是否有账单
if(line.startsWith("<xml>")) return bills; if(line.startsWith("<xml>")) return bills;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment