Bladeren bron

打卡广场详情 店铺不存在提示

dujian 2 dagen geleden
bovenliggende
commit
f6ca526862

+ 15 - 1
alien-entity/src/main/java/shop/alien/entity/result/R.java

@@ -63,7 +63,7 @@ public class R<T> implements Serializable {
      */
     public static boolean isSuccess(@Nullable R<?> result) {
         return Optional.ofNullable(result)
-                .map(x -> ObjectUtils.nullSafeEquals(ResultCode.SUCCESS.code, x.code))
+                .map(x -> ObjectUtils.nullSafeEquals(ResultCode.SUCCESS.code, x.code) && x.isSuccess())
                 .orElse(Boolean.FALSE);
     }
 
@@ -158,6 +158,20 @@ public class R<T> implements Serializable {
         return new R<>(ResultCode.FAILURE, msg);
     }
 
+    /**
+     * 业务失败但 body 中 {@code code} 仍为 HTTP 200({@link APPConstant#SC_OK}),与部分移动端约定一致:
+     * 仅当 {@code success=false} 时表示失败;拦截器在 {@code code==200} 时仍 resolve 整包 JSON,便于展示 {@code msg}。
+     *
+     * @param msg 提示文案(如「当前店铺已删除。」)
+     */
+    public static <T> R<T> failWithOkStatus(String msg) {
+        R<T> r = new R<>();
+        r.setCode(APPConstant.SC_OK);
+        r.setSuccess(false);
+        r.setData(null);
+        r.setMsg(msg);
+        return r;
+    }
 
     /**
      * 返回R

+ 5 - 1
alien-store/src/main/java/shop/alien/store/controller/StoreClockInController.java

@@ -114,7 +114,11 @@ public class StoreClockInController {
     public R<StoreClockInVo> getStoreClockInById(@ApiIgnore @TokenInfo UserLoginInfo userLoginInfo, Integer id) {
         Integer userId = userLoginInfo != null ? userLoginInfo.getUserId() : null;
         log.info("StoreClockInController.getStoreClockInById?userId={},id={}", userId, id);
-        return R.data(storeClockInService.getStoreClockInById(id, userId));
+        try {
+            return R.data(storeClockInService.getStoreClockInById(id, userId));
+        } catch (IllegalArgumentException e) {
+            return R.failWithOkStatus(e.getMessage());
+        }
     }
 
     @ApiOperation("打卡记录筛选校验(年份各月是否有打卡、可选城市过滤、用户打卡涉及城市列表)")

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/StoreClockInService.java

@@ -43,7 +43,8 @@ public interface StoreClockInService extends IService<StoreClockIn> {
      *
      * @param id 主键id
      * @param userId 当前登录用户ID(用于查询收藏状态)
-     * @return 打卡记录
+     * @return 打卡记录;无此打卡时返回 null
+     * @throws IllegalArgumentException 打卡存在但门店不可用(如已逻辑删除)时抛出,消息为「当前店铺已删除。」,由控制层转为 {@code R.fail}
      */
     StoreClockInVo getStoreClockInById(Integer id, Integer userId);
 

+ 4 - 1
alien-store/src/main/java/shop/alien/store/service/impl/StoreClockInServiceImpl.java

@@ -482,12 +482,15 @@ public class StoreClockInServiceImpl extends ServiceImpl<StoreClockInMapper, Sto
     @Override
     public StoreClockInVo getStoreClockInById(Integer id, Integer userId) {
         StoreClockIn storeClockIn = storeClockInMapper.selectById(id);
-        StoreClockInVo storeClockInVo = BeanUtil.copyProperties(storeClockIn, StoreClockInVo.class);
         if (null == storeClockIn) {
             return null;
         }
+        StoreClockInVo storeClockInVo = BeanUtil.copyProperties(storeClockIn, StoreClockInVo.class);
 
         StoreInfo storeInfo = storeInfoMapper.selectById(storeClockIn.getStoreId());
+        if (storeInfo == null) {
+            throw new IllegalArgumentException("当前店铺已删除");
+        }
         // 店铺名称
         storeClockInVo.setStoreName(storeInfo.getStoreName());
         storeClockInVo.setStoreBlurb(storeInfo.getStoreBlurb());