chendayu 2 سال پیش
والد
کامیت
ebd32ce96c

+ 20 - 8
PAS/src/main/java/cn/cslg/pas/mapper/ProductCategoryMapper.java

@@ -51,6 +51,15 @@ public interface ProductCategoryMapper {
     int countByProductCategoryName(String productCategoryName);
 
     /**
+     * 根据id和名称统计数量
+     *
+     * @param id                  id
+     * @param productCategoryName 名称
+     * @return
+     */
+    int countByIdAndName(Integer id, String productCategoryName);
+
+    /**
      * 根据id统计数量
      *
      * @param id 产品类别id
@@ -68,20 +77,22 @@ public interface ProductCategoryMapper {
 
     /**
      * 根据架构id、营销地区、时间单位和公司名称查询营销数据
-     * @param categoryId 架构id(必需)
+     *
+     * @param categoryId   架构id(必需)
      * @param categoryArea 营销地区
-     * @param companyName 公司名称
+     * @param companyName  公司名称
      * @return 返回查询到的营销数据
      */
-    List<ProductMarketDataTrendVO> categoryQueryByYear(Integer categoryId,String categoryArea,String companyName);
+    List<ProductMarketDataTrendVO> categoryQueryByYear(Integer categoryId, String categoryArea, String companyName);
 
-    List<ProductMarketDataTrendVO> categoryQueryBySeason(Integer categoryId,String categoryArea,String companyName);
+    List<ProductMarketDataTrendVO> categoryQueryBySeason(Integer categoryId, String categoryArea, String companyName);
 
-    List<ProductMarketDataTrendVO> categoryQueryByMonth(Integer categoryId,String categoryArea,String companyName);
+    List<ProductMarketDataTrendVO> categoryQueryByMonth(Integer categoryId, String categoryArea, String companyName);
 
     /**
      * 根据产品id查询营销数据
-     * @param productId 产品id
+     *
+     * @param productId    产品id
      * @param categoryArea 营销地区
      * @return 返回查询到的营销数据
      */
@@ -94,12 +105,13 @@ public interface ProductCategoryMapper {
 
     /**
      * 根据架构id查询产品id和名称
-     * @param categoryId 架构id(必需)
+     *
+     * @param categoryId  架构id(必需)
      * @param companyName 公司名
      * @return productId 产品id
      * @return productName 产品名称
      */
-    List<ProductIdAndNameVO> queryProductIdAndNameByCategoryId(Integer categoryId,String companyName);
+    List<ProductIdAndNameVO> queryProductIdAndNameByCategoryId(Integer categoryId, String companyName);
 
     /**
      * 查询地区列表

+ 19 - 8
PAS/src/main/java/cn/cslg/pas/service/impl/ProductCategoryServiceImpl.java

@@ -147,6 +147,7 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
 
         //检查尝试修改的数据是否存在
         Integer productCategoryId = productCategoryUpdateDTO.getId();
+        String productCategoryName = productCategoryUpdateDTO.getProductCategoryName();
         log.info("检查尝试修改的数据是否存在");
         int count = productCategoryMapper.countById(productCategoryId);
         if (count == 0) {
@@ -155,6 +156,15 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
             throw new XiaoShiException(message);
         }
 
+        //检查尝试修改的产品类别名称是否被占用
+        log.info("检查尝试修改的产品类别名称是否被占用");
+        count = productCategoryMapper.countByIdAndName(productCategoryId, productCategoryName);
+        if (count > 0) {
+            String message = "修改产品类别失败,类别名称【" + productCategoryName + "】已存在,请尝试更换名称";
+            log.info("{}", message);
+            throw new XiaoShiException(message);
+        }
+
         //产品类别DTO对象赋值给实体类
         ProductCategory productCategory = new ProductCategory();
         BeanUtils.copyProperties(productCategoryUpdateDTO, productCategory);
@@ -247,11 +257,12 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
         log.info("删除产品类别完成");
 
     }
+
     //返回总的营销数据
     @Override
     public List<ProductCategoryTrendVO> showTrend(ProductCategoryDTO dto) {
         //判断架构id是否有内容,没有的话直接返回null
-        if(dto.getCategoryId() == null && dto.getCategoryId() == 0) {
+        if (dto.getCategoryId() == null && dto.getCategoryId() == 0) {
             return null;
         }
         //存储各个产品信息和营销数据
@@ -265,11 +276,11 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
         //查询架构id返回的总体营销数据
         List<ProductMarketDataTrendVO> totalSaleVOS = new ArrayList<>();
         if (dto.getTimeUnit() == 2) {//按照年份返回营销数据
-            totalSaleVOS = productCategoryMapper.categoryQueryByYear(dto.getCategoryId(),dto.getCategoryArea(),dto.getCompanyName());
+            totalSaleVOS = productCategoryMapper.categoryQueryByYear(dto.getCategoryId(), dto.getCategoryArea(), dto.getCompanyName());
         } else if (dto.getTimeUnit() == 1) {//按照季度返回营销数据
-            totalSaleVOS = productCategoryMapper.categoryQueryBySeason(dto.getCategoryId(),dto.getCategoryArea(),dto.getCompanyName());
+            totalSaleVOS = productCategoryMapper.categoryQueryBySeason(dto.getCategoryId(), dto.getCategoryArea(), dto.getCompanyName());
         } else if (dto.getTimeUnit() == null || dto.getTimeUnit() == 0) {//按照月份返回营销数据
-            totalSaleVOS = productCategoryMapper.categoryQueryByMonth(dto.getCategoryId(),dto.getCategoryArea(),dto.getCompanyName());
+            totalSaleVOS = productCategoryMapper.categoryQueryByMonth(dto.getCategoryId(), dto.getCategoryArea(), dto.getCompanyName());
         }
         totalTrendVO.setSaleVOS(totalSaleVOS);
         trendVOS.add(totalTrendVO);
@@ -277,17 +288,17 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
         List<ProductIdAndNameVO> idNameVOS = new ArrayList<>();
         idNameVOS = productCategoryMapper.queryProductIdAndNameByCategoryId(dto.getCategoryId(), dto.getCompanyName());
         //返回根据架构id查询到的每个产品id的营销数据
-        for(ProductIdAndNameVO idNameVO:idNameVOS){
+        for (ProductIdAndNameVO idNameVO : idNameVOS) {
             ProductCategoryTrendVO trendVO = new ProductCategoryTrendVO();
             trendVO.setProductId(idNameVO.getProductId());
             trendVO.setProductName(idNameVO.getProductName());
             List<ProductMarketDataTrendVO> temSaleVOS = new ArrayList<>();
             if (dto.getTimeUnit() == 2) {//按照年份返回营销数据
-                temSaleVOS = productCategoryMapper.queryByYear(idNameVO.getProductId(),dto.getCategoryArea());
+                temSaleVOS = productCategoryMapper.queryByYear(idNameVO.getProductId(), dto.getCategoryArea());
             } else if (dto.getTimeUnit() == 1) {//按照季度返回营销数据
-                temSaleVOS = productCategoryMapper.queryBySeason(idNameVO.getProductId(),dto.getCategoryArea());
+                temSaleVOS = productCategoryMapper.queryBySeason(idNameVO.getProductId(), dto.getCategoryArea());
             } else if (dto.getTimeUnit() == null || dto.getTimeUnit() == 0) {//按照月份返回营销数据
-                temSaleVOS = productCategoryMapper.queryByMonth(idNameVO.getProductId(),dto.getCategoryArea());
+                temSaleVOS = productCategoryMapper.queryByMonth(idNameVO.getProductId(), dto.getCategoryArea());
             }
             trendVO.setSaleVOS(temSaleVOS);
             trendVOS.add(trendVO);

+ 0 - 7
PAS/src/main/java/cn/cslg/pas/service/impl/ProductServiceImpl.java

@@ -238,13 +238,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
             List<ProductGroupVO> productGroupVOS;
             if (groupBy.equals("product_category_id")) {
                 productGroupVOS = productMapper.queryByGroupProductCategoryId(productQueryPageDTO);
-//                for (ProductGroupVO productGroupVO : productGroupVOS) {
-//                    ProductVO productVO = productGroupVO.getProducts().get(0);
-//                    if (productVO != null) {
-//                        String productCategoryName = productVO.getProductCategory().getProductCategoryName();
-//                        productGroupVO.setProductCategoryName(productCategoryName);
-//                    }
-//                }
             } else {
                 productGroupVOS = productMapper.queryByGroupCompanyName(productQueryPageDTO);
             }

+ 51 - 42
PAS/src/main/resources/mapper/ProductCategoryMapper.xml

@@ -43,6 +43,15 @@
         where product_category_name = #{productCategoryName}
     </select>
 
+    <!--根据id和名称统计数量-->
+    <!--int countByIdAndName(Integer id, String productCategoryName);-->
+    <select id="countByIdAndName" resultType="int">
+        select count(*)
+        from product_category
+        where product_category_name = #{productCategoryName}
+          and id != #{id}
+    </select>
+
     <!--根据id统计数量-->
     <!--int countById(Integer id);-->
     <select id="countById" resultType="int">
@@ -116,35 +125,35 @@
     <!--按照月份返回总体-->
     <select id="categoryQueryByMonth" 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,
-               CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
-        FROM  product_market_data
+        CAST(MONTH(STR_TO_DATE(sale_time,'%Y-%m')) AS CHAR)) AS market_date,
+        sum(sale_money) AS sale_total_money,
+        CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
+        FROM product_market_data
         WHERE product_id IN(SELECT id AS product_id
-                            FROM product
-                            WHERE product_category_id = #{categoryId}
-                            <if test="companyName != null and companyName != ''">
-                                AND company_name = #{companyName}
-                            </if>)
-                <if test="categoryArea != null and categoryArea != ''">
-                    AND sale_area = #{categoryArea}
-                </if>
+        FROM product
+        WHERE product_category_id = #{categoryId}
+        <if test="companyName != null and companyName != ''">
+            AND company_name = #{companyName}
+        </if>)
+        <if test="categoryArea != null and categoryArea != ''">
+            AND sale_area = #{categoryArea}
+        </if>
         GROUP BY market_date
     </select>
 
     <!--按照季度返回总体-->
     <select id="categoryQueryBySeason" 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,
-               CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
-        FROM  product_market_data
+        '第',CAST(QUARTER(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'季度') AS market_date,
+        sum(sale_money) AS sale_total_money,
+        CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
+        FROM product_market_data
         WHERE product_id IN(SELECT id AS product_id
-                            FROM product
-                            WHERE product_category_id = #{categoryId}
-                            <if test="companyName != null and companyName != ''">
-                                AND company_name = #{companyName}
-                            </if>)
+        FROM product
+        WHERE product_category_id = #{categoryId}
+        <if test="companyName != null and companyName != ''">
+            AND company_name = #{companyName}
+        </if>)
         <if test="categoryArea != null and categoryArea != ''">
             AND sale_area = #{categoryArea}
         </if>
@@ -153,15 +162,15 @@
     <!--按照年度返回总体-->
     <select id="categoryQueryByYear" 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,
-               CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
-        FROM  product_market_data
+        sum(sale_money) AS sale_total_money,
+        CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
+        FROM product_market_data
         WHERE product_id IN(SELECT id AS product_id
-                            FROM product
-                            WHERE product_category_id = #{categoryId}
-                            <if test="companyName != null and companyName != ''">
-                                AND company_name = #{companyName}
-                            </if>)
+        FROM product
+        WHERE product_category_id = #{categoryId}
+        <if test="companyName != null and companyName != ''">
+            AND company_name = #{companyName}
+        </if>)
         <if test="categoryArea != null and categoryArea != ''">
             AND sale_area = #{categoryArea}
         </if>
@@ -171,9 +180,9 @@
     <!--按照年度返回每个-->
     <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,
-               CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
-        FROM  product_market_data
+        sum(sale_money) AS sale_total_money,
+        CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
+        FROM product_market_data
         WHERE product_id = #{productId}
         <if test="categoryArea != null and categoryArea != ''">
             AND sale_Area = #{categoryArea}
@@ -184,10 +193,10 @@
     <!--按照季度返回每个-->
     <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,
-                      CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
-        FROM  product_market_data
+        '第',CAST(QUARTER(STR_TO_DATE(sale_time,'%Y-%m')) as CHAR),'季度') AS market_date,
+        sum(sale_money) AS sale_total_money,
+        CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
+        FROM product_market_data
         WHERE product_id = #{productId}
         <if test="categoryArea != null and categoryArea != ''">
             AND sale_Area = #{categoryArea}
@@ -198,10 +207,10 @@
     <!--按照月份返回每个-->
     <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,
-                      CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
-        FROM  product_market_data
+        CAST(MONTH(STR_TO_DATE(sale_time,'%Y-%m')) AS CHAR)) AS market_date,
+        sum(sale_money) AS sale_total_money,
+        CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
+        FROM product_market_data
         WHERE product_id = #{productId}
         <if test="categoryArea != null and categoryArea != ''">
             AND sale_Area = #{categoryArea}
@@ -217,10 +226,10 @@
 
     <select id="queryProductIdAndNameByCategoryId" resultMap="idNameMap">
         SELECT id AS product_id,product_name
-        FROM  product
+        FROM product
         WHERE product_category_id = #{categoryId}
         <if test="companyName != null and companyName != ''">
-          AND company_name = #{companyName}
+            AND company_name = #{companyName}
         </if>
     </select>
 

+ 83 - 24
PAS/src/main/resources/mapper/ProductMapper.xml

@@ -115,21 +115,21 @@
         from product p
         join product_category pc on p.product_category_id = pc.id
         <where>
-            <if test="productName != null">
+            <if test="productName != null and productName != ''">
                 and product_name like '%${productName}%'
             </if>
-            <if test="companyName != null">
+            <if test="companyName != null and companyName != ''">
                 and company_name like '%${companyName}%'
             </if>
-            <if test="patentNo != null">
-                and id in
+            <if test="patentNo != null and patentNo != ''">
+                and p.id in
                 (select product_id from asso_product_patent where patent_no = #{patentNo}
                 union select product_id from asso_structure_patent where patent_no = #{patentNo})
             </if>
-            <if test="productCategoryId != null">
+            <if test="productCategoryId != null and productCategoryId != ''">
                 and product_category_id = #{productCategoryId}
             </if>
-            <if test="productCategoryName != null">
+            <if test="productCategoryName != null and productCategoryName != ''">
                 and product_category_id in (select id from product_category where product_category_name like
                 '%${productCategoryName}%')
             </if>
@@ -230,26 +230,31 @@
     <select id="queryByGroupProductCategoryId" resultMap="queryByGroupProductCategoryIdMap">
         select product_category_id pci,
         product_category_name,
-        #{orderBy} orderBy,
-        #{orderType} orderType
+        ifnull(#{orderBy}, '') orderBy,
+        ifnull(#{orderType}, '') orderType,
+        ifnull(#{productName}, '') productName,
+        ifnull(#{companyName}, '') companyName,
+        ifnull(#{patentNo}, '') patentNo,
+        ifnull(#{productCategoryId}, '') productCategoryId,
+        ifnull(#{productCategoryName}, '') productCategoryName
         from product p
         join product_category pc on p.product_category_id = pc.id
         <where>
-            <if test="productName != null">
+            <if test="productName != null and productName != ''">
                 and product_name like '%${productName}%'
             </if>
-            <if test="companyName != null">
+            <if test="companyName != null and companyName != ''">
                 and company_name like '%${companyName}%'
             </if>
-            <if test="patentNo != null">
-                and id in
+            <if test="patentNo != null and patentNo != ''">
+                and p.id in
                 (select product_id from asso_product_patent where patent_no = #{patentNo}
                 union select product_id from asso_structure_patent where patent_no = #{patentNo})
             </if>
-            <if test="productCategoryId != null">
+            <if test="productCategoryId != null and productCategoryId != ''">
                 and product_category_id = #{productCategoryId}
             </if>
-            <if test="productCategoryName != null">
+            <if test="productCategoryName != null and productCategoryName != ''">
                 and product_category_id in (select id from product_category where product_category_name like
                 '%${productCategoryName}%')
             </if>
@@ -262,7 +267,9 @@
         <result column="product_category_id" property="productCategoryId"/>
         <result column="product_category_name" property="productCategoryName"/>
         <collection property="products" ofType="cn.cslg.pas.common.model.vo.ProductVO"
-                    select="queryByGroupProductCategoryId2" column="{pci=pci, orderBy=orderBy, orderType=orderType}">
+                    select="queryByGroupProductCategoryId2"
+                    column="{pci=pci, orderBy=orderBy, orderType=orderType, productName=productName, companyName=companyName,
+                             patentNo=patentNo, productCategoryId=productCategoryId, productCategoryName=productCategoryName}">
         </collection>
     </resultMap>
 
@@ -279,7 +286,29 @@
         product_category_name
         from product p
         join product_category pc on p.product_category_id = pc.id
-        where product_category_id = #{pci}
+        <where>
+            <if test="productName != null and productName != ''">
+                and product_name like '%${productName}%'
+            </if>
+            <if test="companyName != null and companyName != ''">
+                and company_name like '%${companyName}%'
+            </if>
+            <if test="patentNo != null and patentNo != ''">
+                and p.id in
+                (select product_id from asso_product_patent where patent_no = #{patentNo}
+                union select product_id from asso_structure_patent where patent_no = #{patentNo})
+            </if>
+            <if test="productCategoryId != null and productCategoryId != ''">
+                and product_category_id = #{productCategoryId}
+            </if>
+            <if test="productCategoryName != null and productCategoryName != ''">
+                and product_category_id in (select id from product_category where product_category_name like
+                '%${productCategoryName}%')
+            </if>
+            <if test="true">
+                and product_category_id = #{pci}
+            </if>
+        </where>
         order by
         <choose>
             <when test="orderBy != null and orderBy != ''">
@@ -295,24 +324,30 @@
     <!--List<ProductGroupVO> queryByGroupCompanyName(ProductQueryPageDTO productQueryPageDTO);-->
     <select id="queryByGroupCompanyName" resultMap="queryByGroupCompanyNameMap">
         select company_name cn,
-        #{orderBy} orderBy, #{orderType} orderType
+        ifnull(#{orderBy}, '') orderBy,
+        ifnull(#{orderType}, '') orderType,
+        ifnull(#{productName}, '') productName,
+        ifnull(#{companyName}, '') companyName,
+        ifnull(#{patentNo}, '') patentNo,
+        ifnull(#{productCategoryId}, '') productCategoryId,
+        ifnull(#{productCategoryName}, '') productCategoryName
         from product
         <where>
-            <if test="productName != null">
+            <if test="productName != null and productName != ''">
                 and product_name like '%${productName}%'
             </if>
-            <if test="companyName != null">
+            <if test="companyName != null and companyName != ''">
                 and company_name like '%${companyName}%'
             </if>
-            <if test="patentNo != null">
+            <if test="patentNo != null and patentNo != ''">
                 and id in
                 (select product_id from asso_product_patent where patent_no = #{patentNo}
                 union select product_id from asso_structure_patent where patent_no = #{patentNo})
             </if>
-            <if test="productCategoryId != null">
+            <if test="productCategoryId != null and productCategoryId != ''">
                 and product_category_id = #{productCategoryId}
             </if>
-            <if test="productCategoryName != null">
+            <if test="productCategoryName != null and productCategoryName != ''">
                 and product_category_id in (select id from product_category where product_category_name like
                 '%${productCategoryName}%')
             </if>
@@ -327,7 +362,9 @@
     <resultMap id="queryByGroupCompanyNameMap" type="cn.cslg.pas.common.model.vo.ProductGroupVO">
         <result column="cn" property="companyName"/>
         <collection property="products" ofType="cn.cslg.pas.common.model.vo.ProductVO"
-                    select="queryByGroupCompanyNameMap2" column="{cn=cn, orderBy=orderBy, orderType=orderType}">
+                    select="queryByGroupCompanyNameMap2"
+                    column="{cn=cn, orderBy=orderBy, orderType=orderType, productName=productName, companyName=companyName,
+                             patentNo=patentNo, productCategoryId=productCategoryId, productCategoryName=productCategoryName}">
         </collection>
     </resultMap>
 
@@ -344,7 +381,29 @@
         product_category_name
         from product p
         join product_category pc on p.product_category_id = pc.id
-        where company_name = #{cn}
+        <where>
+            <if test="productName != null and productName != ''">
+                and product_name like '%${productName}%'
+            </if>
+            <if test="companyName != null and companyName != ''">
+                and company_name like '%${companyName}%'
+            </if>
+            <if test="patentNo != null and patentNo != ''">
+                and p.id in
+                (select product_id from asso_product_patent where patent_no = #{patentNo}
+                union select product_id from asso_structure_patent where patent_no = #{patentNo})
+            </if>
+            <if test="productCategoryId != null and productCategoryId != ''">
+                and product_category_id = #{productCategoryId}
+            </if>
+            <if test="productCategoryName != null and productCategoryName != ''">
+                and product_category_id in (select id from product_category where product_category_name like
+                '%${productCategoryName}%')
+            </if>
+            <if test="true">
+                and company_name = #{cn}
+            </if>
+        </where>
         order by
         <choose>
             <when test="orderBy != null and orderBy != ''">