|
|
@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.Row;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.springframework.data.redis.core.BoundListOperations;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
|
|
|
|
|
@ -31,13 +32,18 @@ import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
@ -73,49 +79,198 @@ public class CustomerImpressionImplTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private WeekReporter weekReporter;
|
|
|
|
private WeekReporter weekReporter;
|
|
|
|
// @Test
|
|
|
|
|
|
|
|
// public void redisQueue() {
|
|
|
|
@Test
|
|
|
|
// BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
|
|
|
public void redisQueue() {
|
|
|
|
// JSONObject order = orderMapper.find("00009201711300930013961422");
|
|
|
|
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
|
|
|
// for (int i = 0; i < 10000; i++) {
|
|
|
|
JSONObject order = orderMapper.find("00009201711300930013961422");
|
|
|
|
// ops.rightPush(order.toJSONString());
|
|
|
|
for (int i = 0; i < 10000; i++) {
|
|
|
|
//
|
|
|
|
ops.rightPush(order.toJSONString());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// @Test
|
|
|
|
|
|
|
|
// public void excel() {
|
|
|
|
@Test
|
|
|
|
// try {
|
|
|
|
public void excel1() {
|
|
|
|
// XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx")));
|
|
|
|
try {
|
|
|
|
// XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx")));
|
|
|
|
// Iterator<Row> rowIterator = sheet.rowIterator();
|
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
|
// Row row = null;
|
|
|
|
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
|
|
// Cell cell = null;
|
|
|
|
Row row = null;
|
|
|
|
// while (rowIterator.hasNext()) {
|
|
|
|
Cell cell = null;
|
|
|
|
// row = rowIterator.next();
|
|
|
|
Map<String, Map<String, String>> result = new HashMap<>();
|
|
|
|
// cell = row.getCell(3);
|
|
|
|
while (rowIterator.hasNext()) {
|
|
|
|
// cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
|
row = rowIterator.next();
|
|
|
|
//
|
|
|
|
cell = row.getCell(0);
|
|
|
|
// JSONObject client = clientMapper.findClientByMoniker(cell.getStringCellValue().trim());
|
|
|
|
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
|
// if(client==null){
|
|
|
|
|
|
|
|
// System.out.println();
|
|
|
|
String amount = cell.getStringCellValue().trim();
|
|
|
|
// continue;
|
|
|
|
cell = row.getCell(1);
|
|
|
|
// }
|
|
|
|
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
|
// JSONObject org = orgMapper.findOne(client.getIntValue("org_id"));
|
|
|
|
String dateStr = cell.getStringCellValue();
|
|
|
|
// if(org==null){
|
|
|
|
|
|
|
|
// continue;
|
|
|
|
cell = row.getCell(2);
|
|
|
|
// }
|
|
|
|
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
|
//
|
|
|
|
String clientId = cell.getStringCellValue();
|
|
|
|
// row.createCell(5).setCellValue(org.getString("name"));
|
|
|
|
|
|
|
|
// }
|
|
|
|
if (result.containsKey(clientId)) {
|
|
|
|
//
|
|
|
|
result.get(clientId).put(dateStr, amount);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Map<String, String> ele = new HashMap<>();
|
|
|
|
|
|
|
|
ele.put(dateStr, amount);
|
|
|
|
|
|
|
|
result.put(clientId, ele);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<String> 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<Row> rowIterator = sheet.rowIterator();
|
|
|
|
|
|
|
|
Row row = null;
|
|
|
|
|
|
|
|
Cell cell = null;
|
|
|
|
|
|
|
|
Map<String, LinkedHashMap<String, String>> 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<String, String> ele = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
ele.put(dateStr, orders);
|
|
|
|
|
|
|
|
result.put(clientId, ele);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<String> clients = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, LinkedHashMap<String, String>> p : result.entrySet()) {
|
|
|
|
|
|
|
|
int count = 1;
|
|
|
|
|
|
|
|
for (Map.Entry<String, String> 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");
|
|
|
|
// OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx");
|
|
|
|
// workbook.write(out);
|
|
|
|
// workbook.write(out);
|
|
|
|
// workbook.close();
|
|
|
|
workbook.close();
|
|
|
|
// } catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void sendSimpleMessage() throws Exception {
|
|
|
|
public void sendSimpleMessage() throws Exception {
|
|
|
|