kangyu před 4 měsíci
revize
dbaed40184

+ 38 - 0
.gitignore

@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 7 - 0
.idea/encodings.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+  </component>
+</project>

+ 14 - 0
.idea/misc.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 124 - 0
.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

binární
5.0风机设备控制与监测代码生成工具类.docx


+ 0 - 0
README.md


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1446 - 0
generate/Wl1k.txt


+ 32 - 0
pom.xml

@@ -0,0 +1,32 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.example</groupId>
+  <artifactId>FastPlcGenerate</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>FastPlcGenerate</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+
+
+    </dependency>
+    <dependency>
+      <groupId>org.apache.poi</groupId>
+      <artifactId>poi-ooxml</artifactId>
+      <version>5.2.3</version> <!-- Use the latest version available -->
+    </dependency>
+  </dependencies>
+</project>

+ 521 - 0
src/main/java/com/ventanaly/FastPlcGenerate.java

@@ -0,0 +1,521 @@
+package com.ventanaly;//import com.ventanaly.device.facility.fanMain.FanMainSXFacility;
+//import com.ventanaly.device.facility.fanMain.FanMainSgtFacility;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FastPlcGenerate {
+
+
+    // 风机类型 主扇:Main 局扇:System
+    public static String FAN_TYPE="Main";
+
+    //矿井唯一表示,万里一矿--->Wl1k
+    public static String MINE_NAME="Wl1k";
+
+    //设备名称
+    public static String DEVICE_NAME="万里一矿主扇";
+
+    // Excel文件路径
+    public static String EXCEL_FILE_PATH = "template/wl1k.xlsx";
+
+
+    public static String ENUM_NAME = "Fan"+FAN_TYPE+MINE_NAME+"Enum";
+
+    public static String ENUM_PREFIX = "FAN_"+FAN_TYPE.toUpperCase()+"_"+MINE_NAME.toUpperCase()+"_ENUM_";
+
+    public static String FROM_NAME = "Fan"+FAN_TYPE+MINE_NAME+"From";
+
+    public static String VO_NAME = "Fan"+FAN_TYPE+MINE_NAME+"Vo";
+
+    public static String FACILITY_NAME = "Fan"+FAN_TYPE+MINE_NAME+"Facility";
+
+    public static String FACILITY_REF_NAME = "fan"+FAN_TYPE+MINE_NAME+"Facility";
+
+
+
+    public static void main(String[] args)  {
+
+        // 指定输出文件的路径
+        String filePath = "generate/"+MINE_NAME+".txt";
+
+        LocalDate currentDate = LocalDate.now();
+
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+        String nowDate = currentDate.format(formatter);
+
+
+        try {
+
+            PrintStream out = new PrintStream(Files.newOutputStream(Paths.get(filePath)));
+
+            // 将System.out设置为新的PrintStream实例
+            System.setOut(out);
+
+            FileInputStream fis = new FileInputStream(EXCEL_FILE_PATH);
+            Workbook workbook = new XSSFWorkbook(fis);
+            Sheet sheet = workbook.getSheetAt(0);
+
+            List<String> columnNameList = new ArrayList<>();
+            List<String> typeList = new ArrayList<>();
+            List<String> chineseExplanationList = new ArrayList<>();
+            List<String> accessModeList = new ArrayList<>();
+            List<String> pointsList = new ArrayList<>();
+
+            for (Row row : sheet) {
+                if (row.getRowNum() == 0) continue; // 跳过标题行
+
+                Cell columnNameCell = row.getCell(0);
+                Cell typeCell = row.getCell(1);
+                Cell chineseExplanationCell = row.getCell(2);
+                Cell accessModeCell = row.getCell(3);
+                Cell pointsCell = row.getCell(4);
+
+
+                columnNameList.add(getCellValueAsString(columnNameCell));
+                typeList.add(getCellValueAsString(typeCell));
+                chineseExplanationList.add(getCellValueAsString(chineseExplanationCell));
+                accessModeList.add(getCellValueAsString(accessModeCell));
+                pointsList.add(getCellValueAsString(pointsCell));
+            }
+
+            String[] colArray = columnNameList.toArray(new String[0]);
+            String[] typeArray = typeList.toArray(new String[0]);
+            String[] notesArray = chineseExplanationList.toArray(new String[0]);
+            String[] accessModes = accessModeList.toArray(new String[0]);
+            String[] pointsArray = pointsList.toArray(new String[0]);
+            System.out.println("监测实体类====================================================================");
+            creatVoEntity(colArray,typeArray,notesArray,accessModes,nowDate);
+            System.out.println("控制实体类====================================================================");
+            creatFromEntity(colArray,typeArray,notesArray,accessModes,nowDate);
+            System.out.println("枚举=========================================================================");
+            creatEnum(colArray,notesArray,pointsArray,accessModes,nowDate);
+            System.out.println("业务实现类=====================================================================");
+            creatFacility(colArray,typeArray,notesArray,accessModes,false,"1","1",nowDate);
+            System.out.println("控制方法实现====================================================================");
+            createServiceControl(colArray,notesArray,accessModes,nowDate);
+            System.out.println();
+            System.out.println("监测方法片段====================================================================");
+            createServiceMonitor(nowDate);
+            System.out.println("点表配置json====================================================================");
+            creatDBJSON(colArray,pointsArray);
+            System.out.println("点位解释json====================================================================");
+            createInterpret(colArray,notesArray,accessModes);
+            System.out.println("控制请求表格====================================================================");
+            createReqFormDoc(colArray,notesArray,typeArray,accessModes);
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+
+
+    }
+
+
+    private static String getCellValueAsString(Cell cell) {
+        if (cell == null) return "";
+
+        switch (cell.getCellType()) {
+            case STRING:
+                return cell.getStringCellValue().trim();
+            case NUMERIC:
+                return String.valueOf(cell.getNumericCellValue());
+            case BOOLEAN:
+                return String.valueOf(cell.getBooleanCellValue());
+            case FORMULA:
+                return cell.getCellFormula();
+            case BLANK:
+                return "";
+            default:
+                return "";
+        }
+    }
+
+    public static void createServiceControl(String[] colArray,String[] notesArray,String[] accessModes,String nowDate){
+        System.out.println("    //"+DEVICE_NAME+"  "+nowDate);
+        System.out.println("    public boolean controlFan"+FAN_TYPE+MINE_NAME+"(Fan"+FAN_TYPE+"From from, Json json, FanMainPage fm, UserLogPage ulPage) {\n");
+        System.out.println("        boolean r = false;\n" +
+                "        ulPage.setDeviceType(4);\n" +
+                "        DeviceRelationPage dr = SubStationStatic.DRMap.get(from.getId());\n" +
+                "        if (null == dr) {\n" +
+                "            throw new ServiceException(\"不存在的分站\");\n" +
+                "        }\n" +
+                "        SubStationPage page = dr.getSubStationPage();\n" +
+                "        try {\n" +
+                "            RelationVo g = (RelationVo) dr.getObjVo();\n" +
+                "            from.setStrInstallPos(g.getStrInstallPos());\n" +
+                "        } catch (Exception e) {\n" +
+                "            e.printStackTrace();\n" +
+                "        }\n" +
+                "        Map<String, String> tableMeta = SubStationStatic.tableMetas.get(dr.getPLC_table());\n" +
+                "        json.setMsg(\"无任何操作\");\n" +
+                "        if (dr.getDevice_id() != fm.getNFanID()) {\n" +
+                "            throw new ServiceException(\"输入密码不正确\");\n" +
+                "        }\n" +
+                "        SensorNet net = page.getSensorNet();");
+        System.out.println("        if (!dr.getIsFake()) {\n" +
+                "            if (!net.getState()) {\n" +
+                "                json.setMsg(\"无任何操作\");\n" +
+                "                throw new ServiceException(\"无法与设备建立链接\");\n" +
+                "            }\n");
+
+        for(int i = 0;i<colArray.length;i++){
+            if ("只读".equals(accessModes[i])){continue;}
+            Character c = colArray[i].charAt(0);
+            String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
+            System.out.println("            if (null != from.get"+FROM_NAME+"().get"+newCol+"()) {");
+            System.out.println("               logger.info(\""+notesArray[i]+"--->\" + from.get"+FROM_NAME+"().get"+newCol+"());");
+            System.out.println("               json.setMsg(\""+notesArray[i]+"\");");
+            System.out.println("               ulPage.setRecord(\""+notesArray[i]+":\" + from.get"+FROM_NAME+"().get"+newCol+"());");
+            System.out.println("               r = "+FACILITY_REF_NAME+"."+colArray[i]+"(from, net, tableMeta, null);");
+            System.out.println("            }");
+            System.out.println();
+        }
+        System.out.println("        }");
+        System.out.println("        return r;\n" +
+                "    }");
+
+    }
+
+
+    public static void createServiceMonitor(String nowDate){
+        System.out.println("    //"+DEVICE_NAME+"  "+nowDate);
+        System.out.println("            case Fan"+FAN_TYPE+MINE_NAME+"Facility.TYPE:\n" +
+                "                vo = fan"+FAN_TYPE+MINE_NAME+"Facility.status(dr,tableMeta,page);\n" +
+                "                break;");
+    }
+
+    public static void creatFacility(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes,boolean flag,String cy,String num,String nowDate){
+        System.out.println("import com.ventanaly.tool.enums.PLCDevice2Enum;\n" +
+                "import com.ventanaly.tool.froms.FanMainFrom;\n" +
+                "import com.ventanaly.tool.page.FanMainPage;\n" +
+                "import com.ventanaly.tool.utils.Constants;\n" +
+                "import com.ventanaly.tool.page.DeviceRelationPage;\n" +
+                "import com.ventanaly.tool.page.SubStationPage;\n" +
+                "import com.ventanaly.tool.utils.SensorNet;\n" +
+                "import org.slf4j.Logger;\n" +
+                "import org.slf4j.LoggerFactory;\n" +
+                "import org.springframework.stereotype.Component;\n" +
+                "import java.util.Map;");
+
+        System.out.println("    //"+DEVICE_NAME+"  "+nowDate);
+        System.out.println("@Component");
+        System.out.println("public class "+FACILITY_NAME+" {");
+        System.out.println("\n" +
+                "    private final Logger logger = LoggerFactory.getLogger(getClass());");
+        System.out.println("    public static final String TYPE = \"fan_"+FAN_TYPE.toLowerCase()+"_"+MINE_NAME.toLowerCase()+"\";");
+        System.out.println("    public static final String TYPE_NAME = "+"\""+DEVICE_NAME+"\""+";\n" +
+                "    private static boolean control = true;\n" +
+                "\n");
+        System.out.println("    public "+VO_NAME+" fan"+ FAN_TYPE +MINE_NAME+"Status(DeviceRelationPage dr, Map<String, String> tableMeta, FanMainPage page) {\n");
+        System.out.println("        "+VO_NAME+" vo = new "+ VO_NAME+"();");
+        System.out.println("        vo.setDeviceType(Constants.DEVICE_TYPE_FAN_"+FAN_TYPE.toUpperCase()+");");
+        System.out.println("        vo.setSmallType(TYPE);");
+        System.out.println("        vo.setDeviceId(dr.getDevice_id());");
+        System.out.println("        vo.setId(dr.getId());");
+        System.out.println("        SubStationPage sp = dr.getSubStationPage();");
+        System.out.println("        if (null == sp) {");
+        System.out.println("            return vo;");
+        System.out.println("        }");
+        System.out.println("        SensorNet net = sp.getSensorNet();");
+        System.out.println("        vo.setNetStatus(net.isLinkState() ? 1 : 0);");
+        System.out.println("        if (1 == vo.getNetStatus()) {");
+        System.out.println("            String address;");
+        System.out.println("            String tName;");
+        System.out.println("            vo.setUrl(net.getIp());");
+        for(int i = 0;i<colArray.length;i++){
+            if ("只写".equals(accessModes[i])){continue;}
+
+            System.out.println("            tName = PLCDevice2Enum."+ENUM_NAME+"."+ENUM_PREFIX + colArray[i].toUpperCase() + ".getName();");
+            System.out.println("            address = tableMeta.get(tName);");
+            if("Boolean".equals(typeArray[i])){
+                System.out.println("            "+typeArray[i] + " " + colArray[i] + " = net.getSensorBoolean(address);");
+            }else{
+                System.out.println("            "+typeArray[i] + " " + colArray[i] + " = net.getSensor" + typeArray[i] + "(address);");
+            }
+            if(flag && !"Boolean".equals(typeArray[i])){
+                System.out.println("            "+"BigDecimal"+" "+ colArray[i] + "Val = StringUtils.roundHalfUp("+colArray[i]+"*"+cy+","+num+");");
+            }
+
+            System.out.println("            "+"logger.debug(\"" + notesArray[i] + "-ID:{}-点位名称:{},address:{},Val:{}\", dr.getId(), tName, address, " + colArray[i] + ");");
+            Character c = colArray[i].charAt(0);
+            String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
+            if(flag && !"Boolean".equals(typeArray[i])){
+                System.out.println("            "+"vo.set" + newCol + "(" + colArray[i] + "Val.floatValue());");
+            }else{
+                System.out.println("            "+"vo.set" + newCol + "(" + colArray[i] + ");");
+            }
+
+            System.out.println();
+        }
+        System.out.println("        }");
+        System.out.println("        dr.setObjVo(vo);\n" +
+                "        return vo;");
+        System.out.println("    }");
+        creatControl(colArray,typeArray,notesArray,accessModes);
+        System.out.println("}");
+    }
+
+    /**
+     *生成实体类
+     * @param colArray 字段
+     * @param typeArray 字段类型
+     * @param notesArray 字段解释
+     */
+    public static void creatEntity(String[] colArray,String[] typeArray,String[] notesArray){
+        //都用逗号隔开
+        for(int i = 0;i<colArray.length;i++){
+            System.out.println("@JsonProperty(value = " + "\"" + colArray[i] + "\"" + ")");
+            System.out.println("private " + typeArray[i] + " " + colArray[i] + ";  //" + notesArray[i]);
+        }
+    }
+
+    //生成监测实体类
+    public static void creatVoEntity(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes,String nowDate){
+        System.out.println("    //"+DEVICE_NAME+"  "+nowDate);
+        System.out.println("@Data");
+        System.out.println("public class "+VO_NAME+" extends RelationVo {");
+        for(int i = 0;i<colArray.length;i++){
+            if ("只写".equals(accessModes[i])){continue;}
+            System.out.println("    @JsonProperty(value = " + "\"" + colArray[i] + "\"" + ")");
+            System.out.println("    private " + typeArray[i] + " " + colArray[i] + ";  //" + notesArray[i]);
+        }
+        System.out.println("}");
+    }
+
+    //生成控制请求类
+    public static void creatFromEntity(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes,String nowDate){
+        System.out.println("    //"+DEVICE_NAME+"  "+nowDate);
+        System.out.println("@Data");
+        System.out.println("public class "+FROM_NAME+"{");
+        for(int i = 0;i<colArray.length;i++){
+            if ("只读".equals(accessModes[i])){continue;}
+            System.out.println("    @JsonProperty(value = " + "\"" + colArray[i] + "\"" + ")");
+            System.out.println("    private " + typeArray[i] + " " + colArray[i] + ";  //" + notesArray[i]);
+        }
+        System.out.println("}");
+    }
+
+    /**
+     * 生成Enum
+     * @param colArray 字段
+     * @param notesArray 字段解释
+     */
+    public static void creatEnum(String[] colArray,String[] notesArray,String[] pointsArray,String[] accessModes,String nowDate){
+        String befStr = ENUM_PREFIX;
+        System.out.println("    //"+DEVICE_NAME+"  "+nowDate);
+        System.out.println("    public enum Fan"+FAN_TYPE+MINE_NAME+"Enum {");
+        for(int i = 0;i<colArray.length;i++){
+                if (i!=colArray.length-1){
+
+                    System.out.println("        "+befStr + colArray[i].toUpperCase() + "(" + "\"" + colArray[i] + "\", \"" + notesArray[i] + "\", \"" +pointsArray[i]+ "\"" +"),");
+
+                }else {
+                    System.out.println("        "+befStr + colArray[i].toUpperCase() + "(" + "\"" + colArray[i] + "\", \"" + notesArray[i] + "\", \"" +pointsArray[i]+ "\"" +");");
+
+                }
+        }
+        System.out.println("\n" +
+                "        private String name; //状态位/控制位\n" +
+                "        private String message; //指令描述\n" +
+                "        private String point;");
+        System.out.println("        Fan"+FAN_TYPE+MINE_NAME+"Enum(String name, String message,String point) {\n" +
+                "            this.name = name;\n" +
+                "            this.message = message;\n" +
+                "            this.point = point;\n" +
+                "        }\n");
+        System.out.println("        public String getName() {\n" +
+                "            return name;\n" +
+                "        }\n" +
+                "\n" +
+                "        public String getMessage() {\n" +
+                "            return message;\n" +
+                "        }\n" +
+                "\n" +
+                "        public String getPoint(){return point;}\n" +
+                "    }");
+
+    }
+
+    /**
+     * 生成Enum
+     * @param colArray 字段
+     * @param lcsxArray 量程上限字段
+     * @param lcxxArray 量程下限字段
+     * @param bjsxArray 报警上限
+     * @param bjxxArray 报警下限
+     */
+    public static void creatFtpEnum(String[] colArray,String[] lcsxArray,String[] lcxxArray,String[] bjsxArray,String[] bjxxArray,String[] notesArray){
+        String befStr = "FAN_MAIN_TLH_ENUM_";
+        for(int i = 0;i<colArray.length;i++){
+            int id = i + 1;
+            String val ="" + id + "," + lcsxArray[i] + "," + lcxxArray[i] + "," + bjsxArray[i] + "," + bjxxArray[i];
+            System.out.print(befStr + colArray[i].toUpperCase() + "(" + "\"" + colArray[i] + "\", \"" + val + "\"" + "),");
+            System.out.println("//" + notesArray[i]);
+        }
+    }
+
+    /**
+     * 生成点表json字符串
+     * @param colArray 字段
+     * @param dbArray 点位地址/id
+     */
+    public static void creatDBJSON(String[] colArray , String[] dbArray){
+        StringBuffer str = new StringBuffer();
+        str.append("{");
+        for(int i = 0;i<colArray.length;i++)
+        {
+            str.append("\"");
+            //拼接请求json数据格式["",""]
+            str.append(colArray[i]);
+            str.append("\"");
+            str.append(":");
+            str.append("\"");
+            str.append(dbArray[i]);
+            str.append("\"");
+            if(i==colArray.length-1) {
+                break;
+            }
+            str.append(",");
+        }
+        str.append("}");
+        System.out.println(str.toString());
+    }
+
+    /**
+     * 生成测试模拟数据代码
+     * @param colArray 字段
+     * @param typeArray 字段类型
+     */
+    public static void creatTestData(String[] colArray , String[] typeArray){
+        for(int i = 0;i<colArray.length;i++){
+            Character c = colArray[i].charAt(0);
+            String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
+            String val = "";
+            if("boolean".equals(typeArray[i]) || "Boolean".equals(typeArray[i])){
+                val = "(true";
+            }else{
+                val = "(setVal(10f, 5f)";
+            }
+            System.out.println("vo.set" + newCol + val + ");");
+        }
+    }
+
+    /**
+     *生成实体类
+     */
+    public static void creatEntity2(String col,String type,String note){
+        //都用逗号隔开
+        for(int i = 0;i<540;i++){
+            System.out.println("@JsonProperty(value = " + "\"" + col + i + "\"" + ")");
+            System.out.println("private " + type + " " + col + i + ";  //" + note);
+        }
+    }
+
+    /**
+     * 生成控制代码
+     * @param colArray
+     * @param typeArray
+     * @param notesArray
+     */
+    public static void creatControl(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes){
+
+        for(int i = 0;i<colArray.length;i++){
+
+            if ("只读".equals(accessModes[i])){continue;}
+            System.out.println("    //"+notesArray[i]);
+            System.out.println("    public boolean " + colArray[i] + "(Fan"+FAN_TYPE+"From from, SensorNet net, Map<String, String> tableMeta, Long timeout) {");
+            System.out.println("        boolean result = false;");
+            System.out.println("        if (control) {");
+            System.out.println("            control = false;");
+            Character c = colArray[i].charAt(0);
+            String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
+            System.out.println("            String tName = PLCDevice2Enum."+ENUM_NAME+"."+ENUM_PREFIX + colArray[i].toUpperCase() + ".getName();");
+            System.out.println("            String address = tableMeta.get(tName);");
+            System.out.println("            try {");
+            if("Boolean".equals(typeArray[i]) || "boolean".equals(typeArray[i])){
+                System.out.println("                result = net.setSensor(address,Constants.PLC_BOOLEAN_TRUE);");
+                System.out.println("                logger.debug(\"设置-" + notesArray[i] + "-点位名称:{},address:{},Val:{}\"" + ", tName, address, Constants.PLC_BOOLEAN_TRUE);");
+                System.out.println("                Thread.sleep(1000);");
+            }else{
+                System.out.println("                result = net.setSensor(address,from.get"+FROM_NAME+"().get" + newCol + "());");
+                System.out.println("                logger.debug(\"设置-" + notesArray[i] + "-点位名称:{},address:{},Val:{}\"" + ", tName, address, from.get"+FROM_NAME+"().get"  + newCol + "());");
+            }
+            System.out.println("            } catch (Throwable e) {");
+            System.out.println("                e.printStackTrace();");
+            System.out.println("            } finally {");
+            System.out.println("                control = true;");
+//            if("Boolean".equals(typeArray[i]) || "boolean".equals(typeArray[i])){
+//                System.out.println("            result = net.setSensor(address,Constants.PLC_BOOLEAN_FALSE);");
+//                System.out.println("            logger.debug(\"回位-" + notesArray[i] + "-点位名称:{},address:{},Val:{}\"" + ", tName, address, Constants.PLC_BOOLEAN_FALSE);");
+//            }
+            System.out.println("            }");
+            System.out.println("        }");
+            System.out.println("        return result;");
+            System.out.println("    }");
+        }
+    }
+    //生成文档中点位表解释
+    public static void createInterpret(String[] colArray,String[] notesArray,String[] accessModes){
+        System.out.println("{");
+        for(int i = 0;i<colArray.length;i++){
+            if ("只写".equals(accessModes[i])){continue;}
+            if (i!=colArray.length-1){
+                System.out.println("\"" + colArray[i] + "\""+":"+"\""+notesArray[i]+"\""+",");
+            }else {
+                System.out.println("\"" + colArray[i] + "\""+":"+"\""+notesArray[i]+"\"");
+
+            }
+        }
+        System.out.println("}");
+    }
+    //生成 文档中控制命令的请求参数表单
+    public static void createReqFormDoc(String[] colArray,String[] notesArray,String[] typeArray,String[] accessModes){
+        System.out.println("|参数名|必选|类型|说明|");
+        System.out.println("|:----    |:---|:----- |-----   |");
+        for(int i = 0;i<colArray.length;i++){
+            if ("只读".equals(accessModes[i])){continue;}
+            System.out.println("|"+colArray[i]+"|否|"+typeArray[i]+"|"+notesArray[i]+"|");
+        }
+    }
+
+
+
+
+    //生成设备接入时控制文档
+//    public static void createControlDoc(){
+//        PLCDevice2Enum.FanMainSgtEnum[] values = PLCDevice2Enum.FanMainSgtEnum.values();
+//        FanMainSgtFacility fanMainSgtFacility = new FanMainSgtFacility();
+//        Class<? extends FanMainSgtFacility> aClass = fanMainSgtFacility.getClass();
+//        Method[] methods = aClass.getMethods();
+//
+//        FanMainSgt fanMainSgt = new FanMainSgt();
+//        Class<? extends FanMainSgt> aClass1 = fanMainSgt.getClass();
+//        Field[] fields = aClass1.getDeclaredFields();
+//
+//        for(Method method:methods){
+//            String name = method.getName();
+//            for(Field field:fields){
+//                if(name.equals(field.getName())){
+//                    String type = field.getType().getSimpleName();
+//                    for(PLCDevice2Enum.FanMainSgtEnum enn:values){
+//                        if(name.equals(enn.getName())){
+//                            String message = PLCDevice2Enum.FanMainSgtEnum.valueOf("FAN_MAIN_SGT_ENUM_"+enn.getName().toUpperCase()).getMessage();
+//                            System.out.println("参数名: "+name+"       类型: "+type+"       说明: "+message);
+//                        }
+//                    }
+//                }
+//            }
+//        }
+//    }
+
+}

+ 38 - 0
src/test/java/com/ventanaly/AppTest.java

@@ -0,0 +1,38 @@
+package com.ventanaly;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}

binární
template/5.0风扇对接代码生成变量模板.xlsx


binární
template/wl1k.xlsx


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů