From eae17d27ec56a6b7887f5597335e38ca40273ef4 Mon Sep 17 00:00:00 2001
From: 廖井涛 <2265517004@qq.com>
Date: 星期一, 04 三月 2024 14:43:47 +0800
Subject: [PATCH] 提交nglib
---
nglib/src/druidConnect/getMeterParatermeter.java | 60
nglib/out/artifacts/nglib_150/nglib.150.jar | 0
nglib/out/production/nglib/nglib.ipr | 197 +
nglib/src/ng/devices/HexUtil.java | 322 ++
nglib/out/production/nglib/.classpath | 9
nglib/src/toTcp/TcpMain.java | 41
nglib/src/ng/devices/ModbusClient.java | 350 ++
nglib/nglib.iml | 48
nglib/.settings/org.eclipse.jdt.core.prefs | 11
nglib/src/toTcp/TcpMultiServer.java | 36
nglib/.idea/misc.xml | 5
nglib/.classpath | 9
nglib/.idea/.gitignore | 8
nglib/bin/META-INF/MANIFEST.MF | 3
nglib/out/production/nglib/nglib.iml | 19
nglib/src/ng/db/NGFunction.java | 79
nglib/out/production/nglib/.project | 17
nglib/src/druidConnect/JDBCUtils.java | 82
nglib/src/ng/Algorithm/Layouts/Piece.java | 15
nglib/.settings/org.eclipse.core.resources.prefs | 5
nglib/out/production/nglib/src/druid.properties | 11
nglib/src/Optimize/OptimizationResult.java | 137 +
nglib/src/Optimize/OptimizeTag.java | 204 +
nglib/src/builder/GetCameraPreviewURL.java | 64
nglib/src/druid.properties | 11
nglib/src/toTcp/gethex.java | 78
nglib/inputLine/Encoding.java | 4
nglib/src/ng/Algorithm/Layouts/LayoutResult.java | 9
nglib/src/builder/MachineManager.java | 148 +
nglib/src/ng/db/toFtp.java | 234 +
nglib/.idea/modules.xml | 8
nglib/.idea/libraries/fastjson_1_2_2.xml | 15
nglib/src/builder/ThreadHttpServer.java | 30
nglib/src/ng/devices/ModbusService.java | 154 +
nglib/src/builder/PaibanManager.java | 31
nglib/src/toTcp/to16HEX.java | 25
nglib/out/artifacts/nglib_150_jar/nglib.jar | 0
nglib/src/Optimize/mn.java | 124 +
nglib/.idea/artifacts/nglib_jar.xml | 17
nglib/bin/druid.properties | 11
nglib/src/builder/HttpHandlerDemo.java | 112
nglib/src/ng/db/aaa.java | 15
nglib/src/toTcp/TCPClient.java | 24
nglib/src/toTcp/TcpClientHandler.java | 114
nglib/src/Optimize/OptimizationInput.java | 214 +
nglib/.idea/artifacts/nglib_150_jar.xml | 18
nglib/src/ng/devices/IoBlock.java | 14
nglib/src/META-INF/MANIFEST.MF | 3
nglib/src/ng/Algorithm/Layouts/AlgorithmDBInterface.java | 423 +++
nglib/.project | 17
nglib/out/production/nglib/.settings/org.eclipse.jdt.core.prefs | 11
nglib/src/Optimize/OptimizationManager.java | 92
nglib/src/ng/db/DBHelper.java | 535 ++++
nglib/src/ng/db/DBSession.java | 361 +++
nglib/src/toTcp/DLT645_2007Control.java | 163 +
nglib/src/ng/Algorithm/Layouts/Rect.java | 84
nglib/src/ng/db/getFtpData.java | 53
nglib/out/production/nglib/src/META-INF/MANIFEST.MF | 3
nglib/src/ng/Algorithm/Layouts/Heuristic.java | 515 ++++
nglib/src/ng/devices/MysqlService.java | 156 +
/dev/null | 102
nglib/out/production/nglib/druid.properties | 11
nglib/out/production/nglib/.settings/org.eclipse.core.resources.prefs | 5
nglib/src/Optimize/NGException.java | 21
nglib/.idea/encodings.xml | 8
nglib/out/production/nglib/META-INF/MANIFEST.MF | 3
nglib/src/ng/Algorithm/Layouts/LayoutAlgorithm.java | 32
nglib/src/builder/Manager.java | 226 +
nglib/out/production/nglib/nglib.iws | 902 +++++++
nglib/src/ng/db/sendOptFile.java | 70
nglib/src/Optimize/OptimizationState.java | 108
71 files changed, 6,944 insertions(+), 102 deletions(-)
diff --git a/gmms/WebContent/WEB-INF/lib/nglib.jar b/gmms/WebContent/WEB-INF/lib/nglib.jar
deleted file mode 100644
index 4d6ba86..0000000
--- a/gmms/WebContent/WEB-INF/lib/nglib.jar
+++ /dev/null
Binary files differ
diff --git a/gmms/WebContent/js/mixins.js b/gmms/WebContent/js/mixins.js
deleted file mode 100644
index dae06b2..0000000
--- a/gmms/WebContent/js/mixins.js
+++ /dev/null
@@ -1,102 +0,0 @@
-
-let str = window.location.href.substr(window.location.href.indexOf('?') + 1)
-let json = new Object()
- const arr = str.split('&')
- for(let i = 0; i < arr.length; i++) {
- let item = arr[i].split('=')
- json[item[0]] = item[1]
-}
-
-var mixin={
- methods:{
- connects:function(gongneng,sql,flag,num){
- let param = new URLSearchParams();
- param.append("gongneng",gongneng);
- param.append("sql",sql);
- param.append("flag",flag);
- param.append("anquanma",json["anquanma"]);
-
- this.$http.post( '../mysqlInsert/mysql.jsp',param)
- .then(function (response) {
- if(num==1){
- result=$(response.data).text();
- index = result.indexOf("[[");
- if(index>-1){
- if(result.indexOf("[[anquanmaerr]]")>-1){
- //alert('璇峰厛鐧诲綍鍚庢搷浣�');
- window.parent.location.href='../login/index.jsp';
- }else{
- result=result.substring(index).trim()
- alert(result);
- window.location.reload();
- }
- }else{
- alert(gongneng+"鎴愬姛锛�")
- window.location.reload();
- }
- }
- })
- .catch(function (error) {
- alert('Error: ' + "鏈嶅姟鍣ㄦ暟鎹彂鐢熼敊璇紒");
- });
-
- },
- loadAjxss:function(gongneng,sql,flag,vals){
- let param = new URLSearchParams();
- param.append("yemian","123");
- param.append("gongneng",gongneng);
- param.append("sql",sql);
- param.append("flag",flag);
- param.append("anquanma",json["anquanma"]);
- this.$http.post( '../mysqlInsert/mysql.jsp',param
- )
- .then(function (response) {
- if(flag==2){
- let result=$(response.data).text();
- let index = result.indexOf("[{");
- if(index>-1){
- result=result.substring(index).trim();
- app.$data[vals]=JSON.parse(result);
- app.$data["loading"]=false;
- console.log(vals+":");
- console.log(app.$data[vals]);
- }else if(result.indexOf("[[anquanmaerr]]")>-1){
- //alert('璇峰厛鐧诲綍鍚庢搷浣�');
- window.parent.location.href='../login/index.jsp';
- }
- }
- })
- .catch(function (error) {
- alert('Error: ' + "鏈嶅姟鍣ㄦ暟鎹彂鐢熼敊璇紒");
- });
- }
- }
-}
-//gongneng:鑷畾涔夛紝sql瀛樺偍杩囩▼锛宖lag鏍囧織(0,鏄敤寮犲伐涔嬪墠鍔熻兘鎻掑叆锛�1瀛樺偍杩囩▼鏌ヨ锛�2瀛樺偍杩囩▼鎻掑叆)锛寁als锛歷ue閲宒ata鍙傛暟
-function loadAjxs(gongneng,sql,flag,vals){
-
-
- $.post("../mysqlInsert/mysql.jsp",
- {"yemian":"123","gongneng":gongneng,"sql":sql,'flag':flag,'anquanma':json["anquanma"]},
- function(result){
- if(flag==2){
- result=$(result).text();
- index = result.indexOf("[{");
- if(index>-1){
- result=result.substring(index).trim();
- app.$data[vals]=JSON.parse(result);
- console.log(vals+":");
- console.log(app.$data[vals]);
- }else if(result.indexOf("[[anquanmaerr]]")>-1){
- //alert('璇峰厛鐧诲綍鍚庢搷浣�');
- window.parent.location.href='../login/index.jsp';
- }
- }
-
- })
- .fail(function(response) {
- alert('Error: ' + "鏈嶅姟鍣ㄦ暟鎹彂鐢熼敊璇紒");
- });
-}
-
-
diff --git a/nglib/.classpath b/nglib/.classpath
new file mode 100644
index 0000000..e4a2f2a
--- /dev/null
+++ b/nglib/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="lib" path="C:/Users/a'a'a/Desktop/Mes椤圭洰/repository/org/json/json/20080701/json-20080701.jar"/>
+ <classpathentry kind="lib" path="D:/zyz/web_optima/GERP/WebContent/WEB-INF/lib/mysql-connector-java-8.0.20.jar"/>
+ <classpathentry kind="lib" path="D:/zyz/web_optima/GERP/WebContent/WEB-INF/lib/jacob.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/nglib/.idea/.gitignore b/nglib/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/nglib/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 榛樿蹇界暐鐨勬枃浠�
+/shelf/
+/workspace.xml
+# 鍩轰簬缂栬緫鍣ㄧ殑 HTTP 瀹㈡埛绔姹�
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/nglib/.idea/artifacts/nglib_150_jar.xml b/nglib/.idea/artifacts/nglib_150_jar.xml
new file mode 100644
index 0000000..5c40cc5
--- /dev/null
+++ b/nglib/.idea/artifacts/nglib_150_jar.xml
@@ -0,0 +1,18 @@
+<component name="ArtifactManager">
+ <artifact type="jar" name="nglib_150_jar">
+ <output-path>$PROJECT_DIR$/out/artifacts/nglib_150_jar</output-path>
+ <root id="archive" name="nglib.jar">
+ <element id="module-output" name="nglib" />
+ <element id="library" level="module" name="jacob.jar" module-name="nglib" />
+ <element id="library" level="module" name="mysql-connector-java-8.0.20.jar" module-name="nglib" />
+ <element id="library" level="module" name="json-20080701.jar" module-name="nglib" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../fastjson-1.2.2.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../commons-net-3.9.0.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../druid-1.1.12.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../jacob-1.18.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../mysql-connector-java-8.0.20.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../json-20230618.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../artemis-http-client-1.1.10.jar" path-in-jar="/" />
+ </root>
+ </artifact>
+</component>
\ No newline at end of file
diff --git a/nglib/.idea/artifacts/nglib_jar.xml b/nglib/.idea/artifacts/nglib_jar.xml
new file mode 100644
index 0000000..781b960
--- /dev/null
+++ b/nglib/.idea/artifacts/nglib_jar.xml
@@ -0,0 +1,17 @@
+<component name="ArtifactManager">
+ <artifact type="jar" name="nglib:jar">
+ <output-path>$PROJECT_DIR$/classes/artifacts/nglib_jar</output-path>
+ <root id="archive" name="nglib.jar">
+ <element id="module-output" name="nglib" />
+ <element id="library" level="module" name="mysql-connector-java-8.0.20.jar" module-name="nglib" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../fastjson-1.2.2.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../commons-net-3.9.0.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../druid-1.1.12.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../jacob-1.18.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../mysql-connector-java-8.0.20.jar" path-in-jar="/" />
+ <element id="library" level="module" name="jacob.jar" module-name="nglib" />
+ <element id="artifact" artifact-name="json-20080701_jar" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../json-20230618.jar" path-in-jar="/" />
+ </root>
+ </artifact>
+</component>
\ No newline at end of file
diff --git a/nglib/.idea/encodings.xml b/nglib/.idea/encodings.xml
new file mode 100644
index 0000000..50077d5
--- /dev/null
+++ b/nglib/.idea/encodings.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Encoding">
+ <file url="file://$PROJECT_DIR$/src/builder/HttpHandlerDemo.java" charset="GBK" />
+ <file url="file://$PROJECT_DIR$/src/builder/MachineManager.java" charset="GBK" />
+ <file url="file://$PROJECT_DIR$/src/builder/Manager.java" charset="GBK" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/nglib/.idea/libraries/fastjson_1_2_2.xml b/nglib/.idea/libraries/fastjson_1_2_2.xml
new file mode 100644
index 0000000..ec7c95a
--- /dev/null
+++ b/nglib/.idea/libraries/fastjson_1_2_2.xml
@@ -0,0 +1,15 @@
+<component name="libraryTable">
+ <library name="fastjson-1.2.2">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../fastjson-1.2.2.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../commons-net-3.9.0.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../druid-1.1.12.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../jacob-1.18.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../mysql-connector-java-8.0.20.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../json-20230618.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../artemis-http-client-1.1.10.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+</component>
\ No newline at end of file
diff --git a/nglib/.idea/misc.xml b/nglib/.idea/misc.xml
new file mode 100644
index 0000000..7b292ac
--- /dev/null
+++ b/nglib/.idea/misc.xml
@@ -0,0 +1,5 @@
+<project version="4">
+ <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$/classes" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/nglib/.idea/modules.xml b/nglib/.idea/modules.xml
new file mode 100644
index 0000000..90cdc05
--- /dev/null
+++ b/nglib/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/nglib.iml" filepath="$PROJECT_DIR$/nglib.iml" />
+ </modules>
+ </component>
+</project>
\ No newline at end of file
diff --git a/nglib/.project b/nglib/.project
new file mode 100644
index 0000000..910cc40
--- /dev/null
+++ b/nglib/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>nglib</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/nglib/.settings/org.eclipse.core.resources.prefs b/nglib/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..59b8320
--- /dev/null
+++ b/nglib/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+encoding//src/ng/db/DBHelper.java=UTF-8
+encoding//src/ng/devices/HexUtil.java=UTF-8
+encoding//src/ng/devices/ModbusClient.java=UTF-8
+encoding//src/ng/devices/ModbusService.java=UTF-8
diff --git a/nglib/.settings/org.eclipse.jdt.core.prefs b/nglib/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/nglib/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/nglib/bin/META-INF/MANIFEST.MF b/nglib/bin/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9c0cd07
--- /dev/null
+++ b/nglib/bin/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: builder.Manager
+
diff --git a/nglib/bin/druid.properties b/nglib/bin/druid.properties
new file mode 100644
index 0000000..faab9b5
--- /dev/null
+++ b/nglib/bin/druid.properties
@@ -0,0 +1,11 @@
+driverClassName=com.mysql.cj.jdbc.Driver
+url=jdbc:mysql://localhost:3306/gmms?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
+username=root
+password=beibo.123/
+
+#初始化时池中建立的物理连接个数
+initialSize=10
+#最大的可活跃的连接池数量
+maxActive=20
+#获取连接时最大等待时间,单位毫秒,超过连接就会失效
+maxWait=3000
\ No newline at end of file
diff --git a/nglib/inputLine/Encoding.java b/nglib/inputLine/Encoding.java
new file mode 100644
index 0000000..feb7b20
--- /dev/null
+++ b/nglib/inputLine/Encoding.java
@@ -0,0 +1,4 @@
+package inputLine;
+
+public class Encoding {
+}
diff --git a/nglib/nglib.iml b/nglib/nglib.iml
new file mode 100644
index 0000000..215b874
--- /dev/null
+++ b/nglib/nglib.iml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="EclipseModuleManager">
+ <libelement value="file://C:/Users/a'a'a/Desktop/Mes椤圭洰/repository/org/json/json/20080701/json-20080701.jar" />
+ <libelement value="file://$MODULE_DIR$/../../zyz/web_optima/GERP/WebContent/WEB-INF/lib/mysql-connector-java-8.0.20.jar" />
+ <libelement value="file://$MODULE_DIR$/../../zyz/web_optima/GERP/WebContent/WEB-INF/lib/jacob.jar" />
+ <src_description expected_position="0">
+ <src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
+ </src_description>
+ </component>
+ <component name="NewModuleRootManager">
+ <output url="file://$MODULE_DIR$/bin" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ </content>
+ <orderEntry type="jdk" jdkName="JavaSE-1.8" jdkType="JavaSDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module-library">
+ <library name="json-20080701.jar">
+ <CLASSES>
+ <root url="file://C:/Users/a'a'a/Desktop/Mes椤圭洰/repository/org/json/json/20080701/json-20080701.jar" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="mysql-connector-java-8.0.20.jar">
+ <CLASSES>
+ <root url="file://$MODULE_DIR$/../../zyz/web_optima/GERP/WebContent/WEB-INF/lib/mysql-connector-java-8.0.20.jar" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="jacob.jar">
+ <CLASSES>
+ <root url="file://$MODULE_DIR$/../../zyz/web_optima/GERP/WebContent/WEB-INF/lib/jacob.jar" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="library" name="fastjson-1.2.2" level="project" />
+ </component>
+</module>
\ No newline at end of file
diff --git a/nglib/out/artifacts/nglib_150/nglib.150.jar b/nglib/out/artifacts/nglib_150/nglib.150.jar
new file mode 100644
index 0000000..f66180c
--- /dev/null
+++ b/nglib/out/artifacts/nglib_150/nglib.150.jar
Binary files differ
diff --git a/nglib/out/artifacts/nglib_150_jar/nglib.jar b/nglib/out/artifacts/nglib_150_jar/nglib.jar
new file mode 100644
index 0000000..38d3813
--- /dev/null
+++ b/nglib/out/artifacts/nglib_150_jar/nglib.jar
Binary files differ
diff --git a/nglib/out/production/nglib/.classpath b/nglib/out/production/nglib/.classpath
new file mode 100644
index 0000000..e4a2f2a
--- /dev/null
+++ b/nglib/out/production/nglib/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="lib" path="C:/Users/a'a'a/Desktop/Mes椤圭洰/repository/org/json/json/20080701/json-20080701.jar"/>
+ <classpathentry kind="lib" path="D:/zyz/web_optima/GERP/WebContent/WEB-INF/lib/mysql-connector-java-8.0.20.jar"/>
+ <classpathentry kind="lib" path="D:/zyz/web_optima/GERP/WebContent/WEB-INF/lib/jacob.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/nglib/out/production/nglib/.project b/nglib/out/production/nglib/.project
new file mode 100644
index 0000000..910cc40
--- /dev/null
+++ b/nglib/out/production/nglib/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>nglib</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/nglib/out/production/nglib/.settings/org.eclipse.core.resources.prefs b/nglib/out/production/nglib/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..59b8320
--- /dev/null
+++ b/nglib/out/production/nglib/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+encoding//src/ng/db/DBHelper.java=UTF-8
+encoding//src/ng/devices/HexUtil.java=UTF-8
+encoding//src/ng/devices/ModbusClient.java=UTF-8
+encoding//src/ng/devices/ModbusService.java=UTF-8
diff --git a/nglib/out/production/nglib/.settings/org.eclipse.jdt.core.prefs b/nglib/out/production/nglib/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/nglib/out/production/nglib/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/nglib/out/production/nglib/META-INF/MANIFEST.MF b/nglib/out/production/nglib/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9c0cd07
--- /dev/null
+++ b/nglib/out/production/nglib/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: builder.Manager
+
diff --git a/nglib/out/production/nglib/druid.properties b/nglib/out/production/nglib/druid.properties
new file mode 100644
index 0000000..faab9b5
--- /dev/null
+++ b/nglib/out/production/nglib/druid.properties
@@ -0,0 +1,11 @@
+driverClassName=com.mysql.cj.jdbc.Driver
+url=jdbc:mysql://localhost:3306/gmms?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
+username=root
+password=beibo.123/
+
+#初始化时池中建立的物理连接个数
+initialSize=10
+#最大的可活跃的连接池数量
+maxActive=20
+#获取连接时最大等待时间,单位毫秒,超过连接就会失效
+maxWait=3000
\ No newline at end of file
diff --git a/nglib/out/production/nglib/nglib.iml b/nglib/out/production/nglib/nglib.iml
new file mode 100644
index 0000000..c3ada42
--- /dev/null
+++ b/nglib/out/production/nglib/nglib.iml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <output url="file://$MODULE_DIR$/out/production/nglib" />
+ <output-test url="file://$MODULE_DIR$/out/test/nglib" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="json-20230618" level="project" />
+ <orderEntry type="library" name="commons-net-3.9.0" level="project" />
+ <orderEntry type="library" name="druid-1.1.12" level="project" />
+ <orderEntry type="library" name="mysql-connector-java-8.0.20" level="project" />
+ <orderEntry type="library" name="fastjson-1.2.2" level="project" />
+ </component>
+</module>
\ No newline at end of file
diff --git a/nglib/out/production/nglib/nglib.ipr b/nglib/out/production/nglib/nglib.ipr
new file mode 100644
index 0000000..d401199
--- /dev/null
+++ b/nglib/out/production/nglib/nglib.ipr
@@ -0,0 +1,197 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ArtifactManager">
+ <artifact type="jar" name="nglib.150:jar">
+ <output-path>$PROJECT_DIR$/out/artifacts/nglib_150_jar</output-path>
+ <root id="archive" name="nglib.jar">
+ <element id="extracted-dir" path="$PROJECT_DIR$/../json-20230618.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../jacob-1.18.jar" path-in-jar="/" />
+ <element id="module-output" name="nglib" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../commons-net-3.9.0.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../druid-1.1.12.jar" path-in-jar="/" />
+ <element id="extracted-dir" path="$PROJECT_DIR$/../fastjson-1.2.2.jar" path-in-jar="/" />
+ </root>
+ </artifact>
+ </component>
+ <component name="Encoding">
+ <file url="file://$PROJECT_DIR$/src/builder/HttpHandlerDemo.java" charset="GBK" />
+ <file url="file://$PROJECT_DIR$/src/builder/ThreadHttpServer.java" charset="GBK" />
+ <file url="file://$PROJECT_DIR$/src/ng/devices/HexUtil.java" charset="UTF-8" />
+ <file url="file://$PROJECT_DIR$/src/ng/devices/ModbusClient.java" charset="GBK" />
+ <file url="file://$PROJECT_DIR$/src/toTcp/TcpClientHandler.java" charset="GBK" />
+ <file url="PROJECT" charset="GBK" />
+ </component>
+ <component name="InspectionProjectProfileManager">
+ <profile version="1.0">
+ <option name="myName" value="Project Default" />
+ </profile>
+ <version value="1.0" />
+ </component>
+ <component name="Palette2">
+ <group name="Swing">
+ <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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>
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/nglib.iml" filepath="$PROJECT_DIR$/nglib.iml" />
+ </modules>
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/out" />
+ </component>
+ <component name="libraryTable">
+ <library name="commons-net-3.9.0">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../../commons-net-3.9.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ <library name="druid-1.1.12">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../druid-1.1.12.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ <library name="fastjson-1.2.2">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../fastjson-1.2.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ <library name="json-20230618">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../json-20230618.jar!/" />
+ <root url="jar://$PROJECT_DIR$/../jacob-1.18.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ <library name="mysql-connector-java-8.0.20">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../mysql-connector-java-8.0.20.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </component>
+</project>
\ No newline at end of file
diff --git a/nglib/out/production/nglib/nglib.iws b/nglib/out/production/nglib/nglib.iws
new file mode 100644
index 0000000..cadb0fb
--- /dev/null
+++ b/nglib/out/production/nglib/nglib.iws
@@ -0,0 +1,902 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ArtifactsWorkspaceSettings">
+ <artifacts-to-build>
+ <artifact name="nglib.150:jar" />
+ </artifacts-to-build>
+ </component>
+ <component name="AutoImportSettings">
+ <option name="autoReloadType" value="SELECTIVE" />
+ </component>
+ <component name="ChangeListManager">
+ <list default="true" id="d34e5e1f-0819-4ff8-9d57-020da84e9134" name="榛樿鏇存敼鍒楄〃" comment="" />
+ <option name="SHOW_DIALOG" value="false" />
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+ <option name="LAST_RESOLUTION" value="IGNORE" />
+ </component>
+ <component name="CoverageViewManager">
+ <option name="myElementSize" value="221" />
+ </component>
+ <component name="DefaultGradleProjectSettings">
+ <option name="isMigrated" value="true" />
+ </component>
+ <component name="FileEditorManager">
+ <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
+ <file pinned="false" current-in-tab="true">
+ <entry file="file://$PROJECT_DIR$/src/ng/db/sendOptFile.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="402">
+ <caret line="66" column="15" selection-start-line="66" selection-start-column="8" selection-end-line="66" selection-end-column="15" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file pinned="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/src/toTcp/TCPClient.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="220">
+ <caret line="12" column="42" selection-start-line="12" selection-start-column="42" selection-end-line="12" selection-end-column="42" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file pinned="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/src/druidConnect/getMeterParatermeter.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="132">
+ <caret line="8" column="8" selection-start-line="8" selection-start-column="8" selection-end-line="8" selection-end-column="54" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </file>
+ </leaf>
+ </component>
+ <component name="FileTemplateManagerImpl">
+ <option name="RECENT_TEMPLATES">
+ <list>
+ <option value="Class" />
+ </list>
+ </option>
+ </component>
+ <component name="FindInProjectRecents">
+ <findStrings>
+ <find>setConnectionParam</find>
+ <find>machineID</find>
+ <find>sn</find>
+ <find>yilianjie</find>
+ <find>mmgr</find>
+ <find>ct</find>
+ <find>rbuff</find>
+ <find>buffer</find>
+ <find>br</find>
+ <find>clientSocket</find>
+ <find>tohex</find>
+ <find>string</find>
+ <find>stringto</find>
+ <find>len</find>
+ <find>arr</find>
+ <find>clientSocket.getOutputStream</find>
+ <find>Sys</find>
+ <find>getOutputStream</find>
+ <find>appStart</find>
+ <find>1111</find>
+ <find>SendFlagMessage</find>
+ <find>System.out.println</find>
+ <find>panban_mgr</find>
+ <find>OI</find>
+ <find>app</find>
+ <find>IO</find>
+ <find>TcpMultiServer</find>
+ <find>APP</find>
+ <find>HEX</find>
+ <find>serverSocket</find>
+ </findStrings>
+ </component>
+ <component name="IdeDocumentHistory">
+ <option name="CHANGED_PATHS">
+ <list>
+ <option value="$PROJECT_DIR$/src/ng/db/uploadImage.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/Manager.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/aaa.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/testa.java" />
+ <option value="$PROJECT_DIR$/src/ng/devices/IoBlock.java" />
+ <option value="$PROJECT_DIR$/src/builder/MachineManager.java" />
+ <option value="$PROJECT_DIR$/src/druid/getDruid.java" />
+ <option value="$PROJECT_DIR$/src/druidConnect/druid.properties" />
+ <option value="$PROJECT_DIR$/src/druidConnect/getDruid.java" />
+ <option value="$PROJECT_DIR$/src/druid.properties" />
+ <option value="$PROJECT_DIR$/src/druidConnect/JDBCUtils.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/getFtpData.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/toFtp.java" />
+ <option value="$PROJECT_DIR$/src/ng/devices/ModbusClient.java" />
+ <option value="$PROJECT_DIR$/inputLine/Encoding.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/TCPClient.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/DLT645_2007Control.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/to16HEX.java" />
+ <option value="$PROJECT_DIR$/src/ng/devices/gethex.java" />
+ <option value="$PROJECT_DIR$/src/druidConnect/test.java" />
+ <option value="$PROJECT_DIR$/src/ng/devices/ModbusService.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/DBHelper.java" />
+ <option value="$PROJECT_DIR$/src/builder/Manager.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/TcpMain.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/TcpMultiServer.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/TcpClientHandler.java" />
+ <option value="$PROJECT_DIR$/src/toTcp/gethex.java" />
+ <option value="$PROJECT_DIR$/src/druidConnect/getMeterParatermeter.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/uploadImages.java" />
+ <option value="$PROJECT_DIR$/src/ng/db/sendOptFile.java" />
+ </list>
+ </option>
+ </component>
+ <component name="ProjectColorInfo">{
+ "associatedIndex": 2
+}</component>
+ <component name="ProjectFrameBounds">
+ <option name="x" value="95" />
+ <option name="y" value="40" />
+ <option name="width" value="1705" />
+ <option name="height" value="980" />
+ </component>
+ <component name="ProjectId" id="2XSiv79QgED9CfzjyA9NJn0bQG0" />
+ <component name="ProjectView">
+ <navigator proportions="" version="1">
+ <foldersAlwaysOnTop value="true" />
+ </navigator>
+ <panes>
+ <pane id="PackagesPane" />
+ <pane id="ProjectPane">
+ <subPane>
+ <expand>
+ <path>
+ <item name="nglib" type="b2602c69:ProjectViewProjectNode" />
+ <item name="nglib" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="nglib" type="b2602c69:ProjectViewProjectNode" />
+ <item name="nglib" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="nglib" type="b2602c69:ProjectViewProjectNode" />
+ <item name="nglib" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="druidConnect" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="nglib" type="b2602c69:ProjectViewProjectNode" />
+ <item name="nglib" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="ng" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="nglib" type="b2602c69:ProjectViewProjectNode" />
+ <item name="nglib" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="ng" type="462c0819:PsiDirectoryNode" />
+ <item name="db" type="462c0819:PsiDirectoryNode" />
+ </path>
+ </expand>
+ <select />
+ </subPane>
+ </pane>
+ <pane id="Scope" />
+ </panes>
+ </component>
+ <component name="ProjectViewState">
+ <option name="hideEmptyMiddlePackages" value="true" />
+ <option name="showLibraryContents" value="true" />
+ </component>
+ <component name="PropertiesComponent"><![CDATA[{
+ "keyToString": {
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "WebServerToolWindowFactoryState": "false",
+ "last_opened_file_path": "D:/Documents/鏂板缓鏂囦欢澶�/fastjson-1.2.2.jar",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "project.structure.last.edited": "宸ヤ欢",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.25632185",
+ "settings.editor.selected.configurable": "preferences.lookFeel",
+ "vue.rearranger.settings.migration": "true"
+ }
+}]]></component>
+ <component name="RecentsManager">
+ <key name="CreateClassDialog.RecentsKey">
+ <recent name="inputLine" />
+ <recent name="ng.db" />
+ </key>
+ <key name="CopyFile.RECENT_KEYS">
+ <recent name="D:\Documents\鏂板缓鏂囦欢澶筡nglib\src\builder" />
+ </key>
+ <key name="MoveFile.RECENT_KEYS">
+ <recent name="D:\Documents\鏂板缓鏂囦欢澶筡nglib\src" />
+ </key>
+ <key name="ExtractSuperBase.RECENT_KEYS">
+ <recent name="toTcp" />
+ </key>
+ </component>
+ <component name="RunManager" selected="搴旂敤绋嬪簭.sendOptFile">
+ <configuration name="TcpMain" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+ <option name="MAIN_CLASS_NAME" value="toTcp.TcpMain" />
+ <module name="nglib" />
+ <extension name="coverage">
+ <pattern>
+ <option name="PATTERN" value="toTcp.*" />
+ <option name="ENABLED" value="true" />
+ </pattern>
+ </extension>
+ <method v="2">
+ <option name="Make" enabled="true" />
+ </method>
+ </configuration>
+ <configuration name="getMeterParatermeter" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+ <option name="MAIN_CLASS_NAME" value="druidConnect.getMeterParatermeter" />
+ <module name="nglib" />
+ <extension name="coverage">
+ <pattern>
+ <option name="PATTERN" value="druidConnect.*" />
+ <option name="ENABLED" value="true" />
+ </pattern>
+ </extension>
+ <method v="2">
+ <option name="Make" enabled="true" />
+ </method>
+ </configuration>
+ <configuration name="gethex" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+ <option name="MAIN_CLASS_NAME" value="toTcp.gethex" />
+ <module name="nglib" />
+ <extension name="coverage">
+ <pattern>
+ <option name="PATTERN" value="toTcp.*" />
+ <option name="ENABLED" value="true" />
+ </pattern>
+ </extension>
+ <method v="2">
+ <option name="Make" enabled="true" />
+ </method>
+ </configuration>
+ <configuration name="sendOptFile" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+ <option name="MAIN_CLASS_NAME" value="ng.db.sendOptFile" />
+ <module name="nglib" />
+ <extension name="coverage">
+ <pattern>
+ <option name="PATTERN" value="ng.db.*" />
+ <option name="ENABLED" value="true" />
+ </pattern>
+ </extension>
+ <method v="2">
+ <option name="Make" enabled="true" />
+ </method>
+ </configuration>
+ <configuration name="uploadImages" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+ <option name="MAIN_CLASS_NAME" value="ng.db.uploadImages" />
+ <module name="nglib" />
+ <extension name="coverage">
+ <pattern>
+ <option name="PATTERN" value="ng.db.*" />
+ <option name="ENABLED" value="true" />
+ </pattern>
+ </extension>
+ <method v="2">
+ <option name="Make" enabled="true" />
+ </method>
+ </configuration>
+ <recent_temporary>
+ <list>
+ <item itemvalue="搴旂敤绋嬪簭.sendOptFile" />
+ </list>
+ </recent_temporary>
+ </component>
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="搴旂敤绋嬪簭绾�" UseSingleDictionary="true" transferred="true" />
+ <component name="SvnConfiguration">
+ <configuration />
+ </component>
+ <component name="TaskManager">
+ <task active="true" id="Default" summary="Default task">
+ <changelist id="d34e5e1f-0819-4ff8-9d57-020da84e9134" name="榛樿鏇存敼鍒楄〃" comment="" />
+ <created>1689674873300</created>
+ <option name="number" value="Default" />
+ <option name="presentableId" value="Default" />
+ <updated>1689674873300</updated>
+ <workItem from="1689674876605" duration="4623000" />
+ <workItem from="1690163563230" duration="2995000" />
+ <workItem from="1690332010977" duration="821000" />
+ <workItem from="1690519172458" duration="642000" />
+ <workItem from="1690965893844" duration="130000" />
+ <workItem from="1690966086810" duration="15269000" />
+ <workItem from="1691026929739" duration="1318000" />
+ <workItem from="1691400653177" duration="5824000" />
+ <workItem from="1692841020354" duration="35464000" />
+ <workItem from="1692944626995" duration="9358000" />
+ <workItem from="1692965394750" duration="4500000" />
+ <workItem from="1693011883051" duration="6525000" />
+ <workItem from="1693216302474" duration="678000" />
+ <workItem from="1693217133236" duration="32430000" />
+ <workItem from="1693803165660" duration="4690000" />
+ <workItem from="1693808154484" duration="8458000" />
+ <workItem from="1694047997151" duration="1060000" />
+ <workItem from="1694132429066" duration="2155000" />
+ <workItem from="1694221622567" duration="18436000" />
+ <workItem from="1694243850779" duration="8381000" />
+ <workItem from="1694391412945" duration="9925000" />
+ <workItem from="1694409182989" duration="43605000" />
+ <workItem from="1694674287131" duration="8685000" />
+ <workItem from="1695010546704" duration="2484000" />
+ <workItem from="1695087660255" duration="7008000" />
+ <workItem from="1696942801180" duration="8000" />
+ <workItem from="1696944767498" duration="70000" />
+ <workItem from="1696944861105" duration="125000" />
+ <workItem from="1696986714219" duration="134000" />
+ <workItem from="1698629111182" duration="528000" />
+ <workItem from="1698630185412" duration="1954000" />
+ <workItem from="1699580908446" duration="954000" />
+ <workItem from="1701416503341" duration="3181000" />
+ <workItem from="1701652652796" duration="4379000" />
+ </task>
+ <servers />
+ </component>
+ <component name="TimeTrackingManager">
+ <option name="totallyTimeSpent" value="235801000" />
+ </component>
+ <component name="ToolWindowManager">
+ <frame x="76" y="32" width="1364" height="784" extended-state="0" />
+ <layout>
+ <window_info id="Image Layers" order="0" />
+ <window_info id="Capture Tool" order="1" />
+ <window_info id="UI Designer" order="2" />
+ <window_info id="Favorites" order="3" side_tool="true" />
+ <window_info id="璁捐鍣�" order="4" />
+ <window_info content_ui="combo" id="Project" order="5" visible="true" weight="0.287902" />
+ <window_info id="Structure" order="6" side_tool="true" weight="0.25" />
+ <window_info anchor="bottom" id="Messages" order="0" weight="0.32956153" />
+ <window_info anchor="bottom" id="Terminal" order="1" weight="0.32956153" />
+ <window_info anchor="bottom" id="Docker" order="2" show_stripe_button="false" />
+ <window_info anchor="bottom" id="Event Log" order="3" sideWeight="0.5020107" side_tool="true" weight="0.35785007" />
+ <window_info anchor="bottom" id="Java Enterprise" order="4" />
+ <window_info anchor="bottom" id="Database Changes" order="5" />
+ <window_info anchor="bottom" id="Version Control" order="6" />
+ <window_info anchor="bottom" id="Message" order="7" />
+ <window_info anchor="bottom" id="Find" order="8" weight="0.32924962" />
+ <window_info anchor="bottom" id="Run" order="9" sideWeight="0.49798927" weight="0.35785007" />
+ <window_info anchor="bottom" id="Debug" order="10" sideWeight="0.49731904" weight="0.3323124" />
+ <window_info anchor="bottom" id="Cvs" order="11" weight="0.25" />
+ <window_info anchor="bottom" id="Inspection" order="12" weight="0.4" />
+ <window_info anchor="bottom" id="TODO" order="13" />
+ <window_info anchor="right" id="Maven" order="0" />
+ <window_info anchor="right" id="Capture Analysis" order="1" />
+ <window_info anchor="right" id="璋冭壊鏉�" order="2" />
+ <window_info anchor="right" id="Database" order="3" />
+ <window_info anchor="right" id="Palette	" order="4" />
+ <window_info anchor="right" id="Theme Preview" order="5" />
+ <window_info anchor="right" id="Commander" internal_type="SLIDING" order="6" type="SLIDING" weight="0.4" />
+ <window_info anchor="right" id="Key Promoter X" order="7" weight="0.3293092" />
+ <window_info anchor="right" id="Ant Build" order="8" weight="0.25" />
+ <window_info anchor="right" content_ui="combo" id="Hierarchy" order="9" weight="0.25" />
+ <window_info anchor="right" id="Coverage" order="10" side_tool="true" weight="0.3297587" />
+ </layout>
+ </component>
+ <component name="TypeScriptGeneratedFilesManager">
+ <option name="version" value="3" />
+ </component>
+ <component name="com.intellij.coverage.CoverageDataManagerImpl">
+ <SUITE FILE_PATH="coverage/nglib$TcpMain.ic" NAME="TcpMain Coverage Results" MODIFIED="1694423588304" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false">
+ <FILTER>toTcp.*</FILTER>
+ </SUITE>
+ <SUITE FILE_PATH="coverage/nglib$uploadImages.ic" NAME="uploadImages Coverage Results" MODIFIED="1692865981231" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false">
+ <FILTER>ng.db.*</FILTER>
+ </SUITE>
+ <SUITE FILE_PATH="coverage/nglib$getFtpData.ic" NAME="getFtpData Coverage Results" MODIFIED="1692866982718" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false">
+ <FILTER>ng.db.*</FILTER>
+ </SUITE>
+ </component>
+ <component name="editorHistoryManager">
+ <entry file="file://$PROJECT_DIR$/src/ng/db/NGFunction.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="-1084">
+ <caret line="6" column="13" selection-start-line="6" selection-start-column="13" selection-end-line="6" selection-end-column="13" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/lang/Object.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="148">
+ <caret line="234" column="18" selection-start-line="234" selection-start-column="18" selection-end-line="234" selection-end-column="18" />
+ <folding>
+ <element signature="e#10065#10066#0" expanded="true" />
+ <element signature="e#10148#10149#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/db/Manager.java" />
+ <entry file="file://$PROJECT_DIR$/src/ng/db/aaa.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="242">
+ <caret line="12" column="9" selection-start-line="12" selection-start-column="9" selection-end-line="12" selection-end-column="9" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://$PROJECT_DIR$/../../commons-net-3.9.0.jar!/org/apache/commons/net/ftp/FTPClient.class">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="226">
+ <caret line="920" column="21" selection-start-line="920" selection-start-column="21" selection-end-line="920" selection-end-column="21" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/util/ArrayList.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="158">
+ <caret line="652" column="18" selection-start-line="652" selection-start-column="18" selection-end-line="652" selection-end-column="18" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/db/testa.java" />
+ <entry file="file://$PROJECT_DIR$/src/ng/db/DBSession.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="198">
+ <caret line="326" column="13" selection-start-line="326" selection-start-column="9" selection-end-line="326" selection-end-column="13" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/sql/DriverManager.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="141">
+ <caret line="235" column="29" selection-start-line="235" selection-start-column="29" selection-end-line="235" selection-end-column="29" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/net/InetAddress.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="207">
+ <caret line="1532" lean-forward="true" selection-start-line="1532" selection-end-line="1532" />
+ <folding>
+ <element signature="e#55662#55663#0" expanded="true" />
+ <element signature="e#55707#55708#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/net/InetSocketAddress.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="265">
+ <caret line="71" column="9" lean-forward="true" selection-start-line="71" selection-start-column="9" selection-end-line="71" selection-end-column="9" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/net/Socket.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="265">
+ <caret line="433" column="29" lean-forward="true" selection-start-line="433" selection-start-column="29" selection-end-line="433" selection-end-column="29" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/lang/Runnable.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="502">
+ <caret line="67" column="26" lean-forward="true" selection-start-line="67" selection-start-column="26" selection-end-line="67" selection-end-column="26" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/util/Properties.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="326">
+ <caret line="340" column="8" selection-start-line="340" selection-start-column="8" selection-end-line="340" selection-end-column="8" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://$PROJECT_DIR$/../druid-1.1.12.jar!/com/alibaba/druid/pool/DruidDataSource.class">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="136">
+ <caret line="819" selection-start-line="819" selection-end-line="819" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://$PROJECT_DIR$/../druid-1.1.12.jar!/com/alibaba/druid/util/JdbcUtils.class">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="226">
+ <caret line="560" column="62" selection-start-line="560" selection-start-column="58" selection-end-line="560" selection-end-column="62" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/io/Reader.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="91">
+ <caret line="77" column="18" selection-start-line="77" selection-start-column="18" selection-end-line="77" selection-end-column="18" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/io/InputStreamReader.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="128">
+ <caret line="96" selection-start-line="96" selection-end-line="96" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/devices/IoBlock.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="181">
+ <caret line="10" column="23" selection-start-line="10" selection-start-column="16" selection-end-line="10" selection-end-column="23" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/lang/Byte.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="163">
+ <caret line="477" column="32" selection-start-line="477" selection-start-column="27" selection-end-line="477" selection-end-column="32" />
+ <folding>
+ <element signature="e#16701#16702#0" expanded="true" />
+ <element signature="e#16740#16741#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/net/SocketInputStream.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="2112">
+ <caret line="126" column="15" selection-start-line="126" selection-start-column="15" selection-end-line="126" selection-end-column="15" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/jre/lib/rt.jar!/java/lang/System.class">
+ <provider selected="true" editor-type-id="text-editor" />
+ </entry>
+ <entry file="file://$PROJECT_DIR$/inputLine/Encoding.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="66">
+ <caret line="3" column="30" selection-start-line="3" selection-start-column="24" selection-end-line="3" selection-end-column="30" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/DLT645_2007Control.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="616">
+ <caret line="69" lean-forward="true" selection-start-line="69" selection-end-line="69" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/to16HEX.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="278">
+ <caret line="21" column="58" selection-start-line="20" selection-start-column="20" selection-end-line="22" selection-end-column="37" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/devices/HexUtil.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="127">
+ <caret line="172" column="36" selection-start-line="172" selection-start-column="25" selection-end-line="172" selection-end-column="36" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/util/Hashtable.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="148">
+ <caret line="360" column="26" selection-start-line="360" selection-start-column="26" selection-end-line="360" selection-end-column="26" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://$PROJECT_DIR$/../mysql-connector-java-8.0.20.jar!/com/mysql/cj/jdbc/exceptions/SQLExceptionsMapping.class">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="148">
+ <caret line="73" selection-start-line="73" selection-end-line="73" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/Algorithm/Layouts/AlgorithmDBInterface.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="39">
+ <caret line="12" column="60" lean-forward="true" selection-start-line="12" selection-start-column="60" selection-end-line="12" selection-end-column="60" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/Algorithm/Layouts/Heuristic.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="88">
+ <caret line="7" column="13" selection-start-line="7" selection-start-column="13" selection-end-line="7" selection-end-column="13" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/druid.properties">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="220">
+ <caret line="10" column="12" lean-forward="true" selection-start-line="10" selection-start-column="12" selection-end-line="10" selection-end-column="12" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/lang/Thread.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="136">
+ <caret line="246" column="44" selection-start-line="246" selection-start-column="44" selection-end-line="246" selection-end-column="44" />
+ <folding>
+ <element signature="e#15465#15466#0" expanded="true" />
+ <element signature="e#15531#15532#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/devices/ModbusClient.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="389">
+ <caret line="339" column="32" selection-start-line="339" selection-start-column="30" selection-end-line="339" selection-end-column="32" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/devices/ModbusService.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="136">
+ <caret line="54" lean-forward="true" selection-start-line="54" selection-end-line="54" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/devices/MysqlService.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="161">
+ <caret line="144" column="17" lean-forward="true" selection-start-line="144" selection-start-column="17" selection-end-line="144" selection-end-column="17" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/db/DBHelper.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="189">
+ <caret line="530" column="34" lean-forward="true" selection-start-line="530" selection-start-column="34" selection-end-line="530" selection-end-column="34" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ <element signature="e#1764#1765#0" expanded="true" />
+ <element signature="e#1794#1795#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/builder/PaibanManager.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="241">
+ <caret line="23" column="17" lean-forward="true" selection-start-line="23" selection-start-column="17" selection-end-line="24" selection-end-column="35" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="jar://C:/Program Files/Java/jdk1.8.0_121/src.zip!/java/net/ServerSocket.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="153">
+ <caret line="126" column="23" selection-start-line="126" selection-start-column="11" selection-end-line="126" selection-end-column="23" />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/TcpMain.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="726">
+ <caret line="34" column="32" selection-start-line="34" selection-start-column="32" selection-end-line="34" selection-end-column="32" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/TcpMultiServer.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="440">
+ <caret line="26" column="39" selection-start-line="26" selection-start-column="39" selection-end-line="26" selection-end-column="39" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/builder/Manager.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="374">
+ <caret line="29" column="42" selection-start-line="29" selection-start-column="42" selection-end-line="29" selection-end-column="42" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/builder/MachineManager.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="550">
+ <caret line="35" column="16" selection-start-line="35" selection-start-column="16" selection-end-line="35" selection-end-column="16" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/TcpClientHandler.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="160">
+ <caret line="66" column="36" selection-start-line="66" selection-start-column="36" selection-end-line="66" selection-end-column="36" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/gethex.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="918">
+ <caret line="69" column="9" selection-start-line="69" selection-start-column="9" selection-end-line="69" selection-end-column="9" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/db/getFtpData.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="703">
+ <caret line="49" column="25" lean-forward="true" selection-start-line="49" selection-start-column="25" selection-end-line="49" selection-end-column="25" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/db/toFtp.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="-1">
+ <caret line="105" lean-forward="true" selection-start-line="105" selection-end-line="105" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ <element signature="method#getFtpClient#0;class#toFtp#0" />
+ <element signature="method#disConnect#0;class#toFtp#0" />
+ <element signature="method#upload#0;class#toFtp#0" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/druidConnect/JDBCUtils.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="-575">
+ <caret line="31" column="7" selection-start-line="31" selection-start-column="7" selection-end-line="31" selection-end-column="7" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/ng/db/sendOptFile.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="402">
+ <caret line="66" column="15" selection-start-line="66" selection-start-column="8" selection-end-line="66" selection-end-column="15" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/toTcp/TCPClient.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="220">
+ <caret line="12" column="42" selection-start-line="12" selection-start-column="42" selection-end-line="12" selection-end-column="42" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/druidConnect/getMeterParatermeter.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="132">
+ <caret line="8" column="8" selection-start-line="8" selection-start-column="8" selection-end-line="8" selection-end-column="54" />
+ <folding>
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </component>
+ <component name="masterDetails">
+ <states>
+ <state key="ArtifactsStructureConfigurable.UI">
+ <settings>
+ <artifact-editor />
+ <last-edited>nglib.150:jar</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ <option value="0.5" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="FacetStructureConfigurable.UI">
+ <settings>
+ <last-edited>No facets are configured</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="GlobalLibrariesConfigurable.UI">
+ <settings>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="JdkListConfigurable.UI">
+ <settings>
+ <last-edited>1.8</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="ModuleStructureConfigurable.UI">
+ <settings>
+ <last-edited>nglib</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="ProjectJDKs.UI">
+ <settings>
+ <last-edited>1.8</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="ProjectLibrariesConfigurable.UI">
+ <settings>
+ <last-edited>mysql-connector-java-8.0.20</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ </states>
+ </component>
+</project>
\ No newline at end of file
diff --git a/nglib/out/production/nglib/src/META-INF/MANIFEST.MF b/nglib/out/production/nglib/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9c0cd07
--- /dev/null
+++ b/nglib/out/production/nglib/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: builder.Manager
+
diff --git a/nglib/out/production/nglib/src/druid.properties b/nglib/out/production/nglib/src/druid.properties
new file mode 100644
index 0000000..faab9b5
--- /dev/null
+++ b/nglib/out/production/nglib/src/druid.properties
@@ -0,0 +1,11 @@
+driverClassName=com.mysql.cj.jdbc.Driver
+url=jdbc:mysql://localhost:3306/gmms?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
+username=root
+password=beibo.123/
+
+#初始化时池中建立的物理连接个数
+initialSize=10
+#最大的可活跃的连接池数量
+maxActive=20
+#获取连接时最大等待时间,单位毫秒,超过连接就会失效
+maxWait=3000
\ No newline at end of file
diff --git a/nglib/src/META-INF/MANIFEST.MF b/nglib/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9c0cd07
--- /dev/null
+++ b/nglib/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: builder.Manager
+
diff --git a/nglib/src/Optimize/NGException.java b/nglib/src/Optimize/NGException.java
new file mode 100644
index 0000000..8920866
--- /dev/null
+++ b/nglib/src/Optimize/NGException.java
@@ -0,0 +1,21 @@
+package Optimize;
+
+public class NGException extends Exception {
+
+ public int ErrorCode;
+ public Object Tag;
+
+ public NGException(String message){
+ super(message);
+ }
+
+ public NGException(String message,Exception e){
+ super(message,e);
+ }
+
+ public NGException(int ErrorCode,String message,Exception e){
+ super(message,e);
+ this.ErrorCode=ErrorCode;
+ }
+
+}
diff --git a/nglib/src/Optimize/OptimizationInput.java b/nglib/src/Optimize/OptimizationInput.java
new file mode 100644
index 0000000..0e6a49d
--- /dev/null
+++ b/nglib/src/Optimize/OptimizationInput.java
@@ -0,0 +1,214 @@
+package Optimize;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class OptimizationInput {
+
+ public Param Param;
+ public Polygon_Info[] Polygons;
+ public Stock_Info[] Stocks;
+ public String GongCheng;
+
+
+ public OptimizationInput(){
+
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject obj=new JSONObject();
+ obj.put("GongCheng",this.GongCheng);
+ obj.put("Param",this.Param.toJson());
+ JSONArray arr=new JSONArray();
+ for(int i=0;i<this.Polygons.length;i++){
+ arr.put(this.Polygons[i].toJson());
+ }
+ obj.put("Polygons", arr);
+ arr=new JSONArray();
+ for(int i=0;i<this.Stocks.length;i++){
+ arr.put(this.Stocks[i].toJson());
+ }
+ obj.put("Stocks", arr);
+ return obj;
+ }
+
+ public OptimizationInput(JSONObject obj) throws JSONException{
+ this.Param=new Param(obj.getJSONObject("Param"));
+ JSONArray arr=obj.getJSONArray("Polygons");
+ this.Polygons=new Polygon_Info[arr.length()];
+ for(int i=0;i<arr.length();i++){
+ this.Polygons[i]=new Polygon_Info(arr.getJSONObject(i));
+ }
+ arr=obj.getJSONArray("Stocks");
+ this.Stocks=new Stock_Info[arr.length()];
+ for(int i=0;i<arr.length();i++){
+ this.Stocks[i]=new Stock_Info( arr.getJSONObject(i));
+ }
+ this.GongCheng=obj.getString("GongCheng");
+ }
+
+
+ public static class Param{
+ public boolean AutoMatch=false;
+ public boolean RotateAble=false;
+ public int MaxRack=0;
+ public double BaiBian=12;
+ public double ZhengGongCha=0;
+ public double FuGongCha=0;
+ public int YuanDianWeiZhi=0;
+ public int XiuBianMode=0;
+ public int TongDaoShu=1;
+ public int YouHuaCiShu=9;
+ public int MobianMinSize=0;
+ public Param(JSONObject obj) throws JSONException{
+ this.AutoMatch=obj.getBoolean("AutoMatch");
+ this.RotateAble=obj.getBoolean("RotateAble");
+ this.MaxRack=obj.getInt("MaxRack");
+ this.BaiBian=obj.getDouble("BaiBian");
+ this.ZhengGongCha=obj.getDouble("ZhengGongCha");
+ this.FuGongCha=obj.getDouble("FuGongCha");
+ this.YuanDianWeiZhi=obj.getInt("YuanDianWeiZhi");
+ this.XiuBianMode=obj.getInt("XiuBianMode");
+ this.TongDaoShu=obj.getInt("TongDaoShu");
+ this.YouHuaCiShu=obj.getInt("YouHuaCiShu");
+ this.MobianMinSize=obj.getInt("MobianMinSize");
+ }
+
+ public Param(){
+
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject ret=new JSONObject();
+ ret.put("AutoMatch", this.AutoMatch);
+ ret.put("RotateAble", this.RotateAble);
+ ret.put("MaxRack", this.MaxRack);
+ ret.put("BaiBian", this.BaiBian);
+ ret.put("ZhengGongCha", this.ZhengGongCha);
+ ret.put("FuGongCha", this.FuGongCha);
+ ret.put("YuanDianWeiZhi", this.YuanDianWeiZhi);
+ ret.put("XiuBianMode", this.XiuBianMode);
+ ret.put("TongDaoShu", this.TongDaoShu);
+ ret.put("YouHuaCiShu", this.YouHuaCiShu);
+ ret.put("MobianMinSize", this.MobianMinSize);
+ return ret;
+ }
+ }
+
+ public static class Polygon_Info{
+ public double width;
+ public double height;
+ public double thickness;
+ public double LM1;
+ public double LM2;
+ public double DM1;
+ public double DM2;
+ public String JiaHao;
+ public String CustomName;
+ public String orderid; //架号+/+层
+ public String xuhao; //序号
+ public int count;
+ public String gongcheng;
+ public int rownumber;
+ public String liuchengka;
+
+ public Polygon_Info(){
+
+ }
+
+ public Polygon_Info(JSONObject obj) throws JSONException{
+ this.width=obj.getDouble("width");
+ this.height=obj.getDouble("height");
+ this.thickness=obj.getDouble("thickness");
+ this.LM1=obj.getDouble("LM1");
+ this.LM2=obj.getDouble("LM2");
+ this.DM1=obj.getDouble("DM1");
+ this.DM2=obj.getDouble("DM2");
+ this.JiaHao=obj.getString("JiaHao");
+ this.CustomName=obj.getString("CustomName");
+ this.orderid=obj.getString("orderid");
+ this.xuhao=obj.getString("xuhao");
+ this.count=obj.getInt("count");
+ this.gongcheng=obj.getString("gongcheng");
+ this.rownumber=obj.getInt("rownumber");
+ this.liuchengka=obj.getString("liuchengka");
+ }
+
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject ret=new JSONObject();
+ ret.put("width", this.width);
+ ret.put("height", this.height);
+ ret.put("thickness", this.thickness);
+ ret.put("LM1", this.LM1);
+ ret.put("LM2", this.LM2);
+ ret.put("DM1", this.DM1);
+ ret.put("DM2", this.DM2);
+ ret.put("JiaHao", this.JiaHao);
+ ret.put("CustomName", this.CustomName);
+ ret.put("orderid", this.orderid);
+ ret.put("xuhao", this.xuhao);
+ ret.put("count", this.count);
+ ret.put("gongcheng", this.gongcheng);
+ ret.put("rownumber", this.rownumber);
+ ret.put("liuchengka", this.liuchengka);
+
+ return ret;
+ }
+
+
+ }
+
+ public static class Stock_Info{
+ public double up;
+ public double down;
+ public double left;
+ public double right;
+ public double width;
+ public double height;
+ public int count;
+ public String libposition;
+ public String Color;
+ public double thickness;
+ public String supplyer;
+ public String wuliao_number;
+ public Stock_Info(JSONObject obj) throws JSONException{
+
+ this.up=obj.getDouble("up");
+ this.down=obj.getDouble("down");
+ this.left=obj.getDouble("left");
+ this.right=obj.getDouble("right");
+ this.width=obj.getDouble("width");
+ this.height=obj.getDouble("height");
+ this.count=obj.getInt("count");
+ this.libposition=obj.getString("libposition");
+ this.Color=obj.getString("Color");
+ this.thickness=obj.getDouble("thickness");
+ this.supplyer=obj.getString("supplyer");
+ this.wuliao_number=obj.getString("wuliao_number");
+ }
+
+ public Stock_Info(){
+
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject ret=new JSONObject();
+ ret.put("up", this.up);
+ ret.put("down", this.down);
+ ret.put("left", this.left);
+ ret.put("right", this.right);
+ ret.put("width", this.width);
+ ret.put("height", this.height);
+ ret.put("count", this.count);
+ ret.put("libposition", this.libposition);
+ ret.put("count", this.count);
+ ret.put("thickness", this.thickness);
+ ret.put("supplyer", this.supplyer);
+ ret.put("wuliao_number", this.wuliao_number);
+
+ return ret;
+ }
+ }
+}
diff --git a/nglib/src/Optimize/OptimizationManager.java b/nglib/src/Optimize/OptimizationManager.java
new file mode 100644
index 0000000..72177a8
--- /dev/null
+++ b/nglib/src/Optimize/OptimizationManager.java
@@ -0,0 +1,92 @@
+package Optimize;
+import java.util.*;
+import java.util.UUID;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.jacob.activeX.ActiveXComponent;
+import com.jacob.com.Dispatch;
+public class OptimizationManager {
+
+
+
+ static List<OptimizeTag> tags=new ArrayList<OptimizeTag>();
+
+
+ public static OptimizeTag createOptimization(String id) throws NGException{
+ OptimizeTag tag=null;
+ synchronized(tags){
+ for(int i=0;i<tags.size();i++){
+ OptimizeTag tg=tags.get(i);
+ if(tg.getId().equals(id)){
+ throw new NGException("优化对象名称已存在");
+ }
+ }
+ tag=OptimizeTag.create(id);
+ tags.add(tag);
+ }
+ return tag;
+ }
+
+ public static OptimizeTag getOrCreateOptimization(String id){
+ OptimizeTag tag=null;
+ synchronized(tags){
+ for(int i=0;i<tags.size();i++){
+ OptimizeTag tag1=tags.get(i);
+ if(tag1.getId().equals(id)){
+ return tag1;
+ }
+ }
+ tag=OptimizeTag.create(id);
+ tags.add(tag);
+ return tag;
+ }
+ }
+
+
+ public static OptimizeTag getTag(String id){
+ synchronized(tags){
+ for(int i=0;i<tags.size();i++){
+ OptimizeTag tag=tags.get(i);
+ if(tag.getId().equals(id)){
+ return tag;
+ }
+ }
+ }
+ return null;
+ }
+
+ //获取所有Tag信息(管理者用)
+ public static JSONArray getAllTagInfo() throws JSONException{
+ JSONArray arr=new JSONArray();
+ synchronized(tags){
+ for(int i=0;i<tags.size();i++){
+ OptimizeTag tag=tags.get(i);
+ arr.put(tag.infoToJson());
+ }
+ }
+ return arr;
+ }
+
+ //删除指定Tag
+ public static void delete(String id){
+ synchronized(tags){
+ for(int i=0;i<tags.size();i++){
+ OptimizeTag tag=tags.get(i);
+ if(tag.getId().equals(id)){
+ tags.remove(tag);
+ }
+ }
+ }
+ }
+
+
+
+ public static String saveOpt(String Gongcheng, String BtContent, String type, String path){
+ OptimizeTag tag=OptimizeTag.create();
+ return tag.saveOpt(Gongcheng,BtContent,type,path);
+ }
+
+}
diff --git a/nglib/src/Optimize/OptimizationResult.java b/nglib/src/Optimize/OptimizationResult.java
new file mode 100644
index 0000000..3da302c
--- /dev/null
+++ b/nglib/src/Optimize/OptimizationResult.java
@@ -0,0 +1,137 @@
+package Optimize;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class OptimizationResult {
+
+ public Boolean Success;
+ public String ErrorMessage;
+ public String btContent;
+ public Layout[] Layouts;
+
+ public OptimizationResult(JSONObject obj) throws JSONException{
+ this.Success=obj.getBoolean("Success");
+ this.ErrorMessage=obj.getString("ErrorMessage");
+ if(obj.has("btContent"))
+ this.btContent=obj.getString("btContent");
+ if(obj.has("Layouts")){
+ JSONArray arr=obj.getJSONArray("Layouts");
+ Layouts=new Layout[arr.length()];
+ for(int i=0;i<Layouts.length;i++){
+ this.Layouts[i]=new Layout(arr.getJSONObject(i));
+ }
+ }
+ }
+
+
+ public JSONObject toJson() throws JSONException {
+ JSONObject obj=new JSONObject();
+ obj.put("Success", this.Success);
+ obj.put("ErrorMessage", this.ErrorMessage);
+
+ obj.put("btContent", this.btContent==null?JSONObject.NULL:this.btContent);
+ if(Layouts==null)
+ obj.put("Layouts",JSONObject.NULL);
+ else{
+ JSONArray ar=new JSONArray();
+ for(int i=0;i<Layouts.length;i++){
+ ar.put(this.Layouts[i].toJson());
+ }
+ obj.put("Layouts",ar);
+ }
+
+ return obj;
+ }
+
+
+
+ public class Layout{
+ public Rect[] rects;
+ public int number;
+ public String wuliao;
+ public int width;
+ public int height;
+ public int SameCount;
+
+ public Layout(JSONObject obj) throws JSONException{
+ this.number=obj.getInt("number");
+ this.wuliao=obj.getString("wuliao");
+ this.width=obj.getInt("width");
+ this.height=obj.getInt("height");
+ this.SameCount=obj.getInt("SameCount");
+ JSONArray arr=obj.getJSONArray("rects");
+ this.rects=new Rect[arr.length()];
+ for(int i=0;i<this.rects.length;i++){
+ this.rects[i]=new Rect(arr.getJSONObject(i));
+ }
+ }
+ public JSONObject toJson() throws JSONException{
+ JSONObject ret=new JSONObject();
+ ret.put("mnumber", number);
+ ret.put("wuliao", this.wuliao);
+ ret.put("width", this.width);
+ ret.put("height",this.height);
+ ret.put("SameCount", this.SameCount);
+ JSONArray arr=new JSONArray();
+ for(int i=0;i<this.rects.length;i++){
+ arr.put(this.rects[i].toJson());
+ }
+ ret.put("rects", arr);
+ return ret;
+ }
+ }
+
+ public class Rect{
+ public double x;
+ public double y;
+ public double w;
+ public double h;
+ public double DM1;
+ public double DM2;
+ public double LM1;
+ public double LM2;
+ public int rownumber;
+ public String xuhao;
+ public boolean isRemain;
+ public String liuchengka;
+ public String JiaHao;
+
+ public Rect(JSONObject obj) throws JSONException{
+ this.x=obj.getDouble("x");
+ this.y=obj.getDouble("y");
+ this.w=obj.getDouble("w");
+ this.h=obj.getDouble("h");
+ this.DM1=obj.getDouble("DM1");
+ this.DM2=obj.getDouble("DM2");
+ this.LM1=obj.getDouble("LM1");
+ this.LM2=obj.getDouble("LM1");
+ this.rownumber=obj.getInt("rownumber");
+ this.xuhao=obj.getString("xuhao");
+ this.isRemain=obj.getBoolean("isRemain");
+ this.liuchengka=obj.getString("liuchengka");
+ this.JiaHao=obj.getString("JiaHao");
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject obj=new JSONObject();
+ obj.put("x", x);
+ obj.put("y", y);
+ obj.put("w", w);
+ obj.put("h", h);
+ obj.put("DM1", DM1);
+ obj.put("DM2", DM2);
+ obj.put("LM1", LM1);
+ obj.put("LM2", LM2);
+ obj.put("rownumber", rownumber);
+ obj.put("xuhao", xuhao);
+ obj.put("isRemain", isRemain);
+ obj.put("liuchengka", liuchengka);
+ obj.put("JiaHao", JiaHao);
+ return obj;
+ }
+ }
+
+
+}
diff --git a/nglib/src/Optimize/OptimizationState.java b/nglib/src/Optimize/OptimizationState.java
new file mode 100644
index 0000000..3c34cda
--- /dev/null
+++ b/nglib/src/Optimize/OptimizationState.java
@@ -0,0 +1,108 @@
+package Optimize;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class OptimizationState {
+ public String State;
+ public TongDaoState[] TongDaoInfos;
+
+ public OptimizationState(JSONObject obj) throws JSONException{
+
+ this.State=obj.getString("State");
+ if(obj.has("TongDaoInfos")){
+ if(obj.isNull("TongDaoInfos")==false){
+ JSONArray arr=obj.getJSONArray("TongDaoInfos");
+ this.TongDaoInfos=new TongDaoState[arr.length()];
+ for(int i=0;i<arr.length();i++){
+ this.TongDaoInfos[i]=new TongDaoState(arr.getJSONObject(i));
+ }
+ }
+ }
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject obj=new JSONObject();
+ obj.put("State",this.State);
+ JSONArray arr=new JSONArray();
+ for(int i=0;i<this.TongDaoInfos.length;i++){
+ arr.put(this.TongDaoInfos[i].toJson());
+ }
+ obj.put("TongDaoInfos", arr);
+ return obj;
+ }
+
+
+
+ public class TongDaoState{
+ public int OptCount;
+ public int value;
+ public int max;
+ public int TotalCount;
+ public UseStock[] UseStocks;
+ public boolean NotEnough;
+
+
+ public TongDaoState(JSONObject obj) throws JSONException{
+ this.OptCount=obj.getInt("OptCount");
+ this.value=obj.getInt("value");
+ this.max=obj.getInt("max");
+ this.TotalCount=obj.getInt("TotalCount");
+ this.NotEnough=obj.getBoolean("NotEnough");
+ if(obj.has("UseStocks")){
+ if(obj.isNull("UseStocks")==false){
+ JSONArray a=obj.getJSONArray("UseStocks");
+ UseStocks=new UseStock[a.length()];
+ for(int i=0;i<this.UseStocks.length;i++){
+ this.UseStocks[i]=new UseStock(a.getJSONObject(i));
+ }
+ }
+ }
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject obj=new JSONObject();
+ obj.put("OptCount",this.OptCount);
+ obj.put("value",this.value);
+ obj.put("max", max);
+ obj.put("TotalCount", this.TotalCount);
+ obj.put("NotEnough", this.NotEnough);
+ JSONArray arr=new JSONArray();
+ if(this.UseStocks!=null){
+ for(int i=0;i<this.UseStocks.length;i++){
+ arr.put(this.UseStocks[i].toJson());
+ }
+ }
+ obj.put("UseStocks",arr);
+ return obj;
+ }
+ }
+
+
+ public class UseStock
+ {
+ public int width;
+ public int height;
+ public int count;
+ public double UseArea;
+
+ public UseStock(JSONObject obj) throws JSONException{
+ this.width=obj.getInt("width");
+ this.height=obj.getInt("height");
+ this.count=obj.getInt("count");
+ this.UseArea=obj.getDouble("UseArea");
+
+ }
+
+ public JSONObject toJson() throws JSONException{
+ JSONObject ret=new JSONObject();
+ ret.put("width", width);
+ ret.put("height", height);
+ ret.put("count",count);
+ ret.put("UseArea", UseArea);
+ return ret;
+ }
+
+ }
+}
diff --git a/nglib/src/Optimize/OptimizeTag.java b/nglib/src/Optimize/OptimizeTag.java
new file mode 100644
index 0000000..d448be9
--- /dev/null
+++ b/nglib/src/Optimize/OptimizeTag.java
@@ -0,0 +1,204 @@
+package Optimize;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.UUID;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.jacob.activeX.ActiveXComponent;
+import com.jacob.com.Dispatch;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import ng.db.*;
+
+ public class OptimizeTag implements Runnable {
+ private String id;
+ private com.jacob.activeX.ActiveXComponent com;
+ private com.jacob.com.Dispatch dispatch;
+ private int running;
+ private java.util.Date date,lastdate;
+ private OptimizationInput input;
+ private java.lang.Thread thread;
+ public String flag;
+ public Object Token;
+ private static Semaphore sem;
+
+ private Dictionary<String,Object> dic=new Hashtable<String,Object>();
+
+
+
+ public Object getProperty(String s){
+ synchronized(dic){
+ return dic.get(s);
+ }
+ }
+
+ public void setProperty(String s,Object obj){
+ synchronized(dic){
+ dic.put(s,obj);
+ }
+ }
+
+
+
+ public OptimizationInput getInput(){
+ return input;
+ }
+
+ public JSONObject infoToJson() throws JSONException{
+ JSONObject obj=new JSONObject();
+ obj.put("id", id);
+ String s="free";
+ if(running==1){
+ s="running";
+ }
+ if(running==2){
+ s="complated";
+ }
+ obj.put("state", s);
+ obj.put("createTime",NGFunction.dateFormat("yyyy-MM-dd HH:mm:ss", date));
+ obj.put("lastTime",NGFunction.dateFormat("yyyy-MM-dd HH:mm:ss",this.lastdate));
+ s="";
+ OptimizationInput in=this.input;
+ if(in!=null){
+ s=in.GongCheng;
+ }
+ obj.put("lastGongCheng", s);
+ return obj;
+ }
+
+ boolean getExe(){
+
+ try {
+ if(sem.tryAcquire(0, TimeUnit.MILLISECONDS)){
+ return true;
+ }
+ return false;
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ public boolean BeginOptimize(OptimizationInput input){
+ if(sem==null){
+ sem=new Semaphore(1);
+ }
+
+ if(running==0 || running==2){
+ if(getExe()){
+ running=1;
+ this.input=input;
+ thread=new Thread(this);
+ thread.start();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String saveOpt(String Gongcheng, String BtContent, String type, String path){
+ this.lastdate=new java.util.Date();
+ return Dispatch.call(this.dispatch,"saveOpt",Gongcheng,BtContent,type,path).toString();
+ }
+
+ public Object[] getResultByBT(String Gongcheng, String BtContent){
+ String s= Dispatch.call(this.dispatch, "btToResult",Gongcheng,BtContent).toString();
+ try {
+ JSONArray obj=new JSONArray(s);
+ JSONObject ob=obj.getJSONObject(1);
+ OptimizationResult a=new OptimizationResult(ob);
+ JSONObject b=obj.getJSONObject(0);
+ JSONArray ar=new JSONArray();
+ Object[] ret=new Object[2];
+ ret[0]=b;
+ ret[1]=a;
+ return ret;
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+ public static OptimizeTag create(){
+ ActiveXComponent dotnetCom = new ActiveXComponent("CLSID:97D686F9-F577-4E41-B5BF-CB8CC5BC73CB");
+ Dispatch myCom = (Dispatch) dotnetCom.getObject();
+ OptimizeTag tag=new OptimizeTag();
+ tag.id=null;
+ tag.com=dotnetCom;
+ tag.dispatch=myCom;
+
+ tag.date=new java.util.Date();
+ tag.lastdate=new java.util.Date();
+ return tag;
+ }
+
+ public static OptimizeTag create(String id){
+ ActiveXComponent dotnetCom = new ActiveXComponent("CLSID:97D686F9-F577-4E41-B5BF-CB8CC5BC73CB");
+ Dispatch myCom = (Dispatch) dotnetCom.getObject();
+ OptimizeTag tag=new OptimizeTag();
+ tag.id=id;
+ tag.com=dotnetCom;
+ tag.dispatch=myCom;
+ tag.date=new java.util.Date();
+ tag.lastdate=new java.util.Date();
+ return tag;
+ }
+ public OptimizationState getState() throws JSONException{
+ this.lastdate=new java.util.Date();
+ String s= Dispatch.call(this.dispatch,"getState").toString();
+ if("null".equals(s))
+ return null;
+
+ JSONObject obj=new JSONObject(s);
+
+ OptimizationState r=new OptimizationState(obj);
+
+ if(this.running==1){
+ r.State="busy";
+ }
+ return r;
+ }
+
+ public OptimizationResult getResult() throws JSONException{
+ this.lastdate=new java.util.Date();
+ if(running!=2)
+ return null;
+ String s= Dispatch.call(this.dispatch,"getResult").toString();
+ if("null".equals(s))
+ return null;
+ JSONObject obj=new JSONObject(s);
+ return new OptimizationResult(obj);
+ }
+
+
+ public String getId(){
+ return this.id;
+ }
+
+ @Override
+ public void run() {
+ this.lastdate=new java.util.Date();
+ this.running=1;
+ // TODO Auto-generated method stub
+ String s;
+ try {
+ Dispatch.call(this.dispatch,"Optima",this.input.toJson().toString()).toString();
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ sem.release();
+ this.running=2;
+ this.thread=null;
+ }
+
+
+}
diff --git a/nglib/src/Optimize/mn.java b/nglib/src/Optimize/mn.java
new file mode 100644
index 0000000..277d661
--- /dev/null
+++ b/nglib/src/Optimize/mn.java
@@ -0,0 +1,124 @@
+package Optimize;
+
+import org.json.JSONException;
+
+import com.jacob.activeX.ActiveXComponent;
+import com.jacob.com.Dispatch;
+import com.jacob.com.Variant;
+
+import Optimize.*;
+import ng.db.DBHelper;
+import ng.db.DBSession;
+import ng.db.NGFunction;
+public class mn {
+
+ public static void _wmain(String[] inputs){
+
+ ActiveXComponent dotnetCom = new ActiveXComponent("Microsoft.PhotoAcquire");
+ Dispatch myCom = (Dispatch) dotnetCom.getObject();
+ //Variant ret= Dispatch.call(myCom, "getState");
+ System.out.println(myCom.toString());
+ }
+
+
+
+
+ public static void main(String[] inputs){
+
+ try {
+
+ OptimizeTag tag = OptimizationManager.createOptimization("abc");
+ tag.setProperty("abc", "hello world");
+ System.out.println(tag.getProperty("abc"));
+ tag.setProperty("abc", "kkkk");
+ System.out.println(tag.getProperty("abc"));
+ OptimizationInput input=new OptimizationInput();
+
+ input.GongCheng="P0001";
+ input.Param=new OptimizationInput.Param();
+ input.Polygons=new OptimizationInput.Polygon_Info[2];
+ OptimizationInput.Polygon_Info p=new OptimizationInput.Polygon_Info();
+ p.count=30;
+ p.CustomName="a";
+ p.DM1=0;
+ p.DM2=0;
+ p.gongcheng="P0001";
+ p.height=800;
+ p.JiaHao="A01";
+ p.liuchengka="NG01";
+ p.LM1=0;
+ p.LM2=0;
+ p.orderid="nnn";
+ p.rownumber=1;
+ p.thickness=6;
+ p.width=1000;
+ p.xuhao="1";
+ input.Polygons[0]=p;
+
+ p=new OptimizationInput.Polygon_Info();
+ p.count=20;
+ p.CustomName="a";
+ p.DM1=0;
+ p.DM2=0;
+ p.gongcheng="P0001";
+ p.height=1800;
+ p.JiaHao="A02";
+ p.liuchengka="NG02";
+ p.LM1=0;
+ p.LM2=0;
+ p.orderid="nnn";
+ p.rownumber=2;
+ p.thickness=6;
+ p.width=1000;
+ p.xuhao="2";
+ input.Polygons[1]=p;
+
+ input.Stocks=new OptimizationInput.Stock_Info[1];
+
+ OptimizationInput.Stock_Info st=new OptimizationInput.Stock_Info();
+ st.Color="c";
+ st.count=1000;
+ st.down=0;
+ st.height=2440;
+ st.left=0;
+ st.libposition="aaa";
+ st.right=0;
+ st.supplyer="aaa";
+ st.thickness=6;
+ st.up=0;
+ st.width=3660;
+ st.wuliao_number="M0001";
+ input.Stocks[0]=st;
+ System.out.println(input.toJson().toString());
+ tag.BeginOptimize(input);
+
+ while(true){
+ java.lang.Thread.sleep(5000);
+ OptimizationState state=tag.getState();
+ if(state==null)
+ continue;
+ System.out.println(state.toJson().toString());
+ if(state.State!="busy"){
+ break;
+ }
+ }
+ OptimizationResult ret=tag.getResult();
+ tag.saveOpt(input.GongCheng,ret.btContent,"OPTIMA","D:\\0001.opt");
+ Object[] o= tag.getResultByBT(input.GongCheng,ret.btContent);
+ System.out.println(o[0].toString());
+ ret=(OptimizationResult)o[1];
+ if(ret!=null)
+ System.out.println(ret.toJson().toString());
+
+ }catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NGException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/nglib/src/builder/GetCameraPreviewURL.java b/nglib/src/builder/GetCameraPreviewURL.java
new file mode 100644
index 0000000..2d280cb
--- /dev/null
+++ b/nglib/src/builder/GetCameraPreviewURL.java
@@ -0,0 +1,64 @@
+package builder;
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
+import com.alibaba.fastjson.JSONObject;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GetCameraPreviewURL {
+ private static final String host = "xxx:4433";
+ private static final String appKey = "xxxx";
+ private static final String appSecret = "xxxxx";
+ public static String GetCameraPreviewURL() {
+
+ /**
+ * STEP1锛氳缃钩鍙板弬鏁帮紝鏍规嵁瀹為檯鎯呭喌,璁剧疆host appkey appsecret 涓変釜鍙傛暟.
+ */
+
+
+
+
+ /**
+ * STEP2锛氳缃甇penAPI鎺ュ彛鐨勪笂涓嬫枃
+ */
+ final String ARTEMIS_PATH = "/artemis";
+
+ /**
+ * STEP3锛氳缃帴鍙g殑URI鍦板潃
+ */
+ final String previewURLsApi = ARTEMIS_PATH + "/api/acs/v1/door/states";
+ Map<String, String> path = new HashMap<String, String>(2) {
+ {
+ put("https://", previewURLsApi);//鏍规嵁鐜板満鐜閮ㄧ讲纭鏄痟ttp杩樻槸https
+ }
+ };
+
+ /**
+ * STEP4锛氳缃弬鏁版彁浜ゆ柟寮�
+ */
+ String contentType = "application/json";
+
+ /**
+ * STEP5锛氱粍瑁呰姹傚弬鏁�
+ */
+ JSONObject jsonBody = new JSONObject();
+ jsonBody.put("doorIndexCodes", "748d84750e3a4a5bbad3cd4af9ed5101");
+ String body = jsonBody.toJSONString();
+ /**
+ * STEP6锛氳皟鐢ㄦ帴鍙�
+ */
+ ArtemisConfig artemisConfig = new ArtemisConfig(host, appKey, appSecret);
+ String result = null;// post璇锋眰application/json绫诲瀷鍙傛暟
+ try {
+ result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path, body, null, null, contentType , null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return result;
+ }
+
+ public static void main(String[] args) {
+ String result = GetCameraPreviewURL();
+ System.out.println("result缁撴灉绀轰緥: " + result);
+ }
+}
diff --git a/nglib/src/builder/HttpHandlerDemo.java b/nglib/src/builder/HttpHandlerDemo.java
new file mode 100644
index 0000000..2c5f029
--- /dev/null
+++ b/nglib/src/builder/HttpHandlerDemo.java
@@ -0,0 +1,112 @@
+package builder;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+
+import com.alibaba.fastjson.JSONArray;
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+
+import com.alibaba.fastjson.JSONObject;
+import ng.db.DBHelper;
+import ng.db.DBSession;
+
+
+
+
+
+public class HttpHandlerDemo implements HttpHandler{
+ DBHelper db;
+
+ @Override
+ public void handle(HttpExchange httpExchange) throws IOException {
+ //请求地址
+ InetSocketAddress inetSocketAddress=httpExchange.getRemoteAddress();
+ //请求方式
+ String requestMethod=httpExchange.getRequestMethod();
+ //url
+ URI url=httpExchange.getRequestURI();
+ if(requestMethod.equalsIgnoreCase("GET")){//客户端的请求是get方法
+ //设置服务端响应的编码格式,否则在客户端收到的可能是乱码
+ Headers responseHeaders = httpExchange.getResponseHeaders();
+ responseHeaders.set("Content-Type", "text/html;charset=utf-8");
+
+ //在这里通过httpExchange获取客户端发送过来的消息
+ //URI url = httpExchange.getRequestURI();
+ //InputStream requestBody = httpExchange.getRequestBody();
+
+ String response = "this is server";
+
+ httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.getBytes("UTF-8").length);
+
+ OutputStream responseBody = httpExchange.getResponseBody();
+ OutputStreamWriter writer = new OutputStreamWriter(responseBody, "UTF-8");
+ writer.write(response);
+ writer.close();
+ responseBody.close();
+ }
+ else {
+ //请求报文
+ InputStream inputStream=httpExchange.getRequestBody();
+ ByteArrayOutputStream bas=new ByteArrayOutputStream();
+ int i;
+ while((i=inputStream.read())!=-1) {
+ bas.write(i);
+ }
+ String requestmsg=bas.toString();
+ JSONObject jsonObject = JSONObject.parseObject(requestmsg);
+
+ String shebei=jsonObject.get("sn").toString();
+
+ JSONArray a=jsonObject.getJSONArray("logs");
+
+ String user_id=a.getJSONObject(0).get("user_id").toString();
+ String times=a.getJSONObject(0).get("recog_time").toString();
+ System.out.println("请求报文:"+shebei+user_id+times);
+
+ DBSession sn=null;
+ DBHelper.addHelper("mes","jdbc:mysql://127.0.0.1:3307/gmms?serverTimezone=GMT%2B8","root","beibo.123/");
+ String result=null;
+
+ try{
+
+ sn=DBHelper.getDBHelper("mes").createSession(false);
+ Connection con= sn.getConnection();
+ CallableStatement sql=con.prepareCall("{call Face_recognition(?,?,?,?)}");
+ sql.registerOutParameter(4, java.sql.Types.VARCHAR);
+ sql.setString(1, shebei);
+ sql.setString(2, user_id);
+ sql.setString(3, times);
+ sql.execute();
+ result= sql.getString(4);
+ System.out.println(result);
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ finally{
+ sn.close();
+
+ }
+
+ //返回报文
+ JSONObject jsonObject1 = new JSONObject();
+ jsonObject1.put("Result", 0);
+ jsonObject1.put("Content", "");
+ jsonObject1.put("Msg", "");
+ httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,jsonObject1.toString().getBytes("UTF-8").length );
+ OutputStream outputStream=httpExchange.getResponseBody();
+ outputStream.write(jsonObject1.toString().getBytes("UTF-8"));
+ outputStream.close();
+ }
+ }
+
+}
diff --git a/nglib/src/builder/MachineManager.java b/nglib/src/builder/MachineManager.java
new file mode 100644
index 0000000..70ab82f
--- /dev/null
+++ b/nglib/src/builder/MachineManager.java
@@ -0,0 +1,148 @@
+package builder;
+import ng.devices.*;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.*;
+
+import ng.db.DBHelper;
+import ng.db.DBSession;
+import ng.devices.*;
+public class MachineManager {
+
+
+
+
+
+
+
+ class item {
+ public DBHelper helper;
+ public MysqlService serv;
+ public int ID;
+ public String IP;
+ public int Port;
+ public int ReadOffset;
+ public int ReadSize;
+ public String ProcName;
+ public String Name;
+ public byte FunctionType;
+
+ }
+ List<item> items=new ArrayList<item>();
+
+ public void RunAll(){
+ for(item it:items){
+ Run(it.Name);
+
+ }
+ }
+
+
+ public void Run(String name){
+ item itm=null;
+ synchronized(items){
+ itm=innerGetItem(name);
+ }
+ if(itm!=null){
+ if(itm.serv==null){
+ itm.serv=new MysqlService(itm.helper,itm.ID);
+ itm.serv.Run(itm.ID,itm.IP,itm.Port, (byte)1,itm.ReadOffset, itm.ReadSize,1000,itm.FunctionType);
+ System.out.println(String.format("设备启动-{%s}(%s)(%s)",itm.Name,itm.IP,itm.FunctionType));
+ }
+ }
+ }
+
+ private item innerGetItem(String name){
+ for(int i=0;i<items.size();i++){
+ if(name==items.get(i).Name)
+ return items.get(i);
+ }
+ return null;
+ }
+
+ public item innerGetItem(int id){
+ for(int i=0;i<items.size();i++){
+ if(id==items.get(i).ID)
+ return items.get(i);
+ }
+ return null;
+ }
+
+
+
+ public void createDevice(DBHelper helper,int DeviceID,String Name,String Ip,int Port,int ReadOffset,int ReadSize,String ProcName,byte FunctionType){
+ synchronized(items){
+
+ item itm=new item();
+ itm.helper=helper; //数据库
+ itm.ProcName=ProcName; //存储过程名
+ itm.Name=Name; //设备名
+ itm.ID=DeviceID; //设备ID
+ itm.IP=Ip; //设备IP
+ itm.Port=Port; //设备端口
+ itm.ReadOffset=ReadOffset; //读取偏移
+ itm.ReadSize=ReadSize;//发送偏移
+ itm.FunctionType=FunctionType;
+ /*if(DeviceID==6 || DeviceID==19 || DeviceID==29 || DeviceID==30){
+ itm.ReadOffset=12000;
+ }*/
+ items.add(itm);
+
+ }
+ }
+
+
+ //将设备信息转化为JSON数组,用于前台显示
+ public JSONArray getContext(){
+ JSONArray arr=new JSONArray();
+ for(int i=0;i<this.items.size();i++){
+ item it=this.items.get(i);
+ JSONObject obj=new JSONObject();
+ try {
+ obj.put("ip", it.IP); //放入IP
+ obj.put("port",it.Port); //放入端口
+ obj.put("name",it.Name); //放入设备名
+ obj.put("id", it.ID); //放入ID
+
+ String send="---";
+ String get="---";
+ if(it.serv!=null){
+ obj.put("count", it.serv.ioCount); //放入读取次数
+ send=it.serv.lastSend;
+ get=it.serv.lastGet;
+ if(send==null)
+ send="---";
+ if(get==null){
+ get="---";
+ }
+ }
+ else{
+ obj.put("count", 0);
+ }
+ obj.put("send", send); //放入最后一次发送信息
+ obj.put("get", get); //放入最后一次读取信息
+ obj.put("dev_state", it.serv.zhangtai);
+ String st="线程未开启";
+ if(it.serv!=null){
+ if(it.serv.isRunning())
+ st="未连接";
+ if(it.serv.isOnLine()){
+ st="已连接";
+ }
+ }
+ obj.put("st",st); //放入线程状态
+ arr.put(obj);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ return arr; //返回结果
+ }
+
+
+}
diff --git a/nglib/src/builder/Manager.java b/nglib/src/builder/Manager.java
new file mode 100644
index 0000000..63687e0
--- /dev/null
+++ b/nglib/src/builder/Manager.java
@@ -0,0 +1,226 @@
+package builder;
+
+import java.io.BufferedWriter;
+import java.io.OutputStreamWriter;
+import java.net.Socket;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.json.JSONArray;
+
+import ng.db.DBHelper;
+import ng.db.DBSession;
+import ng.devices.HexUtil;
+
+public class Manager {
+ //设备管理器
+ static MachineManager mmgr;
+ //优化排版管理器
+ static PaibanManager panban_mgr;
+
+ //初始化各种模块
+ static void init() throws Exception {
+
+ //初始化数据库模块
+ DBHelper.InitHelper();
+ mmgr = new MachineManager();
+ //panban_mgr=new PaibanManager();
+ //panban_mgr.initPainbanManager();
+
+ }
+
+ static void init(String[] con) throws Exception {
+
+ //初始化数据库模块
+
+ DBHelper.addHelper("mes",con[0],con[1],con[2]);
+ mmgr = new MachineManager();
+// panban_mgr=new PaibanManager();
+// panban_mgr.initPainbanManager(con[0],con[1],con[2]);
+
+ }
+
+
+ public static boolean isStart(){
+ return state;
+ }
+
+ //是否已经启动
+ static boolean state = false;
+
+ //Manager启动函数
+ public static void appStart(String[] ss) {
+ if (state == false) {
+ try {
+ //初始化管理器
+ Manager.init(ss);
+ //从数据库配置创建设备
+ Manager.buildDevice();
+ //启动所有设备通讯
+ Manager.mmgr.RunAll();
+ //启动标志
+ state = true;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ //获取所有设备信息生成JSON数组
+ public static JSONArray getDevice(){
+ return mmgr.getContext();
+ }
+
+
+ //从数据库创建所有设备
+ static void buildDevice(){
+
+ DBSession sn=null;
+ try{
+ //读取设备列表
+ DBHelper db=DBHelper.getDBHelper("mes");
+ sn=DBHelper.getDBHelper("mes").createSession(false);
+ sn.createSql("select id,machine_name,ip_address,port,flag,read_size,read_offset,function_type,flag from machine");
+ ResultSet set= sn.query().getCurrentResult();
+ //创建所有设备通讯
+ while(set.next()){
+ int id=(int)set.getLong(1);
+ String name=set.getString(2);
+ String ip=set.getString(3);
+ int port=set.getInt(4);
+ int flag=set.getInt(5);
+ int readSize=set.getInt(6);
+ int readOffset=set.getInt(7);
+ byte functionType=set.getByte(8);
+ int flags=set.getInt(9);
+ if(flags==1){
+ mmgr.createDevice(db,id,name,ip,port,readOffset,readSize,null,functionType);
+ }
+
+ }
+ }
+ catch(Exception e){
+
+ }
+ finally{
+ if(sn!=null)
+ sn.close();
+ }
+ mmgr.RunAll();
+ }
+
+ //异常记录(这里做一次封装是为了可以记录异常,比如记录到日志文件或数据库等)
+ public static void catchException(String sender,Exception e){
+ e.printStackTrace();
+ }
+
+
+ //允许存储过程向框架发送消息实现Mysql回调机制
+ public static void SendMessage(String message){
+ try{
+ char c=message.charAt(0);
+ message=message.substring(1,message.length());
+ //#代表一个功能执行 @仅代表一个消息提醒
+ if(c=='#'){
+ String[] ss=message.split(",");//读取命令参数
+ switch(ss[0]){
+ //参数名为钢化排版(该函数在新MES方案中取消,或者选择性使用,改用提前排版)
+ case "paiban":
+ int line=Integer.parseInt(ss[1]);//线号参数
+ Manager.panban_mgr.Paiban(line);
+ return;
+ default:
+ System.out.println("未知命令消息:"+message);
+ return;
+ }
+ }
+ else{
+ System.out.println("msg:"+message);
+ }
+ }
+ catch(Exception e){
+ catchException("manger.SendFlagMessage",e);
+ }
+ }
+
+ public static void sendtoPLC(int deviceID, int Address, int count, String buffer, int offset) {
+ try {
+ System.out.println(buffer);
+ byte[] bb= HexUtil.stringToInt(buffer);
+ mmgr.innerGetItem(deviceID).serv.SendPLC(Address, count, bb, offset);
+ String ss="";
+ for (int i = 0; i < bb.length; i++) {
+ ss+=ss+bb[i]+",";
+ }
+ System.out.println(ss);
+ }catch (Exception e) {
+ // TODO: handle exception
+ System.out.println(deviceID+"号机器未连接");
+ }
+
+ }
+
+ public static void dayin(int leixing,String peifenhao){
+ try {
+ Socket sk= new Socket("192.168.20.195",9100);
+
+ try {
+ leixing=1;
+ String str1="^Kkuandao\n"+peifenhao+"\ngetElectric\n~p1\n";
+ String str2="~S,BUFCLR\n";
+ String str3="~S,PAUSE\n";
+
+
+ BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(sk.getOutputStream()));
+
+ if(leixing==1){
+ bw.write(str1);
+ bw.newLine();
+ bw.flush();
+ }else{
+ bw.write(str2);
+ bw.newLine();
+ bw.flush();
+ Thread.sleep(100);
+ bw.write(str3);
+ bw.newLine();
+ bw.flush();
+ Thread.sleep(3000);
+ bw.write(str2);
+ bw.newLine(); //写后换行
+ bw.flush(); //表示刷新,也就是立即写给对方
+ }
+
+ sk.close();
+
+
+ } catch (Exception e) {
+ // TODO: handle exception
+ System.out.println("其他");
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ System.out.println("错误");
+ }
+ }
+
+ public static void main(String[] args){
+ //Manager.appStart(new String[]{"jdbc:mysql://10.153.19.150/gmms?serverTimezone=GMT%2B8","root","beibo.123/" });
+ while(true){
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ }
+
+
+}
diff --git a/nglib/src/builder/PaibanManager.java b/nglib/src/builder/PaibanManager.java
new file mode 100644
index 0000000..fb13e40
--- /dev/null
+++ b/nglib/src/builder/PaibanManager.java
@@ -0,0 +1,31 @@
+package builder;
+import java.io.IOException;
+import java.util.Properties;
+
+import ng.Algorithm.Layouts.*;
+import ng.Algorithm.Layouts.AlgorithmDBInterface.ComputeResult;
+import ng.db.NGFunction;
+
+public class PaibanManager {
+
+ //排版软件启动的钢化线配置
+ int[] lines=new int[]{1,2};
+
+ //优化并返回结果
+ public ComputeResult Paiban(int line){
+ return ng.Algorithm.Layouts.AlgorithmDBInterface.ComputeOnce(line);
+ }
+
+ //初始化排版管理器
+ public void initPainbanManager(String url,String user,String password) throws IOException{
+ Properties properties = NGFunction.getProperties();
+ String s= url+"&user="+
+ user+"&password="+
+ password;
+ System.out.println("l:"+s);
+ ng.Algorithm.Layouts.AlgorithmDBInterface.initAlgorithm(s, lines);
+ }
+
+
+
+}
diff --git a/nglib/src/builder/ThreadHttpServer.java b/nglib/src/builder/ThreadHttpServer.java
new file mode 100644
index 0000000..49be5e1
--- /dev/null
+++ b/nglib/src/builder/ThreadHttpServer.java
@@ -0,0 +1,30 @@
+package builder;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import com.sun.net.httpserver.*;
+
+public class ThreadHttpServer {
+ //启动端口8080
+ private static final int port=8880;
+ private static final String Httpcontext="/demo";
+ private static final int nThreads=8;
+ public static void mains() {
+ HttpServer httpServer;
+ try {
+ httpServer=HttpServer.create(new InetSocketAddress(port),0);
+ httpServer.createContext(Httpcontext,new HttpHandlerDemo() );
+// 设置并发数
+ ExecutorService executor=Executors.newFixedThreadPool(nThreads);
+ httpServer.setExecutor(executor);
+ httpServer.start();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/nglib/src/druid.properties b/nglib/src/druid.properties
new file mode 100644
index 0000000..faab9b5
--- /dev/null
+++ b/nglib/src/druid.properties
@@ -0,0 +1,11 @@
+driverClassName=com.mysql.cj.jdbc.Driver
+url=jdbc:mysql://localhost:3306/gmms?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
+username=root
+password=beibo.123/
+
+#初始化时池中建立的物理连接个数
+initialSize=10
+#最大的可活跃的连接池数量
+maxActive=20
+#获取连接时最大等待时间,单位毫秒,超过连接就会失效
+maxWait=3000
\ No newline at end of file
diff --git a/nglib/src/druidConnect/JDBCUtils.java b/nglib/src/druidConnect/JDBCUtils.java
new file mode 100644
index 0000000..72a331c
--- /dev/null
+++ b/nglib/src/druidConnect/JDBCUtils.java
@@ -0,0 +1,82 @@
+package druidConnect;
+
+import com.alibaba.druid.pool.DruidDataSourceFactory;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+public class JDBCUtils{
+ //1.定义成员变量
+ private static DataSource dataSource;
+
+ static {
+
+ try {
+ //1.加载配置文件
+ Properties properties = new Properties();
+ properties.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
+ //System.out.println(properties);
+ //2.获取DataSource
+ dataSource = DruidDataSourceFactory.createDataSource(properties);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ /**
+ * 获取连接
+ */
+ public static Connection getConnection() throws Exception {
+ return dataSource.getConnection();
+ }
+
+ /**
+ * 释放资源
+ */
+ public static void close(Statement stmt, Connection conn){
+ close(null, stmt, conn);
+ }
+ /**
+ * 释放资源
+ */
+ public static void close(ResultSet rs, Statement stmt, Connection conn){
+ if (rs != null){
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ if (stmt != null){
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ if (conn != null){
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 获取连接池
+ */
+ public static DataSource getDataSource(){
+ return dataSource;
+ }
+
+ public static void main(String[] args) throws SQLException {
+ //getDataSource();
+ }
+}
\ No newline at end of file
diff --git a/nglib/src/druidConnect/getMeterParatermeter.java b/nglib/src/druidConnect/getMeterParatermeter.java
new file mode 100644
index 0000000..2fd19fe
--- /dev/null
+++ b/nglib/src/druidConnect/getMeterParatermeter.java
@@ -0,0 +1,60 @@
+package druidConnect;
+
+import java.sql.*;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+
+public class getMeterParatermeter {
+ public static void main(String[] args) throws Exception {
+ LinkedList<LinkedHashMap> a=getMeterParater();
+ System.out.println(a);
+ }
+ public static LinkedList<LinkedHashMap> getMeterParater() throws Exception {
+ Connection con = druidConnect.JDBCUtils.getConnection();
+ CallableStatement cs =con.prepareCall("call AXJ_a_meter_paramenter()");
+ ResultSet rs = cs.executeQuery();
+ ResultSetMetaData rsmd = rs.getMetaData();
+ String[] arr;
+ LinkedList<LinkedHashMap> results = new LinkedList<LinkedHashMap>();
+
+ while(rs.next()){
+ LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
+ for(int i=0;i<rsmd.getColumnCount();i++){
+ String val=rs.getString(i+1)!=null?String.valueOf(rs.getString(i+1)):"";
+ result.put(String.valueOf(rsmd.getColumnName(i+1)),val);
+ }
+ results.add(result);
+ }
+ druidConnect.JDBCUtils.close(cs, con);
+ return results;
+ }
+ public static void meterToMysql(String meterid,Double meter,String DLT645) throws Exception {
+ Connection con = druidConnect.JDBCUtils.getConnection();
+ CallableStatement cs =con.prepareCall("call AXJ_a_addMeter(?,?,?)");
+ cs.setString(1, meterid);
+ cs.setDouble(2, meter);
+ cs.setString(3, DLT645);
+ cs.executeQuery();
+ druidConnect.JDBCUtils.close(cs, con);
+ }
+
+ public static LinkedList<LinkedHashMap> getOrderOpt() throws Exception {
+ Connection con = druidConnect.JDBCUtils.getConnection();
+ CallableStatement cs =con.prepareCall("call AXJ_a_get_orderRecipeOpt_select()");
+ ResultSet rs = cs.executeQuery();
+ ResultSetMetaData rsmd = rs.getMetaData();
+ String[] arr;
+ LinkedList<LinkedHashMap> results = new LinkedList<LinkedHashMap>();
+
+ while(rs.next()){
+ LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
+ for(int i=0;i<rsmd.getColumnCount();i++){
+ String val=rs.getString(i+1)!=null?String.valueOf(rs.getString(i+1)):"";
+ result.put(String.valueOf(rsmd.getColumnName(i+1)),val);
+ }
+ results.add(result);
+ }
+ druidConnect.JDBCUtils.close(cs, con);
+ return results;
+ }
+}
diff --git a/nglib/src/ng/Algorithm/Layouts/AlgorithmDBInterface.java b/nglib/src/ng/Algorithm/Layouts/AlgorithmDBInterface.java
new file mode 100644
index 0000000..9ab28ba
--- /dev/null
+++ b/nglib/src/ng/Algorithm/Layouts/AlgorithmDBInterface.java
@@ -0,0 +1,423 @@
+package ng.Algorithm.Layouts;
+
+
+import java.lang.reflect.Array;
+import java.sql.*;
+import java.util.*;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import ng.Algorithm.Layouts.Heuristic.RowResult;
+import ng.Algorithm.Layouts.LayoutAlgorithm.AlgorithmParams;
+
+public class AlgorithmDBInterface {
+
+ private String connectionString;
+ private int workId;
+ public AlgorithmDBInterface(String connectionString,int WorkId){
+ this.connectionString=connectionString;
+ this.workId=WorkId;
+ param_sql=String.format("SELECT `width`,`length`,`xinterval`,`yinterval` from gmms_furnace where id=%d", WorkId);
+ this.peice_sql=String.format("select id,processcard,position,front,width,height,glass_idx,thickness,color,layout_mode,w,h from tempere_task_glass where work_id=%d", WorkId);
+ }
+
+ private String param_sql;
+ private String peice_sql;
+
+ public int Line;
+
+ public boolean canr=true;
+
+
+ private AlgorithmParams getParam(Connection con) throws SQLException{
+ Statement sm= con.createStatement();
+ ResultSet rs= sm.executeQuery(param_sql);
+ rs.next();
+ AlgorithmParams p=new AlgorithmParams();
+ p.width=rs.getInt(1);
+ p.length=rs.getInt(2);
+ p.h_interval=rs.getInt(3);
+ p.v_interval=rs.getInt(4);
+ p.method="Heuristic";
+ rs.close();
+ sm.close();
+ return p;
+ }
+
+ class Info {
+ public long id;
+ public int thicknss;
+ public String color;
+ public int width;
+ public int height;
+ public Piece.LayoutMode layout_mode;
+ public int FrameNumber;
+ public boolean IsFront;
+ public int GlassIndex;
+ public String Processcard;
+ public int GlassNumber;
+ public double w,h;
+ @Override
+ public String toString(){
+ return String.format("%d.%d[%d]",FrameNumber,GlassNumber,id);
+ }
+
+ }
+
+ compare piececompare=new compare();
+
+
+ class compare implements java.util.Comparator<Piece>{
+
+ @Override
+ public int compare(Piece arg0, Piece arg1) {
+ // TODO Auto-generated method stub
+ Info info1=(Info)arg0.Source;
+ Info info2=(Info)arg1.Source;
+ int a1=info1.IsFront?0:1;
+ int a2=info2.IsFront?0:1;
+ if(a1>a2)
+ return -1;
+ if(a1<a2)
+ return 1;
+ if(info1.GlassIndex<info2.GlassIndex)
+ return 1;
+ if(info1.GlassIndex>info2.GlassIndex)
+ return -1;
+ return 0;
+ }
+
+ }
+
+
+
+ private Info[] toInfo(ResultSet set,boolean canRotate) throws SQLException{
+ List<Info> list=new ArrayList<Info>();
+ while(set.next()){
+ Info info=new Info();
+ info.id=set.getLong("id");
+ info.thicknss= (int)set.getDouble("thickness");
+ info.color=set.getString("color");
+ info.width=(int)set.getDouble("width");
+ info.height=(int)set.getDouble("height");
+ info.Processcard=set.getString("processcard");
+ double w=set.getDouble("w");
+ double h=set.getDouble("h");
+ info.w=w;
+ info.h=h;
+ if(canRotate==true){
+ info.layout_mode=Piece.LayoutMode.Both;
+ }
+ else{
+ info.layout_mode=w<h?Piece.LayoutMode.Zhong:Piece.LayoutMode.Heng;
+ }
+
+ /*
+ int mode=set.getInt("layout_mode");
+ switch(mode){
+ case 1:
+ info.layout_mode= Piece.LayoutMode.Zhong;
+ break;
+ case 2:
+ info.layout_mode=Piece.LayoutMode.Heng;
+ break;
+ default:
+ info.layout_mode=Piece.LayoutMode.Both;
+ break;
+ }
+ */
+ info.FrameNumber=set.getInt("position");
+ info.IsFront=set.getInt("front")==1;
+ info.GlassIndex=set.getInt("glass_idx");
+ list.add(info);
+; }
+ Info[] ret=new Info[list.size()];
+ return list.toArray(ret);
+ }
+
+
+
+ private List<Piece>[] getPiece(Connection con,boolean canRotate) throws SQLException{
+ Statement sm= con.createStatement();
+ ResultSet rs= sm.executeQuery(this.peice_sql);
+ ArrayList<ArrayList<Piece>> pss=new ArrayList<ArrayList<Piece>>();
+ Info[] infos=toInfo(rs,canRotate);
+ if(infos==null)
+ return null;
+ if(infos.length==0)
+ return null;
+ rs.close();
+ sm.close();
+ for(int i=0;i<infos.length;i++){
+ Info cur=infos[i];
+ Piece p=new Piece();
+ p.width=cur.width;
+ p.height=cur.height;
+ p.Mode=cur.layout_mode;
+ p.Source=cur;
+ p.w=cur.w;
+ p.h=cur.h;
+ boolean ok=false;
+ for(int j=0;j<pss.size();j++){
+ Piece pp=pss.get(j).get(0);
+ Info info=(Info)pp.Source;
+ if(info.FrameNumber==cur.FrameNumber){
+ pss.get(j).add(p);
+ ok=true;
+ break;
+ }
+ }
+ if(ok==false){
+ ArrayList<Piece> pl=new ArrayList<Piece>();
+ pl.add(p);
+ pss.add(pl);
+ }
+ }
+ for(int i=0;i<pss.size();i++){
+ pss.get(i).sort(this.piececompare);
+ List<Piece> list=pss.get(i);
+ for(int j=0;j<list.size();j++){
+ Info info= (Info)list.get(j).Source;
+ info.GlassNumber=j+1;
+ }
+ }
+ List<Piece> p=new ArrayList<Piece>();
+ List<Piece>[] ret=(List<Piece>[])Array.newInstance(p.getClass(), pss.size());
+ for(int i=0;i<ret.length;i++){
+ ret[i]=pss.get(i);
+ }
+ return ret;
+ }
+
+
+
+
+
+
+
+ private void saveLayout(Connection con,LayoutResult result,AlgorithmParams param) throws SQLException {
+ int step=0;
+ try {
+ con.setAutoCommit(false);
+ int number=result.Number;
+ step=1;
+ CallableStatement call= con.prepareCall("{call insert_tempere_layout(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
+ boolean ok=true;
+ for(int i=0;i<result.layout.length;i++){
+ Rect r=result.layout[i];
+ Info info=(Info)r.getSource().Source;
+ int move=0;
+ int pendulum=1;
+ if(i==result.layout.length-1){
+ pendulum=3;
+ }
+ else{
+ if(result.layout[i].Row!=result.layout[i+1].Row)
+ pendulum=2;
+ }
+
+
+ if(pendulum!=1){
+ move=param.width-result.layout[i].x;
+ }
+ else{
+ move=result.layout[i+1].x-result.layout[i].x;
+ }
+
+ call.setInt(1,this.workId);
+ call.setInt(2,number);
+ call.setDouble(3,result.rate);
+ call.setInt(4,i+1);
+ call.setInt(5,r.x);
+ call.setInt(6,r.y);
+ if(r.getLength()==r.getWidth()){
+ call.setInt(7,0);
+ }else{
+ call.setInt(7,r.isHeng?0:1);
+ }
+
+ call.setInt(8, pendulum);
+ call.setInt(9,move);
+ call.setInt(10, r.Row);
+ call.setInt(11,r.Col);
+ call.setLong(12,info.id);
+ call.setString(13, null);
+ call.registerOutParameter(14,java.sql.Types.INTEGER);
+ call.execute();
+ if(call.getInt(14)!=1){
+ ok=false;
+ break;
+ }
+
+ }
+ if(ok){
+ con.commit();
+ }
+ else{
+ con.rollback();
+ }
+ con.close();
+
+ } catch (SQLException e) {
+ if(step>=1)
+ con.rollback();
+ con.close();
+
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public LayoutResult lastResult;
+
+ public class ComputeResult{
+ public Exception Error;
+ public boolean Success;
+ public int Number;
+ public boolean isNothing;
+ public LayoutResult Result;
+ public String toJson(){
+
+ try{
+ JSONArray arr=new JSONArray();
+ for(int i=0;i<Result.layout.length;i++){
+ Rect r=Result.layout[i];
+ JSONObject obj=new JSONObject();
+ obj.put("x",r.x);
+ obj.put("y",r.y);
+ obj.put("w",r.getXSize());
+ obj.put("h",r.getYSize());
+ obj.put("size",""+r.getSource().w+"*"+r.getSource().h);
+ int k=0;
+ if(r.canHeng()){
+ k=2;
+ }
+ if(r.canZhong()){
+ k+=1;
+ }
+ obj.put("mode",k);
+ arr.put(obj);
+ }
+ return arr.toString();
+ }
+ catch(Exception e){
+ return "{}";
+ }
+ }
+ }
+
+
+
+ int getNextLayoutNumber(Connection con) throws SQLException{
+ CallableStatement sm= con.prepareCall("{call get_next_tempere_number(?,?)}");
+ sm.setInt(1,this.workId);
+ sm.registerOutParameter(2,java.sql.Types.INTEGER);
+
+ int ret=0;
+ sm.execute();
+ ret=sm.getInt(2);
+ sm.close();
+ return ret;
+ }
+
+
+ public ComputeResult ComputeOnce(boolean canRotate){
+ Connection con=null;
+ lastResult=null;
+ try {
+ con = java.sql.DriverManager.getConnection(this.connectionString);
+ AlgorithmParams param=getParam(con);
+ List<Piece>[] ps=getPiece(con,canRotate);
+ if(ps==null){
+ ComputeResult ret= new ComputeResult();
+ ret.Success=false;
+ ret.Number=0;
+ ret.Error=null;
+ ret.isNothing=true;
+ con.close();
+ return ret;
+ }
+ LayoutResult result= LayoutAlgorithm.Compute(param,ps);
+ int number= getNextLayoutNumber(con);
+ result.WorkId=this.workId;
+ result.Number=number;
+ if(result!=null){
+ this.saveLayout(con, result,param);
+ this.lastResult=result;
+ ComputeResult ret= new ComputeResult();
+ ret.Success=true;
+ ret.Number=number;
+ ret.Error=null;
+ ret.isNothing=false;
+ ret.Result=result;
+ return ret;
+ }
+ ComputeResult ret1= new ComputeResult();
+ ret1.Success=false;
+ ret1.Number=0;
+ ret1.Error=null;
+ ret1.isNothing=true;
+ con.close();
+ return ret1;
+
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ ComputeResult ret= new ComputeResult();
+ ret.Success=false;
+ ret.Number=0;
+ ret.Error=e;
+ ret.isNothing=false;
+ return ret;
+ }
+ finally{
+ try {
+ con.close();
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+
+ }
+ private static AlgorithmDBInterface[] als;
+ public static void initAlgorithm(String connectionString,int[] lines){
+ als=new AlgorithmDBInterface[lines.length];
+ for(int i=0;i<lines.length;i++){
+ als[i]=new AlgorithmDBInterface(connectionString,lines[i]);
+ als[i].Line=lines[i];
+ }
+ }
+
+ public static int getCanRotate(int line){
+ for(int i=0;i<als.length;i++){
+ if(als[i].Line==line)
+ return als[i].canr?1:0;
+ }
+ return -1;
+ }
+
+ public static boolean setCanRotate(int line,boolean rotate){
+ for(int i=0;i<als.length;i++){
+ if(als[i].Line==line){
+ als[i].canr=rotate;
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public static ComputeResult ComputeOnce(int line){
+
+ for(int i=0;i<als.length;i++){
+ if(als[i].Line==line)
+ return als[i].ComputeOnce(als[i].canr);
+ }
+ return null;
+ }
+}
diff --git a/nglib/src/ng/Algorithm/Layouts/Heuristic.java b/nglib/src/ng/Algorithm/Layouts/Heuristic.java
new file mode 100644
index 0000000..53ae748
--- /dev/null
+++ b/nglib/src/ng/Algorithm/Layouts/Heuristic.java
@@ -0,0 +1,515 @@
+package ng.Algorithm.Layouts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import ng.Algorithm.Layouts.LayoutAlgorithm.AlgorithmParams;
+
+public class Heuristic {
+
+ public static class HeuristicParam{
+ public double RowWidthThreshold; //琛屽搴﹀彲鎺ュ彈闃堝��
+ public double RowLayoutThreshold; //琛岃杞藉彲鐜囬槇鍊�
+ public double LayoutLengthThreshold; //鏁翠綋瑁呭湪闀垮害闃堝��
+ public double LayoutRateThreshold; //闈㈡澘瑁呰浇鐜囬槇鍊�
+ }
+
+
+ class Row{
+ int rowIndex;
+ List<RowResult> results=new ArrayList<RowResult>();
+ RowResult root;
+ RowResult best1;
+ //閫掑綊鎼滅储缁撴灉
+ private void seek(RowResult result,RectDataContext dc){
+ int[] anchor=dc.getAnchor();
+ boolean ok=false;
+ for(int i=0;i<dc.groups.length;i++){
+ RectGroup g=dc.groups[i];
+ RectEx rect=g.getCurrent();
+ if(rect==null)
+ continue;
+ boolean a1=result.canPush(rect,false);
+ boolean a2=result.canPush(rect,true);
+ if(a1==false && a2==false){
+ continue;
+ }
+ if(a1==true){
+ RowResult r=result.Clone();
+ r.Push(rect,false);
+ g.next();
+ seek(r,dc);
+ dc.SetAnchor(anchor);
+ ok=true;
+ }
+ if(a2==true){
+ RowResult r=result.Clone();
+ r.Push(rect,true);
+ g.next();
+ seek(r,dc);
+ dc.SetAnchor(anchor);
+ ok=true;
+ }
+
+ }
+ if(ok==false){
+ result.compute();
+ results.add(result);
+ result.anchor=anchor;
+ }
+ }
+
+
+
+ void tryAddRow(List<Row> rrs,Row row){
+ int count=2;
+ if(rrs.size()==0){
+ rrs.add(row);
+ return;
+ }
+ for(int i=0;i<rrs.size();i++){
+ Row r=rrs.get(i);
+ if(r.best1.result_layoutrate<row.best1.result_layoutrate){
+ rrs.add(i,row);
+ break;
+ }
+ }
+ while(rrs.size()>=count){
+ rrs.remove(rrs.size()-1);
+ }
+ }
+
+ public void Compute(RectDataContext dc,AlgorithmParams param,RowResult result,List<RowResult> resultList){
+ if(result.nextRows.size()!=0)
+ return;
+ int rlen=result.getRemainLength(param.length,param.v_interval);
+ dc.SetAnchor(result.anchor);
+ List<Row> rrs=new ArrayList<Row>();
+ for(int i=0;i<dc.groups.length;i++){
+ RectGroup g=dc.groups[i];
+ RectEx rect=g.getCurrent();
+ if(rect==null){
+ continue;
+ }
+
+
+ boolean b1=rect.getLength()<=rlen && rect.getWidth()<=param.width && rect.canZhong();
+ boolean b2=rect.getLength()<=param.width && rect.getWidth()<=rlen && rect.canHeng();
+ if(b1){
+ g.next();
+ Row row=new Row(dc,rect,false,param,result);
+ if(row.best1!=null){
+ this.tryAddRow(rrs, row);
+ }
+ dc.SetAnchor(result.anchor);
+ }
+
+ if(b2){
+ g.next();
+ Row row=new Row(dc,rect,true,param,result);
+ if(row.best1!=null){
+ this.tryAddRow(rrs, row);
+ }
+ dc.SetAnchor(result.anchor);
+ }
+ }
+ if(rrs.size()>0){
+ result.nextRows.addAll(rrs);
+ for(int i=0;i<result.nextRows.size();i++){
+ Row row=result.nextRows.get(i);
+ row.Compute(dc, param,row.best1,resultList);
+ }
+ }
+ else{
+ resultList.add(result);
+ }
+
+
+ }
+
+
+
+ public Row(RectDataContext dc,RectEx first,boolean isheng,AlgorithmParams param,RowResult parent){
+ root=new RowResult(first,isheng,param,parent);
+ this.results.clear();
+ seek(root.Clone(),dc);
+ for(int i=0;i<results.size();i++){
+ results.get(i).compute();
+ }
+ if(results.size()>0){
+ results.sort(root);
+ this.best1=results.get(0);
+ }
+ }
+ }
+
+ class RowResult implements java.util.Comparator<RowResult>{
+ private RowResult parent;
+ private List<Row> nextRows=new ArrayList<Row>();
+ private int[] anchor;
+ private List<RectEx> rects=new ArrayList<RectEx>();
+ private int length;
+ private int remainwidth;
+ private int width;
+ private int interval;
+ private int ystart;
+ private int yend;
+
+
+ int rowIndex;
+
+ public double LayoutRate;
+ public double ComputeLayoutRectArea(){
+ double a=0;
+ RowResult r=this;
+ while(r!=null){
+ for(int i=0;i<r.rects.size();i++){
+ a+=r.rects.get(i).getArea();
+ }
+ r=r.parent;
+ }
+ return a;
+ }
+
+
+
+ public void adjust(){
+ int c=this.rects.size();
+ int size=0;
+ for(int i=0;i<c;i++){
+ size+= this.rects.get(i).getXSize();
+ }
+ if(c>1){
+ int iv=(this.width-size)/(c-1);
+ for(int i=1;i<c;i++){
+ Rect r2=this.rects.get(i);
+ Rect r1=this.rects.get(i-1);
+ r2.x=r1.x+r1.getXSize()+iv;
+ }
+ }
+ else{
+ Rect r1=this.rects.get(0);
+ r1.x=(this.width-r1.getXSize())/2;
+ }
+ }
+
+
+ public RowResult Clone(){
+ RowResult r=new RowResult();
+ r.width=this.width;
+ r.parent=parent;
+ r.anchor=this.anchor;
+ for(int i=0;i<rects.size();i++){
+ r.rects.add(rects.get(i).Clone());
+ }
+ r.length=length;
+ r.remainwidth=this.remainwidth;
+ r.interval=this.interval;
+ r.ystart=this.ystart;
+ r.yend=this.yend;
+ r.rowIndex=this.rowIndex;
+
+ return r;
+ }
+
+
+ public double result_layoutrate;
+ public RowResult(RectEx _first,boolean isheng,AlgorithmParams param,RowResult parent){
+ this.parent=parent;
+ RectEx first=_first.Clone();
+ first.isHeng=isheng;
+ if(this.parent==null){
+ this.rowIndex=1;
+ this.ystart=0;
+
+ this.yend=first.getYSize();
+ }
+ else{
+ this.ystart=this.parent.yend+param.v_interval;
+ this.yend=this.ystart+first.getYSize();
+ this.rowIndex=this.parent.rowIndex+1;
+ }
+ rects.add(first);
+ this.length=first.getYSize();
+ this.width=param.width;
+ this.interval=param.h_interval;
+ this.remainwidth=this.width-interval-first.getXSize();
+ this.yend=this.ystart+first.getYSize();
+ first.x=0;
+ first.y=this.ystart;
+ first.Row=this.rowIndex;
+ first.Col=1;
+ }
+
+
+ private RowResult(){
+
+ }
+
+
+ public void compute(){
+ double a=(this.width+interval)*this.length;
+ double b=0;
+ for(int i=0;i<this.rects.size();i++){
+ RectEx r=this.rects.get(i);
+ b+=(r.getXSize()+interval)*r.getYSize();
+ }
+ this.result_layoutrate=b/a;
+ }
+
+ //璁$畻鎺掔倝鍓╀綑闀垮害
+ public int getRemainLength(int maxlength,int yinterval){
+ int len=0;
+ RowResult r=this;
+ while(r!=null){
+ len+=r.length+yinterval;
+ r=r.parent;
+ }
+ if(len==0)
+ len=maxlength;
+ else
+ len=maxlength-len;
+ return len;
+ }
+
+
+ public boolean canPush(RectEx r,boolean heng){
+ if((heng && r.canHeng()==false) && (heng==false && r.canZhong()==false)){
+ return false;
+ }
+ r.isHeng=heng;
+ if(r.getXSize()>this.remainwidth){
+ return false;
+ }
+ if(r.getYSize()>this.length)
+ return false;
+ return true;
+ }
+
+
+ public void Push(RectEx r,boolean heng){
+ r=r.Clone();
+ r.isHeng=heng;
+
+ this.remainwidth-=r.getXSize()+interval;
+ Rect last=this.rects.get(this.rects.size()-1);
+ r.x=last.x+last.getXSize()+interval;
+ int k=this.ystart+r.getYSize();
+ if(k>this.yend)
+ this.yend=k;
+ r.y=this.ystart;
+ r.Row=this.rowIndex;
+
+ this.rects.add(r);
+ r.Col=this.rects.size();
+ }
+
+
+
+
+
+
+ @Override
+ public int compare(RowResult o1, RowResult o2) {
+ // TODO Auto-generated method stub
+ if(o1.result_layoutrate<o2.result_layoutrate)
+ return 1;
+ if(o1.result_layoutrate>o2.result_layoutrate)
+ return -1;
+ return 0;
+ }
+ }
+
+ class RectEx extends Rect{
+ public int groupNumber;
+ public int pieceIndex;
+ public RectEx(Piece source) {
+ super(source);
+ // TODO Auto-generated constructor stub
+ }
+
+ public RectEx Clone(){
+ RectEx r=new RectEx(this.getSource());
+ this.CopyTo(r);
+ r.groupNumber=this.groupNumber;
+ r.pieceIndex=this.pieceIndex;
+ return r;
+ }
+
+ }
+
+ class RectDataContext{
+ public RectGroup[] groups;
+ public int[] getAnchor(){
+ int[] r=new int[groups.length];
+ for(int i=0;i<r.length;i++){
+ r[i]=groups[i].index;
+ }
+ return r;
+ }
+
+ public void SetAnchor(int[] Anchor){
+ for(int i=0;i<groups.length;i++){
+ groups[i].index=Anchor[i];
+ }
+ }
+
+ public void Reset(){
+ for(int i=0;i<groups.length;i++){
+ groups[i].Reset();
+ }
+ }
+
+ public RectDataContext(List<Piece>[] rects){
+ groups=new RectGroup[rects.length];
+ for(int i=0;i<groups.length;i++){
+ RectGroup rg=new RectGroup();
+ rg.index=0;
+ for(int j=0;j<rects[i].size();j++){
+ Piece r=rects[i].get(j);
+ RectEx rr=new RectEx(r);
+ rr.groupNumber=i+1;
+ rr.pieceIndex=j;
+ rg.rects.add(rr);
+ }
+ groups[i]=rg;
+ }
+ }
+ }
+
+ class RectGroup{
+ private List<RectEx> rects=new ArrayList<RectEx>();
+ private int index;
+
+ public RectEx getCurrent(){
+ if(index<rects.size())
+ return rects.get(index);
+ return null;
+ }
+
+
+
+ public int getCount(){
+ return rects.size()-index;
+ }
+
+ public void next(){
+ if(index<rects.size())
+ index++;
+ }
+
+ public void Reset(){
+ index=0;
+ }
+ }
+
+ AlgorithmParams param;
+ HeuristicParam hparam;
+ RectDataContext dc;
+ List<RowResult> results=new ArrayList<RowResult>();
+
+ //閲嶆柊鍒濆鍖�
+ public void SetParam(AlgorithmParams param){
+ this.param=param;
+ this.hparam=(HeuristicParam)param.methodParam;
+ }
+
+
+ public LayoutResult compute(List<Piece>[] rects){
+ this.dc=new RectDataContext(rects);
+ results.clear();
+ List<Row> rows=new ArrayList<Row>();
+ for(int i=0;i<this.dc.groups.length;i++){
+ RectGroup g=dc.groups[i];
+ RectEx rect=g.getCurrent();
+ if(rect==null)
+ continue;
+ boolean b1=rect.getLength()<=param.length && rect.getWidth()<=param.width && rect.canZhong();
+ boolean b2=rect.getLength()<=param.width && rect.getWidth()<=param.length && rect.canHeng();
+
+ if(b1){
+ g.next();
+ Row row=new Row(dc, rect,false, param, null);
+ rows.add(row);
+ dc.Reset();
+ }
+ if(b2){
+ g.next();
+ Row row=new Row(dc, rect,true, param, null);
+ rows.add(row);
+ dc.Reset();
+ }
+ }
+ for(int i=0;i<rows.size();i++){
+ Row row=rows.get(i);
+ row.Compute(dc, param,row.best1,results);
+
+ }
+ RowResult best=null;
+ double k=param.width*param.length;
+ for(int i=0;i<results.size();i++){
+ RowResult r=results.get(i);
+ double area= r.ComputeLayoutRectArea();
+ r.LayoutRate=area/k;
+ if(best==null)
+ best=r;
+ else
+ {
+ if(best.LayoutRate<r.LayoutRate){
+ best=r;
+ }
+ }
+ }
+ LayoutResult ret= this.getLayoutResult(best);
+ return ret;
+ }
+
+
+ void adjust(RowResult result){
+ RowResult r=result;
+ while(r!=null){
+ r.adjust();
+ r=r.parent;
+ }
+ }
+
+ LayoutResult getLayoutResult(RowResult oneResult){
+ List<Integer> ids=new ArrayList<Integer>();
+ List<RectEx> rects=new ArrayList<RectEx>();
+ RowResult r=oneResult;
+ while(r!=null){
+ for(int i=r.rects.size()-1;i>=0;i--){
+ RectEx re=r.rects.get(i);
+ ids.add(0,re.groupNumber*2+(re.isHeng?1:0));
+ rects.add(0,re);
+ }
+ r=r.parent;
+ }
+ dc.Reset();
+ boolean bug=false;
+ for(int i=0;i<ids.size();i++){
+ int a=ids.get(i);
+ int idx=a/2-1;
+ boolean ish=(idx%2)==1;
+ RectEx rr= dc.groups[idx].getCurrent().Clone();
+ dc.groups[idx].next();
+ rr.isHeng=ish;
+ if(rr.getSource()!=rects.get(i).getSource()){
+ //璇ユ潯浠� 涓嶅彲鑳� 绠楁硶鏈� bug;
+ bug=true;
+ }
+ }
+ if(bug==true){
+ System.out.println("bug");
+ return null;
+ }
+ this.adjust(oneResult);
+ LayoutResult result=new LayoutResult();
+ result.layout=new Rect[rects.size()];
+ rects.toArray(result.layout);
+ result.rate=oneResult.LayoutRate;
+
+ return result;
+ }
+
+}
diff --git a/nglib/src/ng/Algorithm/Layouts/LayoutAlgorithm.java b/nglib/src/ng/Algorithm/Layouts/LayoutAlgorithm.java
new file mode 100644
index 0000000..e96d869
--- /dev/null
+++ b/nglib/src/ng/Algorithm/Layouts/LayoutAlgorithm.java
@@ -0,0 +1,32 @@
+package ng.Algorithm.Layouts;
+import java.sql.Connection;
+import java.util.*;
+public class LayoutAlgorithm {
+ public static class AlgorithmParams{
+ public int width;
+ public int length;
+ public int h_interval;
+ public int v_interval;
+ public String method; //浣跨敤鐨勭畻娉曞悕
+ public Object methodParam; //绠楁硶闇�瑕佺殑鍙傛暟瀵硅薄
+
+ public void Fill(AlgorithmParams data){
+ this.width=data.width;
+ this.length=data.length;
+ this.h_interval=data.h_interval;
+ this.v_interval=data.v_interval;
+
+ }
+ }
+
+
+
+ public static LayoutResult Compute(AlgorithmParams param,List<Piece>[] allglass){
+ if(param.method=="Heuristic"){
+ Heuristic heuristic=new Heuristic();
+ heuristic.SetParam(param);
+ return heuristic.compute(allglass);
+ }
+ return null;
+ }
+}
diff --git a/nglib/src/ng/Algorithm/Layouts/LayoutResult.java b/nglib/src/ng/Algorithm/Layouts/LayoutResult.java
new file mode 100644
index 0000000..1269ecd
--- /dev/null
+++ b/nglib/src/ng/Algorithm/Layouts/LayoutResult.java
@@ -0,0 +1,9 @@
+package ng.Algorithm.Layouts;
+
+import java.util.*;
+public class LayoutResult {
+ public Rect[] layout;
+ public double rate;
+ public int Number;
+ public int WorkId;
+}
diff --git a/nglib/src/ng/Algorithm/Layouts/Piece.java b/nglib/src/ng/Algorithm/Layouts/Piece.java
new file mode 100644
index 0000000..a052d9f
--- /dev/null
+++ b/nglib/src/ng/Algorithm/Layouts/Piece.java
@@ -0,0 +1,15 @@
+package ng.Algorithm.Layouts;
+
+public class Piece {
+ public int width;
+ public int height;
+ public double w;
+ public double h;
+ public Object Source;
+ public LayoutMode Mode;
+ public enum LayoutMode{
+ Heng,
+ Zhong,
+ Both
+ }
+}
diff --git a/nglib/src/ng/Algorithm/Layouts/Rect.java b/nglib/src/ng/Algorithm/Layouts/Rect.java
new file mode 100644
index 0000000..babc9d9
--- /dev/null
+++ b/nglib/src/ng/Algorithm/Layouts/Rect.java
@@ -0,0 +1,84 @@
+package ng.Algorithm.Layouts;
+
+public class Rect {
+ private Piece source;
+ private int width;
+ private int length;
+ private double area;
+ public int x,y;
+ public int Row,Col;
+ public boolean isHeng=false;
+ private Piece.LayoutMode mode;
+ private Rect(){
+
+ }
+
+ public boolean canHeng(){
+ return mode==Piece.LayoutMode.Both || mode== Piece.LayoutMode.Heng;
+ }
+
+
+ public boolean canZhong(){
+ return mode==Piece.LayoutMode.Both || mode== Piece.LayoutMode.Zhong;
+ }
+
+
+
+ public Rect(Piece source){
+ this.width=source.width<=source.height?source.width:source.height;
+ this.length=source.width>=source.height?source.width:source.height;
+ this.area=this.width*this.length;
+ this.mode=source.Mode;
+ this.source=source;
+
+ }
+
+
+ public int getWidth(){
+ return this.width;
+ }
+
+ public int getLength(){
+ return this.length;
+ }
+
+
+
+ public double getArea(){
+ return this.area;
+ }
+
+
+ public int getXSize(){
+ return isHeng?this.length:this.width;
+ }
+
+ public int getYSize(){
+ return isHeng?this.width:this.length;
+ }
+
+
+ public Piece getSource(){
+ return source;
+ }
+
+ protected void CopyTo(Rect r){
+ r.source=this.source;
+ r.width=this.width;
+ r.length=this.length;
+ r.mode=this.mode;
+ r.isHeng=this.isHeng;
+ r.area=this.area;
+ r.Row=this.Row;
+ r.Col=this.Col;
+ r.x=this.x;
+ r.y=this.y;
+ }
+
+
+ public Rect CloneRect(){
+ Rect r=new Rect();
+ CopyTo(r);
+ return r;
+ }
+}
diff --git a/nglib/src/ng/db/DBHelper.java b/nglib/src/ng/db/DBHelper.java
new file mode 100644
index 0000000..fb645ad
--- /dev/null
+++ b/nglib/src/ng/db/DBHelper.java
@@ -0,0 +1,535 @@
+package ng.db;
+import org.json.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.json.*;
+
+
+public class DBHelper{
+
+ private String sqlurl="jdbc:mysql://10.153.19.150/gmms";
+ private String user="root";
+ private String password="beibo.123/";
+ static java.util.Hashtable<String, DBHelper> helper=new java.util.Hashtable<String, DBHelper>();
+
+
+ public static DBSession createDBSession(String sqlurl,String user,String password,boolean manulcomit) throws SQLException{
+ return DBSession.createSession(sqlurl, user, password,manulcomit);
+ }
+
+ public class ProcResult{
+ public int code;
+ public String Message;
+ public JSONArray Datas;
+ }
+
+ public static DBSession createDBSession(String name,boolean manulcomit) throws Exception{
+ if(helper.size()==0){
+ InitHelper();
+ }
+ DBHelper ret= helper.get(name);
+ if(ret!=null)
+ return ret.createSession(manulcomit);
+ throw new Exception("閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷�");
+ }
+
+
+
+
+ public int update(String sql,Object...params) throws SQLException{
+ DBSession sn=null;
+ try{
+ sn= createSession(false);
+ sn.createSql(sql);
+ return sn._update(params);
+ }
+ finally{
+ sn.close();
+ }
+ }
+
+
+ public JSONArray query(boolean asObject,String sql,Object...params) throws SQLException, JSONException{
+ DBSession sn=null;
+ try{
+ sn= createSession(false);
+ sn.createSql(sql);
+ return sn._query(params).resultToJson(asObject);
+ }
+ finally{
+ sn.close();
+ }
+ }
+
+
+
+
+
+
+ public static DBHelper getDBHelper(String name){
+ return helper.get(name);
+ }
+
+
+ public static void addHelper(String name,String url,String user,String pass){
+
+ DBHelper help=new DBHelper(url,user,pass);
+ helper.put("mes",help);
+ }
+
+
+
+ public static void InitHelper() throws Exception{
+
+
+ Properties properties = NGFunction.getProperties();
+ Class.forName(properties.getProperty("driver"));
+ String data= properties.getProperty("connection");
+ if(data==null)
+ {
+ throw new Exception("鏈敓鎻鎷烽敓鏂ゆ嫹閿熸枻鎷�");
+ }
+ System.out.println(data);
+ String[] names=data.split(",");
+ for(int i=0;i<names.length;i++){
+ DBHelper help=new DBHelper(properties.getProperty(names[i]+".url"),
+ properties.getProperty(names[i]+".user"),
+ properties.getProperty(names[i]+".password")
+ );
+ helper.put(names[i],help);
+ System.out.println("create "+names[i]);
+ }
+
+ }
+
+
+
+
+ public static void updateConnection(String name) throws Exception{
+ Properties properties = NGFunction.getProperties();
+ DBHelper ret= helper.get(name);
+ if(ret==null){
+ throw new Exception("閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷�");
+ }
+ ret.sqlurl=properties.getProperty(name+".url");
+ ret.user=properties.getProperty(name+".user");
+ ret.password=properties.getProperty(name+".password");
+ }
+
+
+
+
+
+
+ public JSONArray query(String sql,Boolean RowAsObject,Object...params) throws SQLException, JSONException{
+ DBSession sn=null;
+ try{
+ sn=this.createSession(false);
+ sn.createSql(sql);
+ return sn.query(params).resultToJson(RowAsObject);
+
+ }
+ finally{
+ if(sn!=null)
+ sn.close();
+ }
+ }
+
+ public int update(String sql,Boolean RowAsObject,Object...params) throws SQLException{
+ DBSession sn=null;
+ try{
+ sn=this.createSession(false);
+ sn.createSql(sql);
+ return sn.update(params);
+
+
+ }
+ finally{
+ if(sn!=null)
+ sn.close();
+ }
+ }
+
+
+
+ public void init(String sqlurl,String user,String password){
+ this.sqlurl=sqlurl;
+ this.user=user;
+ this.password=password;
+ }
+
+
+ private static boolean odbc_regist=false;
+
+
+
+
+
+ //閿熸枻鎷烽敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹in閿熸枻鎷烽敓鏂ゆ嫹 閿熸枻鎷烽敓鏂ゆ嫹out閿熸枻鎷烽敓鏂ゆ嫹閿熶茎瀛樺偍閿熸枻鎷烽敓鏁欙綇鎷蜂竴閿熸枻鎷烽敓琛楄鎷烽敓鏂ゆ嫹int 1閿熸枻鎷烽敓鏂ゆ嫹鏅掗敓锟� 涓�閿熸枻鎷烽敓鏂ゆ嫹String閿熸枻鎷蜂负涓�閿熸枻鎷烽敓鎴潻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓缁炑嶆嫹閿熺粸鎲嬫嫹閿熻娇顏庢嫹閿熺粸鎾呮嫹閿熻緝顫嫹閿燂拷
+ public QueryResult SelectByProc(String name,String[] Params){
+ Connection con=null;
+ try{
+ int length=Params.length;
+
+ String s=String.format("{call %s(",name);
+ for(int i=0;i<=length;i++){
+ if(i==0)
+ s+="?";
+ else
+ s+=",?";
+ }
+ s+=")}";
+
+ con=DriverManager.getConnection(sqlurl,user,password);
+ CallableStatement c=con.prepareCall(s);
+ for(int i=0;i<length;i++){
+ c.setString(i+1,Params[i]);
+ }
+ c.registerOutParameter(length+1, java.sql.Types.VARCHAR);
+ ResultSet result= c.executeQuery();
+ String rest=c.getString(length+1);
+ QueryResult r=new QueryResult(con,c,result);
+ if(rest!=null){
+ if(rest.equals("success")){
+ return r;
+ }
+ }
+ r.Close();
+ return null;
+
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ if(con!=null)
+ try {
+ con.close();
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ return null;
+ }
+ }
+
+ //閿熸枻鎷烽敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹in閿熸枻鎷烽敓鏂ゆ嫹 涓�閿熸枻鎷穙ut閿熸枻鎷烽敓鏂ゆ嫹閿熶茎瀛樺偍閿熸枻鎷烽敓鏂ゆ嫹
+ public String InvokeSqlProc(String name,String[] Params){
+ Connection con=null;
+ try{
+ int length=Params.length;
+
+ String s=String.format("{call %s(",name);
+ for(int i=0;i<=length;i++){
+ if(i==0)
+ s+="?";
+ else
+ s+=",?";
+ }
+ s+=")}";
+
+ con=DriverManager.getConnection(sqlurl,user,password);
+ CallableStatement c=con.prepareCall(s);
+ for(int i=0;i<length;i++){
+ c.setString(i+1,Params[i]);
+ }
+ c.registerOutParameter(length+1, java.sql.Types.VARCHAR);
+ c.execute();
+ String message=c.getString(length+1);
+ c.close();
+ con.close();
+ return message;
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ if(con!=null)
+ try {
+ con.close();
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ return "fail";
+ }
+ }
+
+
+ //閿熸枻鎷烽敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹in閿熸枻鎷烽敓鏂ゆ嫹 涓�閿熸枻鎷穙ut閿熸枻鎷烽敓鏂ゆ嫹閿熶茎瀛樺偍閿熸枻鎷烽敓鏂ゆ嫹
+ public String InvokeSqlProc(String name,String param1,String param2){
+ Connection con=null;
+ try{
+ con=DriverManager.getConnection(sqlurl,user,password);
+ CallableStatement c=con.prepareCall(String.format("{call %s(?,?,?)}",name));
+ c.setString(1,param1);
+ c.setString(2,param2);
+
+ c.registerOutParameter(3, java.sql.Types.VARCHAR);
+ System.out.println("ok");
+ c.execute();
+ System.out.println("ok1");
+ String message=c.getString(3);
+ c.close();
+ con.close();
+ return message;
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ if(con!=null)
+ try {
+ con.close();
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ return "fail";
+ }
+
+ }
+
+ //閿熸枻鎷烽敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹
+ public Connection getConnection() throws SQLException{
+
+ return DriverManager.getConnection(sqlurl,user,password);
+ //return DriverManager.getConnection(sqlurl,user,password);
+ }
+
+
+
+ //閿熸枻鎷烽敓鏂ゆ嫹閿熸嵎鍖℃嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鎻紮鎷烽敓鏂ゆ嫹渚勯敓鏂ゆ嫹閿熻娇顎︾枻鈺痚lect 閿熸枻鎷烽�夐敓鏂ゆ嫹
+ public String MakeSelectOptionBySql(String sql,String field){
+ QueryResult query=null;
+ try{
+ query=new QueryResult(sqlurl,user,password,sql);
+ ResultSet result=query.Result;
+ StringBuilder sb=new StringBuilder();
+ while(result.next()){
+ Object o=result.getObject(field);
+ if(o!=null)
+ sb.append(String.format("<option value=\"%s\">%s</option>\r\n",o.toString(),o.toString()));
+ }
+ query.Close();
+ return sb.toString();
+ }
+ catch(Exception e){
+ if(query!=null)
+ query.Close();
+ return null;
+ }
+ }
+
+ //閫氶敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷峰彇閿熸枻鎷烽敓鎹风》鎷烽敓鏂ゆ嫹閿燂拷
+ public QueryResult getQueryResult(String sql){
+ QueryResult query=null;
+ try{
+ query=new QueryResult(sqlurl,user,password,sql);
+ return query;
+ }
+ catch(Exception e){
+ if(query!=null)
+ query.Close();
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+
+ //閿熸枻鎷烽敓鏂ゆ嫹閿熸嵎鍖℃嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸彮浼欐嫹閿熻鐤ゎ煉鎷疯皨閿熸枻鎷穞body閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鎹凤綇鎷稰KName閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓琛楁锝忔嫹ShowField閿熸枻鎷疯閿熸枻鎷风ず閿熸枻鎷烽敓鏂ゆ嫹 閿熸枻鎷烽敓鏂ゆ嫹#閿熸枻鎷峰ご閿熸枻鎷烽敓琛楀嚖鎷烽敓鏂ゆ嫹鐩撮敓鏂ゆ嫹閿熸枻鎷蜂负t閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹
+ public String MakeHTMLTableRowsBySql(String sql,String PKName,String[] ShowField) throws SQLException{
+ QueryResult query=null;
+ try{
+ query=new QueryResult(sqlurl,user,password,sql);
+ ResultSet result=query.Result;
+ StringBuilder sb=new StringBuilder();
+ int[] fieldIndex=new int[ShowField.length];
+ for(int i=0;i<ShowField.length;i++){
+ if(ShowField[i].charAt(0)=='#'){
+ fieldIndex[i]=-100;
+ ShowField[i]=ShowField[i].substring(1);
+ }
+ else
+ fieldIndex[i]=result.findColumn(ShowField[i]);
+ }
+ //sb.append("<tbody>\r\n");
+ while(result.next()){
+ if(PKName!=null){
+ sb.append(String.format("<tr data-id=\"%s\">\r\n",result.getObject(PKName).toString().trim()));
+ }
+ else
+ sb.append("<tr>\r\n");
+ for(int i=0;i<fieldIndex.length;i++){
+ sb.append("<td>");
+ int idx=fieldIndex[i];
+ if(idx==-100){
+ sb.append(ShowField[i]);
+ }
+ else{
+
+ Object o=result.getObject(idx);
+ if(o!=null)
+ sb.append(o);
+ }
+ sb.append("</td>");
+ }
+ sb.append("</tr>\r\n");
+ }
+ //sb.append("</tbody>\r\n");
+ query.Close();
+ return sb.toString();
+ }
+ catch(Exception e){
+ if(query!=null)
+ query.Close();
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public DBHelper(String sqlurl,String user,String password){
+ this.sqlurl=sqlurl;
+ this.user=user;
+ this.password=password;
+ }
+
+ //涓�閿熸枻鎷烽敓娲ュ崟鐨勮鎷疯閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷峰獟閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹涓�浜涢敓鏂ゆ嫹璇㈤敓鏂ゆ嫹婧愰敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹close缁熶竴閿熼叺鏀撅綇鎷烽敓鏂ゆ嫹閿熼叺鏀剧櫢鎷烽敓鏂ゆ嫹
+ public class QueryResult{
+ private java.sql.Connection con;
+ private java.sql.Statement statement;
+ public java.sql.ResultSet Result;
+
+ public QueryResult(String conString,String user,String password,String Sql) throws SQLException{
+ this.con= java.sql.DriverManager.getConnection(conString,user,password);
+ this.statement=con.createStatement();
+ this.Result=this.statement.executeQuery(Sql);
+ }
+
+
+ public QueryResult(Connection con,java.sql.Statement statement,ResultSet result){
+ this.con=con;
+ this.statement=statement;
+ this.Result=result;
+ }
+
+
+ public void Close(){
+ try{
+ if(Result!=null){
+ Result.close();
+ Result=null;
+ }
+ }catch(Exception e){
+
+ }
+ try{
+ if(statement!=null){
+ statement.close();
+ statement=null;
+ }
+ }catch(Exception e){
+
+ }
+ try{
+ if(con!=null){
+ con.close();
+ con=null;
+ }
+ }catch(Exception e){
+
+ }
+ }
+ }
+
+ public DBSession createSession(boolean ManulCommit) throws SQLException{
+ Connection con=this.getConnection();
+ return new DBSession(con,ManulCommit);
+ }
+
+
+ public static org.json.JSONArray resultToJson(String[] fields,ResultSet result,boolean RowAsObject) throws SQLException, JSONException{
+ JSONArray arr=new JSONArray();
+
+ String[] cols=fields;
+
+ if(RowAsObject){
+ while(result.next()){
+ JSONObject obj=new JSONObject();
+ for(int i=0;i<cols.length;i++){
+ Object o=result.getObject(i+1);
+ if(o==null)
+ o=JSONObject.NULL;
+ obj.put(cols[i],o);
+
+ }
+ arr.put(obj);
+ }
+ }
+ else{
+ while(result.next()){
+ JSONArray obj=new JSONArray();
+ for(int i=0;i<cols.length;i++){
+ Object o=result.getObject(i+1);
+ if(o==null)
+ o=JSONObject.NULL;
+ obj.put(o);
+ }
+ arr.put(obj);
+ }
+ }
+ return arr;
+ }
+
+
+
+
+
+ //閿熸枻鎷烽敓鏂ゆ嫹閿熸嵎鍖℃嫹閿熺獤顖ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹鑿侀敓琛楁唻鎷烽敓闃额亷鎷烽敓杞跨嫬sonArray, 閿熸枻鎷烽敓绲塷wAsObject=true 姣忛敓鏂ゆ嫹閿熸枻鎷风洰閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷蜂负閿熸枻鎷烽敓鏂ゆ嫹閿熻璁规嫹閿熸枻鎷烽敓鏂ゆ嫹jsonobject 閿熸枻鎷烽敓鏂ゆ嫹姣忛敓鏂ゆ嫹閿熸枻鎷风洰閿熸枻鎷烽敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹閿熻璁规嫹閿熸枻鎷烽敓鏂ゆ嫹 jsonarray閿熸枻鎷烽敓鏂ゆ嫹
+ public static org.json.JSONArray resultToJson(ResultSet result,boolean RowAsObject) throws SQLException, JSONException{
+ JSONArray arr=new JSONArray();
+ ResultSetMetaData r= result.getMetaData();
+ String[] cols=new String[r.getColumnCount()];
+
+ for(int i=0;i<cols.length;i++){
+ cols[i]=r.getColumnLabel(i+1);
+
+ }
+ if(RowAsObject){
+ while(result.next()){
+ JSONObject obj=new JSONObject();
+ for(int i=0;i<cols.length;i++){
+ Object o=result.getObject(i+1);
+ if(o==null)
+ o=JSONObject.NULL;
+ obj.put(cols[i],o);
+ }
+ arr.put(obj);
+ }
+ }
+ else{
+ while(result.next()){
+ JSONArray obj=new JSONArray();
+ for(int i=0;i<cols.length;i++){
+ Object o=result.getObject(i+1);
+ if(o==null)
+ o=JSONObject.NULL;
+ obj.put(o);
+ }
+ arr.put(obj);
+ }
+ }
+ return arr;
+ }
+
+
+ public static void main(String[] ss) throws Exception{
+// DBHelper.InitHelper();
+// System.out.println(DBHelper.getDBHelper("mes").query(true,"select * from gmms_galss_task where width>? limit 1",100));
+// System.out.println(DBHelper.getDBHelper("mes").query(true,"select * from gmms_galss_task where width>? limit 1",false));
+// System.out.println(DBHelper.getDBHelper("mes").update("insert into abc (a,b,c) values (?,?,?)", 1,"2","3"));
+ }
+}
\ No newline at end of file
diff --git a/nglib/src/ng/db/DBSession.java b/nglib/src/ng/db/DBSession.java
new file mode 100644
index 0000000..932e03a
--- /dev/null
+++ b/nglib/src/ng/db/DBSession.java
@@ -0,0 +1,361 @@
+package ng.db;
+import java.sql.*;
+import java.util.*;
+import org.json.*;
+
+
+
+
+
+
+public class DBSession implements AutoCloseable {
+ private Connection con; //锟斤拷锟斤拷锟斤拷
+ private boolean auto; //锟角凤拷为锟皆讹拷锟结交
+ private Statement sql; //锟斤拷锟揭伙拷锟绞癸拷玫锟絊tatement
+
+
+
+ public Connection getConnection(){
+ return con;
+ }
+ //锟斤拷锟斤拷
+ private void reset(){
+ if(sql!=null){
+ try{
+ sql.close();
+ }
+ catch(Exception e){
+
+ }
+ sql=null;
+ }
+ }
+
+
+
+
+ //锟斤拷询锟斤拷锟斤拷锟�
+ public class SelectResult{
+ private Statement state;
+ private boolean closed;
+
+
+ public Object getFirst() throws SQLException{
+ ResultSet r= state.getResultSet();
+ if(r.next())
+ return r.getObject(1);
+ else
+ return null;
+ }
+ //锟斤拷取锟斤拷前锟侥斤拷锟�
+ public ResultSet getCurrentResult() throws SQLException {
+ return state.getResultSet();
+ }
+
+ public JSONObject allResultToJson() throws SQLException, JSONException{
+ JSONObject obj=new JSONObject();
+ int idx=1;
+ do{
+ JSONArray a=this.resultToJson(false);
+ obj.put("Table"+idx,a);
+ idx++;
+ }while(this.nextResult());
+ return obj;
+ }
+
+
+
+ //锟狡讹拷锟斤拷锟斤拷一锟斤拷锟斤拷锟�,锟斤拷锟斤拷锟斤拷欧锟斤拷锟絫rue
+ public boolean nextResult() throws SQLException {
+ return state.getMoreResults();
+ }
+ public void close(){
+ if(closed==false){
+ closed=true;
+ try{
+ state.close();
+ }
+ catch(Exception e){
+
+ }
+ }
+ }
+
+ //锟斤拷锟届函锟斤拷
+ public SelectResult(Statement state){
+ this.state=state;
+ ResultSet set=null;
+ }
+
+ //锟斤拷锟斤拷前锟侥斤拷锟斤拷锟街憋拷锟斤拷锟斤拷锟絁SON锟斤拷锟斤拷
+ public JSONArray resultToJson(boolean RowAsObject) throws SQLException, JSONException{
+ return DBHelper.resultToJson(this.getCurrentResult(), RowAsObject);
+ }
+
+ public JSONArray resultToJson(String[] fields,boolean RowAsObject) throws SQLException, JSONException{
+ return DBHelper.resultToJson(fields,this.getCurrentResult(), RowAsObject);
+ }
+
+
+ public List<JSONArray> allToJson(boolean RowAsObject) throws SQLException, JSONException{
+ List<JSONArray> arrs=new ArrayList<JSONArray>();
+ do{
+ arrs.add(DBHelper.resultToJson(this.getCurrentResult(), RowAsObject));
+ }while(this.nextResult());
+ return arrs;
+ }
+
+
+
+ }
+
+ //锟斤拷准锟芥储锟斤拷锟教碉拷锟矫o拷锟斤拷准锟芥储锟斤拷锟教讹拷锟斤拷,锟斤拷锟侥碉拷
+ public class StdCallResult extends SelectResult{
+ public int ResultCode;
+ public String ResultMessage;
+ public StdCallResult(CallableStatement state,int ResultCode,String ResultMessage){
+ super(state);
+ this.ResultCode=ResultCode;
+ this.ResultMessage=ResultMessage;
+ }
+ }
+
+
+
+ //锟斤拷锟斤拷一锟斤拷SQL锟斤拷锟斤拷
+ public void createSql(String sql) throws SQLException{
+ reset();
+ PreparedStatement result= con.prepareStatement(sql);
+ this.sql=result;
+ }
+
+ public StdCallResult CallProc(String proc,Object... params) throws SQLException{
+ createStdCall(proc,params.length);
+ return this.stdCall(params);
+ }
+
+
+
+
+
+
+ public void createQueryCall(String procName,int InputParamCount) throws SQLException {
+ reset();
+ StringBuilder sp=new StringBuilder();
+ sp.append("{call ");
+ sp.append(procName);
+ sp.append("(");
+ for(int i=0;i<InputParamCount;i++){
+ if(i==0){
+ sp.append('?');
+ }
+ else{
+ sp.append(",?");
+ }
+ }
+
+ CallableStatement sql=con.prepareCall(sp.toString());
+ sql.registerOutParameter(InputParamCount+1, java.sql.Types.INTEGER);
+ sql.registerOutParameter(InputParamCount+2, java.sql.Types.VARCHAR);
+ this.sql=sql;
+ }
+
+
+
+ //锟斤拷锟斤拷一锟斤拷锟斤拷准锟芥储锟斤拷锟教碉拷锟矫o拷锟斤拷锟斤拷1锟角存储锟斤拷锟教o拷锟斤拷锟斤拷2锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷母锟斤拷锟�
+ public void createStdCall(String procName,int InputParamCount) throws SQLException {
+ reset();
+ StringBuilder sp=new StringBuilder();
+ sp.append("{call ");
+ sp.append(procName);
+ sp.append("(");
+ for(int i=0;i<InputParamCount;i++){
+ if(i==0){
+ sp.append('?');
+ }
+ else{
+ sp.append(",?");
+ }
+ }
+ if(InputParamCount==0)
+ {
+ sp.append("?,?)}");
+ }
+ else{
+ sp.append(",?,?)}");
+ }
+ CallableStatement sql=con.prepareCall(sp.toString());
+ sql.registerOutParameter(InputParamCount+1, java.sql.Types.INTEGER);
+ sql.registerOutParameter(InputParamCount+2, java.sql.Types.VARCHAR);
+ this.sql=sql;
+ }
+
+ //锟矫达拷锟斤拷锟斤拷SQL锟斤拷锟斤拷锟斤拷锟捷库,执锟斤拷INSERT DELETE UPDATE锟斤拷SQL锟斤拷洌� 锟斤拷锟斤拷锟斤拷?占位锟斤拷锟斤拷应锟侥憋拷锟斤拷
+ public int update(Object... params) throws SQLException {
+
+ PreparedStatement sql=(PreparedStatement)this.sql;
+ if(params!=null){
+
+ for(int i=0;i<params.length;i++){
+ sql.setObject(i+1, params[i]);
+ }
+
+ }
+ return sql.executeUpdate();
+
+ }
+
+ public int _update(Object[] params) throws SQLException {
+
+ PreparedStatement sql=(PreparedStatement)this.sql;
+ if(params!=null){
+
+ for(int i=0;i<params.length;i++){
+ sql.setObject(i+1, params[i]);
+ }
+
+ }
+ return sql.executeUpdate();
+
+}
+
+ public Object queryFirst(Object... params) throws SQLException{
+ PreparedStatement sql=(PreparedStatement)this.sql;
+ if(params!=null){
+
+ for(int i=0;i<params.length;i++){
+ sql.setObject(i+1, params[i]);
+ }
+
+ }
+ if(sql.execute()){
+ ResultSet r=new SelectResult(sql).getCurrentResult();
+ if(r.next()){
+ return r.getObject(1);
+ }
+ return null;
+ }
+ else
+ return null;
+ }
+
+
+ //锟矫达拷锟斤拷锟斤拷SQL锟斤拷询锟斤拷锟捷库,执锟斤拷SELECT 锟斤拷洌� 锟斤拷锟斤拷锟斤拷?占位锟斤拷锟斤拷应锟侥憋拷锟斤拷
+ public SelectResult query(Object... params) throws SQLException{
+ PreparedStatement sql=(PreparedStatement)this.sql;
+ if(params!=null){
+
+ for(int i=0;i<params.length;i++){
+ sql.setObject(i+1, params[i]);
+ }
+
+ }
+ if(sql.execute()){
+ return new SelectResult(sql);
+ }
+ else
+ return null;
+ }
+
+
+
+
+ public SelectResult _query(Object[] params) throws SQLException{
+ PreparedStatement sql=(PreparedStatement)this.sql;
+ if(params!=null){
+
+ for(int i=0;i<params.length;i++){
+ sql.setObject(i+1, params[i]);
+ }
+
+ }
+ if(sql.execute()){
+ return new SelectResult(sql);
+ }
+ else
+ return null;
+ }
+
+
+ //锟斤拷锟斤拷锟斤拷锟揭伙拷未锟斤拷锟斤拷牡谋锟阶硷拷娲拷锟斤拷蹋锟斤拷锟斤拷锟轿拷娲拷锟斤拷痰锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷值锟角憋拷准锟斤拷锟矫斤拷锟斤拷锟斤拷锟斤拷锟芥储锟斤拷锟教达拷锟斤拷SELECT 锟斤拷锟皆碉拷锟斤拷SelectResult使锟斤拷
+ public StdCallResult stdCall(Object...params) throws SQLException{
+ CallableStatement sql=(CallableStatement)this.sql;
+ if(params!=null){
+ for(int i=0;i<params.length;i++){
+ sql.setObject(i+1, params[i]);
+ }
+ }
+ sql.execute();
+ sql.getResultSet();
+ int count= sql.getParameterMetaData().getParameterCount();
+ int a1=sql.getInt(count-1);
+ String a2=sql.getString(count);
+ return new StdCallResult(sql,a1,a2);
+ }
+
+ //锟截闭会话
+ public void close(){
+ try{
+ reset();
+ if(con!=null){
+ con.close();
+ con=null;
+ }
+ }
+ catch(Exception e){
+
+ }
+ }
+
+ //锟街讹拷锟结交锟斤拷式锟铰o拷锟斤拷锟斤拷锟斤拷锟斤拷锟结交
+ public void commit() throws SQLException{
+ if(!auto){
+ con.commit();
+ }
+ }
+ //锟街讹拷锟结交锟斤拷式锟铰o拷锟斤拷锟节回癸拷锟斤拷锟斤拷
+ public void rollback() throws SQLException{
+ if(!auto){
+ con.rollback();
+ }
+ }
+
+
+ //锟结话锟侥癸拷锟届函锟斤拷
+ public DBSession(Connection con,boolean ManulCommit) throws SQLException{
+ con.setAutoCommit(!ManulCommit);
+ this.auto=!ManulCommit;
+ this.con=con;
+ }
+
+ public DBSession(Connection con) throws SQLException{
+ this(con,false);
+ }
+
+
+ public static DBSession createSession(String url,String user,String password,boolean ManulCommit) throws SQLException{
+ Connection con=null;
+ DBSession sn=null;
+ try{
+ con= DriverManager.getConnection(url,user,password);
+ sn=new DBSession(con,ManulCommit);
+ return sn;
+ }
+ catch(SQLException e){
+ if(sn!=null)
+ sn.close();
+ else
+ {
+ if(con!=null){
+ con.close();
+ }
+ }
+ throw e;
+ }
+ }
+
+
+
+
+
+}
diff --git a/nglib/src/ng/db/NGFunction.java b/nglib/src/ng/db/NGFunction.java
new file mode 100644
index 0000000..3233d43
--- /dev/null
+++ b/nglib/src/ng/db/NGFunction.java
@@ -0,0 +1,79 @@
+package ng.db;
+import java.io.*;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Properties;
+
+public class NGFunction {
+
+
+ public static Properties getProperties() throws IOException{
+ Properties properties = new Properties();
+ // 使用ClassLoader加载properties配置文件生成对应的输入流
+ InputStream in =new java.io.FileInputStream("C:\\Program Files\\NorthGlass\\db.config");
+ // 使用properties对象加载输入流
+ try{
+ properties.load(in);
+ }
+ finally{
+ if(in!=null)
+ in.close();
+ }
+ return properties;
+ //获取key对应的value值
+ }
+
+
+
+
+ public static String dateFormat(String format,java.util.Date date){
+ SimpleDateFormat f=new SimpleDateFormat(format);
+ return f.format(date);
+ }
+
+ public static java.util.Date dateParse(String format,String date) throws ParseException{
+ SimpleDateFormat f=new SimpleDateFormat(format);
+ return f.parse(date);
+ }
+
+ public static String getFileContent(String path) throws IOException{
+ FileReader reader=null;
+ try{
+ reader= new FileReader(path);
+ String s= getReaderContent(reader);
+ reader.close();
+ reader=null;
+ return s;
+ }
+ finally{
+ if(reader!=null)
+ reader.close();
+ }
+
+
+ }
+
+ public static String getReaderContent(java.io.Reader reader) throws IOException{
+ BufferedReader in=null;
+ try{
+ in=new BufferedReader(reader);
+ StringBuffer jsonStr=new StringBuffer();
+ String str="";
+ while((str=in.readLine())!=null){
+ jsonStr.append(str);
+ }
+ in.close();
+ in=null;
+ return jsonStr.toString();
+ }
+ finally{
+ if(in!=null)
+ in.close();
+ }
+ }
+
+
+
+
+
+}
diff --git a/nglib/src/ng/db/aaa.java b/nglib/src/ng/db/aaa.java
new file mode 100644
index 0000000..bfa329d
--- /dev/null
+++ b/nglib/src/ng/db/aaa.java
@@ -0,0 +1,15 @@
+package ng.db;
+
+import builder.Manager;
+import ng.devices.HexUtil;
+
+public class aaa {
+ public static void main(String[] args) {
+ //uploadImages.uploadImage("D:\\picture/121.jpg", "file://localhost/picture/113.jpg");
+// int[] a=new int[2];
+//// a[0]=1;
+//// a[1]=1;
+//// Manager.sendtoPLC(76,20,2,a,0);
+ // Manager.sendtoPLC(76,20,2,"0001000a",0);
+ }
+}
diff --git a/nglib/src/ng/db/getFtpData.java b/nglib/src/ng/db/getFtpData.java
new file mode 100644
index 0000000..ef71bfa
--- /dev/null
+++ b/nglib/src/ng/db/getFtpData.java
@@ -0,0 +1,53 @@
+package ng.db;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+public class getFtpData {
+ private static final String FTP_HOST = "172.16.17.253";
+
+ private static final Integer FTP_PORT = 21;
+
+ private static final String FTP_USERNAME = "ftpusers";
+
+ private static final String FTP_PASSWORD = "beibo.123/";
+
+
+
+ public static ArrayList<String> getImg(String ip) throws Exception {
+ // TODO Auto-generated method stub
+
+ FTPClient ftpClient = toFtp.getFtpClient(ip, FTP_PORT, FTP_USERNAME, FTP_PASSWORD);
+
+ // 展示文件夹
+ //FTPFile[] ftpFiles = ftpClient.listDirectories();
+// for(FTPFile file : ftpFiles){
+// System.out.println(file.getName());
+// }ip
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+ Date date = new Date();
+ String dateString = sdf.format(date);
+ // 下载文件
+ ArrayList<String> result;
+ result=toFtp.download(ftpClient, "./data/mes-file/"+dateString+".txt", dateString+".txt");
+
+
+ //System.out.println(result.get(1));
+ //FtpUtil.download(ftpClient, "test.py", "test.py");
+ // 上传文件
+// FtpUtil.upload(ftpClient, "D:/图片3");
+
+
+ toFtp.disConnect(ftpClient);
+ return result;
+ }
+
+ public static void main(String[] args) throws Exception {
+ getImg("192.168.20.51");
+ //ArrayList<String> getImg()
+ }
+}
diff --git a/nglib/src/ng/db/sendOptFile.java b/nglib/src/ng/db/sendOptFile.java
new file mode 100644
index 0000000..f363525
--- /dev/null
+++ b/nglib/src/ng/db/sendOptFile.java
@@ -0,0 +1,70 @@
+package ng.db;
+import builder.MachineManager;
+import druidConnect.getMeterParatermeter;
+
+import javax.sql.rowset.Predicate;
+import java.io.*;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Objects;
+
+public class sendOptFile {
+ static MachineManager mmgr;
+
+ //uploadImage("D:/11.jpg", "file://10.153.19.25//共享//11.jpg"); //调用并测试
+
+ /**
+ * 通过网络url取文件,并保存
+ * @param path
+ * 文件保存路径
+ * @param url
+ */
+ public static void sendOpt(String path, String url) {
+ try {
+ //删除文件夹下文件
+ LinkedList<LinkedHashMap> orderOpt=getMeterParatermeter.getOrderOpt();
+ File directory = new File("\\\\192.168.10.25\\optfile");
+ for (File file: Objects.requireNonNull(directory.listFiles())) {
+ if (!file.isDirectory()) {
+ file.delete();
+ }
+ }
+ path+= orderOpt.get(0).get("optfileName");
+ url+=orderOpt.get(0).get("optfileName");
+ URL pathUrl = new URL(url);
+ DataInputStream dataInputStream = new DataInputStream(pathUrl.openStream());
+ File file = new File(path);
+
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(dataInputStream,"utf-8"))) {
+ String line;
+ FileWriter writer = new FileWriter(file);
+ while ((line = br.readLine()) != null) {
+
+ if(line.equals("Pieces=100")){
+ line="Pieces="+orderOpt.get(0).get("largeglass_no");
+ }
+ writer.write(line+"\n");
+ }
+ writer.flush();
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ dataInputStream.close();// 关闭输入流
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static void main(String[] args) throws Exception {
+ sendOpt("\\\\192.168.10.25\\optfile/", "file:///d/optfile/");
+ }
+
+}
\ No newline at end of file
diff --git a/nglib/src/ng/db/toFtp.java b/nglib/src/ng/db/toFtp.java
new file mode 100644
index 0000000..96a761d
--- /dev/null
+++ b/nglib/src/ng/db/toFtp.java
@@ -0,0 +1,234 @@
+package ng.db;
+
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+import sun.misc.BASE64Encoder;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Random;
+
+public class toFtp {
+
+ /**
+ * 获取一个ftp连接
+ * @param host ip地址
+ * @param port 端口
+ * @param username 用户名
+ * @param password 密码
+ * @return 返回ftp连接对象
+ * @throws Exception 连接ftp时发生的各种异常
+ */
+ public static FTPClient getFtpClient(String host, Integer port, String username, String password) throws Exception{
+ FTPClient ftpClient = new FTPClient();
+
+
+ // 连接服务器
+ ftpClient.connect(host, port);
+
+ int reply = ftpClient.getReplyCode();
+ if(!FTPReply.isPositiveCompletion(reply)){
+
+ ftpClient.disconnect();
+ return null;
+ }
+
+ // 登入服务器
+ boolean login = ftpClient.login(username, password);
+ if(!login){
+
+ ftpClient.logout();
+ ftpClient.disconnect();
+ return null;
+ }
+
+ // 连接并且成功登陆ftp服务器
+
+
+ // 设置通道字符集, 要与服务端设置一致
+ ftpClient.setControlEncoding("UTF-8");
+ // 设置文件传输编码类型, 字节传输:BINARY_FILE_TYPE, 文本传输:ASCII_FILE_TYPE, 建议使用BINARY_FILE_TYPE进行文件传输
+ ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
+ // 动模式: enterLocalActiveMode(),被动模式: enterLocalPassiveMode(),一般选择被动模式
+ ftpClient.enterLocalPassiveMode();
+ // 切换目录
+ //ftpClient.changeWorkingDirectory("xxxx");
+
+ return ftpClient;
+ }
+
+ /**
+ * 断开ftp连接
+ * @param ftpClient ftp连接客户端
+ */
+ public static void disConnect(FTPClient ftpClient){
+ if(ftpClient == null){
+ return;
+ }
+ try {
+
+ ftpClient.logout();
+ ftpClient.disconnect();
+ } catch (IOException e) {
+ e.printStackTrace();
+
+ }
+
+ }
+
+ /**
+ * 文件下载
+ * @param ftpClient ftp连接客户端
+ * @param path 文件路径
+ * @param fileName 文件名称
+ */
+ public static ArrayList<String> download(FTPClient ftpClient, String path, String fileName) throws Exception {
+
+
+
+ if(ftpClient == null || path == null || fileName == null){
+ return null;
+ }
+
+ // 中文目录处理存在问题, 转化为ftp能够识别中文的字符集
+ String remotePath;
+ try {
+ remotePath = new String(path.getBytes(StandardCharsets.UTF_8), FTP.DEFAULT_CONTROL_ENCODING);
+ } catch (UnsupportedEncodingException e) {
+ remotePath = path;
+ }
+
+
+
+
+ //获取指定路径文件里面图片存放的路径
+ InputStream inputStream = ftpClient.retrieveFileStream(remotePath);
+ ArrayList<String> getPictureList=new ArrayList<String>();
+ ArrayList<String> folderNameList=new ArrayList<String>();
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,"utf-8"))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+
+ folderNameList.add(line);
+ }
+
+ getPictureList.add(folderNameList.get(folderNameList.size()-2));
+ getPictureList.add(folderNameList.get(folderNameList.size()-1));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ inputStream.close();
+ ftpClient.completePendingCommand();
+
+ ArrayList<String> result=new ArrayList<String>();
+ for( String item: getPictureList){
+ //System.out.println(item);
+ InputStream InputStream = ftpClient.retrieveFileStream("./data/"+item);
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ try{
+ byte[] buffer = new byte[1024*900];
+ int i;
+ while ( (i = InputStream.read(buffer)) != -1) {
+ outStream.write(buffer, 0, i);
+ //w outputStream.flush();
+ }
+ buffer = outStream.toByteArray();
+ String picture="data:image/jpeg;base64,"+ Base64.getEncoder().encodeToString(buffer);;
+
+ result.add(picture);
+ } catch (Exception e) {
+
+ }
+ InputStream.close();
+ outStream.close();
+ ftpClient.completePendingCommand();
+ }
+ //InputStream inputStream1=ftpClient.retrieveFileStream("./data/"+lujin);
+
+
+// System.out.println("---");
+// System.out.println(inputStream1);
+// if (inputStream1 == null) {
+// return;
+// }
+// FileOutputStream outputStream = new FileOutputStream("D:\\picture\\" + "1.jpg");
+// BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream1);
+// BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
+// try{
+// byte[] buffer = new byte[2048];
+// int i;
+// while ((i = bufferedInputStream.read(buffer)) != -1) {
+// bufferedOutputStream.write(buffer, 0, i);
+// bufferedOutputStream.flush();
+// }
+// } catch (Exception e) {
+//
+// }
+// inputStream1.close();
+// outputStream.close();
+// bufferedInputStream.close();
+// bufferedOutputStream.close();
+
+
+ // 关闭流之后必须执行,否则下一个文件导致流为空
+// boolean complete = ftpClient.completePendingCommand();
+// if(complete){
+// //System.out.println("文件{}下载成功"+ remotePath);
+// }else{
+// //System.out.println("文件{}下载失败"+ remotePath);
+// }
+ return result;
+ }
+
+ /**
+ * 上传文件
+ * @param ftpClient ftp连接客户端
+ * @param sourcePath 源地址
+ */
+ public static void upload(FTPClient ftpClient, String sourcePath) throws Exception{
+ if(ftpClient == null || sourcePath == null){
+ return;
+ }
+
+ File file = new File(sourcePath);
+ if(!file.exists() || !file.isFile()){
+ return;
+ }
+
+ // 中文目录处理存在问题, 转化为ftp能够识别中文的字符集
+ String remotePath;
+ try {
+ remotePath = new String(file.getName().getBytes(StandardCharsets.UTF_8), FTP.DEFAULT_CONTROL_ENCODING);
+ } catch (UnsupportedEncodingException e) {
+ remotePath = file.getName();
+ }
+
+ try(
+ InputStream inputStream = new FileInputStream(file);
+ OutputStream outputStream = ftpClient.storeFileStream(remotePath);
+ ){
+ byte[] buffer = new byte[2048];
+ int length;
+ while((length = inputStream.read(buffer)) != -1){
+ outputStream.write(buffer, 0, length);
+ outputStream.flush();
+ }
+ }catch (Exception e){
+
+ }
+
+ // 关闭流之后必须执行,否则下一个文件导致流为空
+ boolean complete = ftpClient.completePendingCommand();
+ if(complete){
+ System.out.println("文件{}上传完成"+ remotePath);
+ }else{
+ System.out.println("文件{}上传失败"+ remotePath);
+ }
+
+
+ }
+}
diff --git a/nglib/src/ng/devices/HexUtil.java b/nglib/src/ng/devices/HexUtil.java
new file mode 100644
index 0000000..cf21d94
--- /dev/null
+++ b/nglib/src/ng/devices/HexUtil.java
@@ -0,0 +1,322 @@
+package ng.devices;
+
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public class HexUtil {
+
+ public static String formatHex(String hex) {
+ String result = "";
+
+ for (int i = 0; i < hex.length() - 1; i+=2) {
+ String output = hex.substring(i, i + 2);
+ result += ("0x" + output + " ");
+ }
+
+ if (result.length() > 0) {
+ result = result.substring(0, result.lastIndexOf(" "));
+ }
+
+ return result;
+ }
+
+ //姝e父鐨勫瓧姣嶆暟瀛楀彉鎴愬瓧鑺傛暟鍙戦?佺粰鐩掑瓙
+ public static String asciiToHex(String str) {
+ char[] chars = str.toCharArray();
+
+ StringBuffer hex = new StringBuffer();
+ for (int i = 0; i < chars.length; i++) {
+ hex.append(Integer.toHexString(chars[i]));
+ }
+
+ return hex.toString();
+ }
+
+ public static String hexToAscii(String hex) {
+ StringBuffer result = new StringBuffer();
+
+ for (int i = 0; i < hex.length() - 1; i+= 2) {
+ String output = hex.substring(i, i + 2);
+ int decimal = Integer.parseInt(output, 16);
+ result.append((char) decimal);
+ }
+
+ return result.toString();
+ }//12300 //00321
+ //浜岃繘鍒惰浆鍗佽繘鍒?
+ public static int int2ToHex(String number) {
+ return Integer.parseInt(number, 2);
+ }
+ //浜岃繘鍒惰浆16杩涘埗 4浣?
+ public static String intBinaryTo16(String number) {
+ int num=int2ToHex(number);
+ return intTo2ByteHex(num);
+ }
+ //鍗佸叚杩涘埗杞崄杩涘埗
+ public static int int16ToHex(String number) {
+ return Integer.parseInt(number, 16);
+ }
+ //鍗佽繘鍒惰浆浜岃繘鍒?
+ public static String intToBinary(int number) {
+ return Integer.toBinaryString(number);
+ }
+ //鍗佸叚杩涘埗杞簩杩涘埗
+ public static String int16ToBinary(String number) {
+ return intToBinary(int16ToHex(number));
+ }
+ //鍗佸叚杩涘埗杞簩杩涘埗
+ public static String int16ToBinaryEight(String number,int count) {
+ String binary=int16ToBinary(number);
+ String zero="";
+ for (int i = 0; i <count-binary.length(); i++) {
+ zero+="0";
+ }
+ binary=zero+binary;
+ return binary;
+ }
+
+ public static String intToHex(int number) {
+ return Integer.toHexString(number);
+ }
+
+ /**
+ * 灏嗘暣鏁拌浆鎹负2浣?16杩涘埗锛屽1杞崲涓?01锛?10杞崲涓?0a
+ *
+ * @param number
+ * @return
+ */
+ public static String intTo1ByteHex(int number) {
+ String numberHex = HexUtil.intToHex(number);
+
+ numberHex = String.format("%2s", numberHex).replace(' ', '0');
+
+ return numberHex;
+ }
+
+ /**
+ * 灏嗘暣鏁拌浆鎹负4浣?16杩涘埗锛屽1杞崲涓?0001锛?10杞崲涓?000a
+ *
+ * @param number
+ * @return
+ */
+ public static String intTo2ByteHex(int number) {
+ String numberHex = HexUtil.intToHex(number);
+
+ numberHex = String.format("%4s", numberHex).replace(' ', '0');
+
+ return numberHex;
+ }
+
+ /**
+ * 灏嗘暣鏁拌浆鎹负8浣?16杩涘埗锛屽1杞崲涓?00000001锛?10杞崲涓?0000000a
+ *
+ * @param number
+ * @return
+ */
+ public static String intTo4ByteHex(int number) {
+ String numberHex = HexUtil.intToHex(number);
+ numberHex = String.format("%8s", numberHex).replace(' ', '0');
+ return numberHex;
+ }
+
+ /**
+ * 灏嗘椂闂磋浆鎹负16杩涘埗鏍煎紡锛屽勾锛?2瀛楄妭锛? + 鏈堬紙1瀛楄妭锛? + 鏃ワ紙1瀛楄妭锛? + 鏃讹紙1瀛楄妭锛? + 鍒嗭紙1瀛楄妭锛? + 绉掞紙1瀛楄妭锛?
+ *
+ * @param time
+ * @return
+ */
+ public static String timeToHex(Date time) {
+ Calendar c = Calendar.getInstance();
+ c.setTime(time);
+
+ String yearHex = intTo2ByteHex(c.get(Calendar.YEAR));
+ String monthHex = intTo1ByteHex(c.get(Calendar.MONTH) + 1);
+ String dayHex = intTo1ByteHex(c.get(Calendar.DAY_OF_MONTH));
+ String hourHex = intTo1ByteHex(c.get(Calendar.HOUR_OF_DAY));
+ String minuteHex = intTo1ByteHex(c.get(Calendar.MINUTE));
+ String secondHex = intTo1ByteHex(c.get(Calendar.SECOND));
+
+ return yearHex + monthHex + dayHex + hourHex + minuteHex + secondHex;
+ }
+
+ /**
+ * 灏?16杩涘埗鐨勬椂闂磋浆鎹负yyyy-MM-dd HH:mm:ss鐨勬牸寮?
+ *
+ * @param hexTime
+ * @return
+ */
+ public static String hexToTime(String hexTime) {
+ String year = hexTo4DigitInt(hexTime.substring(0, 4));
+ String month = hexTo2DigitInt(hexTime.substring(4, 6));
+ String day = hexTo2DigitInt(hexTime.substring(6, 8));
+ String hour = hexTo2DigitInt(hexTime.substring(8, 10));
+ String minute = hexTo2DigitInt(hexTime.substring(10, 12));
+ String second = hexTo2DigitInt(hexTime.substring(12, 14));
+
+ return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
+ }
+ //鍗佸叚杩涘埗杞?10杩涘埗
+ public static int hexToInt(String hex) {
+ return Integer.parseInt(hex, 16);
+ }
+ //鍗佸叚杩涘埗杞垚10杩涘埗鍥涗綅
+ public static String hexTo4DigitInt(String hex) {
+ return new DecimalFormat("0000").format(hexToInt(hex));
+ }
+ //鍗佸叚杩涘埗杞垚10杩涘埗涓や綅
+ public static String hexTo2DigitInt(String hex) {
+ return new DecimalFormat("00").format(hexToInt(hex));
+ }
+
+ public static byte[] stringToInt(String a){
+ byte[] byt = new byte[a.length()/2];
+ for (int i = 0; i < a.length() - 1; i+=2) {
+ String output = a.substring(i, i + 2);
+ byt[i/2]=(byte)Integer.parseInt(output, 16);
+ }
+
+ return byt;
+ }
+
+ /**
+ * 灏嗗瓧鑺傝浆鎹负涓や綅鍗佸叚杩涘埗瀛楃涓诧紝涓嶅浣嶅墠鍔?0
+ *
+ * @param b
+ * @return
+ */
+ public static String byteToHexString(byte b) {
+ String hex = Integer.toHexString(b & 0xFF);
+
+ if (hex.length() == 1) {
+ hex = "0" + hex;
+ }
+
+ return hex;
+ }
+
+ /**
+ * 灏嗗崄鍏繘鍒跺瓧绗︼紝杞崲鎴愪簩杩涘埗鐨勫瓧绗?
+ *
+ * @param b
+ * @return
+ */
+ public static String getBin(String hex){
+ String[] hexs = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "a", "b", "c", "d", "e", "f"};
+ String[] bins = new String[]{"0000", "0001", "0010", "0011", "0100", "0101",
+ "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
+ int i;
+ for(i=0; i<hexs.length && !hex.toLowerCase().equals(hexs[i]); i++);
+ return bins[i];
+ }
+
+ /**
+ * 灏嗗崄鍏繘鍒跺瓧绗︼紝杞崲鎴愪簩杩涘埗鐨勫瓧绗?
+ *
+ * @param b
+ * @return
+ */
+ public static String gethex(String hex){
+ String[] hexs = new String[]{"0000", "0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", "0009",
+ "000a", "000b", "000c", "000d", "000e", "000f"};
+ String[] bins = new String[]{"0000", "0001", "0010", "0011", "0100", "0101",
+ "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
+ int i;
+ for(i=0; i<bins.length && !hex.toLowerCase().equals(bins[i]); i++);
+ return hexs[i];
+ }
+
+
+
+ /**
+ * 鍗佽繘鍒跺瓧鑺傛暟缁勮浆鍗佸叚杩涘埗瀛楃涓?
+ * @param bufSize
+ * @param msg
+ * @return
+ */
+ public static String byteToHexString(int bufSize,byte[] msg){
+ String tempHex = "";
+ String command = "";
+ if (bufSize != -1) {
+ for (int i = 0; i < bufSize; i++) {
+ tempHex = Integer.toHexString(msg[i] & 0xFF);
+
+ if (tempHex.length() == 1) {
+ tempHex = "0" + tempHex;
+ }
+ command += tempHex;
+ }
+ }
+ return command;
+ }
+
+ public static String hexToBinary(String hexString) {
+ String binaryString = Integer.toBinaryString(hexToInt(hexString));
+ return String.format("%16s", binaryString).replace(' ', '0');
+ }
+
+ public static String binaryTo2ByteHex(String binaryString) {
+ String HexString = Integer.toHexString(Integer.parseInt(binaryString, 2));
+ return String.format("%4s", HexString).replace(' ', '0');
+ }
+
+ public static void main(String[] args) {
+// System.out.println(HexUtil.hexToAscii("3c5354413e48656c6c6f20576f726c64217c5468697320697320746865206669727374207369676e616c2066726f6d20646576696365213c454f463e"));
+// System.out.println(HexUtil.asciiToHex("<STA>Hello World!|This is the first signal from device!<EOF>"));
+//
+// System.out.println(String.format("%4S", HexUtil.intToHex(55)).replace(' ', '0'));
+// System.out.println(HexUtil.hexToInt("00d2"));
+//
+// System.out.println(HexUtil.formatHex("3c5354413e"));
+ String message = "Hello World!|This is the first signal from device!";
+ int length = message.length() * 2 + 10; // 闀垮害鍖呮嫭缁撳熬鐨?<EOF>锛屼竴涓瓧绗﹀湪淇″彿涓敱涓や釜瀛楄妭琛ㄧず銆?
+
+ String command = HexUtil.asciiToHex("<STA>"); // 娣诲姞寮?濮嬫爣璇?
+
+ command += (String.format("%4s", HexUtil.intToHex(length)).replace(' ', '0')); // 娣诲姞闀垮害鏍囪瘑
+ command += "01"; // 娣诲姞璁惧绫诲瀷 0x01琛ㄧず鍒囧壊鏈猴紝0x02琛ㄧず閽㈠寲鐐?
+ command += "0001"; // 娣诲姞璁惧鍨嬪彿锛?0x0001琛ㄧず鍩烘湰娆撅紝0x0002琛ㄧず涓骇娆?
+ command += "0000"; // 鍔熻兘鍙凤紝0x0000鏄笅浣嶆満涓诲姩鍙戠粰涓婁綅鏈猴紱0x0001鏄笂浣嶆満淇敼涓嬩綅鏈篟TC
+ command += "00"; // 鍔犲瘑鏂瑰紡锛?0x00琛ㄧず涓嶅姞瀵?
+
+ Calendar c = Calendar.getInstance();
+
+ // 娣诲姞鏃堕棿锛屽苟灏嗘椂闂磋浆鎹负16杩涘埗琛ㄧず
+ command += (String.format("%4s", HexUtil.intToHex(c.get(Calendar.YEAR))).replace(' ', '0'));
+ command += (String.format("%2s", HexUtil.intToHex(c.get(Calendar.MONTH) + 1)).replace(' ', '0'));
+ command += (String.format("%2s", HexUtil.intToHex(c.get(Calendar.DAY_OF_MONTH))).replace(' ', '0'));
+ command += (String.format("%2s", HexUtil.intToHex(c.get(Calendar.HOUR_OF_DAY))).replace(' ', '0'));
+ command += (String.format("%2s", HexUtil.intToHex(c.get(Calendar.MINUTE))).replace(' ', '0'));
+ command += (String.format("%2s", HexUtil.intToHex(c.get(Calendar.SECOND))).replace(' ', '0'));
+
+ command += ("00000001"); // 鍞竴鏍囪瘑锛屼娇鐢ㄥ簭鍒楀彿
+
+ command += (HexUtil.asciiToHex(message)); // 娣诲姞涓昏淇℃伅鍐呭
+
+ command += (HexUtil.asciiToHex("<EOF>")); // 娣诲姞缁撳熬鏍囪瘑
+
+ System.out.println(command);
+
+ System.out.println(String.format("%4s", "1"));
+
+ Date time = new Date();
+ System.out.println(new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(time));
+
+ String timeHex = timeToHex(time);
+ System.out.println(timeHex);
+ System.out.println(hexToTime(timeHex));
+
+ System.out.println("3c5354413e001a00000000000000000000000000010007e0021500152800000000000000005041001d017c017c01017c3c454f463e".length());
+
+ System.out.println(hexToBinary("0c0a"));
+
+ System.out.println(Integer.MAX_VALUE);
+ }
+
+ public static String hexTo2Binary(String hexString) {
+ String binaryString = Integer.toBinaryString(hexToInt(hexString));
+ return String.format("%8s", binaryString).replace(' ', '0');
+ }
+}
diff --git a/nglib/src/ng/devices/IoBlock.java b/nglib/src/ng/devices/IoBlock.java
new file mode 100644
index 0000000..994cd08
--- /dev/null
+++ b/nglib/src/ng/devices/IoBlock.java
@@ -0,0 +1,14 @@
+package ng.devices;
+
+public interface IoBlock {
+ //从数据块指定地址读取count个字节的数据
+ public String read(int Address,int count,byte[] buffer,int offset,byte command);
+ //向数据块指定地址协议count个字节的数据
+ public String write(int Address,int count,byte[] buffer,int offset);
+ //数据块是否可用(未连接将不可用)
+ public boolean IsEnable();
+ //连接数据块
+ public void connect();
+ //断开数据块
+ public void close();
+}
diff --git a/nglib/src/ng/devices/ModbusClient.java b/nglib/src/ng/devices/ModbusClient.java
new file mode 100644
index 0000000..292adc2
--- /dev/null
+++ b/nglib/src/ng/devices/ModbusClient.java
@@ -0,0 +1,350 @@
+package ng.devices;
+
+import ng.db.DBHelper;
+import ng.db.DBSession;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.Socket;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class ModbusClient implements IoBlock {
+
+ String name; //名称
+ byte mbstate; //站号
+ int timeout; //等待超时时间
+ Socket sock; //套接字
+ int state=0; //运行状态 0(未连接) 1(已连接)
+ int machineID;
+ String ip;
+ int port;
+ byte[] wbuff;
+ byte[] rbuff;
+ String zhengzailianjie="正在连接";
+ String yilianjie="已连接";
+ short frame=0; //帧号
+
+
+ public ModbusClient(){
+ wbuff=new byte[500];
+ rbuff=new byte[1024*10];
+ }
+
+ public byte getModbusState(){
+ return mbstate;
+ }
+
+ public String getIP(){
+ return ip;
+ }
+
+ public String getName(){
+ return name;
+ }
+
+ public void setName(String name){
+ this.name=name;
+ }
+
+ public int getPort(){
+ return port;
+ }
+
+ public boolean isOpened(){
+ return state==1;
+ }
+
+
+
+
+ @Override
+ public String read(int Address, int count, byte[] buffer, int offset,byte command) {
+ if(this.IsEnable()==false){
+ return "通讯未使能";
+ }
+ if(command==3 &&(Address%2!=0 || count%2!=0)){
+ return "地址和读取数量必须是偶数";
+ }
+ int ct=count;
+ int tmp1=Address;
+ int tmp2=0;
+ int tmp=0;
+ while(tmp2<ct){
+ tmp=240;
+ if(ct-tmp2<240){
+ tmp=ct-tmp2;
+ }
+ String s=inner_read(tmp2+tmp1,tmp,buffer,offset+tmp2,command);
+ if(s=="ok"){
+ tmp2+=tmp;
+ }
+ else
+ return s;
+ }
+ return "ok";
+ }
+
+ @Override
+ public String write(int Address, int count, byte[] buffer, int offset) {
+
+ if(this.IsEnable()==false){
+ return "通讯未使能";
+ }
+ if(Address%2!=0 || count%2!=0){
+ return "地址和读取数量必须是偶数";
+ }
+ int ct=count;
+ int tmp1=Address;
+ int tmp2=0;
+ int tmp=0;
+ while(tmp2<ct){
+ tmp=240;
+ if(ct-tmp2<240){
+ tmp=ct-tmp2;
+ }
+ String s=inner_write(tmp2+tmp1,tmp,buffer,offset+tmp2);
+ if(s=="ok"){
+ tmp2+=tmp;
+ }
+ else
+ return s;
+ }
+ return "ok";
+
+ }
+
+ String inner_read(int Address, int count, byte[] buffer, int offset,byte command) {
+
+ if (this.IsEnable() == false) {
+ return "通讯未连接";
+ }
+ // TODO Auto-generated method stub
+ int addr = Address;
+ int ct = count;
+
+ addr = Address / 2;
+ ct = count / 2;
+
+ frame++;
+ wbuff[0] = (byte) ((frame & 0xff00) >> 8); // buff[0..1]帧号
+ wbuff[1] = (byte) (frame & 0xff);
+ wbuff[2] = 0; //// buff[2..3] 填0
+ wbuff[3] = 0;
+ wbuff[4] = 0; // buff[4..5] 后续帧长 总长-6
+ wbuff[5] = 6;
+ wbuff[6] = this.mbstate; // 站号
+ wbuff[7] = command; // 读功能吗
+ wbuff[8] = (byte) ((addr & 0xff00) >> 8); // buff[8..9] 地址
+ wbuff[9] = (byte) (addr & 0xff);
+ wbuff[10] = (byte) ((ct & 0xff00) >> 8); // buff[10..11] word数据数量
+ wbuff[11] = (byte) (ct & 0xff);
+
+ try {
+ // 用套接字发送数据
+ DataOutputStream out = new DataOutputStream(sock.getOutputStream());
+ out.write(wbuff, 0, 12);
+ out.flush();
+ // 用套接字读取数据
+ DataInputStream in = new DataInputStream(sock.getInputStream());
+ int c = in.read(rbuff);
+ boolean ok = false;
+ if (c > 0) {
+ // 判断报文头有效性
+ String ret = this.compareHeader(wbuff, rbuff, c);
+
+ if (ret != null)
+ return ret;
+ switch (rbuff[7]) {
+ case 1:
+
+ case 3:
+ int size = Byte.toUnsignedInt(rbuff[8]);
+ if (rbuff[7]==3&&size != ct * 2) {
+
+ return "数据长度有误";
+ }
+ for (int i = 0; i < size; i++) {
+ buffer[offset + i] = rbuff[9 + i];
+ }
+ return "ok";
+ case (byte) 0x83:
+ return "请求地址超范围或功能吗不支持";
+ default:
+ ;
+ return "收到未知功能吗";
+ }
+
+ }
+
+ } catch (IOException e) {
+ this.close();
+ return "Io Error";
+ }
+ return "err";
+ }
+
+ //比较帧头是否匹配
+ String compareHeader(byte[] send,byte[] recv,int count){
+ int step=0;
+ if(count<9){
+ return "接受帧错误(帧头有误)";
+ }
+ if(send[0]!=recv[0] || send[1]!=recv[1]){
+ return "帧号不对应";
+ }
+ if(send[2]!=0 || send[3]!=0 || recv[2]!=0 || send[3]!=0){
+ return "接受帧错误(帧头有误)";
+ }
+
+ return null;
+ }
+
+
+
+ public String inner_write(int Address, int count, byte[] buffer, int offset) {
+ if(this.IsEnable()==false){
+ return "通讯未连接";
+ }
+ // TODO Auto-generated method stub
+ int addr=Address/2;
+ int ct=count/2;
+ frame++;
+ wbuff[0]=(byte)((frame&0xff00)>>8); // buff[0..1]帧号
+ wbuff[1]=(byte)(frame&0xff);
+ wbuff[2]=0; //buff[2..3] 填0
+ wbuff[3]=0;
+ wbuff[4]=0; //buff[4..5] 后续帧长 总长-6
+ wbuff[5]=(byte)(7+ct*2);
+ wbuff[6]=this.mbstate; //站号
+ wbuff[7]=0x10; //功能码写保持寄存器
+ wbuff[8]=(byte)((addr&0xff00)>>8); //buff[8..9] 地址
+ wbuff[9]=(byte)(addr&0xff);
+ wbuff[10]=(byte)((ct&0xff00)>>8); //buff[10..11] word数据数量
+ wbuff[11]=(byte)(ct&0xff);
+ wbuff[12]=(byte)(ct*2); //数据域byte数量
+ for(int i=0;i<ct*2;i++){ //填充数据域
+ wbuff[13+i]=buffer[i+offset];
+ }
+ try {
+ //发送
+ DataOutputStream out=new DataOutputStream(sock.getOutputStream());
+ out.write(wbuff,0,13+ct*2);
+ //读应答帧
+ DataInputStream in=new DataInputStream(sock.getInputStream());
+ int c= in.read(rbuff);
+ boolean ok=false;
+ if(c>0){
+ //判断报文头有效性
+ String ret=this.compareHeader(wbuff,rbuff,c);
+ if(ret!=null)
+ return ret;
+
+ switch(rbuff[7]){
+ case 0x10:
+ return "ok";
+ case (byte)0x90:
+ return "写数据出错:通常是地址不存在";
+ default:;
+ return "未知命令码";
+ }
+
+ }
+ else{
+ //这种情况不会存在
+ return "未读到任何数据";
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ this.close();
+ //e.printStackTrace();
+ return "Io Error";
+ }
+
+ }
+
+
+ @Override
+ public boolean IsEnable() {
+ // TODO Auto-generated method stub
+ return state==1;
+ }
+
+ //设置参数
+ public void setConnectionParam(int MachineID,String IP,int Port,byte ModbusState,int Timeout){
+ this.machineID=MachineID;
+ this.mbstate=ModbusState;
+ this.ip=IP;
+ this.port=Port;
+ this.mbstate=ModbusState;
+ if(Timeout<10){
+ Timeout=10;
+ }
+ this.timeout=Timeout;
+ }
+ //关闭连接
+ @Override
+ public void close(){
+
+ if(sock!=null){
+ state=0;
+ try {
+ sock.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ //e.printStackTrace();
+ }
+ sock=null;
+ }
+ state=0;
+ }
+
+ //打开连接,或重连
+ @Override
+ public void connect(){
+
+ close();
+ DBSession sn=null;
+ DBHelper.addHelper("mes","jdbc:mysql://127.0.0.1/gmms?serverTimezone=GMT%2B8","root","beibo.123/");
+ try{
+ this.sock = new Socket(ip,port);//创建连接
+ this.sock.setSoTimeout(timeout); //设置超时
+ this.state=1;
+ try {
+
+ //String str1 = new String(yilianjie.getBytes("GBK"), "utf-8");
+ //DBHelper db=DBHelper.getDBHelper("mes");
+ sn=DBHelper.getDBHelper("mes").createSession(false);
+ sn.createSql("update machine set connect_state='已连接' where id="+machineID+"");
+ int a=sn.update();
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+
+
+
+ try {
+ //String str1 = new String(zhengzailianjie.getBytes("GBK"), "utf-8");
+ sn=DBHelper.getDBHelper("mes").createSession(false);
+ sn.createSql("update machine set connect_state='正在连接' where id="+machineID+"");
+ int a=sn.update();
+ } catch (SQLException ex) {
+ ex.printStackTrace();
+ }
+
+ }
+ }
+
+
+
+}
+
diff --git a/nglib/src/ng/devices/ModbusService.java b/nglib/src/ng/devices/ModbusService.java
new file mode 100644
index 0000000..c8d3fba
--- /dev/null
+++ b/nglib/src/ng/devices/ModbusService.java
@@ -0,0 +1,154 @@
+package ng.devices;
+
+import java.sql.SQLException;
+
+import ng.db.DBHelper;
+import ng.db.DBSession;
+import ng.db.DBSession.StdCallResult;
+
+
+public abstract class ModbusService implements Runnable {
+
+ //modbus瀹㈡埛绔�
+ protected ModbusClient client;
+ //鑷姩璇绘暟鎹湴鍧�(瀛楄妭涓哄崟浣�,鐩墠鏄�0)
+ protected int readOffset;
+ //鑷姩璇诲彇鏁版嵁闀垮害(瀛楄妭涓哄崟浣嶏紝鍙秴闀匡紝鐩墠鐢�50锛屾渶澶�250)
+ protected int readSize;
+ //璁惧ID
+ protected int machineID;
+ //杩炴帴绫诲瀷
+ protected byte functionType;
+ //绾跨▼杩愯鐘舵��
+ protected boolean running;
+
+ //璁惧IP
+ protected String ip;
+ //璁惧绔彛
+ protected int port;
+ //绾跨▼
+ java.lang.Thread thread;
+ //缂撳啿鍖猴紙鏈嶅姟鍏佽鍙戦�佽秴杩囧崗璁姹傜殑鏁版嵁锛屾墍浠ョ紦鍐插尯鏇村ぇ锛�
+ byte[] buff=new byte[10000];
+
+
+
+ public String LastReturn;
+
+ //鍏抽棴绾跨▼
+ public void close(){
+ this.running=false;
+ }
+
+ //杩愯
+ public void Run(int MachineID,String ip,int port,byte state,int ReadOffset,int ReadSize,int timeout,byte FunctionType){
+ //璁剧疆鍙傛暟
+ this.machineID=MachineID;
+ this.ip=ip;
+ this.port=port;
+ this.readOffset=ReadOffset;
+ this.readSize=ReadSize;
+ this.functionType= FunctionType;
+ this.client=new ModbusClient();
+ //鍚姩绾跨▼
+ this.client.setConnectionParam(MachineID,ip,port,(byte)state,timeout);
+
+ thread=new java.lang.Thread(this);
+ thread.start();
+ }
+
+
+ //涓�娆¤鍙栬涓�
+ String once(){
+ //鎸夌収閰嶇疆璇绘暟鎹�
+ String msg= client.read(this.readOffset,this.readSize,buff,0,this.functionType);
+ this.LastReturn=msg;
+ if(msg=="ok"){
+ try {
+ //璇锋眰鎵撳寘
+ ModbusDataPackage pack=new ModbusDataPackage();
+ pack.ByteSize=this.readSize;
+ pack.Address=this.readOffset;
+ pack.Content=buff;
+ ModbusDataPackage rsp=new ModbusDataPackage();
+ //璋冪敤鏈嶅姟
+ if(this.Service(pack,rsp)){
+ //鏈嶅姟瑕佹眰浼氭暟鎹紝鍒欎細
+ if(rsp.Content!=null){
+ return client.write(rsp.Address,rsp.ByteSize,rsp.Content,0);
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ finally{
+ }
+
+
+ }
+ return msg;
+ }
+
+ public void SendPLC(int Address, int count, byte[] buffer, int offset) {
+ this.client.write(Address, count, buffer, offset);
+ }
+ public boolean isRunning(){
+ return this.running;
+ }
+
+ public boolean isOnLine(){
+ ModbusClient c=this.client;
+ if(this.client!=null)
+ return this.client.IsEnable();
+ return false;
+ }
+
+ protected int UpadateInterval=200;
+
+ //绾跨▼杩愯鍑芥暟
+ void proc(){
+ running=true;
+ while(running){
+ if(client.IsEnable()){
+ try {
+ java.lang.Thread.sleep(UpadateInterval);
+ String back=once();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ }
+ }
+ else{
+ client.connect();
+ if(client.IsEnable()==false){
+ try {
+ java.lang.Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ }
+ }
+// else{
+// System.out.print("IO閾炬帴鎴愬姛");
+// }
+ }
+ }
+ this.running=false;
+ client.close();
+
+ }
+
+ //绾跨▼鍏ュ彛
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ proc();
+ }
+ public class ModbusDataPackage{
+ public int Address;
+ public int ByteSize;
+ public byte[] Content;
+ }
+ protected abstract boolean Service(ModbusDataPackage request,ModbusDataPackage response);
+
+
+}
diff --git a/nglib/src/ng/devices/MysqlService.java b/nglib/src/ng/devices/MysqlService.java
new file mode 100644
index 0000000..7785c18
--- /dev/null
+++ b/nglib/src/ng/devices/MysqlService.java
@@ -0,0 +1,156 @@
+package ng.devices;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+
+import builder.Manager;
+import ng.db.DBHelper;
+import ng.db.DBSession;
+import ng.devices.ModbusService.ModbusDataPackage;
+
+public class MysqlService extends ModbusService {
+
+ //数据库
+ DBHelper db;
+ //设备ID
+ int id;
+ //使用的存储过程名,固定名称
+ String proc="Total_method";
+ //记录通讯次数
+ public int ioCount;
+
+ //最后一次读的数据
+ public String lastGet;
+ //最后一次写的数据
+ public String lastSend;
+ //发送标志位定位
+ public int fa_song_Pos=-1;
+ //请求标志位定位
+ public int qing_qiu_Pos=-1;
+ //状态标志位定位
+ public int zhuang_tai_Pos=-1;
+ //汇报标志位定位
+ public int hui_bao_Pos=-1;
+ //确认标志位定位
+ public int que_ren_Pos=-1;
+
+
+ public int zhangtai;
+
+ //构造函数初始化
+ public MysqlService(DBHelper db,int id) {
+ super();
+ this.db=db;
+ this.id=id;
+
+ // TODO Auto-generated constructor stub
+ }
+
+ int readWord(byte[] buff,int offset){
+ if(offset<0 || offset>=buff.length-1)
+ return 0;
+ int k=buff[offset];
+ k=(k<<8)+buff[offset+1];
+ return k;
+ }
+
+ //判断是否标志位全0
+ boolean PassInvoke(byte[] buff){
+
+ int a=0,b=0,c=0,d=0;
+ a=readWord(buff,fa_song_Pos);
+ b=readWord(buff,qing_qiu_Pos);
+ c=readWord(buff,hui_bao_Pos);
+ d=readWord(buff,que_ren_Pos);
+ this.zhangtai=readWord(buff,this.zhuang_tai_Pos);
+ if(a==0 && b==0 && c==0 && d==0)
+ return true;
+ return false;
+ }
+
+
+
+ //这是将读应答包转换为Msyql识别的形式(只能转化读应答数据包)
+ String packToString(ModbusDataPackage pack){
+ String s=HexUtil.intTo2ByteHex(1);
+ s+=HexUtil.intTo2ByteHex(0);
+ s+=HexUtil.intTo2ByteHex((3+pack.ByteSize));
+ s+="0103";
+ s+=HexUtil.intTo1ByteHex(pack.ByteSize);
+ s+=HexUtil.byteToHexString(pack.ByteSize,pack.Content);
+ return s;
+ }
+ //这是将mysql返回的字符串转换为数据包(只能转化写请求包)
+ boolean fillPack(ModbusDataPackage pack,String message){
+ if(message==null)
+ return false;
+ int a= HexUtil.hexToInt(message.substring(8*2,10*2));
+ int b= HexUtil.hexToInt(message.substring(10*2,12*2));
+ String s=message.substring(13*2,message.length());
+ byte[] bb= HexUtil.stringToInt(s);
+ pack.Address=a*2;
+ pack.ByteSize=b*2;
+ pack.Content=bb;
+ return true;
+ }
+
+ //服务实现函数
+ @Override
+ protected boolean Service(ModbusDataPackage arg0, ModbusDataPackage arg1) {
+ // TODO Auto-generated method stub
+ //读次数+1
+ ioCount++;
+ //判断是否不调用
+ // if(this.PassInvoke(arg0.Content))
+ // return false;
+ //转化为mysql输入参数
+ String s=this.packToString(arg0);
+ //更新最后一条读报文
+ this.lastGet=s;
+ DBSession sn=null;
+ String result=null;
+ String flag=null;
+
+ try{
+ //创建连接
+ sn=this.db.createSession(false);
+ Connection con= sn.getConnection();
+ //掉哦那个存储过程
+ CallableStatement sql=con.prepareCall("{call Total_method(?,?,?,?)}");
+ sql.registerOutParameter(3, java.sql.Types.VARCHAR);
+ sql.registerOutParameter(4, java.sql.Types.VARCHAR);
+ sql.setString(1, s);
+ sql.setLong(2, id);
+ sql.execute();
+ //读取返回参数
+ result= sql.getString(3);
+ flag= sql.getString(4);
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ finally{
+ sn.close();
+
+ }
+
+ if(result!=null){
+ if(result.length()>0){
+ char c=result.charAt(0);
+ //# @ 开头代表特殊消息字符,否则代表通讯
+ if(c=='#' || c=='@'){
+ //调用消息处理函数(这是一个外部接口)
+ Manager.SendMessage(result);
+ }
+ else{
+ //更新最后一次发送
+ this.lastSend=result;
+ //返回要发送的报文
+ return this.fillPack(arg1,result);
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/nglib/src/toTcp/DLT645_2007Control.java b/nglib/src/toTcp/DLT645_2007Control.java
new file mode 100644
index 0000000..fbaee0f
--- /dev/null
+++ b/nglib/src/toTcp/DLT645_2007Control.java
@@ -0,0 +1,163 @@
+package toTcp;
+
+import static java.lang.System.arraycopy;
+
+public class DLT645_2007Control {
+
+ // 读数据 ,传入电表的表号后生成 读数据的命令,将命令发送到电表
+ public byte[] ReadData(String address) {
+
+ byte[] readcommand = new byte[20];
+ readcommand[0] = (byte) 0xFE; // 网上资料说前面要加四个固定的 0xFE,
+ readcommand[1] = (byte) 0xFE;
+ readcommand[2] = (byte) 0xFE;
+ readcommand[3] = (byte) 0xFE;
+ readcommand[4] = (byte) 0x68;// 真正的数据帧起始位置
+ byte[] addressbytes = setAddrByte(address); // 电表的地址 转成16进制,有一个倒序的操作
+ arraycopy(addressbytes, 0, readcommand, 5, addressbytes.length);
+ readcommand[11] = (byte) 0x68;// 固定格式
+ readcommand[12] = (byte) 0x11;// 表示 读数据
+ readcommand[13] = (byte) 0x04;// 后面 数据项的长度
+ // byte[] dataTypeBytes = new byte[] { (byte) 0x00, (byte) 0x00, (byte)
+ // 0x00, (byte) 0x00 };//读电表的有功总电能
+ byte[] dataTypeBytes = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00 };// 数据项代码:
+ // 读电表的正向有功总电能
+
+ if (dataTypeBytes != null) {
+ for (int i = 0; i < dataTypeBytes.length; i++) {
+ dataTypeBytes[i] += 0x33;
+ }
+ }
+ arraycopy(dataTypeBytes, 0, readcommand, 14, dataTypeBytes.length);
+ readcommand[18] = getSigned(getCSCode(readcommand, 4, 17));
+ readcommand[19] = (byte) 0x16;
+ return readcommand;
+ }
+
+ // 解析从设备返回的数据
+ public static void ReturnData(byte[] returndatas) {
+ float reslut =0;
+ if (returndatas.length > 8) {
+
+ if (returndatas[8] == (byte) 0x91)// 对应读数据命令11 的正确应答
+ {
+ String EachByteAddress = GetBCDAddress(returndatas); // 得到
+ // 当前返回数据代表的
+ // 电表表号
+ boolean check = checkData(returndatas);
+ if (check) {
+ int[] read_ints = new int[returndatas.length];
+ for (int i = 0; i < returndatas.length; i++) {
+ if ((int) returndatas[i] > 0) {
+ read_ints[i] = (int) returndatas[i];
+ } else {
+ read_ints[i] = (int) returndatas[i] + 256;
+ }
+ }
+
+ if (read_ints[8] == 0x91) {
+ int lengthOfData = read_ints[9];// 数据长度;
+ byte[] data = new byte[lengthOfData - 4];
+ for (int d = 0; d < lengthOfData - 4; d++) {
+ data[d] = (byte) (read_ints[14 + d] - 0x33);
+ }
+ int value = 0;
+ for (int v = 0; v < lengthOfData - 4; v++) {
+ value = v + (data[v] * 10 / 16 + (data[v]) % 16) * 100 ^ v;
+ }
+ reslut = value * 0.01f;// value *0.01 是最终的 正向有功总电能
+
+
+ }
+ }
+ }
+ }
+ // System.out.println(reslut);
+ }
+
+ // 把表号地址转成16进制
+ public byte[] setAddrByte(String addr) {
+ byte[] addressByte = new byte[6];
+ for (int i = 11; i > 0; i -= 2) {
+ int a = addr.charAt(i);
+ int b = addr.charAt(i - 1);
+ // 由于地址是16进制,所以先进行判断
+ // A - F
+ if (a >= 65 && a <= 70) {
+ a -= 15;
+ } else if (a >= 97 && a <= 102) {
+ a -= 87;
+ } else {
+ a -= 48;
+ }
+
+ if (b >= 65 && b <= 70) {
+ b -= 15;
+ } else if (b >= 97 && b <= 102) {
+ b -= 87;
+ } else {
+ b -= 48;
+ }
+
+ addressByte[(11 - i) / 2] = (byte) (b * 16 + a);
+ }
+ return addressByte;
+ }
+
+ // 把16进制的表号数据 转成字符串形式的表号
+ public static String GetBCDAddress(byte[] address) {
+ byte[] byteAddress = new byte[6];
+ arraycopy(address, 1, byteAddress, 0, 6);
+ String addr = "";
+ String EachByteAddress;
+ int bitdata;
+ for (byte addr_b : byteAddress) {
+ if (addr_b < 0) {
+ bitdata = addr_b + 256;
+ } else {
+ bitdata = addr_b;
+ }
+ EachByteAddress = bitdata / 16 + "" + bitdata % 16;
+ addr = EachByteAddress + addr;
+ }
+ return addr;
+ }
+
+ // CS校验码
+ private int getCSCode(byte[] byteFrame, int i, int j) {
+ int s = 0;
+ for (int k = i; k <= j; k++) {
+ s += (byteFrame[k] & 0xff) % 256;
+ }
+ return s;
+ }
+
+ // 将无符号(形式上的)的数据转化成有符号的byte数据值
+ private byte getSigned(int a) {
+ if (a > 0x7f)
+ return (byte) (a - 256);
+ else
+ return (byte) (a);
+ }
+
+ // 校验 返回的数据包内容
+ static boolean checkData(byte[] data) {
+ byte s = 0;
+ int j;
+ for (j = data.length - 1; j > 0; j--) {
+ if (data[j] == 22) {
+ break;
+ }
+ }
+
+ for (int i = 0; i < j - 1; i++) {
+ s += (data[i] & 0xff) % 256;
+ }
+ // System.out.println(s);
+ if (s == data[j - 1]) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/nglib/src/toTcp/TCPClient.java b/nglib/src/toTcp/TCPClient.java
new file mode 100644
index 0000000..29b0dc4
--- /dev/null
+++ b/nglib/src/toTcp/TCPClient.java
@@ -0,0 +1,24 @@
+package toTcp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
+
+public class TCPClient {
+ public static void main(String[] args) throws IOException, IOException {
+
+ System.out.println("TCP客户端启动...");
+
+ //1.建立客户端socket服务
+ Socket s = new Socket("192.168.3 .7 ", 8887);
+
+ //2.获取socket流中的输出流
+ OutputStream out = s.getOutputStream();
+
+ //使用输出流将指定的数据写出去
+ out.write("tcp演示: Hello Java".getBytes());
+
+ //关闭资源
+ s.close();
+ }
+}
diff --git a/nglib/src/toTcp/TcpClientHandler.java b/nglib/src/toTcp/TcpClientHandler.java
new file mode 100644
index 0000000..8e8a00c
--- /dev/null
+++ b/nglib/src/toTcp/TcpClientHandler.java
@@ -0,0 +1,114 @@
+package toTcp;
+
+
+import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
+import ng.devices.HexUtil;
+
+import java.io.*;
+import java.net.Socket;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+
+import static druidConnect.getMeterParatermeter.meterToMysql;
+
+public class TcpClientHandler extends Thread {
+ private Socket clientSocket;
+ private PrintWriter out;
+ private InputStream in;
+ private Socket socket;
+ private LinkedList<LinkedHashMap> meterParameter;
+ public TcpClientHandler(Socket socket, LinkedList<LinkedHashMap> meterParameter) {
+ this.clientSocket = socket;
+ this.meterParameter=meterParameter;
+ }
+
+ public void run() {
+ try {
+ while (true) {
+ try {
+ System.out.println(clientSocket.getInetAddress().getHostAddress()+"客户端连接上了");
+ InputStream in = clientSocket.getInputStream();
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+ byte[] b = new byte[20];
+
+ int len;
+ while ( (len = in.read(b)) != -1) {
+ output.write(b, 0, len);
+
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ if(in.available() == 0) {
+ output.reset();
+ }
+
+ String result=new String(b, 0, len);
+ String HexDLT645=gethex.BinaryToHexString(b);
+ if(result.equals("123")){
+ for (int i = 0; i <meterParameter.size() ; i++) {
+ String hexString="";
+ if(meterParameter.get(i).get("ip").equals(clientSocket.getInetAddress().getHostAddress())){
+ hexString= (String) meterParameter.get(i).get("hexdlt645");
+ byte[] data = HexUtil.stringToInt(hexString);
+ DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
+ out.write(data);
+ out.flush();
+
+ }
+ }
+
+
+ }else if(HexDLT645.indexOf("68")>-1){
+ String HEX=HexDLT645.replace(" ", "");
+ for (int i = 0; i < meterParameter.size(); i++) {
+ if(HEX.indexOf((String) meterParameter.get(i).get("addless"))>-1 && meterParameter.get(i).get("addless")!="" ){
+ Double electricNum = gethex.toSqlElectric(HexDLT645);
+ String ratio = (String) meterParameter.get(i).get("ratio");
+ electricNum = Math.round(electricNum * Integer.parseInt(ratio) ) * 1d;
+ String meterID = (String) meterParameter.get(i).get("id");
+ meterToMysql(meterID,electricNum,HEX);
+ }
+ }
+
+ //System.out.println(HEX);
+ }
+
+ b = new byte[20];
+ len = 0;
+
+ }
+ output.close();
+ in.close();
+
+ }catch (Exception e){
+ //
+ System.out.println("tcp电表客户端已断开连接---------"+e);
+ break;
+ }
+
+
+ //inputLine += new String(temp, 0, length);
+ //System.out.println(inputLine);
+// if (".".equals(inputLine)) {
+// System.out.println(inputLine);
+// System.out.println("tcp电表客户端已断开连接1---------");
+// //out.println("bye");
+// break;
+// }
+ }
+
+ clientSocket.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }finally {
+
+ }
+ }
+ private static byte charToByte(char c) {
+ return (byte) "0123456789ABCDEF".indexOf(c);
+ }
+}
diff --git a/nglib/src/toTcp/TcpMain.java b/nglib/src/toTcp/TcpMain.java
new file mode 100644
index 0000000..2b79895
--- /dev/null
+++ b/nglib/src/toTcp/TcpMain.java
@@ -0,0 +1,41 @@
+package toTcp;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+public class TcpMain {
+ public static void main(String[] args) throws Exception
+ {
+// try{
+// new TcpMultiServer().start(55559);
+// }catch (Exception e){
+// System.out.println("tcp服务发生错误");
+// }
+ getElectric();
+
+ }
+ public static void getElectric() throws Exception
+ {
+ //new ServerSocket(55550).close();
+ try{
+ new TcpMultiServer().start(55550);
+ }catch (Exception e){
+
+ System.out.println("tcp服务发生错误"+e);
+ }
+
+ }
+
+ public static void getElectric1() throws Exception
+ {
+ try{
+ new TcpMultiServer().start(55550);
+ }catch (Exception e){
+
+ System.out.println("tcp服务发生错误"+e);
+ }
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/nglib/src/toTcp/TcpMultiServer.java b/nglib/src/toTcp/TcpMultiServer.java
new file mode 100644
index 0000000..d6b9c4c
--- /dev/null
+++ b/nglib/src/toTcp/TcpMultiServer.java
@@ -0,0 +1,36 @@
+package toTcp;
+
+
+import druidConnect.getMeterParatermeter;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.ServerSocket;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+
+public class TcpMultiServer {
+ LinkedList<LinkedHashMap> meterParameter;
+
+ {
+ try {
+ meterParameter = getMeterParatermeter.getMeterParater();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private ServerSocket serverSocket;
+
+
+ public void start(int port) throws IOException {
+ serverSocket = new ServerSocket(port);
+ while (true) {
+ new TcpClientHandler(serverSocket.accept(),meterParameter).start();
+ }
+ }
+
+ public void stop() throws IOException {
+ serverSocket.close();
+ }
+}
\ No newline at end of file
diff --git a/nglib/src/toTcp/gethex.java b/nglib/src/toTcp/gethex.java
new file mode 100644
index 0000000..e1c7d7b
--- /dev/null
+++ b/nglib/src/toTcp/gethex.java
@@ -0,0 +1,78 @@
+package toTcp;
+
+import java.util.Arrays;
+
+import static java.lang.Integer.parseInt;
+import static java.lang.Integer.toHexString;
+
+public class gethex {
+ public static byte[] hexStrToBinaryStr(String hexString) {
+
+
+// if (TextUtils.isEmpty(hexString)) {
+// return null;
+// }
+
+ hexString = hexString.replaceAll(" ", "");
+
+ int len = hexString.length();
+ int index = 0;
+
+ byte[] bytes = new byte[len / 2];
+
+ while (index < len) {
+
+ String sub = hexString.substring(index, index + 2);
+
+ bytes[index/2] = (byte)Integer.parseInt(sub,16);
+
+ index += 2;
+ }
+
+ //BinaryToHexString(bytes);
+ return bytes;
+ }
+ public static String BinaryToHexString(byte[] bytes) {
+ String hexStr = "0123456789ABCDEF";
+ String result = "";
+ String hex = "";
+ for (byte b : bytes) {
+ hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4));
+ hex += String.valueOf(hexStr.charAt(b & 0x0F));
+ result += hex + " ";
+ }
+ // System.out.println("------");
+ //System.out.println(result);
+ return result;
+ }
+
+ public static double toSqlElectric(String DLT645) {
+ String[] data=DLT645.split(" ");
+ int start = 0;
+ int end = data.length - 1;
+
+ while (start < end) {
+ String temp = data[start];
+ data[start] = data[end];
+ data[end] = temp;
+
+ start++;
+ end--;
+ }
+ int num1 = Integer.parseInt("33", 16);
+ String result="";
+ for (int i = 2; i <6; i++) {
+
+ int num2 = Integer.parseInt(data[i], 16);
+ int num3 = num2 - num1 ;
+ int num4=Integer.parseInt(Integer.toHexString(num3));
+ result+=String.format("%02d", num4);
+ }
+ return Math.round(Float.valueOf(result)) * 0.01d;
+ }
+
+ public static void main(String[] args) {
+ String DLT645="68 23 01 00 91 03 57 68 91 08 33 33 34 33 37 8A 34 33 6D 16";
+ toSqlElectric(DLT645);
+ }
+}
diff --git a/nglib/src/toTcp/to16HEX.java b/nglib/src/toTcp/to16HEX.java
new file mode 100644
index 0000000..289ddc5
--- /dev/null
+++ b/nglib/src/toTcp/to16HEX.java
@@ -0,0 +1,25 @@
+package toTcp;
+
+import java.text.DecimalFormat;
+
+import static com.sun.corba.se.impl.util.RepositoryId.getByteArray;
+
+public class to16HEX {
+
+ public static void to16Hex1(byte[] bytes, int len){
+ byte[] afByte;
+ //定义16进制字符串
+ String hex = "";
+ for (int i = 0; i < len; i++) {
+ int ce = bytes[i] & 0xFF;
+ //这里不满足两个长度的需要填充0,为了满足一个字节占的是字符串的两位 比如 10的16进制就是a 转为16进制字符串就是0a
+ DecimalFormat df = new DecimalFormat("00");
+ hex += " "+df.format(ce);
+ }
+ //afByte = getByteArray(hex);
+ System.out.println(hex);
+ System.out.println(len);
+ //String result=new String(afByte, 0, afByte.length);
+ //System.out.println(result);
+ }
+}
--
Gitblit v1.8.0