|
|
@@ -38,6 +38,13 @@ public class FollowUpServiceImpl implements FollowUpService {
|
|
|
@Override
|
|
|
public void createFollowUp(CreateFollowUpRequest request) {
|
|
|
Long userId = SecurityUtils.getCurrentUserId();
|
|
|
+
|
|
|
+ // 验证医生ID是否有效
|
|
|
+ UserInfo doctor = userInfoMapper.selectById(request.getDoctorUserId());
|
|
|
+ if (doctor == null || doctor.getRole() != PermissionGroup.DOCTOR) {
|
|
|
+ throw new CustomException(ErrorCode.INVALID_DOCTOR.getCode(), ErrorCode.INVALID_DOCTOR.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
FollowUp followUp = new FollowUp();
|
|
|
BeanUtils.copyProperties(request, followUp);
|
|
|
followUp.setPatientUserId(userId);
|
|
|
@@ -73,6 +80,17 @@ public class FollowUpServiceImpl implements FollowUpService {
|
|
|
"无权操作该复诊记录");
|
|
|
}
|
|
|
|
|
|
+ // 如果患者修改了已确认的复诊申请的关键字段,重置状态为待确认
|
|
|
+ boolean isModifiedByPatient = role == PermissionGroup.PATIENT;
|
|
|
+ boolean isConfirmed = FollowUpStatus.CONFIRMED.equals(followUp.getStatus());
|
|
|
+ boolean hasModifiedAppointmentTime = request.getAppointmentTime() != null &&
|
|
|
+ !request.getAppointmentTime().equals(followUp.getAppointmentTime());
|
|
|
+ boolean hasModifiedReason = request.getReason() != null &&
|
|
|
+ !request.getReason().equals(followUp.getReason());
|
|
|
+ if (isModifiedByPatient && isConfirmed && (hasModifiedAppointmentTime || hasModifiedReason)) {
|
|
|
+ followUp.setStatus(FollowUpStatus.PENDING);
|
|
|
+ }
|
|
|
+
|
|
|
// 更新字段
|
|
|
if (request.getAppointmentTime() != null) {
|
|
|
followUp.setAppointmentTime(request.getAppointmentTime());
|
|
|
@@ -83,6 +101,9 @@ public class FollowUpServiceImpl implements FollowUpService {
|
|
|
if (request.getNotes() != null) {
|
|
|
followUp.setNotes(request.getNotes());
|
|
|
}
|
|
|
+ if (request.getReason() != null) {
|
|
|
+ followUp.setReason(request.getReason());
|
|
|
+ }
|
|
|
|
|
|
// 如果状态更新为已完成,则设置实际就诊时间
|
|
|
if (FollowUpStatus.COMPLETED.equals(followUp.getStatus())) {
|
|
|
@@ -133,7 +154,16 @@ public class FollowUpServiceImpl implements FollowUpService {
|
|
|
BeanUtils.copyProperties(r, resp);
|
|
|
resp.setId(r.getId().toString());
|
|
|
|
|
|
- // 设置用户昵称
|
|
|
+ // 设置用户ID为字符串类型,避免前端精度丢失
|
|
|
+ if (r.getPatientUserId() != null) {
|
|
|
+ resp.setPatientUserId(r.getPatientUserId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (r.getDoctorUserId() != null) {
|
|
|
+ resp.setDoctorUserId(r.getDoctorUserId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置昵称
|
|
|
UserInfo patient = userInfoMap.get(r.getPatientUserId());
|
|
|
if (patient != null) {
|
|
|
resp.setPatientNickname(patient.getNickname());
|
|
|
@@ -148,7 +178,6 @@ public class FollowUpServiceImpl implements FollowUpService {
|
|
|
if (r.getStatus() != null) {
|
|
|
resp.setStatus(r.getStatus().getCode());
|
|
|
}
|
|
|
-
|
|
|
return resp;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
@@ -184,10 +213,45 @@ public class FollowUpServiceImpl implements FollowUpService {
|
|
|
|
|
|
Page<FollowUp> result = followUpMapper.selectPage(page, wrapper);
|
|
|
|
|
|
+ // 批量查询用户信息
|
|
|
+ Set<Long> userIds = result.getRecords().stream()
|
|
|
+ .flatMap(r -> java.util.stream.Stream.of(r.getPatientUserId(), r.getDoctorUserId()))
|
|
|
+ .filter(id -> id != null)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ Map<Long, UserInfo> userInfoMap;
|
|
|
+ if (userIds.isEmpty()) {
|
|
|
+ userInfoMap = java.util.Collections.emptyMap();
|
|
|
+ } else {
|
|
|
+ List<UserInfo> userInfos = userInfoMapper.selectBatchIds(userIds);
|
|
|
+ userInfoMap = userInfos.stream().collect(Collectors.toMap(UserInfo::getId, u -> u));
|
|
|
+ }
|
|
|
+
|
|
|
List<FollowUpResponse> responses = result.getRecords().stream().map(r -> {
|
|
|
FollowUpResponse resp = new FollowUpResponse();
|
|
|
BeanUtils.copyProperties(r, resp);
|
|
|
resp.setId(r.getId().toString());
|
|
|
+
|
|
|
+ // 设置用户ID为字符串类型,避免前端精度丢失
|
|
|
+ if (r.getPatientUserId() != null) {
|
|
|
+ resp.setPatientUserId(r.getPatientUserId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (r.getDoctorUserId() != null) {
|
|
|
+ resp.setDoctorUserId(r.getDoctorUserId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置昵称
|
|
|
+ UserInfo patient = userInfoMap.get(r.getPatientUserId());
|
|
|
+ if (patient != null) {
|
|
|
+ resp.setPatientNickname(patient.getNickname());
|
|
|
+ }
|
|
|
+
|
|
|
+ UserInfo doctor = userInfoMap.get(r.getDoctorUserId());
|
|
|
+ if (doctor != null) {
|
|
|
+ resp.setDoctorNickname(doctor.getNickname());
|
|
|
+ }
|
|
|
+
|
|
|
// 设置状态码
|
|
|
if (r.getStatus() != null) {
|
|
|
resp.setStatus(r.getStatus().getCode());
|