|
@ -2490,12 +2490,13 @@ public class StatisticsAllService extends BaseService {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
//获取微信关注的未交费
|
|
|
Map<String, Integer> expenseStatus0 = getByIndex(date, area, level, "49", sort, lowLevel, dateFormat);
|
|
|
//获取微信关注的已交费
|
|
|
Map<String, Integer> expenseStatus1 = getByIndex(date, area, level, "50", sort, lowLevel, dateFormat);
|
|
|
//获取已缴费的签约数
|
|
|
Map<String, Integer> expenseStatus1Sigjn = getByIndex(date, area, level, "1", sort, lowLevel, dateFormat);
|
|
|
|
|
|
if (date.compareTo(dateFormat.format(new Date())) >= 0) {
|
|
|
resultList = getTodayLowLevelTotal(area, level, index, sort, lowLevel);
|
|
|
} else {
|
|
|
resultList = getTodayBeforeLowLevelTotal(date, area, level, index, sort, lowLevel);
|
|
|
}
|
|
|
|
|
|
// 结果为空时,自建结果集
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
@ -2505,98 +2506,34 @@ public class StatisticsAllService extends BaseService {
|
|
|
if (resultList != null) {
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
Integer expenseStatus0amountNum = expenseStatus0.get(map.get("code").toString());
|
|
|
Integer expenseStatus1amountNum = expenseStatus1.get(map.get("code").toString());
|
|
|
Integer expenseStatus1SigjnNum = expenseStatus1Sigjn.get(map.get("code").toString());
|
|
|
|
|
|
map.put("amount", map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L);
|
|
|
map.put("weChatAmount0", expenseStatus0amountNum);//微信关注未交费数
|
|
|
map.put("weChatAmount1", expenseStatus1amountNum);//微信关注已交费数
|
|
|
map.put("signAccount", expenseStatus1SigjnNum);//签约已缴费的数目
|
|
|
map.put("bindDoubleRate", getRangeDouuble(expenseStatus1amountNum, expenseStatus1SigjnNum, 2));//微信关注率
|
|
|
|
|
|
if (!low_level.equals("1")) {
|
|
|
String redisNum = "";
|
|
|
try {
|
|
|
redisNum = redisTemplate.opsForValue().get("people:num:" + map.get("code").toString());
|
|
|
} catch (Exception e) {
|
|
|
redisNum = "";
|
|
|
}
|
|
|
if (StringUtils.isEmpty(redisNum)) {
|
|
|
PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(), Integer.valueOf(Constant.getNowYear()));
|
|
|
if (peopleNum != null) {
|
|
|
map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
|
|
|
map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getTaskNum() * 100));
|
|
|
map.put("targetRate", df.format(peopleNum.getTaskNum() * 1.0000 / peopleNum.getNum() * 100));
|
|
|
map.put("rateString", map.get("amount") + "/" + peopleNum.getNum());
|
|
|
map.put("taskRateString", map.get("amount") + "/" + peopleNum.getTaskNum());
|
|
|
map.put("targetRateString", peopleNum.getTaskNum() + "/" + peopleNum.getNum());
|
|
|
map.put("num", peopleNum.getNum());
|
|
|
map.put("task", peopleNum.getTaskNum());
|
|
|
}
|
|
|
} else {
|
|
|
JSONObject peopleNum = new JSONObject(redisNum);
|
|
|
if (peopleNum != null) {
|
|
|
map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("num") * 100));
|
|
|
map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("taskNum") * 100));
|
|
|
map.put("targetRate", df.format(peopleNum.getInt("taskNum") * 1.0000 / peopleNum.getInt("num") * 100));
|
|
|
map.put("rateString", map.get("amount") + "/" + peopleNum.getInt("num"));
|
|
|
map.put("taskRateString", map.get("amount") + "/" + peopleNum.getInt("taskNum"));
|
|
|
map.put("targetRateString", peopleNum.getInt("taskNum") + "/" + peopleNum.getInt("num"));
|
|
|
map.put("num", peopleNum.getInt("num"));
|
|
|
map.put("task", peopleNum.getInt("taskNum"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Collections.sort(resultList, new Comparator<Map<String, Object>>() {
|
|
|
if ((level == 4 && "1".equals(lowLevel)) || (level == 2)) {
|
|
|
translateTeamLeaderName(resultList);
|
|
|
}
|
|
|
// 排序 按绑定率来排序
|
|
|
resultList.sort(new Comparator<Map<String, Object>>() {
|
|
|
@Override
|
|
|
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
|
|
long map1value = (long) o1.get("amount");
|
|
|
long map2value = (long) o2.get("amount");
|
|
|
|
|
|
if (map1value - map2value > 0) {
|
|
|
return sort == 1 ? -1 : 1;
|
|
|
} else if (map1value - map2value < 0) {
|
|
|
return sort == 1 ? 1 : -1;
|
|
|
if ((double) o1.get("bindDoubleRate") >= (double) o2.get("bindDoubleRate")) {
|
|
|
return -1;
|
|
|
} else if ((double) o1.get("bindDoubleRate") < (double) o2.get("bindDoubleRate")) {
|
|
|
return 1;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
//计算签约人数
|
|
|
List<Map<String, Object>> signList = getTodayLowLevelTotal2(area, level, "1", sort, lowLevel);
|
|
|
Map<String, Object> signMap = new HashMap<>();
|
|
|
if (signList != null && signList.size() > 0) {
|
|
|
//将List转化为Map减小循环层数
|
|
|
for (Map<String, Object> sign : signList) {
|
|
|
signMap.put(sign.get("code").toString(), sign);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
Long bindCout = (Long) map.get("amount");
|
|
|
Map<String, Object> sMap = (Map<String, Object>) signMap.get(map.get("code").toString());
|
|
|
Long signCout = (Long) sMap.get("amount");
|
|
|
if ((signCout != null && signCout != 0) && (bindCout != null && bindCout != 0)) {
|
|
|
double rate = (double) bindCout / signCout * 100;
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
|
|
map.put("bindRate", decimalFormat.format(rate) + "%");
|
|
|
map.put("bindDoubleRate", rate);
|
|
|
} else {
|
|
|
map.put("bindRate", "0.00%");
|
|
|
map.put("bindDoubleRate", 0.00);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ((level == 4 && "1".equals(lowLevel)) || (level == 2)) {
|
|
|
translateTeamLeaderName(resultList);
|
|
|
}
|
|
|
// 排序 按绑定率来排序
|
|
|
// resultList.sort(new Comparator<Map<String, Object>>() {
|
|
|
// @Override
|
|
|
// public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
|
|
// if ((double) o1.get("bindDoubleRate") >= (double) o2.get("bindDoubleRate")) {
|
|
|
// return -1;
|
|
|
// } else if ((double) o1.get("bindDoubleRate") < (double) o2.get("bindDoubleRate")) {
|
|
|
// return 1;
|
|
|
// } else {
|
|
|
// return 0;
|
|
|
// }
|
|
|
// }
|
|
|
// });
|
|
|
|
|
|
return new JSONArray(resultList);
|
|
|
} else {
|
|
@ -2604,6 +2541,35 @@ public class StatisticsAllService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取某个指标某一天某一level的值 到达量
|
|
|
*
|
|
|
* @param date
|
|
|
* @param area
|
|
|
* @param level
|
|
|
* @param index
|
|
|
* @param sort
|
|
|
* @param lowLevel
|
|
|
* @param dateFormat
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
private Map<String, Integer> getByIndex(String date, String area, int level, String index, int sort, String lowLevel, SimpleDateFormat dateFormat) throws Exception {
|
|
|
Map<String, Integer> returnMap = new HashMap<>();
|
|
|
List<Map<String, Object>> resultList;//获取未交费微信关注
|
|
|
if (date.compareTo(dateFormat.format(new Date())) >= 0) {
|
|
|
resultList = getTodayLowLevelTotal(area, level, index, sort, lowLevel);
|
|
|
} else {
|
|
|
resultList = getTodayBeforeLowLevelTotal(date, area, level, index, sort, lowLevel);
|
|
|
}
|
|
|
if (resultList != null && resultList.size() > 0) {
|
|
|
resultList.stream().forEach(one -> {
|
|
|
returnMap.put(one.get("code").toString(), Integer.valueOf(one.get("amount").toString()));
|
|
|
});
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询签约人数
|
|
|
*
|
|
@ -2865,7 +2831,19 @@ public class StatisticsAllService extends BaseService {
|
|
|
String filesize = df.format(size);
|
|
|
return filesize + "%";
|
|
|
}
|
|
|
|
|
|
public double getRangeDouuble(int first, int second, int i) {
|
|
|
if (second == 0 && first > 0) {
|
|
|
//如果分母为0 分子不为0 返回100%
|
|
|
return 100;
|
|
|
} else if (second == 0 && first == 0) {
|
|
|
//如果分母为0 分子为0 返回0%
|
|
|
return 0;
|
|
|
}
|
|
|
float size = (float) (first * 100) / second;
|
|
|
DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0
|
|
|
String filesize = df.format(size);
|
|
|
return Double.valueOf(filesize);
|
|
|
}
|
|
|
public JSONArray getLevelTwoLowLevelTotalSignAndRenew(String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
|
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|