|
@ -14,6 +14,7 @@ import com.yihu.wlyy.util.DateUtil;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.keyvalue.core.IterableConverter;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
@ -63,6 +64,21 @@ public class StatisticsService extends BaseService {
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
/**
|
|
|
* 缓存人口数据到redis
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean peopleNumToRedis() {
|
|
|
Iterable<PopulationBase> peopleNums = peopleNumDao.findAll();
|
|
|
|
|
|
for (PopulationBase peopleNum : peopleNums) {
|
|
|
redisTemplate.opsForValue().set("people:num:" + peopleNum.getCode(), new JSONObject(peopleNum).toString());
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询截止某个日期累计量
|
|
|
*
|
|
@ -126,19 +142,22 @@ public class StatisticsService extends BaseService {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getSignRate(String endDate, String area, int level) throws Exception {
|
|
|
JSONObject json = new JSONObject();
|
|
|
JSONObject json = new JSONObject();
|
|
|
long signAmount = getTotalAmount(endDate, area, level, SIGN);
|
|
|
PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
|
|
|
if (peopleNum != null && peopleNum.getNum() > 0) {
|
|
|
json.put("rate",df.format((signAmount * 1.0000) / peopleNum.getNum() * 100));
|
|
|
json.put("sign",signAmount);
|
|
|
json.put("rate", df.format((signAmount * 1.0000) / peopleNum.getNum() * 100));
|
|
|
json.put("sign", signAmount);
|
|
|
json.put("people", peopleNum.getNum());
|
|
|
return json;
|
|
|
} else {
|
|
|
throw new Exception("户籍任务人口数为0");
|
|
|
json.put("rate", "0.0000");
|
|
|
json.put("sign", signAmount);
|
|
|
json.put("people", 0);
|
|
|
}
|
|
|
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -150,19 +169,22 @@ public class StatisticsService extends BaseService {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getSignTaskRate(String endDate, String area, int level) throws Exception {
|
|
|
JSONObject json = new JSONObject();
|
|
|
JSONObject json = new JSONObject();
|
|
|
long signAmount = getTotalAmount(endDate, area, level, SIGN);
|
|
|
PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
|
|
|
if (peopleNum != null && peopleNum.getTaskNum() > 0) {
|
|
|
json.put("rate",df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100));
|
|
|
json.put("sign",signAmount);
|
|
|
json.put("rate", df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100));
|
|
|
json.put("sign", signAmount);
|
|
|
json.put("people", peopleNum.getTaskNum());
|
|
|
return json;
|
|
|
} else {
|
|
|
throw new Exception("户籍人口任务数为0");
|
|
|
json.put("rate", "0.0000");
|
|
|
json.put("sign", signAmount);
|
|
|
json.put("people", 0);
|
|
|
}
|
|
|
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -409,11 +431,13 @@ public class StatisticsService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(" + lowLevelField + ",'') code " +
|
|
|
" ,ifnull(" + lowLevelName + ",'') 'name' " +
|
|
|
" ,ifnull(sum(result),0) amount" +
|
|
|
" ,ifnull(sum(result),0.0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -429,11 +453,11 @@ public class StatisticsService extends BaseService {
|
|
|
sql += " order by amount asc ";
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{(StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel), endDate, area});
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{low_level, endDate, area});
|
|
|
// 结果为空时,自建结果集
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
|
resultList = new ArrayList<>();
|
|
|
if (level == 4) {
|
|
|
if (low_level.equals("3")) {
|
|
|
List<Town> towns = townDao.findByCityCode(area);
|
|
|
if (towns != null) {
|
|
|
for (Town town : towns) {
|
|
@ -441,9 +465,10 @@ public class StatisticsService extends BaseService {
|
|
|
obj.put("code", town.getCode());
|
|
|
obj.put("name", town.getName());
|
|
|
obj.put("amount", Double.valueOf("0.0"));
|
|
|
obj.put("rate", Double.valueOf("0.0000"));
|
|
|
}
|
|
|
}
|
|
|
} else if (level == 3) {
|
|
|
} else if (low_level.equals("2")) {
|
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(area);
|
|
|
if (hospitals != null) {
|
|
|
for (Hospital hos : hospitals) {
|
|
@ -451,9 +476,10 @@ public class StatisticsService extends BaseService {
|
|
|
obj.put("code", hos.getCode());
|
|
|
obj.put("name", hos.getName());
|
|
|
obj.put("amount", Double.valueOf("0.0"));
|
|
|
obj.put("rate", Double.valueOf("0.0000"));
|
|
|
}
|
|
|
}
|
|
|
} else if (level == 2) {
|
|
|
} else if (low_level.equals("1")) {
|
|
|
List<Doctor> doctors = doctorDao.findDoctorByLevelAndHospital(area, 2);
|
|
|
if (doctors != null) {
|
|
|
for (Doctor doc : doctors) {
|
|
@ -467,18 +493,35 @@ public class StatisticsService extends BaseService {
|
|
|
}
|
|
|
|
|
|
if (resultList != null) {
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
map.put("amount", map.get("amount") != null ? Math.round((double) map.get("amount")) : 0);
|
|
|
// 截止日期包含当天,则从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 + ":" + (StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel) + ":" + code);
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code);
|
|
|
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"));
|
|
|
}
|
|
|
}
|
|
|
if (!low_level.equals("1")) {
|
|
|
String redisNum = redisTemplate.opsForValue().get("people:num:" + map.get("code").toString());
|
|
|
|
|
|
if (StringUtils.isEmpty(redisNum)) {
|
|
|
PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(), Calendar.getInstance().get(Calendar.YEAR));
|
|
|
if (peopleNum != null) {
|
|
|
map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
|
|
|
}
|
|
|
} else {
|
|
|
JSONObject peopleNum = new JSONObject(redisNum);
|
|
|
if (peopleNum != null) {
|
|
|
map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("num") * 100));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
@ -513,7 +556,7 @@ public class StatisticsService extends BaseService {
|
|
|
* @param index 指标
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray getLowLevelIncrementDetail(String startDate, String endDate, String area, int level, String index, int sort,String lowLevel) throws Exception {
|
|
|
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 = "";
|
|
@ -552,11 +595,13 @@ public class StatisticsService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(" + lowLevelField + ",'') code " +
|
|
|
" ,ifnull(" + lowLevelName + ",'') 'name' " +
|
|
|
" ,ifnull(sum(result),0) amount" +
|
|
|
" ,ifnull(sum(result),0.0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -573,12 +618,12 @@ public class StatisticsService extends BaseService {
|
|
|
sql += " order by amount asc ";
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{(StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel), startDate, endDate, area});
|
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, new Object[]{low_level, startDate, endDate, area});
|
|
|
|
|
|
// 结果为空时,自建结果集
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
|
resultList = new ArrayList<>();
|
|
|
if (level == 4) {
|
|
|
if (low_level.equals("3")) {
|
|
|
List<Town> towns = townDao.findByCityCode(area);
|
|
|
if (towns != null) {
|
|
|
for (Town town : towns) {
|
|
@ -589,7 +634,7 @@ public class StatisticsService extends BaseService {
|
|
|
resultList.add(obj);
|
|
|
}
|
|
|
}
|
|
|
} else if (level == 3) {
|
|
|
} else if (low_level.equals("2")) {
|
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(area);
|
|
|
if (hospitals != null) {
|
|
|
for (Hospital hos : hospitals) {
|
|
@ -600,7 +645,7 @@ public class StatisticsService extends BaseService {
|
|
|
resultList.add(obj);
|
|
|
}
|
|
|
}
|
|
|
} else if (level == 2) {
|
|
|
} else if (low_level.equals("1")) {
|
|
|
List<Doctor> doctors = doctorDao.findDoctorByLevelAndHospital(area, 2);
|
|
|
if (doctors != null) {
|
|
|
for (Doctor doc : doctors) {
|
|
@ -620,7 +665,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 + ":" + (StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel) + ":" + code);
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code);
|
|
|
if (!StringUtils.isEmpty(val)) {
|
|
|
JSONObject valJson = new JSONObject(val);
|
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
@ -760,7 +805,7 @@ public class StatisticsService extends BaseService {
|
|
|
|
|
|
sql = " select " +
|
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
|
" ,ifnull(sum(result),0) amount " +
|
|
|
" ,ifnull(sum(result),0.0) amount " +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -927,7 +972,7 @@ public class StatisticsService extends BaseService {
|
|
|
// 查询时间范围内所有记录
|
|
|
sql = " select " +
|
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
|
" ,ifnull(sum(result),0) amount " +
|
|
|
" ,ifnull(sum(result),0.0) amount " +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -1123,7 +1168,7 @@ public class StatisticsService extends BaseService {
|
|
|
// 查询时间范围内所有记录
|
|
|
sql = " select " +
|
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
|
" ,ifnull(sum(result),0) amount " +
|
|
|
" ,ifnull(sum(result),0.0) amount " +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -1225,7 +1270,7 @@ public class StatisticsService extends BaseService {
|
|
|
String sql = " select " +
|
|
|
" ifnull(level2_type,'') code " +
|
|
|
" ,ifnull(level2_type_name,'') 'name' " +
|
|
|
" ,ifnull(sum(result),0) amount" +
|
|
|
" ,ifnull(sum(result),0.0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -1457,7 +1502,7 @@ public class StatisticsService extends BaseService {
|
|
|
String sql = " select " +
|
|
|
" ifnull(level3_type,'') code " +
|
|
|
" ,ifnull(level3_type_name,'') 'name' " +
|
|
|
" ,ifnull(sum(result),0) amount" +
|
|
|
" ,ifnull(sum(result),0.0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|
|
@ -1571,7 +1616,7 @@ public class StatisticsService extends BaseService {
|
|
|
|
|
|
// 查询语句
|
|
|
String sql = " select " +
|
|
|
" ifnull(sum(result),0) amount" +
|
|
|
" ifnull(sum(result),0.0) amount" +
|
|
|
" from " +
|
|
|
" wlyy_quota_result " +
|
|
|
" where " +
|