Api06Controller.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.modules.api.controller;
  18. import com.baomidou.mybatisplus.core.metadata.IPage;
  19. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  20. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import io.swagger.annotations.ApiParam;
  24. import lombok.AllArgsConstructor;
  25. import org.springblade.common.constant.CacheBizConstant;
  26. import org.springblade.common.constant.CommonConstant;
  27. import org.springblade.core.boot.ctrl.BladeController;
  28. import org.springblade.core.mp.support.Condition;
  29. import org.springblade.core.mp.support.Query;
  30. import org.springblade.core.redis.cache.BladeRedis;
  31. import org.springblade.core.tool.api.R;
  32. import org.springblade.core.tool.utils.StringUtil;
  33. import org.springblade.modules.desk.entity.Notice;
  34. import org.springblade.modules.desk.service.INoticeService;
  35. import org.springblade.modules.desk.vo.NoticeVO;
  36. import org.springblade.modules.desk.wrapper.NoticeWrapper;
  37. import org.springblade.modules.shopping.entity.Brands;
  38. import org.springblade.modules.shopping.entity.Goods;
  39. import org.springblade.modules.shopping.service.IBrandsService;
  40. import org.springblade.modules.shopping.service.IConsignConfigService;
  41. import org.springblade.modules.shopping.service.IConsignService;
  42. import org.springblade.modules.shopping.service.IGoodsService;
  43. import org.springblade.modules.system.service.IRegionService;
  44. import org.springframework.web.bind.annotation.GetMapping;
  45. import org.springframework.web.bind.annotation.RequestMapping;
  46. import org.springframework.web.bind.annotation.RequestParam;
  47. import org.springframework.web.bind.annotation.RestController;
  48. import java.util.List;
  49. /**
  50. * 控制器
  51. *
  52. * @author xuwei
  53. * @since 2022-02-12
  54. */
  55. @RestController
  56. @AllArgsConstructor
  57. @RequestMapping(CommonConstant.API_URL)
  58. @Api(value = "商城", tags = "11.商城接口")
  59. public class Api06Controller extends BladeController {
  60. private final IGoodsService goodsService;
  61. private final IBrandsService brandsService;
  62. private final INoticeService noticeService;
  63. public static IRegionService regionService;
  64. private final BladeRedis bladeRedis;
  65. /**
  66. * 商品分页查询
  67. */
  68. @GetMapping("/goods-page")
  69. @ApiOperationSupport(order = 1)
  70. @ApiOperation(value = "商品分页查询", notes = "传入类型: 1新品推荐,2人气推荐,3酒票专区,4猜我喜欢, 不传类型是传入搜索关键字则搜索相关商品")
  71. public R<List<Goods>> goodsPage(@ApiParam(value = "传入类型", required = false) @RequestParam(required = false) Integer type,
  72. @ApiParam(value = "用户ID", required = false) @RequestParam(required = false) Long userId,
  73. @ApiParam(value = "所属关键字", required = false) @RequestParam(required = false) String searchName,
  74. Query query) {
  75. Goods goods = new Goods();
  76. goods.setIsSale(2);//上架
  77. if (type == 1) {
  78. goods.setIsNew(2);//新品
  79. }else if (type == 2) {
  80. goods.setIsHot(2);//热销-人气推荐
  81. }else if (type == 3) {
  82. goods.setIsTicket(2);//酒票专区
  83. }else if (type == 4) {
  84. if (userId == null){
  85. return R.fail("传入参数错误!");
  86. }
  87. IPage<Goods> list = goodsService.page(Condition.getPage(query),
  88. Condition.getQueryWrapper(goods).lambda()
  89. .exists("select 1 from t_user_browse b where b.user_id = " + userId + " and b.goods_id = goods_id order by update_time, times")
  90. .orderByAsc(Goods::getSort));
  91. return R.data(list.getRecords());
  92. }else{
  93. if (StringUtil.isNotBlank(searchName)){
  94. //商品搜索
  95. IPage<Goods> list = goodsService.page(Condition.getPage(query),
  96. Condition.getQueryWrapper(goods).lambda()
  97. .like(Goods::getGoodsDesc, searchName).or()
  98. .like(Goods::getGoodsName, searchName).or()
  99. .like(Goods::getGoodsLabel, searchName)
  100. .orderByAsc(Goods::getSort));
  101. return R.data(list.getRecords());
  102. }
  103. }
  104. IPage<Goods> list = goodsService.page(Condition.getPage(query),
  105. Condition.getQueryWrapper(goods).lambda()
  106. .gt(Goods::getGoodsStock, 10)
  107. .orderByAsc(Goods::getSort));
  108. return R.data(list.getRecords());
  109. }
  110. @GetMapping("/brands-list")
  111. @ApiOperationSupport(order = 2)
  112. @ApiOperation(value = "商品品牌", notes = "商品品牌")
  113. public R<List<Brands>> brandsList() {
  114. List<Brands> list = bladeRedis.get(CacheBizConstant.CACHE_GOODS_BRAND);
  115. if (list == null || list.size() == 0){
  116. list = brandsService.list(Wrappers.<Brands>lambdaQuery());
  117. bladeRedis.setEx(CacheBizConstant.CACHE_GOODS_BRAND, list, CacheBizConstant.CACHE_TIME);
  118. }
  119. return R.data(list);
  120. }
  121. /**
  122. * 通知公告
  123. */
  124. @GetMapping("/notice-list")
  125. @ApiOperationSupport(order = 3)
  126. @ApiOperation(value = "通知公告", notes = "通知公告")
  127. public R<List<NoticeVO>> noticeList() {
  128. List<Notice> list = noticeService.list(Wrappers.<Notice>lambdaQuery()
  129. .eq(Notice::getStatus, 1)
  130. .eq(Notice::getCategory, 6)
  131. .orderByDesc(Notice::getUpdateTime));
  132. return R.data(NoticeWrapper.build().listVO(list));
  133. }
  134. }