一、就医提醒
系统通过定时任务,每天8点执行,提醒就诊,并发送短信给患者。
1 、搭建定时任务模块service-task
1.1 搭建service-task服务
1.2添加依赖
<dependencies>
<dependency>
<groupId>com.zhoujk</groupId>
<artifactId>rabbit_util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
1.3添加配置文件
server:
port: 8207
spring:
application:
name: service-task
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
rabbitmq:
host: 124.223.201.83
port: 5672
# virtual-host: /
username: guest
password: guest
1.4 添加启动类
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@ComponentScan(basePackages = "com.zhoujk")
@EnableDiscoveryClient
public class ServiceTaskApplication
{
public static void main(String[] args)
{
SpringApplication.run(ServiceTaskApplication.class, args);
}
}
1.5 添加常量配置
需要在rabbit-util模块中,com.zhoujk.yygh.rabbitmq.constant.MqCons添加定时任务的常量。
public class MqConst
{
/**
* 预约下单
*/
public static final String EXCHANGE_DIRECT_ORDER = "exchange.direct.order";
public static final String ROUTING_ORDER = "order";
//队列
public static final String QUEUE_ORDER = "queue.order";
/**
* 短信
*/
public static final String EXCHANGE_DIRECT_MSM = "exchange.direct.msm";
public static final String ROUTING_MSM_ITEM = "msm.item";
//队列
public static final String QUEUE_MSM_ITEM = "queue.msm.item";
/**
* 定时任务
*/
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
@EnableSchedulingpublic class ScheduledTask {
@Autowired<br /> **private **RabbitService **rabbitService**;
_/**<br /> * 每天8点执行 提醒就诊<br /> */<br /> //@Scheduled(cron = "0 0 1 * * ?")<br /> _@Scheduled(cron = **"0/30 * * * * ?"**)<br /> **public void **task1() {<br /> **rabbitService**.sendMessage(MqConst.**_EXCHANGE_DIRECT_TASK_**, MqConst.**_ROUTING_TASK_8_**, **""**);<br /> }<br />} |
| —- |
2、添加就医提醒处理
2.1 添加service接口
在OrderService类添加接口
/* 就诊提醒 */void patientTips(); |
---|
2.2 添加service接口实现类
在OrderServiceImpl类添加接口实现
@Overridepublic void patientTips() { QueryWrapper queryWrapper.eq(“reserve_date”,new DateTime().toString(“yyyy-MM-dd”)); List 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 put(“title”, orderInfo.getHosname()+“|”+orderInfo.getDepname()+“|”+orderInfo.getTitle()); put(“reserveDate”, reserveDate); put(“name”, orderInfo.getPatientName()); }}; msmVo.setParam(param); rabbitService.sendMessage(MqConst.**_EXCHANGE_DIRECT_MSM } } |
---|
2.3 添加mq监听
添加OrderReceiver 类
| @Componentpublic class OrderReceiver {
@Autowired<br /> **private **OrderService **orderService**;
@RabbitListener(bindings = @QueueBinding(<br /> value = @Queue(value = MqConst.**_QUEUE_TASK_8_**, durable = **"true"**),<br /> exchange = @Exchange(value = MqConst.**_EXCHANGE_DIRECT_TASK_**),<br /> key = {MqConst.**_ROUTING_TASK_8_**}<br /> ))<br /> **public void **patientTips(Message message, Channel channel) **throws **IOException {<br /> **orderService**.patientTips();<br /> }<br />} |
| —- |
二、预约统计
我们统计医院每天的预约情况,通过图表的形式展示,统计的数据都来自订单模块,因此我们在该模块封装好数据,在统计模块通过feign的形式获取数据。
我们为什么需要一个统计模块呢,因为在实际的生成环境中,有很多种各式统计,数据来源于各个服务模块,我们得有一个统计模块来专门管理
1、ECharts
1.1简介
ECharts是百度的一个项目,后来百度把Echart捐给apache,用于图表展示,提供了常规的折线图、柱状图、散点图、饼图、K线图,用于统计的盒形图,用于地理数据可视化的地图、热力图、线图,用于关系数据可视化的关系图、treemap、旭日图,多维数据可视化的平行坐标,还有用于 BI 的漏斗图,仪表盘,并且支持图与图之间的混搭。
官方网站:https://echarts.apache.org/zh/index.html
1.2基本使用
(1)引入ECharts
(2)定义图表区域
(3)渲染图表(折线图)
(4)渲染图表(柱状图)
1.3项目中集成ECharts
npm install —save echarts@4.1.0 |
---|
2、获取医院每天平台预约数据接口
2.1添加Mapper接口
1、在OrderInfoMapper类添加接口
public interface OrderMapper extends BaseMapper List } |
---|
在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 reservedate as reserveDate, _count(reserve_date) as count
from 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_date
order by reserve_date
</select>
</mapper> | | —- |
添加application.properties配置
mybatis-plus.mapper-locations=classpath:com/atguigu/yygh/order/mapper/xml/*.xml |
---|
2.2添加service接口
在OrderService类添加接口
/* 订单统计 _*/_Map |
---|
2.3添加service接口实现
在OrderServiceImpl类添加实现
| @Overridepublic Map
Map
List<OrderCountVo> orderCountVoList <br />= **baseMapper**.selectOrderCount(orderCountQueryVo);<br /> _//日期列表<br /> _List<String> dateList <br />=orderCountVoList.stream().map(OrderCountVo::getReserveDate).collect(Collectors._toList_());<br /> _//统计列表<br /> _List<Integer> countList <br />=orderCountVoList.stream().map(OrderCountVo::getCount).collect(Collectors._toList_());<br /> map.put(**"dateList"**, dateList);<br /> map.put(**"countList"**, countList);<br /> **return **map;<br />} |
| —- |
2.4添加controller方法
在OrderApiController类添加方法
@ApiOperation(value = “获取订单统计数据”)@PostMapping(“inner/getCountMap”)public Map return orderService.getCountMap(orderCountQueryVo); } |
---|
3、添加feign方法
3.1添加feign接口
添加接口和方法
| @FeignClient(value = “service-order”)@Repositorypublic interface OrderFeignClient {
/*
获取订单统计数据 */
@PostMapping(“/api/order/orderInfo/inner/getCountMap”)
Map
} | | —- |
4、搭建service-statistics
4.1搭建service-statistics服务
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、prodspring.profiles.active=dev # nacos服务地址spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 |
---|
4.4添加启动类
| @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消数据源自动配置@EnableDiscoveryClient
@EnableFeignClients
@ComponentScan(basePackages = {“com.atguigu”})public class ServiceStatisticsApplication {
**public static void **main(String[] args) {<br /> SpringApplication._run_(ServiceStatisticsApplication.**class**, args);<br /> }
} | | —- |
4.5添加controller方法
| @Api(tags = “统计管理接口”)@RestController
@RequestMapping(“/admin/statistics”)public class StatisticsController {
@Autowired<br /> **private **OrderFeignClient **orderFeignClient**;
@ApiOperation(value = **"获取订单统计数据"**)<br /> @GetMapping(**"getCountMap"**)<br /> **public **Result getCountMap(@ApiParam(name = **"orderCountQueryVo"**, value = **"查询对象"**, required = **false**) OrderCountQueryVo orderCountQueryVo) {<br /> **return **Result._ok_(**orderFeignClient**.getCountMap(orderCountQueryVo));<br /> }<br />} |
| —- |
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组件
type=”date” placeholder=”选择开始日期” value-format=”yyyy-MM-dd”/> type=”date” placeholder=”选择截止日期” value-format=”yyyy-MM-dd”/> type=”primary” icon=”el-icon-search” @click=”showChart()”>查询 class=”chart” style=”height:500px;width:100%”/> |
---|