Explorar el Código

登录时更新设备类型

黄远 hace 5 años
padre
commit
57f2a514f3

+ 57 - 0
lift-common/src/main/java/cn.com.ty.lift.common/constants/WebSocketConstants.java

@@ -0,0 +1,57 @@
+package cn.com.ty.lift.common.constants;
+
+/**
+ * @author huangyuan
+ * @date 2020/4/29
+ * @description 消息推送常量
+ */
+public class WebSocketConstants {
+
+    /**
+     * 推送当前用户信息
+     */
+    public static final String CURRENT_TIMEY_USER = "currentTimeyUser";
+
+    /**
+     * 查看标识 已经查看
+     */
+    public static final int IS_VIEW = 1;
+
+    public static final int IS_NOT_VIEW = 0;
+
+    /**
+     * 消息类型
+     */
+    public interface MessageType {
+        /**
+         * 团队消息
+         */
+        int TEAM_MSG = 1;
+
+        /**
+         * 工作消息
+         */
+        int WORK_MSG = 2;
+
+        /**
+         * 保养消息
+         */
+        int MAINTENANCE_MSG = 3;
+
+        /**
+         * 急修消息
+         */
+        int EMERGENCY_MSG = 4;
+
+        /**
+         * 年检
+         */
+        int INSPECTION_MSG = 5;
+
+        /**
+         * 提醒(消息简报)
+         */
+        int TIPS_MSG = 6;
+    }
+
+}

+ 49 - 0
lift-common/src/main/java/cn.com.ty.lift.common/model/TimeyMessage.java

@@ -0,0 +1,49 @@
+package cn.com.ty.lift.common.model;
+
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-22
+ * @description 实时推送消息实体类
+ */
+@Data
+public class TimeyMessage {
+
+    /**
+     * 消息id
+     */
+    private Long id;
+
+    /**
+     * 用户id,用推送的用户id
+     */
+    private Long userId;
+
+    /**
+     * 推送消息内容
+     */
+    private String content;
+
+    /**
+     * 消息类型 1.团队消息 2.工作消息 3.保养消息 4.急修消息 5.年检消息 6.提醒(经营简报)
+     */
+    private Integer type;
+
+    /**
+     * 查看标识:1:已经查看, 0:未查看
+     */
+    private Integer viewFlag;
+
+    /**
+     * 创建者id
+     */
+    private Long createUserId;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+}

+ 20 - 0
lift-common/src/main/java/cn.com.ty.lift.common/model/TimeyUser.java

@@ -0,0 +1,20 @@
+package cn.com.ty.lift.common.model;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-22
+ * @description 实时消息用户信息类
+ */
+@Data
+public class TimeyUser {
+    /**
+     * 用户id
+     */
+    private Long userId;
+    /**
+     * 用户昵称
+     */
+    private String userName;
+}

+ 2 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/dao/entity/model/UserRequest.java

@@ -24,6 +24,8 @@ public class UserRequest {
     private String authCode;//微信授权码
     private String appletOpenId;//小程序标识码
     private String weChatOpenId;//用户微信标识码
+    private Integer deviceModel;//设备类型
+    private String deviceFlag;//设备标识
     private Integer mobileType;//端类型
     private Long pageSize;//每页条数
     private Long pageNum;//页数

+ 1 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IUserLoginService.java

@@ -21,6 +21,6 @@ public interface IUserLoginService extends IService<UserLogin> {
      * @param
      * @return
      */
-    void saveLoginInfo(HttpServletRequest request, Long userId);
+    boolean saveLoginInfo(HttpServletRequest request, Long userId);
 
 }

+ 19 - 4
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/LoginService.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -98,6 +99,8 @@ public class LoginService implements ILoginService {
     @Override
     public RestResponse login(HttpServletRequest request, UserRequest userRequest) {
         String password = userRequest.getPassword();
+        //登录端类型
+        Integer mobileType = userRequest.getMobileType();
         if (StringUtils.isBlank(userRequest.getMobile())) {
             return RestResponse.fail(ApiConstants.RESULT_ERROR, "手机号为空无法登录");
         }
@@ -119,8 +122,8 @@ public class LoginService implements ILoginService {
         int userType = userAccount.getType() != null ? userAccount.getType() : ApiConstants.UserConstants.TYPE_USER;
         if (ApiConstants.UserConstants.PUBLIC_TYPE_USER == userType) {
             //物管端用户,查看登录端
-            if (ApiConstants.ACCESS_TYPE_APPLETS == userRequest.getMobileType()
-                    || ApiConstants.ACCESS_TYPE_PC == userRequest.getMobileType()) {
+            if (ApiConstants.ACCESS_TYPE_APPLETS == mobileType
+                    || ApiConstants.ACCESS_TYPE_PC == mobileType) {
                 return RestResponse.fail(ApiConstants.RESULT_ERROR, "没有登录权限");
             }
         }
@@ -133,7 +136,20 @@ public class LoginService implements ILoginService {
         //登录成功后初始化登录信息
         UserResponse userResponse = initLoginInfo(request, userRequest);
         //添加登录记录
-        userLoginService.saveLoginInfo(request, userAccount.getUserId());
+        if (!userLoginService.saveLoginInfo(request, userAccount.getUserId())) {
+            return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存登录记录失败");
+        }
+        //将登录设备类型更新到数据库
+        if (ApiConstants.ACCESS_TYPE_APP == mobileType) {
+            //设备类型: 1.Android 2:IOS
+            userAccount.setDeviceModel(userRequest.getDeviceModel());
+            //设备唯一标识
+            userAccount.setDeviceFlag(userRequest.getDeviceFlag());
+            if (!userAccountService.updateById(userAccount)) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return RestResponse.fail(ApiConstants.RESULT_ERROR, "更新设备类型失败");
+            }
+        }
         return RestResponse.success(userResponse, ApiConstants.RESULT_SUCCESS, "登录成功");
     }
 
@@ -145,7 +161,6 @@ public class LoginService implements ILoginService {
     public Object getLoginUserInfoFromRedis(UserRequest userRequest) {
         Object mobileUserInfo = getUserInfoKeyInRedis(userRequest);
         //获取电话是否在redis中存在
-        assert mobileUserInfo != null;
         return redisTemplate.opsForValue().get(mobileUserInfo);
     }
 

+ 2 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserLoginService.java

@@ -21,12 +21,12 @@ import javax.servlet.http.HttpServletRequest;
 public class UserLoginService extends ServiceImpl<UserLoginMapper, UserLogin> implements IUserLoginService {
 
     @Override
-    public void saveLoginInfo(HttpServletRequest request, Long userId){
+    public boolean saveLoginInfo(HttpServletRequest request, Long userId){
         UserLogin userLogin = new UserLogin();
         userLogin.setUserId(userId);
         userLogin.setIp(CommonUtil.getIpAddress(request));
         //添加登录记录
-        this.save(userLogin);
+        return this.save(userLogin);
     }
 
 }