修复周日均价查询bug

This commit is contained in:
2025-04-27 13:39:31 +08:00
parent d3fe040597
commit 8c175743e8
@@ -1604,9 +1604,13 @@ public class DistrictStatServiceImpl implements DistrictStatService {
if (startDate == null) { if (startDate == null) {
throw new IllegalArgumentException("开始日期不能为空"); throw new IllegalArgumentException("开始日期不能为空");
}else {
startDate = DateUtil.truncateDay(startDate);
} }
if (endDate == null) { if (endDate == null) {
throw new IllegalArgumentException("结束日期不能为空"); throw new IllegalArgumentException("结束日期不能为空");
}else {
endDate = DateUtil.truncateDay(endDate);
} }
if (StringUtils.isBlank(periodModel)) { if (StringUtils.isBlank(periodModel)) {
periodModel = "weekly"; periodModel = "weekly";
@@ -1642,7 +1646,6 @@ public class DistrictStatServiceImpl implements DistrictStatService {
sortParams.add(new SortParam("weekend", true)); sortParams.add(new SortParam("weekend", true));
List<DistrictStat> dss = this.districtStatDao.findAllByParams(params, sortParams); List<DistrictStat> dss = this.districtStatDao.findAllByParams(params, sortParams);
if (null == dss || dss.isEmpty()) {// 如果没有在小区均价表中查到均价数据,通过城市的价格计算小区均价 if (null == dss || dss.isEmpty()) {// 如果没有在小区均价表中查到均价数据,通过城市的价格计算小区均价
List<QueryParam> cityQueryParams = new ArrayList<QueryParam>(); List<QueryParam> cityQueryParams = new ArrayList<QueryParam>();
cityQueryParams.add(new QueryParam("city", city)); cityQueryParams.add(new QueryParam("city", city));
cityQueryParams.add(new QueryParam("region", region)); cityQueryParams.add(new QueryParam("region", region));
@@ -1708,15 +1711,35 @@ public class DistrictStatServiceImpl implements DistrictStatService {
} }
List<Date> timeSeries = generateTimeSeries(weekendDates.get(0), endDate, periodModel); List<Date> timeSeries = generateTimeSeries(weekendDates.get(0), endDate, periodModel);
Map<Date, DistrictStat> statMap = new HashMap<Date, DistrictStat>(); Map<Date, DistrictStat> statMap = new HashMap<Date, DistrictStat>();
for (DistrictStat districtStat : dss) { for (DistrictStat districtStat : dss) {
if (timeSeries.contains(districtStat.getWeekend())) { if (timeSeries.contains(districtStat.getWeekend())) {
statMap.put(districtStat.getWeekend(), districtStat); statMap.put(districtStat.getWeekend(), districtStat);
} }
} }
if("monthly".equals(periodModel)){
Date firstWeekendOfMonth = DateUtil.getFirstWeekendOfMonth(endDate);
List<DistrictStat> stats = districtStatService.findDistrictStat(new DistrictKey(city, region, name), null , firstWeekendOfMonth, endDate);
if(stats.isEmpty()){
Date sunDay = DateUtil.getFirstDayOfWeek(endDate);
if(!timeSeries.contains(sunDay)){
timeSeries.add(sunDay);
}
}else{
if(DateUtil.isSunday(endDate)){
timeSeries.remove(endDate);
}else{
timeSeries.remove(DateUtil.getLastSunday(endDate));
}
for(int i = stats.size()-1; i >= 0; i--){
if (!timeSeries.contains(stats.get(i).getWeekend())){
statMap.put(stats.get(i).getWeekend(), stats.get(i));
timeSeries.add(stats.get(i).getWeekend());
}
break;
}
}
}
for (Date time : timeSeries) { for (Date time : timeSeries) {
if (!statMap.containsKey(time)) { if (!statMap.containsKey(time)) {
DistrictStat districtStat = new DistrictStat(); DistrictStat districtStat = new DistrictStat();
@@ -1772,10 +1795,6 @@ public class DistrictStatServiceImpl implements DistrictStatService {
monthlyDates.add(date); monthlyDates.add(date);
} }
} }
Date sunDay = DateUtil.getFirstDayOfWeek(endDate);
if (!monthlyDates.contains(sunDay)) {
monthlyDates.add(sunDay);
}
return monthlyDates; return monthlyDates;
} else { } else {
throw new IllegalArgumentException("非法的计算周期"); throw new IllegalArgumentException("非法的计算周期");