167 lines
6.8 KiB
Java
167 lines
6.8 KiB
Java
package com.tenwa.lease.app.vehicleAssessment;
|
|
/**
|
|
* 二手车评估
|
|
* @author 张磊
|
|
*/
|
|
import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import jbo.app.LB_EQUIPMENT_CAR_TEMP;
|
|
import jbo.sys.CODE_LIBRARY;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
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 FlowUnid;
|
|
private String id;
|
|
|
|
private Logger logger = Logger.getLogger(this.getClass());
|
|
|
|
|
|
public String getFlowUnid() {
|
|
return FlowUnid;
|
|
}
|
|
|
|
public void setFlowUnid(String flowUnid) {
|
|
FlowUnid = flowUnid;
|
|
}
|
|
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(String id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String vehicleAppraisement(JBOTransaction tx){
|
|
try {
|
|
BizObjectManager bomLSNT = JBOFactory.getBizObjectManager(LB_EQUIPMENT_CAR_TEMP.CLASS_NAME,tx);
|
|
BizObjectManager codeSNT = JBOFactory.getBizObjectManager(CODE_LIBRARY.CLASS_NAME,tx);
|
|
if(bomLSNT != null){
|
|
BizObject boLSNT = bomLSNT.createQuery("id=:id").setParameter("id",id).getSingleResult(true);
|
|
//获取车型ID
|
|
String modelId = boLSNT.getAttribute("modelId").getString();
|
|
//获取用户选择的所属地区
|
|
//天津天津市河东区
|
|
String area = boLSNT.getAttribute("zone").getString();
|
|
/*if(area.indexOf("上海") != -1){
|
|
area = "上海上海市";
|
|
}
|
|
if(area.indexOf("重庆") != -1){
|
|
area = "重庆重庆市";
|
|
}
|
|
if(area.indexOf("北京") != -1){
|
|
area = "北京北京市";
|
|
}
|
|
if(area.indexOf("天津") != -1){
|
|
//area = "天津市市辖区";
|
|
area = "天津天津市";
|
|
}
|
|
if(area.indexOf("地区") != -1){
|
|
area = area.substring(0,area.indexOf("地区")+2);
|
|
}
|
|
if(area.indexOf("市") != -1){
|
|
area = area.substring(0,area.indexOf("市")+1);
|
|
}
|
|
if(area.indexOf("区") != -1){
|
|
area = area.substring(0,area.indexOf("区")+1);
|
|
}
|
|
if(area.indexOf("自治州") != -1){
|
|
area = area.substring(0,area.indexOf("自治州")+3);
|
|
}
|
|
if(area.indexOf("自治县") != -1){
|
|
area = area.substring(0,area.indexOf("自治县")+3);
|
|
}
|
|
if(area.indexOf("县") != -1){
|
|
area = area.substring(0,area.indexOf("县")+1);
|
|
}
|
|
if(area.indexOf("盟") != -1){
|
|
area = area.substring(0,area.indexOf("盟")+1);
|
|
}
|
|
if(area ==null ||"".equals(area)){
|
|
return "请返回租赁车辆基本信息页面填写地区!";
|
|
}*/
|
|
//到数据字典中查询对应的行政编号作为接口入参的zone参数
|
|
String zone = "";
|
|
if(codeSNT != null){
|
|
BizObject zoneResult = codeSNT.createQuery("select itemname,itemno FROM O WHERE codeno='AreaCode' AND itemname=:AREA")
|
|
.setParameter("AREA",area).getSingleResult(false);
|
|
|
|
String itemno = zoneResult == null ? "" : zoneResult.getAttribute("itemno").toString();
|
|
if(null == itemno || "".equals(itemno) || itemno.length() == 0 ){
|
|
return "没有查询到对应的上牌地区信息!!!";
|
|
}else{
|
|
/*BizObject usedCarCode = codeSNT.createQuery("select itemname,itemno FROM O WHERE codeno='UsedCarCode' AND itemno=:AREA")
|
|
.setParameter("AREA",itemno).getSingleResult(false);
|
|
if(null != usedCarCode){
|
|
zone = itemno;
|
|
}else{
|
|
zone = itemno.substring(0,4)+"00";
|
|
}*/
|
|
zone = itemno;
|
|
System.out.println("二手车评估地址ID:"+zone);
|
|
}
|
|
|
|
}
|
|
//因为从数据库获取到的上牌日期的格式不满足接口需求,所以要利用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();
|
|
if(mile == null || regDate == null || zone == null){
|
|
return "请到租赁车辆基本信息页面完善相关信息!";
|
|
}
|
|
//得到Car300接口返回的Json数据
|
|
String responseResult = VehicleAppraisementUtil.getVehicleAppraisementResponse(modelId, zone, regDate, mile);
|
|
//String responseResult = ReadJSON.ReadFile("D://che300new.txt");
|
|
JSONObject object = JSONObject.parseObject(responseResult);
|
|
String status = object.get("status").toString();
|
|
//提取出Json数据中的status属性(1:成功;0:失败)并判断,如果为0,则将出错原因返回到前台
|
|
if("0".equals(status)){
|
|
String errormsg = object.getString("error_msg");
|
|
return "评估失败,原因为:"+errormsg;
|
|
}
|
|
BigDecimal model_price = new BigDecimal(object.get("model_price").toString());
|
|
boLSNT.setAttributeValue("discharge_standard", object.get("discharge_standard").toString());
|
|
boLSNT.setAttributeValue("NOW_TOTAL", model_price.multiply(new BigDecimal(10000)));
|
|
boLSNT.setAttributeValue("detail_report_url", object.get("detail_report_url").toString());
|
|
//将Json字符串中的数组数据部分转换为Json数组
|
|
@SuppressWarnings("rawtypes")
|
|
List<HashMap> list = JSONArray.parseArray(JSON.toJSONString(object.get("eval_prices")),HashMap.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";
|
|
}
|
|
}
|