买家端联调bug
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.aida.buyer.module.account.controller;
|
||||
|
||||
import com.aida.buyer.common.context.UserContext;
|
||||
import com.aida.buyer.common.result.Response;
|
||||
import com.aida.buyer.module.account.dto.*;
|
||||
import com.aida.buyer.module.account.service.IBuyerAccountService;
|
||||
@@ -67,4 +68,10 @@ public class BuyerAccountController {
|
||||
public Response<BindEmailVO> bindEmail(@Valid @RequestBody BindEmailDTO dto) {
|
||||
return buyerAccountService.bindEmail(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
@Operation(summary = "登出:清除本地 token 并将用户加入 gateway 黑名单")
|
||||
public Response<Boolean> logout(@RequestBody LogoutDTO dto) {
|
||||
return buyerAccountService.logout(dto.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.aida.buyer.module.account.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "登出请求")
|
||||
public class LogoutDTO {
|
||||
|
||||
@NotNull(message = "userId is required")
|
||||
@Schema(description = "用户ID")
|
||||
private Long userId;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.aida.buyer.module.account.feign;
|
||||
|
||||
import com.aida.buyer.common.result.Response;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* 调用 Gateway 黑名单接口,将指定用户的 token 加入黑名单。
|
||||
*/
|
||||
@FeignClient(name = "aida-gateway", path = "/internal")
|
||||
public interface GatewayFeignClient {
|
||||
|
||||
/**
|
||||
* 将用户 token 加入黑名单。
|
||||
* Gateway 会拒绝携带该用户 token 的后续请求。
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
Response<Void> logout(@RequestParam("userId") Long userId);
|
||||
}
|
||||
@@ -21,4 +21,6 @@ public interface IBuyerAccountService {
|
||||
Response<Boolean> sendEmailChangeCode(SendEmailCodeDTO dto);
|
||||
|
||||
Response<BindEmailVO> bindEmail(BindEmailDTO dto);
|
||||
|
||||
Response<Boolean> logout(Long userId);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.aida.buyer.common.exception.BusinessException;
|
||||
import com.aida.buyer.model.vo.AuthPrincipalVo;
|
||||
import com.aida.buyer.module.account.entity.BuyerAccount;
|
||||
import com.aida.buyer.module.account.mapper.BuyerAccountMapper;
|
||||
import com.aida.buyer.module.account.feign.GatewayFeignClient;
|
||||
import com.aida.buyer.module.account.service.IBuyerAccountService;
|
||||
import com.aida.buyer.util.LoginCacheUtil;
|
||||
import com.aida.buyer.util.RandomsUtil;
|
||||
@@ -26,6 +27,7 @@ public class BuyerAccountServiceImpl implements IBuyerAccountService {
|
||||
private final BuyerAccountMapper buyerAccountMapper;
|
||||
private final TokenGenerateUtils tokenGenerateUtils;
|
||||
private final RedisLoginUtil redisLoginUtil;
|
||||
private final GatewayFeignClient gatewayFeignClient;
|
||||
|
||||
@Override
|
||||
public Response<Boolean> sendCode(SendCodeDTO dto) {
|
||||
@@ -274,4 +276,16 @@ public class BuyerAccountServiceImpl implements IBuyerAccountService {
|
||||
|
||||
return Response.success(new BindEmailVO(account.getId(), newEmail));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Boolean> logout(Long userId) {
|
||||
redisLoginUtil.deleteLoginToken(userId);
|
||||
try {
|
||||
gatewayFeignClient.logout(userId);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to add token to gateway blacklist, userId={}, error={}", userId, e.getMessage());
|
||||
}
|
||||
log.info("Buyer logged out, userId={}", userId);
|
||||
return Response.success(Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,7 @@ public class CartItemDTO implements Serializable {
|
||||
|
||||
@Schema(description = "加入购物车时间")
|
||||
private LocalDateTime addTime;
|
||||
|
||||
/** 店铺名称 */
|
||||
private String shopName;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ public class CartServiceImpl implements ICartService {
|
||||
dto.setStatus(listing.getStatus());
|
||||
dto.setProductCategory(listing.getProductCategory());
|
||||
dto.setAddTime(item.getAddTime());
|
||||
dto.setShopName(listing.getShopName());
|
||||
return dto;
|
||||
})
|
||||
.toList();
|
||||
|
||||
@@ -29,4 +29,7 @@ public class ListingMallVO implements Serializable {
|
||||
|
||||
/** 商品分类列表 */
|
||||
private List<String> productCategory;
|
||||
|
||||
/** 店铺名称 */
|
||||
private String shopName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user