|
|
@@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.system.service.appointment;
|
|
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.AppointmentConfigRespVO;
|
|
|
-import cn.iocoder.yudao.module.system.controller.app.appointment.vo.AppointmentQuotaOccupyReqVO;
|
|
|
-import cn.iocoder.yudao.module.system.controller.app.appointment.vo.AppointmentQuotaOccupyRespVO;
|
|
|
-import cn.iocoder.yudao.module.system.controller.app.appointment.vo.AppointmentQuotaQueryReqVO;
|
|
|
-import cn.iocoder.yudao.module.system.controller.app.appointment.vo.AppointmentQuotaQueryRespVO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.biz.appointment.vo.AppointmentQuotaOccupyReqVO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.biz.appointment.vo.AppointmentQuotaOccupyRespVO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.biz.appointment.vo.AppointmentQuotaQueryReqVO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.biz.appointment.vo.AppointmentQuotaQueryRespVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.biz.AppointmentConfigDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.biz.AppointmentGroupDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.miniapp.JiashuVisitAppointmentMapper;
|
|
|
@@ -68,7 +68,7 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
public AppointmentQuotaOccupyRespVO occupy(AppointmentQuotaOccupyReqVO reqVO) {
|
|
|
Long tenantId = reqVO.getOrgId();
|
|
|
LocalDate visitDate = reqVO.getVisitDate();
|
|
|
- String openId = reqVO.getVisitorOpenId();
|
|
|
+ String phone = reqVO.getPhone();
|
|
|
|
|
|
// 1. 配置存在 & 开关
|
|
|
AppointmentConfigRespVO configResp = appointmentConfigService.getByTenant(tenantId);
|
|
|
@@ -106,7 +106,7 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
// 4. 总名额(daily / weekly / monthly)
|
|
|
checkTotalLimit(config, tenantId, visitDate);
|
|
|
// 5. 单人名额(daily / weekly / monthly)
|
|
|
- checkPersonLimit(config, tenantId, openId, visitDate);
|
|
|
+ checkPersonLimit(config, tenantId, phone, visitDate);
|
|
|
// 6. 组名额(每组每天 limitCount)
|
|
|
checkGroupLimit(matchedGroup, visitDate);
|
|
|
|
|
|
@@ -114,9 +114,9 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
appointmentQuotaRedisDAO.incrTotalDaily(tenantId, visitDate, OCCUPY_COUNT);
|
|
|
appointmentQuotaRedisDAO.incrTotalWeekly(tenantId, visitDate, OCCUPY_COUNT);
|
|
|
appointmentQuotaRedisDAO.incrTotalMonthly(tenantId, visitDate, OCCUPY_COUNT);
|
|
|
- appointmentQuotaRedisDAO.incrPersonDaily(tenantId, openId, visitDate, OCCUPY_COUNT);
|
|
|
- appointmentQuotaRedisDAO.incrPersonWeekly(tenantId, openId, visitDate, OCCUPY_COUNT);
|
|
|
- appointmentQuotaRedisDAO.incrPersonMonthly(tenantId, openId, visitDate, OCCUPY_COUNT);
|
|
|
+ appointmentQuotaRedisDAO.incrPersonDaily(tenantId, phone, visitDate, OCCUPY_COUNT);
|
|
|
+ appointmentQuotaRedisDAO.incrPersonWeekly(tenantId, phone, visitDate, OCCUPY_COUNT);
|
|
|
+ appointmentQuotaRedisDAO.incrPersonMonthly(tenantId, phone, visitDate, OCCUPY_COUNT);
|
|
|
appointmentQuotaRedisDAO.incrGroupDaily(matchedGroup.getId(), visitDate, OCCUPY_COUNT);
|
|
|
|
|
|
return AppointmentQuotaOccupyRespVO.success(matchedGroup.getId());
|
|
|
@@ -126,7 +126,7 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
public void release(AppointmentQuotaOccupyReqVO reqVO) {
|
|
|
Long tenantId = reqVO.getOrgId();
|
|
|
LocalDate visitDate = reqVO.getVisitDate();
|
|
|
- String openId = reqVO.getVisitorOpenId();
|
|
|
+ String phone = reqVO.getPhone();
|
|
|
|
|
|
/*
|
|
|
* release 调用时机:前端调 occupy 通过 → 调实际预约接口落库 → 立即调 release
|
|
|
@@ -141,9 +141,9 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatTotalDailyKey(tenantId, visitDate), OCCUPY_COUNT);
|
|
|
appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatTotalWeeklyKey(tenantId, visitDate), OCCUPY_COUNT);
|
|
|
appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatTotalMonthlyKey(tenantId, visitDate), OCCUPY_COUNT);
|
|
|
- appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatPersonDailyKey(tenantId, openId, visitDate), OCCUPY_COUNT);
|
|
|
- appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatPersonWeeklyKey(tenantId, openId, visitDate), OCCUPY_COUNT);
|
|
|
- appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatPersonMonthlyKey(tenantId, openId, visitDate), OCCUPY_COUNT);
|
|
|
+ appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatPersonDailyKey(tenantId, phone, visitDate), OCCUPY_COUNT);
|
|
|
+ appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatPersonWeeklyKey(tenantId, phone, visitDate), OCCUPY_COUNT);
|
|
|
+ appointmentQuotaRedisDAO.decr(appointmentQuotaRedisDAO.formatPersonMonthlyKey(tenantId, phone, visitDate), OCCUPY_COUNT);
|
|
|
// 注意:组维度不递减——visit_appointment 缺 groupId 无法从 DB 按组统计,Redis 即正式计数,到期自动释放
|
|
|
}
|
|
|
|
|
|
@@ -220,24 +220,24 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void checkPersonLimit(AppointmentConfigDO config, Long tenantId, String openId, LocalDate date) {
|
|
|
+ private void checkPersonLimit(AppointmentConfigDO config, Long tenantId, String phone, LocalDate date) {
|
|
|
if (config.getPersonDailyLimit() != null) {
|
|
|
- Long db = countByOpenIdInMiniapp(openId, date, date);
|
|
|
- Long redis = appointmentQuotaRedisDAO.getCount(appointmentQuotaRedisDAO.formatPersonDailyKey(tenantId, openId, date));
|
|
|
+ Long db = countByPhoneInMiniapp(phone, date, date);
|
|
|
+ Long redis = appointmentQuotaRedisDAO.getCount(appointmentQuotaRedisDAO.formatPersonDailyKey(tenantId, phone, date));
|
|
|
if (db + redis >= config.getPersonDailyLimit()) {
|
|
|
throw exception(ErrorCodeConstants.APPOINTMENT_PERSON_LIMIT);
|
|
|
}
|
|
|
}
|
|
|
if (config.getPersonWeeklyLimit() != null) {
|
|
|
- Long db = countByOpenIdInMiniapp(openId, date.with(DayOfWeek.MONDAY), date.with(DayOfWeek.SUNDAY));
|
|
|
- Long redis = appointmentQuotaRedisDAO.getCount(appointmentQuotaRedisDAO.formatPersonWeeklyKey(tenantId, openId, date));
|
|
|
+ Long db = countByPhoneInMiniapp(phone, date.with(DayOfWeek.MONDAY), date.with(DayOfWeek.SUNDAY));
|
|
|
+ Long redis = appointmentQuotaRedisDAO.getCount(appointmentQuotaRedisDAO.formatPersonWeeklyKey(tenantId, phone, date));
|
|
|
if (db + redis >= config.getPersonWeeklyLimit()) {
|
|
|
throw exception(ErrorCodeConstants.APPOINTMENT_PERSON_LIMIT);
|
|
|
}
|
|
|
}
|
|
|
if (config.getPersonMonthlyLimit() != null) {
|
|
|
- Long db = countByOpenIdInMiniapp(openId, date.withDayOfMonth(1), date.withDayOfMonth(date.lengthOfMonth()));
|
|
|
- Long redis = appointmentQuotaRedisDAO.getCount(appointmentQuotaRedisDAO.formatPersonMonthlyKey(tenantId, openId, date));
|
|
|
+ Long db = countByPhoneInMiniapp(phone, date.withDayOfMonth(1), date.withDayOfMonth(date.lengthOfMonth()));
|
|
|
+ Long redis = appointmentQuotaRedisDAO.getCount(appointmentQuotaRedisDAO.formatPersonMonthlyKey(tenantId, phone, date));
|
|
|
if (db + redis >= config.getPersonMonthlyLimit()) {
|
|
|
throw exception(ErrorCodeConstants.APPOINTMENT_PERSON_LIMIT);
|
|
|
}
|
|
|
@@ -267,10 +267,10 @@ public class AppAppointmentQuotaServiceImpl implements AppAppointmentQuotaServic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Long countByOpenIdInMiniapp(String openId, LocalDate start, LocalDate end) {
|
|
|
+ private Long countByPhoneInMiniapp(String phone, LocalDate start, LocalDate end) {
|
|
|
DynamicDataSourceContextHolder.push("miniapp");
|
|
|
try {
|
|
|
- return jiashuVisitAppointmentMapper.countByOpenIdAndDateRange(openId, start, end);
|
|
|
+ return jiashuVisitAppointmentMapper.countByPhoneAndDateRange(phone, start, end);
|
|
|
} finally {
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
}
|