|
@@ -1,23 +1,31 @@
|
|
|
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.context.SessionContextHolder;
|
|
|
+import com.chelvc.framework.location.Address;
|
|
|
+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.util.StringUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
/**
|
|
@@ -30,7 +38,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 +51,6 @@ public class IndexController {
|
|
|
@DubboReference
|
|
|
private MerchantService merchantService;
|
|
|
|
|
|
- /**
|
|
|
- * 获取附近距离配置
|
|
|
- *
|
|
|
- * @return 距离(米)
|
|
|
- */
|
|
|
- private int getNearbyDistance() {
|
|
|
- return ApplicationContextHolder.getSafeProperty("platform.nearby.distance", int.class, 20000);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取系统配置
|
|
|
*
|
|
@@ -59,11 +61,25 @@ public class IndexController {
|
|
|
return ConfigurationVO.builder().build();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前位置
|
|
|
+ *
|
|
|
+ * @param point 经纬度(如:30.563443,104.009457),如果为空则根据IP获取位置信息
|
|
|
+ * @return 位置信息
|
|
|
+ */
|
|
|
+ @GetMapping("/location")
|
|
|
+ public Address getLocation(@RequestParam(value = "point", required = false) String point) {
|
|
|
+ if (StringUtils.isEmpty(point)) {
|
|
|
+ return this.locationHandler.ip2address(SessionContextHolder.getHost());
|
|
|
+ }
|
|
|
+ return this.locationHandler.location2address(point);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 刷新用户使用记录
|
|
|
*/
|
|
|
@PostMapping("/usage")
|
|
|
- public void using() {
|
|
|
+ public void refreshUsage() {
|
|
|
this.usageService.refresh();
|
|
|
}
|
|
|
|
|
@@ -74,28 +90,29 @@ 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) {
|
|
|
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(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(param, 4);
|
|
|
+ index.setRecommends(MerchantCopier.INSTANCE.copying(merchants));
|
|
|
} catch (Exception e) {
|
|
|
log.error("Load recommend merchants failed", e);
|
|
|
}
|