Commit c16251b3 authored by 杨林's avatar 杨林

解析淘宝数据

parent b09ad719
package tools.dataformat
import model.Item
import tools.http.HttpTools
import tools.timestamp.TimestampTools
import scala.collection.mutable
/**
* Created with IntelliJ IDEA.
* Class: TB
* Description:
* User: lin
* Date: 2021-06-04
* Time: 14:18
*/
object TB {
/**
* 解析淘宝字段
*
* @param x 淘宝字段映射
* @return 返回格式化结果
*/
def formatTBData(x: mutable.Map[String, String]): Item = {
val price = x.getOrElse("zk_final_price", "0.0").replaceAll("\"", "").toDouble
val coupon_amount = x.getOrElse("coupon_amount", "0.0").replaceAll("\"", "").toDouble
val coupon_price = price - coupon_amount
val commission_rate = x.getOrElse("commission_rate", "0").replaceAll("\"", "").toInt / 10000.0
val title = x.getOrElse("title", "").replaceAll("\"", "")
Item(
platform = 1,
item_id = x.getOrElse("item_id", "").replaceAll("\"", ""),
item_name = title,
item_desc = x.getOrElse("item_description", "").replaceAll("\"", ""),
brand_name = "",
item_url = x.getOrElse("item_url", "").replaceAll("\"", ""),
item_pic_url = if (x.getOrElse("white_image", "").replaceAll("\"", "").isEmpty) x.getOrElse("pict_url", "").replaceAll("\"", "") else x.getOrElse("white_image", "").replaceAll("\"", ""),
item_volume = x.getOrElse("volume", "").replaceAll("\"", ""),
origin_category = x.getOrElse("level_one_category_name", "").replaceAll("\"", "") + "/" + x.getOrElse("category_name", "").replaceAll("\"", ""),
origin_category_id = x.getOrElse("level_one_category_id", "").replaceAll("\"", "") + "/" + x.getOrElse("category_id", "").replaceAll("\"", ""),
new_category = "",
new_category_id = "",
price = price,
coupon_price = coupon_price,
commission_rate = commission_rate,
coupon_commission = coupon_price,
commission_start_time = 0,
commission_end_time = 0,
coupon_amount = coupon_amount,
coupon_tips = x.getOrElse("coupon_info", "").replaceAll("\"", ""),
coupon_count = x.getOrElse("coupon_total_count", "0").replaceAll("\"", "").toInt,
coupon_remain = x.getOrElse("coupon_remain_count", "0").replaceAll("\"", "").toInt,
coupon_start_time = TimestampTools.date2Timestamp(x.getOrElse("coupon_start_time", "").replaceAll("\"", "")),
coupon_end_time = TimestampTools.date2Timestamp(x.getOrElse("coupon_end_time", "").replaceAll("\"", "")),
coupon_link = x.getOrElse("coupon_share_url", "").replaceAll("\"", ""),
item_label = HttpTools("POST").nlp_request(title),
shop_id = x.getOrElse("seller_id", "").replaceAll("\"", ""),
shop_name = x.getOrElse("shop_title", "").replaceAll("\"", ""),
shop_level = 0,
description_level = 0,
express_level = 0,
server_level = 0,
shop_type = 0,
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