Bläddra i källkod

1.按钮盒代码优化
2.条码扫描记录表更新有效标识

k 1 år sedan
förälder
incheckning
5191f07e7d

+ 10 - 0
src/main/java/com/warewms/controller/ErpWriteBackController.java

@@ -44,6 +44,16 @@ public class ErpWriteBackController {
         return erpSyncService.writeBack(erpBarCodeListList);
     }
 
+    /**
+     * 修改叉车扫描条码记录表失效标记
+     */
+    @ApiOperation("修改叉车扫描条码记录表失效标记")
+    @ResponseBody
+    @PostMapping("writeDataU")
+    public String writeDataU(@RequestBody ErpBarCodeList erpBarCodeList) {
+        return erpSyncService.writeDataU(erpBarCodeList);
+    }
+
     /**
      * 中间表修改数据(需求单扫描状态修改)
      */

+ 2 - 0
src/main/java/com/warewms/service/ErpSyncService.java

@@ -10,5 +10,7 @@ public interface ErpSyncService {
 
     String writeBack(List<ErpBarCodeList> erpBarCodeListList);
 
+    String writeDataU(ErpBarCodeList erpBarCodeList);
+
     String updateErpStatus(ErpOrderList erpOrderList);
 }

+ 29 - 13
src/main/java/com/warewms/service/impl/ErpSyncServiceImpl.java

@@ -108,26 +108,42 @@ public class ErpSyncServiceImpl implements ErpSyncService {
     public String writeBack(List<ErpBarCodeList> erpBarCodeListList) {
         for (ErpBarCodeList erpBarCodeList : erpBarCodeListList) {
             Kv param = Kv.create();
-            param.set("barcode",erpBarCodeList.getBarcode());
-            param.set("orderName",erpBarCodeList.getOrderName());
-            param.set("orderNo",erpBarCodeList.getOrderNo());
-            param.set("qty",erpBarCodeList.getQty());
-            param.set("orderType",erpBarCodeList.getOrder_type());
-            param.set("inout",erpBarCodeList.getInOut());
-            param.set("stockID",erpBarCodeList.getStockId());
-            param.set("boxid",erpBarCodeList.getBoxNo());
-            param.set("erpResult",erpBarCodeList.getErpResult());
+            param.set("barcode", erpBarCodeList.getBarcode());
+            param.set("orderName", erpBarCodeList.getOrderName());
+            param.set("orderNo", erpBarCodeList.getOrderNo());
+            param.set("qty", erpBarCodeList.getQty());
+            param.set("orderType", erpBarCodeList.getOrder_type());
+            param.set("inout", erpBarCodeList.getInOut());
+            param.set("stockID", erpBarCodeList.getStockId());
+            param.set("boxid", erpBarCodeList.getBoxNo());
+            param.set("erpResult", erpBarCodeList.getErpResult());
+            param.set("valid", erpBarCodeList.getVaild());
             param.set("createUser", erpBarCodeList.getCreateUser());
-            param.set("createDate",erpBarCodeList.getCreateDate());
+            param.set("createDate", erpBarCodeList.getCreateDate());
             //param.set("wmsMark","N");
-            SqlPara sqlPara = Db.getSqlPara("erp.insertBarcodeList",param);
+            SqlPara sqlPara = Db.getSqlPara("erp.insertBarcodeList", param);
             if (Db.update(sqlPara) == 0) {
-                throw new RRException("writeBack失败!");
+                return "500";
             }
         }
         return "200";
     }
 
+    @JFinalTx
+    @Override
+    public String writeDataU(ErpBarCodeList erpBarCodeList) {
+        Kv param = Kv.create();
+        param.set("barcode", erpBarCodeList.getBarcode());
+        param.set("orderName", erpBarCodeList.getOrderName());
+        param.set("orderNo", erpBarCodeList.getOrderNo());
+        param.set("valid", erpBarCodeList.getVaild());
+        SqlPara sqlPara = Db.getSqlPara("erp.updateBarcodeList", param);
+        if (Db.update(sqlPara) == 0) {
+            return "500";
+        }
+        return "200";
+    }
+
     @Override
     public String updateErpStatus(ErpOrderList erpOrderList) {
 
@@ -137,7 +153,7 @@ public class ErpSyncServiceImpl implements ErpSyncService {
         param.put("orderName", erpOrderList.getOrderName());
         SqlPara update = Db.getSqlPara("erp.updateErpStatus", param);
 
-        if(Db.update(update) == 0){
+        if (Db.update(update) == 0) {
             return "500";
         }
         return "200";

+ 53 - 26
src/main/java/com/warewms/thread/ReadClientDataThread.java

@@ -1,5 +1,6 @@
 package com.warewms.thread;
 
+import com.warewms.common.utils.ByteUtil;
 import com.warewms.common.utils.R;
 import com.warewms.common.utils.SpringContextUtils;
 import com.warewms.form.BtnOpForm;
@@ -19,6 +20,7 @@ public class ReadClientDataThread implements Runnable {
     private InputStream is = null;
     private OutputStream os = null;
     private String ipHome = null;
+    private Socket socket = null;
 
     public ReadClientDataThread(Socket socket) {
         try {
@@ -26,6 +28,7 @@ public class ReadClientDataThread implements Runnable {
             ipHome = address.getHostAddress();
             is = socket.getInputStream();
             os = socket.getOutputStream();
+            socket = socket;
         } catch (IOException e) {
             System.out.println("获取已连接会话中的输入流出现了错误:\n");
             e.printStackTrace();
@@ -41,41 +44,65 @@ public class ReadClientDataThread implements Runnable {
             WcsTransitionUtils wcsTransitionUtils = new WcsTransitionUtils();
             BtnService buttonTaskService = (BtnService) SpringContextUtils.getBean("btnServiceImpl");//注入ben
             R r = new R();
-
-            while ((len = is.read(bytes)) != -1) {
-                log.info("________________");
-                log.info("客户端地址:" + ipHome);
-                log.info("________________");
+            while (true) {
                 try {
-                    //02EACDF2CDF2CBEA0202
-                    //CBEACDF2CDF2CBEA0202
-                    //请求参数
-                    BtnOpForm btnOpForm = new BtnOpForm();
-                    btnOpForm.setIp(ipHome);
-                    String orderText = wcsTransitionUtils.bytesToHexString(bytes).replace(" ", "");
-                    //System.out.println(orderText);
-                    if (orderText.equals("2A0163030203016D2424")) {
-                        btnOpForm.setOpType("CLOSE");
-                        buttonTaskService.opBtn(btnOpForm);
-                        log.info("控制-------------------》");
-                    } else if (orderText.equals("2A0163030204016E2424")) {
-                        btnOpForm.setOpType("OPEN");
-                        buttonTaskService.opBtn(btnOpForm);
-                        log.info("解除控制-------------------》");
-                    } else {
-                        //log.info("过滤无效的指令");
-                    }
-                } catch (Exception e) {
-                    log.error("调用接口下达任务出现异常-异常原因如下:");
-                    log.error(e.getMessage());
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
                     e.printStackTrace();
                 }
+                // 服务器向客户端写,如果客户端断开了,这边会抛出异常,释放线程
+                os.write(ByteUtil.hexString2ByteArray("0000000000"));
+                while ((len = is.read(bytes)) != -1) {
+                    log.info("________________");
+                    log.info("客户端地址:" + ipHome);
+                    log.info("________________");
+                    try {
+                        //02EACDF2CDF2CBEA0202
+                        //CBEACDF2CDF2CBEA0202
+                        //请求参数
+                        BtnOpForm btnOpForm = new BtnOpForm();
+                        btnOpForm.setIp(ipHome);
+                        String orderText = wcsTransitionUtils.bytesToHexString(bytes).replace(" ", "");
+                        //System.out.println(orderText);
+                        if (orderText.equals("2A0163030203016D2424")) {
+                            btnOpForm.setOpType("CLOSE");
+                            buttonTaskService.opBtn(btnOpForm);
+                            log.info("控制-------------------》");
+                        } else if (orderText.equals("2A0163030204016E2424")) {
+                            btnOpForm.setOpType("OPEN");
+                            buttonTaskService.opBtn(btnOpForm);
+                            log.info("解除控制-------------------》");
+                        } else {
+                            //log.info("过滤无效的指令");
+                        }
+                    } catch (Exception e) {
+                        log.error("调用接口下达任务出现异常-异常原因如下:");
+                        log.error(e.getMessage());
+                        e.printStackTrace();
+                    } finally {
+                        try {
+                            is.close();
+                            os.close();
+                            socket.close();
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
             }
 
         } catch (Exception e) {
             log.error("读取按钮盒信息失败");
             log.error(e.getMessage());
             // e.printStackTrace();
+        }finally {
+            try {
+                is.close();
+                os.close();
+                socket.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 }

+ 7 - 0
src/main/java/com/warewms/thread/SocketServerThread.java

@@ -76,6 +76,13 @@ public class SocketServerThread implements Runnable{
                                     log.info(sockets.toString());
                                 }
                             }
+                            //关闭连接
+                            try {
+                                socket.close();
+                            } catch (Exception ex) {
+                                ex.printStackTrace();
+                            }
+                            throw new RuntimeException("按钮盒客户端断开,释放线程资源:" + e.getMessage());
                         }
                     }
                 }, 5000, 1000);

+ 10 - 0
src/main/resources/sql/erp.sql

@@ -46,6 +46,7 @@
         ,[STOCKID]
         ,[BOXID]
         ,[ERP_RESULT]
+        ,[VALID]
         ,[CREATE_USER]
         ,[CREATE_DATE]
         ,[DB])
@@ -59,10 +60,19 @@
             , #para(stockID)
             , #para(boxid)
             , #para(erpResult)
+            , #para(valid)
             , #para(createUser)
             , #para(createDate)
             , 'YH'
         )
 #end
 
+#sql("updateBarcodeList")
+    UPDATE ERP_BARCODE_LIST
+        SET `VALID` = #para(valid)
+    WHERE ORDER_NO = #para(orderNo)
+    AND ORDER_NAME = #para(orderName)
+    AND BARCODE = #para(barcode)
+#end
+