尚硅谷8:开发平台接口,SpringCloud,上传排班

news2024/9/24 7:22:33

目录

内容介绍

开发平台接口-查询医院

开发平台接口-上传科室接口

开发平台接口-查询科室接口

开发平台接口-删除科室接口

上传排班和查询排班接口

医院列表功能(接口)


内容介绍

1、开发平台接口-查询医院

2、开发平台接口-上传科室接口

3、开发平台接口-查询科室接口

4、开发平台接口-删除科室接口

5、上传排班和查询排班接口

6、SpringCloud相关概念介绍

7、服务发现-搭建Nacos服务

8、医院管理模块需求

9、医院列表功能(接口)

开发平台接口-查询医院

1、查看api文档

2、实现controller

@ApiOperation(value = "获取医院信息")

  @PostMapping("hospital/show")

  public Result hospital(HttpServletRequest request) {

    //1request获取参数,类型转化

    Map<String, String[]> parameterMap = request.getParameterMap();

    Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);

    //2取出hoscode、校验参数

    String hoscode = (String) paramMap.get("hoscode");

    if(StringUtils.isEmpty(hoscode)){

      throw new YyghException(20001,"参数有误");  

    }

    //3进行验签(省略)

    //4 根据hoscode查询医院信息

    Hospital hospital = hospitalService.getByHoscode(hoscode);

    //5封装返回

    return Result.ok(hospital);

  }

3、实现service

//根据hoscode查询医院信息

  @Override

  public Hospital getByHoscode(String hoscode) {

    Hospital hospital = hospitalRepository.getByHoscode(hoscode);

    return hospital;

  }

4、测试

开发平台接口-上传科室接口

1、查看api文档

2、搭建Mongo框架

1)确认实体

2)创建接口

@Repository

  public interface DepartmentRepository extends MongoRepository<Department,String> {

}

3)创建service

public interface DepartmentService {

}

@Service

  public class DepartmentServiceImpl implements DepartmentService {

  

    @Autowired

    private DepartmentRepository departmentRepository;

  

  }

5)改造controller

3、实现controller

@ApiOperation(value = "上传科室")

  @PostMapping("saveDepartment")

  public Result saveDepartment(HttpServletRequest request) {

    //1request获取参数,类型转化

    Map<String, String[]> parameterMap = request.getParameterMap();

    Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);

    //2 进行验签(省略)

    //3 保存科室信息

    departmentService.save(paramMap);

    //4返回结果

    return Result.ok();

  }

4、实现service

//保存科室信息

  @Override

  public void save(Map<String, Object> paramMap) {

    //1转化参数paramMap=Department

    String paramJsonStr = JSONObject.toJSONString(paramMap);

    Department department = JSONObject.parseObject(paramJsonStr, Department.class);

    //2根据hoscodedepcode查询科室信息

    Department targetDepartment = departmentRepository

            .getByHoscodeAndDepcode(department.getHoscode(),department.getDepcode());

    if(targetDepartment!=null){

        //3存在,更新

        department.setId(targetDepartment.getId());

        department.setCreateTime(targetDepartment.getCreateTime());

        department.setUpdateTime(new Date());

        department.setIsDeleted(targetDepartment.getIsDeleted());

        departmentRepository.save(department);

  

    }else{

        //4不存在,新增

        department.setCreateTime(new Date());

        department.setUpdateTime(new Date());

        department.setIsDeleted(0);

        departmentRepository.save(department);

    }

  }

5、测试

1)测试数据

2)测试步骤

开发平台接口-查询科室接口

1、查看api文档

2、实现controller

1)分析接口

*参数:请求对象

*返回值:ResultPage

2)实现方法

@ApiOperation(value = "获取分页列表")

  @PostMapping("department/list")

  public Result department(HttpServletRequest request) {

    //1request获取参数,类型转化

    Map<String, String[]> parameterMap = request.getParameterMap();

    Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);

    //2取出参数

    String hoscode = (String) paramMap.get("hoscode");

    String sign = (String) paramMap.get("sign");

    //3进行验签(省略)

    //4取出分页参数进行验空

    int page = StringUtils.isEmpty((String) paramMap.get("page"))?1:

            Integer.parseInt((String) paramMap.get("page"));

    int limit = StringUtils.isEmpty((String) paramMap.get("limit"))?10:

            Integer.parseInt((String) paramMap.get("limit"));

    //5封装查询条件

    DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();

    departmentQueryVo.setHoscode(hoscode);

    //6实现带分页带条件科室列表查询

    Page<Department> pageModel = departmentService

            .selectPage(page,limit,departmentQueryVo);

    //7封装返回数据

    return Result.ok(pageModel);

  

  }

3、实现service

//实现带分页带条件科室列表查询

  @Override

  public Page<Department> selectPage(int page, int limit, DepartmentQueryVo departmentQueryVo) {

    //1创建分页查询对象

    //1.1创建排序对象

    Sort sort = Sort.by(Sort.Direction.ASC,"depcode");

    //1.2创建分页对象

    Pageable pageable = PageRequest.of(page-1,limit,sort);

    //2创建查询条件模板

    //2.1封装查询条件

    Department department = new Department();

    BeanUtils.copyProperties(departmentQueryVo,department);

    //2.2创建模板构造器

    ExampleMatcher matcher = ExampleMatcher.matching()

            .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)

            .withIgnoreCase(true);

    //2.3创建模板

    Example<Department> example = Example.of(department,matcher);

    

    //3实现带分页带条件查询

    Page<Department> pageModel = departmentRepository.findAll(example, pageable);

    return pageModel;

  }

4、测试

开发平台接口-删除科室接口

1、查看api文档

2、实现controller

@ApiOperation(value = "删除科室")

  @PostMapping("department/remove")

  public Result removeDepartment(HttpServletRequest request) {

    //1request获取参数,类型转化

    Map<String, String[]> parameterMap = request.getParameterMap();

    Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);

    //2取出参数

    String hoscode = (String) paramMap.get("hoscode");

    String depcode = (String) paramMap.get("depcode");

    String sign = (String) paramMap.get("sign");

    //3进行验签(省略)

    //4调用接口删除

    departmentService.remove(hoscode,depcode);

    return Result.ok();

  }

3、实现service

//删除科室

  @Override

  public void remove(String hoscode, String depcode) {

    //先查询

    Department department = departmentRepository

            .getByHoscodeAndDepcode(hoscode,depcode);

    //后删除

    if(department!=null){

        departmentRepository.deleteById(department.getId());

    }

  }

4、测试

上传排班和查询排班接口

1、查看api文档

2、搭建框架

1)确认实体

2)创建相关接口、类

3、创建接口

1)实现controller

@ApiOperation(value = "上传排班")

  @PostMapping("saveSchedule")

  public Result saveSchedule(HttpServletRequest request) {

    //1request获取参数,类型转化

    Map<String, String[]> parameterMap = request.getParameterMap();

    Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);

    //2 进行验签(省略)

    //3 保存排班信息

    scheduleService.save(paramMap);

    //4返回结果

    return Result.ok();

  }

2)实现service

//保存排班信息

  @Override

  public void save(Map<String, Object> paramMap) {

    //1转化参数paramMap=Department

    String paramJsonStr = JSONObject.toJSONString(paramMap);

    Schedule schedule = JSONObject.parseObject(paramJsonStr, Schedule.class);

    //2根据hoscodehosScheduleId查询排班信息

    Schedule targetSchedule = scheduleRepository

            .getByHoscodeAndHosScheduleId(schedule.getHoscode(),schedule.getHosScheduleId());

    

    if(targetSchedule!=null){

        //3存在,更新

        schedule.setId(targetSchedule.getId());

        schedule.setCreateTime(targetSchedule.getCreateTime());

        schedule.setUpdateTime(new Date());

        schedule.setIsDeleted(targetSchedule.getIsDeleted());

        scheduleRepository.save(schedule);

        

    }else{

        //4不存在,新增

        schedule.setCreateTime(new Date());

        schedule.setUpdateTime(new Date());

        schedule.setIsDeleted(0);

        scheduleRepository.save(schedule);

    }

  }

4、测试

1)测试数据

2)测试步骤

医院列表功能(接口)

1、分析接口

1)参数:pagelimit、查询条件对象

*确认vo对象

2)返回值:RPage

2、初步创建查询接口

1)创建controller

@Api(tags = "医院接口")

  @RestController

@RequestMapping("/admin/hosp/hospital")

  @CrossOrigin

  public class HospitalController {

  

    //注入service

    @Autowired

    private HospitalService hospitalService;

  

  

  }

2)实现controller方法

@ApiOperation(value = "带条件带分页查询医院列表")

  @GetMapping("getHospPage/{page}/{limit}")

  public R getHospPage(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo) {

    Page<Hospital> pageModel = hospitalService.selectPage(page,limit,hospitalQueryVo);

    return R.ok().data("pageModel",pageModel);

  }

3)实现service

//带条件带分页查询医院列表

  @Override

  public Page<Hospital> selectPage(Integer page, Integer limit,

                                 HospitalQueryVo hospitalQueryVo) {

    //1创建分页对象

    //1.1创建排序对象

    Sort sort = Sort.by(Sort.Direction.ASC,"hoscode");

    //1.2创建分页对象

    Pageable pageable = PageRequest.of((page-1),limit,sort);

    //2创建条件模板

    //2.1封装查询条件

    Hospital hospital = new Hospital();

    BeanUtils.copyProperties(hospitalQueryVo,hospital);

    //2.2模板构造器

    ExampleMatcher matcher = ExampleMatcher.matching()

            .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)

            .withIgnoreCase(true);

    //2.3创建模板

    Example<Hospital> example = Example.of(hospital,matcher);

    //3实现带条件带分页查询

    Page<Hospital> pageModel = hospitalRepository.findAll(example, pageable);

  

    //4 TODO 遍历集合翻译字段

  

    return pageModel;

  }

3、在cmn模块实现翻译字段接口

1)分析数据

#国标数据

SELECT d.`name` FROM dict d WHERE d.`value` = 110114;

#自定义数据

#根据字典编码查询父级别数据

SELECT d.id FROM dict d WHERE d.`dict_code` = 'Hostype';

#根据父级别数据id+value查询数据

SELECT d.name FROM dict d WHERE d.`parent_id`=10000 AND d.`value`=1;

2)分析接口

#国标数据

*参数:value

*返回值:name

#自定义数据

*参数:dictCode value

*返回值:name

3)实现controller

@ApiOperation(value = "获取数据字典名称(自定义)")

  @GetMapping(value = "/getName/{parentDictCode}/{value}")

  public String getName(

        @PathVariable("parentDictCode") String parentDictCode,

        @PathVariable("value") String value) {

    String name = dictService.getName(parentDictCode,value);

    return name;

  }

  

  @ApiOperation(value = "获取数据字典名称(国标)")

  @GetMapping(value = "/getName/{value}")

  public String getName(

        @PathVariable("value") String value) {

    String name = dictService.getName("",value);

    return name;

  }

4)实现service

//获取数据字典名称

  @Override

  public String getName(String parentDictCode, String value) {

    if(StringUtils.isEmpty(parentDictCode)){

        //1查询国标数据

        LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(Dict::getValue,value);

        Dict dict = baseMapper.selectOne(wrapper);

        if(dict!=null){

            return dict.getName();

        }

    }else{

        //2自定义数据查询

        //2.1根据parentDictCode 查询父级别数据

        Dict parentDict = this.getByDictCode(parentDictCode);

        LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(Dict::getParentId,parentDict.getId());

        wrapper.eq(Dict::getValue,value);

        Dict dict = baseMapper.selectOne(wrapper);

        if(dict!=null){

            return dict.getName();

        }

    }

    return "";

  }

  

  //根据dictCode查询字典数据

  private Dict getByDictCode(String dictCode) {

    LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();

    wrapper.eq(Dict::getDictCode,dictCode);

    Dict dict = baseMapper.selectOne(wrapper);

    return dict;

  }

5)测试

4、封装Feign服务调用

1)搭建方案

2搭建service_client父模块

  1. 删除src
  2. 修改pom,引入通用依赖

<dependencies>

    <dependency>

        <groupId>com.atguigu</groupId>

        <artifactId>common_utils</artifactId>

        <version>0.0.1-SNAPSHOT</version>

    </dependency>

  

    <dependency>

        <groupId>com.atguigu</groupId>

        <artifactId>model</artifactId>

        <version>0.0.1-SNAPSHOT</version>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

        <scope>provided </scope>

    </dependency>

    <!-- 服务调用feign -->

    <dependency>

        <groupId>org.springframework.cloud</groupId>

        <artifactId>spring-cloud-starter-openfeign</artifactId>

        <scope>provided </scope>

    </dependency>

  </dependencies>

5)搭建service_cmn_client模块

6)创建目录、创建接口

创建目录:com.atguigu.yygh.cmn.client

@FeignClient("service-cmn")

  public interface DictFeignClient {

  

    //获取数据字典名称(自定义)

    @GetMapping(value = "/admin/cmn/dict/getName/{parentDictCode}/{value}")

    public String getName(

            @PathVariable("parentDictCode") String parentDictCode,

            @PathVariable("value") String value);

  

    //获取数据字典名称(国标)

    @GetMapping(value = "/admin/cmn/dict/getName/{value}")

    public String getName(

            @PathVariable("value") String value);

  

  }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/798512.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

leetcode-707.设计链表

leetcode-707.设计链表 文章目录 leetcode-707.设计链表一.题目描述二.代码随想录三.易错点 一.题目描述 二.代码随想录 代码 class MyLinkedList {public:// 定义链表节点结构体struct ListNode {int val;ListNode *next;ListNode(int val) : val(val), next(nullptr) {}};//…

Apipost变量高亮展示,变量操作更流畅

之前Apipost配置的各种环境变量只能在右上角环境管理中查看&#xff0c;很多小伙伴希望能有一种更好的解决方案用以快速复制变量值&#xff0c;快速查看变量的当前值和初始值&#xff0c;于是在Apipost 7.1.7中我们推出环境变量高亮展示功能来满足用户的使用需求。 功能描述&a…

机器学习之Boosting和AdaBoost

1 Boosting和AdaBoost介绍 1.1 集成学习 集成学习 (Ensemble Learning) 算法的基本思想就是将多个分类器组合&#xff0c;从而实现一个预测效果更好的集成分类器。 集成学习通过建立几个模型来解决单一预测问题。它的工作原理是生成多个分类器/模型&#xff0c;各自独立地学…

PDA开发:MAUI调用Jar包,so文件

PDA系统&#xff1a;android 6.0 PDA功能&#xff1a;扫码打印一体机&#xff0c;扫物料标签&#xff0c;调用金蝶云星空ERP实现收发料&#xff0c;PDA打印功能主要是同一个料号物品只贴一个标签&#xff0c;打印功能是为了复制物料标签&#xff0c;下次再发料使用 打印SDK只…

中国农业大学计算机考研分析

关注我们的微信公众号 姚哥计算机考研 更多详情欢迎咨询 中国农业大学&#xff08;B-&#xff09;考研难度&#xff08;☆☆☆&#xff09; 中国农业大学计算机考研招生学院是信息与电气工程学院。目前均已出拟录取名单。 中国农业大学信息与电气工程学院&#xff0c;起源于…

ST官方基于米尔STM32MP135开发板培训课程(一)

本文将以Myirtech的MYD-YF13X以及STM32MP135F-DK为例&#xff0c;讲解如何使用STM32CubeMX结合Developer package实现最小系统启动。 1.开发准备 1.1 Developer package准备 a.Developer package下载&#xff1a; ‍https://www.st.com/en/embedded-software/stm32mp1dev.ht…

手把手移植 simpleFOC (三):编码器篇

文章目录 前言 一、延时函数 二、修改encoder外中断接口 1.中断调用接口 2.嫁接回调函数 3、新增digitalRead函数 三、添加编译项 四、编译&#xff0c;调试 总结 前言 今天移植的主要内容是simpleFoc的encoder&#xff0c;目标是转到电机&#xff0c;读出对应的角度及角度率。…

Labview串口通信VISA实现串口收发

文章目录 前言一、什么是 VISA二、VISA 驱动下载及安装1、下载2、安装 三、VISA 实现串口收发1、打开虚拟串口2、前面板运行效果3、程序框图 前言 前面使用过调用 MSComm 控件的方式&#xff08;Labview串口通信MSComm实现串口收发&#xff09;&#xff0c;即利用 Windows 提供…

尚医通07:MongoDB+医院需求介绍

内容介绍 1、客户端工具 2、MongoDB常用操作 3、springboot集成MongoDB&#xff08;mongoTemplate&#xff09; 4、springboot集成MongoDB&#xff08;MongoRepository&#xff09; 5、医院需求介绍 6、部署医院模拟系统 7、开发平台接口-上传医院接口 客户端工具 1、…

【用IDEA基于Scala2.12.18开发Spark 3.4.1 项目】

目录 使用IDEA创建Spark项目设置sbt依赖创建Spark 项目结构新建Scala代码 使用IDEA创建Spark项目 打开IDEA后选址新建项目 选址sbt选项 配置JDK debug 解决方案 相关的依赖下载出问题多的话&#xff0c;可以关闭idea&#xff0c;重启再等等即可。 设置sbt依赖 将sbt…

Linux6.2 ansible 自动化运维工具(机器管理工具)

文章目录 计算机系统5G云计算第一章 LINUX ansible 自动化运维工具&#xff08;机器管理工具&#xff09;一、概述二、ansible 环境安装部署三、ansible 命令行模块1.command 模块2.shell 模块3.cron 模块4.user 模块5.group 模块6.copy 模块7.file 模块8.hostname 模块9.ping …

【Python入门系列】第十九篇:Python基于协同过滤推荐系统的实现

文章目录 前言一、协同过滤算法简介二、计算相似度三、Python实现简单的协同过滤推荐系统总结 前言 推荐系统是现代互联网平台中的重要组成部分&#xff0c;它可以根据用户的兴趣和行为&#xff0c;向其推荐个性化的内容。协同过滤是推荐系统中常用的一种方法&#xff0c;它基…

POI信息点的diPointX、diPointY转化成经纬度

需求&#xff1a;接口返回某个地点的数据&#xff08;diPointX、diPointY&#xff09;&#xff0c;前端需把该地点转化成经纬度形式在地图上进行Marker标记。 实现&#xff1a;&#xff08;查找百度地图开发文档&#xff09; 代码验证&#xff1a; console.log(new BMap.Merca…

性能测试问题之慢sql分析

我们在做性能测试的时候&#xff0c;慢sql也可以说是很常见问题&#xff0c;我的性能测试生涯几乎经常遇到慢sql&#xff0c;那么我们怎么来判断有没有慢sql呢&#xff0c;有慢sql后怎么来分析优化呢?如图&#xff1a; 通过上图看可以看到当存在慢sql的时候&#xff0c;这里会…

火爆全网,接口自动化测试-DDT数据驱动实战总结,一篇贯通...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 DDT&#xff08;D…

信息安全:网络安全体系 与 网络安全模型.

信息安全&#xff1a;网络安全体系 与 网络安全模型. 网络安全保障是一项复杂的系统工程&#xff0c;是安全策略、多种技术、管理方法和人员安全素质的综合。一般而言&#xff0c;网络安全体系是网络安全保障系统的最高层概念抽象&#xff0c;是由各种网络安全单元按照一定的规…

python更换iterm2背景图片

背景 在看知乎的时候&#xff0c;突然看到了这样的一个视频教程&#xff0c;用python代码更换iterm2的背景。于是我细细的研究一下。视频地址 视频中提到的参考文章地址&#xff1a; iterm2官网官方仓库 实现过程 我直接把作者的代码粘贴如下&#xff0c;首先需要安装iter…

pycharm 使用远程服务器 jupyter (本地jupyter同理)

1. 远程服务器miniconda 环境中创建jupyter环境 # 1. 激活环境 conda activate envname#2. 在环境中安装jupyter pip install jupyter # 或者 conda install jupyter#3. 生成jupyter_notebook_config.py文件 jupyter notebook --generate-config#4. 设置密码 jupyter noteboo…

docker—springboot服务通信

文章目录 docker—springboot服务通信一、方式1、host 二、坑点末、参考资料 docker—springboot服务通信 一、方式 1、host 步骤&#xff1a; host文件增加域名解析&#xff1a; 127.0.0.1 rabbitmqapplication.yml&#xff1a; application.yml中&#xff0c;连接方式使用…

【HarmonyOS】API6使用storage实现轻量级数据存储

写在前面 本篇内容基于API6 JS语言进行开发&#xff0c;通过结合轻量级数据存储开发指导的文档&#xff0c;帮助大家完成一个实际的代码案例&#xff0c;通过这个小案例&#xff0c;可以实现简单数据的存储。 参考文档&#xff1a;文档中心 1、页面布局 首先我们编写一个简单…