package com.yeshi.fanli.job;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Component;
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
import com.yeshi.fanli.entity.goods.jd.NYouHuiGoods;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.goods.jd.NYouHuiService;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.TimeUtil;
|
import com.yeshi.fanli.util.goods.jd.NYouHuiUtil;
|
import com.yeshi.fanli.util.jd.JDUtil;
|
|
/**
|
* 京东商品更新
|
*
|
* @author Administrator
|
*
|
*/
|
@Component
|
public class JDGoodsUpdateJob {
|
|
@Resource
|
private NYouHuiService nyouHuiService;
|
|
/**
|
* 更新内优惠最近几天的商品
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
@XxlJob("nyhLatest2DayGoodsUpdateHandler")
|
public ReturnT<String> updateNYHLatest2DayGoods(String param) throws Exception {
|
long startTime = TimeUtil.convertToTimeTemp(
|
TimeUtil.getGernalTime(System.currentTimeMillis() - 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd");
|
List<String> list = NYouHuiUtil.getClasses();
|
for (String name : list) {
|
if (name.trim().equalsIgnoreCase("未分类"))
|
continue;
|
try {
|
List<NYouHuiGoods> goodsList = NYouHuiUtil.listByClassName(name,
|
StringUtil.isNullOrEmpty(param) ? 1 : Integer.parseInt(param));
|
for (NYouHuiGoods goods : goodsList) {
|
try {
|
if (TimeUtil.convertToTimeTemp(goods.getPublishTime(), "yyyy-MM-dd") >= startTime) {
|
NYouHuiGoods old = nyouHuiService.selectByName(goods.getName());
|
if (old == null
|
|| TimeUtil.convertToTimeTemp(old.getPublishTime(), "yyyy-MM-dd") < startTime) {
|
NYouHuiGoods goodsDetail = NYouHuiUtil.getGoodsDetail(goods.getSourceUrl());
|
List<Long> skuList = new ArrayList<>();
|
for (String link : goodsDetail.getLinkList()) {
|
String skuId = JDUtil.getJDGoodsIdByUJD(link);
|
skuList.add(Long.parseLong(skuId));
|
}
|
goodsDetail.setSkuId(skuList.get(0));
|
goodsDetail.setSkuList(skuList);
|
goodsDetail.setClassName(name);
|
nyouHuiService.addGoods(goodsDetail);
|
Thread.sleep(2000 + (int) (Math.random() * 5) * 1000);
|
}
|
}
|
} catch (Exception e) {
|
LogHelper.errorDetailInfo(e, "京东-内优惠出错", goods.getSourceUrl());
|
}
|
}
|
} catch (Exception e) {
|
LogHelper.errorDetailInfo(e, "京东-内优惠出错", name);
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
|
}
|