Эх сурвалжийг харах

feat(app): 实现场地、课程、赛事、教练搜索列表距离计算功能

- 在 AppHomeServiceImpl 中添加了计算距离的方法
- 在 AppCoursesMapper、AppGameMapper、AppInstructorMapper 和 AppSiteMapper 中增加了经纬度相关字段的查询
- 新增 PositionUtil 工具类用于计算两点之间的距离- 在 SearchVO 和 PlaceVO 中添加了经纬度相关的属性
SheepHy 2 долоо хоног өмнө
parent
commit
fe49073a24

+ 13 - 14
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/AppHomeServiceImpl.java

@@ -6,15 +6,13 @@ import org.jeecg.modules.app.dto.GetPlaceListDTO;
 import org.jeecg.modules.app.dto.SearchDTO;
 import org.jeecg.modules.app.service.IAppHomeService;
 import org.jeecg.modules.app.vo.*;
-import org.jeecg.modules.system.app.entity.AppBanner;
-import org.jeecg.modules.system.app.entity.AppCourses;
-import org.jeecg.modules.system.app.entity.AppInstructor;
-import org.jeecg.modules.system.app.entity.AppSearchHot;
+import org.jeecg.modules.system.app.entity.*;
 import org.jeecg.modules.system.app.mapper.*;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.mapper.SysDepartMapper;
 import org.jeecg.modules.system.mapper.SysUserMapper;
+import org.jeecg.modules.system.util.PositionUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
@@ -147,8 +145,7 @@ public class AppHomeServiceImpl implements IAppHomeService {
         Page<PlaceVO> page = new Page<>(getPlaceListDTO.getCurrent(), getPlaceListDTO.getSize());
         Page<PlaceVO> placeList = appSiteMapper.getPlaceList(page, getPlaceListDTO.getVenueType());
         placeList.getRecords().forEach(placeVO -> {
-            //todo 待申请第三方地图接口
-            placeVO.setKm(0.0)
+            placeVO.setKm(PositionUtil.calculateDistance(getPlaceListDTO.getLatitude(), getPlaceListDTO.getLongitude(), placeVO.getLatitude().doubleValue(), placeVO.getLongitude().doubleValue()))
                     .setCategory(getCategoryName(placeVO.getCategoryId()));
         });
         if(getPlaceListDTO.getVenueType().equals("0-2")
@@ -208,8 +205,8 @@ public class AppHomeServiceImpl implements IAppHomeService {
         Page<SearchVO.SearchPlaceVO> page = new Page<>(searchDTO.getCurrent(), searchDTO.getSize());
         Page<SearchVO.SearchPlaceVO> searchPlaceVOPage = appSiteMapper.convertSearchPlaceVOPage(page, searchDTO);
         searchPlaceVOPage.getRecords().forEach(placeVO -> {
-            //todo 待申请第三方地图接口
-            placeVO.setKm(0.0)
+            AppSite appSite = appSiteMapper.selectById(placeVO.getId());
+            placeVO.setKm(PositionUtil.calculateDistance(searchDTO.getLatitude(), searchDTO.getLongitude(), appSite.getLatitude().doubleValue(), appSite.getLongitude().doubleValue()))
                     .setCategory(getCategoryName(placeVO.getCategoryId()));
         });
         if(searchDTO.getVenueType().equals("0-2")
@@ -253,8 +250,8 @@ public class AppHomeServiceImpl implements IAppHomeService {
         Page<SearchVO.SearchTrainVO> page = new Page<>(searchDTO.getCurrent(), searchDTO.getSize());
         Page<SearchVO.SearchTrainVO> searchTrainVOPage = appCoursesMapper.convertSearchTrainVOPage(page, searchDTO);
         searchTrainVOPage.getRecords().forEach(trainVO -> {
-            //todo 待申请第三方地图接口
-            trainVO.setKm(0.0);
+            AppSite appSite = appSiteMapper.selectById(trainVO.getSiteId());
+            trainVO.setKm(PositionUtil.calculateDistance(searchDTO.getLatitude(), searchDTO.getLongitude(), appSite.getLatitude().doubleValue(), appSite.getLongitude().doubleValue()));
         });
         return searchTrainVOPage;
     }
@@ -270,15 +267,16 @@ public class AppHomeServiceImpl implements IAppHomeService {
         Page<SearchVO.SearchRaceVO> page = new Page<>(searchDTO.getCurrent(), searchDTO.getSize());
         Page<SearchVO.SearchRaceVO> searchCompetitionVOPage = appGameMapper.convertSearchCompetitionVOPage(page, searchDTO);
         searchCompetitionVOPage.getRecords().forEach(competitionVO -> {
-            //todo 待申请第三方地图接口
-            competitionVO.setKm(0.0);
+            AppSite appSite = appSiteMapper.selectOne(Wrappers.<AppSite>lambdaQuery().eq(AppSite::getOrgCode,competitionVO.getOrgCode()));
+            competitionVO.setKm(PositionUtil.calculateDistance(searchDTO.getLatitude(), searchDTO.getLongitude(), appSite.getLatitude().doubleValue(), appSite.getLongitude().doubleValue()));
+
         });
         return page;
     }
     
     /** 
      * @Author SheepHy
-     * @Description //TODO 
+     * @Description
      * @Date 14:43 2025/7/7
      * @Param searchDTO {@link SearchDTO}
      * @return Page<SearchVO.SearchInstructorVO>
@@ -297,7 +295,8 @@ public class AppHomeServiceImpl implements IAppHomeService {
                         return vo;
                     })
                     .collect(Collectors.toList());
-            instructorVO.setKm(0.0)
+            AppSite appSite = appSiteMapper.selectOne(Wrappers.<AppSite>lambdaQuery().eq(AppSite::getOrgCode, instructorVO.getOrgCode()));
+            instructorVO.setKm(PositionUtil.calculateDistance(searchDTO.getLatitude(), searchDTO.getLongitude(), appSite.getLatitude().doubleValue(), appSite.getLongitude().doubleValue()))
                     .setCourseList(courseInfoVOS);
         });
         return searchInstructorVOPage;

+ 4 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/PlaceVO.java

@@ -32,5 +32,9 @@ public class PlaceVO extends Page<PlaceVO> {
     private List<String> category;
     @Schema(hidden = true)
     private String categoryId;
+    @Schema(description ="经度")
+    private BigDecimal longitude;
+    @Schema(description ="纬度")
+    private BigDecimal latitude;
 
 }

+ 6 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/SearchVO.java

@@ -40,6 +40,8 @@ public class SearchVO{
         private String excelMsg;
         @Schema(description = "km")
         private double km;
+        @Schema(hidden = true)
+        private String orgCode;
         @Schema(description = "教学理念")
         private String teachingPhilosophy;
         @Schema(description = "好评率")
@@ -87,6 +89,8 @@ public class SearchVO{
         private BigDecimal sellingPrice;
         @Schema(description = "图片")
         private String cover;
+        @Schema(hidden = true)
+        private String orgCode;
         @Schema(description = "类目")
         private String categoryId;
         @Schema(description = "开始时间")
@@ -128,6 +132,8 @@ public class SearchVO{
         private int refundType;
         @Schema(description = "地址")
         private String address;
+        @Schema(hidden = true)
+        private String siteId;
         @Schema(description = "距离(KM)")
         private double km;
         @Schema(description = "课程开始时间")

+ 2 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppCoursesMapper.xml

@@ -12,7 +12,8 @@
             COALESCE(d.sales, 0) AS sales,
             a.good_rate,
             a.start_time,
-            a.end_time
+            a.end_time,
+            b.id AS siteId
         FROM
             nm_courses a
                 LEFT JOIN nm_site b ON a.tenant_id = b.tenant_id

+ 1 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppGameMapper.xml

@@ -9,6 +9,7 @@
             COALESCE(g.min_original_price, 0) AS original_price,
             COALESCE(g.min_selling_price, 0) AS selling_price,
             a.address,
+            a.org_code AS orgCode
             CASE
                 WHEN a.application_end_time >= NOW() THEN TRUE
                 ELSE FALSE

+ 1 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppInstructorMapper.xml

@@ -12,6 +12,7 @@
             a.good_rate,
             a.classes_number,
             b.id AS userId,
+            a.org_code AS orgCode,
             COUNT( DISTINCT d.user_id, c2.id ) AS orderCount
         FROM
             nm_instructor a

+ 3 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppSiteMapper.xml

@@ -8,6 +8,8 @@
             a.good_rate AS goodRate,
             a.address,
             a.category_id,
+            a.latitude,
+            a.longitude,
             CASE
                 WHEN EXISTS (
                     SELECT SUM(inventory)
@@ -18,7 +20,7 @@
                 END AS ticketWhether
         FROM nm_site a LEFT JOIN sys_depart b ON a.tenant_id = b.id WHERE 1=1
         <if test="venueType != null and venueType == '0-1'">
-            ORDER BY  a.good_rate DESC
+            ORDER BY a.good_rate DESC
         </if>
         <if test="venueType != null and venueType == '1-1'">
             AND b.org_category = 2

+ 3 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/util/PositionUtil.java

@@ -11,6 +11,9 @@ public class PositionUtil {
      * @return 两点之间的直线距离(单位:公里)
      */
     public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
+        if (lat1 == lat2 && lon1 == lon2) {
+            return 0; // 两点相同时返回0
+        }
         final int EARTH_RADIUS_KM = 6371; // 地球平均半径,单位:公里
         // 将角度转换为弧度
         double lat1Rad = Math.toRadians(lat1);