Back-end-hospital query interface

Back-end-hospital query interface

1. Add a control layer interface

Insert picture description here
//查询医院信息
    @PostMapping("/hospital/show")
    public Result getHospital(HttpServletRequest request){
        //获取传递过来的医院信息
        Map<String, String[]> requestMap = request.getParameterMap();
        //将Map<String, String[]> 形式转换成Map<String, Object>方便后续使用
        Map<String, Object>  paramMap = HttpRequestHelper.switchMap(requestMap);

        //获取医院的编号
        String hoscode = (String)paramMap.get("hoscode");

        //1、获取医院端传递过来的签名,签名进行MD5加密
        String hospSign = (String)paramMap.get("sign");

        //2、根据传递过来的医院编码,查询数据库,查询签名
        String signKey = hospitalSetService.getSignKey(hoscode);

        //3、把数据库查询的签名进行加密
        String signKeyMD5 = MD5.encrypt(signKey);

        //4、判断签名是否一致
        if(!hospSign.equals(signKeyMD5)){
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }
        //调用service方法根据医院编号查询
        Hospital hospital = hospitalService.getByHoscode(hoscode);
        return Result.ok(hospital);
    }

2. Business layer interface

Insert picture description here
//根据医院编号查询医院信息
Hospital getByHoscode(String hoscode);

3. Business layer implementation class

Insert picture description here
//根据医院编号查询医院信息
  @Override
  public Hospital getByHoscode(String hoscode) {
      Hospital hospital = hospitalRepository.getHospitalByHoscode(hoscode);
      return hospital;
  }

4. Write methods in HospitalRepository to query data from mongoDB

Insert picture description here
@Repository
public interface HospitalRepository extends MongoRepository<Hospital,String> {
/*   1、Spring Data提供了对mongodb数据访问的支持,我们只需要继承MongoRepository类,
    按照Spring Data规范就可以了。
    2、也就是说我们继承MongoRepository类后,再按照Spring Data规范编写方法,就可以实现对数据的增删改查操作。
    而不用再编写执行sql了*/
    Hospital getHospitalByHoscode(String hoscode);
}