From 1c15675ba61ccc30eedc508a73e799367deae603 Mon Sep 17 00:00:00 2001 From: yiming Date: Thu, 12 May 2022 14:20:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=98=E7=82=B9lotnum=E6=89=B9=E6=AC=A1?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zhehekeji/common/util/FileUtil.java | 59 +++++++++++++++++++ .../web/service/StockLogService.java | 2 +- .../zhehekeji/web/service/StockService.java | 25 ++++---- .../zhehekeji/web/service/WarnService.java | 6 -- .../web/service/ksec/KsecDecoder.java | 6 ++ .../web/service/ksec/KsecNettyClient.java | 5 ++ .../web/service/sick/SickSocket.java | 5 ++ 7 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 modules/common/src/main/java/com/zhehekeji/common/util/FileUtil.java diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/FileUtil.java b/modules/common/src/main/java/com/zhehekeji/common/util/FileUtil.java new file mode 100644 index 0000000..c56f19d --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/FileUtil.java @@ -0,0 +1,59 @@ +package com.zhehekeji.common.util; + +import lombok.extern.slf4j.Slf4j; + +import java.io.*; + +@Slf4j +public class FileUtil { + + public static void save(String text,String path){ + + //判断文件是否存在 + File file = new File(path); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + try { + FileOutputStream fileOutputStream = new FileOutputStream(file); + fileOutputStream.write(text.getBytes()); + fileOutputStream.close(); + log.info("write text success :{}",text); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String getText(String path){ + File file = new File(path); + if(file.exists()){ + try { + FileInputStream fileInputStream = new FileInputStream(file); + byte[] bytes = new byte[1024];//定义字节长度 + int len = 0; + String txt = null; + while ((len = fileInputStream.read(bytes)) != -1) {//与文件读取出来的长度比较,内部有数据读完是-1,所以不等于-1 + txt = new String(bytes, 0, len);//从0取到有数据的末尾 + } + + fileInputStream.close(); + return txt; + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + + } + + public static void main(String[] args) { + String path = "./lotnum_now"; + save("www",path); + getText(path); + } +} diff --git a/web/src/main/java/com/zhehekeji/web/service/StockLogService.java b/web/src/main/java/com/zhehekeji/web/service/StockLogService.java index dc59286..88a3f9d 100644 --- a/web/src/main/java/com/zhehekeji/web/service/StockLogService.java +++ b/web/src/main/java/com/zhehekeji/web/service/StockLogService.java @@ -50,7 +50,7 @@ public class StockLogService { if(search.getColumn() != null && search.getColumn() != 0){ wrapper.eq("`column`",search.getColumn()); } - wrapper.orderByDesc("shelve_id","`row`","`column`"); + wrapper.orderByDesc("shelve_id","`row`","`column`","id"); ListstockChecks = checkLogMapper.selectList(wrapper); return new PageInfo<>(stockChecks); diff --git a/web/src/main/java/com/zhehekeji/web/service/StockService.java b/web/src/main/java/com/zhehekeji/web/service/StockService.java index fd29418..180f379 100644 --- a/web/src/main/java/com/zhehekeji/web/service/StockService.java +++ b/web/src/main/java/com/zhehekeji/web/service/StockService.java @@ -136,11 +136,13 @@ public class StockService { for(String columnTab: rowColumnStatus.getColumnTabs()){ if(isRowColumnInTab(stock,columnTab,false)){ tabStatus(stock,columnTabStatus,columnTab); - if(columnTabCorrectCount.get(columnTab) == null){ - columnTabCorrectCount.put(columnTab,1); - }else { - int c = columnTabCorrectCount.get(columnTab); - columnTabCorrectCount.put(columnTab,c+1); + if(stock.getStatus() != 0 && stock.getStatus() != 1){ + if(columnTabCorrectCount.get(columnTab) == null){ + columnTabCorrectCount.put(columnTab,1); + }else { + int c = columnTabCorrectCount.get(columnTab); + columnTabCorrectCount.put(columnTab,c+1); + } } } } @@ -151,7 +153,7 @@ public class StockService { String [] strings = entry.getKey().split(" - "); Integer tabStart = Integer.valueOf(strings[0]); Integer tabEnd = Integer.valueOf(strings[1]); - int counts = (tabEnd- tabStart) * rows; + int counts = (tabEnd- tabStart + 1) * rows; if(counts == entry.getValue()){ rowTabStatus.put(entry.getKey(),2); } @@ -160,7 +162,7 @@ public class StockService { String [] strings = entry.getKey().split(" - "); Integer tabStart = Integer.valueOf(strings[0]); Integer tabEnd = Integer.valueOf(strings[1]); - int counts = (tabEnd- tabStart) * rows; + int counts = (tabEnd- tabStart + 1) * rows; if(counts == entry.getValue()){ columnTabStatus.put(entry.getKey(),2); } @@ -307,11 +309,10 @@ public class StockService { Stock stock = stockInfo(stockCheck); Assert.isTrue(stock != null && stock.getId() != null, "该货位暂时没有记录"); Integer oldStatus = stock.getStatus(); - if(StockStatus.SUCCESS.getStatus().equals(oldStatus)){ - return stock; - } + Assert.isTrue(StockStatus.ERROR.getStatus().equals(oldStatus), "无需核对"); + log.info("check stock correct, shelveID:{},row:{},column:{}", stockCheck.getShelveId(), stockCheck.getRow(), stockCheck.getColumn()); - stock.setStatus(StockStatus.SUCCESS.getStatus()); + stock.setStatus(StockStatus.MANUAL.getStatus()); stockMapper.updateById(stock); checkLog(stock); return stock; @@ -322,6 +323,8 @@ public class StockService { private void checkLog(Stock stock){ CheckLog checkLog = new CheckLog(); + checkLog.setRow(stock.getRow()); + checkLog.setColumn(stock.getColumn()); checkLog.setCheckNum(stock.getCheckNum()); checkLog.setPic(stock.getCheckPic()); checkLog.setShelveId(stock.getShelveId()); diff --git a/web/src/main/java/com/zhehekeji/web/service/WarnService.java b/web/src/main/java/com/zhehekeji/web/service/WarnService.java index 82d50b3..ed215c8 100644 --- a/web/src/main/java/com/zhehekeji/web/service/WarnService.java +++ b/web/src/main/java/com/zhehekeji/web/service/WarnService.java @@ -35,12 +35,6 @@ public class WarnService { int remainingSeconds = seconds.intValue() % 60; String timeLength = String.format("%02d:%02d", minutes,remainingSeconds); warnVO.setTimeLength(timeLength); - if(configProperties.getCameraConfig().getCameraType() == 1 && !StringUtils.isEmpty(warnVO.getVideoPath1())){ - warnVO.setCmd1(" VSPlayer "+ warnVO.getVideoPath1()); - } - if(configProperties.getCameraConfig().getCameraType() == 1 && !StringUtils.isEmpty(warnVO.getVideoPath2())){ - warnVO.setCmd1(" VSPlayer "+ warnVO.getVideoPath2()); - } } }); diff --git a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecDecoder.java b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecDecoder.java index 100b3de..605fcb8 100644 --- a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecDecoder.java +++ b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecDecoder.java @@ -1,6 +1,7 @@ package com.zhehekeji.web.service.ksec; import com.alibaba.fastjson.JSONObject; +import com.zhehekeji.common.util.FileUtil; import com.zhehekeji.web.pojo.Cmd; import com.zhehekeji.web.service.GoodsActionTimes; import com.zhehekeji.web.service.PlcCmdInfo; @@ -23,6 +24,10 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder { private static final Logger tcpLogger = LoggerFactory.getLogger("tcp"); + public static void setLastLotnum(String lotnum){ + lastLotnum = lotnum; + } + private static String lastLotnum; private PlcService plcService; @@ -108,6 +113,7 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder { if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){ //需要把stock表truncate + FileUtil.save(lotnum,"lastLotnum"); tcpLogger.info("truncate table ,last lotnum:{},new lotnum:{}",lastLotnum,lotnum); plcService.truncateStock(); lastLotnum = lotnum; diff --git a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java index 2c074f2..e5e3b25 100644 --- a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java +++ b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java @@ -1,6 +1,7 @@ package com.zhehekeji.web.service.ksec; +import com.zhehekeji.common.util.FileUtil; import com.zhehekeji.web.config.ConfigProperties; import com.zhehekeji.web.service.PlcService; import io.netty.bootstrap.Bootstrap; @@ -32,6 +33,10 @@ public class KsecNettyClient { private static Channel channel; public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException { + String lotnum = FileUtil.getText("lastLotnum"); + if(lotnum != null){ + KsecDecoder.setLastLotnum(lotnum); + } if (StringUtils.isEmpty(ksec.getIp()) || ksec.getPort() == null) { return; } diff --git a/web/src/main/java/com/zhehekeji/web/service/sick/SickSocket.java b/web/src/main/java/com/zhehekeji/web/service/sick/SickSocket.java index fe84805..4712b26 100644 --- a/web/src/main/java/com/zhehekeji/web/service/sick/SickSocket.java +++ b/web/src/main/java/com/zhehekeji/web/service/sick/SickSocket.java @@ -1,6 +1,8 @@ package com.zhehekeji.web.service.sick; import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.net.InetSocketAddress; @@ -13,6 +15,7 @@ import java.nio.charset.StandardCharsets; @Slf4j public class SickSocket { + private static final Logger tcpLogger = LoggerFactory.getLogger("sick"); public static void main(String[] args) { String code = readOCR("192.168.8.236", 2002); System.out.println(code); @@ -29,10 +32,12 @@ public class SickSocket { writeCmd(os); is = socket.getInputStream(); code = read(is); + tcpLogger.info(code); if(code!= null){ code = code.replace("\\n",""); } } catch (IOException e) { + tcpLogger.error("sick time out,ip:{},info:{}",ip,e); log.error("sick time out,ip:{},info:{}",ip,e); }finally { if(os != null){