From b1187e08e13a9bafc2742591f82ed9abc9c89935 Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期五, 09 五月 2025 13:21:27 +0800
Subject: [PATCH] Merge branch 'master' of http://159.223.171.199:10439/r/Haier_MES_II

---
 nglib/src/ng/devices/ModbusService.java                      |   29 +----
 gmms/.classpath                                              |   11 -
 nglib/.idea/encodings.xml                                    |    4 
 gmms/WebContent/login/run.jsp                                |    4 
 gmms/.settings/org.eclipse.wst.common.project.facet.core.xml |    1 
 nglib/src/builder/Manager.java                               |    1 
 nglib/src/builder/httpApi.java                               |  142 ++++++++++++++++++++++++++++
 nglib/src/ng/devices/MysqlService.java                       |   93 +++++++++++++-----
 8 files changed, 222 insertions(+), 63 deletions(-)

diff --git a/gmms/.classpath b/gmms/.classpath
index b80cf54..83f762b 100644
--- a/gmms/.classpath
+++ b/gmms/.classpath
@@ -1,17 +1,12 @@
 <?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/jre1.8.0_121">
+	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
+	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
 		<attributes>
 			<attribute name="owner.project.facets" value="java"/>
 		</attributes>
 	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0">
-		<attributes>
-			<attribute name="owner.project.facets" value="jst.web"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
-	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
 	<classpathentry kind="output" path="build/classes"/>
 </classpath>
diff --git a/gmms/.settings/org.eclipse.wst.common.project.facet.core.xml b/gmms/.settings/org.eclipse.wst.common.project.facet.core.xml
index bec785d..28755e1 100644
--- a/gmms/.settings/org.eclipse.wst.common.project.facet.core.xml
+++ b/gmms/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <faceted-project>
-  <runtime name="Apache Tomcat v8.0"/>
   <fixed facet="jst.web"/>
   <fixed facet="java"/>
   <fixed facet="wst.jsdt.web"/>
diff --git a/gmms/WebContent/login/run.jsp b/gmms/WebContent/login/run.jsp
index 026f384..9def358 100644
--- a/gmms/WebContent/login/run.jsp
+++ b/gmms/WebContent/login/run.jsp
@@ -3,10 +3,10 @@
 <%@page import="toTcp.TcpMain"%>
 <%@include file="../mysqlInsert/mysql_connect.jsp"%>
 <%
-  ThreadHttpServer.mains(); 
+  //ThreadHttpServer.mains(); 
  
 //TcpMain.getElectric();
-//Manager.appStart(new String[]{url,user,password });
+Manager.appStart(new String[]{url,user,password });
 
 //response.sendRedirect("bdg.jsp");
 %>
\ No newline at end of file
diff --git a/nglib/.idea/encodings.xml b/nglib/.idea/encodings.xml
index 83b0b33..b858a91 100644
--- a/nglib/.idea/encodings.xml
+++ b/nglib/.idea/encodings.xml
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="Encoding">
-    <file url="file://$PROJECT_DIR$/bin/S7/S7control.java" charset="UTF-8" />
     <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" />
@@ -10,11 +9,12 @@
     <file url="file://$PROJECT_DIR$/src/builder/ThreadHttpServer.java" charset="GBK" />
     <file url="file://$PROJECT_DIR$/src/ng/db/DBSession.java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/src/ng/devices/InitUtil.java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/ng/devices/MysqlService.java" charset="GBK" />
     <file url="file://$PROJECT_DIR$/src/ng/devices/PlcBitInfo.java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/src/ng/devices/PlcBitObject.java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/src/ng/devices/PlcParameterInfo.java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/src/ng/devices/PlcParameterObject.java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/src/toTcp/TCPClient.java" charset="GBK" />
-    <file url="PROJECT" charset="GBK" />
+    <file url="PROJECT" charset="UTF-8" />
   </component>
 </project>
\ No newline at end of file
diff --git a/nglib/src/builder/Manager.java b/nglib/src/builder/Manager.java
index 6cbe3a6..b705925 100644
--- a/nglib/src/builder/Manager.java
+++ b/nglib/src/builder/Manager.java
@@ -207,7 +207,6 @@
 			System.out.println("错误");
 		}
 	}
-
 	public static void main(String[] args){
 		Manager.appStart(new String[]{"jdbc:mysql://localhost/gmms?serverTimezone=GMT%2B8","root","beibo.123/" });
 		while(true){
diff --git a/nglib/src/builder/httpApi.java b/nglib/src/builder/httpApi.java
new file mode 100644
index 0000000..f0189bc
--- /dev/null
+++ b/nglib/src/builder/httpApi.java
@@ -0,0 +1,142 @@
+package builder;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class httpApi {
+
+    public static String Ip="localhost";
+    public static void main(String[] args) {
+
+
+        JSONObject jsonObject=new JSONObject();
+        jsonObject.put("thickness", "5");
+        jsonObject.put("width", "3660");
+        jsonObject.put("height", "2440");
+        jsonObject.put("sameCount", "2");
+        jsonObject.put("glassType", "瓒呯櫧鐜�");
+        sendShelfTask(jsonObject);
+        JSONObject a=selectLoadRack();
+        double width=Double.valueOf(a.get("width").toString());
+        double height=Double.valueOf(a.get("height").toString());
+        double thickness=Double.valueOf(a.get("thickness").toString());
+        int sameCount=Integer.valueOf(a.get("sameCount").toString());
+        System.out.println(width+","+height+","+thickness+","+sameCount);
+
+    }
+    //鍙戦�佷粨鍌ㄦ墍闇�鐜荤拑浠诲姟
+    public static JSONObject sendShelfTask(JSONObject params){
+        try {
+            String requestURL="http://"+Ip+":5000/GlassInfo";
+            String requestBody = params.toString();
+            JSONObject resultJSON= httpApi(requestURL,"POST",requestBody);
+            return resultJSON;
+        } catch (Exception e) {
+            // TODO: handle exception
+            System.out.println("HTTP ERROR:http://39.105.110.179:5000/GlassInfo  POST");
+        }
+        return null;
+    }
+    //MES鏄惁姝e父杩炴帴
+    public static JSONObject sendShelfTask(){
+        try {
+            String requestURL="http://"+Ip+":5000/GlassInfo";
+            JSONObject resultJSON= httpApi(requestURL,"GET",null);
+            return resultJSON;
+        } catch (Exception e) {
+            // TODO: handle exception
+            System.out.println("HTTP ERROR:http://39.105.110.179:5000/GlassInfo  GET");
+        }
+        return null;
+    }
+    //鏌ヨ涓婄墖浣嶄俊鎭�
+    public static JSONObject selectLoadRack(){
+        try {
+            String requestURL="http://"+Ip+":5000/GlassInfo/getReady";
+            JSONObject resultJSON= httpApi(requestURL,"GET",null);
+            JSONObject loadRack=resultJSON.getJSONObject("data").getJSONArray("stocklist").getJSONObject(0);
+            return loadRack;
+        } catch (Exception e) {
+            // TODO: handle exception
+            System.out.println("HTTP ERROR:http://"+Ip+":5000/GlassInfo GET");
+        }
+        return null;
+    }
+    //鍙嶉涓婄墖浣嶄俊鎭�-1
+    public static JSONObject loadRackReduction(){
+        try {
+            String requestURL="http://"+Ip+":5000/GlassInfo/finishGet";
+            JSONObject resultJSON= httpApi(requestURL,"GET",null);
+            return resultJSON;
+        } catch (Exception e) {
+            // TODO: handle exception
+            System.out.println("HTTP ERROR:http://"+Ip+":5000/GlassInfo/finishGet GET");
+        }
+        return null;
+    }
+    //鏌ヨ浠撳偍搴撳唴淇℃伅
+    public static JSONObject storageRackInfo(){
+        try {
+            String requestURL="http://"+Ip+":5000/GlassInfo";
+            JSONObject resultJSON= httpApi(requestURL,"GET",null);
+            return resultJSON;
+        } catch (Exception e) {
+            // TODO: handle exception
+            System.out.println("HTTP ERROR:http://39.105.110.179:5000/GlassInfo GET");
+        }
+        return null;
+    }
+    public static JSONObject httpApi(String requestURL,String requestMethod,String requestBody){
+        JSONObject jsonObject = null;
+        try {
+            // 鍦板潃 URL
+            URL url = new URL(requestURL);
+            // 杩炴帴
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            // 璇锋眰鏂瑰紡
+            connection.setRequestMethod(requestMethod);
+            connection.setDoOutput(true);
+            connection.setRequestProperty("Content-type", "application/json; charset=UTF-8");
+            System.out.println(requestBody);
+            // 鍙傛暟鍐欏叆
+            if(requestBody!=null){
+                try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
+                    outputStream.writeBytes(requestBody);
+                    outputStream.flush();
+                }
+            }
+            // 鐘舵�佺爜
+            int responseCode = connection.getResponseCode();
+            // 璇诲彇杩斿洖鍐呭
+            if (responseCode==200){
+                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+                String line;
+                StringBuilder response = new StringBuilder();
+                while ((line = reader.readLine()) != null) {
+                    response.append(line);
+                }
+                reader.close();
+                // 鍏抽棴
+                connection.disconnect();
+                String resultStr = response.toString();
+                if (resultStr!=null&&resultStr.length()>0) {
+                    jsonObject =JSONObject.parseObject(resultStr);
+                }
+                //System.out.println(jsonObject);
+            }else{
+                System.out.println("Response Code: " + responseCode);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return jsonObject;
+    }
+
+}
diff --git a/nglib/src/ng/devices/ModbusService.java b/nglib/src/ng/devices/ModbusService.java
index c56725e..06a514e 100644
--- a/nglib/src/ng/devices/ModbusService.java
+++ b/nglib/src/ng/devices/ModbusService.java
@@ -72,7 +72,6 @@
 
     }
     
-    
     //涓�娆¤鍙栬涓�
     String once(){
     	//鎸夌収閰嶇疆璇绘暟鎹�
@@ -112,27 +111,24 @@
 			String flag=null;
 			String messsage="000000000000000000";
 			EPlcType ePlcType=null;
-			if(this.machineID==4){
-				ePlcType=EPlcType.S1500;
-			}else if(this.machineID==6){
+			if(this.functionType==10){
 				ePlcType=EPlcType.S200_SMART;
-			}else{
+			}else if(this.functionType==11){
+				ePlcType=EPlcType.S1500;
+			}else if(this.functionType==12){
 				ePlcType=EPlcType.S1200;
+			}else{
+				return "";
 			}
 			S7control s7=new S7control(ePlcType, ip, port, 0, 0);
-			//List<Integer> word=s7.readWord("DB34.122",  1);
 			List<Integer> listWord=s7.readWord(this.remarks,(this.readSize/2));
 			if(listWord==null){
 				System.out.println("notread");
 				return "";
 			}
             for(int i=0;i<listWord.size();i++){
-				//System.out.println("i  "+listWord.size()+"   "+messsage);
 				messsage+=HexUtil.intTo2ByteHex(listWord.get(i));
 			}
-
-			//System.out.println(messsage);
-			//System.out.println(ip+"  "+s7.readWord("DB34.122",  1));
 			//鏁版嵁搴�
 			DBHelper db=DBHelper.getDBHelper("mes");
 			try{
@@ -154,25 +150,12 @@
 					//寰楀埌瀛樺偍杩囩▼杩斿洖鐨勫�硷紝鏁扮粍绗竴涓负鍦板潃锛岀浜屼釜涓哄��
 					int resultsLength=results.length;
 					int resultsSize=resultsLength/2;
-
 					for(int i=1;i<resultsSize+1;i++){
 						int addressIndex=(i-1)*2;
 						int valueIndex=i*2-1;
 						s7.writeWord(results[addressIndex],Integer.valueOf(results[valueIndex]));//鍙傛暟缁勫啓鍏�
 					}
-//					if(results.length==2){
-//						s7.writeWord(results[0],Integer.valueOf(results[1]) );
-//					}
-//					if(results.length==4){
-//						s7.writeWord(results[0],Integer.valueOf(results[1]));//閰嶆柟
-//						s7.writeWord(results[2],Integer.valueOf(results[3]));//閫熷害
-//					}
-					List<Integer> listWord2=s7.readWord(this.remarks,(this.readSize/2));
-					System.out.println(listWord2.size());
-
 				}
-
-
 			}
 			catch(Exception e){
 				e.printStackTrace();
diff --git a/nglib/src/ng/devices/MysqlService.java b/nglib/src/ng/devices/MysqlService.java
index 8a4079f..3290efa 100644
--- a/nglib/src/ng/devices/MysqlService.java
+++ b/nglib/src/ng/devices/MysqlService.java
@@ -5,6 +5,8 @@
 
 import builder.Manager;
 import builder.S7control;
+import builder.httpApi;
+import com.alibaba.fastjson.JSONObject;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import ng.db.DBHelper;
 import ng.db.DBSession;
@@ -102,9 +104,6 @@
 		// TODO Auto-generated method stub
 		//读次数+1
 		ioCount++;
-		//判断是否不调用
-	//	 if(this.PassInvoke(arg0.Content))
-		// return false;
 		//转化为mysql输入参数
 		String s=this.packToString(arg0);
 		//更新最后一条读报文
@@ -112,31 +111,73 @@
 	    DBSession sn=null;
 	    String result=null;
 	    String flag=null;
+		//上片
+		if(id==2){
+			try{
+				JSONObject jSONObject=httpApi.selectLoadRack();
+//				JSONObject jSONObject=new JSONObject();
+//				jSONObject.put("thickness", "4");
+//				jSONObject.put("width", "3660");
+//				jSONObject.put("height", "2440");
+//				jSONObject.put("sameCount", "1");
+//				jSONObject.put("glassType", "string");
+				if (jSONObject!=null){
+					//创建连接
+					sn=this.db.createSession(false);
+					Connection con= sn.getConnection();
+					//调用那个存储过程
+					CallableStatement sql=con.prepareCall("{call Total_method_load(?,?,?,?,?,?,?,?)}");
+					sql.registerOutParameter(7, java.sql.Types.VARCHAR);
+					sql.registerOutParameter(8, java.sql.Types.VARCHAR);
+					sql.setString(1, s);
+					sql.setLong(2, id);
+					sql.setDouble(3, Double.valueOf(jSONObject.get("width").toString()) );
+					sql.setDouble(4, Double.valueOf(jSONObject.get("height").toString()) );
+					sql.setDouble(5, Double.valueOf(jSONObject.get("thickness").toString()) );
+					sql.setLong(6, Integer.valueOf(jSONObject.get("sameCount").toString()) );
+					sql.execute();
+					//读取返回参数
+					result= sql.getString(7);
+					flag= sql.getString(8);//1 表示任务完成数量减一
+					if ("1".equals(flag) ){
+						for (int i=0;i<1;){
+							JSONObject loadRackReductionJson=httpApi.loadRackReduction();
+							if ("true".equals(loadRackReductionJson.get("success").toString())){
+								//调用成功
+								i++;
+								break;
+							}
+						}
 
-	    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();
+			}
+		}else{
+			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();
-	    	
-	    }
-	
+			}catch(Exception e){
+				e.printStackTrace();
+			}finally{
+				sn.close();
+			}
+		}
 	    if(result!=null){
 	    	if(result.length()>0){
 	    	char c=result.charAt(0);

--
Gitblit v1.8.0