feat: 新增计算两点的巨鹿

This commit is contained in:
weizhiqiang 2024-11-15 11:09:24 +08:00
parent 53419da43e
commit aa58aabc30
2 changed files with 26 additions and 0 deletions

View file

@ -75,6 +75,10 @@ public class ShopStore extends AreaInfo {
@ApiModelProperty(value = "纬度")
private String latitude;
@TableField(exist = false)
@Property(value = "两点之间的距离,单位:米")
private Double distance;
@TableField("start_time")
@ApiModelProperty(value = "开始时间")
private String startTime;

View file

@ -16,6 +16,8 @@ import com.skyeye.common.enumeration.WhetherEnum;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.common.util.CalculationUtil;
import com.skyeye.common.util.MapUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.common.util.mybatisplus.MybatisPlusUtil;
import com.skyeye.rest.shopmaterialnorms.rest.IShopMaterialNormsRest;
import com.skyeye.store.dao.ShopStoreDao;
@ -61,10 +63,30 @@ public class ShopStoreServiceImpl extends SkyeyeBusinessServiceImpl<ShopStoreDao
return queryWrapper;
}
@Override
public void setDefaultOrderBy(CommonPageInfo commonPageInfo, QueryWrapper<ShopStore> wrapper) {
if (StrUtil.isNotEmpty(commonPageInfo.getLatitude()) && StrUtil.isNotEmpty(commonPageInfo.getLongitude())) {
// 使用ST_Distance_Sphere函数计算距离并按距离排序
String orderByClause = "ORDER BY ST_Distance_Sphere(point(longitude, latitude), " +
"point(" + commonPageInfo.getLongitude() + ", " + commonPageInfo.getLatitude() + ")) ASC";
wrapper.last(orderByClause);
}
}
@Override
public List<Map<String, Object>> queryPageDataList(InputObject inputObject) {
CommonPageInfo commonPageInfo = inputObject.getParams(CommonPageInfo.class);
List<Map<String, Object>> beans = super.queryPageDataList(inputObject);
shopAreaService.setMationForMap(beans, "shopAreaId", "shopAreaMation");
if (StrUtil.isNotEmpty(commonPageInfo.getLatitude()) && StrUtil.isNotEmpty(commonPageInfo.getLongitude())) {
// 计算距离并添加距离字段
beans.forEach(bean -> {
double distance = ToolUtil.calculateDistance(Double.parseDouble(commonPageInfo.getLatitude()), Double.parseDouble(commonPageInfo.getLongitude()),
Double.parseDouble(MapUtil.checkKeyIsNull(bean, "latitude") ? "0" : bean.get("latitude").toString()),
Double.parseDouble(MapUtil.checkKeyIsNull(bean, "longitude") ? "0" : bean.get("longitude").toString()));
bean.put("distance", distance);
});
}
return beans;
}