|
@@ -1,14 +1,17 @@
|
|
|
package cn.iocoder.yudao.module.system.service.miniapp;
|
|
package cn.iocoder.yudao.module.system.service.miniapp;
|
|
|
|
|
|
|
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.VisitAppointmentCountRespVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.VisitAppointmentCountRespVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.miniapp.JiashuVisitAppointmentDO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.miniapp.JiashuVisitAppointmentDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.miniapp.JiashuVisitAppointmentMapper;
|
|
import cn.iocoder.yudao.module.system.dal.mysql.miniapp.JiashuVisitAppointmentMapper;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.time.DayOfWeek;
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 探访预约 Service 实现(yanglao-jiashu 数据源)
|
|
* 探访预约 Service 实现(yanglao-jiashu 数据源)
|
|
@@ -33,6 +36,35 @@ public class JiashuVisitAppointmentServiceImpl implements JiashuVisitAppointment
|
|
|
return respVO;
|
|
return respVO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public VisitAppointmentCountRespVO getVisitCountByPhone(String phone, LocalDate date) {
|
|
|
|
|
+ // 前端未传日期时,默认以当天作为基准日期
|
|
|
|
|
+ LocalDate baseDate = date != null ? date : LocalDate.now();
|
|
|
|
|
+ VisitAppointmentCountRespVO respVO = new VisitAppointmentCountRespVO();
|
|
|
|
|
+ respVO.setTodayCount(getTodayCountByPhone(phone, baseDate));
|
|
|
|
|
+ respVO.setWeekCount(getWeekCountByPhone(phone, baseDate));
|
|
|
|
|
+ respVO.setMonthCount(getMonthCountByPhone(phone, baseDate));
|
|
|
|
|
+ return respVO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void cancelVisitAppointment(Long id) {
|
|
|
|
|
+ JiashuVisitAppointmentDO existing = jiashuVisitAppointmentMapper.selectById(id);
|
|
|
|
|
+ if (existing == null) {
|
|
|
|
|
+ throw new ServiceException(ErrorCodeConstants.VISIT_APPOINTMENT_NOT_FOUND);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 状态:0-待确认,1-已预约,2-已取消,3-已完成,4-已删除
|
|
|
|
|
+ Integer status = existing.getStatus();
|
|
|
|
|
+ if (status != null && (status == 2 || status == 4)) {
|
|
|
|
|
+ throw new ServiceException(ErrorCodeConstants.VISIT_APPOINTMENT_CANCELED);
|
|
|
|
|
+ }
|
|
|
|
|
+ JiashuVisitAppointmentDO updateDO = new JiashuVisitAppointmentDO();
|
|
|
|
|
+ updateDO.setId(id);
|
|
|
|
|
+ updateDO.setStatus(2);
|
|
|
|
|
+ updateDO.setUpdatedAt(LocalDateTime.now());
|
|
|
|
|
+ jiashuVisitAppointmentMapper.updateById(updateDO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 当日预约参观数量(以传入的基准日期为准)
|
|
* 当日预约参观数量(以传入的基准日期为准)
|
|
|
*/
|
|
*/
|
|
@@ -58,4 +90,29 @@ public class JiashuVisitAppointmentServiceImpl implements JiashuVisitAppointment
|
|
|
return jiashuVisitAppointmentMapper.countByVisitDateRange(firstDay, lastDay, tenantId);
|
|
return jiashuVisitAppointmentMapper.countByVisitDateRange(firstDay, lastDay, tenantId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 当日预约参观数量(以传入的基准日期为准,按手机号过滤)
|
|
|
|
|
+ */
|
|
|
|
|
+ private Long getTodayCountByPhone(String phone, LocalDate baseDate) {
|
|
|
|
|
+ return jiashuVisitAppointmentMapper.countByPhoneAndDateRange(phone, baseDate, baseDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 当周(周一至周日)预约参观数量(以传入的基准日期所在周为准,按手机号过滤)
|
|
|
|
|
+ */
|
|
|
|
|
+ private Long getWeekCountByPhone(String phone, LocalDate baseDate) {
|
|
|
|
|
+ LocalDate monday = baseDate.with(DayOfWeek.MONDAY);
|
|
|
|
|
+ LocalDate sunday = baseDate.with(DayOfWeek.SUNDAY);
|
|
|
|
|
+ return jiashuVisitAppointmentMapper.countByPhoneAndDateRange(phone, monday, sunday);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 当月(1号至月末)预约参观数量(以传入的基准日期所在月为准,按手机号过滤)
|
|
|
|
|
+ */
|
|
|
|
|
+ private Long getMonthCountByPhone(String phone, LocalDate baseDate) {
|
|
|
|
|
+ LocalDate firstDay = baseDate.withDayOfMonth(1);
|
|
|
|
|
+ LocalDate lastDay = baseDate.withDayOfMonth(baseDate.lengthOfMonth());
|
|
|
|
|
+ return jiashuVisitAppointmentMapper.countByPhoneAndDateRange(phone, firstDay, lastDay);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|