hospital_manager(service_hosp接口)

贺高杰
2023-12-01

医院上传接口

hospital_manager系统用于医院端接口模拟,配合尚医通完成接口调试。
要写的接口还是在service_hosp里,每个医院有自己的页面,所有的医院统一调用service_hosp里的接口来实现上传等功能,统一。

数据库(涉及两个数据库,三个表)

hospital_manager的数据库是mysql的yygh_manager,里面事先存了这个医院自己的信息。这里面的hospital_set指的是这一个医院。
医院自己页面的“医院管理“导航显示的是Hospital这个类的信息,是存在mongoDB里的,通过service_hosp的HospitalServiceImpl加进去的。
而在存Hospital类的过程中需要对比签名,就需要从service_hosp的数据库yygh_hosp(mysql)的hospital_set找出对应的sign_key,与yygh_manager里的hospital_set进行对比,是通过service_hosp的HospitalSetServiceImpl实现的。

医院

实体类

Hospital
(注意实体类里的bookingRule属性,是之后预约挂号功能用到的)

controller

医院自己把接口地址封装到request里(hospital_magager的ApiServiceImpl方法)

JSONObject respone =
                HttpRequestHelper.sendRequest(paramMap,this.getApiUrl()+"/api/hosp/saveHospital");

service_hosp里的ApiController实现这个接口

//上传医院接口
    @PostMapping("saveHospital")
    //要得到那边post传过来的医院的信息,把信息加到数据库,所以参数要用HttpServletRequest
    public Result saveHosp(HttpServletRequest request) {
        //获取传递过来医院信息
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

        /*
        写在private方法里了
        //1 获取医院系统传递过来的签名,这里的签名已经进行MD5加密
        String hospSign = (String)paramMap.get("sign");

        //2 根据传递过来医院编码,查询mysql数据库hospital_set里的签名,要注入hospitalSetService
        String hoscode = (String)paramMap.get("hoscode");
        String signKey = hospitalSetService.getSignKey(hoscode);

        //3 把数据库查询出来签名进行MD5加密,再与获取的签名进行比对
        String signKeyMd5 = MD5.encrypt(signKey);
        */
        //4 判断签名是否一致
        if(!signVerify(paramMap)) {
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }

        //传输过程中“+”转换为了“ ”,因此我们要转换回来
        String logoData = (String)paramMap.get("logoData");
        logoData = logoData.replaceAll(" ","+");
        paramMap.put("logoData",logoData);

        //调用service的方法
        hospitalService.save(paramMap);
        return Result.ok();
    }

不需要

不需要

医院自己把接口地址封装到request里(hospital_magager的ApiServiceImpl方法)

JSONObject respone = HttpRequestHelper.sendRequest(paramMap,this.getApiUrl()+"/api/hosp/hospital/show");

service_hosp里的ApiController实现这个接口

//查询医院
    @PostMapping("hospital/show")
    public Result getHospital(HttpServletRequest request) {
        //获取传递过来医院信息
        Map<String, String[]> requestMap = request.getParameterMap();
        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 把数据库查询签名进行MD5加密
        String signKeyMd5 = MD5.encrypt(signKey);*/

        //4 判断签名是否一致
        if(!signVerify(paramMap)) {
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }

        String hoscode = (String)paramMap.get("hoscode");
        //调用service方法实现根据医院编号查询
        Hospital hospital = hospitalService.getByHoscode(hoscode);
        return Result.ok(hospital);
    }

service

public void save(Map<String, Object> paramMap) {
        //把参数map集合转换对象 Hospital,用json转换工具
        String mapString = JSONObject.toJSONString(paramMap);
        Hospital hospital = JSONObject.parseObject(mapString, Hospital.class);

        //判断是否存在数据,即查询
        String hoscode = hospital.getHoscode();
        Hospital hospitalExist = hospitalRepository.getHospitalByHoscode(hoscode);

        //如果存在,进行修改
        if(hospitalExist != null) {
            hospital.setStatus(hospitalExist.getStatus());
            hospital.setCreateTime(hospitalExist.getCreateTime());
            hospital.setUpdateTime(new Date());
            hospital.setIsDeleted(0);
            hospitalRepository.save(hospital);
        } else {//如果不存在,进行添加
            hospital.setStatus(0);
            hospital.setCreateTime(new Date());
            hospital.setUpdateTime(new Date());
            hospital.setIsDeleted(0);
            hospitalRepository.save(hospital);
        }
    }

不需要

不需要

public Hospital getByHoscode(String hoscode) {
        /*Hospital hospital = hospitalRepository.getHospitalByHoscode(hoscode);
        return hospital;*/
        Hospital hospitalByHoscode = hospitalRepository.getHospitalByHoscode(hoscode);
        return hospitalByHoscode;
    }

部门

实体类

Department

controller

医院自己把接口地址封装到request里(hospital_magager的ApiServiceImpl方法)

JSONObject respone = HttpRequestHelper.sendRequest(paramMap,this.getApiUrl()+"/api/hosp/saveDepartment");

service_hosp里的ApiController实现这个接口

 //上传科室接口
    @PostMapping("saveDepartment")
    public Result saveDepartment(HttpServletRequest request) {
        //获取request中的所有参数对应的map,把String[]转换为Object类型,方便后面获取value值
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

        //签名校验
        /*String signParam = (String)paramMap.get("sign");
        String hoscode = (String)paramMap.get("hoscode");
        //根据参数的hoscode查询set中的sign,再加密
        String signKey = hospitalSetService.getSignKey(hoscode);
        String signHospSet = MD5.encrypt(signKey);*/
        if(!signVerify(paramMap)){
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }

        departmentService.save(paramMap);
        return Result.ok();
}

 //删除科室接口
    @PostMapping("department/remove")
    public Result removeDepartment(HttpServletRequest request) {
        //获取传递过来科室信息
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
        //医院编号 和 科室编号
        String hoscode = (String)paramMap.get("hoscode");
        String depcode = (String)paramMap.get("depcode");
        //TODO 签名校验
        departmentService.remove(hoscode,depcode);
        return Result.ok();
    }

不需要

医院自己把接口地址封装到request里(hospital_magager的ApiServiceImpl方法)

JSONObject respone = HttpRequestHelper.sendRequest(paramMap,this.getApiUrl()+"/api/hosp/department/list");

service_hosp里的ApiController实现这个接口

//查询科室接口
    @PostMapping("department/list")
    public Result findDepartment(HttpServletRequest request) {
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
        String hoscode = (String)paramMap.get("hoscode");
        //判断是否为空,为空就给个默认值1
        int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page"));
        int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1 : Integer.parseInt((String)paramMap.get("limit"));
        DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();
        departmentQueryVo.setHoscode(hoscode);
        Page<Department> pageDept = departmentService.findPageDepartment(page,limit,departmentQueryVo);
        return Result.ok(pageDept);
    }

service

//上传科室接口
    @Override
    public void save(Map<String, Object> paramMap) {
        //把map转换成department对象,因为对象中有属性,就和map中的每个键值对对应上了
        String s = JSONObject.toJSONString(paramMap);
        Department department = JSONObject.parseObject(s, Department.class);
        //先要查询下你上传的这个对象是否已经存在,存在就修改即可
        //来到service要调用repository了
        Department departmentExist = departmentRepository.getDepartmentByHoscodeAndDepcode(department.getHoscode(), department.getDepcode());
        if(departmentExist != null){
            departmentExist.setUpdateTime(new Date());
            departmentExist.setIsDeleted(0);
            //最后还是要用repository来保存的啦
            departmentRepository.save(departmentExist);
        }else {//注意这里,departmentExist等于null就没法存了啊,要存你上传的department
            department.setCreateTime(new Date());
            department.setUpdateTime(new Date());
            department.setIsDeleted(0);
            departmentRepository.save(department);
        }

//删除科室接口
    @Override
    public void remove(String hoscode, String depcode) {
        //根据医院编号 和 科室编号查询
        Department department = departmentRepository.getDepartmentByHoscodeAndDepcode(hoscode, depcode);
        if(department != null) {
            //调用方法删除
            departmentRepository.deleteById(department.getId());
        }
    }

不需要

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

        //PageRequest里的0代表第一页,而我们传入的第一页是1,所以要减1
        Pageable pageable = PageRequest.of(page-1, limit);

        ExampleMatcher matching = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
                .withIgnoreCase(true);
        //把departmentQueryVo拷贝到department
        Department department = new Department();
        BeanUtils.copyProperties(departmentQueryVo,department);
        Example<Department> example = Example.of(department, matching);
        Page<Department> all = departmentRepository.findAll(example, pageable);
        return all;

排班

实体类

Schedule

controller

//上传排班接口
    @PostMapping("saveSchedule")
    public Result saveSchedule(HttpServletRequest request) {
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
        if(!signVerify(paramMap)){
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }
        scheduleService.save(paramMap);
        return Result.ok();


        /*//获取传递过来科室信息
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

        //TODO 签名校验
        scheduleService.save(paramMap);
        return Result.ok();*/
    }

//删除排班
    @PostMapping("schedule/remove")
    public Result remove(HttpServletRequest request) {
        //获取传递过来科室信息
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

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

        if(!signVerify(paramMap)){
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }

        scheduleService.remove(hoscode,hosScheduleId);
        return Result.ok();

不需要

//查询排班接口
    @PostMapping("schedule/list")
    public Result findSchedule(HttpServletRequest request) {
        //获取传递过来科室信息
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

        String hoscode = (String)paramMap.get("hoscode");
        String depcode = (String)paramMap.get("depcode");
        ScheduleQueryVo scheduleQueryVo = new ScheduleQueryVo();
        scheduleQueryVo.setHoscode(hoscode);
        scheduleQueryVo.setDepcode(depcode);

        //得到的page和limit是string
        int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page"));
        int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1 : Integer.parseInt((String)paramMap.get("limit"));

        Page<Schedule> pageModel = scheduleService.findPageSchedule(page,limit,scheduleQueryVo);
        return Result.ok(pageModel);

service

 //上传排班接口
    @Override
    public void save(Map<String, Object> paramMap) {
        String s = JSONObject.toJSONString(paramMap);
        Schedule schedule = JSONObject.parseObject(s, Schedule.class);
        //先看存在不
        Schedule scheduleExist = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(),schedule.getHosScheduleId());
        if(scheduleExist != null){
            scheduleExist.setUpdateTime(new Date());
            scheduleExist.setIsDeleted(0);
            scheduleExist.setStatus(1);
            scheduleRepository.save(scheduleExist);
        }else {
            schedule.setCreateTime(new Date());
            schedule.setUpdateTime(new Date());
            schedule.setIsDeleted(0);
            schedule.setStatus(1);
            scheduleRepository.save(schedule);
        }

    //删除排班
    @Override
    public void remove(String hoscode, String hosScheduleId) {
        Schedule schedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(hoscode, hosScheduleId);
        if(schedule!= null){
            scheduleRepository.deleteById(schedule.getId());
        }

//查询排班接口
    @Override
    public Page<Schedule> findPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo) {

        Schedule schedule = new Schedule();
        BeanUtils.copyProperties(scheduleQueryVo,schedule);
        schedule.setStatus(1);
        schedule.setIsDeleted(0);
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
                .withIgnoreCase(true);
        Example<Schedule> example = Example.of(schedule, matcher);

        Pageable pageable = PageRequest.of(page - 1, limit);
        Page<Schedule> all = scheduleRepository.findAll(example, pageable);
        return all;
 类似资料: