diff --git a/web/pom.xml b/web/pom.xml index eec8838..4be065f 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -79,11 +79,10 @@ filter 1.0.0 - com.alibaba easyexcel - 2.1.1 + 3.3.2 com.sun.jna diff --git a/web/src/main/java/com/zhehekeji/web/controller/OrderController.java b/web/src/main/java/com/zhehekeji/web/controller/OrderController.java index e9f8c3f..279b05f 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/OrderController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/OrderController.java @@ -92,6 +92,10 @@ public class OrderController { return ResultResp.success(ksecDataInfos); } + public static void main(String[] args) { + String i = "KsecInfos(header=BQ, Type=C, data=[KsecDataInfo(SRMNumber=SRM01, cmdName=C1, taskId=96d2c9a0e6664cc88e9b97c5aba02808, fromColumn=0, fromRow=0, fromStorey=0, fromDirection=2, fromSide=null, fromSeparation=0, toColumn=25, toRow=1, toStorey=6, toDirection=1, toSide=null, toSeparation=2, code=, warnCode=, ackStatus=null, trayCode=100132049539, goodsType=, goodsNumber=0, goodsTypeResult=, goodsNumberResult=0, result=0, lotnum=, fromAround=1), KsecDataInfo(SRMNumber=SRM01, cmdName=C1, taskId=f5ed012f8d92418387b4b57462928bce, fromColumn=0, fromRow=0, fromStorey=0, fromDirection=2, fromSide=null, fromSeparation=0, toColumn=26, toRow=1, toStorey=6, toDirection=1, toSide=null, toSeparation=2, code=, warnCode=, ackStatus=null, trayCode=100132049539, goodsType=, goodsNumber=0, goodsTypeResult=, goodsNumberResult=0, result=0, lotnum=, fromAround=2)])"; + } + @ApiOperation("发生告警") @GetMapping("/error") public Result orderError(@ApiParam("plc") @RequestParam String plcId){ diff --git a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java index 9d3d66a..bc967db 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java @@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; import java.util.Map; +import java.util.concurrent.*; + @Api(value = "StreetController",tags = "巷道管理") @RestController(value = "StreetController") @@ -129,6 +131,58 @@ public class StreetController { return Result.success(); } + // 在 PlcService 类中已有类似的实现 + private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10); + + private static ConcurrentHashMap> scheduledTasks = new ConcurrentHashMap<>(); + + // 添加可刷新的延时任务 + public void addRefreshableDelayTask(String taskId, Runnable task, long delaySeconds) { + // 取消已存在的任务 + ScheduledFuture existingTask = scheduledTasks.remove(taskId); + if (existingTask != null && !existingTask.isDone()) { + existingTask.cancel(false); + } + + // 添加新任务 + ScheduledFuture future = scheduler.schedule(task, delaySeconds, TimeUnit.SECONDS); + scheduledTasks.put(taskId, future); + } + + // 刷新任务时间(重新调度) + public void refreshDelayTask(String taskId, Runnable task, long delaySeconds) { + addRefreshableDelayTask(taskId, task, delaySeconds); + } + + // 取消任务 + public void cancelDelayTask(String taskId) { + ScheduledFuture existingTask = scheduledTasks.remove(taskId); + if (existingTask != null && !existingTask.isDone()) { + existingTask.cancel(false); + } + } + + public void openStreetLightSourceAsyncClose(Integer streetId){ + List lightSources = lightSourceService.getLightSourceByStreetId(streetId); + lightSources.forEach(lightSource -> { + if(configProperties.getLightSource().getType() == 1){ + JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); + JYDamHelper.openDO(equip,configProperties.getLightSource().getIndex()); + Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex()); + log.info("ip:{},status:{}",lightSource.getIp(),status); + equip.DisConnect(); + }else if(configProperties.getLightSource().getType() == 2){ + HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1); + }else if (configProperties.getLightSource().getType() == 3){ + LightSourceService.lightController(lightSource.getIp(),lightSource.getPort(),1); + } + + }); + addRefreshableDelayTask("closeLightSource"+streetId,()->{ + closeStreetLightSource(streetId); + },30); + + } @GetMapping("/lightSource/open/{streetId}") @ApiOperation(value = "开启单个巷道光源") diff --git a/web/src/main/java/com/zhehekeji/web/entity/Category.java b/web/src/main/java/com/zhehekeji/web/entity/Category.java index 7cef01d..e06fd9f 100644 --- a/web/src/main/java/com/zhehekeji/web/entity/Category.java +++ b/web/src/main/java/com/zhehekeji/web/entity/Category.java @@ -27,7 +27,7 @@ public class Category { @TableField(value = "`number`") private Integer number; - private Integer degree; + private Double degree; private Integer milliliter; private String image; diff --git a/web/src/main/java/com/zhehekeji/web/entity/Stock.java b/web/src/main/java/com/zhehekeji/web/entity/Stock.java index 1a13912..8d40b52 100644 --- a/web/src/main/java/com/zhehekeji/web/entity/Stock.java +++ b/web/src/main/java/com/zhehekeji/web/entity/Stock.java @@ -12,6 +12,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; @Data @TableName("`stock`") @@ -108,4 +109,12 @@ public class Stock { @TableField(exist=false) private String sidePic4; + // 获取格式化后的字符串 + public String getFormattedExportTime() { + if (exportTime != null) { + return exportTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } + return null; + } + } diff --git a/web/src/main/java/com/zhehekeji/web/pojo/stock/LocalDateTimeConvert.java b/web/src/main/java/com/zhehekeji/web/pojo/stock/LocalDateTimeConvert.java index f41d858..ab045d0 100644 --- a/web/src/main/java/com/zhehekeji/web/pojo/stock/LocalDateTimeConvert.java +++ b/web/src/main/java/com/zhehekeji/web/pojo/stock/LocalDateTimeConvert.java @@ -2,8 +2,8 @@ package com.zhehekeji.web.pojo.stock; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import java.time.LocalDateTime; @@ -20,21 +20,5 @@ public class LocalDateTimeConvert implements Converter { return null; } - @Override - public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { - return null; - } - - @Override - public CellData convertToExcelData(LocalDateTime localDateTime, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { - - if (localDateTime != null) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); - String time = localDateTime.format(formatter); - return new CellData(time); - } - return null; - } - } diff --git a/web/src/main/java/com/zhehekeji/web/pojo/stock/StockExportExcel.java b/web/src/main/java/com/zhehekeji/web/pojo/stock/StockExportExcel.java index b91a43f..6af134f 100644 --- a/web/src/main/java/com/zhehekeji/web/pojo/stock/StockExportExcel.java +++ b/web/src/main/java/com/zhehekeji/web/pojo/stock/StockExportExcel.java @@ -1,6 +1,7 @@ package com.zhehekeji.web.pojo.stock; import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; import lombok.Data; import java.time.LocalDateTime; @@ -11,37 +12,54 @@ public class StockExportExcel { @ExcelProperty(index = 0, value = "巷道名称") private String streetName; - @ExcelProperty(index = 8, value = "盘点批次号") + @ExcelProperty(index = 1, value = "盘点批次号") private String lotnum; - @ExcelProperty(index = 5, value = "条码") - private String code; - @ExcelProperty(index = 6, value = "WMS条码") - private String wmsCode; + @ExcelProperty(index = 2, value = "位置" ) + @ColumnWidth(30) // 设置列宽为25个字符宽度 + private String direction; +// +// @ExcelProperty(index = 2, value = "深浅,1:浅货位,2:深货位") +// private String side; +// +//// @ExcelProperty(index = 1, value = "货架号") +//// private String shelveId; +// +//// @ExcelProperty(index = 5, value = "数量") +//// private Integer count; +// +// @ExcelProperty(index = 3, value = "行") +// private String row; +// +// @ExcelProperty(index = 4, value = "列") +// private String column; - @ExcelProperty(index = 1, value = "左右,1:左侧,2:右侧") - private Integer direction; - @ExcelProperty(index = 2, value = "深浅,1:浅货位,2:深货位") - private Integer side; -// @ExcelProperty(index = 1, value = "货架号") -// private String shelveId; + @ExcelProperty(index = 3, value = "上位品规") + private String wmsCategory; -// @ExcelProperty(index = 5, value = "数量") -// private Integer count; - @ExcelProperty(index = 3, value = "行") - private Integer row; + @ExcelProperty(index = 4, value = "核对品规结果") + private String category; - @ExcelProperty(index = 4, value = "列") - private Integer column; - @ExcelProperty(index = 7, value = "盘点结果", converter = StockStatusConvert.class) - private Integer status; + @ExcelProperty(index = 5, value = "上位个数") + private Integer wmsCount; - @ExcelProperty(index = 9, value = "时间", converter = LocalDateTimeConvert.class) - private LocalDateTime exportTime; + + + @ExcelProperty(index = 6, value = "核对个数") + private Integer count; + + + + + @ExcelProperty(index = 7, value = "盘点结果") + private String status; + + @ExcelProperty(index = 8, value = "时间") + private String exportTime; } diff --git a/web/src/main/java/com/zhehekeji/web/pojo/stock/StockStatusConvert.java b/web/src/main/java/com/zhehekeji/web/pojo/stock/StockStatusConvert.java index aff4508..2067b98 100644 --- a/web/src/main/java/com/zhehekeji/web/pojo/stock/StockStatusConvert.java +++ b/web/src/main/java/com/zhehekeji/web/pojo/stock/StockStatusConvert.java @@ -2,8 +2,8 @@ package com.zhehekeji.web.pojo.stock; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; public class StockStatusConvert implements Converter { @@ -17,20 +17,6 @@ public class StockStatusConvert implements Converter { return null; } - @Override - public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { - return null; - } - - @Override - public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { - for (StockStatus orderStatus : StockStatus.values()) { - if (orderStatus.getStatus().equals(integer)) { - return new CellData(orderStatus.getName()); - } - } - return null; - } } diff --git a/web/src/main/java/com/zhehekeji/web/service/CronTab.java b/web/src/main/java/com/zhehekeji/web/service/CronTab.java index 1b15b14..1a515ad 100644 --- a/web/src/main/java/com/zhehekeji/web/service/CronTab.java +++ b/web/src/main/java/com/zhehekeji/web/service/CronTab.java @@ -16,7 +16,6 @@ import com.zhehekeji.web.service.damLightSource.JYDamHelper; import com.zhehekeji.web.service.hikLightSource.HikControlSocket; import io.swagger.models.auth.In; import lombok.extern.slf4j.Slf4j; -import net.sf.cglib.core.Local; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -113,34 +112,34 @@ public class CronTab { } } } - - @Scheduled(cron = "0 0/1 * * * ?") - public void lightStatus() { - log.debug(" lightStatus"); - long timeStamp = System.currentTimeMillis(); - - Iterator> it = lightTimeMap.entrySet().iterator(); - while (it.hasNext()){ - Map.Entry entry = it.next(); - if((BigInteger.valueOf(timeStamp).subtract(BigInteger.valueOf(entry.getValue()))).compareTo(timeDIff) > 0){ - List lightSources = lightSourceMapper.selectList(new QueryWrapper().eq("street_id",entry.getKey())); - lightSources.forEach(lightSource -> { - if(configProperties.getLightSource().getType() == 1){ - - JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); - JYDamHelper.closeDO(equip,configProperties.getLightSource().getIndex()); - //不再获取灯光状态 - //Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex()); - //log.info("ip:{},status:{}",lightSource.getIp(),status); - equip.DisConnect(); - }else if(configProperties.getLightSource().getType() == 2){ - HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0); - } - }); - it.remove(); - } - } - } +// +// @Scheduled(cron = "0 0/1 * * * ?") +// public void lightStatus() { +// log.debug(" lightStatus"); +// long timeStamp = System.currentTimeMillis(); +// +// Iterator> it = lightTimeMap.entrySet().iterator(); +// while (it.hasNext()){ +// Map.Entry entry = it.next(); +// if((BigInteger.valueOf(timeStamp).subtract(BigInteger.valueOf(entry.getValue()))).compareTo(timeDIff) > 0){ +// List lightSources = lightSourceMapper.selectList(new QueryWrapper().eq("street_id",entry.getKey())); +// lightSources.forEach(lightSource -> { +// if(configProperties.getLightSource().getType() == 1){ +// +// JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); +// JYDamHelper.closeDO(equip,configProperties.getLightSource().getIndex()); +// //不再获取灯光状态 +// //Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex()); +// //log.info("ip:{},status:{}",lightSource.getIp(),status); +// equip.DisConnect(); +// }else if(configProperties.getLightSource().getType() == 2){ +// HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0); +// } +// }); +// it.remove(); +// } +// } +// } @Scheduled(cron = "0 4 0 * * ? ") diff --git a/web/src/main/java/com/zhehekeji/web/service/PlcService.java b/web/src/main/java/com/zhehekeji/web/service/PlcService.java index c1fdfd5..565c7bc 100644 --- a/web/src/main/java/com/zhehekeji/web/service/PlcService.java +++ b/web/src/main/java/com/zhehekeji/web/service/PlcService.java @@ -53,10 +53,7 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.LocalDateTime; import java.util.*; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingDeque; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.stream.Collectors; /** @@ -118,8 +115,7 @@ public class PlcService { private RfidLiveService rfidLiveService; @Resource - private RestTemplate restTemplate ; - + private RestTemplate restTemplate; @Resource @@ -157,7 +153,7 @@ public class PlcService { public void orderStart(PlcCmdInfo plcCmdInfo) { Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId()); //打开光源 - streetController.openStreetLightSource( street.getId()); + streetController.openStreetLightSource(street.getId()); Integer cameraId = (plcCmdInfo.getFromAround() == 1) ? street.getCamera1Id() : street.getCamera2Id(); gyrateCameraByCode(cameraId, "C5", plcCmdInfo.getTaskId()); @@ -233,7 +229,7 @@ public class PlcService { Street street = streetMapper.selectById(order.getStreetId()); //关闭光源 - Thread thread = new Thread(()->{ + Thread thread = new Thread(() -> { try { Thread.sleep(10000); } catch (InterruptedException e) { @@ -264,7 +260,6 @@ public class PlcService { } - public void orderStopByWarn(String orderNum) { Order order = orderMapper.getOneByOrderNum(orderNum); if (order == null) { @@ -278,12 +273,13 @@ public class PlcService { upd.setStatus(1); orderMapper.updateById(upd); } + @Resource private TaskDelayExecutor taskDelayExecutor; public String cameraVideo(Integer cameraId, LocalDateTime startTime, LocalDateTime endTime) { String path = PathUtil.createFileName("mp4", cameraId); - if(configProperties.getCameraConfig().getDownloadType() == 1){ + if (configProperties.getCameraConfig().getDownloadType() == 1) { String finalPath = path; Thread thread = new Thread(new Runnable() { @Override @@ -293,11 +289,11 @@ public class PlcService { } }); thread.start(); - }else if(configProperties.getCameraConfig().getDownloadType() == 0){ - Street street = streetService.getOne(new QueryWrapper().eq("camera1_Id",cameraId).or().eq("camera2_Id",cameraId)); - if(street != null){ + } else if (configProperties.getCameraConfig().getDownloadType() == 0) { + Street street = streetService.getOne(new QueryWrapper().eq("camera1_Id", cameraId).or().eq("camera2_Id", cameraId)); + if (street != null) { // 设置请求URL - String url = "http://"+street.getPlcIp()+":"+environment.getProperty("server.port")+"/api/camera/control/mp4/delay"; + String url = "http://" + street.getPlcIp() + ":" + environment.getProperty("server.port") + "/api/camera/control/mp4/delay"; // 设置请求头 HttpHeaders headers = new HttpHeaders(); @@ -316,12 +312,12 @@ public class PlcService { restTemplate.getMessageConverters().add(new StringHttpMessageConverter(Charset.forName("utf-8"))); // 发起POST请求,获取响应数据 path = restTemplate.postForObject(url, requestEntity, String.class); - path = "http://"+street.getPlcIp()+":9007/api/mp4/"+path; + path = "http://" + street.getPlcIp() + ":9007/api/mp4/" + path; // 输出响应数据 System.out.println(path); - }else { - log.error("camera:{}未绑定巷道,无法远程下载",cameraId); + } else { + log.error("camera:{}未绑定巷道,无法远程下载", cameraId); } } @@ -682,32 +678,32 @@ public class PlcService { long startTime = System.currentTimeMillis(); Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId()); + //打开光源 + streetController.openStreetLightSourceAsyncClose(street.getId()); if (checkLogMapper.selectCount(new QueryWrapper() - .eq("street_Id",street.getId()) - .eq("check_Num",plcCmdInfo.getOrderNum()))>0){ + .eq("street_Id", street.getId()) + .eq("check_Num", plcCmdInfo.getOrderNum())) > 0) { log.error("库存信息已经盘点"); CheckLog checkLog = checkLogMapper.selectOne(new QueryWrapper() - .eq("street_Id",street.getId()) - .eq("check_Num",plcCmdInfo.getOrderNum())); + .eq("street_Id", street.getId()) + .eq("check_Num", plcCmdInfo.getOrderNum())); AlgorithmPojo pojo = AlgorithmPojo.buildAlgorithmPojo(street, dataInfo); if (checkLog.getWmsCategory() != null) - pojo.setGoodsType(checkLog.getWmsCategory()); + pojo.setGoodsType(checkLog.getWmsCategory()); if (checkLog.getWmsCount() != null) - pojo.setGoodsNumber(checkLog.getWmsCount()); + pojo.setGoodsNumber(checkLog.getWmsCount()); if (checkLog.getCategory() != null) - pojo.setGoodsTypeResult(checkLog.getCategory()); + pojo.setGoodsTypeResult(checkLog.getCategory()); if (checkLog.getCount() != null) - pojo.setGoodsNumberResult(checkLog.getCount()); + pojo.setGoodsNumberResult(checkLog.getCount()); return pojo; } - //打开光源 - streetController.openStreetLightSource( street.getId()); CronTab.putTime(street.getId()); plcCmdInfo.setStreetName(street.getName()); // List lightSources = lightSourceMapper.selectList(new QueryWrapper().eq("street_id", street.getId())); //关闭光源 - streetController.openStreetLightSource(street.getId()); + streetController.openStreetLightSourceAsyncClose(street.getId()); log.info("盘点摄像头变化参数:" + plcCmdInfo.toString()); @@ -729,22 +725,22 @@ public class PlcService { OrderInfo orderInfo = new OrderInfo(street, plcCmdInfo, 1, cmdCode); Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(), plcCmdInfo.getFromDirection(), orderInfo.getSeparation(), orderInfo.getRow(), orderInfo.getColumn()); AlgorithmPojo algorithmPojo = algorithmService.getGoodResult(street, dataInfo); - String paths = String.join(";", algorithmPojo.getCalculate().getFisheye()) +";"+String.join(";",algorithmPojo.getCalculate().getCloseUp())+";"+algorithmPojo.getCalculate().getPath(); + String paths = String.join(";", algorithmPojo.getCalculate().getFisheye()) + ";" + String.join(";", algorithmPojo.getCalculate().getCloseUp()) + ";" + algorithmPojo.getCalculate().getPath(); //货物使用球机扫码 log.info("盘点信息:{}", algorithmPojo.toString()); - //关闭光源 - Thread thread = new Thread(() -> { - try { - Thread.sleep(30000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - //关闭光源 - streetController.closeStreetLightSource(street.getId()); - }); - thread.start(); +// //关闭光源 +// Thread thread = new Thread(() -> { +// try { +// Thread.sleep(30000); +// } catch (InterruptedException e) { +// throw new RuntimeException(e); +// } +// //关闭光源 +// streetController.closeStreetLightSource(street.getId()); +// }); +// thread.start(); //核对异常 Integer status = 4; //托盘和货物都正确 @@ -871,6 +867,10 @@ public class PlcService { return configProperties; } + // 在PlcService类中添加以下静态成员 + private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10); + private static ConcurrentHashMap> scheduledTasks = new ConcurrentHashMap<>(); + public KsecDataInfo orderDecoder(KsecInfo ksecInfo) { log.info("收到命令:{}", ksecInfo.toString()); KsecDataInfo dataInfo = ksecInfo.getData(); @@ -900,11 +900,11 @@ public class PlcService { plcCmdInfo.setFromAround(dataInfo.getFromAround()); plcCmdInfo.setToSide(dataInfo.getToSeparation()); //古井贡增加层概念,等于行 - if( dataInfo.getToStorey()!=null ){ + if (dataInfo.getToStorey() != null) { plcCmdInfo.setToRow(dataInfo.getToStorey()); plcCmdInfo.setRow2(dataInfo.getToStorey()); } - if( dataInfo.getFromStorey()!=null ){ + if (dataInfo.getFromStorey() != null) { plcCmdInfo.setFromRow(dataInfo.getFromStorey()); plcCmdInfo.setRow1(dataInfo.getFromStorey()); } @@ -944,10 +944,25 @@ public class PlcService { //任务开始 旋转到原点位 gyrateCamera(plcCmdInfo, Cmd.C5.name()); orderStart(plcCmdInfo); - + // 添加延时任务 + PlcCmdInfo finalPlcCmdInfo = plcCmdInfo; + ScheduledFuture future = scheduler.schedule(() -> { + // 执行orderStop + orderStop(finalPlcCmdInfo); + // 从map中移除已执行的任务 + scheduledTasks.remove(finalPlcCmdInfo.getTaskId()); + }, 5, TimeUnit.MINUTES); + + // 将future放入map中,便于后续取消 + scheduledTasks.put(plcCmdInfo.getTaskId(), future); } else if (Cmd.B2.name().equals(cmdName)) { + // 取消对应的计划任务(如果存在) + ScheduledFuture existingTask = scheduledTasks.remove(plcCmdInfo.getTaskId()); + if (existingTask != null && !existingTask.isDone()) { + existingTask.cancel(false); // 取消尚未执行的任务 + } orderStop(plcCmdInfo); } } else if (Cmd.C.name().equals(ksecInfo.getType())) { @@ -976,12 +991,12 @@ public class PlcService { String code = dataInfo.getCmdName(); log.info("盘点指令:{}", ksecInfo); - AlgorithmPojo algorithmPojo = check(plcCmdInfo, ksecInfo.getType(), dataInfo); - ksecInfo.getData().setAckStatus(1); - dataInfo.setResult(algorithmPojo.getResult()); - dataInfo.setGoodsTypeResult(algorithmPojo.getGoodsTypeResult()); - dataInfo.setGoodsNumberResult(algorithmPojo.getGoodsNumberResult()); - log.info("盘点完成"); + AlgorithmPojo algorithmPojo = check(plcCmdInfo, ksecInfo.getType(), dataInfo); + ksecInfo.getData().setAckStatus(1); + dataInfo.setResult(algorithmPojo.getResult()); + dataInfo.setGoodsTypeResult(algorithmPojo.getGoodsTypeResult()); + dataInfo.setGoodsNumberResult(algorithmPojo.getGoodsNumberResult()); + log.info("盘点完成"); // if (configProperties.getOrderTest() == 1) { // checkTest(plcCmdInfo); 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 e7d9b3c..caad750 100644 --- a/web/src/main/java/com/zhehekeji/web/service/StockService.java +++ b/web/src/main/java/com/zhehekeji/web/service/StockService.java @@ -273,23 +273,34 @@ public class StockService { * @return */ public List exportExcels(Integer streetId) { + String[] status = {"未盘点","盘点异常","盘点正确","人工盘点正确","待人工盘点"}; List stocks = list(streetId); Street street = streetService.streetById(streetId); List stockExportExcels = new ArrayList<>(stocks.size()); stocks.forEach(stock -> { StockExportExcel stockExportExcel = new StockExportExcel(); - stockExportExcel.setCode(stock.getTrayCode()); - stockExportExcel.setLotnum(stock.getLotnum()); - stockExportExcel.setColumn(stock.getColumn()); - stockExportExcel.setWmsCode(stock.getWmsTrayCode()); - //stockExportExcel.setCount(stock.getCount()); - stockExportExcel.setRow(stock.getRow()); stockExportExcel.setStreetName(street.getName()); - stockExportExcel.setExportTime(stock.getExportTime()); - stockExportExcel.setDirection(stock.getDirection()); - stockExportExcel.setSide(stock.getSide()); - //stockExportExcel.setShelveId(stock.getShelveId()); - stockExportExcel.setStatus(stock.getStatus()); + stockExportExcel.setLotnum(stock.getLotnum()); + stockExportExcel.setDirection((stock.getDirection() == 1 ? "左侧" : "右侧")+"-"+(stock.getSide()==1?"浅货位":"深货位")+"-"+stock.getRow()+"层"+"-"+stock.getColumn()+"列"); + stockExportExcel.setWmsCategory(stock.getWmsCategory()); + stockExportExcel.setCategory((stock.getCategory() == null||stock.getWmsCategory() == null) ? "无" : (stock.getWmsCategory().equals(stock.getCategory())?"一致":"不一致")); + + stockExportExcel.setWmsCount(stock.getWmsCount()); + stockExportExcel.setCount(stock.getCount()+stock.getCountTop()); + stockExportExcel.setStatus(status[stock.getStatus()]); + stockExportExcel.setExportTime(stock.getFormattedExportTime()); +// stockExportExcel.setCode(stock.getTrayCode()); +// stockExportExcel.setLotnum(stock.getLotnum()); +// stockExportExcel.setColumn(stock.getColumn()); +// stockExportExcel.setWmsCode(stock.getWmsTrayCode()); +// //stockExportExcel.setCount(stock.getCount()); +// stockExportExcel.setRow(stock.getRow()); +// stockExportExcel.setStreetName(street.getName()); +// stockExportExcel.setExportTime(stock.getExportTime()); +// stockExportExcel.setDirection(stock.getDirection()); +// stockExportExcel.setSide(stock.getSide()); +// //stockExportExcel.setShelveId(stock.getShelveId()); +// stockExportExcel.setStatus(stock.getStatus()); stockExportExcels.add(stockExportExcel); }); return stockExportExcels; @@ -297,6 +308,7 @@ public class StockService { public List exportAllExcels() { + String[] status = {"未盘点","盘点异常","盘点正确","人工盘点正确","待人工盘点"}; List stocks = stockMapper.selectByMap(new HashMap<>()); List streets = streetMapper.selectByMap(new HashMap<>()); Map streetMap = new HashMap<>(); @@ -307,16 +319,27 @@ public class StockService { List stockExportExcels = new ArrayList<>(stocks.size()); stocks.forEach(stock -> { StockExportExcel stockExportExcel = new StockExportExcel(); - stockExportExcel.setCode(stock.getTrayCode()); - stockExportExcel.setLotnum(stock.getLotnum()); - stockExportExcel.setColumn(stock.getColumn()); - //stockExportExcel.setCount(stock.getCount()); - stockExportExcel.setRow(stock.getRow()); stockExportExcel.setStreetName(streetMap.get(stock.getStreetId())); - stockExportExcel.setExportTime(stock.getExportTime()); - stockExportExcel.setDirection(stock.getDirection()); - stockExportExcel.setSide(stock.getSide()); - stockExportExcel.setStatus(stock.getStatus()); + stockExportExcel.setLotnum(stock.getLotnum()); + stockExportExcel.setDirection((stock.getDirection() == 1 ? "左侧" : "右侧")+"-"+(stock.getSide()==1?"浅货位":"深货位")+"-"+stock.getRow()+"层"+"-"+stock.getColumn()+"列"); + stockExportExcel.setWmsCategory(stock.getWmsCategory()); + stockExportExcel.setCategory((stock.getCategory() == null||stock.getWmsCategory() == null) ? "无" : (stock.getWmsCategory().equals(stock.getCategory())?"一致":"不一致")); + stockExportExcel.setWmsCount(stock.getWmsCount()); + stockExportExcel.setCount(stock.getCount()+stock.getCountTop()); + stockExportExcel.setStatus(status[stock.getStatus()]); + stockExportExcel.setExportTime(stock.getFormattedExportTime()); +// stockExportExcel.setCode(stock.getTrayCode()); +// stockExportExcel.setLotnum(stock.getLotnum()); +// stockExportExcel.setColumn(stock.getColumn()); +// stockExportExcel.setWmsCode(stock.getWmsTrayCode()); +// //stockExportExcel.setCount(stock.getCount()); +// stockExportExcel.setRow(stock.getRow()); +// stockExportExcel.setStreetName(street.getName()); +// stockExportExcel.setExportTime(stock.getExportTime()); +// stockExportExcel.setDirection(stock.getDirection()); +// stockExportExcel.setSide(stock.getSide()); +// //stockExportExcel.setShelveId(stock.getShelveId()); +// stockExportExcel.setStatus(stock.getStatus()); stockExportExcels.add(stockExportExcel); }); return stockExportExcels; @@ -342,8 +365,6 @@ public class StockService { }else { stock.setStreetName(street.getName()); } - //不再需要操作照片 - List stockLogs = stockLogMapper.selectList(new QueryWrapper().eq("`row`",stockCheck.getRow()).eq("`column`",stockCheck.getColumn()).eq("street_id",stockCheck.getStreetId()).eq("direction",stockCheck.getDirection()).eq("side",stockCheck.getSide()).orderByDesc("create_time").last(" limit 2")); // if(stockLogs.size() == 1){ // stock.setOveroperationPic(stockLogs.get(0).getPic()); // }else if(stockLogs.size() == 2){ @@ -417,7 +438,7 @@ public class StockService { log.info("check stock correct, street_id:{},direction:{},side:{},row:{},column:{}", stockCheck.getStreetId(),stockCheck.getDirection(),stockCheck.getSide(), stockCheck.getRow(), stockCheck.getColumn()); int count =(stock.getCount() != null) ? stock.getCount() : 0; - if(stockCheck.getCountTop()+ count == stock.getWmsCount() && stock.getWmsCategory().equals(stockCheck.getCategory())){ + if(stockCheck.getCountTop()+ count == stock.getWmsCount() ){ stock.setStatus(StockStatus.MANUAL.getStatus()); }else { @@ -483,43 +504,27 @@ public class StockService { public Stock nextOne(Long id) { QueryWrapper stockQueryWrapper = new QueryWrapper<>(); - stockQueryWrapper.eq("status","0").or().eq("status","1") + stockQueryWrapper.eq("status","0").or().eq("status","1").or().eq("status","4") .ne(ToolUtil.isNotEmpty(id),"id",id) .orderByDesc("export_time").last("limit 1"); Stock stock =stockMapper.selectOne(stockQueryWrapper); - if (stock != null) { - Street street = streetMapper.selectById(stock.getStreetId()); - stock.setStreetName(street.getName()); - List stockLogs = stockLogMapper.selectList(new QueryWrapper() - .eq("`row`",stock.getRow()) - .eq("`column`",stock.getColumn()) - .eq("street_id",stock.getStreetId()) - .eq("direction",stock.getDirection()) - .eq("side",stock.getSide()) - .orderByDesc("create_time").last(" limit 2")); - if(stockLogs.size() == 1){ - stock.setOveroperationPic(stockLogs.get(0).getPic()); - }else if(stockLogs.size() == 2){ - stock.setOveroperationPic(stockLogs.get(0).getPic()); - stock.setPreoperationPic(stockLogs.get(1).getPic()); - } + Street street = streetService.getById(stock.getStreetId()); - String ip ="http://"+ street.getPlcIp()+":9002/pic/"; - if (stock.getPreoperationPic() != null&& stock.getPreoperationPic().length() > 0) { - String[] pics = stock.getPreoperationPic().split(";"); - if (pics.length>3) - stock.setSidePic1(String.format("%s%s", ip, pics[3])); - if (pics.length>2) - stock.setSidePic2(String.format("%s%s", ip, pics[2])); - if (pics.length>4) - stock.setSidePic3(String.format("%s%s", ip, pics[4])); - if (pics.length>5) - stock.setSidePic4(String.format("%s%s", ip, pics[5])); - stock.setTopPic1(String.format("%s%s", ip, pics[0])); - if (pics.length>1) - stock.setTopPic2(String.format("%s%s", ip, pics[1])); - } + String ip ="http://"+ street.getPlcIp()+":9002/pic/"; + if (stock.getPreoperationPic() != null&& stock.getPreoperationPic().length() > 0) { + String[] pics = stock.getPreoperationPic().split(";"); + if (pics.length>3) + stock.setSidePic1(String.format("%s%s", ip, pics[3])); + if (pics.length>2) + stock.setSidePic2(String.format("%s%s", ip, pics[2])); + if (pics.length>4) + stock.setSidePic3(String.format("%s%s", ip, pics[4])); + if (pics.length>5) + stock.setSidePic4(String.format("%s%s", ip, pics[5])); + stock.setTopPic1(String.format("%s%s", ip, pics[0])); + if (pics.length>1) + stock.setTopPic2(String.format("%s%s", ip, pics[1])); } return stock; diff --git a/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java b/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java index 79af5de..0975ef0 100644 --- a/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java +++ b/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java @@ -75,7 +75,7 @@ public class AlgorithmService { public static List readJsonArrayFile(String fileName) { try { - String content = new String(Files.readAllBytes(Paths.get(fileName))); + String content = new String(Files.readAllBytes(Paths.get(fileName)), "UTF-8"); return JSON.parseArray(content, String.class); } catch (IOException e) { e.printStackTrace(); @@ -84,6 +84,11 @@ public class AlgorithmService { } public AlgorithmPojo getGoodResultHttp(AlgorithmPojo algorithmPojo) { + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } String url = "http://"+algorithmPojo.getIp()+":8094/industrialCamera/panoramaAlgorithm"; //String url = "http://127.0.0.1:8083"+"/visionCompute"; @@ -124,6 +129,8 @@ public class AlgorithmService { }catch (Exception e){ log.error("堆垛机报错"+e); e.printStackTrace(); + algorithmPojo.setResult(0); + return algorithmPojo; } return algorithmPojo; } diff --git a/web/src/main/java/com/zhehekeji/web/util/ToolUtil.java b/web/src/main/java/com/zhehekeji/web/util/ToolUtil.java index 09c6b55..1fa63c4 100644 --- a/web/src/main/java/com/zhehekeji/web/util/ToolUtil.java +++ b/web/src/main/java/com/zhehekeji/web/util/ToolUtil.java @@ -1,6 +1,5 @@ package com.zhehekeji.web.util; -import com.alibaba.excel.util.CollectionUtils; import org.apache.poi.util.ArrayUtil; import java.lang.reflect.Array;