|
@@ -1,7 +1,10 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
import com.google.gson.internal.$Gson$Preconditions;
|
|
|
+import com.openapi.sdk.service.DataExchangeService;
|
|
|
import com.yh.saas.common.support.util.IdGenerator;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.*;
|
|
@@ -14,9 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -44,7 +50,10 @@ public class CarrierInfoServiceImpl extends ServiceImpl<CarrierInfoMapper, HyCar
|
|
|
private IHyCargoOwnerCapitalInfoService hyCargoOwnerCapitalInfoService;
|
|
|
@Autowired
|
|
|
private IHyFreightSettlementInfoService hyFreightSettlementInfoService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IDriverCarInfoService driverCarInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IHyTokenService hyToken;
|
|
|
|
|
|
/**
|
|
|
* 查看装车信息
|
|
@@ -67,7 +76,7 @@ public class CarrierInfoServiceImpl extends ServiceImpl<CarrierInfoMapper, HyCar
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public String loadingAdd(HyCarrierInfo hyCarrierInfo) {
|
|
|
+ public String loadingAdd(HyCarrierInfo hyCarrierInfo) throws Exception {
|
|
|
HyCarrierInfo hyCarrierInfo1 = this.selectById(hyCarrierInfo.getId());
|
|
|
if (hyCarrierInfo != null) {
|
|
|
//判断暂存提交(前端传参1暂存3提交)
|
|
@@ -75,6 +84,54 @@ public class CarrierInfoServiceImpl extends ServiceImpl<CarrierInfoMapper, HyCar
|
|
|
hyCarrierInfo.setStatus(StatusEnum.TEMPORARILY_STORED.getName());
|
|
|
hyCarrierInfo.setStatusFlag(StatusEnum.TEMPORARILY_STORED.getFlag());
|
|
|
} else {
|
|
|
+ /****************************判断发货地和车辆位置开始************************************/
|
|
|
+ HyToken token = hyToken.selectOne(new EntityWrapper<HyToken>()
|
|
|
+ .eq("delete_flag", 0));
|
|
|
+ if (token == null) {
|
|
|
+ token = login();
|
|
|
+ }
|
|
|
+ //查询车辆信息
|
|
|
+ HyDriverCarInfo hyDriverCarInfo = driverCarInfoService.selectOne(new EntityWrapper<HyDriverCarInfo>().eq("car_number", hyCarrierInfo1.getCarNo())
|
|
|
+ .eq("delete_flag", "0"));
|
|
|
+ Map<String, String> map = new HashMap<String, String>(4);
|
|
|
+ map.put("token", token.getToken());
|
|
|
+ map.put("cid", "871a05fd-a098-49af-9760-27ce9ecf61e3");
|
|
|
+ map.put("srt", "762ea319-5f05-4810-aa28-5f92c99485ae");
|
|
|
+ //车牌颜色
|
|
|
+ String color = "2";
|
|
|
+ if ("黄色".equals(hyDriverCarInfo.getCarNumberColour())) {
|
|
|
+ color = "2";
|
|
|
+ } else {
|
|
|
+ color = "1";
|
|
|
+ }
|
|
|
+ map.put("vnos", hyCarrierInfo.getCarNo()+"_"+color);
|
|
|
+ String url = "https://zhiyunopenapi.95155.com/save/apis/transTimeManageV2";
|
|
|
+ // 设置 http 读写超时
|
|
|
+ DataExchangeService des = new DataExchangeService(5000, 8000);
|
|
|
+ System.out.println("请求地址:" + url);
|
|
|
+ // 通过 https 方式调用,此方法内部会使用私钥生成签名参数 sign,私钥不会发送
|
|
|
+ String res = des.postHttps(url, map);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("status").toString().equals("1001")) {
|
|
|
+ JSONObject jsonData = jsonObject.getJSONObject("result");
|
|
|
+ JSONObject jsonArray = jsonData.getJSONObject("firstVcl");
|
|
|
+ BigDecimal lonResult = jsonArray.getBigDecimal("lon");
|
|
|
+ Double lon = lonResult.doubleValue() / 600000;
|
|
|
+ BigDecimal latResult = jsonArray.getBigDecimal("lat");
|
|
|
+ Double lat = latResult.doubleValue() / 600000;
|
|
|
+ //发货地经纬度
|
|
|
+ BigDecimal lonb = new BigDecimal(hyCarrierInfo.getLoadingLongitude());
|
|
|
+ BigDecimal latb = new BigDecimal(hyCarrierInfo.getLoadingLatitude());
|
|
|
+ Double lon1 = lonb.doubleValue() / 600000;
|
|
|
+ Double lat1 = latb.doubleValue() / 600000;
|
|
|
+ // 距离
|
|
|
+ double s = GetDistance(lon,lat,lon1,lat1);
|
|
|
+ if(s>3000){
|
|
|
+ throw new ArithmeticException("请检查北斗导航可以正常使用!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /****************************判断发货地和车辆位置结束************************************/
|
|
|
+
|
|
|
hyCarrierInfo.setStatus(StatusEnum.SUBMITTED.getName());
|
|
|
hyCarrierInfo.setStatusFlag(StatusEnum.SUBMITTED.getFlag());
|
|
|
//司机确认装车后,订单状态改为待货主确认装车
|
|
@@ -105,6 +162,77 @@ public class CarrierInfoServiceImpl extends ServiceImpl<CarrierInfoMapper, HyCar
|
|
|
return "OK";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认地球半径
|
|
|
+ */
|
|
|
+ private static double EARTH_RADIUS = 6371000;//赤道半径(单位m)
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转化为弧度(rad)
|
|
|
+ * */
|
|
|
+ private static double rad(double d)
|
|
|
+ {
|
|
|
+ return d * Math.PI / 180.0;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @param lon1 第一点的精度
|
|
|
+ * @param lat1 第一点的纬度
|
|
|
+ * @param lon2 第二点的精度
|
|
|
+ * @param lat2 第二点的纬度
|
|
|
+ * @return 返回的距离,单位m
|
|
|
+ * */
|
|
|
+ public static double GetDistance(double lon1,double lat1,double lon2, double lat2) {
|
|
|
+ double radLat1 = rad(lat1);
|
|
|
+ double radLat2 = rad(lat2);
|
|
|
+ double a = radLat1 - radLat2;
|
|
|
+ double b = rad(lon1) - rad(lon2);
|
|
|
+ double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
|
|
|
+ s = s * EARTH_RADIUS;
|
|
|
+ s = Math.round(s * 10000) / 10000;
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public HyToken login() {
|
|
|
+ try {
|
|
|
+ Map<String, String> map = new HashMap<String, String>(4);
|
|
|
+ map.put("user", "ec841c89-4550-4dae-a377-0bda27185932");
|
|
|
+ map.put("pwd", "z6ZJcF32T28EF9Tkn8923uDT42609w");
|
|
|
+ map.put("srt", "762ea319-5f05-4810-aa28-5f92c99485ae");
|
|
|
+ map.put("cid", "871a05fd-a098-49af-9760-27ce9ecf61e3");
|
|
|
+ String url = "https://zhiyunopenapi.95155.com/save/apis/login";
|
|
|
+ // 设置 http 读写超时
|
|
|
+ DataExchangeService des = new DataExchangeService(5000, 8000);
|
|
|
+ System.out.println("请求地址:" + url);
|
|
|
+ // 通过 https 方式调用,此方法内部会使用私钥生成签名参数 sign,私钥不会发送
|
|
|
+ String res = des.postHttps(url, map);
|
|
|
+ res = res.substring(1, res.length() - 1);
|
|
|
+ String[] strs = res.split(",");
|
|
|
+ Map<String, String> map1 = new HashMap<String, String>();
|
|
|
+ for (String string : strs) {
|
|
|
+ String key = string.split(":")[0];
|
|
|
+ String value = string.split(":")[1];
|
|
|
+ // 去掉头部空格
|
|
|
+ String key1 = key.trim().replaceAll("\"", "");
|
|
|
+ String value1 = value.trim().replaceAll("\"", "");
|
|
|
+ map1.put(key1, value1);
|
|
|
+ }
|
|
|
+ hyToken.delete(new EntityWrapper<HyToken>().eq("delete_flag", "0"));
|
|
|
+ HyToken token = new HyToken();
|
|
|
+ token.setId(IdGenerator.generateUUID());
|
|
|
+ token.setToken(map1.get("\"result\"").replaceAll("\"", ""));
|
|
|
+ hyToken.insert(token);
|
|
|
+ System.out.println("返回:" + res);
|
|
|
+ return token;
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("e:" + e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 确认卸车
|
|
|
*
|