| | |
| | | package com.yeshi.fanli.service.impl.lable;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.TaoBaoClassRelationMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.lable.LabelGoodsMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.lable.QualityFactoryMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.lable.QualityFlashSaleMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper;
|
| | | import com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule;
|
| | | import com.yeshi.fanli.entity.bus.lable.Label;
|
| | | import com.yeshi.fanli.entity.bus.lable.LabelGoods;
|
| | | import com.yeshi.fanli.entity.bus.lable.QualityFactory;
|
| | | import com.yeshi.fanli.entity.bus.lable.QualityFlashSale;
|
| | | import com.yeshi.fanli.entity.common.AdminUser;
|
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
|
| | | 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.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.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import com.yeshi.fanli.vo.quality.QualityFactoryVO;
|
| | |
|
| | | @Service
|
| | | public class QualityFactoryServiceImpl implements QualityFactoryService {
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | | @Resource
|
| | | private QualityFactoryMapper qualityFactoryMapper;
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
| | | @Resource
|
| | | private LabelGoodsMapper labelGoodsMapper;
|
| | | @Resource
|
| | | private LabelService labelService;
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper;
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | | @Resource
|
| | | private TaoBaoClassRelationMapper taoBaoClassRelationMapper;
|
| | | @Resource
|
| | | private QualityFlashSaleService qualityFlashSaleService;
|
| | | @Resource
|
| | | private QualityFlashSaleMapper qualityFlashSaleMapper;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKeySelective(QualityFactory record) throws QualityFactoryException {
|
| | | return qualityFactoryMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void deleteByTaoBaoGoodsId(Long auctionId) {
|
| | | if (auctionId == null) {
|
| | | return;
|
| | | }
|
| | | // 移除精选库
|
| | | qualityFactoryMapper.deleteByGoodsId(auctionId);
|
| | | // 删除限时抢购
|
| | | qualityFlashSaleMapper.deleteByGoodsId(auctionId);
|
| | | // 删除对应标签
|
| | | labelGoodsMapper.deleteByGoodsId(auctionId);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public void deleteBatchByTaoBaoGoodsId(List<Long> listGid) {
|
| | |
|
| | | if (listGid == null || listGid.size() == 0) {
|
| | | return;
|
| | | }
|
| | | // 批量删除精选库
|
| | | qualityFactoryMapper.deleteBatchByGoodsId(listGid);
|
| | | // 批量删除限时抢购
|
| | | qualityFlashSaleMapper.deleteBatchByQualityID(listGid);
|
| | | // 删除对应标签
|
| | | labelGoodsMapper.deleteBatchByGoodsId(listGid);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void deleteByGoodsId(List<String> ids) throws QualityFactoryException {
|
| | |
|
| | | if (ids != null && ids.size() > 0) {
|
| | | for (String goodsId : ids) {
|
| | | qualityFactoryMapper.deleteByGoodsId(Long.parseLong(goodsId));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public QualityFactory selectByPrimaryKey(Long id) throws QualityFactoryException {
|
| | | return qualityFactoryMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Long> getAuctionIdbyClassId(Long systemCid, Integer goodsSource, String dateTime){
|
| | | return qualityFactoryMapper.getAuctionIdbyClassId(systemCid, goodsSource, dateTime);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<QualityFactory> queryAll(long start, int count, Integer days) {
|
| | | return qualityFactoryMapper.queryAll(start, count, days);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<QualityFactory> query(QualityFactoryVO qualityFactoryVO) throws QualityFactoryException {
|
| | | return qualityFactoryMapper.query(qualityFactoryVO);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long queryCount(QualityFactoryVO qualityFactoryVO) throws QualityFactoryException {
|
| | | return qualityFactoryMapper.queryCount(qualityFactoryVO);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getCountAll() {
|
| | | return qualityFactoryMapper.getCountAll();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Long queryCountByGoodsId(Long goodsId) {
|
| | | return qualityFactoryMapper.queryCountByGoodsId(goodsId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<QualityFactory> listQueryByAuctionId(List<Long> list) {
|
| | | return qualityFactoryMapper.listQueryByAuctionId(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void addBatchTaoBaoGoods(List<TaoBaoGoodsBrief> listTaoBaoGoods, String lableNames, AdminUser admin)
|
| | | throws Exception {
|
| | |
|
| | | if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) {
|
| | | throw new Exception("未找到匹配的商品");
|
| | | }
|
| | |
|
| | | // 创建标签
|
| | | 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>();
|
| | | |
| | |
|
| | | // 插入商品淘宝ID集合
|
| | | List<Long> listAuctionId = new ArrayList<Long>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : listTaoBaoGoods) {
|
| | | listAuctionId.add(goodsBrief.getAuctionId());
|
| | | }
|
| | | List<Long> listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | |
|
| | | // 遍历商品
|
| | | 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 {
|
| | | // 设置商品默认值
|
| | | 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.setEntryMode(QualityFactory.MODE_MANUAL);// 人工筛选
|
| | | selectionGoods.setGoodsSource(QualityFactory.SOURCE_TAOBAO);// 来源
|
| | | selectionGoods.setWeight((int) (Math.random() * (4000)));
|
| | | listInsertQuality.add(selectionGoods);
|
| | |
|
| | | // 商品标签
|
| | | if (listLabs != null && listLabs.size() > 0) {
|
| | | for (Label lab: listLabs) {
|
| | | LabelGoods lg = new LabelGoods();
|
| | | lg.setLabel(lab);
|
| | | lg.setCreateUser(admin);
|
| | | lg.setCreatetime(new Date());
|
| | | 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 (listLabelAdd.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(listLabelAdd);
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void setWeightBatch(List<Long> idList, AdminUser admin, Integer weight, Integer weightSmall,
|
| | | Integer weightLarge) throws Exception {
|
| | |
|
| | | for (Long selectId : idList) {
|
| | |
|
| | | QualityFactory selectionGoods = qualityFactoryMapper.selectByPrimaryKey(selectId);
|
| | |
|
| | | if (selectionGoods == null) {
|
| | | continue;
|
| | | }
|
| | | // 默认 50
|
| | | int resultWeight = 50;
|
| | |
|
| | | if (weight != null) {
|
| | | resultWeight = weight;
|
| | | } else {
|
| | | if (weightSmall != null && weightLarge != null) {
|
| | | // 随机权重
|
| | | resultWeight = weightSmall + (int) (Math.random() * ((weightLarge - weightSmall) + 1));
|
| | | }
|
| | | }
|
| | |
|
| | | // 修改权重
|
| | | selectionGoods.setUpdateUser(admin);
|
| | | selectionGoods.setWeight(resultWeight);
|
| | | qualityFactoryMapper.updateByPrimaryKeySelective(selectionGoods);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Long countTotalRows(Integer days) {
|
| | | return qualityFactoryMapper.countTotalRows(days);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateWeight(Integer weight, Integer time) {
|
| | | qualityFactoryMapper.updateWeight(weight, time);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 获取缓存
|
| | | * |
| | | * @param key
|
| | | * 键
|
| | | * @param title
|
| | | * 标签名称
|
| | | * @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)) {
|
| | |
|
| | | // id为空时系统进行查询
|
| | | List<Label> list9K9 = labelService.selectByTitle(title);
|
| | |
|
| | | if (list9K9 != null && list9K9.size() > 0) {
|
| | | Long id = list9K9.get(0).getId();
|
| | | if (id != null) {
|
| | | value = id + "";
|
| | | // 缓存20分钟
|
| | | redisManager.cacheCommonString(key, value, 60 * 20);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return value;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateQualityGoods(Long goodsId) {
|
| | | if (goodsId == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | boolean isDelete = false;
|
| | | try {
|
| | | // 获取详情
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(goodsId);
|
| | | if(goods == null) {
|
| | | isDelete = true;
|
| | | } else if (goods.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) {
|
| | | isDelete = true;
|
| | | }
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | isDelete = true;
|
| | | }
|
| | | |
| | | // 移除精选库
|
| | | if (isDelete) {
|
| | | deleteByTaoBaoGoodsId(goodsId);
|
| | | taoBaoGoodsBriefService.deleteByPrimaryKey(goodsId);
|
| | | return;
|
| | | }
|
| | | |
| | | goods.setId(goodsId);
|
| | | goods.setCreatetime(new Date());
|
| | | goods.setUpdatetime(new Date());
|
| | | try {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(goods);
|
| | | } catch (TaobaoGoodsUpdateException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void autoInsertOrUpadateStorage(BoutiqueAutoRule autoRule, List<TaoBaoGoodsBrief> goodsList, List<Label> listLabs) {
|
| | |
|
| | | if (goodsList == null || goodsList.size() == 0) {
|
| | | return;
|
| | | }
|
| | | |
| | | /* 来源推荐商品 需要获取详情 */
|
| | | if (QualityFactory.SOURCE_TAOBAO_MATERIAL == autoRule.getGoodsSource()) {
|
| | | List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
|
| | | |
| | | goodsList.parallelStream().forEach(goods -> {
|
| | | try {
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = TaoKeApiUtil.searchGoodsDetail(goods.getAuctionId());
|
| | | if (taoBaoGoodsBrief != null) {
|
| | | listGoodsBrief.add(taoBaoGoodsBrief);
|
| | | }
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | });
|
| | | |
| | | goodsList.clear();
|
| | | goodsList = listGoodsBrief;
|
| | |
|
| | | if (goodsList == null || goodsList.size() == 0) {
|
| | | return;
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | // for (int i = 0; i < goodsList.size(); i++) {
|
| | | // if (goodsList.get(i).getMaterialLibType() != null && goodsList.get(i).getMaterialLibType() == 0) {
|
| | | // goodsList.remove(i);
|
| | | // i--;
|
| | | // }
|
| | | // }
|
| | | |
| | |
|
| | | // 添加商品标签列表
|
| | | 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> listUpdateQuality = new ArrayList<QualityFactory>();
|
| | | |
| | | // 插入商品淘宝ID集合
|
| | | List<Long> listAuctionId = new ArrayList<Long>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : goodsList) {
|
| | | listAuctionId.add(goodsBrief.getAuctionId());
|
| | | }
|
| | | |
| | | List<Long> listHas = new ArrayList<Long>();
|
| | | if (listAuctionId.size() > 0) {
|
| | | listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | | }
|
| | | |
| | | |
| | | // 遍历商品
|
| | | for (TaoBaoGoodsBrief newGoodsBrief : goodsList) {
|
| | | 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(autoRule.getAdminUser());
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | listLabelAdd.add(lg);
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | // 更新的商品信息 是否存在精选库中
|
| | | QualityFactory quality = qualityFactoryMapper.getByAuctionId(auctionId);
|
| | | if (quality == null) {
|
| | | listInsertQuality.add(getNewQualityFactory(newGoodsBrief, autoRule));
|
| | | } else {
|
| | | // 随机权重
|
| | | int weight = autoRule.getStartWeight()
|
| | | + (int) (Math.random() * ((autoRule.getEndWeight() - autoRule.getStartWeight()) + 1));
|
| | | quality.setWeight(weight);
|
| | | // 更新时间
|
| | | quality.setUpdatetime(new Date());
|
| | | // 更新来源规则
|
| | | quality.setBoutiqueAutoRule(autoRule);
|
| | | // 更新来源类别
|
| | | quality.setSourceCalss(autoRule.getSourceCalss());
|
| | | // 来源
|
| | | quality.setGoodsSource(autoRule.getGoodsSource());
|
| | | listUpdateQuality.add(quality);
|
| | | }
|
| | | |
| | | } else {
|
| | | // 设置商品默认值
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(newGoodsBrief);
|
| | | listGoodsInsert.add(newGoodsBrief);
|
| | | |
| | | // 精选库信息
|
| | | listInsertQuality.add(getNewQualityFactory(newGoodsBrief, autoRule));
|
| | |
|
| | | // 商品标签
|
| | | if (listLabs != null && listLabs.size() > 0) {
|
| | | for (Label lab: listLabs) {
|
| | | LabelGoods lg = new LabelGoods();
|
| | | lg.setLabel(lab);
|
| | | lg.setCreateUser(autoRule.getAdminUser());
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | listLabelAdd.add(lg);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 插入淘宝商品
|
| | | if (listGoodsInsert.size() > 0) {
|
| | | taoBaoGoodsBriefService.insertBatch(listGoodsInsert);
|
| | | }
|
| | | |
| | | // 更新淘宝商品
|
| | | if (listGoodsUpdate.size() > 0) {
|
| | | try {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listGoodsUpdate);
|
| | | } catch (TaobaoGoodsUpdateException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | // 加入精选库
|
| | | if (listInsertQuality.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(listInsertQuality);
|
| | | }
|
| | |
|
| | | // 更新精选库
|
| | | if (listUpdateQuality.size() > 0) {
|
| | | qualityFactoryMapper.updateBatchSelective(listUpdateQuality);
|
| | | }
|
| | |
|
| | | // 添加标签
|
| | | if (listLabelAdd.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(listLabelAdd);
|
| | | }
|
| | |
|
| | | // 加入限时抢购
|
| | | if (autoRule.isFlashSale()) {
|
| | | updateQualityFlashSale(goodsList, autoRule);
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 限时秒杀
|
| | | * @param listinsert
|
| | | * @param listUpdate
|
| | | * @param autoRule
|
| | | */
|
| | | public void updateQualityFlashSale(List<TaoBaoGoodsBrief> listGoods, BoutiqueAutoRule autoRule) {
|
| | | |
| | | List<Long> listQFId = new ArrayList<Long>();
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoods) {
|
| | | listQFId.add(taoBaoGoodsBrief.getId());
|
| | | }
|
| | |
|
| | | int startWeight = autoRule.getStartWeight();
|
| | | int endWeight = autoRule.getEndWeight();
|
| | | int goodsSource = autoRule.getGoodsSource();
|
| | |
|
| | | // 加入入限时抢购
|
| | | List<QualityFlashSale> listFlashSale = new ArrayList<QualityFlashSale>();
|
| | | // 限时抢购更新:
|
| | | List<QualityFlashSale> listFlashSaleUpdate = new ArrayList<QualityFlashSale>();
|
| | | |
| | |
|
| | | // 查询已存在显示限时抢购的商品
|
| | | List<QualityFlashSale> listQuery = qualityFlashSaleService.listQueryByQualityID(listQFId);
|
| | | |
| | | if (listQuery == null || listQuery.size() == 0) {
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief: listGoods) {
|
| | | listFlashSale.add(getNewQualityFlashSale(taoBaoGoodsBrief, startWeight, endWeight, goodsSource));
|
| | | }
|
| | | } else {
|
| | | |
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief: listGoods) {
|
| | | boolean exist = false;
|
| | | Long id = taoBaoGoodsBrief.getId();
|
| | | |
| | | for (QualityFlashSale flashSale : listQuery) {
|
| | | TaoBaoGoodsBrief goodsBrief = flashSale.getTaoBaoGoodsBrief();
|
| | | if (id.equals(goodsBrief.getId())) {
|
| | | exist = true;
|
| | | double weight = startWeight + (Math.random() * ((endWeight - startWeight) + 1));
|
| | | flashSale.setWeight(weight);
|
| | | flashSale.setUpdatetime(new Date());
|
| | | listFlashSaleUpdate.add(flashSale);
|
| | | listQuery.remove(flashSale);
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | if (!exist) {
|
| | | listFlashSale.add(getNewQualityFlashSale(taoBaoGoodsBrief, startWeight, endWeight, goodsSource));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 插入限时抢购
|
| | | if (listFlashSale.size() > 0) {
|
| | | qualityFlashSaleService.insertBatch(listFlashSale);
|
| | | }
|
| | |
|
| | | // 更新限时抢购
|
| | | if (listFlashSaleUpdate.size() > 0) {
|
| | | qualityFlashSaleService.updateBatchSelective(listFlashSaleUpdate);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建新对象QualityFlashSale
|
| | | * |
| | | * @param qfId
|
| | | * @param i
|
| | | * @return
|
| | | */
|
| | | public QualityFlashSale getNewQualityFlashSale(TaoBaoGoodsBrief taoBaoGoodsBrief, int startWeight, |
| | | int endWeight, int goodsSource) {
|
| | |
|
| | | QualityFlashSale flashSale = new QualityFlashSale();
|
| | | flashSale.setTaoBaoGoodsBrief(taoBaoGoodsBrief);
|
| | | flashSale.setCreatetime(new Date());
|
| | | flashSale.setUpdatetime(new Date());
|
| | | |
| | | // 权重设置:大淘客优先展示
|
| | | double weight = 0;
|
| | | if (QualityFactory.SOURCE_TAOBAO_DATAOKE == goodsSource) {
|
| | | weight = 10000 + (Math.random() * 2001);
|
| | | } else {
|
| | | weight = startWeight + (Math.random() * ((endWeight - startWeight) + 1));
|
| | | }
|
| | | flashSale.setWeight(weight);
|
| | | |
| | | return flashSale;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 商品加入精选库-new QualityFactory()
|
| | | * |
| | | * @param goodsBrief
|
| | | * @param admin
|
| | | * @return
|
| | | */
|
| | | public QualityFactory getNewQualityFactory(TaoBaoGoodsBrief goodsBrief, BoutiqueAutoRule autoRule) {
|
| | |
|
| | | /* 分类 */
|
| | | Long classID = null;
|
| | |
|
| | | Integer rootCatId = goodsBrief.getRootCatId();
|
| | | if (rootCatId != null) {
|
| | | classID = taoBaoClassRelationMapper.getClassIdByTaoBaoCid(rootCatId.longValue());
|
| | | }
|
| | |
|
| | | // 添加至精选商品库
|
| | | QualityFactory selectionGoods = new QualityFactory();
|
| | |
|
| | | selectionGoods.setBoutiqueAutoRule(autoRule);
|
| | | selectionGoods.setSourceCalss(autoRule.getSourceCalss());
|
| | | selectionGoods.setSystemCid(classID);// 类别id
|
| | | selectionGoods.setGoodsSource(autoRule.getGoodsSource());// 来源
|
| | | selectionGoods.setTaoBaoGoodsBrief(goodsBrief);
|
| | |
|
| | | selectionGoods.setCreateUser(autoRule.getAdminUser());
|
| | | selectionGoods.setCreatetime(new Date());
|
| | | selectionGoods.setUpdateUser(autoRule.getAdminUser());
|
| | | selectionGoods.setUpdatetime(new Date());
|
| | | selectionGoods.setEntryMode(QualityFactory.MODE_AUTO);// 系统筛选
|
| | |
|
| | | // 随机权重
|
| | | int resultWeight = autoRule.getStartWeight()
|
| | | + (int) (Math.random() * ((autoRule.getEndWeight() - autoRule.getStartWeight()) + 1));
|
| | |
|
| | | selectionGoods.setWeight(resultWeight);
|
| | |
|
| | | return selectionGoods;
|
| | |
|
| | | }
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 删除未更新的商品
|
| | | * |
| | | * @param systemCid
|
| | | * @param formatDate
|
| | | * @param source
|
| | | */
|
| | | @Override
|
| | | public void deleteNotUpdateGoods(Long systemCid, String formatDate, int source) {
|
| | | List<Long> list = qualityFactoryMapper.getAuctionIdbyClassId(systemCid, source, formatDate);
|
| | | if (list == null || list.size() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 小于100条直接删除
|
| | | if (list.size() <= 100) {
|
| | | // 删除精选库
|
| | | deleteBatchByTaoBaoGoodsId(list);
|
| | | // 删除商品
|
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(list);
|
| | | return;
|
| | | } |
| | | |
| | | // 大于100需要分段删除
|
| | | int start = 0;
|
| | | int end = 100;
|
| | | int countRow = 100;
|
| | |
|
| | | int count = list.size() / countRow;
|
| | | if (list.size() % countRow > 0) {
|
| | | count += 1;
|
| | | }
|
| | |
|
| | | for (int i = 0; i < count; i++) {
|
| | | List<Long> sublist = new ArrayList<Long>();
|
| | | if (i == count - 1) {
|
| | | sublist = list.subList(start, list.size());
|
| | | deleteBatchByTaoBaoGoodsId(sublist);
|
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(sublist);
|
| | | break;
|
| | | }
|
| | | sublist = list.subList(start, end);
|
| | | deleteBatchByTaoBaoGoodsId(sublist);
|
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(sublist);
|
| | | start += countRow;
|
| | | end += countRow;
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | |
|
| | | @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);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<QualityFactory> listByMinSalesCountOrderByCreateTimeDesc(int salesCount, int page, int pageSize) {
|
| | | return qualityFactoryMapper.listByMinSalesCountOrderByCreateTimeDesc(salesCount, (page - 1) * pageSize,
|
| | | pageSize);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.lable; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.TaoBaoClassRelationMapper; |
| | | import com.yeshi.fanli.dao.mybatis.lable.LabelGoodsMapper; |
| | | import com.yeshi.fanli.dao.mybatis.lable.QualityFactoryMapper; |
| | | import com.yeshi.fanli.dao.mybatis.lable.QualityFlashSaleMapper; |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper; |
| | | import com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule; |
| | | import com.yeshi.fanli.entity.bus.lable.Label; |
| | | import com.yeshi.fanli.entity.bus.lable.LabelGoods; |
| | | import com.yeshi.fanli.entity.bus.lable.QualityFactory; |
| | | import com.yeshi.fanli.entity.bus.lable.QualityFlashSale; |
| | | import com.yeshi.fanli.entity.common.AdminUser; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | 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.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.RedisKeyEnum; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | import com.yeshi.fanli.vo.quality.QualityFactoryVO; |
| | | |
| | | @Service |
| | | public class QualityFactoryServiceImpl implements QualityFactoryService { |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | @Resource |
| | | private QualityFactoryMapper qualityFactoryMapper; |
| | | @Resource |
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService; |
| | | @Resource |
| | | private LabelGoodsMapper labelGoodsMapper; |
| | | @Resource |
| | | private LabelService labelService; |
| | | @Resource |
| | | private TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper; |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | @Resource |
| | | private TaoBaoClassRelationMapper taoBaoClassRelationMapper; |
| | | @Resource |
| | | private QualityFlashSaleService qualityFlashSaleService; |
| | | @Resource |
| | | private QualityFlashSaleMapper qualityFlashSaleMapper; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; |
| | | |
| | | @Override |
| | | public int updateByPrimaryKeySelective(QualityFactory record) throws QualityFactoryException { |
| | | return qualityFactoryMapper.updateByPrimaryKeySelective(record); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void deleteByTaoBaoGoodsId(String auctionId) { |
| | | if (auctionId == null) { |
| | | return; |
| | | } |
| | | // 移除精选库 |
| | | qualityFactoryMapper.deleteByGoodsId(auctionId); |
| | | // 删除限时抢购 |
| | | qualityFlashSaleMapper.deleteByGoodsId(auctionId); |
| | | // 删除对应标签 |
| | | labelGoodsMapper.deleteByGoodsId(auctionId); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void deleteBatchByTaoBaoGoodsId(List<String> listGid) { |
| | | |
| | | if (listGid == null || listGid.size() == 0) { |
| | | return; |
| | | } |
| | | // 批量删除精选库 |
| | | qualityFactoryMapper.deleteBatchByGoodsId(listGid); |
| | | // 批量删除限时抢购 |
| | | qualityFlashSaleMapper.deleteBatchByQualityID(listGid); |
| | | // 删除对应标签 |
| | | labelGoodsMapper.deleteBatchByGoodsId(listGid); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void deleteByGoodsId(List<String> ids) throws QualityFactoryException { |
| | | |
| | | if (ids != null && ids.size() > 0) { |
| | | for (String goodsId : ids) { |
| | | qualityFactoryMapper.deleteByGoodsId(goodsId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public QualityFactory selectByPrimaryKey(Long id) throws QualityFactoryException { |
| | | return qualityFactoryMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getAuctionIdbyClassId(Long systemCid, Integer goodsSource, String dateTime){ |
| | | return qualityFactoryMapper.getAuctionIdbyClassId(systemCid, goodsSource, dateTime); |
| | | } |
| | | |
| | | @Override |
| | | public List<QualityFactory> queryAll(long start, int count, Integer days) { |
| | | return qualityFactoryMapper.queryAll(start, count, days); |
| | | } |
| | | |
| | | @Override |
| | | public List<QualityFactory> query(QualityFactoryVO qualityFactoryVO) throws QualityFactoryException { |
| | | return qualityFactoryMapper.query(qualityFactoryVO); |
| | | } |
| | | |
| | | @Override |
| | | public long queryCount(QualityFactoryVO qualityFactoryVO) throws QualityFactoryException { |
| | | return qualityFactoryMapper.queryCount(qualityFactoryVO); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getCountAll() { |
| | | return qualityFactoryMapper.getCountAll(); |
| | | } |
| | | |
| | | @Override |
| | | public Long queryCountByGoodsId(String goodsId) { |
| | | return qualityFactoryMapper.queryCountByGoodsId(goodsId); |
| | | } |
| | | |
| | | @Override |
| | | public List<QualityFactory> listQueryByAuctionId(List<String> list) { |
| | | return qualityFactoryMapper.listQueryByAuctionId(list); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void addBatchTaoBaoGoods(List<TaoBaoGoodsBrief> listTaoBaoGoods, String lableNames, AdminUser admin) |
| | | throws Exception { |
| | | |
| | | if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) { |
| | | throw new Exception("未找到匹配的商品"); |
| | | } |
| | | |
| | | // 创建标签 |
| | | 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>(); |
| | | |
| | | |
| | | // 插入商品淘宝ID集合 |
| | | List<String> listAuctionId = new ArrayList<>(); |
| | | for (TaoBaoGoodsBrief goodsBrief : listTaoBaoGoods) { |
| | | listAuctionId.add(goodsBrief.getAuctionId()); |
| | | } |
| | | List<Long> listHas = taoBaoGoodsBriefService.listExistById(listAuctionId); |
| | | |
| | | // 遍历商品 |
| | | for (TaoBaoGoodsBrief newGoodsBrief : listTaoBaoGoods) { |
| | | String auctionId = newGoodsBrief.getAuctionId(); |
| | | // 设置成主键 |
| | | newGoodsBrief.setAuctionId(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 { |
| | | // 设置商品默认值 |
| | | 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.setEntryMode(QualityFactory.MODE_MANUAL);// 人工筛选 |
| | | selectionGoods.setGoodsSource(QualityFactory.SOURCE_TAOBAO);// 来源 |
| | | selectionGoods.setWeight((int) (Math.random() * (4000))); |
| | | listInsertQuality.add(selectionGoods); |
| | | |
| | | // 商品标签 |
| | | if (listLabs != null && listLabs.size() > 0) { |
| | | for (Label lab: listLabs) { |
| | | LabelGoods lg = new LabelGoods(); |
| | | lg.setLabel(lab); |
| | | lg.setCreateUser(admin); |
| | | lg.setCreatetime(new Date()); |
| | | 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 (listLabelAdd.size() > 0) { |
| | | labelGoodsMapper.insertBatch(listLabelAdd); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void setWeightBatch(List<Long> idList, AdminUser admin, Integer weight, Integer weightSmall, |
| | | Integer weightLarge) throws Exception { |
| | | |
| | | for (Long selectId : idList) { |
| | | |
| | | QualityFactory selectionGoods = qualityFactoryMapper.selectByPrimaryKey(selectId); |
| | | |
| | | if (selectionGoods == null) { |
| | | continue; |
| | | } |
| | | // 默认 50 |
| | | int resultWeight = 50; |
| | | |
| | | if (weight != null) { |
| | | resultWeight = weight; |
| | | } else { |
| | | if (weightSmall != null && weightLarge != null) { |
| | | // 随机权重 |
| | | resultWeight = weightSmall + (int) (Math.random() * ((weightLarge - weightSmall) + 1)); |
| | | } |
| | | } |
| | | |
| | | // 修改权重 |
| | | selectionGoods.setUpdateUser(admin); |
| | | selectionGoods.setWeight(resultWeight); |
| | | qualityFactoryMapper.updateByPrimaryKeySelective(selectionGoods); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public Long countTotalRows(Integer days) { |
| | | return qualityFactoryMapper.countTotalRows(days); |
| | | } |
| | | |
| | | @Override |
| | | public void updateWeight(Integer weight, Integer time) { |
| | | qualityFactoryMapper.updateWeight(weight, time); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取缓存 |
| | | * |
| | | * @param key |
| | | * 键 |
| | | * @param title |
| | | * 标签名称 |
| | | * @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)) { |
| | | |
| | | // id为空时系统进行查询 |
| | | List<Label> list9K9 = labelService.selectByTitle(title); |
| | | |
| | | if (list9K9 != null && list9K9.size() > 0) { |
| | | Long id = list9K9.get(0).getId(); |
| | | if (id != null) { |
| | | value = id + ""; |
| | | // 缓存20分钟 |
| | | redisManager.cacheCommonString(key, value, 60 * 20); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return value; |
| | | } |
| | | |
| | | @Override |
| | | public void updateQualityGoods(String goodsId) { |
| | | if (goodsId == null) { |
| | | return; |
| | | } |
| | | |
| | | TaoBaoGoodsBrief goods = null; |
| | | boolean isDelete = false; |
| | | try { |
| | | // 获取详情 |
| | | goods = TaoKeApiUtil.searchGoodsDetail(goodsId); |
| | | if(goods == null) { |
| | | isDelete = true; |
| | | } else if (goods.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) { |
| | | isDelete = true; |
| | | } |
| | | } catch (TaobaoGoodsDownException e) { |
| | | isDelete = true; |
| | | } |
| | | |
| | | // 移除精选库 |
| | | if (isDelete) { |
| | | deleteByTaoBaoGoodsId(goodsId); |
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(Arrays.asList(new String[]{ goodsId})); |
| | | return; |
| | | } |
| | | |
| | | goods.setAuctionId(goodsId); |
| | | goods.setCreatetime(new Date()); |
| | | goods.setUpdatetime(new Date()); |
| | | try { |
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(goods); |
| | | } catch (TaobaoGoodsUpdateException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void autoInsertOrUpadateStorage(BoutiqueAutoRule autoRule, List<TaoBaoGoodsBrief> goodsList, List<Label> listLabs) { |
| | | |
| | | if (goodsList == null || goodsList.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | /* 来源推荐商品 需要获取详情 */ |
| | | if (QualityFactory.SOURCE_TAOBAO_MATERIAL == autoRule.getGoodsSource()) { |
| | | List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>(); |
| | | |
| | | goodsList.parallelStream().forEach(goods -> { |
| | | try { |
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = TaoKeApiUtil.searchGoodsDetail(goods.getAuctionId()); |
| | | if (taoBaoGoodsBrief != null) { |
| | | listGoodsBrief.add(taoBaoGoodsBrief); |
| | | } |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | goodsList.clear(); |
| | | goodsList = listGoodsBrief; |
| | | |
| | | if (goodsList == null || goodsList.size() == 0) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | // for (int i = 0; i < goodsList.size(); i++) { |
| | | // if (goodsList.get(i).getMaterialLibType() != null && goodsList.get(i).getMaterialLibType() == 0) { |
| | | // goodsList.remove(i); |
| | | // i--; |
| | | // } |
| | | // } |
| | | |
| | | |
| | | // 添加商品标签列表 |
| | | 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> listUpdateQuality = new ArrayList<QualityFactory>(); |
| | | |
| | | // 插入商品淘宝ID集合 |
| | | List<String> listAuctionId = new ArrayList<>(); |
| | | for (TaoBaoGoodsBrief goodsBrief : goodsList) { |
| | | listAuctionId.add(goodsBrief.getAuctionId()); |
| | | } |
| | | |
| | | List<Long> listHas = new ArrayList<Long>(); |
| | | if (listAuctionId.size() > 0) { |
| | | listHas = taoBaoGoodsBriefService.listExistById(listAuctionId); |
| | | } |
| | | |
| | | |
| | | // 遍历商品 |
| | | for (TaoBaoGoodsBrief newGoodsBrief : goodsList) { |
| | | String auctionId = newGoodsBrief.getAuctionId(); |
| | | // 设置成主键 |
| | | newGoodsBrief.setAuctionId(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(autoRule.getAdminUser()); |
| | | lg.setCreatetime(new Date()); |
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief); |
| | | listLabelAdd.add(lg); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 更新的商品信息 是否存在精选库中 |
| | | QualityFactory quality = qualityFactoryMapper.getByAuctionId(auctionId); |
| | | if (quality == null) { |
| | | listInsertQuality.add(getNewQualityFactory(newGoodsBrief, autoRule)); |
| | | } else { |
| | | // 随机权重 |
| | | int weight = autoRule.getStartWeight() |
| | | + (int) (Math.random() * ((autoRule.getEndWeight() - autoRule.getStartWeight()) + 1)); |
| | | quality.setWeight(weight); |
| | | // 更新时间 |
| | | quality.setUpdatetime(new Date()); |
| | | // 更新来源规则 |
| | | quality.setBoutiqueAutoRule(autoRule); |
| | | // 更新来源类别 |
| | | quality.setSourceCalss(autoRule.getSourceCalss()); |
| | | // 来源 |
| | | quality.setGoodsSource(autoRule.getGoodsSource()); |
| | | listUpdateQuality.add(quality); |
| | | } |
| | | |
| | | } else { |
| | | // 设置商品默认值 |
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(newGoodsBrief); |
| | | listGoodsInsert.add(newGoodsBrief); |
| | | |
| | | // 精选库信息 |
| | | listInsertQuality.add(getNewQualityFactory(newGoodsBrief, autoRule)); |
| | | |
| | | // 商品标签 |
| | | if (listLabs != null && listLabs.size() > 0) { |
| | | for (Label lab: listLabs) { |
| | | LabelGoods lg = new LabelGoods(); |
| | | lg.setLabel(lab); |
| | | lg.setCreateUser(autoRule.getAdminUser()); |
| | | lg.setCreatetime(new Date()); |
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief); |
| | | listLabelAdd.add(lg); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 插入淘宝商品 |
| | | if (listGoodsInsert.size() > 0) { |
| | | taoBaoGoodsBriefService.insertBatch(listGoodsInsert); |
| | | } |
| | | |
| | | // 更新淘宝商品 |
| | | if (listGoodsUpdate.size() > 0) { |
| | | try { |
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listGoodsUpdate); |
| | | } catch (TaobaoGoodsUpdateException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 加入精选库 |
| | | if (listInsertQuality.size() > 0) { |
| | | qualityFactoryMapper.insertBatch(listInsertQuality); |
| | | } |
| | | |
| | | // 更新精选库 |
| | | if (listUpdateQuality.size() > 0) { |
| | | qualityFactoryMapper.updateBatchSelective(listUpdateQuality); |
| | | } |
| | | |
| | | // 添加标签 |
| | | if (listLabelAdd.size() > 0) { |
| | | labelGoodsMapper.insertBatch(listLabelAdd); |
| | | } |
| | | |
| | | // 加入限时抢购 |
| | | if (autoRule.isFlashSale()) { |
| | | updateQualityFlashSale(goodsList, autoRule); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 限时秒杀 |
| | | * @param listGoods |
| | | * @param autoRule |
| | | */ |
| | | public void updateQualityFlashSale(List<TaoBaoGoodsBrief> listGoods, BoutiqueAutoRule autoRule) { |
| | | |
| | | List<Long> listQFId = new ArrayList<Long>(); |
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoods) { |
| | | listQFId.add(taoBaoGoodsBrief.getId()); |
| | | } |
| | | |
| | | int startWeight = autoRule.getStartWeight(); |
| | | int endWeight = autoRule.getEndWeight(); |
| | | int goodsSource = autoRule.getGoodsSource(); |
| | | |
| | | // 加入入限时抢购 |
| | | List<QualityFlashSale> listFlashSale = new ArrayList<QualityFlashSale>(); |
| | | // 限时抢购更新: |
| | | List<QualityFlashSale> listFlashSaleUpdate = new ArrayList<QualityFlashSale>(); |
| | | |
| | | |
| | | // 查询已存在显示限时抢购的商品 |
| | | List<QualityFlashSale> listQuery = qualityFlashSaleService.listQueryByQualityID(listQFId); |
| | | |
| | | if (listQuery == null || listQuery.size() == 0) { |
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief: listGoods) { |
| | | listFlashSale.add(getNewQualityFlashSale(taoBaoGoodsBrief, startWeight, endWeight, goodsSource)); |
| | | } |
| | | } else { |
| | | |
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief: listGoods) { |
| | | boolean exist = false; |
| | | Long id = taoBaoGoodsBrief.getId(); |
| | | |
| | | for (QualityFlashSale flashSale : listQuery) { |
| | | TaoBaoGoodsBrief goodsBrief = flashSale.getTaoBaoGoodsBrief(); |
| | | if (id.equals(goodsBrief.getId())) { |
| | | exist = true; |
| | | double weight = startWeight + (Math.random() * ((endWeight - startWeight) + 1)); |
| | | flashSale.setWeight(weight); |
| | | flashSale.setUpdatetime(new Date()); |
| | | listFlashSaleUpdate.add(flashSale); |
| | | listQuery.remove(flashSale); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!exist) { |
| | | listFlashSale.add(getNewQualityFlashSale(taoBaoGoodsBrief, startWeight, endWeight, goodsSource)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 插入限时抢购 |
| | | if (listFlashSale.size() > 0) { |
| | | qualityFlashSaleService.insertBatch(listFlashSale); |
| | | } |
| | | |
| | | // 更新限时抢购 |
| | | if (listFlashSaleUpdate.size() > 0) { |
| | | qualityFlashSaleService.updateBatchSelective(listFlashSaleUpdate); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建新对象QualityFlashSale |
| | | * |
| | | * @return |
| | | */ |
| | | public QualityFlashSale getNewQualityFlashSale(TaoBaoGoodsBrief taoBaoGoodsBrief, int startWeight, |
| | | int endWeight, int goodsSource) { |
| | | |
| | | QualityFlashSale flashSale = new QualityFlashSale(); |
| | | flashSale.setTaoBaoGoodsBrief(taoBaoGoodsBrief); |
| | | flashSale.setCreatetime(new Date()); |
| | | flashSale.setUpdatetime(new Date()); |
| | | |
| | | // 权重设置:大淘客优先展示 |
| | | double weight = 0; |
| | | if (QualityFactory.SOURCE_TAOBAO_DATAOKE == goodsSource) { |
| | | weight = 10000 + (Math.random() * 2001); |
| | | } else { |
| | | weight = startWeight + (Math.random() * ((endWeight - startWeight) + 1)); |
| | | } |
| | | flashSale.setWeight(weight); |
| | | |
| | | return flashSale; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 商品加入精选库-new QualityFactory() |
| | | * |
| | | * @param goodsBrief |
| | | * @param autoRule |
| | | * @return |
| | | */ |
| | | public QualityFactory getNewQualityFactory(TaoBaoGoodsBrief goodsBrief, BoutiqueAutoRule autoRule) { |
| | | |
| | | /* 分类 */ |
| | | Long classID = null; |
| | | |
| | | Integer rootCatId = goodsBrief.getRootCatId(); |
| | | if (rootCatId != null) { |
| | | classID = taoBaoClassRelationMapper.getClassIdByTaoBaoCid(rootCatId.longValue()); |
| | | } |
| | | |
| | | // 添加至精选商品库 |
| | | QualityFactory selectionGoods = new QualityFactory(); |
| | | |
| | | selectionGoods.setBoutiqueAutoRule(autoRule); |
| | | selectionGoods.setSourceCalss(autoRule.getSourceCalss()); |
| | | selectionGoods.setSystemCid(classID);// 类别id |
| | | selectionGoods.setGoodsSource(autoRule.getGoodsSource());// 来源 |
| | | selectionGoods.setTaoBaoGoodsBrief(goodsBrief); |
| | | |
| | | selectionGoods.setCreateUser(autoRule.getAdminUser()); |
| | | selectionGoods.setCreatetime(new Date()); |
| | | selectionGoods.setUpdateUser(autoRule.getAdminUser()); |
| | | selectionGoods.setUpdatetime(new Date()); |
| | | selectionGoods.setEntryMode(QualityFactory.MODE_AUTO);// 系统筛选 |
| | | |
| | | // 随机权重 |
| | | int resultWeight = autoRule.getStartWeight() |
| | | + (int) (Math.random() * ((autoRule.getEndWeight() - autoRule.getStartWeight()) + 1)); |
| | | |
| | | selectionGoods.setWeight(resultWeight); |
| | | |
| | | return selectionGoods; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 删除未更新的商品 |
| | | * |
| | | * @param systemCid |
| | | * @param formatDate |
| | | * @param source |
| | | */ |
| | | @Override |
| | | public void deleteNotUpdateGoods(Long systemCid, String formatDate, int source) { |
| | | List<String> list = qualityFactoryMapper.getAuctionIdbyClassId(systemCid, source, formatDate); |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | // 小于100条直接删除 |
| | | if (list.size() <= 100) { |
| | | // 删除精选库 |
| | | deleteBatchByTaoBaoGoodsId(list); |
| | | // 删除商品 |
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(list); |
| | | return; |
| | | } |
| | | |
| | | // 大于100需要分段删除 |
| | | int start = 0; |
| | | int end = 100; |
| | | int countRow = 100; |
| | | |
| | | int count = list.size() / countRow; |
| | | if (list.size() % countRow > 0) { |
| | | count += 1; |
| | | } |
| | | |
| | | for (int i = 0; i < count; i++) { |
| | | List<String> sublist = new ArrayList<>(); |
| | | if (i == count - 1) { |
| | | sublist = list.subList(start, list.size()); |
| | | deleteBatchByTaoBaoGoodsId(sublist); |
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(sublist); |
| | | break; |
| | | } |
| | | sublist = list.subList(start, end); |
| | | deleteBatchByTaoBaoGoodsId(sublist); |
| | | taoBaoGoodsBriefService.deleteBatchByGoodsId(sublist); |
| | | start += countRow; |
| | | end += countRow; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @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); |
| | | } |
| | | |
| | | @Override |
| | | public List<QualityFactory> listByMinSalesCountOrderByCreateTimeDesc(int salesCount, int page, int pageSize) { |
| | | return qualityFactoryMapper.listByMinSalesCountOrderByCreateTimeDesc(salesCount, (page - 1) * pageSize, |
| | | pageSize); |
| | | } |
| | | |
| | | } |