|
@ -18,7 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
@ -1283,4 +1283,214 @@ public class StatisticsService extends BaseService {
|
|
|
StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM wlyy_sign_family f WHERE f.type='2' AND f.`status`>0 AND f.expenses_status='1' ");
|
|
|
return sql.toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计回复和未回复
|
|
|
* @param level
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONObject getConsultingStatisticsList(int level,String area,String lowLevel)throws Exception{
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
//级别为市级,统计区级统计区和机构
|
|
|
if(level == 4){
|
|
|
|
|
|
if(StringUtils.isBlank(lowLevel)){
|
|
|
String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
|
|
|
//及时回复数
|
|
|
|
|
|
String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":3:"+timeKey);
|
|
|
JSONArray rely = new JSONArray(relyVal);
|
|
|
|
|
|
//咨询总数
|
|
|
String relyTotal = redisTemplate.opsForValue().get("quota:3:"+level+":"+area+":3:"+timeKey);
|
|
|
JSONArray total = new JSONArray(relyTotal);
|
|
|
|
|
|
//未回复数
|
|
|
String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":3:"+timeKey);
|
|
|
JSONArray onRely = new JSONArray(relyTotal);
|
|
|
|
|
|
result.put("resultList",getCoutList(rely,total,onRely));
|
|
|
}else{
|
|
|
String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
|
|
|
//及时回复数
|
|
|
|
|
|
String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":2:"+timeKey);
|
|
|
JSONArray rely = new JSONArray(relyVal);
|
|
|
|
|
|
//咨询总数
|
|
|
String relyTotal = redisTemplate.opsForValue().get("quota:3:"+level+":"+area+":2:"+timeKey);
|
|
|
JSONArray total = new JSONArray(relyTotal);
|
|
|
|
|
|
//未回复数
|
|
|
String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":2:"+timeKey);
|
|
|
JSONArray onRely = new JSONArray(relyTotal);
|
|
|
|
|
|
result.put("resultList",getCoutList(rely,total,onRely));
|
|
|
}
|
|
|
|
|
|
|
|
|
}else if(level == 3){//区级底下的机构
|
|
|
|
|
|
//quota:23:4:350200:2:1492939333191
|
|
|
|
|
|
String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
|
|
|
//及时回复数
|
|
|
|
|
|
String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":2:"+timeKey);
|
|
|
JSONArray rely = new JSONArray(relyVal);
|
|
|
|
|
|
//咨询总数
|
|
|
String relyTotal = redisTemplate.opsForValue().get("quota:3:"+level+":"+area+":2:"+timeKey);
|
|
|
JSONArray total = new JSONArray(relyTotal);
|
|
|
|
|
|
//未回复数
|
|
|
String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":2:"+timeKey);
|
|
|
JSONArray onRely = new JSONArray(relyTotal);
|
|
|
|
|
|
result.put("resultList",getCoutList(rely,total,onRely));
|
|
|
|
|
|
}else if(level == 2){//机构级别统计,统计所有团队
|
|
|
|
|
|
//quota:23:4:350200:2:1492939333191
|
|
|
|
|
|
String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
|
|
|
//及时回复数
|
|
|
|
|
|
String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":1:"+timeKey);
|
|
|
JSONArray rely = new JSONArray(relyVal);
|
|
|
|
|
|
//咨询总数
|
|
|
String relyTotal = redisTemplate.opsForValue().get("quota:3:"+level+":"+area+":1:"+timeKey);
|
|
|
JSONArray total = new JSONArray(relyTotal);
|
|
|
|
|
|
//未回复数
|
|
|
String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":1:"+timeKey);
|
|
|
JSONArray onRely = new JSONArray(relyTotal);
|
|
|
|
|
|
result.put("resultList",getCoutList(rely,total,onRely));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 统计当前级别下数据
|
|
|
* @param level
|
|
|
* @param area
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getConsultingTitle(int level,String area){
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
|
|
|
//及时回复数
|
|
|
|
|
|
String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":"+timeKey);
|
|
|
JSONObject relyObject =new JSONObject(relyVal);
|
|
|
JSONArray rely = new JSONArray();
|
|
|
rely.put(relyObject);
|
|
|
//咨询总数
|
|
|
String relyTotal = redisTemplate.opsForValue().get("quota:3:"+level+":"+area+":"+timeKey);
|
|
|
JSONObject totalObject =new JSONObject(relyVal);
|
|
|
JSONArray total = new JSONArray();
|
|
|
total.put(totalObject);
|
|
|
//未回复数
|
|
|
String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":"+timeKey);
|
|
|
JSONObject onRelyObject =new JSONObject(relyVal);
|
|
|
JSONArray onRely = new JSONArray();
|
|
|
onRely.put(onRelyObject);
|
|
|
|
|
|
result.put("result",getCoutList(rely,total,onRely));
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计
|
|
|
* 根据总数,未回复数,回复数统计,合并结果集及排序
|
|
|
* @param rely
|
|
|
* @param total
|
|
|
* @param onRely
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String,Object>> getCoutList(JSONArray rely,JSONArray total,JSONArray onRely){
|
|
|
|
|
|
Map<String,Object> relyMap = new HashMap<>();
|
|
|
Map<String,Object> totalMap = new HashMap<>();
|
|
|
Map<String,Object> onRelyMap = new HashMap<>();
|
|
|
|
|
|
//将List转换为Map,Key为要比较的CODE,降低循环层数
|
|
|
//转换回复数
|
|
|
Iterator iterator = rely.iterator();
|
|
|
while(iterator.hasNext()){
|
|
|
JSONObject jsonObject = (JSONObject)iterator.next();
|
|
|
relyMap.put(jsonObject.get("code").toString(),jsonObject);
|
|
|
}
|
|
|
//转换总咨询数
|
|
|
Iterator iterator2 = total.iterator();
|
|
|
while(iterator2.hasNext()){
|
|
|
JSONObject jsonObject = (JSONObject)iterator2.next();
|
|
|
totalMap.put(jsonObject.get("code").toString(),jsonObject);
|
|
|
}
|
|
|
|
|
|
//转换总咨询数
|
|
|
Iterator iterator3 = onRely.iterator();
|
|
|
while(iterator3.hasNext()){
|
|
|
JSONObject jsonObject = (JSONObject)iterator3.next();
|
|
|
onRelyMap.put(jsonObject.get("code").toString(),jsonObject);
|
|
|
}
|
|
|
|
|
|
List<Map<String,Object>> resultMaps = new ArrayList<>();
|
|
|
for(String key : totalMap.keySet()){
|
|
|
Map<String,Object> rs = new HashMap<>();
|
|
|
JSONObject relyRs = (JSONObject)relyMap.get(key);
|
|
|
JSONObject totalRs = (JSONObject)totalMap.get(key);
|
|
|
JSONObject onRelyRs = (JSONObject)onRelyMap.get(key);
|
|
|
//合并结果集
|
|
|
Long totalNm = totalRs.getLong("num");
|
|
|
Long relyNm = relyRs.getLong("num");
|
|
|
Long noRelyNm = onRelyRs.getLong("num");
|
|
|
rs.put("name",relyRs.get("name"));
|
|
|
rs.put("noRelyCount",noRelyNm);
|
|
|
rs.put("relyCount",relyNm);
|
|
|
rs.put("total",totalNm);
|
|
|
rs.put("code",key);
|
|
|
if(totalNm !=null&&totalNm!=0){
|
|
|
if(relyNm!=null&&relyNm!=0){
|
|
|
double rr = (double)relyNm/totalNm*100;
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
rs.put("relyRate",df.format(rr)+"%");
|
|
|
}else{
|
|
|
rs.put("relyRate","0.00%");
|
|
|
}
|
|
|
if(noRelyNm!=null&&noRelyNm!=0){
|
|
|
double rr = (double)noRelyNm/totalNm*100;
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
rs.put("noRelyRate",df.format(rr)+"%");
|
|
|
}else{
|
|
|
rs.put("noRelyRate","0.00%");
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
rs.put("relyRate","0.00%");
|
|
|
rs.put("noRelyRate","0.00%");
|
|
|
}
|
|
|
|
|
|
resultMaps.add(rs);
|
|
|
}
|
|
|
|
|
|
//根据回复数排序
|
|
|
Collections.sort(resultMaps, new Comparator<Map<String,Object>>(){
|
|
|
|
|
|
public int compare(Map<String,Object> o1,Map<String,Object> o2){
|
|
|
return (Long)o1.get("relyCount")<(Long)o2.get("relyCount")?1:( (Long)o1.get("relyCount")==(Long)o2.get("relyCount")?0:-1);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return resultMaps;
|
|
|
}
|
|
|
}
|