package com.cyksj.web.controller.goods; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.cyksj.common.constant.Constant; import com.cyksj.common.exception.BusinessRuntimeException; import com.cyksj.common.util.Jsons; import com.cyksj.common.util.StringUtil; import com.cyksj.dto.Result; import com.cyksj.dto.UserSharedDto; import com.cyksj.enums.GatewayResponse; import com.cyksj.mapper.GiftCardGoodsSkuMapper; import com.cyksj.mapper.GoodsDonSkuMapper; import com.cyksj.mapper.OrderDonMapper; import com.cyksj.mapper.RegisterOrderDonMapper; import com.cyksj.mapper.manage.coupon.CouponUserMapper; import com.cyksj.mapper.shop.YhShopGoodsSkuMapper; import com.cyksj.mapper.sys.SysConfigMapper; import com.cyksj.model.entity.*; import com.cyksj.model.request.ClickRecordReq; import com.cyksj.model.views.*; import com.cyksj.redis.RedisService; import com.cyksj.service.goods.GoodsDonFrontService; import com.cyksj.service.home.ClickRecordFrontService; import com.cyksj.service.shop.YhShopFrontService; import com.cyksj.service.user.UserBindRelationService; import com.cyksj.service.user.UserService; import com.cyksj.web.util.StpUserUtil; import com.ejlchina.searcher.BeanSearcher; import com.ejlchina.searcher.SearchResult; import com.ejlchina.searcher.param.Operator; import com.ejlchina.searcher.util.MapBuilder; import com.ejlchina.searcher.util.MapUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import java.util.stream.Stream; /** * @author chan * @date 2022/9/26 5:33 PM */ @Slf4j @RestController @RequestMapping("/applets/goods") @RequiredArgsConstructor public class GoodsDonController { private final HttpServletRequest request; private final BeanSearcher beanSearcher; private final OrderDonMapper orderDonMapper; private final RegisterOrderDonMapper registerOrderDonMapper; private final GoodsDonSkuMapper goodsDonSkuMapper; private final YhShopGoodsSkuMapper yhShopGoodsSkuMapper; private final RedisService redisService; private final SysConfigMapper sysConfigMapper; private final ClickRecordFrontService clickRecordFrontService; private final YhShopFrontService yhShopFrontService; private final UserService userService; private final CouponUserMapper couponUserMapper; private final GoodsDonFrontService goodsDonFrontService; private final UserBindRelationService userBindRelationService; private final GiftCardGoodsSkuMapper giftCardGoodsSkuMapper; /** * 获取平台商品分类 */ @GetMapping("/get/category") public Result> getCategory(String customId) { Long yhsId = null; if (StrUtil.isNotBlank(customId)) { yhsId = yhShopFrontService.getYhsIdByCustomId(customId); } String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category"; if (yhsId != null) { key += ":yhShop:" + yhsId; } Object o = redisService.get(key); List list; MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap()); 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"; if (yhsId != null) { 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)); } else { condition = String.format(condition, StrUtil.EMPTY); } mapBuilder.put("condition", condition); if (o == null) { list = beanSearcher.searchAll(GoodsDonCategoryFrontView.class, mapBuilder .build()); redisService.setNx(key, list, 30 * 60l); o = redisService.get(key); } list = Jsons.parseList(o, GoodsDonCategoryFrontView.class); return GatewayResponse.SUCCESS.newBuilder().toResult(list); } /** * 商品搜索 */ @GetMapping("/search") public Result> search() { SearchResult search = beanSearcher.search(GoodsDonSearchView.class, MapUtils.flatBuilder(request.getParameterMap()).build()); return GatewayResponse.SUCCESS.newBuilder().toResult(search); } /** * 获取商品列表 */ @GetMapping("/get") public Result> get() { SearchResult search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap()) .field(GoodsDon::getStatus, true) .field(GoodsDon::getDeleted, true) .orderBy(GoodsDon::getSortBy).asc() .orderBy(GoodsDon::getId).asc() .build() ); search.getDataList().forEach(goods -> { GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goods.getId()) .eq(GoodsDonSku::getStatus, true) .orderByAsc(GoodsDonSku::getPrice) .last("limit 1") .select(GoodsDonSku::getPrice)); Optional.ofNullable(goodsDonSku).ifPresent(sku -> { goods.setPrice(goodsDonSku.getPrice()); goods.setSoldNum(getGoodsSold(goods.getId(), goods.getVirtualSold())); }); }); return GatewayResponse.SUCCESS.newBuilder().toResult(search); } /** * 推广未登录,虚拟商品列表 */ @GetMapping("/get/popularize") @Deprecated public Result> getPopularizeVipGoods() { SearchResult search = beanSearcher.search(GoodsDonPopularizeView.class, MapUtils.flatBuilder(request.getParameterMap()) .field(GoodsDonPopularizeView::getStatus, true) .field(GoodsDonPopularizeView::getDeleted, true) .field(GoodsDonPopularizeView::getType, 1) .orderBy(GoodsDonPopularizeView::getSortBy).asc() .orderBy(GoodsDonPopularizeView::getId).asc() .build()); DateTime now = DateTime.now(); search.getDataList().forEach(data -> { data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build())); data.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, data.getId()).field(GoodsDonSku::getStatus, true).orderBy(GoodsDonSku::getPrice).asc().build())); data.setSold(getGoodsSold(data.getId(), data.getVirtualSold())); Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> { if (skuList.size() > 0) { GoodsDonSku goodsDonSku = skuList.get(0); data.setPrice(goodsDonSku.getPrice()); data.setMonths(goodsDonSku.getMonths()); } }); OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class) .eq(OrderDon::getGoodsId, data.getId()) .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId) .orderByDesc(OrderDon::getId) .last("limit 1")); StringBuilder notifyMsg = new StringBuilder(); if (orderDon == null) { notifyMsg.append("点击购买立即上车"); data.setNotifyMsg(notifyMsg.toString()); return; } else { Date payTime = orderDon.getPayTime(); Date startTime = payTime != null ? payTime : orderDon.getCreatedTime(); long hour = DateUtil.between(startTime, now, DateUnit.HOUR); if (hour == 0) { long minute = DateUtil.between(startTime, now, DateUnit.MINUTE); if (minute == 0) { notifyMsg.append("1分钟"); } else { notifyMsg.append(minute); notifyMsg.append("分钟"); } } else { if (hour > 3) { int hours = RandomUtil.randomInt(3) + 1; notifyMsg.append(hours); } else { notifyMsg.append(hour); } notifyMsg.append("小时"); } } notifyMsg.append("前有人购买"); data.setNotifyMsg(notifyMsg.toString()); }); return GatewayResponse.SUCCESS.newBuilder().toResult(search); } /** * 官网首页 平台列表 */ @GetMapping("/get/list") @Deprecated public Result getGoodsList(String customId) { if (StrUtil.isNotBlank(customId)) { Result> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId)); return shopGoods; } //List filter_goodsIds = getFilterGoodsIds(); List filter_goodsIds = null; String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "PC"; if (CollUtil.isNotEmpty(filter_goodsIds)) { pcCacheKey += ":hz-ip"; } Long fUid = StpUserUtil.getUserIdAfterLogin(); Object o = redisService.get(pcCacheKey); List list = null; if (o == null) { MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()); if (CollUtil.isNotEmpty(filter_goodsIds)) { builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn); } builder.field(GoodsFrontListView::getType, 1); list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build()); redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); o = redisService.get(pcCacheKey); } if (list == null) { list = Jsons.parseList(o, GoodsFrontListView.class); } DateTime now = DateTime.now(); list.forEach(data -> { data.setSold(getGoodsSold(data.getId(), data.getSold())); data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null)); //设置特定价格 setSpecificPrice(data, fUid, null); }); return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list)); } /** * h5 银河首页平台展示 */ @GetMapping("/get/homePage") @Deprecated public Result getGoodsHomePage(String customId) { if (StrUtil.isNotBlank(customId)) { Result> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId)); return shopGoods; } //List filter_goodsIds = getFilterGoodsIds(); List filter_goodsIds = null; String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "H5"; if (CollUtil.isNotEmpty(filter_goodsIds)) { h5CacheKey += ":hz-ip"; } Long fUid = StpUserUtil.getUserIdAfterLogin(); Object o = redisService.get(h5CacheKey); List list = null; if (o == null) { MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()); if (CollUtil.isNotEmpty(filter_goodsIds)) { builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn); } list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build()); redisService.setNx(h5CacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); o = redisService.get(h5CacheKey); } if (list == null) { list = Jsons.parseList(o, GoodsFrontListView.class); } DateTime now = DateTime.now(); list.forEach(data -> { data.setSold(getGoodsSold(data.getId(), data.getSold())); data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null)); //设置特定价格 setSpecificPrice(data, fUid, null); }); return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list)); } /** * 注册首页平台展示 */ @GetMapping("/get/register") public Result> getRegisterGoodsDon() { String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getName(); Object value = redisService.get(registerCacheKey); if (value != null) { try { List list = Jsons.parseList(value, RegisterGoodsDonView.class); if (CollUtil.isNotEmpty(list)) { return GatewayResponse.SUCCESS.newBuilder().toResult(list); } } catch (Exception e) { } } MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()); List dataList = beanSearcher.searchAll(RegisterGoodsDonView.class, builder.build()); DateTime now = DateTime.now(); dataList.forEach(data -> { Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class) .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus)); data.setSold(sold + data.getVirtualSold()); data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2, null)); }); redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout()); return GatewayResponse.SUCCESS.newBuilder().toResult(dataList); } /** * 获取商品详情 */ @GetMapping("/get/{id}") public Result getDetail(@PathVariable Long id, String customId, String dsCode, BigDecimal discount) { if (StrUtil.isNotBlank(customId) && id != 15) { Result yhShopGoodsDetail = getGoodsDetailByYhsId(yhShopFrontService.getYhsIdByCustomId(customId), id); return yhShopGoodsDetail; } String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "goods_detail:" + id; //List filter_goodsIds = getFilterGoodsIds(); List filter_goodsIds = null; //存在过滤平台 商品详情不返回 if (CollUtil.isNotEmpty(filter_goodsIds) && filter_goodsIds.contains(id)) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } Object o = redisService.get(goodsDetailKey); if (o == null) { GoodsFrontListView views = beanSearcher.searchFirst(GoodsFrontListView.class, MapUtils.builder().field(GoodsFrontListView::getId, id) .build()); if (views == null) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build())); MapBuilder builder = MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, views.getId()).field(GoodsDonSkuFrontView::getStatus, true); if (views.getType() == 1) { builder.orderBy(GoodsDonSkuFrontView::getSorted).asc(); } views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build())); views.setSold(getGoodsSold(views.getId(), views.getSold())); List donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, MapUtils.builder().field(GoodsDonQaFrontView::getGoodsId, id).field(GoodsDonQaFrontView::getType, 1).build()); views.setQuestions(donQaFrontViews); redisService.setNx(goodsDetailKey, views, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10)); o = redisService.get(goodsDetailKey); } Long fUid = StpUserUtil.getUserIdAfterLogin(); GoodsFrontListView views = Jsons.parseObject(o, GoodsFrontListView.class); AtomicLong dsUserId = new AtomicLong(); AtomicBoolean existsChannel = new AtomicBoolean(true); if (StrUtil.isNotBlank(dsCode)) { UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode); dsUserId.set(userSharedDto.getSharedId()); } views.setIsGift(giftCardGoodsSkuMapper.selectCount(Wrappers.lambdaQuery(GiftCardGoodsSku.class) .eq(GiftCardGoodsSku::getGcGoodsId, views.getId()) .eq(GiftCardGoodsSku::getStatus, 1) .eq(GiftCardGoodsSku::getDeleted, 1)) > 0); views.setSkuList(views.getSkuList().stream().filter(sku -> { if (StrUtil.isNotBlank(sku.getUserOwns())) { if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) { Long sharedId = userService.getSharedIdByUserId(fUid); if (sharedId == 0) { existsChannel.set(false); } dsUserId.set(sharedId); } if (dsUserId.get() == 0 || !sku.getUserOwns().contains(String.valueOf(dsUserId.get()))) { return false; } } if (sku.getIsDp()) { sku.setDpSkuViews(beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder() .field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId()) .build())); } if (views.getIsSp()) { if (fUid == null) { sku.setSpecificPrice(null); sku.setSpecificGoodsIds(null); } else { //设置特定价格 if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) { sku.setSpecificGoodsIds(null); sku.setSpecificPrice(null); } else { BigDecimal specificPrice = views.getSpecificPrice(); BigDecimal skuSpecificPrice = sku.getSpecificPrice(); Long specificSkuId = sku.getId(); if (specificPrice == null) { views.setSpecificPrice(skuSpecificPrice); views.setSpecificSkuId(specificSkuId); } else if (specificPrice.compareTo(skuSpecificPrice) > 0) { views.setSpecificPrice(skuSpecificPrice); views.setSpecificSkuId(specificSkuId); } } } } // if (fUid != null && Constant.SPECIAL_PRICE_SKU_IDS.contains(sku.getId())) { // UserDistributeShared distributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class) // .eq(UserDistributeShared::getUserId, fUid) // .last("limit 1")); // if (distributeShared != null) { // Optional.ofNullable(sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class) // .eq(SysConfig::getSysKey, Constant.MJ_SPECIAL_SKU_PRICE_KEY) // .last("limit 1"))).ifPresent(sysConfig -> { // if (StrUtil.isNotBlank(sysConfig.getSysValue())) { // try { // GoodsDonPriceDto goodsDonPriceDto = Jsons.parseObject(sysConfig.getSysValue(), GoodsDonPriceDto.class); // sku.setPrice(goodsDonPriceDto.getPrice()); // } catch (Exception e) { // } // } // }); // } // } //设置规格优惠后的价格 sku.setChannelDiscount(discount); setUserCouponSkuMoney(fUid, sku); return true; }).collect(Collectors.toList())); return GatewayResponse.SUCCESS.newBuilder().toResult(views); } /** * 获取商品推荐平台 */ @GetMapping("/get/recommend/{id}") public Result> getRecommendGoodsByGid(@PathVariable Long id, String customId, String dsCode) throws Exception { String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id; Long yhsId = null; if (StrUtil.isNotBlank(customId)) { yhsId = yhShopFrontService.getYhsIdByCustomId(customId); key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":recommend:" + id; } Object o = redisService.get(key); Long fUid = StpUserUtil.getUserIdAfterLogin(); List goodsRecommendViews = null; if (o == null) { GoodsDon goodsDon = beanSearcher.searchFirst(GoodsDon.class, MapUtils.builder() .field(GoodsDon::getId, id).field(GoodsDon::getStatus, true) .field(GoodsDon::getDeleted, true) .build()); if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) { List recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class); MapBuilder mapBuilder = MapUtils.builder(); if (yhsId != null) { 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)); } mapBuilder.field(GoodsFrontListView::getId, recommend_gidList).op(Operator.InList); goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build()); redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l); o = redisService.get(key); } else { return GatewayResponse.SUCCESS.newBuilder().toResult(); } } if (goodsRecommendViews == null) { goodsRecommendViews = Jsons.parseList(o.toString(), GoodsFrontListView.class); } AtomicLong dsUserId = new AtomicLong(); AtomicBoolean existsChannel = new AtomicBoolean(true); if (StrUtil.isNotBlank(dsCode)) { UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode); dsUserId.set(userSharedDto.getSharedId()); } goodsRecommendViews = goodsRecommendViews.stream().filter(data -> { if (data.getIsOwns()) { if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) { Long sharedId = userService.getSharedIdByUserId(fUid); if (sharedId == 0) { existsChannel.set(false); } dsUserId.set(sharedId); } GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get()); if (minPriceUserOwnsSku == null) { return false; } data.setPrice(minPriceUserOwnsSku.getPrice()); data.setMonths(minPriceUserOwnsSku.getMonths()); data.setDays(minPriceUserOwnsSku.getDays()); } //销量 data.setSold(getGoodsSold(data.getId(), data.getSold())); //设置特定价格 setSpecificPrice(data, fUid, dsUserId.get()); return true; }).collect(Collectors.toList()); return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews); } /** * 获取商品多规格列表 */ @GetMapping("/get/sku") public Result> getGoodsDonSkuView(@RequestParam(value = "skuIds") List skuIds) { if (skuIds.isEmpty()) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } List views = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder() .field(GoodsDonSkuView::getSkuId, skuIds).op(Operator.InList) .build()); return GatewayResponse.SUCCESS.newBuilder().toResult(views); } /** * 获取评价列表 */ @GetMapping("/get/comments") public Result> getComments() { SearchResult search = beanSearcher.search(OrderCommentFrontView.class, MapUtils.flatBuilder(request.getParameterMap()) .orderBy(OrderCommentFrontView::getCommentTime).desc() .orderBy(OrderCommentFrontView::getId).desc() .build()); return GatewayResponse.SUCCESS.newBuilder().toResult(search); } /** * 获取礼品卡平台性情 */ @GetMapping("/get/card/{id}") public Result>> getGiftCardDetail(@PathVariable Long id) { List giftCardGoodsSkuFrontViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getGoodsId, id).build()); Map> map = giftCardGoodsSkuFrontViews.stream().collect(Collectors.groupingBy(GiftCardGoodsSkuFrontView::getGcType)); return GatewayResponse.SUCCESS.newBuilder().toResult(map); } /** * 获取首页配置列表 */ @GetMapping("/get/homeManage") public Result>> getHomeManagementFrontPage(String customId, String dsCode, BigDecimal discount) { String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "homeManage"; Long yhsId = null; if (StrUtil.isNotBlank(customId)) { yhsId = yhShopFrontService.getYhsIdByCustomId(customId); key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":homeManage"; } // List filter_goodsIds = getFilterGoodsIds(); List filter_goodsIds = null; AtomicBoolean isRemoveRg = new AtomicBoolean(false); // if (isHzIp()) { // key += ":hz-ip"; // isRemoveRg.set(true); // } Long fUid = StpUserUtil.getUserIdAfterLogin(); Object o = redisService.get(key); if (o == null) { String condition = "g.deleted is true and g.status is true"; if (yhsId != null) { 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); } Map> map = new ConcurrentHashMap<>(); final String conditionSql = condition; Stream.of(HomeManagementConfig.Type.values()) .forEach(type -> { if (isRemoveRg.get() && type == HomeManagementConfig.Type.rg) { return; } MapBuilder builder = MapUtils.builder() .field(HomeManagementFrontView::getType, type.name()); if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) { builder.put("condition", conditionSql); if (CollUtil.isNotEmpty(filter_goodsIds)) { builder.field(HomeManagementFrontView::getGoodsId, filter_goodsIds).op(Operator.NotIn); } } List homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build()); map.putIfAbsent(type.name(), homeManagementFrontViews); }); redisService.setNx(key, map, 50 * 60l); o = redisService.get(key); } AtomicLong dsUserId = new AtomicLong(); AtomicBoolean existsChannel = new AtomicBoolean(true); if (StrUtil.isNotBlank(dsCode)) { UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode); dsUserId.set(userSharedDto.getSharedId()); } Map> map = Jsons.parseObject(o, Map.class); if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) { try { //精彩推荐 List exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class); setHomeConfigGoods(map, HomeManagementConfig.Type.ex, exList, dsUserId, existsChannel, fUid, discount); //虚拟平台 List vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class); setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid, discount); } catch (Exception e) { } } return GatewayResponse.SUCCESS.newBuilder().toResult(map); } /** * 首页点击 记录 */ @PostMapping("/homePage/click") public Result homeManageClick(@RequestBody ClickRecordReq request) { Long userId = StpUserUtil.getUserIdAfterLogin(); clickRecordFrontService.click(userId, request); return GatewayResponse.SUCCESS.newBuilder().toResult(); } public List getFilterGoodsIds() { List filter_goodsIds = null; //获取当前ip地址 if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) { //过滤杭州Ai ChatGPT平台 SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class) .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1")); if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) { try { filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class); } catch (Exception e) { } } } return filter_goodsIds; } public Boolean isHzIp() { if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("无锡")) { return true; } return false; } /** * @param goodsId * @param type 1、普通,2、注册平台 * @param yhsId 店铺id * @return */ public String getPayMsgTime(Long goodsId, DateTime now, Integer type, Long yhsId) { Date startTime = null; StringBuilder notifyMsg = new StringBuilder(); if (type == 1) { OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class) .eq(OrderDon::getGoodsId, goodsId) .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId) .eq(yhsId != null, OrderDon::getYhsId, yhsId) .orderByDesc(OrderDon::getId) .last("limit 1")); if (orderDon == null) { notifyMsg.append("点击购买立即上车"); return notifyMsg.toString(); } startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime(); } else if (type == 2) { RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class) .eq(RegisterOrderDon::getGoodsId, goodsId) .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId) .orderByDesc(RegisterOrderDon::getId) .last("limit 1")); if (orderDon == null) { return null; } startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime(); } long hour = DateUtil.between(startTime, now, DateUnit.HOUR); if (hour == 0) { long minute = DateUtil.between(startTime, now, DateUnit.MINUTE); if (minute == 0) { notifyMsg.append("1分钟"); } else { notifyMsg.append(minute); notifyMsg.append("分钟"); } } else { if (hour > 3) { int hours = RandomUtil.randomInt(3) + 1; notifyMsg.append(hours); } else { notifyMsg.append(hour); } notifyMsg.append("小时"); } notifyMsg.append("前有人购买"); return notifyMsg.toString(); } /** * 是否购买过特定平台 */ public Boolean isPaySpecificGoodsIds(String specificGoodsIdsStr, Long userId) { if (StrUtil.isNotBlank(specificGoodsIdsStr)) { try { Set specificGoodsIds = Jsons.parseSet(specificGoodsIdsStr, Long.class); Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsIds).op(Operator.InList) .field(OrderDon::getUserId, userId) .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn) .build()); if (number.intValue() == 0) { return false; } return true; } catch (Exception e) { } } return false; } /** * 设置平台 特定价格 */ public void setSpecificPrice(GoodsFrontListView data, Long fUid, Long dsUserId) { if (fUid != null) { if (data.getIsSp()) { //查找所有特定规格最小价格 满足条件 String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId(); Object speciObj = redisService.get(specificGoodsKey); List specificSkus = null; if (speciObj != null) { specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class); } else { specificSkus = goodsDonSkuMapper.selectList( Wrappers.lambdaQuery(GoodsDonSku.class) .eq(GoodsDonSku::getGoodsId, data.getId()) .eq(GoodsDonSku::getStatus, true) .gt(GoodsDonSku::getSpecificPrice, 0)); redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); } specificSkus.forEach(specificSku -> { if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) { return; } String specificGoodsIdsStr = specificSku.getSpecificGoodsIds(); if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) { BigDecimal specificPrice = data.getSpecificPrice(); BigDecimal skuSpecificPrice = specificSku.getSpecificPrice(); Long specificSkuId = specificSku.getId(); if (specificPrice == null) { data.setSpecificPrice(skuSpecificPrice); data.setSpecificSkuId(specificSkuId); } else if (specificPrice.compareTo(skuSpecificPrice) > 0) { data.setSpecificPrice(skuSpecificPrice); data.setSpecificSkuId(specificSkuId); } } }); List skuList = data.getSkuList(); if (CollUtil.isNotEmpty(skuList)) { skuList.forEach(sku -> { //设置特定价格 if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) { sku.setSpecificGoodsIds(null); sku.setSpecificPrice(null); } }); } } } } /** * 设置平台 特定价格 */ public void setGcSpecificPrice(GoodsFrontListCategoryView data, Long fUid, Long dsUserId) { if (fUid != null) { if (data.getIsSp()) { //查找所有特定规格最小价格 满足条件 String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId(); Object speciObj = redisService.get(specificGoodsKey); List specificSkus = null; if (speciObj != null) { specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class); } else { specificSkus = goodsDonSkuMapper.selectList( Wrappers.lambdaQuery(GoodsDonSku.class) .eq(GoodsDonSku::getGoodsId, data.getId()) .eq(GoodsDonSku::getStatus, true) .gt(GoodsDonSku::getSpecificPrice, 0)); redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); } specificSkus.forEach(specificSku -> { if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) { return; } String specificGoodsIdsStr = specificSku.getSpecificGoodsIds(); if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) { BigDecimal specificPrice = data.getSpecificPrice(); BigDecimal skuSpecificPrice = specificSku.getSpecificPrice(); Long specificSkuId = specificSku.getId(); if (specificPrice == null) { data.setSpecificPrice(skuSpecificPrice); data.setSpecificSkuId(specificSkuId); } else if (specificPrice.compareTo(skuSpecificPrice) > 0) { data.setSpecificPrice(skuSpecificPrice); data.setSpecificSkuId(specificSkuId); } } }); List skuList = data.getSkuList(); if (CollUtil.isNotEmpty(skuList)) { skuList.forEach(sku -> { //设置特定价格 if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) { sku.setSpecificGoodsIds(null); sku.setSpecificPrice(null); } }); } } } } /** * 获取特定规格 */ public List getSpecificSku(Long goodsId) { //查找所有特定规格最小价格 满足条件 String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + goodsId; Object speciObj = redisService.get(specificGoodsKey); List specificSkus = null; if (speciObj != null) { specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class); } else { specificSkus = goodsDonSkuMapper.selectList( Wrappers.lambdaQuery(GoodsDonSku.class) .eq(GoodsDonSku::getGoodsId, goodsId) .eq(GoodsDonSku::getStatus, true) .gt(GoodsDonSku::getSpecificPrice, 0)); redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); } specificSkus = Optional.ofNullable(specificSkus).orElse(new ArrayList<>()); return specificSkus; } /** * 设置首页配置 涉及平台特定价格 */ public void setHomeManageSpecific(List list, Long fUid, Long dsUserId, BigDecimal discount) { DateTime now = DateTime.now(); list.forEach(data -> { if (data.getIsSp() != null && data.getIsSp() && fUid != null) { //查找所有特定规格最小价格 满足条件 List specificSkus = getSpecificSku(data.getGoodsId()); specificSkus.forEach(specificSku -> { if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) { return; } String specificGoodsIdsStr = specificSku.getSpecificGoodsIds(); if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) { BigDecimal specificPrice = data.getSpecificPrice(); BigDecimal skuSpecificPrice = specificSku.getSpecificPrice(); Long specificSkuId = specificSku.getId(); if (specificPrice == null) { data.setSpecificPrice(skuSpecificPrice); data.setSpecificSkuId(specificSkuId); } else if (specificPrice.compareTo(skuSpecificPrice) > 0) { data.setSpecificPrice(skuSpecificPrice); data.setSpecificSkuId(specificSkuId); } } }); } data.setSold(getGoodsSold(data.getGoodsId(), data.getSold())); data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null)); //设置用户存在优惠券的优惠商品价格 data.setChannelDiscount(discount); setHomeManageUserCouponGoodsMoney(fUid, data); }); } public void setHomeConfigGoods(Map> map, HomeManagementConfig.Type type, List list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid, BigDecimal discount) throws Exception { //设置特定价格 if (CollUtil.isNotEmpty(list)) { list = list.stream().filter(data -> { if (data.getIsOwns()) { if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) { Long sharedId = userService.getSharedIdByUserId(fUid); if (sharedId == 0) { existsChannel.set(false); } dsUserId.set(sharedId); } GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getGoodsId(), dsUserId.get()); if (minPriceUserOwnsSku == null) { return false; } data.setPrice(minPriceUserOwnsSku.getPrice()); data.setMonths(minPriceUserOwnsSku.getMonths()); data.setDays(minPriceUserOwnsSku.getDays()); } return true; }).collect(Collectors.toList()); setHomeManageSpecific(list, fUid, dsUserId.get(), discount); map.put(type.name(), list); } } /** * 店铺平台列表 */ @GetMapping("/get/shop/goods/{yhsId}") public Result> getShopGoods(@PathVariable Long yhsId) { String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId; Object value = redisService.get(yhShopCacheKey); List list = null; if (value != null) { try { list = Jsons.parseList(value, YhShopGoodsFrontView.class); } catch (Exception e) { } } if (CollUtil.isEmpty(list)) { MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()); builder.put("condition", String.format("and yhs_id = %s", yhsId)); list = beanSearcher.searchAll(YhShopGoodsFrontView.class, builder.build()); redisService.setNx(yhShopCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); } DateTime now = DateTime.now(); list.forEach(data -> { data.setSold(getGoodsSold(data.getId(), data.getSold())); data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId)); Optional.ofNullable(yhShopGoodsSkuMapper.selectOne(Wrappers.lambdaQuery(YhShopGoodsSku.class) .eq(YhShopGoodsSku::getYhsId, yhsId) .eq(YhShopGoodsSku::getGoodsId, data.getId()) .eq(YhShopGoodsSku::getPrice, data.getPrice()) .eq(YhShopGoodsSku::getStatus, 1) .eq(YhShopGoodsSku::getDeleted, 1) .last("limit 1"))).ifPresent(yhSku -> { GoodsDonSku sku = goodsDonSkuMapper.selectById(yhSku.getSkuId()); if (sku != null) { data.setMonths(sku.getMonths()); data.setDays(sku.getDays()); } }); }); return GatewayResponse.SUCCESS.newBuilder().toResult(list); } /** * 店铺平台详情 */ @GetMapping("/get/shop/goods/detail/{yhsId}/{goodsId}") public Result getGoodsDetailByYhsId(@PathVariable Long yhsId, @PathVariable Long goodsId) { String yhShopDetailCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":goodsId:" + goodsId; Object value = redisService.get(yhShopDetailCacheKey); if (value == null) { MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()); String condition = String.format("and yhs_id = %s and ys.goods_id = %s", yhsId, goodsId); builder.put("condition", condition); YhShopGoodsFrontView goodsDetailView = beanSearcher.searchFirst(YhShopGoodsFrontView.class, builder.build()); if (goodsDetailView == null) { throw BusinessRuntimeException.getInstance("该平台不存在或已下架,请刷新页面"); } goodsDetailView.setSkuList(beanSearcher.searchAll(YhShopGoodsSkuFrontView.class, MapUtils.builder().put("condition", condition).orderBy(YhShopGoodsSkuFrontView::getSorted).asc().build())); goodsDetailView.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, goodsDetailView.getId()).build())); OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder() .field(OrderCommentFrontView::getGoodsId, goodsDetailView.getId()) .orderBy(OrderCommentFrontView::getCommentTime).desc() .orderBy(OrderCommentFrontView::getId).desc() .build()); goodsDetailView.setComments(comments); redisService.setNx(yhShopDetailCacheKey, goodsDetailView, RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getTimeout() + RandomUtil.randomInt(1000)); value = redisService.get(yhShopDetailCacheKey); } YhShopGoodsFrontView goodsDetailView = Jsons.parseObject(value, YhShopGoodsFrontView.class); return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDetailView); } /** * 根据分类获取对应平台 */ @GetMapping("/get/categoryGoods") public Result getGoodsByCategory(Long cgy, String customId, String dsCode, BigDecimal discount) { if (StrUtil.isNotBlank(customId)) { Result> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy); return shopGoods; } Long fUid = StpUserUtil.getUserIdAfterLogin(); String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category:goods"; if (cgy != null) { categoryGoodsKey += ":" + cgy; } //List filter_goodsIds = getFilterGoodsIds(); List filter_goodsIds = null; if (CollUtil.isNotEmpty(filter_goodsIds)) { categoryGoodsKey += ":hz-ip"; } Object o = redisService.get(categoryGoodsKey); if (o == null) { DateTime now = DateTime.now(); MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap()); if (cgy != null) { String condition = String.format(" and gcr.category = %s", cgy); mapBuilder.put("condition", condition); } if (CollUtil.isNotEmpty(filter_goodsIds)) { mapBuilder.field(GoodsFrontListCategoryView::getId, filter_goodsIds).op(Operator.NotIn); } List goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build()); goodsFrontListViews.forEach(data -> { data.setSold(getGoodsSold(data.getId(), data.getSold())); ; data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null)); }); redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60); o = redisService.get(categoryGoodsKey); } List goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class); AtomicLong dsUserId = new AtomicLong(); AtomicBoolean existsChannel = new AtomicBoolean(true); if (StrUtil.isNotBlank(dsCode)) { UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode); dsUserId.set(userSharedDto.getSharedId()); } AtomicBoolean filterCourseGoods = new AtomicBoolean(false); //增值服务分类 if (fUid != null && cgy != null && (cgy == 3 || cgy == 4)) { //GPT Plus基础2月 课程不展示 List userIdList = userBindRelationService.getRelationUserIdList(fUid, null); Integer orders = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class) .in(OrderDon::getUserId, userIdList) .eq(OrderDon::getSkuId, 444) .notIn(OrderDon::getStatus, Constant.noOrderStatus)); if (orders > 0) { filterCourseGoods.set(true); } } goodsFrontListViews = goodsFrontListViews.stream().filter(data -> { if (data.getIsOwns()) { if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) { Long sharedId = userService.getSharedIdByUserId(fUid); if (sharedId == 0) { existsChannel.set(false); } dsUserId.set(sharedId); } GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get()); if (minPriceUserOwnsSku == null) { return false; } data.setPrice(minPriceUserOwnsSku.getPrice()); data.setMonths(minPriceUserOwnsSku.getMonths()); data.setDays(minPriceUserOwnsSku.getDays()); } //课件类型 且过滤 if (filterCourseGoods.get() && data.getSpecialType() != null && data.getSpecialType() == GoodsDon.SpecialType.courseware) { return false; } //设置特定价格 setGcSpecificPrice(data, fUid, dsUserId.get()); //设置用户存在优惠券的优惠商品价格 data.setChannelDiscount(discount); setUserCouponGoodsMoney(fUid, data); return true; }).collect(Collectors.toList()); return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews); } @GetMapping("/get/shop/categoryGoods/{yhsId}") public Result> getShopCategoryGoods(@PathVariable Long yhsId, Long category) { String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":category"; if (category != null) { categoryGoodsKey += ":" + category; } Object value = redisService.get(categoryGoodsKey); if (value == null) { DateTime now = DateTime.now(); MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()); builder.put("yhsId", String.format(" and yhs_id = %s", yhsId)); String condition = StrUtil.EMPTY; if (category != null) { condition += String.format(" and gcr.category = %s", category); } builder.put("condition", condition); List list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build()); list.forEach(data->{ data.setSold(getGoodsSold(data.getId(), data.getSold())); data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId)); //重新设置最低价格规格 YhShopGoodsSku sku = yhShopGoodsSkuMapper.selectMinPriceSkuByYhsId(yhsId, data.getId()); data.setPrice(sku.getPrice()); data.setSkuId(sku.getSkuId()); }); redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60); value = redisService.get(categoryGoodsKey); } List list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class); list.forEach(data->{ Optional.ofNullable(yhShopGoodsSkuMapper.selectOne(Wrappers.lambdaQuery(YhShopGoodsSku.class) .eq(YhShopGoodsSku::getYhsId, yhsId) .eq(YhShopGoodsSku::getGoodsId, data.getId()) .eq(YhShopGoodsSku::getPrice, data.getPrice()) .eq(YhShopGoodsSku::getStatus, 1) .eq(YhShopGoodsSku::getDeleted, 1) .last("limit 1"))).ifPresent(yhSku -> { GoodsDonSku sku = goodsDonSkuMapper.selectById(yhSku.getSkuId()); if (sku != null) { data.setMonths(sku.getMonths()); data.setDays(sku.getDays()); } }); }); return GatewayResponse.SUCCESS.newBuilder().toResult(list); } /** * 获取设备活动详情 */ @GetMapping("/get/equipment/activity") public Result getEpActivity() { DateTime now = DateTime.now(); EquipmentActivityReduce equipmentActivityReduce = beanSearcher.searchFirst(EquipmentActivityReduce.class, MapUtils.builder() .field(EquipmentActivityReduce::getSt, now).op(Operator.LessEqual) .field(EquipmentActivityReduce::getEt, now).op(Operator.GreaterThan) .field(EquipmentActivityReduce::getDeleted, 1) .onlySelect(EquipmentActivityReduce::getF, EquipmentActivityReduce::getQ, EquipmentActivityReduce::getTq, EquipmentActivityReduce::getSt, EquipmentActivityReduce::getEt) .build()); return GatewayResponse.SUCCESS.newBuilder().toResult(equipmentActivityReduce); } /** * 获取租赁商品列表 */ @GetMapping("/get/deposit") public Result getDepositGoods() { String depositGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "deposit"; Object o = redisService.get(depositGoodsKey); if (o == null) { List depositList = beanSearcher.searchAll(GoodsDon.class, MapUtils.builder() .field(GoodsDon::getType, 4) .field(GoodsDon::getStatus, true) .field(GoodsDon::getDeleted, true) .onlySelect(GoodsDon::getId, GoodsDon::getTitle, GoodsDon::getLogo) .build()); if (CollUtil.isEmpty(depositList)) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } redisService.setNx(depositGoodsKey, depositList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10)); o = redisService.get(depositGoodsKey); } List depositList = Jsons.parseList(o, GoodsDon.class); return GatewayResponse.SUCCESS.newBuilder().toResult(depositList); } /** * 获取pc广告配置 */ @GetMapping("/get/pc/homeManage") public Result>> getPcHomeManagementFrontPage() { String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:homeManage"; //移除奈飞客厅 临时 Long filterConfigId = null; // if (isHzIp()) { // key += ":hz_ip"; // filterConfigId = 55l; // } Object o = redisService.get(key); if (o == null) { MapBuilder builder = MapUtils.builder() .field(HomeManagementFrontView::getAdType, List.of(HomeManagementConfig.AdType.pc.name(), HomeManagementConfig.AdType.pcSec.name(), HomeManagementConfig.AdType.pcDis.name())).op(Operator.InList); if (filterConfigId != null) { builder.field(HomeManagementFrontView::getHomeManageConfigId, filterConfigId).op(Operator.NotEqual); } List homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build()); Map> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType)); redisService.setNx(key, map, 50 * 60l); o = redisService.get(key); } Map> map = Jsons.parseObject(o, Map.class); return GatewayResponse.SUCCESS.newBuilder().toResult(map); } /** * 获取pc实物配置 */ @GetMapping("/get/pc/realGoodsConfig") public Result getPcRealGoodsConfig() throws Exception { String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:realHomePage"; Object o = redisService.get(key); List list = null; if (o == null) { list = goodsDonFrontService.getRealGoodsConfig(); redisService.setNx(key, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 300); } if (list == null && o != null) { list = Jsons.parseList(o, HomeManagementFrontView.class); } return GatewayResponse.SUCCESS.newBuilder().toResult(list); } /** * 百亿补贴 * 补贴规格列表 */ @GetMapping("/get/subsidy") public Result> getSubsidyGoods() { String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy"; Object o = redisService.get(key); if (o == null) { List subsidyList = beanSearcher.searchAll(GoodsDonSkuSubsidyFrontView.class, MapUtils.builder().build()); subsidyList.forEach(e -> { Optional.ofNullable(beanSearcher.searchFirst(GoodsDonSkuSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, e.getId()).field(GoodsDonSkuSubsidyDetailView::getPrice, e.getPrice()).build())).ifPresent(sku -> { e.setOriPrice(sku.getOriPrice()); e.setMonths(sku.getMonths()); e.setDays(sku.getDays()); e.setSkuId(sku.getId()); e.setPicture(sku.getSubsidyPicture()); }); }); redisService.setNx(key, subsidyList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10)); o = redisService.get(key); } List subsidyList = Jsons.parseList(o, GoodsDonSkuSubsidyFrontView.class); if (CollUtil.isEmpty(subsidyList)) { return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList); } Long userId = StpUserUtil.getUserIdAfterLogin(); if (userId != null) { List relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null); //过滤用户已经购买过平台 List goodsIds = orderDonMapper.getPayGoodsIds(relationUserIdList); if (CollUtil.isNotEmpty(goodsIds)) { subsidyList = subsidyList.stream().filter(data -> !goodsIds.contains(data.getId())).collect(Collectors.toList()); } } return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList); } /** * 百亿补贴规格详情 */ @GetMapping("/get/subsidy/detail/{id}") public Result getSubsidyDetailById(@PathVariable Long id) throws Exception { String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:detail:" + id; Object o = redisService.get(goodsDetailKey); GoodsDonSubsidyDetailView subsidyDetail = null; if (o == null) { subsidyDetail = beanSearcher.searchFirst(GoodsDonSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSubsidyDetailView::getId, id).build()); if (subsidyDetail == null) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } subsidyDetail.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, subsidyDetail.getId()).build())); MapBuilder builder = MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, subsidyDetail.getId()); subsidyDetail.setSkuList(beanSearcher.searchAll(GoodsDonSkuSubsidyDetailView.class, builder.build())); subsidyDetail.setSold(getGoodsSold(subsidyDetail.getId(), subsidyDetail.getSold())); redisService.setNx(goodsDetailKey, Jsons.toJson(subsidyDetail), RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10)); } if (subsidyDetail == null) { o = redisService.get(goodsDetailKey); subsidyDetail = Jsons.parseObject(o.toString(), GoodsDonSubsidyDetailView.class); } return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyDetail); } /** * 可选百亿补贴规格列表 */ @GetMapping("/get/available/subsidy/sku/{goodsId}") public Result> getAvailableSubsidySku(@PathVariable Long goodsId) { String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:" + goodsId; Object o = redisService.get(key); if (o == null) { List goodsDonSkuSubsidyAvailableViews = beanSearcher.searchAll(GoodsDonSkuSubsidyAvailableView.class, MapUtils.builder().put("gid", String.format(" and goods_id = %s", goodsId)).build()); if (CollUtil.isEmpty(goodsDonSkuSubsidyAvailableViews)) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } redisService.set(key, goodsDonSkuSubsidyAvailableViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + RandomUtil.randomInt(10000)); o = redisService.get(key); } List goodsDonSkuSubsidyAvailableViews = Jsons.parseList(o, GoodsDonSkuSubsidyAvailableView.class); return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonSkuSubsidyAvailableViews); } /** * 获取用户店铺首页配置列表 */ @GetMapping("/get/shop/homeManage") public Result>> getShopHomeManageConfig(String customId) { //是否同意展示对应首页广告位 String key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + customId + ":homeManage"; Object o = redisService.get(key); if (o == null) { MapBuilder builder = MapUtils.builder() .field(HomeManagementFrontView::getType, HomeManagementConfig.Type.ad.name()) .field(HomeManagementFrontView::getIsShop, 1); List homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build()); if (homeManagementFrontViews == null) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } Map> map = new ConcurrentHashMap<>(); map.putIfAbsent(HomeManagementConfig.Type.ad.name(), homeManagementFrontViews); redisService.setNx(key, map, 50 * 60l); o = redisService.get(key); } Map map = Jsons.parseObject(o, Map.class); return GatewayResponse.SUCCESS.newBuilder().toResult(map); } /** * 获取套餐列表 */ @GetMapping("/get/upgradePackage") public Result> list(Long skuId) { long userId = StpUserUtil.getLoginIdAsLong(); log.info("userId:{}获取套餐列表", userId); Map build = MapUtils.flatBuilder(request.getParameterMap()).build(); if (skuId != null) { build.put("sku", String.format(" and JSON_CONTAINS(up.sku_ids,'\"%s\"')", skuId)); } SearchResult search = beanSearcher.search(UpgradePackageView.class, build); return GatewayResponse.SUCCESS.newBuilder().toResult(search); } /** * 获取所有平台列表 */ @GetMapping("/get/goods") public Result> getAllGoodsList() { List goodsDons = beanSearcher.searchAll(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap()).field(GoodsDon::getStatus, 1) .onlySelect(GoodsDon::getId, GoodsDon::getTitle) .build()); return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDons); } /** * 获取平台销量 * @param goodsId * @param virtualSold * @return */ private Integer getGoodsSold(Long goodsId, Integer virtualSold) { Object soldObj = redisService.get(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId); if (soldObj == null) { Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class) .eq(OrderDon::getGoodsId, goodsId).notIn(OrderDon::getStatus, Constant.noOrderStatus)); soldObj = sold + virtualSold; redisService.set(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId, soldObj, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout()); } return Integer.parseInt(soldObj.toString()); } /** * 设置平台优惠价格 */ private void setUserCouponGoodsMoney(Long userId, GoodsFrontListCategoryView data) { //登录后 if (userId != null) { //特定价格 BigDecimal specificPrice = data.getSpecificPrice(); //渠道折扣 BigDecimal channelDiscount = data.getChannelDiscount(); //支付来源 Integer source = 0; BigDecimal presentCouponMoney = null; //寻找对应最低规格的优惠券 Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getId(), data.getPrice()); if (coupon != null) { source = 1; data.setDiscount(coupon.getDiscount()); data.setReduceMoney(coupon.getReduceMoney()); data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney())); data.setValidEndTime(coupon.getValidEndTime()); data.setCouponId(coupon.getId()); presentCouponMoney = data.getDiscountPrice(); } if (channelDiscount != null) { BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount); if (presentCouponMoney == null) { presentCouponMoney = channelCouponMoney; } if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) { source = 2; presentCouponMoney = channelCouponMoney; data.setDiscount(channelDiscount); data.setReduceMoney(null); data.setDiscountPrice(channelCouponMoney); data.setValidEndTime(null); data.setCouponId(null); } } if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) { if (presentCouponMoney == null) { presentCouponMoney = specificPrice; } if (specificPrice.compareTo(presentCouponMoney) <= 0) { source = 3; data.setDiscount(null); data.setReduceMoney(null); data.setDiscountPrice(specificPrice); data.setValidEndTime(null); data.setCouponId(null); } } data.setSource(source); } } /** * 设置平台规格优惠价格 */ private void setUserCouponSkuMoney(Long userId, GoodsDonSkuFrontView sku) { //登录后 if (userId != null) { //特定价格 BigDecimal specificPrice = sku.getSpecificPrice(); //渠道折扣 BigDecimal channelDiscount = sku.getChannelDiscount(); //支付来源 Integer source = 0; BigDecimal presentCouponMoney = null; //寻找对应最低规格的优惠券 Coupon coupon = couponUserMapper.selectUserCouponBySkuId(userId, sku.getId()); if (coupon != null) { source = 1; sku.setDiscount(coupon.getDiscount()); sku.setReduceMoney(coupon.getReduceMoney()); sku.setDiscountPrice(sku.getPrice().subtract(coupon.getCouponMoney())); sku.setValidEndTime(coupon.getValidEndTime()); sku.setCouponId(coupon.getId()); presentCouponMoney = sku.getDiscountPrice(); } if (channelDiscount != null) { BigDecimal channelCouponMoney = sku.getPrice().multiply(channelDiscount); if (presentCouponMoney == null) { presentCouponMoney = channelCouponMoney; } if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) { source = 2; presentCouponMoney = channelCouponMoney; sku.setDiscount(channelDiscount); sku.setReduceMoney(null); sku.setDiscountPrice(channelCouponMoney); sku.setValidEndTime(null); sku.setCouponId(null); } } if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) { if (presentCouponMoney == null) { presentCouponMoney = specificPrice; } if (specificPrice.compareTo(presentCouponMoney) <= 0) { source = 3; sku.setDiscount(null); sku.setReduceMoney(null); sku.setDiscountPrice(specificPrice); sku.setValidEndTime(null); sku.setCouponId(null); } } sku.setSource(source); } } /** * 设置推荐平台优惠价格 */ private void setHomeManageUserCouponGoodsMoney(Long userId, HomeManagementFrontView data) { //登录后 if (userId != null) { //特定价格 BigDecimal specificPrice = data.getSpecificPrice(); //渠道折扣 BigDecimal channelDiscount = data.getChannelDiscount(); //支付来源 Integer source = 0; BigDecimal presentCouponMoney = null; //寻找对应最低规格的优惠券 Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getGoodsId(), data.getPrice()); if (coupon != null) { source = 1; data.setDiscount(coupon.getDiscount()); data.setReduceMoney(coupon.getReduceMoney()); data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney())); data.setValidEndTime(coupon.getValidEndTime()); data.setCouponId(coupon.getId()); presentCouponMoney = data.getDiscountPrice(); } if (channelDiscount != null) { BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount); if (presentCouponMoney == null) { presentCouponMoney = channelCouponMoney; } if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) { source = 2; presentCouponMoney = channelCouponMoney; data.setDiscount(channelDiscount); data.setReduceMoney(null); data.setDiscountPrice(channelCouponMoney); data.setValidEndTime(null); data.setCouponId(null); } } if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) { if (presentCouponMoney == null) { presentCouponMoney = specificPrice; } if (specificPrice.compareTo(presentCouponMoney) <= 0) { source = 3; data.setDiscount(null); data.setReduceMoney(null); data.setDiscountPrice(specificPrice); data.setValidEndTime(null); data.setCouponId(null); } } data.setSource(source); } } }