Ver Fonte

库存相关功能修改

wukai há 5 meses atrás
pai
commit
845027c640

+ 3 - 30
ruoyi-admin/src/main/java/com/ruoyi/order/controller/OrderApiController.java

@@ -62,35 +62,8 @@ public class OrderApiController extends BaseController {
     @CrossOrigin(origins = "*")
     @ResponseBody
     public Map<String, Object> stock() {
-
-        Map<String, Object> result = new HashMap<>();
-        Map<String, Object> cp = new HashMap<>();
-        cp.put("d-in", 100);
-        cp.put("d-out", 101);
-        cp.put("m-in", 102);
-        cp.put("m-out", 103);
-        Map<String, Object> ycl = new HashMap<>();
-        ycl.put("d-in", 200);
-        ycl.put("d-out", 201);
-        ycl.put("m-in", 202);
-        ycl.put("m-out", 203);
-        Map<String, Object> bpb = new HashMap<>();
-        bpb.put("d-in", 300);
-        bpb.put("d-out", 301);
-        bpb.put("m-in", 302);
-        bpb.put("m-out", 303);
-        Map<String, Object> pt = new HashMap<>();
-        pt.put("d-in", 400);
-        pt.put("d-out", 401);
-        pt.put("m-in", 402);
-        pt.put("m-out", 403);
-
-        result.put("cp", cp);
-        result.put("ycl", ycl);
-        result.put("bpb", bpb);
-        result.put("pt", pt);
-
-        return result;
+        LocalDate localDate = LocalDate.now();
+        return MssqlUtil.mesStock(localDate);
     }
 
     @ApiOperation("导出白胚预测")
@@ -112,7 +85,7 @@ public class OrderApiController extends BaseController {
         List<TwinCalcDay> dayList = dayService.selectTwinCalcDayListByTime(sd, sd);
         //按设备ID分组
         Map<Long, TwinCalcDay> dayMap = dayList.stream().collect(Collectors.toMap(TwinCalcDay::getDeviceId, o -> o));
-        List<VmsStock> stocks = MssqlUtil.stock();
+        List<VmsStock> stocks = MssqlUtil.vmsStock();
         List<TwinOrderDetail> all = new ArrayList<>();
         orderList.forEach(to -> all.addAll(to.getTwinOrderDetailList()));
         //按规格分组

+ 84 - 3
ruoyi-admin/src/main/java/com/ruoyi/order/utils/MssqlUtil.java

@@ -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);
     }
 }

+ 1 - 1
ruoyi-admin/src/test/java/com/jjt/OrderTest.java

@@ -51,7 +51,7 @@ public class OrderTest {
         search.setOrderDate(DateUtils.parseDate(d));
         List<TwinOrder> list = orderService.selectTwinOrderList(search);
         List<TwinFormulaInfo> infos = formulaInfoService.selectTwinFormulaInfoList(new TwinFormulaInfo());
-        List<VmsStock> stocks = MssqlUtil.stock();
+        List<VmsStock> stocks = MssqlUtil.vmsStock();
         for (TwinOrder twinOrder : list) {
 
             List<TwinOrderDetail> details = twinOrder.getTwinOrderDetailList();