300 lines
14 KiB
Java
300 lines
14 KiB
Java
package com.tenwa.gps;
|
|
|
|
import com.amarsoft.are.jbo.JBOException;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.amarsoft.awe.util.ASResultSet;
|
|
import com.amarsoft.awe.util.SqlObject;
|
|
import com.amarsoft.awe.util.Transaction;
|
|
import com.tenwa.comm.exception.BusinessException;
|
|
import com.tenwa.httpclient.resources.GPSConfigure;
|
|
import net.sf.json.JSONArray;
|
|
import net.sf.json.JSONObject;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class GpsCommon {
|
|
|
|
private static String TYuserAccount = GPSConfigure.get("TYuserAccount");
|
|
private static String TYtoken = GPSConfigure.get("TYtoken");
|
|
private static String TYsign = GPSConfigure.get("TYsign");
|
|
private static String TYsign2 = GPSConfigure.get("TYsign2");
|
|
|
|
/**
|
|
* 天易--编辑新增工单请求参数
|
|
*
|
|
* @param flowUnid
|
|
* @param applyNo
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public static String tyEditCreateParameter(String applyNo, Transaction Sqlca) throws Exception {
|
|
ASResultSet res = Sqlca.getASResultSet(new SqlObject("select CONTACT_NAME,CONTACT_PHONE,PICCONTACT_NAME,PICCONTACT_PHONE,INSTALL_TIME,ADDRESS_CODE,ADDRESS_DETAIL,CAR_VIN,WIRED_NUM,WIRED_PERIOD,WIRELESS_NUM,WIRELESS_PERIOD,CAR_ACCOUNT from LM_GPS_ORDER_TEMP where APPLY_NO ='" + applyNo + "'"));
|
|
JSONObject params = new JSONObject();
|
|
if (res.next()) {
|
|
params.put("userAccount", TYuserAccount);
|
|
params.put("token", TYtoken);
|
|
params.put("sign", TYsign);
|
|
params.put("applyNo", applyNo);
|
|
params.put("contactName", res.getString("CONTACT_NAME"));
|
|
params.put("contactPhone", res.getString("CONTACT_PHONE"));
|
|
params.put("piccontactName", res.getString("PICCONTACT_NAME"));
|
|
params.put("piccontactPhone", res.getString("PICCONTACT_PHONE"));
|
|
params.put("installtime", res.getString("INSTALL_TIME"));
|
|
params.put("addressCode", res.getString("ADDRESS_CODE"));
|
|
params.put("addressDetail", res.getString("ADDRESS_DETAIL"));
|
|
params.put("carVin", res.getString("CAR_VIN"));
|
|
params.put("wiredNum", res.getString("WIRED_NUM"));
|
|
params.put("wiredPeriod", res.getString("WIRED_PERIOD"));
|
|
params.put("wirelessNum", res.getString("WIRELESS_NUM"));
|
|
params.put("wirelessPeriod", res.getString("WIRELESS_PERIOD"));
|
|
params.put("carAccount", res.getString("CAR_ACCOUNT"));
|
|
}
|
|
res.close();
|
|
return params.toString();
|
|
}
|
|
|
|
/**
|
|
* 天易--编辑修改工单请求参数
|
|
*
|
|
* @param applyNo
|
|
* @param params
|
|
* @param sqlca
|
|
* @return
|
|
*/
|
|
public static String tyEditAlterParameter(String applyNo, String params, Transaction sqlca) {
|
|
String[] paramArr = params.split("@");
|
|
int i = 0;
|
|
JSONObject json = new JSONObject();
|
|
json.put("userAccount", TYuserAccount);
|
|
json.put("token", TYtoken);
|
|
json.put("sign", TYsign);
|
|
json.put("applyNo", applyNo);
|
|
json.put("contactName", paramArr[i++]);
|
|
json.put("contactPhone", paramArr[i++]);
|
|
json.put("piccontactName", paramArr[i++]);
|
|
json.put("piccontactPhone", paramArr[i++]);
|
|
json.put("installtime", paramArr[i++]);
|
|
json.put("addressCode", paramArr[i++]);
|
|
json.put("addressDetail", paramArr[i++]);
|
|
json.put("carVin", paramArr[i++]);
|
|
json.put("wiredNum", paramArr[i++]);
|
|
json.put("wiredPeriod", paramArr[i++]);
|
|
json.put("wirelessNum", paramArr[i++]);
|
|
json.put("wirelessPeriod", paramArr[i++]);
|
|
json.put("carAccount", paramArr[i++]);
|
|
return json.toString();
|
|
}
|
|
|
|
|
|
/**
|
|
* 天易--编辑查询/取消工单请求参数
|
|
*
|
|
* @param applyNo
|
|
* @return
|
|
*/
|
|
public static Map<String, String> tyEditQueryParameter(String applyNo) {
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
params.put("userAccount", TYuserAccount);
|
|
params.put("token", TYtoken);
|
|
params.put("sign", TYsign);
|
|
params.put("applyNo", applyNo);
|
|
return params;
|
|
}
|
|
|
|
/**
|
|
* 天易--编辑车架号查询工单请求参数
|
|
*
|
|
* @param applyNo
|
|
* @return
|
|
*/
|
|
public static Map<String, String> tyEditQueryToVinParameter(String vin) {
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
params.put("userAccount", TYuserAccount);
|
|
params.put("token", TYtoken);
|
|
params.put("sign", TYsign2);
|
|
params.put("carVin", vin);
|
|
return params;
|
|
}
|
|
|
|
/**
|
|
* 天易--查询订单结果入表
|
|
*
|
|
* @param tableName
|
|
* @param flowUnid
|
|
* @return
|
|
* @throws JBOException
|
|
*/
|
|
public static String tyQueryDataPersistence(String data, String applyNo, String tableName, Transaction Sqlca) throws Exception {
|
|
JSONObject job = JSONObject.fromObject(data);
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
|
String thisDate = sdf.format(new Date());
|
|
String result = job.getString("result");
|
|
if (!"0".equals(result)) {
|
|
Sqlca.executeSQL("update " + tableName + " set RESULT='" + result + "',MESSAGE='查询失败," + job.getString("message") + "' where APPLY_NO='" + applyNo + "'");
|
|
return job.getString("message");
|
|
}
|
|
String status = job.getJSONObject("data").getString("status");
|
|
if ("3".equals(status)) {
|
|
JSONArray terminals = job.getJSONObject("data").getJSONArray("terminal");
|
|
Sqlca.executeSQL("delete from lm_gps_location where APPLY_NO='" + applyNo + "'");
|
|
for (int i = 0; i < terminals.size(); i++) {
|
|
JSONObject terminal = terminals.getJSONObject(i);
|
|
//定位信息入表
|
|
Sqlca.executeSQL("insert into lm_gps_location(ID,APPLY_NO,MODEL,RUN_STATUS,STATUS,IMEI,CAR_VIN,RECEIVE_TIME,GPS_TIME,LNG,LAT,INPUTTIME) value(replace(uuid(),\"-\",\"\"),'" + applyNo + "','" + terminal.getString("model") + "','" + terminal.getString("runStatus") + "','" + terminal.getString("status") + "','" + terminal.getString("imei") + "','" + terminal.getString("carVin") + "','" + terminal.getString("receiveTime") + "','" + terminal.getString("gpsTime") + "','" + (terminal.containsKey("lng") ? terminal.getString("lng") : "") + "','" + (terminal.containsKey("lat") ? terminal.getString("lat") : "") + "','" + thisDate + "')");
|
|
//安装图入表
|
|
int number = Integer.valueOf(Sqlca.getString("select COUNT(1) as number from LM_GPS_PHOTO lgp where lgp.APPLY_NO='" + applyNo + "'"));
|
|
if (number > 0) continue;
|
|
JSONArray photoMsgs = terminal.getJSONArray("photoMsg");
|
|
for (int j = 0; j < photoMsgs.size(); j++) {
|
|
JSONObject photoMsg = photoMsgs.getJSONObject(j);
|
|
Sqlca.executeSQL("insert into LM_GPS_PHOTO value(replace(uuid(),\"-\",\"\"),'" + applyNo + "','" + photoMsg.getString("photoId") + "','" + photoMsg.getString("url") + "','" + thisDate + "')");
|
|
}
|
|
}
|
|
}
|
|
Sqlca.executeSQL("update " + tableName + " set RESULT='" + result + "',STATUS='" + status + "',MESSAGE='查询成功' where APPLY_NO='" + applyNo + "'");
|
|
return "查询成功!";
|
|
}
|
|
|
|
/**
|
|
* 天易--根据车架查询订单结果解析
|
|
*
|
|
* @param tableName
|
|
* @param flowUnid
|
|
* @return
|
|
* @throws JBOException
|
|
*/
|
|
public static boolean tyQueryToVinDataPersistence(String data, Transaction Sqlca) throws Exception {
|
|
JSONObject job = JSONObject.fromObject(data);
|
|
String result = job.getString("result");
|
|
if (!"0".equals(result)) {
|
|
System.err.println("********************result****************");
|
|
System.err.println(result);
|
|
System.err.println("********************result****************");
|
|
return false;
|
|
}
|
|
boolean startUsing = true;
|
|
JSONArray dataArr = job.getJSONArray("data");
|
|
for (int i = 0; i < dataArr.size(); i++) {
|
|
Sqlca.executeSQL("update lm_gps_location set SPD='" + dataArr.getJSONObject(i).getString("spd") + "',DIR='" + dataArr.getJSONObject(i).getString("dir") + "',LOCATE_TYPE='" + dataArr.getJSONObject(i).getString("locateType") + "',STATUS_USING='" + dataArr.getJSONObject(i).getString("status") + "' where IMEI='" + dataArr.getJSONObject(i).getString("imei") + "'");
|
|
if ("0".equals(dataArr.getJSONObject(i).getString("status"))) {
|
|
System.err.println("********************status****************");
|
|
System.err.println(dataArr.getJSONObject(i).getString("status"));
|
|
System.err.println("********************status****************");
|
|
startUsing = false;
|
|
}
|
|
}
|
|
return startUsing;
|
|
}
|
|
|
|
|
|
/**
|
|
* 中瑞--新增工单请求参数
|
|
*
|
|
* @param flowUnid
|
|
* @param applyNo
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public static String zrEditCreateParameter(String applyNo, Transaction Sqlca) throws Exception {
|
|
ASResultSet res = Sqlca.getASResultSet(new SqlObject("select WIRED_PERIOD,WIRED_NUM,WIRELESS_NUM,CAR_VIN,ADDRESS_CODE,SHOPNAME,CONTACT_NAME,CONTACT_PHONE,INSTALL_TIME,ADDRESS_DETAIL,CARTYPE,USERNAME,USERPHONE from LM_GPS_ORDER_TEMP where APPLY_NO='" + applyNo + "'"));
|
|
JSONObject params = new JSONObject();
|
|
while (res.next()) {
|
|
params.put("AppCode", applyNo);
|
|
params.put("ProductId", getProductId(res.getInt("WIRED_PERIOD"),
|
|
res.getStringValue("WIRED_NUM"), res.getStringValue("WIRELESS_NUM"), Sqlca));
|
|
params.put("VIN", res.getString("CAR_VIN"));
|
|
params.put("DistrictCode", res.getString("ADDRESS_CODE"));
|
|
params.put("ShopName", res.getString("SHOPNAME"));
|
|
params.put("LinkMan", res.getString("CONTACT_NAME"));
|
|
params.put("LinkPhone", res.getString("CONTACT_PHONE"));
|
|
params.put("InstallTime", res.getString("INSTALL_TIME"));
|
|
params.put("InstallAdd", res.getString("ADDRESS_DETAIL"));
|
|
params.put("CarType", res.getString("CARTYPE"));
|
|
params.put("UserName", res.getString("USERNAME"));
|
|
params.put("UserPhone", res.getString("USERPHONE"));
|
|
}
|
|
res.close();
|
|
return params.toString();
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取产品配置(中瑞)
|
|
*
|
|
* @param period 设备年限
|
|
* @param wireNum 有线设备数量
|
|
* @param wirelessNum 无线设备数量
|
|
* @return
|
|
*/
|
|
private static String getProductId(Integer period, String wireNum, String wirelessNum, Transaction Sqlca) throws Exception {
|
|
SqlObject sqlObject = new SqlObject("select gps_product_id from gps_product_info where year=:year and wire_num = :wireNum and wireless_num =:wirelessNum")
|
|
.setParameter("year", period).setParameter("wireNum", wireNum).setParameter("wirelessNum", wirelessNum);
|
|
String productId = Sqlca.getString(sqlObject);
|
|
if (productId == null)
|
|
throw new BusinessException("中瑞gps产品{年限:[" + period + "]有线数量:[" + wireNum + "]无线数量:[" + wirelessNum + "]}配置不存在!");
|
|
return productId;
|
|
}
|
|
|
|
/**
|
|
* 中瑞--车架号查询工单请求参数
|
|
*
|
|
* @param applyNo
|
|
* @return
|
|
*/
|
|
public static boolean zrQueryToVinDataPersistence(String data, String vin, Transaction Sqlca) throws Exception {
|
|
JSONObject job = JSONObject.fromObject(data);
|
|
boolean startUsing = job.getBoolean("Success");
|
|
if (!startUsing) {
|
|
System.err.println("********************AllMessages****************");
|
|
System.err.println(job.getString("AllMessages"));
|
|
System.err.println("********************AllMessages****************");
|
|
return false;
|
|
}
|
|
//有GPS终端设备运行异常
|
|
if (!job.getJSONObject("Data").getBoolean("allnormal")) {
|
|
startUsing = false;
|
|
}
|
|
JSONArray dataArr = job.getJSONObject("Data").getJSONArray("postions");
|
|
Sqlca.executeSQL("delete from lm_gps_location where car_vin = '" + vin + "'");
|
|
StringBuilder sb = new StringBuilder("insert into lm_gps_location (ID,APPLY_NO,MODEL,RUN_STATUS,IMEI,CAR_VIN,GPS_TIME,LNG,LAT,LOCATE_TYPE,INPUTTIME) values ");
|
|
String insertVal = null;
|
|
for (int i = 0; i < dataArr.size(); i++) {
|
|
job = dataArr.getJSONObject(i);
|
|
if (i > 0) {
|
|
sb.append(",");
|
|
}
|
|
insertVal = "replace(uuid(),'-',''),'" + job.getString("appcode") + "','" + job.getString("flag") + "','" + job.getString("sbcstatus") + "'"
|
|
+ ",'" + job.getString("imei") + "','" + job.getString("vin") + "','" + job.getString("locationTime") + "'"
|
|
+ ",'" + job.getString("lng") + "','" + job.getString("lat") + "','" + job.getString("LocateMode") + "',date_format(now(),'%Y/%m/%d %H:%i:%s')";
|
|
sb.append("(").append(insertVal).append(")");
|
|
}
|
|
if (insertVal != null) Sqlca.executeSQL(sb.toString());
|
|
if (startUsing)
|
|
Sqlca.executeSQL("update LM_GPS_ORDER_TEMP set RESULT='0',STATUS='3',MESSAGE='查询成功' where CAR_VIN='" + vin + "'");
|
|
return startUsing;
|
|
}
|
|
|
|
/**
|
|
* 调用日志
|
|
*
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public static void callRecord(Map<String, String> params) throws Exception {
|
|
JBOTransaction tx = null;
|
|
try {
|
|
tx = JBOFactory.createJBOTransaction();
|
|
Transaction Sqlca = Transaction.createTransaction(tx);
|
|
Sqlca.executeSQL(" insert into lm_gps_log values(replace(uuid(),\"-\",\"\"),'" + params.get("UPLOAD_PARAMETER") + "','" + params.get("RETURN_PARAMETER") + "',DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'" + params.get("CALL_USERID") + "','" + params.get("FLOWUNID") + "','" + params.get("PROJECT_ID") + "','" + params.get("URL") + "','" + params.get("CALL_PURPOSE") + "','" + params.get("CALL_STATUS") + "')");
|
|
} finally {
|
|
if (tx != null) tx.commit();
|
|
}
|
|
}
|
|
}
|