| | |
| | | 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 javax.annotation.Resource;
|
| | | import javax.transaction.Transactional;
|
| | |
|
| | | 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.dao.mybatis.taobao.TaoBaoGoodsBriefRecordMapper;
|
| | | import com.yeshi.fanli.entity.bus.clazz.TaoBaoClassRelation;
|
| | | 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.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;
|
| | |
|
| | | @Service
|
| | | public class QualityFactoryServiceImpl implements QualityFactoryService {
|
| | |
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefRecordMapper taoBaoGoodsBriefRecordMapper;
|
| | | @Resource
|
| | | private TaoBaoClassRelationMapper taoBaoClassRelationMapper;
|
| | | @Resource
|
| | | private QualityFlashSaleService qualityFlashSaleService;
|
| | |
| | | @Resource
|
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
| | |
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKeySelective(QualityFactory record) throws QualityFactoryException {
|
| | | return qualityFactoryMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | @Override
|
| | | public void deleteByTbAuctionId(Long auctionId) {
|
| | |
|
| | | public void deleteByTaoBaoGoodsId(Long auctionId) {
|
| | | if (auctionId == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<TaoBaoGoodsBrief> tbgoods = taoBaoGoodsBriefMapper.queryByAuctionId(auctionId);
|
| | | if (tbgoods != null && tbgoods.size() > 0) {
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = tbgoods.get(0);
|
| | | try {
|
| | | deleteByTaoBaoGoodsId(taoBaoGoodsBrief.getId());
|
| | | } catch (QualityFactoryException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteByTaoBaoGoodsId(Long gid) throws QualityFactoryException {
|
| | |
|
| | | if (gid == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<QualityFactory> list = qualityFactoryMapper.queryByGoodsId(gid);
|
| | | if (list != null && list.size() > 0) {
|
| | |
|
| | | // 删除限时抢购
|
| | | for (QualityFactory qualityFactory : list) {
|
| | | qualityFlashSaleMapper.deleteByQualityID(qualityFactory.getId());
|
| | | }
|
| | |
|
| | | // 移除精选库
|
| | | qualityFactoryMapper.deleteByGoodsId(gid);
|
| | | }
|
| | |
|
| | | // 移除精选库
|
| | | qualityFactoryMapper.deleteByGoodsId(auctionId);
|
| | | // 删除限时抢购
|
| | | qualityFlashSaleMapper.deleteByGoodsId(auctionId);
|
| | | // 删除对应标签
|
| | | labelGoodsMapper.deleteByGoodsId(gid);
|
| | | labelGoodsMapper.deleteByGoodsId(auctionId);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public void deleteBatchByTaoBaoGoodsId(List<Long> listGid) throws QualityFactoryException {
|
| | | public void deleteBatchByTaoBaoGoodsId(List<Long> listGid) {
|
| | |
|
| | | if (listGid == null || listGid.size() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<QualityFactory> list = qualityFactoryMapper.listQueryGoodsByGoodsId(listGid);
|
| | |
|
| | | if (list != null && list.size() > 0) {
|
| | |
|
| | | List<Long> listFid = new ArrayList<Long>();
|
| | | for (QualityFactory qualityFactory : list) {
|
| | | listFid.add(qualityFactory.getId());
|
| | | }
|
| | |
|
| | | if (listFid.size() > 0) {
|
| | | // 批量删除精选库
|
| | | qualityFactoryMapper.deleteBatchByPrimaryKey(listFid);
|
| | | // 批量删除限时抢购
|
| | | qualityFlashSaleMapper.deleteBatchByQualityID(listFid);
|
| | | }
|
| | | }
|
| | |
|
| | | // 批量删除精选库
|
| | | qualityFactoryMapper.deleteBatchByGoodsId(listGid);
|
| | | // 批量删除限时抢购
|
| | | qualityFlashSaleMapper.deleteBatchByQualityID(listGid);
|
| | | // 删除对应标签
|
| | | labelGoodsMapper.deleteBatchByGoodsId(listGid);
|
| | | }
|
| | |
|
| | |
|
| | | |
| | | @Override
|
| | | @Transactional
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void deleteByGoodsId(List<String> ids) throws QualityFactoryException {
|
| | |
|
| | | if (ids != null && ids.size() > 0) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public QualityFactory selectByPrimaryKey(Long id) throws QualityFactoryException {
|
| | | return qualityFactoryMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Long> getAuctionIdbyClassId(Long systemCid, Integer goodsSource, String dateTime)
|
| | | throws QualityFactoryException {
|
| | | public List<Long> getAuctionIdbyClassId(Long systemCid, Integer goodsSource, String dateTime){
|
| | | return qualityFactoryMapper.getAuctionIdbyClassId(systemCid, goodsSource, dateTime);
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | @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
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void addBatch(List<Long> auctionIdList, String lableNames, AdminUser admin) throws Exception {
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void addBatchTaoBaoGoods(List<TaoBaoGoodsBrief> listTaoBaoGoods, 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);
|
| | | }
|
| | |
|
| | | }
|
| | | if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) {
|
| | | throw new Exception("未找到匹配的商品");
|
| | | }
|
| | |
|
| | | List<TaoBaoGoodsBrief> existList = taoBaoGoodsBriefRecordMapper.queryByAuctionIdList(auctionIdList);
|
| | | // 创建标签
|
| | | 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> addList = new ArrayList<QualityFactory>();
|
| | | List<LabelGoods> addLabelList = new ArrayList<LabelGoods>();
|
| | | // 插入商品淘宝ID集合
|
| | | List<Long> listAuctionId = new ArrayList<Long>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : listTaoBaoGoods) {
|
| | | listAuctionId.add(goodsBrief.getAuctionId());
|
| | | }
|
| | | List<Long> listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | |
|
| | | for (Long auctionId : auctionIdList) {
|
| | |
|
| | | boolean process = false;
|
| | | TaoBaoGoodsBrief goodsBrief = null;
|
| | |
|
| | | 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;
|
| | | // 遍历商品
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | 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);
|
| | |
|
| | | goodsBrief.setId(currentGoodsBrief.getId());
|
| | |
|
| | | // 更新商品最新信息
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(goodsBrief);
|
| | | |
| | | // 更新的商品信息 是否存在精选库中
|
| | | 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());
|
| | | // 非空项 处理
|
| | | setTaoBaoGoodsBriefDefault(goodsBrief);
|
| | |
|
| | | taoBaoGoodsBriefService.insertSelective(goodsBrief);
|
| | | }
|
| | |
|
| | | // 是否已入库
|
| | | Long id = goodsBrief.getId();
|
| | | List<QualityFactory> selectionList = qualityFactoryMapper.queryByGoodsId(id);
|
| | |
|
| | | /* 进入精选商品库 */
|
| | | 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);
|
| | |
|
| | | addList.add(selectionGoods);
|
| | | } else {
|
| | | // 更新商品
|
| | | QualityFactory selectionGoods = selectionList.get(0);
|
| | | selectionGoods.setUpdatetime(new Date());
|
| | | qualityFactoryMapper.updateByPrimaryKeySelective(selectionGoods);
|
| | | }
|
| | |
|
| | | if (listLabs.size() > 0) {
|
| | | for (Label label : listLabs) {
|
| | | /* 贴上标签 : 已贴不处理则 */
|
| | | Long existence = labelGoodsMapper.isExistence(id, 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);
|
| | |
|
| | | addLabelList.add(lg);
|
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | listLabelAdd.add(lg);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (addList.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(addList);
|
| | | // 插入淘宝商品
|
| | | if (listGoodsInsert.size() > 0) {
|
| | | taoBaoGoodsBriefService.insertBatch(listGoodsInsert);
|
| | | }
|
| | | |
| | | // 更新淘宝商品
|
| | | if (listGoodsUpdate.size() > 0) {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listGoodsUpdate);
|
| | | }
|
| | | |
| | | // 加入精选库
|
| | | if (listInsertQuality.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(listInsertQuality);
|
| | | }
|
| | |
|
| | | if (addLabelList.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(addLabelList);
|
| | | // 添加标签
|
| | | if (listLabelAdd.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(listLabelAdd);
|
| | | }
|
| | |
|
| | | |
| | | }
|
| | |
|
| | | @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);
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 获取缓存
|
| | | * @param key 键
|
| | | * @param title 标签名称
|
| | | * |
| | | * @param key
|
| | | * 键
|
| | | * @param title
|
| | | * 标签名称
|
| | | * @return
|
| | | */
|
| | | public String getLabelIdByRedis (String key, String title) throws Exception {
|
| | | |
| | | 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) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | return value;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void updateGoodsFactory(List<Long> listId) {
|
| | |
|
| | | if (listId == null || listId.size() == 0) {
|
| | | public void updateQualityGoods(Long goodsId) {
|
| | | if (goodsId == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<QualityFactory> listQuality = qualityFactoryMapper.listQueryGoodsByGoodsId(listId);
|
| | | if (listQuality == null || listQuality.size() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 删除精选库
|
| | | List<Long> listDeleteQuality = new ArrayList<Long>();
|
| | | // 删除标签
|
| | | List<Long> listDeleteLabel = new ArrayList<Long>();
|
| | | |
| | | |
| | | List<QualityFactory> listUpdateQuality = new ArrayList<QualityFactory>();
|
| | |
|
| | | List<TaoBaoGoodsBrief> listUpdateGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | List<Long> list9ClassDelete = new ArrayList<Long>();
|
| | | // 添加商品标签列表
|
| | | List<LabelGoods> listLabelAdd = new ArrayList<LabelGoods>();
|
| | |
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | boolean isDelete = false;
|
| | | try {
|
| | | |
| | | List<Long> list9Class = new ArrayList<Long>();
|
| | | Map<String, Label> map = new HashMap<String, Label>();
|
| | | |
| | | if (Constant.IS_OUTNET) {
|
| | | |
| | | String value9K9 = getLabelIdByRedis("lab-9K9", "9.9");
|
| | | String value19K9 = getLabelIdByRedis("lab-19K9", "19.9");
|
| | | String value29K9 = getLabelIdByRedis("lab-29K9", "29.9");
|
| | | String value49K9 = getLabelIdByRedis("lab-49K9", "49.9");
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(value9K9)) {
|
| | | map.put("9.9", new Label(Long.parseLong(value9K9)));
|
| | | list9Class.add(Long.parseLong(value9K9)); |
| | | }
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(value19K9)) {
|
| | | map.put("19.9", new Label(Long.parseLong(value19K9)));
|
| | | list9Class.add(Long.parseLong(value19K9)); |
| | | }
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(value29K9)) {
|
| | | map.put("29.9", new Label(Long.parseLong(value29K9)));
|
| | | list9Class.add(Long.parseLong(value29K9)); |
| | | }
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(value49K9)) {
|
| | | map.put("49.9", new Label(Long.parseLong(value49K9)));
|
| | | list9Class.add(Long.parseLong(value49K9)); |
| | | }
|
| | | |
| | | // 获取详情
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(goodsId);
|
| | | if(goods == null) {
|
| | | isDelete = true;
|
| | | } else if (goods.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) {
|
| | | isDelete = true;
|
| | | }
|
| | |
|
| | | listQuality.parallelStream().forEach(quality -> {
|
| | |
|
| | | TaoBaoGoodsBrief goods = quality.getTaoBaoGoodsBrief();
|
| | |
|
| | | if (goods == null) {
|
| | | // 移除精选库
|
| | | listDeleteQuality.add(quality.getId());
|
| | |
|
| | | } else {
|
| | |
|
| | | Long id = goods.getId();
|
| | |
|
| | | TaoBaoGoodsBrief newGoodsBrief = null;
|
| | |
|
| | | Long auctionId = goods.getAuctionId();
|
| | | try {
|
| | | // 获取详情
|
| | | newGoodsBrief = TaoKeApiUtil.searchGoodsDetail(auctionId);
|
| | | } catch (TaobaoGoodsDownException e1) {
|
| | | // 商品下架 移除数据库
|
| | | taoBaoGoodsUpdateService.deleteTaoBaoGoods(auctionId);
|
| | |
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | if (newGoodsBrief == null) {
|
| | |
|
| | | /* 无券信息 移除精选库 */
|
| | | listDeleteQuality.add(quality.getId());
|
| | | // 移除标签
|
| | | listDeleteLabel.add(goods.getId());
|
| | |
|
| | | } else {
|
| | | /* 无券信息 移除精选库 */
|
| | | if (StringUtil.isNullOrEmpty(newGoodsBrief.getCouponInfo())
|
| | | && StringUtil.isNullOrEmpty(newGoodsBrief.getCouponActivityId())) { // 无券信息
|
| | |
|
| | | // 移除精选库
|
| | | listDeleteQuality.add(quality.getId());
|
| | | // 移除标签
|
| | | listDeleteLabel.add(goods.getId());
|
| | |
|
| | | } else {
|
| | | /* 更新商品信息 */
|
| | | TaoBaoGoodsBrief updateGoods = taoBaoGoodsUpdateService.getUpdateTaoBaoGoodsBrief(newGoodsBrief);
|
| | | |
| | | updateGoods.setId(id);
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(updateGoods);
|
| | | |
| | | listUpdateGoodsBrief.add(updateGoods);
|
| | |
|
| | | /* 更新精选库 信息时间 */
|
| | | Integer biz30day = updateGoods.getBiz30day();
|
| | | if (biz30day < 1000) {
|
| | | // 销量小于1000 重新设置权重
|
| | | int weight = 10 + (int) (Math.random() * 2000);
|
| | | quality.setWeight(weight);
|
| | | }
|
| | | quality.setUpdatetime(new Date());
|
| | | listUpdateQuality.add(quality);
|
| | |
|
| | | /* 判断是否已经贴上标签 9k9标签 对应价格变化 */
|
| | | if (list9Class.size() > 0) {
|
| | | List<LabelGoods> listGlid = labelGoodsMapper.listQuery9k9Class(id, list9Class);
|
| | | if (listGlid != null && listGlid.size() > 0) {
|
| | | /* 删除原标签 9k9 */
|
| | | for (LabelGoods labelGoods : listGlid) {
|
| | | list9ClassDelete.add(labelGoods.getId());
|
| | | }
|
| | |
|
| | | /* 贴上新标签 9k9 */
|
| | | LabelGoods labelGds = screen9K9(updateGoods, map);
|
| | | if (labelGds != null) {
|
| | | listLabelAdd.add(labelGds);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | });
|
| | |
|
| | | // 更新商品信息
|
| | | if (listUpdateGoodsBrief.size() > 0) {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listUpdateGoodsBrief);
|
| | | }
|
| | |
|
| | | // 更新精选库
|
| | | if (listUpdateQuality.size() > 0) {
|
| | | qualityFactoryMapper.updateBatchSelective(listUpdateQuality);
|
| | | }
|
| | |
|
| | | // 批量删除精选库
|
| | | if (listDeleteQuality.size() > 0) {
|
| | | qualityFactoryMapper.deleteBatchByPrimaryKey(listDeleteQuality);
|
| | | // 批量删除限时抢购
|
| | | qualityFlashSaleMapper.deleteBatchByQualityID(listDeleteQuality);
|
| | | }
|
| | |
|
| | | // 删除对应标签
|
| | | if (listDeleteLabel.size() > 0) {
|
| | | labelGoodsMapper.deleteBatchByGoodsId(listDeleteLabel);
|
| | | }
|
| | | |
| | | // 添加标签
|
| | | if (listLabelAdd.size() > 0) {
|
| | | labelGoodsMapper.insertBatch(listLabelAdd);
|
| | | }
|
| | |
|
| | | // 删除标签
|
| | | if (list9ClassDelete.size() > 0) {
|
| | | labelGoodsMapper.deleteBatchByPK(list9ClassDelete);
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | } 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
|
| | | public void autoInsertOrUpadateStorage(List<TaoBaoGoodsBrief> goodsList, List<Label> listLabs,
|
| | | BoutiqueAutoRule autoRule) throws Exception {
|
| | | @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 (Exception e) {
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | });
|
| | |
|
| | | |
| | | goodsList.clear();
|
| | |
|
| | | goodsList = listGoodsBrief;
|
| | |
|
| | | if (goodsList == null || goodsList.size() == 0) {
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | // 商品id集合
|
| | | List<Long> listSystemTBid = new ArrayList<Long>();
|
| | | // 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> listAddInsert = new ArrayList<QualityFactory>();
|
| | | List<QualityFactory> listInsertQuality = new ArrayList<QualityFactory>();
|
| | | // 进入精选商品列表
|
| | | List<QualityFactory> listAddUpdate = 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<TaoBaoGoodsBrief> listHas = taoBaoGoodsBriefService.listQueryByAuctionId(listAuctionId);
|
| | |
|
| | | List<Long> list9Class = null;
|
| | | List<Long> list9ClassDelete = new ArrayList<Long>();
|
| | | Map<String, Label> map = new HashMap<String, Label>();
|
| | |
|
| | | list9Class = new ArrayList<Long>();
|
| | |
|
| | | List<Label> list9K9 = labelService.selectByTitleCache("labKey", "9.9");
|
| | | if (list9K9 != null && list9K9.size() > 0) {
|
| | | map.put("9.9", list9K9.get(0));
|
| | | list9Class.add(list9K9.get(0).getId());
|
| | | |
| | | List<Long> listHas = new ArrayList<Long>();
|
| | | if (listAuctionId.size() > 0) {
|
| | | listHas = taoBaoGoodsBriefService.listExistById(listAuctionId);
|
| | | }
|
| | |
|
| | | List<Label> list19k9 = labelService.selectByTitleCache("labKey", "19.9");
|
| | | if (list19k9 != null && list19k9.size() > 0) {
|
| | | map.put("19.9", list19k9.get(0));
|
| | | list9Class.add(list19k9.get(0).getId());
|
| | | }
|
| | |
|
| | | List<Label> list29k9 = labelService.selectByTitleCache("labKey", "29.9");
|
| | | if (list29k9 != null && list29k9.size() > 0) {
|
| | | map.put("29.9", list29k9.get(0));
|
| | | list9Class.add(list29k9.get(0).getId());
|
| | | }
|
| | |
|
| | | List<Label> list49k9 = labelService.selectByTitleCache("labKey", "49.9");
|
| | | if (list49k9 != null && list49k9.size() > 0) {
|
| | | map.put("49.9", list49k9.get(0));
|
| | | list9Class.add(list49k9.get(0).getId());
|
| | | }
|
| | |
|
| | | |
| | | |
| | | // 遍历商品
|
| | | for (TaoBaoGoodsBrief newGoodsBrief : goodsList) {
|
| | |
|
| | | Long systemId = null;
|
| | | boolean isExist = false;
|
| | | Long auctionId = newGoodsBrief.getAuctionId();
|
| | |
|
| | | // 设置成主键
|
| | | newGoodsBrief.setId(auctionId);
|
| | | newGoodsBrief.setState(0); // 状态启用
|
| | | newGoodsBrief.setCreatetime(new Date());
|
| | | newGoodsBrief.setUpdatetime(new Date());
|
| | | |
| | | /* 判断商品 是否已经存在数据库 */
|
| | | if (listHas != null && listHas.size() > 0) {
|
| | | for (TaoBaoGoodsBrief hasgoodsBrief : listHas) {
|
| | | Long hasId = hasgoodsBrief.getAuctionId();
|
| | | if (auctionId.equals(hasId)) {
|
| | | systemId = hasgoodsBrief.getId();
|
| | | // 存在数据库
|
| | | isExist = true;
|
| | | break;// 结束内部循环
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /* 商品已存在数据库 */
|
| | | if (isExist && systemId != null) {
|
| | | if (listHas != null && listHas.size() > 0 && listHas.contains(auctionId)) {
|
| | | // 更新商品
|
| | |
|
| | | // 用于确定是否存在精选库
|
| | | listSystemTBid.add(systemId);
|
| | | listGoodsUpdate.add(newGoodsBrief); |
| | |
|
| | | // 更新商品信息
|
| | | TaoBaoGoodsBrief updateGoods = taoBaoGoodsUpdateService.getUpdateTaoBaoGoodsBrief(newGoodsBrief);
|
| | | // 设置主键id
|
| | | updateGoods.setId(systemId);
|
| | | // 修改创建时间 - 换义新创建
|
| | | Date date = new Date();
|
| | | updateGoods.setCreatetime(date);
|
| | | updateGoods.setUpdatetime(date);
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(updateGoods);
|
| | | |
| | | listGoodsUpdate.add(updateGoods);
|
| | |
|
| | | |
| | | Long has9k9ID = null;
|
| | |
|
| | | /* 贴上标签 */
|
| | | // 商品标签
|
| | | if (listLabs != null && listLabs.size() > 0) {
|
| | |
|
| | | for (Label label : listLabs) {
|
| | | |
| | | // 包含 9.9/19.9/29.9/49.9 、同时来源淘宝推荐: 由于获取详情与推荐接口的券信息存在出入 以最后详情为准
|
| | | if (list9Class.contains(label.getId()) && autoRule.isCalss9k9() && QualityFactory.SOURCE_TAOBAO_MATERIAL == autoRule.getGoodsSource()) {
|
| | | |
| | | /* 获取商品详情后计算是否属于 9k9系列 加入对应的标签*/
|
| | | LabelGoods labelGds = screen9K9(updateGoods, map);
|
| | | |
| | | if (labelGds != null) {
|
| | | |
| | | Label label9k = labelGds.getLabel();
|
| | | Long id = label9k.getId();
|
| | | |
| | | long existence = labelGoodsMapper.isExistence(systemId, id);
|
| | | if (existence <= 0) {
|
| | | // 不存在对应标签
|
| | | listLabelAdd.add(labelGds);
|
| | | } else {
|
| | | // 已存在
|
| | | has9k9ID = id; |
| | | }
|
| | | |
| | | }
|
| | | |
| | | } else {
|
| | | |
| | | long existence = labelGoodsMapper.isExistence(systemId, label.getId());
|
| | | if (existence <= 0) {
|
| | | // 贴上新标签
|
| | | LabelGoods lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | | lg.setCreateUser(autoRule.getAdminUser());
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(updateGoods);
|
| | |
|
| | | listLabelAdd.add(lg);
|
| | | } else {
|
| | | if(list9Class.contains(label.getId())){
|
| | | // 已存在
|
| | | has9k9ID = label.getId(); |
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /* 判断是否已经贴上标签 9k9标签 */
|
| | | if (list9Class.size() > 0) {
|
| | | |
| | | List<LabelGoods> listGlid = labelGoodsMapper.listQuery9k9Class(systemId, list9Class);
|
| | | |
| | | if (listGlid != null && listGlid.size() > 0) {
|
| | | |
| | | if (has9k9ID == null && !autoRule.isCalss9k9()) {
|
| | | // 非9k9入库规则 若商品信息变化 对应的标签根据价格 修改
|
| | | LabelGoods labelGds = screen9K9(updateGoods, map);
|
| | | if (labelGds != null) {
|
| | | Label label9k = labelGds.getLabel();
|
| | | Long id = label9k.getId();
|
| | | |
| | | long existence = labelGoodsMapper.isExistence(systemId, id);
|
| | | if (existence <= 0) {
|
| | | // 不存在对应标签
|
| | | listLabelAdd.add(labelGds);
|
| | | } else {
|
| | | // 已存在
|
| | | has9k9ID = id; |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | // 清空 9K9系列标签
|
| | | for (LabelGoods labelGoods : listGlid) {
|
| | | Label label = labelGoods.getLabel();
|
| | | if (has9k9ID != null && has9k9ID.equals(label.getId())) {
|
| | | continue;
|
| | | }
|
| | | |
| | | list9ClassDelete.add(labelGoods.getId());
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | } else {
|
| | | newGoodsBrief.setId(null);
|
| | | newGoodsBrief.setState(0); // 状态启用
|
| | | newGoodsBrief.setCreatetime(new Date());
|
| | | newGoodsBrief.setUpdatetime(new Date());
|
| | | // 设置默认值
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(newGoodsBrief);
|
| | | // 插入数据库
|
| | | listGoodsInsert.add(newGoodsBrief);
|
| | |
|
| | | // 加入精选库
|
| | | listAddInsert.add(getNewQualityFactory(newGoodsBrief, autoRule));
|
| | |
|
| | | // 贴上标签
|
| | | if (listLabs != null && listLabs.size() > 0) {
|
| | | |
| | | for (Label label : listLabs) {
|
| | | |
| | | // 包含 9.9/19.9/29.9/49.9 、同时来源淘宝推荐: 由于获取详情与推荐接口的券信息存在出入 以最后详情为准
|
| | | if (list9Class.contains(label.getId()) && autoRule.isCalss9k9() && |
| | | QualityFactory.SOURCE_TAOBAO_MATERIAL == autoRule.getGoodsSource()) {
|
| | | /* 加入对应的9.9/19.9/29.9/49.9 标签*/
|
| | | LabelGoods labelGds = screen9K9(newGoodsBrief, map);
|
| | | |
| | | if (labelGds != null) {
|
| | | listLabelAdd.add(labelGds);
|
| | | }
|
| | | |
| | | } else {
|
| | | for (Label lab: listLabs) {
|
| | | long existence = labelGoodsMapper.isExistence(auctionId, lab.getId());
|
| | | if (existence <= 0) {
|
| | | // 贴上新标签
|
| | | LabelGoods lg = new LabelGoods();
|
| | | lg.setLabel(label);
|
| | | lg.setLabel(lab);
|
| | | lg.setCreateUser(autoRule.getAdminUser());
|
| | | lg.setCreatetime(new Date());
|
| | | lg.setTaoBaoGoodsBrief(newGoodsBrief);
|
| | | listLabelAdd.add(lg);
|
| | | }
|
| | | |
| | | }
|
| | | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 更新的商品信息 是否存在精选库中
|
| | | List<QualityFactory> listExist = null;
|
| | | if (listSystemTBid.size() > 0) {
|
| | | listExist = qualityFactoryMapper.listQueryGoodsByGoodsId(listSystemTBid);
|
| | | }
|
| | |
|
| | | /* 更新淘宝商品信息 */
|
| | | if (listGoodsUpdate.size() > 0) {
|
| | |
|
| | | for (TaoBaoGoodsBrief goodsBrief : listGoodsUpdate) {
|
| | | boolean isExist = false;
|
| | |
|
| | | if (listExist == null || listExist.size() == 0) {
|
| | | // 加入到精选库
|
| | | listAddInsert.add(getNewQualityFactory(goodsBrief, autoRule));
|
| | | continue;
|
| | | }
|
| | |
|
| | | QualityFactory selection = null;
|
| | | Long id = goodsBrief.getId();
|
| | | for (QualityFactory selectionGoods : listExist) {
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
| | | if (taoBaoGoodsBrief != null) {
|
| | | Long sid = taoBaoGoodsBrief.getId();
|
| | | if (id.equals(sid)) {
|
| | | isExist = true;
|
| | | selection = selectionGoods;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (isExist) {
|
| | | /* 更新精选库信息 */
|
| | |
|
| | | |
| | | // 更新的商品信息 是否存在精选库中
|
| | | 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));
|
| | | selection.setWeight(weight);
|
| | | quality.setWeight(weight);
|
| | | // 更新时间
|
| | | selection.setUpdatetime(new Date());
|
| | | quality.setUpdatetime(new Date());
|
| | | // 更新来源规则
|
| | | selection.setBoutiqueAutoRule(autoRule);
|
| | | quality.setBoutiqueAutoRule(autoRule);
|
| | | // 更新来源类别
|
| | | selection.setSourceCalss(autoRule.getSourceCalss());
|
| | | quality.setSourceCalss(autoRule.getSourceCalss());
|
| | | // 来源
|
| | | selection.setGoodsSource(autoRule.getGoodsSource());
|
| | |
|
| | | listAddUpdate.add(selection);
|
| | |
|
| | | } else {
|
| | | // 新增至精选库
|
| | | listAddInsert.add(getNewQualityFactory(goodsBrief, autoRule));
|
| | | quality.setGoodsSource(autoRule.getGoodsSource());
|
| | | listUpdateQuality.add(quality);
|
| | | }
|
| | | |
| | | } else {
|
| | | // 设置商品默认值
|
| | | taoBaoGoodsBriefService.setGoodsBriefDefault(newGoodsBrief);
|
| | | listGoodsInsert.add(newGoodsBrief);
|
| | | |
| | | // 精选库信息
|
| | | listInsertQuality.add(getNewQualityFactory(newGoodsBrief, autoRule));
|
| | |
|
| | | }
|
| | | try {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listGoodsUpdate);
|
| | | } catch (TaobaoGoodsUpdateException e) {
|
| | | System.out.println(e.getMsg());
|
| | | // 商品标签
|
| | | 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 (listAddUpdate.size() > 0) {
|
| | | qualityFactoryMapper.updateBatchSelective(listAddUpdate);
|
| | | |
| | | // 更新淘宝商品
|
| | | if (listGoodsUpdate.size() > 0) {
|
| | | try {
|
| | | taoBaoGoodsUpdateService.updateTaoBaoGoods(listGoodsUpdate);
|
| | | } catch (TaobaoGoodsUpdateException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | // 加入精选库
|
| | | if (listAddInsert.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(listAddInsert);
|
| | | if (listInsertQuality.size() > 0) {
|
| | | qualityFactoryMapper.insertBatch(listInsertQuality);
|
| | | }
|
| | |
|
| | | // 更新精选库
|
| | | if (listUpdateQuality.size() > 0) {
|
| | | qualityFactoryMapper.updateBatchSelective(listUpdateQuality);
|
| | | }
|
| | |
|
| | | // 添加标签
|
| | |
| | | labelGoodsMapper.insertBatch(listLabelAdd);
|
| | | }
|
| | |
|
| | | // 删除标签
|
| | | if (list9ClassDelete.size() > 0) {
|
| | | labelGoodsMapper.deleteBatchByPK(list9ClassDelete);
|
| | | }
|
| | |
|
| | | // 加入限时抢购
|
| | | if (autoRule.isFlashSale()) {
|
| | | updateQualityFlashSale(listAddInsert, listAddUpdate, autoRule);
|
| | | updateQualityFlashSale(goodsList, autoRule);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public void updateQualityFlashSale(List<QualityFactory> listinsert, List<QualityFactory> listUpdate,
|
| | | BoutiqueAutoRule autoRule) {
|
| | | // 精选id集合
|
| | | |
| | | |
| | | /**
|
| | | * 限时秒杀
|
| | | * @param listinsert
|
| | | * @param listUpdate
|
| | | * @param autoRule
|
| | | */
|
| | | public void updateQualityFlashSale(List<TaoBaoGoodsBrief> listGoods, BoutiqueAutoRule autoRule) {
|
| | | |
| | | List<Long> listQFId = new ArrayList<Long>();
|
| | |
|
| | | if (listinsert.size() > 0) {
|
| | | for (QualityFactory qualityFactory : listinsert) {
|
| | | listQFId.add(qualityFactory.getId());
|
| | | }
|
| | | }
|
| | |
|
| | | if (listUpdate.size() > 0) {
|
| | | for (QualityFactory qualityFactory : listUpdate) {
|
| | | listQFId.add(qualityFactory.getId());
|
| | | }
|
| | | }
|
| | |
|
| | | if (listQFId.size() == 0) {
|
| | | return;
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoods) {
|
| | | listQFId.add(taoBaoGoodsBrief.getId());
|
| | | }
|
| | |
|
| | | int startWeight = autoRule.getStartWeight();
|
| | |
| | |
|
| | | // 加入入限时抢购
|
| | | List<QualityFlashSale> listFlashSale = new ArrayList<QualityFlashSale>();
|
| | | // 限时抢购更新: 时间、权重
|
| | | // 限时抢购更新:
|
| | | List<QualityFlashSale> listFlashSaleUpdate = new ArrayList<QualityFlashSale>();
|
| | | |
| | |
|
| | | // 查询已存在显示限时抢购的商品
|
| | | List<QualityFlashSale> listQuery = qualityFlashSaleService.listQueryByQualityID(listQFId);
|
| | |
|
| | | if (listQuery == null || listQuery.size() == 0) {
|
| | | // 全部新增入库
|
| | | int i = 0;
|
| | | for (Long qfId : listQFId) {
|
| | | listFlashSale.add(getNewQualityFlashSale(qfId, i, startWeight, endWeight, goodsSource));
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief: listGoods) {
|
| | | listFlashSale.add(getNewQualityFlashSale(taoBaoGoodsBrief, startWeight, endWeight, goodsSource));
|
| | | }
|
| | | |
| | | } else {
|
| | | int i = 0;
|
| | | boolean exist = false;
|
| | |
|
| | | for (Long qfId : listQFId) {
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief: listGoods) {
|
| | | boolean exist = false;
|
| | | Long id = taoBaoGoodsBrief.getId();
|
| | |
|
| | | for (QualityFlashSale flashSale : listQuery) {
|
| | | QualityFactory qualityFactory = flashSale.getQualityFactory();
|
| | | |
| | | if (qfId.equals(qualityFactory.getId())) {
|
| | | TaoBaoGoodsBrief goodsBrief = flashSale.getTaoBaoGoodsBrief();
|
| | | if (id.equals(goodsBrief.getId())) {
|
| | | exist = true;
|
| | |
|
| | | //即将准备时间段时间
|
| | | //int nowType = qualityFlashSaleService.getQueryType();
|
| | | //flashSale.setType(nowType);
|
| | |
|
| | | 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(qfId, i, startWeight, endWeight, goodsSource));
|
| | | listFlashSale.add(getNewQualityFlashSale(taoBaoGoodsBrief, startWeight, endWeight, goodsSource));
|
| | | }
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | // 插入限时抢购
|
| | |
| | | if (listFlashSaleUpdate.size() > 0) {
|
| | | qualityFlashSaleService.updateBatchSelective(listFlashSaleUpdate);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param i
|
| | | * @return
|
| | | */
|
| | | public QualityFlashSale getNewQualityFlashSale(Long qfId, int i, int startWeight, int endWeight, int goodsSource) {
|
| | | public QualityFlashSale getNewQualityFlashSale(TaoBaoGoodsBrief taoBaoGoodsBrief, int startWeight, |
| | | int endWeight, int goodsSource) {
|
| | |
|
| | | QualityFlashSale flashSale = new QualityFlashSale();
|
| | | QualityFactory qualityFactory = new QualityFactory();
|
| | | qualityFactory.setId(qfId);
|
| | | flashSale.setQualityFactory(qualityFactory);
|
| | |
|
| | | if (QualityFactory.SOURCE_TAOBAO_DATAOKE == goodsSource) {
|
| | | // 大淘客优先展示
|
| | | double weight = 20000 + (Math.random() * 2001);
|
| | | flashSale.setWeight(weight);
|
| | | } else {
|
| | | double weight = startWeight + (Math.random() * ((endWeight - startWeight) + 1));
|
| | | flashSale.setWeight(weight);
|
| | | }
|
| | |
|
| | | //int nowType = qualityFlashSaleService.getNowType();
|
| | | //flashSale.setType(nowType);
|
| | |
|
| | | 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()
|
| | | *
|
| | |
| | |
|
| | | Integer rootCatId = goodsBrief.getRootCatId();
|
| | | if (rootCatId != null) {
|
| | | List<TaoBaoClassRelation> listRelation = taoBaoClassRelationMapper.listByTaoBaoCid(rootCatId.longValue());
|
| | | if (listRelation != null && listRelation.size() > 0) {
|
| | | TaoBaoClassRelation taoBaoClassRelation = listRelation.get(0);
|
| | | classID = taoBaoClassRelation.getCid();
|
| | | }
|
| | | classID = taoBaoClassRelationMapper.getClassIdByTaoBaoCid(rootCatId.longValue());
|
| | | }
|
| | |
|
| | | // 添加至精选商品库
|
| | |
| | | return selectionGoods;
|
| | |
|
| | | }
|
| | |
|
| | | public void setTaoBaoGoodsBriefDefault(TaoBaoGoodsBrief goodsBrief) {
|
| | | BigDecimal defaultZero = new BigDecimal("0");
|
| | |
|
| | | if (goodsBrief.getBiz30day() == null)
|
| | | goodsBrief.setBiz30day(0);
|
| | |
|
| | | if (goodsBrief.getCouponAmount() == null)
|
| | | goodsBrief.setCouponAmount(defaultZero);
|
| | |
|
| | | if (goodsBrief.getCouponLeftCount() == null)
|
| | | goodsBrief.setCouponLeftCount(0);
|
| | |
|
| | | if (goodsBrief.getCouponStartFee() == null)
|
| | | goodsBrief.setCouponStartFee(defaultZero);
|
| | |
|
| | | if (goodsBrief.getCouponTotalCount() == null)
|
| | | goodsBrief.setCouponTotalCount(0);
|
| | |
|
| | | if (goodsBrief.getDayLeft() == null)
|
| | | goodsBrief.setDayLeft(0);
|
| | |
|
| | | if (goodsBrief.getEventCreatorId() == null)
|
| | | goodsBrief.setEventCreatorId(0);
|
| | |
|
| | | if (goodsBrief.getHasRecommended() == null)
|
| | | goodsBrief.setHasRecommended(0);
|
| | |
|
| | | if (goodsBrief.getHasSame() == null)
|
| | | goodsBrief.setHasSame(0);
|
| | |
|
| | | if (goodsBrief.getIncludeDxjh() == null)
|
| | | goodsBrief.setIncludeDxjh(0);
|
| | |
|
| | | if (goodsBrief.getLeafCatId() == null)
|
| | | goodsBrief.setIncludeDxjh(0);
|
| | |
|
| | | if (goodsBrief.getReservePrice() == null)
|
| | | goodsBrief.setReservePrice(defaultZero);
|
| | |
|
| | | if (goodsBrief.getRfdRate() == null)
|
| | | goodsBrief.setRfdRate(0);
|
| | |
|
| | | if (goodsBrief.getRootCatId() == null)
|
| | | goodsBrief.setRootCatId(0);
|
| | |
|
| | | if (goodsBrief.getRootCatScore() == null)
|
| | | goodsBrief.setRootCatScore(0);
|
| | |
|
| | | if (goodsBrief.getSameItemPid() == null)
|
| | | goodsBrief.setSameItemPid(0L);
|
| | |
|
| | | if (goodsBrief.getSellerId() == null)
|
| | | goodsBrief.setSellerId(0L);
|
| | |
|
| | | if (goodsBrief.getTkCommFee() == null)
|
| | | goodsBrief.setTkCommFee(defaultZero);
|
| | |
|
| | | if (goodsBrief.getTkRate() == null)
|
| | | goodsBrief.setTkRate(defaultZero);
|
| | |
|
| | | if (goodsBrief.getTotalFee() == null)
|
| | | goodsBrief.setTotalFee(defaultZero);
|
| | |
|
| | | if (goodsBrief.getTotalNum() == null)
|
| | | goodsBrief.setTotalNum(0);
|
| | |
|
| | | if (goodsBrief.getUserType() == null)
|
| | | goodsBrief.setUserType(0);
|
| | |
|
| | | if (goodsBrief.getZkPrice() == null)
|
| | | goodsBrief.setZkPrice(defaultZero);
|
| | |
|
| | | }
|
| | |
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 查询精选商品数据应用前端
|
| | | * 删除未更新的商品
|
| | | *
|
| | | * @param start
|
| | | * @param count
|
| | | * @param key
|
| | | * @param classId
|
| | | * 分类id
|
| | | * @param labId
|
| | | * 标签id
|
| | | * @return
|
| | | * @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);
|
| | | }
|
| | |
|
| | | 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
|
| | | public List<QualityFactory> listByMinSalesCountOrderByCreateTimeDesc(int salesCount, int page, int pageSize) {
|
| | | return qualityFactoryMapper.listByMinSalesCountOrderByCreateTimeDesc(salesCount, (page - 1) * pageSize,
|
| | | pageSize);
|
| | | }
|
| | |
|
| | | }
|