java 实现查出日数据,根据日数据实现日、周、月char曲线图展示,月展示前6个月,周先生近7周数据,日展示近7天数据,具体展示多少天可以根据配置实现。
1、装换工具类定义
@Slf4j
public class CharMonthWeekDay {
/**
*
* @param timeType 日期范围 月 周 日
* @param
* @param dataFormat
* @param operationByDay 查询日数据
* @return
*/
public static List<ChartData> parse(TimeType timeType, String dataFormat,List<ChartData> operationByDay,Map<String, Double> mapCantChange) {
//SimpleDateFormat querySDF = new SimpleDateFormat(queryFormat == null ? "yyyy-MM-dd 00:00:00" : queryFormat);
Map<String,Double> map=new LinkedHashMap<>();
//防止改变外面的map
for(String key:mapCantChange.keySet()){
map.put(key,mapCantChange.get(key));
}
SimpleDateFormat dataSDF = new SimpleDateFormat(dataFormat == null ? "yyyy-MM-dd" : dataFormat);
Calendar instance = Calendar.getInstance();
instance.setFirstDayOfWeek(Calendar.MONDAY);
// List<ChartData> operationByDay = callback.query(begin, null, appName);
try {
Double val = 0.0;
for (ChartData chartData : operationByDay) {
String key = null;
Date date = dataSDF.parse(chartData.getX());
instance.setTime(date);
if (timeType.equals(TimeType.Day)) {
int month = instance.get(Calendar.MONTH) + 1;
int day = instance.get(Calendar.DAY_OF_MONTH);
key = String.format("%d月%d日", month, day);
} else if (timeType.equals(TimeType.Week)) {
int month = instance.get(Calendar.MONTH) + 1;
int week = instance.get(Calendar.WEEK_OF_MONTH) ;
key = String.format("%d月第%d周", month, week);
} else if (timeType.equals(TimeType.Month)