1 changed files with 144 additions and 0 deletions
@ -0,0 +1,144 @@ |
|||
package cn.chjyj.szwh.utils; |
|||
|
|||
import cn.chjyj.szwh.bean.GoodsDetail; |
|||
import cn.chjyj.szwh.bean.GoodsSource; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 处理api数据,转为bean |
|||
*/ |
|||
public class ApiGoodsUtils { |
|||
/** |
|||
* 从json字符串中抽取对象 |
|||
* @param innerJson |
|||
* @param islicode |
|||
* @return |
|||
*/ |
|||
public static GoodsSource jsonToGoodsSource(JSONObject innerJson,String islicode){ |
|||
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
GoodsSource goodsSource = new GoodsSource(); |
|||
goodsSource.setServicecode(innerJson.getString("'serviceCode'")); |
|||
goodsSource.setLinkcode(innerJson.getString("linkCode")); |
|||
// 发布 id
|
|||
String pubid = innerJson.getString("publisherId"); |
|||
goodsSource.setPublisherid(Integer.valueOf(pubid)); |
|||
goodsSource.setRegistrant(innerJson.getString("register")); |
|||
goodsSource.setResolutionUrl(innerJson.getString("resolutionUrl")); |
|||
goodsSource.setSourceType(innerJson.getString("sourceType")); |
|||
goodsSource.setSourceNameType(innerJson.getString("sourceNameType")); |
|||
goodsSource.setSourceName(innerJson.getString("sourceName")); |
|||
//
|
|||
goodsSource.setSourceidentify(innerJson.getString("sourceIdentify")); |
|||
goodsSource.setSourceFragment(innerJson.getString("sourceFragment")); |
|||
goodsSource.setTargetName(innerJson.getString("targetName")); |
|||
goodsSource.setTargetNameType(innerJson.getString("targetNameType")); |
|||
goodsSource.setTargetidentify(innerJson.getString("targetIdentify")); |
|||
//
|
|||
goodsSource.setTargetFragment(innerJson.getString("targetFragment")); |
|||
goodsSource.setTargetformat(innerJson.getString("targetFormat")); |
|||
// 存放了json字符串
|
|||
goodsSource.setSourceData(innerJson.getString("sourceData")); |
|||
goodsSource.setTargetData(innerJson.getString("targetData")); |
|||
//
|
|||
goodsSource.setMetadataxml(innerJson.getString("metadataXml")); |
|||
goodsSource.setCancellationReason(innerJson.getString("cancellationReason")); |
|||
// 字符串转为日期时间格式
|
|||
String aldate =innerJson.getString("allocationDate"); |
|||
try { |
|||
Date ndate = sdf.parse(aldate); |
|||
goodsSource.setAllocationtime(ndate); |
|||
}catch (Exception ex){ |
|||
// do nothing
|
|||
} |
|||
goodsSource.setSourceType(innerJson.getString("dataType")); |
|||
try{ |
|||
String cldate = innerJson.getString("cancellationDate"); |
|||
Date cndate =sdf.parse(cldate); |
|||
goodsSource.setCancellationtime(cndate); |
|||
}catch (Exception ex){ |
|||
//do nothing
|
|||
} |
|||
// 产品主键
|
|||
goodsSource.setGoodsIsliCode(islicode); |
|||
return goodsSource; |
|||
} |
|||
|
|||
/** |
|||
* 从json字符串中抽取商品详情 |
|||
* @param json soucedata中的字段 |
|||
* @param nodejson json数组中的单项 |
|||
* @return |
|||
*/ |
|||
public static GoodsDetail jsonToGoodsDetail(JSONObject json,JSONObject nodejson){ |
|||
// 抽取出sourcedata
|
|||
String sprice = json.getString("price"); |
|||
float price = Float.valueOf(sprice); |
|||
|
|||
GoodsDetail goodsDetail = new GoodsDetail(); |
|||
goodsDetail.setGoodsName(json.getString("titleName")); |
|||
goodsDetail.setGoodsImage(json.getString("cover")); |
|||
goodsDetail.setPrice(new BigDecimal(sprice)); |
|||
// 商品类型
|
|||
int igtype = "文化资源数据".equalsIgnoreCase("collectionType")?1:2; |
|||
goodsDetail.setGoodsType(igtype); |
|||
//
|
|||
int ictype = price<=0?1:2; |
|||
goodsDetail.setChargesType(ictype); |
|||
goodsDetail.setGoodsIslicode(json.getString("identifier")); |
|||
goodsDetail.setContractualPeriod(0); |
|||
goodsDetail.setSourcedataIslicode(json.getString("isliCode")); |
|||
goodsDetail.setEarnestMoney(new BigDecimal(0)); |
|||
//权属问题
|
|||
String stclass=json.getString("transactionKind"); |
|||
int istclass = "权属".equals(stclass)?1:2; |
|||
goodsDetail.setTransactionClass(istclass); |
|||
// 交易类型
|
|||
String transactionType = json.getString("transactionType"); |
|||
if(istclass==1){ |
|||
goodsDetail.setIdentifier(json.getString("identifier")); |
|||
goodsDetail.setIdentifiers(json.getString("identifiers")); |
|||
goodsDetail.setGoodsOwnershipStr(json.getString("rights")); |
|||
// 判断交易类型
|
|||
int itranstype = "授权".equals(transactionType)?2:1; |
|||
goodsDetail.setGoodsEntrust(itranstype); |
|||
if(itranstype==2){ |
|||
goodsDetail.setStock(-1); |
|||
}else{ |
|||
goodsDetail.setStock(1); |
|||
} |
|||
}else{ |
|||
goodsDetail.setIdentifier(json.getString("identifier")); |
|||
goodsDetail.setClassification(json.getString("classification")); |
|||
int irate = "租赁".equalsIgnoreCase(transactionType)?3:4; |
|||
goodsDetail.setGoodsEntrust(irate); |
|||
goodsDetail.setStock(1); |
|||
} |
|||
// 商品描述
|
|||
goodsDetail.setContract(json.getString("description")); |
|||
goodsDetail.setOtheridentifiers(json.getString("otherIdentifiers")); |
|||
//
|
|||
goodsDetail.setDataJson(nodejson.toJSONString()); |
|||
goodsDetail.setSourceJson(json.toJSONString()); |
|||
//处理授权周期
|
|||
String contractualPeriod =json.getString("contractualPeriod"); |
|||
int iperiod = 0; //授权周期
|
|||
if("永久".equals(contractualPeriod)){ |
|||
iperiod=1; |
|||
} |
|||
if("单次".equals(contractualPeriod)){ |
|||
iperiod=2; |
|||
} |
|||
if("周期".equals(contractualPeriod)){ |
|||
iperiod=3; |
|||
} |
|||
goodsDetail.setContractualPeriod(iperiod); |
|||
|
|||
return goodsDetail; |
|||
} |
|||
|
|||
|
|||
} |
|||
Loading…
Reference in new issue