|
|
@@ -2,6 +2,8 @@ package com.uas.platform.b2c.prod.product.component.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.uas.platform.b2c.common.search.rpc.service.SearchService;
|
|
|
+import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentGoodsDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.ComponentGoods;
|
|
|
import com.uas.platform.b2c.prod.product.component.service.ComponentGoodsService;
|
|
|
@@ -14,17 +16,18 @@ import com.uas.platform.b2c.common.search.util.PageParams.FilterField;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ComponentGoodsServiceImpl implements ComponentGoodsService {
|
|
|
@@ -37,6 +40,10 @@ public class ComponentGoodsServiceImpl implements ComponentGoodsService {
|
|
|
|
|
|
@Autowired
|
|
|
private KindService kindService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Page<ComponentGoods> getCompGoodsByKindid(final PageInfo info) {
|
|
|
@@ -90,7 +97,48 @@ public class ComponentGoodsServiceImpl implements ComponentGoodsService {
|
|
|
Long kindid = Long.parseLong(filter.get("kindid").toString());
|
|
|
List<Long> ids = kindService.getLeafChildrenIdList(kindid);
|
|
|
info.expression(PredicateUtils.in("kindid", ids, false));
|
|
|
- filter.remove("kindid");
|
|
|
+ // 该用搜索方式获取数据
|
|
|
+ com.uas.platform.b2c.common.search.util.PageParams pageParams = new com.uas.platform.b2c.common.search.util.PageParams();
|
|
|
+ pageParams.setPage(info.getPageNumber());
|
|
|
+ pageParams.setSize(info.getPageSize());
|
|
|
+ pageParams.filter(FilterField.GOODS_KINDID,ids);
|
|
|
+ pageParams.setSort(new com.uas.platform.b2c.common.search.util.Sort(com.uas.platform.b2c.common.search.util.Sort.Field.RESERVE,true));
|
|
|
+ Map<String,Object> results = searchService.getGoodsIdsForKinds(pageParams);
|
|
|
+ //为了反爬虫,最多只展示前Constant.PAGEMAX的数据,
|
|
|
+ int maxExposeInfo = Constant.PAGEMAX * info.getPageSize();
|
|
|
+ long totalElements = Long.parseLong(results.get("total").toString());
|
|
|
+ if(totalElements > new Long(maxExposeInfo).longValue()) {
|
|
|
+ totalElements = maxExposeInfo;
|
|
|
+ }
|
|
|
+ System.out.println(JSON.toJSON(info));
|
|
|
+ List<Integer> componentIds = (List<Integer>)results.get("componentIds");
|
|
|
+ List<Integer> goodsIds = (List<Integer>)results.get("goodsIds");
|
|
|
+ List<ComponentGoods> components = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(componentIds)) {
|
|
|
+ for (int i = 0 ;i < componentIds.size() ; i++){
|
|
|
+ Long cid = null;
|
|
|
+ if(!StringUtils.isEmpty
|
|
|
+ (componentIds.get(i))) {
|
|
|
+ cid = Long.valueOf(componentIds.get(i).toString());
|
|
|
+ }
|
|
|
+ Long gid = goodsIds.get(i) == null ? 0L : Long.valueOf(goodsIds.get(i).toString());
|
|
|
+ if((cid == null) && (gid != 0L)) {
|
|
|
+ Goods goods = goodsDao.findOne(gid);
|
|
|
+ if(goods != null) {
|
|
|
+ components.add(new ComponentGoods(goods));
|
|
|
+ }
|
|
|
+ }else if(cid != null){
|
|
|
+ ComponentGoods componentGoods = componentGoodsDao.findByCmpIdAndGoId(cid, gid);
|
|
|
+ if (componentGoods != null){
|
|
|
+ components.add(componentGoods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Page page = new PageImpl<>(components, info, totalElements);
|
|
|
+ return page;
|
|
|
+ //filter.remove("kindid");
|
|
|
}
|
|
|
}
|
|
|
Page<ComponentGoods> page = componentGoodsDao.findAll(new Specification<ComponentGoods>() {
|
|
|
@@ -111,5 +159,5 @@ public class ComponentGoodsServiceImpl implements ComponentGoodsService {
|
|
|
page = new PageImpl<>(page.getContent(), info, totalElements);
|
|
|
return page;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|