浏览代码

增加厂商库校验逻辑页签

cuixubin 4 年之前
父节点
当前提交
ab04bd883e

+ 31 - 28
src/main/java/com/persagy/dptool/CommonUtil.java

@@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.persagy.dptool.annotation.FieldCheck;
 import com.persagy.dptool.dto.PhysicalObject;
 import com.persagy.dptool.dto.physical.PhysicalWorld;
-import com.persagy.dptool.dto.physical.Project;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -20,6 +19,7 @@ import org.apache.http.util.EntityUtils;
 
 import java.io.*;
 import java.lang.reflect.Field;
+import java.net.URL;
 import java.util.*;
 
 public class CommonUtil {
@@ -111,6 +111,19 @@ public class CommonUtil {
     }
 
     /**
+     *
+     * @param filePath resources下面的json文件路径, 例如:/vender/brand.json
+     * @param clz
+     * @param <T>
+     * @return
+     * @throws IOException
+     */
+    public static <T> T jsonStrToObjByResourceJsonFile(String filePath, Class<T> clz) throws IOException {
+        URL rul = MainApp.class.getResource(filePath);
+        return  jsonMapper.readValue(rul, clz);
+    }
+
+    /**
      * 读取properties文件信息,转为map
      * @param propertyFile
      * @return
@@ -289,32 +302,22 @@ public class CommonUtil {
     }
 
     public static void main(String[] args) {
-        List<Project> projects = new ArrayList<>();
-        Project pj1 = new Project();
-        pj1.setProject_id("1101010001");
-        pj1.setValid(true);
-        pj1.setCtime("20201225010101");
-        pj1.setPassword("123");
-
-        Project pj2 = new Project();
-        pj2.setProject_id("1101010002");
-        pj2.setValid(false);
-        pj2.setCtime("20201225010101");
-
-        Project pj3 = new Project();
-        pj3.setProject_id("110101001");
-        pj3.setValid(true);
-        pj3.setCtime("20201225010101");
-        pj3.setPassword("123");
-
-        Project pj4 = new Project();
-        pj4.setProject_id("1101010001");
-        pj4.setCtime("20201125010101");
-        pj4.setPassword("123");
-
-        projects.add(pj1); projects.add(pj2);
-        projects.add(pj3); projects.add(pj4);
-
-        System.out.println(annotationFieldCheck(projects, null));
+        List<String> dataList = readFileToList(new File("D:/downloads/DingDing/download/4403050019/objects.json"));
+        Set<String> allKey = new HashSet<>();
+        Set<String> repeat = new HashSet<>();
+        try {
+            for(String dataStr : dataList) {
+                Map<String, Object> mapData = jsonStrToMap(dataStr);
+                String obj_idAndinfo_id = mapData.get("obj_id") + "";
+                if(allKey.contains(obj_idAndinfo_id)) {
+                    repeat.add(obj_idAndinfo_id);
+                }else {
+                    allKey.add(obj_idAndinfo_id);
+                }
+            }
+        }catch (Exception e){}
+
+        System.out.println(allKey.size());
+        System.out.println(repeat);
     }
 }

+ 43 - 71
src/main/java/com/persagy/dptool/PrimaryController.java

@@ -3,6 +3,7 @@ package com.persagy.dptool;
 import com.persagy.dptool.dialog.HelpDialog;
 import com.persagy.dptool.dialog.MessageDialog;
 import com.persagy.dptool.dto.PhysicalObject;
+import com.persagy.dptool.dto.VenderInfo;
 import javafx.concurrent.Task;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
@@ -10,12 +11,13 @@ import javafx.fxml.Initializable;
 import javafx.scene.control.*;
 import javafx.scene.layout.BorderPane;
 import javafx.stage.DirectoryChooser;
+import javafx.stage.FileChooser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.net.URL;
-import java.util.*;
+import java.util.ResourceBundle;
 
 public class PrimaryController implements Initializable {
     private static final Logger log = LoggerFactory.getLogger(PrimaryController.class);
@@ -34,11 +36,11 @@ public class PrimaryController implements Initializable {
     @FXML
     public TextField txfProject;
     @FXML
-    public TextField txfProjectInput;
+    public TextField txfProjectVender;
     @FXML
-    public TextField txfDataPlatformInput;
+    public Label lblVenderTip;
     @FXML
-    public TextField txfDirInput;
+    public TextField txfObjInfosJson;
     @FXML
     public Button btnCheck;
     @FXML
@@ -49,8 +51,6 @@ public class PrimaryController implements Initializable {
     @FXML
     public TextArea txaContentJson;
     @FXML
-    public TextArea txaContentInput;
-    @FXML
     public ProgressIndicator piState;
     /** 底部状态栏 */
     @FXML
@@ -68,8 +68,6 @@ public class PrimaryController implements Initializable {
         }
         txaContentJson.setText("目前只能校验HBase数据库中,物理世界的以下数据表数据:\n" + tableNameSBStr);
 
-        String checkResultFileName = "checkResult" + new Date().getTime() + ".txt";
-
     }
 
     /**
@@ -106,84 +104,58 @@ public class PrimaryController implements Initializable {
      * 选择配置文件目录
      * @param e
      */
-    public void selectDirJsonInput(ActionEvent e) {
-        DirectoryChooser dirChooser = new DirectoryChooser();
-        dirChooser.setTitle("选择json文件目录");
+    public void selectObjInfoJsonInput(ActionEvent e) {
+        FileChooser fileChooser = new FileChooser();
+        fileChooser.setTitle("选择obj_infos.json文件");
 
-        File folder = dirChooser.showDialog(paneRoot.getScene().getWindow());
+        fileChooser.getExtensionFilters().addAll(
+                new FileChooser.ExtensionFilter("json", "*.json"));
+        File file = fileChooser.showOpenDialog(paneRoot.getScene().getWindow());
 
-        if(null != folder) {
-            txfDirInput.setText(folder.getAbsolutePath());
+        if(null != file) {
+            txfObjInfosJson.setText(file.getAbsolutePath());
         }
     }
 
-    public void inputJsonFile(ActionEvent e) {
-        txaContentInput.setText("");
-        String projectId = txfProjectInput.getText();
-        PhysicalObject physicalObject = null;
+    /**
+     * 厂商库值处理
+     * @param e
+     */
+    public void venderValueHandle(ActionEvent e) {
+        lblVenderTip.setText("");
+
+        String projectId = txfProjectVender.getText();
+
+        VenderInfo venderInfo = null;
         if(projectId != null && projectId.trim().length() == 12 && projectId.startsWith("Pj")) {
-            physicalObject = new PhysicalObject(projectId, projectId.substring(2));
+            venderInfo = new VenderInfo(projectId);
         }else {
-            txaContentInput.setText("项目id不合法!");
-            txfProject.requestFocus();
+            lblVenderTip.setText("项目id不合法!");
+            txfProjectVender.requestFocus();
             return;
         }
 
-        String dataPlatformService = txfDataPlatformInput.getText();
-        if(null == dataPlatformService || dataPlatformService.trim().length() < 20) {
-            txaContentInput.setText("数据平台地址不合法!");
-            txfDataPlatformInput.requestFocus();
-            return;
-        }else if(!CommonUtil.dataPlatformConnectTest(dataPlatformService)) {
-            txaContentInput.setText("数据平台服务访问不通!请确保服务地址填写正确,且保证服务可访问。");
-            txfDataPlatformInput.requestFocus();
-            return;
-        }else {
-            physicalObject.dataPlatformUrl = dataPlatformService;
-        }
-
-        File jsonFileDir = null;
-        String filePath = txfDirInput.getText();
-
-        if(null != filePath) {
-            filePath = filePath.trim();
-            jsonFileDir = new File(filePath);
-            if(!jsonFileDir.exists() || !jsonFileDir.isDirectory()) {
-                txaContentInput.setText("目录地址不合法!");
-                txfDirInput.requestFocus();
+        String jsonFilePath = txfObjInfosJson.getText();
+        if(jsonFilePath != null && jsonFilePath.trim().length() > 10) {
+            if(!jsonFilePath.endsWith(".json")) {
+                lblVenderTip.setText("文件格式无法识别!");
+                txfObjInfosJson.requestFocus();
                 return;
             }
-        }else {
-            txaContentInput.setText("目录地址不合法!");
-        }
-
-        LinkedHashMap<String, File> fileMap = new LinkedHashMap<>();
-
-        Map<String, File> realFileMap = new HashMap<>();
-        for(File file : jsonFileDir.listFiles()) {
-            if(file.isFile() && file.getName().endsWith(ConstantData.tablesFileType)) {
-                realFileMap.put(file.getName(), file);
-            }
-        }
-
-        for(String tableName : ConstantData.tablesNameList) {
-            String realFileName = tableName+ConstantData.tablesFileType;
-            if(realFileMap.containsKey(realFileName)) {
-                fileMap.put(tableName, realFileMap.get(realFileName));
-            }
-        }
-
-        if(fileMap.isEmpty() || fileMap.size() != 9) {
-            StringBuilder errorTips = new StringBuilder("未找到完备、合法的数据表json文件!至少包含以下数据表文件:\n");
-            for(int i=0; i<9; i++) {
-                errorTips.append(" " + (i+1) + ". " + ConstantData.tablesNameList.get(i) + "\n");
+            File jsonFile = new File(jsonFilePath);
+            if(jsonFile.exists() && jsonFile.isFile()) {
+                Task<Boolean> task = TaskFactory.venderValueProcess(this, jsonFile, venderInfo);
+                new Thread(task).start();
+            }else {
+                lblVenderTip.setText("文件无法识别!文件不存在或已损坏");
+                txfObjInfosJson.requestFocus();
+                return;
             }
-            txaContentInput.setText(errorTips.toString());
+        }else {
+            lblVenderTip.setText("文件路径不合法!");
+            txfObjInfosJson.requestFocus();
             return;
         }
-
-        Task<Boolean> task = TaskFactory.jsonFileInput(this, jsonFileDir, physicalObject);
-        new Thread(task).start();
     }
 
     /**

+ 4 - 10
src/main/java/com/persagy/dptool/TaskFactory.java

@@ -17,19 +17,13 @@ public class TaskFactory {
     private static final Logger log = LoggerFactory.getLogger(PrimaryController.class);
     public static String[] prefixStr = {"- Error", "- Warn"};
 
-    public static Task<Boolean> jsonFileInput(PrimaryController controller, File fileDir, PhysicalObject physicalObject) {
+    public static Task<Boolean> venderValueProcess(PrimaryController controller, File jsonFile, VenderInfo venderInfo) {
         return new Task<Boolean>() {
             @Override
             protected Boolean call() throws Exception {
-                Platform.runLater(()->{
-                    controller.txaContentInput.setText("");
-                    controller.setDisable(true, 3);
-                    controller.piState.setVisible(true);
-                    controller.lblState.setText("分析json文件...");
-                });
-
-                log.info("【物理世界数据导入】--1--分析----开始----");
-
+                if(venderInfo.initData()) {
+                    System.out.println("初始化完成");
+                }
 
                 return true;
             }

+ 59 - 0
src/main/java/com/persagy/dptool/dto/VenderInfo.java

@@ -0,0 +1,59 @@
+package com.persagy.dptool.dto;
+
+import com.persagy.dptool.CommonUtil;
+import com.persagy.dptool.dto.vender.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class VenderInfo {
+    /** 项目id,包含Pj前缀 */
+    public String projectId;
+    /** 项目id,不含Pj前缀 */
+    public String pjId;
+
+    public VenderInfo(String projectId) {
+        this.projectId = projectId;
+        this.pjId = projectId.substring(2);
+    }
+
+    public static boolean init = false;
+    public static Map<String, VenderDTO> venderMap = new HashMap<>();
+    public static Map<String, BrandDTO> brandMap = new HashMap<>();
+    public static Map<String, VenderContactDTO> venderContMap = new HashMap<>();
+    public static Map<String, SpecificatDTO> specificMap = new HashMap<>();
+
+    public boolean initData() {
+        if(!init) {
+            try {
+                BrandRecords brandRecords = CommonUtil.jsonStrToObjByResourceJsonFile("/vender/brand.json", BrandRecords.class);
+                for(BrandDTO obj : brandRecords.getRecords()) {
+                    brandMap.put(obj.getBrandId(), obj);
+                }
+
+                VenderRecords venderRecords = CommonUtil.jsonStrToObjByResourceJsonFile("/vender/venders.json", VenderRecords.class);
+                for(VenderDTO obj : venderRecords.getRecords()) {
+                    venderMap.put(obj.getVenderId(), obj);
+                }
+
+                VenderContactRecords venderContactRecords = CommonUtil.jsonStrToObjByResourceJsonFile("/vender/vendercontactinfo.json", VenderContactRecords.class);
+                for(VenderContactDTO obj : venderContactRecords.getRecords()) {
+                    venderContMap.put(obj.getVenderId(), obj);
+                }
+
+                SpecificatRecords specificatRecords = CommonUtil.jsonStrToObjByResourceJsonFile("/vender/specification.json", SpecificatRecords.class);
+                for(SpecificatDTO obj : specificatRecords.getRecords()) {
+                    specificMap.put(obj.getSpecId(), obj);
+                }
+
+                System.out.println("厂商库配置初始化成功。venderSize=" + venderMap.size() + ", brandSize=" + brandMap.size()+ ", venderCont=" + venderContMap.size()+ ", specific=" + specificMap.size());
+                init = true;
+            }catch (Exception e) {
+                System.out.println("厂商库配置初始化失败");
+                e.printStackTrace();
+            }
+        }
+
+        return init;
+    }
+}

+ 34 - 0
src/main/java/com/persagy/dptool/dto/vender/BrandDTO.java

@@ -0,0 +1,34 @@
+package com.persagy.dptool.dto.vender;
+
+/**
+ * 品牌
+ */
+public class BrandDTO {
+    private String brandId;
+    private String venderId;
+    private String brandName;
+
+    public String getBrandId() {
+        return brandId;
+    }
+
+    public void setBrandId(String brandId) {
+        this.brandId = brandId;
+    }
+
+    public String getVenderId() {
+        return venderId;
+    }
+
+    public void setVenderId(String venderId) {
+        this.venderId = venderId;
+    }
+
+    public String getBrandName() {
+        return brandName;
+    }
+
+    public void setBrandName(String brandName) {
+        this.brandName = brandName;
+    }
+}

+ 15 - 0
src/main/java/com/persagy/dptool/dto/vender/BrandRecords.java

@@ -0,0 +1,15 @@
+package com.persagy.dptool.dto.vender;
+
+import java.util.List;
+
+public class BrandRecords {
+    private List<BrandDTO> records;
+
+    public List<BrandDTO> getRecords() {
+        return records;
+    }
+
+    public void setRecords(List<BrandDTO> records) {
+        this.records = records;
+    }
+}

+ 25 - 0
src/main/java/com/persagy/dptool/dto/vender/SpecificatDTO.java

@@ -0,0 +1,25 @@
+package com.persagy.dptool.dto.vender;
+
+/**
+ * 设备型号
+ */
+public class SpecificatDTO {
+    private String specId;
+    private String specName;
+
+    public String getSpecId() {
+        return specId;
+    }
+
+    public void setSpecId(String specId) {
+        this.specId = specId;
+    }
+
+    public String getSpecName() {
+        return specName;
+    }
+
+    public void setSpecName(String specName) {
+        this.specName = specName;
+    }
+}

+ 15 - 0
src/main/java/com/persagy/dptool/dto/vender/SpecificatRecords.java

@@ -0,0 +1,15 @@
+package com.persagy.dptool.dto.vender;
+
+import java.util.List;
+
+public class SpecificatRecords {
+    private List<SpecificatDTO> records;
+
+    public List<SpecificatDTO> getRecords() {
+        return records;
+    }
+
+    public void setRecords(List<SpecificatDTO> records) {
+        this.records = records;
+    }
+}

+ 34 - 0
src/main/java/com/persagy/dptool/dto/vender/VenderContactDTO.java

@@ -0,0 +1,34 @@
+package com.persagy.dptool.dto.vender;
+
+/**
+ * 厂商库联系方式
+ */
+public class VenderContactDTO {
+    private String venderId;
+    private String name;
+    private String phone;
+
+    public String getVenderId() {
+        return venderId;
+    }
+
+    public void setVenderId(String venderId) {
+        this.venderId = venderId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+}

+ 15 - 0
src/main/java/com/persagy/dptool/dto/vender/VenderContactRecords.java

@@ -0,0 +1,15 @@
+package com.persagy.dptool.dto.vender;
+
+import java.util.List;
+
+public class VenderContactRecords {
+    private List<VenderContactDTO> records;
+
+    public List<VenderContactDTO> getRecords() {
+        return records;
+    }
+
+    public void setRecords(List<VenderContactDTO> records) {
+        this.records = records;
+    }
+}

+ 25 - 0
src/main/java/com/persagy/dptool/dto/vender/VenderDTO.java

@@ -0,0 +1,25 @@
+package com.persagy.dptool.dto.vender;
+
+/**
+ * 厂商库
+ */
+public class VenderDTO {
+    private String venderId;
+    private String venderName;
+
+    public String getVenderId() {
+        return venderId;
+    }
+
+    public void setVenderId(String venderId) {
+        this.venderId = venderId;
+    }
+
+    public String getVenderName() {
+        return venderName;
+    }
+
+    public void setVenderName(String venderName) {
+        this.venderName = venderName;
+    }
+}

+ 15 - 0
src/main/java/com/persagy/dptool/dto/vender/VenderRecords.java

@@ -0,0 +1,15 @@
+package com.persagy.dptool.dto.vender;
+
+import java.util.List;
+
+public class VenderRecords {
+    private List<VenderDTO> records;
+
+    public List<VenderDTO> getRecords() {
+        return records;
+    }
+
+    public void setRecords(List<VenderDTO> records) {
+        this.records = records;
+    }
+}

+ 11 - 19
src/main/resources/primary.fxml

@@ -84,37 +84,29 @@
                             </children></AnchorPane>
                     </content>
                 </Tab>
-                <Tab text="物理世界导入">
+
+                <Tab text="厂商库值处理">
                     <content>
                         <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                      <children>
-                        <Label layoutX="14.0" layoutY="14.0" text="项目id: " />
-                        <Label layoutX="225.0" layoutY="14.0" text="数据平台地址: " />
-                        <TextField fx:id="txfProjectInput" layoutX="66.0" layoutY="9.0" prefHeight="30.0" prefWidth="144.0" promptText="Pj110101001" />
-                        <TextField fx:id="txfDataPlatformInput" layoutX="324.0" layoutY="9.0" prefHeight="30.0" prefWidth="499.0" promptText="http://127.0.0.1:8080/data-platform-3" />
-                        <Label layoutX="14.0" layoutY="55.0" text="json文件目录: " />
-                        <TextField fx:id="txfDirInput" layoutX="111.0" layoutY="50.0" prefHeight="30.0" prefWidth="680.0" />
-                        <Button layoutX="793.0" layoutY="50.0" mnemonicParsing="false" onAction="#selectDirJsonInput" text="···" />
-                        <Label layoutX="111.0" layoutY="80.0" prefHeight="24.0" prefWidth="733.0" text="注: 只识别由HbaseCat工具导出的json文件;json文件名应与表名一致。请保证json文件通过了物理世界校验。" textFill="#7c7c7c">
+                        <Label layoutX="31.0" layoutY="14.0" prefHeight="20.0" prefWidth="60.0" text="*项目id: " />
+                        <TextField fx:id="txfProjectVender" layoutX="91.0" layoutY="9.0" prefHeight="30.0" prefWidth="157.0" promptText="Pj110101001" />
+                        <Label layoutX="17.0" layoutY="63.0" prefHeight="20.0" prefWidth="74.0" text="*选择文件:" />
+                        <TextField fx:id="txfObjInfosJson" layoutX="91.0" layoutY="58.0" prefHeight="30.0" prefWidth="699.0" promptText="D:/temp/obj_infos.json" />
+                        <Button layoutX="796.0" layoutY="58.0" mnemonicParsing="false" onAction="#selectObjInfoJsonInput" text="···" />
+                        <Label layoutX="91.0" layoutY="88.0" prefHeight="24.0" prefWidth="696.0" text="注: 所选文件为HBaseCat工具导出的,HBase中物理世界,导出的obj_infos表数据的,json格式文件" textFill="#7c7c7c">
                            <font>
                               <Font size="14.0" />
                            </font>
                         </Label>
                         <Label layoutX="55.0" layoutY="142.0" />
-                        <Button layoutX="15.0" layoutY="122.0" mnemonicParsing="false" onAction="#inputJsonFile" text="执行" />
                         <Label layoutX="21.0" layoutY="171.0" />
-                        <StackPane layoutX="71.0" layoutY="122.0" prefHeight="408.0" prefWidth="752.0">
-                           <children>
-                              <FlowPane prefHeight="408.0" prefWidth="781.0">
-                                 <children>
-                                    <TextArea fx:id="txaContentInput" prefHeight="410.0" prefWidth="753.0" />
-                                 </children>
-                              </FlowPane>
-                           </children>
-                        </StackPane>
+                        <Button layoutX="405.0" layoutY="137.0" mnemonicParsing="false" onAction="#venderValueHandle" text="处理" />
+                        <Label fx:id="lblVenderTip" layoutX="91.0" layoutY="257.0" prefHeight="32.0" prefWidth="697.0" textFill="RED" />
                      </children></AnchorPane>
                     </content>
                 </Tab>
+
             </tabs>
         </TabPane>
     </center>

文件差异内容过多而无法显示
+ 2714 - 0
src/main/resources/vender/brand.json


文件差异内容过多而无法显示
+ 9604 - 0
src/main/resources/vender/specification.json


文件差异内容过多而无法显示
+ 1539 - 0
src/main/resources/vender/vendercontactinfo.json


文件差异内容过多而无法显示
+ 3836 - 0
src/main/resources/vender/venders.json