浏览代码

修复BUG

wukai 5 月之前
父节点
当前提交
0c9bd35185

+ 20 - 8
ruoyi-admin/src/main/java/com/ruoyi/order/controller/OrderApiController.java

@@ -6,6 +6,7 @@ import com.ruoyi.biz.service.ITwinCalcDayService;
 import com.ruoyi.biz.service.ITwinFormulaInfoService;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.order.domain.MesStock;
 import com.ruoyi.order.domain.TwinOrder;
 import com.ruoyi.order.domain.TwinOrderDetail;
 import com.ruoyi.order.domain.VmsStock;
@@ -61,12 +62,23 @@ public class OrderApiController extends BaseController {
     @GetMapping("/api/stock")
     @CrossOrigin(origins = "*")
     @ResponseBody
-    public Map<String, Object> stock() {
+    public Map<String, Object> mesStock() {
         LocalDate localDate = LocalDate.now();
         return MssqlUtil.mesStock(localDate);
     }
 
-    @ApiOperation("导出白胚预测")
+    @ApiOperation("查看当前库存")
+    @GetMapping("/api/mes-trend")
+    @CrossOrigin(origins = "*")
+    @ResponseBody
+    public Map<String, MesStock> mesTrend() {
+        LocalDate localDate = LocalDate.now();
+        Map<String, MesStock> map = MssqlUtil.mesTrend(localDate);
+        List<MesStock> mesList = new ArrayList<>(map.values());
+        return map;
+    }
+
+    @ApiOperation("导出白柸预测")
     @GetMapping("/api/export/order")
     @CrossOrigin(origins = "*")
     public void orderExport(String start, String end, HttpServletResponse response) {
@@ -94,7 +106,7 @@ public class OrderApiController extends BaseController {
         List<SkuVO> skuList = new ArrayList<>();
         for (String spec : allMap.keySet()) {
             List<TwinOrderDetail> todList = allMap.get(spec);
-            //匹配白布库存
+            //匹配白布库存
             Float kc = 0f;
             VmsStock stock = matchStock(spec, stocks);
             if (stock != null) {
@@ -181,7 +193,7 @@ public class OrderApiController extends BaseController {
             bk.setFillPattern(FillPatternType.SOLID_FOREGROUND);
             XSSFSheet sheet0 = wb.getSheetAt(0);
             Cell title = sheet0.getRow(0).getCell(0);
-            title.setCellValue("白布靶向生产测算-10天(" + start + " 至 " + end + ")");
+            title.setCellValue("白布靶向生产测算-10天(" + start + " 至 " + end + ")");
 
             sheet0(sheet0, bomList);
             sheet1(wb.getSheetAt(1), stocks);
@@ -194,7 +206,7 @@ public class OrderApiController extends BaseController {
             //Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
             //attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
             // filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
-            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("白布靶向预测" + start + "至" + end + ".xlsx", "UTF-8"));
+            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("白布靶向预测" + start + "至" + end + ".xlsx", "UTF-8"));
             response.setContentType("application/octet-stream");
             wb.write(outputStream);
             outputStream.flush();
@@ -302,7 +314,7 @@ public class OrderApiController extends BaseController {
     }
 
     /**
-     * 白布全量
+     * 白布全量
      *
      * @param sheet  sheet
      * @param stocks 库存
@@ -326,7 +338,7 @@ public class OrderApiController extends BaseController {
     }
 
     /**
-     * 白库存匹配
+     * 白库存匹配
      *
      * @param sheet   sheet
      * @param skuList 库存
@@ -468,7 +480,7 @@ public class OrderApiController extends BaseController {
 
 
     /**
-     * 白布库存--全量
+     * 白布库存--全量
      *
      * @param sheet sheet
      * @param infos 库存

+ 38 - 0
ruoyi-admin/src/main/java/com/ruoyi/order/domain/MesStock.java

@@ -0,0 +1,38 @@
+package com.ruoyi.order.domain;
+
+import com.ruoyi.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * mes库存
+ *
+ * @author ruoyi
+ * @date 2024-12-30
+ */
+@ApiModel(value = "MesStock", description = "mes库存")
+@Data
+public class MesStock extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+    @ApiModelProperty("仓库编码")
+    private String code;
+    @ApiModelProperty("仓库名称")
+    private String name;
+    @ApiModelProperty("仓库类型")
+    private String type;
+    @ApiModelProperty("入库数量")
+    private Integer inNum;
+    @ApiModelProperty("出库数量")
+    private Integer outNum;
+    @ApiModelProperty("年")
+    private Integer year;
+    @ApiModelProperty("月")
+    private Integer month;
+    @ApiModelProperty("日")
+    private Integer day;
+    @ApiModelProperty("时间")
+    private String date;
+    @ApiModelProperty("key")
+    private String key;
+}

+ 76 - 1
ruoyi-admin/src/main/java/com/ruoyi/order/utils/MssqlUtil.java

@@ -1,5 +1,6 @@
 package com.ruoyi.order.utils;
 
+import com.ruoyi.order.domain.MesStock;
 import com.ruoyi.order.domain.VmsStock;
 
 import java.sql.Connection;
@@ -36,6 +37,10 @@ public class MssqlUtil {
      */
     private static final String PASSWORD = "MES";
 
+    /**
+     * 白柸布库存
+     * @return 结果
+     */
     public static List<VmsStock> vmsStock() {
         List<VmsStock> stocks = new ArrayList<>();
         try {
@@ -88,6 +93,11 @@ public class MssqlUtil {
         return stocks;
     }
 
+    /**
+     * mes当前库存
+     * @param localDate 当前时间
+     * @return 结果
+     */
     public static Map<String, Object> mesStock(LocalDate localDate) {
         Map<String, Object> mapping = new HashMap<>();
         mapping.put("成辅仓库", "cp");
@@ -98,6 +108,7 @@ public class MssqlUtil {
         Map<String, Object> ycl = new HashMap<>();
         ycl.put("fdy", new HashMap<>());
         ycl.put("poy", new HashMap<>());
+        ycl.put("dty", new HashMap<>());
         result.put("ycl", ycl);
         result.put("cp", new HashMap<>());
         result.put("bpb", new HashMap<>());
@@ -148,8 +159,10 @@ public class MssqlUtil {
                                 Map<String, Object> cm;
                                 if (type.startsWith("FDY")) {
                                     cm = (Map<String, Object>) map.get("fdy");
-                                } else {
+                                } else if (type.startsWith("POY")) {
                                     cm = (Map<String, Object>) map.get("poy");
+                                } else {
+                                    cm = (Map<String, Object>) map.get("dty");
                                 }
                                 cm.put(key, num);
                             } else {
@@ -166,6 +179,68 @@ public class MssqlUtil {
         return result;
     }
 
+    /**
+     * mes趋势
+     * @param localDate 当前时间
+     * @return  结果
+     */
+    public static Map<String, MesStock> mesTrend(LocalDate localDate) {
+        Map<String, MesStock> map = new HashMap<>();
+        LocalDate start = localDate.minusMonths(11).withDayOfMonth(1);
+        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();
+        }
+
+        return map;
+    }
     public static void main(String[] args) throws Exception {
         Map<String, Object> map = mesStock(LocalDate.now());
         System.err.println(map);

二进制
ruoyi-admin/src/main/resources/tpl/order.xlsx


+ 178 - 0
ruoyi-admin/src/test/java/com/jjt/MssqlTest.java

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