| | |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | 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.taobao.TaoBaoGoodsUpdateService;
|
| | |
| | | private QualityFactoryService qualityFactoryService;
|
| | | @Resource
|
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
| | | |
| | |
|
| | | public QualityFactoryJob() {
|
| | | System.out.println("--UpdateQualityFactoryJob 构造函数--");
|
| | |
| | | */
|
| | | private void searchTaoBao(JSONObject jsonData, List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | | try {
|
| | | Date time = new Date();
|
| | | String formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(time);
|
| | | String formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
|
| | |
|
| | | // 页大小,默认100条
|
| | | int pageSize = 100;
|
| | |
| | | autoRule.setStartWeight(startWeight);
|
| | | autoRule.setEndWeight(endWeight);
|
| | |
|
| | | /* 筛选商品进入精选库中 */
|
| | | if (!StringUtil.isNullOrEmpty(title) && title.contains(IS_9K9)) {
|
| | | screen9K9(filter, listGoods, jsonData, listLabs, autoRule);
|
| | | } else {
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | }
|
| | | // 筛选入库
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | |
|
| | | |
| | | |
| | | /* 销售量小值 */
|
| | | int minSales = 0;
|
| | | if (jsonData.get("startSales") != null) {
|
| | |
| | | /* 更新完成后清理之前创建的数据 */
|
| | | if (jsonData.get("systemCid") != null && !StringUtil.isNullOrEmpty(jsonData.get("systemCid").toString())) {
|
| | | Long systemCid = Long.parseLong(jsonData.get("systemCid").toString());
|
| | | deleteNotUpdateGoods(systemCid, formatDate, autoRule.getGoodsSource());
|
| | | qualityFactoryService.deleteNotUpdateGoods(systemCid, formatDate, autoRule.getGoodsSource());
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
| | | private void searchMaterial(JSONObject jsonData, List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | |
|
| | | try {
|
| | | String formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
|
| | |
|
| | | // 默认20条
|
| | | int pageSize = 20;
|
| | |
|
| | | boolean isCrawl = true;
|
| | |
|
| | | // 权重起始
|
| | | int startWeight = 1000;
|
| | | // 权重结束
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | /* 筛选商品进入精选库中 */
|
| | | if (!StringUtil.isNullOrEmpty(title) && title.contains(IS_9K9)) {
|
| | | screen9K9(filter, listGoods, jsonData, listLabs, autoRule);
|
| | | } else {
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | }
|
| | | // 筛选入库
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | |
| | |
|
| | | // 总页数爬取完成
|
| | | PageEntity pageEntity = result.getPageEntity();
|
| | |
| | | LogHelper.test("----" + title + "--结束-------");
|
| | | break;// 结束爬取数据
|
| | | }
|
| | | }
|
| | | |
| | | // 9k9 限时抢购 不操作删除
|
| | | if (!StringUtil.isNullOrEmpty(title) && (title.contains(IS_9K9) || title.contains(FLASH_SALE))) {
|
| | | return;
|
| | | }
|
| | |
|
| | | /* 更新完成后清理之前创建的数据 */
|
| | | if (jsonData.get("systemCid") != null && !StringUtil.isNullOrEmpty(jsonData.get("systemCid").toString())) {
|
| | | Long systemCid = Long.parseLong(jsonData.get("systemCid").toString());
|
| | | qualityFactoryService.deleteNotUpdateGoods(systemCid, formatDate, autoRule.getGoodsSource());
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
| | | return filter;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 9.9 19.9 29.9 39.9 商品筛选
|
| | | * |
| | | * @param taoBaoGoodsBriefs
|
| | | */
|
| | | public void screen9K9(SearchFilter filter, List<TaoBaoGoodsBrief> taoBaoGoodsBriefs, JSONObject jsonData,
|
| | | List<Label> listLabs, BoutiqueAutoRule autoRule) throws Exception {
|
| | |
|
| | | /* 9k9 */
|
| | | BigDecimal price9k9 = new BigDecimal(10);
|
| | | List<TaoBaoGoodsBrief> list9k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | /* 19k9 */
|
| | | BigDecimal price19k9 = new BigDecimal(20);
|
| | | List<TaoBaoGoodsBrief> list19k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | /* 29.9 */
|
| | | BigDecimal price29K9 = new BigDecimal(30);
|
| | | List<TaoBaoGoodsBrief> list29k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | /* 49.9 */
|
| | | BigDecimal price49K9 = new BigDecimal(50);
|
| | | List<TaoBaoGoodsBrief> list49k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | /* 销售量小值 */
|
| | | int minSales = 0;
|
| | | if (jsonData.get("startSales") != null) {
|
| | | minSales = (int) jsonData.get("startSales");
|
| | | }
|
| | |
|
| | | /* 销售量大值 */
|
| | | int maxSales = 0;
|
| | | if (jsonData.get("endSales") != null) {
|
| | | maxSales = (int) jsonData.get("endSales");
|
| | | }
|
| | |
|
| | | // 验证是否符合要求入库
|
| | | for (TaoBaoGoodsBrief goodsBrief : taoBaoGoodsBriefs) {
|
| | |
|
| | | /* 验证在是否有券 */
|
| | | if (filter.getQuan() > 0) {
|
| | | String couponInfo = goodsBrief.getCouponInfo();
|
| | | if (StringUtil.isNullOrEmpty(couponInfo)) {
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | /* 验证销售量 */
|
| | | int biz30day = goodsBrief.getBiz30day();
|
| | | if (maxSales > 0 && minSales > 0 && (biz30day < minSales || biz30day > maxSales)) {
|
| | | continue;
|
| | | } else if (maxSales > 0 && biz30day > maxSales) {
|
| | | continue;
|
| | | } else if (minSales > 0 && biz30day < minSales) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | /* 验证比例 */
|
| | | if (BoutiqueAutoRule.TB_MATERIAL == autoRule.getSource()) {
|
| | | int startTkRate = filter.getStartTkRate();
|
| | | int endTkRate = filter.getEndTkRate();
|
| | | BigDecimal tkRate = goodsBrief.getTkRate();
|
| | | if (startTkRate > 0 && endTkRate > 0 && (tkRate.compareTo(new BigDecimal(startTkRate / 100)) < 0
|
| | | || tkRate.compareTo(new BigDecimal(endTkRate / 100)) > 0)) {
|
| | | continue;
|
| | | } else if (endTkRate > 0 && tkRate.compareTo(new BigDecimal(endTkRate / 100)) > 0) {
|
| | | continue;
|
| | | } else if (startTkRate > 0 && tkRate.compareTo(new BigDecimal(startTkRate / 100)) < 0) {
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | /* 券后价--计算 */
|
| | | BigDecimal couponPrice = TaoBaoUtil.getAfterUseCouplePrice(goodsBrief);
|
| | | if (couponPrice.compareTo(price9k9) < 0) {
|
| | | list9k9.add(goodsBrief);
|
| | | } else if (couponPrice.compareTo(price19k9) < 0) {
|
| | | list19k9.add(goodsBrief);
|
| | | } else if (couponPrice.compareTo(price29K9) < 0) {
|
| | | list29k9.add(goodsBrief);
|
| | | } else if (couponPrice.compareTo(price49K9) < 0) {
|
| | | list49k9.add(goodsBrief);
|
| | | }
|
| | | }
|
| | | autoRule.setCalss9k9(true);
|
| | | AdminUser admin = autoRule.getAdminUser();
|
| | |
|
| | | if (list9k9.size() > 0) {
|
| | | Label label = labelService.getByTitleCache("labKey", "9.9");
|
| | | if (label == null) {
|
| | | label = insertLabel("9.9", admin);
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, list9k9, listLabs, label);
|
| | | }
|
| | |
|
| | | if (list19k9.size() > 0) {
|
| | | Label label = labelService.getByTitleCache("labKey", "19.9");
|
| | | if (label == null) {
|
| | | label = insertLabel("9.9", admin);
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, list19k9, listLabs, label);
|
| | | }
|
| | |
|
| | | if (list29k9.size() > 0) {
|
| | | Label label = labelService.getByTitleCache("labKey", "29.9");
|
| | | if (label == null) {
|
| | | label = insertLabel("9.9", admin);
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, list29k9, listLabs, label);
|
| | | }
|
| | |
|
| | | if (list49k9.size() > 0) {
|
| | | Label label = labelService.getByTitleCache("labKey", "49.9");
|
| | | if (label == null) {
|
| | | label = insertLabel("9.9", admin);
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, list49k9, listLabs, label);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 筛选符合条件的商品
|
| | |
| | | * @throws Exception
|
| | | */
|
| | | public void screen(List<TaoBaoGoodsBrief> taoBaoGoodsBriefs, JSONObject jsonData, SearchFilter filter,
|
| | | List<Label> listLabs, BoutiqueAutoRule autoRule) throws Exception {
|
| | |
|
| | | List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : taoBaoGoodsBriefs) {
|
| | | // 验证是否符合要求
|
| | | if (validate(filter, jsonData, goodsBrief, 1)) {
|
| | | listGoods.add(goodsBrief);
|
| | | List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | | try {
|
| | | List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : taoBaoGoodsBriefs) {
|
| | | // 验证是否符合要求
|
| | | if (validate(filter, jsonData, goodsBrief, 1)) {
|
| | | listGoods.add(goodsBrief);
|
| | | }
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, listGoods, listLabs);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | if (listGoods.size() > 0) {
|
| | | autoRule.setCalss9k9(false);
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, listGoods, listLabs, null);
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | return label;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除未更新的商品
|
| | | * |
| | | * @param systemCid
|
| | | * @param formatDate
|
| | | * @param source
|
| | | */
|
| | | public void deleteNotUpdateGoods(Long systemCid, String formatDate, int source) {
|
| | | List<Long> list = qualityFactoryService.getAuctionIdbyClassId(systemCid, source, formatDate);
|
| | | if (list == null || list.size() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 小于100条直接删除
|
| | | if (list.size() <= 100) {
|
| | | qualityFactoryService.deleteBatchByTaoBaoGoodsId(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());
|
| | | qualityFactoryService.deleteBatchByTaoBaoGoodsId(sublist);
|
| | | break;
|
| | | }
|
| | | sublist = list.subList(start, end);
|
| | | qualityFactoryService.deleteBatchByTaoBaoGoodsId(sublist);
|
| | | start += countRow;
|
| | | end += countRow;
|
| | | }
|
| | |
|
| | | }
|
| | | }
|