日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

【技术改造】电商系统用户模块集成Feign-1

發布時間:2024/4/13 windows 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【技术改造】电商系统用户模块集成Feign-1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
@FeignClient("foodie-user-service") @RequestMapping("user-api") public interface UserService {/*** 判斷用戶名是否存在*/@GetMapping("user/exists")public boolean queryUsernameIsExist(@RequestParam("username") String username);/*** 判斷用戶名是否存在*/@PostMapping("user")public Users createUser(@RequestBody UserBO userBO);/*** 檢索用戶名和密碼是否匹配,用于登錄*/@GetMapping("verify")public Users queryUserForLogin(@RequestParam("username") String username,@RequestParam("password") String password); } @FeignClient("foodie-user-service") @RequestMapping("address-api") public interface AddressService {/*** 根據用戶id查詢用戶的收貨地址列表* @param userId* @return*/@GetMapping("addressList")public List<UserAddress> queryAll(@RequestParam("userId") String userId);/*** 用戶新增地址* @param addressBO*/@PostMapping("address")public void addNewUserAddress(@RequestBody AddressBO addressBO);/*** 用戶修改地址* @param addressBO*/@PutMapping("address")public void updateUserAddress(@RequestBody AddressBO addressBO);/*** 根據用戶id和地址id,刪除對應的用戶地址信息* @param userId* @param addressId*/@DeleteMapping("address")public void deleteUserAddress(@RequestParam("userId") String userId,@RequestParam("addressId") String addressId);/*** 修改默認地址* @param userId* @param addressId*/@PostMapping("setDefaultAddress")public void updateUserAddressToBeDefault(@RequestParam("userId") String userId,@RequestParam("addressId") String addressId);/*** 根據用戶id和地址id,查詢具體的用戶地址對象信息* @param userId* @param addressId* @return*/@GetMapping("queryAddress")public UserAddress queryUserAddres(@RequestParam("userId") String userId,@RequestParam(value = "addressId", required = false) String addressId); } spring:application:name: foodie-user-service### Feign - 當Bean名字一樣的時候,允許覆蓋注冊main:allow-bean-definition-overriding: true @FeignClient("foodie-item-service") @RequestMapping("item-api") public interface ItemService {/*** 根據商品ID查詢詳情* @param itemId* @return*/@GetMapping("item")public Items queryItemById(@RequestParam("itemId") String itemId);/*** 根據商品id查詢商品圖片列表* @param itemId* @return*/@GetMapping("itemImages")public List<ItemsImg> queryItemImgList(@RequestParam("itemId")String itemId);/*** 根據商品id查詢商品規格* @param itemId* @return*/@GetMapping("itemSpecs")public List<ItemsSpec> queryItemSpecList(@RequestParam("itemId")String itemId);/*** 根據商品id查詢商品參數* @param itemId* @return*/@GetMapping("itemParam")public ItemsParam queryItemParam(@RequestParam("itemId") String itemId);/*** 根據商品id查詢商品的評價等級數量* @param itemId*/@GetMapping("countComments")public CommentLevelCountsVO queryCommentCounts(@RequestParam("itemId") String itemId);/*** 根據商品id查詢商品的評價(分頁)* @param itemId* @param level* @return*/@GetMapping("pagedComments")public PagedGridResult queryPagedComments(@RequestParam("itemId") String itemId,@RequestParam(value = "level", required = false) Integer level,@RequestParam(value = "page", required = false) Integer page,@RequestParam(value = "pageSize", required = false) Integer pageSize);// /** // * 搜索商品列表 // * @param keywords // * @param sort // * @param page // * @param pageSize // * @return // */ // public PagedGridResult searhItems(String keywords, String sort, // Integer page, Integer pageSize); // // /** // * 根據分類id搜索商品列表 // * @param catId // * @param sort // * @param page // * @param pageSize // * @return // */ // public PagedGridResult searhItems(Integer catId, String sort, // Integer page, Integer pageSize);/*** 根據規格ids查詢最新的購物車中商品數據(用于刷新渲染購物車中的商品數據)* @param specIds* @return*/@GetMapping("getCartBySpecIds")public List<ShopcartVO> queryItemsBySpecIds(@RequestParam("specIds") String specIds);/*** 根據商品規格id獲取規格對象的具體信息* @param specId* @return*/@GetMapping("singleItemSpec")public ItemsSpec queryItemSpecById(@RequestParam("specId") String specId);/*** 根據商品id獲得商品圖片主圖url* @param itemId* @return*/@GetMapping("primaryImage")public String queryItemMainImgById(@RequestParam("itemId") String itemId);/*** 減少庫存* @param specId* @param buyCounts*/@PostMapping("decreaseStock")public void decreaseItemSpecStock(@RequestParam("specId") String specId,@RequestParam("buyCounts") int buyCounts); } /*** 內部的降級(商品中心),放到item-server里面來實現** 調用方降級(訂單中心,調用商品中心服務),由訂單中心定義降級邏輯** Created by 半仙.*/ @FeignClient("foodie-item-service") @RequestMapping("item-comments-api") public interface ItemCommentsService {/*** 我的評價查詢 分頁* @param userId* @param page* @param pageSize* @return*/@GetMapping("myComments")public PagedGridResult queryMyComments(@RequestParam("userId") String userId,@RequestParam(value = "page", required = false) Integer page,@RequestParam(value = "pageSize", required = false)Integer pageSize);@PostMapping("saveComments")public void saveComments(@RequestBody Map<String, Object> map);} @Autowired // private ItemCommentsService itemCommentsService; private ItemCommentsFeignClient itemCommentsService; Map<String, Object> map = new HashMap<>(); map.put("userId", userId); map.put("commentList", commentList); itemCommentsService.saveComments(map); // TODO 學了Feign在來把注釋打開 @Autowired private AddressService addressService; @Autowired private ItemService itemService; String orderId = sid.nextShort(); UserAddress address = addressService.queryUserAddres(userId, addressId); // 2.2 根據商品id,獲得商品信息以及商品圖片 String itemId = itemSpec.getItemId(); Items item = itemService.queryItemById(itemId); String imgUrl = itemService.queryItemMainImgById(itemId); // 2.4 在用戶提交訂單以后,規格表中需要扣除庫存 itemService.decreaseItemSpecStock(itemSpecId, buyCounts); @SpringBootApplication // 掃描 mybatis 通用 mapper 所在的包 @MapperScan(basePackages = "com.leon.order.mapper") // 掃描所有包以及相關組件包 @ComponentScan(basePackages = {"com.leon", "org.n3r.idworker"}) @EnableDiscoveryClient @EnableScheduling @EnableFeignClients(clients = {ItemCommentsFeignClient.class,ItemService.class,UserService.class,AddressService.class} // basePackages = { // "com.leon.user.service", // "com.leon.item.service", // "com.leon.order.fallback.itemservice" // } ) public class OrderApplication {public static void main(String[] args) {SpringApplication.run(OrderApplication.class, args);}} @Autowired // private ItemCommentsService itemCommentsService; private ItemCommentsFeignClient itemCommentsService; PagedGridResult grid = itemCommentsService.queryMyComments(userId,page,pageSize); @ConfigurationProperties("eureka.instance") public class EurekaInstanceConfigBeanimplements CloudEurekaInstanceConfig, EnvironmentAware { /*** Flag to say that, when guessing a hostname, the IP address of the server should be* used in prference to the hostname reported by the OS.*/ private boolean preferIpAddress = false; @Override public String getHostName(boolean refresh) {if (refresh && !this.hostInfo.override) {this.ipAddress = this.hostInfo.getIpAddress();this.hostname = this.hostInfo.getHostname();}return this.preferIpAddress ? this.ipAddress : this.hostname; } @RestController public class MyCommentsServiceImpl extends BaseService implements MyCommentsService {

?

總結

以上是生活随笔為你收集整理的【技术改造】电商系统用户模块集成Feign-1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。