Commit 9bd9a0da authored by 杨林's avatar 杨林

解析京东数据

parent c600f068
package tools.dataformat
import model.{CouponItem, Item}
import tools.http.HttpTools
import tools.json.Jackson
import scala.collection.mutable
import scala.collection.immutable
/**
* Created with IntelliJ IDEA.
* Class: TB
* Description:
* User: lin
* Date: 2021-06-04
* Time: 14:18
*/
object JD {
/**
* 解析淘宝字段
*
* @param x 淘宝字段映射
* @return 返回格式化结果
*/
def formatJDData(x: mutable.Map[String, String]): Item = {
val title = x.getOrElse("skuName", "").replaceAll("\"", "")
val list = Jackson.parseStringToArray(x.getOrElse("couponList", "[]"))
val image = Jackson.parseStringToArray(x.getOrElse("imageList", "[]"))
// 取第一张券
var couponItem: CouponItem = null
if (list.isEmpty) {
couponItem = CouponItem(0.0, "", 0.0, 0L, 0L)
} else {
val coupon = list(0).asInstanceOf[immutable.HashMap[String, Any]]
couponItem = CouponItem(
discount = coupon.getOrElse("discount", "0").toString.replaceAll("\"", "").toDouble,
link = coupon.getOrElse("link", "").toString.replaceAll("\"", ""),
quota = coupon.getOrElse("quota", "0").toString.replaceAll("\"", "").toDouble,
useEndTime = coupon.getOrElse("useEndTime", "0").toString.replaceAll("\"", "").toLong,
useStartTime = coupon.getOrElse("useStartTime", "0").toString.replaceAll("\"", "").toLong
)
}
var imageUrl: String = null
if (image.isEmpty) {
imageUrl = ""
} else {
val map = image(0).asInstanceOf[immutable.Map[String,Any]]
imageUrl = map.getOrElse("url", "").toString
}
val price = x.getOrElse("price", "").replaceAll("\"", "").toDouble
Item(
platform = 2,
item_id = x.getOrElse("skuId", "").replaceAll("\"", ""),
item_name = title,
item_desc = x.getOrElse("document", "").replaceAll("\"", ""),
brand_name = x.getOrElse("brandName", "").replaceAll("\"", ""),
item_url = x.getOrElse("materialUrl", "").replaceAll("\"", ""),
item_pic_url = imageUrl,
item_volume = x.getOrElse("inOrderCount30Days", "").replaceAll("\"", ""),
origin_category = x.getOrElse("cid1Name", "").replaceAll("\"", "") + "/" +
x.getOrElse("cid2Name", "").replaceAll("\"", "") + "/" +
x.getOrElse("cid3Name", "").replaceAll("\"", ""),
origin_category_id = x.getOrElse("cid1", "").replaceAll("\"", "") + "/" +
x.getOrElse("cid2", "").replaceAll("\"", "") + "/" +
x.getOrElse("cid3", "").replaceAll("\"", ""),
new_category = "",
new_category_id = "",
price = price,
coupon_price = price - couponItem.discount,
commission_rate = x.getOrElse("commissionShare", "0").replaceAll("\"", "").toDouble / 100,
coupon_commission = x.getOrElse("couponCommission", "0").toDouble,
commission_start_time = 0L,
commission_end_time = 0L,
coupon_amount = couponItem.discount,
coupon_tips = "满" + couponItem.quota + "减" + couponItem.discount,
coupon_count = 9999,
coupon_remain = 9999,
coupon_start_time = couponItem.useStartTime,
coupon_end_time = couponItem.useEndTime,
coupon_link = couponItem.link,
item_label = HttpTools("POST").nlp_request(title),
shop_id = x.getOrElse("shopId", "").replaceAll("\"", ""),
shop_name = x.getOrElse("shopName", "").replaceAll("\"", ""),
shop_level = x.getOrElse("shopLevel", "0").replaceAll("\"", "").toDouble,
description_level = x.getOrElse("userEvaluateScore", "0").replaceAll("\"", "").toDouble,
express_level = x.getOrElse("logisticsLvyueScore", "0").replaceAll("\"", "").toDouble,
server_level = x.getOrElse("afterServiceScore", "0").replaceAll("\"", "").toDouble,
shop_type = x.getOrElse("shopLabel", "0").replaceAll("\"", "").toInt,
createTime = System.currentTimeMillis() / 1000
)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment