Quellcode durchsuchen

fix: 修复微信登陆登陆天数累加缺陷

hidewnd vor 1 Monat
Ursprung
Commit
6241795198

+ 5 - 0
yt-question/yt-question-service/src/main/java/com/ytpm/question/dao/LoginRecordMapper.java

@@ -19,6 +19,11 @@ public interface LoginRecordMapper {
      */
     List<YtDyzLoginRecord> getLoginRecords(@Param("userId")String userId);
 
+    /**
+     * 查询最近一次登陆记录
+     */
+    YtDyzLoginRecord getLastLoginRecord(@Param("userId")String userId, @Param("isVisitor") Integer  isVisitor);
+
     List<YtDyzLoginRecord> getLoginRecordByIds(@Param("userIds")String userIds);
 
     List<String> queryLoginCount(AppUserQueryParam appUserQueryParam);

+ 8 - 1
yt-question/yt-question-service/src/main/java/com/ytpm/question/service/impl/AppUserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ytpm.question.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
@@ -134,7 +135,13 @@ public class AppUserServiceImpl implements AppUserService {
         newUser.setPhone(param.getPhone());
         newUser.setPhoneJson(param.getPhoneJson());
         newUser.setDeviceId(param.getDeviceId());
-        newUser.setLoginDays(old.getLoginDays() + 1);
+        YtDyzLoginRecord wxLoginRecord = loginRecordMapper.getLastLoginRecord(old.getUserId(), 0);
+        YtDyzLoginRecord visitorLoginRecord = loginRecordMapper.getLastLoginRecord(old.getUserId(), 1);
+        if (wxLoginRecord == null && visitorLoginRecord == null
+                || wxLoginRecord != null && wxLoginRecord.getLoginTime() != null
+                && DateUtil.compare(wxLoginRecord.getLoginTime(), newUser.getLastLoginTime(), "yyyy-MM-dd") < 0) {
+            newUser.setLoginDays(old.getLoginDays() + 1);
+        }
         appUserMapper.updateUser(newUser);
     }
 

+ 14 - 0
yt-question/yt-question-service/src/main/resources/mapper/LoginRecordMapper.xml

@@ -73,4 +73,18 @@
         from yt_dyz_login_record
         where user_id = #{userId} and DATE(login_time) = current_date()
     </select>
+    <select id="getLastLoginRecord" resultType="com.ytpm.app.model.YtDyzLoginRecord">
+        select
+            record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
+        from yt_dyz_login_record
+        where user_id = #{userId}
+        <if test="isVisitor != null and isVisitor == 1">
+            and login_type = 'VISITOR'
+        </if>
+        <if test="isVisitor != null and isVisitor == 0">
+            and (login_type is null or login_type = '')
+        </if>
+        order by login_time desc
+        limit 1
+    </select>
 </mapper>