|
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.chelvc.cloud.uc.api.dto.UserDTO;
|
|
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.uc.api.service.UserService;
|
|
import com.chelvc.cloud.vehicle.api.constant.MerchantStatus;
|
|
import com.chelvc.cloud.vehicle.api.constant.MerchantStatus;
|
|
import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
|
|
import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
|
|
@@ -23,19 +22,17 @@ import com.chelvc.cloud.vehicle.server.service.CategoryService;
|
|
import com.chelvc.cloud.vehicle.server.service.GoodsService;
|
|
import com.chelvc.cloud.vehicle.server.service.GoodsService;
|
|
import com.chelvc.cloud.vehicle.server.service.MerchantService;
|
|
import com.chelvc.cloud.vehicle.server.service.MerchantService;
|
|
import com.chelvc.framework.base.context.SessionContextHolder;
|
|
import com.chelvc.framework.base.context.SessionContextHolder;
|
|
-import com.chelvc.framework.base.util.ResourceUtils;
|
|
|
|
import com.chelvc.framework.common.model.Pagination;
|
|
import com.chelvc.framework.common.model.Pagination;
|
|
|
|
+import com.chelvc.framework.common.util.AssertUtils;
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
-import com.chelvc.framework.database.util.PagingUtils;
|
|
|
|
|
|
+import com.chelvc.framework.database.context.DatabaseContextHolder;
|
|
import com.chelvc.framework.location.Address;
|
|
import com.chelvc.framework.location.Address;
|
|
import com.chelvc.framework.location.LocationHandler;
|
|
import com.chelvc.framework.location.LocationHandler;
|
|
-import com.chelvc.framework.redis.RedisConstant;
|
|
|
|
import lombok.NonNull;
|
|
import lombok.NonNull;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -56,15 +53,10 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
|
|
|
|
private final CategoryService categoryService;
|
|
private final CategoryService categoryService;
|
|
|
|
|
|
- private final RedisTemplate<String, Object> redisTemplate;
|
|
|
|
-
|
|
|
|
private final LocationHandler locationHandler;
|
|
private final LocationHandler locationHandler;
|
|
|
|
|
|
private final RegionMapper regionMapper;
|
|
private final RegionMapper regionMapper;
|
|
|
|
|
|
- @DubboReference
|
|
|
|
- EmployeeService employeeService;
|
|
|
|
-
|
|
|
|
@DubboReference
|
|
@DubboReference
|
|
UserService userService;
|
|
UserService userService;
|
|
|
|
|
|
@@ -87,7 +79,7 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
public MerchantDetailDTO getMerchantDetail(@NonNull Long id) {
|
|
public MerchantDetailDTO getMerchantDetail(@NonNull Long id) {
|
|
// 获取商家信息
|
|
// 获取商家信息
|
|
MerchantDTO merchant = MerchantCopier.INSTANCE.copying(
|
|
MerchantDTO merchant = MerchantCopier.INSTANCE.copying(
|
|
- ResourceUtils.required(this.getById(id), "商家不存在")
|
|
|
|
|
|
+ AssertUtils.available(this.getById(id), "商家不存在")
|
|
);
|
|
);
|
|
|
|
|
|
// 获取商家全部商品列表
|
|
// 获取商家全部商品列表
|
|
@@ -108,7 +100,7 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
public MerchantDetailDTO getMerchantDetail(Long id, LocationQueryParam param) {
|
|
public MerchantDetailDTO getMerchantDetail(Long id, LocationQueryParam param) {
|
|
// 获取商家信息
|
|
// 获取商家信息
|
|
MerchantDTO merchant = MerchantCopier.INSTANCE.copying(
|
|
MerchantDTO merchant = MerchantCopier.INSTANCE.copying(
|
|
- ResourceUtils.required(this.baseMapper.getMerchantById(id, param), "商家不存在")
|
|
|
|
|
|
+ AssertUtils.available(this.baseMapper.getMerchantById(id, param), "商家不存在")
|
|
);
|
|
);
|
|
Long userId = SessionContextHolder.getSession().getId();
|
|
Long userId = SessionContextHolder.getSession().getId();
|
|
//查询商家是否被收藏
|
|
//查询商家是否被收藏
|
|
@@ -140,7 +132,7 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
Integer count = this.lambdaQuery()
|
|
Integer count = this.lambdaQuery()
|
|
.eq(Merchant::getName, param.getName())
|
|
.eq(Merchant::getName, param.getName())
|
|
.eq(Merchant::getStatus, MerchantStatus.ONLINE).count();
|
|
.eq(Merchant::getStatus, MerchantStatus.ONLINE).count();
|
|
- ResourceUtils.available(count < 1 , "商家名称已存在");
|
|
|
|
|
|
+ AssertUtils.available(count < 1 , "商家名称已存在");
|
|
Merchant merchant = MerchantCopier.INSTANCE.copying(param);
|
|
Merchant merchant = MerchantCopier.INSTANCE.copying(param);
|
|
merchant.setUserId(0L);
|
|
merchant.setUserId(0L);
|
|
merchant.setScore(0D);
|
|
merchant.setScore(0D);
|
|
@@ -152,42 +144,30 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void updateMerchant(@NonNull Long id, @NonNull MerchantModifyParam param) {
|
|
public void updateMerchant(@NonNull Long id, @NonNull MerchantModifyParam param) {
|
|
- Merchant merchant = ResourceUtils.required(this.getById(id), "商家不存在");
|
|
|
|
|
|
+ Merchant merchant = AssertUtils.available(this.getById(id), "商家不存在");
|
|
MerchantCopier.INSTANCE.copying(param, merchant);
|
|
MerchantCopier.INSTANCE.copying(param, merchant);
|
|
this.updateById(merchant);
|
|
this.updateById(merchant);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void deleteMerchant(@NonNull Long id) {
|
|
public void deleteMerchant(@NonNull Long id) {
|
|
- ResourceUtils.required(this.getById(id), "商家不存在");
|
|
|
|
|
|
+ AssertUtils.available(this.getById(id), "商家不存在");
|
|
this.baseMapper.deleteById(id);
|
|
this.baseMapper.deleteById(id);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Pagination<MerchantDTO> getMerchantPaging(@NonNull MerchantPagingParam param) {
|
|
public Pagination<MerchantDTO> getMerchantPaging(@NonNull MerchantPagingParam param) {
|
|
- Long userId = SessionContextHolder.getSession().getId();
|
|
|
|
- if (employeeService.isAdmin(userId)){
|
|
|
|
- Page<Merchant> page = this.lambdaQuery()
|
|
|
|
- .like(StringUtils.nonEmpty(param.getName()), Merchant::getName, param.getName())
|
|
|
|
- .eq(Objects.nonNull(param.getRecommend()), Merchant::getRecommend, param.getRecommend())
|
|
|
|
- .eq(Objects.nonNull(param.getStatus()), Merchant::getStatus, param.getStatus())
|
|
|
|
- .orderByDesc(Merchant::getCreateTime).page(PagingUtils.convert(param.getPaging()));
|
|
|
|
- return PagingUtils.convert(page, MerchantCopier.INSTANCE::copying);
|
|
|
|
- }else{
|
|
|
|
- Page<Merchant> page = this.lambdaQuery()
|
|
|
|
- .like(StringUtils.nonEmpty(param.getName()), Merchant::getName, param.getName())
|
|
|
|
- .eq(Objects.nonNull(param.getRecommend()), Merchant::getRecommend, param.getRecommend())
|
|
|
|
- .eq(Objects.nonNull(param.getStatus()), Merchant::getStatus, param.getStatus())
|
|
|
|
- .eq(Merchant::getUserId,userId)
|
|
|
|
- .orderByDesc(Merchant::getCreateTime).page(PagingUtils.convert(param.getPaging()));
|
|
|
|
- return PagingUtils.convert(page, MerchantCopier.INSTANCE::copying);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ Page<Merchant> page = this.lambdaQuery()
|
|
|
|
+ .like(StringUtils.notEmpty(param.getName()), Merchant::getName, param.getName())
|
|
|
|
+ .eq(Objects.nonNull(param.getRecommend()), Merchant::getRecommend, param.getRecommend())
|
|
|
|
+ .eq(Objects.nonNull(param.getStatus()), Merchant::getStatus, param.getStatus())
|
|
|
|
+ .orderByDesc(Merchant::getCreateTime).page(DatabaseContextHolder.page(param.getPaging()));
|
|
|
|
+ return DatabaseContextHolder.pagination(page, MerchantCopier.INSTANCE::copying);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public MerchantDTO getMerchant(@NonNull Long id) {
|
|
public MerchantDTO getMerchant(@NonNull Long id) {
|
|
- Merchant merchant = ResourceUtils.required(this.getById(id), "商家不存在");
|
|
|
|
|
|
+ Merchant merchant = AssertUtils.available(this.getById(id), "商家不存在");
|
|
return this.convert(merchant);
|
|
return this.convert(merchant);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -226,23 +206,13 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
Integer regionId = param.getRegionId();
|
|
Integer regionId = param.getRegionId();
|
|
Double longitude = (double) 0;
|
|
Double longitude = (double) 0;
|
|
Double latitude = (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){
|
|
if(regionId == null){
|
|
UserDTO user = userService.getUser(userId);
|
|
UserDTO user = userService.getUser(userId);
|
|
if(user == null){
|
|
if(user == null){
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
//LocationHandler locationHandler = locationHandlerConfig.getBean();
|
|
//LocationHandler locationHandler = locationHandlerConfig.getBean();
|
|
- Address address = locationHandler.ip2address(user.getHost());
|
|
|
|
|
|
+ Address address = locationHandler.ip2address(SessionContextHolder.getHost());
|
|
if(address == null){
|
|
if(address == null){
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|