|
|
@@ -7,7 +7,6 @@ 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.Assert;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
@@ -19,10 +18,10 @@ import com.cyksj.mapper.OrderDonMapper;
|
|
|
import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
-import com.cyksj.model.request.HomeManagementClickRecordReq;
|
|
|
+import com.cyksj.model.request.ClickRecordReq;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
-import com.cyksj.service.home.HomeManagementFrontService;
|
|
|
+import com.cyksj.service.home.ClickRecordFrontService;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
@@ -34,9 +33,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @author chan
|
|
|
@@ -62,15 +61,32 @@ public class GoodsDonController {
|
|
|
|
|
|
private final SysConfigMapper sysConfigMapper;
|
|
|
|
|
|
- private final HomeManagementFrontService homeManagementFrontService;
|
|
|
+ private final ClickRecordFrontService clickRecordFrontService;
|
|
|
|
|
|
/**
|
|
|
* 获取平台商品分类
|
|
|
*/
|
|
|
@GetMapping("/get/category")
|
|
|
- public Result<SearchResult<GoodsDonCategoryFrontView>> getCategory() {
|
|
|
- SearchResult<GoodsDonCategoryFrontView> search = beanSearcher.search(GoodsDonCategoryFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
- .build());
|
|
|
+ public Result<List<GoodsDonCategoryFrontView>> getCategory() {
|
|
|
+ String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category";
|
|
|
+ Object o = redisService.get(key);
|
|
|
+ List<GoodsDonCategoryFrontView> list;
|
|
|
+ if (o == null) {
|
|
|
+ list = beanSearcher.searchAll(GoodsDonCategoryFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .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);
|
|
|
}
|
|
|
|
|
|
@@ -290,6 +306,10 @@ public class GoodsDonController {
|
|
|
public Result<GoodsDonViews> getDetail(@PathVariable Long id) {
|
|
|
GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, id).build());
|
|
|
|
|
|
+ Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getGoodsId, views.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ views.setSold(sold + views.getVirtualSold());
|
|
|
+
|
|
|
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);
|
|
|
|
|
|
@@ -365,6 +385,42 @@ public class GoodsDonController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取首页配置列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/homeManage")
|
|
|
+ public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage() {
|
|
|
+ String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "homeManage";
|
|
|
+ Object o = redisService.get(key);
|
|
|
+ if (o == null) {
|
|
|
+ String condition = "g.deleted is true and g.status is true";
|
|
|
+ Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
|
|
|
+ Stream.of(HomeManagementConfig.Type.values())
|
|
|
+ .forEach(type -> {
|
|
|
+ MapBuilder builder = MapUtils.builder()
|
|
|
+ .field(HomeManagementConfig::getType, type.name());
|
|
|
+ if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
|
|
|
+ builder.put("condition", condition);
|
|
|
+ }
|
|
|
+ List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
|
|
|
+ map.putIfAbsent(type.name(), homeManagementFrontViews);
|
|
|
+ });
|
|
|
+ redisService.setNx(key, map, 50 * 60l);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(map);
|
|
|
+ }
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(Jsons.parseObject(o, Map.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页点击 记录
|
|
|
+ */
|
|
|
+ @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() {
|
|
|
//过滤杭州Ai ChatGPT平台
|
|
|
//获取当前ip地址
|
|
|
@@ -389,74 +445,49 @@ public class GoodsDonController {
|
|
|
* @return
|
|
|
*/
|
|
|
public String getPayMsgTime(Long goodsId, DateTime now, Integer type) {
|
|
|
- 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)
|
|
|
- .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();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取首页配置列表
|
|
|
- */
|
|
|
- @GetMapping("/get/homeManage")
|
|
|
- public Result<List<HomeManagementFrontView>> getHomeManagementFrontPage() {
|
|
|
- List<HomeManagementFrontView> views = beanSearcher.searchAll(HomeManagementFrontView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 记录首页配置 用户点击记录
|
|
|
- */
|
|
|
- @PostMapping("/homeManage/click")
|
|
|
- public Result<String> homeManageClick(@RequestBody HomeManagementClickRecordReq request) {
|
|
|
- Long userId = null;
|
|
|
- Boolean isLogin = request.getIsLogin();
|
|
|
- Long configId = request.getConfigId();
|
|
|
- Assert.notNull(configId, "参数错误");
|
|
|
- if (isLogin != null && isLogin) {
|
|
|
- userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ 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)
|
|
|
+ .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();
|
|
|
}
|
|
|
- homeManagementFrontService.click(userId, configId);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ 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();
|
|
|
}
|
|
|
}
|