• 尚医通 (二十六) --------- 科室接口开发



    一、上传科室接口

    1. 添加科室基础类

    A、添加 model

    说明:由于实体对象没有逻辑,我们已经统一导入
    com.fancy.yygh.model.hosp.Department

    B、添加 repository

    添加 com.fancy.yygh.hosp.repository.DepartmentRepository

    package com.fancy.yygh.hosp.repository;
    
    
    @Repository
    public interface DepartmentRepository extends MongoRepository<Department,String> {
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    C、添加 service 接口及实现类

    添加 com.fancy.yygh.hosp.service.DepartmentService 接口

    package com.fancy.yygh.hosp.service;
    
    
    public interface DepartmentService {
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    添加com.fancy.yygh.hosp.service.impl.DepartmentServiceImpl 接口实现

    package com.fancy.yygh.hosp.service.impl;
    
    @Service
    @Slf4j
    public class DepartmentServiceImpl implements DepartmentService {
    	@Autowired
    	private DepartmentRepository departmentRepository;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2. 上传科室

    A、上传科室

    医院编号是平台分配的,全局唯一,科室编号为医院自己的编号,相对医院唯一,上传科室接口可以多次调用,如果医院编号与科室编号组合唯一为更新操作

    B、接口数据分析

    {
    	"hoscode": "1000_0",
    	"depcode": "200050923",
    	"depname": "门诊部核酸检测门诊(东院)",
    	"intro": "门诊部核酸检测门诊(东院)",
    	"bigcode": "44f162029abb45f9ff0a5f743da0650d",
    	"bigname": "体检科"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    说明:一个大科室下可以有多个小科室,如图:
    在这里插入图片描述

    C、添加 service 接口

    在 DepartmentService 类添加接口

    /**
     * 上传科室信息
     * @param paramMap
    */
    void save(Map<String, Object> paramMap);
    
    • 1
    • 2
    • 3
    • 4
    • 5

    说明:参数使用 Map,减少对象封装,有利于签名校验,后续会体验到

    在 DepartmentServiceImpl 类添加实现

    @Override
    public void save(Map<String, Object> paramMap) {
    	Department department = JSONObject.parseObject(JSONObject.toJSONString(paramMap), Department.class);
    	Department targetDepartment = departmentRepository.getDepartmentByHoscodeAndDepcode(department.getHoscode(), department.getDepcode());
    	if(null != targetDepartment) {
    		//copy不为null的值,该方法为自定义方法
    		BeanUtils.copyBean(department, targetDepartment, Department.class);
    		departmentRepository.save(targetDepartment);
    	} else {
    		department.setCreateTime(new Date());
    		department.setUpdateTime(new Date());
    		department.setIsDeleted(0);
    		departmentRepository.save(department);
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    D、添加 repository 接口

    在DepartmentRepository添加方法

    Department getDepartmentByHoscodeAndDepcode(String hoscode, String depcode);
    
    • 1

    E、添加 controller 接口

    在 ApiController 类添加接口

    @Autowired
    private DepartmentService departmentService;
    
    @ApiOperation(value = "上传科室")
    @PostMapping("saveDepartment")
    public Result saveDepartment(HttpServletRequest request) {
    	Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
    	//必须参数校验 略
    	String hoscode = (String)paramMap.get("hoscode");
    	if(StringUtils.isEmpty(hoscode)) {
    		throw new YyghException(ResultCodeEnum.PARAM_ERROR);
    	}
    	//签名校验
    	if(!HttpRequestHelper.isSignEquals(paramMap, hospitalSetService.getSignKey(hoscode))) {
    		throw new YyghException(ResultCodeEnum.SIGN_ERROR);
    	}
    	
    	departmentService.save(paramMap);
    	return Result.ok();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    二、查询科室接口

    一个医院有多个科室,因此我们采取分页查询方式

    A、添加 service 接口

    在 DepartmentService 类添加接口

    /**
     * 分页查询
     * @param page 当前页码
     * @param limit 每页记录数
     * @param departmentQueryVo 查询条件
     * @return
    */
    Page<Department> selectPage(Integer page, Integer limit, DepartmentQueryVo departmentQueryVo);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在 DepartmentServiceImpl 类添加实现

    @Override
    public Page<Department> selectPage(Integer page, Integer limit, DepartmentQueryVo departmentQueryVo) {
    	Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
    	//0为第一页
    	Pageable pageable = PageRequest.of(page-1, limit, sort);
    
    	Department department = new Department();
    	BeanUtils.copyProperties(departmentQueryVo, department);
    	department.setIsDeleted(0);
    
    	//创建匹配器,即如何使用查询条件
    	ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
    		.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式:模糊查询
    		.withIgnoreCase(true); //改变默认大小写忽略方式:忽略大小写
    
    	//创建实例
    	Example<Department> example = Example.of(department, matcher);
    	Page<Department> pages = departmentRepository.findAll(example, pageable);
    	return pages;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    B、添加 controller 接口

    在 ApiController 类添加接口

    @ApiOperation(value = "获取分页列表")
    @PostMapping("department/list")
    public Result department(HttpServletRequest request) {
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
    	
    	//必须参数校验 略
    	String hoscode = (String)paramMap.get("hoscode");
    	
    	//非必填
    	String depcode = (String)paramMap.get("depcode");
    	int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page"));
    	int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 10 : Integer.parseInt((String)paramMap.get("limit"));
    
    	if(StringUtils.isEmpty(hoscode)) {
    		throw new YyghException(ResultCodeEnum.PARAM_ERROR);
        }
    	//签名校验
    	if(!HttpRequestHelper.isSignEquals(paramMap, hospitalSetService.getSignKey(hoscode))) {
    		throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }
    
    	DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();
    	departmentQueryVo.setHoscode(hoscode);
    	departmentQueryVo.setDepcode(depcode);
    	Page<Department> pageModel = departmentService.selectPage(page, limit, departmentQueryVo);
    	return Result.ok(pageModel);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    三、删除科室接口

    根据医院编号与科室编号删除科室

    A、添加 service 接口

    在 DepartmentService 类添加接口

    /**
     * 删除科室
     * @param hoscode
    * @param depcode
    */
    void remove(String hoscode, String depcode);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在 DepartmentServiceImpl 类添加实现

    @Override
    public void remove(String hoscode, String depcode) {
    	Department department = departmentRepository.getDepartmentByHoscodeAndDepcode(hoscode, depcode);
    	if(null != department) {
    		//departmentRepository.delete(department);
    		departmentRepository.deleteById(department.getId());
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    B、添加 controller 接口

    在 ApiController 类添加接口

    @ApiOperation(value = "删除科室")
    @PostMapping("department/remove")
    public Result removeDepartment(HttpServletRequest request) {
    	Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
    	//必须参数校验 略
    	String hoscode = (String)paramMap.get("hoscode");
    	//必填
    	String depcode = (String)paramMap.get("depcode");
    	if(StringUtils.isEmpty(hoscode)) {
    		throw new YyghException(ResultCodeEnum.PARAM_ERROR);
    	}
    	//签名校验
    	if(!HttpRequestHelper.isSignEquals(paramMap, hospitalSetService.getSignKey(hoscode))) {
    		throw new YyghException(ResultCodeEnum.SIGN_ERROR);
    	}
    	
    	departmentService.remove(hoscode, depcode);
    	return Result.ok();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
  • 相关阅读:
    消息队列(中间件)
    解决navicat连接oracle19c数据库缺少oci.dll
    GitLab统计代码提交行数
    【BOOST C++ 8 输入输出流】(2)过滤器
    深圳市罗湖、龙岗、南山等7各区的研发补贴汇总
    骨传导耳机低频差理所当然?飞利浦A6606表示不服
    Linux--文件、进程、fork、open、系统调用、库函数相关知识
    Jupyter Notebook与Pycharm代码连接Docker容器中的远程服务器运行
    Iview Tree组件点击标题展开
    前端工作总结140-返回时间戳代码
  • 原文地址:https://blog.csdn.net/m0_51111980/article/details/127947652