| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.quartz.Job;
|
| | | import org.quartz.JobDataMap;
|
| | | import org.quartz.JobExecutionContext;
|
| | |
| | | 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 构造函数--");
|
| | |
| | |
|
| | | @Override
|
| | | public void execute(JobExecutionContext context) throws JobExecutionException {
|
| | | LogHelper.test("---UpdateQualityFactoryJob----execute ");
|
| | |
|
| | | // 爬取商品信息
|
| | | searchGoods(context);
|
| | | }
|
| | |
|
| | | public void searchGoods(JobExecutionContext context) {
|
| | | try {
|
| | |
|
| | | JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
|
| | |
|
| | | BoutiqueAutoRule autoRule = new BoutiqueAutoRule();
|
| | |
|
| | | /* 规则id */
|
| | | if (jobDataMap.get("ruleId") != null && !StringUtil.isNullOrEmpty(jobDataMap.get("ruleId").toString())) {
|
| | | Long ruleId = Long.parseLong(jobDataMap.get("ruleId").toString());
|
| | | autoRule.setId(ruleId);
|
| | | Object object = jobDataMap.get("key");
|
| | | if (object == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | /* 筛选条件 */
|
| | | JSONObject jsonData = null;
|
| | | if (jobDataMap.get("searchContent") != null) {
|
| | | String jsonContent = jobDataMap.get("searchContent").toString();
|
| | | jsonData = JSONObject.fromObject(jsonContent);
|
| | | }
|
| | |
|
| | | if (jsonData == null) {
|
| | | jsonData = new JSONObject();
|
| | | }
|
| | |
|
| | | /* 来源名称 */
|
| | | if (jsonData.get("sourceCalss") != null && !StringUtil.isNullOrEmpty(jsonData.get("sourceCalss").toString())) {
|
| | | String sourceCalss = jsonData.get("sourceCalss").toString();
|
| | | autoRule.setSourceCalss(sourceCalss);
|
| | | }
|
| | |
|
| | | /* 规则名称 */
|
| | | String title = "";
|
| | | if (jsonData.get("title") != null && !StringUtil.isNullOrEmpty(jsonData.get("title").toString())) {
|
| | | title = jsonData.get("title").toString();
|
| | | }
|
| | | autoRule.setTitle(title);
|
| | |
|
| | | /* 系统类目id */
|
| | | String systemCid = "";
|
| | | if (jsonData.get("systemCid") != null && !StringUtil.isNullOrEmpty(jsonData.get("systemCid").toString())) {
|
| | | systemCid = jsonData.get("systemCid").toString();
|
| | | }
|
| | | autoRule.setSystemCid(systemCid);
|
| | |
|
| | | |
| | | BoutiqueAutoRule autoRule = (BoutiqueAutoRule) object;
|
| | | /* 操作人: 开发账号 */
|
| | | AdminUser admin = new AdminUser(2L);
|
| | | autoRule.setAdminUser(admin);
|
| | |
|
| | | |
| | | /* 标签列表 */
|
| | | List<Label> listLabs = new ArrayList<Label>();
|
| | |
|
| | | if (jsonData.get("lableNames") != null && !StringUtil.isNullOrEmpty(jsonData.get("lableNames").toString())) {
|
| | |
|
| | | // 空格隔开
|
| | | String[] arrtitles = jsonData.get("lableNames").toString().split("\\s+");
|
| | |
|
| | | /* 遍历标签名称:查询数据库中是否已存在 */
|
| | | String lableNames = autoRule.getLableNames();
|
| | | if (!StringUtil.isNullOrEmpty(lableNames)) {
|
| | | String[] arrtitles = lableNames.split("\\s+"); // 空格隔开
|
| | | for (String name : arrtitles) {
|
| | | List<Label> labels = labelService.selectByTitle(name.trim());
|
| | |
|
| | | if (labels != null && labels.size() > 0) {
|
| | | Label label = labels.get(0);
|
| | |
|
| | | listLabs.add(label);
|
| | | } else {
|
| | | // 新增
|
| | | Label addLabel = addLabel(name, admin);
|
| | | listLabs.add(addLabel);
|
| | | Label label = labelService.getByTitleCache("labKey", name.trim());
|
| | | if (label == null) {
|
| | | label = insertLabel(name, admin);
|
| | | }
|
| | |
|
| | | listLabs.add(label);
|
| | | }
|
| | | }
|
| | |
|
| | | int source = Integer.parseInt(jobDataMap.get("source").toString());
|
| | | autoRule.setSource(QualityFactory.SOURCE_TAOBAO);
|
| | |
|
| | | if (BoutiqueAutoRule.TB_OPTIONAL == source) {
|
| | | // 来源淘宝普通接口
|
| | | |
| | | if (BoutiqueAutoRule.TB_OPTIONAL == autoRule.getSource()) { // 1、来源淘宝普通接口
|
| | | autoRule.setGoodsSource(QualityFactory.SOURCE_TAOBAO);
|
| | |
|
| | | searchTaoBao(jsonData, listLabs, autoRule);
|
| | | }
|
| | |
|
| | | if (BoutiqueAutoRule.TB_MATERIAL == source) {
|
| | | searchTaoBao(listLabs, autoRule);
|
| | | } else if (BoutiqueAutoRule.TB_MATERIAL == autoRule.getSource()) { // 2、淘宝推荐
|
| | | autoRule.setGoodsSource(QualityFactory.SOURCE_TAOBAO_MATERIAL);
|
| | | // 淘宝推荐
|
| | | searchMaterial(jsonData, listLabs, autoRule);
|
| | | searchMaterial(listLabs, autoRule);
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
| | | *
|
| | | * @param jobDataMap
|
| | | */
|
| | | private void searchTaoBao(JSONObject jsonData, List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | |
|
| | | private void searchTaoBao(List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | | try {
|
| | | Date time = new Date();
|
| | | String formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(time);
|
| | |
|
| | | // 页大小,默认100条
|
| | | int pageSize = 100;
|
| | |
|
| | | String formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
|
| | | boolean isCrawl = true;
|
| | | // 权重起始
|
| | | int startWeight = 0;
|
| | |
| | |
|
| | | // 最多爬取页码
|
| | | int pageMax = 200;
|
| | | if (jsonData.get("maxPage") != null) {
|
| | | pageMax = Integer.parseInt(jsonData.get("maxPage").toString());
|
| | | if (autoRule.getMaxPage() != null) {
|
| | | pageMax = autoRule.getMaxPage();
|
| | | }
|
| | |
|
| | | /* 参数处理 */
|
| | | SearchFilter filter = getSearchFilter(jsonData);
|
| | | // 展示条目
|
| | | filter.setPageSize(pageSize);
|
| | | SearchFilter filter = getSearchFilter(autoRule);
|
| | | filter.setPageSize(100);
|
| | |
|
| | | for (int page = 1; page <= pageMax; page++) {
|
| | |
|
| | | filter.setPage(page);
|
| | |
|
| | | TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiao(filter);
|
| | | LogHelper.test(title + "searchWuLiao 已爬取- " + page + "-页-");
|
| | |
|
| | | // 结果为空 时不再请求
|
| | | // 结果为空 结束请求
|
| | | if (result == null) {
|
| | | LogHelper.test(title + "searchWuLiao返回 result为空");
|
| | | return;
|
| | | break;
|
| | | }
|
| | |
|
| | | // 结果数据处理
|
| | |
| | |
|
| | | /* 权重范围 */
|
| | | if (page < 3) {
|
| | | startWeight = 10000;
|
| | | endWeight = 12000;
|
| | | startWeight = 4000;
|
| | | endWeight = 6000;
|
| | | } else {
|
| | | startWeight = 10;
|
| | | endWeight = 3000;
|
| | |
| | | autoRule.setStartWeight(startWeight);
|
| | | autoRule.setEndWeight(endWeight);
|
| | |
|
| | | /* 筛选商品进入精选库中 */
|
| | | if (StringUtil.isNullOrEmpty(title)) {
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | } else {
|
| | | if (title.contains(IS_9K9)) {
|
| | | screen9K9(filter, listGoods, jsonData, listLabs, autoRule);
|
| | | } else {
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | }
|
| | | }
|
| | |
|
| | | // 筛选入库
|
| | | screen(listGoods, filter, listLabs, autoRule);
|
| | | |
| | | /* 销售量小值 */
|
| | | int minSales = 0;
|
| | | if (jsonData.get("startSales") != null) {
|
| | | minSales = (int) jsonData.get("startSales");
|
| | | if (autoRule.getStartSales() != null) {
|
| | | minSales = autoRule.getStartSales();
|
| | | }
|
| | |
|
| | | /* 销售量大值 */
|
| | | int maxSales = 0;
|
| | | if (jsonData.get("endSales") != null) {
|
| | | maxSales = (int) jsonData.get("endSales");
|
| | | if (autoRule.getEndSales() != null) {
|
| | | maxSales = autoRule.getEndSales();
|
| | | }
|
| | |
|
| | | // 销量控制
|
| | | for (TaoBaoGoodsBrief goodsBrief : listGoods) {
|
| | |
|
| | | int biz30day = goodsBrief.getBiz30day();
|
| | | /* 验证销售量 -- 结束爬取数据 */
|
| | | if (maxSales > 0 && minSales > 0 && (biz30day < minSales || biz30day > maxSales)) {
|
| | |
| | | break;// 结束爬取数据
|
| | | }
|
| | | }
|
| | | |
| | | // 9k9 限时抢购 不操作删除
|
| | | if (title.contains(IS_9K9) || title.contains(FLASH_SALE)) {
|
| | |
|
| | | // 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());
|
| | | |
| | | List<Long> list = qualityFactoryService.getAuctionIdbyClassId(systemCid, autoRule.getGoodsSource(), formatDate);
|
| | | |
| | | if (list != null && list.size() > 0) {
|
| | | if (list.size() <= 100) {
|
| | | qualityFactoryService.deleteBatchByTaoBaoGoodsId(list);
|
| | | } else {
|
| | |
|
| | | 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) {
|
| | | //System.out.println(list.subList(start, list.size()));
|
| | | sublist = list.subList(start, list.size());
|
| | | qualityFactoryService.deleteBatchByTaoBaoGoodsId(sublist);
|
| | | break;
|
| | | }
|
| | | sublist = list.subList(start, end);
|
| | | qualityFactoryService.deleteBatchByTaoBaoGoodsId(sublist);
|
| | | start += countRow;
|
| | | end += countRow;
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(autoRule.getSystemCid())) {
|
| | | Long systemCid = Long.parseLong(autoRule.getSystemCid());
|
| | | qualityFactoryService.deleteNotUpdateGoods(systemCid, formatDate, autoRule.getGoodsSource());
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
| | | *
|
| | | * @param jobDataMap
|
| | | */
|
| | | private void searchMaterial(JSONObject jsonData, List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | | private void searchMaterial(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;
|
| | | // 权重结束
|
| | |
| | |
|
| | | // 最多爬取页码
|
| | | int pageMax = 200;
|
| | | if (jsonData.get("maxPage") != null) {
|
| | | pageMax = Integer.parseInt(jsonData.get("maxPage").toString());
|
| | | }
|
| | | if (autoRule.getMaxPage() != null)
|
| | | pageMax = autoRule.getMaxPage();
|
| | |
|
| | | /* 参数处理 */
|
| | | SearchFilter filter = getSearchFilter(jsonData);
|
| | | SearchFilter filter = getSearchFilter(autoRule);
|
| | |
|
| | | for (int page = 1; page <= pageMax; page++) {
|
| | |
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | /* 筛选商品进入精选库中 */
|
| | | if (StringUtil.isNullOrEmpty(title)) {
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | } else {
|
| | | if (title.contains(IS_9K9)) {
|
| | | screen9K9(filter, listGoods, jsonData, listLabs, autoRule);
|
| | | } else {
|
| | | screen(listGoods, jsonData, filter, listLabs, autoRule);
|
| | | }
|
| | | }
|
| | | // 筛选入库
|
| | | screen(listGoods, 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 (!StringUtil.isNullOrEmpty(autoRule.getSystemCid())) {
|
| | | Long systemCid = Long.parseLong(autoRule.getSystemCid());
|
| | | qualityFactoryService.deleteNotUpdateGoods(systemCid, formatDate, autoRule.getGoodsSource());
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
| | | * @param jobDataMap
|
| | | * @return
|
| | | */
|
| | | public SearchFilter getSearchFilter(JSONObject jsonData) {
|
| | |
|
| | | public SearchFilter getSearchFilter(BoutiqueAutoRule autoRule) {
|
| | | SearchFilter filter = new SearchFilter();
|
| | |
|
| | | // 排序字段 销量高到低(默认)
|
| | | filter.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
|
| | | // 搜索关键词
|
| | | filter.setKey(autoRule.getKey());
|
| | | // 官方推荐商品库投放ID;淘宝类目id集合
|
| | | filter.setCateIds(autoRule.getCateIds());
|
| | |
|
| | | if (jsonData.get("key") != null) {
|
| | | String key = jsonData.get("key").toString();
|
| | | if (!StringUtil.isNullOrEmpty(key)) {
|
| | | // 搜索关键词
|
| | | filter.setKey(key);
|
| | | }
|
| | | // 在售价范围小值
|
| | | if (autoRule.getStartZkPrice() != null) {
|
| | | filter.setStartPrice(new BigDecimal(autoRule.getStartPrice()));
|
| | | }
|
| | |
|
| | | if (jsonData.get("cateIds") != null) {
|
| | | // 官方推荐商品库投放ID;淘宝类目id集合
|
| | | filter.setCateIds(jsonData.get("cateIds").toString());
|
| | | // 在售价范围大值
|
| | | if (autoRule.getEndZkPrice() != null) {
|
| | | filter.setEndPrice(new BigDecimal(autoRule.getEndZkPrice()));
|
| | | }
|
| | |
|
| | | if (jsonData.get("startZkPrice") != null) {
|
| | | // 在售价范围小值
|
| | | Double startZkPrice = Double.valueOf(jsonData.get("startZkPrice").toString());
|
| | | filter.setStartPrice(new BigDecimal(startZkPrice));
|
| | | }
|
| | |
|
| | | if (jsonData.get("endZkPrice") != null) {
|
| | | // 在售价范围大值
|
| | | Double endZxPrice = Double.valueOf(jsonData.get("endZkPrice").toString());
|
| | | filter.setEndPrice(new BigDecimal(endZxPrice));
|
| | | }
|
| | |
|
| | | if (jsonData.get("startTkRate") != null) {
|
| | | // 佣金范围小值
|
| | | BigDecimal b = new BigDecimal(jsonData.get("startTkRate").toString());
|
| | | // 佣金范围小值
|
| | | if (autoRule.getStartTkRate() != null) {
|
| | | BigDecimal b = new BigDecimal(autoRule.getStartTkRate());
|
| | | double df = b.setScale(2, BigDecimal.ROUND_FLOOR).doubleValue();
|
| | | int tkRate = (int) (df * 100);
|
| | | filter.setStartTkRate(tkRate);
|
| | | }
|
| | |
|
| | | if (jsonData.get("endTkRate") != null) {
|
| | | // 佣金范围大值
|
| | | BigDecimal b = new BigDecimal(jsonData.get("endTkRate").toString());
|
| | | // 佣金范围大值
|
| | | if (autoRule.getEndTkRate() != null) {
|
| | | BigDecimal b = new BigDecimal(autoRule.getEndTkRate());
|
| | | double df = b.setScale(2, BigDecimal.ROUND_FLOOR).doubleValue();
|
| | | int tkRate = (int) (df * 100);
|
| | | filter.setEndTkRate(tkRate);
|
| | | }
|
| | |
|
| | | if (jsonData.get("isTmall") != null && jsonData.get("isTmall").toString().equals("1")) {
|
| | | // 是否天猫if ("1".equals(isTmall)) {
|
| | | // 是否天猫
|
| | | if (autoRule.getIsTmall() != null && autoRule.getIsTmall() == 1) {
|
| | | filter.setTmall(true);
|
| | | }
|
| | |
|
| | | if (jsonData.get("hasCoupon") != null && jsonData.get("hasCoupon").toString().equals("1")) {
|
| | | // 是否有券:1 有 0 无
|
| | | |
| | | // 是否有券:1 有 0 无
|
| | | if (autoRule.getHasCoupon() != null && autoRule.getHasCoupon() == 1) {
|
| | | filter.setQuan(1);
|
| | | }
|
| | |
|
| | | if (jsonData.get("freeShipment") != null && jsonData.get("freeShipment").toString().equals("1")) {
|
| | | // 是否包邮:1 有 0 无
|
| | | |
| | | // 是否包邮:1 有 0 无
|
| | | if (autoRule.getFreeShipment() != null && autoRule.getFreeShipment() == 1) {
|
| | | filter.setBaoYou(true);
|
| | | // ip地址
|
| | | // filter.setIp("113.251.22.10");// 重庆
|
| | | filter.setIp("218.72.111.105");// 杭州
|
| | | }
|
| | |
|
| | | if (jsonData.get("needPrepay") != null && jsonData.get("needPrepay").toString().equals("1")) {
|
| | | // 是否消费保障:1有 0 无
|
| | | |
| | | // 是否消费保障:1有 0 无
|
| | | if (autoRule.getNeedPrepay() != null && autoRule.getNeedPrepay() == 1) {
|
| | | filter.setNeedPrepay(true);
|
| | | }
|
| | |
|
| | | if (jsonData.get("npxLevel") != null) {
|
| | | // 牛皮癣程度,取值:1:不限,2:无,3:轻微
|
| | | filter.setNpxLevel((int) jsonData.get("npxLevel"));
|
| | | // 牛皮癣程度,取值:1:不限,2:无,3:轻微
|
| | | if (autoRule.getNpxLevel() != null && autoRule.getNpxLevel() == 1) {
|
| | | filter.setNpxLevel(autoRule.getNpxLevel());
|
| | | }
|
| | |
|
| | | if (jsonData.get("includePayRate30") != null && jsonData.get("includePayRate30").toString().equals("1")) {
|
| | | // 成交转化是否高于行业均值
|
| | | |
| | | // 成交转化是否高于行业均值
|
| | | if (autoRule.getIncludePayRate30() != null && autoRule.getIncludePayRate30() == 1) {
|
| | | filter.setIncludePayRate30(true);
|
| | | }
|
| | |
|
| | | if (jsonData.get("includeGoodRate") != null && jsonData.get("includeGoodRate").toString().equals("1")) {
|
| | | // 好评率是否高于行业均值 1 有 0 无
|
| | | // 好评率是否高于行业均值 1 有 0 无
|
| | | if (autoRule.getIncludeGoodRate() != null && autoRule.getIncludeGoodRate() == 1) {
|
| | | filter.setIncludeGoodRate(true);
|
| | | }
|
| | |
|
| | | if (jsonData.get("includeRfdRate") != null && jsonData.get("includeRfdRate").toString().equals("1")) {
|
| | | // 退款率是否低于行业均值 1 有 0 无
|
| | | // 退款率是否低于行业均值 1 有 0 无
|
| | | if (autoRule.getIncludeRfdRate() != null && autoRule.getIncludeRfdRate() == 1) {
|
| | | filter.setIncludeRfdRate(true);
|
| | | }
|
| | |
|
| | | return filter;
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | /**
|
| | | * 筛选符合条件的商品
|
| | | * |
| | | * @param taoBaoGoodsBriefs
|
| | | * @param jsonData
|
| | | * @param filter
|
| | | * @param listLabs
|
| | | * @param autoRule
|
| | | * @throws Exception
|
| | | */
|
| | | public void screen(List<TaoBaoGoodsBrief> taoBaoGoodsBriefs, SearchFilter filter,
|
| | | List<Label> listLabs, BoutiqueAutoRule autoRule) {
|
| | | try {
|
| | | List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
|
| | | for (TaoBaoGoodsBrief goodsBrief : taoBaoGoodsBriefs) {
|
| | | // 验证是否符合要求
|
| | | if (validate(filter, autoRule, goodsBrief, 1)) {
|
| | | listGoods.add(goodsBrief);
|
| | | }
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(autoRule, listGoods, listLabs);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * @return
|
| | | */
|
| | | public boolean validate(SearchFilter filter, JSONObject jsonData, TaoBaoGoodsBrief goodsBrief, int source) {
|
| | |
|
| | | /* 销售量小值 */
|
| | | public boolean validate(SearchFilter filter, BoutiqueAutoRule autoRule, TaoBaoGoodsBrief goodsBrief, int source) {
|
| | | int minSales = 0;
|
| | | if (jsonData.get("startSales") != null) {
|
| | | minSales = (int) jsonData.get("startSales");
|
| | | }
|
| | | if (autoRule.getStartSales() != null)
|
| | | minSales = autoRule.getStartSales();
|
| | |
|
| | | /* 销售量大值 */
|
| | | int maxSales = 0;
|
| | | if (jsonData.get("endSales") != null) {
|
| | | maxSales = (int) jsonData.get("endSales");
|
| | | }
|
| | |
|
| | | int biz30day = goodsBrief.getBiz30day();
|
| | | if (autoRule.getEndSales() != null)
|
| | | maxSales = autoRule.getEndSales();
|
| | |
|
| | | /* 验证销售量 */
|
| | | if (maxSales > 0 && minSales > 0 && (biz30day < minSales || biz30day > maxSales)) {
|
| | | return false;
|
| | | } else if (maxSales > 0 && biz30day > maxSales) {
|
| | | return false;
|
| | | } else if (minSales > 0 && biz30day < minSales) {
|
| | | return false;
|
| | | if (maxSales == 0 && minSales ==0) {
|
| | | |
| | | } else {
|
| | | int biz30day = goodsBrief.getBiz30day();
|
| | | if (maxSales > 0 && minSales > 0 && (biz30day < minSales || biz30day > maxSales)) {
|
| | | return false;
|
| | | } else if (maxSales > 0 && biz30day > maxSales) {
|
| | | return false;
|
| | | } else if (minSales > 0 && biz30day < minSales) {
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | /* 验证比例 */
|
| | | if (BoutiqueAutoRule.TB_MATERIAL == source) {
|
| | |
|
| | | 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)) {
|
| | | if (startTkRate > 0 && endTkRate > 0 && (tkRate.compareTo(new BigDecimal(startTkRate / 100)) < 0
|
| | | || tkRate.compareTo(new BigDecimal(endTkRate / 100)) > 0)) {
|
| | | return false;
|
| | | } else if (endTkRate > 0 && tkRate.compareTo(new BigDecimal(endTkRate / 100)) > 0) {
|
| | | return false;
|
| | |
| | |
|
| | | /* 券后价范围下限 */
|
| | | BigDecimal startPrice = null;
|
| | | if (jsonData.get("startPrice") != null) {
|
| | | startPrice = new BigDecimal(jsonData.get("startPrice").toString());
|
| | | }
|
| | |
|
| | | if (autoRule.getStartPrice() != null)
|
| | | startPrice = new BigDecimal(autoRule.getStartPrice().toString());
|
| | | /* 券后价范围上限 */
|
| | | BigDecimal endPrice = null;
|
| | | if (jsonData.get("endPrice") != null) {
|
| | | endPrice = new BigDecimal(jsonData.get("endPrice").toString());
|
| | | }
|
| | | if (autoRule.getEndPrice() != null)
|
| | | endPrice = new BigDecimal(autoRule.getEndPrice().toString());
|
| | |
|
| | | /* 券后价--计算 */
|
| | | BigDecimal couponPrice = TaoBaoUtil.getAfterUseCouplePrice(goodsBrief);
|
| | |
|
| | | /* 验证在券后价 */
|
| | | if (startPrice != null && endPrice != null && (couponPrice.compareTo(startPrice) < 0 || couponPrice.compareTo(endPrice) > 0)) {
|
| | | return false;
|
| | | } else if (endPrice != null && couponPrice.compareTo(endPrice) > 0) {
|
| | | return false;
|
| | | } else if (startPrice != null && couponPrice.compareTo(startPrice) < 0) {
|
| | | return false;
|
| | | }
|
| | |
|
| | | /* 验证在是否有券 */
|
| | | if (filter.getQuan() > 0) {
|
| | | String couponInfo = goodsBrief.getCouponInfo();
|
| | | if (StringUtil.isNullOrEmpty(couponInfo)) {
|
| | | if (startPrice == null && endPrice == null) {
|
| | | |
| | | } else {
|
| | | BigDecimal couponPrice = TaoBaoUtil.getAfterUseCouplePrice(goodsBrief);
|
| | | if (startPrice != null && endPrice != null
|
| | | && (couponPrice.compareTo(startPrice) < 0 || couponPrice.compareTo(endPrice) > 0)) {
|
| | | return false;
|
| | | } else if (endPrice != null && couponPrice.compareTo(endPrice) > 0) {
|
| | | return false;
|
| | | } else if (startPrice != null && couponPrice.compareTo(startPrice) < 0) {
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /* 验证在是否有券 */
|
| | | if (filter.getQuan() > 0) {
|
| | | String couponInfo = goodsBrief.getCouponInfo();
|
| | | if (StringUtil.isNullOrEmpty(couponInfo))
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 9.9 19.9 29.9 39.9 商品筛选
|
| | | * 插入新的标签
|
| | | *
|
| | | * @param taoBaoGoodsBriefs
|
| | | * @param title
|
| | | * @param admin
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public void screen9K9(SearchFilter filter, List<TaoBaoGoodsBrief> taoBaoGoodsBriefs, JSONObject jsonData, List<Label> listLabs,
|
| | | BoutiqueAutoRule autoRule) throws Exception {
|
| | |
|
| | | // 9k9数据-
|
| | | List<TaoBaoGoodsBrief> list9k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | // 19k9数据-
|
| | | List<TaoBaoGoodsBrief> list19k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | // 29k9数据-
|
| | | List<TaoBaoGoodsBrief> list29k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | // 49k9数据-
|
| | | List<TaoBaoGoodsBrief> list49k9 = new ArrayList<TaoBaoGoodsBrief>();
|
| | |
|
| | | // 验证是否符合要求入库
|
| | | for (TaoBaoGoodsBrief goodsBrief : taoBaoGoodsBriefs) {
|
| | |
|
| | | /* 销售量小值 */
|
| | | 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");
|
| | | }
|
| | |
|
| | | 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 (filter.getQuan() > 0) {
|
| | | String couponInfo = goodsBrief.getCouponInfo();
|
| | | if (StringUtil.isNullOrEmpty(couponInfo)) {
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
|
| | | /* 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) {
|
| | | 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) {
|
| | | List<Label> labs9K9 = new ArrayList<Label>();
|
| | | labs9K9.addAll(listLabs);
|
| | |
|
| | | List<Label> list = labelService.selectByTitleCache("labKey", "9.9");
|
| | |
|
| | | if (list == null || list.size() == 0) {
|
| | | // 新增
|
| | | Label addLabel = addLabel("9.9", admin);
|
| | | labs9K9.add(addLabel);
|
| | | } else {
|
| | | labs9K9.add(list.get(0));
|
| | | }
|
| | |
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(list9k9, labs9K9, autoRule);
|
| | | }
|
| | |
|
| | | if (list19k9.size() > 0) {
|
| | | List<Label> labs19K9 = new ArrayList<Label>();
|
| | | labs19K9.addAll(listLabs);
|
| | | List<Label> list = labelService.selectByTitleCache("labKey", "19.9");
|
| | | if (list == null || list.size() == 0) {
|
| | | // 新增
|
| | | Label addLabel = addLabel("19.9", admin);
|
| | | labs19K9.add(addLabel);
|
| | | } else {
|
| | | labs19K9.add(list.get(0));
|
| | | }
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(list19k9, labs19K9, autoRule);
|
| | | }
|
| | |
|
| | | if (list29k9.size() > 0) {
|
| | | List<Label> labs29K9 = new ArrayList<Label>();
|
| | | labs29K9.addAll(listLabs);
|
| | | List<Label> list = labelService.selectByTitleCache("labKey", "29.9");
|
| | | if (list == null || list.size() == 0) {
|
| | | // 新增
|
| | | Label addLabel = addLabel("29.9", admin);
|
| | | labs29K9.add(addLabel);
|
| | | } else {
|
| | | labs29K9.add(list.get(0));
|
| | | }
|
| | |
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(list29k9, labs29K9, autoRule);
|
| | | }
|
| | |
|
| | | if (list49k9.size() > 0) {
|
| | | List<Label> labs49K9 = new ArrayList<Label>();
|
| | | labs49K9.addAll(listLabs);
|
| | | List<Label> list = labelService.selectByTitleCache("labKey", "49.9");
|
| | | if (list == null || list.size() == 0) {
|
| | | // 新增
|
| | | Label addLabel = addLabel("49.9", admin);
|
| | | labs49K9.add(addLabel);
|
| | | } else {
|
| | | labs49K9.add(list.get(0));
|
| | | }
|
| | |
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(list49k9, labs49K9, autoRule);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | | }
|
| | |
|
| | | if (listGoods.size() > 0) {
|
| | | autoRule.setCalss9k9(false);
|
| | | qualityFactoryService.autoInsertOrUpadateStorage(listGoods, listLabs, autoRule);
|
| | | }
|
| | | }
|
| | |
|
| | | public Label addLabel(String title, AdminUser admin) throws Exception {
|
| | | public Label insertLabel(String title, AdminUser admin) throws Exception {
|
| | | // 新增
|
| | | Label label = new Label();
|
| | | label.setTitle(title);// 名称
|
| | |
| | | label.setIosClick(0l);
|
| | | label.setAndroidClick(0l);
|
| | | labelService.insertSelective(label);
|
| | |
|
| | | return label;
|
| | | }
|
| | |
|