定时任务与统计
一、就醫提醒
我們通過定時任務,每天8點執行,提醒就診
1 、搭建定時任務模塊service-task
1.1 搭建service-task服務
搭建方式如service-user
1.2 修改配置pom.xml
<dependencies><dependency><groupId>com.atguigu</groupId><artifactId>rabbit_util</artifactId><version>0.0.1-SNAPSHOT</version></dependency> </dependencies>說明:引入依賴
1.3 添加配置文件
1、application.properties
# 服務端口 server.port=8207 # 服務名 spring.application.name=service-task # 環境設置:dev、test、prod spring.profiles.active=dev# nacos服務地址 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848#rabbitmq地址 spring.rabbitmq.host=192.168.44.165 spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest1.4 添加啟動類
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消數據源自動配置 @EnableDiscoveryClient public class ServiceTaskApplication {public static void main(String[] args) {SpringApplication.run(ServiceTaskApplication.class, args);} }1.5 添加常量配置
在rabbit-util模塊com.atguigu.yygh.common.constant.MqConst類添加
public static final String EXCHANGE_DIRECT_TASK = "exchange.direct.task"; public static final String ROUTING_TASK_8 = "task.8"; //隊列 public static final String QUEUE_TASK_8 = "queue.task.8";1.6 添加定時任務
Cron表達式
@Component @EnableScheduling public class ScheduledTask {@Autowiredprivate RabbitService rabbitService;/*** 每天8點執行 提醒就診*///@Scheduled(cron = "0 0 1 * * ?")@Scheduled(cron = "0/30 * * * * ?")public void task1() {rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_8, "");} }2、添加就醫提醒處理
操作模塊service-order
2.1 添加service接口
在OrderService類添加接口
/*** 就診提醒*/ void patientTips();2.2 添加service接口實現類
在OrderServiceImpl類添加接口實現
@Override public void patientTips() {QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<>();queryWrapper.eq("reserve_date",new DateTime().toString("yyyy-MM-dd"));List<OrderInfo> orderInfoList = baseMapper.selectList(queryWrapper);for(OrderInfo orderInfo : orderInfoList) {//短信提示MsmVo msmVo = new MsmVo();msmVo.setPhone(orderInfo.getPatientPhone());String reserveDate = new DateTime(orderInfo.getReserveDate()).toString("yyyy-MM-dd") + (orderInfo.getReserveTime()==0 ? "上午": "下午");Map<String,Object> param = new HashMap<String,Object>(){{put("title", orderInfo.getHosname()+"|"+orderInfo.getDepname()+"|"+orderInfo.getTitle());put("reserveDate", reserveDate);put("name", orderInfo.getPatientName());}};msmVo.setParam(param);rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MSM, MqConst.ROUTING_MSM_ITEM, msmVo);} }2.3 添加mq監聽
添加OrderReceiver 類
@Component public class OrderReceiver {@Autowiredprivate OrderService orderService;@RabbitListener(bindings = @QueueBinding(value = @Queue(value = MqConst.QUEUE_TASK_8, durable = "true"),exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_TASK),key = {MqConst.ROUTING_TASK_8}))public void patientTips(Message message, Channel channel) throws IOException {orderService.patientTips();} }三、預約統計
我們統計醫院每天的預約情況,通過圖表的形式展示,統計的數據都來自訂單模塊,因此我們在該模塊封裝好數據,在統計模塊通過feign的形式獲取數據。
我們為什么需要一個統計模塊呢,因為在實際的生成環境中,有很多種各式統計,數據來源于各個服務模塊,我們得有一個統計模塊來專門管理
1、ECharts
1.1簡介
ECharts是百度的一個項目,后來百度把Echart捐給apache,用于圖表展示,提供了常規的折線圖、柱狀圖、散點圖、餅圖、K線圖,用于統計的盒形圖,用于地理數據可視化的地圖、熱力圖、線圖,用于關系數據可視化的關系圖、treemap、旭日圖,多維數據可視化的平行坐標,還有用于 BI 的漏斗圖,儀表盤,并且支持圖與圖之間的混搭。
官方網站:https://echarts.apache.org/zh/index.html
1.2基本使用
(1)引入ECharts
<!-- 引入 ECharts 文件 --> <script src="echarts.min.js"></script>(2)定義圖表區域
<!-- 為ECharts準備一個具備大小(寬高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div>(3)渲染圖表(折線圖)
<script>var myChart = echarts.init(document.getElementById('main'));var option = {//x軸是類目軸(離散數據),必須通過data設置類目數據xAxis: {type: 'category',data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']},//y軸是數據軸(連續數據)yAxis: {type: 'value'},//系列列表。每個系列通過 type 決定自己的圖表類型series: [{//系列中的數據內容數組data: [820, 932, 901, 934, 1290, 1330, 1320],//折線圖type: 'line'}]};myChart.setOption(option); </script>(4)渲染圖表(柱狀圖)
<script type="text/javascript">// 基于準備好的dom,初始化echarts實例var myChart = echarts.init(document.getElementById('main'));// 指定圖表的配置項和數據var option = {title: {text: 'ECharts 入門示例'},tooltip: {},legend: {data:['銷量']},xAxis: {data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]},yAxis: {},series: [{name: '銷量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]};// 使用剛指定的配置項和數據顯示圖表。myChart.setOption(option); </script>1.3項目中集成ECharts
npm install --save echarts@4.1.0
2、獲取醫院每天平臺預約數據接口
操作模塊:service-order
2.1添加Mapper接口
1、在OrderInfoMapper類添加接口
public interface OrderMapper extends BaseMapper<OrderInfo> {List<OrderCountVo> selectOrderCount(@Param("vo") OrderCountQueryVo orderCountQueryVo); }2、在OrderInfoMapper.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.atguigu.yygh.order.mapper.OrderMapper"><select id="selectOrderCount" resultType="com.atguigu.yygh.vo.order.OrderCountVo">select reserve_date as reserveDate, count(reserve_date) as countfrom order_info<where><if test="vo.hosname != null and vo.hosname != ''">and hosname like CONCAT('%',#{vo.hosname},'%')</if><if test="vo.reserveDateBegin != null and vo.reserveDateBegin != ''">and reserve_date >= #{vo.reserveDateBegin}</if><if test="vo.reserveDateEnd != null and vo.reserveDateEnd != ''">and reserve_date <= #{vo.reserveDateEnd}</if>and is_deleted = 0</where>group by reserve_dateorder by reserve_date</select> </mapper>添加application.properties配置
mybatis-plus.mapper-locations=classpath:com/atguigu/yygh/order/mapper/xml/*.xml2.2添加service接口
在OrderService類添加接口
/*** 訂單統計*/ Map<String, Object> getCountMap(OrderCountQueryVo orderCountQueryVo);2.3添加service接口實現
在OrderServiceImpl類添加實現
@Override public Map<String, Object> getCountMap(OrderCountQueryVo orderCountQueryVo) {Map<String, Object> map = new HashMap<>();List<OrderCountVo> orderCountVoList = baseMapper.selectOrderCount(orderCountQueryVo);//日期列表List<String> dateList =orderCountVoList.stream().map(OrderCountVo::getReserveDate).collect(Collectors.toList());//統計列表List<Integer> countList =orderCountVoList.stream().map(OrderCountVo::getCount).collect(Collectors.toList());map.put("dateList", dateList);map.put("countList", countList);return map; }2.4添加controller方法
在OrderApiController類添加方法
@ApiOperation(value = "獲取訂單統計數據") @PostMapping("inner/getCountMap") public Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {return orderService.getCountMap(orderCountQueryVo); }3、添加feign方法
創建模塊:service-order-client
3.1添加feign接口
添加接口和方法
@FeignClient(value = "service-order") @Repository public interface OrderFeignClient {/*** 獲取訂單統計數據*/@PostMapping("/api/order/orderInfo/inner/getCountMap")Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo);}4、搭建service-statistics
4.1搭建service-statistics服務
搭建方式如service-user
4.2修改配置pom.xml
<dependencies><dependency><groupId>com.atguigu</groupId><artifactId>service_order_client</artifactId><version>0.0.1-SNAPSHOT</version></dependency> </dependencies>4.3添加配置文件
1、application.properties
# 服務端口 server.port=8208 # 服務名 spring.application.name=service-statistics # 環境設置:dev、test、prod spring.profiles.active=dev# nacos服務地址 spring.cloud.nacos.discovery.server-addr=127.0.0.1:88484.4添加啟動類
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消數據源自動配置 @EnableDiscoveryClient @EnableFeignClients @ComponentScan(basePackages = {"com.atguigu"}) public class ServiceStatisticsApplication {public static void main(String[] args) {SpringApplication.run(ServiceStatisticsApplication.class, args);}}4.5添加controller方法
@Api(tags = "統計管理接口") @RestController @RequestMapping("/admin/statistics") public class StatisticsController {@Autowiredprivate OrderFeignClient orderFeignClient;@ApiOperation(value = "獲取訂單統計數據")@GetMapping("getCountMap")public Result getCountMap(@ApiParam(name = "orderCountQueryVo", value = "查詢對象", required = false) OrderCountQueryVo orderCountQueryVo) {return Result.ok(orderFeignClient.getCountMap(orderCountQueryVo));} }5、前端展示
5.1添加路由
在 src/router/index.js 文件添加路由
{path: '/statistics',component: Layout,redirect: '/statistics/order/index',name: 'BasesInfo',meta: { title: '統計管理', icon: 'table' },alwaysShow: true,children: [{path: 'order/index',name: '預約統計',component: () =>import('@/views/statistics/order/index'),meta: { title: '預約統計' }}] },5.2封裝api請求
創建/api/statistics/orderStatistics.js
import request from '@/utils/request'const api_name = '/admin/statistics'export default {getCountMap(searchObj) {return request({url: `${api_name}/getCountMap`,method: 'get',params: searchObj})} }5.3添加組件
創建/views/statistics/order/index.vue組件
<template><div class="app-container"><!--表單--><el-form :inline="true" class="demo-form-inline"><el-form-item><el-input v-model="searchObj.hosname" placeholder="點擊輸入醫院名稱"/></el-form-item><el-form-item><el-date-pickerv-model="searchObj.reserveDateBegin"type="date"placeholder="選擇開始日期"value-format="yyyy-MM-dd"/></el-form-item><el-form-item><el-date-pickerv-model="searchObj.reserveDateEnd"type="date"placeholder="選擇截止日期"value-format="yyyy-MM-dd"/></el-form-item><el-button:disabled="btnDisabled"type="primary"icon="el-icon-search"@click="showChart()">查詢</el-button></el-form><div class="chart-container"><div id="chart" ref="chart" class="chart" style="height:500px;width:100%"/></div></div> </template><script> import echarts from 'echarts' import statisticsApi from '@/api/orderStatistics'export default {data() {return {searchObj: {hosname: '',reserveDateBegin: '',reserveDateEnd: ''},btnDisabled: false,chart: null,title: '',xData: [], // x軸數據yData: [] // y軸數據}},methods: {// 初始化圖表數據showChart() {statisticsApi.getCountMap(this.searchObj).then(response => {this.yData = response.data.countListthis.xData = response.data.dateListthis.setChartData()})},setChartData() {// 基于準備好的dom,初始化echarts實例var myChart = echarts.init(document.getElementById('chart'))// 指定圖表的配置項和數據var option = {title: {text: this.title + '掛號量統計'},tooltip: {},legend: {data: [this.title]},xAxis: {data: this.xData},yAxis: {minInterval: 1},series: [{name: this.title,type: 'line',data: this.yData}]}// 使用剛指定的配置項和數據顯示圖表。myChart.setOption(option)},} } </script> },tooltip: {},legend: {data: [this.title]},xAxis: {data: this.xData},yAxis: {minInterval: 1},series: [{name: this.title,type: 'line',data: this.yData}]}// 使用剛指定的配置項和數據顯示圖表。myChart.setOption(option)}, }}
總結
- 上一篇: 2600评测_佳能专微的雄心,RF 28
- 下一篇: 单片机无线调试-看见心跳-手机显示心率波