Эх сурвалжийг харах

fix(address): 修复地址查询未过滤已删除记录的问题并更新默认地址时间戳

在地址查询方法中添加 is_deleted = 0 条件以过滤已删除记录
在设置默认地址时同时更新 update_time 字段
skyfffire 1 долоо хоног өмнө
parent
commit
b08827fac4

+ 5 - 4
src/main/java/modules/address/AddressService.java

@@ -10,11 +10,11 @@ public class AddressService {
     private final Address dao = new Address().dao();
 
     public List<Address> findByUserId(Long userId) {
-        return dao.find("select * from t_address where user_id = ? order by is_default desc, id desc", userId);
+        return dao.find("select * from t_address where user_id = ? and is_deleted = 0 order by is_default desc, id desc", userId);
     }
 
     public Address findById(int id, Long userId) {
-        return dao.findFirst("select * from t_address where id = ? and user_id = ?", id, userId);
+        return dao.findFirst("select * from t_address where id = ? and user_id = ? and is_deleted = 0", id, userId);
     }
 
     public boolean save(Address address) {
@@ -46,10 +46,11 @@ public class AddressService {
     public boolean setDefault(int id, Long userId) {
         // 开启事务
         return Db.tx(() -> {
+            long currentTime = System.currentTimeMillis();
             // 先将该用户所有地址设为非默认
-            Db.update("update t_address set is_default = 0 where user_id = ?", userId);
+            Db.update("update t_address set is_default = 0, update_time = ? where user_id = ?", currentTime, userId);
             // 再将指定地址设为默认
-            return Db.update("update t_address set is_default = 1 where id = ? and user_id = ?", id, userId) > 0;
+            return Db.update("update t_address set is_default = 1, update_time = ? where id = ? and user_id = ?", currentTime, id, userId) > 0;
         });
     }
 }