Back-end-department information management interface

Backend-upload department interface

Refer to "API Interface Document.docx" Business Interface 4.2 to upload department

1. Add the basic department of the department

1.1, add model

Insert picture description here
@Data
@ApiModel(description = "Department")
@Document("Department")
public class Department extends BaseMongoEntity {
	
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "医院编号")
	@Indexed //普通索引
	private String hoscode;

	@ApiModelProperty(value = "科室编号")
	@Indexed(unique = true) //唯一索引
	private String depcode;

	@ApiModelProperty(value = "科室名称")
	private String depname;

	@ApiModelProperty(value = "科室描述")
	private String intro;

	@ApiModelProperty(value = "大科室编号")
	private String bigcode;

	@ApiModelProperty(value = "大科室名称")
	private String bigname;

}

1.2, add repository

Insert picture description here
@Repository
public interface DepartmentRepository extends MongoRepository<Department,String> {
}

1.3, create service

Interface:

Insert picture description here


business layer implementation class:

Insert picture description here

1.4, create a control layer

Insert picture description here

2. Upload department information

2.1, development requirements document

2.1.1. Submit address (path)

http://localhost/api/hosp/saveDepartment

2.1.2, request parameters

◎ 变量定义
Insert picture description here

2.1.3, synchronous return

Result parameter meaning

Insert picture description here

2.1.4, department information description

Insert picture description here


Note: There can be multiple small departments under a large department, as shown in the figure:

Insert picture description here

2.2, add control layer method

Insert picture description here
 //添加科室信息
@PostMapping("saveDepartment")
public Result saveDepartment(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、把数据库查询的签名进行加密
    String signKeyMD5 = MD5.encrypt(signKey);

    //4、判断签名是否一致
    if(!hospSign.equals(signKeyMD5)){
        throw new YyghException(ResultCodeEnum.SIGN_ERROR);
    }

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

2.3, add business layer method

Interface:

Insert picture description here


Implementation class:

Insert picture description here
 //添加科室信息
@Override
public void save(Map<String, Object> paramMap) {
    //将Map<String, Object>形式转换成Department对象
    String StringParamMap = JSONObject.toJSONString(paramMap);
    Department department = JSONObject.parseObject(StringParamMap, Department.class);

    Department departmentExist = departmentRepository.
            getDepartmentByHoscodeAndDepcode(department.getHoscode(),department.getDepcode());

    //判断departmentExist
    if(departmentExist != null){
        //修改操作
        departmentExist.setUpdateTime(new Date());
        departmentExist.setIsDeleted(0);
        departmentRepository.save(departmentExist);
    }else{
        //添加操作
        department.setCreateTime(new Date());
        department.setUpdateTime(new Date());
        department.setIsDeleted(0);
        departmentRepository.save(department);
    }
}

2.4, DepartmentRepository

Operate mongoDB to save data

Insert picture description here
@Repository
public interface DepartmentRepository extends MongoRepository<Department,String> {

    Department getDepartmentByHoscodeAndDepcode(String hoscode, String depcode);
}

3. Query the department information list interface

3.1, development requirements document

3.1.1. Submit address

http://localhost/api/hosp/department/list

3.1.2. Request parameters

◎ 变量定义
Insert picture description here

3.1.3, synchronous return

Insert picture description here

3.2. Create a control method

Insert picture description here
//查询科室信息
 @PostMapping("/department/list")
 public Result findDepartment(HttpServletRequest request){
     //获取传递过来的科室信息
     Map<String, String[]> resultMap = request.getParameterMap();
     Map<String, Object> paramMap = HttpRequestHelper.switchMap(resultMap);
     //获取医院编号
     String hoscode = (String)paramMap.get("hoscode");

     //获取当前页
     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"));

     //签名校验
     //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);
     }

     DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();
     departmentQueryVo.setHoscode(hoscode);
     //调用业务层方法查询数据
     Page<Department> pageModel = departmentService.finPageDepartment(page,limit,departmentQueryVo);
     return Result.ok(pageModel);
 }

3.3, write business layer method

interface:

Insert picture description here
//查询科室信息
Page<Department> finPageDepartment(Integer page,Integer limit,DepartmentQueryVo departmentQueryVo);

Business layer implementation class:

Insert picture description here
//查询科室信息
@Override
public Page<Department> finPageDepartment(Integer page,Integer limit,DepartmentQueryVo departmentQueryVo) {
    //分页设置,当前页和每页记录大小
    Pageable pageable = PageRequest.of(page-1,limit);

    //将传递过来的departmentQueryVo转换成department对象
    Department department = new Department();
    BeanUtils.copyProperties(departmentQueryVo,department);

    //设置查询规则
    ExampleMatcher matcher = ExampleMatcher.matching()
            .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
            .withIgnoreCase(true);//查询时忽略大小写
    Example<Department> example = Example.of(department,matcher);

    //查询出来分页带条件查询的数据
    Page<Department> all = departmentRepository.findAll(example, pageable);
    return all;
}

4. Delete department information interface

4.1. Development requirements

4.1.1. Submit address

http://localhost/api/hosp/department/remove

4.1.2, request parameters

◎ 变量定义
Insert picture description here

4.1.3, synchronous return

Insert picture description here

4.2, add control layer method

Insert picture description here
//删除科室信息
@PostMapping("/department/remove")
public Result deleteDepartment(HttpServletRequest request){
    //获取传递过来的科室信息
    Map<String, String[]> resultMap = request.getParameterMap();
    Map<String, Object> paramMap = HttpRequestHelper.switchMap(resultMap);
    //获取医院编号和科室编号
    String hoscode = (String)paramMap.get("hoscode");
    String depcode = (String)paramMap.get("depcode");

    //获取医院传递过来的签名
    String hospSign = (String) paramMap.get("sign");
    //从数据库中查询出平台中存放的医院签名
    String signKey = hospitalSetService.getSignKey(hoscode);
    String signKeyMD5 = MD5.encrypt(signKey);

    if(!signKeyMD5.equals(hospSign)){
        throw new YyghException(ResultCodeEnum.SIGN_ERROR);
    }
    //调用业务层方法删除科室信息
    departmentService.remove(hoscode,depcode);
    return Result.ok();
}

4.3, business layer method

interface:

Insert picture description here
//删除科室信息
 void remove(String hoscode, String depcode);

Implementation class:

Insert picture description here
//删除科室信息
@Override
public void remove(String hoscode, String depcode) {
    //根据医院编号和科室编号查询数据
    Department department = departmentRepository.getDepartmentByHoscodeAndDepcode(hoscode,depcode);

    //如果数据库中有要删除的科室信息,
    if(department != null){
        //执行删除操作
        departmentRepository.deleteById(depcode);
    }
}

4.4, the persistence layer

Query department information in mongodb according to the hospital id and department ie

Insert picture description here