1、添加科室信息基础类
- 1.1、model实体类
- 1.2、创建ScheduleRepository
- 1.3、创建业务层
- 1.4、控制层
- 2、上传排班接口
- 2.1、开发需求文档
- 2.1.1、请求路径
- 2.1.2、请求参数
- 2.1.3、同步返回
- 2.2、控制层代码编写
- 2.3、业务层
- 2.4、Repository
- 3、查询排班信息接口
- 3.1、需求
- 3.1.1、提交地址
- 3.1.2、请求参数
- 3.1.3、同步返回
- 3.2、控制层接口
- 3.3、业务层
- 4、删除排班接口
- 4.1、开发需求
- 4.1.1、提交地址
- 4.1.2、请求参数
- 4.1.3、同步返回
- 4.2、控制层
- 4.3、业务层
- 5、测试
1、添加科室信息基础类
1.1、model实体类
@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;
}
1.2、创建ScheduleRepository
@Repository
public interface ScheduleRepository extends MongoRepository<Schedule,String> {
}
1.3、创建业务层
接口:
public interface ScheduleService {
}
实现类:
@Service
public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private ScheduleRepository scheduleRepository;
}
1.4、控制层
2、上传排班接口
2.1、开发需求文档
2.1.1、请求路径
http://localhost/api/hosp/saveSchedule
2.1.2、请求参数
◎ 变量定义
2.1.3、同步返回
◎ 结果参数含义
2.2、控制层代码编写
//上传排班信息
@PostMapping("/saveSchedule")
public Result saveSchedule(HttpServletRequest request){
//获取传递过来的科室信息
Map<String, String[]> requestMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
String hoscode = (String)paramMap.get("hoscode");
//签名校验
//1、获取医院传递过来的签名
String signKey = (String)paramMap.get("sign");
//2、获取医院签名
String hosSignKey = hospitalSetService.getSignKey(hoscode);
String hosSignKeyMD5 = MD5.encrypt(hosSignKey);
//3、如果两个签名不一致,则校验失败
if(!hosSignKeyMD5.equals(signKey)){
throw new YyghException(ResultCodeEnum.SIGN_ERROR);
}
//调用service方法
scheduleService.save(paramMap);
return Result.ok();
}
2.3、业务层
接口:
//上传排班信息
void save(Map<String, Object> paramMap);
实现类:
//上传排班信息
@Override
public void save(Map<String, Object> paramMap) {
//将数据转换成字符串
String paramMapString = JSONObject.toJSONString(paramMap);
//将字符串转换成对象
Schedule schedule = JSONObject.parseObject(paramMapString, Schedule.class);
//根据医院编号和排版编号查询
Schedule scheduleExist =
scheduleRepository.getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(),schedule.getHosScheduleId());
//scheduleExist不为空,修改操作
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);
}
}
2.4、Repository
@Repository
public interface ScheduleRepository extends MongoRepository<Schedule,String> {
Schedule getScheduleByHoscodeAndHosScheduleId(String hoscode, String hosScheduleId);
}
3、查询排班信息接口
3.1、需求
3.1.1、提交地址
http://localhost/api/hosp/schedule/list
3.1.2、请求参数
3.1.3、同步返回
3.2、控制层接口
//查询排班信息
@PostMapping("/schedule/list")
public Result getSchedule(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");
//当前页和每页记录数
Integer page = StringUtils.isEmpty(paramMap.get("page")) ? 1:Integer.parseInt((String)paramMap.get("page"));
Integer limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1:Integer.parseInt((String)paramMap.get("limit"));
//签名校验
//1、获取医院传递过来的签名
String signKey = (String)paramMap.get("sign");
//2、获取医院签名
String hosSignKey = hospitalSetService.getSignKey(hoscode);
String hosSignKeyMD5 = MD5.encrypt(hosSignKey);
//3、如果两个签名不一致,则校验失败
if(!hosSignKeyMD5.equals(signKey)){
throw new YyghException(ResultCodeEnum.SIGN_ERROR);
}
ScheduleQueryVo scheduleQueryVo = new ScheduleQueryVo();
scheduleQueryVo.setHoscode(hoscode);
scheduleQueryVo.setDoccode(depcode);
//调用service方法
Page<Schedule> pageModel = scheduleService.findPageSchedule(page,limit,scheduleQueryVo);
return Result.ok(pageModel);
}
3.3、业务层
接口:
//查询排班信息
Page<Schedule> findPageSchedule(Integer page, Integer limit, ScheduleQueryVo scheduleQueryVo);
实现类:
//查询排班信息
@Override
public Page<Schedule> findPageSchedule(Integer page, Integer limit, ScheduleQueryVo scheduleQueryVo) {
//设置分页信息
Pageable pageable = PageRequest.of(page,limit);
//创建Example对象
Schedule schedule = new Schedule();
BeanUtils.copyProperties(scheduleQueryVo,schedule);
schedule.setIsDeleted(0);
schedule.setStatus(1);
//设置查询规则
ExampleMatcher matcher = ExampleMatcher.matching()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
.withIgnoreCase(true);
Example<Schedule> example = Example.of(schedule,matcher);
//调用方法查询数据
Page<Schedule> all = scheduleRepository.findAll(example,pageable);
return all;
}
4、删除排班接口
4.1、开发需求
4.1.1、提交地址
http://localhost/api/hosp/department/remove
.
4.1.2、请求参数
4.1.3、同步返回
◎ 结果参数含义
4.2、控制层
//删除排班信息
@PostMapping("/schedule/remove")
public Result deleteSchedule(HttpServletRequest request){
//获取传递过来的科室信息
Map<String, String[]> resultMap = request.getParameterMap();
Map<String, Object> paramMap = HttpRequestHelper.switchMap(resultMap);
//获取医院编号和排班编号
String hoscode = (String)paramMap.get("hoscode");
String hosScheduleId = (String)paramMap.get("hosScheduleId");
//获取医院传递过来的签名
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);
}
scheduleService.remove(hoscode,hosScheduleId);
return Result.ok();
}
4.3、业务层
接口:
//删除排班信息
void remove(String hoscode, String hosScheduleId);
实现类:
//删除科室信息
@Override
public void remove(String hoscode, String hosScheduleId) {
Schedule schedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(hoscode, hosScheduleId);
if(schedule != null){
scheduleRepository.deleteById(schedule.getId());
}
}
5、测试