|
|
@@ -1,17 +1,24 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.uc.api.dto.UserDTO;
|
|
|
import com.chelvc.cloud.uc.api.service.EmployeeService;
|
|
|
+import com.chelvc.cloud.uc.api.service.UserService;
|
|
|
import com.chelvc.cloud.vehicle.api.constant.MerchantStatus;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.GoodsDTO;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.MerchantDetailDTO;
|
|
|
import com.chelvc.cloud.vehicle.api.param.*;
|
|
|
+import com.chelvc.cloud.vehicle.api.util.DateTimeUtils;
|
|
|
import com.chelvc.cloud.vehicle.server.copier.MerchantCopier;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.MerchantMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.RegionMapper;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Merchant;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.Region;
|
|
|
import com.chelvc.cloud.vehicle.server.service.CategoryService;
|
|
|
import com.chelvc.cloud.vehicle.server.service.GoodsService;
|
|
|
import com.chelvc.cloud.vehicle.server.service.MerchantService;
|
|
|
@@ -20,12 +27,18 @@ import com.chelvc.framework.base.util.ResourceUtils;
|
|
|
import com.chelvc.framework.common.model.Pagination;
|
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.chelvc.framework.database.util.PagingUtils;
|
|
|
+import com.chelvc.framework.location.Address;
|
|
|
+import com.chelvc.framework.location.LocationHandler;
|
|
|
+import com.chelvc.framework.redis.RedisConstant;
|
|
|
import lombok.NonNull;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -44,9 +57,18 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
|
|
|
|
private final CategoryService categoryService;
|
|
|
|
|
|
+ private final RedisTemplate<String, Serializable> redisTemplate;
|
|
|
+
|
|
|
+ private final LocationHandler locationHandler;
|
|
|
+
|
|
|
+ private final RegionMapper regionMapper;
|
|
|
+
|
|
|
@DubboReference
|
|
|
EmployeeService employeeService;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<MerchantDTO> listNearbyMerchants(@NonNull LocationQueryParam param, int size) {
|
|
|
return this.baseMapper.listNearbyMerchants(param, size);
|
|
|
@@ -198,8 +220,54 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
|
.list();
|
|
|
return MerchantCopier.INSTANCE.copying(merchants);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MerchantDTO> listRankMerchants(MerchantRankParam param, Long userId) {
|
|
|
+ List<MerchantDTO> result = new ArrayList<>();
|
|
|
+ Integer regionId = param.getRegionId();
|
|
|
+ Double longitude = (double) 0;
|
|
|
+ Double latitude = (double) 0;
|
|
|
+ if(regionId == null){
|
|
|
+ if(Boolean.TRUE.equals(redisTemplate.hasKey(RedisConstant.USER_ADDRESS + userId))){
|
|
|
+ Address address = (Address)redisTemplate.opsForValue().get(RedisConstant.USER_ADDRESS + userId);
|
|
|
+ if(address != null){
|
|
|
+ regionId = address.getDistrict().getId();
|
|
|
+ longitude = address.getLongitude();
|
|
|
+ latitude = address.getLatitude();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(regionId == null){
|
|
|
+ UserDTO user = userService.getUser(userId);
|
|
|
+ if(user == null){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Address address = locationHandler.ip2address(user.getHost());
|
|
|
+ if(address == null){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ regionId = address.getDistrict().getId();
|
|
|
+ longitude = address.getLongitude();
|
|
|
+ latitude = address.getLatitude();
|
|
|
+ }
|
|
|
+ Region region = regionMapper.selectById(regionId);
|
|
|
+ if(region == null){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ result = baseMapper.listRankMerchants(DateTimeUtils.getMonthStartLocalTime(), regionId, longitude, latitude, region.getLevel());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public MerchantDTO getMerchantById(Long merchantId){
|
|
|
return MerchantCopier.INSTANCE.copying(this.getById(merchantId));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getMerchantName(Long merchantId) {
|
|
|
+ LambdaQueryWrapper<Merchant> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(Merchant::getUserId, merchantId);
|
|
|
+ Merchant merchant = baseMapper.selectOne(wrapper);
|
|
|
+ return merchant != null ? merchant.getName() : "";
|
|
|
+ }
|
|
|
}
|