|
@@ -9,6 +9,7 @@ import com.example.xiaoshiweixinback.business.common.base.SystemFile;
|
|
|
import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
|
import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.StringUtils;
|
|
|
import com.example.xiaoshiweixinback.domain.*;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.AssoPersonProductDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.GetProductDTO;
|
|
@@ -21,8 +22,11 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -40,8 +44,9 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
private final AssoProductFileService assoProductFileService;
|
|
|
private final FileManagerService fileManagerService;
|
|
|
private final AssoPersonProductService assoPersonProductService;
|
|
|
- private final VipService vipService;
|
|
|
- private ProductCategoryService productCategoryService;
|
|
|
+ private final ProductCategoryService productCategoryService;
|
|
|
+ private final AssoproductCategoryService assoproductCategoryService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询爆款产品
|
|
|
*
|
|
@@ -57,7 +62,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
records.setData(new ArrayList<>());
|
|
|
records.setTotal(0L);
|
|
|
String name = productDTO.getName();
|
|
|
-
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
//查询登录人关联的产品类别id
|
|
|
List<Integer> ids = assoPersonCategoryService.getChoosedProductCategoryIds();
|
|
|
|
|
@@ -67,10 +72,13 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
getProductDTO.setCurrent(current);
|
|
|
getProductDTO.setSize(size);
|
|
|
getProductDTO.setCategoryIds(ids);
|
|
|
+ if (!personnelVO.getPersonType().equals(0)) {
|
|
|
+ getProductDTO.setIfShow(true);
|
|
|
+ }
|
|
|
if (ids != null) {
|
|
|
List<ProductVO> productVOs = this.getBaseMapper().getProductByCategory(getProductDTO);
|
|
|
Long count = this.getBaseMapper().getProductCount(getProductDTO);
|
|
|
- this.loadProduct(productVOs,false);
|
|
|
+ this.loadProduct(productVOs, false);
|
|
|
records.setData(productVOs);
|
|
|
records.setTotal(count);
|
|
|
}
|
|
@@ -78,8 +86,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- private void loadProduct(List<ProductVO> productVOS,Boolean ifCotentCategoryPath) {
|
|
|
+ private void loadProduct(List<ProductVO> productVOS, Boolean ifCotentCategoryPath) {
|
|
|
PersonnelVO personnelVO = null;
|
|
|
try {
|
|
|
personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
@@ -99,7 +106,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> ids = productVOS.stream().map(ProductVO::getId).collect(Collectors.toList());
|
|
|
- List<Integer> projectCategoryIds=productVOS.stream().map(ProductVO::getProductCategoryId).collect(Collectors.toList());
|
|
|
+ List<Integer> projectCategoryIds = productVOS.stream().map(ProductVO::getProductCategoryId).collect(Collectors.toList());
|
|
|
List<SystemFile> systemFiles = new ArrayList<>();
|
|
|
|
|
|
if (ids.size() != 0) {
|
|
@@ -123,10 +130,9 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- if(projectCategoryIds.size()!=0){
|
|
|
- productCategoryService.getProductCategory(projectCategoryIds,ifCotentCategoryPath);
|
|
|
-
|
|
|
+ List<ProductCategory> productCategories = new ArrayList<>();
|
|
|
+ if (projectCategoryIds.size() != 0) {
|
|
|
+ productCategories = productCategoryService.getProductCategory(projectCategoryIds, ifCotentCategoryPath);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -151,18 +157,40 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
-
|
|
|
+ //装载产品类别
|
|
|
+ if (productVO.getProductCategoryId() != null && productCategories.size() > 0) {
|
|
|
+ ProductCategory productCategory = productCategories.stream().filter(item -> item.getId().equals(productVO.getProductCategoryId())).findFirst().orElse(null);
|
|
|
+
|
|
|
+ if (productCategory != null) {
|
|
|
+ productVO.setCategoryName(productCategory.getName());
|
|
|
+ productVO.setPath(productCategory.getPath());
|
|
|
+ if (ifCotentCategoryPath == true) {
|
|
|
+ String path = productCategory.getPath();
|
|
|
+ if (path != null) {
|
|
|
+ String[] cIdArrs = path.split("/");
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
+ for (int i = 0; i < cIdArrs.length; i++) {
|
|
|
+ Integer cId = Integer.parseInt(cIdArrs[i]);
|
|
|
+ ProductCategory temCategory = productCategories.stream().filter(item -> item.getId().equals(cId)).findFirst().orElse(null);
|
|
|
+ if (temCategory != null) {
|
|
|
+ names.add(temCategory.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String pathName = StringUtils.join(names, "/");
|
|
|
+ productVO.setCategoryPath(pathName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Integer addOrUpdateProduct(ProductAddDTO productAddDTO) {
|
|
|
Product product = new Product();
|
|
|
if (productAddDTO.getId() == null) {
|
|
|
- product = this.addProduct(productAddDTO);
|
|
|
+ product = this.addProduct(productAddDTO,null);
|
|
|
AssoPersonProductDTO assoPersonProductDTO = new AssoPersonProductDTO();
|
|
|
assoPersonProductDTO.setProductId(product.getId());
|
|
|
assoPersonProductDTO.setConcernType(productAddDTO.getConcernType());
|
|
@@ -175,11 +203,16 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Product addProduct(Object productAddDTO) {
|
|
|
+ public Product addProduct(Object productAddDTO,String createUuid) {
|
|
|
Product product = new Product();
|
|
|
BeanUtils.copyProperties(productAddDTO, product);
|
|
|
- PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
- product.setCreateId(personnelVO.getUuid());
|
|
|
+ if(createUuid==null) {
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ product.setCreateId(personnelVO.getUuid());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ product.setCreateId(createUuid);
|
|
|
+ }
|
|
|
product.setIfCustomized(true);
|
|
|
product.insert();
|
|
|
return product;
|
|
@@ -225,7 +258,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
getProductDTO.setConcernTypes(productDTO.getConcernTypes());
|
|
|
List<ProductVO> productVOs = this.getBaseMapper().getConcernProduct(getProductDTO);
|
|
|
Long count = this.getBaseMapper().getConcernProductCount(getProductDTO);
|
|
|
- this.loadProduct(productVOs,false);
|
|
|
+ this.loadProduct(productVOs, false);
|
|
|
records.setData(productVOs);
|
|
|
records.setTotal(count);
|
|
|
return records;
|
|
@@ -233,34 +266,38 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Integer addOrUpdateHotProduct(HotProductAddDTO hotProductAddDTO) {
|
|
|
+ public Integer addOrUpdateHotProduct(HotProductAddDTO hotProductAddDTO,String createId) {
|
|
|
Product product = new Product();
|
|
|
- String name =hotProductAddDTO.getName();
|
|
|
- if(name==null){
|
|
|
- throw new BusinessException("608","产品名称不可为空");
|
|
|
+ String name = hotProductAddDTO.getName();
|
|
|
+ Integer categoryId = hotProductAddDTO.getProductCategoryId();
|
|
|
+ if (name == null) {
|
|
|
+ throw new BusinessException("608", "产品名称不可为空");
|
|
|
}
|
|
|
- LambdaQueryWrapper<Product> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(Product::getName,name)
|
|
|
- .eq(Product::getIfHot,true);
|
|
|
- Product orgProject =this.getOne(queryWrapper,false);
|
|
|
- if(product!=null){
|
|
|
- throw new BusinessException("607","产品名称不可重复");
|
|
|
+ LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Product::getName, name)
|
|
|
+ .eq(Product::getIfHot, true);
|
|
|
+ Product orgProject = this.getOne(queryWrapper, false);
|
|
|
+ if (orgProject != null) {
|
|
|
+ throw new BusinessException("607", "产品名称不可重复");
|
|
|
}
|
|
|
|
|
|
if (hotProductAddDTO.getId() == null) {
|
|
|
- product = this.addProduct(hotProductAddDTO);
|
|
|
+ hotProductAddDTO.setIfHot(true);
|
|
|
+ product = this.addProduct(hotProductAddDTO, createId);
|
|
|
} else {
|
|
|
product = this.updateProduct(hotProductAddDTO, hotProductAddDTO.getId());
|
|
|
}
|
|
|
assoProductFileService.addOrUpdateProductFile(product.getId(), hotProductAddDTO.getFileGuids());
|
|
|
+
|
|
|
+ assoproductCategoryService.addOrUpdate(product.getId(), categoryId);
|
|
|
return product.getId();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 根据id查询爆款专利
|
|
|
+ * 查询产品详情
|
|
|
*
|
|
|
- * @param id
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
public ProductVO queryHotProductDetail(Integer id) {
|
|
@@ -270,9 +307,17 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
return productVO;
|
|
|
}
|
|
|
BeanUtils.copyProperties(product, productVO);
|
|
|
+
|
|
|
+ //查询相关产品类别id
|
|
|
+ LambdaQueryWrapper<AssoproductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AssoproductCategory::getProductId, product.getId());
|
|
|
+ AssoproductCategory assoproductCategory = assoproductCategoryService.getOne(queryWrapper, false);
|
|
|
+ if (assoproductCategory != null) {
|
|
|
+ productVO.setProductCategoryId(assoproductCategory.getProductCategoryId());
|
|
|
+ }
|
|
|
List<ProductVO> productVOS = new ArrayList<>();
|
|
|
productVOS.add(productVO);
|
|
|
- this.loadProduct(productVOS,true);
|
|
|
+ this.loadProduct(productVOS, true);
|
|
|
return productVO;
|
|
|
}
|
|
|
|
|
@@ -314,6 +359,33 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
|
|
|
this.removeBatchByIds(ids);
|
|
|
return ids;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void ImportProduct(MultipartFile multipartFile) {
|
|
|
+ String guid = "";
|
|
|
+
|
|
|
+ //上传文件
|
|
|
+ try {
|
|
|
+ List<String> guids = fileManagerService.uploadFileGetGuid(Arrays.asList(multipartFile));
|
|
|
+ if (guids == null | guids.size() == 0) {
|
|
|
+ throw new BusinessException("607", "上传文件错误");
|
|
|
+ }
|
|
|
+ guid =guids.get(0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException("607", "上传文件错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建导入产品任务
|
|
|
+
|
|
|
+
|
|
|
+ //导入产品
|
|
|
+
|
|
|
+
|
|
|
+ //发送消息
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|