前言
前面有一篇文章介绍了使用selenium获取上市公司半年报的方法,这篇文章就给这些数据写一个简单的前端展示页面
上一篇文章的链接在这里
【java爬虫】使用selenium获取某交易所公司半年报数据-优快云博客
首先来看一下整个页面的展示效果
前端页面采用vue+element-plus+axio进行编写,采用cdn的方式引入,只有一个index.html文件。
我们要展示的数据如下:
- 整体的统计数据(各种平均值)
- 经营收入排名前十的公司
- 净利润排名前十的公司
- 经营现金流排名前十的公司
- 资产收益率排名前十的公司
- 基本每股收益排名前十的公司
- 资产负债率排名前十的公司
第一个组数据用<el-descriptions>进行展示,后面的数据用<el-table>进行展示。
后端部分
我们需要写一些sql语句用于统计这些数据。
首先需要写一个用于获取第一组数据的实体类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class StatisticsEntity {
// 平均营业收入
private Double incomeavg;
// 平均净利润
private Double profit1avg;
// 平均经营现金流
private Double cashflowavg;
// 平均资产收益率
private Double rate1avg;
// 平均基本每股收益
private Double rate2avg;
// 平均资产负债率
private Double rate3avg;
}
接着是Mapper接口
@Mapper
public interface ReportMapper {
// 清空表
public void clearAll();
// 插入一条数据
public void insertOneItem(@Param("item")ReportEntity entity);
// 查询营业收入最高的十大公司
public List<ReportEntity> queryMaxIncome();
// 查询净利润最高的十大公司
public List<ReportEntity> queryMaxProfit();
// 查询经营现金流最高的十大公司
public List<ReportEntity> queryMaxCashflow();
// 查询净资产收益率最高的十大公司
public List<ReportEntity> queryMaxRate1();
// 查询每股收益最高的十大公司
public List<ReportEntity> queryMaxRate2();
// 查询资产负债率率最高的十大公司
public List<ReportEntity> queryMaxRate3();
// 平均营业收入
public Double queryIncomeAvg();
// 平均净利润
public Double queryProfit1Avg();
// 平均经营现金流
public Double queryCashflowAvg();
// 平均资产负债率
public Double queryRate1Avg();
// 平均基本每股收益
public Double queryRate2Avg();
// 平均资产负债率
public Double queryRate3Avg();
}
Mapper对应的xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.ReportMapper">
<sql id="select_columns">
company, stock, income, profit1, profit2, cashflow, rate1, rate2, rate3
</sql>
<delete id="clearAll">
delete from t_report where 1=1
</delete>
<insert id="insertOneItem" parameterType="ReportEntity">
insert into t_report
(company, stock, income, profit1, profit2, cashflow, rate1, rate2, rate3)
values
(#{item.company}, #{item.stock}, #{item.income}, #{item.profit1},
#{item.profit2}, #{item.cashflow}, #{item.rate1}, #{item.rate2}, #{item.rate3})
</insert>
<select id="queryMaxIncome" resultType="ReportEntity">
select
<include refid="select_columns"></include>
from t_report
order by income DESC
limit 10
</select>
<select id="queryMaxProfit" resultType="ReportEntity">
select
<include refid="select_columns"></include>
from t_report
order by profit1 DESC
limit 10
</select>
<select id="queryMaxCashflow" resultType="ReportEntity">
select
<include refid="select_columns"></include>
from t_report
order by cashflow DESC
limit 10
</select>
<select id="queryMaxRate1" resultType="ReportEntity">
select
<include refid="select_columns"></include>
from t_report
order by rate1 DESC
limit 10
</select>
<select id="queryMaxRate2" resultType="ReportEntity">
select
<include refid="select_columns"></include>
from t_report
order by rate2 DESC
limit 10
</select>
<select id="queryMaxRate3" resultType="ReportEntity">
select
<include refid="select_columns"></include>
from t_report
order by rate3 DESC
limit 10
</select>
<select id="queryIncomeAvg" resultType="Double">
select
avg(income)
from t_report
</select>
<select id="queryProfit1Avg" resultType="Double">
select
avg(profit1)
from t_report
</select>
<select id="queryCashflowAvg" resultType="Double">
select
avg(cashflow)
from t_report
</select>
<select id="queryRate1Avg" resultType="Double">
select
avg(rate1)
from t_report
</select>
<select id="queryRate2Avg" resultType="Double">
select
avg(rate2)
from t_report
</select>
<select id="queryRate3Avg" resultType="Double