|
@@ -1,20 +1,27 @@
|
|
|
package com.chelvc.cloud.maintain.controller;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
import com.chelvc.cloud.maintain.copier.CategoryCopier;
|
|
|
import com.chelvc.cloud.maintain.copier.MerchantCopier;
|
|
|
-import com.chelvc.cloud.maintain.param.CustomerIndexParam;
|
|
|
import com.chelvc.cloud.maintain.vo.ConfigurationVO;
|
|
|
import com.chelvc.cloud.maintain.vo.CustomerIndexVO;
|
|
|
import com.chelvc.cloud.uc.api.service.UsageService;
|
|
|
-import com.chelvc.cloud.vehicle.api.param.NearbyQueryParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.LocationQueryParam;
|
|
|
import com.chelvc.cloud.vehicle.api.service.CategoryService;
|
|
|
import com.chelvc.cloud.vehicle.api.service.MerchantService;
|
|
|
import com.chelvc.framework.base.annotation.UnifiedResponseBody;
|
|
|
-import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
+import com.chelvc.framework.base.util.ObjectUtils;
|
|
|
+import com.chelvc.framework.location.Address;
|
|
|
+import com.chelvc.framework.location.Area;
|
|
|
+import com.chelvc.framework.location.LocationHandler;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -30,7 +37,10 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@Validated
|
|
|
@RestController
|
|
|
@UnifiedResponseBody
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
public class IndexController {
|
|
|
+ private final LocationHandler locationHandler;
|
|
|
+
|
|
|
@DubboReference
|
|
|
private UsageService usageService;
|
|
|
|
|
@@ -40,15 +50,6 @@ public class IndexController {
|
|
|
@DubboReference
|
|
|
private MerchantService merchantService;
|
|
|
|
|
|
- /**
|
|
|
- * 获取附近距离配置
|
|
|
- *
|
|
|
- * @return 距离(米)
|
|
|
- */
|
|
|
- private int getNearbyDistance() {
|
|
|
- return ApplicationContextHolder.getSafeProperty("platform.nearby.distance", int.class, 20000);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取系统配置
|
|
|
*
|
|
@@ -74,28 +75,35 @@ public class IndexController {
|
|
|
* @return 首页信息
|
|
|
*/
|
|
|
@GetMapping("/customer/index")
|
|
|
- public CustomerIndexVO getCustomerIndex(@Valid CustomerIndexParam param) {
|
|
|
- NearbyQueryParam query = NearbyQueryParam.builder().longitude(param.getLongitude())
|
|
|
- .latitude(param.getLatitude()).distance(this.getNearbyDistance()).build();
|
|
|
+ public CustomerIndexVO getCustomerIndex(@Valid LocationQueryParam param) {
|
|
|
+ // 通过经纬度定位所属城市地区
|
|
|
+ Address address = this.locationHandler.location2address(param.getLongitude(), param.getLatitude());
|
|
|
+ int region = ObjectUtils.ifNull(
|
|
|
+ ObjectUtils.ifNull(ObjectUtils.ifNull(address, Address::getCity), Area::getId), 0
|
|
|
+ );
|
|
|
+
|
|
|
CustomerIndexVO index = CustomerIndexVO.builder().build();
|
|
|
|
|
|
// 加载推荐分类列表
|
|
|
try {
|
|
|
- index.setCategories(CategoryCopier.INSTANCE.copying(this.categoryService.listRecommendCategories(15)));
|
|
|
+ List<CategoryDTO> categories = this.categoryService.listRecommendCategories(15);
|
|
|
+ index.setCategories(CategoryCopier.INSTANCE.copying(categories));
|
|
|
} catch (Exception e) {
|
|
|
log.error("Load recommend categories failed", e);
|
|
|
}
|
|
|
|
|
|
// 加载附近商家列表
|
|
|
try {
|
|
|
- index.setNears(MerchantCopier.INSTANCE.copying(this.merchantService.listNearbyMerchants(query, 4)));
|
|
|
+ List<MerchantDTO> merchants = this.merchantService.listNearbyMerchants(region, param, 4);
|
|
|
+ index.setNears(MerchantCopier.INSTANCE.copying(merchants));
|
|
|
} catch (Exception e) {
|
|
|
log.error("Load nearby merchants failed", e);
|
|
|
}
|
|
|
|
|
|
// 加载推荐商家列表
|
|
|
try {
|
|
|
- index.setRecommends(MerchantCopier.INSTANCE.copying(this.merchantService.listRecommendMerchants(query, 4)));
|
|
|
+ List<MerchantDTO> merchants = this.merchantService.listRecommendMerchants(region, param, 4);
|
|
|
+ index.setRecommends(MerchantCopier.INSTANCE.copying(merchants));
|
|
|
} catch (Exception e) {
|
|
|
log.error("Load recommend merchants failed", e);
|
|
|
}
|