//图标 按照
@Override
public List<DoctorServiceChartVo> queryDoctorServiceChart(MonitorHu monitorHu) {
log.info("请求图表:{}", monitorHu);
List<Integer> hosIdsInt = monitorHu.getHosIds();
List<String> hosIds = hosIdsInt.stream().map(String::valueOf).collect(Collectors.toList());
Date startDate = DateUtil.parse(monitorHu.getStartTime());
Date endDate = DateUtil.parse(monitorHu.getEndTime());
List<String> dateList = null;
// 获取查询时间方式
if ("day".equals(monitorHu.getTimeType())) {
dateList = DateUtils.calDay(monitorHu.getStartTime(), monitorHu.getEndTime());
} else if ("week".equals(monitorHu.getTimeType())) {
// 周的时间跨度
dateList = DateUtils.calcWeek(monitorHu.getStartTime(), monitorHu.getEndTime());
} else if ("month".equals(monitorHu.getTimeType())) {
dateList = DateUtils.calMonth(monitorHu.getStartTime(), monitorHu.getEndTime());
} else if ("year".equals(monitorHu.getTimeType())) {
dateList = DateUtils.calYear(monitorHu.getStartTime(), monitorHu.getEndTime());
} else {
return Collections.emptyList();
}
// 视图
List<DataVo> hisNoticeVo, repeatNoticeVo, callNumVo,
mutualRecognitionNumVo, nonMutualRecognitionNumVo,
applyNumVo, consultationNum, loginNumVo;
String startTimeDate = DateUtil.format(DateUtil.beginOfDay(startDate), "yyyy-MM-dd HH:mm:ss");
String endTimeDate = DateUtil.format(DateUtil.endOfDay(endDate), "yyyy-MM-dd HH:mm:ss");
// 历史提醒次数
hisNoticeVo = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"history_notice_num", hosIds, startTimeDate, endTimeDate);
// 重复提醒次数
repeatNoticeVo = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"repeat_notice_num", hosIds, startTimeDate, endTimeDate);
//调阅次数、iu_operate_detail 1234
callNumVo = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"call_number", hosIds, startTimeDate, endTimeDate);
//互认次数、iuOperateDetail 8
mutualRecognitionNumVo = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"mutual_recognition_num", hosIds, startTimeDate, endTimeDate);
//不互认次数、iuOperateDetail 9
nonMutualRecognitionNumVo = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"non_mutual_recognition_num", hosIds, startTimeDate, endTimeDate);
//院内申请量、iuOperateDetailMapper 12
applyNumVo = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"apply_num", hosIds, startTimeDate, endTimeDate);
//院内会诊量;iuOperateDetailMapper 14
consultationNum = iuUserStatisticsMapper.queryDoctorServiceChart(monitorHu.getTimeType(),
"consultation_num", hosIds, startTimeDate, endTimeDate);
//包含登录次数、iu_operate operate_type_id=1
loginNumVo = iuOperateMapper.queryLoginNumChart(monitorHu.getTimeType(), OperateTypeEnum.LOGIN.getId(),
hosIds, startTimeDate, endTimeDate);
return convertMap(dateList, hisNoticeVo, repeatNoticeVo, callNumVo,
mutualRecognitionNumVo, nonMutualRecognitionNumVo,
applyNumVo, consultationNum, loginNumVo,
monitorHu.getTimeType());
}
将日 星期 月年 的工具类
/**
* 计算日
*/
public static List<String> calDay(String startTime, String endTime) {
List<String> dayList = new ArrayList<>();
try {
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = sfd.parse(startTime);
Date end = sfd.parse(endTime);
Calendar calStart = Calendar.getInstance();
calStart.setTime(start);
Calendar calEnd = Calendar.getInstance();
calEnd.setTime(end);
while (calStart.compareTo(calEnd) < 0) {
int month = calStart.get(Calendar.MONTH) + 1;
int day = calStart.get(Calendar.DATE);
dayList.add(calStart.get(Calendar.YEAR) + (month < 10 ? '0' + String.valueOf(month) : String.valueOf(month))
+ (day < 10 ? '0' + String.valueOf(day) : String.valueOf(day)));
calStart.add(Calendar.DATE, 1);
}
} catch (ParseException e) {
e.printStackTrace();
}
return dayList;
}
convertMap();
public List<DoctorServiceChartVo> convertMap(List<String> dateList,
List<DataVo> hisNoticeVo,
List<DataVo> repeatNoticeVo,
List<DataVo> callNumVo,
List<DataVo> mutualRecognitionNumVo,
List<DataVo> nonMutualRecognitionNumVo,
List<DataVo> applyNumVo,
List<DataVo> consultationNumVo,
List<DataVo> loginNumVo,
String dateType) {
List<String> totalTime = new ArrayList<>();
Map<String, Integer> hisNoticeMap = new LinkedHashMap<>();
Map<String, Integer> repeatNoticeMap = new LinkedHashMap<>();
Map<String, Integer> callNumMap = new LinkedHashMap<>();
Map<String, Integer> mutualRecognitionNumMap = new LinkedHashMap<>();
Map<String, Integer> nonMutualRecognitionNumMap = new LinkedHashMap<>();
Map<String, Integer> applyNumMap = new LinkedHashMap<>();
Map<String, Integer> consultationNumMap = new LinkedHashMap<>();
Map<String, Integer> loginNumMap = new LinkedHashMap<>();
List<Integer> dataTotal = new ArrayList<>();
for (DataVo dataVo : hisNoticeVo) {
hisNoticeMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : repeatNoticeVo) {
repeatNoticeMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : callNumVo) {
callNumMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : mutualRecognitionNumVo) {
mutualRecognitionNumMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : nonMutualRecognitionNumVo) {
nonMutualRecognitionNumMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : applyNumVo) {
applyNumMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : consultationNumVo) {
consultationNumMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (DataVo dataVo : loginNumVo) {
loginNumMap.put(dataVo.getTimes(), dataVo.getNum());
}
for (String date : dateList) {
Integer hisNoticeNum = hisNoticeMap.get(date);
Integer repeatNoticeNum = repeatNoticeMap.get(date);
Integer callNum = callNumMap.get(date);
Integer mutualRecognitionNum = mutualRecognitionNumMap.get(date);
Integer nonMutualRecognitionNum = nonMutualRecognitionNumMap.get(date);
Integer applyNum = applyNumMap.get(date);
Integer consultationNum = consultationNumMap.get(date);
Integer loginNum = loginNumMap.get(date);
String tempTime = date;
if ("week".equals(dateType)) {
tempTime = date.substring(0, 4) + "-" + date.substring(4) + "周";
} else if ("day".equals(dateType)) {
tempTime = date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6);
} else if ("month".equals(dateType)) {
tempTime = date.substring(0, 4) + "-" + date.substring(4);
}
if (Objects.isNull(hisNoticeNum)) {
hisNoticeNum = 0;
}
if (Objects.isNull(repeatNoticeNum)) {
repeatNoticeNum = 0;
}
if (Objects.isNull(callNum)) {
callNum = 0;
}
if (Objects.isNull(mutualRecognitionNum)) {
mutualRecognitionNum = 0;
}
if (Objects.isNull(nonMutualRecognitionNum)) {
nonMutualRecognitionNum = 0;
}
if (Objects.isNull(applyNum)) {
applyNum = 0;
}
if (Objects.isNull(consultationNum)) {
consultationNum = 0;
}
if (Objects.isNull(loginNum)) {
loginNum = 0;
}
totalTime.add(date);
Integer total = hisNoticeNum + repeatNoticeNum + callNum
+ mutualRecognitionNum + nonMutualRecognitionNum
+ applyNum + consultationNum + loginNum;
dataTotal.add(total);
}
List<DoctorServiceChartVo> resultDataList = new ArrayList<>();
resultDataList.add(new DoctorServiceChartVo("doctorServiceVolume", "医生服务量", totalTime, dataTotal));
return resultDataList;
}
实体类DoctorServiceChartVo
package com.imagingunion.iustatistics.domain.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class DoctorServiceChartVo implements Serializable {
private static final long serialVersionUID = 1L;
String type;
String typeName;
private List<String> times;
private List<Integer> data;
}
sql
<select id="queryDoctorServiceChart" resultType="com.imagingunion.iustatistics.domain.response.DataVo">
select
<if test="queryType == 'repeat_notice_num'">
sum(repeat_notice_num) as num
if>
<if test="queryType == 'history_notice_num'">
sum(history_notice_num) as num
if>
<if test="queryType == 'call_number'">
sum(call_number) as num
if>
<if test="queryType == 'mutual_recognition_num'">
sum(mutual_recognition_num) as num
if>
<if test="queryType == 'non_mutual_recognition_num'">
sum(non_mutual_recognition_num) as num
if>
<if test="queryType == 'apply_num'">
sum(apply_num) as num
if>
<if test="queryType == 'consultation_num'">
sum(consultation_num) as num
if>
,
<if test="ways == 'day'">
toYYYYMMDD(query_time) as times
if>
<if test="ways == 'month'">
toYYYYMM(query_time) as times
if>
<if test="ways == 'year'">
toYear(query_time) as times
if>
<if test="ways == 'week'">
toYearWeek(query_time, 9) as times
if>
from iu_digital_images_analysis.iu_user_statistic
where query_time between toDate(#{startTime}) and toDate(#{endTime})
<if test="hosIds!=null and hosIds.size()>0">
and hospital_id in
<foreach collection="hosIds" index="index" item="hosId" separator="," close=")" open="(">
#{hosId}
foreach>
if>
group by times
order by times desc
select>
补充:可以将页面显示的周 进行处理
package com.imagingunion.common.utils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author LQ
* @date 2022/11/16
* @note
*/
public class DateUtils {
//public static Integer calcYear(String startTime, String endTime){
// DateUtil.betweenMonth()
//}
public static void main(String[] args) throws ParseException {
//Date startTime = DateUtil.parse("2022-10-27 00:00:00");
//Date endTime = DateUtil.parse("2022-11-15 23:59:59");
System.out.println(DateUtil.betweenWeek(startTime, endTime, true));
//new DateBetween(startTime, endTime, false).between(DateUnit.WEEK);
//System.out.println(new DateBetween(startTime, endTime, true).between(DateUnit.WEEK));
//
//System.out.println(new DateBetween(startTime, endTime, true).betweenMonth(true) + 1);
//System.out.println(new DateBetween(startTime, endTime, true).betweenYear(true) + 1);
//long from = startTime.getTime();
//long to = endTime.getTime();
//System.out.println("相差周数为:" + (to - from) / (1000 * 3600 * 24 * 7));
//Calendar bef = Calendar.getInstance();
//bef.setTime(startTime);
//System.out.println(bef.get(Calendar.WEEK_OF_YEAR));
System.out.println(calcWeek("2021-10-27 00:00:00", "2022-11-13 00:00:00"));
System.out.println(calYear("2021-10-27 00:00:00", "2022-11-13 00:00:00"));
System.out.println(calMonth("2022-10-27 00:00:00", "2022-11-13 00:00:00"));
System.out.println(calDay("2020-10-27 00:00:00", "2022-11-13 00:00:00"));
}
/**
* 时间转为周
*
* @param startTime
* @param endTime
* @return
*/
public static List<String> calcWeek(String startTime, String endTime) {
List<String> resultList = new ArrayList<>();
Date start = DateUtil.parse(startTime);
Date end = DateUtil.parse(endTime);
Calendar bef = Calendar.getInstance();
Calendar aft = Calendar.getInstance();
bef.setTime(start);
aft.setTime(end);
// 设置周一为每周第一天
bef.setFirstDayOfWeek(Calendar.MONDAY);
aft.setFirstDayOfWeek(Calendar.MONDAY);
int startYear = bef.get(Calendar.YEAR);
int endYear = aft.get(Calendar.YEAR);
// 开始周 结束周
int startWeek = bef.get(Calendar.WEEK_OF_YEAR);
int endWeek = aft.get(Calendar.WEEK_OF_YEAR);
if (startYear == endYear) {
// 转为周
for (int i = startWeek; i <= endWeek; i++) {
resultList.add(String.valueOf(startYear) + i);
}
} else {
// 开始年份小于结束年份
for (int i = startYear; i <= endYear; i++) {
if (i != endYear) {
for (int j = startWeek; j <= 52; j++) {
resultList.add(i + (j < 10 ? '0' + String.valueOf(j) : String.valueOf(j)));
}
}
if (i == endYear) {
for (int n = 1; n <= endWeek; n++) {
resultList.add(endYear + (n < 10 ? '0' + String.valueOf(n) : String.valueOf(n)));
}
}
}
}
return resultList;
}
/**
* 计算年
*
* @param startTime
* @param endTime
* @return
*/
public static List<String> calYear(String startTime, String endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar bef = Calendar.getInstance();
Calendar aft = Calendar.getInstance();
bef.setTime(DateUtil.parse(startTime));
aft.setTime(DateUtil.parse(endTime));
int start = bef.get(Calendar.YEAR);
int end = aft.get(Calendar.YEAR);
List<String> yearList = new ArrayList<>();
for (int i = start; i <= end; i++) {
yearList.add(String.valueOf(i));
}
return yearList;
}
/**
* 计算月
*
* @param startTime
* @param endTime
* @return
*/
public static List<String> calMonth(String startTime, String endTime) {
List<String> monthList = new ArrayList<>();
try {
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = sfd.parse(startTime);
Date end = sfd.parse(endTime);
int startYear = getYear(start);
int startMonth = getMonth(start);
int endYear = getYear(end);
int endMonth = getMonth(end);
// 中间有间隔年份
if ((endYear - startYear) >= 2) {
for (int i = startMonth; i <= 12; i++) {
monthList.add(startYear + (i < 10 ? '0' + String.valueOf(i) : String.valueOf(i)));
}
for (int i = startYear + 1; i < endYear; i++) {
for (int j = 1; j <= 12; j++) {
monthList.add(i + (j < 10 ? '0' + String.valueOf(j) : String.valueOf(j)));
}
}
for (int i = 1; i <= endMonth; i++) {
monthList.add(endYear + (i < 10 ? '0' + String.valueOf(i) : String.valueOf(i)));
}
} else if (endYear == startYear) {
for (int i = startMonth; i <= endMonth; i++) {
monthList.add(startYear + (i < 10 ? '0' + String.valueOf(i) : String.valueOf(i)));
}
} else {
for (int i = startMonth; i <= 12; i++) {
monthList.add(startYear + (i < 10 ? '0' + String.valueOf(i) : String.valueOf(i)));
}
for (int i = 1; i <= endMonth; i++) {
monthList.add(endYear + (i < 10 ? '0' + String.valueOf(i) : String.valueOf(i)));
}
}
} catch (ParseException e) {
e.printStackTrace();
}
return monthList;
}
/**
* 计算日
*
* @param startTime
* @param endTime
* @return
*/
public static List<String> calDay(String startTime, String endTime) {
List<String> dayList = new ArrayList<>();
try {
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = sfd.parse(startTime);
Date end = sfd.parse(endTime);
Calendar calStart = Calendar.getInstance();
calStart.setTime(start);
Calendar calEnd = Calendar.getInstance();
calEnd.setTime(end);
while (calStart.compareTo(calEnd) < 0) {
int month = calStart.get(Calendar.MONTH) + 1;
int day = calStart.get(Calendar.DATE);
dayList.add(calStart.get(Calendar.YEAR) + (month < 10 ? '0' + String.valueOf(month) : String.valueOf(month))
+ (day < 10 ? '0' + String.valueOf(day) : String.valueOf(day)));
calStart.add(Calendar.DATE, 1);
}
} catch (ParseException e) {
e.printStackTrace();
}
return dayList;
}
public static Integer calMonth1(String startTime, String endTime) {
int result = 0;
List<String> monthList = new ArrayList<>();
try {
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = sfd.parse(startTime);
Date end = sfd.parse(endTime);
int startYear = getYear(start);
int startMonth = getMonth(start);
int startDay = getDay(start);
int endYear = getYear(end);
int endMonth = getMonth(end);
int endDay = getDay(end);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(start);
int maxDay = calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);//获取起始日期所在月的最后一天
Calendar calendar3 = Calendar.getInstance();
calendar3.setTime(end);
int maxEndDay = calendar3.getActualMaximum(Calendar.DAY_OF_MONTH);//获取结束日期所在月的最后一天
if (startDay == maxDay) {//起始日期是在月末
if (maxEndDay == endDay) {
result = (endYear - startYear) * 12 + endMonth - startMonth;
} else {
result = (endYear - startYear) * 12 + endMonth - startMonth - 1;
}
} else if (endDay == maxEndDay) {//结束日期是在月末
result = (endYear - startYear) * 12 + endMonth - startMonth;
} else {
if (endDay >= startDay) {
result = (endYear - startYear) * 12 + endMonth - startMonth;
} else {
result = (endYear - startYear) * 12 + endMonth - startMonth - 1;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static Integer calWeek(String startTime, String endTime) {
if (StrUtil.isNotEmpty(startTime) && StrUtil.isNotEmpty(endTime)) {
Date start = DateUtil.parse(startTime);
Date end = DateUtil.parse(endTime);
Calendar cal = Calendar.getInstance();
cal.setTime(start);
long time1 = cal.getTimeInMillis();
cal.setTime(end);
long time2 = cal.getTimeInMillis();
long between_days = (time2 - time1) / (1000 * 3600 * 24);
Double days = Double.parseDouble(String.valueOf(between_days));
if ((days / 7) > 0 && (days / 7) <= 1) {
//不满一周的按一周算
return 1;
} else if (days / 7 > 1) {
int day = days.intValue();
if (day % 7 > 0) {
return day / 7 + 1;
} else {
return day / 7;
}
} else if ((days / 7) == 0) {
return 0;
} else {
//负数返还null
return 0;
}
}
return 0;
}
public static int getDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.DATE);
}
/**
* 返回日期的月份,1-12,即yyyy-MM-dd中的MM
*
* @param date
* @return
*/
public static int getMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.MONTH) + 1;
}
/**
* 返回日期的年,即yyyy-MM-dd中的yyyy
*
* @param date Date
* @return int
*/
public static int getYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.YEAR);
}
public long betweenWeek(boolean isReset, Date begin, Date end) {
final Calendar beginCal = DateUtil.calendar(begin);
final Calendar endCal = DateUtil.calendar(end);
final int betweenYear = endCal.get(Calendar.YEAR) - beginCal.get(Calendar.YEAR);
final int betweenMonthOfYear = endCal.get(Calendar.MONTH) - beginCal.get(Calendar.MONTH);
endCal.get(Calendar.WEEK_OF_YEAR);
int result = betweenYear * 12 + betweenMonthOfYear;
if (false == isReset) {
endCal.set(Calendar.YEAR, beginCal.get(Calendar.YEAR));
endCal.set(Calendar.MONTH, beginCal.get(Calendar.MONTH));
long between = endCal.getTimeInMillis() - beginCal.getTimeInMillis();
if (between < 0) {
return result - 1;
}
}
return result;
}
/**
* 传入两个时间范围,返回这两个时间范围内的所有日期,并保存在一个集合中
*
* @param beginTime
* @param endTime
* @return
* @throws Exception
*/
public static List<Map<String, String>> findEveryDay(String beginTime, String endTime) throws Exception {
List<Map<String, String>> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
Map<String, String> map = new HashMap<>();
map.put(sdf.format(dBegin), sdf.format(dBegin));
dates.add(map);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
while (dEnd.after(calBegin.getTime())) {
map = new HashMap<>();
calBegin.add(Calendar.DAY_OF_MONTH, 1);
map.put(sdf.format(calBegin.getTime()), sdf.format(calBegin.getTime()));
dates.add(map);
}
return dates;
}
public static List<JSONObject> findEveryDayJson(String beginTime, String endTime) throws Exception {
List<JSONObject> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
JSONObject map = new JSONObject();
map.put("timeInterval", sdf.format(dBegin));
map.put("printCount", 0);
map.put("examineCount", 0);
dates.add(map);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
while (dEnd.after(calBegin.getTime())) {
map = new JSONObject();
calBegin.add(Calendar.DAY_OF_MONTH, 1);
map.put("timeInterval", sdf.format(calBegin.getTime()));
map.put("printCount", 0);
map.put("examineCount", 0);
dates.add(map);
}
return dates;
}
/**
* 传入两个时间范围,返回这两个时间范围内的所有月份,并保存在一个集合中
*
* @param beginTime
* @param endTime
* @return
* @throws Exception
*/
public static List<Map<String, String>> findEveryMonth(String beginTime, String endTime) throws Exception {
List<Map<String, String>> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
Map<String, String> map = new HashMap<>();
map.put(sdf.format(dBegin), sdf.format(dBegin));
dates.add(map);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
while (dEnd.after(calBegin.getTime())) {
map = new HashMap<>();
calBegin.add(Calendar.MONTH, 1);
map.put(sdf.format(calBegin.getTime()), sdf.format(calBegin.getTime()));
dates.add(map);
}
return dates;
}
public static List<JSONObject> findEveryMonthJson(String beginTime, String endTime) throws Exception {
List<JSONObject> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
JSONObject map = new JSONObject();
map.put("timeInterval", sdf.format(dBegin));
map.put("printCount", 0);
map.put("examineCount", 0);
dates.add(map);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
while (dEnd.after(calBegin.getTime())) {
map = new JSONObject();
calBegin.add(Calendar.MONTH, 1);
map.put("timeInterval", sdf.format(calBegin.getTime()));
map.put("printCount", 0);
map.put("examineCount", 0);
dates.add(map);
}
return dates;
}
/**
* 传入两个时间范围,返回这两个时间范围内的所有年,并保存在一个集合中
*
* @param beginTime
* @param endTime
* @return
* @throws Exception
*/
public static List<Map<String, String>> findEveryYear(String beginTime, String endTime) throws Exception {
List<Map<String, String>> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
Map<String, String> map = new HashMap<>();
map.put(sdf.format(dBegin), sdf.format(dBegin));
dates.add(map);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
while (dEnd.after(calBegin.getTime())) {
map = new HashMap<>();
calBegin.add(Calendar.YEAR, 1);
map.put(sdf.format(calBegin.getTime()), sdf.format(calBegin.getTime()));
dates.add(map);
}
return dates;
}
public static List<JSONObject> findEveryYearJson(String beginTime, String endTime) throws Exception {
List<JSONObject> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
JSONObject map = new JSONObject();
map.put("timeInterval", sdf.format(dBegin));
map.put("printCount", 0);
map.put("examineCount", 0);
dates.add(map);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
while (dEnd.after(calBegin.getTime())) {
map = new JSONObject();
calBegin.add(Calendar.YEAR, 1);
map.put("timeInterval", sdf.format(calBegin.getTime()));
map.put("printCount", 0);
map.put("examineCount", 0);
dates.add(map);
}
return dates;
}
/**
* 传入两个时间范围,返回这两个时间范围内的所有周,并保存在一个集合中
*
* @param beginTime
* @param endTime
* @return
* @throws Exception
*/
public static List<Map<String, String>> findEveryWeek(String beginTime, String endTime) throws Exception {
List<Map<String, String>> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
Map<String, String> map = new HashMap<>();
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
//设置星期一为一周开始的第一天
calBegin.setFirstDayOfWeek(Calendar.MONDAY);
while (!dEnd.before(calBegin.getTime())) {
String dayLimit = sdf.format(calBegin.getTime()) + "&";
int firstWeek = calBegin.get(Calendar.WEEK_OF_YEAR);
calBegin.add(Calendar.DAY_OF_MONTH, 1);
int weekOfYear = calBegin.get(Calendar.WEEK_OF_YEAR);
while (weekOfYear == firstWeek && !dEnd.before(calBegin.getTime())) {
calBegin.add(Calendar.DAY_OF_MONTH, 1);
weekOfYear = calBegin.get(Calendar.WEEK_OF_YEAR);
}
calBegin.add(Calendar.DAY_OF_MONTH, -1);
dayLimit = dayLimit + sdf.format(calBegin.getTime());
String key = StringUtils.EMPTY;
if (firstWeek < 10) {
key = sdf.format(calBegin.getTime()).substring(0, 4) + "-" + "0" + firstWeek;
} else {
key = sdf.format(calBegin.getTime()).substring(0, 4) + "-" + firstWeek;
}
map = new HashMap<>();
map.put(key, dayLimit);
calBegin.add(Calendar.DAY_OF_MONTH, 1);
dates.add(map);
}
return dates;
}
public static List<JSONObject> findEveryWeekJson(String beginTime, String endTime) throws Exception {
List<JSONObject> dates = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dBegin = sdf.parse(beginTime);
Date dEnd = sdf.parse(endTime);
JSONObject map;
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
//设置星期一为一周开始的第一天
calBegin.setFirstDayOfWeek(Calendar.MONDAY);
while (!dEnd.before(calBegin.getTime())) {
String dayLimit = sdf.format(calBegin.getTime()) + "&";
int firstWeek = calBegin.get(Calendar.WEEK_OF_YEAR);
calBegin.add(Calendar.DAY_OF_MONTH, 1);
int weekOfYear = calBegin.get(Calendar.WEEK_OF_YEAR);
while (weekOfYear == firstWeek && !dEnd.before(calBegin.getTime())) {
calBegin.add(Calendar.DAY_OF_MONTH, 1);
weekOfYear = calBegin.get(Calendar.WEEK_OF_YEAR);
}
calBegin.add(Calendar.DAY_OF_MONTH, -1);
dayLimit = dayLimit + sdf.format(calBegin.getTime());
String key = StringUtils.EMPTY;
if (firstWeek < 10) {
key = sdf.format(calBegin.getTime()).substring(0, 4) + "-" + "0" + firstWeek;
} else {
key = sdf.format(calBegin.getTime()).substring(0, 4) + "-" + firstWeek;
}
map = new JSONObject();
map.put("timeInterval", key);
map.put("printCount", 0);
map.put("examineCount", 0);
calBegin.add(Calendar.DAY_OF_MONTH, 1);
dates.add(map);
}
return dates;
}
}