目录:
(1)数据接口-查询和删除科室接口-功能实现
(2)数据接口-排版接口-功能实现
(1)数据接口-查询和删除科室接口-功能实现
查看医院系统中查询科室的对应的方法
查询条件需要用的类:
package com.atguigu.yygh.vo.hosp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(description = "Department")
public class DepartmentQueryVo {
@ApiModelProperty(value = "医院编号")
private String hoscode;
@ApiModelProperty(value = "科室编号")
private String depcode;
@ApiModelProperty(value = "科室名称")
private String depname;
@ApiModelProperty(value = "大科室编号")
private String bigcode;
@ApiModelProperty(value = "大科室名称")
private String bigname;
}
在ApiController中继续添加接口:
//查询科室的方法
@ApiOperation(value = "获取分页列表")
@PostMapping("department/list")
public Result department(HttpServletRequest request) {
//获取传递过来的科室的信息
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);
//医院的编号:
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"));
//签名校验
//1获取医院系统中传递过来的签名,这个签名做了MD5加密
String hospSign = (String) paramMap.get("sign");
//2根据传递过来的医院编号,查询数据库,查询签名
//调用hospitalSetService中的方法根据医院编码获取签名
String singKey = hospitalSetService.getSignKey(hoscode);
//3把数据库查询出来的签名进行MD5的加密
String signMd5 = MD5.encrypt(singKey);
//4判断签名是否一致
if (!hospSign.equals(signMd5)) {
throw new HospitalException(ResultCodeEnum.SIGN_ERROR);//抛出我们自定义的异常
}
DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();//查询条件实体
departmentQueryVo.setHoscode(hoscode);
departmentQueryVo.setDepcode(depcode);
//调用departmentService中的方法
Page<Department> pageModel = departmentService.findPageDepartment(page, limit, departmentQueryVo);
return Result.ok(pageModel);
}
DepartmentService 接口:
package com.atguigu.yygh.hosp.service;
import com.atguigu.yygh.model.hosp.Department;
import com.atguigu.yygh.vo.hosp.DepartmentQueryVo;
import org.springframework.data.domain.Page;
import java.util.Map;
public interface DepartmentService {
//上传科室的接口
void save(Map<String, Object> paramMap);
//查询科室的方法
Page<Department> findPageDepartment(int page, int limit, DepartmentQueryVo departmentQueryVo);
}
实现类:
//查询科室的接口方法
@Override
public Page<Department> findPageDepartment(int page, int limit, DepartmentQueryVo departmentQueryVo) {
//创建Pageable对象,设置当前页和每页记录数 0是第一页
Sort sort = Sort.by(Sort.Direction.DESC, "createTime");//排序
Pageable pageable = PageRequest.of(page-1, limit, sort);
//创建Exapmle对象
//设置模糊查询的匹配规则 ExampleMatcher.StringMatcher.CONTAINING模糊匹配 .withIgnoreCase(true)忽略大小写
ExampleMatcher matcher = ExampleMatcher.matching()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式:模糊查询
.withIgnoreCase(true); //改变默认大小写忽略方式:忽略大小写
Department department = new Department();
BeanUtils.copyProperties(departmentQueryVo, department);//使用工具类把departmentQueryVo转换成department
department.setIsDeleted(0);
Example<Department> example = Example.of(department, matcher);
Page<Department> pages = departmentRepository.findAll(example, pageable);
return pages;
}
删除医院的接口:查看医院系统的方法,看他传递得参数:
在ApiController:继续添加删除科室的方法
//删除科室的接口方法
@ApiOperation(value = "删除科室")
@PostMapping("department/remove")
public Result removeDepartment(HttpServletRequest request) {
//获取传递过来的科室的信息
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);
//获取医院编号
String hoscode = (String)paramMap.get("hoscode");
//获取科室编号
String depcode = (String)paramMap.get("depcode");
//签名校验
//1获取医院系统中传递过来的签名,这个签名做了MD5加密
String hospSign = (String) paramMap.get("sign");
//2根据传递过来的医院编号,查询数据库,查询签名
//调用hospitalSetService中的方法根据医院编码获取签名
String singKey = hospitalSetService.getSignKey(hoscode);
//3把数据库查询出来的签名进行MD5的加密
String signMd5 = MD5.encrypt(singKey);
//4判断签名是否一致
if (!hospSign.equals(signMd5)) {
throw new HospitalException(ResultCodeEnum.SIGN_ERROR);//抛出我们自定义的异常
}
//调用方法删除
departmentService.remove(hoscode, depcode);
return Result.ok();
}
DepartmentService :接口
package com.atguigu.yygh.hosp.service;
import com.atguigu.yygh.model.hosp.Department;
import com.atguigu.yygh.vo.hosp.DepartmentQueryVo;
import org.springframework.data.domain.Page;
import java.util.Map;
public interface DepartmentService {
//上传科室的接口
void save(Map<String, Object> paramMap);
//查询科室的方法
Page<Department> findPageDepartment(int page, int limit, DepartmentQueryVo departmentQueryVo);
//删除科室的接口方法
void remove(String hoscode, String depcode);
}
实现类:
//删除科室的接口方法
@Override
public void remove(String hoscode, String depcode) {
//先根据医院编号和科室编号查询出科室的信息
Department department = departmentRepository.getDepartmentByHoscodeAndDepcode(hoscode, depcode);
if (null != department) {
//根据id进行删除
departmentRepository.deleteById(department.getId());
}
}
点击科室列表:成功显示数据:
比如我们删除:200048644这个科室
点击删除:
成功删除:
(2)数据接口-排版接口-功能实现
排班也分为3个接口:上传排班、查询排班、删除排班
字段名 | 类型 | 长度 | 必输 | 说明 |
hoscode | string | 30 | 是 | 给医院分配的唯一标识 |
depcode | string | 20 | 是 | 科室编号 |
title | string | 30 | 是 | 职称 |
docname | string | 30 | 是 | 医生名称 |
skill | string | 300 | 是 | 擅长技能 |
workDate | string | 10 | 是 | 安排日期(yyyy-MM-dd) |
workTime | int | 是 | 安排时间(0:上午 1:下午) | |
reservedNumber | int | 可预约数 | ||
availableNumber | int | 剩余预约数 | ||
amount | string | 5 | 挂号费 | |
status | int | 排班状态(-1:停诊 0:停约 1:可约) | ||
hosScheduleId | string | 30 | 排班编号(医院自己的排班主键) | |
timestamp | long | 是 | 时间戳。从1970-01-01 00:00:00算起的毫秒数 | |
sign | string | 32 | 是 | 验签参数。 |
原来准备好的排班实体类:Shedule:
package com.atguigu.yygh.model.hosp;
import com.atguigu.yygh.model.base.BaseMongoEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.math.BigDecimal;
import java.util.Date;
/**
* <p>
* Schedule
* </p>
*
* @author qy
*/
@Data
@ApiModel(description = "Schedule")
@Document("Schedule")
public class Schedule extends BaseMongoEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "医院编号")
@Indexed //普通索引
private String hoscode;
@ApiModelProperty(value = "科室编号")
@Indexed //普通索引
private String depcode;
@ApiModelProperty(value = "职称")
private String title;
@ApiModelProperty(value = "医生名称")
private String docname;
@ApiModelProperty(value = "擅长技能")
private String skill;
@ApiModelProperty(value = "排班日期")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date workDate;
@ApiModelProperty(value = "排班时间(0:上午 1:下午)")
private Integer workTime;
@ApiModelProperty(value = "可预约数")
private Integer reservedNumber;
@ApiModelProperty(value = "剩余预约数")
private Integer availableNumber;
@ApiModelProperty(value = "挂号费")
private BigDecimal amount;
@ApiModelProperty(value = "排班状态(-1:停诊 0:停约 1:可约)")
private Integer status;
@ApiModelProperty(value = "排班编号(医院自己的排班主键)")
@Indexed //普通索引
private String hosScheduleId;
}
创建排班的reposity、service、controller:
package com.atguigu.yygh.hosp.repository;
import com.atguigu.yygh.model.hosp.Schedule;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ScheduleRepository extends MongoRepository<Schedule,String> {
}
创建ScheduleService接口 :
package com.atguigu.yygh.hosp.service;
public interface ScheduleService {
}
创建实现类:ScheduleServiceImpl
package com.atguigu.yygh.hosp.service.impl;
import com.atguigu.yygh.hosp.repository.ScheduleRepository;
import com.atguigu.yygh.hosp.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ScheduleServiceImpl implements ScheduleService {
//service操作Reposity操作MongoDB
//注入reposity
@Autowired
private ScheduleRepository scheduleRepository;
}
看一下医院系统上传科室的方法参数
在ApiController:注入:先ScheduleService
写上传排班接口:
//上传排班的接口
@ApiOperation(value = "上传排班")
@PostMapping("saveSchedule")
public Result saveSchedule(HttpServletRequest request) {
//获取传递过来的科室的信息
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);
//获取医院编号
String hoscode = (String) paramMap.get("hoscode");
//签名校验
//1获取医院系统中传递过来的签名,这个签名做了MD5加密
String hospSign = (String) paramMap.get("sign");
//2根据传递过来的医院编号,查询数据库,查询签名
//调用hospitalSetService中的方法根据医院编码获取签名
String singKey = hospitalSetService.getSignKey(hoscode);
//3把数据库查询出来的签名进行MD5的加密
String signMd5 = MD5.encrypt(singKey);
//4判断签名是否一致
if (!hospSign.equals(signMd5)) {
throw new HospitalException(ResultCodeEnum.SIGN_ERROR);//抛出我们自定义的异常
}
//调用service上传科室方法
scheduleService.save(paramMap);
return Result.ok();
}
ScheduleService 接口:
package com.atguigu.yygh.hosp.service;
import java.util.Map;
public interface ScheduleService {
//上传科室方法
void save(Map<String, Object> paramMap);
}
实现类:
package com.atguigu.yygh.hosp.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.yygh.hosp.repository.ScheduleRepository;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Schedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Map;
@Service
public class ScheduleServiceImpl implements ScheduleService {
//service操作Reposity操作MongoDB
//注入reposity
@Autowired
private ScheduleRepository scheduleRepository;
//上传科室方法
@Override
public void save(Map<String, Object> paramMap) {
//将paramMap转换为Schedule对象
String paramMapString = JSONObject.toJSONString(paramMap);
Schedule schedule = JSONObject.parseObject(paramMapString, Schedule.class);
//根据医院编号和排班编号进行查询
Schedule scheduleExist=scheduleRepository.getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(), schedule.getHosScheduleId());
if (scheduleExist!=null){
schedule.setCreateTime(new Date());
schedule.setIsDeleted(0);
schedule.setStatus(1);
scheduleRepository.save(schedule);//更新
}else {
schedule.setCreateTime(new Date());
schedule.setUpdateTime(new Date());
schedule.setIsDeleted(0);
schedule.setStatus(1);
scheduleRepository.save(schedule);//添加
}
}
}
ScheduleRepository :
package com.atguigu.yygh.hosp.repository;
import com.atguigu.yygh.model.hosp.Schedule;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ScheduleRepository extends MongoRepository<Schedule,String> {
//根据医院编号和排班编号进行查询 不需要我们自己实现 MongoRepository会帮祝我们实现
Schedule getScheduleByHoscodeAndHosScheduleId(String hoscode, String hosScheduleId);
}
查询排班的接口:
ApiController:添加查询排班接口:
//查询排班的接口
@ApiOperation(value = "获取排班分页列表")
@PostMapping("schedule/list")
public Result schedule(HttpServletRequest request) {
//获取传递过来的科室的信息
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);
//医院的编号:
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"));
//签名校验
//1获取医院系统中传递过来的签名,这个签名做了MD5加密
String hospSign = (String) paramMap.get("sign");
//2根据传递过来的医院编号,查询数据库,查询签名
//调用hospitalSetService中的方法根据医院编码获取签名
String singKey = hospitalSetService.getSignKey(hoscode);
//3把数据库查询出来的签名进行MD5的加密
String signMd5 = MD5.encrypt(singKey);
//4判断签名是否一致
if (!hospSign.equals(signMd5)) {
throw new HospitalException(ResultCodeEnum.SIGN_ERROR);//抛出我们自定义的异常
}
//查询条件实体
ScheduleQueryVo scheduleQueryVo = new ScheduleQueryVo();
scheduleQueryVo.setHoscode(hoscode);
scheduleQueryVo.setDepcode(depcode);
Page<Schedule> pageModel = scheduleService.selectPageSchedule(page , limit, scheduleQueryVo);
return Result.ok(pageModel);
}
ScheduleService 接口:
package com.atguigu.yygh.hosp.service;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.ScheduleQueryVo;
import org.springframework.data.domain.Page;
import java.util.Map;
public interface ScheduleService {
//上传科室方法
void save(Map<String, Object> paramMap);
//查询排班的接口
Page<Schedule> selectPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo);
}
实现类:ScheduleServiceImpl:
//查询排班的接口
@Override
public Page<Schedule> selectPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo) {
//创建Pageable对象,设置当前页和每页记录数 0是第一页
Sort sort = Sort.by(Sort.Direction.DESC, "createTime");//排序
Pageable pageable = PageRequest.of(page-1, limit, sort);
//创建Exapmle对象
//设置模糊查询的匹配规则 ExampleMatcher.StringMatcher.CONTAINING模糊匹配 .withIgnoreCase(true)忽略大小写
ExampleMatcher matcher = ExampleMatcher.matching()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式:模糊查询
.withIgnoreCase(true); //改变默认大小写忽略方式:忽略大小写
Schedule schedule = new Schedule();
BeanUtils.copyProperties(scheduleQueryVo, schedule);//使用工具类把departmentQueryVo转换成schedule
schedule.setIsDeleted(0);
schedule.setStatus(1);
Example<Schedule> example = Example.of(schedule, matcher);
Page<Schedule> pages = scheduleRepository.findAll(example, pageable);
return pages;
}
删除排班的接口:
ApiController:添加删除排班的接口:
//删除排班接口
@ApiOperation(value = "删除科室")
@PostMapping("schedule/remove")
public Result removeSchedule(HttpServletRequest request) {
//获取传递过来的科室的信息
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(parameterMap);
//获取医院编号:
String hoscode = (String)paramMap.get("hoscode");
//获取排班编号
String hosScheduleId = (String)paramMap.get("hosScheduleId");
//签名校验
//1获取医院系统中传递过来的签名,这个签名做了MD5加密
String hospSign = (String) paramMap.get("sign");
//2根据传递过来的医院编号,查询数据库,查询签名
//调用hospitalSetService中的方法根据医院编码获取签名
String singKey = hospitalSetService.getSignKey(hoscode);
//3把数据库查询出来的签名进行MD5的加密
String signMd5 = MD5.encrypt(singKey);
//4判断签名是否一致
if (!hospSign.equals(signMd5)) {
throw new HospitalException(ResultCodeEnum.SIGN_ERROR);//抛出我们自定义的异常
}
//调用service的方法进行删除
scheduleService.remove(hoscode, hosScheduleId);
return Result.ok();
}
ScheduleService :接口:
package com.atguigu.yygh.hosp.service;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.ScheduleQueryVo;
import org.springframework.data.domain.Page;
import java.util.Map;
public interface ScheduleService {
//上传科室方法
void save(Map<String, Object> paramMap);
//查询排班的接口
Page<Schedule> selectPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo);
//删除排班接口
void remove(String hoscode, String hosScheduleId);
}
实现类:ScheduleService Impl:
//删除排班接口
@Override
public void remove(String hoscode, String hosScheduleId) {
//根据医院编号和排班编号查询信息
Schedule schedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(hoscode, hosScheduleId);
if(null != schedule) {
//根据id进行删除
scheduleRepository.deleteById(schedule.getId());
}
}
运行项目:
复制提前准备好的数据:schdule.json:
点击保存:
数据成功添加进来了:
把第一条数据邵迎红的数据删掉:
成功删除: