zxa 3 лет назад
Родитель
Сommit
b6c2aa047a

+ 39 - 37
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/mapper/xml/ProductMaterialMapper.xml

@@ -39,23 +39,22 @@
         select
         trade_name
         FROM ctop_product_material
-        <where>
-            <if test="productId!=null">
-                and product_id = #{productId}
-            </if>
-            <if test="tradeName!=null">
-                and trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
-            </if>
-            <if test="startMonth!=null">
-                and start_month >= #{startMonth}
-            </if>
-            <if test="endMonth!=null">
-                and end_month &lt;= #{endMonth}
-            </if>
-            <if test="itemRun!=null">
-                and item_run = #{itemRun}
-            </if>
-        </where>
+        where video_url!=''
+        <if test="productId!=null">
+            and product_id = #{productId}
+        </if>
+        <if test="tradeName!=null">
+            and trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
+        </if>
+        <if test="startMonth!=null">
+            and start_month >= #{startMonth}
+        </if>
+        <if test="endMonth!=null">
+            and end_month &lt;= #{endMonth}
+        </if>
+        <if test="itemRun!=null">
+            and item_run = #{itemRun}
+        </if>
         group by product_id,trade_name
         ) t
     </select>
@@ -71,8 +70,7 @@
         IFNULL(sum(t2.charge),0.00) as 'charge',
         CONCAT(t1.start_month,' ~ ',t1.end_month) as 'time',
         IFNULL(t3.realname,'-') as 'user',
-        (SELECT COUNT(1) FROM ctop_product_material tt WHERE tt.product_id = t1.product_id AND tt.trade_name =
-        t1.trade_name) as 'videoCount'
+        t4.videoCount
         FROM ctop_product_material t1
         LEFT JOIN
         (
@@ -90,24 +88,28 @@
         </where>
         GROUP BY signature
         ) t2 ON t1.signature = t2.signature
-            left join (select id, realname from sys_user)t3 on t1.user_id =t3.id
-        <where>
-            <if test="productId!=null">
-                and t1.product_id = #{productId}
-            </if>
-            <if test="tradeName!=null">
-                and t1.trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
-            </if>
-            <if test="startMonth!=null">
-                and t1.start_month >= #{startMonth}
-            </if>
-            <if test="endMonth!=null">
-                and t1.end_month &lt;= #{endMonth}
-            </if>
-            <if test="itemRun!=null">
-                and t1.item_run = #{itemRun}
-            </if>
-        </where>
+        LEFT JOIN (select id, realname from sys_user) t3 on t1.user_id =t3.id
+        LEFT JOIN (
+        SELECT product_id,trade_name,COUNT(signature) as 'videoCount' FROM ctop_product_material
+        WHERE video_url!=''
+        GROUP BY product_id,trade_name
+        ) t4 ON t1.product_id = t4.product_id AND t1.trade_name= t4.trade_name
+        where video_url!=''
+        <if test="productId!=null">
+            and t1.product_id = #{productId}
+        </if>
+        <if test="tradeName!=null">
+            and t1.trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
+        </if>
+        <if test="startMonth!=null">
+            and t1.start_month >= #{startMonth}
+        </if>
+        <if test="endMonth!=null">
+            and t1.end_month &lt;= #{endMonth}
+        </if>
+        <if test="itemRun!=null">
+            and t1.item_run = #{itemRun}
+        </if>
         group by t1.product_id,t1.trade_name
     </select>
 

+ 42 - 36
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/service/impl/ProductMaterialServiceImpl.java

@@ -108,46 +108,52 @@ public class ProductMaterialServiceImpl extends ServiceImpl<ProductMaterialMappe
             String signature = trade.getString("signature");
             String uploaderId = trade.getString("uploaderId");
             int count = 0;
-            if (Check.isNull(signature) && Check.isNull(uploaderId)) {
-                List<String> urls = Arrays.asList(videoUrl.split(","));
-                for (String url : urls) {
-                    ProductMaterial material = new ProductMaterial();
-                    count++;
-                    //获取MD5
-                    String localPath = LoadFileUtil.downLoadFromUrl(url, downloadPath);
-                    String md5 = MD5Util.getMd5(localPath);
-                    if (checkVideo(entity.getProductId(), tradeName, md5)) {
-                        BeanUtils.copyProperties(entity, material);
-                        material.setTradeName(tradeName);
-                        MaterialInfo info = materialInfoService.getMaterialInfoByCode(md5);
-                        if (!Check.isNull(info)) {
-                            material.setUploaderId(uploaderId);
+            if (Check.isNull(videoUrl)) {
+                ProductMaterial material = new ProductMaterial();
+                material.setTradeName(tradeName);
+                lists.add(material);
+            } else {
+                if (Check.isNull(signature) && Check.isNull(uploaderId)) {
+                    List<String> urls = Arrays.asList(videoUrl.split(","));
+                    for (String url : urls) {
+                        ProductMaterial material = new ProductMaterial();
+                        count++;
+                        //获取MD5
+                        String localPath = LoadFileUtil.downLoadFromUrl(url, downloadPath);
+                        String md5 = MD5Util.getMd5(localPath);
+                        if (checkVideo(entity.getProductId(), tradeName, md5)) {
+                            BeanUtils.copyProperties(entity, material);
+                            material.setTradeName(tradeName);
+                            MaterialInfo info = materialInfoService.getMaterialInfoByCode(md5);
+                            if (!Check.isNull(info)) {
+                                material.setUploaderId(uploaderId);
+                            } else {
+                                material.setUploaderId(material.getUserId());
+                            }
+                            material.setSignature(md5);
+                            String cosUrl = getCosUrl(url);
+                            material.setVideoUrl(cosUrl);
+                            lists.add(material);
                         } else {
-                            material.setUploaderId(material.getUserId());
+                            flag = true;
+                            if (msg.contains(tradeName)) {
+                                msg += "第" + count + "条视频已存在,";
+                            } else {
+                                msg += "商品(" + tradeName + ")下的第" + count + "条视频已存在,";
+                            }
                         }
-                        material.setSignature(md5);
-                        String cosUrl = getCosUrl(url);
-                        material.setVideoUrl(cosUrl);
+                        LoadFileUtil.delFile(localPath);
+                    }
+                } else {
+                    ProductMaterial material = new ProductMaterial();
+                    BeanUtils.copyProperties(entity, material);
+                    material.setTradeName(tradeName);
+                    material.setVideoUrl(videoUrl);
+                    material.setSignature(signature);
+                    material.setUploaderId(uploaderId);
+                    if (checkVideo(entity.getProductId(), tradeName, signature)) {
                         lists.add(material);
-                    } else {
-                        flag = true;
-                        if (msg.contains(tradeName)) {
-                            msg += "第" + count + "条视频已存在,";
-                        } else {
-                            msg += "商品(" + tradeName + ")下的第" + count + "条视频已存在,";
-                        }
                     }
-                    LoadFileUtil.delFile(localPath);
-                }
-            } else {
-                ProductMaterial material = new ProductMaterial();
-                BeanUtils.copyProperties(entity, material);
-                material.setTradeName(tradeName);
-                material.setVideoUrl(videoUrl);
-                material.setSignature(signature);
-                material.setUploaderId(uploaderId);
-                if (checkVideo(entity.getProductId(), tradeName, signature)) {
-                    lists.add(material);
                 }
             }
         }