文章目录
- 一、医院模块开发
- 1、搭建医院模块service-hosp
- 1.1搭建service-hosp
- 1.2修改配置
- 1.3 添加启动类
- 2、添加医院设置CURD
- 2.1 添加model
- 2.2 添加Mapper
- 2.3 添加service接口及实现类
- 2.4 添加controller
- 2.5 医院设置CRUD
- 2.6 添加controller方法
- 3、Swagger2介绍与集成
- 4、医院锁定与解锁
- 4.1 添加controller方法
- 5、发送签名key
- 5.1 添加controller方法
- 6、全局异常处理
- 7、日志
一、医院模块开发
1、搭建医院模块service-hosp
1.1搭建service-hosp
点击service,选择New–>Module,操作如下
选择下一步
选择下一步
完成,结构如下:
1.2修改配置
1、修改pom.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.atguigu.yygh</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>1.0</version>
<artifactId>service-hosp</artifactId>
<packaging>jar</packaging>
<name>service-hosp</name>
<description>service-hosp</description>
<dependencies>
</dependencies>
<build>
<finalName>service-hosp</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2、添加配置文件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.44.163:3306/yygh_hosp?characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=root123
#返回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/atguigu/yygh/mapper/xml/*.xml
mybatis-plus.mapper-locations=classpath:com/atguigu/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.44.163
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.3 添加启动类
添加com.atguigu.yygh.ServiceHospApplication类
package com.atguigu.yygh;
@SpringBootApplication
public class ServiceHospApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceHospApplication.class, args);
}
}
2、添加医院设置CURD
2.1 添加model
说明:由于实体对象没有逻辑,我们已经统一导入
com.atguigu.yygh.model.hosp.HospitalSet
2.2 添加Mapper
添加com.atguigu.yygh.hosp.mapper.HospitalSetMapper
package com.atguigu.yygh.hosp.mapper;
@Mapper
public interface HospitalSetMapper extends BaseMapper<HospitalSet> {
}
在mapper/xml下添加HospitalSetMapper.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.hosp.mapper.HospitalSetMapper">
</mapper>
2.3 添加service接口及实现类
1、添加com.atguigu.yygh.hosp.service.HospitalSetService接口
package com.atguigu.yygh.hosp.service;
public interface HospitalSetService extends IService<HospitalSetService> {
}
2、添加com.atguigu.yygh.hosp.service.impl.HospitalSetServiceImpl接口实现
package com.atguigu.yygh.hosp.service.impl;
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet>implements HospitalSetService {
@Autowired
private HospitalSetMapper hospitalSetMapper;
}
2.4 添加controller
添加com.atguigu.yygh.hosp.controller.HospitalSetController类
package com.atguigu.yygh.hosp.controller;
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {
@Autowired
private HospitalSetService hospitalSetService;
}
2.5 医院设置CRUD
由于com.baomidou.mybatisplus.extension.service.impl.ServiceImpl类已经默认实现 了单表的CRUD,分页查询也有默认实现,能够更加灵活和代码简洁把分页查询功能实现。
2.6 添加controller方法
@Api(tags = "医院设置管理")
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {
//注入service
@Autowired
private HospitalSetService hospitalSetService;
//1 查询医院设置表所有信息
@ApiOperation(value = "获取所有医院设置")
@GetMapping("findAll")
public Result findAllHospitalSet() {
//调用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();
}
}
说明:一个完整的CRUD就实现了
3、Swagger2介绍与集成
Swagger2介绍与集成
4、医院锁定与解锁
医院锁定后不能再上传数据
4.1 添加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();
}
5、发送签名key
医院信息配置后,可以通过短信的形式发送医院编号与签名key给联系人,联系人拿到该信息就可以参考《尚医通API接口文档.docx》对接接口了。
5.1 添加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();
}
6、全局异常处理
全局异常处理
7、日志
日志