| | |
| | | package com.yeshi.fanli.util.dataoke;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import org.jsoup.Jsoup;
|
| | | import org.jsoup.nodes.Document;
|
| | | import org.jsoup.nodes.Element;
|
| | | import org.jsoup.select.Elements;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.dataoke.DaTaoKeApiResult;
|
| | | import com.yeshi.fanli.dto.taobao.TaoBaoShopDTO;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
| | | for (int i = 0; i < array.size(); i++) {
|
| | | list.add(gson.fromJson(array.optJSONObject(i).toString(), DaTaoKeDetail.class));
|
| | | }
|
| | |
|
| | | for (DaTaoKeDetail dt : list)
|
| | | if (!dt.getPic().startsWith("http"))
|
| | | dt.setPic("https:" + dt.getPic());
|
| | |
|
| | | return new DaTaoKeApiResult(resultJson.optJSONObject("data").optInt("total_num"),
|
| | | resultJson.optJSONObject("data").optString("update_time"), list);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取大淘客品牌优选 品牌id
|
| | | * |
| | | * @return
|
| | | */
|
| | | public static List<String> getBrandIdList() {
|
| | | List<String> listId = new ArrayList<>();
|
| | | try {
|
| | | Document doc = Jsoup.connect("http://www.dataoke.com/brandFilter?cid=0&sort=1&main=0").get();
|
| | | Element root = doc.getElementsByClass("brand-list").get(0);
|
| | | Elements items = root.getElementsByTag("a");
|
| | | for (int i = 0; i < items.size(); i++) {
|
| | | String id = items.get(i).attr("href").split("\\?")[1].replace("id=", "").trim();
|
| | | listId.add(id);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return listId;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取店铺下前4个商品、店铺介绍
|
| | | * |
| | | * @param brandId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoShopDTO getDynamicShopInfo(String brandId) {
|
| | | if (brandId == null) {
|
| | | return null;
|
| | | }
|
| | | TaoBaoShopDTO taoBaoShopDTO = null;
|
| | |
|
| | | Document doc;
|
| | | try {
|
| | | doc = Jsoup.connect("http://www.dataoke.com/brandSingle?id=" + brandId).get();
|
| | | Elements els = doc.getElementsByTag("script");
|
| | | for (int i = 0; i < els.size(); i++) {
|
| | | if (els.get(i).html().contains("var brandData")) {
|
| | |
|
| | | JSONObject data = JSONObject
|
| | | .fromObject(els.get(i).html().replace("var brandData =", "").trim().split("};")[0] + "}");
|
| | | taoBaoShopDTO = convertTaoBaoShopDTO(data);
|
| | | break;
|
| | | }
|
| | | }
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return taoBaoShopDTO;
|
| | |
|
| | | }
|
| | |
|
| | | public static TaoBaoShopDTO convertTaoBaoShopDTO(JSONObject data) {
|
| | | TaoBaoShopDTO taoBaoShopDTO = new TaoBaoShopDTO();
|
| | | JSONObject item = data.optJSONObject("act");
|
| | | taoBaoShopDTO.setSellerId(item.optLong("seller_id"));
|
| | | taoBaoShopDTO.setBrandId(item.optString("brand_id"));
|
| | | taoBaoShopDTO.setBrandDes(item.optString("brand_des"));
|
| | | int userType = 0;
|
| | |
|
| | | List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
|
| | | JSONArray arrayGoods = data.optJSONArray("goods");
|
| | | for (int i = 0; i < arrayGoods.size(); i++) {
|
| | | if (i >= 2) {
|
| | | break;
|
| | | }
|
| | | JSONObject itemGoods = arrayGoods.optJSONObject(i);
|
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
| | | taoBaoGoods.setAuctionId(itemGoods.optLong("goodsid"));
|
| | | taoBaoGoods.setBiz30day(itemGoods.optInt("xiaoliang"));
|
| | | taoBaoGoods.setCouponAmount(new BigDecimal(itemGoods.optString("quan_jine")));
|
| | | taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", itemGoods.optString("quan_tiaojian"),
|
| | | MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(itemGoods.optString("quan_jine")))));
|
| | | taoBaoGoods.setCouponLeftCount(itemGoods.optInt("quan_num"));
|
| | | taoBaoGoods.setCouponStartFee(new BigDecimal(itemGoods.optString("quan_tiaojian")));
|
| | | taoBaoGoods.setCouponTotalCount(itemGoods.optInt("quan_num"));
|
| | | taoBaoGoods.setPictUrl(itemGoods.optString("pic"));
|
| | | taoBaoGoods.setPictUrlWhite(itemGoods.optString("pic"));
|
| | | taoBaoGoods.setSellerId(itemGoods.optLong("seller_id"));
|
| | | taoBaoGoods.setShopTitle("");
|
| | | taoBaoGoods.setTitle(itemGoods.optString("title"));
|
| | | taoBaoGoods.setUserType(itemGoods.optInt("istmall"));
|
| | | taoBaoGoods.setZkPrice(new BigDecimal(itemGoods.optString("yuanjia")));
|
| | | taoBaoGoods.setTkRate(new BigDecimal(itemGoods.optString("yongjin")));
|
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0"));
|
| | | taoBaoGoods.setState(0);
|
| | |
|
| | | listGoods.add(taoBaoGoods);
|
| | |
|
| | | userType = itemGoods.optInt("istmall");
|
| | | }
|
| | | taoBaoShopDTO.setListGoods(listGoods);
|
| | | taoBaoShopDTO.setUserType(userType);
|
| | | return taoBaoShopDTO;
|
| | | }
|
| | |
|
| | | class DaTaoKeResult {
|
| | | Date updateTime;
|
| | | List<DaTaoKeDetail> dataList;
|