|
|
@@ -1,621 +0,0 @@
|
|
|
-package com.qlm.job;
|
|
|
-
|
|
|
-import com.jfinal.plugin.activerecord.Db;
|
|
|
-import com.jfinal.plugin.activerecord.Record;
|
|
|
-import com.qlm.entity.DayHbEntity;
|
|
|
-import com.qlm.entity.HbEntity;
|
|
|
-import com.qlm.entity.ScanHbEntity;
|
|
|
-import com.qlm.tools.LocalDateUtils;
|
|
|
-import org.quartz.Job;
|
|
|
-import org.quartz.JobExecutionContext;
|
|
|
-import org.quartz.JobExecutionException;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author nommpp
|
|
|
- * 汇总每天的扫码量和红包发放金额
|
|
|
- */
|
|
|
-public class AddUpJob implements Job {
|
|
|
-
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(AddUpJob.class);
|
|
|
-
|
|
|
- private static final String T_SCAN_HB = "t_scan_hb";
|
|
|
-
|
|
|
- private static final String T_DAY_HB = "t_day_hb";
|
|
|
-
|
|
|
- private static final String T_DAY_HB_DETAIL = "t_day_hb_detail";
|
|
|
-
|
|
|
- private static final String T_DAY_SCAN_HB = "t_day_scan_hb";
|
|
|
-
|
|
|
- private static final int SINGLE_COUNT = 100000;
|
|
|
-
|
|
|
- private static final String SPLIT = ",";
|
|
|
-
|
|
|
- @Override
|
|
|
- public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- LocalDateTime yestoday = now.minusDays(1);
|
|
|
- String yesStart = LocalDateUtils.localToStr(LocalDateUtils.getDayStart(yestoday));
|
|
|
- String yesEnd = LocalDateUtils.localToStr(LocalDateUtils.getDayEnd(yestoday));
|
|
|
-
|
|
|
- String day = LocalDateUtils.localToDateStr(yestoday);
|
|
|
-
|
|
|
- LOGGER.info("{} ---定时统计---",yesStart);
|
|
|
-
|
|
|
- //查询扫码量
|
|
|
- String scanCountSql = "select count(*) from t_scanrecord where scan_time >= '"+yesStart+"' and scan_time <= '"+yesEnd+"'";
|
|
|
- Long scanCountDb = Db.queryLong(scanCountSql);
|
|
|
- int scanCount = scanCountDb == null ? 0 : scanCountDb.intValue();
|
|
|
-
|
|
|
- //查询发放成功的红包总个数
|
|
|
- String hbCountSql = "select count(*) from t_scanrecord where send_time >= '"+yesStart+"' and send_time <= '"+yesEnd+"'";
|
|
|
- Long hbCountDb = Db.queryLong(hbCountSql);
|
|
|
- int hbCount = hbCountDb == null ? 0 : hbCountDb.intValue();
|
|
|
-
|
|
|
- statisticsScanHb(yesStart,yesEnd,day,scanCount,hbCount);
|
|
|
- statisticsDayScanHb(yesStart,yesEnd,day,scanCount,hbCount);
|
|
|
- statisticsDayScanHbDetail(yesStart,yesEnd,day,hbCount);
|
|
|
-
|
|
|
- LOGGER.info("{} 定时统计完成",yesStart);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 统计总的扫码量和发放成功的红包金额
|
|
|
- * @param startTime 统计开始时间
|
|
|
- * @param endTime 统计结束时间
|
|
|
- * @param day 时间的yyyy-MM-dd表示
|
|
|
- */
|
|
|
- private void statisticsScanHb(String startTime,String endTime,String day,int scanCount,int hbTotalCount){
|
|
|
- LOGGER.info("{} 号 开始统计 {} 表数据",day, T_SCAN_HB);
|
|
|
-
|
|
|
- if(hbTotalCount > SINGLE_COUNT){
|
|
|
- //总次数
|
|
|
- int count = hbTotalCount / SINGLE_COUNT;
|
|
|
- //剩余次数
|
|
|
- int residue = hbTotalCount % SINGLE_COUNT;
|
|
|
- int hbAmount = 0;
|
|
|
- int len = 0;
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='" + startTime + "' and send_time<='" + endTime + "' limit " + len + "," + SINGLE_COUNT + "";
|
|
|
- List<Record> listHb = Db.find(sqlHb);
|
|
|
- hbAmount += listHb.parallelStream().mapToInt(r->r.getInt("amount")).sum();
|
|
|
- len += SINGLE_COUNT;
|
|
|
- }
|
|
|
-
|
|
|
- if(residue > 0){
|
|
|
- String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+ hbTotalCount +"";
|
|
|
- List<Record> listHb = Db.find(sqlHb);
|
|
|
- hbAmount += listHb.parallelStream().mapToInt(r->r.getInt("amount")).sum();
|
|
|
- }
|
|
|
- Record record = new Record();
|
|
|
- record.set("day_",day);
|
|
|
- record.set("scan_", scanCount);
|
|
|
- record.set("hb_", hbAmount);
|
|
|
- Db.save(T_SCAN_HB,record);
|
|
|
- }else{
|
|
|
- //查询红包发放金额
|
|
|
- String hbSql = "select sum(amount) from t_scanrecord where send_time >= '"+startTime+"' and send_time <= '"+endTime+"'";
|
|
|
- BigDecimal hbCountDb = Db.queryBigDecimal(hbSql);
|
|
|
- int hbCount = hbCountDb == null ? 0 : hbCountDb.intValue();
|
|
|
- Record record = new Record();
|
|
|
- record.set("day_",day);
|
|
|
- record.set("scan_", scanCount);
|
|
|
- record.set("hb_", hbCount);
|
|
|
- Db.save(T_SCAN_HB,record);
|
|
|
- }
|
|
|
- LOGGER.info("{} 号 {} 表数据 统计完成", day,T_SCAN_HB);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获得扫码map
|
|
|
- * @param startTime 统计开始日期
|
|
|
- * @param endTime 统计结束日期
|
|
|
- * @param day yyyy-MM-dd表示
|
|
|
- * @param scanCount 总扫码次数
|
|
|
- * @return Map<String,Integer>
|
|
|
- */
|
|
|
- private Map<String,Integer> getScanMap(String startTime,String endTime,String day,int scanCount){
|
|
|
- Map<String,Integer> scanMap = new HashMap<>();
|
|
|
- //总次数
|
|
|
- int count = scanCount / SINGLE_COUNT;
|
|
|
- //剩余次数
|
|
|
- int residue = scanCount % SINGLE_COUNT;
|
|
|
- int len = 0;
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- String sqlScan = "select scan_time,type_,area from t_scanrecord where scan_time >='"+startTime+"' and scan_time <= '"+endTime+"' limit "+len+","+ SINGLE_COUNT +"";
|
|
|
- List<Record> listScan = Db.find(sqlScan);
|
|
|
- //统计扫码量
|
|
|
- Map<Integer,List<Record>> typeMap = listScan.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
|
|
|
- List<Record> areaList = typeEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = areaList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
-
|
|
|
- List<Record> resultList = areaEntry.getValue();
|
|
|
- Integer scan = resultList.size();
|
|
|
- //拼接key day_ + type_ + area_
|
|
|
- String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
|
|
|
- if(scanMap.get(key) == null){
|
|
|
- scanMap.put(key,scan);
|
|
|
- }else{
|
|
|
- Integer oldScan = scanMap.get(key);
|
|
|
- scanMap.put(key,oldScan+scan);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- len += SINGLE_COUNT;
|
|
|
- }
|
|
|
-
|
|
|
- if(residue > 0){
|
|
|
- String sqlScan = "select scan_time,type_,area from t_scanrecord where scan_time >='"+startTime+"' and scan_time <= '"+endTime+"' limit "+len+","+ scanCount +"";
|
|
|
- List<Record> listScan = Db.find(sqlScan);
|
|
|
- //统计扫码量
|
|
|
- Map<Integer,List<Record>> typeMap = listScan.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
|
|
|
- List<Record> areaList = typeEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = areaList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
-
|
|
|
- List<Record> resultList = areaEntry.getValue();
|
|
|
- Integer scan = resultList.size();
|
|
|
- //拼接key day_ + type_ + area_
|
|
|
- String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
|
|
|
- if(scanMap.get(key) == null){
|
|
|
- scanMap.put(key,scan);
|
|
|
- }else{
|
|
|
- Integer oldScan = scanMap.get(key);
|
|
|
- scanMap.put(key,oldScan+scan);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return scanMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获得hbmap
|
|
|
- * @param startTime 统计开始时间
|
|
|
- * @param endTime 统计结束时间
|
|
|
- * @param day yyyy-MM-dd表示
|
|
|
- * @param hbCount 总红包发放个数
|
|
|
- * @return Map<String, HbEntity>
|
|
|
- */
|
|
|
- private Map<String, HbEntity> getHbMap(String startTime, String endTime, String day, int hbCount){
|
|
|
- Map<String,HbEntity> hbMap = new HashMap<>();
|
|
|
- //总次数
|
|
|
- int count = hbCount / SINGLE_COUNT;
|
|
|
- //剩余次数
|
|
|
- int residue = hbCount % SINGLE_COUNT;
|
|
|
-
|
|
|
- int len = 0;
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+ SINGLE_COUNT +"";
|
|
|
- List<Record> listHb = Db.find(sqlHb);
|
|
|
- //统计红包和个数
|
|
|
- //对map里的list再根据 type 进行分组
|
|
|
- Map<Integer,List<Record>> typeHbMap = listHb.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeHbMap.entrySet()){
|
|
|
- List<Record> areaList = typeEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = areaList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- HbEntity hbEntity = new HbEntity();
|
|
|
- List<Record> resultList = areaEntry.getValue();
|
|
|
- int hb = resultList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
|
|
|
- long subHbCount = resultList.parallelStream().count();
|
|
|
- hbEntity.setHbAmount(hb);
|
|
|
- hbEntity.setHbCount((int) subHbCount);
|
|
|
-
|
|
|
- String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
|
|
|
-
|
|
|
- if(hbMap.get(key) == null){
|
|
|
- hbMap.put(key,hbEntity);
|
|
|
- }else{
|
|
|
- HbEntity oldHbEntity = hbMap.get(key);
|
|
|
- HbEntity newHbEntity = new HbEntity();
|
|
|
- newHbEntity.setHbAmount(oldHbEntity.getHbAmount()+hbEntity.getHbAmount());
|
|
|
- newHbEntity.setHbCount(oldHbEntity.getHbCount()+hbEntity.getHbCount());
|
|
|
- hbMap.put(key,newHbEntity);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- len += SINGLE_COUNT;
|
|
|
- }
|
|
|
-
|
|
|
- if(residue > 0){
|
|
|
- String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+ hbCount +"";
|
|
|
- List<Record> listHb = Db.find(sqlHb);
|
|
|
- //统计红包和个数
|
|
|
- //对map里的list再根据 type 进行分组
|
|
|
- Map<Integer,List<Record>> typeHbMap = listHb.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeHbMap.entrySet()){
|
|
|
- List<Record> areaList = typeEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = areaList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- HbEntity hbEntity = new HbEntity();
|
|
|
- List<Record> resultList = areaEntry.getValue();
|
|
|
- int hb = resultList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
|
|
|
- long subHbCount = resultList.parallelStream().count();
|
|
|
- hbEntity.setHbAmount(hb);
|
|
|
- hbEntity.setHbCount((int) subHbCount);
|
|
|
-
|
|
|
- String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
|
|
|
-
|
|
|
- if(hbMap.get(key) == null){
|
|
|
- hbMap.put(key,hbEntity);
|
|
|
- }else{
|
|
|
- HbEntity oldHbEntity = hbMap.get(key);
|
|
|
- HbEntity newHbEntity = new HbEntity();
|
|
|
- newHbEntity.setHbAmount(oldHbEntity.getHbAmount()+hbEntity.getHbAmount());
|
|
|
- newHbEntity.setHbCount(oldHbEntity.getHbCount()+hbEntity.getHbCount());
|
|
|
- hbMap.put(key,newHbEntity);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return hbMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据品相和区域分组统计扫码量,红包发放个数和红包发放金额
|
|
|
- * @param startTime 统计开始时间
|
|
|
- * @param endTime 统计结束时间
|
|
|
- * @param day 时间的yyyy-MM-dd表示
|
|
|
- * @param scanCount 总的扫码量
|
|
|
- * @param hbCount 发放成功的红包数量
|
|
|
- */
|
|
|
- private void statisticsDayScanHb(String startTime,String endTime,String day,int scanCount,int hbCount) {
|
|
|
- LOGGER.info("{} 号 开始统计 {} 表数据",day, T_DAY_SCAN_HB);
|
|
|
-
|
|
|
- if(scanCount > SINGLE_COUNT) {
|
|
|
- Map<String, ScanHbEntity> scanHbMap = new HashMap<>();
|
|
|
- Map<String, Integer> scanMap = getScanMap(startTime, endTime, day, scanCount);
|
|
|
-
|
|
|
- Map<String,HbEntity> hbMap = getHbMap(startTime,endTime,day,hbCount);
|
|
|
-
|
|
|
- for(Map.Entry<String,Integer> scanEntry:scanMap.entrySet()){
|
|
|
- ScanHbEntity scanHbEntity = new ScanHbEntity();
|
|
|
- scanHbEntity.setScanCount(scanEntry.getValue());
|
|
|
- scanHbMap.put(scanEntry.getKey(),scanHbEntity);
|
|
|
- }
|
|
|
-
|
|
|
- for(Map.Entry<String,HbEntity> hbEntity:hbMap.entrySet()){
|
|
|
- if(scanHbMap.get(hbEntity.getKey()) != null){
|
|
|
- ScanHbEntity scanHbEntity = scanHbMap.get(hbEntity.getKey());
|
|
|
- scanHbEntity.setHbAmount(hbEntity.getValue().getHbAmount());
|
|
|
- scanHbEntity.setHbCount(hbEntity.getValue().getHbCount());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for(Map.Entry<String,ScanHbEntity> scanHbEntry:scanHbMap.entrySet()){
|
|
|
- Record record = new Record();
|
|
|
- String[] dta = scanHbEntry.getKey().split(SPLIT);
|
|
|
- record.set("day_",dta[0]);
|
|
|
- record.set("type_",dta[1]);
|
|
|
- record.set("area_",dta[2]);
|
|
|
- record.set("scan_",scanHbEntry.getValue().getScanCount());
|
|
|
- record.set("hb_",scanHbEntry.getValue().getHbAmount());
|
|
|
- record.set("hbc_",scanHbEntry.getValue().getHbCount());
|
|
|
- Db.save(T_DAY_SCAN_HB,record);
|
|
|
- }
|
|
|
-
|
|
|
- }else{
|
|
|
- String sqlScan = "select scan_time,type_,area from t_scanrecord where scan_time >='"+startTime+"' and scan_time<='"+endTime+"'";
|
|
|
- List<Record> listScan = Db.find(sqlScan);
|
|
|
- //统计扫码量
|
|
|
- Map<Integer,List<Record>> typeMap = listScan.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
|
|
|
- List<Record> areaList = typeEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = areaList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- Record typeRecord = new Record();
|
|
|
- typeRecord.set("day_",day);
|
|
|
- typeRecord.set("type_",typeEntry.getKey());
|
|
|
- typeRecord.set("area_",areaEntry.getKey());
|
|
|
-
|
|
|
- List<Record> resultList = areaEntry.getValue();
|
|
|
- Integer scan = resultList.size();
|
|
|
- typeRecord.set("scan_",scan);
|
|
|
-
|
|
|
- Db.save(T_DAY_SCAN_HB,typeRecord);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"'";
|
|
|
- List<Record> listHb = Db.find(sqlHb);
|
|
|
- //统计红包和个数
|
|
|
- //对map里的list再根据 type 进行分组
|
|
|
- Map<Integer,List<Record>> typeHbMap = listHb.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- String sql = "select * from "+ T_DAY_SCAN_HB +" where day_ = ? and type_ = ? and area_ = ? limit 1";
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeHbMap.entrySet()){
|
|
|
- List<Record> areaList = typeEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = areaList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- Record typeRecord = Db.findFirst(sql,day,typeEntry.getKey(),areaEntry.getKey());
|
|
|
- if(typeRecord == null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<Record> resultList = areaEntry.getValue();
|
|
|
- int hb = resultList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
|
|
|
- long count = resultList.parallelStream()
|
|
|
- .count();
|
|
|
- typeRecord.set("hb_",hb);
|
|
|
- typeRecord.set("hbc_", (int) count);
|
|
|
- Db.update(T_DAY_SCAN_HB,typeRecord);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- LOGGER.info("{} 号 {} 表数据 统计完成",day,T_DAY_SCAN_HB);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 统计每种红包金额的发放个数和发放的金额
|
|
|
- * 并统计每种红包金额在不同品相和区域发放的个数和发放的金额
|
|
|
- * @param startTime 统计开始时间
|
|
|
- * @param endTime 统计结束时间
|
|
|
- * @param day 时间的yyyy-MM-dd表示
|
|
|
- * @param hbCount 发放成功的红包数量
|
|
|
- */
|
|
|
- private void statisticsDayScanHbDetail(String startTime,String endTime,String day,int hbCount){
|
|
|
- LOGGER.info("{} 号 开始统计 {}表 和 {} 表数据",day,T_DAY_HB,T_DAY_HB_DETAIL);
|
|
|
-
|
|
|
- if(hbCount > SINGLE_COUNT){
|
|
|
- int count = hbCount / SINGLE_COUNT;
|
|
|
- int residue = hbCount % SINGLE_COUNT;
|
|
|
- int len = 0;
|
|
|
- Map<String, DayHbEntity> dayHbMap = new HashMap<>();
|
|
|
- Map<String,DayHbEntity> dayHbDetailMap = new HashMap<>();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- String sql = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+SINGLE_COUNT+"";
|
|
|
- List<Record> listHb = Db.find(sql);
|
|
|
-
|
|
|
- Map<Integer,List<Record>> amountMap = listHb.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
|
|
|
- TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(amountMap);
|
|
|
-
|
|
|
- //给map按照key排序
|
|
|
- List<Map.Entry<Integer,List<Record>>> amountKeyList = new ArrayList<>(amtTreeMap.entrySet());
|
|
|
- amountKeyList.sort(Comparator.comparing(Map.Entry::getKey));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> amountEntry:amtTreeMap.entrySet()){
|
|
|
- List<Record> amountList = amountEntry.getValue();
|
|
|
- if(!amountList.isEmpty()){
|
|
|
- String dayHbKey = day +SPLIT+amountEntry.getKey();
|
|
|
- if(dayHbMap.get(dayHbKey) == null){
|
|
|
- DayHbEntity dayHbEntity = new DayHbEntity();
|
|
|
- dayHbEntity.setHb(amountEntry.getKey());
|
|
|
- dayHbEntity.setHbCount(amountList.size());
|
|
|
- dayHbMap.put(dayHbKey,dayHbEntity);
|
|
|
- }else{
|
|
|
- DayHbEntity oldDayHbEntity = dayHbMap.get(dayHbKey);
|
|
|
- DayHbEntity newDayHbEntity = new DayHbEntity();
|
|
|
- newDayHbEntity.setHb(oldDayHbEntity.getHb());
|
|
|
- newDayHbEntity.setHbCount(oldDayHbEntity.getHbCount()+amountList.size());
|
|
|
- dayHbMap.put(dayHbKey,newDayHbEntity);
|
|
|
- }
|
|
|
-
|
|
|
- Map<Integer,List<Record>> typeMap = amountList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
|
|
|
- List<Record> typeList = typeEntry.getValue();
|
|
|
- if(!typeList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = typeList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- List<Record> areaList = areaEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
-
|
|
|
- //Integer hbt = areaList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
|
|
|
- long hbc = areaList.parallelStream().count();
|
|
|
- String key = day +SPLIT+amountEntry.getKey()+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
|
|
|
- if(dayHbDetailMap.get(key) == null){
|
|
|
- DayHbEntity dayHbEntity = new DayHbEntity();
|
|
|
- dayHbEntity.setHb(amountEntry.getKey());
|
|
|
- dayHbEntity.setHbCount((int) hbc);
|
|
|
- dayHbDetailMap.put(key,dayHbEntity);
|
|
|
- }else{
|
|
|
- DayHbEntity oldDayHbEntity = dayHbDetailMap.get(key);
|
|
|
- DayHbEntity newDayHbEntity = new DayHbEntity();
|
|
|
- newDayHbEntity.setHb(oldDayHbEntity.getHb());
|
|
|
- newDayHbEntity.setHbCount((int) (oldDayHbEntity.getHbCount()+hbc));
|
|
|
- dayHbDetailMap.put(key,newDayHbEntity);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- len += SINGLE_COUNT;
|
|
|
- }
|
|
|
-
|
|
|
- if(residue > 0){
|
|
|
- String sql = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+hbCount+"";
|
|
|
- List<Record> listHb = Db.find(sql);
|
|
|
- Map<Integer,List<Record>> amountMap = listHb.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
|
|
|
- TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(amountMap);
|
|
|
-
|
|
|
- //给map按照key排序
|
|
|
- List<Map.Entry<Integer,List<Record>>> amountKeyList = new ArrayList<>(amtTreeMap.entrySet());
|
|
|
- amountKeyList.sort(Comparator.comparing(Map.Entry::getKey));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> amountEntry:amtTreeMap.entrySet()){
|
|
|
- List<Record> amountList = amountEntry.getValue();
|
|
|
- if(!amountList.isEmpty()){
|
|
|
- String dayHbKey = day +SPLIT+amountEntry.getKey();
|
|
|
- if(dayHbMap.get(dayHbKey) == null){
|
|
|
- DayHbEntity dayHbEntity = new DayHbEntity();
|
|
|
- dayHbEntity.setHb(amountEntry.getKey());
|
|
|
- dayHbEntity.setHbCount(amountList.size());
|
|
|
- dayHbMap.put(dayHbKey,dayHbEntity);
|
|
|
- }else{
|
|
|
- DayHbEntity oldDayHbEntity = dayHbMap.get(dayHbKey);
|
|
|
- DayHbEntity newDayHbEntity = new DayHbEntity();
|
|
|
- newDayHbEntity.setHb(oldDayHbEntity.getHb());
|
|
|
- newDayHbEntity.setHbCount(oldDayHbEntity.getHbCount()+amountList.size());
|
|
|
- dayHbMap.put(dayHbKey,newDayHbEntity);
|
|
|
- }
|
|
|
-
|
|
|
- Map<Integer,List<Record>> typeMap = amountList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
|
|
|
- List<Record> typeList = typeEntry.getValue();
|
|
|
- if(!typeList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = typeList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- List<Record> areaList = areaEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
-
|
|
|
- //Integer hbt = areaList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
|
|
|
- long hbc = areaList.parallelStream().count();
|
|
|
- String key = day +SPLIT+amountEntry.getKey()+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
|
|
|
- if(dayHbDetailMap.get(key) == null){
|
|
|
- DayHbEntity dayHbEntity = new DayHbEntity();
|
|
|
- dayHbEntity.setHb(amountEntry.getKey());
|
|
|
- dayHbEntity.setHbCount((int) hbc);
|
|
|
- dayHbDetailMap.put(key,dayHbEntity);
|
|
|
- }else{
|
|
|
- DayHbEntity oldDayHbEntity = dayHbDetailMap.get(key);
|
|
|
- DayHbEntity newDayHbEntity = new DayHbEntity();
|
|
|
- newDayHbEntity.setHb(oldDayHbEntity.getHb());
|
|
|
- newDayHbEntity.setHbCount((int) (oldDayHbEntity.getHbCount()+hbc));
|
|
|
- dayHbDetailMap.put(key,newDayHbEntity);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for(Map.Entry<String,DayHbEntity> dayHbEntry:dayHbMap.entrySet()){
|
|
|
- Record amountRecord = new Record();
|
|
|
- amountRecord.set("day_",day);
|
|
|
- amountRecord.set("hb_",dayHbEntry.getValue().getHb());
|
|
|
- amountRecord.set("hbc_",dayHbEntry.getValue().getHbCount());
|
|
|
- amountRecord.set("hbt_",dayHbEntry.getValue().getHbAmount());
|
|
|
- Db.save(T_DAY_HB,amountRecord);
|
|
|
- }
|
|
|
-
|
|
|
- for(Map.Entry<String,DayHbEntity> dayHbDetailEntry:dayHbDetailMap.entrySet()){
|
|
|
- Record typeRecord = new Record();
|
|
|
- String[] dta = dayHbDetailEntry.getKey().split(SPLIT);
|
|
|
- typeRecord.set("hb_",dayHbDetailEntry.getValue().getHb());
|
|
|
- typeRecord.set("day_",day);
|
|
|
- typeRecord.set("type_",dta[2]);
|
|
|
- typeRecord.set("area_",dta[3]);
|
|
|
- typeRecord.set("hbc_",dayHbDetailEntry.getValue().getHbCount());
|
|
|
- typeRecord.set("hbt_",dayHbDetailEntry.getValue().getHbAmount());
|
|
|
- Db.save(T_DAY_HB_DETAIL,typeRecord);
|
|
|
- }
|
|
|
-
|
|
|
- }else{
|
|
|
- String sql = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"'";
|
|
|
- List<Record> listHb = Db.find(sql);
|
|
|
- //需要过滤掉未发送成功的
|
|
|
- Map<Integer,List<Record>> amountMap = listHb.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
|
|
|
-
|
|
|
- TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(amountMap);
|
|
|
-
|
|
|
- //给map按照key排序
|
|
|
- List<Map.Entry<Integer,List<Record>>> amountKeyList = new ArrayList<>(amtTreeMap.entrySet());
|
|
|
- amountKeyList.sort(Comparator.comparing(Map.Entry::getKey));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> amountEntry:amtTreeMap.entrySet()){
|
|
|
- List<Record> amountList = amountEntry.getValue();
|
|
|
- if(!amountList.isEmpty()){
|
|
|
- Record amountRecord = new Record();
|
|
|
- amountRecord.set("day_",day);
|
|
|
- amountRecord.set("hb_",amountEntry.getKey());
|
|
|
- amountRecord.set("hbc_",amountList.size());
|
|
|
- amountRecord.set("hbt_",amountEntry.getKey()*amountList.size());
|
|
|
- Db.save(T_DAY_HB,amountRecord);
|
|
|
-
|
|
|
- Map<Integer,List<Record>> typeMap = amountList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
|
|
|
- List<Record> typeList = typeEntry.getValue();
|
|
|
- if(!typeList.isEmpty()){
|
|
|
- Map<String,List<Record>> areaMap = typeList.parallelStream()
|
|
|
- .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
|
|
|
-
|
|
|
- for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
|
|
|
- List<Record> areaList = areaEntry.getValue();
|
|
|
- if(!areaList.isEmpty()){
|
|
|
- Record typeRecord = new Record();
|
|
|
- typeRecord.set("hb_",amountEntry.getKey());
|
|
|
- typeRecord.set("day_",day);
|
|
|
- typeRecord.set("type_",typeEntry.getKey());
|
|
|
- typeRecord.set("area_",areaEntry.getKey());
|
|
|
-
|
|
|
- Integer hbt = areaList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
|
|
|
- long hbc = areaList.parallelStream()
|
|
|
- .count();
|
|
|
- typeRecord.set("hbc_", (int) hbc);
|
|
|
- typeRecord.set("hbt_",hbt);
|
|
|
-
|
|
|
- Db.save(T_DAY_HB_DETAIL,typeRecord);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- LOGGER.info("{} 号 {} 和 {} 表数据 统计完成",day,T_DAY_HB,T_DAY_HB_DETAIL);
|
|
|
- }
|
|
|
-}
|