修改距离计算

This commit is contained in:
cb 2025-09-12 10:18:55 +08:00
parent e9771921db
commit c3f89a3a4f
6 changed files with 234 additions and 199 deletions

View File

@ -347,6 +347,9 @@ public class OrderDetailController extends BaseController {
try {
// 子单信息
OrderDetail detail = orderDetailService.selectById(request.getId());
if (detail == null) {
return AjaxResult.error("订单详情不存在");
}
// 主单信息
OrderMaster orderMaster = orderMasterService.selectById(detail.getOrderMasterId());
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMaster.getId());
@ -516,14 +519,14 @@ public class OrderDetailController extends BaseController {
Shop shop=shopService.getShop(goods.getShopId());
// 计算主单地址与店铺的距离
shop = calculateShopDistance(customerAddress, shop);
shop = calculateShopDistance(orderMaster, shop);
orderListResponse.setShop(shop);
// 编辑返回属性
orderListResponse.setTrackingNumber(orderMaster.getTrackingNumber());
orderListResponse.setDeliveryImages(orderMaster.getDeliveryImages());
orderListResponse.setDeliveryRemark(orderMaster.getDeliveryRemark());
orderListResponse.setDeliveryType(orderMaster.getDeliveryType());
orderListResponse.setTrackingNumber(detail.getTrackingNumber());
orderListResponse.setDeliveryImages(detail.getDeliveryImages());
orderListResponse.setDeliveryRemark(detail.getDeliveryRemark());
orderListResponse.setDeliveryType(detail.getDeliveryType());
orderListResponse.setShareAccountCountdownEndTime(detail.getShareAccountCountdownEndTime());
orderListResponse.setShareAccountCountdownDuration(detail.getShareAccountCountdownDuration());
orderListResponse.setHandoverImages(detail.getHandoverImages());
@ -1711,108 +1714,86 @@ public class OrderDetailController extends BaseController {
}
/**
* 计算商家与客户地址之间的距离
* @param customerAddress 客户地址信息
* 计算商家与主单地址之间的距离
* @param orderMaster 主单信息
* @param shop 商家信息
* @param string
* @return 带有距离信息的商家对象
*/
private Shop calculateShopDistance(CustomerAddress customerAddress, Shop shop) {
private Shop calculateShopDistance(OrderMaster orderMaster, Shop shop) {
try {
// 检查客户地址经纬度是否有效
if (customerAddress.getLongitude() != null && customerAddress.getLatitude() != null &&
customerAddress.getLongitude().compareTo(BigDecimal.ZERO) != 0 &&
customerAddress.getLatitude().compareTo(BigDecimal.ZERO) != 0) {
// 直接使用主单地址获取经纬度
logger.info("使用主单地址获取经纬度");
// 使用已有的经纬度计算距离
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
StringBuilder fullAddress = new StringBuilder();
double distance = LocationUtils.getDistanceInMeters(
customerAddress.getLatitude().doubleValue(),
customerAddress.getLongitude().doubleValue(),
shop.getLatitude().doubleValue(),
shop.getLongitude().doubleValue()
);
String distanceStr = String.format("%.2f", distance);
shop.setDistance(distanceStr);
logger.info("使用已有经纬度计算距离成功,商家[{}]与客户地址距离:{}km", shop.getShopName(), distanceStr);
}
} else {
// 客户地址经纬度为空尝试通过地址获取经纬度
logger.info("客户地址经纬度为空,尝试通过地址获取经纬度");
StringBuilder fullAddress = new StringBuilder();
// 构建完整地址
if (customerAddress.getProvinceId() != null) {
SysArea province = sysAreaService.selectById(customerAddress.getProvinceId());
if (province != null) {
fullAddress.append(province.getAreaName());
}
}
if (customerAddress.getCityId() != null) {
SysArea city = sysAreaService.selectById(customerAddress.getCityId());
if (city != null) {
fullAddress.append(city.getAreaName());
}
}
if (customerAddress.getCountryId() != null) {
SysArea area = sysAreaService.selectById(customerAddress.getCountryId());
if (area != null) {
fullAddress.append(area.getAreaName());
}
}
if (customerAddress.getStreetId() != null) {
SysArea street = sysAreaService.selectById(customerAddress.getStreetId());
if (street != null) {
fullAddress.append(street.getAreaName());
}
}
if (StringUtils.isNotEmpty(customerAddress.getAddress())) {
fullAddress.append(customerAddress.getAddress());
}
String addressStr = fullAddress.toString();
logger.info("构建的完整地址:{}", addressStr);
if (StringUtils.isNotEmpty(addressStr)) {
// 调用百度地图API获取经纬度
Map<String, Double> coordinates = baiduMapUtils.getCoordinatesByAddress(shop.getProvinceName(), shop.getCityName(), shop.getCountryName(), shop.getStreetName(), addressStr);
if (coordinates != null && coordinates.containsKey("longitude") && coordinates.containsKey("latitude")) {
BigDecimal lng = new BigDecimal(coordinates.get("longitude").toString());
BigDecimal lat = new BigDecimal(coordinates.get("latitude").toString());
logger.info("通过地址获取到经纬度longitude={}, latitude={}", lng, lat);
// 计算距离
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
double distance = LocationUtils.getDistanceInMeters(
lat.doubleValue(),
lng.doubleValue(),
shop.getLatitude().doubleValue(),
shop.getLongitude().doubleValue()
);
String distanceStr = String.format("%.2f", distance);
shop.setDistance(distanceStr);
logger.info("通过地址获取经纬度后计算距离成功,商家[{}]与客户地址距离:{}km", shop.getShopName(), distanceStr);
}
} else {
logger.warn("通过地址[{}]获取经纬度失败", addressStr);
}
} else {
logger.warn("无法构建完整地址,跳过距离计算");
// 构建完整地址
if (orderMaster.getProvinceId() != null) {
SysArea province = sysAreaService.selectById(orderMaster.getProvinceId());
if (province != null) {
fullAddress.append(province.getAreaName());
}
}
if (orderMaster.getCityId() != null) {
SysArea city = sysAreaService.selectById(orderMaster.getCityId());
if (city != null) {
fullAddress.append(city.getAreaName());
}
}
if (orderMaster.getCountryId() != null) {
SysArea area = sysAreaService.selectById(orderMaster.getCountryId());
if (area != null) {
fullAddress.append(area.getAreaName());
}
}
if (orderMaster.getStreetId() != null) {
SysArea street = sysAreaService.selectById(orderMaster.getStreetId());
if (street != null) {
fullAddress.append(street.getAreaName());
}
}
if (StringUtils.isNotEmpty(orderMaster.getAddress())) {
fullAddress.append(orderMaster.getAddress());
}
String addressStr = fullAddress.toString();
logger.info("构建的完整地址:{}", addressStr);
if (StringUtils.isNotEmpty(addressStr)) {
// 调用百度地图API获取经纬度
Map<String, Double> coordinates = baiduMapUtils.getCoordinatesByAddress(shop.getProvinceName(), shop.getCityName(), shop.getCountryName(), shop.getStreetName(), addressStr);
if (coordinates != null && coordinates.containsKey("longitude") && coordinates.containsKey("latitude")) {
BigDecimal lng = new BigDecimal(coordinates.get("longitude").toString());
BigDecimal lat = new BigDecimal(coordinates.get("latitude").toString());
logger.info("通过地址获取到经纬度longitude={}, latitude={}", lng, lat);
// 计算距离
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
double distance = LocationUtils.getDistanceInMeters(
lat.doubleValue(),
lng.doubleValue(),
shop.getLatitude().doubleValue(),
shop.getLongitude().doubleValue()
);
String formattedDistance = LocationUtils.formatDistance(distance);
shop.setDistance(formattedDistance);
logger.info("通过地址获取经纬度后计算距离成功,商家[{}]与主单地址距离:{}", shop.getShopName(), formattedDistance);
}
} else {
logger.warn("通过地址[{}]获取经纬度失败", addressStr);
}
} else {
logger.warn("无法构建完整地址,跳过距离计算");
}
} catch (Exception e) {
logger.error("计算商家与客户地址距离时发生异常", e);
logger.error("计算商家与主单地址距离时发生异常", e);
}
return shop;

View File

@ -1705,6 +1705,10 @@ public class OrderMasterController extends BaseController {
}
OrderStandardDetail orderStandardDetail = new OrderStandardDetail();
orderStandardDetail.setDeliveryType(orderDetail.getDeliveryType());
orderStandardDetail.setDeliveryRemark(orderDetail.getDeliveryRemark());
orderStandardDetail.setDeliveryImages(orderDetail.getDeliveryImages());
orderStandardDetail.setTrackingNumber(orderDetail.getTrackingNumber());
orderStandardDetail.setRemark(remark);
orderStandardDetail.setAddMoney(addMoneyTotal);
orderStandardDetail.setOrderDetailId(orderDetail.getId());
@ -1848,7 +1852,7 @@ public class OrderMasterController extends BaseController {
serverMoney=serverMoney.add(leaderMoney);
logger.info("大师傅的服务金额{}大师傅的分成{}",serverMoney,leaderMoney);
Shop shop=shopService.getShop(goods.getShopId());
shop = calculateShopDistance(customerAddress, shop);
shop = calculateShopDistance(orderMaster, shop);
// 编辑返回属性
orderListResponse.setDeliveryType(orderMaster.getDeliveryType());
orderListResponse.setDeliveryRemark(orderMaster.getDeliveryRemark());
@ -2554,108 +2558,87 @@ public class OrderMasterController extends BaseController {
}
/**
* 计算商家与客户地址之间的距离
* @param customerAddress 客户地址信息
/**
* 计算商家与主单地址之间的距离
* @param orderMaster 主单信息
* @param shop 商家信息
* @return 带有距离信息的商家对象
*/
private Shop calculateShopDistance(CustomerAddress customerAddress, Shop shop) {
private Shop calculateShopDistance(OrderMaster orderMaster, Shop shop) {
try {
// 检查客户地址经纬度是否有效
if (customerAddress.getLongitude() != null && customerAddress.getLatitude() != null &&
customerAddress.getLongitude().compareTo(BigDecimal.ZERO) != 0 &&
customerAddress.getLatitude().compareTo(BigDecimal.ZERO) != 0) {
// 直接使用主单地址获取经纬度
logger.info("使用主单地址获取经纬度");
// 使用已有的经纬度计算距离
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
StringBuilder fullAddress = new StringBuilder();
double distance = LocationUtils.getDistanceInMeters(
customerAddress.getLatitude().doubleValue(),
customerAddress.getLongitude().doubleValue(),
shop.getLatitude().doubleValue(),
shop.getLongitude().doubleValue()
);
String distanceStr = String.format("%.2f", distance);
shop.setDistance(distanceStr);
logger.info("使用已有经纬度计算距离成功,商家[{}]与客户地址距离:{}km", shop.getShopName(), distanceStr);
}
} else {
// 客户地址经纬度为空尝试通过地址获取经纬度
logger.info("客户地址经纬度为空,尝试通过地址获取经纬度");
StringBuilder fullAddress = new StringBuilder();
// 构建完整地址
if (customerAddress.getProvinceId() != null) {
SysArea province = sysAreaService.selectById(customerAddress.getProvinceId());
if (province != null) {
fullAddress.append(province.getAreaName());
}
}
if (customerAddress.getCityId() != null) {
SysArea city = sysAreaService.selectById(customerAddress.getCityId());
if (city != null) {
fullAddress.append(city.getAreaName());
}
}
if (customerAddress.getCountryId() != null) {
SysArea area = sysAreaService.selectById(customerAddress.getCountryId());
if (area != null) {
fullAddress.append(area.getAreaName());
}
}
if (customerAddress.getStreetId() != null) {
SysArea street = sysAreaService.selectById(customerAddress.getStreetId());
if (street != null) {
fullAddress.append(street.getAreaName());
}
}
if (StringUtils.isNotEmpty(customerAddress.getAddress())) {
fullAddress.append(customerAddress.getAddress());
}
String addressStr = fullAddress.toString();
logger.info("构建的完整地址:{}", addressStr);
if (StringUtils.isNotEmpty(addressStr)) {
// 调用百度地图API获取经纬度
Map<String, Double> coordinates = baiduMapUtils.getCoordinatesByAddress(shop.getProvinceName(), shop.getCityName(), shop.getCountryName(), shop.getStreetName(), addressStr);
if (coordinates != null && coordinates.containsKey("longitude") && coordinates.containsKey("latitude")) {
BigDecimal lng = new BigDecimal(coordinates.get("longitude").toString());
BigDecimal lat = new BigDecimal(coordinates.get("latitude").toString());
logger.info("通过地址获取到经纬度longitude={}, latitude={}", lng, lat);
// 计算距离
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
double distance = LocationUtils.getDistanceInMeters(
lat.doubleValue(),
lng.doubleValue(),
shop.getLatitude().doubleValue(),
shop.getLongitude().doubleValue()
);
String distanceStr = String.format("%.2f", distance);
shop.setDistance(distanceStr);
logger.info("通过地址获取经纬度后计算距离成功,商家[{}]与客户地址距离:{}km", shop.getShopName(), distanceStr);
}
} else {
logger.warn("通过地址[{}]获取经纬度失败", addressStr);
}
} else {
logger.warn("无法构建完整地址,跳过距离计算");
// 构建完整地址
if (orderMaster.getProvinceId() != null) {
SysArea province = sysAreaService.selectById(orderMaster.getProvinceId());
if (province != null) {
fullAddress.append(province.getAreaName());
}
}
if (orderMaster.getCityId() != null) {
SysArea city = sysAreaService.selectById(orderMaster.getCityId());
if (city != null) {
fullAddress.append(city.getAreaName());
}
}
if (orderMaster.getCountryId() != null) {
SysArea area = sysAreaService.selectById(orderMaster.getCountryId());
if (area != null) {
fullAddress.append(area.getAreaName());
}
}
if (orderMaster.getStreetId() != null) {
SysArea street = sysAreaService.selectById(orderMaster.getStreetId());
if (street != null) {
fullAddress.append(street.getAreaName());
}
}
if (StringUtils.isNotEmpty(orderMaster.getAddress())) {
fullAddress.append(orderMaster.getAddress());
}
String addressStr = fullAddress.toString();
logger.info("构建的完整地址:{}", addressStr);
if (StringUtils.isNotEmpty(addressStr)) {
// 调用百度地图API获取经纬度
Map<String, Double> coordinates = baiduMapUtils.getCoordinatesByAddress(shop.getProvinceName(), shop.getCityName(), shop.getCountryName(), shop.getStreetName(), addressStr);
if (coordinates != null && coordinates.containsKey("longitude") && coordinates.containsKey("latitude")) {
BigDecimal lng = new BigDecimal(coordinates.get("longitude").toString());
BigDecimal lat = new BigDecimal(coordinates.get("latitude").toString());
logger.info("通过地址获取到经纬度longitude={}, latitude={}", lng, lat);
// 计算距离
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
double distance = LocationUtils.getDistanceInMeters(
lat.doubleValue(),
lng.doubleValue(),
shop.getLatitude().doubleValue(),
shop.getLongitude().doubleValue()
);
String formattedDistance = LocationUtils.formatDistance(distance);
shop.setDistance(formattedDistance);
logger.info("通过地址获取经纬度后计算距离成功,商家[{}]与主单地址距离:{}", shop.getShopName(), formattedDistance);
}
} else {
logger.warn("通过地址[{}]获取经纬度失败", addressStr);
}
} else {
logger.warn("无法构建完整地址,跳过距离计算");
}
} catch (Exception e) {
logger.error("计算商家与客户地址距离时发生异常", e);
logger.error("计算商家与主单地址距离时发生异常", e);
}
return shop;

View File

@ -99,4 +99,25 @@ public class OrderStandardDetail {
*/
private String returnImages;
/**
* 发货类型 - 订单的发货方式
*/
private Integer deliveryType;
/**
* 发货备注 - 发货相关备注信息
*/
private String deliveryRemark;
/**
* 发货图片 - 发货凭证图片
*/
private String deliveryImages;
/**
* 快递单号 - 物流跟踪单号
*/
private String trackingNumber;
}

View File

@ -273,4 +273,28 @@ public class OrderDetail extends BaseEntity {
*/
@Excel(name = "分账倒计时时长(小时)")
private Integer shareAccountCountdownDuration;
/**
* 发货类型 - 订单的发货方式
*/
@Excel(name = "发货类型")
private Integer deliveryType;
/**
* 发货备注 - 发货相关备注信息
*/
@Excel(name = "发货备注")
private String deliveryRemark;
/**
* 发货图片 - 发货凭证图片
*/
@Excel(name = "发货图片")
private String deliveryImages;
/**
* 快递单号 - 物流跟踪单号
*/
@Excel(name = "快递单号")
private String trackingNumber;
}

View File

@ -45,6 +45,10 @@
<result property="workerRemark" column="worker_remark"/>
<result property="shareAccountCountdownEndTime" column="share_account_countdown_end_time"/>
<result property="shareAccountCountdownDuration" column="share_account_countdown_duration"/>
<result property="deliveryType" column="delivery_type"/>
<result property="deliveryRemark" column="delivery_remark"/>
<result property="deliveryImages" column="delivery_images"/>
<result property="trackingNumber" column="tracking_number"/>
</resultMap>
<sql id="selectOrderDetail">
@ -85,7 +89,11 @@
worker_remark,
after_service_status,
share_account_countdown_end_time,
share_account_countdown_duration
share_account_countdown_duration,
delivery_type,
delivery_remark,
delivery_images,
tracking_number
FROM order_detail
</sql>
@ -128,7 +136,11 @@
od.worker_remark,
od.after_service_status,
od.share_account_countdown_end_time,
od.share_account_countdown_duration
od.share_account_countdown_duration,
od.delivery_type,
od.delivery_remark,
od.delivery_images,
od.tracking_number
FROM order_detail od
LEFT JOIN order_master om ON om.id = od.order_master_id
LEFT JOIN customer_address ca ON ca.customer_address_id = om.address_id
@ -408,6 +420,10 @@
<if test="afterServiceStatus != null">after_service_status = #{afterServiceStatus},</if>
<if test="shareAccountCountdownEndTime != null">share_account_countdown_end_time = #{shareAccountCountdownEndTime},</if>
<if test="shareAccountCountdownDuration != null">share_account_countdown_duration = #{shareAccountCountdownDuration},</if>
<if test="deliveryType != null">delivery_type = #{deliveryType},</if>
<if test="deliveryRemark != null">delivery_remark = #{deliveryRemark},</if>
<if test="deliveryImages != null">delivery_images = #{deliveryImages},</if>
<if test="trackingNumber != null">tracking_number = #{trackingNumber},</if>
update_time = SYSDATE()
</set>
WHERE id = #{id}
@ -473,6 +489,10 @@
<if test="workerRemark != null">worker_remark,</if>
<if test="shareAccountCountdownEndTime != null">share_account_countdown_end_time,</if>
<if test="shareAccountCountdownDuration != null">share_account_countdown_duration,</if>
<if test="deliveryType != null">delivery_type,</if>
<if test="deliveryRemark != null">delivery_remark,</if>
<if test="deliveryImages != null">delivery_images,</if>
<if test="trackingNumber != null">tracking_number,</if>
<if test="expectTimeStart != null">expect_time_start,</if>
<if test="expectTimeEnd != null">expect_time_end,</if>
<if test="workBeginTime != null">work_begin_time,</if>
@ -499,6 +519,10 @@
<if test="workerRemark != null">#{workerRemark},</if>
<if test="shareAccountCountdownEndTime != null">#{shareAccountCountdownEndTime},</if>
<if test="shareAccountCountdownDuration != null">#{shareAccountCountdownDuration},</if>
<if test="deliveryType != null">#{deliveryType},</if>
<if test="deliveryRemark != null">#{deliveryRemark},</if>
<if test="deliveryImages != null">#{deliveryImages},</if>
<if test="trackingNumber != null">#{trackingNumber},</if>
<if test="expectTimeStart != null">#{expectTimeStart},</if>
<if test="expectTimeEnd != null">#{expectTimeEnd},</if>
<if test="workBeginTime != null">#{workBeginTime},</if>

View File

@ -675,7 +675,9 @@ public class OrderServiceImpl implements OrderService {
// long day14ago = now - 10000L;
for (OrderDetail orderDetail : orderDetails) {
int hours=orderDetail.getShareAccountCountdownDuration();
// 获取倒计时时长如果为null则使用默认值336小时14天
Integer countdownDuration = orderDetail.getShareAccountCountdownDuration();
int hours = countdownDuration != null ? countdownDuration : 1;
// 超时时间
//TODO:修改为后台类目配置时间