SpringBoot在自定义类中调用service层mapper层
/**
我自己编写的工具类
*/
@Component
public class GetChartDataUtils {
private static GetChartDataUtils getChartDataUtils ;
@Autowired
private OrderMapper orderMapper;
@PostConstruct //通过@PostConstruct实现初始化bean之前进行的操作
public void init() {
getChartDataUtils = this;
getChartDataUtils.orderMapper=this.orderMapper;
// 初使化时将已静态化的orderMapper实例化
}
public static Trend<PosMonth> getOrgMonthTrend() {
Trend<PosMonth> posMonthTrend = new Trend<>();
posMonthTrend.setTitle("客源分析趋势");
posMonthTrend.setBase(300);
posMonthTrend.setUnit("万");
List<PosMonth> posMonths = new ArrayList<PosMonth>();
//封装每个出发地点每个月的数据
PosMonth zzgs = new PosMonth("郑州工商学院",getChartDataUtils.orderMapper.queryOriginMonthCount("郑州工商学院"));//出发地为郑州工商学院每个月的数据
PosMonth zzjt = new PosMonth("河南交通学院",getChartDataUtils.orderMapper.queryOriginMonthCount("河南交通学院"));//出发地为河南交通学院每个月的数据
PosMonth zkzx = new PosMonth("周口中心站",getChartDataUtils.orderMapper.queryOriginMonthCount("周口中心站"));//出发地为周口中心站每个月的数据
PosMonth zzly = new PosMonth("郑州旅游学院",getChartDataUtils.orderMapper.queryOriginMonthCount("郑州旅游学院"));//出发地为郑州旅游学院每个月的数据
//数据封装进趋势图
posMonths.add(zzgs);
posMonths.add(zzjt);
posMonths.add(zkzx);
posMonths.add(zzly);
posMonthTrend.setData(posMonths);
return posMonthTrend;
}
public static Trend<PosMonth> getDisMonthTrend() {
Trend<PosMonth> posMonthTrend = new Trend<>();
posMonthTrend.setTitle("去向分析趋势");
posMonthTrend.setBase(300);
posMonthTrend.setUnit("万");
List<PosMonth> posMonths = new ArrayList();
//封装每个去向地点每个月的数据
PosMonth zzgs = new PosMonth("周口火车站",getChartDataUtils.orderMapper.queryDestinationMonthCount("周口火车站"));//目的地为周口火车站每个月的数据
PosMonth zzjt = new PosMonth("周口市中心站",getChartDataUtils.orderMapper.queryDestinationMonthCount("周口市中心站"));//目的地为周口市中心站每个月的数据
PosMonth zkzx = new PosMonth("周口市淮阳",getChartDataUtils.orderMapper.queryDestinationMonthCount("周口市淮阳"));//目的地为周口市淮阳每个月的数据
PosMonth zzly = new PosMonth("周口市项城",getChartDataUtils.orderMapper.queryDestinationMonthCount("周口市项城"));//目的地为周口市项城每个月的数据
//数据封装进趋势图
posMonths.add(zzgs);
posMonths.add(zzjt);
posMonths.add(zkzx);
posMonths.add(zzly);
posMonthTrend.setData(posMonths);
return posMonthTrend;
}
}