|
|
@ -2,21 +2,49 @@ package com.ccsens.logistics.service; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.logistics.bean.dto.CarIdentificationDto; |
|
|
|
import com.ccsens.logistics.Util.Constant; |
|
|
|
import com.ccsens.logistics.bean.dto.CarRecordDto; |
|
|
|
import com.ccsens.logistics.bean.po.LogisticsCarRecord; |
|
|
|
import com.ccsens.logistics.persist.dao.LogisticsCarRecordDao; |
|
|
|
import com.ccsens.util.Base64FileUtil; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.PropUtil; |
|
|
|
import com.ccsens.util.RestTemplateUtil; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
import org.apache.http.NameValuePair; |
|
|
|
import org.apache.http.StatusLine; |
|
|
|
import org.apache.http.client.entity.UrlEncodedFormEntity; |
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
|
|
import org.apache.http.message.BasicNameValuePair; |
|
|
|
import org.apache.http.protocol.HTTP; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.Map; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author 马 |
|
|
@ -89,5 +117,165 @@ public class CarIdentificationService implements ICarIdentificationService{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 请求智慧云停车管理系统接口 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void requestCarPort() throws IOException { |
|
|
|
|
|
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build(); |
|
|
|
//调用登录接口,获取token
|
|
|
|
String token = getToken(httpClient); |
|
|
|
|
|
|
|
//获取车辆类型
|
|
|
|
Map<String, String> carType = getCarType(httpClient, token); |
|
|
|
|
|
|
|
//查询停车记录
|
|
|
|
List<CarRecordDto.AddCarRecord> carData = getCarData(httpClient, token, carType); |
|
|
|
carRecordDao.insertRecordList(carData); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
*获取智慧云停车管理系统的token |
|
|
|
* @return token |
|
|
|
*/ |
|
|
|
private String getToken(CloseableHttpClient httpClient){ |
|
|
|
try { |
|
|
|
String loginUrl = "http://120.78.14.85:8081/cloud/user/dologin"; |
|
|
|
HttpPost httPost = new HttpPost(loginUrl); |
|
|
|
httPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); |
|
|
|
|
|
|
|
List<NameValuePair> param = new ArrayList<NameValuePair>(); |
|
|
|
param.add(new BasicNameValuePair("username", "1311786")); |
|
|
|
param.add(new BasicNameValuePair("password", "eir/kjbPIHGGrGamcZVlDg==")); |
|
|
|
httPost.setEntity(new UrlEncodedFormEntity(param)); |
|
|
|
|
|
|
|
CloseableHttpResponse execute = httpClient.execute(httPost); |
|
|
|
HttpEntity entity = execute.getEntity(); |
|
|
|
String result = EntityUtils.toString(entity); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
|
JSONObject user = jsonObject.getJSONObject("user"); |
|
|
|
String token = user.getString("token"); |
|
|
|
return token; |
|
|
|
}catch (Exception e){ |
|
|
|
log.info("获取停车系统token失败",e); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
*获取智慧云停车管理系统的车辆类型 |
|
|
|
* @return 车辆类型carType(value_no)为key value_name为value |
|
|
|
*/ |
|
|
|
private Map<String,String> getCarType(CloseableHttpClient httpClient,String token){ |
|
|
|
try { |
|
|
|
Map<String,String> carTypeMap = new HashMap<>(); |
|
|
|
String queryType = "http://120.78.14.85:8081/cloud/getdata/getCardType?token="+token+"&comid=121964&showTempCar=showTempCar"; |
|
|
|
HttpGet httpGet = new HttpGet(queryType); |
|
|
|
httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); |
|
|
|
CloseableHttpResponse carType = httpClient.execute(httpGet); |
|
|
|
String typeResult = EntityUtils.toString(carType.getEntity()); |
|
|
|
JSONArray jsonArray = JSONObject.parseArray(typeResult); |
|
|
|
|
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
JSONObject jsonObject1 = jsonArray.getJSONObject(i); |
|
|
|
String value_no = jsonObject1.getString("value_no"); |
|
|
|
String value_name = jsonObject1.getString("value_name"); |
|
|
|
carTypeMap.put(value_no,value_name); |
|
|
|
} |
|
|
|
|
|
|
|
return carTypeMap; |
|
|
|
}catch (Exception e){ |
|
|
|
log.info("获取智慧云停车管理系统的车辆类型失败",e); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
*获取智慧云停车管理系统的车辆出入数据 |
|
|
|
* @return 车辆类型carType(value_no)为key value_name为value |
|
|
|
*/ |
|
|
|
private List<CarRecordDto.AddCarRecord> getCarData(CloseableHttpClient httpClient, String token,Map<String,String> carType){ |
|
|
|
|
|
|
|
List<CarRecordDto.AddCarRecord> carRecords = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
Date end = new Date(System.currentTimeMillis()); |
|
|
|
Date start = new Date(System.currentTimeMillis()-600000); |
|
|
|
String endTime = simpleDateFormat.format(end); |
|
|
|
String startTime = simpleDateFormat.format(start); |
|
|
|
String timeParam = startTime+"至"+endTime; |
|
|
|
|
|
|
|
try { |
|
|
|
String queryRecord = "http://120.78.14.85:8081/cloud/OrderManagePark/query"; |
|
|
|
HttpPost httPostRecord = new HttpPost(queryRecord); |
|
|
|
httPostRecord.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); |
|
|
|
List<NameValuePair> paramRecord = new ArrayList<NameValuePair>(); |
|
|
|
paramRecord.add(new BasicNameValuePair("token", token)); |
|
|
|
paramRecord.add(new BasicNameValuePair("comid", "121964")); |
|
|
|
paramRecord.add(new BasicNameValuePair("groupid", "120353")); |
|
|
|
paramRecord.add(new BasicNameValuePair("date", timeParam)); |
|
|
|
|
|
|
|
httPostRecord.setEntity(new UrlEncodedFormEntity(paramRecord, StandardCharsets.UTF_8)); |
|
|
|
|
|
|
|
CloseableHttpResponse executeRecord = httpClient.execute(httPostRecord); |
|
|
|
|
|
|
|
HttpEntity record = executeRecord.getEntity(); |
|
|
|
String resultRecord = EntityUtils.toString(record); |
|
|
|
JSONObject jsonObjectRecord = JSONObject.parseObject(resultRecord); |
|
|
|
JSONArray rows = jsonObjectRecord.getJSONArray("rows"); |
|
|
|
for (int i = 0; i < rows.size(); i++) { |
|
|
|
JSONObject row = rows.getJSONObject(i); |
|
|
|
CarRecordDto.AddCarRecord inCar = new CarRecordDto.AddCarRecord(); |
|
|
|
CarRecordDto.AddCarRecord outCar = new CarRecordDto.AddCarRecord(); |
|
|
|
//添加进的车
|
|
|
|
inCar.setRecordId(snowflake.nextId()); |
|
|
|
inCar.setInOut((byte)0); |
|
|
|
inCar.setCarType(carType.get(row.getString("cartype"))); |
|
|
|
inCar.setLicensePlate(row.getString("vehicle_no")); |
|
|
|
inCar.setRecordTime(row.getLong("intime")*1000); |
|
|
|
//添加出的车
|
|
|
|
outCar.setRecordId(snowflake.nextId()); |
|
|
|
outCar.setInOut((byte)1); |
|
|
|
outCar.setCarType(carType.get(row.getString("cartype"))); |
|
|
|
outCar.setLicensePlate(row.getString("vehicle_no")); |
|
|
|
outCar.setRecordTime(row.getLong("outtime")*1000); |
|
|
|
|
|
|
|
switch (carType.get(row.getString("cartype"))){ |
|
|
|
|
|
|
|
case Constant.FREE_CAR_B: |
|
|
|
case Constant.TEMPORARY_CAR_D: |
|
|
|
case Constant.MONTHLY_CAR_B: |
|
|
|
case Constant.MONTHLY_CAR_C: |
|
|
|
inCar.setCarWeight(Constant.CAR_WEIGHT_TWENTY); |
|
|
|
outCar.setCarWeight(Constant.CAR_WEIGHT_TWENTY); |
|
|
|
break; |
|
|
|
|
|
|
|
case Constant.TEMPORARY_CAR_B: |
|
|
|
case Constant.TEMPORARY_CAR_C: |
|
|
|
case Constant.MONTHLY_CAR_A: |
|
|
|
inCar.setCarWeight(Constant.CAR_WEIGHT_ONE); |
|
|
|
outCar.setCarWeight(Constant.CAR_WEIGHT_ONE); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
inCar.setCarWeight(Constant.CAR_WEIGHT_ZERO); |
|
|
|
outCar.setCarWeight(Constant.CAR_WEIGHT_ZERO); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
carRecords.add(inCar); |
|
|
|
carRecords.add(outCar); |
|
|
|
} |
|
|
|
return carRecords; |
|
|
|
}catch (Exception e){ |
|
|
|
log.info("获取智慧云停车管理系统的车辆类型失败",e); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|