apzl_leasing/src_tenwa/com/tenwa/gps/GpsController.java
2020-08-20 15:40:00 +08:00

419 lines
17 KiB
Java

package com.tenwa.gps;
import com.alibaba.fastjson.JSON;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.are.lang.StringX;
import com.amarsoft.awe.util.ASResultSet;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.google.common.collect.ImmutableMap;
import com.tenwa.apzl.comm.GpsEnum;
import com.tenwa.httpclient.resources.GPSConfigure;
import net.sf.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class GpsController {
private String applyNo;
private String orderNo;
private String flowUnid;
private String tableName;
private String vin;
private String projectId;
private String userId;
private String params;
private String source;
/**
* 新增工单
*
* @throws Exception
*/
public String createOrder(JBOTransaction tx) throws Exception {
Transaction Sqlca = Transaction.createTransaction(tx);
String url, params, tips = null;
Map<String, String> header = null;
if (GpsEnum.ZR.getCode().equals(source)) {
url = GPSConfigure.get("ZR_create_url");
params = GpsCommon.zrEditCreateParameter(applyNo, Sqlca);
header = ImmutableMap.of("appKey", GPSConfigure.get("ZR_AppKey"));
tips = GpsEnum.ZR.getName();
} else {
url = GPSConfigure.get("TYUrl");
params = GpsCommon.tyEditCreateParameter(applyNo, Sqlca);
tips = GpsEnum.TY.getName();
}
if (url == null || params == null) return "组装请求工单信息失败,联系管理员!";
System.err.println("***************" + tips + "--新增工单上传参数*****************");
System.err.println(params);
System.err.println("***************" + tips + "--新增工单上传参数*****************");
Map<String, String> resultMap = HttpClientSUtil.doPostJson(url, params, header);
String data = resultMap.get("data");
System.err.println("***************" + tips + "--新增返回上传参数*****************");
System.err.println(data);
System.err.println("***************" + tips + "--新增返回上传参数*****************");
//日志参数
Map<String, String> logMap = new HashMap<String, String>();
logMap.put("URL", url);
logMap.put("UPLOAD_PARAMETER", params);
logMap.put("RETURN_PARAMETER", data);
logMap.put("CALL_USERID", userId);
logMap.put("FLOWUNID", flowUnid);
logMap.put("PROJECT_ID", projectId);
logMap.put("CALL_PURPOSE", tips + "--新增工单");
logMap.put("CALL_STATUS", resultMap.get("status"));//http请求状态
//添加日志记录
GpsCommon.callRecord(logMap, Sqlca);
JSONObject job = JSONObject.fromObject(data);
String result = null;
boolean orderStatus = false;//订单是否成功状态
String orderNo = "";//工单ID
if (GpsEnum.ZR.getCode().equals(source)) {
orderStatus = job.getBoolean("Success");
result = orderStatus ? "0" : "9";
if(orderStatus){
orderNo = job.getJSONObject("Data").getString("Id");
}
} else {
result = job.getString("result");
orderStatus = !StringX.isSpace(result) && "0".equals(result) ? true : false;
if(orderStatus){
orderNo = job.getString("orderNo");
}
}
if (orderStatus) {
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='" + result + "',ORDER_NO='" + orderNo + "',STATUS='8',MESSAGE='提交成功' where APPLY_NO='" + applyNo + "'");
return "提交成功!";
} else {
String errorMsg = "新增工单失败,";
if (GpsEnum.ZR.getCode().equals(source)) {
errorMsg += job.getString("AllMessages");
} else {
errorMsg += job.getString("message");
}
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='" + result + "',MESSAGE='" + errorMsg + "' where APPLY_NO='" + applyNo + "'");
return errorMsg;
}
}
/**
* 取消工单
*
* @throws Exception
*/
public String cancelOrder(JBOTransaction tx) throws Exception {
Transaction Sqlca = Transaction.createTransaction(tx);
String url, tips = null;
Map<String, String> params = null;
Map<String, String> header = null;
if (GpsEnum.ZR.getCode().equals(source)) {
params = ImmutableMap.of("Appcode", applyNo);
url = GPSConfigure.get("ZR_cancel_url");
tips = GpsEnum.ZR.getName();
header = ImmutableMap.of("appKey", GPSConfigure.get("ZR_AppKey"));
} else {
params = params = GpsCommon.tyEditQueryParameter(applyNo);
url = GPSConfigure.get("TYUrl");
tips = GpsEnum.TY.getName();
}
System.err.println("***************" + tips + "--取消工单URL*****************");
System.err.println(url);
System.err.println("***************" + tips + "--取消工单URL*****************");
String params2 = JSON.toJSONString(params);
System.err.println("***************" + tips + "--取消工单上传参数*****************");
System.err.println(params2);
System.err.println("***************" + tips + "--取消工单上传参数*****************");
Map<String, String> resultMap = null;
if (GpsEnum.ZR.getCode().equals(source)) {
resultMap = HttpClientSUtil.doPostJson(url, params2, header);
}else{
resultMap = HttpClientSUtil.doPatchJson(url, params2);
}
String data = resultMap.get("data");
System.err.println("***************" + tips + "--取消工单返回参数*****************");
System.err.println(data);
System.err.println("***************" + tips + "--取消工单返回参数*****************");
Map<String, String> logMap = new HashMap<String, String>();
logMap.put("URL", url);
logMap.put("UPLOAD_PARAMETER", params.toString());
logMap.put("RETURN_PARAMETER", data);
logMap.put("CALL_USERID", userId);
logMap.put("FLOWUNID", flowUnid);
logMap.put("PROJECT_ID", projectId);
logMap.put("CALL_PURPOSE", tips + "--取消工单");
logMap.put("CALL_STATUS", resultMap.get("status"));
GpsCommon.callRecord(logMap, Sqlca);
JSONObject job = JSONObject.fromObject(data);
String result = null;
boolean orderStatus = false;//订单是否成功状态
if (GpsEnum.ZR.getCode().equals(source)) {
orderStatus = job.getBoolean("Success");
result = orderStatus ? "0" : "9";
} else {
result = job.getString("result");
orderStatus = !StringX.isSpace(result) && "0".equals(result) ? true : false;
}
if (orderStatus) {
boolean succ = job.containsKey("success") ? job.getBoolean("success") : false;
//中瑞或天易[succ=true]
if (succ || GpsEnum.ZR.getCode().equals(source)) {
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='" + result + "',MESSAGE='取消成功' where APPLY_NO='" + applyNo + "'");
return "取消成功!";
} else {
String orderStep = job.getString("orderStep");
String itemname = Sqlca.getString("select cl.itemname from code_library cl where cl.codeno='gps_order_step' and cl.itemno='" + orderStep + "'");
return "取消失败,当前订单状态为" + itemname;
}
} else {
String errorMsg = "取消失败,";
if (GpsEnum.ZR.getCode().equals(source)) {
errorMsg += job.getString("AllMessages");
} else {
errorMsg += job.getString("message");
}
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='" + result + "',MESSAGE='" + errorMsg + "' where APPLY_NO='" + applyNo + "'");
return errorMsg;
}
}
/**
* 根据车架号查询工单
*
* @throws Exception
*/
public boolean queryOrderToVin(Transaction Sqlca) throws Exception {
String url, tips = null;
Map<String, String> params = null;
if(StringX.isSpace(source)) source = Sqlca.getString("select source from LM_GPS_ORDER_TEMP where FLOWUNID ='"+flowUnid+"'");
if (GpsEnum.ZR.getCode().equals(source)) {
params = ImmutableMap.of("VIN", vin);
url = GPSConfigure.get("ZR_query_url");
tips = GpsEnum.ZR.getName();
} else {
params = GpsCommon.tyEditQueryToVinParameter(vin);
url = GPSConfigure.get("TYQueryOrderToVin");
tips = GpsEnum.TY.getName();
}
System.err.println("***************" + tips + "--根据车架号查询工单URL*****************");
System.err.println(url);
System.err.println("***************" + tips + "--根据车架号查询工单URL*****************");
System.err.println("***************" + tips + "--根据车架号查询工单上传参数*****************");
System.err.println(params);
System.err.println("***************" + tips + "--根据车架号查询工单上传参数*****************");
Map<String, String> resultMap = HttpClientSUtil.doGet(url, params, GpsEnum.ZR.getCode().equals(source) ? GPSConfigure.get("ZR_AppKey") : null);
String data = resultMap.get("data");
System.err.println("***************" + tips + "--根据车架号查询工单返回参数*****************");
System.err.println(data);
System.err.println("***************" + tips + "--根据车架号查询工单返回参数*****************");
//日志参数
Map<String, String> logMap = new HashMap<String, String>();
logMap.put("URL", url);
logMap.put("UPLOAD_PARAMETER", params.toString());
logMap.put("RETURN_PARAMETER", data);
logMap.put("CALL_USERID", userId);
logMap.put("FLOWUNID", flowUnid);
logMap.put("PROJECT_ID", projectId);
logMap.put("CALL_PURPOSE", tips + "--根据车架号查询工单");
logMap.put("CALL_STATUS", resultMap.get("status"));
GpsCommon.callRecord(logMap, Sqlca);
if (GpsEnum.ZR.getCode().equals(source)) {
return GpsCommon.zrQueryToVinDataPersistence(data, vin, Sqlca);
}
return GpsCommon.tyQueryToVinDataPersistence(data, Sqlca);
}
/**
* 根据申请编号查询工单
*
* @throws Exception
*/
public String queryOrder(JBOTransaction tx) throws Exception {
Transaction Sqlca = Transaction.createTransaction(tx);
if(GpsEnum.ZR.getCode().equals(source)){
String result2 = queryOrderToVin(Sqlca) == true ? "查询成功!" : "查询失败!";
return "车架号查询定位信息:" + result2;
}
String url = GPSConfigure.get("TYUrl") + "/" + orderNo + "," + applyNo;
System.err.println("***************天易--根据申请编号查询工单URL*****************");
System.err.println(url);
System.err.println("***************天易--根据申请编号查询工单URL*****************");
Map<String, String> params = GpsCommon.tyEditQueryParameter(applyNo);
System.err.println("***************天易--根据申请编号查询工单上传参数*****************");
System.err.println(params);
System.err.println("***************天易--根据申请编号查询工单上传参数*****************");
Map<String, String> resultMap = HttpClientSUtil.doGet(url, params, null);
String data = resultMap.get("data");
System.err.println("***************天易--根据申请编号查询工单返回参数*****************");
System.err.println(data);
System.err.println("***************天易--根据申请编号查询工单返回参数*****************");
//日志参数
Map<String, String> logMap = new HashMap<String, String>();
logMap.put("URL", url);
logMap.put("UPLOAD_PARAMETER", params.toString());
logMap.put("RETURN_PARAMETER", data);
logMap.put("CALL_USERID", userId);
logMap.put("FLOWUNID", flowUnid);
logMap.put("PROJECT_ID", projectId);
logMap.put("CALL_PURPOSE", "天易--根据申请编号查询工单");
logMap.put("CALL_STATUS", resultMap.get("status"));
GpsCommon.callRecord(logMap, Sqlca);
String result1 = GpsCommon.tyQueryDataPersistence(data, applyNo, tableName, Sqlca);
String result2 = queryOrderToVin(Sqlca) == true ? "查询成功!" : "查询失败!";
return "申请编号查询定位信息:" + result1 + ",车架号查询定位信息:" + result2;
}
/**
* 天易--修改工单
*
* @throws Exception
*/
public String alterOrder(JBOTransaction tx) throws Exception {
Transaction Sqlca = Transaction.createTransaction(tx);
String url = GPSConfigure.get("TYUrl");
String params = GpsCommon.tyEditAlterParameter(applyNo, this.params, Sqlca);
System.err.println("***************天易--修改工单上传参数*****************");
System.err.println(params);
System.err.println("***************天易--修改工单上传参数*****************");
Map<String, String> resultMap = HttpClientSUtil.doPutJson(url, params);
String data = resultMap.get("data");
System.err.println("***************天易--修改工单返回参数*****************");
System.err.println(data);
System.err.println("***************天易--修改工单返回参数*****************");
Map<String, String> logMap = new HashMap<String, String>();
logMap.put("URL", url);
logMap.put("UPLOAD_PARAMETER", params.toString());
logMap.put("RETURN_PARAMETER", data);
logMap.put("CALL_USERID", userId);
logMap.put("FLOWUNID", flowUnid);
logMap.put("PROJECT_ID", projectId);
logMap.put("CALL_PURPOSE", "天易--修改工单");
logMap.put("CALL_STATUS", resultMap.get("status"));
GpsCommon.callRecord(logMap, Sqlca);
JSONObject job = JSONObject.fromObject(data);
String result = job.getString("result");
if ("0".equals(result)) {
String success = job.getString("success");
if ("true".equals(success)) {
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='" + result + "',MESSAGE='修改成功' where APPLY_NO='" + applyNo + "'");
return "修改成功!";
} else {
String orderStep = job.getString("orderStep");
String itemname = Sqlca.getString("select cl.itemname from code_library cl where cl.codeno='gps_order_step' and cl.itemno='" + orderStep + "'");
return "修改失败,当前订单状态为" + itemname;
}
} else {
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='" + result + "',MESSAGE='修改失败," + job.getString("message") + "' where APPLY_NO='" + applyNo + "'");
return "修改失败," + job.getString("message");
}
}
/**
* 天易--获取图片
*
* @throws Exception
*/
public String getImage(JBOTransaction tx) throws Exception {
Transaction Sqlca = Transaction.createTransaction(tx);
ASResultSet res = Sqlca.getASResultSet(new SqlObject("SELECT url FROM lm_gps_photo WHERE apply_no='" + applyNo + "'"));
StringBuffer strb = null;
while (res.next()) {
if (strb == null) {
strb = new StringBuffer(res.getString("url"));
} else {
strb.append("," + res.getString("url"));
}
}
res.close();
if (strb == null)
return "null";
return strb.toString();
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getVin() {
return vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getApplyNo() {
return applyNo;
}
public void setApplyNo(String applyNo) {
this.applyNo = applyNo;
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getFlowUnid() {
return flowUnid;
}
public void setFlowUnid(String flowUnid) {
this.flowUnid = flowUnid;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}