|
@@ -39,6 +39,7 @@ public class MssqlUtil {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 白柸布库存
|
|
* 白柸布库存
|
|
|
|
+ *
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
public static List<VmsStock> vmsStock() {
|
|
public static List<VmsStock> vmsStock() {
|
|
@@ -95,33 +96,44 @@ public class MssqlUtil {
|
|
|
|
|
|
/**
|
|
/**
|
|
* mes当前库存
|
|
* mes当前库存
|
|
|
|
+ *
|
|
* @param localDate 当前时间
|
|
* @param localDate 当前时间
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
public static Map<String, Object> mesStock(LocalDate localDate) {
|
|
public static Map<String, Object> mesStock(LocalDate localDate) {
|
|
|
|
+ HashMap<String, Object> initMap = new HashMap<>();
|
|
|
|
+ initMap.put("d-in", 0);
|
|
|
|
+ initMap.put("d-out", 0);
|
|
|
|
+ initMap.put("m-in", 0);
|
|
|
|
+ initMap.put("m-out", 0);
|
|
Map<String, Object> mapping = new HashMap<>();
|
|
Map<String, Object> mapping = new HashMap<>();
|
|
- mapping.put("成辅仓库", "cp");
|
|
|
|
- mapping.put("原料仓库", "ycl");
|
|
|
|
- mapping.put("白坯仓库", "bpb");
|
|
|
|
- mapping.put("盘头仓库", "pt");
|
|
|
|
|
|
+ mapping.put("WH08", "cp");
|
|
|
|
+ mapping.put("WH01", "ycl");
|
|
|
|
+ mapping.put("WH04", "bpb");
|
|
|
|
+ mapping.put("WH03", "pt");
|
|
Map<String, Object> result = new HashMap<>(16);
|
|
Map<String, Object> result = new HashMap<>(16);
|
|
Map<String, Object> ycl = new HashMap<>();
|
|
Map<String, Object> ycl = new HashMap<>();
|
|
- ycl.put("fdy", new HashMap<>());
|
|
|
|
- ycl.put("poy", new HashMap<>());
|
|
|
|
- ycl.put("dty", new HashMap<>());
|
|
|
|
|
|
+ ycl.put("fdy", initMap.clone());
|
|
|
|
+ ycl.put("poy", initMap.clone());
|
|
|
|
+ ycl.put("dty", initMap.clone());
|
|
|
|
+
|
|
result.put("ycl", ycl);
|
|
result.put("ycl", ycl);
|
|
- result.put("cp", new HashMap<>());
|
|
|
|
- result.put("bpb", new HashMap<>());
|
|
|
|
- result.put("pt", new HashMap<>());
|
|
|
|
|
|
+ result.put("cp", initMap.clone());
|
|
|
|
+ result.put("bpb", initMap.clone());
|
|
|
|
+ result.put("pt", initMap.clone());
|
|
String[] sqls = new String[4];
|
|
String[] sqls = new String[4];
|
|
|
|
+ String inPrefix = "select 仓库编码 as code,仓库名称 as name,物料类型 as type,sum(当日入库量) as num,sum(try_cast(单托_支数_米数 as decimal)) as n2 from V_MES_SHANGJIA";
|
|
|
|
+ String outPrefix = "select 仓库编码 as code,仓库名称 as name,物料类型 as type,sum(当日出库量) as num,sum(try_cast(单托_支数_米数 as decimal)) as n2 from V_MES_FAYUN";
|
|
|
|
+ String where = " where DATEPART(year, 时间)=" + localDate.getYear() + " and DATEPART(month, 时间)=" + localDate.getMonthValue();
|
|
|
|
+ String suffix = " group by 仓库编码,仓库名称,物料类型";
|
|
//当日入库
|
|
//当日入库
|
|
- 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[0] = inPrefix + where + " and DATEPART(day, 时间)=" + localDate.getDayOfMonth() + suffix;
|
|
//当日出库
|
|
//当日出库
|
|
- 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[1] = outPrefix + where + " and DATEPART(day, 时间)=" + localDate.getDayOfMonth() + suffix;
|
|
//当月入库
|
|
//当月入库
|
|
- 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[2] = inPrefix + where + suffix;
|
|
//当月出库
|
|
//当月出库
|
|
- 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 仓库名称,物料类型";
|
|
|
|
|
|
+ sqls[3] = outPrefix + where + suffix;
|
|
try {
|
|
try {
|
|
//第一步:加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责
|
|
//第一步:加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责
|
|
Class.forName(DB_DRIVER);
|
|
Class.forName(DB_DRIVER);
|
|
@@ -133,8 +145,9 @@ public class MssqlUtil {
|
|
for (int i = 0; i < sqls.length; i++) {
|
|
for (int i = 0; i < sqls.length; i++) {
|
|
try (ResultSet rs = statement.executeQuery(sqls[i])) {
|
|
try (ResultSet rs = statement.executeQuery(sqls[i])) {
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
|
|
+ String code = rs.getString("code");
|
|
String name = rs.getString("name");
|
|
String name = rs.getString("name");
|
|
- Map<String, Object> map = (Map<String, Object>) result.get(mapping.get(name));
|
|
|
|
|
|
+ Map<String, Object> map = (Map<String, Object>) result.get(mapping.get(code));
|
|
String type = rs.getString("type");
|
|
String type = rs.getString("type");
|
|
String key = "";
|
|
String key = "";
|
|
switch (i + 1) {
|
|
switch (i + 1) {
|
|
@@ -154,19 +167,22 @@ public class MssqlUtil {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
Integer num = rs.getInt("num");
|
|
Integer num = rs.getInt("num");
|
|
-
|
|
|
|
- if ("原料仓库".equals(name)) {
|
|
|
|
|
|
+ Integer num2 = rs.getInt("n2");
|
|
|
|
+ double num3 = rs.getDouble("n2");
|
|
|
|
+ System.err.println(code+"\t"+num+"\t"+num2+"\t"+num3);
|
|
|
|
+ if ("WH01".equals(code)) {
|
|
Map<String, Object> cm;
|
|
Map<String, Object> cm;
|
|
if (type.startsWith("FDY")) {
|
|
if (type.startsWith("FDY")) {
|
|
cm = (Map<String, Object>) map.get("fdy");
|
|
cm = (Map<String, Object>) map.get("fdy");
|
|
- } else if (type.startsWith("POY")) {
|
|
|
|
- cm = (Map<String, Object>) map.get("poy");
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else if (type.startsWith("DTY")) {
|
|
cm = (Map<String, Object>) map.get("dty");
|
|
cm = (Map<String, Object>) map.get("dty");
|
|
|
|
+ } else {
|
|
|
|
+ cm = (Map<String, Object>) map.get("poy");
|
|
}
|
|
}
|
|
cm.put(key, num);
|
|
cm.put(key, num);
|
|
} else {
|
|
} else {
|
|
- map.put(key, num);
|
|
|
|
|
|
+ int oldNum = (int) map.get(key);
|
|
|
|
+ map.put(key, num + oldNum);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -181,8 +197,9 @@ public class MssqlUtil {
|
|
|
|
|
|
/**
|
|
/**
|
|
* mes趋势
|
|
* mes趋势
|
|
|
|
+ *
|
|
* @param localDate 当前时间
|
|
* @param localDate 当前时间
|
|
- * @return 结果
|
|
|
|
|
|
+ * @return 结果
|
|
*/
|
|
*/
|
|
public static Map<String, MesStock> mesTrend(LocalDate localDate) {
|
|
public static Map<String, MesStock> mesTrend(LocalDate localDate) {
|
|
Map<String, MesStock> map = new HashMap<>();
|
|
Map<String, MesStock> map = new HashMap<>();
|
|
@@ -241,6 +258,7 @@ public class MssqlUtil {
|
|
|
|
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
+
|
|
public static void main(String[] args) throws Exception {
|
|
public static void main(String[] args) throws Exception {
|
|
Map<String, Object> map = mesStock(LocalDate.now());
|
|
Map<String, Object> map = mesStock(LocalDate.now());
|
|
System.err.println(map);
|
|
System.err.println(map);
|