二手车补充
This commit is contained in:
parent
0b746abd83
commit
d0c736ebfa
@ -0,0 +1,80 @@
|
||||
package com.tenwa.lease.app.vehicleAssessment;
|
||||
/**
|
||||
* 二手车评估
|
||||
* @author 张磊
|
||||
*/
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.log4j.Logger;
|
||||
import jbo.app.LB_EQUIPMENT_CAR_TEMP;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.amarsoft.are.jbo.BizObject;
|
||||
import com.amarsoft.are.jbo.BizObjectManager;
|
||||
import com.amarsoft.are.jbo.JBOFactory;
|
||||
import com.amarsoft.are.jbo.JBOTransaction;
|
||||
import com.tenwa.lease.util.VehicleAppraisementUtil;
|
||||
|
||||
public class vehicleAssessmentController {
|
||||
|
||||
private String id;
|
||||
|
||||
private Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String vehicleAppraisement(JBOTransaction tx){
|
||||
String result = null;
|
||||
try {
|
||||
BizObjectManager bomLSNT = JBOFactory.getBizObjectManager(LB_EQUIPMENT_CAR_TEMP.CLASS_NAME,tx);
|
||||
BizObject boLSNT = bomLSNT.createQuery("ID=:ID").setParameter("ID",id).getSingleResult(false);
|
||||
//获取车型ID
|
||||
String modelId = boLSNT.getAttribute("modelId").toString();
|
||||
//获取地区编号
|
||||
String zone = boLSNT.getAttribute("zone").toString();
|
||||
//因为从数据库获取到的上牌日期的格式不满足接口需求,所以要利用SimpleDateFormat进行变换
|
||||
Date date = new SimpleDateFormat("yyyy/MM/dd").parse(boLSNT.getAttribute("regDate").toString());
|
||||
String regDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
|
||||
//获取车辆行驶里程
|
||||
String mile = boLSNT.getAttribute("mile").toString();
|
||||
//得到Car300接口返回的Json数据
|
||||
String responseResult = VehicleAppraisementUtil.getVehicleAppraisementResponse(modelId, zone, regDate, mile);
|
||||
JSONObject object = JSONObject.parseObject(responseResult);
|
||||
boLSNT.setAttributeValue("discharge_standard", object.get("discharge_standard").toString());
|
||||
boLSNT.setAttributeValue("detail_report_url", object.get("detail_report_url").toString());
|
||||
//提取出Json数据中的status属性(1:成功;0:失败)并判断,如果为0,则将出错原因返回到前台
|
||||
String status = object.get("status").toString();
|
||||
if(status == "0"){
|
||||
result = object.getString("error_msg").toString();
|
||||
return result;
|
||||
}
|
||||
//将Json字符串中的数组数据部分转换为Json数组
|
||||
List<ConcurrentHashMap> list = JSONArray.parseArray((String)object.get("eval_prices"),ConcurrentHashMap.class);
|
||||
//遍历Json数组并将对应字段的数据加入到数据库中
|
||||
for(int i=0;i<list.size();i++){
|
||||
String condition = list.get(i).get("condition").toString();
|
||||
boLSNT.setAttributeValue(condition+"_dealer_low_buy_price",list.get(i).get("dealer_low_buy_price"));
|
||||
boLSNT.setAttributeValue(condition+"_dealer_buy_price",list.get(i).get("dealer_low_buy_price"));
|
||||
boLSNT.setAttributeValue(condition+"_individual_low_sold_price",list.get(i).get("individual_low_sold_price"));
|
||||
boLSNT.setAttributeValue(condition+"_individual_price",list.get(i).get("individual_price"));
|
||||
boLSNT.setAttributeValue(condition+"_dealer_low_sold_price", list.get(i).get("dealer_low_sold_price"));
|
||||
boLSNT.setAttributeValue(condition+"_dealer_price",list.get(i).get("dealer_price"));
|
||||
boLSNT.setAttributeValue(condition+"_dealer_high_sold_price", list.get(i).get("dealer_high_sold_price"));
|
||||
}
|
||||
bomLSNT.saveObject(boLSNT);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("执行车辆评估操作失败", e);
|
||||
return "ERROR";
|
||||
}
|
||||
return "SUCCESS";
|
||||
}
|
||||
}
|
||||
56
src_tenwa/com/tenwa/lease/util/VehicleAppraisementUtil.java
Normal file
56
src_tenwa/com/tenwa/lease/util/VehicleAppraisementUtil.java
Normal file
@ -0,0 +1,56 @@
|
||||
package com.tenwa.lease.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class VehicleAppraisementUtil {
|
||||
|
||||
public static String getVehicleAppraisementResponse(String modelId,String zone,String regDate,String mile){
|
||||
String urlStr = "https://api.che300.com/service/getUsedCarPrice?"
|
||||
+"token=ee450692cbd24e8bacb27b6f46b4d752&modelId="+modelId
|
||||
+"®Date="+regDate+"&mile="+mile+"&zone="+zone+"";
|
||||
String result = VehicleAppraisementUtil.getResponseResult(urlStr);
|
||||
return result;
|
||||
}
|
||||
//通过请求url返回Json数据
|
||||
public static String getResponseResult (String url){
|
||||
String line = "";
|
||||
String httpResponseResult = "";
|
||||
try {
|
||||
HttpURLConnection connection = VehicleAppraisementUtil.getURLConnection(url);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
connection.getInputStream(),"utf-8"));
|
||||
while ((line = reader.readLine()) != null) {
|
||||
httpResponseResult += line.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return httpResponseResult;
|
||||
}
|
||||
//获取请求需要的HttpURLConnection连接
|
||||
public static HttpURLConnection getURLConnection(String url){
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
URL newUrl = new URL(url);
|
||||
connection = (HttpURLConnection) newUrl.openConnection();
|
||||
connection.setDoOutput(false);//post请求应改为true
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setUseCaches(false);
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("Charset", "utf-8");
|
||||
connection.setRequestProperty("Accept-Charset", "utf-8");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user