Răsfoiți Sursa

refactor(user): 修改用户绑定响应中的用户ID类型为字符串

- 将 UserBindingResponse 中的 patientUserId 和 boundUserId 类型从 Long 改为 String
- 在 UserBindingServiceImpl 中对绑定类型参数增加异常处理,防止非法值导致查询失败
- 查询结果转换时,将 patientUserId 和 boundUserId 转换为字符串格式
- 修复批量查询用户信息逻辑,确保获取的是患者用户而非绑定用户的信息
- 更新相关代码注释以反映最新的数据流向和业务逻辑
mcbaiyun 1 lună în urmă
părinte
comite
09fc42a391

+ 2 - 2
src/main/java/work/baiyun/chronicdiseaseapp/model/vo/UserBindingResponse.java

@@ -13,10 +13,10 @@ public class UserBindingResponse {
     private String id;
 
     @Schema(description = "患者用户ID")
-    private Long patientUserId;
+    private String patientUserId;
 
     @Schema(description = "被绑定用户ID(医生或家属)")
-    private Long boundUserId;
+    private String boundUserId;
 
     @Schema(description = "绑定类型(DOCTOR-医生, FAMILY-家属)")
     private String bindingType;

+ 21 - 8
src/main/java/work/baiyun/chronicdiseaseapp/service/impl/UserBindingServiceImpl.java

@@ -78,7 +78,11 @@ public class UserBindingServiceImpl implements UserBindingService {
                 .le(request.getEndTime() != null, UserBinding::getCreateTime, request.getEndTime());
 
         if (bindingType != null && !bindingType.isEmpty()) {
-            wrapper.eq(UserBinding::getBindingType, UserBindingType.fromCode(bindingType));
+            try {
+                wrapper.eq(UserBinding::getBindingType, UserBindingType.fromCode(bindingType));
+            } catch (Exception e) {
+                // 如果绑定类型无效,则忽略该条件,查询所有类型
+            }
         }
 
         wrapper.orderByDesc(UserBinding::getCreateTime);
@@ -102,6 +106,8 @@ public class UserBindingServiceImpl implements UserBindingService {
             UserBindingResponse resp = new UserBindingResponse();
             BeanUtils.copyProperties(r, resp);
             resp.setId(r.getId().toString());
+            resp.setPatientUserId(r.getPatientUserId().toString());
+            resp.setBoundUserId(r.getBoundUserId().toString());
             if (r.getBindingType() != null) {
                 resp.setBindingType(r.getBindingType().getCode());
             }
@@ -133,24 +139,28 @@ public class UserBindingServiceImpl implements UserBindingService {
                 .le(request.getEndTime() != null, UserBinding::getCreateTime, request.getEndTime());
         
         if (bindingType != null && !bindingType.isEmpty()) {
-            wrapper.eq(UserBinding::getBindingType, UserBindingType.fromCode(bindingType));
+            try {
+                wrapper.eq(UserBinding::getBindingType, UserBindingType.fromCode(bindingType));
+            } catch (Exception e) {
+                // 如果绑定类型无效,则忽略该条件,查询所有类型
+            }
         }
         
         wrapper.orderByDesc(UserBinding::getCreateTime);
 
         Page<UserBinding> result = userBindingMapper.selectPage(page, wrapper);
 
-        // 批量查询被绑定用户信息,避免 N+1
-        Set<Long> boundUserIds = result.getRecords().stream()
-                .map(UserBinding::getBoundUserId)
+        // 批量查询患者用户信息,避免 N+1
+        Set<Long> patientUserIds = result.getRecords().stream()
+                .map(UserBinding::getPatientUserId)
                 .filter(id -> id != null)
                 .collect(Collectors.toSet());
 
         Map<Long, work.baiyun.chronicdiseaseapp.model.po.UserInfo> userInfoMap;
-        if (boundUserIds.isEmpty()) {
+        if (patientUserIds.isEmpty()) {
             userInfoMap = new HashMap<>();
         } else {
-            List<work.baiyun.chronicdiseaseapp.model.po.UserInfo> userInfos = userInfoMapper.selectBatchIds(boundUserIds);
+            List<work.baiyun.chronicdiseaseapp.model.po.UserInfo> userInfos = userInfoMapper.selectBatchIds(patientUserIds);
             userInfoMap = userInfos.stream().collect(Collectors.toMap(work.baiyun.chronicdiseaseapp.model.po.UserInfo::getId, u -> u));
         }
 
@@ -158,11 +168,14 @@ public class UserBindingServiceImpl implements UserBindingService {
             UserBindingResponse resp = new UserBindingResponse();
             BeanUtils.copyProperties(r, resp);
             resp.setId(r.getId().toString());
+            resp.setPatientUserId(r.getPatientUserId().toString());
+            resp.setBoundUserId(r.getBoundUserId().toString());
             if (r.getBindingType() != null) {
                 resp.setBindingType(r.getBindingType().getCode());
             }
 
-            work.baiyun.chronicdiseaseapp.model.po.UserInfo ui = userInfoMap.get(r.getBoundUserId());
+            // 获取患者用户信息而不是绑定用户信息
+            work.baiyun.chronicdiseaseapp.model.po.UserInfo ui = userInfoMap.get(r.getPatientUserId());
             if (ui != null) {
                 resp.setBoundUserNickname(ui.getNickname());
                 resp.setBoundUserPhone(ui.getPhone());