|
@@ -2,22 +2,32 @@ package cn.cslg.pas.service.business;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.business.ProductCategoryDTO;
|
|
|
import cn.cslg.pas.common.model.cronModel.GroupVO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.domain.business.AssoProductCategoryFile;
|
|
|
import cn.cslg.pas.domain.business.ProductCategory;
|
|
|
+import cn.cslg.pas.exception.UnLoginException;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.factorys.businessFactory.Business;
|
|
|
import cn.cslg.pas.mapper.ProductCategoryMapper;
|
|
|
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 产品类别的Service层
|
|
@@ -30,17 +40,36 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
@Autowired
|
|
|
private ProductCategoryMapper productCategoryMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AssoProductCategoryFileService assoProductCategoryFileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+
|
|
|
@Override
|
|
|
public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增产品类别
|
|
|
+ * @param object
|
|
|
+ * @param files
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public Object addMessage(Object object, List<MultipartFile> files) {
|
|
|
- //object to productCategory
|
|
|
+ //object to productCategoryDTO
|
|
|
ProductCategoryDTO productCategoryDTO = (ProductCategoryDTO)object;
|
|
|
- //检测名成
|
|
|
+ //检测名称是否不规范
|
|
|
productCategoryDTO.setName(productCategoryDTO.getName().trim());
|
|
|
+ //根据名称查询数据库中是否存在
|
|
|
String name = productCategoryDTO.getName();
|
|
|
LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(ProductCategory::getName, name);
|
|
@@ -48,30 +77,114 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
if(productCategories != null && productCategories.size() != 0){
|
|
|
throw new XiaoShiException("参数错误");
|
|
|
}
|
|
|
- //赋值
|
|
|
+ //获取登陆人信息 用于设置创建人
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
+ try {
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new UnLoginException("未登录");
|
|
|
+ }
|
|
|
+ //产品类别入表
|
|
|
ProductCategory productCategory = new ProductCategory();
|
|
|
BeanUtils.copyProperties(productCategoryDTO, productCategory);
|
|
|
- //数据入表
|
|
|
productCategory.insert();
|
|
|
+ //判断文件是否为空
|
|
|
+ if (files != null && files.size() != 0) {
|
|
|
+ try {
|
|
|
+ //调用上传文件接口
|
|
|
+ List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
|
+ List<AssoProductCategoryFile> assoProductCategoryFiles = new ArrayList<>();
|
|
|
+ for (String item : guids) {
|
|
|
+ AssoProductCategoryFile assoProductCategoryFile = new AssoProductCategoryFile();
|
|
|
+ assoProductCategoryFile.setProductCategoryId(productCategory.getId());
|
|
|
+ assoProductCategoryFile.setFileGuid(item);
|
|
|
+ assoProductCategoryFile.setCreateId(personnelVO.getId());
|
|
|
+ assoProductCategoryFiles.add(assoProductCategoryFile);
|
|
|
+ }
|
|
|
+ if (assoProductCategoryFiles != null && assoProductCategoryFiles.size() != 0) {
|
|
|
+ assoProductCategoryFileService.saveBatch(assoProductCategoryFiles);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
//返回id
|
|
|
return productCategory.getId();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除产品类别
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public Object deleteMessage(List<Integer> ids) {
|
|
|
- this.removeByIds(ids);
|
|
|
- return null;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object deleteMessage(List<Integer> ids) throws IOException {
|
|
|
+ //根据产品类别id删除产品类别和文件关联表
|
|
|
+ LambdaQueryWrapper<AssoProductCategoryFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(AssoProductCategoryFile::getProductCategoryId, ids);
|
|
|
+ List<AssoProductCategoryFile> assoProductCategoryFiles = assoProductCategoryFileService.list(queryWrapper);
|
|
|
+ List<String> guids = assoProductCategoryFiles.stream().map(AssoProductCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ //TODO 根据guids删除文件
|
|
|
+ if (guids.size() != 0) {
|
|
|
+ fileManagerService.deleteFileFromFMS(guids);
|
|
|
+ }
|
|
|
+ //删除产品类别和文件关联表中数据
|
|
|
+ assoProductCategoryFiles.remove(queryWrapper);
|
|
|
+ //根据产品类别id删除产品类别
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ return ids;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新产品类别
|
|
|
+ * @param object
|
|
|
+ * @param files
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
//object to productCategory
|
|
|
ProductCategoryDTO productCategoryDTO = (ProductCategoryDTO)object;
|
|
|
+ //检测名称是否不规范
|
|
|
+ productCategoryDTO.setName(productCategoryDTO.getName().trim());
|
|
|
+ //根据名称查询数据库中是否存在
|
|
|
+ String name = productCategoryDTO.getName();
|
|
|
+ LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ProductCategory::getName, name);
|
|
|
+ List<ProductCategory> productCategories = this.list(queryWrapper);
|
|
|
+ if (productCategories == null && productCategories.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //获取登陆人信息 用于设置创建人
|
|
|
+ PersonnelVO personnelVO;
|
|
|
+ try {
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new UnLoginException("未登录");
|
|
|
+ }
|
|
|
ProductCategory productCategory = this.getById(productCategoryDTO.getId());
|
|
|
BeanUtils.copyProperties(productCategoryDTO, productCategory);
|
|
|
productCategory.insert();
|
|
|
- return null;
|
|
|
+ if (files != null && files.size() != 0) {
|
|
|
+ try {
|
|
|
+ List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
|
+ List<AssoProductCategoryFile> assoProductCategoryFiles = new ArrayList<>();
|
|
|
+ for (String item : guids) {
|
|
|
+ AssoProductCategoryFile assoProductCategoryFile = new AssoProductCategoryFile();
|
|
|
+ assoProductCategoryFile.setProductCategoryId(productCategory.getId());
|
|
|
+ assoProductCategoryFile.setFileGuid(item);
|
|
|
+ assoProductCategoryFile.setCreateId(personnelVO.getId());
|
|
|
+ assoProductCategoryFiles.add(assoProductCategoryFile);
|
|
|
+ }
|
|
|
+ if (assoProductCategoryFiles != null && assoProductCategoryFiles.size() != 0) {
|
|
|
+ assoProductCategoryFileService.saveBatch(assoProductCategoryFiles);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return productCategory.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|