|
@@ -4,27 +4,37 @@ import cn.cslg.pas.common.JsonPage;
|
|
|
import cn.cslg.pas.common.model.PersonnelVO;
|
|
|
import cn.cslg.pas.common.model.dto.*;
|
|
|
import cn.cslg.pas.common.model.vo.ProductCategoryPictureVO;
|
|
|
+import cn.cslg.pas.common.model.vo.ProductCategoryTrendVO;
|
|
|
import cn.cslg.pas.common.model.vo.ProductCategoryVO;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
|
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
|
+import cn.cslg.pas.domain.Product;
|
|
|
import cn.cslg.pas.domain.ProductCategory;
|
|
|
+import cn.cslg.pas.domain.ProductMarketData;
|
|
|
+import cn.cslg.pas.domain.Project;
|
|
|
import cn.cslg.pas.domain.asso.AssoProductCategoryPicture;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.mapper.AssoProductCategoryPictureMapper;
|
|
|
import cn.cslg.pas.mapper.ProductCategoryMapper;
|
|
|
import cn.cslg.pas.mapper.ProductMapper;
|
|
|
+import cn.cslg.pas.mapper.ProjectMapper;
|
|
|
import cn.cslg.pas.service.IProductCategoryService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 产品类别的Service层接口实现类
|
|
@@ -42,6 +52,8 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
private final CacheUtils cacheUtils;
|
|
|
private final LoginUtils loginUtils;
|
|
|
private final FileUtils fileUtils;
|
|
|
+ private final ProductServiceImpl productService;
|
|
|
+ private final ProductMarketDataIServicempl productMarketDataIService;
|
|
|
|
|
|
/**
|
|
|
* 新增产品类别
|
|
@@ -242,4 +254,117 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<ProductCategoryTrendVO> showTrend(ProductCategoryDTO dto) {
|
|
|
+ //存储各个产品信息和营销数据信息
|
|
|
+ List<ProductCategoryTrendVO> trendVOS = new ArrayList<>();
|
|
|
+ //存储所有产品的营销数据
|
|
|
+ List<ProductMarketData> marketData = new ArrayList<>();
|
|
|
+ //根据产品类别ID获得产品id和产品名称
|
|
|
+ LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productWrapper.eq(Product::getProductCategoryId, dto.getCategoryId());
|
|
|
+ List<Product> products = productService.list(productWrapper);
|
|
|
+ if (products.size() != 0) {
|
|
|
+ List<Integer> productIds = products.stream().map(Product::getId).collect(Collectors.toList());
|
|
|
+ if (productIds.size() > 0) {
|
|
|
+ //根据产品Id获得产品营销数据
|
|
|
+ LambdaQueryWrapper<ProductMarketData> market = new LambdaQueryWrapper<>();
|
|
|
+ market.in(ProductMarketData::getProductId, productIds);
|
|
|
+ marketData = productMarketDataIService.list(market);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Product product : products) {
|
|
|
+ ProductCategoryTrendVO trendVO = new ProductCategoryTrendVO();
|
|
|
+ trendVO.setProductId(product.getId());
|
|
|
+ trendVO.setProductName(product.getProductName());
|
|
|
+ //获得产品的营销数据
|
|
|
+ // 如果地区不为空
|
|
|
+ List<ProductMarketData> temMarketData = new ArrayList<>();
|
|
|
+ if (dto.getCategoryArea() != null && dto.getCategoryArea() != "") {
|
|
|
+ temMarketData = marketData.stream().filter(item -> item.getProductId().equals(product.getId()) && item.getSaleArea().equals(dto.getCategoryArea())).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ temMarketData = marketData.stream().filter(item -> item.getProductId().equals(product.getId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ Map<String, Object> marketDataMap = new HashMap<>();
|
|
|
+ //营销数据遍历
|
|
|
+ temMarketData.forEach(item -> {
|
|
|
+ //获得营销数据的时间
|
|
|
+ String date = item.getSaleTime();
|
|
|
+ double saleCount = item.getSaleCount() * item.getSaleMoney();
|
|
|
+ if (dto.getTimeUnit() == 1) {
|
|
|
+ try {
|
|
|
+ Date dateForm = new SimpleDateFormat("yyyy-MM").parse(date);
|
|
|
+ int month = dateForm.getMonth();
|
|
|
+ int year = dateForm.getYear();
|
|
|
+ int season = (month - 1) / 3;
|
|
|
+ date = year + "-" + season;
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算销售额
|
|
|
+ if (marketDataMap.get(date) != null) {
|
|
|
+ saleCount += Double.parseDouble(marketDataMap.get(date).toString());
|
|
|
+ }
|
|
|
+ marketDataMap.put(date, saleCount);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ Set keyset = marketDataMap.keySet();
|
|
|
+ List<ProductCategoryTrendVO.saleVO> saleVOS = new ArrayList<>();
|
|
|
+ for (Object key : keyset) {
|
|
|
+ ProductCategoryTrendVO.saleVO saleVO = new ProductCategoryTrendVO.saleVO();
|
|
|
+ saleVO.setMarketData(key.toString());
|
|
|
+ saleVO.setSaleTotalMoney(Double.parseDouble(marketDataMap.get(key).toString()));
|
|
|
+ saleVOS.add(saleVO);
|
|
|
+ }
|
|
|
+ trendVO.setSaleVOS(saleVOS);
|
|
|
+ trendVOS.add(trendVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ return trendVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getAreaList(Integer id) {
|
|
|
+ //存储所有产品的营销数据
|
|
|
+ List<ProductMarketData> marketData = new ArrayList<>();
|
|
|
+ List<String> areaList = new ArrayList<>();
|
|
|
+ //根据架构id获得产品
|
|
|
+ LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productWrapper.eq(Product::getProductCategoryId, id);
|
|
|
+ List<Product> products = productService.list(productWrapper);
|
|
|
+ if (products.size() != 0) {
|
|
|
+ List<Integer> productIds = products.stream().map(Product::getId).collect(Collectors.toList());
|
|
|
+ if (productIds.size() > 0) {
|
|
|
+ //根据产品Id获得产品营销数据
|
|
|
+ LambdaQueryWrapper<ProductMarketData> market = new LambdaQueryWrapper<>();
|
|
|
+ market.in(ProductMarketData::getProductId, productIds);
|
|
|
+ marketData = productMarketDataIService.list(market);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ marketData.forEach(
|
|
|
+ item -> {
|
|
|
+ if (!areaList.contains(item.getSaleArea())) {
|
|
|
+ areaList.add(item.getSaleArea());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return areaList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<String> getCompanyList(Integer id) {
|
|
|
+
|
|
|
+ List<String> areaList = new ArrayList<>();
|
|
|
+ //根据架构id获得产品
|
|
|
+ LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productWrapper.eq(Product::getProductCategoryId, id);
|
|
|
+ List<Product> products = productService.list(productWrapper);
|
|
|
+ products.forEach(item->{
|
|
|
+ if(!areaList.contains(item.getCompanyName())){
|
|
|
+ areaList.add(item.getCompanyName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return areaList;
|
|
|
+ }
|
|
|
}
|