• Day119.尚医通:取消预约(微信退款)、就医提醒(定时任务)、预约统计


    目录

    一、取消预约 (微信退款)

    1、准备工作

    2、保存退款记录接口

    3、实现微信退款

    4、取消预约接口

    5、前端实现

    二、就医提醒

    1、准备工作,搭建模块

    2、在orders模块实现功能

    三、预约统计功能

    1、开发统计每天预约数据接口


    一、取消预约 (微信退款)

    1、准备工作

    1. 确认需求

    (1)未支付取消订单,直接通知医院更新取消预约状态

    (2)已支付取消订单,先退款给用户,然后通知医院更新取消预约状态

    参考文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4

    该接口需要使用证书,详情参考文档并下载证书

    2. 确认证书

    3. 添加配置证书地址,解开相关注释

    1. #双向证书
    2. weixin.cert=E:\\apiclient_cert.p12


    4. 获取支付记录方法

    PaymentService

    1. //获取支付记录
    2. PaymentInfo getPaymentInfo(Long orderId, Integer paymentType);
    3. //获取支付记录
    4. @Override
    5. public PaymentInfo getPaymentInfo(Long orderId, Integer paymentType) {
    6. QueryWrapper wrapper = new QueryWrapper<>();
    7. wrapper.eq("order_id", orderId);
    8. wrapper.eq("payment_type", paymentType);
    9. PaymentInfo paymentInfo = baseMapper.selectOne(wrapper);
    10. return paymentInfo;
    11. }

    2、保存退款记录接口

    1. 确认库表 refund_info

    2. 创建相关接口、类

    3. 接口实现

    1. public interface RefundInfoService extends IService {
    2. //保存退款记录
    3. RefundInfo saveRefundInfo(PaymentInfo paymentInfo);
    4. }
    5. @Service
    6. public class RefundInfoServiceImpl extends ServiceImpl implements RefundInfoService {
    7. //保存退款记录
    8. @Override
    9. public RefundInfo saveRefundInfo(PaymentInfo paymentInfo) {
    10. //1.查询退款记录,如果存在直接返回
    11. QueryWrapper queryWrapper = new QueryWrapper<>();
    12. queryWrapper.eq("order_id", paymentInfo.getOrderId());
    13. queryWrapper.eq("payment_type", paymentInfo.getPaymentType());
    14. RefundInfo refundInfo = baseMapper.selectOne(queryWrapper);
    15. if(null != refundInfo) return refundInfo;
    16. //2.如果不存在,新增退款记录
    17. refundInfo = new RefundInfo();
    18. refundInfo.setCreateTime(new Date());
    19. refundInfo.setOrderId(paymentInfo.getOrderId());
    20. refundInfo.setPaymentType(paymentInfo.getPaymentType());
    21. refundInfo.setOutTradeNo(paymentInfo.getOutTradeNo());
    22. refundInfo.setRefundStatus(RefundStatusEnum.UNREFUND.getStatus());//1 退款中
    23. refundInfo.setSubject(paymentInfo.getSubject());
    24. //paymentInfo.setSubject("test");
    25. refundInfo.setTotalAmount(paymentInfo.getTotalAmount());
    26. baseMapper.insert(refundInfo);
    27. return refundInfo;
    28. }
    29. }

    3、实现微信退款

    1. 接口实现

    weixinService 

    1. //退款
    2. Boolean refund(Long orderId);
    3. //退款
    4. @Override
    5. public Boolean refund(Long orderId) {
    6. try {
    7. //1.根据参数查询交易记录
    8. PaymentInfo paymentInfo = paymentService.getPaymentInfo(orderId, PaymentTypeEnum.WEIXIN.getStatus());
    9. if (paymentInfo == null) {
    10. throw new YyghException(20001, "交易记录有误");
    11. }
    12. //2.根据交易记录添加退款记录,确认退款状态
    13. RefundInfo refundInfo = refundInfoService.saveRefundInfo(paymentInfo);
    14. if (refundInfo.getRefundStatus() ==
    15. RefundStatusEnum.REFUND.getStatus()) {
    16. return true; //已完成退款
    17. }
    18. //3.封装调用接口参数
    19. Map paramMap = new HashMap<>(8);
    20. paramMap.put("appid",ConstantPropertiesUtils.APPID); //公众账号ID
    21. paramMap.put("mch_id",ConstantPropertiesUtils.PARTNER); //商户编号
    22. paramMap.put("nonce_str",WXPayUtil.generateNonceStr());
    23. paramMap.put("transaction_id",paymentInfo.getTradeNo()); //微信订单号
    24. paramMap.put("out_trade_no",paymentInfo.getOutTradeNo()); //商户订单编号
    25. paramMap.put("out_refund_no","tk"+paymentInfo.getOutTradeNo()); //商户退款单号
    26. //paramMap.put("total_fee",paymentInfoQuery.getTotalAmount().multiply(new BigDecimal("100")).longValue()+"");
    27. //paramMap.put("refund_fee",paymentInfoQuery.getTotalAmount().multiply(new BigDecimal("100")).longValue()+"");
    28. paramMap.put("total_fee","1"); //总金额
    29. paramMap.put("refund_fee","1"); //退款多少,小于总金额
    30. //4.创建客户端(设置url) 参考文档
    31. HttpClient client = new HttpClient("https://api.mch.weixin.qq.com/secapi/pay/refund");
    32. //5.设置参数 (map=>xml),开启读取证书开关
    33. String paramXml = WXPayUtil.generateSignedXml(paramMap,ConstantPropertiesUtils.PARTNERKEY);
    34. client.setXmlParam(paramXml);
    35. client.setHttps(true);
    36. client.setCert(true); //开启读取证书开关
    37. client.setCertPassword(ConstantPropertiesUtils.PARTNER); //整证密码(商户编号)
    38. //6.客户端发送请求
    39. client.post();
    40. //7.获取响应,转化响应类型(xml=>map)
    41. String xml = client.getContent();
    42. System.out.println("退款xml = " + xml);
    43. Map resultMap = WXPayUtil.xmlToMap(xml);
    44. //8.如果退款成功,更新退款记录信息
    45. if (null != resultMap &&
    46. WXPayConstants.SUCCESS.equalsIgnoreCase(resultMap.get("result_code"))) {
    47. refundInfo.setCallbackTime(new Date());
    48. refundInfo.setTradeNo(resultMap.get("refund_id"));//交易编号
    49. refundInfo.setRefundStatus(RefundStatusEnum.REFUND.getStatus());//退款编号
    50. refundInfo.setCallbackContent(JSONObject.toJSONString(resultMap));//退款状态
    51. refundInfoService.updateById(refundInfo);//报文
    52. return true;
    53. }
    54. return false;
    55. } catch (Exception e) {
    56. e.printStackTrace();
    57. }
    58. return false;
    59. }

    4、取消预约接口

    1. OrderController 方法

    *参数:orderId

    *返回值:R.ok()

    1. @ApiOperation(value = "取消预约")
    2. @GetMapping("auth/cancelOrder/{orderId}")
    3. public R cancelOrder(
    4. @ApiParam(name = "orderId", value = "订单id", required = true)
    5. @PathVariable("orderId") Long orderId) {
    6. Boolean flag = orderService.cancelOrder(orderId);
    7. return R.ok().data("flag",flag);
    8. }

    2. service

    注释掉医院取消预约 校验签名

    1. //取消预约
    2. @Override
    3. public Boolean cancelOrder(Long orderId) {
    4. //1.查询订单信息
    5. OrderInfo orderInfo = baseMapper.selectById(orderId);
    6. if(orderInfo==null){
    7. throw new YyghException(20001,"订单信息有误");
    8. }
    9. //2.判断是否已过退号时间
    10. DateTime quitDateTime = new DateTime(orderInfo.getQuitTime());
    11. if(quitDateTime.isBeforeNow()){
    12. throw new YyghException(20001,"已过取消预约截止时间");
    13. }
    14. //3.调用医院系统接口,取消预约
    15. Map reqMap = new HashMap<>();
    16. reqMap.put("hoscode",orderInfo.getHoscode());
    17. reqMap.put("hosRecordId",orderInfo.getHosRecordId());
    18. reqMap.put("timestamp", HttpRequestHelper.getTimestamp());
    19. reqMap.put("sign", "");
    20. JSONObject result = HttpRequestHelper.sendRequest(reqMap, "http://localhost:9998/order/updateCancelStatus");
    21. //4.医院取消预约成功
    22. if(result.getInteger("code")!=200){
    23. throw new YyghException(20001,"取消预约失败");
    24. }else {
    25. //判断是否已支付
    26. if(orderInfo.getOrderStatus() == OrderStatusEnum.PAID.getStatus()) {
    27. //5.如果已支付,调用微信退款
    28. Boolean refund = weixinService.refund(orderId);
    29. if(!refund){
    30. throw new YyghException(20001,"微信退款失败");
    31. }
    32. }
    33. //6.更新订单状态
    34. orderInfo.setOrderStatus(OrderStatusEnum.CANCLE.getStatus());
    35. this.updateById(orderInfo);
    36. //7.发送MQ消息,更新号源,通知就诊人
    37. OrderMqVo orderMqVo = new OrderMqVo();
    38. orderMqVo.setScheduleId(orderInfo.getHosScheduleId());
    39. orderMqVo.setHoscode(orderInfo.getHoscode());
    40. //短信提示
    41. MsmVo msmVo = new MsmVo();
    42. msmVo.setPhone(orderInfo.getPatientPhone());
    43. orderMqVo.setMsmVo(msmVo);
    44. rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_ORDER, MqConst.ROUTING_ORDER, orderMqVo);
    45. return true;
    46. }
    47. }

    3. 改造HospitalReceiver 监听器,判断取消预约还是创建订单

    1. @Component
    2. public class HospitalReceiver {
    3. @Autowired
    4. private ScheduleService scheduleService;
    5. @Autowired
    6. private RabbitService rabbitService;
    7. @RabbitListener(bindings = @QueueBinding(
    8. value = @Queue(value = MqConst.QUEUE_ORDER, durable = "true"),
    9. exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_ORDER),
    10. key = {MqConst.ROUTING_ORDER}
    11. ))
    12. public void receiver(OrderMqVo orderMqVo, Message message, Channel channel) throws IOException {
    13. //1.取出参数
    14. String hoscode = orderMqVo.getHoscode();
    15. String hosScheduleId = orderMqVo.getScheduleId();
    16. Integer reservedNumber = orderMqVo.getReservedNumber();
    17. Integer availableNumber = orderMqVo.getAvailableNumber();
    18. MsmVo msmVo = orderMqVo.getMsmVo();
    19. //2.根据参数查询排班信息
    20. Schedule schedule = scheduleService.getScheduleByIds(hoscode, hosScheduleId);
    21. //2.5判断创建订单,还是取消预约 (剩余预约数是否为空 取消订单医院接口没有返回值)
    22. if(StringUtils.isEmpty(availableNumber)){
    23. //取消预约,更新号源
    24. availableNumber = schedule.getAvailableNumber().intValue() + 1;
    25. schedule.setAvailableNumber(availableNumber);
    26. }else {
    27. //创建订单,更新号源
    28. schedule.setReservedNumber(reservedNumber);
    29. schedule.setAvailableNumber(availableNumber);
    30. }
    31. //3.更新排班信息
    32. schedule.setUpdateTime(new Date()); //MongoDB不会自动更新时间
    33. scheduleService.update(schedule);
    34. //4.发送短信相关MQ消息
    35. if(msmVo!=null){
    36. rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MSM, MqConst.ROUTING_MSM_ITEM, msmVo);
    37. }
    38. }
    39. }

    5、前端实现

    1. wx.js 创建API接口方法

    1. //取消预约订单
    2. cancelOrder(orderId) {
    3. return request({
    4. url: `/api/order/orderInfo/auth/cancelOrder/${orderId}`,
    5. method: 'get'
    6. })
    7. },

    2. JS实现

    1. //取消预约
    2. cancelOrder() {
    3. this.$confirm('此操作将取消预约,是否继续?', '提示', {
    4. confirmButtonText: '确定',
    5. cancelButtonText: '取消',
    6. type: 'warning'
    7. }).then(() => {
    8. return weixinApi.cancelOrder(this.orderId).then(response => {
    9. this.$message({
    10. type: "success",
    11. message: "取消预约成功!"
    12. })
    13. window.location.reload()
    14. })
    15. }).catch(() => {
    16. this.$message({
    17. type: "info",
    18. message: "已取消操作"
    19. })
    20. })
    21. }

    5. 测试,收到微信退款、短信

    二、就医提醒 (定时调度)

    我们通过定时任务,每天8点执行,提醒就诊

    1、准备工作,搭建模块

    1. 新建service_task 模块

    1. <dependencies>
    2. <dependency>
    3. <groupId>com.atguigugroupId>
    4. <artifactId>rabbit_utilartifactId>
    5. <version>0.0.1-SNAPSHOTversion>
    6. dependency>
    7. dependencies>
    1. # 服务端口
    2. server.port=8208
    3. # 服务名
    4. spring.application.name=service-task
    5. # 环境设置:dev、test、prod
    6. spring.profiles.active=dev
    7. # nacos服务地址
    8. spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
    9. #rabbitmq地址
    10. spring.rabbitmq.host=192.168.86.86
    11. spring.rabbitmq.port=5672
    12. spring.rabbitmq.username=guest
    13. spring.rabbitmq.password=guest
    1. @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    2. @EnableDiscoveryClient
    3. @ComponentScan(basePackages = {"com.atguigu"})
    4. public class ServiceTaskApplication {
    5. public static void main(String[] args) {
    6. SpringApplication.run(ServiceTaskApplication.class, args);
    7. }
    8. }

    2. 添加常量配置

    在rabbit-util模块MqConst类添加

    1. //定时任务
    2. public static final String EXCHANGE_DIRECT_TASK = "exchange.direct.task";
    3. public static final String ROUTING_TASK_8 = "task.8";
    4. //队列
    5. public static final String QUEUE_TASK_8 = "queue.task.8";

    3. 七域表达式 (七个时间区域)

    在线Cron表达式生成器

    4. ScheduledTask 实现

    1. @Component
    2. @EnableScheduling //开启定时任务
    3. public class ScheduledTask {
    4. @Autowired
    5. private RabbitService rabbitService;
    6. //@Scheduled(cron = "0 0 8 * * ?")
    7. @Scheduled(cron = "0/5 * * * * ?")
    8. public void test() {
    9. System.out.println("定时任务启动");
    10. }
    11. //每天8点执行 提醒就诊
    12. @Scheduled(cron = "0 0 8 * * ?")
    13. public void task1() {
    14. System.out.println(new Date().toLocaleString());
    15. rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_8, "");
    16. }
    17. }

    2、在orders模块实现功能

    1. OrderService 添加方法 就诊提醒

    1. //就诊提醒
    2. void patientTips();
    3. //就诊提醒
    4. @Override
    5. public void patientTips() {
    6. //1.查询符合条件订单集合
    7. QueryWrapper queryWrapper = new QueryWrapper<>();
    8. queryWrapper.eq("reserve_date",
    9. new DateTime().toString("yyyy-MM-dd"));
    10. List orderInfoList = baseMapper.selectList(queryWrapper);
    11. //2.遍历集合,拼写短信,发送mq消息
    12. for(OrderInfo orderInfo : orderInfoList) {
    13. //短信提示
    14. MsmVo msmVo = new MsmVo();
    15. msmVo.setPhone(orderInfo.getPatientPhone());
    16. String reserveDate = new DateTime(orderInfo.getReserveDate()).toString("yyyy-MM-dd") + (orderInfo.getReserveTime()==0 ? "上午": "下午");
    17. Map param = new HashMap(){{
    18. put("title", orderInfo.getHosname()+"|"+orderInfo.getDepname()+"|"+orderInfo.getTitle());
    19. put("reserveDate", reserveDate);
    20. put("name", orderInfo.getPatientName());
    21. }};
    22. msmVo.setParam(param);
    23. rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MSM, MqConst.ROUTING_MSM_ITEM, msmVo);
    24. }

    2. 创建监听器

    receiver/OrderReceiver

    1. @ComponentScan
    2. public class OrderReceiver {
    3. @Autowired
    4. OrderService orderService;
    5. //定时任务:就医提醒
    6. @RabbitListener(bindings = @QueueBinding(
    7. value = @Queue(value = MqConst.QUEUE_TASK_8, durable = "true"),
    8. exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_TASK),
    9. key = {MqConst.ROUTING_TASK_8}
    10. ))
    11. public void patientTips(Message message, Channel channel) throws IOException {
    12. orderService.patientTips();
    13. }
    14. }

    三、预约统计功能

    我们统计医院每天的预约情况,通过图表的形式展示,统计的数据都来自订单模块,因此我们在该模块封装好数据,在统计模块通过feign的形式获取数据。

    1、分析统计分析方案

    (1) 创建远程接口统计数据

    优势实时查询

    劣势影响各个模块使用的性能 (占用服务器资源)

    (2) 每天固定时间,统计分析各个指标数据,生成前一天统计报表

    优势各个模块使用影响相对小

    劣势不是实时数据

    (3) 使用脚本语言、数据库编程、数据统计分析

    优势数据统计块,对资源占用少

    劣势不能使用JAVA实现 (学习成本高)

    2、开发统计每天预约数据接口

    1. 查询数据sql

    SELECT o.`reserve_date`,COUNT(o.`id`) FROM order_info o

    WHERE XXXXX

    GROUP BY o.`reserve_date`;

    2. 接口分析

    *参数:OrderCountQueryVo

    *返回值:Map (x轴,y轴数据)

    3. OrderApiController 新增方法

    1. @ApiOperation(value = "获取订单统计数据")
    2. @PostMapping("inner/getCountMap")
    3. public Map getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
    4. Map map = orderService.getCountMap(orderCountQueryVo);
    5. return map;
    6. }

    4. 实现mapper

    由于MP(MybatisPlus) 无法实现统计sql,需要自行实现

    1. public interface OrderInfoMapper extends BaseMapper {
    2. //统计每天平台预约数据
    3. List selectOrderCount(OrderCountQueryVo orderCountQueryVo);
    4. }

    创建 mapper/xml/OrderInfoMapper.xml

    1. mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    2. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    3. <mapper namespace="com.atguigu.yygh.order.mapper.OrderInfoMapper">
    4. <select id="selectOrderCount" resultType="com.atguigu.yygh.vo.order.OrderCountVo">
    5. select reserve_date as reserveDate, count(reserve_date) as count
    6. from order_info
    7. <where>
    8. <if test="hosname != null and hosname != ''">
    9. and hosname like CONCAT('%',#{hosname},'%')
    10. if>
    11. <if test="reserveDateBegin != null and reserveDateBegin != ''">
    12. and reserve_date >= #{reserveDateBegin}
    13. if>
    14. <if test="reserveDateEnd != null and reserveDateEnd != ''">
    15. and reserve_date <= #{reserveDateEnd}
    16. if>
    17. and is_deleted = 0
    18. where>
    19. group by reserve_date
    20. order by reserve_date
    21. select>
    22. mapper>

    5. 添加配置

    *service.pom.xml 添加 maven插件,部署xml文件

    1. <build>
    2. <plugins>
    3. <plugin>
    4. <groupId>org.springframework.bootgroupId>
    5. <artifactId>spring-boot-maven-pluginartifactId>
    6. plugin>
    7. plugins>
    8. <resources>
    9. <resource>
    10. <directory>src/main/javadirectory>
    11. <includes>
    12. <include>**/*.ymlinclude>
    13. <include>**/*.propertiesinclude>
    14. <include>**/*.xmlinclude>
    15. includes>
    16. <filtering>falsefiltering>
    17. resource>
    18. <resource>
    19. <directory>src/main/resourcesdirectory>
    20. <includes> <include>**/*.ymlinclude>
    21. <include>**/*.propertiesinclude>
    22. <include>**/*.xmlinclude>
    23. includes>
    24. <filtering>falsefiltering>
    25. resource>
    26. resources>
    27. build>

    *order 配置文件添加相关配置

    1. #mapper xml文件扫描
    2. mybatis-plus.mapper-locations=classpath:com/atguigu/yygh/order/mapper/xml/*.xml

    6. 实现service

    1. //获取订单统计数据
    2. @Override
    3. public Map getCountMap(OrderCountQueryVo orderCountQueryVo) {
    4. //1.查询统计信息
    5. List orderCountVoList = baseMapper.selectOrderCount(orderCountQueryVo);
    6. //2.收集x轴、y轴数据
    7. List dateList //日期列表
    8. =orderCountVoList.stream()
    9. .map(OrderCountVo::getReserveDate)
    10. .collect(Collectors.toList());
    11. List countList //统计列表
    12. =orderCountVoList.stream()
    13. .map(OrderCountVo::getCount)
    14. .collect(Collectors.toList());
    15. //3.封装数据返回
    16. Map map = new HashMap<>();
    17. map.put("dateList", dateList);
    18. map.put("countList", countList);
    19. return map;
    20. }

    7. 测试

    3、创建远程调用接口

    1. 创建模块 service_order_client

    2. 创建目录、接口

    1. @FeignClient(value = "service-orders")
    2. @Repository
    3. public interface OrderFeignClient {
    4. //获取订单统计数据
    5. @PostMapping("/api/order/orderInfo/inner/getCountMap")
    6. Map getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo);
    7. }

    4. 创建统计分析模块

    1. service下创建service_statistics模块

    1. <dependencies>
    2. <dependency>
    3. <groupId>com.atguigugroupId>
    4. <artifactId>service_order_clientartifactId>
    5. <version>0.0.1-SNAPSHOTversion>
    6. dependency>
    7. dependencies>
    1. # 服务端口
    2. server.port=8209
    3. # 服务名
    4. spring.application.name=service-sta
    5. # 环境设置:dev、test、prod
    6. spring.profiles.active=dev
    7. # nacos服务地址
    8. spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
    1. @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    2. @EnableDiscoveryClient
    3. @EnableFeignClients(basePackages = {"com.atguigu"})
    4. @ComponentScan(basePackages = {"com.atguigu"})
    5. public class ServiceStatisticsApplication {
    6. public static void main(String[] args) {
    7. SpringApplication.run(ServiceStatisticsApplication.class, args);
    8. }
    9. }

    添加网关配置

    1. #设置路由id
    2. spring.cloud.gateway.routes[7].id=service-sta
    3. #设置路由的uri
    4. spring.cloud.gateway.routes[7].uri=lb://service-sta
    5. #设置路由断言,代理servicerId为auth-service的/auth/路径
    6. spring.cloud.gateway.routes[7].predicates= Path=/*/statistics/**

    2. 实现 controller

    1. @Api(tags = "统计管理接口")
    2. @RestController
    3. @RequestMapping("/admin/statistics")
    4. public class StatisticsController {
    5. @Autowired
    6. private OrderFeignClient orderFeignClient;
    7. @ApiOperation(value = "获取订单统计数据")
    8. @GetMapping("getCountMap")
    9. public R getCountMap(OrderCountQueryVo orderCountQueryVo) {
    10. Map map = orderFeignClient.getCountMap(orderCountQueryVo);
    11. return R.ok().data(map);
    12. }
    13. }

    5、统计功能前端 (ECharts)

    ​ECharts是百度的一个项目,后来百度把Echart捐给apache,用于图表展示,提供了常规的折线图、柱状图、散点图、饼图、K线图,用于统计的盒形图,用于地理数据可视化的地图、热力图、线图,用于关系数据可视化的关系图、treemap、旭日图,多维数据可视化的平行坐标,还有用于 BI 的漏斗图,仪表盘,并且支持图与图之间的混搭。

    官网:Apache ECharts

    1. 后台前端 安装echarts

    npm install --save echarts@4.1.0

    2. 添加路由、创建页面

    1. {
    2. path: '/statistics',
    3. component: Layout,
    4. redirect: '/statistics/order/index',
    5. name: 'BasesInfo',
    6. meta: { title: '统计管理', icon: 'table' },
    7. alwaysShow: true,
    8. children: [
    9. {
    10. path: 'order/index',
    11. name: '预约统计',
    12. component: () => import('@/views/yygh/sta/order/index'),
    13. meta: { title: '预约统计' }
    14. }
    15. ]
    16. },

    3. 添加API接口方法 sta.js

    1. import request from '@/utils/request'
    2. const api_name = '/admin/statistics'
    3. export default {
    4. //获取统计数据
    5. getCountMap(searchObj) {
    6. return request({
    7. url: `${api_name}/getCountMap`,
    8. method: 'get',
    9. params: searchObj
    10. })
    11. }
    12. }

    4. 实现相关页面

    1. <script>
    2. import echarts from 'echarts'
    3. import statisticsApi from '@/api/yygh/sta'
    4. export default {
    5. data() {
    6. return {
    7. searchObj: {
    8. hosname: '',
    9. reserveDateBegin: '',
    10. reserveDateEnd: ''
    11. },
    12. btnDisabled: false,
    13. chart: null,
    14. title: '',
    15. xData: [], // x轴数据
    16. yData: [] // y轴数据
    17. }
    18. },
    19. methods: {
    20. // 初始化图表数据
    21. showChart() {
    22. statisticsApi.getCountMap(this.searchObj).then(response => {
    23. this.yData = response.data.countList
    24. this.xData = response.data.dateList
    25. this.setChartData()
    26. })
    27. },
    28. setChartData() {
    29. // 基于准备好的dom,初始化echarts实例
    30. var myChart = echarts.init(document.getElementById('chart'))
    31. // 指定图表的配置项和数据
    32. var option = {
    33. title: {
    34. text: this.title + '挂号量统计'
    35. },
    36. tooltip: {},
    37. legend: {
    38. data: [this.title]
    39. },
    40. xAxis: {
    41. data: this.xData
    42. },
    43. yAxis: {
    44. minInterval: 1
    45. },
    46. series: [{
    47. name: this.title,
    48. type: 'line',
    49. data: this.yData
    50. }]
    51. }
    52. // 使用刚指定的配置项和数据显示图表。
    53. myChart.setOption(option)
    54. },
    55. }
    56. }
    57. script>

    5. 实现相关页面

  • 相关阅读:
    11月22日星期三今日早报简报微语报早读
    SpringBoot+Mybatis-Plus+Thymeleaf 实现增删改查+登录/注册
    powderdesigner 关于mysql生成pdm和java的方法
    趣味C语言——【猜数字】小游戏
    Nodejs+vue体育用品商城商品购物推荐系统_t81xg
    Spring Boot 2.x系列【20】应用监控篇之Actuator入门案例及端点配置详解
    Makefile 基础(二)—— Makefile 自动推导+ Makefile伪目标
    postgresql|数据库|序列Sequence的创建和管理
    FSDP(Fully Sharded Data Parallel)
    Integration by parts
  • 原文地址:https://blog.csdn.net/a111042555/article/details/126182914