# 医院设置需求
## 1.需求
医院设置主要是用来保存开通医院的一些基本信息,每个医院一条信息,保存了医院编号(平台分配,全局唯一)和接口调用相关的签名key信息,是整个流程的第一步,只有开通了医院设置信息,才可以上传医院相关信息。
我们所开发的功能就是基于单表的一个CRUD、锁定/解锁和发送签名信息这些基本功能。
## 2.表结构
![image-20220330193150520](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220330193150520.png)
# 医院模块开发
## 1.搭建医院模块service-hosp
### 1.1搭建service-hosp
用Maven工具直接在service中添加子模块service-hosp
![image-20220330210309330](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220330210309330.png)
### 1.2修改配置
添加配置文件`application.yaml`,其中`Nacos`、`Rabbmit`等配置暂时用不到,先不急用,可以注释。
```yaml
# 服务端口
server:
port: 8201
spring:
application:
name: service_hosp
datasource:
url: jdbc:mysql://localhost:3306/yygh_hosp?setUnicode=true&characterEncoding=utf8
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
profiles:
active: dev
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
# 现在暂时用不着,先注释掉
# cloud:
# nacos:
# discovery:
# server-addr: 127.0.0.0:8848
# sentinel:
# transport:
# dashboard: http://127.0.0.1:8858
# rabbitmq:
# host: 127.0.0.1
# port: 5672
# username: guest
# password: guest
# data:
# mongodb:
# database: yygh_hosp
# host: 127.0.0.1
# port: 27017
# fegin:
# sentinel:
# enabled: true
# mybatis-plus:
# mapper-locations: classpath*:/mapper/*.xml
# type-aliases-package: com.zhoujk.yygh.model.*
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# knife4j:
# enable: true
```
### 1.3添加启动类
```java
package com.zhoujk.yygh.hosp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication
public class ServiceHospApplication {
//SpringBoot启动
public static void main(String[] args) {
SpringApplication.run(ServiceHospApplication.class, args);
}
}
```
## 2.添加医院设置CRUD
### 2.1添加model
说明:由于实体对象没有逻辑,统一导入。`model`模块统一存放管理所有医院的实体对象。下面是所有的项目用到的实体类、VO。
![image-20220331211435063](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220331211435063.png)
==com.zhoujk.yygh.hosp.model.*==
```
com
└── zhoujk
└── yygh
└── hosp
├── enums
│ ├── AuthStatusEnum.java
│ ├── OrderStatusEnum.java
│ ├── PaymentStatusEnum.java
│ ├── PaymentTypeEnum.java
│ └── RefundStatusEnum.java
├── model
│ ├── acl
│ │ ├── Permission.java
│ │ ├── Role.java
│ │ ├── RolePermission.java
│ │ ├── User.java
│ │ └── UserRole.java
│ ├── base
│ │ ├── BaseEntity.java
│ │ └── BaseMongoEntity.java
│ ├── cmn
│ │ └── Dict.java
│ ├── enums
│ │ └── DictEnum.java
│ ├── hospital
│ │ ├── BookingRule.java
│ │ ├── Department.java
│ │ ├── Hospital.java
│ │ ├── HospitalSet.java
│ │ └── Schedule.java
│ ├── order
│ │ ├── OrderInfo.java
│ │ ├── PaymentInfo.java
│ │ └── RefundInfo.java
│ └── user
│ ├── Patient.java
│ ├── UserInfo.java
│ └── UserLoginRecord.java
└── vo
├── cmn
│ └── DictExcelVO.java
├── hospital
│ ├── BookingScheduleRuleVO.java
│ ├── DepartmentQueryVO.java
│ ├── DepartmentVO.java
│ ├── HospitalQueryVO.java
│ ├── HospitalSetQueryVO.java
│ ├── ScheduleOrderVO.java
│ └── ScheduleQueryVO.java
├── msm
│ └── MsmVo.java
├── order
│ ├── OrderCountQueryVo.java
│ ├── OrderCountVo.java
│ ├── OrderMqVo.java
│ ├── OrderQueryVo.java
│ └── SignInfoVo.java
└── user
├── LoginVO.java
├── RegisterVo.java
├── UserAuthVo.java
└── UserInfoQueryVo.java
```
### 2.2添加Mapper
添加==com.zhoujk.yygh.hosp.mapper.HospitalSetMapper==
```java
package com.zhoujk.yygh.hosp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhoujk.yygh.hosp.model.hospital.HospitalSet;
import org.apache.ibatis.annotations.Mapper;
public interface HospitalSetMapper extends BaseMapper<HospitalSet> {
}
```
添加==com.zhoujk.yygh.hosp.mapper.xml==xml配置文件
```xml-dtd
<?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.zhoujk.yygh.hosp.mapper.HospitalSetMapper">
</mapper>
```
注意:同时需要把`model`依赖加入`service_hosp`中:如下是:pom.xml(service_hosp)文件
```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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>service</artifactId>
<groupId>com.zhoujk</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service_hosp</artifactId>
<dependencies>
<dependency>
< ! -- model依赖 -- >
<groupId>com.zhoujk</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
```
### 2.3添加service接口以及实现类
添加==com.zhoujk.yygh.hosp.service.HospitalSetService==接口
```java
public interface HospitalSetService extends IService<HospitalSet> {
}
```
添加==com.zhoujk.yygh.hosp.service.impl.HospitalSetServiceImpl==实现类
```java
package com.zhoujk.yygh.hosp.service.impl;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhoujk.yygh.hosp.mapper.HospitalSetMapper;
import com.zhoujk.yygh.hosp.model.hospital.HospitalSet;
import com.zhoujk.yygh.hosp.service.HospitalSetService;
import org.springframework.stereotype.Service;
/**
* @author : zhoujiankang
* @Desc:
* @since : 2022/3/31 20:52
*/
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
}
```
### 2.4添加controller
添加==com.zhoujk.yygh.hosp.controller.HospitalSetController==
```java
@RestController
@RequestMapping("/admin/hosp/HospitalSet")
public class HospitalSetController {
//注入service
@Autowired
private HospitalSetService hospitalSetService;
}
```
### 2.5医院设置CRUD
由于com.baomindou.mybatis.extension.service.impl.ServiceImpl类已经默认实现了单表的CRUD,分页查询也有默认实现,能够更加灵活地、简洁地实现分页查询功能。
### 2.6添加controller方法
```java
@RestController
@RequestMapping("/admin/hosp/HospitalSet")
public class HospitalSetController {
//注入service
@Autowired
private HospitalSetService hospitalSetService;
/** 在浏览器中打开
* 返回地址 http://localhost:8201/admin/hosp/HospitalSet/findAll
* */
//查询所有
@GetMapping("findAll")
public List<HospitalSet> findAllHospitalSet() {
//调用service的方法
List<HospitalSet> list = hospitalSetService.list();
return list;
}
//删除医院设置
@DeleteMapping("{id}")
public boolean removeHospitalSet(@PathVariable long id) {
boolean flag = hospitalSetService.removeById(id);
return flag;
}
}
```
![image-20220331221054888](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220331221054888.png)
很遗憾,我不太使用ApiPost测试Controller的删除操作。所以接下来要介绍一下Swaager,它能很好测试接口。
service_hosp模块建立