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

目录

内容介绍

开发平台接口-查询医院

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

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

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

上传排班和查询排班接口

医院列表功能(接口)


内容介绍

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

尚硅谷8:开发平台接口,SpringCloud,上传排班_第1张图片

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、测试

尚硅谷8:开发平台接口,SpringCloud,上传排班_第2张图片

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

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)确认实体

尚硅谷8:开发平台接口,SpringCloud,上传排班_第3张图片

2)创建相关接口、类

尚硅谷8:开发平台接口,SpringCloud,上传排班_第4张图片

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)测试数据

尚硅谷8:开发平台接口,SpringCloud,上传排班_第5张图片

2)测试步骤

尚硅谷8:开发平台接口,SpringCloud,上传排班_第6张图片

尚硅谷8:开发平台接口,SpringCloud,上传排班_第7张图片

医院列表功能(接口)

1、分析接口

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

*确认vo对象

尚硅谷8:开发平台接口,SpringCloud,上传排班_第8张图片

2)返回值:RPage

2、初步创建查询接口

1)创建controller

尚硅谷8:开发平台接口,SpringCloud,上传排班_第9张图片

@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)测试

尚硅谷8:开发平台接口,SpringCloud,上传排班_第10张图片

尚硅谷8:开发平台接口,SpringCloud,上传排班_第11张图片

4、封装Feign服务调用

1)搭建方案

尚硅谷8:开发平台接口,SpringCloud,上传排班_第12张图片

2搭建service_client父模块

尚硅谷8:开发平台接口,SpringCloud,上传排班_第13张图片

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

尚硅谷8:开发平台接口,SpringCloud,上传排班_第14张图片

<dependencies>

    <dependency>

        <groupId>com.atguigugroupId>

        <artifactId>common_utilsartifactId>

        <version>0.0.1-SNAPSHOTversion>

    dependency>

  

    <dependency>

        <groupId>com.atguigugroupId>

        <artifactId>modelartifactId>

        <version>0.0.1-SNAPSHOTversion>

    dependency>

    <dependency>

        <groupId>org.springframework.bootgroupId>

        <artifactId>spring-boot-starter-webartifactId>

        <scope>provided scope>

    dependency>

    

    <dependency>

        <groupId>org.springframework.cloudgroupId>

        <artifactId>spring-cloud-starter-openfeignartifactId>

        <scope>provided scope>

    dependency>

  dependencies>

5)搭建service_cmn_client模块

尚硅谷8:开发平台接口,SpringCloud,上传排班_第15张图片

6)创建目录、创建接口

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

尚硅谷8:开发平台接口,SpringCloud,上传排班_第16张图片

@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);

  

  }

你可能感兴趣的:(项目,java,开发语言)