wukai пре 5 месеци
родитељ
комит
aa6b5221cb

+ 4 - 1
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinCalcDayServiceImpl.java

@@ -340,7 +340,10 @@ public class TwinCalcDayServiceImpl implements ITwinCalcDayService {
             calcDay.calcHours(hours);
             int num = 0;
             for (TwinCalcHour hour : hours) {
-                BigDecimal v = resultMap.get(hour.getDeviceId());
+                BigDecimal v = BigDecimal.ZERO;
+                if (resultMap.get(hour.getDeviceId()) != null) {
+                    v = resultMap.get(hour.getDeviceId());
+                }
                 v.add(hour.getLength());
                 if (v.doubleValue() > 0d) {
                     num++;

+ 40 - 22
ruoyi-admin/src/main/java/com/ruoyi/order/utils/MssqlUtil.java

@@ -39,6 +39,7 @@ public class MssqlUtil {
 
     /**
      * 白柸布库存
+     *
      * @return 结果
      */
     public static List<VmsStock> vmsStock() {
@@ -95,33 +96,44 @@ public class MssqlUtil {
 
     /**
      * mes当前库存
+     *
      * @param localDate 当前时间
      * @return 结果
      */
     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<>();
-        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> 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("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 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 {
             //第一步:加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责
             Class.forName(DB_DRIVER);
@@ -133,8 +145,9 @@ public class MssqlUtil {
                 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");
-                            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 key = "";
                             switch (i + 1) {
@@ -154,19 +167,22 @@ public class MssqlUtil {
                                     break;
                             }
                             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;
                                 if (type.startsWith("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");
+                                } else {
+                                    cm = (Map<String, Object>) map.get("poy");
                                 }
                                 cm.put(key, num);
                             } else {
-                                map.put(key, num);
+                                int oldNum = (int) map.get(key);
+                                map.put(key, num + oldNum);
                             }
 
                         }
@@ -181,8 +197,9 @@ public class MssqlUtil {
 
     /**
      * mes趋势
+     *
      * @param localDate 当前时间
-     * @return  结果
+     * @return 结果
      */
     public static Map<String, MesStock> mesTrend(LocalDate localDate) {
         Map<String, MesStock> map = new HashMap<>();
@@ -241,6 +258,7 @@ public class MssqlUtil {
 
         return map;
     }
+
     public static void main(String[] args) throws Exception {
         Map<String, Object> map = mesStock(LocalDate.now());
         System.err.println(map);