一. HospitalSetController类(医院设置)
接口1:后台系统——添加医院
Post:http://localhost:8201/admin/hosp/hospitalSet/saveHospitalSet
1. 前端页面
2. controller
@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)));//调用serviceboolean save = hospitalSetService.save(hospitalSet);if (save) {return Result.ok();} else {return Result.fail();}}
3. 知识点:
(1)Random
第三方类
包名:java.util.Random
详情:https://www.cnblogs.com/ningvsban/p/3590722.html
两种构造方法。
rand.nextInt(100);中的100是随机数的上限,产生的随机数为0-100的整数,不包括100。
(2)MD5
自己写的类:
public final class MD5 {public static String encrypt(String strSrc) {try {char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8','9', 'a', 'b', 'c', 'd', 'e', 'f'};byte[] bytes = strSrc.getBytes();MessageDigest md = MessageDigest.getInstance("MD5");md.update(bytes);bytes = md.digest();int j = bytes.length;char[] chars = new char[j * 2];int k = 0;for (int i = 0; i < bytes.length; i++) {byte b = bytes[i];chars[k++] = hexChars[b >>> 4 & 0xf];chars[k++] = hexChars[b & 0xf];}return new String(chars);} catch (NoSuchAlgorithmException e) {e.printStackTrace();throw new RuntimeException("MD5加密出错!!+" + e);}}}
md5加密有两种方式,加盐方式和普通方式,这里用的是普通方式。这里是固定形式!固定调用
4. 总结:
(1)添加医院接口,service层和dao层是调用别人写好的!
(2)记忆方式:
前端传来hospital对象(含数据),附加两个属性,然后存入数据库。
如何附加属性数据?两个属性:
- 签名(密钥——MD5加密)
- 医院状态
接口2:后台系统——条件查询医院(分页)
Post:/admin/hosp/hospitalSet/findPageHospSet/{current}/{limit}
1. controller
//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);}
2. 总结:
(2)记忆方式:
- 参数:三个参数
第一个:当前页
第二个:总页数
第三个:封装查询条件的对象(有几种条件,就有几种属性)
- 创建分页对象
- 创建条件对象
- 条件对象封装条件
- 调用方法实现分页查询
- 返回
简单来说就三步:
- 分页
- 条件
-
接口3:后台——根据医院id查询医院
Get:/admin/hosp/hospitalSet/getHospSet/{id}
@GetMapping("getHospSet/{id}")public Result getHospSet(@PathVariable Long id) {HospitalSet hospitalSet = hospitalSetService.getById(id);return Result.ok(hospitalSet);}
二. HospitalController类(医院)
接口1:条件分页查询医院
1. controller
//医院列表(条件查询分页)@GetMapping("list/{page}/{limit}")public Result listHosp(@PathVariable Integer page,@PathVariable Integer limit,HospitalQueryVo hospitalQueryVo) {Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);//Slice:spring data Slice 学习https://segmentfault.com/a/1190000016999494//getContent():以list形式返回页面内容//getTotalElements():返回元素总数//这里这两个数据并没有要求打印出来,可有可无。但是从这里了解了一个东西,那就是mybatis-plus和spring data都有分页查询功能//这里调用的是spring data的分页查询接口!List<Hospital> content = pageModel.getContent();long totalElements = pageModel.getTotalElements();return Result.ok(pageModel);}
2. service
//医院列表(条件查询分页)//调用的是spring data的接口,我觉得想要看得懂代码,还得去系统的学spring data@Overridepublic Page<Hospital> selectHospPage(Integer page, Integer limit, HospitalQueryVo hospitalQueryVo) {//创建pageable对象//Pageable:封装了分页的参数,当前页,每页的显示的条数。注意:他的当前页是从0开始//https://blog.csdn.net/weixin_40936211/article/details/88682941Pageable pageable = PageRequest.of(page - 1, limit);//创建条件匹配器(mybatis-plus中的叫条件构造器)ExampleMatcher matcher = ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase(true);//hospitalSetQueryVo转换Hospital对象Hospital hospital = new Hospital();//vo类数据少BeanUtils.copyProperties(hospitalQueryVo, hospital);//创建对象Example<Hospital> example = Example.of(hospital, matcher);//调用方法实现查询Page<Hospital> pages = hospitalRepository.findAll(example, pageable);//获取查询list集合,遍历进行医院等级封装pages.getContent().stream().forEach(item -> {this.setHospitalHosType(item);});
3. 总结
接口2:更新医院上线状态
1. controller
@ApiOperation(value = "更新医院上线状态")@GetMapping("updateHospStatus/{id}/{status}")public Result updateHospStatus(@PathVariable String id, @PathVariable Integer status) {hospitalService.updateStatus(id, status);return Result.ok();}
2. service
//更新医院上线状态@Overridepublic void updateStatus(String id, Integer status) {//根据id查询医院信息Hospital hospital = hospitalRepository.findById(id).get();//设置修改的值hospital.setStatus(status);hospital.setUpdateTime(new Date());hospitalRepository.save(hospital);}
3. 总结:
接口3:医院详情信息
1. controller
@ApiOperation(value = "医院详情信息")@GetMapping("showHospDetail/{id}")public Result showHospDetail(@PathVariable String id) {Map<String, Object> map = hospitalService.getHospById(id);return Result.ok(map);}
2. service
@Overridepublic Map<String, Object> getHospById(String id) {Map<String, Object> result = new HashMap<>();Hospital hospital = this.setHospitalHosType(hospitalRepository.findById(id).get());//医院基本信息(包含医院等级)result.put("hospital", hospital);//单独处理更直观result.put("bookingRule", hospital.getBookingRule());//不需要重复返回hospital.setBookingRule(null);return result;}
3. 总结:
设置预约规则我不太懂,其他的都好说
service直接返回一整个hospital给controller,再传至客户端三. DepartmentController类
接口1:根据医院编号,查询医院所有科室列表
1. controller
//根据医院编号,查询医院所有科室列表@ApiOperation(value = "查询医院所有科室列表")@GetMapping("getDeptList/{hoscode}")public Result getDeptList(@PathVariable String hoscode) {List<DepartmentVo> list = departmentService.findDeptTree(hoscode);return Result.ok(list);}
2. service
//根据医院编号,查询医院所有科室列表@Overridepublic List<DepartmentVo> findDeptTree(String hoscode) {//创建list集合,用于最终数据封装List<DepartmentVo> result = new ArrayList<>();//根据医院编号,查询医院所有科室信息Department departmentQuery = new Department();departmentQuery.setHoscode(hoscode);Example example = Example.of(departmentQuery);//所有科室列表 departmentListList<Department> departmentList = departmentRepository.findAll(example);//根据大科室编号 bigcode 分组,获取每个大科室里面下级子科室Map<String, List<Department>> deparmentMap =departmentList.stream().collect(Collectors.groupingBy(Department::getBigcode));//遍历map集合 deparmentMapfor (Map.Entry<String, List<Department>> entry : deparmentMap.entrySet()) {//大科室编号String bigcode = entry.getKey();//大科室编号对应的全局数据List<Department> deparment1List = entry.getValue();//封装大科室DepartmentVo departmentVo1 = new DepartmentVo();departmentVo1.setDepcode(bigcode);departmentVo1.setDepname(deparment1List.get(0).getBigname());//封装小科室List<DepartmentVo> children = new ArrayList<>();for (Department department : deparment1List) {DepartmentVo departmentVo2 = new DepartmentVo();departmentVo2.setDepcode(department.getDepcode());departmentVo2.setDepname(department.getDepname());//封装到list集合children.add(departmentVo2);}//把小科室list集合放到大科室children里面departmentVo1.setChildren(children);//放到最终result里面result.add(departmentVo1);}//返回return result;}
3. 总结
遗留问题
医院设置和医院有什么区别?
说实话,我不懂!!!
医院设置类的医院是mysql数据库的yygh_hosp表中的
医院类的医院是mongodb数据库的yygh_hosp表中的
这是个遗留问题!
- 医院类的第3个接口有个设置预约规则,不太懂!
