From db88b87df461820152d68d3d55a28f30c2da83e6 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 20 九月 2019 17:54:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java |  157 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 121 insertions(+), 36 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
index 8d5665f..481652c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -1,5 +1,6 @@
 package com.yeshi.fanli.service.impl.brand;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -9,28 +10,35 @@
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
-import com.yeshi.fanli.dao.brand.BrandGoodsCaheDao;
 import com.yeshi.fanli.dao.brand.BrandShopCaheDao;
 import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper;
+import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
+import com.yeshi.fanli.entity.brand.BrandGoodsCahe;
 import com.yeshi.fanli.entity.brand.BrandInfo;
+import com.yeshi.fanli.entity.jd.JDGoods;
+import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
 import com.yeshi.fanli.entity.taobao.TaoBaoShop;
 import com.yeshi.fanli.exception.brand.BrandInfoException;
 import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
+import com.yeshi.fanli.service.inter.brand.BrandGoodsCaheService;
 import com.yeshi.fanli.service.inter.brand.BrandInfoService;
+import com.yeshi.fanli.service.inter.brand.BrandShopCaheService;
 import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
 import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
 import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
 import com.yeshi.fanli.vo.brand.BrandInfoVO;
 import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
+import com.yeshi.fanli.vo.goods.GoodsDetailVO;
 
 @Service
 public class BrandInfoServiceImpl implements BrandInfoService {
-	
+
 	@Resource
 	private BrandInfoMapper brandInfoMapper;
-	
+
 	@Resource
 	private HongBaoManageService hongBaoManageService;
 
@@ -42,28 +50,29 @@
 
 	@Resource
 	private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
-	
+
 	@Resource
 	private BrandClassShopService brandClassShopService;
 
 	@Resource
 	private BrandShopCaheDao brandShopCaheDao;
-	
+
 	@Resource
-	private BrandGoodsCaheDao brandGoodsCaheDao;
-	
-	
-	
+	private BrandGoodsCaheService brandGoodsCaheService;
+
+	@Resource
+	private BrandShopCaheService brandShopCaheService;
+
 	@Override
-	public void saveObject(BrandInfo record) throws BrandInfoException{
+	public void saveObject(BrandInfo record) throws BrandInfoException {
 		String name = record.getName();
 		if (name == null || name.trim().length() == 0)
 			throw new BrandInfoException(1, "鍚嶇О涓嶈兘涓虹┖");
-		
+
 		Integer state = record.getState();
 		if (state == null)
 			record.setState(0);
-		
+
 		Long id = record.getId();
 		if (id == null) {
 			record.setCreateTime(new Date());
@@ -73,36 +82,33 @@
 			BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
 			if (resultObj == null)
 				throw new BrandInfoException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
-			
+
 			record.setCreateTime(resultObj.getCreateTime());
 			record.setUpdateTime(new Date());
 			brandInfoMapper.updateByPrimaryKey(record);
 		}
 	}
-	
-	
+
 	@Override
 	public int deleteBatchByPrimaryKey(List<Long> list) {
 		return brandInfoMapper.deleteBatchByPrimaryKey(list);
 	}
 
-	
 	@Override
-	public List<BrandInfo> listQuery(long start, int count, String key, Integer state) {
-		return null;
+	public List<BrandInfo> listQuery(long start, int count, String key, Long cid, Integer state) {
+		return brandInfoMapper.listQuery(start, count, key, cid, state);
 	}
 
-
 	@Override
-	public long countQuery(String key, Integer state) {
-		return 0;
+	public long countQuery(String key, Long cid, Integer state) {
+		return brandInfoMapper.countQuery(key, cid, state);
 	}
-	
+
 	@Override
 	@Cacheable(value = "brandCache", key = "'listValidBrandInfoCache-'+#cid")
 	public List<BrandInfo> listValidBrandInfoCache(Long cid) {
 		List<BrandInfo> listInfo = new ArrayList<BrandInfo>();
-		
+
 		List<TaoBaoShop> listShop = brandClassShopService.listEffectiveClassShop(cid);
 		if (listShop == null || listShop.size() == 0)
 			return listInfo;
@@ -115,17 +121,16 @@
 		}
 		return listInfo;
 	}
-	
-	
+
 	@Override
 	@Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid")
 	public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid) {
 		List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
-		
+
 		List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid);
 		if (listShop == null || listShop.size() == 0)
 			return listInfo;
-		
+
 		for (TaoBaoShopVO taoBaoShopVO : listShop) {
 			String shopNameCustom = taoBaoShopVO.getShopNameCustom();
 			if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
@@ -135,7 +140,7 @@
 			if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
 				taoBaoShopVO.setShopIcon(shopIconCustom);
 			}
-			
+
 			BrandInfoVO brandInfoVO = new BrandInfoVO();
 			brandInfoVO.setId(taoBaoShopVO.getId());
 			brandInfoVO.setName(taoBaoShopVO.getShopName());
@@ -146,15 +151,95 @@
 		return listInfo;
 	}
 
-	
 	@Override
-	public long countBrandInfo(Long cid){
+	public long countBrandInfo(Long cid) {
 		return brandClassShopService.countBrandShopinfo(cid);
 	}
-	
-	
-	public void addShopAndGoods(BrandInfo record) {
-		
+
+	@Override
+	public void addShopAndGoods(long start, int count) {
+		List<BrandInfo> list = brandInfoMapper.listValidAll(start, count);
+		if (list == null || list.size() == 0)
+			return;
+
+		for (BrandInfo brandInfo : list) {
+			String key = brandInfo.getName();
+			if (StringUtil.isNullOrEmpty(key))
+				continue;
+
+			// 娣诲姞鍟嗗搧
+			int goodsTotal = brandGoodsCaheService.addBrandGoods(brandInfo);
+
+			brandInfo.setGoodsTotal(goodsTotal);
+			brandInfo.setUpdateTime(new Date());
+			brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
+		}
 	}
-	
+
+	@Override
+	public long countValidByCid(Long cid) {
+		return brandInfoMapper.countValidByCid(cid);
+	}
+
+	@Override
+	public long countValidByCidToApp(Long cid) {
+		return brandInfoMapper.countValidByCidToApp(cid);
+	}
+
+	@Override
+	@Cacheable(value = "brandCache", key = "'listValidByCidToApp-'+#cid")
+	public List<BrandInfo> listValidByCidToApp(Long cid) {
+		if (cid == null)
+			return null;
+		return brandInfoMapper.listValidByCidToApp(cid);
+	}
+
+	@Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#start +'-'+#cid")
+	@Override
+	public List<BrandInfoVO> listValidToApp(long start, int count, Long cid) {
+		List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid);
+		if (list == null || list.size() == 0)
+			return null;
+
+		BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
+		BigDecimal shareRate = hongBaoManageService.getShareRate();
+
+		List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
+		for (int i = 0; i < list.size(); i++) {
+			BrandInfoVO brand = list.get(i);
+			if (brand == null)
+				continue;
+			
+			List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId());
+			if (listGoods == null || listGoods.size() < 3)
+				continue;
+
+			List<GoodsDetailVO> listGoodsVO = new ArrayList<GoodsDetailVO>();
+			for (BrandGoodsCahe brandGoods : listGoods) {
+				JDGoods goodsJD = brandGoods.getGoodsJD();
+				if (goodsJD != null) {
+					listGoodsVO.add(GoodsDetailVOFactory.convertJDGoods(goodsJD, fanLiRate, shareRate));
+					continue;
+				}
+
+				TaoBaoGoodsBrief goodsTB = brandGoods.getGoodsTB();
+				if (goodsTB != null) {
+					listGoodsVO.add(GoodsDetailVOFactory.convertTaoBao(goodsTB, null, fanLiRate, shareRate));
+					continue;
+				}
+
+				PDDGoodsDetail goodsPDD = brandGoods.getGoodsPDD();
+				if (goodsPDD != null) {
+					listGoodsVO.add(GoodsDetailVOFactory.convertPDDGoods(goodsPDD, fanLiRate, shareRate));
+					continue;
+				}
+			}
+
+			if (listGoodsVO.size() >= 3) {
+				brand.setListGoods(listGoodsVO);
+				listInfo.add(brand);
+			}
+		}
+		return listInfo;
+	}
 }

--
Gitblit v1.8.0