ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

解决高并发-springboot-redis-mysql医院预约系统项目超详细讲解--半个小时教你如何使用springboot完成预约项目-----第六章:删除预约

2021-01-08 20:01:26  阅读:191  来源: 互联网

标签:String parent 预约 redis doctorId key Integer booking springboot


之前我们写过三个set方法,删除也需要删除三个del方法,不然会导致数据不一致
set为了去重,hash为了方便查看预约,list为了算方便算长度(预约数)

dao层
RedisDao 新增三个方法

    @Override
    public Integer hashDel(String key, String hkey) {

        return redisTemplate.opsForHash().delete(key, hkey).intValue();
    }

    @Override
    public Integer setDel(String key, String value) {
        return redisTemplate.opsForSet().remove(key, value).intValue();
    }

    @Override
    public Integer listDel(String key, String value) {
        return redisTemplate.opsForList().remove(key,1,value).intValue();
    }

service层
BOokingServiceImpl

   @Transactional
    public Integer delOneBooking(Booking booking) {
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");

        String date = fmt.format(booking.getBookingDate());
        Integer doctorId = booking.getDoctor().getDoctorId();
        Integer patientId = booking.getPatient().getPatientId();

        String key = "patient:" + patientId;
        redisDao.hashDel(key, date + "@" + booking.getVisitTime());

        key = String.format("patient-set:%s", date);
        redisDao.setDel(key,patientId.toString());

        key = String.format("doctor:%d:%s", doctorId, date);
        System.out.println(key);
        Integer integer = redisDao.listDel(key,doctorId.toString());
        return 1;
    }

controller层
BookingController
//页面获取doctorid 因为好多键名需要它

 @RequestMapping("del_booking")
    @ResponseBody
    public Map<String, Object> delOneBooking(Booking booking,Integer doctorId, HttpSession session) { 
        Map<String, Object> result = new HashMap<>();
        Patient user = (Patient)session.getAttribute("user");
        Doctor doctor = new Doctor();
        doctor.setDoctorId(doctorId);//修改doctorId
        booking.setDoctor(doctor);
        booking.setPatient(user);

        if (bookingService.delOneBooking(booking) > 0) {
            result.put("success", true);
        }
        else {
            result.put("success", false);
        }

        return result;
    }

页面
ajax

function delBooking(obj) {
				var bookingDate = $(obj).parent().prev().prev().text();
				var visitTime = $(obj).parent().prev().text();
				var doctorId = $(obj).parent().parent().find("input").val(); //从隐藏input标签获取医生id
				$.ajax({
					url: 'del_booking?bookingDate='+bookingDate+"&visitTime="+visitTime+"&doctorId="+doctorId,
					type: 'post',
					dataType: "json",
					success: function (data) {
						if (data.success) {
							//删除本行数据
							$(obj).parent().parent().remove();
						}
						else {
							alert("取消失败");
						}
					},
					error: function(error){    //失败后回调
						alert("服务器连接失败");
					}
				});
			}

页面循环列表 写一个隐藏的input标签 估计是最笨的方法了吧 ~

		<#list bookings as b>
								<tr>
									<input type="hidden" value="${b.doctor.doctorId}">
									<td>${b_index + 1}</td>
                                    <td>${b.doctor.office.officeName}</td>
									<td>${b.doctor.name}</td>
                                    <td>${b.bookingDate?string("yyyy-MM-dd")}</td>
									<td>${b.visitTime}</td>
									<td><a href="javascript:void(0)" onclick="delBooking(this)">取消预约</a></td>
								</tr>
							</#list>

标签:String,parent,预约,redis,doctorId,key,Integer,booking,springboot
来源: https://blog.csdn.net/zhhhhhh1213/article/details/112382000

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有