|
@@ -289,18 +289,42 @@ public class PcBladeSalesForecastMainServiceImpl extends BaseServiceImpl<PcBlade
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据年份和月份查询销售预测数据(支持查询全部)
|
|
|
+ * 当year和month都为null时,查询所有数据;任一参数不为null时,按对应条件过滤
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<PcBladeSalesForecastMain> findByYearAndMonth(Integer year, Integer month) {
|
|
|
QueryWrapper<PcBladeSalesForecastMain> mainQuery = new QueryWrapper<>();
|
|
|
- mainQuery.eq("year", year)
|
|
|
- .eq("month", month);
|
|
|
+
|
|
|
+ // 动态添加年份条件:仅当year不为null时生效
|
|
|
+ if (year != null) {
|
|
|
+ mainQuery.eq("year", year);
|
|
|
+ }
|
|
|
+ // 动态添加月份条件:仅当month不为null时生效
|
|
|
+ if (month != null) {
|
|
|
+ mainQuery.eq("month", month);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询主表数据
|
|
|
List<PcBladeSalesForecastMain> mainList = baseMapper.selectList(mainQuery);
|
|
|
|
|
|
+ // 为每个主表数据匹配对应的明细表数据(同步主表的条件逻辑)
|
|
|
for (PcBladeSalesForecastMain main : mainList) {
|
|
|
QueryWrapper<PcBladeSalesForecastSummary> summaryQuery = new QueryWrapper<>();
|
|
|
- summaryQuery.eq("forecast_main_id", main.getId())
|
|
|
- .eq("year", year)
|
|
|
- .eq("month", month);
|
|
|
+ // 关联主表ID(必选条件,确保明细表属于当前主表)
|
|
|
+ summaryQuery.eq("forecast_main_id", main.getId());
|
|
|
+
|
|
|
+ // 明细表同步主表的年份条件(仅当year不为null时添加)
|
|
|
+ if (year != null) {
|
|
|
+ summaryQuery.eq("year", year);
|
|
|
+ }
|
|
|
+ // 明细表同步主表的月份条件(仅当month不为null时添加)
|
|
|
+ if (month != null) {
|
|
|
+ summaryQuery.eq("month", month);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询明细表数据并设置到主表中
|
|
|
List<PcBladeSalesForecastSummary> summaryList = summaryMapper.selectList(summaryQuery);
|
|
|
main.setPcBladeSalesForecastSummaryList(summaryList);
|
|
|
}
|
|
@@ -310,21 +334,38 @@ public class PcBladeSalesForecastMainServiceImpl extends BaseServiceImpl<PcBlade
|
|
|
|
|
|
/**
|
|
|
* 根据用户ID、年份和月份查询销售预测数据
|
|
|
+ * 当year或month为null时,查询该用户的全部数据
|
|
|
*/
|
|
|
@Override
|
|
|
public List<PcBladeSalesForecastMain> findByUserAndYearAndMonth(Long userId, Integer year, Integer month) {
|
|
|
QueryWrapper<PcBladeSalesForecastMain> mainQuery = new QueryWrapper<>();
|
|
|
- mainQuery.eq("year", year)
|
|
|
- .eq("month", month)
|
|
|
- .eq("CUSTOMER_ID", userId);
|
|
|
+ // 始终按用户ID过滤
|
|
|
+ mainQuery.eq("CUSTOMER_ID", userId);
|
|
|
+
|
|
|
+ // 动态添加年份条件(仅当year不为null时)
|
|
|
+ if (year != null) {
|
|
|
+ mainQuery.eq("year", year);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 动态添加月份条件(仅当month不为null时)
|
|
|
+ if (month != null) {
|
|
|
+ mainQuery.eq("month", month);
|
|
|
+ }
|
|
|
|
|
|
List<PcBladeSalesForecastMain> mainList = baseMapper.selectList(mainQuery);
|
|
|
|
|
|
for (PcBladeSalesForecastMain main : mainList) {
|
|
|
QueryWrapper<PcBladeSalesForecastSummary> summaryQuery = new QueryWrapper<>();
|
|
|
- summaryQuery.eq("forecast_main_id", main.getId())
|
|
|
- .eq("year", year)
|
|
|
- .eq("month", month);
|
|
|
+ summaryQuery.eq("forecast_main_id", main.getId());
|
|
|
+
|
|
|
+ // 明细表也同步添加年份和月份条件(如果有)
|
|
|
+ if (year != null) {
|
|
|
+ summaryQuery.eq("year", year);
|
|
|
+ }
|
|
|
+ if (month != null) {
|
|
|
+ summaryQuery.eq("month", month);
|
|
|
+ }
|
|
|
+
|
|
|
List<PcBladeSalesForecastSummary> summaryList = summaryMapper.selectList(summaryQuery);
|
|
|
main.setPcBladeSalesForecastSummaryList(summaryList);
|
|
|
}
|