网站首页 > 技术文章 正文
常规写法
@FeignClient(name = "middle-platform", contextId = "ai")
public interface AiAccountApiClient {
/**
* 扣减库存
* @return Result<SendMessagesResponse>
*/
@PostMapping("/v1/ai/aiAccountFrequency/deduction")
Result<Long> deduction(@RequestBody @Valid AiAccountDeductionRequest request);
}
优雅写法
避免每次都需要判断请求状态码
package com.zhijian.staff.app.commons.client;
import com.zhijian.base.common.model.dto.ZBizException;
import com.zhijian.base.common.model.response.Result;
import com.zhijian.staff.app.commons.client.request.ai.AiAccountDeductionRequest;
import com.zhijian.staff.app.commons.enums.AiApplicationBizCodeEnum;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid;
import java.util.List;
/**
* 短信client
*
* @author zhao
*/
@FeignClient(name = "middle-platform", contextId = "ai")
public interface AiAccountApiClient {
/**
* 扣减库存
* @return Result<SendMessagesResponse>
*/
@PostMapping("/v1/ai/aiAccountFrequency/deduction")
Result<Long> deduction(@RequestBody @Valid AiAccountDeductionRequest request);
default void deductionDeafult( AiAccountDeductionRequest request){
Result<Long> deduction = deduction(request);
if(deduction.getStatus() != 200){
throw new ZBizException(AiApplicationBizCodeEnum.CURRENT_USER_HAS_NO_AVAILABLE_TIMES_ERROR);
}
}
}
猜你喜欢
- 2025-07-28 如何优雅的实现 Spring Boot 接口参数加密解密?
- 2025-07-28 SpringBoot注解最全详解(9大常用注解)
- 2025-07-28 SpringBoot注解全攻略:这些注解让你的代码更专业!
- 2025-07-28 后端使用技术 —— 规范统一入口方法
- 2025-07-28 答应我,不要再用 Map 做出入参了好吗
- 2025-07-28 自研分布式高性能RPC框架及服务注册中心ApiRegistry实践笔记
- 2025-07-28 spring基础面试题整理(2)(spring基本面试题)
- 2025-07-28 Spring Boot异常处理太难搞,这样实现让你轻松应对!
- 2025-07-28 独立开发:高效集成大模型,看这篇就够了
- 2025-07-28 Spring&SpringBoot常用注解总结
- 1518℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 600℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 521℃MySQL service启动脚本浅析(r12笔记第59天)
- 490℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 489℃启用MySQL查询缓存(mysql8.0查询缓存)
- 477℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 457℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 454℃MySQL server PID file could not be found!失败
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- windowsscripthost (69)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- c语言min函数头文件 (68)
- asynccallback (71)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)