This commit is contained in:
liuzhao 2018-07-14 11:48:05 +08:00
commit 9086ad14a7
2 changed files with 94 additions and 55 deletions

View File

@ -5,26 +5,35 @@
Content: ʾÀýÏêÇéÒ³Ãæ
History Log:
*/
String sFlowUnid = CurPage.getParameter("FlowUnid");//流程编号
String sPrevUrl = CurPage.getParameter("PrevUrl");
if(sPrevUrl == null) sPrevUrl = "/Tenwa/Lease/App/Interface/VehicleEvaluation/LBEquipmentCarTempList.jsp";
String sTempletNo = "LBEquipmentCarTempInfo";//--Ä£°åºÅ--
ASObjectModel doTemp = new ASObjectModel(sTempletNo);
doTemp.setColTips("", "测试");
doTemp.setColTips("", "万元");
ASObjectWindow dwTemp = new ASObjectWindow(CurPage, doTemp,request);
dwTemp.Style = "2";//freeform
//dwTemp.ReadOnly = "-2";//Ö»¶Áģʽ
dwTemp.genHTMLObjectWindow(CurPage.getParameter("ID"));
dwTemp.genHTMLObjectWindow(sFlowUnid);
String sButtons[][] = {
{"true","All","Button","保存","保存所有修改","as_save(0)","","","",""},
{String.valueOf(!com.amarsoft.are.lang.StringX.isSpace(sPrevUrl)),"All","Button","返回","返回列表","returnList()","","","",""}
/* {"true","All","Button","保存","保存所有修改","as_save(0)","","","",""},
{String.valueOf(!com.amarsoft.are.lang.StringX.isSpace(sPrevUrl)),"All","Button","返回","返回列表","returnList()","","","",""} */
{"true","","Button","评估校验","评估校验","vehicleAppraisement()","","","","btn_icon_check"}
};
sButtonPosition = "south";
%><%@ include file="/Frame/resources/include/ui/include_info.jspf"%>
<script type="text/javascript">
function returnList(){
AsControl.OpenView("<%=sPrevUrl%>", "","_self","");
}
function vehicleAppraisement(){
var flowunid = "<%=sFlowUnid%>";
var result = RunJavaMethodTrans("com.tenwa.lease.app.vehicleAssessment.vehicleAssessmentController","vehicleAppraisement","FlowUnid="+flowunid);
if('SUCCESS' == result){
alert('评估成功,数据已写入数据库中');
location.reload();
}else if('ERROR' == result){
alert('评估失败');
}else{
alert(result);
}
}
</script>
<%@ include file="/Frame/resources/include/include_end.jspf"%>

View File

@ -12,6 +12,7 @@ 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;
@ -24,59 +25,88 @@ import com.tenwa.lease.util.VehicleAppraisementUtil;
public class vehicleAssessmentController {
private String id;
private String FlowUnid;
private Logger logger = Logger.getLogger(this.getClass());
public String getId() {
return id;
public String getFlowUnid() {
return FlowUnid;
}
public void setId(String id) {
this.id = id;
public void setFlowUnid(String flowUnid) {
FlowUnid = flowUnid;
}
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(true);
//获取车型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);
//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;
}
boLSNT.setAttributeValue("discharge_standard", object.get("discharge_standard").toString());
boLSNT.setAttributeValue("NOW_TOTAL", object.get("model_price").toString());
boLSNT.setAttributeValue("detail_report_url", object.get("detail_report_url").toString());
//将Json字符串中的数组数据部分转换为Json数组
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);
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("flowunid=:FLOWUNID").setParameter("FLOWUNID",FlowUnid).getSingleResult(true);
//获取车型ID
String modelId = boLSNT.getAttribute("modelId").getString();
//获取用户选择的所属地区
String area = boLSNT.getAttribute("zone").getString();
if(area.indexOf("上海") != -1){
area = "上海市市辖区";
}else if(area.indexOf("重庆") != -1){
area = "重庆市市辖区";
}else if(area.indexOf("地区") != -1){
area = area.substring(0,area.indexOf("地区")+2);
}else if(area.indexOf("") != -1){
area = area.substring(0,area.indexOf("")+1);
}else if(area.indexOf("") != -1){
area = area.substring(0,area.indexOf("")+1);
}else{
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);
if(zoneResult != null){
zone = zoneResult.getAttribute("itemno").getString();
}
}
//因为从数据库获取到的上牌日期的格式不满足接口需求,所以要利用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;
}
boLSNT.setAttributeValue("discharge_standard", object.get("discharge_standard").toString());
boLSNT.setAttributeValue("NOW_TOTAL", object.get("model_price").toString());
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);