数据总览 - 食堂(超市)订单及销量趋势加入weekDay
This commit is contained in:
parent
db925f3fc1
commit
19ec96e0dc
|
|
@ -183,6 +183,9 @@ public class DataScreeningServiceImpl implements DataScreeningService {
|
|||
List<EchartsVO> result = dateList.stream().map(dateStr -> {
|
||||
EchartsVO echartsVO = dataMap.getOrDefault(dateStr, new EchartsVO());
|
||||
echartsVO.setOrderDate(dateStr);
|
||||
//根据日期设置星期几
|
||||
|
||||
echartsVO.setWeekday(getWeekday(dateStr));
|
||||
echartsVO.setSalesValue(Optional.ofNullable(echartsVO.getSalesValue())
|
||||
.map(value -> new BigDecimal(value).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).toString())
|
||||
.orElse("0"));
|
||||
|
|
@ -279,4 +282,26 @@ public class DataScreeningServiceImpl implements DataScreeningService {
|
|||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据日期字符串获取星期几
|
||||
*
|
||||
* @param dateStr 日期字符串,格式为yyyy-MM-dd
|
||||
* @return 星期几
|
||||
*/
|
||||
private String getWeekday(String dateStr) {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = sdf.parse(dateStr);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (dayOfWeek < 0) dayOfWeek = 0;
|
||||
return weekDays[dayOfWeek];
|
||||
} catch (Exception e) {
|
||||
log.error("日期转换异常", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ public class EchartsVO {
|
|||
private String salesValue;
|
||||
private String orderValue;
|
||||
private String orderDate;
|
||||
private String weekday;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue