From 07d7995a6a7a097c1f27db30d10d26be3dfb33b9 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Thu, 2 Aug 2018 20:03:33 +0800 Subject: [PATCH] update --- .../impls/CustomerImpressionImplTest.java | 249 ++++++++++++++---- 1 file changed, 202 insertions(+), 47 deletions(-) diff --git a/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java b/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java index e61eae7ae..051952185 100644 --- a/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java +++ b/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java @@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.Test; +import org.springframework.data.redis.core.BoundListOperations; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.RequestMethod; @@ -31,13 +32,18 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.math.BigDecimal; import java.net.URISyntaxException; import java.nio.charset.Charset; +import java.text.ParseException; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import javax.annotation.Resource; @@ -73,49 +79,198 @@ public class CustomerImpressionImplTest { @Resource private WeekReporter weekReporter; - // @Test - // public void redisQueue() { - // BoundListOperations ops = stringRedisTemplate.boundListOps("customer_impression"); - // JSONObject order = orderMapper.find("00009201711300930013961422"); - // for (int i = 0; i < 10000; i++) { - // ops.rightPush(order.toJSONString()); - // - // } - // } - - // @Test - // public void excel() { - // try { - // XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx"))); - // XSSFSheet sheet = workbook.getSheetAt(0); - // Iterator rowIterator = sheet.rowIterator(); - // Row row = null; - // Cell cell = null; - // while (rowIterator.hasNext()) { - // row = rowIterator.next(); - // cell = row.getCell(3); - // cell.setCellType(HSSFCell.CELL_TYPE_STRING); - // - // JSONObject client = clientMapper.findClientByMoniker(cell.getStringCellValue().trim()); - // if(client==null){ - // System.out.println(); - // continue; - // } - // JSONObject org = orgMapper.findOne(client.getIntValue("org_id")); - // if(org==null){ - // continue; - // } - // - // row.createCell(5).setCellValue(org.getString("name")); - // } - // - // OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx"); - // workbook.write(out); - // workbook.close(); - // } catch (IOException e) { - // e.printStackTrace(); - // } - // } + + @Test + public void redisQueue() { + BoundListOperations ops = stringRedisTemplate.boundListOps("customer_impression"); + JSONObject order = orderMapper.find("00009201711300930013961422"); + for (int i = 0; i < 10000; i++) { + ops.rightPush(order.toJSONString()); + + } + } + + @Test + public void excel1() { + try { + XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx"))); + XSSFSheet sheet = workbook.getSheetAt(0); + Iterator rowIterator = sheet.rowIterator(); + Row row = null; + Cell cell = null; + Map> result = new HashMap<>(); + while (rowIterator.hasNext()) { + row = rowIterator.next(); + cell = row.getCell(0); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + + String amount = cell.getStringCellValue().trim(); + cell = row.getCell(1); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + String dateStr = cell.getStringCellValue(); + + cell = row.getCell(2); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + String clientId = cell.getStringCellValue(); + + if (result.containsKey(clientId)) { + result.get(clientId).put(dateStr, amount); + } else { + Map ele = new HashMap<>(); + ele.put(dateStr, amount); + result.put(clientId, ele); + } + } + Set clients = new HashSet<>(); + + result.entrySet().parallelStream().forEach(p -> { + + p.getValue().entrySet().parallelStream().forEach(o -> { + BigDecimal insAvg = BigDecimal.valueOf(Double.valueOf(o.getValue())); + BigDecimal pastTotal = BigDecimal.ZERO; + for (int i = 1; i < 4; i++) { + if (i == 1) { + pastTotal = BigDecimal.ZERO; + } + try { + Date tmp = DateUtils.addMonths(DateUtils.parseDate(o.getKey(),"YYYYMM"),(-i+1)); + String pastKey = String.valueOf(tmp.getYear()+1900)+ String.valueOf(tmp.getMonth()); + + if (p.getValue().containsKey(String.valueOf(pastKey))) { + BigDecimal pastAvgtmp = BigDecimal.valueOf(Double.parseDouble(p.getValue().get(String.valueOf(pastKey)))); + pastTotal = pastTotal.add(pastAvgtmp); + } else { + i = 10; + } + + if (i == 3) { + try { + BigDecimal pastAvg = pastTotal.divide(BigDecimal.valueOf(3L),5,BigDecimal.ROUND_HALF_DOWN); + if (pastAvg.compareTo(BigDecimal.ZERO) > 0) { + if (insAvg.divide(pastAvg,5,BigDecimal.ROUND_HALF_DOWN).intValue()>3) { + clients.add(p.getKey()); + } + } + } catch (Exception ignore) { + + } + } + } catch (ParseException e) { + } + + } + + }); + }); + + + clients.forEach(p->{ + System.out.println(p); + }); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + + OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx"); + workbook.write(out); + workbook.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void excel2() { + try { + XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/qwe.xlsx"))); + XSSFSheet sheet = workbook.getSheetAt(0); + Iterator rowIterator = sheet.rowIterator(); + Row row = null; + Cell cell = null; + Map> result = new HashMap<>(); + while (rowIterator.hasNext()) { + row = rowIterator.next(); + cell = row.getCell(3); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + String orders = cell.getStringCellValue().trim(); + + + + cell = row.getCell(1); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + String dateStr = cell.getStringCellValue(); + + cell = row.getCell(2); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + String clientId = cell.getStringCellValue(); + + if (result.containsKey(clientId)) { + result.get(clientId).put(dateStr, orders); + } else { + LinkedHashMap ele = new LinkedHashMap<>(); + ele.put(dateStr, orders); + result.put(clientId, ele); + } + } + Set clients = new HashSet<>(); + + + for (Map.Entry> p : result.entrySet()) { + int count = 1; + for (Map.Entry o : p.getValue().entrySet()) { + count+=1; + for (int i = 1; i < 4; i++) { + if(p.getValue().size()<4 && count==p.getValue().size()){ + try { + if(DateUtils.addMonths(DateUtils.parseDate(o.getKey(),"YYYYMM"),3).compareTo(new Date())<0){ + clients.add(p.getKey()); + } + } catch (ParseException e) { + } + } + + Date tmp = null; + try { + tmp = DateUtils.addMonths(DateUtils.parseDate(o.getKey(),"YYYYMM"),i); + String pastKey = String.valueOf(tmp.getYear()+1900)+ String.valueOf(tmp.getMonth()); + if (p.getValue().containsKey(String.valueOf(pastKey))) { + i = 10; + }else { + if(i==3 && (Integer.valueOf(o.getValue())>99)){ + clients.add(p.getKey()); + } + } + + } catch (ParseException e) { + e.printStackTrace(); + } + + } + + } + + } + + + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + System.out.println(clients.size()); + +// OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx"); +// workbook.write(out); + workbook.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } @Test public void sendSimpleMessage() throws Exception { @@ -359,16 +514,16 @@ public class CustomerImpressionImplTest { public String recursionIndustry(JSONArray jsonArray, String mccCode) { String result = ""; for (Object o : jsonArray) { - if(StringUtils.isNotEmpty(result)){ + if (StringUtils.isNotEmpty(result)) { break; } JSONObject tmp = (JSONObject) o; if (tmp.getString("mccCode").equals(mccCode)) { result = tmp.getString("label"); - }else { - if(tmp.getJSONArray("children")!=null){ + } else { + if (tmp.getJSONArray("children") != null) { result = recursionIndustry(tmp.getJSONArray("children"), mccCode); - }else { + } else { result = ""; } }