|
@@ -11,9 +11,7 @@ import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
-import com.cyksj.model.views.GoodsDonPopularizeView;
|
|
|
|
|
-import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
|
|
-import com.cyksj.model.views.GoodsDonViews;
|
|
|
|
|
|
|
+import com.cyksj.model.views.*;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
import com.ejlchina.searcher.param.Operator;
|
|
@@ -26,9 +24,9 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author chan
|
|
* @author chan
|
|
@@ -87,18 +85,10 @@ public class GoodsDonController {
|
|
|
.orderBy(GoodsDonPopularizeView::getId).asc()
|
|
.orderBy(GoodsDonPopularizeView::getId).asc()
|
|
|
.build());
|
|
.build());
|
|
|
DateTime now = DateTime.now();
|
|
DateTime now = DateTime.now();
|
|
|
|
|
+ LinkedList<GoodsDonPopularizeView> collect = new LinkedList<>();
|
|
|
search.getDataList().forEach(data -> {
|
|
search.getDataList().forEach(data -> {
|
|
|
- GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
|
|
- .eq(GoodsDonSku::getGoodsId, data.getId())
|
|
|
|
|
- .eq(GoodsDonSku::getStatus, true)
|
|
|
|
|
- .orderByAsc(GoodsDonSku::getPrice)
|
|
|
|
|
- .last("limit 1"));
|
|
|
|
|
- Optional.ofNullable(goodsDonSku).ifPresent(sku -> {
|
|
|
|
|
- data.setPrice(sku.getPrice());
|
|
|
|
|
- data.setMonths(sku.getMonths());
|
|
|
|
|
- });
|
|
|
|
|
data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
|
|
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).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)
|
|
Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
.eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
.eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
data.setSold(sold + data.getVirtualSold());
|
|
data.setSold(sold + data.getVirtualSold());
|
|
@@ -106,6 +96,14 @@ public class GoodsDonController {
|
|
|
MapUtils.builder().field(OrderComment::getGoodsId, data.getId())
|
|
MapUtils.builder().field(OrderComment::getGoodsId, data.getId())
|
|
|
.orderBy(OrderComment::getId).desc()
|
|
.orderBy(OrderComment::getId).desc()
|
|
|
.build());
|
|
.build());
|
|
|
|
|
+
|
|
|
|
|
+ Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> {
|
|
|
|
|
+ GoodsDonSku goodsDonSku = skuList.get(0);
|
|
|
|
|
+ if (goodsDonSku != null) {
|
|
|
|
|
+ data.setPrice(goodsDonSku.getPrice());
|
|
|
|
|
+ data.setMonths(goodsDonSku.getMonths());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
if (orderComments != null) {
|
|
if (orderComments != null) {
|
|
|
List<OrderComment> comments = orderComments.getDataList();
|
|
List<OrderComment> comments = orderComments.getDataList();
|
|
|
data.setOrderComments(comments);
|
|
data.setOrderComments(comments);
|
|
@@ -144,8 +142,81 @@ public class GoodsDonController {
|
|
|
}
|
|
}
|
|
|
notifyMsg.append("前有人购买");
|
|
notifyMsg.append("前有人购买");
|
|
|
data.setNotifyMsg(notifyMsg.toString());
|
|
data.setNotifyMsg(notifyMsg.toString());
|
|
|
|
|
+ if (data.getPrice() != null && data.getPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ collect.add(data);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ search = new SearchResult<>(collect);
|
|
|
|
|
+ search.setTotalCount(collect.size());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 官网首页 平台列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/list")
|
|
|
|
|
+ public Result<SearchResult<GoodsFrontListView>> getGoodsList() {
|
|
|
|
|
+ SearchResult<GoodsFrontListView> search = beanSearcher.search(GoodsFrontListView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
|
|
+ .field(GoodsFrontListView::getStatus, true)
|
|
|
|
|
+ .field(GoodsFrontListView::getDeleted, true)
|
|
|
|
|
+ .field(GoodsFrontListView::getType, 1)
|
|
|
|
|
+ .orderBy(GoodsFrontListView::getSortBy).desc()
|
|
|
|
|
+ .orderBy(GoodsFrontListView::getId).asc()
|
|
|
|
|
+ .build());
|
|
|
|
|
+ DateTime now = DateTime.now();
|
|
|
|
|
+ LinkedList<GoodsFrontListView> collect = new LinkedList<>();
|
|
|
|
|
+ search.getDataList().forEach(data -> {
|
|
|
|
|
+ data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
|
|
|
|
|
+ data.setSkuList(beanSearcher.searchAll(GoodsDonFrontSkuView.class, MapUtils.builder().field(GoodsDonFrontSkuView::getGoodsId, data.getId()).field(GoodsDonFrontSkuView::getStatus, true).orderBy(GoodsDonFrontSkuView::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 -> {
|
|
|
|
|
+ GoodsDonFrontSkuView donFrontSkuView = skuList.get(0);
|
|
|
|
|
+ if (donFrontSkuView != null) {
|
|
|
|
|
+ data.setPrice(donFrontSkuView.getPrice());
|
|
|
|
|
+ data.setMonths(donFrontSkuView.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());
|
|
|
|
|
+ if (data.getPrice() != null && data.getPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ collect.add(data);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
- List<GoodsDonPopularizeView> collect = search.getDataList().stream().filter(data -> data.getPrice().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
|
|
|
|
|
search = new SearchResult<>(collect);
|
|
search = new SearchResult<>(collect);
|
|
|
search.setTotalCount(collect.size());
|
|
search.setTotalCount(collect.size());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|