| 
					
				 | 
			
			
				@@ -0,0 +1,178 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.jjt; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ruoyi.order.domain.MesStock; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.sql.Connection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.sql.DriverManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.sql.ResultSet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.sql.Statement; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.time.LocalDate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @author wukai 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class MssqlTest { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * SQLServer本地驱动的地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final String DB_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 连接sqlserver数据库;本地连接;通过1433号端口号连接(根据你自身数据库的端口号来),数据库名称DBMS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 你需要现在Sql Server客户端上建立一个数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final String DB_URL = "jdbc:sqlserver://wmsdb.tlct.com.cn:1433;databaseName=WMS_V2_1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 用户名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final String USER = "MES"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final String PASSWORD = "MES"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static Map<String, Object> mesStock(LocalDate localDate) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> mapping = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mapping.put("成辅仓库", "cp"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mapping.put("原料仓库", "ycl"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mapping.put("白坯仓库", "bpb"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mapping.put("盘头仓库", "pt"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> result = new HashMap<>(16); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> ycl = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ycl.put("fdy", new HashMap<>()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ycl.put("poy", new HashMap<>()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result.put("ycl", ycl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result.put("cp", new HashMap<>()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result.put("bpb", new HashMap<>()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result.put("pt", new HashMap<>()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] sqls = new String[4]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //当日入库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sqls[0] = "select 仓库名称 as name,物料类型 as type,sum(当日入库量) as num from V_MES_SHANGJIA where DATEPART(year, 时间)=" + localDate.getYear() + " and DATEPART(month, 时间)=" + localDate.getMonthValue() + " and DATEPART(day, 时间)=" + localDate.getDayOfMonth() + " group by 仓库名称,物料类型"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //当日出库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sqls[1] = "select 仓库名称 as name,物料类型 as type,sum(当日出库量) as num from V_MES_FAYUN where DATEPART(year, 时间)=" + localDate.getYear() + " and DATEPART(month, 时间)=" + localDate.getMonthValue() + " and DATEPART(day, 时间)=" + localDate.getDayOfMonth() + " group by 仓库名称,物料类型"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //当月入库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sqls[2] = "select 仓库名称 as name,物料类型 as type,sum(当日入库量) as num from V_MES_SHANGJIA where DATEPART(year, 时间)=" + localDate.getYear() + " and DATEPART(month, 时间)=" + localDate.getMonthValue() + " group by 仓库名称,物料类型"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //当月出库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sqls[3] = "select 仓库名称 as name,物料类型 as type,sum(当日出库量) as num from V_MES_FAYUN where DATEPART(year, 时间)=" + localDate.getYear() + " and DATEPART(month, 时间)=" + localDate.getMonthValue() + " group by 仓库名称,物料类型"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //第一步:加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Class.forName(DB_DRIVER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASSWORD); Statement statement = conn.createStatement()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //第二步:根据连接协议、用户名、密码连接数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //第三步:进行数据库的数据操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //取得Statement对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //当日出库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (int i = 0; i < sqls.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    try (ResultSet rs = statement.executeQuery(sqls[i])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        while (rs.next()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String name = rs.getString("name"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Map<String, Object> map = (Map<String, Object>) result.get(mapping.get(name)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String type = rs.getString("type"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String key = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            switch (i + 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                case 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    key = "d-in"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                case 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    key = "d-out"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                case 3: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    key = "m-in"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                case 4: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    key = "m-out"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Integer num = rs.getInt("num"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if ("原料仓库".equals(name)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Map<String, Object> cm; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                if (type.startsWith("FDY")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    cm = (Map<String, Object>) map.get("fdy"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    cm = (Map<String, Object>) map.get("poy"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                cm.put(key, num); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                map.put(key, num); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static void trend(LocalDate localDate) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, MesStock> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        LocalDate start = localDate.minusMonths(11).withDayOfMonth(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        LocalDate start = localDate.minusDays(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.err.println(start); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] sqls = new String[2]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sqls[0] = "select 仓库编码 as code,仓库名称 as name,物料类型 as type,时间 as date,sum(当日出库量) num from V_MES_FAYUN where convert(date,时间)>=convert(date,'" + start + "')" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                " group by 仓库编码,仓库名称,物料类型,时间  order by 时间"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sqls[1] = "select 仓库编码 as code,仓库名称 as name,物料类型 as type,时间 as date,sum(当日入库量) num from V_MES_SHANGJIA where convert(date,时间)>=convert(date,'" + start + "')" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                " group by 仓库编码,仓库名称,物料类型,时间  order by 时间"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //第一步:加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Class.forName(DB_DRIVER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASSWORD); Statement statement = conn.createStatement()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //第二步:根据连接协议、用户名、密码连接数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //第三步:进行数据库的数据操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //取得Statement对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //当日出库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (int i = 0; i < sqls.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    try (ResultSet rs = statement.executeQuery(sqls[i])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        while (rs.next()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String code = rs.getString("code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String name = rs.getString("name"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String type = rs.getString("type"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String date = rs.getString("date"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Integer num = rs.getInt("num"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String key = code + type + date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            String[] tmp = date.split("-"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            int year = Integer.parseInt(tmp[0]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            int month = Integer.parseInt(tmp[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            int day = Integer.parseInt(tmp[2]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            MesStock mesStock = map.get(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (mesStock == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                mesStock = new MesStock(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setKey(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setDate(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setYear(year); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setMonth(month); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setDay(day); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setCode(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setName(name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            mesStock.setType(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (i == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                mesStock.setOutNum(num); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                mesStock.setInNum(num); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            map.put(key, mesStock); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.err.println(map.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static void main(String[] args) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        LocalDate localDate = LocalDate.now(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        trend(localDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |