增加交货图片备注以及店铺和店铺距离
This commit is contained in:
parent
9ebbcfacf7
commit
e9771921db
|
|
@ -30,6 +30,7 @@ import com.ghy.shop.service.ShopService;
|
||||||
import com.ghy.system.domain.SysArea;
|
import com.ghy.system.domain.SysArea;
|
||||||
import com.ghy.system.service.ISysAreaService;
|
import com.ghy.system.service.ISysAreaService;
|
||||||
import com.ghy.system.service.IWxMsgService;
|
import com.ghy.system.service.IWxMsgService;
|
||||||
|
import com.ghy.common.utils.BaiduMapUtils;
|
||||||
import com.ghy.web.pojo.vo.OrderChangePriceRequest;
|
import com.ghy.web.pojo.vo.OrderChangePriceRequest;
|
||||||
import com.ghy.web.pojo.vo.OrderListResponse;
|
import com.ghy.web.pojo.vo.OrderListResponse;
|
||||||
import com.ghy.web.pojo.vo.OrderStandard;
|
import com.ghy.web.pojo.vo.OrderStandard;
|
||||||
|
|
@ -132,6 +133,9 @@ public class OrderDetailController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private AdapayService adapayService;
|
private AdapayService adapayService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BaiduMapUtils baiduMapUtils;
|
||||||
|
|
||||||
@RequiresPermissions("order:detail:view")
|
@RequiresPermissions("order:detail:view")
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
public String orderDetail() {
|
public String orderDetail() {
|
||||||
|
|
@ -509,7 +513,11 @@ public class OrderDetailController extends BaseController {
|
||||||
}
|
}
|
||||||
logger.info("所有的加价订单{}",financialChangeRecords);
|
logger.info("所有的加价订单{}",financialChangeRecords);
|
||||||
|
|
||||||
Shop shop=shopService.getShop(goods.getShopId());
|
Shop shop=shopService.getShop(goods.getShopId());
|
||||||
|
|
||||||
|
// 计算主单地址与店铺的距离
|
||||||
|
shop = calculateShopDistance(customerAddress, shop);
|
||||||
|
|
||||||
orderListResponse.setShop(shop);
|
orderListResponse.setShop(shop);
|
||||||
// 编辑返回属性
|
// 编辑返回属性
|
||||||
orderListResponse.setTrackingNumber(orderMaster.getTrackingNumber());
|
orderListResponse.setTrackingNumber(orderMaster.getTrackingNumber());
|
||||||
|
|
@ -1701,4 +1709,116 @@ public class OrderDetailController extends BaseController {
|
||||||
return AjaxResult.error("保存子单师傅备注失败:" + e.getMessage());
|
return AjaxResult.error("保存子单师傅备注失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算商家与客户地址之间的距离
|
||||||
|
* @param customerAddress 客户地址信息
|
||||||
|
* @param shop 商家信息
|
||||||
|
* @param string
|
||||||
|
* @return 带有距离信息的商家对象
|
||||||
|
*/
|
||||||
|
private Shop calculateShopDistance(CustomerAddress customerAddress, Shop shop) {
|
||||||
|
try {
|
||||||
|
// 检查客户地址经纬度是否有效
|
||||||
|
if (customerAddress.getLongitude() != null && customerAddress.getLatitude() != null &&
|
||||||
|
customerAddress.getLongitude().compareTo(BigDecimal.ZERO) != 0 &&
|
||||||
|
customerAddress.getLatitude().compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
|
||||||
|
// 使用已有的经纬度计算距离
|
||||||
|
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
|
||||||
|
|
||||||
|
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("无法构建完整地址,跳过距离计算");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("计算商家与客户地址距离时发生异常", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,8 @@ public class OrderMasterController extends BaseController {
|
||||||
private InsuranceService insuranceService;
|
private InsuranceService insuranceService;
|
||||||
@Resource
|
@Resource
|
||||||
private ShopService shopService;
|
private ShopService shopService;
|
||||||
|
@Autowired
|
||||||
|
private BaiduMapUtils baiduMapUtils;
|
||||||
@Resource
|
@Resource
|
||||||
private IInsuranceManagerService insuranceManagerService;
|
private IInsuranceManagerService insuranceManagerService;
|
||||||
|
|
||||||
|
|
@ -1847,6 +1848,7 @@ public class OrderMasterController extends BaseController {
|
||||||
serverMoney=serverMoney.add(leaderMoney);
|
serverMoney=serverMoney.add(leaderMoney);
|
||||||
logger.info("大师傅的服务金额{}大师傅的分成{}",serverMoney,leaderMoney);
|
logger.info("大师傅的服务金额{}大师傅的分成{}",serverMoney,leaderMoney);
|
||||||
Shop shop=shopService.getShop(goods.getShopId());
|
Shop shop=shopService.getShop(goods.getShopId());
|
||||||
|
shop = calculateShopDistance(customerAddress, shop);
|
||||||
// 编辑返回属性
|
// 编辑返回属性
|
||||||
orderListResponse.setDeliveryType(orderMaster.getDeliveryType());
|
orderListResponse.setDeliveryType(orderMaster.getDeliveryType());
|
||||||
orderListResponse.setDeliveryRemark(orderMaster.getDeliveryRemark());
|
orderListResponse.setDeliveryRemark(orderMaster.getDeliveryRemark());
|
||||||
|
|
@ -2551,4 +2553,111 @@ public class OrderMasterController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算商家与客户地址之间的距离
|
||||||
|
* @param customerAddress 客户地址信息
|
||||||
|
* @param shop 商家信息
|
||||||
|
* @return 带有距离信息的商家对象
|
||||||
|
*/
|
||||||
|
private Shop calculateShopDistance(CustomerAddress customerAddress, Shop shop) {
|
||||||
|
try {
|
||||||
|
// 检查客户地址经纬度是否有效
|
||||||
|
if (customerAddress.getLongitude() != null && customerAddress.getLatitude() != null &&
|
||||||
|
customerAddress.getLongitude().compareTo(BigDecimal.ZERO) != 0 &&
|
||||||
|
customerAddress.getLatitude().compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
|
||||||
|
// 使用已有的经纬度计算距离
|
||||||
|
if (shop.getLongitude() != null && shop.getLatitude() != null ) {
|
||||||
|
|
||||||
|
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("无法构建完整地址,跳过距离计算");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("计算商家与客户地址距离时发生异常", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue