• 尚医通 (五) --------- 医院模块



    一、需求

    医院设置主要是用来保存开通医院的一些基本信息,每个医院一条信息,保存了医院编号 (平台分配,全局唯一) 和 接口调用相关的签名 key 等信息,是整个流程的第一步,只有开通了医院设置信息,才可以上传医院相关信息。

    我们所开发的功能就是基于单表的一个 CRUD、锁定/解锁和发送签名信息这些基本功能。

    二、表结构

    在这里插入图片描述

    • hosname :医院名称
    • hoscode :医院编号 (平台分配,全局唯一,api接口必填信息)
    • api_url :医院回调的基础 url (如:预约下单,我们要调用该地址去医院下单)
    • sign_key :双方 api 接口调用的签名 key,由平台生成
    • contacts_name:医院联系人姓名
    • contacts_phone:医院联系人手机
    • status :状态 (锁定/解锁)

    三、医院模块开发

    1. 搭建医院模块 service-hosp

    A、搭建 service-hosp

    点击 service,选择 New–>Module ,操作如下

    在这里插入图片描述

    点击 create ,结构如下

    在这里插入图片描述

    B、修改配置

    修改 pom.xml

    
    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <parent>
            <artifactId>serviceartifactId>
            <groupId>com.fancy.yyghgroupId>
            <version>1.0version>
        parent>
        <modelVersion>4.0.0modelVersion>
    
        <version>1.0version>
        <artifactId>service-hospartifactId>
        <packaging>jarpackaging>
        <name>service-hospname>
        <description>service-hospdescription>
    
        <dependencies>
        dependencies>
    
        <build>
            <finalName>service-hospfinalName>
            <plugins>
                <plugin>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-maven-pluginartifactId>
                plugin>
            plugins>
        build>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    添加配置文件 application.properties

    # 服务端口
    server.port=8201
    # 服务名
    spring.application.name=service-hosp
    
    # 环境设置:dev、test、prod
    spring.profiles.active=dev
    
    # mysql数据库连接
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://192.168.38.130:3306/yygh_hosp?characterEncoding=utf-8&useSSL=false
    spring.datasource.username=root
    spring.datasource.password=aszhuo123
    
    #返回json的全局时间格式
    spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
    spring.jackson.time-zone=GMT+8
    
    #配置mapper xml文件的路径
    #mybatis-plus.mapper-locations=classpath:com/fancy/yygh/mapper/xml/*.xml
    mybatis-plus.mapper-locations=classpath:com/fancy/yygh/mapper/xml/*.xml
    # nacos服务地址
    spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
    
    #开启sentinel
    feign.sentinel.enabled=true
    #设置sentinel地址
    spring.cloud.sentinel.transport.dashboard=http://127.0.0.1:8858
    
    #mongodb地址
    spring.data.mongodb.host=192.168.38.131
    spring.data.mongodb.port=27017
    spring.data.mongodb.database=yygh_hosp
    
    #rabbitmq地址
    spring.rabbitmq.host=127.0.0.1
    spring.rabbitmq.port=5672
    spring.rabbitmq.username=guest
    spring.rabbitmq.password=guest
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    C、添加启动类

    package com.fancy.yygh;
    
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class ServiceHospitalApplication {
        public static void main(String[] args) {
            SpringApplication.run(ServiceHospitalApplication.class, args);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    2. 添加医院设置 CRUD

    A、添加 model

    说明:由于实体对象没有逻辑,我们已经统一导入com.fancy.yygh.model.hosp.HospitalSet

    B、添加 Mapper

    添加 com.fancy.yygh.hosp.mapper.HospitalSetMapper

    package com.fancy.yygh.mapper;
    
    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import com.fancy.yygh.model.hosp.HospitalSet;
    import org.apache.ibatis.annotations.Mapper;
    import org.mybatis.spring.annotation.MapperScan;
    
    @Mapper
    public interface HospitalSetMapper extends BaseMapper<HospitalSet> {
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    C、在 resoucre/mapper 下添加 HospitalSetMapper.xml

    
    DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.fancy.yygh.hosp.mapper.HospitalSetMapper">
    mapper>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    C、添加 service 接口及实现类

    添加com.fancy.yygh.hosp.service.HospitalSetService 接口

    package com.fancy.yygh.hosp.service;
    
    import com.baomidou.mybatisplus.extension.service.IService;
    
    public interface HospitalSetService extends IService<HospitalSet> {
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    添加 com.fancy.yygh.hosp.service.impl.HospitalSetServiceImpl 接口实现

    package com.fancy.yygh.hosp.service.impl;
    
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.fancy.yygh.hosp.mapper.HospitalSetMapper;
    import com.fancy.yygh.hosp.service.HospitalSetService;
    import com.fancy.yygh.model.hosp.HospitalSet;
    import org.springframework.beans.factory.annotation.Autowired;
    
    public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
        @Autowired
        private HospitalSetMapper hospitalSetMapper;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    D、添加 controller

    package com.fancy.yygh.hosp.controller;
    
    
    import com.fancy.yygh.hosp.service.HospitalSetService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/admin/hosp/hospitalSet")
    public class HospitalSetController {
        @Autowired
        HospitalSetService hospitalSetService;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    F、医院设置 CRUD

    由于com.baomidou.mybatisplus.extension.service.impl.ServiceImpl类已经默认实现了单表的CRUD,分页查询也有默认实现,能够更加灵活和代码简洁把分页查询功能实现。、

    G、添加 controller 方法

    package com.fancy.yygh.hosp.controller;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.fancy.yygh.common.result.Result;
    import com.fancy.yygh.common.util.MD5;
    import com.fancy.yygh.hosp.service.HospitalSetService;
    import com.fancy.yygh.model.hosp.HospitalSet;
    import com.fancy.yygh.vo.hosp.HospitalSetQueryVo;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.util.StringUtils;
    import org.springframework.web.bind.annotation.*;
    
    import java.util.List;
    import java.util.Random;
    
    @Api(tags = "医院设置管理")
    @RestController
    @RequestMapping("/admin/hosp/hospitalSet")
    public class HospitalSetController {
        @Autowired
        HospitalSetService hospitalSetService;
    
        // 1. 查询医院设置表的所有信息
        @ApiOperation(value = "获取所有医院设置")
        @GetMapping("findAll")
        public Result findAllHostpitalSet() {
            // 调用 service 方法
            List<HospitalSet> list = hospitalSetService.list();
            return Result.ok(list);
        }
    
        //2 逻辑删除医院设置
        @ApiOperation(value = "逻辑删除医院设置")
        @DeleteMapping("{id}")
        public Result removeHospSet(@PathVariable Long id) {
            boolean flag = hospitalSetService.removeById(id);
            if(flag) {
                return Result.ok();
            } else {
                return Result.fail();
            }
        }
    
        //3 条件查询带分页
        @PostMapping("findPageHospSet/{current}/{limit}")
        public Result findPageHospSet(@PathVariable long current,
                                      @PathVariable long limit,
                                      @RequestBody
                                              (required = false)HospitalSetQueryVo hospitalSetQueryVo) {
            //创建page对象,传递当前页,每页记录数
            Page<HospitalSet> page = new Page<>(current,limit);
            //构建条件
            QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
            String hosname = hospitalSetQueryVo.getHosname();//医院名称
            String hoscode = hospitalSetQueryVo.getHoscode();//医院编号
            if(!StringUtils.isEmpty(hosname)) {
                wrapper.like("hosname",hospitalSetQueryVo.getHosname());
            }
            if(!StringUtils.isEmpty(hoscode)) {
                wrapper.eq("hoscode",hospitalSetQueryVo.getHoscode());
            }
            //调用方法实现分页查询
            Page<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper);
            //返回结果
            return Result.ok(pageHospitalSet);
        }
    
        //4 添加医院设置
        @PostMapping("saveHospitalSet")
        public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet) {
            //设置状态 1 使用 0 不能使用
            hospitalSet.setStatus(1);
            //签名秘钥
            Random random = new Random();
            hospitalSet.setSignKey(MD5.encrypt(System.currentTimeMillis()+""+random.nextInt(1000)));
            //调用service
            boolean save = hospitalSetService.save(hospitalSet);
            if(save) {
                return Result.ok();
            } else {
                return Result.fail();
            }
        }
    
        //5 根据id获取医院设置
        @GetMapping("getHospSet/{id}")
        public Result getHospSet(@PathVariable Long id) {
            HospitalSet hospitalSet = hospitalSetService.getById(id);
            return Result.ok(hospitalSet);
        }
    
        //6 修改医院设置
        @PostMapping("updateHospitalSet")
        public Result updateHospitalSet(@RequestBody HospitalSet hospitalSet) {
            boolean flag = hospitalSetService.updateById(hospitalSet);
            if(flag) {
                return Result.ok();
            } else {
                return Result.fail();
            }
        }
    
        //7 批量删除医院设置
        @DeleteMapping("batchRemove")
        public Result batchRemoveHospitalSet(@RequestBody List<Long> idList) {
            hospitalSetService.removeByIds(idList);
            return Result.ok();
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112

    这里用到了统一返回结果,定义如下:

    package com.fancy.yygh.common.result;
    
    import io.swagger.annotations.ApiModel;
    import io.swagger.annotations.ApiModelProperty;
    import lombok.Data;
    
    /**
     * 全局统一返回结果类
     */
    @Data
    @ApiModel(value = "全局统一返回结果")
    public class Result<T> {
    
        @ApiModelProperty(value = "返回码")
        private Integer code;
    
        @ApiModelProperty(value = "返回消息")
        private String message;
    
        @ApiModelProperty(value = "返回数据")
        private T data;
    
        public Result(){}
    
        protected static <T> Result<T> build(T data) {
            Result<T> result = new Result<T>();
            if (data != null)
                result.setData(data);
            return result;
        }
    
        public static <T> Result<T> build(T body, ResultCodeEnum resultCodeEnum) {
            Result<T> result = build(body);
            result.setCode(resultCodeEnum.getCode());
            result.setMessage(resultCodeEnum.getMessage());
            return result;
        }
    
        public static <T> Result<T> build(Integer code, String message) {
            Result<T> result = build(null);
            result.setCode(code);
            result.setMessage(message);
            return result;
        }
    
        public static<T> Result<T> ok(){
            return Result.ok(null);
        }
    
        /**
         * 操作成功
         * @param data
         * @param 
         * @return
         */
        public static<T> Result<T> ok(T data){
            Result<T> result = build(data);
            return build(data, ResultCodeEnum.SUCCESS);
        }
    
        public static<T> Result<T> fail(){
            return Result.fail(null);
        }
    
        /**
         * 操作失败
         * @param data
         * @param 
         * @return
         */
        public static<T> Result<T> fail(T data){
            Result<T> result = build(data);
            return build(data, ResultCodeEnum.FAIL);
        }
    
        public Result<T> message(String msg){
            this.setMessage(msg);
            return this;
        }
    
        public Result<T> code(Integer code){
            this.setCode(code);
            return this;
        }
    
        public boolean isOk() {
            if(this.getCode().intValue() == ResultCodeEnum.SUCCESS.getCode().intValue()) {
                return true;
            }
            return false;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92

    这样一个完整的 CRUD 就完成了。。。

    四、医院锁定与解锁

    医院锁定后不能再上传数据。。。

    添加 controller 方法

    在 HospitalSetController 类添加方法

    //8 医院设置锁定和解锁
    @PutMapping("lockHospitalSet/{id}/{status}")
    public Result lockHospitalSet(@PathVariable Long id,
                                  @PathVariable Integer status) {
        //根据id查询医院设置信息
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        //设置状态
        hospitalSet.setStatus(status);
        //调用方法
        hospitalSetService.updateById(hospitalSet);
        return Result.ok();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    五、发送签名 key

    医院信息配置后,可以通过短信的形式发送医院编号与签名 key 给联系人,联系人拿到该信息就可以参考《尚医通 API 接口文档.docx》对接接口了。

    添加 controller 方法

    在 HospitalSetController 类添加方法

    //9 发送签名秘钥
    @PutMapping("sendKey/{id}")
    public Result lockHospitalSet(@PathVariable Long id) {
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        String signKey = hospitalSet.getSignKey();
        String hoscode = hospitalSet.getHoscode();
        //TODO 发送短信
        return Result.ok();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    mysql5.7停止维护时间
    Impala入门案例
    KylinOSv10修改ulimit值
    52基于MATLAB的希尔伯特Hilbert变换求包络谱
    ApplicationContext版本的快速入门
    解决https页面加载http资源报错
    Tomcat 源码解析一初识
    Google XTS测试简述
    [教程] 一文进阶Redis
    精通 VS 调试技巧,学习与工作效率翻倍!
  • 原文地址:https://blog.csdn.net/m0_51111980/article/details/127736677