|
@ -5101,26 +5101,62 @@ public class StatisticsService extends BaseService {
|
|
|
* @param type 类型1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String,Object>> getPrescriptionTotalHistogram(String level,String area,String disease,String type){
|
|
|
public List<Map<String,Object>> getPrescriptionTotalHistogram(String level,String area,String disease,String type,int interval){
|
|
|
|
|
|
List<Map<String,Object>> rs =new ArrayList<>();
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String sql ="";
|
|
|
Calendar dd = Calendar.getInstance();//定义日期实例
|
|
|
Date endDate = new Date();
|
|
|
dd.setTime(endDate);
|
|
|
|
|
|
for(int i=1;i<7;i++){
|
|
|
Map<String,Object> mc = new HashedMap();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
String date = sdf.format(dd.getTime());
|
|
|
mc.put("month",date);
|
|
|
mc.put("count",0);
|
|
|
dd.add(Calendar.MONTH,-1);
|
|
|
rs.add(mc);
|
|
|
String startTime ="";
|
|
|
String endTime = "";
|
|
|
|
|
|
//六个月前的开始时间
|
|
|
Date startDate = DateUtil.getNextMonthReturnDate(endDate,-6);
|
|
|
startDate = DateUtil.getDateShort(startDate);
|
|
|
if (interval==1){
|
|
|
sql = "SELECT count(1) AS count,LEFT(p.create_time,10) date FROM wlyy_prescription p ";
|
|
|
rs = DateUtil.findDates(startDate,endDate);
|
|
|
//加入当天数据
|
|
|
Map<String,Object> dateMap = new HashedMap();
|
|
|
dateMap.put("date",sdf.format(endDate));
|
|
|
dateMap.put("count", 0.0D);
|
|
|
rs.add(dateMap);
|
|
|
startTime = DateUtil.dateToStr(startDate, "YYYY-MM-dd HH:mm:ss");
|
|
|
endTime = DateUtil.dateToStr(endDate, "YYYY-MM-dd HH:mm:ss");
|
|
|
}
|
|
|
if (interval==2){
|
|
|
sql = "SELECT count(1) AS count,LEFT(date_sub(p.create_time,INTERVAL WEEKDAY(p.create_time) +0 DAY),10) date FROM wlyy_prescription p ";
|
|
|
rs = DateUtil.findDateASWeeks(startDate,endDate);
|
|
|
String MondayWeekDateStr = DateUtil.getMondayOfThisDate(startDate);
|
|
|
Date MondayWeekDate = DateUtil.strToDate(MondayWeekDateStr,"yyyy-MM-dd");
|
|
|
if (startDate.after(MondayWeekDate)){
|
|
|
//开始时间不是当周的周一,则加入本周周一的时间
|
|
|
Map<String,Object> dateMap = new HashedMap();
|
|
|
dateMap.put("date",MondayWeekDateStr);
|
|
|
dateMap.put("count", 0.0D);
|
|
|
rs.add(0,dateMap);
|
|
|
}
|
|
|
startTime = DateUtil.dateToStr(startDate, "YYYY-MM-dd HH:mm:ss");
|
|
|
endTime = DateUtil.dateToStr(endDate, "YYYY-MM-dd HH:mm:ss");
|
|
|
}else if (interval==3){
|
|
|
sql = "SELECT count(1) AS count,LEFT(p.create_time,7) AS month FROM wlyy_prescription p ";
|
|
|
for (int i = 1; i < 7; i++) {
|
|
|
Map<String, Object> mc = new HashedMap();
|
|
|
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM");
|
|
|
String date = sdf2.format(dd.getTime());
|
|
|
mc.put("month", date);
|
|
|
mc.put("count", 0.0D);
|
|
|
dd.add(Calendar.MONTH, -1);
|
|
|
rs.add(mc);
|
|
|
}
|
|
|
startTime = DateUtil.dateToStr(dd.getTime(), "YYYY-MM-dd HH:mm:ss");
|
|
|
endTime = DateUtil.dateToStr(new Date(), "YYYY-MM-dd HH:mm:ss");
|
|
|
}
|
|
|
|
|
|
String sql = "SELECT count(1) AS count,LEFT(p.create_time,7) AS month " +
|
|
|
" FROM wlyy_prescription p ";
|
|
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
sql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code WHERE d.health_problem ='"+disease+"' ";
|
|
|
}else{
|
|
@ -5152,17 +5188,32 @@ public class StatisticsService extends BaseService {
|
|
|
sql +=" AND p.`status` <='"+PrescriptionLog.PrescriptionLogStatus.pay_outtime.getValue()+"'";
|
|
|
}
|
|
|
|
|
|
sql += " AND p.create_time >='"+DateUtil.dateToStr(dd.getTime(),"YYYY-MM-dd HH:mm:ss")+"' AND p.create_time <='"+ DateUtil.dateToStr(new Date(),"YYYY-MM-dd HH:mm:ss")+"' GROUP BY LEFT(p.create_time,7) ";
|
|
|
//增加时间维度
|
|
|
if(interval==1){
|
|
|
sql += " AND p.create_time >='"+startTime+"' AND p.create_time <='"+ endTime+"' GROUP BY LEFT(p.create_time,10) ";
|
|
|
}else if (interval==2){
|
|
|
sql += " AND p.create_time >='"+startTime+"' AND p.create_time <='"+ endTime+"' GROUP BY DATE_FORMAT(p.create_time, '%v %x') ";
|
|
|
}else if (interval==3){
|
|
|
sql += " AND p.create_time >='"+startTime+"' AND p.create_time <='"+ endTime+"' GROUP BY LEFT(p.create_time,7) ";
|
|
|
}
|
|
|
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
for(Map<String,Object> m:rs){
|
|
|
Iterator iterator = list.iterator();
|
|
|
String key = "";
|
|
|
String keyDb = "";
|
|
|
while (iterator.hasNext()){
|
|
|
Map<String,Object> ml = ( Map<String,Object>)iterator.next();
|
|
|
String monthKey = (String)m.get("month");
|
|
|
String monthKeyDb = (String)ml.get("month");
|
|
|
if(monthKey.equals(monthKeyDb)){
|
|
|
if (interval!=3){
|
|
|
key = (String)m.get("date");
|
|
|
keyDb = (String)ml.get("date");
|
|
|
}else{
|
|
|
key = (String)m.get("month");
|
|
|
keyDb = (String)ml.get("month");
|
|
|
}
|
|
|
|
|
|
if(key.equals(keyDb)){
|
|
|
m.put("count",ml.get("count"));
|
|
|
}
|
|
|
}
|