소스 검색

接口复查

hxd 4 달 전
부모
커밋
e638ede28a

+ 3 - 3
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/ShareController.java

@@ -38,10 +38,10 @@ public class ShareController {
         return ApiResult.success();
     }
 
-    @GetMapping("/devShare")
+    @GetMapping("/queryDevShare")
     @ApiOperation(value = "查看设备分享记录")
-    public ApiResult<List<ShareDto>> queryShare(@Valid @RequestParam Long userId) {
-        return ApiResult.success(deviceGateway.queryShare(userId));
+    public ApiResult<List<ShareDto>> queryDevShare(@Valid @RequestParam Long userId) {
+        return ApiResult.success(deviceGateway.queryDevShare(userId));
     }
 
     @GetMapping("/shareConfirm")

+ 6 - 2
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/UserController.java

@@ -4,7 +4,6 @@ import cn.hfln.framework.catchlog.CatchAndLog;
 import cn.hfln.framework.dto.ApiResult;
 import com.hfln.portal.common.dto.data.user.UserDto;
 import com.hfln.portal.common.request.user.*;
-import com.hfln.portal.common.request.user.*;
 import com.hfln.portal.common.response.user.UserInfoWxRes;
 import com.hfln.portal.domain.gateway.UserGateway;
 import com.hfln.portal.domain.gateway.sms.SmsGateway;
@@ -128,11 +127,16 @@ public class UserController {
         return ApiResult.success();
     }
 
-    @PostMapping("wap/user/logout")
+    @PostMapping("/logout")
     @ApiOperation(value = "用户注销")
     public ApiResult<?> logout(@RequestBody @Valid UserLogoutParams request){
         userGateway.logout(request);
         return ApiResult.success();
     }
 
+    @GetMapping("/checkPhone")
+    @ApiOperation(value = "校验手机号是否被注册")
+    public ApiResult<Boolean> checkPhone(@RequestParam String phone,@RequestParam String openid) {
+        return ApiResult.success(userGateway.checkPhone(phone, openid));
+    }
 }

+ 2 - 2
portal-service-application/src/test/java/com/hfln/portal/application/controller/wap/DeviceControllerTest.java

@@ -271,7 +271,7 @@ class DeviceControllerTest {
     void updateDeviceLocation_Success() {
         // 准备测试数据
         DeviceLocationParams params = new DeviceLocationParams();
-        params.setDeviceId(TEST_DEVICE_ID);
+        params.setDevId(TEST_DEVICE_ID);
         params.setXValue(new BigDecimal("100.5"));
         params.setYValue(200L);
         
@@ -293,7 +293,7 @@ class DeviceControllerTest {
     void updateDeviceLocation_Failed() {
         // 准备测试数据
         DeviceLocationParams params = new DeviceLocationParams();
-        params.setDeviceId(TEST_DEVICE_ID);
+        params.setDevId(TEST_DEVICE_ID);
         params.setXValue(new BigDecimal("100.5"));
         params.setYValue(200L);
         

+ 6 - 6
portal-service-application/src/test/java/com/hfln/portal/application/controller/wap/ShareControllerTest.java

@@ -163,30 +163,30 @@ class ShareControllerTest {
         );
 
         // 模拟 Gateway 行为
-        when(deviceGateway.queryShare(TEST_USER_ID)).thenReturn(expectedShares);
+        when(deviceGateway.queryDevShare(TEST_USER_ID)).thenReturn(expectedShares);
 
         // 执行测试
-        ApiResult<List<ShareDto>> result = shareController.queryShare(TEST_USER_ID);
+        ApiResult<List<ShareDto>> result = shareController.queryDevShare(TEST_USER_ID);
 
         // 验证结果
         assertEquals(SUCCESS_CODE, result.getCode());
         assertEquals(2, result.getData().size());
         assertEquals(expectedShares, result.getData());
-        verify(deviceGateway, times(1)).queryShare(TEST_USER_ID);
+        verify(deviceGateway, times(1)).queryDevShare(TEST_USER_ID);
     }
 
     @Test
     void queryShare_EmptyResult() {
         // 模拟 Gateway 行为
-        when(deviceGateway.queryShare(TEST_USER_ID)).thenReturn(null);
+        when(deviceGateway.queryDevShare(TEST_USER_ID)).thenReturn(null);
 
         // 执行测试
-        ApiResult<List<ShareDto>> result = shareController.queryShare(TEST_USER_ID);
+        ApiResult<List<ShareDto>> result = shareController.queryDevShare(TEST_USER_ID);
 
         // 验证结果
         assertEquals(SUCCESS_CODE, result.getCode());
         assertNull(result.getData());
-        verify(deviceGateway, times(1)).queryShare(TEST_USER_ID);
+        verify(deviceGateway, times(1)).queryDevShare(TEST_USER_ID);
     }
 
     // ========== shareConfirm 测试用例 ==========

+ 62 - 5
portal-service-application/src/test/java/com/hfln/portal/application/controller/wap/UserControllerTest.java

@@ -486,8 +486,6 @@ class UserControllerTest {
         verify(userGateway, times(1)).loginBySmsCode(request);
     }
 
-
-
     @Test
     void getUserPhone_Success() {
         // 准备测试数据
@@ -530,10 +528,10 @@ class UserControllerTest {
         assertEquals(ErrorEnum.WECHAT_CODE_ISNULL.getErrorCode(), exception.getErrCode());
         assertEquals(ErrorEnum.WECHAT_CODE_ISNULL.getErrorMessage(), exception.getMessage());
 
-
         // 验证交互
         verify(userGateway, times(1)).getUserPhone(invalidCode);
     }
+
     @Test
     void getUserPhone_Exception() {
         // 准备测试数据
@@ -549,6 +547,67 @@ class UserControllerTest {
         verify(userGateway, times(1)).getUserPhone(code);
     }
 
+    @Test
+    void checkPhone_EmptyPhone() {
+        // 准备测试数据
+        String phone = "";
+        String openid = "test_openid";
+        
+        // 模拟UserGateway抛出异常
+        when(userGateway.checkPhone(phone, openid))
+                .thenThrow(new BizException(ErrorEnum.PHONE_IS_NULL.getErrorCode(), ErrorEnum.PHONE_IS_NULL.getErrorMessage()));
+        
+        // 执行测试并验证异常
+        BizException exception = assertThrows(BizException.class, 
+            () -> userController.checkPhone(phone, openid));
+        
+        // 验证异常内容
+        assertEquals(ErrorEnum.PHONE_IS_NULL.getErrorCode(), exception.getErrCode());
+        assertEquals(ErrorEnum.PHONE_IS_NULL.getErrorMessage(), exception.getMessage());
+        
+        // 验证交互
+        verify(userGateway, times(1)).checkPhone(phone, openid);
+    }
+
+    @Test
+    void checkPhone_PhoneExists() {
+        // 准备测试数据
+        String phone = "13800138000";
+        String openid = "test_openid";
+        
+        // 模拟UserGateway返回true表示手机号存在
+        when(userGateway.checkPhone(phone, openid)).thenReturn(true);
+        
+        // 执行测试
+        ApiResult<Boolean> result = userController.checkPhone(phone, openid);
+        
+        // 验证结果
+        assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
+        assertEquals(true, result.getData());
+        
+        // 验证交互
+        verify(userGateway, times(1)).checkPhone(phone, openid);
+    }
+
+    @Test
+    void checkPhone_PhoneNotExists() {
+        // 准备测试数据
+        String phone = "13800138000";
+        String openid = "test_openid";
+        
+        // 模拟UserGateway返回false表示手机号不存在
+        when(userGateway.checkPhone(phone, openid)).thenReturn(false);
+        
+        // 执行测试
+        ApiResult<Boolean> result = userController.checkPhone(phone, openid);
+        
+        // 验证结果
+        assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
+        assertEquals(false, result.getData());
+        
+        // 验证交互
+        verify(userGateway, times(1)).checkPhone(phone, openid);
+    }
 
     @Test
     void updatePassword_Success() {
@@ -617,8 +676,6 @@ class UserControllerTest {
         verify(userGateway, times(1)).logout(request);
     }
 
-
-
     // 辅助方法
     private PhoneLoginParams createTestPhoneLoginParams(String phone, String openId, String unionId) {
         PhoneLoginParams params = new PhoneLoginParams();

+ 1 - 1
portal-service-common/src/main/java/com/hfln/portal/common/request/device/DeviceLocationParams.java

@@ -18,7 +18,7 @@ public class DeviceLocationParams extends BaseVO {
 
     @NotEmpty(message = "设备Id不能为空!")
     @ApiModelProperty(value = "设备表Id",required = true)
-    private String deviceId;
+    private String devId;
 
     @ApiModelProperty(value = "X坐标")
     private BigDecimal xValue;

+ 1 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/exception/ErrorEnum.java

@@ -36,6 +36,7 @@ public enum ErrorEnum implements ErrorEnumInterface{
     USER_IS_NOT_EXIST("30005", "用户不存在"),
     PASSWORD_IS_REPEAT("30006", "新密码与旧密码相同"),
     USER_NAME_IS_NULL("30007", "用户名不能为空"),
+    PHONE_IS_NULL("30008", "手机号不能为空"),
 
     /**
      * 三方系统调用相关

+ 1 - 1
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/DeviceGateway.java

@@ -61,7 +61,7 @@ public interface DeviceGateway {
 
     Boolean shareByUrl(ShareParam shareParam);
 
-    List<ShareDto> queryShare(Long userId);
+    List<ShareDto> queryDevShare(Long userId);
 
     void shareConfirm(ShareConfirmParam shareConfirmParam);
 

+ 2 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/UserGateway.java

@@ -42,4 +42,6 @@ public interface UserGateway {
     String authUrl();
 
     String callback(String code);
+
+    boolean checkPhone(String phone, String code);
 }

+ 3 - 3
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java

@@ -316,7 +316,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
 
         DevInfo devInfo = devInfoService.getOne(
                 Wrappers.<DevInfo>lambdaQuery()
-                        .eq(DevInfo::getDevId, params.getDeviceId()));
+                        .eq(DevInfo::getDevId, params.getDevId()));
         if (Objects.isNull(devInfo)) {
             throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
         }
@@ -333,7 +333,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
             return false;
         }
 
-        updateWrapper.eq(DevInfo::getDevId, params.getDeviceId());
+        updateWrapper.eq(DevInfo::getDevId, params.getDevId());
         updateWrapper.eq(DevInfo::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
 
         return devInfoService.update(updateWrapper);
@@ -449,7 +449,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
     }
 
     @Override
-    public List<ShareDto> queryShare(Long userId) {
+    public List<ShareDto> queryDevShare(Long userId) {
 
         List<DevShare> shares = devShareService.queryBySharedUserId(userId);
         if (CollectionUtils.isEmpty(shares)) {

+ 26 - 2
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/UserGatewayImpl.java

@@ -11,12 +11,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.hfln.portal.common.constant.redis.RedisCacheConstant;
 import com.hfln.portal.common.dto.data.user.UserDto;
 import com.hfln.portal.common.request.user.*;
-import com.hfln.portal.common.request.user.*;
 import com.hfln.portal.common.response.user.UserInfoWxRes;
 import com.hfln.portal.domain.customer.util.PasswordUtil;
 import com.hfln.portal.domain.exception.ErrorEnum;
 import com.hfln.portal.domain.gateway.UserGateway;
-import com.hfln.portal.infrastructure.mapper.UserInfoMapper;
 import com.hfln.portal.infrastructure.po.DevGroup;
 import com.hfln.portal.infrastructure.po.DevInfo;
 import com.hfln.portal.infrastructure.po.DevShare;
@@ -392,4 +390,30 @@ public class UserGatewayImpl implements UserGateway {
                         .set(GroupShare::getIsDeleted, 1)
         );
     }
+
+    @Override
+    public boolean checkPhone(String phone, String openid) {
+        // 1. 校验手机号是否为空
+        if (StringUtils.isEmpty(phone)) {
+            throw new BizException(ErrorEnum.PHONE_IS_NULL.getErrorCode(), ErrorEnum.PHONE_IS_NULL.getErrorMessage());
+        }
+
+        // 2. 查询手机号是否存在
+        UserInfo userInfo = userService.getOne(
+            Wrappers.<UserInfo>lambdaQuery()
+                .eq(UserInfo::getPhone, phone)
+        );
+
+        // 3. 如果存在,更新openid
+        if (Objects.nonNull(userInfo)) {
+            UserInfo updateUser = new UserInfo();
+            updateUser.setUserId(userInfo.getUserId());
+            updateUser.setOpenid(openid);
+            userService.updateById(updateUser);
+            return true;
+        }
+
+        // 4. 如果不存在,返回false表示该号码未注册
+        return false;
+    }
 }

+ 9 - 4
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSubHandle.java

@@ -12,6 +12,7 @@ import com.hfln.portal.domain.customer.util.WxOfficeAccountClient;
 import com.hfln.portal.infrastructure.po.*;
 import com.hfln.portal.infrastructure.service.*;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -186,8 +187,10 @@ public class MqttSubHandle {
                     log.info("mqttutil--当前useropenid=" + user.getOpenid() + ", fwhopenId=" + fwhOpenId);
                     log.info("发送微信公众号信息:devName=" + devName.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
                     // 发送微信公告号消息
-                    wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到跌倒,请前往小程序查看详细信息");
-                    log.info("发送微信公众号消息发完了");
+                    if (StringUtils.contains(devName.toString(), "卫生间")) {
+                        wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到异常滞留,请前往小程序查看详细信息");
+                        log.info("发送微信公众号消息发完了");
+                    }
                 }
 
             }
@@ -237,8 +240,10 @@ public class MqttSubHandle {
                 log.info("mqttutil--当前useropenid=" + user.getOpenid() + ", fwhopenId=" + fwhOpenId);
                 log.info("发送微信公众号信息:devName=" + devName.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
                 // 发送微信公告号消息
-                wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到跌倒,请前往小程序查看详细信息");
-                log.info("发送微信公众号消息发完了");
+                if (StringUtils.contains(devName.toString(), "卫生间")) {
+                    wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到异常滞留,请前往小程序查看详细信息");
+                    log.info("发送微信公众号消息发完了");
+                }
             }
 
         }