Quellcode durchsuchen

Merge remote-tracking branch 'remotes/origin/developer' into developerB

plf vor 4 Jahren
Ursprung
Commit
baf258573f

+ 6 - 0
pom.xml

@@ -133,6 +133,12 @@
             <version>2.8.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.jsoup</groupId>
+            <artifactId>jsoup</artifactId>
+            <version>1.11.2</version>
+        </dependency>
+
     </dependencies>
 
 

+ 15 - 1
src/main/java/com/caimei/www/controller/GenerateApi.java

@@ -1,11 +1,16 @@
 package com.caimei.www.controller;
 
+import com.caimei.www.mapper.ProductDao;
+import com.caimei.www.pojo.JsonModel;
 import com.caimei.www.service.generate.GenerateHtml;
+import com.caimei.www.utils.GetProductImgUtil;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.server.ServerWebExchange;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * Description
@@ -17,7 +22,8 @@ import javax.annotation.Resource;
 public class GenerateApi {
     @Resource
     private GenerateHtml generateHtml;
-
+    @Resource
+    private ProductDao productDao;
     /**
      * 生成静态首页
      */
@@ -34,4 +40,12 @@ public class GenerateApi {
         return generateHtml.generateStaticFiles();
     }
 
+
+//    @PostMapping("/product/img/repair")
+//    public String repairProductImg() {
+//        List<String> infoList = productDao.getProductInfo();
+//        infoList.forEach(GetProductImgUtil::saveProductImg);
+//        return "商品数量:" + infoList.size() + ", " + infoList.toString();
+//    }
+
 }

+ 4 - 0
src/main/java/com/caimei/www/mapper/ProductDao.java

@@ -67,4 +67,8 @@ public interface ProductDao {
     List<Bigtype> findBigtype();
 
     List<SmallType> findSmalltype();
+    /**
+     * 修复商品图片(临时)
+     */
+    List<String> getProductInfo();
 }

+ 43 - 4
src/main/java/com/caimei/www/service/generate/impl/GenerateHtmlImpl.java

@@ -19,10 +19,9 @@ import org.thymeleaf.spring5.context.webflux.SpringWebFluxContext;
 import org.thymeleaf.util.StringUtils;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -224,4 +223,44 @@ public class GenerateHtmlImpl implements GenerateHtml {
         }
     }
 
+
+
+    public static void download(String urlString, String filename,String savePath) throws Exception {
+        // 构造URL
+        URL url = new URL(urlString);
+        // 打开连接
+        URLConnection con = url.openConnection();
+        //设置请求超时为5s
+        con.setConnectTimeout(5*1000);
+        // 输入流
+        InputStream is = con.getInputStream();
+        // 1K的数据缓冲
+        byte[] bs = new byte[1024];
+        // 读取到的数据长度
+        int len;
+        // 输出的文件流
+       File sf=new File(savePath);
+       if(!sf.exists()){
+           sf.mkdirs();
+       }
+       OutputStream os = new FileOutputStream(sf.getPath()+"\\"+filename);
+        // 开始读取
+        while ((len = is.read(bs)) != -1) {
+          os.write(bs, 0, len);
+        }
+        // 完毕,关闭所有链接
+        os.close();
+        is.close();
+    }
+
+
+
+
+
+
+
+
+
+
+
 }

+ 86 - 0
src/main/java/com/caimei/www/utils/GetProductImgUtil.java

@@ -0,0 +1,86 @@
+package com.caimei.www.utils;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/5/28
+ */
+@Slf4j
+public class GetProductImgUtil {
+
+    /**
+     * 保存图片到本地服务器
+     * @param textBody 富文本
+     */
+    public static void saveProductImg(String textBody) {
+        // 解析富文本
+        Element doc = Jsoup.parseBodyFragment(textBody).body();
+        Elements images = doc.select("img[src]");
+        List<String> srcList = new ArrayList<>();
+        for (Element element : images) {
+            String imgUrl = element.attr("src");
+            // 筛选测试服务器的图片路径
+            if (imgUrl.indexOf("img-b.caimei365.com") > 0) {
+                srcList.add(imgUrl);
+            }
+        }
+        // 本地存放路径
+        String basePath = "D:/mnt/newdatadrive/fdfs/storage/data/";
+        srcList.forEach(img -> {
+            try {
+                // 下载图片,并根据路径规律保持原有路径
+                GetProductImgUtil.downloadImage(img, img.substring(45), basePath+img.substring(39, 45));
+            } catch (Exception e) {
+                log.error("try-catch:",e);
+            }
+        });
+    }
+
+    /**
+     * 下载图片
+     *
+     * @param urlString 图片链接
+     * @param filename  图片名称
+     * @param savePath  保存路径
+     */
+    private static void downloadImage(String urlString, String filename, String savePath) throws Exception {
+        // 构造URL打开连接,并设置输入流与缓冲
+        URL url = new URL(urlString);
+        URLConnection con = url.openConnection();
+        con.setConnectTimeout(5*1000);
+        InputStream is = con.getInputStream();
+        byte[] bs = new byte[1024];
+        // 读取到的数据长度
+        int len;
+        // 输出的文件流
+        File sf=new File(savePath);
+        if(!sf.exists()){
+           sf.mkdirs();
+        }
+        OutputStream os = new FileOutputStream(sf.getPath()+"/"+filename);
+        // 开始读取
+        while ((len = is.read(bs)) != -1) {
+            os.write(bs, 0, len);
+        }
+        os.close();
+        is.close();
+        // 打印图片链接
+        log.info(urlString);
+    }
+
+}

+ 3 - 0
src/main/resources/mapper/ProductMapper.xml

@@ -117,6 +117,9 @@
 	<select id="findSmalltype" resultType="com.caimei.www.pojo.classify.SmallType">
 		SELECT smallTypeID,name FROM smalltype ORDER BY sortIndex
 	</select>
+    <select id="getProductInfo" resultType="java.lang.String">
+        select detailinfo from productdetailinfo where detailinfo like '%img-b.caimei365.com%'
+	</select>
 
 
 </mapper>

+ 15 - 15
src/main/resources/static/js/index.js

@@ -1,5 +1,5 @@
-var isFormal = window.location.href.indexOf('www.caimei365.com') !== -1;
-if(isFormal){var _czc = _czc || [];_czc.push(["_setAccount", "1279558759"]);}
+// var isFormal = window.location.href.indexOf('www.caimei365.com') !== -1;
+// if(isFormal){var _czc = _czc || [];_czc.push(["_setAccount", "1279558759"]);}
 var homeData = new Vue({
     el: '#container',
     data: {
@@ -317,18 +317,18 @@ var homeData = new Vue({
             });
         },2000);
         //关闭广告图
-        $('#advertising').on('click','.close',function () {
-            $(this).parents('.item').hide();
-        });
-        var isActivityStatus =  localStorage.getItem('isActivityStatus');
-        //新加优惠券弹窗
-        if(isActivityStatus){
-            var  lockTime = localStorage.getItem('lockTime');
-            _this.popupFlag = this.diffTime(lockTime);
-        }else{
-            setTimeout(function () {
-                 _this.popupFlag = true;
-            },1000);
-        }
+        // $('#advertising').on('click','.close',function () {
+        //     $(this).parents('.item').hide();
+        // });
+        // var isActivityStatus =  localStorage.getItem('isActivityStatus');
+        // //新加优惠券弹窗
+        // if(isActivityStatus){
+        //     var  lockTime = localStorage.getItem('lockTime');
+        //     _this.popupFlag = this.diffTime(lockTime);
+        // }else{
+        //     setTimeout(function () {
+        //          _this.popupFlag = true;
+        //     },1000);
+        // }
     }
 });

+ 1 - 2
src/main/resources/static/js/supplier-center/shop/release.js

@@ -1124,8 +1124,7 @@ var releaseContainer = new Vue({
     },
     mounted: function () {
         var _this = this;
-        // var NODE_ENV_BASE_URL = $('#spiServer').val();
-        var NODE_ENV_BASE_URL = 'https://spi-b.caimei365.com';
+        var NODE_ENV_BASE_URL = $('#spiServer').val();
         _this.NODE_ENV_BASE_URL = NODE_ENV_BASE_URL;
         if(globalUserData){
             _this.releaseParams.shopId = globalUserData.shopId;

+ 10 - 10
src/main/resources/templates/index.html

@@ -230,16 +230,16 @@
         </div>
     </div>
     <!--美博会弹窗-->
-    <div id="meibohui" class="Popup" v-if="popupFlag" :class="popupFlag ? 'show' :'' "
-         onclick="_czc.push(['_trackEvent','美博会','点击','用户访问','','meibohui'])">
-        <div class="show_popup">
-            <div class="bg_icon" @click="closePopup"><i class="icon mIcon"></i></div>
-            <div class="bg_img" @click="popupPage">
-                <img src="https://static.caimei365.com/app/meibohui/www/activity-pop-pc.png" v-if="isPC">
-                <img src="https://static.caimei365.com/app/meibohui/www/activity-pop-h5.png" v-else>
-            </div>
-        </div>
-    </div>
+<!--    <div id="meibohui" class="Popup" v-if="popupFlag" :class="popupFlag ? 'show' :'' "-->
+<!--         onclick="_czc.push(['_trackEvent','美博会','点击','用户访问','','meibohui'])">-->
+<!--        <div class="show_popup">-->
+<!--            <div class="bg_icon" @click="closePopup"><i class="icon mIcon"></i></div>-->
+<!--            <div class="bg_img" @click="popupPage">-->
+<!--                <img src="https://static.caimei365.com/app/meibohui/www/activity-pop-pc.png" v-if="isPC">-->
+<!--                <img src="https://static.caimei365.com/app/meibohui/www/activity-pop-h5.png" v-else>-->
+<!--            </div>-->
+<!--        </div>-->
+<!--    </div>-->
 </div>
 <!-- 引入底部 -->
 <template th:replace="components/footer"></template>

+ 6 - 6
src/main/resources/templates/user-center/dashboard.html

@@ -102,12 +102,12 @@
                         </div>
                     </div>
                     <!--美博会活动标题-->
-                    <div class=" user-content coupon">
-                        <a href="/user/beautyfair.html" id="meibohui" onclick="_czc.push(['_trackEvent','美博会','点击','用户访问','','meibohui'])">
-                            <img src="https://static.caimei365.com/app/meibohui/www/activity-in-pc.jpg" class="coupon_img" v-if="isPC"/>
-                            <img src="https://static.caimei365.com/app/meibohui/www/activity-in-h5.jpg" class="coupon_img" v-else>
-                        </a>
-		            </div>
+<!--                    <div class=" user-content coupon">-->
+<!--                        <a href="/user/beautyfair.html" id="meibohui" onclick="_czc.push(['_trackEvent','美博会','点击','用户访问','','meibohui'])">-->
+<!--                            <img src="https://static.caimei365.com/app/meibohui/www/activity-in-pc.jpg" class="coupon_img" v-if="isPC"/>-->
+<!--                            <img src="https://static.caimei365.com/app/meibohui/www/activity-in-h5.jpg" class="coupon_img" v-else>-->
+<!--                        </a>-->
+<!--		            </div>-->
                     <div class="user-content">
                         <div class="title">今日推荐</div>
                         <div class="section">