|
@@ -7,6 +7,7 @@ import java.util.Objects;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.uc.api.model.Scope;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
|
|
|
import com.chelvc.cloud.vehicle.api.param.CategoryListParam;
|
|
|
import com.chelvc.cloud.vehicle.api.param.CategoryModifyParam;
|
|
@@ -15,12 +16,17 @@ import com.chelvc.cloud.vehicle.server.copier.CategoryCopier;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.CategoryMapper;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Category;
|
|
|
import com.chelvc.cloud.vehicle.server.service.CategoryService;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.MerchantService;
|
|
|
+import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
import com.chelvc.framework.common.model.Pagination;
|
|
|
import com.chelvc.framework.common.util.AssertUtils;
|
|
|
+import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.chelvc.framework.database.context.DatabaseContextHolder;
|
|
|
import lombok.NonNull;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
/**
|
|
|
* 分类业务操作实现
|
|
@@ -29,13 +35,27 @@ import org.apache.dubbo.config.annotation.DubboService;
|
|
|
* @date 2023/5/2
|
|
|
*/
|
|
|
@DubboService(interfaceClass = com.chelvc.cloud.vehicle.api.service.CategoryService.class)
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService,
|
|
|
com.chelvc.cloud.vehicle.api.service.CategoryService {
|
|
|
+
|
|
|
+ private final MerchantService merchantService;
|
|
|
+
|
|
|
@Override
|
|
|
public Long addCategory(@NonNull CategoryModifyParam param) {
|
|
|
Integer count = this.lambdaQuery().eq(Category::getName, param.getName()).count();
|
|
|
AssertUtils.available(count <= 0, "分类名称已存在");
|
|
|
Category category = CategoryCopier.INSTANCE.copying(param);
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ Scope scope = StringUtils.ifEmpty(SessionContextHolder.getScope(), Scope::parse);
|
|
|
+ if (scope == Scope.ADMIN) {
|
|
|
+ }else {
|
|
|
+ List<Long> merchants = this.merchantService.getMerchantIdsByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(merchants)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ param.setMerchantId(merchants.get(0));
|
|
|
+ }
|
|
|
this.save(category);
|
|
|
return category.getId();
|
|
|
}
|
|
@@ -49,15 +69,37 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|
|
|
|
|
@Override
|
|
|
public Pagination<CategoryDTO> getCategoryPaging(@NonNull CategoryPagingParam param) {
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ Scope scope = StringUtils.ifEmpty(SessionContextHolder.getScope(), Scope::parse);
|
|
|
+ if (scope == Scope.ADMIN) {
|
|
|
+ }else {
|
|
|
+ List<Long> merchants = this.merchantService.getMerchantIdsByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(merchants)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ param.setMerchantId(merchants.get(0));
|
|
|
+ }
|
|
|
Page<Category> page = this.lambdaQuery()
|
|
|
.like(StringUtils.notEmpty(param.getName()), Category::getName, param.getName())
|
|
|
+ .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
|
.eq(Objects.nonNull(param.getEnabled()), Category::getEnabled, param.getEnabled())
|
|
|
+ .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
.orderByAsc(Category::getSort).page(DatabaseContextHolder.page(param.getPaging()));
|
|
|
return DatabaseContextHolder.pagination(page, CategoryCopier.INSTANCE::copying);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<CategoryDTO> listActiveCategories(CategoryListParam param) {
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ Scope scope = StringUtils.ifEmpty(SessionContextHolder.getScope(), Scope::parse);
|
|
|
+ if (scope == Scope.ADMIN) {
|
|
|
+ }else {
|
|
|
+ List<Long> merchants = this.merchantService.getMerchantIdsByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(merchants)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ param.setMerchantId(merchants.get(0));
|
|
|
+ }
|
|
|
List<Category> categories = this.lambdaQuery().eq(Category::getEnabled, true)
|
|
|
.eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
.eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|