yujian
2019-02-28 02ece4ea308a26928dea57ca68f0585fef1d2e62
fanli/src/main/java/com/yeshi/fanli/service/impl/lable/QualityFactoryServiceImpl.java
@@ -41,6 +41,7 @@
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.quality.QualityFactoryVO;
@Service
public class QualityFactoryServiceImpl implements QualityFactoryService {
@@ -174,29 +175,13 @@
   }
   @Override
   public List<QualityFactory> query(long start, int count, String key, Integer totalSales, Integer price,
         Integer tkRate, Integer propor, Integer goodsSource, Integer days, Integer startZkPrice, Integer endZkPrice,
         Integer startBiz30day, Integer endBiz30day, Integer startWeight, Integer endWeight, Integer startTkRate,
         Integer endTkRate, Integer startAmount, Integer endAmount, Integer hasCoupon, Integer freeShipment,
         Integer isPrepay, Integer payRate30, Integer goodRate, Integer rfdRate, Integer startPropor,
         Integer endPropor, Long gcid, Integer keyType) throws QualityFactoryException {
      return qualityFactoryMapper.query(start, count, key, totalSales, price, tkRate, propor, goodsSource, days,
            startZkPrice, endZkPrice, startBiz30day, endBiz30day, startWeight, endWeight, startTkRate, endTkRate,
            startAmount, endAmount, hasCoupon, freeShipment, isPrepay, payRate30, goodRate, rfdRate, startPropor,
            endPropor, gcid, keyType);
   public List<QualityFactory> query(QualityFactoryVO qualityFactoryVO) throws QualityFactoryException {
      return qualityFactoryMapper.query(qualityFactoryVO);
   }
   @Override
   public long queryCount(String key, Integer goodsSource, Integer days, Integer startZkPrice, Integer endZkPrice,
         Integer startBiz30day, Integer endBiz30day, Integer startWeight, Integer endWeight, Integer startTkRate,
         Integer endTkRate, Integer startAmount, Integer endAmount, Integer hasCoupon, Integer freeShipment,
         Integer isPrepay, Integer payRate30, Integer goodRate, Integer rfdRate, Integer startPropor,
         Integer endPropor, Long gcid, Integer keyType) throws QualityFactoryException {
      return qualityFactoryMapper.queryCount(key, goodsSource, days, startZkPrice, endZkPrice, startBiz30day,
            endBiz30day, startWeight, endWeight, startTkRate, endTkRate, startAmount, endAmount, hasCoupon,
            freeShipment, isPrepay, payRate30, goodRate, rfdRate, startPropor, endPropor, gcid, keyType);
   public long queryCount(QualityFactoryVO qualityFactoryVO) throws QualityFactoryException {
      return qualityFactoryMapper.queryCount(qualityFactoryVO);
   }
   @Override
@@ -216,98 +201,61 @@
   @Override
   @Transactional
   public void addBatch(List<Long> auctionIdList, String lableNames, AdminUser admin) throws Exception {
      List<Label> listLabs = new ArrayList<Label>();
      if (!StringUtil.isNullOrEmpty(lableNames)) {
         // 空格隔开
         String[] arrtitles = lableNames.split("\\s+");
         for (String title : arrtitles) {
            /* 遍历标签名称:查询数据库中是否已存在 */
            List<Label> labels = labelService.selectByTitle(title.trim());
            if (labels != null && labels.size() > 0) {
               Label label = labels.get(0);
               listLabs.add(label);
            } else {
               // 新增
               Label label = new Label();
               label.setTitle(title);// 名称
               label.setEntrymode(Label.MODE_SYSTEM); // 批量录入
               label.setCreatetime(new Date());
               label.setUpdatetime(new Date());
               label.setCreateUser(admin);
               label.setIosClick(0l);
               label.setAndroidClick(0l);
               labelService.insertSelective(label);
               listLabs.add(label);
   public void addBatchGoodsByTaoBaoId(List<Long> listTaoBaoId, String lableNames, AdminUser admin)
         throws Exception {
      List<TaoBaoGoodsBrief> listAddGoods = new ArrayList<TaoBaoGoodsBrief>();
      if (listTaoBaoId != null && listTaoBaoId.size() > 0) {
         for (Long auctionId: listTaoBaoId) {
            /* 根据auctionId 获取淘宝商品 */
            TaoBaoGoodsBrief goodsBrief = TaoKeApiUtil.searchGoodsDetail(auctionId);
            if (goodsBrief != null) {
               listAddGoods.add(goodsBrief);
            }
         }
      }
   }
      List<TaoBaoGoodsBrief> existList = taoBaoGoodsBriefRecordMapper.queryByAuctionIdList(auctionIdList);
   @Override
   @Transactional
   public void addBatchTaoBaoGoods(List<TaoBaoGoodsBrief> listTaoBaoGoods, String lableNames, AdminUser admin) throws Exception {
      if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) {
         throw new Exception("未找到匹配的商品");
      }
      // 创建标签
      List<Label> listLabel = labelService.addBatchByNames(lableNames, admin);
      List<QualityFactory> addList = new ArrayList<QualityFactory>();
      List<LabelGoods> addLabelList = new ArrayList<LabelGoods>();
      List<QualityFactory> listQuality = new ArrayList<QualityFactory>();
      List<LabelGoods> listLabelGoods = new ArrayList<LabelGoods>();
      for (Long auctionId : auctionIdList) {
      for (TaoBaoGoodsBrief goodsBrief: listTaoBaoGoods) {
         boolean process = false;
         TaoBaoGoodsBrief goodsBrief = null;
         // 本地是否已存在此商品
         List<TaoBaoGoodsBrief> hasList = taoBaoGoodsBriefService.queryByAuctionId(goodsBrief.getAuctionId());
         if (existList != null && existList.size() > 0) {
            for (TaoBaoGoodsBrief taoBaoGoodsBrief : existList) {
               Long aId = taoBaoGoodsBrief.getAuctionId();
               if (auctionId.equals(aId)) {
                  goodsBrief = taoBaoGoodsBrief;
                  goodsBrief.setId(null);
                  process = true;
               }
            }
         }
         if (!process) {
            /* 根据auctionId 获取淘宝商品 */
            goodsBrief = redisManager.getTaoBaoGoodsBrief(auctionId);
         }
         if (goodsBrief == null)
            continue;
         /* 判断商品 是否已经存在数据库 */
         List<TaoBaoGoodsBrief> taoBaoGoodsBriefList = taoBaoGoodsBriefService.queryByAuctionId(auctionId);
         if (taoBaoGoodsBriefList != null && taoBaoGoodsBriefList.size() > 0) {
            TaoBaoGoodsBrief currentGoodsBrief = taoBaoGoodsBriefList.get(0);
         if (hasList != null && hasList.size() > 0) {
            TaoBaoGoodsBrief currentGoodsBrief = hasList.get(0);
            goodsBrief.setId(currentGoodsBrief.getId());
            // 更新商品最新信息
            taoBaoGoodsUpdateService.updateTaoBaoGoods(goodsBrief);
         } else {
            // 插入本地数据库
            goodsBrief.setId(null);
            goodsBrief.setState(0);
            goodsBrief.setCreatetime(new Date());
            goodsBrief.setUpdatetime(new Date());
            // 非空项 处理
            // 非空项 设置默认值
            setTaoBaoGoodsBriefDefault(goodsBrief);
            // 保存至本地
            taoBaoGoodsBriefService.insertSelective(goodsBrief);
         }
         // 是否已入库
         Long id = goodsBrief.getId();
         List<QualityFactory> selectionList = qualityFactoryMapper.queryByGoodsId(id);
         List<QualityFactory> selectionList = qualityFactoryMapper.queryByGoodsId(goodsBrief.getId());
         /* 进入精选商品库 */
         if (selectionList == null || selectionList.size() == 0) {
            // 添加至精选商品库
            QualityFactory selectionGoods = new QualityFactory();
@@ -322,7 +270,7 @@
            selectionGoods.setEntryMode(QualityFactory.MODE_MANUAL);// 人工筛选
            selectionGoods.setGoodsSource(QualityFactory.SOURCE_TAOBAO);// 来源淘宝
            addList.add(selectionGoods);
            listQuality.add(selectionGoods);
         } else {
            // 更新商品
            QualityFactory selectionGoods = selectionList.get(0);
@@ -330,10 +278,10 @@
            qualityFactoryMapper.updateByPrimaryKeySelective(selectionGoods);
         }
         if (listLabs.size() > 0) {
            for (Label label : listLabs) {
         if (listLabel != null && listLabel.size() > 0) {
            for (Label label : listLabel) {
               /* 贴上标签 : 已贴不处理则 */
               Long existence = labelGoodsMapper.isExistence(id, label.getId());
               Long existence = labelGoodsMapper.isExistence(goodsBrief.getId(), label.getId());
               // 该商品不存在此标签则添加, 反之不做处理
               if (existence == null || existence == 0l) {
@@ -343,23 +291,24 @@
                  lg.setCreateUser(admin);
                  lg.setCreatetime(new Date());
                  lg.setTaoBaoGoodsBrief(goodsBrief);
                  addLabelList.add(lg);
                  listLabelGoods.add(lg);
               }
            }
         }
      }
      if (addList.size() > 0) {
         qualityFactoryMapper.insertBatch(addList);
      if (listQuality.size() > 0) {
         qualityFactoryMapper.insertBatch(listQuality);
      }
      if (addLabelList.size() > 0) {
         labelGoodsMapper.insertBatch(addLabelList);
      if (listLabelGoods.size() > 0) {
         labelGoodsMapper.insertBatch(listLabelGoods);
      }
   }
   @Override
   @Transactional
   public void setWeightBatch(List<Long> idList, AdminUser admin, Integer weight, Integer weightSmall,