之前说过把患者预约的的时间当作字段,医生当作字段的值放入hash(患者表中)
现在我们取出来
dao层
RedisDaoImpl
@Override
public Map<Object, Object> hashGetAll(String key) {
return redisTemplate.opsForHash().entries(key);
}
service层
BookingServiceImpl新增一个方法
由于顺序是按添加顺序,我们需要给list进行按时间排序 使用Collections.sort
代码较多
@Override
public List<Booking> getBookingsByPatient(Integer patientId) {
List<Booking> list = new ArrayList<>();
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
//拼接出key名
String key = String.format("patient:%d", patientId);
//获取所有的预约,map--key=看病时间,value=医生id
Map<Object, Object> map = redisDao.hashGetAll(key);
for (Object k : map.keySet()) {
Date date = null;
String doctorId = (String)map.get(k);
String time[] =