GoodsDonController.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. package com.cyksj.web.controller.goods;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUnit;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.RandomUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import cn.hutool.extra.servlet.ServletUtil;
  9. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  10. import com.cyksj.common.constant.Constant;
  11. import com.cyksj.common.exception.BusinessRuntimeException;
  12. import com.cyksj.common.util.Jsons;
  13. import com.cyksj.common.util.StringUtil;
  14. import com.cyksj.dto.Result;
  15. import com.cyksj.enums.GatewayResponse;
  16. import com.cyksj.mapper.GoodsDonSkuMapper;
  17. import com.cyksj.mapper.OrderDonMapper;
  18. import com.cyksj.mapper.RegisterOrderDonMapper;
  19. import com.cyksj.mapper.sys.SysConfigMapper;
  20. import com.cyksj.model.entity.*;
  21. import com.cyksj.model.request.ClickRecordReq;
  22. import com.cyksj.model.views.*;
  23. import com.cyksj.redis.RedisService;
  24. import com.cyksj.service.goods.GoodsDonFrontService;
  25. import com.cyksj.service.home.ClickRecordFrontService;
  26. import com.cyksj.service.shop.YhShopFrontService;
  27. import com.cyksj.web.util.StpUserUtil;
  28. import com.ejlchina.searcher.BeanSearcher;
  29. import com.ejlchina.searcher.SearchResult;
  30. import com.ejlchina.searcher.param.Operator;
  31. import com.ejlchina.searcher.util.MapBuilder;
  32. import com.ejlchina.searcher.util.MapUtils;
  33. import lombok.RequiredArgsConstructor;
  34. import lombok.extern.slf4j.Slf4j;
  35. import org.springframework.web.bind.annotation.*;
  36. import javax.servlet.http.HttpServletRequest;
  37. import java.math.BigDecimal;
  38. import java.util.*;
  39. import java.util.concurrent.ConcurrentHashMap;
  40. import java.util.stream.Collectors;
  41. import java.util.stream.Stream;
  42. /**
  43. * @author chan
  44. * @date 2022/9/26 5:33 PM
  45. */
  46. @Slf4j
  47. @RestController
  48. @RequestMapping("/applets/goods")
  49. @RequiredArgsConstructor
  50. public class GoodsDonController {
  51. private final HttpServletRequest request;
  52. private final BeanSearcher beanSearcher;
  53. private final OrderDonMapper orderDonMapper;
  54. private final RegisterOrderDonMapper registerOrderDonMapper;
  55. private final GoodsDonSkuMapper goodsDonSkuMapper;
  56. private final RedisService redisService;
  57. private final SysConfigMapper sysConfigMapper;
  58. private final ClickRecordFrontService clickRecordFrontService;
  59. private final YhShopFrontService yhShopFrontService;
  60. private final GoodsDonFrontService goodsDonFrontService;
  61. /**
  62. * 获取平台商品分类
  63. */
  64. @GetMapping("/get/category")
  65. public Result<List<GoodsDonCategoryFrontView>> getCategory(String customId) {
  66. Long yhsId = null;
  67. if (StrUtil.isNotBlank(customId)) {
  68. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  69. }
  70. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "category";
  71. if (yhsId != null) {
  72. key += ":yhShop:" + yhsId;
  73. }
  74. Object o = redisService.get(key);
  75. List<GoodsDonCategoryFrontView> list;
  76. MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
  77. String condition = " and (select count(*) from goods_don_category_relate gcr inner join goods_don g on g.id = gcr.goods_id %s where gcr.category = gc.id) > 0";
  78. if (yhsId != null) {
  79. condition = String.format(condition, String.format(" and (select count(*) from yh_shop_goods_sku ys where ys.goods_id = g.id and ys.status is true and ys.deleted is true and g.is_distribute is true and ys.yhs_id = %s) > 0", yhsId));
  80. } else {
  81. condition = String.format(condition, StrUtil.EMPTY);
  82. }
  83. mapBuilder.put("condition", condition);
  84. if (o == null) {
  85. list = beanSearcher.searchAll(GoodsDonCategoryFrontView.class, mapBuilder
  86. .build());
  87. redisService.setNx(key, list, 30 * 60l);
  88. o = redisService.get(key);
  89. }
  90. list = Jsons.parseList(o, GoodsDonCategoryFrontView.class);
  91. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  92. }
  93. /**
  94. * 商品搜索
  95. */
  96. @GetMapping("/search")
  97. public Result<SearchResult<GoodsDonSearchView>> search() {
  98. SearchResult<GoodsDonSearchView> search = beanSearcher.search(GoodsDonSearchView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  99. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  100. }
  101. /**
  102. * 获取商品列表
  103. */
  104. @GetMapping("/get")
  105. public Result<SearchResult<GoodsDon>> get() {
  106. SearchResult<GoodsDon> search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap())
  107. .field(GoodsDon::getStatus, true)
  108. .field(GoodsDon::getDeleted, true)
  109. .orderBy(GoodsDon::getSortBy).asc()
  110. .orderBy(GoodsDon::getId).asc()
  111. .build()
  112. );
  113. search.getDataList().forEach(goods -> {
  114. GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goods.getId())
  115. .eq(GoodsDonSku::getStatus, true)
  116. .orderByAsc(GoodsDonSku::getPrice)
  117. .last("limit 1")
  118. .select(GoodsDonSku::getPrice));
  119. Optional.ofNullable(goodsDonSku).ifPresent(sku -> {
  120. goods.setPrice(goodsDonSku.getPrice());
  121. goods.setSoldNum(goods.getVirtualSold() + orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  122. .eq(OrderDon::getGoodsId, goods.getId())
  123. .notIn(OrderDon::getStatus, Constant.noOrderStatus)));
  124. });
  125. });
  126. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  127. }
  128. /**
  129. * 推广未登录,虚拟商品列表
  130. */
  131. @GetMapping("/get/popularize")
  132. @Deprecated
  133. public Result<SearchResult<GoodsDonPopularizeView>> getPopularizeVipGoods() {
  134. SearchResult<GoodsDonPopularizeView> search = beanSearcher.search(GoodsDonPopularizeView.class, MapUtils.flatBuilder(request.getParameterMap())
  135. .field(GoodsDonPopularizeView::getStatus, true)
  136. .field(GoodsDonPopularizeView::getDeleted, true)
  137. .field(GoodsDonPopularizeView::getType, 1)
  138. .orderBy(GoodsDonPopularizeView::getSortBy).asc()
  139. .orderBy(GoodsDonPopularizeView::getId).asc()
  140. .build());
  141. DateTime now = DateTime.now();
  142. search.getDataList().forEach(data -> {
  143. data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
  144. data.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, data.getId()).field(GoodsDonSku::getStatus, true).orderBy(GoodsDonSku::getPrice).asc().build()));
  145. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  146. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  147. data.setSold(sold + data.getVirtualSold());
  148. Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> {
  149. if (skuList.size() > 0) {
  150. GoodsDonSku goodsDonSku = skuList.get(0);
  151. data.setPrice(goodsDonSku.getPrice());
  152. data.setMonths(goodsDonSku.getMonths());
  153. }
  154. });
  155. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  156. .eq(OrderDon::getGoodsId, data.getId())
  157. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  158. .orderByDesc(OrderDon::getId)
  159. .last("limit 1"));
  160. StringBuilder notifyMsg = new StringBuilder();
  161. if (orderDon == null) {
  162. notifyMsg.append("点击购买立即上车");
  163. data.setNotifyMsg(notifyMsg.toString());
  164. return;
  165. } else {
  166. Date payTime = orderDon.getPayTime();
  167. Date startTime = payTime != null ? payTime : orderDon.getCreatedTime();
  168. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  169. if (hour == 0) {
  170. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  171. if (minute == 0) {
  172. notifyMsg.append("1分钟");
  173. } else {
  174. notifyMsg.append(minute);
  175. notifyMsg.append("分钟");
  176. }
  177. } else {
  178. if (hour > 3) {
  179. int hours = RandomUtil.randomInt(3) + 1;
  180. notifyMsg.append(hours);
  181. } else {
  182. notifyMsg.append(hour);
  183. }
  184. notifyMsg.append("小时");
  185. }
  186. }
  187. notifyMsg.append("前有人购买");
  188. data.setNotifyMsg(notifyMsg.toString());
  189. });
  190. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  191. }
  192. /**
  193. * 官网首页 平台列表
  194. */
  195. @GetMapping("/get/list")
  196. public Result<? extends Object> getGoodsList(String customId) {
  197. if (StrUtil.isNotBlank(customId)) {
  198. Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
  199. return shopGoods;
  200. }
  201. List<Long> filter_goodsIds = getFilterGoodsIds();
  202. String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "PC";
  203. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  204. pcCacheKey += ":hz-ip";
  205. }
  206. Long fUid = StpUserUtil.getUserIdAfterLogin();
  207. Object o = redisService.get(pcCacheKey);
  208. List<GoodsFrontListView> list = null;
  209. if (o == null) {
  210. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  211. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  212. builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
  213. }
  214. builder.field(GoodsFrontListView::getType, 1);
  215. list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
  216. redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  217. o = redisService.get(pcCacheKey);
  218. }
  219. if (list == null) {
  220. list = Jsons.parseList(o, GoodsFrontListView.class);
  221. }
  222. DateTime now = DateTime.now();
  223. list.forEach(data -> {
  224. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  225. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  226. data.setSold(sold + data.getSold());
  227. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  228. //设置特定价格
  229. setSpecificPrice(data, fUid);
  230. });
  231. return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list));
  232. }
  233. /**
  234. * h5 银河首页平台展示
  235. */
  236. @GetMapping("/get/homePage")
  237. @Deprecated
  238. public Result<? extends Object> getGoodsHomePage(String customId) {
  239. if (StrUtil.isNotBlank(customId)) {
  240. Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
  241. return shopGoods;
  242. }
  243. List<Long> filter_goodsIds = getFilterGoodsIds();
  244. String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "H5";
  245. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  246. h5CacheKey += ":hz-ip";
  247. }
  248. Long fUid = StpUserUtil.getUserIdAfterLogin();
  249. Object o = redisService.get(h5CacheKey);
  250. List<GoodsFrontListView> list = null;
  251. if (o == null) {
  252. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  253. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  254. builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
  255. }
  256. list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
  257. redisService.setNx(h5CacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  258. o = redisService.get(h5CacheKey);
  259. }
  260. if (list == null) {
  261. list = Jsons.parseList(o, GoodsFrontListView.class);
  262. }
  263. DateTime now = DateTime.now();
  264. list.forEach(data -> {
  265. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  266. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  267. data.setSold(sold + data.getSold());
  268. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  269. //设置特定价格
  270. setSpecificPrice(data, fUid);
  271. });
  272. return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list));
  273. }
  274. /**
  275. * 注册首页平台展示
  276. */
  277. @GetMapping("/get/register")
  278. public Result<List<RegisterGoodsDonView>> getRegisterGoodsDon() {
  279. String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getEnvName();
  280. Object value = redisService.get(registerCacheKey);
  281. if (value != null) {
  282. try {
  283. List<RegisterGoodsDonView> list = Jsons.parseList(value, RegisterGoodsDonView.class);
  284. if (CollUtil.isNotEmpty(list)) {
  285. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  286. }
  287. } catch (Exception e) {
  288. }
  289. }
  290. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  291. List<RegisterGoodsDonView> dataList = beanSearcher.searchAll(RegisterGoodsDonView.class, builder.build());
  292. DateTime now = DateTime.now();
  293. dataList.forEach(data -> {
  294. Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
  295. .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
  296. data.setSold(sold + data.getVirtualSold());
  297. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2, null));
  298. });
  299. redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout());
  300. return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
  301. }
  302. /**
  303. * 获取商品详情
  304. */
  305. @GetMapping("/get/{id}")
  306. public Result<? extends Object> getDetail(@PathVariable Long id, String customId) {
  307. if (StrUtil.isNotBlank(customId) && id != 15) {
  308. Result<YhShopGoodsFrontView> yhShopGoodsDetail = getGoodsDetailByYhsId(yhShopFrontService.getYhsIdByCustomId(customId), id);
  309. return yhShopGoodsDetail;
  310. }
  311. String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "goods_detail:" + id;
  312. Object o = redisService.get(goodsDetailKey);
  313. GoodsFrontListView views = null;
  314. if (o == null) {
  315. views = beanSearcher.searchFirst(GoodsFrontListView.class, MapUtils.builder().field(GoodsFrontListView::getId, id)
  316. .build());
  317. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
  318. MapBuilder builder = MapUtils.builder().field(GoodsDonSku::getGoodsId, views.getId()).field(GoodsDonSku::getStatus, true);
  319. if (views.getType() == 1) {
  320. builder.orderBy(GoodsDonSku::getOrderBy).asc();
  321. }
  322. views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
  323. redisService.setNx(goodsDetailKey, views, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  324. o = redisService.get(goodsDetailKey);
  325. }
  326. Long fUid = StpUserUtil.getUserIdAfterLogin();
  327. if (views == null) {
  328. views = Jsons.parseObject(o, GoodsFrontListView.class);
  329. }
  330. for (GoodsDonSkuFrontView sku : views.getSkuList()) {
  331. if (sku.getIsDp()) {
  332. sku.setDpSkuViews(beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder()
  333. .field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId())
  334. .build()));
  335. }
  336. if (views.getIsSp()) {
  337. if (fUid == null) {
  338. sku.setSpecificPrice(null);
  339. sku.setSpecificGoodsIds(null);
  340. continue;
  341. }
  342. //设置特定价格
  343. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  344. sku.setSpecificGoodsIds(null);
  345. sku.setSpecificPrice(null);
  346. } else {
  347. BigDecimal specificPrice = views.getSpecificPrice();
  348. BigDecimal skuSpecificPrice = sku.getSpecificPrice();
  349. Long specificSkuId = sku.getId();
  350. if (specificPrice == null) {
  351. views.setSpecificPrice(skuSpecificPrice);
  352. views.setSpecificSkuId(specificSkuId);
  353. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  354. views.setSpecificPrice(skuSpecificPrice);
  355. views.setSpecificSkuId(specificSkuId);
  356. }
  357. }
  358. }
  359. }
  360. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  361. .eq(OrderDon::getGoodsId, views.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  362. views.setSold(sold + views.getSold());
  363. //评论
  364. // OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
  365. // .field(OrderCommentFrontView::getGoodsId, views.getId())
  366. // .orderBy(OrderCommentFrontView::getCommentTime).desc()
  367. // .orderBy(OrderCommentFrontView::getId).desc()
  368. // .build());
  369. // views.setComments(comments);
  370. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  371. }
  372. /**
  373. * 获取商品推荐平台
  374. */
  375. @GetMapping("/get/recommend/{id}")
  376. public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, String customId) throws Exception {
  377. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "recommend:" + id;
  378. Long yhsId = null;
  379. if (StrUtil.isNotBlank(customId)) {
  380. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  381. key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":recommend:" + id;
  382. }
  383. Object o = redisService.get(key);
  384. Long fUid = StpUserUtil.getUserIdAfterLogin();
  385. List<GoodsFrontListView> goodsRecommendViews = null;
  386. if (o == null) {
  387. GoodsDon goodsDon = beanSearcher.searchFirst(GoodsDon.class, MapUtils.builder()
  388. .field(GoodsDon::getId, id).field(GoodsDon::getStatus, true)
  389. .field(GoodsDon::getDeleted, true)
  390. .build());
  391. if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
  392. List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
  393. MapBuilder mapBuilder = MapUtils.builder();
  394. if (yhsId != null) {
  395. mapBuilder.put("condition", String.format(" and g.id in (select distinct goods_id from yh_shop_goods_sku where yhs_id = %s and status is true and deleted is true) and g.is_distribute is true", yhsId));
  396. }
  397. mapBuilder.field(GoodsFrontListView::getId, recommend_gidList).op(Operator.InList);
  398. goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build());
  399. redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
  400. o = redisService.get(key);
  401. } else {
  402. return GatewayResponse.SUCCESS.newBuilder().toResult();
  403. }
  404. }
  405. if (goodsRecommendViews == null) {
  406. goodsRecommendViews = Jsons.parseList(o.toString(), GoodsFrontListView.class);
  407. }
  408. goodsRecommendViews.forEach(data -> {
  409. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  410. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  411. data.setSold(data.getSold() + sold);
  412. //设置特定价格
  413. setSpecificPrice(data, fUid);
  414. });
  415. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
  416. }
  417. /**
  418. * 获取商品多规格列表
  419. */
  420. @GetMapping("/get/sku")
  421. public Result<List<GoodsDonSkuView>> getGoodsDonSkuView(@RequestParam(value = "skuIds") List<Long> skuIds) {
  422. if (skuIds.isEmpty()) {
  423. return GatewayResponse.SUCCESS.newBuilder().toResult();
  424. }
  425. List<GoodsDonSkuView> views = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder()
  426. .field(GoodsDonSkuView::getSkuId, skuIds).op(Operator.InList)
  427. .build());
  428. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  429. }
  430. /**
  431. * 获取评价列表
  432. */
  433. @GetMapping("/get/comments")
  434. public Result<SearchResult<OrderCommentFrontView>> getComments() {
  435. SearchResult<OrderCommentFrontView> search = beanSearcher.search(OrderCommentFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  436. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  437. .orderBy(OrderCommentFrontView::getId).desc()
  438. .build());
  439. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  440. }
  441. /**
  442. * 获取礼品卡平台性情
  443. */
  444. @GetMapping("/get/card/{id}")
  445. public Result<Map<Integer, List<GiftCardGoodsSkuFrontView>>> getGiftCardDetail(@PathVariable Long id) {
  446. List<GiftCardGoodsSkuFrontView> giftCardGoodsSkuFrontViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getGoodsId, id).build());
  447. Map<Integer, List<GiftCardGoodsSkuFrontView>> map = giftCardGoodsSkuFrontViews.stream().collect(Collectors.groupingBy(GiftCardGoodsSkuFrontView::getGcType));
  448. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  449. }
  450. /**
  451. * 获取首页配置列表
  452. */
  453. @GetMapping("/get/homeManage")
  454. public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId) {
  455. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "homeManage";
  456. Long yhsId = null;
  457. if (StrUtil.isNotBlank(customId)) {
  458. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  459. key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":homeManage";
  460. }
  461. Long fUid = StpUserUtil.getUserIdAfterLogin();
  462. Object o = redisService.get(key);
  463. if (o == null) {
  464. String condition = "g.deleted is true and g.status is true";
  465. if (yhsId != null) {
  466. condition += String.format(" and g.id in (select distinct goods_id from yh_shop_goods_sku where yhs_id = %s and status is true and deleted is true) and g.is_distribute is true", yhsId);
  467. }
  468. Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
  469. final String conditionSql = condition;
  470. Stream.of(HomeManagementConfig.Type.values())
  471. .forEach(type -> {
  472. MapBuilder builder = MapUtils.builder()
  473. .field(HomeManagementFrontView::getType, type.name());
  474. if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
  475. builder.put("condition", conditionSql);
  476. }
  477. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  478. map.putIfAbsent(type.name(), homeManagementFrontViews);
  479. });
  480. redisService.setNx(key, map, 50 * 60l);
  481. o = redisService.get(key);
  482. }
  483. Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
  484. if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) {
  485. try {
  486. //设置特定价格
  487. List<HomeManagementFrontView> exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class);
  488. if (CollUtil.isNotEmpty(exList)) {
  489. setHomeManageSpecific(exList, fUid);
  490. map.put(HomeManagementConfig.Type.ex.name(), exList);
  491. }
  492. //设置特定价格
  493. List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
  494. if (CollUtil.isNotEmpty(vgList)) {
  495. setHomeManageSpecific(vgList, fUid);
  496. map.put(HomeManagementConfig.Type.vg.name(), vgList);
  497. }
  498. } catch (Exception e) {
  499. }
  500. }
  501. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  502. }
  503. /**
  504. * 首页点击 记录
  505. */
  506. @PostMapping("/homePage/click")
  507. public Result<String> homeManageClick(@RequestBody ClickRecordReq request) {
  508. Long userId = StpUserUtil.getUserIdAfterLogin();
  509. clickRecordFrontService.click(userId, request);
  510. return GatewayResponse.SUCCESS.newBuilder().toResult();
  511. }
  512. public List<Long> getFilterGoodsIds() {
  513. //过滤杭州Ai ChatGPT平台
  514. //获取当前ip地址
  515. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  516. .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1"));
  517. List<Long> filter_goodsIds = null;
  518. if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
  519. if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) {
  520. try {
  521. filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class);
  522. } catch (Exception e) {
  523. }
  524. }
  525. }
  526. return filter_goodsIds;
  527. }
  528. /**
  529. * @param goodsId
  530. * @param type 1、普通,2、注册平台
  531. * @param yhsId 店铺id
  532. * @return
  533. */
  534. public String getPayMsgTime(Long goodsId, DateTime now, Integer type, Long yhsId) {
  535. Date startTime = null;
  536. StringBuilder notifyMsg = new StringBuilder();
  537. if (type == 1) {
  538. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  539. .eq(OrderDon::getGoodsId, goodsId)
  540. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  541. .eq(yhsId != null, OrderDon::getYhsId, yhsId)
  542. .orderByDesc(OrderDon::getId)
  543. .last("limit 1"));
  544. if (orderDon == null) {
  545. notifyMsg.append("点击购买立即上车");
  546. return notifyMsg.toString();
  547. }
  548. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  549. } else if (type == 2) {
  550. RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class)
  551. .eq(RegisterOrderDon::getGoodsId, goodsId)
  552. .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId)
  553. .orderByDesc(RegisterOrderDon::getId)
  554. .last("limit 1"));
  555. if (orderDon == null) {
  556. return null;
  557. }
  558. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  559. }
  560. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  561. if (hour == 0) {
  562. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  563. if (minute == 0) {
  564. notifyMsg.append("1分钟");
  565. } else {
  566. notifyMsg.append(minute);
  567. notifyMsg.append("分钟");
  568. }
  569. } else {
  570. if (hour > 3) {
  571. int hours = RandomUtil.randomInt(3) + 1;
  572. notifyMsg.append(hours);
  573. } else {
  574. notifyMsg.append(hour);
  575. }
  576. notifyMsg.append("小时");
  577. }
  578. notifyMsg.append("前有人购买");
  579. return notifyMsg.toString();
  580. }
  581. /**
  582. * 是否购买过特定平台
  583. */
  584. public Boolean isPaySpecificGoodsIds(String specificGoodsIdsStr, Long userId) {
  585. if (StrUtil.isNotBlank(specificGoodsIdsStr)) {
  586. try {
  587. Set<Long> specificGoodsIds = Jsons.parseSet(specificGoodsIdsStr, Long.class);
  588. Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsIds).op(Operator.InList)
  589. .field(OrderDon::getUserId, userId)
  590. .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
  591. .build());
  592. if (number.intValue() == 0) {
  593. return false;
  594. }
  595. return true;
  596. } catch (Exception e) {
  597. }
  598. }
  599. return false;
  600. }
  601. /**
  602. * 设置平台 特定价格
  603. */
  604. public void setSpecificPrice(GoodsFrontListView data, Long fUid) {
  605. if (fUid != null) {
  606. if (data.getIsSp()) {
  607. //查找所有特定规格最小价格 满足条件
  608. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "specific:" + data.getId();
  609. Object speciObj = redisService.get(specificGoodsKey);
  610. List<GoodsDonSku> specificSkus = null;
  611. if (speciObj != null) {
  612. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  613. } else {
  614. specificSkus = goodsDonSkuMapper.selectList(
  615. Wrappers.lambdaQuery(GoodsDonSku.class)
  616. .eq(GoodsDonSku::getGoodsId, data.getId())
  617. .eq(GoodsDonSku::getStatus, true)
  618. .gt(GoodsDonSku::getSpecificPrice, 0));
  619. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  620. }
  621. specificSkus.forEach(specificSku -> {
  622. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  623. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  624. BigDecimal specificPrice = data.getSpecificPrice();
  625. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  626. Long specificSkuId = specificSku.getId();
  627. if (specificPrice == null) {
  628. data.setSpecificPrice(skuSpecificPrice);
  629. data.setSpecificSkuId(specificSkuId);
  630. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  631. data.setSpecificPrice(skuSpecificPrice);
  632. data.setSpecificSkuId(specificSkuId);
  633. }
  634. }
  635. });
  636. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  637. if (CollUtil.isNotEmpty(skuList)) {
  638. skuList.forEach(sku -> {
  639. //设置特定价格
  640. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  641. sku.setSpecificGoodsIds(null);
  642. sku.setSpecificPrice(null);
  643. }
  644. });
  645. }
  646. }
  647. }
  648. }
  649. /**
  650. * 设置平台 特定价格
  651. */
  652. public void setGcSpecificPrice(GoodsFrontListCategoryView data, Long fUid) {
  653. if (fUid != null) {
  654. if (data.getIsSp()) {
  655. //查找所有特定规格最小价格 满足条件
  656. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "specific:" + data.getId();
  657. Object speciObj = redisService.get(specificGoodsKey);
  658. List<GoodsDonSku> specificSkus = null;
  659. if (speciObj != null) {
  660. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  661. } else {
  662. specificSkus = goodsDonSkuMapper.selectList(
  663. Wrappers.lambdaQuery(GoodsDonSku.class)
  664. .eq(GoodsDonSku::getGoodsId, data.getId())
  665. .eq(GoodsDonSku::getStatus, true)
  666. .gt(GoodsDonSku::getSpecificPrice, 0));
  667. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  668. }
  669. specificSkus.forEach(specificSku -> {
  670. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  671. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  672. BigDecimal specificPrice = data.getSpecificPrice();
  673. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  674. Long specificSkuId = specificSku.getId();
  675. if (specificPrice == null) {
  676. data.setSpecificPrice(skuSpecificPrice);
  677. data.setSpecificSkuId(specificSkuId);
  678. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  679. data.setSpecificPrice(skuSpecificPrice);
  680. data.setSpecificSkuId(specificSkuId);
  681. }
  682. }
  683. });
  684. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  685. if (CollUtil.isNotEmpty(skuList)) {
  686. skuList.forEach(sku -> {
  687. //设置特定价格
  688. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  689. sku.setSpecificGoodsIds(null);
  690. sku.setSpecificPrice(null);
  691. }
  692. });
  693. }
  694. }
  695. }
  696. }
  697. /**
  698. * 获取特定规格
  699. */
  700. public List<GoodsDonSku> getSpecificSku(Long goodsId) {
  701. //查找所有特定规格最小价格 满足条件
  702. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "specific:" + goodsId;
  703. Object speciObj = redisService.get(specificGoodsKey);
  704. List<GoodsDonSku> specificSkus = null;
  705. if (speciObj != null) {
  706. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  707. } else {
  708. specificSkus = goodsDonSkuMapper.selectList(
  709. Wrappers.lambdaQuery(GoodsDonSku.class)
  710. .eq(GoodsDonSku::getGoodsId, goodsId)
  711. .eq(GoodsDonSku::getStatus, true)
  712. .gt(GoodsDonSku::getSpecificPrice, 0));
  713. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  714. }
  715. specificSkus = Optional.ofNullable(specificSkus).orElse(new ArrayList<>());
  716. return specificSkus;
  717. }
  718. /**
  719. * 设置首页配置 涉及平台特定价格
  720. */
  721. public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid) {
  722. DateTime now = DateTime.now();
  723. list.forEach(data -> {
  724. if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
  725. //查找所有特定规格最小价格 满足条件
  726. List<GoodsDonSku> specificSkus = getSpecificSku(data.getGoodsId());
  727. specificSkus.forEach(specificSku -> {
  728. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  729. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  730. BigDecimal specificPrice = data.getSpecificPrice();
  731. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  732. Long specificSkuId = specificSku.getId();
  733. if (specificPrice == null) {
  734. data.setSpecificPrice(skuSpecificPrice);
  735. data.setSpecificSkuId(specificSkuId);
  736. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  737. data.setSpecificPrice(skuSpecificPrice);
  738. data.setSpecificSkuId(specificSkuId);
  739. }
  740. }
  741. });
  742. }
  743. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  744. .eq(OrderDon::getGoodsId, data.getGoodsId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  745. data.setSold(sold + data.getSold());
  746. data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
  747. });
  748. }
  749. /**
  750. * 店铺平台列表
  751. */
  752. @GetMapping("/get/shop/goods/{yhsId}")
  753. public Result<List<YhShopGoodsFrontView>> getShopGoods(@PathVariable Long yhsId) {
  754. String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId;
  755. Object value = redisService.get(yhShopCacheKey);
  756. List<YhShopGoodsFrontView> list = null;
  757. if (value != null) {
  758. try {
  759. list = Jsons.parseList(value, YhShopGoodsFrontView.class);
  760. } catch (Exception e) {
  761. }
  762. }
  763. if (CollUtil.isEmpty(list)) {
  764. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  765. builder.put("condition", String.format("and yhs_id = %s", yhsId));
  766. list = beanSearcher.searchAll(YhShopGoodsFrontView.class, builder.build());
  767. redisService.setNx(yhShopCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  768. }
  769. DateTime now = DateTime.now();
  770. list.forEach(data->{
  771. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  772. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  773. data.setSold(sold + data.getSold());
  774. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
  775. });
  776. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  777. }
  778. /**
  779. * 店铺平台详情
  780. */
  781. @GetMapping("/get/shop/goods/detail/{yhsId}/{goodsId}")
  782. public Result<YhShopGoodsFrontView> getGoodsDetailByYhsId(@PathVariable Long yhsId, @PathVariable Long goodsId) {
  783. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  784. String condition = String.format("and yhs_id = %s and ys.goods_id = %s", yhsId, goodsId);
  785. builder.put("condition", condition);
  786. YhShopGoodsFrontView goodsDetailView = beanSearcher.searchFirst(YhShopGoodsFrontView.class, builder.build());
  787. if (goodsDetailView == null) {
  788. throw BusinessRuntimeException.getInstance("该平台不存在或已下架,请刷新页面");
  789. }
  790. goodsDetailView.setSkuList(beanSearcher.searchAll(YhShopGoodsSkuFrontView.class, MapUtils.builder().put("condition", condition).orderBy(YhShopGoodsSkuFrontView::getOrderBy).asc().build()));
  791. goodsDetailView.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, goodsDetailView.getId()).build()));
  792. OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
  793. .field(OrderCommentFrontView::getGoodsId, goodsDetailView.getId())
  794. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  795. .orderBy(OrderCommentFrontView::getId).desc()
  796. .build());
  797. goodsDetailView.setComments(comments);
  798. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDetailView);
  799. }
  800. /**
  801. * 根据分类获取对应平台
  802. */
  803. @GetMapping("/get/categoryGoods")
  804. public Result<? extends Object> getGoodsByCategory(Long cgy, String customId) {
  805. if (StrUtil.isNotBlank(customId)) {
  806. Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
  807. return shopGoods;
  808. }
  809. Long fUid = StpUserUtil.getUserIdAfterLogin();
  810. String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "category:goods";
  811. if (cgy != null) {
  812. categoryGoodsKey += ":" + cgy;
  813. }
  814. Object o = redisService.get(categoryGoodsKey);
  815. if (o == null) {
  816. MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
  817. if (cgy != null) {
  818. String condition = String.format(" and gcr.category = %s", cgy);
  819. mapBuilder.put("condition", condition);
  820. }
  821. List<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
  822. redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
  823. o = redisService.get(categoryGoodsKey);
  824. }
  825. List<GoodsFrontListCategoryView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class);
  826. DateTime now = DateTime.now();
  827. goodsFrontListViews.forEach(data -> {
  828. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  829. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  830. data.setSold(sold + data.getSold());
  831. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  832. //设置特定价格
  833. setGcSpecificPrice(data, fUid);
  834. });
  835. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews);
  836. }
  837. @GetMapping("/get/shop/categoryGoods/{yhsId}")
  838. public Result<List<YhShopGoodsFrontCategoryView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
  839. String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":category";
  840. if (category != null) {
  841. categoryGoodsKey += ":" + category;
  842. }
  843. Object value = redisService.get(categoryGoodsKey);
  844. if (value == null) {
  845. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  846. builder.put("yhsId", String.format(" and yhs_id = %s", yhsId));
  847. String condition = StrUtil.EMPTY;
  848. if (category != null) {
  849. condition += String.format(" and gcr.category = %s", category);
  850. }
  851. builder.put("condition", condition);
  852. List<YhShopGoodsFrontCategoryView> list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build());
  853. redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60);
  854. value = redisService.get(categoryGoodsKey);
  855. }
  856. List<YhShopGoodsFrontCategoryView> list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class);
  857. DateTime now = DateTime.now();
  858. list.forEach(data -> {
  859. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  860. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  861. data.setSold(sold + data.getSold());
  862. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
  863. });
  864. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  865. }
  866. /**
  867. * 获取pc广告配置
  868. */
  869. @GetMapping("/get/pc/homeManage")
  870. public Result<Map<String, List<HomeManagementFrontView>>> getPcHomeManagementFrontPage() {
  871. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "pc:homeManage";
  872. Object o = redisService.get(key);
  873. if (o == null) {
  874. MapBuilder builder = MapUtils.builder()
  875. .field(HomeManagementFrontView::getAdType, List.of(HomeManagementConfig.AdType.pc.name(), HomeManagementConfig.AdType.pcSec.name(), HomeManagementConfig.AdType.pcDis.name())).op(Operator.InList);
  876. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  877. Map<HomeManagementConfig.AdType, List<HomeManagementFrontView>> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType));
  878. redisService.setNx(key, map, 50 * 60l);
  879. o = redisService.get(key);
  880. }
  881. Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
  882. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  883. }
  884. /**
  885. * 获取pc实物配置
  886. */
  887. @GetMapping("/get/pc/realGoodsConfig")
  888. public Result<? extends Object> getPcRealGoodsConfig() throws Exception {
  889. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "pc:realHomePage";
  890. Object o = redisService.get(key);
  891. List<HomeManagementFrontView> list = null;
  892. if (o == null) {
  893. list = goodsDonFrontService.getRealGoodsConfig();
  894. redisService.setNx(key, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 300);
  895. }
  896. if (list == null && o != null) {
  897. list = Jsons.parseList(o, HomeManagementFrontView.class);
  898. }
  899. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  900. }
  901. }