wangyc 7 лет назад
Родитель
Сommit
04ec546288

+ 9 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/GoodsDao.java

@@ -422,6 +422,15 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
     @Query(value = "select g from Goods g where g.batchid = :batchid")
 	public List<Goods> findByBatchid(@Param("batchid") String batchid);
 
+    /**
+     * Count by StoreUuid and Kindid
+      * @param uuid 店铺uuid
+     * @param kindid 类目id
+     * @return
+     */
+    @Query(value = "select count(1) from Goods g where g.storeid = :uuid and g.kindUuid = :kinid and g.status=601")
+    Integer CountByStoreUuidAndKindid(@Param("uuid") String uuid, @Param("kindid") Long kindid);
+
     /**
      * 获取店铺的所有类目信息
      *

+ 14 - 0
src/main/java/com/uas/platform/b2c/prod/product/kind/model/KindInfo.java

@@ -62,6 +62,12 @@ public class KindInfo {
 	@Column(name = "ki_level")
 	private Short level;
 
+	/**
+	 * 类目下器件数量
+	 */
+	@Transient
+	private Integer count;
+
 	public Long getId() {
 		return id;
 	}
@@ -110,6 +116,14 @@ public class KindInfo {
 		this.level = level;
 	}
 
+	public Integer getCount() {
+		return count;
+	}
+
+	public void setCount(Integer count) {
+		this.count = count;
+	}
+
 	public Set<KindInfo> getChildren() {
 		return children;
 	}

+ 11 - 3
src/main/java/com/uas/platform/b2c/prod/store/facade/impl/CommodityFacadeImpl.java

@@ -6,13 +6,15 @@ import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
 import com.uas.platform.b2c.prod.product.kind.service.KindService;
 import com.uas.platform.b2c.prod.store.facade.CommodityFacade;
 import com.uas.platform.b2c.prod.store.service.CommodityService;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
-import java.util.*;
-
 /**
  * 商品外观实现类
  *
@@ -49,6 +51,10 @@ public class CommodityFacadeImpl implements CommodityFacade {
 				children.addAll(kindList);
 			}
 		}
+		// 补充该店铺各类目下商品数量
+		for (KindInfo kindInfo : children) {
+			kindInfo.setCount(commodityService.CountCommodityByKindAndStore(kindInfo.getId(), storeUuid));
+		}
 		int count = goodsService.getNonstandardGoodsCount(storeUuid); //有效的在售非标数
 		if (!sysConf.getStoreid().equals(storeUuid)) {
 			Long enUU = goodsService.findenUUByStoreid(storeUuid);
@@ -61,7 +67,9 @@ public class CommodityFacadeImpl implements CommodityFacade {
 			}
 		}
 		if (count != 0){ //存在非标则添加其他类目
-			children.add(KindInfo.getOtherKind());
+			KindInfo kindInfo = KindInfo.getOtherKind();
+			kindInfo.setCount(count);
+			children.add(kindInfo);
 		}
 		allKind.setChildren(children);
 		return Collections.singletonList(allKind);

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/store/service/CommodityService.java

@@ -21,4 +21,12 @@ public interface CommodityService {
 	 * 获取所有类目信息
 	 */
 	Set<Long> findAllKinds();
+
+	/**
+	 * 通过店铺uuid和类目id获取上架商品数量
+	 * @param kindid 类目id
+	 * @param storeUuid 店铺uuid
+	 * @return
+	 */
+	Integer CountCommodityByKindAndStore(Long kindid, String storeUuid);
 }

+ 5 - 0
src/main/java/com/uas/platform/b2c/prod/store/service/impl/CommodityServiceImpl.java

@@ -32,4 +32,9 @@ public class CommodityServiceImpl implements CommodityService {
 	public Set<Long> findAllKinds() {
 		return goodsDao.findAllKinds();
 	}
+
+	@Override
+	public Integer CountCommodityByKindAndStore(Long kindid, String storeUuid) {
+		return goodsDao.CountByStoreUuidAndKindid(storeUuid, kindid);
+	}
 }