Pārlūkot izejas kodu

代码格式化

15810770710@163.com 3 gadi atpakaļ
vecāks
revīzija
5cf42fcbfc

+ 0 - 6
src/main/java/com/jkcredit/traffic/record/action/TrafficRecordsAction.java

@@ -1,8 +1,5 @@
 package com.jkcredit.traffic.record.action;
 
-import com.ciphergateway.ciphersuite.CipherSuiteException;
-import com.ciphergateway.ciphersuite.CipherSuiteMacException;
-import com.ciphergateway.ciphersuite.CipherSuiteUtils;
 import com.jkcredit.traffic.record.model.CommonResponseObject;
 import com.jkcredit.traffic.record.service.TrafficRecordsAnalyseService;
 import lombok.extern.slf4j.Slf4j;
@@ -12,9 +9,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.xml.bind.DatatypeConverter;
-import java.io.UnsupportedEncodingException;
-
 /**
  * @author xusonglin
  * @version V1.0

+ 1 - 2
src/main/java/com/jkcredit/traffic/record/config/SparkSessionConfig.java

@@ -4,7 +4,6 @@ import org.apache.spark.SparkConf;
 import org.apache.spark.sql.SparkSession;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.stereotype.Component;
 
 /**
  * @author xusonglin
@@ -12,7 +11,7 @@ import org.springframework.stereotype.Component;
  **/
 @Configuration
 public class SparkSessionConfig {
-    private static String APP_NAME ="DataExtract";
+    private static String APP_NAME = "DataExtract";
 
     @Bean
     public SparkSession getSparkSession() {

+ 0 - 2
src/main/java/com/jkcredit/traffic/record/config/ThreadPoolConfig.java

@@ -3,8 +3,6 @@ package com.jkcredit.traffic.record.config;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableAsync;
 
 import java.util.concurrent.*;
 

+ 0 - 3
src/main/java/com/jkcredit/traffic/record/service/TrafficRecordsAnalyseService.java

@@ -1,9 +1,6 @@
 package com.jkcredit.traffic.record.service;
 
 import com.jkcredit.traffic.record.model.CommonResponseObject;
-import com.jkcredit.traffic.record.model.MonthResult;
-
-import java.util.List;
 
 /**
  * @author xusonglin

+ 9 - 9
src/main/java/com/jkcredit/traffic/record/util/CsvUtil.java

@@ -14,23 +14,23 @@ import java.util.List;
  **/
 @Slf4j
 public class CsvUtil {
-    public static void writeCsv(List<String> list, String filePath){
+    public static void writeCsv(List<String> list, String filePath) {
         try {
             Long start = System.currentTimeMillis();
-            File file=new File(filePath);
-            FileOutputStream fos=new FileOutputStream(file,true);
-            OutputStreamWriter osw=new OutputStreamWriter(fos, "UTF-8");
-            BufferedWriter bw=new BufferedWriter(osw);
+            File file = new File(filePath);
+            FileOutputStream fos = new FileOutputStream(file, true);
+            OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
+            BufferedWriter bw = new BufferedWriter(osw);
             for (String line : list) {
-                bw.write(line+"\n");
+                bw.write(line + "\n");
             }
             //注意关闭的先后顺序,先打开的后关闭,后打开的先关闭
             bw.close();
             osw.close();
             fos.close();
             long end = System.currentTimeMillis();
-            System.out.println("完成"+filePath+"入库,耗时:" + (end - start) +" ms");
-        } catch (Exception e){
+            System.out.println("完成" + filePath + "入库,耗时:" + (end - start) + " ms");
+        } catch (Exception e) {
             e.printStackTrace();
             log.error("writeCsv:", e);
         }
@@ -129,7 +129,7 @@ public class CsvUtil {
                     byteBuffer.clear(); //重置缓存块指针
                     read = inputChannel.read(byteBuffer, endPosition);
                 }
-            }else{
+            } else {
                 endPosition = fileSize; //最后一个文件直接指向文件末尾
             }
 

+ 34 - 28
src/main/java/com/jkcredit/traffic/record/util/DivideDataUtil.java

@@ -8,6 +8,7 @@ public class DivideDataUtil {
     /**
      * 出行次数
      * 0-100/5/20;100-300/10/20;300-600/20/15;600-1000/50/8;1000以上/1
+     *
      * @param exTimesCount 出行次数
      * @return 脱敏后出行次数区间
      */
@@ -16,13 +17,13 @@ public class DivideDataUtil {
         int times = Integer.parseInt(exTimesCount.split("\\.")[0]);
 
         if (times < 100) {
-            result = result + (times/5 +1);
+            result = result + (times / 5 + 1);
         } else if (times < 300) {
-            result = result + ((times-100)/10 + 1 + 20);
+            result = result + ((times - 100) / 10 + 1 + 20);
         } else if (times < 600) {
-            result = result + ((times-300)/20 + 1 + 20 + 20);
+            result = result + ((times - 300) / 20 + 1 + 20 + 20);
         } else if (times < 1000) {
-            result = result + ((times-600)/50 + 1 + 20 + 20 + 15);
+            result = result + ((times - 600) / 50 + 1 + 20 + 20 + 15);
         } else {
             result = result + (1 + 20 + 20 + 15 + 8);
         }
@@ -31,6 +32,7 @@ public class DivideDataUtil {
 
     /**
      * 出行消费总金额,第一个区间是0;第二个区间:(0,2000],第三个区间:(2000,4000]
+     *
      * @param sumFee 0/1; 0-10000/2000/5; 10000-100000/3000/30; 100000-500000/16000/25; 500000-1000000/25000/20; 1000000-8000000/500000/14; 8000000以上/1
      * @return 脱敏后出行消费总金额区间
      */
@@ -43,15 +45,15 @@ public class DivideDataUtil {
         }
         fee = fee - 1;
         if (fee < 10000) {
-            result = result + (fee/2000 + 1);
+            result = result + (fee / 2000 + 1);
         } else if (fee < 100000) {
-            result = result + ((fee-10000)/3000 + 1 + 5);
+            result = result + ((fee - 10000) / 3000 + 1 + 5);
         } else if (fee <= 500000) {
-            result = result + ((fee-100000)/16000 + 1 + 5 + 30);
+            result = result + ((fee - 100000) / 16000 + 1 + 5 + 30);
         } else if (fee <= 1000000) {
-            result = result + ((fee-500000)/25000 + 1 + 5 + 30 + 25);
+            result = result + ((fee - 500000) / 25000 + 1 + 5 + 30 + 25);
         } else if (fee <= 8000000) {
-            result = result + ((fee-1000000)/500000 + 1 + 5 + 30 + 25 + 20);
+            result = result + ((fee - 1000000) / 500000 + 1 + 5 + 30 + 25 + 20);
         } else {
             result = result + (1 + 1 + 5 + 30 + 25 + 20 + 14);
         }
@@ -60,6 +62,7 @@ public class DivideDataUtil {
 
     /**
      * 出行总时长
+     *
      * @param sumTravelTime 0-3600/1800/2; 3600-68400/3600/18; 68400-608400/36000/15; 608400-2595600/86400/23; 2595600以上/1
      * @return 脱敏后出行总时长区间
      */
@@ -67,13 +70,13 @@ public class DivideDataUtil {
         String result = "C";
         long travelTime = Long.parseLong(sumTravelTime.split("\\.")[0]);
         if (travelTime < 3600) {
-            result = result + (travelTime/1800 + 1);
+            result = result + (travelTime / 1800 + 1);
         } else if (travelTime < 68400) {
-            result = result + ((travelTime-3600)/3600 + 1 + 2);
+            result = result + ((travelTime - 3600) / 3600 + 1 + 2);
         } else if (travelTime < 608400) {
-            result = result + ((travelTime-68400)/36000 + 1 + 2 + 18);
+            result = result + ((travelTime - 68400) / 36000 + 1 + 2 + 18);
         } else if (travelTime < 2595600) {
-            result = result + ((travelTime-608400)/86400 + 1 + 2 + 18 + 15);
+            result = result + ((travelTime - 608400) / 86400 + 1 + 2 + 18 + 15);
         } else {
             result = result + (1 + 2 + 18 + 15 + 23);
         }
@@ -82,6 +85,7 @@ public class DivideDataUtil {
 
     /**
      * 最长出行时长
+     *
      * @param maxTravelTime 0-12000/1000/12; 12000-612000/20000/30; 612000以上/1个
      * @return 脱敏后最长出行时长区间
      */
@@ -89,9 +93,9 @@ public class DivideDataUtil {
         String result = "D";
         long travelTime = Long.parseLong(maxTravelTime.split("\\.")[0]);
         if (travelTime < 12000) {
-            result = result + (travelTime/1000 +1);
+            result = result + (travelTime / 1000 + 1);
         } else if (travelTime < 612000) {
-            result = result + ((travelTime-12000)/20000 + 1 + 12);
+            result = result + ((travelTime - 12000) / 20000 + 1 + 12);
         } else {
             result = result + (1 + 12 + 30);
         }
@@ -100,6 +104,7 @@ public class DivideDataUtil {
 
     /**
      * 出行总里程
+     *
      * @param sumFeeMileage 0-200000/50000/4; 200000-1000000/100000/8; 1000000-5000000/200000/20;
      *                      5000000-10000000/500000/10; 10000000-40000000/1000000/30; 40000000-80000000/1000600/25; 8000000以上;1
      * @return 脱敏后出行总里程区间
@@ -108,17 +113,17 @@ public class DivideDataUtil {
         String result = "E";
         long feeMileage = Long.parseLong(sumFeeMileage.split("\\.")[0]);
         if (feeMileage < 200000) {
-            result = result + (feeMileage/50000 +1);
+            result = result + (feeMileage / 50000 + 1);
         } else if (feeMileage < 1000000) {
-            result = result + ((feeMileage-200000)/100000 + 1 + 4);
+            result = result + ((feeMileage - 200000) / 100000 + 1 + 4);
         } else if (feeMileage < 5000000) {
-            result = result + ((feeMileage-1000000)/200000 + 1 + 4 + 8);
+            result = result + ((feeMileage - 1000000) / 200000 + 1 + 4 + 8);
         } else if (feeMileage < 10000000) {
-            result = result + ((feeMileage-5000000)/500000 + 1 + 4 + 8 + 20);
+            result = result + ((feeMileage - 5000000) / 500000 + 1 + 4 + 8 + 20);
         } else if (feeMileage < 40000000) {
-            result = result + ((feeMileage-10000000)/1000000 + 1 + 4 + 8 + 20 + 10);
+            result = result + ((feeMileage - 10000000) / 1000000 + 1 + 4 + 8 + 20 + 10);
         } else if (feeMileage < 80000000) {
-            result = result + ((feeMileage-40000000)/1600000 + 1 + 4 + 8 + 20 + 10 + 30);
+            result = result + ((feeMileage - 40000000) / 1600000 + 1 + 4 + 8 + 20 + 10 + 30);
         } else {
             result = result + (1 + 4 + 8 + 20 + 10 + 30 + 25);
         }
@@ -127,8 +132,9 @@ public class DivideDataUtil {
 
     /**
      * 负重出行总里程
+     *
      * @param sumWeightMileage 0/1; 0-200000/50000/4; 200000-1000000/100000/8; 1000000-5000000/200000/20;
-     *                        5000000-10000000/500000/10; 10000000-40000000/1000000/30; 40000000-80000000/1600000/25;
+     *                         5000000-10000000/500000/10; 10000000-40000000/1000000/30; 40000000-80000000/1600000/25;
      *                         80000000以上/1
      * @return 脱敏后负重出行总里程区间
      */
@@ -141,17 +147,17 @@ public class DivideDataUtil {
         }
         weightMileage = weightMileage - 1;
         if (weightMileage <= 200000) {
-            result = result + (weightMileage/50000 +1);
+            result = result + (weightMileage / 50000 + 1);
         } else if (weightMileage <= 1000000) {
-            result = result + ((weightMileage - 200000)/100000 + 1 + 4);
+            result = result + ((weightMileage - 200000) / 100000 + 1 + 4);
         } else if (weightMileage <= 5000000) {
-            result = result + ((weightMileage - 1000000)/200000 + 1 + 4 + 8);
+            result = result + ((weightMileage - 1000000) / 200000 + 1 + 4 + 8);
         } else if (weightMileage <= 10000000) {
-            result = result + ((weightMileage - 5000000)/500000 + 1 + 4 + 8 + 20);
+            result = result + ((weightMileage - 5000000) / 500000 + 1 + 4 + 8 + 20);
         } else if (weightMileage <= 40000000) {
-            result = result + ((weightMileage - 10000000)/1000000 + 1 + 4 + 8 + 20 + 10);
+            result = result + ((weightMileage - 10000000) / 1000000 + 1 + 4 + 8 + 20 + 10);
         } else if (weightMileage <= 80000000) {
-            result = result + ((weightMileage - 40000000)/1600000 + 1 + 4 + 8 + 20 + 10 + 30);
+            result = result + ((weightMileage - 40000000) / 1600000 + 1 + 4 + 8 + 20 + 10 + 30);
         } else {
             result = result + (1 + 1 + 4 + 8 + 20 + 10 + 30 + 25);
         }

+ 0 - 2
src/main/java/com/jkcredit/traffic/record/util/FileUtil.java

@@ -1,8 +1,6 @@
 package com.jkcredit.traffic.record.util;
 
 import java.io.File;
-import java.io.IOException;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 

+ 8 - 10
src/main/java/com/jkcredit/traffic/record/util/SparkTool.java

@@ -3,11 +3,9 @@ package com.jkcredit.traffic.record.util;
 import com.jkcredit.traffic.record.model.MonthResult;
 import org.apache.spark.SparkConf;
 import org.apache.spark.api.java.JavaSparkContext;
-import org.apache.spark.sql.*;
-import org.apache.spark.sql.expressions.Window;
-import org.apache.spark.sql.types.LongType;
-import org.apache.spark.sql.types.StructType;
-import scala.reflect.ClassTag;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Encoders;
+import org.apache.spark.sql.SparkSession;
 
 import java.util.List;
 
@@ -18,7 +16,7 @@ import java.util.List;
 
 public class SparkTool {
 
-    public static String appName ="DataExtract";
+    public static String appName = "DataExtract";
     private static JavaSparkContext jsc = null;
     private static SparkSession spark = null;
 
@@ -47,7 +45,7 @@ public class SparkTool {
     }
 
     public static SparkSession getSession() {
-        if (spark == null ) {
+        if (spark == null) {
             initSpark();
         }
         return spark;
@@ -67,15 +65,15 @@ public class SparkTool {
                 .option("header", true)
                 .csv("/Users/jkxy/Desktop/test/part-00000-4b3bccbf-a8ad-4bfe-b9a4-31e455238c9c-c000.csv")
                 .toDF("month", "vehicleid", "max_exTime", "sum_travel_time", "max_travel_time", "sum_feemileage",
-                        "sum_fee", "sum_weight_mileage","exTimes_count", "axlecount", "vehicletype",
+                        "sum_fee", "sum_weight_mileage", "exTimes_count", "axlecount", "vehicletype",
                         "travel_provinces_count", "transtime_count")
                 .as(Encoders.bean(MonthResult.class))
                 .coalesce(36);
         monthResultDataset.createOrReplaceTempView("monthDataset");
 
         // 110
-        Dataset<MonthResult> rows = spark.sql("select * from monthDataset where sum_travel_time < 2678400 "+
-                "and max_travel_time < 604800 and sum_feemileage < 89280000 and sum_weight_mileage < 89280000 and exTimes_count < 1200" )
+        Dataset<MonthResult> rows = spark.sql("select * from monthDataset where sum_travel_time < 2678400 " +
+                "and max_travel_time < 604800 and sum_feemileage < 89280000 and sum_weight_mileage < 89280000 and exTimes_count < 1200")
                 .as(Encoders.bean(MonthResult.class));
         List<MonthResult> results = rows.javaRDD().collect();
         spark.sqlContext().dropTempTable("monthDataset");