| | |
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | |
| | | import com.yeshi.fanli.entity.bus.lable.QualityFlashSale;
|
| | | import com.yeshi.fanli.entity.common.AdminUser;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.exception.QualityFactoryException;
|
| | | import com.yeshi.fanli.exception.goods.quality.QualityFactoryException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsUpdateException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
| | | import com.yeshi.fanli.service.inter.lable.LabelService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityFlashSaleService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | 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;
|
| | |
|
| | |
| | |
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void deleteByGoodsId(List<String> ids) throws QualityFactoryException {
|
| | |
|
| | | if (ids != null && ids.size() > 0) {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void addBatchTaoBaoGoods(List<TaoBaoGoodsBrief> listTaoBaoGoods, String lableNames, AdminUser admin)
|
| | | throws Exception {
|
| | |
|
| | |
| | | }
|
| | |
|
| | | // 创建标签
|
| | | List<Label> listLabel = labelService.addBatchByNames(lableNames, admin);
|
| | | List<Label> listLabs = labelService.addBatchByNames(lableNames, admin);
|
| | | |
| | | |
| | | // 添加商品标签列表
|
| | | List<LabelGoods> listLabelAdd = new ArrayList<LabelGoods>();
|
| | | // 插入商品集合
|
| | | List<TaoBaoGoodsBrief> listGoodsInsert = new ArrayList<TaoBaoGoodsBrief>();
|
| | | // 更新商品集合
|
| | | List<TaoBaoGoodsBrief> listGoodsUpdate = new ArrayList<TaoBaoGoodsBrief>();
|
| | | // 进入精选商品列表
|
| | | List<QualityFactory> listInsertQuality = new ArrayList<QualityFactory>();
|
| | | |
| | |
|
| | | List<QualityFactory> listQuality = new ArrayList<QualityFactory>();
|
| | | List<LabelGoods> listLabelGoods = new ArrayList<LabelGoods>();
|
| | |
|
| | | // 插入商品淘宝ID集合
|
| | | List<Long> listAuctionId = new ArrayList<Long>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : listTaoBaoGoods) {
|
| | | listAuctionId.add(goodsBrief.getAuctionId());
|
| | | }
|
| | | List<Long> listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | |
|
| | | // 本地是否已存在此商品
|
| | | List<TaoBaoGoodsBrief> hasList = taoBaoGoodsBriefService.queryByAuctionId(goodsBrief.getAuctionId());
|
| | |
|
| | | if (hasList != null && hasList.size() > 0) {
|
| | | TaoBaoGoodsBrief currentGoodsBrief = hasList.get(0);
|
| | | goodsBrief.setId(currentGoodsBrief.getId());
|
| | |
|
| | | // 更新商品最新信息
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(goodsBrief);
|
| | | // 遍历商品
|
| | | for (TaoBaoGoodsBrief newGoodsBrief : listTaoBaoGoods) {
|
| | | Long auctionId = newGoodsBrief.getAuctionId();
|
| | | // 设置成主键
|
| | | newGoodsBrief.setId(auctionId);
|
| | | newGoodsBrief.setState(0); // 状态启用
|
| | | newGoodsBrief.setCreatetime(new Date());
|
| | | newGoodsBrief.setUpdatetime(new Date());
|
| | | |
| | | /* 判断商品 是否已经存在数据库 */
|
| | | if (listHas != null && listHas.size() > 0 && listHas.contains(auctionId)) {
|
| | | // 更新商品
|
| | | |
| | | listGoodsUpdate.add(newGoodsBrief); |
| | | // 商品标签
|
| | | if (listLabs != null && listLabs.size() > 0) {
|
| | | for (Label lab: listLabs) {
|
| | | long existence = labelGoodsMapper.isExistence(auctionId, lab.getId());
|
| | | if (existence <= 0) {
|
| | | // 贴上新标签
|
| | | LabelGoods lg = new LabelGoods();
|
| | | lg.setLabel(lab);
|
| | | lg.setCreateUser(admin);
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | listLabelAdd.add(lg);
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | // 更新的商品信息 是否存在精选库中
|
| | | QualityFactory quality = qualityFactoryMapper.getByAuctionId(auctionId);
|
| | | if (quality == null) {
|
| | | QualityFactory selectionGoods = new QualityFactory();
|
| | | selectionGoods.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | selectionGoods.setCreateUser(admin);
|
| | | selectionGoods.setCreatetime(new Date());
|
| | | selectionGoods.setUpdateUser(admin);
|
| | | selectionGoods.setUpdatetime(new Date());
|
| | | selectionGoods.setEntryMode(QualityFactory.MODE_MANUAL);// 人工筛选
|
| | | selectionGoods.setGoodsSource(QualityFactory.SOURCE_TAOBAO);// 来源
|
| | | selectionGoods.setWeight((int) (Math.random() * (4000)));
|
| | | listInsertQuality.add(selectionGoods);
|
| | | } |
| | | } else {
|
| | | goodsBrief.setId(null);
|
| | | goodsBrief.setState(0);
|
| | | goodsBrief.setCreatetime(new Date());
|
| | | goodsBrief.setUpdatetime(new Date());
|
| | | // 非空项 设置默认值
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(goodsBrief);
|
| | | // 保存至本地
|
| | | taoBaoGoodsBriefService.insertSelective(goodsBrief);
|
| | | }
|
| | |
|
| | | // 是否已入库
|
| | | List<QualityFactory> selectionList = qualityFactoryMapper.queryByGoodsId(goodsBrief.getId());
|
| | |
|
| | | if (selectionList == null || selectionList.size() == 0) {
|
| | | // 添加至精选商品库
|
| | | // 设置商品默认值
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(newGoodsBrief);
|
| | | listGoodsInsert.add(newGoodsBrief);
|
| | | |
| | | // 精选库信息
|
| | | QualityFactory selectionGoods = new QualityFactory();
|
| | |
|
| | | selectionGoods.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | selectionGoods.setCreateUser(admin);
|
| | | selectionGoods.setCreatetime(new Date());
|
| | | selectionGoods.setUpdateUser(admin);
|
| | | selectionGoods.setUpdatetime(new Date());
|
| | |
|
| | | selectionGoods.setWeight(50);// 默认50
|
| | | selectionGoods.setTaoBaoGoodsBrief(goodsBrief);
|
| | | selectionGoods.setEntryMode(QualityFactory.MODE_MANUAL);// 人工筛选
|
| | | selectionGoods.setGoodsSource(QualityFactory.SOURCE_TAOBAO);// 来源淘宝
|
| | | selectionGoods.setGoodsSource(QualityFactory.SOURCE_TAOBAO);// 来源
|
| | | selectionGoods.setWeight((int) (Math.random() * (4000)));
|
| | | listInsertQuality.add(selectionGoods);
|
| | |
|
| | | listQuality.add(selectionGoods);
|
| | | } else {
|
| | | // 更新商品
|
| | | QualityFactory selectionGoods = selectionList.get(0);
|
| | | selectionGoods.setUpdatetime(new Date());
|
| | | qualityFactoryMapper.updateByPrimaryKeySelective(selectionGoods);
|
| | | }
|
| | |
|
| | | if (listLabel != null && listLabel.size() > 0) {
|
| | | for (Label label : listLabel) {
|
| | | /* 贴上标签 : 已贴不处理则 */
|
| | | Long existence = labelGoodsMapper.isExistence(goodsBrief.getId(), label.getId());
|
| | |
|
| | | // 该商品不存在此标签则添加, 反之不做处理
|
| | | if (existence == null || existence == 0l) {
|
| | | // 贴上新标签
|
| | | // 商品标签
|
| | | if (listLabs != null && listLabs.size() > 0) {
|
| | | for (Label lab: listLabs) {
|
| | | LabelGoods lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | | lg.setLabel(lab);
|
| | | lg.setCreateUser(admin);
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(goodsBrief);
|
| | | listLabelGoods.add(lg);
|
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | listLabelAdd.add(lg);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | // 插入淘宝商品
|
| | | if (listGoodsInsert.size() > 0) {
|
| | | taoBaoGoodsBriefService.insertBatch(listGoodsInsert);
|
| | | }
|
| | | |
| | | // 更新淘宝商品
|
| | | if (listGoodsUpdate.size() > 0) {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listGoodsUpdate);
|
| | | }
|
| | | |
| | | // 加入精选库
|
| | | if (listInsertQuality.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(listInsertQuality);
|
| | | }
|
| | |
|
| | | if (listQuality.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(listQuality);
|
| | | // 添加标签
|
| | | if (listLabelAdd.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(listLabelAdd);
|
| | | }
|
| | |
|
| | | if (listLabelGoods.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(listLabelGoods);
|
| | | }
|
| | |
|
| | | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void setWeightBatch(List<Long> idList, AdminUser admin, Integer weight, Integer weightSmall,
|
| | | Integer weightLarge) throws Exception {
|
| | |
|
| | |
| | | qualityFactoryMapper.updateWeight(weight, time);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long queryNeedUpdateCount() {
|
| | | return qualityFactoryMapper.countQueryNeedUpdate();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Long> queryNeedUpdate(long start, int count, int hour) {
|
| | | return qualityFactoryMapper.queryNeedUpdate(start, count, hour);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取缓存
|
| | |
| | | * @return
|
| | | */
|
| | | public String getLabelIdByRedis(String key, String title) throws Exception {
|
| | |
|
| | | key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, key);
|
| | | String value = redisManager.getCommonString(key);
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(value)) {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void autoInsertOrUpadateStorage(BoutiqueAutoRule autoRule, List<TaoBaoGoodsBrief> goodsList, List<Label> listLabs) {
|
| | |
|
| | | if (goodsList == null || goodsList.size() == 0) {
|
| | |
| | | for (TaoBaoGoodsBrief goodsBrief : goodsList) {
|
| | | listAuctionId.add(goodsBrief.getAuctionId());
|
| | | }
|
| | | List<Long> listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | |
|
| | | |
| | | List<Long> listHas = new ArrayList<Long>();
|
| | | if (listAuctionId.size() > 0) {
|
| | | listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | | }
|
| | |
|
| | |
|
| | | // 遍历商品
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | |
| | | // 大于100需要分段删除
|
| | | int start = 0;
|
| | | int end = 100;
|
| | |
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 查询精选商品数据应用前端
|
| | | * |
| | | * @param start
|
| | | * @param count
|
| | | * @param key
|
| | | * @param classId
|
| | | * 分类id
|
| | | * @param labId
|
| | | * 标签id
|
| | | * @return
|
| | | */
|
| | |
|
| | | @Override
|
| | | public List<QualityFactory> listQuery(long start, int count, String key, Long classId, Long labId) {
|
| | | return qualityFactoryMapper.listQuery(start, count, key, classId, labId, null, null);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对应查询精选商品数据应用前端统计
|
| | | */
|
| | | |
| | | @Override
|
| | | public long countQuery(String key, Integer goodsSource, Long classId, Long labId) {
|
| | | return qualityFactoryMapper.countQuery(key, classId, labId, null, null);
|
| | | }
|
| | |
|
| | | public LabelGoods screen9K9(TaoBaoGoodsBrief goodsBrief, Map<String, Label> map) {
|
| | | // 贴上新标签
|
| | | LabelGoods lg = null;
|
| | |
|
| | | /* 9k9 */
|
| | | BigDecimal price9k9 = new BigDecimal(10);
|
| | | /* 19k9 */
|
| | | BigDecimal price19k9 = new BigDecimal(20);
|
| | | /* 29.9 */
|
| | | BigDecimal price29K9 = new BigDecimal(30);
|
| | | /* 49.9 */
|
| | | BigDecimal price49K9 = new BigDecimal(50);
|
| | | /* 券后价--计算 */
|
| | | BigDecimal couponPrice = TaoBaoUtil.getAfterUseCouplePrice(goodsBrief);
|
| | |
|
| | | if (couponPrice.compareTo(price9k9) < 0) {
|
| | | Label label = map.get("9.9");
|
| | | if (label == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | |
|
| | | } else if (couponPrice.compareTo(price19k9) < 0) {
|
| | | Label label = map.get("19.9");
|
| | | if (label == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | | } else if (couponPrice.compareTo(price29K9) < 0) {
|
| | | Label label = map.get("29.9");
|
| | | if (label == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | | } else if (couponPrice.compareTo(price49K9) < 0) {
|
| | | Label label = map.get("49.9");
|
| | | if (label == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | |
|
| | | lg.setCreateUser(new AdminUser(2L));
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(goodsBrief);
|
| | |
|
| | | return lg;
|
| | | }
|
| | |
|
| | | @Override
|