Quellcode durchsuchen

feat: B域接口封装--是否开通了5G套餐

weijianghai vor 2 Jahren
Ursprung
Commit
66b92ab3c5

+ 1 - 0
doc/接口文档/domainBAPI接口说明.md

@@ -84,6 +84,7 @@ Content-Type: application/json
   "message": "成功",
   "data": {
     "isHebeiUnicomNumber": true,
+    "is5gProduct": true,
     "isHaveSa": true,
     "isHaveVolte": true
   }

+ 20 - 0
src/main/java/com/nokia/domainb/controller/TestController.java

@@ -0,0 +1,20 @@
+package com.nokia.domainb.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Slf4j
+@RequestMapping("/test")
+@RestController
+public class TestController {
+    /**
+     * 短信告警测试
+     */
+    @GetMapping("/alert/")
+    public Object alert() {
+        log.error("短信告警测试");
+        return "ok";
+    }
+}

+ 10 - 0
src/main/java/com/nokia/domainb/service/DomainService.java

@@ -1,6 +1,7 @@
 package com.nokia.domainb.service;
 
 import cn.chinaunicom.open.nlgxptconnection.COMPConnectionContext;
+import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
@@ -121,6 +122,7 @@ public class DomainService {
         vo.setIsHaveSa(false);
         vo.setIsHaveVolte(false);
         vo.setIsHebeiUnicomNumber(true);
+        vo.setIs5gProduct(false);
         String res = result.getResponseContext();
         if (res.contains("VoLTE")) {
             vo.setIsHaveVolte(true);
@@ -130,6 +132,14 @@ public class DomainService {
             vo.setIsHaveSa(true);
         }
 
+        JsonArray data = rsp.getAsJsonArray("DATA");
+        for (JsonElement t : data) {
+            JsonObject tt = t.getAsJsonObject();
+            if ("M".equals(tt.get("productType").getAsString()) && tt.get("productName").getAsString().contains("5G")) {
+                vo.setIs5gProduct(true);
+                break;
+            }
+        }
         return R.ok().data(vo);
     }
 

+ 10 - 2
src/main/java/com/nokia/domainb/util/Utils.java

@@ -8,6 +8,11 @@ import java.util.HashSet;
 import java.util.Set;
 
 public class Utils {
+    public static void main(String[] args) {
+        Set<String> phones = Utils.readPhones();
+        System.out.println(phones.size());
+    }
+
     /**
      * 读取手机号放入set去重
      */
@@ -19,11 +24,13 @@ public class Utils {
 //        String location = "classpath:data/1000.txt";
 //        String location = "classpath:data/2000.txt";
 //        String location = "classpath:data/5000.txt";
-        String location = "classpath:data/8000.txt";
-//        String location = "classpath:data/10000.txt";
+//        String location = "classpath:data/8000.txt";
+        String location = "classpath:data/10000.txt";
 //        String location = "classpath:data/10000+.txt";
 //        String location = "classpath:data/测试号码2.txt";
 //        String location = "classpath:data/测试号码1万多.txt";
+//        String location = "classpath:data/100route.txt";
+//        String location = "classpath:data/1000route.txt";
         FileInputStream fis;
         try {
             File file = ResourceUtils.getFile(location);
@@ -50,6 +57,7 @@ public class Utils {
         } catch (IOException e) {
             e.printStackTrace();
         }
+
         return result;
     }
 }

+ 1 - 0
src/main/java/com/nokia/domainb/vo/SaAndVolteVO.java

@@ -7,4 +7,5 @@ public class SaAndVolteVO {
     private Boolean isHebeiUnicomNumber;
     private Boolean isHaveSa;
     private Boolean isHaveVolte;
+    private Boolean is5gProduct;
 }

+ 2 - 2
src/main/resources/data/10000.txt

@@ -9988,13 +9988,13 @@
 15532146668
 15614172892
 13223417632
-15512476268
 15533682112
 15613300657
-17692110530
 13111532907
 18603299111
 18500069099
 15076408711
+18633188421
+13020037388
 15210846112
 18411086112

+ 65 - 3
src/test/java/com/nokia/domainb/capability/ForeignproductTest.java

@@ -1,17 +1,79 @@
 package com.nokia.domainb.capability;
 
 import cn.chinaunicom.open.nlgxptconnection.COMPConnectionContext;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.nokia.domainb.util.Utils;
+import de.siegmar.fastcsv.writer.CsvWriter;
+import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * 已订购产品查询
  * json_microservice_users_foreignproduct
  */
-public class ForeignproductTest {
+@Slf4j
+class ForeignproductTest {
     @Test
-    void testQuery() {
+    void test() {
         Foreignproduct foreignproduct = new Foreignproduct();
-        COMPConnectionContext result = foreignproduct.query("18622305641", "13", false);
+        COMPConnectionContext result = foreignproduct.query("18633367653", "18", false);
         System.out.println(result.getResponseContext());
     }
+
+    @Test
+    void testQuery() {
+        String filePath = "result/已订购产品查询.csv";
+        try {
+            Files.createDirectories(Paths.get("result"));
+        } catch (IOException e) {
+            e.printStackTrace();
+            return;
+        }
+        Set<String> phones = Utils.readPhones();
+        try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(Paths.get(filePath)), StandardCharsets.UTF_8);
+             CsvWriter csv = CsvWriter.builder().build(osw);) {
+            csv.writeRow("phone", "productType", "productName");
+            for (String t : phones) {
+                Map<String, JsonObject> map = new HashMap<>();
+                String[] a = t.split(",");
+                String phone = a[0];
+                String provinceCode = a[1];
+                Foreignproduct foreignproduct = new Foreignproduct();
+                log.info("phone: {}", phone);
+                COMPConnectionContext result = foreignproduct.query(phone, provinceCode, false);
+                JsonObject jsonObject = JsonParser.parseString(result.getResponseContext()).getAsJsonObject();
+                JsonObject rsp = jsonObject.getAsJsonObject("UNI_BSS_BODY")
+                        .getAsJsonObject("FOREIGN_PRODUCT_RSP")
+                        .getAsJsonObject("RSP");
+                String rspCode = rsp.get("RSP_CODE").getAsString();
+                if (!"0000".equals(rspCode)) {
+                    continue;
+                }
+                JsonArray data = rsp.getAsJsonArray("DATA");
+                for (JsonElement tt : data) {
+                    JsonObject ttt = tt.getAsJsonObject();
+                    if ("M".equals(ttt.get("productType").getAsString())) {
+                        map.put(phone + ttt.get("productType").getAsString() + ttt.get("productName").getAsString(), ttt);
+                    }
+                }
+                for (JsonObject value : map.values()) {
+                    csv.writeRow(phone, value.get("productType").getAsString(), value.get("productName").getAsString());
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 15 - 16
src/test/java/com/nokia/domainb/capability/controller/DomainControllerTest.java

@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
 @SpringBootTest
 @Import(DomainControllerTest.ConcurrentTestConfig.class)
 class DomainControllerTest {
-    public static final int poolSize = 10;
+    public static final int poolSize = 40;
     /**
      * 测试结果保存文件夹
      */
@@ -114,9 +114,9 @@ class DomainControllerTest {
             e.printStackTrace();
             return;
         }
-        resultPath = resultPath + "路由查询10个线程10000条数据测试结果.csv";
-//        resultPath = resultPath + "路由查询10个线程1000条数据测试结果.csv";
-//        resultPath = resultPath + "路由查询10个线程100条数据测试结果.csv";
+        resultPath = resultPath + "路由查询" + poolSize + "个线程10000条数据测试结果.csv";
+//        resultPath = resultPath + "路由查询" + poolSize + "个线程1000条数据测试结果.csv";
+//        resultPath = resultPath + "路由查询" + poolSize + "个线程100条数据测试结果.csv";
         // 接口地址
         String url = "http://133.96.94.108:12091/domainB/api/route/";
         Set<String> phones = Utils.readPhones();
@@ -149,9 +149,9 @@ class DomainControllerTest {
             e.printStackTrace();
             return;
         }
-        resultPath = resultPath + "5GSA查询10个线程10000条数据测试结果.csv";
-//        resultPath = resultPath + "5GSA查询10个线程1000条数据测试结果.csv";
-//        resultPath = resultPath + "5GSA查询10个线程100条数据测试结果.csv";
+        resultPath = resultPath + "5GSA查询" + poolSize + "个线程10000条数据测试结果.csv";
+//        resultPath = resultPath + "5GSA查询" + poolSize + "个线程1000条数据测试结果.csv";
+//        resultPath = resultPath + "5GSA查询" + poolSize + "个线程100条数据测试结果.csv";
         // 接口地址
         String url = "http://133.96.94.108:12091/domainB/api/sa/";
         Set<String> phones = Utils.readPhones();
@@ -184,17 +184,16 @@ class DomainControllerTest {
             e.printStackTrace();
             return;
         }
-        resultPath = resultPath + "功能查询10个线程10000条数据测试结果.csv";
-//        resultPath = resultPath + "功能查询10个线程1000条数据测试结果.csv";
-//        resultPath = resultPath + "功能查询10个线程100条数据测试结果.csv";
+        resultPath = resultPath + "new功能查询" + poolSize + "个线程10000条数据测试结果.csv";
+//        resultPath = resultPath + "功能查询" + poolSize + "个线程1000条数据测试结果.csv";
+//        resultPath = resultPath + "功能查询" + poolSize + "个线程100条数据测试结果.csv";
         // 接口地址
-        String url = "http://133.96.94.108:12091/domainB/api/product/saAndVolte/";
+        String url = "http://192.168.50.3:12091/domainB/api/product/saAndVolte/";
+//        String url = "http://133.96.94.108:12091/domainB/api/product/saAndVolte/";
         Set<String> phones = Utils.readPhones();
         for (String t : phones) {
-            String[] a = t.split(",");
-            String phoneNumber = a[0];
-            SaAndVolteDTO dto = new SaAndVolteDTO("test", phoneNumber);
-            executor.submit(new Task(template, phoneNumber, url, dto, singlePath));
+            SaAndVolteDTO dto = new SaAndVolteDTO("test", t);
+            executor.submit(new Task(template, t, url, dto, singlePath));
         }
         // 等待所有任务执行结束
         while (executor.getActiveCount() > 0) {
@@ -219,7 +218,7 @@ class DomainControllerTest {
             e.printStackTrace();
             return;
         }
-        resultPath = resultPath + "用户资料三户返回10个线程7月1-24日移网质量投诉业务号码测试结果.csv";
+        resultPath = resultPath + "用户资料三户返回" + poolSize + "个线程7月1-24日移网质量投诉业务号码测试结果.csv";
         // 接口地址
         String url = "http://133.96.94.108:12091/domainB/api/threePart/userState/";
         Set<String> phones = Utils.readPhones();