| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113 |
- 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.GoodsDonSkuMapper;
- import com.cyksj.mapper.OrderDonMapper;
- import com.cyksj.mapper.RegisterOrderDonMapper;
- 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.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 RedisService redisService;
- private final SysConfigMapper sysConfigMapper;
- private final ClickRecordFrontService clickRecordFrontService;
- private final YhShopFrontService yhShopFrontService;
- private final UserService userService;
- private final GoodsDonFrontService goodsDonFrontService;
- /**
- * 获取平台商品分类
- */
- @GetMapping("/get/category")
- public Result<List<GoodsDonCategoryFrontView>> getCategory(String customId) {
- Long yhsId = null;
- if (StrUtil.isNotBlank(customId)) {
- yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
- }
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "category";
- if (yhsId != null) {
- key += ":yhShop:" + yhsId;
- }
- Object o = redisService.get(key);
- List<GoodsDonCategoryFrontView> 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<SearchResult<GoodsDonSearchView>> search() {
- SearchResult<GoodsDonSearchView> search = beanSearcher.search(GoodsDonSearchView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 获取商品列表
- */
- @GetMapping("/get")
- public Result<SearchResult<GoodsDon>> get() {
- SearchResult<GoodsDon> 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(goods.getVirtualSold() + orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, goods.getId())
- .notIn(OrderDon::getStatus, Constant.noOrderStatus)));
- });
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 推广未登录,虚拟商品列表
- */
- @GetMapping("/get/popularize")
- @Deprecated
- public Result<SearchResult<GoodsDonPopularizeView>> getPopularizeVipGoods() {
- SearchResult<GoodsDonPopularizeView> 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()));
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + 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<? extends Object> getGoodsList(String customId) {
- if (StrUtil.isNotBlank(customId)) {
- Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
- return shopGoods;
- }
- List<Long> filter_goodsIds = getFilterGoodsIds();
- String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "PC";
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- pcCacheKey += ":hz-ip";
- }
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- Object o = redisService.get(pcCacheKey);
- List<GoodsFrontListView> 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 -> {
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + 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<? extends Object> getGoodsHomePage(String customId) {
- if (StrUtil.isNotBlank(customId)) {
- Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
- return shopGoods;
- }
- List<Long> filter_goodsIds = getFilterGoodsIds();
- String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "H5";
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- h5CacheKey += ":hz-ip";
- }
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- Object o = redisService.get(h5CacheKey);
- List<GoodsFrontListView> 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 -> {
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + 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<List<RegisterGoodsDonView>> getRegisterGoodsDon() {
- String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getEnvName();
- Object value = redisService.get(registerCacheKey);
- if (value != null) {
- try {
- List<RegisterGoodsDonView> 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<RegisterGoodsDonView> 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<? extends Object> getDetail(@PathVariable Long id, String customId, String dsCode) {
- if (StrUtil.isNotBlank(customId) && id != 15) {
- Result<YhShopGoodsFrontView> yhShopGoodsDetail = getGoodsDetailByYhsId(yhShopFrontService.getYhsIdByCustomId(customId), id);
- return yhShopGoodsDetail;
- }
- String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "goods_detail:" + id;
- List<Long> filter_goodsIds = getFilterGoodsIds();
- //存在过滤平台 商品详情不返回
- 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());
- views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
- MapBuilder builder = MapUtils.builder().field(GoodsDonSku::getGoodsId, views.getId()).field(GoodsDonSku::getStatus, true);
- if (views.getType() == 1) {
- builder.orderBy(GoodsDonSku::getOrderBy).asc();
- }
- views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
- 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.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);
- }
- }
- }
- }
- return true;
- }).collect(Collectors.toList()));
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, views.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- views.setSold(sold + views.getSold());
- //评论
- // OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
- // .field(OrderCommentFrontView::getGoodsId, views.getId())
- // .orderBy(OrderCommentFrontView::getCommentTime).desc()
- // .orderBy(OrderCommentFrontView::getId).desc()
- // .build());
- // views.setComments(comments);
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
- }
- /**
- * 获取商品推荐平台
- */
- @GetMapping("/get/recommend/{id}")
- public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, String customId, String dsCode) throws Exception {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "recommend:" + id;
- Long yhsId = null;
- if (StrUtil.isNotBlank(customId)) {
- yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
- key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":recommend:" + id;
- }
- Object o = redisService.get(key);
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- List<GoodsFrontListView> 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<Long> 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());
- }
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(data.getSold() + sold);
- //设置特定价格
- setSpecificPrice(data, fUid, dsUserId.get());
- return true;
- }).collect(Collectors.toList());
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
- }
- /**
- * 获取商品多规格列表
- */
- @GetMapping("/get/sku")
- public Result<List<GoodsDonSkuView>> getGoodsDonSkuView(@RequestParam(value = "skuIds") List<Long> skuIds) {
- if (skuIds.isEmpty()) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- List<GoodsDonSkuView> 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<SearchResult<OrderCommentFrontView>> getComments() {
- SearchResult<OrderCommentFrontView> 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<Map<Integer, List<GiftCardGoodsSkuFrontView>>> getGiftCardDetail(@PathVariable Long id) {
- List<GiftCardGoodsSkuFrontView> giftCardGoodsSkuFrontViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getGoodsId, id).build());
- Map<Integer, List<GiftCardGoodsSkuFrontView>> map = giftCardGoodsSkuFrontViews.stream().collect(Collectors.groupingBy(GiftCardGoodsSkuFrontView::getGcType));
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 获取首页配置列表
- */
- @GetMapping("/get/homeManage")
- public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId, String dsCode) {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "homeManage";
- Long yhsId = null;
- if (StrUtil.isNotBlank(customId)) {
- yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
- key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":homeManage";
- }
- List<Long> filter_goodsIds = getFilterGoodsIds();
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- key += ":hz-ip";
- }
- 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<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
- final String conditionSql = condition;
- Stream.of(HomeManagementConfig.Type.values())
- .forEach(type -> {
- 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<HomeManagementFrontView> 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<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
- if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) {
- try {
- //精彩推荐
- List<HomeManagementFrontView> exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class);
- setHomeConfigGoods(map, HomeManagementConfig.Type.ex, exList, dsUserId, existsChannel, fUid);
- //虚拟平台
- List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
- setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid);
- } catch (Exception e) {
- }
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 首页点击 记录
- */
- @PostMapping("/homePage/click")
- public Result<String> homeManageClick(@RequestBody ClickRecordReq request) {
- Long userId = StpUserUtil.getUserIdAfterLogin();
- clickRecordFrontService.click(userId, request);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- public List<Long> getFilterGoodsIds() {
- List<Long> 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;
- }
- /**
- * @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<Long> 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.getEnvName() + "specific:" + data.getId();
- Object speciObj = redisService.get(specificGoodsKey);
- List<GoodsDonSku> 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<GoodsDonSkuFrontView> 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.getEnvName() + "specific:" + data.getId();
- Object speciObj = redisService.get(specificGoodsKey);
- List<GoodsDonSku> 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<GoodsDonSkuFrontView> skuList = data.getSkuList();
- if (CollUtil.isNotEmpty(skuList)) {
- skuList.forEach(sku -> {
- //设置特定价格
- if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
- sku.setSpecificGoodsIds(null);
- sku.setSpecificPrice(null);
- }
- });
- }
- }
- }
- }
- /**
- * 获取特定规格
- */
- public List<GoodsDonSku> getSpecificSku(Long goodsId) {
- //查找所有特定规格最小价格 满足条件
- String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "specific:" + goodsId;
- Object speciObj = redisService.get(specificGoodsKey);
- List<GoodsDonSku> 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<HomeManagementFrontView> list, Long fUid, Long dsUserId) {
- DateTime now = DateTime.now();
- list.forEach(data -> {
- if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
- //查找所有特定规格最小价格 满足条件
- List<GoodsDonSku> 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);
- }
- }
- });
- }
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getGoodsId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + data.getSold());
- data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
- });
- }
- public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid) 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());
- map.put(type.name(), list);
- }
- }
- /**
- * 店铺平台列表
- */
- @GetMapping("/get/shop/goods/{yhsId}")
- public Result<List<YhShopGoodsFrontView>> getShopGoods(@PathVariable Long yhsId) {
- String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId;
- Object value = redisService.get(yhShopCacheKey);
- List<YhShopGoodsFrontView> 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->{
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + data.getSold());
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- /**
- * 店铺平台详情
- */
- @GetMapping("/get/shop/goods/detail/{yhsId}/{goodsId}")
- public Result<YhShopGoodsFrontView> getGoodsDetailByYhsId(@PathVariable Long yhsId, @PathVariable Long goodsId) {
- 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::getOrderBy).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);
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDetailView);
- }
- /**
- * 根据分类获取对应平台
- */
- @GetMapping("/get/categoryGoods")
- public Result<? extends Object> getGoodsByCategory(Long cgy, String customId, String dsCode) {
- if (StrUtil.isNotBlank(customId)) {
- Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
- return shopGoods;
- }
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "category:goods";
- if (cgy != null) {
- categoryGoodsKey += ":" + cgy;
- }
- List<Long> filter_goodsIds = getFilterGoodsIds();
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- categoryGoodsKey += ":hz-ip";
- }
- Object o = redisService.get(categoryGoodsKey);
- if (o == null) {
- 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<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
- redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
- o = redisService.get(categoryGoodsKey);
- }
- List<GoodsFrontListCategoryView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class);
- DateTime now = DateTime.now();
- AtomicLong dsUserId = new AtomicLong();
- AtomicBoolean existsChannel = new AtomicBoolean(true);
- if (StrUtil.isNotBlank(dsCode)) {
- UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
- dsUserId.set(userSharedDto.getSharedId());
- }
- 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());
- }
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + data.getSold());
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
- //设置特定价格
- setGcSpecificPrice(data, fUid, dsUserId.get());
- return true;
- }).collect(Collectors.toList());
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews);
- }
- @GetMapping("/get/shop/categoryGoods/{yhsId}")
- public Result<List<YhShopGoodsFrontCategoryView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
- String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":category";
- if (category != null) {
- categoryGoodsKey += ":" + category;
- }
- Object value = redisService.get(categoryGoodsKey);
- if (value == null) {
- 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<YhShopGoodsFrontCategoryView> list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build());
- redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60);
- value = redisService.get(categoryGoodsKey);
- }
- List<YhShopGoodsFrontCategoryView> list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class);
- DateTime now = DateTime.now();
- list.forEach(data -> {
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + data.getSold());
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- /**
- * 获取设备活动详情
- */
- @GetMapping("/get/equipment/activity")
- public Result<EquipmentActivityReduce> 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<? extends Object> getDepositGoods() {
- String depositGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "deposit";
- Object o = redisService.get(depositGoodsKey);
- if (o == null) {
- List<GoodsDon> 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<GoodsDon> depositList = Jsons.parseList(o, GoodsDon.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(depositList);
- }
- /**
- * 获取pc广告配置
- */
- @GetMapping("/get/pc/homeManage")
- public Result<Map<String, List<HomeManagementFrontView>>> getPcHomeManagementFrontPage() {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "pc:homeManage";
- 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);
- List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
- Map<HomeManagementConfig.AdType, List<HomeManagementFrontView>> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType));
- redisService.setNx(key, map, 50 * 60l);
- o = redisService.get(key);
- }
- Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 获取pc实物配置
- */
- @GetMapping("/get/pc/realGoodsConfig")
- public Result<? extends Object> getPcRealGoodsConfig() throws Exception {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "pc:realHomePage";
- Object o = redisService.get(key);
- List<HomeManagementFrontView> 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);
- }
- }
|