springboot+mybatis+echarts前后端的分离疫情防控大数据分析

2020年的新型冠状病毒来临,大家都在家待着,我们计算机专业博士的老师让我做一个我校(本科院校)疫情防控大数据分析,我当时也刚学会springboot的增删改查和拦截器,就开始上手做这个系统,所有的技术都是初次使用,springboot第一次用,mybatis-plus(mybatis的升级版)第一次用,echarts初次使用,因为前后端传值要使用json,所以只好用前后端分离来做,刚好也可以锻炼自己,其实在做这个项目之前,也一直想学echarts的使用,但无奈网上一直没有合适的教程,我用的是boot2.2.4从网上找boot结合echarts的教程,没有合适的,于是就硬着头皮做这个大数据分析的项目,做了大概一周,遇到的坑很多,来回修修改改,不过自己学到了很多,所以就想写此博客记录此次开发的经历。

先放几张效果图吧(敏感内容我要去掉),第一版(有各个学院的信息,所有学生的体温信息组成的那条黄线后期版本去掉了)

第二版(由于学生信息过多于是就去掉了体温的信息,保留了其他)

第三版:

(添加了一些更具体的信息,增加了查询功能)

终版:(优于部分学生所填信息不属实,就去掉了相关圆圈所显示的信息),最终的版本,可以缓一缓了。

通过此项目学到了很多很多知识,

  1. mysql根据汉字拼音首字母排序
    按照汉字的拼音排序,用的比较多是在人名的排序中,按照姓氏的拼音字母,从A到Z排序;(name是排序的字段)
    
    如果存储姓名的字段采用的是GBK字符集,那就好办了,因为GBK内码编码时本身就采用了拼音排序的方法(常用一级汉字3755个采用拼音排序,二级汉字就不是了,但考虑到人名等都是常用汉字,因此只是针对一级汉字能正确排序也够用了)。
    
    直接在查询语句后面 添加 order by name asc; 查询结果按照姓氏的升序排序;
    
    如果存储姓名的字段采用的是 utf8字符集,需要在排序的时候对字段进行转码;对应的代码是 order by convert(name using gbk) asc; 同样,查询的结果也是按照姓氏的升序排序;
  2. jq对div,span等很多标签赋值、取值

input标签可以用$("#id").val();

span标签可以用$("#id").text();

赋值:在text后边的括号里加上值就好

//1, 纯js获取数据

var a = document.getElementById("id1").innerText;

//2, jqeury获取数据

var a = $("#id1").html();

var b = $("#id1").text();

alert(a + "1234");

alert(b + "5678");

//3, 纯js写入数据

document.getElementById("id2").innerHTML = "id2";

//4,jqeury写入数据

$('#id3').html("id3");

$("#id4").text("id4");

//div 引入其他页面

//load只能引入自己内部页面

$('.content-wrap-inner').html('');

$('.content-wrap-inner').load("test.html");

//网址引入不进去

//$('#id5').load("http://www.baidu.com/");

$('#id5').load("test.html");

3.js定时器

window.setInterval(function () {
        countStudent();// 函数
        load_echarts_5();//函数
    }, 5000);

4.echart给坐标轴添加点击事件

myChart.on('click', function (params) {
           当componentType == "xAxis"或者 ==“yAxisx”时,取被点击时坐标轴的值params.value
               alert("单击了"+params.componentType+"x轴标签"+params.value);
           if(params.componentType == "xAxis"){ 
               alert("单击了"+params.value+"x轴标签"); 
           }else if (params.componentType == "yAxis") {
               alert("单击了"+params.value+"y轴标签"); 
           }
           else{  // 最核心的部分
              alert("单击了"+params.name+"柱状图"+params.value); 
           }  

        // invalid start
        //     获取data长度
        //   alert(option.series[0].data.length);
        //      获取地N个data的值
        //   alert(option.series[0].data[3]);
        //     获取series中param.dataIndex事件对应的值
        // alert(params.dataIndex);
        //   alert(option.series[params.seriesIndex].data[params.dataIndex]);
        //invalid end
            // alert(param.value);
        //    获取xAxis当前点击事件索引对应的值,可以用作传参
              // alert("test "+option.xAxis.data[params.dataIndex]);    
          //param.dataIndex 获取当前点击索引,
        //   alert(param.dataIndex);
        //  当前点击事件位于series中的索引
        //   alert(param.seriesIndex);
        //param具体包含的参数见 https://blog.csdn.net/allenjay11/article/details/76033232
          updatePage(option.xAxis.data[params.dataIndex],params.value);
          refresh();
        });
    </script>
<script type="text/javascript">
  function updatePage(tag, value){
    var xAxisTag = $("#xAxisTag"); 
    xAxisTag.html(tag);
    var barValue = $("#barValue"); 
    barValue.html(value);
  };
  function refresh(){           
  // 刷新页面
  // location.reload();
      //window.location.reload();   
      //局部刷新main内容
      //此处没有用常用的刷新div等方法,而是直接改变了option的值,然后重新赋值给myChart
      console.log("refresh");
      option.title.text='入门';
      // option.series.data[0] = Math.floor(Math.random()*50+1);
      // option.series.data[1] = Math.floor(Math.random()*50+1);
      // option.series.data[2] = Math.floor(Math.random()*50+1);
      // option.series.data[3] = Math.floor(Math.random()*50+1);
      // option.series.data[4] = Math.floor(Math.random()*50+1);
      // option.series.data[5] = Math.floor(Math.random()*50+1);
      //console.log(option.series.data[0]);
      //var v1 = Math.floor(Math.random()*50+1);
      //option.series.data[0] = v1;
      //简化方法,调用getSeriesData更新数据。
      option.series.data = getSeriesData();
      myChart.setOption(option);
  };     
</script>

5.lombok插件

我的项目里使用了lombok,就不需要写get和set方法了,就很省事,开发不用写,编译的时候会把get和set方法编译到里面去

6.echarts配置项详解,echarts的表格的初始化和数据刷新是分开的,先初始化,后刷新数据,这也是一个坑,后来看的官方文档。

mytextStyle={
color:"#333", //文字颜色
fontStyle:"normal", //italic斜体 oblique倾斜
fontWeight:"normal", //文字粗细bold bolder lighter 100 | 200 | 300 | 400...
fontFamily:"sans-serif", //字体系列
fontSize:18, //字体大小
};
mylineStyle={
color:"#333", //颜色,'rgb(128, 128, 128)','rgba(128, 128, 128, 0.5)',支持线性渐变,径向渐变,纹理填充
shadowColor:"red", //阴影颜色
shadowOffsetX:0, //阴影水平方向上的偏移距离。
shadowOffsetY:0, //阴影垂直方向上的偏移距离
shadowBlur:10, //图形阴影的模糊大小。
type:"solid", //坐标轴线线的类型,solid,dashed,dotted
width:1, //坐标轴线线宽
opacity:1, //图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形
};
myareaStyle={
color:['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)'],//分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
shadowColor:"red", //阴影颜色
shadowOffsetX:0, //阴影水平方向上的偏移距离。
shadowOffsetY:0, //阴影垂直方向上的偏移距离
shadowBlur:10, //图形阴影的模糊大小。
opacity:1, //图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形
};


grid=[{
show:true, //是否显示
zlevel:0, //所属图形的Canvas分层,zlevel 大的 Canvas 会放在 zlevel 小的 Canvas 的上面
z:2, //所属组件的z分层,z值小的图形会被z值大的图形覆盖
left:"10%", //组件离容器左侧的距离,百分比字符串或整型数字
top:60, //组件离容器上侧的距离,百分比字符串或整型数字
right:"auto", //组件离容器右侧的距离,百分比字符串或整型数字
bottom:"auto", //组件离容器下侧的距离,百分比字符串或整型数字
width:"auto", //图例宽度
height:"auto", //图例高度
containLabel: true, //grid 区域是否包含坐标轴的刻度标签,
backgroundColor:"transparent", //标题背景色
borderColor:"#ccc", //边框颜色
borderWidth:0, //边框线宽
shadowColor:"red", //阴影颜色
shadowOffsetX:0, //阴影水平方向上的偏移距离
shadowOffsetY:0, //阴影垂直方向上的偏移距离
shadowBlur:10, //阴影的模糊大小
tooltip:{ //坐标系特定的 tooltip 设定
show:true, //是否显示提示框组件,包括提示框浮层和 axisPointer
trigger:"axis", //触发类型 none不触发 'item' 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。 'axis' 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
position: ['50%', '50%'], //提示框浮层的位置,默认不设置时位置会跟随鼠标的位置,[10, 10],回掉函数,inside鼠标所在图形的内部中心位置,top、left、bottom、right鼠标所在图形上侧,左侧,下侧,右侧,
formatter:"{b0}: {c0}<br />{b1}: {c1}", //提示框浮层内容格式器,支持字符串模板和回调函数两种形式,模板变量有 {a}, {b},{c},{d},{e},分别表示系列名,数据名,数据值等
backgroundColor:"transparent", //标题背景色
borderColor:"#ccc", //边框颜色
borderWidth:0, //边框线宽
padding:5, //图例内边距,单位px 5 [5, 10] [5,10,5,10]
textStyle:mytextStyle, //文本样式
},
}];
xAxis=[
{
show:true, //是否显示 x 轴
gridIndex:0, //x 轴所在的 grid 的索引,默认位于第一个 grid
position:"bottom", //x 轴的位置。"top","bottom",默认 grid 中的第一个 x 轴在 grid 的下方('bottom'),第二个 x 轴视第一个 x 轴的位置放在另一侧
offset:0, //X 轴相对于默认位置的偏移,在相同的 position 上有多个 X 轴的时候有用
type:"category", //坐标轴类型。'value' 数值轴,适用于连续数据。'category' 类目轴,适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。
// 'time' 时间轴,适用于连续的时序数据,与数值轴相比时间轴带有时间的格式化,在刻度计算上也有所不同,例如会根据跨度的范围来决定使用月,星期,日还是小时范围的刻度。'log' 对数轴。适用于对数数据
name:'时间', //坐标轴名称
nameLocation:"end", //坐标轴名称显示位置。可选:'start','middle','end'
nameTextStyle:mytextStyle, //坐标轴名称的文字样式
nameGap:15, //坐标轴名称与轴线之间的距离
nameRotate:0, //坐标轴名字旋转,角度值
inverse:false, //是否是反向坐标轴
boundaryGap:true, //类目轴中 boundaryGap 可以配置为 true 和 false。非类目轴,包括时间,数值,对数轴,boundaryGap是一个两个值的数组,分别表示数据最小值和最大值的延伸范围,可以直接设置数值或者相对的百分比,在设置 min 和 max 后无效['20%', '20%']
min:null, //坐标轴刻度最小值。可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。不设置时会自动计算最小值保证坐标轴刻度的均匀分布。在类目轴中,也可以设置为类目的序数
max:null, //坐标轴刻度最大值。可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。不设置时会自动计算最大值保证坐标轴刻度的均匀分布。在类目轴中,也可以设置为类目的序数
scale:false, //只在数值轴中(type: 'value')有效。是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度。在双数值轴的散点图中比较有用。在设置 min 和 max 之后该配置项无效。
splitNumber:5, //坐标轴的分割段数,需要注意的是这个分割段数只是个预估值,最后实际显示的段数会在这个基础上根据分割后坐标轴刻度显示的易读程度作调整
minInterval:0, //自动计算的坐标轴最小间隔大小,例如可以设置成1保证坐标轴分割刻度显示成整数。只在数值轴中(type: 'value')有效。
logBase:10, //对数轴的底数,只在对数轴中(type: 'log')有效
silent:false, //坐标轴是否是静态无法交互
triggerEvent:false, //坐标轴的标签是否响应和触发鼠标事件
axisLine:{ //坐标 轴线
show:true, //是否显示坐标轴轴线
onZero:true, //X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效
lineStyle:mylineStyle
},
axisTick :{ //坐标轴刻度相关设置
show:true, //是否显示坐标轴刻度。
alignWithLabel:false, //类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐
interval:auto, //坐标轴刻度的显示间隔,在类目轴中有效。默认会采用标签不重叠的策略间隔显示标签。可以设置成 0 强制显示所有标签。如果设置为 1,表示『隔一个标签显示一个标签』,如果值为 2,表示隔两个标签显示一个标签,以此类推
inside:false, //坐标轴刻度是否朝内,默认朝外。
length:5, //坐标轴刻度的长度。
lineStyle:mylineStyle
},
axisLabel:{ //坐标轴刻度标签的相关设置
show:true, //是否显示
interval:"auto", //坐标轴刻度标签的显示间隔,在类目轴中有效。默认会采用标签不重叠的策略间隔显示标签。可以设置成 0 强制显示所有标签。如果设置为 1,表示『隔一个标签显示一个标签』,如果值为 2,表示隔两个标签显示一个标签,以此类推
inside:false, //刻度标签是否朝内,默认朝外
rotate:0, //刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。旋转的角度从 -90 度到 90 度
margin:8, //刻度标签与轴线之间的距离
formatter: function (value, index) { //使用函数模板,函数参数分别为刻度数值(类目),刻度的索引
return value+"kg";
},
showMinLabel:null, //是否显示最小 tick 的 label。可取值 true, false, null。默认自动判定(即如果标签重叠,不会显示最小 tick 的 label)
showMaxLabel:null, //是否显示最大 tick 的 label。可取值 true, false, null。默认自动判定(即如果标签重叠,不会显示最大 tick 的 label)
textStyle:mytextStyle
},
splitLine:{ //坐标轴在 grid 区域中的分隔线。
show:true, //是否显示分隔线。默认数值轴显示,类目轴不显示。
interval:"auto", //坐标轴分隔线的显示间隔,在类目轴中有效。默认会采用标签不重叠的策略间隔显示标签。可以设置成 0 强制显示所有标签。如果设置为 1,表示『隔一个标签显示一个标签』,可以用数值表示间隔的数据,也可以通过回调函数控制。回调函数格式如下:
lineStyle:mylineStyle
},
splitArea:{ //坐标轴在 grid 区域中的分隔区域,默认不显示。
interval:"auto",
show:false, //是否显示分隔区域
areaStyle:myareaStyle
},
data : ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], //类目数据,在类目轴(type: 'category')中有效。
zlevel:0, //X 轴所有图形的 zlevel 值。
z:0, //X 轴组件的所有图形的z值
}
];
yAxis=xAxis; //y轴配置内容同x轴

7.有一个错误困扰了我一天,我的项目打成war包部署时,一直报链接数据库有错,将csdn和博客园来回看了三遍相关的博客,最后老师一说,找到解决办法了。

错误是:“org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean”

解决方案如下:

1) service接口实现类上有没有加@Service注解,注解是不是引用的spring的类?不要导错包

2) 接口有没有写实现类,实现类是实现的对应接口么?比如CategoryServiceImpl implementsCategoryDAO 一不小心根据自动提示,本来应该实现CategoryService,结果实现了CategoryDAO

3) 有没有扫描Service所在的
4)确保代码无误后,再看看包是否下载完整

5)查看注入是否正确

经历过以上解决办法之后我的项目还是报链接数据库有问题
解决办法如下:

spring:
  datasource:
    username: root
    password: 
    url: jdbc:mysql://127.0.0.1:3306/coronavirus?useUnicode=true&characterEncoding=utf-8&userSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver

我写的ip一开始时服务器的ip,部署到服务器上,要改成127.0.0.1,具体为啥,有点玄学,有人说是版本问题。

下面具体介绍开发经历:

我用的是一个大数据分析的前端echarts模板,结合我校的需求修修改改,就把前端弄得差不多了。

在此处也学到了一些前端的知识,会在文章的最后介绍,然后就开始进入后端的开发。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>yqfx.system</groupId>
    <artifactId>yqfx</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>yqfx</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--jdbc-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        
        <!--servlet-api 打war包时用-->
       <!--<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>-->
        <!--web开发,打war包时移除tomcat-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--<exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>-->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.6</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>yqfx</finalName>
    </build>

</project>

继续写配置文件,我删除了自带的applicaiton.propertites,新建了application.yml,application-dev.yml,application-prod.yml

application.yml(激活的是开发环境dev)

spring:
  profiles:
    active: dev

application-dev.yml

spring:
  datasource:
    username: root
    password: 数据库密码
    url: jdbc:mysql://127.0.0.1:3306/数据库?useUnicode=true&characterEncoding=utf-8&userSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver
  thymeleaf:
    cache: false
    prefix: classpath:/templates/
    suffix: .html
    encoding: UTF-8
    mode: html5
    servlet:
      content-type: text/html

mybatis-plus:
  mapper-locations: classpath:/mapper/*.xml
  type-aliases-package: yqfx.system.entity
  configuration:
    map-underscore-to-camel-case: true

server:
  port: 8089
  servlet:
    context-path: /yqfx

创建entity(ma作为类对象转化成json返回前端,Spring Boot 中默认使用的 JSON 解析框架是 Jackson),我是用lombok插件,我就可以不用写get和set方法,使用@Data注解就可以

CollegeRate.java

package yqfx.system.entity;


import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Author: Coffee君
 * Time: 2020/2/17 15:16
 * Description: No Description
 */
@Component
@Data
public class CollegeRate {
    private String collegename;
    private Integer num;
    private Integer allstudent;
}

Count.java

package yqfx.system.entity;

import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Author: Coffee君
 * Time: 2020/2/17 9:51
 * Description: No Description
 */
@Component
@Data
public class Count {
    private Integer countStudent; //总的签到人数
}

Student.java

package yqfx.system.entity;

import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Author: Coffee君
 * Time: 2020/2/15 22:32
 * Description: No Description
 */
@Component
@Data
public class Student {
    private Integer id;
    private String ybRealname;
    private String ybCollegename;
    private String ybClassname;
    private String ybStudentid;
    private String temperature;
}

ZhiBiao.java

package yqfx.system.entity;

import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Author: Coffee君
 * Time: 2020/2/16 20:08
 * Description: No Description
 */
@Component
@Data
public class ZhiBiao {
    private Integer v1; // v1
    private Integer v2; // v2
}

然后开始创建mapeer和相应的xml文件

EchartMapper.java

package yqfx.system.mapper;

import org.springframework.stereotype.Repository;
import yqfx.system.entity.CollegeRate;
import yqfx.system.entity.Student;

import java.util.List;
import java.util.Map;


/**
 * Created with IntelliJ IDEA.
 * Author: Coffee君
 * Time: 2020/2/15 22:26
 * Description: No Description
 */
@Repository
public interface EchartMapper {

    // 查询总签到人数
    int countStudent();

    int notHbCountTouchAll();

    // 查询学生是否签到
    Student search(String studentid);

    // 查询非湖北与病例接触
    int notHbCountTouch(String collegename);

    int hbCountTouchAll();

    // 查询湖北与病例接触
    int hbCountTouch(String collegename);

    int notHbCountHotAll();

    // 查询非湖北发热人数
    int notHbCountHot(String collegename);

    int hbCountHotAll();

    // 查询湖北发热人数
    int hbCountHot(String collegename);

    int notHbCountIllAll();

    // 查询非湖北确诊人数
    int notHbCountIll(String collegename);

    int hbCountIllAll();

    // 查询湖北确诊人数
    int hbCountIll(String collegename);

    // 查询非湖北重症人数

    // 查询湖北重症人数

    int  notHbFixIsolatedAll();

    // 查询非湖北定点隔离人数
    int  notHbFixIsolated(String collegename);

    int  hbFixIsolatedAll();

    // 查询湖北定点隔离人数
    int  hbFixIsolated(String collegename);

    int  notHbHomeIsolatedAll();

    // 查询非湖北居家隔离人数
    int  notHbHomeIsolated(String collegename);

    int  hbHomeIsolatedAll();

    // 查询湖北居家隔离人数
    int  hbHomeIsolated(String collegename);

    int notHbHospitalAll();

    // 查询非湖北住院治疗人数
    int notHbHospital(String collegename);

    int hbHospitalAll();

    // 查询湖北住院治疗人数
    int hbHospital(String collegename);

    // 查询各学院签到人数
    List<CollegeRate> collegeRateRank();

    // 查询某学院签到人数
    int countCollegeStudent(String collegename);

    // 查询本学院学生签到信息
    List<Student> collegeStudentInfo(String collegename);

}

在类路径下的resources创建mapper文件夹(我前面是这样配的)

<?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="yqfx.system.mapper.EchartMapper">

    <select id="countStudent" resultType="Int">
        SELECT count(DISTINCT yb_userid) from qiandao
    </select>

    <select id="search" resultType="yqfx.system.entity.Student">
        select yb_realname,yb_studentid,yb_userid from qiandao where yb_studentid=#{yb_studentid}
    </select>

    <!-- 查询非湖北与病例接触 -->
    <select id="notHbCountTouchAll" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 1), '|', -1)) = '是'
    </select>

    <!-- 查询非湖北与病例接触 -->
    <select id="notHbCountTouch" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 1), '|', -1)) = '是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询湖北与病例接触 -->
    <select id="hbCountTouchAll" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 5), '|', -1)) = '是'
    </select>

    <!-- 查询湖北与病例接触 -->
    <select id="hbCountTouch" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 5), '|', -1)) = '是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询非湖北发热人数 -->
    <select id="notHbCountHotAll" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 2), '|', -1)) = '是'
    </select>

    <!-- 查询非湖北发热人数 -->
    <select id="notHbCountHot" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 2), '|', -1)) = '是' and yb_collegename = #{collegename}
    </select>

    <select id="hbCountHotAll" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 1), '|', -1)) = '是'
    </select>

    <select id="hbCountHot" resultType="Int">
        SELECT count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 1), '|', -1)) = '是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询非湖北确诊 -->
    <select id="notHbCountIllAll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 4), '|', -1)) ='是'
    </select>

    <!-- 查询非湖北确诊 -->
    <select id="notHbCountIll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 4), '|', -1)) ='是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询湖北确诊 -->
    <select id="hbCountIllAll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 3), '|', -1)) ='是'
    </select>

    <!-- 查询湖北确诊 -->
    <select id="hbCountIll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 3), '|', -1)) ='是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询非湖北定点隔离 -->
    <select id="notHbFixIsolatedAll" resultType="Int">
       select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 5), '|', -1)) ='定点隔离'
    </select>

    <!-- 查询非湖北定点隔离 -->
    <select id="notHbFixIsolated" resultType="Int">
       select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 5), '|', -1)) ='定点隔离' and yb_collegename = #{collegename}
    </select>

    <!-- 查询湖北定点隔离 -->
    <select id="hbFixIsolatedAll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 6), '|', -1)) ='定点隔离'
    </select>

    <!-- 查询湖北定点隔离 -->
    <select id="hbFixIsolated" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 6), '|', -1)) ='定点隔离' and yb_collegename = #{collegename}
    </select>

    <!-- 查询非湖北居家隔离 -->
    <select id="notHbHomeIsolatedAll" resultType="Int">
       select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 5), '|', -1)) ='居家隔离'
    </select>

    <!-- 查询非湖北居家隔离 -->
    <select id="notHbHomeIsolated" resultType="Int">
       select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 5), '|', -1)) ='居家隔离' and yb_collegename = #{collegename}
    </select>

    <!-- 查询湖北居家隔离 -->
    <select id="hbHomeIsolatedAll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 6), '|', -1)) ='居家隔离'
    </select>

    <!-- 查询湖北居家隔离 -->
    <select id="hbHomeIsolated" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 6), '|', -1)) ='居家隔离' and yb_collegename = #{collegename}
    </select>

    <!-- 查询非湖北住院治疗 -->
    <select id="notHbHospitalAll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 7), '|', -1)) ='是'
    </select>

    <!-- 查询非湖北住院治疗 -->
    <select id="notHbHospital" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 0 and (select substring_index(substring_index(wenjuan, '|', 7), '|', -1)) ='是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询湖北住院治疗 -->
    <select id="hbHospitalAll" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 8), '|', -1)) ='是'
    </select>

    <!-- 查询湖北住院治疗 -->
    <select id="hbHospital" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 8), '|', -1)) ='是' and yb_collegename = #{collegename}
    </select>


    <!-- 查询非湖北家人被确诊 -->

    <!-- 查询湖北家人确诊 -->
    <select id="hbDiagnosis" resultType="Int">
        select count(DISTINCT yb_userid) FROM qiandao where is_hb = 1 and (select substring_index(substring_index(wenjuan, '|', 4), '|', -1)) ='是' and yb_collegename = #{collegename}
    </select>

    <!-- 查询各学院签到人数 -->
    <select id="collegeRateRank" resultType="yqfx.system.entity.CollegeRate">
     select yb_collegename as collegename ,count(DISTINCT yb_userid) as num from qiandao WHERE yb_collegename !='' GROUP BY yb_collegename order by convert(yb_collegename using gbk) asc
    </select>

    <!-- 查询某学院签到人数 -->
    <select id="countCollegeStudent" resultType="Int">
     select count(DISTINCT yb_userid) from qiandao WHERE yb_collegename = #{collegename}
    </select>

    <!-- 查询本学院学生签到信息 -->
    <select id="collegeStudentInfo" resultType="yqfx.system.entity.Student">
        select id, yb_realname as ybRealname, yb_classname as ybClassname,yb_studentid as ybStudentid ,(select substring_index(substring_index(wenjuan, '|', 1), '|', -1)) as temperature from qiandao WHERE yb_collegename = #{collegename}
    </select>

</mapper>

然后创建service层

service.java

package yqfx.system.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yqfx.system.entity.CollegeRate;
import yqfx.system.entity.Student;
import yqfx.system.mapper.EchartMapper;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Author: Coffee君
 * Time: 2020/2/15 22:25
 * Description: No Description
 */
@Service
public class EchartService {

    @Autowired
    private EchartMapper echartMapper;

    // 查询总签到人数
    public int countStudent() {
        return echartMapper.countStudent();
    }

    // 查询学生是否签到
    public Student search(String studentid){
        return echartMapper.search(studentid);
    }

    // 查询1月8日以来与确诊或者疑似病例接触人数
    public int countTouchAll() {
        return echartMapper.notHbCountTouchAll() + echartMapper.hbCountTouchAll();
    }

    // 查询1月8日以来与确诊或者疑似病例接触人数
    public int countTouch(String collegename) {
        return echartMapper.notHbCountTouch(collegename) + echartMapper.hbCountTouch(collegename);
    }

    // 查询发热人数 = 非湖北发热人数 + 湖北发热人数
    public int counthotAll() {
        return echartMapper.notHbCountHotAll() + echartMapper.notHbCountHotAll();
    }

    // 查询发热人数 = 非湖北发热人数 + 湖北发热人数
    public int counthot(String collegename) {
        return echartMapper.notHbCountHot(collegename) + echartMapper.notHbCountHot(collegename);
    }

    // 查询确诊人数 = 非湖北确诊 + 湖北确诊
    public int countIllAll(){
        return echartMapper.notHbCountIllAll() + echartMapper.hbCountIllAll();
    }

    // 查询确诊人数 = 非湖北确诊 + 湖北确诊
    public int countIll(String collegename){
        return echartMapper.notHbCountIll(collegename) + echartMapper.hbCountIll(collegename);
    }
    // 查询重症人数 = 非湖北重症 + 湖北重症

    // 查询定点隔离人数 = 非湖北定点隔离 + 湖北定点隔离
    public int countFixIsloatedAll(){
        return echartMapper.notHbFixIsolatedAll() + echartMapper.hbFixIsolatedAll();
    }

    // 查询定点隔离人数 = 非湖北定点隔离 + 湖北定点隔离
    public int countFixIsloated(String collegename){
        return echartMapper.notHbFixIsolated(collegename) + echartMapper.hbFixIsolated(collegename);
    }

    // 查询居家隔离人数 = 非湖北居家隔离 + 湖北居家隔离
    public int countHomeIsloatedAll(){
        return echartMapper.notHbHomeIsolatedAll() + echartMapper.hbHomeIsolatedAll();
    }

    // 查询居家隔离人数 = 非湖北居家隔离 + 湖北居家隔离
    public int countHomeIsloated(String collegename){
        return echartMapper.notHbHomeIsolated(collegename) + echartMapper.hbHomeIsolated(collegename);
    }

    // 查询住院治疗 = 非湖北住院 + 湖北住院治疗
    public int countHospitalAll(){
        return echartMapper.notHbHospitalAll() + echartMapper.hbHospitalAll();
    }

    // 查询住院治疗 = 非湖北住院 + 湖北住院治疗
    public int countHospital(String collegename){
        return echartMapper.notHbHospital(collegename) + echartMapper.hbHospital(collegename);
    }

    // 查询某学院签到人数
    public int countCollegeStudent(String collegename){
        return echartMapper.countCollegeStudent(collegename);
    }

    // 查询各学院签到人数
    public List<CollegeRate> countCollegeRate(){
        return echartMapper.collegeRateRank();
    }

    // 查询某学院学生签到信息
    public List<Student> collegeStudentInfo(String collegename){
        return echartMapper.collegeStudentInfo(collegename);
    }
}

开始写controller层代码

package yqfx.system.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yqfx.system.entity.CollegeRate;
import yqfx.system.entity.Count;
import yqfx.system.entity.Student;
import yqfx.system.entity.ZhiBiao;
import yqfx.system.service.EchartService;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;


/**
 * Created with IntelliJ IDEA.
 * User: Coffee君
 * Date: 2020/2/15
 * Time: 22:22
 * Description: No Description
 */
@RestController
public class EchartController {

    @Autowired
    private EchartService echartService;

    // 查询总签到人数
    @ResponseBody
    @RequestMapping("/getCountStudent")
    public Count CountStudent(){
        int getCountStudent = echartService.countStudent();
        //System.out.println("总签到人数:" + echartService.countStudent());
        Count count = new Count();
        count.setCountStudent(getCountStudent);
        return count;
    }

    // 查询某学生是否签到
    @ResponseBody
    @RequestMapping("/search")
    public String Search(String studentid){
        Student student= new Student();
        System.out.println(echartService.search(studentid));
        if(echartService.search(studentid) == null){
            return studentid+":未签到";
        }else{
            return echartService.search(studentid).getYbRealname()+":已签到";
        }
    }


    // 查询1月8日以来与确诊或者疑似病例接触总人数
    @ResponseBody
    @RequestMapping("/getAll1")
    public Count GetAll1(){
        Count count = new Count();
        count.setCountStudent(echartService.countTouchAll());
        return count;
    }

    // 查询1月8日以来与确诊或者疑似病例接触人数
    @RequestMapping("/getZb1")
    public ZhiBiao GetZb1(String collegename){
        ZhiBiao zhiBiao = new ZhiBiao();
        zhiBiao.setV1(echartService.countTouch(collegename));
        zhiBiao.setV2(echartService.countStudent()-echartService.countTouch(collegename));
        return zhiBiao;
    }

    // 查询发热人数、不发热人数
    @RequestMapping("/getZb2")
    public ZhiBiao GetZb2(String collegename){
        ZhiBiao zhiBiao = new ZhiBiao();
        zhiBiao.setV1(echartService.counthot(collegename));
        zhiBiao.setV2(echartService.countStudent()-echartService.counthot(collegename));
        return zhiBiao;
    }

    // 查询发热人数、不发热人数
    @ResponseBody
    @RequestMapping("/getAll2")
    public Count GetAll2(){
        Count count = new Count();
        count.setCountStudent(echartService.counthotAll());
        return count;
    }

    // 查询确诊或者疑似人数及比例
    @RequestMapping("/getZb3")
    public ZhiBiao GetZb3(String collegename){
        ZhiBiao zhiBiao = new ZhiBiao();
        zhiBiao.setV1(echartService.countIll(collegename));
        zhiBiao.setV2(echartService.countStudent()-echartService.countIll(collegename));
        return zhiBiao;
    }

    // 查询确诊或者疑似人数及比例
    @ResponseBody
    @RequestMapping("/getAll3")
    public Count GetAll3(){
        Count count = new Count();
        count.setCountStudent(echartService.countIllAll());
        return count;
    }

    // 查询定点隔离人数及比例
    @RequestMapping("/getZb4")
    public ZhiBiao GetZb4(String collegename){
        ZhiBiao zhiBiao = new ZhiBiao();
        zhiBiao.setV1(echartService.countFixIsloated(collegename));
        zhiBiao.setV2(echartService.countStudent()-echartService.countFixIsloated(collegename));
        return zhiBiao;
    }

    // 查询定点隔离人数及比例
    @ResponseBody
    @RequestMapping("/getAll4")
    public Count GetAll4(){
        Count count = new Count();
        count.setCountStudent(echartService.countFixIsloatedAll());
        return count;
    }

    // 查询在家隔离人数
    @RequestMapping("/getZb5")
    public ZhiBiao GetZb5(String collegename){
        ZhiBiao zhiBiao = new ZhiBiao();
        zhiBiao.setV1(echartService.countHomeIsloated(collegename));
        zhiBiao.setV2(echartService.countStudent()-echartService.countHomeIsloated(collegename));
        return zhiBiao;
    }

    // 查询在家隔离人数及比例
    @ResponseBody
    @RequestMapping("/getAll5")
    public Count GetAll5(){
        Count count = new Count();
        count.setCountStudent(echartService.countHomeIsloatedAll());
        return count;
    }

    // 查询住院治疗人数及比例
    @RequestMapping("/getZb6")
    public ZhiBiao GetZb6(String collegename){
        ZhiBiao zhiBiao = new ZhiBiao();
        zhiBiao.setV1(echartService.countHospital(collegename));
        zhiBiao.setV2(echartService.countStudent()-echartService.countHospital(collegename));
        return zhiBiao;
    }

    // 查询住院治疗人数及比例
    @ResponseBody
    @RequestMapping("/getAll6")
    public Count GetAll6(){
        Count count = new Count();
        count.setCountStudent(echartService.countHospitalAll());
        return count;
    }

    // 查询各学院签到人数所占比例
    @RequestMapping("/chart5")
    public List<CollegeRate> Echart5(){
        List<CollegeRate> list1 = new ArrayList<>();
        List<CollegeRate> list2 = new ArrayList<>();
        list1 = echartService.countCollegeRate();
        for (int i = 0; i < list1.size(); i++) {
            CollegeRate collegeRate = new CollegeRate();
            collegeRate.setCollegename(list1.get(i).getCollegename());
            collegeRate.setNum(list1.get(i).getNum());
            collegeRate.setAllstudent(echartService.countStudent());
            list2.add(collegeRate);
        }
        return list2;
    }

    // 查询学院签到人数
    @ResponseBody
    @RequestMapping("/countCollegeStudent")
    public int CountCollegeStudent (String collegename){
        System.out.println(echartService.countCollegeStudent(collegename));
        return echartService.countCollegeStudent(collegename);
    }

    //查询本学院学生签到信息
    @ResponseBody
    @RequestMapping("/collegeStudentInfo")
    public List<Student> CollegeStudentInfo(String collegename){
        List<Student> list = new ArrayList<>();
        list = echartService.collegeStudentInfo(collegename);
        System.out.println(list.size());
        return list;
    }

    /*@GetMapping("/first")
    public ModelAndView firstDemo(){
        return new ModelAndView("index");//跟templates文件夹下的test.html名字一样,返回这个界面

    }*/

}

目录结构

 

祝大家平安,顺利度过疫情,奥里给。

发布了85 篇原创文章 · 获赞 67 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/secretstarlyp/article/details/104450288