|
@@ -119,9 +119,11 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
public JsonPage query(ProductCategoryQueryPageDTO productCategoryQueryPageDTO) {
|
|
|
log.info("开始处理【分页查询产品类别】的业务,参数为:{}", productCategoryQueryPageDTO);
|
|
|
|
|
|
+ //获取登陆人信息(取出租户id,控制查询权限)
|
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
productCategoryQueryPageDTO.setTenantId(personnelVO.getTenantId());
|
|
|
|
|
|
+ //分页查询
|
|
|
Integer current = productCategoryQueryPageDTO.getCurrent();
|
|
|
Integer size = productCategoryQueryPageDTO.getSize();
|
|
|
if (current != null && size != null) {
|
|
@@ -141,6 +143,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
public void update(ProductCategoryUpdateDTO productCategoryUpdateDTO, List<MultipartFile> files) {
|
|
|
log.info("开始处理【修改产品类别】的业务,参数为:{}, {}", productCategoryUpdateDTO, files);
|
|
|
|
|
|
+ //获取登陆人信息(取出租户id,控制权限)
|
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
Integer tenantId = personnelVO.getTenantId();
|
|
|
|
|
@@ -150,18 +153,14 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
log.info("检查尝试修改的数据是否存在");
|
|
|
int count = productCategoryMapper.countById(productCategoryId);
|
|
|
if (count == 0) {
|
|
|
- String message = "修改产品类别失败,尝试访问的数据已不存在";
|
|
|
- log.info("{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
+ ThrowException.throwXiaoShiException("修改产品类别失败,尝试访问的数据已不存在");
|
|
|
}
|
|
|
|
|
|
//检查尝试修改的产品类别名称是否被占用
|
|
|
log.info("检查尝试修改的产品类别名称是否被占用");
|
|
|
count = productCategoryMapper.countByIdAndName(productCategoryId, productCategoryName, tenantId);
|
|
|
if (count > 0) {
|
|
|
- String message = "修改产品类别失败,类别名称【" + productCategoryName + "】已存在,请尝试更换名称";
|
|
|
- log.info("{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
+ ThrowException.throwXiaoShiException("修改产品类别失败,类别名称【" + productCategoryName + "】已存在,请尝试更换名称");
|
|
|
}
|
|
|
|
|
|
//产品类别DTO对象赋值给实体类
|
|
@@ -171,9 +170,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
log.info("修改产品类别");
|
|
|
int rows = productCategoryMapper.updateById(productCategory);
|
|
|
if (rows != 1) {
|
|
|
- String message = "修改产品类别失败,服务器忙请稍后再次尝试!";
|
|
|
- log.info("{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
+ ThrowException.throwXiaoShiException("修改产品类别失败,服务器忙请稍后再次尝试!");
|
|
|
}
|
|
|
|
|
|
//先通过产品类别id查询出所有原来的图片文件id
|
|
@@ -190,14 +187,16 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
Integer newOldPictureId = productCategoryPictureUpateDTO.getId();
|
|
|
newOldPictureIds.add(newOldPictureId);
|
|
|
}
|
|
|
- //图片id集合去重,保留下来的即被删除的图片id
|
|
|
+ //集合去重
|
|
|
oldPictureIds.removeAll(newOldPictureIds);
|
|
|
|
|
|
+ //判断若去重后的集合(即被前台删除的图片文件)仍有长度,则根据该图片id集合删除产品类别与图片关联表数据
|
|
|
if (oldPictureIds.size() > 0) {
|
|
|
log.info("产品类别图片关联表删除被删除的图片");
|
|
|
assoProductCategoryPictureMapper.deleteByIds(oldPictureIds);
|
|
|
}
|
|
|
|
|
|
+ //判断若有上传新的图片文件,则上传图片并入库
|
|
|
if (files != null && files.size() != 0) {
|
|
|
ArrayList<AssoProductCategoryPicture> assoProductCategoryPictures = new ArrayList<>();
|
|
|
for (MultipartFile file : files) {
|
|
@@ -236,9 +235,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
log.info("产品类别图片关联表删除数据");
|
|
|
int rows = assoProductCategoryPictureMapper.deleteByProductCategoryId(id);
|
|
|
if (rows != count) {
|
|
|
- String message = "删除产品类别失败,产品类别图片关联表删除数据失败,服务器忙请稍后再试!";
|
|
|
- log.info("{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
+ ThrowException.throwXiaoShiException("删除产品类别失败,产品类别图片关联表删除数据失败,服务器忙请稍后再试!");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -246,9 +243,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
log.info("删除产品类别");
|
|
|
int rows = productCategoryMapper.deleteById(id);
|
|
|
if (rows != 1) {
|
|
|
- String message = "删除产品类别失败,服务器忙请稍后再试!";
|
|
|
- log.info("{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
+ ThrowException.throwXiaoShiException("删除产品类别失败,服务器忙请稍后再试!");
|
|
|
}
|
|
|
|
|
|
log.info("删除产品类别完成");
|
|
@@ -258,20 +253,20 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
//返回总的营销数据以及每个的营销数据
|
|
|
@Override
|
|
|
public List<ProductCategoryTrendVO> showTrend(ProductCategoryDTO dto) {
|
|
|
- //判断架构id是否有内容,没有的话直接返回null
|
|
|
+ //判断产品类别id是否有内容,没有的话直接返回null
|
|
|
if (dto.getCategoryId() == null || dto.getCategoryId() == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
- //存储各个产品信息和营销数据
|
|
|
+ //存储每个产品类别信息和营销数据
|
|
|
List<ProductCategoryTrendVO> trendVOS = new ArrayList<>();
|
|
|
- //存储所有产品营销数据
|
|
|
+ //存储所有产品类别营销数据
|
|
|
List<ProductMarketDataTrendVO> saleVOS = new ArrayList<>();
|
|
|
//存储所有
|
|
|
ProductCategoryTrendVO totalTrendVO = new ProductCategoryTrendVO();
|
|
|
//返回总的营销数据 将id设为0
|
|
|
totalTrendVO.setProductId(0);
|
|
|
totalTrendVO.setProductName("总产品");
|
|
|
- //查询架构id返回的总体营销数据
|
|
|
+ //查询产品类别id返回的总体营销数据
|
|
|
List<ProductMarketDataTrendVO> totalSaleVOS = new ArrayList<>();
|
|
|
if (dto.getTimeUnit() == 2) {//按照年份返回营销数据
|
|
|
totalSaleVOS = productCategoryMapper.categoryQueryByYear(dto.getCategoryId(), dto.getCategoryArea(), dto.getCompanyName());
|
|
@@ -286,7 +281,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
//根据传入的类别id、公司名称以及营销地区查询产品id
|
|
|
List<ProductIdAndNameVO> idNameVOS = new ArrayList<>();
|
|
|
idNameVOS = productCategoryMapper.queryProductIdAndNameByCategoryId(dto.getCategoryId(), dto.getCompanyName());
|
|
|
- //返回根据架构id查询到的每个产品id的营销数据
|
|
|
+ //返回根据产品类别id查询到的每个产品id的营销数据
|
|
|
//遍历
|
|
|
for (ProductIdAndNameVO idNameVO : idNameVOS) {//遍历类取得id和名称
|
|
|
ProductCategoryTrendVO trendVO = new ProductCategoryTrendVO();
|
|
@@ -321,7 +316,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
public List<String> getCompanyList(Integer id) {
|
|
|
|
|
|
List<String> areaList = new ArrayList<>();
|
|
|
- //根据架构id获得产品
|
|
|
+ //根据产品类别id获得产品
|
|
|
LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();
|
|
|
productWrapper.eq(Product::getProductCategoryId, id);
|
|
|
List<Product> products = productService.list(productWrapper);
|