一、上传排班接口
1. 添加排班基础类
A、添加 model
说明:由于实体对象没有逻辑,我们已经统一导入com.fancy.yygh.model.hosp.Schedule
B、添加 repository
添加 com.fancy.yygh.hosp.repository.ScheduleRepository
package com.fancy.yygh.hosp.repository;
@Repository
public interface ScheduleRepository extends MongoRepository<Schedule,String> {
}
C、添加 service 接口及实现类
添加 com.fancy.yygh.hosp.service.ScheduleService 接口
package com.fancy.yygh.hosp.service;
public interface ScheduleService {
}
添加com.fancy.yygh.hosp.service.impl.ScheduleServiceImpl
接口实现
package com.fancy.yygh.hosp.service.impl;
@Service
@Slf4j
public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private ScheduleRepository scheduleRepository;
}
2. 上传排班
A、上传排班
医院编号是平台分配的,全局唯一,排班编号为医院自己的编号,相对医院唯一,上传排班接口可以多次调用,如果医院编号与排班编号组合唯一为更新操作
B、接口数据分析
{
"hoscode": "1000_0",
"depcode": "200040878",
"title": "医师",
"docname": "",
"skill": "内分泌科常见病。",
"workDate": "2020-06-22",
"workTime": 0,
"reservedNumber": 33,
"availableNumber": 22,
"amount": "100",
"status": 1,
"hosScheduleId": "1"
}
C、添加 service 接口
在 ScheduleService 类添加接口
/**
* 上传排班信息
* @param paramMap
*/
void save(Map<String, Object> paramMap);
说明:参数使用 Map,减少对象封装,有利于签名校验,后续会体验到
在 ScheduleServiceImpl 类添加实现
@Override
public void save(Map<String, Object> paramMap) {
Schedule schedule = JSONObject.parseObject(JSONObject.toJSONString(paramMap), Schedule.class);
Schedule targetSchedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(), schedule.getHosScheduleId());
if(null != targetSchedule) {
//值copy不为null的值,该方法为自定义方法
BeanUtils.copyBean(schedule, targetSchedule, Schedule.class);
scheduleRepository.save(targetSchedule);
} else {
schedule.setCreateTime(new Date());
schedule.setUpdateTime(new Date());
schedule.setIsDeleted(0);
scheduleRepository.save(schedule);
}
}
D、添加 repository 接口
在 ScheduleRepository 添加方法
Schedule getScheduleByHoscodeAndHosScheduleId(String hoscode, String hosScheduleId);
E、添加 controller 接口
在 ApiController 类添加接口
@Autowired
private ScheduleService scheduleService;
@ApiOperation(value = "上传排班")
@PostMapping("saveSchedule")
public Result saveSchedule(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);
}
scheduleService.save(paramMap);
return Result.ok();
}
二、查询排班接口
一个科室有多个科室,因此我们采取分页查询方式
A、添加 service 接口
在 ScheduleService 类添加接口
/**
* 分页查询
* @param page 当前页码
* @param limit 每页记录数
* @param scheduleQueryVo 查询条件
* @return
*/
Page<Schedule> selectPage(Integer page, Integer limit, ScheduleQueryVo scheduleQueryVo);
在 ScheduleServiceImpl 类添加实现
@Override
public Page<Schedule> selectPage(Integer page, Integer limit, ScheduleQueryVo scheduleQueryVo) {
Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
//0为第一页
Pageable pageable = PageRequest.of(page-1, limit, sort);
Schedule schedule = new Schedule();
BeanUtils.copyProperties(scheduleQueryVo, schedule);
schedule.setIsDeleted(0);
//创建匹配器,即如何使用查询条件
ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式:模糊查询
.withIgnoreCase(true); //改变默认大小写忽略方式:忽略大小写
//创建实例
Example<Schedule> example = Example.of(schedule, matcher);
Page<Schedule> pages = scheduleRepository.findAll(example, pageable);
return pages;
}
B、添加 controller 接口
在 ApiController 类添加接口
@ApiOperation(value = "获取排班分页列表")
@PostMapping("schedule/list")
public Result schedule(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);
}
ScheduleQueryVo scheduleQueryVo = new ScheduleQueryVo();
scheduleQueryVo.setHoscode(hoscode);
scheduleQueryVo.setDepcode(depcode);
Page<Schedule> pageModel = scheduleService.selectPage(page , limit, scheduleQueryVo);
return Result.ok(pageModel);
}
三、删除排班接口
根据医院编号与排班编号删除科室
A、添加 service 接口
在 ScheduleService 类添加接口
/**
* 删除科室
* @param hoscode
* @param hosScheduleId
*/
void remove(String hoscode, String hosScheduleId);
B、在 ScheduleServiceImpl 类添加实现
@Override
public void remove(String hoscode, String hosScheduleId) {
Schedule schedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(hoscode, hosScheduleId);
if(null != schedule) {
scheduleRepository.deleteById(schedule.getId());
}
}
C、添加 controller 接口
在 ApiController 类添加接口
@ApiOperation(value = "删除科室")
@PostMapping("schedule/remove")
public Result removeSchedule(HttpServletRequest request) {
Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
//必须参数校验 略
String hoscode = (String)paramMap.get("hoscode");
//必填
String hosScheduleId = (String)paramMap.get("hosScheduleId");
if(StringUtils.isEmpty(hoscode)) {
throw new YyghException(ResultCodeEnum.PARAM_ERROR);
}
//签名校验
if(!HttpRequestHelper.isSignEquals(paramMap, hospitalSetService.getSignKey(hoscode))) {
throw new YyghException(ResultCodeEnum.SIGN_ERROR);
}
scheduleService.remove(hoscode, hosScheduleId);
return Result.ok();
}