Ver Fonte

3/14 XieXiang

xiexiang há 2 anos atrás
pai
commit
5dd8a54cc3

+ 26 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/ProductMarketDataDTO.java

@@ -0,0 +1,26 @@
+package cn.cslg.pas.common.model.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/3/13
+ */
+@Accessors(chain = true)
+@Data
+public class ProductMarketDataDTO {
+    /**
+     * 产品Id
+     */
+    private Integer productId;
+    /**
+     * 产品地区
+     */
+    private String saleArea;
+    /**
+     * 时间单位(0月份,1季度,2年份,不传为月份)
+     */
+    private Integer timeUnit;
+
+}

+ 27 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/PMDTrendVO.java

@@ -0,0 +1,27 @@
+package cn.cslg.pas.common.model.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 联合产品id以及名称总体返回类
+ *
+ * @Author xiexiang
+ * @Date 2023/3/14
+ */
+@Data
+public class PMDTrendVO {
+    /**
+     * 产品id
+     */
+    private Integer productId;
+    /**
+     * 产品名称
+     */
+    private String productName;
+    /**
+     * 返回类
+     */
+    private List<ProductMarketDataTrendVO> saleVOS;
+}

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

@@ -21,6 +21,7 @@ public class ProductCategoryTrendVO implements Serializable {
      */
     private String productName;
     private List<saleVO> saleVOS;
+
     @Data
     @Accessors(chain = true)
     public static class saleVO {

+ 30 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/ProductMarketDataTrendVO.java

@@ -0,0 +1,30 @@
+package cn.cslg.pas.common.model.vo;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+
+
+/**
+ * @Author xiexiang
+ * @Date 2023/3/13
+ */
+@Accessors(chain = true)
+@Data
+public class ProductMarketDataTrendVO {
+
+        /**
+         * 时间(季度/月份/年份)
+         */
+        private String marketDate;
+
+        /**
+         * 销售额
+         */
+        private Double saleTotalMoney;
+}
+
+
+
+
+

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

@@ -76,7 +76,7 @@ public class PermissionRecordController {
         pageHelperT.setList(queryResult);
         pageHelperT.setCurrent(queryPREntity.getCurrent());
         pageHelperT.setSize(queryPREntity.getSize());
-        pageHelperT.setTotal(permissionRecordMapper.countById());
+        pageHelperT.setTotal(permissionRecordMapper.countByPatentNo(queryPREntity.getPatentNo()));
         return Response.success(pageHelperT);
     }
 }

+ 20 - 3
PAS/src/main/java/cn/cslg/pas/controller/ProductController.java

@@ -2,11 +2,12 @@ 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.ProductAddNewDTO;
-import cn.cslg.pas.common.model.dto.ProductQueryPageDTO;
-import cn.cslg.pas.common.model.dto.ProductUpdateDTO;
+import cn.cslg.pas.common.model.dto.*;
+import cn.cslg.pas.common.model.vo.PMDTrendVO;
+import cn.cslg.pas.common.model.vo.ProductMarketDataTrendVO;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.exception.XiaoShiException;
+import cn.cslg.pas.service.IProductMarketDataService;
 import cn.cslg.pas.service.IProductService;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.v3.oas.annotations.Operation;
@@ -31,6 +32,7 @@ import java.util.List;
 @RestController
 public class ProductController {
     private final IProductService productService;
+    private final IProductMarketDataService productMarketDataService;
 
     @Operation(summary = "新增产品")
     @PostMapping("/addNew")
@@ -72,6 +74,21 @@ public class ProductController {
         return Response.success(jsonPage);
     }
 
+    @Operation(summary = "查询产品趋势图")
+    @PostMapping("/showTrend")
+    public String showTrend(@RequestBody ProductMarketDataDTO dto) {
+        List<ProductMarketDataTrendVO> queryResult = productMarketDataService.showTrend(dto);
+        PMDTrendVO pmdTrendVO = new PMDTrendVO();
+        pmdTrendVO.setProductId(dto.getProductId());
+        pmdTrendVO.setProductName(productMarketDataService.queryNameByProductId(dto.getProductId()));
+        pmdTrendVO.setSaleVOS(queryResult);
+        if (pmdTrendVO != null){
+            return Response.success(pmdTrendVO);
+        } else {
+            return Response.error("查询失败");
+        }
+    }
+
     @Operation(summary = "删除产品")
     @GetMapping("/delete")
     public String delete(Integer id) {

+ 3 - 2
PAS/src/main/java/cn/cslg/pas/mapper/PermissionRecordMapper.java

@@ -31,11 +31,12 @@ public interface PermissionRecordMapper {
     int update(PermissionRecord permissionRecord);
 
     /**
-     * 统计数量
+     * 统计该专利号下许可记录的数量
      *
+     * @param patentNo 专利号
      * @return 返回统计到的总数量total
      */
-    int countById();
+    int countByPatentNo(String patentNo);
 
 
     /**

+ 8 - 0
PAS/src/main/java/cn/cslg/pas/mapper/ProductMapper.java

@@ -65,6 +65,14 @@ public interface ProductMapper extends BaseMapper<Product> {
     int countById(Integer id);
 
     /**
+     * 根据id查询产品名称
+     *
+     * @param id 产品id
+     * @return 返回查询到的名字
+     */
+    String queryNameById(Integer id);
+
+    /**
      * 根据所属产品类别id统计数量
      *
      * @param productCategoryId 所属产品类别id

+ 28 - 0
PAS/src/main/java/cn/cslg/pas/mapper/ProductMarketDataMapper.java

@@ -1,10 +1,12 @@
 package cn.cslg.pas.mapper;
 
 import cn.cslg.pas.common.model.dto.ProductMarketDataQueryPageDTO;
+import cn.cslg.pas.common.model.vo.ProductMarketDataTrendVO;
 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 org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
 import java.util.List;
@@ -67,4 +69,30 @@ public interface ProductMarketDataMapper extends BaseMapper<ProductMarketData> {
      */
     List<ProductMarketDataVO> query(ProductMarketDataQueryPageDTO productMarketDataQueryPageDTO);
 
+    /**
+     * 传入的营销地区saleArea不为空(按地区划分),且timeUnit为2,按照年份返回数据
+     *
+     * @param saleArea 营销地区
+     * @param productId 产品id(必需)
+     * @return 返回查询到的数据
+     */
+    List<ProductMarketDataTrendVO> queryByYear(Integer productId, String saleArea);
+
+    List<ProductMarketDataTrendVO> queryBySeason(Integer productId, String saleArea);
+
+    List<ProductMarketDataTrendVO> queryByMonth(Integer productId, String saleArea);
+
+    /**
+     * 未传入的营销地区saleArea
+     *
+     * @param saleArea 营销地区
+     * @param productId 产品id(必需)
+     * @return 返回查询到的数据
+     */
+    List<ProductMarketDataTrendVO> queryByYear2(Integer productId, String saleArea);
+
+    List<ProductMarketDataTrendVO> queryBySeason2(Integer productId, String saleArea);
+
+    List<ProductMarketDataTrendVO> queryByMonth2(Integer productId, String saleArea);
+
 }

+ 17 - 3
PAS/src/main/java/cn/cslg/pas/service/IProductMarketDataService.java

@@ -1,11 +1,12 @@
 package cn.cslg.pas.service;
 
 import cn.cslg.pas.common.JsonPage;
-import cn.cslg.pas.common.model.dto.ProductMarketDataAddNewDTO;
-import cn.cslg.pas.common.model.dto.ProductMarketDataQueryPageDTO;
-import cn.cslg.pas.common.model.dto.ProductMarketDataUpdateDTO;
+import cn.cslg.pas.common.model.dto.*;
+import cn.cslg.pas.common.model.vo.ProductMarketDataTrendVO;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+
 /**
  * 产品营销数据的Service层接口
  *
@@ -44,4 +45,17 @@ public interface IProductMarketDataService {
      */
     void delete(Integer id);
 
+    /**
+     * 查询产品营销数据趋势图
+     * @param dto
+     */
+    @Transactional
+    List<ProductMarketDataTrendVO> showTrend(ProductMarketDataDTO dto);
+
+    /**
+     * 根据productId查询productName
+     * @param productId
+     */
+    String queryNameByProductId(Integer productId);
+
 }

+ 53 - 0
PAS/src/main/java/cn/cslg/pas/service/impl/ProductMarketDataIServicempl.java

@@ -3,9 +3,12 @@ package cn.cslg.pas.service.impl;
 import cn.cslg.pas.common.JsonPage;
 import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.dto.ProductMarketDataAddNewDTO;
+import cn.cslg.pas.common.model.dto.ProductMarketDataDTO;
 import cn.cslg.pas.common.model.dto.ProductMarketDataQueryPageDTO;
 import cn.cslg.pas.common.model.dto.ProductMarketDataUpdateDTO;
+import cn.cslg.pas.common.model.vo.ProductMarketDataTrendVO;
 import cn.cslg.pas.common.model.vo.ProductMarketDataVO;
+import cn.cslg.pas.common.model.vo.ProductVO;
 import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.domain.Product;
@@ -37,6 +40,7 @@ import java.util.regex.Pattern;
 @Service
 public class ProductMarketDataIServicempl extends ServiceImpl<ProductMarketDataMapper, ProductMarketData> implements IProductMarketDataService {
     private final ProductMarketDataMapper productMarketDataMapper;
+    private final ProductMapper productMapper;
     private final CacheUtils cacheUtils;
     private final LoginUtils loginUtils;
 
@@ -184,4 +188,53 @@ public class ProductMarketDataIServicempl extends ServiceImpl<ProductMarketDataM
 
     }
 
+    /**
+     * 根据productId查询productName
+     * @param productId
+     */
+    @Override
+    public String queryNameByProductId(Integer productId){
+        int id = productId;
+        String ProductName = productMapper.queryNameById(id);
+        return ProductName;
+    }
+
+    /**
+     * 查询产品趋势图
+     *
+     * @param dto
+     * @return
+     */
+    @Override
+    public List<ProductMarketDataTrendVO> showTrend(ProductMarketDataDTO dto) {
+
+        //传入的营销地区不为空(查询出来的数据要根据地区分类,)
+        if(dto.getSaleArea() != null && dto.getSaleArea() != "") {
+            if(dto.getTimeUnit() == 2){//按照年份返回营销数据
+                List<ProductMarketDataTrendVO> list1= productMarketDataMapper.queryByYear(dto.getProductId(), dto.getSaleArea());
+                return list1;
+            }else if(dto.getTimeUnit() == 1 ){//按照季度返回营销数据
+                List<ProductMarketDataTrendVO> list2= productMarketDataMapper.queryBySeason(dto.getProductId(), dto.getSaleArea());
+                return list2;
+            }else if(dto.getTimeUnit() == 0 && dto.getTimeUnit() == null){//按照月份返回营销数据
+                List<ProductMarketDataTrendVO> list3= productMarketDataMapper.queryByMonth(dto.getProductId(), dto.getSaleArea());
+                return list3;
+            }else{
+                return null;
+            }
+        }else{//未传入的营销地区,所查询出来的数据需要合并
+            if(dto.getTimeUnit() == 2){//按照年份返回营销数据
+                List<ProductMarketDataTrendVO> list4= productMarketDataMapper.queryByYear2(dto.getProductId(), dto.getSaleArea());
+                return list4;
+            }else if(dto.getTimeUnit() == 1 ){//按照季度返回营销数据
+                List<ProductMarketDataTrendVO> list5= productMarketDataMapper.queryBySeason2(dto.getProductId(), dto.getSaleArea());
+                return list5;
+            }else if( dto.getTimeUnit() == null||dto.getTimeUnit() == 0){//按照月份返回营销数据
+                List<ProductMarketDataTrendVO> list6= productMarketDataMapper.queryByMonth2(dto.getProductId(), dto.getSaleArea());
+                return list6;
+            }else{
+                return null;
+            }
+        }
+    }
 }

+ 4 - 3
PAS/src/main/resources/mapper/PermissionRecordMapper.xml

@@ -84,11 +84,12 @@
         where patent_no= #{patentNo}
     </select>
 
-    <!--根据许可id统计数量-->
-    <!--int countById();-->
-    <select id="countById" resultType="int">
+    <!--根据专利号统计许可记录数量-->
+    <!--int countByPatentNo();-->
+    <select id="countByPatentNo" resultType="int">
         select count(*)
         from permission_record
+        where patent_No = #{patentNo}
     </select>
 
 

+ 9 - 0
PAS/src/main/resources/mapper/ProductMapper.xml

@@ -65,6 +65,15 @@
         where id = #{id}
     </select>
 
+    <!--根据id查询名称-->
+    <!-- String queryNameById(Integer id);;-->
+    <select id="queryNameById" resultType="String">
+        select product_Name
+        from product
+        where id = #{id}
+    </select>
+
+
     <!--根据所属产品类别id统计数量-->
     <!--int countByProductCategoryId(Integer productCategoryId);-->
     <select id="countByProductCategoryId" resultType="int">

+ 57 - 0
PAS/src/main/resources/mapper/ProductMarketDataMapper.xml

@@ -109,4 +109,61 @@
         <result column="custom_license_rate" property="customLicenseRate"/>
     </resultMap>
 
+
+    <resultMap id="queryByDateMap" type="cn.cslg.pas.common.model.vo.ProductMarketDataTrendVO">
+        <result column="market_date" property="marketDate"/>
+        <result column="sale_total_money" property="saleTotalMoney"/>
+    </resultMap>
+
+    <select id="queryByYear" resultMap="queryByDateMap">
+        SELECT CONCAT(CAST(YEAR(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'年') AS market_date,
+               sum(sale_money) AS sale_total_money
+        FROM  product_market_data
+        WHERE product_id = #{productId} AND saleArea = #{saleArea}
+        GROUP BY market_date
+    </select>
+
+    <select id="queryBySeason" resultMap="queryByDateMap">
+        SELECT CONCAT(CAST(YEAR(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'年',
+                      '第',CAST(QUARTER(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'季度') AS market_date,
+               sum(sale_money) AS sale_total_money
+        FROM  product_market_data
+        WHERE product_id = #{productId} AND saleArea = #{saleArea}
+        GROUP BY market_date
+    </select>
+
+    <select id="queryByMonth" resultMap="queryByDateMap">
+        SELECT CONCAT(CAST(YEAR(STR_TO_DATE(sale_time,'%Y-%m')) AS CHAR),'-',
+                      CAST(MONTH(STR_TO_DATE(sale_time,'%Y-%m')) AS CHAR)) AS market_date,
+               sum(sale_money) AS sale_total_money
+        FROM  product_market_data
+        WHERE product_id = #{productId} AND saleArea = #{saleArea}
+        GROUP BY market_date
+    </select>
+
+    <select id="queryByYear2" resultMap="queryByDateMap">
+        SELECT CONCAT(CAST(YEAR(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'年') AS market_date,
+               sum(sale_money) AS sale_total_money
+        FROM product_market_data
+        WHERE product_id = #{productId}
+        GROUP BY market_date
+    </select>
+
+    <select id="queryBySeason2" resultMap="queryByDateMap">
+        SELECT CONCAT(CAST(YEAR(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'年',
+                '第',CAST(QUARTER(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'季度') AS market_date,
+               sum(sale_money) AS sale_total_money
+        FROM product_market_data
+        WHERE product_id = #{productId}
+        GROUP BY market_date
+    </select>
+
+    <select id="queryByMonth2" resultMap="queryByDateMap">
+        SELECT CONCAT(CAST(YEAR(STR_TO_DATE(sale_time,'%Y-%m')) AS CHAR),'-',
+                CAST(MONTH(STR_TO_DATE(sale_time,'%Y-%m')) AS CHAR)) AS market_date,
+               sum(sale_money) AS sale_total_money
+        FROM product_market_data
+        WHERE product_id = #{productId}
+        GROUP BY market_date
+    </select>
 </mapper>