|
@ -1,14 +1,15 @@
|
|
|
package com.yihu.wlyy.service.app.statistics;
|
|
|
|
|
|
import com.google.common.collect.Collections2;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yihu.wlyy.entity.WlyyPeopleNum;
|
|
|
import com.yihu.wlyy.entity.address.City;
|
|
|
import com.yihu.wlyy.entity.address.Hospital;
|
|
|
import com.yihu.wlyy.entity.address.Town;
|
|
|
import com.yihu.wlyy.entity.doctor.Doctor;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.statistics.PopulationBase;
|
|
|
import com.yihu.wlyy.repository.*;
|
|
|
import com.yihu.wlyy.repository.address.CityDao;
|
|
|
import com.yihu.wlyy.repository.address.TownDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalDao;
|
|
|
import com.yihu.wlyy.repository.statistics.PopulationBaseDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import org.json.JSONArray;
|
|
@ -18,12 +19,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import redis.clients.jedis.JedisPoolConfig;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@ -63,7 +60,7 @@ public class StatisticsService extends BaseService {
|
|
|
@Autowired
|
|
|
JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
PeopleNumDao peopleNumDao;
|
|
|
PopulationBaseDao peopleNumDao;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
@ -131,11 +128,11 @@ public class StatisticsService extends BaseService {
|
|
|
*/
|
|
|
public String getSignRate(String endDate, String area, int level) throws Exception {
|
|
|
long signAmount = getTotalAmount(endDate, area, level, SIGN);
|
|
|
WlyyPeopleNum peopleNum = peopleNumDao.findByCodeAndYear(area,Calendar.getInstance().get(Calendar.YEAR));
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
|
|
|
if (peopleNum != null && peopleNum.getNum() > 0) {
|
|
|
return df.format((signAmount * 1.00) / peopleNum.getNum() * 100);
|
|
|
return df.format((signAmount * 1.0000) / peopleNum.getNum() * 100);
|
|
|
} else {
|
|
|
throw new Exception("户籍人口为0");
|
|
|
}
|
|
@ -151,11 +148,11 @@ public class StatisticsService extends BaseService {
|
|
|
*/
|
|
|
public String getSignTaskRate(String endDate, String area, int level) throws Exception {
|
|
|
long signAmount = getTotalAmount(endDate, area, level, SIGN);
|
|
|
WlyyPeopleNum peopleNum = peopleNumDao.findByCodeAndYear(area,Calendar.getInstance().get(Calendar.YEAR));
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
|
|
|
if (peopleNum != null && peopleNum.getTaskNum() > 0) {
|
|
|
return df.format((signAmount * 1.00) / peopleNum.getTaskNum() * 100);
|
|
|
return df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100);
|
|
|
} else {
|
|
|
throw new Exception("户籍人口任务数为0");
|
|
|
}
|
|
@ -366,7 +363,7 @@ public class StatisticsService extends BaseService {
|
|
|
* @param level 级别
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort) {
|
|
|
public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort, String lowLevel) throws Exception {
|
|
|
String areaField = "";
|
|
|
String lowLevelField = "";
|
|
|
String lowLevelName = "";
|
|
@ -387,8 +384,24 @@ public class StatisticsService extends BaseService {
|
|
|
lowLevelField = "qkdoctor_code";
|
|
|
lowLevelName = "qkdoctor_name";
|
|
|
} else if (level == 1) {
|
|
|
throw new Exception("param level error");
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(lowLevel)) {
|
|
|
if (lowLevel.equals("3")) {
|
|
|
lowLevelField = "town";
|
|
|
lowLevelName = "town_name";
|
|
|
} else if (lowLevel.equals("2")) {
|
|
|
lowLevelField = "org_code";
|
|
|
lowLevelName = "org_name";
|
|
|
} else if (lowLevel.equals("1")) {
|
|
|
lowLevelField = "qkdoctor_code";
|
|
|
lowLevelName = "qkdoctor_name";
|
|
|
} else {
|
|
|
throw new Exception("param lowLevel error");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(" + lowLevelField + ",'') code " +
|
|
@ -409,7 +422,7 @@ public class StatisticsService extends BaseService {
|
|
|
sql += " order by amount asc ";
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{level - 1, endDate, area});
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{(StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel), endDate, area});
|
|
|
// 结果为空时,自建结果集
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
|
resultList = new ArrayList<>();
|
|
@ -452,7 +465,7 @@ public class StatisticsService extends BaseService {
|
|
|
// 截止日期包含当天,则从redis查询当天统计数据
|
|
|
if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
|
|
|
String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + (level - 1) + ":" + code);
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + (StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel) + ":" + code);
|
|
|
if (!StringUtils.isEmpty(val)) {
|
|
|
JSONObject valJson = new JSONObject(val);
|
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
@ -493,7 +506,7 @@ public class StatisticsService extends BaseService {
|
|
|
* @param index 指标
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray getLowLevelIncrementDetail(String startDate, String endDate, String area, int level, String index, int sort) {
|
|
|
public JSONArray getLowLevelIncrementDetail(String startDate, String endDate, String area, int level, String index, int sort,String lowLevel) throws Exception {
|
|
|
String areaField = "";
|
|
|
String lowLevelField = "";
|
|
|
String lowLevelName = "";
|
|
@ -514,8 +527,24 @@ public class StatisticsService extends BaseService {
|
|
|
lowLevelField = "qkdoctor_code";
|
|
|
lowLevelName = "qkdoctor_name";
|
|
|
} else if (level == 1) {
|
|
|
throw new Exception("param level error");
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(lowLevel)) {
|
|
|
if (lowLevel.equals("3")) {
|
|
|
lowLevelField = "town";
|
|
|
lowLevelName = "town_name";
|
|
|
} else if (lowLevel.equals("2")) {
|
|
|
lowLevelField = "org_code";
|
|
|
lowLevelName = "org_name";
|
|
|
} else if (lowLevel.equals("1")) {
|
|
|
lowLevelField = "qkdoctor_code";
|
|
|
lowLevelName = "qkdoctor_name";
|
|
|
} else {
|
|
|
throw new Exception("param lowLevel error");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(" + lowLevelField + ",'') code " +
|
|
@ -537,7 +566,7 @@ public class StatisticsService extends BaseService {
|
|
|
sql += " order by amount asc ";
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{level - 1, startDate, endDate, area});
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{(StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel), startDate, endDate, area});
|
|
|
|
|
|
// 结果为空时,自建结果集
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
@ -584,7 +613,7 @@ public class StatisticsService extends BaseService {
|
|
|
// 截止日期包含当天,则从redis查询当天统计数据
|
|
|
if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
|
|
|
String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + (level - 1) + ":" + code);
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + (StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel) + ":" + code);
|
|
|
if (!StringUtils.isEmpty(val)) {
|
|
|
JSONObject valJson = new JSONObject(val);
|
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
@ -1263,6 +1292,12 @@ public class StatisticsService extends BaseService {
|
|
|
tnb.put("name", "糖尿病");
|
|
|
tnb.put("amount", Double.valueOf("0.0"));
|
|
|
resultList.add(tnb);
|
|
|
|
|
|
Map<String, Object> tnbGxy = new HashMap<>();
|
|
|
tnbGxy.put("code", "100");
|
|
|
tnbGxy.put("name", "高血压+糖尿病");
|
|
|
tnbGxy.put("amount", Double.valueOf("0.0"));
|
|
|
resultList.add(tnb);
|
|
|
} else if (index.equals(AGE)) {
|
|
|
Map<String, Object> map1 = new HashMap<>();
|
|
|
map1.put("code", "1");
|
|
@ -1323,30 +1358,46 @@ public class StatisticsService extends BaseService {
|
|
|
if (index.equals(GROUP)) {
|
|
|
// 分组指标总数算法
|
|
|
String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
|
|
|
if (!code.equals("2")) {
|
|
|
if (code.equals("1") || code.equals("2") || code.equals("3")) {
|
|
|
total += (long) map.get("amount");
|
|
|
}
|
|
|
} else {
|
|
|
total += (long) map.get("amount");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!index.equals(AGE)) {
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
double rateTotal = 0.00;
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
double rateTotal = 0.0000;
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
double rateG = (total > 0 ? ((long) map.get("amount")) * 1.00 / total * 100 : 0);
|
|
|
String code = String.valueOf(map.get("code"));
|
|
|
double rateG = (total > 0 ? ((long) map.get("amount")) * 1.0000 / total * 100 : 0);
|
|
|
map.put("rate", df.format(rateG));
|
|
|
rateTotal += rateG;
|
|
|
// if (index.equals(GROUP)) {
|
|
|
// if (code.equals("1") || code.equals("2") || code.equals("3")) {
|
|
|
// rateTotal += rateG;
|
|
|
// }
|
|
|
// } else {
|
|
|
// rateTotal += rateG;
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
if (1 - rateTotal > 0) {
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
if ((long) map.get("amount") > 0) {
|
|
|
map.put("rate", df.format(Double.valueOf((String) map.get("rate")) + (1 - rateTotal)));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// if (1 - rateTotal > 0) {
|
|
|
// for (Map<String, Object> map : resultList) {
|
|
|
// if (index.equals(GROUP)) {
|
|
|
// String code = String.valueOf(map.get("code"));
|
|
|
// if ((long) map.get("amount") > 0 && (code.equals("1") || code.equals("2") || code.equals("3"))) {
|
|
|
// map.put("rate", df.format(Double.valueOf((String) map.get("rate")) + (1 - rateTotal)));
|
|
|
// break;
|
|
|
// }
|
|
|
// }else{
|
|
|
// if ((long) map.get("amount") > 0) {
|
|
|
// map.put("rate", df.format(Double.valueOf((String) map.get("rate")) + (1 - rateTotal)));
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
}
|
|
|
if (index.equals(SEX) && resultList.size() > 0) {
|
|
|
int i = 0;
|
|
@ -1368,4 +1419,188 @@ public class StatisticsService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 统计65以上人群数据
|
|
|
*
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @param area
|
|
|
* @param level
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray getSixFiveStatistics(String startDate, String endDate, String area, int level) {
|
|
|
String areaField = "";
|
|
|
|
|
|
if (level == 4) {
|
|
|
// 市级别
|
|
|
areaField = "city";
|
|
|
} else if (level == 3) {
|
|
|
// 区、城镇级别
|
|
|
areaField = "town";
|
|
|
} else if (level == 2) {
|
|
|
// 机构级别
|
|
|
areaField = "org_code";
|
|
|
} else if (level == 1) {
|
|
|
// 团队
|
|
|
areaField = "qkdoctor_code";
|
|
|
}
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(level3_type,'') code " +
|
|
|
" ,ifnull(level3_type_name,'') 'name' " +
|
|
|
" ,ifnull(sum(result),0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
|
" quato_code = '12' " +
|
|
|
" and level2_type = '6' " +
|
|
|
" and level1_type = ? and del = '1'";
|
|
|
|
|
|
|
|
|
if (!org.apache.commons.lang3.StringUtils.isEmpty(startDate)) {
|
|
|
sql += " and quota_date >= ? ";
|
|
|
}
|
|
|
|
|
|
sql += " and quota_date <= ? " +
|
|
|
" and " + areaField + " = ? " +
|
|
|
" group by level3_type,level3_type_name";
|
|
|
|
|
|
List<Map<String, Object>> resultList = null;
|
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(startDate)) {
|
|
|
resultList = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
|
|
|
} else {
|
|
|
resultList = jdbcTemplate.queryForList(sql, new Object[]{level, startDate, endDate, area});
|
|
|
}
|
|
|
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
|
resultList = new ArrayList<>();
|
|
|
|
|
|
Map<String, Object> gxy = new HashMap<>();
|
|
|
gxy.put("code", "1");
|
|
|
gxy.put("name", "高血压");
|
|
|
gxy.put("amount", Double.valueOf("0.0"));
|
|
|
resultList.add(gxy);
|
|
|
|
|
|
Map<String, Object> tnb = new HashMap<>();
|
|
|
tnb.put("code", "2");
|
|
|
tnb.put("name", "糖尿病");
|
|
|
tnb.put("amount", Double.valueOf("0.0"));
|
|
|
resultList.add(tnb);
|
|
|
|
|
|
Map<String, Object> gxyTnb = new HashMap<>();
|
|
|
gxyTnb.put("code", "3");
|
|
|
gxyTnb.put("name", "高血压+糖尿病");
|
|
|
gxyTnb.put("amount", Double.valueOf("0.0"));
|
|
|
resultList.add(gxyTnb);
|
|
|
|
|
|
Map<String, Object> jk = new HashMap<>();
|
|
|
jk.put("code", "4");
|
|
|
jk.put("name", "健康人群");
|
|
|
jk.put("amount", Double.valueOf("0.0"));
|
|
|
resultList.add(jk);
|
|
|
}
|
|
|
|
|
|
if (resultList != null) {
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
map.put("amount", map.get("amount") == null ? 0 : Math.round((double) map.get("amount")));
|
|
|
|
|
|
// 当天数据统计
|
|
|
if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
|
|
|
String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
|
|
|
String val = redisTemplate.opsForValue().get("quota:12:" + level + ":6:" + code + ":" + area);
|
|
|
if (!StringUtils.isEmpty(val)) {
|
|
|
JSONObject valJson = new JSONObject(val);
|
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
|
map.put("amount", (long) map.get("amount") + valJson.getInt("num"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 65岁以上人群总数统计
|
|
|
long sixFiveTotal = getSixFiveTotal(startDate, endDate, area, level);
|
|
|
Map<String, Object> sixFive = new HashMap<>();
|
|
|
|
|
|
sixFive.put("code", "0");
|
|
|
sixFive.put("name", "总数");
|
|
|
sixFive.put("amount", sixFiveTotal);
|
|
|
resultList.add(sixFive);
|
|
|
|
|
|
return new JSONArray(resultList);
|
|
|
} else {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取65岁以上人群总数
|
|
|
*
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @param area
|
|
|
* @param level
|
|
|
* @return
|
|
|
*/
|
|
|
public long getSixFiveTotal(String startDate, String endDate, String area, int level) {
|
|
|
String areaField = "";
|
|
|
long total = 0;
|
|
|
|
|
|
if (level == 4) {
|
|
|
// 市级别
|
|
|
areaField = "city";
|
|
|
} else if (level == 3) {
|
|
|
// 区、城镇级别
|
|
|
areaField = "town";
|
|
|
} else if (level == 2) {
|
|
|
// 机构级别
|
|
|
areaField = "org_code";
|
|
|
} else if (level == 1) {
|
|
|
// 团队
|
|
|
areaField = "qkdoctor_code";
|
|
|
}
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(sum(result),0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
|
" quato_code = '8' " +
|
|
|
" and level2_type = '6' " +
|
|
|
" and level1_type = ? and del = '1'";
|
|
|
|
|
|
|
|
|
if (!org.apache.commons.lang3.StringUtils.isEmpty(startDate)) {
|
|
|
sql += " and quota_date >= ? ";
|
|
|
}
|
|
|
|
|
|
sql += " and quota_date <= ? " +
|
|
|
" and " + areaField + " = ? ";
|
|
|
|
|
|
Map<String, Object> result = null;
|
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(startDate)) {
|
|
|
result = jdbcTemplate.queryForMap(sql, new Object[]{level, endDate, area});
|
|
|
} else {
|
|
|
result = jdbcTemplate.queryForMap(sql, new Object[]{level, startDate, endDate, area});
|
|
|
}
|
|
|
|
|
|
if (result != null && result.containsKey("amount")) {
|
|
|
total += (result.get("amount") == null ? 0 : Math.round((double) result.get("amount")));
|
|
|
}
|
|
|
|
|
|
String code = "6";
|
|
|
String val = redisTemplate.opsForValue().get("quota:8:" + level + ":" + code + ":" + area);
|
|
|
if (!StringUtils.isEmpty(val)) {
|
|
|
JSONObject valJson = new JSONObject(val);
|
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
|
total += valJson.getInt("num");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return total;
|
|
|
}
|
|
|
}
|