| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.dataoke.DaTaoKeDetailMapper;
|
| | | import com.yeshi.fanli.dto.dataoke.DaTaoKeApiResult;
|
| | | import com.yeshi.fanli.dto.dataoke.DingDongQiangDTO;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
|
| | |
| | |
|
| | | @Override
|
| | | public void startSyncGoods() {
|
| | | |
| | | LogHelper.test("大淘客同步开始");
|
| | | // 判断是否有正在进行的更新
|
| | | String key1 = "dataoke-updating";
|
| | | // if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key1)))
|
| | | // return;
|
| | |
|
| | | // 开始更新
|
| | | redisManager.cacheCommonString(key1, "1", 60 * 20);
|
| | | long firstTime = System.currentTimeMillis() - 1000 * 60 * 5L;
|
| | | int totalCount = 0;
|
| | | for (int p = 1; p <= 2000; p++) {// 10W数据
|
| | | DaTaoKeApiResult result = DaTaoKeApiUtil.goodsList(p);
|
| | | if (result.getDetailList().size() < 50)// 更新完成
|
| | | {
|
| | | redisManager.removeCommonString(key1);
|
| | | break;
|
| | | try {
|
| | | DaTaoKeApiResult result = DaTaoKeApiUtil.goodsList(p);
|
| | | if (result.getDetailList().size() < 50)// 更新完成
|
| | | {
|
| | | break;
|
| | | }
|
| | | addGoodsList(result.getDetailList());
|
| | | totalCount += result.getDetailList().size();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | addGoodsList(result.getDetailList());
|
| | | totalCount += result.getDetailList().size();
|
| | | }
|
| | |
|
| | | LogHelper.test("大淘客总共更新数据数量:" + totalCount);
|
| | | // 清除过期数据
|
| | | if (totalCount > 50000)// 保证有5w数据再清除过期
|
| | |
| | | List<DaTaoKeDetail> dtList = listByGoodsIds(goodsIdList);
|
| | |
|
| | | Map<Long, DaTaoKeDetail> map = new HashMap<>();
|
| | | for (DaTaoKeDetail goods : dtList)
|
| | | map.put(goods.getGoodsId(), goods);
|
| | | if (dtList != null)
|
| | | for (DaTaoKeDetail goods : dtList)
|
| | | map.put(goods.getGoodsId(), goods);
|
| | | for (TaoBaoGoodsBrief goods : goodsList) {
|
| | | DaTaoKeDetail detail = map.get(goods.getAuctionId());
|
| | | goods = DaTaoKeUtil.filterTaoBaoGoods(goods, detail);
|
| | |
| | | public List<DaTaoKeDetail> listByIds(List<Long> idList) {
|
| | | return daTaoKeDetailMapper.listByIds(idList);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public List<DaTaoKeDetail> listByDtitle(String dtitle) {
|
| | |
|
| | |
| | | return daTaoKeDetailMapper.countSearchByTitleWithCid(title, (cid == null || cid == 0 ? null : cid));
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public List<DaTaoKeDetail> getGoodsNotInList(Long cid, List<Long> listId,int count) {
|
| | | return daTaoKeDetailMapper.getGoodsNotInList(cid, listId,count);
|
| | | public List<DaTaoKeDetail> getGoodsNotInList(Long cid, List<Long> listId, int count) {
|
| | | return daTaoKeDetailMapper.getGoodsNotInList(cid, listId, count);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public List<DaTaoKeDetail> listByCidAndMaxPrice(Integer cid, BigDecimal maxPrice, int page, int pageSize) {
|
| | | return daTaoKeDetailMapper.listByCidAndMaxMinPrice(cid, maxPrice, null, (page - 1) * pageSize, pageSize);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Long countByCidAndMaxPrice(Integer cid, BigDecimal maxPrice) {
|
| | |
|
| | | return daTaoKeDetailMapper.countByCidAndMaxMinPrice(cid, maxPrice, null);
|
| | | }
|
| | |
|
| | |
|
| | | private void updateGoods(Long id) {
|
| | | DaTaoKeDetail detail = daTaoKeDetailMapper.selectByPrimaryKey(id);
|
| | | if (detail != null)
|
| | | return;
|
| | | detail = DaTaoKeApiUtil.getGoodsDetailV1(id);
|
| | | if (detail != null) {
|
| | | List<DaTaoKeDetail> list = new ArrayList<>();
|
| | | list.add(detail);
|
| | | addGoodsList(list);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|