wucl преди 2 месеца
родител
ревизия
35c1742eb5

+ 19 - 18
src/main/java/com/leeroa/dydb/datasource/loanorder/schedule/LoanOrderSchedule.java

@@ -20,24 +20,25 @@ public class LoanOrderSchedule {
     private DataLoanOrderService dataLoanOrderService;
 
     // 每10分钟执行一次
-    //@Scheduled(fixedDelay = 1000 * 60 * 10)
+    @Scheduled(fixedDelay = 1000 * 60 * 10)
     public void dailyFetch() {
-        int errorTimes = 0;
-        while (errorTimes < 5) {
-            long total = dataLoanOrderService.dailyFetch();
-            // 如果-1,表示本次抓取失败,再尝试一次
-            if (total == -1) {
-                errorTimes++;
-                continue;
-            }
-            // 表示已经没有数据抓取
-            if (total == 0) {
-                break;
-            }
-            // 表示本次抓取有效数据,继续抓取
-            if (total > 0) {
-                errorTimes = 0;
-            }
-        }
+        dataLoanOrderService.dailyFetch();
+//        int errorTimes = 0;
+//        while (errorTimes < 5) {
+//            long total = dataLoanOrderService.dailyFetch();
+//            // 如果-1,表示本次抓取失败,再尝试一次
+//            if (total == -1) {
+//                errorTimes++;
+//                continue;
+//            }
+//            // 表示已经没有数据抓取
+//            if (total == 0) {
+//                break;
+//            }
+//            // 表示本次抓取有效数据,继续抓取
+//            if (total > 0) {
+//                errorTimes = 0;
+//            }
+//        }
     }
 }

+ 20 - 11
src/main/java/com/leeroa/dydb/datasource/loanorder/service/impl/DataLoanOrderServiceImpl.java

@@ -32,6 +32,7 @@ import com.michael.utils.gson.FloatConverter;
 import com.michael.utils.gson.GsonUtils;
 import com.michael.utils.gson.IntegerConverter;
 import com.michael.utils.string.StringUtils;
+import com.sun.org.apache.bcel.internal.generic.NEW;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.client.fluent.Request;
@@ -46,6 +47,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
 import javax.annotation.Resource;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
@@ -144,8 +147,9 @@ public class DataLoanOrderServiceImpl implements DataLoanOrderService, BeanWrapC
         }
         Map<String, Object> params = SignUtils.sign();
 
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         // 设置开始和截至时间
-        params.put("startTime", lastTime.getTime());
+        params.put("startTime", dateFormat.format(lastTime));
 
         long total = 0;
         // 发起请求
@@ -153,18 +157,20 @@ public class DataLoanOrderServiceImpl implements DataLoanOrderService, BeanWrapC
         AtomicInteger update = new AtomicInteger();
         try {
             String json = GsonUtils.toJson(params);
-            String jsonData = Request.Post("http://noa.scdayou.com/wx/history/loanOrders-kbsl")
-                    .body(new StringEntity(json, "utf-8"))
+            String jsonData = Request.Post("http://mbs.scdayou.com/api/personalTarget/evaData")
+                    .body(new StringEntity(json, "utf-8")).addHeader("Content-Type","application/json;charset=UTF-8")
                     .execute()
                     .returnContent().toString();
+            byte[] bytes = jsonData.getBytes("ISO8859-1");
+            String result = new String(bytes, "UTF-8");
             Gson gson = new GsonBuilder()
                     .registerTypeAdapter(Date.class, new DateConverter())
                     .registerTypeAdapter(Integer.class, new IntegerConverter())
                     .registerTypeAdapter(Float.class, new FloatConverter())
                     .registerTypeAdapter(Double.class, new DoubleConverter())
                     .create();
-            DataLoanOrderWrapper dto = gson.fromJson(jsonData, DataLoanOrderWrapper.class);
-            Assert.isTrue(dto.isSuccess(), dto.getMessage());
+            DataLoanOrderWrapper dto = gson.fromJson(result, DataLoanOrderWrapper.class);
+//            Assert.isTrue(dto.isSuccess(), dto.getMessage());
             List<DataLoanOrderDTO> data = dto.getData();
             Pattern pattern = Pattern.compile("房屋建筑面积(\\d+(\\.\\d+)?)平方米");
             Pattern floorPattern = Pattern.compile("(\\d+)(含地下)?");
@@ -221,16 +227,19 @@ public class DataLoanOrderServiceImpl implements DataLoanOrderService, BeanWrapC
                     if (RegUtils.isDouble(foo.getArea())) {
                         order.setBuildArea(Double.parseDouble(foo.getArea()));
                     } else {
-                        Matcher matcher = pattern.matcher(foo.getArea());
-                        if (matcher.find()) {
-                            order.setBuildArea(Double.parseDouble(matcher.group(1)));
+                        if (StringUtils.isNotEmpty(foo.getArea())){
+                            Matcher matcher = pattern.matcher(foo.getArea());
+                            if (matcher.find()) {
+                                order.setBuildArea(Double.parseDouble(matcher.group(1)));
+                            }
                         }
+
                     }
 
                     // 对于单价,面积都低于指定指标的,都跳过
-                    if (!HouseUtils.check(order.getPrice(), order.getBuildArea())) {
-                        continue;
-                    }
+//                    if (!HouseUtils.check(order.getPrice(), order.getBuildArea())) {
+//                        continue;
+//                    }
 
                     // 套内面积
                     if (RegUtils.isDouble(foo.getInnerArea())) {

+ 1 - 0
src/main/java/com/leeroa/dydb/datasource/utils/HouseUtils.java

@@ -146,6 +146,7 @@ public class HouseUtils {
     }
 
 
+
     public static String getArea(String address) {
         if (address == null) {
             return null;

Файловите разлики са ограничени, защото са твърде много
+ 9 - 1
src/main/java/com/leeroa/dydb/datasource/utils/SpiderUtils.java