Quellcode durchsuchen

fix:答题限制体力不能为0BugFix

zack vor 2 Wochen
Ursprung
Commit
87619c16be

+ 5 - 0
yt-ios-lemon/lemon-ios-service/src/main/java/com/ytpm/lemonios/dao/LoginRecordMapper.java

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

+ 15 - 4
yt-ios-lemon/lemon-ios-service/src/main/java/com/ytpm/lemonios/service/impl/AppUserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ytpm.lemonios.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;
@@ -209,7 +210,13 @@ public class AppUserServiceImpl implements AppUserService {
         newUser.setLastLoginIp(param.getLoginIp());
         newUser.setPhone(param.getPhone());
         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);
     }
 
@@ -240,10 +247,14 @@ public class AppUserServiceImpl implements AppUserService {
         newUser.setLastLoginIp(param.getLoginIp());
         newUser.setPhone(param.getPhone());
         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);
-        YtDyzUser oldUser = appUserMapper.selectById(newUser.getUserId());
-        System.out.println(oldUser);
     }
 
     /**

+ 3 - 3
yt-ios-lemon/lemon-ios-service/src/main/java/com/ytpm/lemonios/service/impl/QuestionServiceImpl.java

@@ -56,14 +56,14 @@ public class QuestionServiceImpl implements QuestionService {
         if(!UserStatusEnum.NORMAL.getCode().equals(user.getUserStatus())){
             return new Result<>(StatusCode.ACCESS_ERR,"当前用户处于风控中");
         }
+        if (user.getPower() == null || user.getPower() <= 0) {
+            return new Result<>(StatusCode.ACCESS_ERR, "用户体力不足,无法答题");
+        }
         YtDyzAnswerRecord record = new YtDyzAnswerRecord();
         BeanUtil.copyProperties(param,record);
         record.setRecordId(IdUtil.fastSimpleUUID());
         record.setAnswerTime(new Date());
         questionMapper.saveAnswerRecord(record);
-        if (user.getPower() == null || user.getPower()<= 1) {
-            return new Result<>(StatusCode.ACCESS_ERR, "用户体力不足,无法答题");
-        }
         appUserMapper.subOnePower(param.getUserId());
         YtDyzPowerRecord powerRecord = new YtDyzPowerRecord();
         powerRecord.setUserId(param.getUserId());

+ 14 - 1
yt-ios-lemon/lemon-ios-service/src/main/resources/mapper/LoginRecordMapper.xml

@@ -71,5 +71,18 @@
         </foreach>
     </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>