fix(订单中心):首页附近景区列表数据逻辑优化,删除用户为直接删除数据逻辑优化
This commit is contained in:
+84
-2
@@ -6,6 +6,7 @@ import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.service.ITourismService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -18,17 +19,21 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tourism information
|
||||
* 景区管理控制器
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:51:47
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "Tourism管理")
|
||||
@Tag(name = "景区管理")
|
||||
@RequestMapping("/tourism")
|
||||
@RequiredArgsConstructor
|
||||
public class TourismController {
|
||||
@@ -91,4 +96,81 @@ public class TourismController {
|
||||
return Result.failed("获取景区设备列表失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
*/
|
||||
@Operation(summary = "查询附近景区列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "longitude", description = "经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "latitude", description = "纬度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "radius", description = "搜索半径(公里),默认10km", required = false, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "limit", description = "返回数量限制,默认20个", required = false, in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/nearby")
|
||||
public Result<List<TourismWithDistance>> findNearbyTourisms(
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude,
|
||||
@RequestParam(required = false) Double radius,
|
||||
@RequestParam(required = false) Integer limit) {
|
||||
try {
|
||||
log.info("查询附近景区,经度: {}, 纬度: {}, 半径: {}km, 限制数量: {}", longitude, latitude, radius, limit);
|
||||
List<TourismWithDistance> tourisms = tourismService.findNearbyTourisms(longitude, latitude, radius, limit);
|
||||
return Result.succeed(tourisms, "查询附近景区成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询附近景区失败", e);
|
||||
return Result.failed("查询附近景区失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度范围查询景区
|
||||
*/
|
||||
@Operation(summary = "根据经纬度范围查询景区")
|
||||
@Parameters({
|
||||
@Parameter(name = "minLongitude", description = "最小经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "maxLongitude", description = "最大经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "minLatitude", description = "最小纬度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "maxLatitude", description = "最大纬度", required = true, in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/bounds")
|
||||
public Result<List<Tourism>> findTourismsByBounds(
|
||||
@RequestParam BigDecimal minLongitude,
|
||||
@RequestParam BigDecimal maxLongitude,
|
||||
@RequestParam BigDecimal minLatitude,
|
||||
@RequestParam BigDecimal maxLatitude) {
|
||||
try {
|
||||
log.info("根据经纬度范围查询景区,经度范围: [{}, {}], 纬度范围: [{}, {}]",
|
||||
minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
List<Tourism> tourisms = tourismService.findTourismsByBounds(minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
return Result.succeed(tourisms, "查询景区成功");
|
||||
} catch (Exception e) {
|
||||
log.error("根据经纬度范围查询景区失败", e);
|
||||
return Result.failed("查询景区失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新景区经纬度信息
|
||||
*/
|
||||
@Operation(summary = "更新景区经纬度信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "景区ID", required = true, in = ParameterIn.PATH),
|
||||
@Parameter(name = "longitude", description = "经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "latitude", description = "纬度", required = true, in = ParameterIn.QUERY)
|
||||
})
|
||||
@PutMapping("/{id}/location")
|
||||
public Result updateTourismLocation(
|
||||
@PathVariable Long id,
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude) {
|
||||
try {
|
||||
log.info("更新景区经纬度信息,景区ID: {}, 经度: {}, 纬度: {}", id, longitude, latitude);
|
||||
return tourismService.updateTourismLocation(id, longitude, latitude);
|
||||
} catch (Exception e) {
|
||||
log.error("更新景区经纬度信息失败", e);
|
||||
return Result.failed("更新景区经纬度信息失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.central.order.mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,4 +42,34 @@ public interface TourismMapper extends SuperMapper<Tourism> {
|
||||
*/
|
||||
List<Map<String, Object>> getDevicesByTourismId(@Param("tourismId") Long tourismId);
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @param radius 搜索半径(公里)
|
||||
* @param limit 返回数量限制
|
||||
* @return 附近景区列表(包含距离信息)
|
||||
*/
|
||||
List<TourismWithDistance> findNearbyTourisms(
|
||||
@Param("longitude") BigDecimal longitude,
|
||||
@Param("latitude") BigDecimal latitude,
|
||||
@Param("radius") Double radius,
|
||||
@Param("limit") Integer limit
|
||||
);
|
||||
|
||||
/**
|
||||
* 根据经纬度范围查询景区
|
||||
* @param minLongitude 最小经度
|
||||
* @param maxLongitude 最大经度
|
||||
* @param minLatitude 最小纬度
|
||||
* @param maxLatitude 最大纬度
|
||||
* @return 景区列表
|
||||
*/
|
||||
List<Tourism> findTourismsByBounds(
|
||||
@Param("minLongitude") BigDecimal minLongitude,
|
||||
@Param("maxLongitude") BigDecimal maxLongitude,
|
||||
@Param("minLatitude") BigDecimal minLatitude,
|
||||
@Param("maxLatitude") BigDecimal maxLatitude
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Device information
|
||||
* 景区信息实体类
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:51:47
|
||||
@@ -34,6 +35,16 @@ public class Tourism extends SuperEntity {
|
||||
private String tourismPhone;
|
||||
private String tourismEmail;
|
||||
|
||||
/**
|
||||
* 景区经度
|
||||
*/
|
||||
private BigDecimal longitude;
|
||||
|
||||
/**
|
||||
* 景区纬度
|
||||
*/
|
||||
private BigDecimal latitude;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
|
||||
+34
-1
@@ -4,11 +4,14 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Firmware file information
|
||||
* 景区信息服务接口
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:52:54
|
||||
@@ -43,5 +46,35 @@ public interface ITourismService extends ISuperService<Tourism> {
|
||||
* @return 设备列表
|
||||
*/
|
||||
java.util.List<java.util.Map<String, Object>> getDevicesByTourismId(Long tourismId);
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @param radius 搜索半径(公里)
|
||||
* @param limit 返回数量限制
|
||||
* @return 附近景区列表(包含距离信息)
|
||||
*/
|
||||
List<TourismWithDistance> findNearbyTourisms(BigDecimal longitude, BigDecimal latitude, Double radius, Integer limit);
|
||||
|
||||
/**
|
||||
* 根据经纬度范围查询景区
|
||||
* @param minLongitude 最小经度
|
||||
* @param maxLongitude 最大经度
|
||||
* @param minLatitude 最小纬度
|
||||
* @param maxLatitude 最大纬度
|
||||
* @return 景区列表
|
||||
*/
|
||||
List<Tourism> findTourismsByBounds(BigDecimal minLongitude, BigDecimal maxLongitude,
|
||||
BigDecimal minLatitude, BigDecimal maxLatitude);
|
||||
|
||||
/**
|
||||
* 更新景区经纬度信息
|
||||
* @param id 景区ID
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @return 更新结果
|
||||
*/
|
||||
Result updateTourismLocation(Long id, BigDecimal longitude, BigDecimal latitude);
|
||||
}
|
||||
|
||||
|
||||
+121
-1
@@ -6,16 +6,22 @@ import com.central.common.model.Result;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.mapper.TourismMapper;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.service.ITourismService;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Order information
|
||||
* 景区信息服务实现类
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:52:54
|
||||
@@ -24,6 +30,12 @@ import java.util.Map;
|
||||
@Service
|
||||
public class TourismServiceImpl extends SuperServiceImpl<TourismMapper, Tourism> implements ITourismService {
|
||||
|
||||
@Autowired
|
||||
private ITourismFileService tourismFileService;
|
||||
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
@@ -52,4 +64,112 @@ public class TourismServiceImpl extends SuperServiceImpl<TourismMapper, Tourism>
|
||||
return baseMapper.getDevicesByTourismId(tourismId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TourismWithDistance> findNearbyTourisms(BigDecimal longitude, BigDecimal latitude, Double radius, Integer limit) {
|
||||
log.info("查询附近景区,经度: {}, 纬度: {}, 半径: {}km, 限制数量: {}", longitude, latitude, radius, limit);
|
||||
|
||||
// 参数验证
|
||||
if (longitude == null || latitude == null) {
|
||||
log.warn("经纬度参数不能为空");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
if (radius == null || radius <= 0) {
|
||||
radius = 10.0; // 默认10公里
|
||||
}
|
||||
|
||||
if (limit == null || limit <= 0) {
|
||||
limit = 20; // 默认返回20个
|
||||
}
|
||||
|
||||
List<TourismWithDistance> tourisms = baseMapper.findNearbyTourisms(longitude, latitude, radius, limit);
|
||||
log.info("查询到附近景区数量: {}", tourisms.size());
|
||||
|
||||
// 为每个景区添加订单展示图片
|
||||
for (TourismWithDistance tourism : tourisms) {
|
||||
try {
|
||||
// 查询景区的订单展示图片(type=6)
|
||||
List<TourismFile> tourismFiles = tourismFileService.getByTourismId(tourism.getId());
|
||||
if (tourismFiles != null && !tourismFiles.isEmpty()) {
|
||||
// 查找订单展示图(type=6)
|
||||
TourismFile orderShowFile = tourismFiles.stream()
|
||||
.filter(file -> file.getType() == 6)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (orderShowFile != null && orderShowFile.getImageUrl() != null) {
|
||||
// 获取图片的完整URL
|
||||
String imageUrl = fileCenterService.getViewUrlByPath(orderShowFile.getImageUrl());
|
||||
tourism.setOrderShowImageUrl(imageUrl);
|
||||
log.debug("景区 {} 设置订单展示图片: {}", tourism.getTourismName(), imageUrl);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取景区 {} 订单展示图片失败: {}", tourism.getTourismName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return tourisms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tourism> findTourismsByBounds(BigDecimal minLongitude, BigDecimal maxLongitude,
|
||||
BigDecimal minLatitude, BigDecimal maxLatitude) {
|
||||
log.info("根据经纬度范围查询景区,经度范围: [{}, {}], 纬度范围: [{}, {}]",
|
||||
minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
|
||||
// 参数验证
|
||||
if (minLongitude == null || maxLongitude == null || minLatitude == null || maxLatitude == null) {
|
||||
log.warn("经纬度范围参数不能为空");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<Tourism> tourisms = baseMapper.findTourismsByBounds(minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
log.info("查询到景区数量: {}", tourisms.size());
|
||||
|
||||
return tourisms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateTourismLocation(Long id, BigDecimal longitude, BigDecimal latitude) {
|
||||
log.info("更新景区经纬度信息,景区ID: {}, 经度: {}, 纬度: {}", id, longitude, latitude);
|
||||
|
||||
// 参数验证
|
||||
if (id == null) {
|
||||
return Result.failed("景区ID不能为空");
|
||||
}
|
||||
|
||||
if (longitude == null || latitude == null) {
|
||||
return Result.failed("经纬度不能为空");
|
||||
}
|
||||
|
||||
// 验证经纬度范围
|
||||
if (longitude.compareTo(BigDecimal.valueOf(-180)) < 0 || longitude.compareTo(BigDecimal.valueOf(180)) > 0) {
|
||||
return Result.failed("经度范围应在-180到180之间");
|
||||
}
|
||||
|
||||
if (latitude.compareTo(BigDecimal.valueOf(-90)) < 0 || latitude.compareTo(BigDecimal.valueOf(90)) > 0) {
|
||||
return Result.failed("纬度范围应在-90到90之间");
|
||||
}
|
||||
|
||||
// 查询景区是否存在
|
||||
Tourism tourism = getById(id);
|
||||
if (tourism == null) {
|
||||
return Result.failed("景区不存在");
|
||||
}
|
||||
|
||||
// 更新经纬度
|
||||
tourism.setLongitude(longitude);
|
||||
tourism.setLatitude(latitude);
|
||||
|
||||
boolean result = updateById(tourism);
|
||||
if (result) {
|
||||
log.info("景区经纬度更新成功,景区ID: {}", id);
|
||||
return Result.succeed(tourism, "经纬度更新成功");
|
||||
} else {
|
||||
log.error("景区经纬度更新失败,景区ID: {}", id);
|
||||
return Result.failed("经纬度更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,42 @@
|
||||
AND t.is_del = 0
|
||||
ORDER BY q.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询附近景区列表 -->
|
||||
<select id="findNearbyTourisms" resultType="com.central.order.model.TourismWithDistance">
|
||||
<![CDATA[
|
||||
SELECT
|
||||
*,
|
||||
(
|
||||
6371 * acos(
|
||||
cos(radians(#{latitude})) *
|
||||
cos(radians(latitude)) *
|
||||
cos(radians(longitude) - radians(#{longitude})) +
|
||||
sin(radians(#{latitude})) *
|
||||
sin(radians(latitude))
|
||||
)
|
||||
) AS distance
|
||||
FROM tourisms
|
||||
WHERE is_del = 0
|
||||
AND status = 1
|
||||
AND longitude IS NOT NULL
|
||||
AND latitude IS NOT NULL
|
||||
HAVING distance <= #{radius}
|
||||
ORDER BY distance ASC
|
||||
]]>
|
||||
<if test="limit != null and limit > 0">
|
||||
LIMIT #{limit}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据经纬度范围查询景区 -->
|
||||
<select id="findTourismsByBounds" resultType="com.central.order.model.Tourism">
|
||||
SELECT * FROM tourisms
|
||||
WHERE is_del = 0
|
||||
AND status = 1
|
||||
AND longitude BETWEEN #{minLongitude} AND #{maxLongitude}
|
||||
AND latitude BETWEEN #{minLatitude} AND #{maxLatitude}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user