|
@@ -7,19 +7,34 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
|
import com.example.xiaoshiweixinback.business.common.base.SystemFile;
|
|
|
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.BeanUtil;
|
|
|
import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
|
import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
|
import com.example.xiaoshiweixinback.domain.*;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.ProductCategoryDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.productCategory.AddCategoryDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.productCategory.CategoryIdDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.productCategory.CategoryIdsDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.productCategory.EditCategoryDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.ProductCategoryVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.ProductVO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.productCategory.SelectCategoryLevelVO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.productCategory.SelectCategoryVO;
|
|
|
+import com.example.xiaoshiweixinback.mapper.AssoCategoryFileMapper;
|
|
|
import com.example.xiaoshiweixinback.mapper.ProductCategoryMapper;
|
|
|
import com.example.xiaoshiweixinback.service.common.FileManagerService;
|
|
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -37,6 +52,9 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
private final AssoCategoryFileService assoCategoryFileService;
|
|
|
private final PersonService personService;
|
|
|
private final FileManagerService fileManagerService;
|
|
|
+ private final ProductCategoryMapper productCategoryMapper;
|
|
|
+ @Autowired
|
|
|
+ private AssoCategoryFileMapper assoCategoryFileMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询产品类别
|
|
@@ -46,33 +64,35 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
*/
|
|
|
public Records queryProductCategory(ProductCategoryDTO productCategoryDTO) {
|
|
|
Boolean ifConcern = productCategoryDTO.getIfConcern();
|
|
|
- Records records = new Records();
|
|
|
Long size = productCategoryDTO.getSize();
|
|
|
Long current = productCategoryDTO.getCurrent();
|
|
|
String name = productCategoryDTO.getName();
|
|
|
Integer parentId = productCategoryDTO.getParentId();
|
|
|
+ Records records = new Records();
|
|
|
records.setCurrent(current);
|
|
|
records.setSize(size);
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- if (name != null && !name.trim().equals("")) {
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
queryWrapper.like(ProductCategory::getName, name);
|
|
|
}
|
|
|
+
|
|
|
if (parentId == null) {
|
|
|
queryWrapper.isNull(ProductCategory::getParentId);
|
|
|
} else {
|
|
|
queryWrapper.eq(ProductCategory::getParentId, parentId);
|
|
|
}
|
|
|
+
|
|
|
if (ifConcern != null && ifConcern) {
|
|
|
//获取关注的
|
|
|
List<Integer> ids = assoPersonCategoryService.getChoosedProductCategoryIds();
|
|
|
- if(ids.size()==0){
|
|
|
+ if (ids.size() == 0) {
|
|
|
ids.add(0);
|
|
|
}
|
|
|
queryWrapper.in(ProductCategory::getId, ids);
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
List<ProductCategory> productCategoryList = new ArrayList<>();
|
|
|
if (size != null && current != null) {
|
|
|
IPage<ProductCategory> productCategoryIPage = this.page(new Page<>(current, size), queryWrapper);
|
|
@@ -104,7 +124,6 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
queryWrapper.in(AssoCategoryFile::getProductCategoryId, ids);
|
|
|
assoCategoryFiles = assoCategoryFileService.list(queryWrapper);
|
|
|
guids = assoCategoryFiles.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//查询创建人名称
|
|
@@ -130,7 +149,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
for (ProductCategory productCategory : productCategorys) {
|
|
|
ProductCategoryVO productCategoryVO = new ProductCategoryVO();
|
|
|
BeanUtils.copyProperties(productCategory, productCategoryVO);
|
|
|
- Person personnel = personList.stream().filter(item -> item.getUuid().toString().equals(productCategoryVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ Person personnel = personList.stream().filter(item -> item.getUuid().equals(productCategoryVO.getCreateId())).findFirst().orElse(null);
|
|
|
if (personnel != null) {
|
|
|
productCategoryVO.setCreateName(personnel.getName());
|
|
|
}
|
|
@@ -145,11 +164,211 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //装载父类产品类别
|
|
|
+ if (productCategory.getParentId() != null) {
|
|
|
+ ProductCategory parentCategory = this.getById(productCategory.getParentId());
|
|
|
+ SelectCategoryLevelVO levelVO = new SelectCategoryLevelVO();
|
|
|
+ levelVO.setId(parentCategory.getId());
|
|
|
+ levelVO.setName(parentCategory.getName());
|
|
|
+ levelVO.setPath(parentCategory.getPath());
|
|
|
+ levelVO.setLevel(parentCategory.getLevel());
|
|
|
+ productCategoryVO.setCategoryLevelVo(levelVO);
|
|
|
+ }
|
|
|
+ //装载产品图
|
|
|
+ productCategoryVO.setFileGuids(guids);
|
|
|
+ //判断是否有子集
|
|
|
+ Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getParentId, productCategory.getId()));
|
|
|
+ if (count > 0) {
|
|
|
+ productCategoryVO.setIfChild(true);
|
|
|
+ }
|
|
|
productCategoryVOS.add(productCategoryVO);
|
|
|
}
|
|
|
return productCategoryVOS;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加产品类别
|
|
|
+ *
|
|
|
+ * @param categoryDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public Integer addCategory(AddCategoryDTO categoryDTO) {
|
|
|
+ Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getName, categoryDTO.getName()));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
|
+ }
|
|
|
+ ProductCategory category = new ProductCategory();
|
|
|
+ category.setName(categoryDTO.getName());
|
|
|
+ category.setDescription(categoryDTO.getDescription());
|
|
|
+ category.setSearchCondition(categoryDTO.getSearchCondition());
|
|
|
+ if (categoryDTO.getParentId() != null) {
|
|
|
+ category.setParentId(categoryDTO.getParentId());
|
|
|
+ ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
|
|
|
+ Integer level = parentCategory.getLevel();
|
|
|
+ category.setLevel(level + 1);
|
|
|
+ category.setPath(this.getPath(level));
|
|
|
+ } else {
|
|
|
+ category.setLevel(1);
|
|
|
+ }
|
|
|
+ category.insert();
|
|
|
+ Integer categoryId = category.getId();
|
|
|
+ if (!CollectionUtils.isEmpty(categoryDTO.getFileGuids())) {
|
|
|
+ for (String fileGuid : categoryDTO.getFileGuids()) {
|
|
|
+ AssoCategoryFile categoryFile = new AssoCategoryFile();
|
|
|
+ categoryFile.setProductCategoryId(categoryId);
|
|
|
+ categoryFile.setFileGuid(fileGuid);
|
|
|
+ categoryFile.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return categoryId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑产品类别
|
|
|
+ *
|
|
|
+ * @param categoryDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public Integer editCategory(EditCategoryDTO categoryDTO) {
|
|
|
+ Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getName, categoryDTO.getName()));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
|
+ }
|
|
|
+ Integer categoryId = categoryDTO.getId();
|
|
|
+ ProductCategory category = this.getById(categoryId);
|
|
|
+ if (StringUtils.isNotEmpty(categoryDTO.getName())) {
|
|
|
+ category.setName(categoryDTO.getName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(categoryDTO.getDescription())) {
|
|
|
+ category.setDescription(categoryDTO.getDescription());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(categoryDTO.getSearchCondition())) {
|
|
|
+ category.setSearchCondition(categoryDTO.getSearchCondition());
|
|
|
+ }
|
|
|
+ if (categoryDTO.getParentId() != null) {
|
|
|
+ category.setParentId(categoryDTO.getParentId());
|
|
|
+ ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
|
|
|
+ Integer level = parentCategory.getLevel();
|
|
|
+ category.setLevel(level + 1);
|
|
|
+ category.setPath(this.getPath(level));
|
|
|
+ }
|
|
|
+ category.updateById();
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(categoryDTO.getFileGuids())) {
|
|
|
+ List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
+ .eq(AssoCategoryFile::getProductCategoryId, categoryId));
|
|
|
+ if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
|
|
|
+ List<Integer> categoryIds = assoCategoryFiles.stream().map(AssoCategoryFile::getId).collect(Collectors.toList());
|
|
|
+ assoCategoryFileMapper.deleteBatchIds(categoryIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String fileGuid : categoryDTO.getFileGuids()) {
|
|
|
+ AssoCategoryFile categoryFile = new AssoCategoryFile();
|
|
|
+ categoryFile.setProductCategoryId(categoryId);
|
|
|
+ categoryFile.setFileGuid(fileGuid);
|
|
|
+ categoryFile.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return categoryId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询产品类别详情
|
|
|
+ *
|
|
|
+ * @param categoryIdDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public SelectCategoryVO selectCategoryDetail(CategoryIdDTO categoryIdDTO) {
|
|
|
+ Integer categoryId = categoryIdDTO.getId();
|
|
|
+ SelectCategoryVO categoryVO = new SelectCategoryVO();
|
|
|
+ ProductCategory category = productCategoryMapper.selectById(categoryId);
|
|
|
+ BeanUtil.copy(category, categoryVO);
|
|
|
+ //获取父类产品类别
|
|
|
+ Integer parentId = category.getParentId();
|
|
|
+ if (parentId != null) {
|
|
|
+ ProductCategory parentCategory = this.getById(parentId);
|
|
|
+ SelectCategoryLevelVO levelVO = new SelectCategoryLevelVO();
|
|
|
+ levelVO.setId(parentCategory.getId());
|
|
|
+ levelVO.setName(parentCategory.getName());
|
|
|
+ levelVO.setPath(parentCategory.getPath());
|
|
|
+ levelVO.setLevel(parentCategory.getLevel());
|
|
|
+ categoryVO.setCategoryLevelVo(levelVO);
|
|
|
+ }
|
|
|
+ //获取guids
|
|
|
+ List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
+ .eq(AssoCategoryFile::getProductCategoryId, categoryId));
|
|
|
+ List<String> fileGuids = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
|
|
|
+ fileGuids = assoCategoryFiles.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ categoryVO.setFileGuids(fileGuids);
|
|
|
+ //判断是否有子集
|
|
|
+ Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getParentId, categoryId));
|
|
|
+ if (count > 0) {
|
|
|
+ categoryVO.setIfChild(true);
|
|
|
+ }
|
|
|
+ return categoryVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除产品类别
|
|
|
+ *
|
|
|
+ * @param categoryIdsDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean deleteCategory(CategoryIdsDTO categoryIdsDTO) {
|
|
|
+ List<Integer> ids = categoryIdsDTO.getIds();
|
|
|
+ for (Integer id : ids) {
|
|
|
+ List<Integer> productCategoryIds = this.getProductCategoryIds(id);
|
|
|
+ ids.addAll(productCategoryIds);
|
|
|
+ }
|
|
|
+ List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
+ .in(AssoCategoryFile::getProductCategoryId, ids));
|
|
|
+ if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
|
|
|
+ List<Integer> fileIds = assoCategoryFiles.stream().map(AssoCategoryFile::getId).collect(Collectors.toList());
|
|
|
+ assoCategoryFileMapper.deleteBatchIds(fileIds);
|
|
|
+ }
|
|
|
+ return this.removeBatchByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Integer> getProductCategoryIds(Integer id) {
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ List<ProductCategory> categories = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getParentId, id));
|
|
|
+ if (!CollectionUtils.isEmpty(categories)) {
|
|
|
+ List<Integer> ids = categories.stream().map(ProductCategory::getId).collect(Collectors.toList());
|
|
|
+ list.addAll(ids);
|
|
|
+ for (ProductCategory category : categories) {
|
|
|
+ List<Integer> categoryIds = this.getProductCategoryIds(category.getId());
|
|
|
+ list.addAll(categoryIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取路径
|
|
|
+ *
|
|
|
+ * @param level
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getPath(Integer level) {
|
|
|
+ String s = "";
|
|
|
+ for (int i = 1; i < level; i++) {
|
|
|
+ if (i != level - 1) {
|
|
|
+ s = s + i + "/";
|
|
|
+ } else {
|
|
|
+ s = s + i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|