|
@@ -6,8 +6,11 @@ import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.Statement;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -33,7 +36,7 @@ public class MssqlUtil {
|
|
|
*/
|
|
|
private static final String PASSWORD = "MES";
|
|
|
|
|
|
- public static List<VmsStock> stock() {
|
|
|
+ public static List<VmsStock> vmsStock() {
|
|
|
List<VmsStock> stocks = new ArrayList<>();
|
|
|
try {
|
|
|
//第一步:加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责
|
|
@@ -85,8 +88,86 @@ public class MssqlUtil {
|
|
|
return stocks;
|
|
|
}
|
|
|
|
|
|
+ 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 main(String[] args) throws Exception {
|
|
|
- List<VmsStock> list = stock();
|
|
|
- System.err.println(list.size());
|
|
|
+ Map<String, Object> map = mesStock(LocalDate.now());
|
|
|
+ System.err.println(map);
|
|
|
}
|
|
|
}
|