|
@@ -7,13 +7,13 @@ import cn.cslg.pas.common.model.vo.ProductCategoryPictureVO;
|
|
import cn.cslg.pas.common.model.vo.ProductCategoryVO;
|
|
import cn.cslg.pas.common.model.vo.ProductCategoryVO;
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
-import cn.cslg.pas.common.utils.Response;
|
|
|
|
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
import cn.cslg.pas.domain.ProductCategory;
|
|
import cn.cslg.pas.domain.ProductCategory;
|
|
import cn.cslg.pas.domain.asso.AssoProductCategoryPicture;
|
|
import cn.cslg.pas.domain.asso.AssoProductCategoryPicture;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.mapper.AssoProductCategoryPictureMapper;
|
|
import cn.cslg.pas.mapper.AssoProductCategoryPictureMapper;
|
|
import cn.cslg.pas.mapper.ProductCategoryMapper;
|
|
import cn.cslg.pas.mapper.ProductCategoryMapper;
|
|
|
|
+import cn.cslg.pas.mapper.ProductMapper;
|
|
import cn.cslg.pas.service.IProductCategoryService;
|
|
import cn.cslg.pas.service.IProductCategoryService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -38,6 +38,7 @@ import java.util.List;
|
|
public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
private final ProductCategoryMapper productCategoryMapper;
|
|
private final ProductCategoryMapper productCategoryMapper;
|
|
private final AssoProductCategoryPictureMapper assoProductCategoryPictureMapper;
|
|
private final AssoProductCategoryPictureMapper assoProductCategoryPictureMapper;
|
|
|
|
+ private final ProductMapper productMapper;
|
|
private final CacheUtils cacheUtils;
|
|
private final CacheUtils cacheUtils;
|
|
private final LoginUtils loginUtils;
|
|
private final LoginUtils loginUtils;
|
|
private final FileUtils fileUtils;
|
|
private final FileUtils fileUtils;
|
|
@@ -62,6 +63,14 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
throw new XiaoShiException(message);
|
|
throw new XiaoShiException(message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //检查许可费率数值是否合法
|
|
|
|
+ Double licenseRate = productCategoryAddNewDTO.getLicenseRate();
|
|
|
|
+ if (licenseRate < 0 || licenseRate > 1) {
|
|
|
|
+ String message = "新增产品失败,许可费率不合法,请填写正确数值";
|
|
|
|
+ log.info("{}", message);
|
|
|
|
+ throw new XiaoShiException(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
//新增产品类别DTO对象赋值给产品类别表实体类
|
|
//新增产品类别DTO对象赋值给产品类别表实体类
|
|
ProductCategory productCategory = new ProductCategory();
|
|
ProductCategory productCategory = new ProductCategory();
|
|
BeanUtils.copyProperties(productCategoryAddNewDTO, productCategory);
|
|
BeanUtils.copyProperties(productCategoryAddNewDTO, productCategory);
|
|
@@ -79,17 +88,18 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
throw new XiaoShiException(message);
|
|
throw new XiaoShiException(message);
|
|
}
|
|
}
|
|
|
|
|
|
- //如果有图片,图片文件上传至服务器,后获取url地址,赋值给产品类别图片关联表实体类
|
|
|
|
- if (files != null) {
|
|
|
|
|
|
+ //如果有图片,图片文件上传至服务器,后获取图片文件的名称、后缀名、url地址,赋值给产品类别图片关联表实体类
|
|
|
|
+ if (files != null && files.size() != 0) {
|
|
ArrayList<AssoProductCategoryPicture> assoProductCategoryPictures = new ArrayList<>();
|
|
ArrayList<AssoProductCategoryPicture> assoProductCategoryPictures = new ArrayList<>();
|
|
for (MultipartFile file : files) {
|
|
for (MultipartFile file : files) {
|
|
//图片文件上传至服务器
|
|
//图片文件上传至服务器
|
|
UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
- //获取图片文件的url地址
|
|
|
|
- String picturePath = fileDTO.getPath();
|
|
|
|
|
|
+ //获取并将产品类别id、图片文件的名称、后缀名、url赋值给产品类别图片关联表实体类
|
|
AssoProductCategoryPicture assoProductCategoryPicture = new AssoProductCategoryPicture()
|
|
AssoProductCategoryPicture assoProductCategoryPicture = new AssoProductCategoryPicture()
|
|
.setProductCategoryId(productCategory.getId())
|
|
.setProductCategoryId(productCategory.getId())
|
|
- .setPicture(picturePath);
|
|
|
|
|
|
+ .setName(fileDTO.getName())
|
|
|
|
+ .setSuffix(fileDTO.getExtName())
|
|
|
|
+ .setUrl(fileDTO.getPath());
|
|
assoProductCategoryPictures.add(assoProductCategoryPicture);
|
|
assoProductCategoryPictures.add(assoProductCategoryPicture);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -115,8 +125,8 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
if (current != null && size != null) {
|
|
if (current != null && size != null) {
|
|
PageHelper.startPage(current, size);
|
|
PageHelper.startPage(current, size);
|
|
}
|
|
}
|
|
- List<ProductCategoryVO> queryResults = productCategoryMapper.query(productCategoryQueryPageDTO);
|
|
|
|
- return JsonPage.restPage(new PageInfo<>(queryResults));
|
|
|
|
|
|
+ List<ProductCategoryVO> ProductCategoryVOs = productCategoryMapper.query(productCategoryQueryPageDTO);
|
|
|
|
+ return JsonPage.restPage(new PageInfo<>(ProductCategoryVOs));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -151,36 +161,37 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
throw new XiaoShiException(message);
|
|
throw new XiaoShiException(message);
|
|
}
|
|
}
|
|
|
|
|
|
- //先通过产品类别id查询出所有原来的图片文件
|
|
|
|
|
|
+ //先通过产品类别id查询出所有原来的图片文件id
|
|
ArrayList<Integer> oldPictureIds = new ArrayList<>();
|
|
ArrayList<Integer> oldPictureIds = new ArrayList<>();
|
|
- List<ProductCategoryPictureVO> productCategoryPictureVOS = assoProductCategoryPictureMapper.queryListByProductCategoryId(productCategoryId);
|
|
|
|
|
|
+ List<ProductCategoryPictureVO> productCategoryPictureVOS = assoProductCategoryPictureMapper.selectByProductCategoryId(productCategoryId);
|
|
for (ProductCategoryPictureVO productCategoryPictureVO : productCategoryPictureVOS) {
|
|
for (ProductCategoryPictureVO productCategoryPictureVO : productCategoryPictureVOS) {
|
|
Integer oldPictureId = productCategoryPictureVO.getId();
|
|
Integer oldPictureId = productCategoryPictureVO.getId();
|
|
oldPictureIds.add(oldPictureId);
|
|
oldPictureIds.add(oldPictureId);
|
|
}
|
|
}
|
|
|
|
+ //再从DTO中取出传过来的图片id
|
|
ArrayList<Integer> newOldPictureIds = new ArrayList<>();
|
|
ArrayList<Integer> newOldPictureIds = new ArrayList<>();
|
|
- List<ProductCategoryPictureDTO> productCategoryPictureDTOS = productCategoryUpdateDTO.getPictures();
|
|
|
|
- System.out.println(productCategoryPictureDTOS);
|
|
|
|
- for (ProductCategoryPictureDTO productCategoryPictureDTO : productCategoryPictureDTOS) {
|
|
|
|
- Integer newOldPictureId = productCategoryPictureDTO.getId();
|
|
|
|
|
|
+ List<ProductCategoryPictureUpateDTO> productCategoryPictureUpateDTOS = productCategoryUpdateDTO.getPictures();
|
|
|
|
+ for (ProductCategoryPictureUpateDTO productCategoryPictureUpateDTO : productCategoryPictureUpateDTOS) {
|
|
|
|
+ Integer newOldPictureId = productCategoryPictureUpateDTO.getId();
|
|
newOldPictureIds.add(newOldPictureId);
|
|
newOldPictureIds.add(newOldPictureId);
|
|
}
|
|
}
|
|
- //集合去重,去重后留下的数据即为被删除的原有图片
|
|
|
|
|
|
+ //图片id集合去重,保留下来的即被删除的图片id
|
|
oldPictureIds.removeAll(newOldPictureIds);
|
|
oldPictureIds.removeAll(newOldPictureIds);
|
|
|
|
|
|
- if (oldPictureIds.size() != 0) {
|
|
|
|
- log.info("产品类别图片关联表删除原有图片");
|
|
|
|
|
|
+ if (oldPictureIds.size() > 0) {
|
|
|
|
+ log.info("产品类别图片关联表删除被删除的图片");
|
|
assoProductCategoryPictureMapper.deleteByIds(oldPictureIds);
|
|
assoProductCategoryPictureMapper.deleteByIds(oldPictureIds);
|
|
}
|
|
}
|
|
|
|
|
|
- ArrayList<AssoProductCategoryPicture> assoProductCategoryPictures = new ArrayList<>();
|
|
|
|
- if (files != null) {
|
|
|
|
|
|
+ if (files != null && files.size() != 0) {
|
|
|
|
+ ArrayList<AssoProductCategoryPicture> assoProductCategoryPictures = new ArrayList<>();
|
|
for (MultipartFile file : files) {
|
|
for (MultipartFile file : files) {
|
|
UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
- String picturePath = fileDTO.getPath();
|
|
|
|
AssoProductCategoryPicture assoProductCategoryPicture = new AssoProductCategoryPicture()
|
|
AssoProductCategoryPicture assoProductCategoryPicture = new AssoProductCategoryPicture()
|
|
.setProductCategoryId(productCategoryId)
|
|
.setProductCategoryId(productCategoryId)
|
|
- .setPicture(picturePath);
|
|
|
|
|
|
+ .setName(fileDTO.getName())
|
|
|
|
+ .setSuffix(fileDTO.getExtName())
|
|
|
|
+ .setUrl(fileDTO.getPath());
|
|
assoProductCategoryPictures.add(assoProductCategoryPicture);
|
|
assoProductCategoryPictures.add(assoProductCategoryPicture);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -206,20 +217,11 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
throw new XiaoShiException(message);
|
|
throw new XiaoShiException(message);
|
|
}
|
|
}
|
|
|
|
|
|
- //删除产品类别
|
|
|
|
- log.info("删除产品类别");
|
|
|
|
- int rows = productCategoryMapper.deleteById(id);
|
|
|
|
- if (rows != 1) {
|
|
|
|
- String message = "删除产品类别失败,服务器忙请稍后再试!";
|
|
|
|
- log.info("{}", message);
|
|
|
|
- throw new XiaoShiException(message);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//检查该产品类别是否有图片
|
|
//检查该产品类别是否有图片
|
|
count = assoProductCategoryPictureMapper.countByProductCategoryId(id);
|
|
count = assoProductCategoryPictureMapper.countByProductCategoryId(id);
|
|
- if (count != 0) {
|
|
|
|
|
|
+ if (count > 0) {
|
|
log.info("产品类别图片关联表删除数据");
|
|
log.info("产品类别图片关联表删除数据");
|
|
- rows = assoProductCategoryPictureMapper.deleteByProductCategoryId(id);
|
|
|
|
|
|
+ int rows = assoProductCategoryPictureMapper.deleteByProductCategoryId(id);
|
|
if (rows != count) {
|
|
if (rows != count) {
|
|
String message = "删除产品类别失败,产品类别图片关联表删除数据失败,服务器忙请稍后再试!";
|
|
String message = "删除产品类别失败,产品类别图片关联表删除数据失败,服务器忙请稍后再试!";
|
|
log.info("{}", message);
|
|
log.info("{}", message);
|
|
@@ -227,6 +229,15 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //删除产品类别
|
|
|
|
+ log.info("删除产品类别");
|
|
|
|
+ int rows = productCategoryMapper.deleteById(id);
|
|
|
|
+ if (rows != 1) {
|
|
|
|
+ String message = "删除产品类别失败,服务器忙请稍后再试!";
|
|
|
|
+ log.info("{}", message);
|
|
|
|
+ throw new XiaoShiException(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
log.info("删除产品类别完成");
|
|
log.info("删除产品类别完成");
|
|
|
|
|
|
}
|
|
}
|