|
@ -17,6 +17,7 @@ import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
@ -27,6 +28,7 @@ import java.util.*;
|
|
/**
|
|
/**
|
|
* Created by lyr-pc on 2016/10/21.
|
|
* Created by lyr-pc on 2016/10/21.
|
|
*/
|
|
*/
|
|
|
|
@Service
|
|
public class StatisticsAllService extends BaseService {
|
|
public class StatisticsAllService extends BaseService {
|
|
@Autowired
|
|
@Autowired
|
|
CityDao cityDao;
|
|
CityDao cityDao;
|
|
@ -45,6 +47,15 @@ public class StatisticsAllService extends BaseService {
|
|
@Autowired
|
|
@Autowired
|
|
private StringRedisTemplate redisTemplate;
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取时间戳
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getQuotaTimeStamp() {
|
|
|
|
return redisTemplate.opsForValue().get("quota:timeKey");
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取一级指标达到量
|
|
* 获取一级指标达到量
|
|
*
|
|
*
|
|
@ -59,7 +70,7 @@ public class StatisticsAllService extends BaseService {
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
|
|
if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|
|
@ -109,59 +120,50 @@ public class StatisticsAllService extends BaseService {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public long getWeiJiaoFei(String endDate, String area, int level) {
|
|
public long getWeiJiaoFei(String endDate, String area, int level) {
|
|
int todayAmount = 0;
|
|
|
|
|
|
long total = 0;
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
String dateCon = endDate;
|
|
|
|
|
|
|
|
if (endDate.compareTo(dateFormat.format(new Date())) == 0) {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.add(Calendar.DATE, -1);
|
|
|
|
dateCon = dateFormat.format(calendar.getTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
// 查询语句
|
|
|
|
String sql = " select " +
|
|
|
|
" ifnull(result,'0') amount" +
|
|
|
|
" from " +
|
|
|
|
" wlyy_quota_result " +
|
|
|
|
" where " +
|
|
|
|
" quato_code = '16' " +
|
|
|
|
" and level1_type = ? and del = '1'" +
|
|
|
|
" and level2_type = '0' " +
|
|
|
|
" and quota_date = ? ";
|
|
|
|
|
|
|
|
if (level == 4) {
|
|
|
|
// 市级别
|
|
|
|
sql += " and city = ? ";
|
|
|
|
} else if (level == 3) {
|
|
|
|
// 区、城镇级别
|
|
|
|
sql += " and town = ? ";
|
|
|
|
} else if (level == 2) {
|
|
|
|
// 机构级别
|
|
|
|
sql += " and org_code = ? ";
|
|
|
|
} else if (level == 1) {
|
|
|
|
sql += " and qkdoctor_code = ?";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 截止日期包含当天,则从redis查询当天统计数据
|
|
|
|
if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:16:" + level + ":0:" + area);
|
|
|
|
|
|
if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:16:" + level + ":"+ area + ":0:" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|
|
todayAmount = valJson.getInt("num");
|
|
|
|
|
|
total = valJson.getInt("num");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
// 查询语句
|
|
|
|
String sql = " select " +
|
|
|
|
" ifnull(result,'0') amount" +
|
|
|
|
" from " +
|
|
|
|
" wlyy_quota_result " +
|
|
|
|
" where " +
|
|
|
|
" quato_code = '16' " +
|
|
|
|
" and level1_type = ? and del = '1'" +
|
|
|
|
" and level2_type = '0' " +
|
|
|
|
" and quota_date = ? ";
|
|
|
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, dateCon, area});
|
|
|
|
|
|
if (level == 4) {
|
|
|
|
// 市级别
|
|
|
|
sql += " and city = ? ";
|
|
|
|
} else if (level == 3) {
|
|
|
|
// 区、城镇级别
|
|
|
|
sql += " and town = ? ";
|
|
|
|
} else if (level == 2) {
|
|
|
|
// 机构级别
|
|
|
|
sql += " and org_code = ? ";
|
|
|
|
} else if (level == 1) {
|
|
|
|
sql += " and qkdoctor_code = ?";
|
|
|
|
}
|
|
|
|
|
|
if (result != null && result.size() > 0) {
|
|
|
|
return (result.get(0).get("amount") != null ? (Long.valueOf(result.get(0).get("amount").toString()) + todayAmount) : todayAmount);
|
|
|
|
} else {
|
|
|
|
return todayAmount;
|
|
|
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
|
|
|
|
|
|
|
|
if (result != null && result.size() > 0) {
|
|
|
|
total = (result.get(0).get("amount") != null ? Long.valueOf(result.get(0).get("amount").toString()) : 0L);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@ -381,11 +383,9 @@ public class StatisticsAllService extends BaseService {
|
|
public List<Map<String, Object>> getTodayLowLevelTotal(String date, String area, int level, String index, String lowLevel) {
|
|
public List<Map<String, Object>> getTodayLowLevelTotal(String date, String area, int level, String index, String lowLevel) {
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
|
|
String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
|
|
String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + low_level);
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(redisData)) {
|
|
|
|
|
|
|
|
|
|
String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + low_level + ":" + getQuotaTimeStamp());
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(redisData)) {
|
|
JSONArray jsonArray = new JSONArray(redisData);
|
|
JSONArray jsonArray = new JSONArray(redisData);
|
|
|
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
@ -503,9 +503,9 @@ public class StatisticsAllService extends BaseService {
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
|
if (endDate.compareTo(datef.format(new Date())) >= 0) {
|
|
if (endDate.compareTo(datef.format(new Date())) >= 0) {
|
|
resultList =getTodayLevelTwoTotal(area,level,index);
|
|
|
|
|
|
resultList = getTodayLevelTwoTotal(area, level, index);
|
|
} else {
|
|
} else {
|
|
resultList = getTodyBeforeLevelTwototal(endDate,area,level,index);
|
|
|
|
|
|
resultList = getTodyBeforeLevelTwototal(endDate, area, level, index);
|
|
}
|
|
}
|
|
|
|
|
|
if (resultList != null) {
|
|
if (resultList != null) {
|
|
@ -517,7 +517,7 @@ public class StatisticsAllService extends BaseService {
|
|
// 当天数据统计
|
|
// 当天数据统计
|
|
if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) == 0) {
|
|
if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) == 0) {
|
|
String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
|
|
String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + code + ":" + area);
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + code + ":" + area + ":" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|
|
@ -634,9 +634,9 @@ public class StatisticsAllService extends BaseService {
|
|
*/
|
|
*/
|
|
public List<Map<String, Object>> getTodayLevelTwoTotal(String area, int level, String index) {
|
|
public List<Map<String, Object>> getTodayLevelTwoTotal(String area, int level, String index) {
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
|
|
|
|
|
|
String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
|
|
|
|
|
|
if (StringUtils.isEmpty(redisData)) {
|
|
|
|
|
|
if (!StringUtils.isEmpty(redisData)) {
|
|
JSONArray jsonArray = new JSONArray(redisData);
|
|
JSONArray jsonArray = new JSONArray(redisData);
|
|
|
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
@ -835,10 +835,10 @@ public class StatisticsAllService extends BaseService {
|
|
SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
|
if(endDate.compareTo(datef.format(new Date())) >= 0) {
|
|
|
|
String redisData = redisTemplate.opsForValue().get("quota:12:" + level + ":" + area + ":6");
|
|
|
|
|
|
if (endDate.compareTo(datef.format(new Date())) >= 0) {
|
|
|
|
String redisData = redisTemplate.opsForValue().get("quota:12:" + level + ":" + area + ":6:" + getQuotaTimeStamp());
|
|
|
|
|
|
if (StringUtils.isEmpty(redisData)) {
|
|
|
|
|
|
if (!StringUtils.isEmpty(redisData)) {
|
|
JSONArray jsonArray = new JSONArray(redisData);
|
|
JSONArray jsonArray = new JSONArray(redisData);
|
|
|
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
@ -950,7 +950,7 @@ public class StatisticsAllService extends BaseService {
|
|
|
|
|
|
if (endDate.compareTo(datef.format(new Date())) >= 0) {
|
|
if (endDate.compareTo(datef.format(new Date())) >= 0) {
|
|
String code = "6";
|
|
String code = "6";
|
|
String val = redisTemplate.opsForValue().get("quota:8:" + level + ":" + area + ":" + code );
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:8:" + level + ":" + area + ":" + code + ":" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|
|
@ -1121,7 +1121,7 @@ public class StatisticsAllService extends BaseService {
|
|
|
|
|
|
// 当前范围包含当天,则需添加当天的统计数据
|
|
// 当前范围包含当天,则需添加当天的统计数据
|
|
if (startStr.compareTo(df.format(new Date())) == 0) {
|
|
if (startStr.compareTo(df.format(new Date())) == 0) {
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|
|
@ -1298,7 +1298,7 @@ public class StatisticsAllService extends BaseService {
|
|
|
|
|
|
// 当前范围包含当天,则需添加当天的统计数据
|
|
// 当前范围包含当天,则需添加当天的统计数据
|
|
if (startStr.compareTo(df.format(new Date())) <= 0 && endStr.compareTo(df.format(new Date())) >= 0) {
|
|
if (startStr.compareTo(df.format(new Date())) <= 0 && endStr.compareTo(df.format(new Date())) >= 0) {
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|
|
@ -1472,7 +1472,7 @@ public class StatisticsAllService extends BaseService {
|
|
|
|
|
|
// 当天数据计算
|
|
// 当天数据计算
|
|
if (startStr.compareTo(df.format(new Date())) <= 0 && endStr.compareTo(df.format(new Date())) >= 0) {
|
|
if (startStr.compareTo(df.format(new Date())) <= 0 && endStr.compareTo(df.format(new Date())) >= 0) {
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num")) {
|
|
if (valJson.has("num")) {
|