Browse Source

产品类别趋势 lrj

lwhhszx 2 years ago
parent
commit
60a0f9470b

+ 31 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/ProductCategoryDTO.java

@@ -0,0 +1,31 @@
+package cn.cslg.pas.common.model.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * 新增产品类别的DTO类
+ */
+@Accessors(chain = true)
+@Data
+public class ProductCategoryDTO implements Serializable {
+    /**
+     * 产品类别Id
+     */
+    private Integer categoryId;
+    /**
+     * 产品地区
+     */
+    private String categoryArea;
+    /**
+     * 时间单位(0月份,1季度,不传为月份)
+     */
+    private Integer timeUnit;
+    /**
+     * 公司名称
+     */
+    private String companyName;
+
+}

+ 39 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/ProductCategoryTrendVO.java

@@ -0,0 +1,39 @@
+package cn.cslg.pas.common.model.vo;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 产品类别趋势图查询VO类
+ */
+@Accessors(chain = true)
+@Data
+public class ProductCategoryTrendVO implements Serializable {
+    /**
+     * 产品id
+     */
+    private Integer productId;
+    /**
+     * 产品名称
+     */
+    private String productName;
+    private List<saleVO> saleVOS;
+    @Data
+    @Accessors(chain = true)
+    public static class saleVO {
+        /**
+         * 时间(季度或者月份)
+         */
+        private String marketData;
+
+        /**
+         * 销售额
+         */
+        private Double saleTotalMoney;
+
+    }
+
+}

+ 17 - 1
PAS/src/main/java/cn/cslg/pas/controller/ProductCategoryController.java

@@ -3,8 +3,10 @@ package cn.cslg.pas.controller;
 import cn.cslg.pas.common.JsonPage;
 import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.model.dto.ProductCategoryAddNewDTO;
+import cn.cslg.pas.common.model.dto.ProductCategoryDTO;
 import cn.cslg.pas.common.model.dto.ProductCategoryQueryPageDTO;
 import cn.cslg.pas.common.model.dto.ProductCategoryUpdateDTO;
+import cn.cslg.pas.common.model.vo.ProductCategoryTrendVO;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.service.IProductCategoryService;
@@ -83,5 +85,19 @@ public class ProductCategoryController {
         }
         return Response.success("删除产品类别完成");
     }
-
+    @Operation(summary = "查询产品架构趋势图")
+    @PostMapping("/showTrend")
+    public String showTrend(@RequestBody  ProductCategoryDTO dto) {
+        return Response.success( productCategoryService.showTrend(dto));
+    }
+    @Operation(summary = "获得架构的地区集合")
+    @GetMapping("/getAreaList")
+    public String getAreaList(Integer id) {
+        return Response.success( productCategoryService.getAreaList(id));
+    }
+    @Operation(summary = "获得架构的公司集合")
+    @GetMapping("/getCompanyList")
+    public String getCompanyList(Integer id) {
+        return Response.success( productCategoryService.getCompanyList(id));
+    }
 }

+ 3 - 1
PAS/src/main/java/cn/cslg/pas/mapper/ProductMapper.java

@@ -3,6 +3,8 @@ package cn.cslg.pas.mapper;
 import cn.cslg.pas.common.model.dto.ProductQueryPageDTO;
 import cn.cslg.pas.common.model.vo.ProductVO;
 import cn.cslg.pas.domain.Product;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.poi.sl.usermodel.Background;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -14,7 +16,7 @@ import java.util.List;
  * @Date 2023/3/8
  */
 @Repository
-public interface ProductMapper {
+public interface ProductMapper extends BaseMapper<Product> {
     /**
      * 插入数据
      *

+ 2 - 1
PAS/src/main/java/cn/cslg/pas/mapper/ProductMarketDataMapper.java

@@ -3,6 +3,7 @@ package cn.cslg.pas.mapper;
 import cn.cslg.pas.common.model.dto.ProductMarketDataQueryPageDTO;
 import cn.cslg.pas.common.model.vo.ProductMarketDataVO;
 import cn.cslg.pas.domain.ProductMarketData;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.springframework.stereotype.Repository;
 
 import java.util.Date;
@@ -15,7 +16,7 @@ import java.util.List;
  * @Date 2023/3/9
  */
 @Repository
-public interface ProductMarketDataMapper {
+public interface ProductMarketDataMapper extends BaseMapper<ProductMarketData> {
     /**
      * 插入数据
      *

+ 13 - 0
PAS/src/main/java/cn/cslg/pas/service/IProductCategoryService.java

@@ -2,8 +2,10 @@ package cn.cslg.pas.service;
 
 import cn.cslg.pas.common.JsonPage;
 import cn.cslg.pas.common.model.dto.ProductCategoryAddNewDTO;
+import cn.cslg.pas.common.model.dto.ProductCategoryDTO;
 import cn.cslg.pas.common.model.dto.ProductCategoryQueryPageDTO;
 import cn.cslg.pas.common.model.dto.ProductCategoryUpdateDTO;
+import cn.cslg.pas.common.model.vo.ProductCategoryTrendVO;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -49,4 +51,15 @@ public interface IProductCategoryService {
     @Transactional
     void delete(Integer id);
 
+    /**
+     * 查询产品架构趋势图
+     * @param dto
+     * @autor lrj
+     */
+    @Transactional
+    List<ProductCategoryTrendVO> showTrend(ProductCategoryDTO dto);
+
+    List<String>  getAreaList(Integer id);
+
+    List<String> getCompanyList(Integer id);
 }

+ 3 - 1
PAS/src/main/java/cn/cslg/pas/service/IProductService.java

@@ -4,6 +4,9 @@ import cn.cslg.pas.common.JsonPage;
 import cn.cslg.pas.common.model.dto.ProductAddNewDTO;
 import cn.cslg.pas.common.model.dto.ProductQueryPageDTO;
 import cn.cslg.pas.common.model.dto.ProductUpdateDTO;
+import cn.cslg.pas.domain.Project;
+import cn.cslg.pas.mapper.ProjectMapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -50,5 +53,4 @@ public interface IProductService {
     @Transactional
     void delete(Integer id);
 
-
 }

+ 127 - 2
PAS/src/main/java/cn/cslg/pas/service/impl/ProductCategoryServiceImpl.java

@@ -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;
+    }
 }

+ 4 - 15
PAS/src/main/java/cn/cslg/pas/service/impl/ProductMarketDataIServicempl.java

@@ -8,10 +8,13 @@ import cn.cslg.pas.common.model.dto.ProductMarketDataUpdateDTO;
 import cn.cslg.pas.common.model.vo.ProductMarketDataVO;
 import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
+import cn.cslg.pas.domain.Product;
 import cn.cslg.pas.domain.ProductMarketData;
 import cn.cslg.pas.exception.XiaoShiException;
+import cn.cslg.pas.mapper.ProductMapper;
 import cn.cslg.pas.mapper.ProductMarketDataMapper;
 import cn.cslg.pas.service.IProductMarketDataService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.RequiredArgsConstructor;
@@ -32,7 +35,7 @@ import java.util.regex.Pattern;
 @RequiredArgsConstructor
 @Slf4j
 @Service
-public class ProductMarketDataIServicempl implements IProductMarketDataService {
+public class ProductMarketDataIServicempl extends ServiceImpl<ProductMarketDataMapper, ProductMarketData> implements IProductMarketDataService {
     private final ProductMarketDataMapper productMarketDataMapper;
     private final CacheUtils cacheUtils;
     private final LoginUtils loginUtils;
@@ -132,20 +135,6 @@ public class ProductMarketDataIServicempl implements IProductMarketDataService {
     public JsonPage query(ProductMarketDataQueryPageDTO productMarketDataQueryPageDTO) {
         log.info("开始处理【分页查询产品营销数据】的业务,参数为:{}", productMarketDataQueryPageDTO);
         String orderBy = productMarketDataQueryPageDTO.getOrderBy();
-//        if (orderBy != null) {
-//            char[] cha = orderBy.toCharArray();
-//            String regex = "[A-Z]+";
-//            StringBuffer builder = new StringBuffer();
-//            for (char c : cha) {
-//                if ((c + "").matches(regex)) {
-//                    String _c = "_" + (c + "").toLowerCase();
-//                    builder.append(_c);
-//                    continue;
-//                }
-//                String _c = String.valueOf(c);
-//                builder.append(c);
-//            }
-//        }
         if (orderBy != null) {
             String regex = "[A-Z]+";
             Pattern pattern = Pattern.compile(regex);

+ 4 - 1
PAS/src/main/java/cn/cslg/pas/service/impl/ProductServiceImpl.java

@@ -9,11 +9,14 @@ 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.Project;
 import cn.cslg.pas.domain.asso.AssoProductPicture;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.mapper.AssoProductPictureMapper;
 import cn.cslg.pas.mapper.ProductMapper;
+import cn.cslg.pas.mapper.ProjectMapper;
 import cn.cslg.pas.service.IProductService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.RequiredArgsConstructor;
@@ -34,7 +37,7 @@ import java.util.List;
 @RequiredArgsConstructor
 @Slf4j
 @Service
-public class ProductServiceImpl implements IProductService {
+public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>  implements IProductService  {
     private final ProductMapper productMapper;
     private final AssoProductPictureMapper assoProductPictureMapper;
     private final CacheUtils cacheUtils;