|
@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@ -69,7 +70,7 @@ public class StatisticsService extends BaseService {
|
|
private StringRedisTemplate redisTemplate;
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
public String getStatisticsTime(){
|
|
|
|
|
|
public String getStatisticsTime() {
|
|
String date = redisTemplate.opsForValue().get("quota:date");
|
|
String date = redisTemplate.opsForValue().get("quota:date");
|
|
|
|
|
|
return date;
|
|
return date;
|
|
@ -145,8 +146,24 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取缴费
|
|
|
|
*
|
|
|
|
* @param endDate 截止日期
|
|
|
|
* @param area 区域
|
|
|
|
* @param level 级别
|
|
|
|
* @return
|
|
|
|
*/
|
|
public long getWeiJiaoFei(String endDate, String area, int level) {
|
|
public long getWeiJiaoFei(String endDate, String area, int level) {
|
|
int todayAmount = 0;
|
|
int todayAmount = 0;
|
|
|
|
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 " +
|
|
String sql = " select " +
|
|
@ -172,9 +189,10 @@ public class StatisticsService extends BaseService {
|
|
sql += " and qkdoctor_code = ?";
|
|
sql += " and qkdoctor_code = ?";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// 截止日期包含当天,则从redis查询当天统计数据
|
|
// 截止日期包含当天,则从redis查询当天统计数据
|
|
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 val = redisTemplate.opsForValue().get("quota:16:" + level + ":" + area);
|
|
|
|
|
|
String val = redisTemplate.opsForValue().get("quota:14:" + level + ":" + area);
|
|
if (!StringUtils.isEmpty(val)) {
|
|
if (!StringUtils.isEmpty(val)) {
|
|
JSONObject valJson = new JSONObject(val);
|
|
JSONObject valJson = new JSONObject(val);
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
if (valJson.has("num") && valJson.getInt("num") > 0) {
|
|
@ -183,10 +201,10 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
|
|
|
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, dateCon, area});
|
|
|
|
|
|
if (result != null && result.size() > 0) {
|
|
if (result != null && result.size() > 0) {
|
|
return (result.get(0).get("amount") != null ? Long.valueOf(result.get(0).get("amount").toString()) : 0);
|
|
|
|
|
|
return (result.get(0).get("amount") != null ? (Long.valueOf(result.get(0).get("amount").toString()) + todayAmount) : todayAmount);
|
|
} else {
|
|
} else {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@ -531,15 +549,15 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
} else if (low_level.equals("2")) {
|
|
} else if (low_level.equals("2")) {
|
|
List<Town> towns = new ArrayList<>();
|
|
List<Town> towns = new ArrayList<>();
|
|
if(level == 4){
|
|
|
|
|
|
if (level == 4) {
|
|
towns = townDao.findByCityCode(area);
|
|
towns = townDao.findByCityCode(area);
|
|
}else if(level == 3){
|
|
|
|
|
|
} else if (level == 3) {
|
|
Town town = townDao.findByCode(area);
|
|
Town town = townDao.findByCode(area);
|
|
towns.add(town);
|
|
towns.add(town);
|
|
}
|
|
}
|
|
|
|
|
|
if (towns != null && towns.size() > 0 ) {
|
|
|
|
for(Town town : towns){
|
|
|
|
|
|
if (towns != null && towns.size() > 0) {
|
|
|
|
for (Town town : towns) {
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
|
|
|
|
|
|
for (Hospital hos : hospitals) {
|
|
for (Hospital hos : hospitals) {
|
|
@ -553,19 +571,19 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
} else if (low_level.equals("1")) {
|
|
} else if (low_level.equals("1")) {
|
|
List<Hospital> hospitals = new ArrayList<>();
|
|
List<Hospital> hospitals = new ArrayList<>();
|
|
if(level == 4){
|
|
|
|
|
|
if (level == 4) {
|
|
hospitals = hospitalDao.findByCity(area);
|
|
hospitals = hospitalDao.findByCity(area);
|
|
}else if(level == 3){
|
|
|
|
|
|
} else if (level == 3) {
|
|
hospitals = hospitalDao.findByTownCode(area);
|
|
hospitals = hospitalDao.findByTownCode(area);
|
|
}else{
|
|
|
|
|
|
} else {
|
|
Hospital hos = hospitalDao.findByCode(area);
|
|
Hospital hos = hospitalDao.findByCode(area);
|
|
if(hos != null){
|
|
|
|
|
|
if (hos != null) {
|
|
hospitals.add(hos);
|
|
hospitals.add(hos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0 ) {
|
|
|
|
for(Hospital hos : hospitals){
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0) {
|
|
|
|
for (Hospital hos : hospitals) {
|
|
List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
|
|
List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
|
|
|
|
|
|
for (AdminTeam team : teams) {
|
|
for (AdminTeam team : teams) {
|
|
@ -725,15 +743,15 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
} else if (low_level.equals("2")) {
|
|
} else if (low_level.equals("2")) {
|
|
List<Town> towns = new ArrayList<>();
|
|
List<Town> towns = new ArrayList<>();
|
|
if(level == 4){
|
|
|
|
|
|
if (level == 4) {
|
|
towns = townDao.findByCityCode(area);
|
|
towns = townDao.findByCityCode(area);
|
|
}else if(level == 3){
|
|
|
|
|
|
} else if (level == 3) {
|
|
Town town = townDao.findByCode(area);
|
|
Town town = townDao.findByCode(area);
|
|
towns.add(town);
|
|
towns.add(town);
|
|
}
|
|
}
|
|
|
|
|
|
if (towns != null && towns.size() > 0 ) {
|
|
|
|
for(Town town : towns){
|
|
|
|
|
|
if (towns != null && towns.size() > 0) {
|
|
|
|
for (Town town : towns) {
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
|
|
|
|
|
|
for (Hospital hos : hospitals) {
|
|
for (Hospital hos : hospitals) {
|
|
@ -747,19 +765,19 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
} else if (low_level.equals("1")) {
|
|
} else if (low_level.equals("1")) {
|
|
List<Hospital> hospitals = new ArrayList<>();
|
|
List<Hospital> hospitals = new ArrayList<>();
|
|
if(level == 4){
|
|
|
|
|
|
if (level == 4) {
|
|
hospitals = hospitalDao.findByCity(area);
|
|
hospitals = hospitalDao.findByCity(area);
|
|
}else if(level == 3){
|
|
|
|
|
|
} else if (level == 3) {
|
|
hospitals = hospitalDao.findByTownCode(area);
|
|
hospitals = hospitalDao.findByTownCode(area);
|
|
}else{
|
|
|
|
|
|
} else {
|
|
Hospital hos = hospitalDao.findByCode(area);
|
|
Hospital hos = hospitalDao.findByCode(area);
|
|
if(hos != null){
|
|
|
|
|
|
if (hos != null) {
|
|
hospitals.add(hos);
|
|
hospitals.add(hos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0 ) {
|
|
|
|
for(Hospital hos : hospitals){
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0) {
|
|
|
|
for (Hospital hos : hospitals) {
|
|
List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
|
|
List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
|
|
|
|
|
|
for (AdminTeam team : teams) {
|
|
for (AdminTeam team : teams) {
|
|
@ -1902,15 +1920,15 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
} else if (low_level.equals("2")) {
|
|
} else if (low_level.equals("2")) {
|
|
List<Town> towns = new ArrayList<>();
|
|
List<Town> towns = new ArrayList<>();
|
|
if(level == 4){
|
|
|
|
|
|
if (level == 4) {
|
|
towns = townDao.findByCityCode(area);
|
|
towns = townDao.findByCityCode(area);
|
|
}else if(level == 3){
|
|
|
|
|
|
} else if (level == 3) {
|
|
Town town = townDao.findByCode(area);
|
|
Town town = townDao.findByCode(area);
|
|
towns.add(town);
|
|
towns.add(town);
|
|
}
|
|
}
|
|
|
|
|
|
if (towns != null && towns.size() > 0 ) {
|
|
|
|
for(Town town : towns){
|
|
|
|
|
|
if (towns != null && towns.size() > 0) {
|
|
|
|
for (Town town : towns) {
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
|
|
List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
|
|
|
|
|
|
for (Hospital hos : hospitals) {
|
|
for (Hospital hos : hospitals) {
|
|
@ -1924,19 +1942,19 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
} else if (low_level.equals("1")) {
|
|
} else if (low_level.equals("1")) {
|
|
List<Hospital> hospitals = new ArrayList<>();
|
|
List<Hospital> hospitals = new ArrayList<>();
|
|
if(level == 4){
|
|
|
|
|
|
if (level == 4) {
|
|
hospitals = hospitalDao.findByCity(area);
|
|
hospitals = hospitalDao.findByCity(area);
|
|
}else if(level == 3){
|
|
|
|
|
|
} else if (level == 3) {
|
|
hospitals = hospitalDao.findByTownCode(area);
|
|
hospitals = hospitalDao.findByTownCode(area);
|
|
}else{
|
|
|
|
|
|
} else {
|
|
Hospital hos = hospitalDao.findByCode(area);
|
|
Hospital hos = hospitalDao.findByCode(area);
|
|
if(hos != null){
|
|
|
|
|
|
if (hos != null) {
|
|
hospitals.add(hos);
|
|
hospitals.add(hos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0 ) {
|
|
|
|
for(Hospital hos : hospitals){
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0) {
|
|
|
|
for (Hospital hos : hospitals) {
|
|
List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
|
|
List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
|
|
|
|
|
|
for (AdminTeam team : teams) {
|
|
for (AdminTeam team : teams) {
|
|
@ -2072,7 +2090,7 @@ public class StatisticsService extends BaseService {
|
|
* @param index
|
|
* @param index
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public JSONArray dateTotalStatistics(String startDate, String endDate, String area, int level, String index) {
|
|
|
|
|
|
public JSONArray dateTotalStatistics(String startDate, String endDate, String area, int level, String index) throws ParseException {
|
|
String areaField = "";
|
|
String areaField = "";
|
|
String sql = "";
|
|
String sql = "";
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
@ -2152,6 +2170,14 @@ public class StatisticsService extends BaseService {
|
|
countResult.put(startStr, range);
|
|
countResult.put(startStr, range);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(startDate.equals(df.format(new Date()))){
|
|
|
|
Calendar preDate = Calendar.getInstance();
|
|
|
|
preDate.setTime(df.parse(endDate));
|
|
|
|
preDate.add(Calendar.DATE,-1);
|
|
|
|
|
|
|
|
startDate = df.format(preDate.getTime());
|
|
|
|
}
|
|
|
|
|
|
sql = " select " +
|
|
sql = " select " +
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
" ,ifnull(result,'0') amount " +
|
|
" ,ifnull(result,'0') amount " +
|
|
@ -2167,6 +2193,16 @@ public class StatisticsService extends BaseService {
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
if (resultList != null) {
|
|
if (resultList != null) {
|
|
|
|
String preStr = "";
|
|
|
|
|
|
|
|
if (endDate.equals(df.format(new Date()))){
|
|
|
|
Calendar preDate = Calendar.getInstance();
|
|
|
|
preDate.setTime(df.parse(endDate));
|
|
|
|
preDate.add(Calendar.DATE,-1);
|
|
|
|
|
|
|
|
preStr = df.format(preDate.getTime());
|
|
|
|
}
|
|
|
|
|
|
for (Map<String, Object> map : resultList) {
|
|
for (Map<String, Object> map : resultList) {
|
|
if (countResult.containsKey(map.get("range").toString())) {
|
|
if (countResult.containsKey(map.get("range").toString())) {
|
|
JSONObject range = (JSONObject) countResult.get(map.get("range").toString());
|
|
JSONObject range = (JSONObject) countResult.get(map.get("range").toString());
|
|
@ -2174,6 +2210,15 @@ public class StatisticsService extends BaseService {
|
|
long resultAmount = map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L;
|
|
long resultAmount = map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L;
|
|
range.put("amount", amount + resultAmount);
|
|
range.put("amount", amount + resultAmount);
|
|
}
|
|
}
|
|
|
|
if(org.apache.commons.lang3.StringUtils.isNotEmpty(preStr) &&
|
|
|
|
preStr.equals(map.get("range").toString())){
|
|
|
|
JSONObject range = (JSONObject) countResult.get(endDate);
|
|
|
|
if(range != null) {
|
|
|
|
long amount = range.getLong("amount");
|
|
|
|
long resultAmount = map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L;
|
|
|
|
range.put("amount", amount + resultAmount);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
List<JSONObject> result = new ArrayList<>(countResult.values());
|
|
List<JSONObject> result = new ArrayList<>(countResult.values());
|
|
@ -2323,6 +2368,14 @@ public class StatisticsService extends BaseService {
|
|
countResult.put(endStr, range);
|
|
countResult.put(endStr, range);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(startDate.equals(df.format(new Date()))){
|
|
|
|
Calendar preDate = Calendar.getInstance();
|
|
|
|
preDate.setTime(df.parse(endDate));
|
|
|
|
preDate.add(Calendar.DATE,-1);
|
|
|
|
|
|
|
|
startDate = df.format(preDate.getTime());
|
|
|
|
}
|
|
|
|
|
|
// 查询时间范围内所有记录
|
|
// 查询时间范围内所有记录
|
|
sql = " select " +
|
|
sql = " select " +
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
@ -2339,6 +2392,14 @@ public class StatisticsService extends BaseService {
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
if (resultList != null) {
|
|
if (resultList != null) {
|
|
|
|
String pre = "";
|
|
|
|
if (endDate.equals(df.format(new Date()))) {
|
|
|
|
Calendar preDate = Calendar.getInstance();
|
|
|
|
preDate.setTime(df.parse(endDate));
|
|
|
|
preDate.add(Calendar.DATE,-1);
|
|
|
|
pre = df.format(preDate.getTime());
|
|
|
|
}
|
|
|
|
|
|
// 计算结果
|
|
// 计算结果
|
|
for (Map<String, Object> map : resultList) {
|
|
for (Map<String, Object> map : resultList) {
|
|
String range = map.get("range").toString();
|
|
String range = map.get("range").toString();
|
|
@ -2348,6 +2409,14 @@ public class StatisticsService extends BaseService {
|
|
long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
|
|
long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
|
|
json.put("amount", amount);
|
|
json.put("amount", amount);
|
|
}
|
|
}
|
|
|
|
if (endDate.equals(df.format(new Date())) && org.apache.commons.lang3.StringUtils.isNotEmpty(pre) && range.equals(pre)) {
|
|
|
|
JSONObject jsonEnd = countResult.get(endDate);
|
|
|
|
|
|
|
|
if (jsonEnd != null) {
|
|
|
|
long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
|
|
|
|
jsonEnd.put("amount", jsonEnd.getLong("amount") + amount);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
List<JSONObject> result = new ArrayList<>(countResult.values());
|
|
List<JSONObject> result = new ArrayList<>(countResult.values());
|
|
@ -2496,6 +2565,14 @@ public class StatisticsService extends BaseService {
|
|
countResult.put(endStr, range);
|
|
countResult.put(endStr, range);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(startDate.equals(df.format(new Date()))){
|
|
|
|
Calendar preDate = Calendar.getInstance();
|
|
|
|
preDate.setTime(df.parse(endDate));
|
|
|
|
preDate.add(Calendar.DATE,-1);
|
|
|
|
|
|
|
|
startDate = df.format(preDate.getTime());
|
|
|
|
}
|
|
|
|
|
|
// 查询时间范围内所有记录
|
|
// 查询时间范围内所有记录
|
|
sql = " select " +
|
|
sql = " select " +
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
" ifnull(quota_date,'') as 'range' " +
|
|
@ -2512,6 +2589,13 @@ public class StatisticsService extends BaseService {
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
if (resultList != null) {
|
|
if (resultList != null) {
|
|
|
|
String pre = "";
|
|
|
|
if (endDate.equals(df.format(new Date()))) {
|
|
|
|
Calendar preDate = Calendar.getInstance();
|
|
|
|
preDate.setTime(df.parse(endDate));
|
|
|
|
preDate.add(Calendar.DATE,-1);
|
|
|
|
pre = df.format(preDate.getTime());
|
|
|
|
}
|
|
// 计算结果
|
|
// 计算结果
|
|
for (Map<String, Object> map : resultList) {
|
|
for (Map<String, Object> map : resultList) {
|
|
String range = map.get("range").toString();
|
|
String range = map.get("range").toString();
|
|
@ -2521,6 +2605,15 @@ public class StatisticsService extends BaseService {
|
|
long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
|
|
long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
|
|
json.put("amount", amount);
|
|
json.put("amount", amount);
|
|
}
|
|
}
|
|
|
|
if (endDate.equals(df.format(new Date())) &&
|
|
|
|
org.apache.commons.lang3.StringUtils.isNotEmpty(pre)
|
|
|
|
&& range.equals(pre)) {
|
|
|
|
JSONObject jsonEnd = countResult.get(endDate);
|
|
|
|
if (jsonEnd != null) {
|
|
|
|
long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
|
|
|
|
jsonEnd.put("amount", jsonEnd.getLong("amount") + amount);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
List<JSONObject> result = new ArrayList<>(countResult.values());
|
|
List<JSONObject> result = new ArrayList<>(countResult.values());
|