From 2ee3c12dc639b22824dab79c01ac0b6812a06954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E7=9D=BF?= Date: Sun, 27 Oct 2019 17:21:43 +0800 Subject: [PATCH 1/6] =?UTF-8?q?#hotfix/=E5=9C=A8=E9=80=94=E8=BD=A8?= =?UTF-8?q?=E8=BF=B9=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-pro.yml | 1 + .../src/main/resources/application-uat.yml | 3 +- .../unlcn/ils/kas/test/BaiDuMapUtilTest.java | 96 ++++++----- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-pro.yml | 1 + .../src/main/resources/application-uat.yml | 1 + .../BaiDuMap/config/BaiDuMapGeoConfig.java | 10 ++ .../BaiDuMap/util/BaiDuMapGeocodeUtil.java | 71 +++++++- .../service/order/impl/ImportServiceImpl.java | 159 +++++++++--------- .../order/impl/SharesOrderServiceImpl.java | 1 - 11 files changed, 212 insertions(+), 133 deletions(-) diff --git a/kas-admin/src/main/resources/application-dev.yml b/kas-admin/src/main/resources/application-dev.yml index 3c07768..8acfe99 100644 --- a/kas-admin/src/main/resources/application-dev.yml +++ b/kas-admin/src/main/resources/application-dev.yml @@ -75,6 +75,7 @@ baiduMap: # 地址检索 geocoderApi: addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s" + gpsToGeoPointUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s" gpsToAddressUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&batch=%s&pois=%d&ak=%s" geoconvUrl: "https://api.map.baidu.com/geoconv/v1/?coords=%s&from=%d&to=%d&ak=%s" routeApi: diff --git a/kas-admin/src/main/resources/application-pro.yml b/kas-admin/src/main/resources/application-pro.yml index 93e0154..575a8c2 100644 --- a/kas-admin/src/main/resources/application-pro.yml +++ b/kas-admin/src/main/resources/application-pro.yml @@ -77,6 +77,7 @@ baiduMap: # 地址检索 geocoderApi: addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s" + gpsToGeoPointUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s" gpsToAddressUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&batch=%s&pois=%d&ak=%s" geoconvUrl: "https://api.map.baidu.com/geoconv/v1/?coords=%s&from=%d&to=%d&ak=%s" routeApi: diff --git a/kas-admin/src/main/resources/application-uat.yml b/kas-admin/src/main/resources/application-uat.yml index 66126db..42c3bd7 100644 --- a/kas-admin/src/main/resources/application-uat.yml +++ b/kas-admin/src/main/resources/application-uat.yml @@ -71,7 +71,8 @@ baiduMap: apiKey: Sfp9cEKmk0p7BzUl1NwQPCIgYrh1m83L # 地址检索 geocoderApi: - addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s" + addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&coordtype=bd09ll&ak=%s" + gpsToGeoPointUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s" gpsToAddressUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&batch=%s&pois=%d&ak=%s" geoconvUrl: "https://api.map.baidu.com/geoconv/v1/?coords=%s&from=%d&to=%d&ak=%s" routeApi: diff --git a/kas-admin/src/test/java/com/unlcn/ils/kas/test/BaiDuMapUtilTest.java b/kas-admin/src/test/java/com/unlcn/ils/kas/test/BaiDuMapUtilTest.java index 7fd205c..f9a750b 100644 --- a/kas-admin/src/test/java/com/unlcn/ils/kas/test/BaiDuMapUtilTest.java +++ b/kas-admin/src/test/java/com/unlcn/ils/kas/test/BaiDuMapUtilTest.java @@ -1,6 +1,7 @@ package com.unlcn.ils.kas.test; -import com.google.common.collect.Maps;import com.unlcn.ils.kas.WebApplication; +import com.google.common.collect.Maps; +import com.unlcn.ils.kas.WebApplication; import com.unlcn.ils.kas.service.map.BaiDuMap.util.BaiDuMapGeocodeUtil; import com.unlcn.ils.kas.service.map.BaiDuMap.util.BaiDuMapRouteUtil; import org.apache.commons.collections4.CollectionUtils; @@ -9,28 +10,36 @@ import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.math.BigDecimal; import java.util.List; import java.util.Map; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes= WebApplication.class) +@SpringBootTest(classes = WebApplication.class) public class BaiDuMapUtilTest { - @Test - public void testaddressToGPS(){ - Map map = BaiDuMapGeocodeUtil.addressToGPS("云南省临沧市临翔区忙畔街道文伟村缅宁大道与214国道交叉口东侧,南亚汽车主题园9号地块"); - System.out.println(map.get("lng")); - System.out.println(map.get("lat")); + public void testaddressToGPS() { + Map map = BaiDuMapGeocodeUtil.addressToGEOPoint("江西上饶市信州区五三延伸段国际公馆"); + System.out.println(new BigDecimal(map.get("lng"))); + System.out.println(new BigDecimal(map.get("lat"))); + System.out.println(map.get("province")); + System.out.println(map.get("city")); + System.out.println(map.get("district")); assertThat(map).isNotNull(); - assertThat(map.get("lng")).isNotNull(); assertThat(map.get("lat")).isNotNull(); + assertThat(map.get("lng")).isNotNull(); + assertThat(map.get("province")).isNotNull(); + assertThat(map.get("city")).isNotNull(); + assertThat(map.get("district")).isNotNull(); } + @Test - public void testaddressToGPSLong(){ - Map map = BaiDuMapGeocodeUtil.addressToGPS("云南省,临沧市,云南省临沧市临翔区忙畔街道文伟村缅宁大道与214国道交叉口东侧,南亚汽车主题园9号地块"); + public void testaddressToGPSLong() { + Map map = BaiDuMapGeocodeUtil + .addressToGPS("云南省,临沧市,云南省临沧市临翔区忙畔街道文伟村缅宁大道与214国道交叉口东侧,南亚汽车主题园9号地块"); System.out.println(map.get("lng")); System.out.println(map.get("lat")); assertThat(map).isNotNull(); @@ -39,28 +48,28 @@ public class BaiDuMapUtilTest { } @Test - public void testGPSToAddress(){ - //String strAddress = BaiDuMapGeocodeUtil.GPSToAddress("39.934,116.329",0); - String strAddress = BaiDuMapGeocodeUtil.GPSToAddress("28.543300,115.879096",0); + public void testGPSToAddress() { + // String strAddress = BaiDuMapGeocodeUtil.GPSToAddress("39.934,116.329",0); + String strAddress = BaiDuMapGeocodeUtil.GPSToAddress("28.543300,115.879096", 0); assertThat(strAddress).isNotEmpty(); System.out.println(strAddress); } @Test - public void testGetDistanceBytactics(){ - double distance = BaiDuMapRouteUtil.getDistance("北京市海淀区上地十街10号","北京市朝阳区朝阳大悦城","13"); -// double distance = BaiDuMapRouteUtil.getDistance("德宏傣族景颇族自治州芒市芒西线西33米(普通路)","云南省红河州蒙自市红河工业园区(新亚太物流公司)","13"); + public void testGetDistanceBytactics() { + double distance = BaiDuMapRouteUtil.getDistance("北京市海淀区上地十街10号", "北京市朝阳区朝阳大悦城", "13"); + // double distance = + // BaiDuMapRouteUtil.getDistance("德宏傣族景颇族自治州芒市芒西线西33米(普通路)","云南省红河州蒙自市红河工业园区(新亚太物流公司)","13"); System.out.println(distance); assertThat(distance).isNotNull(); assertThat(distance).isNotZero(); } - @Test - public void testGeoConv(){ -// String cords = "114.21892734521,29.575429778924"; + public void testGeoConv() { + // String cords = "114.21892734521,29.575429778924"; String cords = "113.93041,22.53332"; - List> lists = BaiDuMapGeocodeUtil.geoConv(cords,1,5); + List> lists = BaiDuMapGeocodeUtil.geoConv(cords, 1, 5); assertThat(lists).isNotNull(); assertThat(lists.get(0)).isNotNull(); @@ -76,40 +85,39 @@ public class BaiDuMapUtilTest { } @Test - public void testGetDistance(){ - double distance = BaiDuMapRouteUtil.getDistance("北京市海淀区上地十街10号","北京市朝阳区朝阳大悦城"); + public void testGetDistance() { + double distance = BaiDuMapRouteUtil.getDistance("北京市海淀区上地十街10号", "北京市朝阳区朝阳大悦城"); System.out.println(distance); assertThat(distance).isNotNull(); assertThat(distance).isNotZero(); } @Test - public void testGetDistanceGeo2Address(){ - String str="江西省南昌市南昌县 327"; + public void testGetDistanceGeo2Address() { + String str = "江西省南昌市南昌县 327"; int length = str.getBytes().length; - System.out.println("字节数:"+length); - Map geoNanChange = BaiDuMapGeocodeUtil.addressToGPS("江西省南昌市南昌县鑫维大道与富山三路交界处"); - double distance = BaiDuMapRouteUtil.getDistance(geoNanChange,"北京市朝阳区朝阳大悦城"); + System.out.println("字节数:" + length); + Map geoNanChange = BaiDuMapGeocodeUtil.addressToGPS("江西省南昌市南昌县鑫维大道与富山三路交界处"); + double distance = BaiDuMapRouteUtil.getDistance(geoNanChange, "北京市朝阳区朝阳大悦城"); System.out.println(distance); assertThat(distance).isNotNull(); assertThat(distance).isNotZero(); } - @Test - public void testGetDistanceMap(){ - Map mapOrgrin = Maps.newHashMap(); - //wgs84坐标转为百度坐标 - mapOrgrin.put("lat",28.543300); - mapOrgrin.put("lng",115.879096); + public void testGetDistanceMap() { + Map mapOrgrin = Maps.newHashMap(); + // wgs84坐标转为百度坐标 + mapOrgrin.put("lat", 28.543300); + mapOrgrin.put("lng", 115.879096); String cords = mapOrgrin.get("lng") + "," + mapOrgrin.get("lat"); - List> lists = BaiDuMapGeocodeUtil.geoConv(cords,1,5); + List> lists = BaiDuMapGeocodeUtil.geoConv(cords, 1, 5); if (!CollectionUtils.isEmpty(lists)) { Map mapGeo = lists.get(0); String destination = "江西抚州江西省抚州市临川区文昌大道775号 铂金水岸对面"; - Map mapDestinations = BaiDuMapGeocodeUtil.addressToGPS(destination); - double distance = BaiDuMapRouteUtil.getDistance(mapGeo,mapDestinations); + Map mapDestinations = BaiDuMapGeocodeUtil.addressToGPS(destination); + double distance = BaiDuMapRouteUtil.getDistance(mapGeo, mapDestinations); System.out.println(distance); assertThat(distance).isNotNull(); assertThat(distance).isNotZero(); @@ -117,19 +125,19 @@ public class BaiDuMapUtilTest { } @Test - public void testChangeWGS84GPSToAddress(){ - //String strAddress = BaiDuMapGeocodeUtil.GPSToAddress("39.934,116.329",0); - Map mapOrgrin = Maps.newHashMap(); - //wgs84坐标转为百度坐标 - mapOrgrin.put("lat",28.543300); - mapOrgrin.put("lng",115.879096); + public void testChangeWGS84GPSToAddress() { + // String strAddress = BaiDuMapGeocodeUtil.GPSToAddress("39.934,116.329",0); + Map mapOrgrin = Maps.newHashMap(); + // wgs84坐标转为百度坐标 + mapOrgrin.put("lat", 28.543300); + mapOrgrin.put("lng", 115.879096); String cords = mapOrgrin.get("lng") + "," + mapOrgrin.get("lat"); - List> lists = BaiDuMapGeocodeUtil.geoConv(cords,1,5); + List> lists = BaiDuMapGeocodeUtil.geoConv(cords, 1, 5); if (!CollectionUtils.isEmpty(lists)) { Map mapGeo = lists.get(0); String changecord = mapGeo.get("lat") + "," + mapGeo.get("lng"); - String strAddress = BaiDuMapGeocodeUtil.GPSToAddress(changecord,0); + String strAddress = BaiDuMapGeocodeUtil.GPSToAddress(changecord, 0); assertThat(strAddress).isNotEmpty(); System.out.println(strAddress); } diff --git a/kas-api/src/main/resources/application-dev.yml b/kas-api/src/main/resources/application-dev.yml index fa981eb..f020f6a 100644 --- a/kas-api/src/main/resources/application-dev.yml +++ b/kas-api/src/main/resources/application-dev.yml @@ -79,6 +79,7 @@ baiduMap: locationIPUrl: "https://api.map.baidu.com/location/ip?ip=%s&ak=%s&coor=bd09ll" geocoderApi: addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s" + gpsToGeoPointUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s" gpsToAddressUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&pois=%d&ak=%s" geoconvUrl: "https://api.map.baidu.com/geoconv/v1/?coords=%s&from=%d&to=%d&ak=%s" routeApi: diff --git a/kas-api/src/main/resources/application-pro.yml b/kas-api/src/main/resources/application-pro.yml index 9b733ff..457e653 100644 --- a/kas-api/src/main/resources/application-pro.yml +++ b/kas-api/src/main/resources/application-pro.yml @@ -80,6 +80,7 @@ baiduMap: locationIPUrl: "https://api.map.baidu.com/location/ip?ip=%s&ak=%s&coor=bd09ll" geocoderApi: addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s" + gpsToGeoPointUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s" gpsToAddressUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&pois=%d&ak=%s" geoconvUrl: "https://api.map.baidu.com/geoconv/v1/?coords=%s&from=%d&to=%d&ak=%s" routeApi: diff --git a/kas-api/src/main/resources/application-uat.yml b/kas-api/src/main/resources/application-uat.yml index 61a0cd8..12ee7da 100644 --- a/kas-api/src/main/resources/application-uat.yml +++ b/kas-api/src/main/resources/application-uat.yml @@ -79,6 +79,7 @@ baiduMap: locationIPUrl: "https://api.map.baidu.com/location/ip?ip=%s&ak=%s&coor=bd09ll" geocoderApi: addressToGpsUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s" + gpsToGeoPointUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s" gpsToAddressUrl: "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&pois=%d&ak=%s" geoconvUrl: "https://api.map.baidu.com/geoconv/v1/?coords=%s&from=%d&to=%d&ak=%s" routeApi: diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/config/BaiDuMapGeoConfig.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/config/BaiDuMapGeoConfig.java index c24ecc1..b8b1ff9 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/config/BaiDuMapGeoConfig.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/config/BaiDuMapGeoConfig.java @@ -11,10 +11,20 @@ public class BaiDuMapGeoConfig { private String addressToGpsUrl; + private String gpsToGeoPointUrl; + public String getGpsToAddressUrl() { return gpsToAddressUrl; } + public String getGpsToGeoPointUrl() { + return gpsToGeoPointUrl; + } + + public void setGpsToGeoPointUrl(String gpsToGeoPointUrl) { + this.gpsToGeoPointUrl = gpsToGeoPointUrl; + } + public void setGpsToAddressUrl(String gpsToAddressUrl) { this.gpsToAddressUrl = gpsToAddressUrl; } diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/util/BaiDuMapGeocodeUtil.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/util/BaiDuMapGeocodeUtil.java index b1b9526..60e3c38 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/util/BaiDuMapGeocodeUtil.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/map/BaiDuMap/util/BaiDuMapGeocodeUtil.java @@ -13,12 +13,11 @@ import com.unlcn.ils.kas.service.util.BaseException; import com.unlcn.ils.kas.service.util.HttpClientUtil; import com.unlcn.ils.kas.service.util.enums.BaiDuMapStatusEnum; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.util.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import java.net.URLEncoder; import java.util.Date; @@ -34,6 +33,10 @@ public class BaiDuMapGeocodeUtil { // 编码格式。发送编码格式统一用UTF-8 private static String ENCODING = "UTF-8"; + // 地址字符串转GEO点 + private static String ADDRESS2GEO_URL = "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s"; + // 经纬度转GEO点 + private static String GPS2GEOPoint_URL = "https://api.map.baidu.com/geocoder/v2/?output=json&location=%s&coordtype=bd09ll&ak=%s"; // 连接超时时间 private static int socketTimeout = 10000; @@ -79,7 +82,7 @@ public class BaiDuMapGeocodeUtil { String url = baiDuMapGeoConfig.getAddressToGpsUrl(); logger.info("addressToGPSURL is ..." + url); if (StringUtils.isEmpty(url)) { - url = "https://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s"; + url = ADDRESS2GEO_URL; } url = String.format(url, addressEncode, baiDuMapCoreConfig.getApiKey()); String strReturn = HttpClientUtil.get(url, null, socketTimeout); @@ -108,6 +111,68 @@ public class BaiDuMapGeocodeUtil { return map; } + public static Map addressToGEOPoint(String address) throws BaseException { + Map map = Maps.newHashMap(); + + try { + address = address.replaceAll("null", ""); + address = address.substring(0, Math.min(address.length(), 42)); + String addressEncode = URLEncoder.encode(address, ENCODING); + logger.info("addressToGPS addressStr:{} encoded: {}", address, addressEncode); + String url = baiDuMapGeoConfig.getAddressToGpsUrl(); + logger.info("addressToGPSURL is ..." + url); + if (StringUtils.isEmpty(url)) { + url = ADDRESS2GEO_URL; + } + url = String.format(url, addressEncode, baiDuMapCoreConfig.getApiKey()); + String strReturn = HttpClientUtil.get(url, null, socketTimeout); + JSONObject jsonObject = JSON.parseObject(strReturn); + int status = jsonObject.getInteger("status"); + String msg = BaiDuMapStatusEnum.getTest(status); + if (status == 0) { + JSONObject location = jsonObject.getJSONObject("result").getJSONObject("location"); + if (!Objects.isNull(location)) { + map.put("lng", location.getString("lng")); + map.put("lat", location.getString("lat")); + } + } else { + throw new BaseException(msg); + } + if (!StringUtils.isEmpty(map)) { + url = StringUtils.isEmpty(baiDuMapGeoConfig.getGpsToGeoPointUrl()) ? GPS2GEOPoint_URL + : baiDuMapGeoConfig.getGpsToGeoPointUrl(); + url = String.format(url, map.get("lat") + "," + map.get("lng"), baiDuMapCoreConfig.getApiKey()); + strReturn = HttpClientUtil.get(url, null, socketTimeout); + jsonObject = JSON.parseObject(strReturn); + status = jsonObject.getInteger("status"); + msg = BaiDuMapStatusEnum.getTest(status); + logger.debug("GPS2GEOPoint ..." + strReturn); + if (status == 0) { + JSONObject addressComponent = jsonObject.getJSONObject("result").getJSONObject("addressComponent"); + if (!Objects.isNull(addressComponent)) { + map.put("province", addressComponent.getString("province")); + map.put("city", addressComponent.getString("city")); + map.put("district", addressComponent.getString("district")); + } + } else { + throw new BaseException(msg); + } + } else { + throw new BaseException("GPS2GEOPoint ... 解析经纬度失败"); + } + } catch (Exception e) { + logger.error("addressToGEOPoint URL error: {}", e); + BaiduException baiduException = new BaiduException(); + baiduException.setAddress(address); + baiduException.setGmtCreate(new Date()); + baiduException.setExceptionMsg(e.getMessage()); + iBaiduExceptionService.insert(baiduException); + + } + + return map; + } + /** * 逆地理编码 * diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java index 280ad16..b020d8d 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.mapper.Wrapper; import com.unlcn.ils.kas.dao.model.order.Customer; import com.unlcn.ils.kas.dao.model.order.OrderOtd; import com.unlcn.ils.kas.dao.model.order.OrderOtdDetail; +import com.unlcn.ils.kas.service.map.BaiDuMap.util.BaiDuMapGeocodeUtil; import com.unlcn.ils.kas.service.map.BaiDuMap.util.BaiDuMapRouteUtil; import com.unlcn.ils.kas.service.order.CustomerService; import com.unlcn.ils.kas.service.order.ImportService; @@ -298,8 +299,8 @@ public class ImportServiceImpl implements ImportService { // 备注说明 orderOtd.setRemarkDesc(StringUtils.isEmpty(arrayRows.getJSONObject(i).getString("备注说明")) ? null : arrayRows.getJSONObject(i).getString("备注说明").trim()); - //添加临牌号 2019-05-29 14:07:59 - orderOtd.setTempLicense(StringUtils.isEmpty(arrayRows.getJSONObject(i).getString("临牌号"))?null + // 添加临牌号 2019-05-29 14:07:59 + orderOtd.setTempLicense(StringUtils.isEmpty(arrayRows.getJSONObject(i).getString("临牌号")) ? null : arrayRows.getJSONObject(i).getString("临牌号").trim()); if (orderOtd.getDistance() == null || 0 == orderOtd.getDistance()) { @@ -410,12 +411,12 @@ public class ImportServiceImpl implements ImportService { arrayHeader.add("导入结果"); arrayHeader.add("执行信息"); int rows_successed = 0; - List saveList = new ArrayList<>(); + List errRetList = new ArrayList<>(); Map checkLastDate = new HashMap<>(); - Map groupDn = new HashMap<>(); + Map needImportDNGrouped = new HashMap<>(); // gpsMap保存需要使用百度地图api的地址 避免重复查询 - Map> addressMap = new HashMap<>(); + Map> addressMap = new HashMap<>(); // 利用map不可重复原理 筛选出 时间最大 订单加入 MAP groupDn // 当整组订单 即相同的dn 都合格情况下才进行业务逻辑处理 // 是否运达 为是的 订单加入 checkLastDate 当checkLastDate中相同dn 时间不同说明 是否运达 为是的 运抵时间小于其中一个 @@ -429,80 +430,76 @@ public class ImportServiceImpl implements ImportService { } // 当前定位时间 Date locationDate1 = formatCellValue2Date(arrayRows.getJSONObject(i).getString("定位时间").trim(), "定位时间"); - if (groupDn.containsKey(dn)) { + if (needImportDNGrouped.containsKey(dn)) { // map中保存的定位时间 - Date locationDate2 = formatCellValue2Date(groupDn.get(dn).getString("定位时间").trim(), "定位时间"); + Date locationDate2 = formatCellValue2Date(needImportDNGrouped.get(dn).getString("定位时间").trim(), + "定位时间"); if (locationDate1.after(locationDate2)) { - groupDn.put(dn, arrayRows.getJSONObject(i)); - } - if (!StringUtils.isEmpty(isReach) && isReach.equals("是")) { - checkLastDate.put(dn, arrayRows.getJSONObject(i)); + needImportDNGrouped.put(dn, arrayRows.getJSONObject(i)); } } else { - groupDn.put(dn, arrayRows.getJSONObject(i)); + needImportDNGrouped.put(dn, arrayRows.getJSONObject(i)); } - } catch (IllegalArgumentException e) { - LOGGER.error("ImportServiceImpl.importOrder ERROR Message : {} ", e); + if (!StringUtils.isEmpty(isReach) && isReach.equals("是")) { + checkLastDate.put(dn, arrayRows.getJSONObject(i)); + } + } catch (Exception e) { + LOGGER.error("ImportServiceImpl.importOnway:", e); arrayRows.getJSONObject(i).put("导入结果", "失败"); arrayRows.getJSONObject(i).put("执行信息", e.getMessage()); - saveList.add((JSONObject) arrayRows.getJSONObject(i)); - + errRetList.add((JSONObject) arrayRows.getJSONObject(i)); } - } - // 在判断checkLastDate和groupDn 相同单号的时间是否相同 - // 并且在判断checkLastDate中 定位位置 百度api解析是否成功 + + // 再判断checkLastDate和groupDn 相同单号的时间是否相同 + // 并且判断checkLastDate中 定位位置 百度api解析是否成功 // 在遍历集合的时候改变集合的size会导致错误 - List errorList = new ArrayList<>(); - for (Map.Entry entry : groupDn.entrySet()) { + + // 如果某DN的运抵行定位时间不是该DN的最大定位时间,则为致命异常,该DN所有记录不导入 + List fatalErrCanNotImportDNList = new ArrayList(); + for (Map.Entry entry : needImportDNGrouped.entrySet()) { if (checkLastDate.containsKey(entry.getKey())) { - String result1 = ""; + String errMsg = ""; try { - Map gpsMap; Boolean flag = true; Date date1 = formatCellValue2Date(entry.getValue().getString("定位时间").trim(), "定位时间"); Date date2 = formatCellValue2Date(checkLastDate.get(entry.getKey()).getString("定位时间").trim(), "定位时间"); // 检测重复位置 - gpsMap = checkAddress(entry.getValue().getString("定位位置").trim(), addressMap); + Map geoPoint = checkAddress(entry.getValue().getString("定位位置").trim(), addressMap); if (date1.getTime() != date2.getTime()) { - result1 += "此类单号是否运抵应为此订单,"; + errMsg += "此类单号是否运抵应为此订单,"; flag = false; } // 正常情况 addressToGPS百度api 返回size 为2的 map - if (gpsMap.size() != 2) { - if (StringUtils.isEmpty(result1)) { - result1 = "位置无法正常解析"; + if (StringUtils.isEmpty(geoPoint) || StringUtils.isEmpty(geoPoint.get("province"))) { + if (StringUtils.isEmpty(errMsg)) { + errMsg = "位置无法正常解析"; } else { - result1 += ",位置无法正常解析"; + errMsg += ",位置无法正常解析"; } - flag = false; } if (!flag) { - throw new IllegalArgumentException(result1); - + throw new IllegalArgumentException(errMsg); } - - } catch (IllegalArgumentException e) { - - LOGGER.error("ImportServiceImpl.importOrder ERROR Message : {} ", entry.getKey() + e.getMessage()); + } catch (Exception e) { + LOGGER.error("ImportServiceImpl.importOrder... dn:" + entry.getKey(), e); if (StringUtils.isEmpty(entry.getValue().getString("执行信息"))) { entry.getValue().put("导入结果", "失败"); entry.getValue().put("执行信息", e.getMessage()); - saveList.add((JSONObject) entry.getValue()); + errRetList.add((JSONObject) entry.getValue()); } else { - if (entry.getValue().getString("执行信息").indexOf("定位时间") == -1) { + if (entry.getValue().getString("执行信息").indexOf(e.getMessage()) == -1) { entry.getValue().put("执行信息", entry.getValue().getString("执行信息") + "," + e.getMessage()); } } - errorList.add(entry.getKey()); + fatalErrCanNotImportDNList.add(entry.getKey()); } - } } - for (String s : errorList) { - groupDn.remove(s); + for (String dn : fatalErrCanNotImportDNList) { + needImportDNGrouped.remove(dn); } // 因为数据库查询出来的数据更全所以还是使用map存 @@ -528,7 +525,7 @@ public class ImportServiceImpl implements ImportService { } String dn = arrayRows.getJSONObject(i).getString("DN").trim(); - if (groupDn.containsKey(dn)) { + if (needImportDNGrouped.containsKey(dn)) { OrderOtd orderOtd = checkOrderOtd(dn, orderOtdMap); if (ObjectUtils.isEmpty(orderOtd)) { throw new IllegalArgumentException("无此单号"); @@ -538,37 +535,39 @@ public class ImportServiceImpl implements ImportService { String orderNo = arrayRows.getJSONObject(i).getString("DN").trim(); String location = arrayRows.getJSONObject(i).getString("定位位置").trim(); String license = arrayRows.getJSONObject(i).getString("承运车牌").trim(); - List> locationMap = addressResolution(location); - Date lastDate = formatCellValue2Date(groupDn.get(dn).getString("定位时间").trim(), "定位时间"); // 系统订单号 orderOtdDetail.setSysOrderNo(orderNo); // 定位时间 orderOtdDetail.setTrackTime(locationTime); - // 定位位置 - if (!CollectionUtils.isEmpty(locationMap)) { - orderOtdDetail.setProvince(locationMap.get(0).get("province")); - orderOtdDetail.setCity(locationMap.get(0).get("city")); - orderOtdDetail.setArea(locationMap.get(0).get("area")); + // 地址验证 + Map geoPoint = checkAddress(location, addressMap); + // 正常情况百度api解析成功返回 + if (geoPoint.size() >= 4) { + orderOtdDetail.setLatitude(new BigDecimal(geoPoint.get("lat"))); + orderOtdDetail.setLongitude(new BigDecimal(geoPoint.get("lng"))); + orderOtdDetail.setProvince(geoPoint.get("province")); + orderOtdDetail.setCity(geoPoint.get("city")); + orderOtdDetail.setArea(geoPoint.get("district")); orderOtdDetail.setAddress(location); - } - - // 检测重复位置 - Map addressToGPS = checkAddress(location, addressMap); - // 正常情况百度api解析成功返回map.size=2 - if (addressToGPS.size() == 2) { - orderOtdDetail.setLatitude(BigDecimal.valueOf(addressToGPS.get("lat"))); - orderOtdDetail.setLongitude(BigDecimal.valueOf(addressToGPS.get("lng"))); } else { throw new IllegalArgumentException("位置无法正常解析"); } // 如果是最后一条记录 + Date lastDate = formatCellValue2Date(needImportDNGrouped.get(dn).getString("定位时间").trim(), "定位时间"); if (lastDate.getTime() == locationTime.getTime()) { Double remainDistanceInKM = 0.00; - Map endMap = addressToGPS(orderOtd.getdAddress()); - if (endMap.size() == 2) { - remainDistanceInKM = BaiDuMapRouteUtil.getDistance(addressToGPS, orderOtd.getdAddress()) - / 1000; + Map lastLocationMap = new HashMap(); + lastLocationMap.put("lat", new Double(geoPoint.get("lat"))); + lastLocationMap.put("lng", new Double(geoPoint.get("lng"))); + Map orderEndMap = new HashMap(); + Map orderEndPoint = checkAddress(orderOtd.getdAddress(), addressMap); + orderEndMap.put("lat", new Double(orderEndPoint.get("lat"))); + orderEndMap.put("lng", new Double(orderEndPoint.get("lng"))); + if (orderEndMap.size() == 2) { + remainDistanceInKM = BaiDuMapRouteUtil.getDistance(lastLocationMap, orderEndMap) / 1000; + } else { + remainDistanceInKM = 0.00; } orderOtdDetail.setDistance(remainDistanceInKM.floatValue()); orderOtd.setNewestPosition(location); @@ -581,7 +580,7 @@ public class ImportServiceImpl implements ImportService { orderOtd.setShiptoTime(locationTime); } orderOtdService.updateById(orderOtd); - // 查询客户编号 + // 删除该定位时间冲突的在途明细 EntityWrapper otdDetailEntity = new EntityWrapper<>(); otdDetailEntity.eq("sys_order_no", dn).gt("track_time", locationTime); orderOtdDetailService.delete(otdDetailEntity); @@ -596,54 +595,47 @@ public class ImportServiceImpl implements ImportService { rows_successed++; } - - // arrayRows.getJSONObject(i).put("导入结果", "成功"); - // arrayRows.getJSONObject(i).put("执行信息", "成功!"); - - } catch (IllegalArgumentException e) { - LOGGER.error("ImportServiceImpl.importOrder ERROR Message : {} ", e); + } catch (Exception e) { + LOGGER.error("ImportServiceImpl.importOrder ...row(" + i + "): ", e); if (StringUtils.isEmpty(arrayRows.getJSONObject(i).getString("执行信息"))) { arrayRows.getJSONObject(i).put("导入结果", "失败"); arrayRows.getJSONObject(i).put("执行信息", e.getMessage()); - JSONObject saveObject = (JSONObject) arrayRows.getJSONObject(i); - saveList.add(saveObject); + JSONObject errRow = (JSONObject) arrayRows.getJSONObject(i); + errRetList.add(errRow); } else { if (arrayRows.getJSONObject(i).getString("执行信息").indexOf(e.getMessage()) == -1) { arrayRows.getJSONObject(i).put("执行信息", arrayRows.getJSONObject(i).getString("执行信息") + "," + e.getMessage()); } } - - // 只反馈导入异常数据到前端 - } } - result = JSONArray.toJSONString(saveList); + // 只反馈导入异常数据到前端 + result = JSONArray.toJSONString(errRetList); Map map = new HashMap<>(); map.put("header", JSONArray.toJSONString(arrayHeader)); map.put("rows", result); - map.put("rows_err", saveList.size() + ""); + map.put("rows_err", errRetList.size() + ""); map.put("rows_successed", rows_successed + ""); return map; } // 从已有的addressMap中查询 有的话就不需要在此调用百度api - private Map checkAddress(String address, Map> addressMap) { - Map map = new HashMap<>(); - for (Map.Entry> entry : addressMap.entrySet()) { + private Map checkAddress(String address, Map> addressMap) { + for (Map.Entry> entry : addressMap.entrySet()) { if (address.equals(entry.getKey())) { return entry.getValue(); } } - Map addressToGPS = addressToGPS(address); - addressMap.put(address, addressToGPS); - return addressToGPS; + Map geoPoint = BaiDuMapGeocodeUtil.addressToGEOPoint(address); + addressMap.put(address, geoPoint); + return geoPoint; } - // 从已有orderOtdMap查询 节省查询数据库时间 + // 从已有orderOtdMap查询 节省查询数据库时间,否则从DB查询 private OrderOtd checkOrderOtd(String orderNo, Map orderOtdMap) { for (Map.Entry entry : orderOtdMap.entrySet()) { if (entry.getKey().equals(orderNo)) { @@ -843,7 +835,6 @@ public class ImportServiceImpl implements ImportService { Matcher matcher = patternDigtalDate.matcher(dateCellVal.trim()); boolean b = matcher.matches(); - boolean c = matcher.matches(); if (!b) { Pattern patternStringDate = Pattern diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java index 8ebb041..9be76d7 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java @@ -682,7 +682,6 @@ public class SharesOrderServiceImpl implements SharesOrderService { */ @Override public Double getDistance(String startAddress, String endAddress) { - if (StringUtils.isEmpty(startAddress) || StringUtils.isEmpty(endAddress)) return 0.0; -- Gitee From 2ecb253b28db206c78fa9e5af88d64eec1a08e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E7=9D=BF?= Date: Sun, 27 Oct 2019 18:34:13 +0800 Subject: [PATCH 2/6] =?UTF-8?q?#hotfix/=E6=98=AF=E5=90=A6=E8=BF=90?= =?UTF-8?q?=E6=8A=B5=E6=A0=8F=E4=B8=BA=E7=A9=BA=E6=97=B6=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ils/kas/service/order/impl/ImportServiceImpl.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java index b020d8d..3880f28 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java @@ -576,7 +576,8 @@ public class ImportServiceImpl implements ImportService { if (!StringUtils.isEmpty(orderOtd.getLicensePlate())) { orderOtd.setLicensePlate(license); } - if (arrayRows.getJSONObject(i).getString("是否运抵").trim().equals("是")) { + String isDelivery = arrayRows.getJSONObject(i).getString("是否运抵"); + if (!StringUtils.isEmpty(isDelivery) && isDelivery.trim().equalsIgnoreCase("是")) { orderOtd.setShiptoTime(locationTime); } orderOtdService.updateById(orderOtd); @@ -821,12 +822,7 @@ public class ImportServiceImpl implements ImportService { } } - if (null == datePhase) { - throw new IllegalArgumentException("无效的" + cellName + "日期单元格数据" + dateCellVal); - } else { - return datePhase; - } - + throw new IllegalArgumentException("无效的" + cellName + "日期单元格数据" + dateCellVal); } private static String testDateFormat(String dateCellVal) { -- Gitee From 839a2aaf0f1108bcd633c3b18049abf984badcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E7=9D=BF?= Date: Sun, 27 Oct 2019 19:04:45 +0800 Subject: [PATCH 3/6] =?UTF-8?q?#hotfix/=E5=AF=BC=E5=85=A5=E8=BD=A8?= =?UTF-8?q?=E8=BF=B9=E6=97=B6=E8=AE=A1=E7=AE=97=E9=A2=84=E8=AE=A1=E8=BF=90?= =?UTF-8?q?=E6=8A=B5=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/order/impl/ImportServiceImpl.java | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java index 3880f28..5ca6d16 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java @@ -572,6 +572,10 @@ public class ImportServiceImpl implements ImportService { orderOtdDetail.setDistance(remainDistanceInKM.floatValue()); orderOtd.setNewestPosition(location); orderOtd.setNewestTime(locationTime); + Date eslimateDeliveryTime = getExpectedArrivalTime(orderOtd, remainDistanceInKM); + if (!StringUtils.isEmpty(eslimateDeliveryTime)) { + orderOtd.setPlanShiptoTime(eslimateDeliveryTime); + } // orderOtd车牌号不为空 更新车牌号 if (!StringUtils.isEmpty(orderOtd.getLicensePlate())) { orderOtd.setLicensePlate(license); @@ -954,6 +958,102 @@ public class ImportServiceImpl implements ImportService { return table; } + /* + * @Description: 计算预计运抵时间 + * + * @Author: zharui + */ + public Date getExpectedArrivalTime(OrderOtd orderOtd, double remainDistanceInKM) { + if (orderOtd == null) + return null; + + // 离昌前 + if (orderOtd.getLeaveTime() == null) { + // 未安排运力,预计送达时间为空 + if (orderOtd.getArrangeCapacityTime() == null) { + return null; + } else { + // 已安排运力,预计送达时间=安排时间+在途时效+流转时间 + Double distance = orderOtd.getDistance().doubleValue(); + Double timeLimitation = 0.00; + Double circulationTime = 0.00; + + if (orderOtd.getTransportTypeCode() == 7 || orderOtd.getTransportTypeCode() == 2) { + // 零公里在途时效 + timeLimitation = distance / 550; + // 零公里流转时间 + circulationTime = 1.0; + } else if (orderOtd.getTransportTypeCode() == 8 || orderOtd.getTransportTypeCode() == 6) { + // 三位板在途时效 + timeLimitation = distance / 550; + // 三位板流转时间 + circulationTime = 0.0; + } else if (orderOtd.getTransportTypeCode() == 1) { + // 人送在途时效 + timeLimitation = distance / 550; + // 人送流转时间 + circulationTime = 0.5; + } else if (orderOtd.getTransportTypeCode() == 4 || orderOtd.getTransportTypeCode() == 5) { + // 铁运在途时效 + timeLimitation = distance / 250; + // 铁运流转时间 + circulationTime = 2.0; + } else if (orderOtd.getTransportTypeCode() == 3) { + // 水运在途时效 + timeLimitation = distance / 185; + // 水运流转时间 + circulationTime = 2.0; + } + + Calendar calendar = Calendar.getInstance(); + // 安排运力时间 + calendar.setTime(orderOtd.getArrangeCapacityTime()); + // 加上在途时效 + Number limitation = Math.ceil(timeLimitation) * 24; + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + // 加上流转时间 + Number circulation = circulationTime * 24; + calendar.add(Calendar.HOUR_OF_DAY, circulation.intValue()); + + return calendar.getTime(); + } + } + // 离昌后 + else { + // 计算剩余公里数 + Double distance = remainDistanceInKM; + if (StringUtils.isEmpty(distance) || distance.compareTo(0d) == 0) { + return null; + } + Number limitation = 0; + // 加上时效,算出预计送达时间 + if (orderOtd.getTransportTypeCode() == 7 || orderOtd.getTransportTypeCode() == 2 + || orderOtd.getTransportTypeCode() == 8 || orderOtd.getTransportTypeCode() == 6) { + // 零公里在途时效 + limitation = Math.ceil(distance / 550) * 24; + } else if (orderOtd.getTransportTypeCode() == 1) { + // 人送 + limitation = Math.ceil(distance / 550) * 24; + } else if (orderOtd.getTransportTypeCode() == 4 || orderOtd.getTransportTypeCode() == 5) { + // 铁运 + limitation = Math.ceil(distance / 250) * 24 + (24) * 3; + } else if (orderOtd.getTransportTypeCode() == 3) { + // 水运 + limitation = Math.ceil(distance / 185) * 24 + (24) * 3; + } else { + limitation = 0; + } + + Calendar calendar = Calendar.getInstance(); + if (orderOtd.getNewestTime() == null) + return null; + calendar.setTime(orderOtd.getNewestTime()); + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + + return calendar.getTime(); + } + } + public static void main(String... args) { // String dateCellVal = "43552.3860532407"; // System.out.println(formatCellValue2Date(dateCellVal, "1")); -- Gitee From 5922aa00b435895e2773f17dad968cfeb8708b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E7=9D=BF?= Date: Mon, 28 Oct 2019 15:44:08 +0800 Subject: [PATCH 4/6] =?UTF-8?q?#hotfix/=E9=A2=84=E8=AE=A1=E8=BF=90?= =?UTF-8?q?=E6=8A=B5=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/order/impl/ImportServiceImpl.java | 132 +++++++++++--- .../order/impl/SharesOrderServiceImpl.java | 165 ++++++++++++------ .../unlcn/ils/kas/service/util/DateUtils.java | 32 +++- 3 files changed, 255 insertions(+), 74 deletions(-) diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java index 5ca6d16..ba9e2cc 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java @@ -13,6 +13,7 @@ import com.unlcn.ils.kas.service.order.CustomerService; import com.unlcn.ils.kas.service.order.ImportService; import com.unlcn.ils.kas.service.order.OrderOtdDetailService; import com.unlcn.ils.kas.service.order.OrderOtdService; +import com.unlcn.ils.kas.service.util.DateUtils; import com.unlcn.ils.kas.service.util.enums.order.OrderDetailDeleteFlagEnum; import com.unlcn.ils.kas.service.util.enums.order.OrderDetailIsmanualEnum; import com.unlcn.ils.kas.service.util.enums.order.OrderWayEnum; @@ -21,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -370,6 +372,7 @@ public class ImportServiceImpl implements ImportService { arrayRows.getJSONObject(i).put("导入结果", "成功"); arrayRows.getJSONObject(i).put("执行信息", "成功!"); + updateNewestPositionRelInfo(orderOtd.getSysOrderNo()); rows_successed++; } catch (Exception e) { LOGGER.error("ImportServiceImpl.importOrder ERROR Message : {} ", e); @@ -570,12 +573,6 @@ public class ImportServiceImpl implements ImportService { remainDistanceInKM = 0.00; } orderOtdDetail.setDistance(remainDistanceInKM.floatValue()); - orderOtd.setNewestPosition(location); - orderOtd.setNewestTime(locationTime); - Date eslimateDeliveryTime = getExpectedArrivalTime(orderOtd, remainDistanceInKM); - if (!StringUtils.isEmpty(eslimateDeliveryTime)) { - orderOtd.setPlanShiptoTime(eslimateDeliveryTime); - } // orderOtd车牌号不为空 更新车牌号 if (!StringUtils.isEmpty(orderOtd.getLicensePlate())) { orderOtd.setLicensePlate(license); @@ -597,7 +594,7 @@ public class ImportServiceImpl implements ImportService { if (CollectionUtils.isEmpty(otdDetails)) { orderOtdDetailService.insert(orderOtdDetail); } - + updateNewestPositionRelInfo(dn); rows_successed++; } } catch (Exception e) { @@ -958,17 +955,36 @@ public class ImportServiceImpl implements ImportService { return table; } - /* - * @Description: 计算预计运抵时间 + /** + * 返回当天日期时间 + * + * @return + */ + private Date getTodayDate() { + Calendar calToday = Calendar.getInstance(); + Date now = new Date(); + calToday.setTime(now); + int year = calToday.get(Calendar.YEAR); + int month = calToday.get(Calendar.MONTH); + int day = calToday.get(Calendar.DAY_OF_MONTH); + calToday.set(year, month, day); + return calToday.getTime(); + } + + /** + * 计算预计运抵时间 * - * @Author: zharui + * @param orderOtd + * @param remainDistanceInKM + * @return */ public Date getExpectedArrivalTime(OrderOtd orderOtd, double remainDistanceInKM) { - if (orderOtd == null) + if (orderOtd == null) { return null; - + } + Date today = getTodayDate(); // 离昌前 - if (orderOtd.getLeaveTime() == null) { + if (StringUtils.isEmpty(orderOtd.getLeaveTime())) { // 未安排运力,预计送达时间为空 if (orderOtd.getArrangeCapacityTime() == null) { return null; @@ -1015,6 +1031,11 @@ public class ImportServiceImpl implements ImportService { Number circulation = circulationTime * 24; calendar.add(Calendar.HOUR_OF_DAY, circulation.intValue()); + if (calendar.getTime().before(today)) { + calendar.setTime(today); + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + calendar.add(Calendar.HOUR_OF_DAY, circulation.intValue()); + } return calendar.getTime(); } } @@ -1022,8 +1043,8 @@ public class ImportServiceImpl implements ImportService { else { // 计算剩余公里数 Double distance = remainDistanceInKM; - if (StringUtils.isEmpty(distance) || distance.compareTo(0d) == 0) { - return null; + if (distance == null || distance.compareTo(0d) == 0) { + distance = 0d; } Number limitation = 0; // 加上时效,算出预计送达时间 @@ -1041,19 +1062,90 @@ public class ImportServiceImpl implements ImportService { // 水运 limitation = Math.ceil(distance / 185) * 24 + (24) * 3; } else { - limitation = 0; + limitation = Math.ceil(distance / 550) * 24; } Calendar calendar = Calendar.getInstance(); - if (orderOtd.getNewestTime() == null) - return null; - calendar.setTime(orderOtd.getNewestTime()); - calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + if (orderOtd.getNewestTime() == null) { + calendar.setTime(today); + } else { + calendar.setTime(orderOtd.getNewestTime()); + } + if (limitation.intValue() == 0) { + calendar.setTime(orderOtd.getPlanShiptoTime()); + } else { + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + } + if (calendar.getTime().before(today)) { + Date oldPlanShipToTime = calendar.getTime(); + calendar.setTime(today); + if (limitation.intValue() == 0) { + int hoursInterval = 0; + if (!StringUtils.isEmpty(orderOtd.getNewestTime())) { + hoursInterval = DateUtils.hoursBetween(orderOtd.getNewestTime(), oldPlanShipToTime); + } else { + hoursInterval = DateUtils.hoursBetween(orderOtd.getLeaveTime(), oldPlanShipToTime); + } + calendar.add(Calendar.HOUR_OF_DAY, hoursInterval); + } else { + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + } + } return calendar.getTime(); } } + @Transactional(propagation = Propagation.SUPPORTS) + public void updateNewestPositionRelInfo(String sysOrderNo) { + OrderOtd orderOtd = orderOtdService.selectOne(new EntityWrapper().eq("sys_order_no", sysOrderNo)); + Wrapper wrapper = new EntityWrapper<>(); + wrapper.eq("sys_order_no", sysOrderNo); + wrapper.orderBy("track_time", false); + List onwayDetail = orderOtdDetailService.selectList(wrapper); + + String endAddress = orderOtd.getdProvince() + orderOtd.getdCity(); + double remainKM = 0d; + if (!StringUtils.isEmpty(orderOtd.getShiptoTime())) { + orderOtd.setNewestPosition(endAddress); + orderOtd.setNewestTime(orderOtd.getShiptoTime()); + } else if (!StringUtils.isEmpty(orderOtd.getManualShiptoTime())) { + orderOtd.setNewestPosition(endAddress); + orderOtd.setNewestTime(orderOtd.getManualShiptoTime()); + } else if (!CollectionUtils.isEmpty(onwayDetail)) { + // 获取最新在途 + OrderOtdDetail newestOnway = onwayDetail.get(0); + if (!StringUtils.isEmpty(newestOnway)) { + String newestPosition = (StringUtils.isEmpty(newestOnway.getProvince()) ? "" + : newestOnway.getProvince() + "-") + + (StringUtils.isEmpty(newestOnway.getCity()) ? "" : newestOnway.getCity() + "-") + + (StringUtils.isEmpty(newestOnway.getArea()) ? "" : newestOnway.getArea() + "-") + + (StringUtils.isEmpty(newestOnway.getAddress()) ? "" : newestOnway.getAddress()); + orderOtd.setNewestPosition(newestPosition); + orderOtd.setNewestTime(newestOnway.getTrackTime()); + remainKM = newestOnway.getDistance(); + } else { + remainKM = orderOtd.getDistance(); + } + } else { + remainKM = orderOtd.getDistance(); + } + + if (!StringUtils.isEmpty(orderOtd.getShiptoTime())) { + orderOtd.setPlanShiptoTime(orderOtd.getShiptoTime()); + } else if (!StringUtils.isEmpty(orderOtd.getManualShiptoTime())) { + orderOtd.setPlanShiptoTime(orderOtd.getManualShiptoTime()); + } else { + // 计算预计送达时间 + orderOtd.setPlanShiptoTime(getExpectedArrivalTime(orderOtd, remainKM)); + } + + if (StringUtils.isEmpty(orderOtd.getArrangeCapacityTime())) { + orderOtd.setPlanShiptoTime(null); + } + orderOtdService.updateById(orderOtd); + } + public static void main(String... args) { // String dateCellVal = "43552.3860532407"; // System.out.println(formatCellValue2Date(dateCellVal, "1")); diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java index 9be76d7..4a9de89 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java @@ -44,9 +44,10 @@ import com.unlcn.ils.kas.service.util.enums.order.OrderOtdExceptionEnum; import com.unlcn.ils.kas.service.util.enums.order.OrderWayEnum; import com.unlcn.ils.kas.service.util.enums.order.PushOrderLogTypeEnum; -import org.apache.commons.lang3.time.DateUtils; +import com.unlcn.ils.kas.service.util.DateUtils; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; +import org.apache.poi.util.StringUtil; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -361,7 +362,54 @@ public class SharesOrderServiceImpl implements SharesOrderService { return executWay; } - /* @author:罗必量 */ + // 更新主表的最新位置,最新在途时间,预计运抵时间 + @Transactional(propagation = Propagation.SUPPORTS) + public void updateNewestPositionRelInfo(String sysOrderNo) { + OrderOtd orderOtd = orderOtdService.selectOne(new EntityWrapper().eq("sys_order_no", sysOrderNo)); + Wrapper wrapper = new EntityWrapper<>(); + wrapper.eq("sys_order_no", sysOrderNo); + wrapper.orderBy("track_time", false); + List onwayDetail = orderOtdDetailService.selectList(wrapper); + + String endAddress = orderOtd.getdProvince() + orderOtd.getdCity(); + if (!StringUtils.isEmpty(orderOtd.getShiptoTime())) { + orderOtd.setNewestPosition(endAddress); + orderOtd.setNewestTime(orderOtd.getShiptoTime()); + } else if (!StringUtils.isEmpty(orderOtd.getManualShiptoTime())) { + orderOtd.setNewestPosition(endAddress); + orderOtd.setNewestTime(orderOtd.getManualShiptoTime()); + } else if (!CollectionUtils.isEmpty(onwayDetail)) { + // 获取最新在途 + OrderOtdDetail newestOnway = onwayDetail.get(0); + if (!StringUtils.isEmpty(newestOnway)) { + String newestPosition = (StringUtils.isEmpty(newestOnway.getProvince()) ? "" + : newestOnway.getProvince() + "-") + + (StringUtils.isEmpty(newestOnway.getCity()) ? "" : newestOnway.getCity() + "-") + + (StringUtils.isEmpty(newestOnway.getArea()) ? "" : newestOnway.getArea() + "-") + + (StringUtils.isEmpty(newestOnway.getAddress()) ? "" : newestOnway.getAddress()); + orderOtd.setNewestPosition(newestPosition); + orderOtd.setNewestTime(newestOnway.getTrackTime()); + } + } + + if (!StringUtils.isEmpty(orderOtd.getShiptoTime())) { + orderOtd.setPlanShiptoTime(orderOtd.getShiptoTime()); + } else if (!StringUtils.isEmpty(orderOtd.getManualShiptoTime())) { + orderOtd.setPlanShiptoTime(orderOtd.getManualShiptoTime()); + } else { + // 计算预计送达时间 + orderOtd.setPlanShiptoTime(this.expectedArrivalTime(orderOtd)); + } + + if (StringUtils.isEmpty(orderOtd.getArrangeCapacityTime())) { + orderOtd.setPlanShiptoTime(null); + } + orderOtdService.updateById(orderOtd); + } + + /* + * @author:罗必量 保存在途轨迹明细,同时更新主表的最新位置,最新在途时间,预计运抵时间 + */ @Transactional(propagation = Propagation.SUPPORTS) @Override public void saveDetail(OrderOtd orderOtd, List orderOtdLogDetailList) { @@ -406,6 +454,8 @@ public class SharesOrderServiceImpl implements SharesOrderService { orderOtdDetailService.insert(orderOtdDetail); } + // 添加计算预计运抵时间的模块 + updateNewestPositionRelInfo(orderOtd.getSysOrderNo()); } /** @@ -477,8 +527,15 @@ public class SharesOrderServiceImpl implements SharesOrderService { */ @Override public OrderOtd transformation(OrderOtdLog orderOtdLog, List orderOtdList) { + String dn = orderOtdLog.getSysOrderNo(); - OrderOtd orderOtd = new OrderOtd(); + System.out.println("订单号:" + dn); + OrderOtd orderOtd = null; + if (!CollectionUtils.isEmpty(orderOtdList) && !StringUtils.isEmpty(orderOtdList.get(0))) { + orderOtd = orderOtdList.get(0); + } else { + orderOtd = new OrderOtd(); + } BeanUtils.copyProperties(orderOtdLog, orderOtd); @@ -496,40 +553,9 @@ public class SharesOrderServiceImpl implements SharesOrderService { // 计算起运地到目的地的距离 String startAddress = orderOtd.getoProvince() + orderOtd.getoCity() + orderOtd.getoAddress(); String endAddress = orderOtd.getdProvince() + orderOtd.getdCity() + orderOtd.getdAddress(); - System.out.println("订单号:" + orderOtdLog.getSysOrderNo()); - - orderOtd.setDistance(getDistance(startAddress, endAddress).floatValue()); - - // 未手动运抵的订单,才会计算预计送达时间 - if (CollectionUtils.isEmpty(orderOtdList) || orderOtdList.get(0).getManualShiptoTime() == null) { - if (orderOtd.getShiptoTime() != null) { - // 如果v_jmc_kas_flow_info.dtassign为空 kas_order_otd.plan_shipto_time为空 - if (!StringUtils.isEmpty(orderOtd.getArrangeCapacityTime())) { - orderOtd.setPlanShiptoTime(orderOtd.getShiptoTime()); - } - } else { - // 如果v_jmc_kas_flow_info.dtassign为空 kas_order_otd.plan_shipto_time为空 - if (!StringUtils.isEmpty(orderOtd.getArrangeCapacityTime())) { - // 计算预计送达时间 - orderOtd.setPlanShiptoTime(this.expectedArrivalTime(orderOtd)); - } - - } - } - // 如果手动不为空 就拿最后一条维护最新在途位置 - if (!CollectionUtils.isEmpty(orderOtdList) && orderOtdList.get(0).getManualShiptoTime() != null) { - // 获取最新在途 - OrderOtdDetail orderOtdDetail = orderOtdDetailService.selectNewestInfo(orderOtd.getSysOrderNo()); - if (orderOtdDetail != null) { - String newestPosition = (StringUtils.isEmpty(orderOtdDetail.getProvince()) ? "" - : orderOtdDetail.getProvince() + "-") - + (StringUtils.isEmpty(orderOtdDetail.getCity()) ? "" : orderOtdDetail.getCity() + "-") - + (StringUtils.isEmpty(orderOtdDetail.getArea()) ? "" : orderOtdDetail.getArea() + "-") - + (StringUtils.isEmpty(orderOtdDetail.getAddress()) ? "" : orderOtdDetail.getAddress()); - orderOtd.setNewestPosition(newestPosition); - orderOtd.setNewestTime(orderOtdDetail.getTrackTime()); - } + if (StringUtils.isEmpty(orderOtd.getDistance()) || orderOtd.getDistance() == 0) { + orderOtd.setDistance(getDistance(startAddress, endAddress).floatValue()); } // 判断挂起状态 @@ -553,6 +579,7 @@ public class SharesOrderServiceImpl implements SharesOrderService { } else if (orderOtd.getBsuspend() == 1) { orderOtd.setManualDriverPhone(null); orderOtd.setManualShiptoTime(null); + orderOtd.setShiptoTime(null); } } @@ -570,6 +597,17 @@ public class SharesOrderServiceImpl implements SharesOrderService { return orderOtd; } + private Date getTodayDate() { + Calendar calToday = Calendar.getInstance(); + Date now = new Date(); + calToday.setTime(now); + int year = calToday.get(Calendar.YEAR); + int month = calToday.get(Calendar.MONTH); + int day = calToday.get(Calendar.DAY_OF_MONTH); + calToday.set(year, month, day); + return calToday.getTime(); + } + /** * 计算距离和预计送达时间 * @@ -580,11 +618,12 @@ public class SharesOrderServiceImpl implements SharesOrderService { @Override public Date expectedArrivalTime(OrderOtd orderOtd) { - if (orderOtd == null) + if (orderOtd == null) { return null; - + } + Date today = getTodayDate(); // 离昌前 - if (orderOtd.getLeaveTime() == null) { + if (StringUtils.isEmpty(orderOtd.getLeaveTime())) { // 未安排运力,预计送达时间为空 if (orderOtd.getArrangeCapacityTime() == null) { return null; @@ -631,6 +670,11 @@ public class SharesOrderServiceImpl implements SharesOrderService { Number circulation = circulationTime * 24; calendar.add(Calendar.HOUR_OF_DAY, circulation.intValue()); + if (calendar.getTime().before(today)) { + calendar.setTime(today); + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + calendar.add(Calendar.HOUR_OF_DAY, circulation.intValue()); + } return calendar.getTime(); } } @@ -640,8 +684,8 @@ public class SharesOrderServiceImpl implements SharesOrderService { String startAddress = orderOtd.getNewestPosition(); String endAddress = orderOtd.getdProvince() + orderOtd.getdCity() + orderOtd.getdAddress(); Double distance = getDistance(startAddress, endAddress); - if (distance == null) { - return null; + if (distance == null || distance.compareTo(0d) == 0) { + distance = 0d; } Number limitation = 0; // 加上时效,算出预计送达时间 @@ -659,15 +703,36 @@ public class SharesOrderServiceImpl implements SharesOrderService { // 水运 limitation = Math.ceil(distance / 185) * 24 + (24) * 3; } else { - limitation = 0; + limitation = Math.ceil(distance / 550) * 24; } Calendar calendar = Calendar.getInstance(); - if (orderOtd.getNewestTime() == null) - return null; - calendar.setTime(orderOtd.getNewestTime()); - calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + if (orderOtd.getNewestTime() == null) { + calendar.setTime(today); + } else { + calendar.setTime(orderOtd.getNewestTime()); + } + if (limitation.intValue() == 0) { + calendar.setTime(orderOtd.getPlanShiptoTime()); + } else { + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + } + if (calendar.getTime().before(today)) { + Date oldPlanShipToTime = calendar.getTime(); + calendar.setTime(today); + if (limitation.intValue() == 0) { + int hoursInterval = 0; + if (!StringUtils.isEmpty(orderOtd.getNewestTime())) { + hoursInterval = DateUtils.hoursBetween(orderOtd.getNewestTime(), oldPlanShipToTime); + } else { + hoursInterval = DateUtils.hoursBetween(orderOtd.getLeaveTime(), oldPlanShipToTime); + } + calendar.add(Calendar.HOUR_OF_DAY, hoursInterval); + } else { + calendar.add(Calendar.HOUR_OF_DAY, limitation.intValue()); + } + } return calendar.getTime(); } } @@ -688,9 +753,11 @@ public class SharesOrderServiceImpl implements SharesOrderService { startAddress = startAddress.replaceAll("null", ""); endAddress = endAddress.replaceAll("null", ""); - Double distance = BaiDuMapRouteUtil.getDistance(startAddress, endAddress); - if (distance == null) { - return 0.0; + Double distance = 0.0; + try { + distance = BaiDuMapRouteUtil.getDistance(startAddress, endAddress); + } catch (Exception e) { + distance = 0.0; } distance = distance / 1000; diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/util/DateUtils.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/util/DateUtils.java index a6fb276..168cfc8 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/util/DateUtils.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/util/DateUtils.java @@ -28,7 +28,7 @@ public class DateUtils { * @return */ public static String getWeekOfDate(Date dt) { - String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; Calendar cal = Calendar.getInstance(); cal.setTime(dt); int w = cal.get(Calendar.DAY_OF_WEEK) - 1; @@ -298,7 +298,7 @@ public class DateUtils { * @return */ public static Date getFirstDay4Month() { - //获取当前月第一天: + // 获取当前月第一天: Calendar c = Calendar.getInstance(); c.add(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天 @@ -318,7 +318,7 @@ public class DateUtils { * @return */ public static Date getFirstDay0Month() { - //获取当前月第一天: + // 获取当前月第一天: Calendar c = Calendar.getInstance(); c.add(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天 @@ -338,13 +338,13 @@ public class DateUtils { * @return */ public static Date getLastDay4Month() { - //获取当前月最后一天 + // 获取当前月最后一天 Calendar ca = Calendar.getInstance(); ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); return ca.getTime(); } - //上周一 + // 上周一 public static Date lastMonday(Date date) throws Exception { int n = -1; @@ -396,6 +396,28 @@ public class DateUtils { return Integer.parseInt(String.valueOf(between_days)); } + /** + * 计算两个日期之间相差的小时数 + * + * @param smdate + * @param bdate + * @return + * @throws ParseException + */ + public static int hoursBetween(Date smdate, Date bdate) { + Calendar cal = Calendar.getInstance(); + cal.setTime(smdate); + long smMillSeconds = cal.getTimeInMillis(); + cal.setTime(bdate); + long bMillSeconds = cal.getTimeInMillis(); + if (smMillSeconds >= bMillSeconds) { + long temp = smMillSeconds; + smMillSeconds = bMillSeconds; + bMillSeconds = temp; + } + return Math.round((bMillSeconds - smMillSeconds) / (1000 * 3600)); + } + /** * 获取当前日期的星期一 * -- Gitee From d6824a70272e451449a1dde852029440369ead58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E7=9D=BF?= Date: Mon, 28 Oct 2019 17:05:49 +0800 Subject: [PATCH 5/6] =?UTF-8?q?#hotfix/=E9=A2=84=E8=AE=A1=E8=BF=90?= =?UTF-8?q?=E6=8A=B5=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unlcn/ils/kas/service/order/impl/ImportServiceImpl.java | 5 +++++ .../ils/kas/service/order/impl/SharesOrderServiceImpl.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java index ba9e2cc..746d15c 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java @@ -1019,6 +1019,11 @@ public class ImportServiceImpl implements ImportService { timeLimitation = distance / 185; // 水运流转时间 circulationTime = 2.0; + } else { + // 零公里在途时效 + timeLimitation = distance / 550; + // 零公里流转时间 + circulationTime = 1.0; } Calendar calendar = Calendar.getInstance(); diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java index 4a9de89..04ffb6f 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java @@ -658,6 +658,11 @@ public class SharesOrderServiceImpl implements SharesOrderService { timeLimitation = distance / 185; // 水运流转时间 circulationTime = 2.0; + } else { + // 默认按零公里在途时效 + timeLimitation = distance / 550; + // 零公里流转时间 + circulationTime = 1.0; } Calendar calendar = Calendar.getInstance(); -- Gitee From ac75c88a657316c44cacafdca2ad4636b58f6b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E7=9D=BF?= Date: Mon, 28 Oct 2019 18:55:47 +0800 Subject: [PATCH 6/6] Merge branch 'master' into develop # Conflicts: # kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java --- .../order/impl/ImportServiceImplTest.java | 10 +++++- .../service/order/impl/ImportServiceImpl.java | 31 +++++++------------ .../order/impl/SharesOrderServiceImpl.java | 26 ++++++---------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/kas-admin/src/test/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImplTest.java b/kas-admin/src/test/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImplTest.java index 8c3384d..25c94ff 100644 --- a/kas-admin/src/test/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImplTest.java +++ b/kas-admin/src/test/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImplTest.java @@ -36,7 +36,7 @@ public class ImportServiceImplTest { @Before public void setUp() { - String targetSysOrderNo = "0171648096"; + String targetSysOrderNo = "0171714775"; EntityWrapper ew = new EntityWrapper<>(); ew.eq("sys_order_no", targetSysOrderNo); List orderOtdList = orderOtdService.selectList(ew); @@ -44,6 +44,14 @@ public class ImportServiceImplTest { otd = orderOtdList.get(0); } + @Test + public void testPlanShip2Time() { + String dn = "0171714775"; + importServiceImpl.updateNewestPositionRelInfo(dn); + OrderOtd otd = orderOtdService.selectOne(new EntityWrapper().eq("sys_order_no", dn)); + assertNotNull(otd.getPlanShiptoTime()); + } + @Test public void calcOtdDetailFromNewestLocate() { Calendar cl = Calendar.getInstance(); diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java index 746d15c..bf82a63 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/ImportServiceImpl.java @@ -994,35 +994,31 @@ public class ImportServiceImpl implements ImportService { Double timeLimitation = 0.00; Double circulationTime = 0.00; - if (orderOtd.getTransportTypeCode() == 7 || orderOtd.getTransportTypeCode() == 2) { - // 零公里在途时效 - timeLimitation = distance / 550; - // 零公里流转时间 - circulationTime = 1.0; - } else if (orderOtd.getTransportTypeCode() == 8 || orderOtd.getTransportTypeCode() == 6) { + if (orderOtd.getTransportType().lastIndexOf("三位") >= 0 + || orderOtd.getTransportType().lastIndexOf("四位") >= 0) { // 三位板在途时效 timeLimitation = distance / 550; // 三位板流转时间 circulationTime = 0.0; - } else if (orderOtd.getTransportTypeCode() == 1) { + } else if (orderOtd.getTransportType().lastIndexOf("人送") >= 0) { // 人送在途时效 timeLimitation = distance / 550; // 人送流转时间 circulationTime = 0.5; - } else if (orderOtd.getTransportTypeCode() == 4 || orderOtd.getTransportTypeCode() == 5) { + } else if (orderOtd.getTransportType().lastIndexOf("铁") >= 0) { // 铁运在途时效 timeLimitation = distance / 250; // 铁运流转时间 circulationTime = 2.0; - } else if (orderOtd.getTransportTypeCode() == 3) { + } else if (orderOtd.getTransportType().lastIndexOf("水") >= 0) { // 水运在途时效 timeLimitation = distance / 185; // 水运流转时间 circulationTime = 2.0; } else { - // 零公里在途时效 + // 默认按普通零公里在途时效 timeLimitation = distance / 550; - // 零公里流转时间 + // 普通零公里流转时间 circulationTime = 1.0; } @@ -1053,20 +1049,17 @@ public class ImportServiceImpl implements ImportService { } Number limitation = 0; // 加上时效,算出预计送达时间 - if (orderOtd.getTransportTypeCode() == 7 || orderOtd.getTransportTypeCode() == 2 - || orderOtd.getTransportTypeCode() == 8 || orderOtd.getTransportTypeCode() == 6) { - // 零公里在途时效 - limitation = Math.ceil(distance / 550) * 24; - } else if (orderOtd.getTransportTypeCode() == 1) { + if (orderOtd.getTransportType().lastIndexOf("人送") >= 0) { // 人送 limitation = Math.ceil(distance / 550) * 24; - } else if (orderOtd.getTransportTypeCode() == 4 || orderOtd.getTransportTypeCode() == 5) { + } else if (orderOtd.getTransportType().lastIndexOf("铁") >= 0) { // 铁运 limitation = Math.ceil(distance / 250) * 24 + (24) * 3; - } else if (orderOtd.getTransportTypeCode() == 3) { + } else if (orderOtd.getTransportType().lastIndexOf("水") >= 0) { // 水运 limitation = Math.ceil(distance / 185) * 24 + (24) * 3; } else { + // 零公里 limitation = Math.ceil(distance / 550) * 24; } @@ -1101,7 +1094,7 @@ public class ImportServiceImpl implements ImportService { } } - @Transactional(propagation = Propagation.SUPPORTS) + @Transactional(propagation = Propagation.REQUIRED) public void updateNewestPositionRelInfo(String sysOrderNo) { OrderOtd orderOtd = orderOtdService.selectOne(new EntityWrapper().eq("sys_order_no", sysOrderNo)); Wrapper wrapper = new EntityWrapper<>(); diff --git a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java index 04ffb6f..4443181 100644 --- a/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java +++ b/kas-service/src/main/java/com/unlcn/ils/kas/service/order/impl/SharesOrderServiceImpl.java @@ -363,7 +363,7 @@ public class SharesOrderServiceImpl implements SharesOrderService { } // 更新主表的最新位置,最新在途时间,预计运抵时间 - @Transactional(propagation = Propagation.SUPPORTS) + @Transactional(propagation = Propagation.REQUIRED) public void updateNewestPositionRelInfo(String sysOrderNo) { OrderOtd orderOtd = orderOtdService.selectOne(new EntityWrapper().eq("sys_order_no", sysOrderNo)); Wrapper wrapper = new EntityWrapper<>(); @@ -633,27 +633,23 @@ public class SharesOrderServiceImpl implements SharesOrderService { Double timeLimitation = 0.00; Double circulationTime = 0.00; - if (orderOtd.getTransportTypeCode() == 7 || orderOtd.getTransportTypeCode() == 2) { - // 零公里在途时效 - timeLimitation = distance / 550; - // 零公里流转时间 - circulationTime = 1.0; - } else if (orderOtd.getTransportTypeCode() == 8 || orderOtd.getTransportTypeCode() == 6) { + if (orderOtd.getTransportType().lastIndexOf("三位") >= 0 + || orderOtd.getTransportType().lastIndexOf("四位") >= 0) { // 三位板在途时效 timeLimitation = distance / 550; // 三位板流转时间 circulationTime = 0.0; - } else if (orderOtd.getTransportTypeCode() == 1) { + } else if (orderOtd.getTransportType().lastIndexOf("人送") >= 0) { // 人送在途时效 timeLimitation = distance / 550; // 人送流转时间 circulationTime = 0.5; - } else if (orderOtd.getTransportTypeCode() == 4 || orderOtd.getTransportTypeCode() == 5) { + } else if (orderOtd.getTransportType().lastIndexOf("铁") >= 0) { // 铁运在途时效 timeLimitation = distance / 250; // 铁运流转时间 circulationTime = 2.0; - } else if (orderOtd.getTransportTypeCode() == 3) { + } else if (orderOtd.getTransportType().lastIndexOf("水") >= 0) { // 水运在途时效 timeLimitation = distance / 185; // 水运流转时间 @@ -694,17 +690,13 @@ public class SharesOrderServiceImpl implements SharesOrderService { } Number limitation = 0; // 加上时效,算出预计送达时间 - if (orderOtd.getTransportTypeCode() == 7 || orderOtd.getTransportTypeCode() == 2 - || orderOtd.getTransportTypeCode() == 8 || orderOtd.getTransportTypeCode() == 6) { - // 零公里在途时效 - limitation = Math.ceil(distance / 550) * 24; - } else if (orderOtd.getTransportTypeCode() == 1) { + if (orderOtd.getTransportType().lastIndexOf("人送") >= 0) { // 人送 limitation = Math.ceil(distance / 550) * 24; - } else if (orderOtd.getTransportTypeCode() == 4 || orderOtd.getTransportTypeCode() == 5) { + } else if (orderOtd.getTransportType().lastIndexOf("铁") >= 0) { // 铁运 limitation = Math.ceil(distance / 250) * 24 + (24) * 3; - } else if (orderOtd.getTransportTypeCode() == 3) { + } else if (orderOtd.getTransportType().lastIndexOf("水") >= 0) { // 水运 limitation = Math.ceil(distance / 185) * 24 + (24) * 3; } else { -- Gitee