Browse Source

商家接口返回主营服务

liude 11 tháng trước cách đây
mục cha
commit
3e644b3004

+ 13 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/HotMerchantServiceImpl.java

@@ -5,9 +5,13 @@ import com.chelvc.cloud.vehicle.client.dto.MerchantDTO;
 import com.chelvc.cloud.vehicle.client.param.LocationQueryParam;
 import com.chelvc.cloud.vehicle.server.dao.HotMerchantMapper;
 import com.chelvc.cloud.vehicle.server.entity.HotMerchant;
+import com.chelvc.cloud.vehicle.server.service.CategoryService;
 import com.chelvc.cloud.vehicle.server.service.HotMerchantService;
 import com.chelvc.framework.base.context.SessionContextHolder;
 import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import javax.validation.Valid;
@@ -21,7 +25,11 @@ import java.util.List;
  * @date 2023/12/16
  */
 @Service
+@RequiredArgsConstructor(onConstructor = @__({@Autowired, @Lazy}))
 public class HotMerchantServiceImpl extends ServiceImpl<HotMerchantMapper, HotMerchant> implements HotMerchantService{
+
+    private final CategoryService categoryService;
+
     @Override
     public Long addHotMerchant(@NonNull Long id) {
         HotMerchant hotMerchant = new HotMerchant();
@@ -44,6 +52,10 @@ public class HotMerchantServiceImpl extends ServiceImpl<HotMerchantMapper, HotMe
     @Override
     public List<MerchantDTO> likeMerchant(@Valid LocationQueryParam param){
         Long userId = SessionContextHolder.getId();
-        return this.baseMapper.likeMerchant(userId,param);
+        List<MerchantDTO> list = this.baseMapper.likeMerchant(userId,param);
+        list.forEach(item ->{
+            item.setMainBusinessName(this.categoryService.getById(item.getMainBusiness()).getName());
+        });
+        return list;
     }
  }

+ 16 - 2
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantServiceImpl.java

@@ -66,7 +66,11 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
 
     @Override
     public List<MerchantDTO> listNearbyMerchants(@NonNull LocationQueryParam param, int size) {
-        return this.baseMapper.listNearbyMerchants(param, size);
+        List<MerchantDTO> list = this.baseMapper.listNearbyMerchants(param, size);
+        list.forEach(item ->{
+            item.setMainBusinessName(this.categoryService.getById(item.getMainBusiness()).getName());
+        });
+        return list;
     }
 
     @Override
@@ -76,16 +80,26 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
         iPage.setSize(param.getPaging().getSize());
         if (0 == param.getQueryType()){
             Page<MerchantDTO> list = this.baseMapper.listNearbyMerchantPaging(iPage,param);
+            list.getRecords().forEach(item ->{
+                item.setMainBusinessName(this.categoryService.getById(item.getMainBusiness()).getName());
+            });
             return DatabaseContextHolder.pagination(list);
         }else{
             Page<MerchantDTO> page = this.baseMapper.listRecommendMerchantPaging(iPage,param);
+            page.getRecords().forEach(item ->{
+                item.setMainBusinessName(this.categoryService.getById(item.getMainBusiness()).getName());
+            });
             return DatabaseContextHolder.pagination(page);
         }
     }
 
     @Override
     public List<MerchantDTO> listRecommendMerchants(@NonNull LocationQueryParam param, int size) {
-        return this.baseMapper.listRecommendMerchants(param, size);
+        List<MerchantDTO> list = this.baseMapper.listRecommendMerchants(param, size);
+        list.forEach(item ->{
+            item.setMainBusinessName(this.categoryService.getById(item.getMainBusiness()).getName());
+        });
+        return list;
     }
 
     @Override

+ 4 - 2
vehicle-server/src/main/resources/mapper/HotmerchantMapper.xml

@@ -19,14 +19,16 @@
     <select id="likeMerchant" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO" parameterType="com.chelvc.cloud.vehicle.client.param.LocationQueryParam">
         select mt.id, mt.user_id as userId, mt.name, mt.logo, mt.banners, mt.liaison, mt.mobile,
                mt.opening, mt.address, mt.score, mt.sale, mt.good_review as goodReview,mt.region, mt.longitude,
-               mt.latitude, mt.recommend, mt.status, mt.creator,
+               mt.latitude, mt.recommend, mt.status, mt.creator,ca.name as mainBusinessName,mt.main_business,
                mt.create_time as createTime,
             round(st_distance_sphere(
                        point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
                    )) distance
             FROM
                 ( SELECT merchant_id,user_id, count( merchant_id) FROM hot_merchant GROUP BY merchant_id,user_id ORDER BY count( merchant_id ) DESC ) t
-                LEFT JOIN merchant mt ON t.merchant_id = mt.id where t.user_id = #{userId}
+                LEFT JOIN merchant mt ON t.merchant_id = mt.id
+                left join category ca on mt.main_business = ca.id
+                where t.user_id = #{userId}
                 and mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE' and mt.recommend = 1
             order by distance asc limit 10
     </select>

+ 4 - 4
vehicle-server/src/main/resources/mapper/MerchantMapper.xml

@@ -9,7 +9,7 @@
     </sql>
 
     <select id="listNearbyMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
-        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,
+        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
         round(st_distance_sphere(
             point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
         )) distance
@@ -20,7 +20,7 @@
 
 
     <select id="listNearbyMerchantPaging" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
-        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,
+        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
                round(st_distance_sphere(
                        point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
                    )) distance
@@ -30,7 +30,7 @@
     </select>
 
     <select id="listRecommendMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
-        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,
+        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
         round(st_distance_sphere(
             point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
         )) distance
@@ -41,7 +41,7 @@
 
 
     <select id="listRecommendMerchantPaging" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
-        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,
+        select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
                round(st_distance_sphere(
                        point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
                    )) distance