diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/aspect/LimitRemindAspect.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/aspect/LimitRemindAspect.java index 9cb524f..e8c5d55 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/aspect/LimitRemindAspect.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/aspect/LimitRemindAspect.java @@ -32,7 +32,6 @@ import org.springframework.stereotype.Component; import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; -import java.util.concurrent.*; /** * @author hx @@ -86,7 +85,7 @@ public class LimitRemindAspect { basicList = (List) basicListField.get(args[0]); warehouseId = (Long) warehouseIdField.get(args[0]); if (CollectionUtil.isNotEmpty(basicList) && ObjectUtil.isNotEmpty(warehouseId)) { - this.pushWarehouseWarningV2(warehouseId, basicList); + this.pushWarehouseThread(warehouseId, basicList); } } catch (IllegalAccessException e) { e.printStackTrace(); @@ -101,11 +100,37 @@ public class LimitRemindAspect { * @param spRecordEntityList 出入库备品备件列表 * @param warehouseId 仓库ID */ - final static ExecutorService executorService = new ThreadPoolExecutor(5, 5, 1, TimeUnit.SECONDS, new LinkedBlockingDeque<>()); +// final static ExecutorService executorService = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + public void pushWarehouseThread(Long warehouseId, List spRecordEntityList) { + try { + Runnable runnable = new Runnable() { + @Override + public void run() { + //异步任务 + pushWarehouseWarningV2(warehouseId, spRecordEntityList); + } + }; + Thread thread = new Thread(runnable); + thread.start(); +// Callable c1 = new Callable() { +// +// @Override +// public Object call() throws Exception { +// //异步任务 +// pushWarehouseWarningV2(warehouseId, spRecordEntityList); +// return "success"; +// } +// }; +// Future f = new FutureTask(c1); +// System.out.println(f.get()); + } catch (Exception e) { + log.error(e.getMessage(), e.toString()); + } + } +// ExecutorService executorService = new ThreadPoolExecutor(1,1,1, TimeUnit.SECONDS,new LinkedBlockingDeque<>()); private void pushWarehouseWarningV2(Long warehouseId, List spRecordEntityList) { - //开启线程池推送消息 - executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> { + spRecordEntityList.forEach(spRecordEntity -> { //查询该仓库是否有备品备件超出上下限 WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId); WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.lambdaQuery() @@ -139,13 +164,9 @@ public class LimitRemindAspect { ); } //推送消息 - CompletableFuture.supplyAsync(() -> { - this.warningPush(alert, pusher,warehouseId); - return "推送成功"; - }); + this.warningPush(alert, pusher,warehouseId); } - })); - executorService.shutdown(); + }); } private void warningPush(String alert, User pusher,Long warehouseId) { @@ -177,56 +198,56 @@ public class LimitRemindAspect { } //此接口已经弃用20230608 - @Deprecated - private void pushWarehouseWarning(Long warehouseId, List spRecordEntityList) { - //开启线程池推送消息 - executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> { - //查询该仓库是否有备品备件超出上下限 - WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId); - WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.lambdaQuery() - .eq(WtSpTotalEntity::getSpBasicId, spRecordEntity.getSpBasicId()) - .eq(WtSpTotalEntity::getWarehouseId, warehouseId) - .last("limit 1;") - ); - WtSpBasicEntity basicEntity = wtSpBasicService.getById(spRecordEntity.getSpBasicId()); - //超出上限/下限发送消息提醒 - log.info("仓库id为:{},库存为:{},上限为:{},下限为:{}", warehouseId, wtSpTotalEntity.getStock(), basicEntity.getUpperLimit(), basicEntity.getLowerLimit()); - if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit() || wtSpTotalEntity.getStock() < basicEntity.getLowerLimit()) { - User pusher = UserCache.getUser(wtSpWarehouseEntity.getManager()); - if (ObjectUtil.isEmpty(pusher)) { - return; - } - //完善推送信息 - String alert; - if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit()) { - alert = String.format("%s内的(%s)已达到上限,目前仓库内的库存为:%s,上限值为:%s。请及时处理!", - wtSpWarehouseEntity.getName(), - basicEntity.getName(), - wtSpTotalEntity.getStock(), - basicEntity.getUpperLimit() - ); - } else { - alert = String.format("%s内的(%s)已达到下限,目前仓库内的库存为:%s,下限值为:%s。请及时处理!", - wtSpWarehouseEntity.getName(), - basicEntity.getName(), - wtSpTotalEntity.getStock(), - basicEntity.getLowerLimit() - ); - } - //推送web消息 - CompletableFuture.supplyAsync(() -> { - this.warningPushWeb(alert, pusher); - return "推送成功"; - }); - //推送App消息 - CompletableFuture.supplyAsync(() -> { - this.warningPushApp(alert, pusher); - return "推送成功"; - }); - } - })); - executorService.shutdown(); - } +// @Deprecated +// private void pushWarehouseWarning(Long warehouseId, List spRecordEntityList) { +// //开启线程池推送消息 +// executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> { +// //查询该仓库是否有备品备件超出上下限 +// WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId); +// WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.lambdaQuery() +// .eq(WtSpTotalEntity::getSpBasicId, spRecordEntity.getSpBasicId()) +// .eq(WtSpTotalEntity::getWarehouseId, warehouseId) +// .last("limit 1;") +// ); +// WtSpBasicEntity basicEntity = wtSpBasicService.getById(spRecordEntity.getSpBasicId()); +// //超出上限/下限发送消息提醒 +// log.info("仓库id为:{},库存为:{},上限为:{},下限为:{}", warehouseId, wtSpTotalEntity.getStock(), basicEntity.getUpperLimit(), basicEntity.getLowerLimit()); +// if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit() || wtSpTotalEntity.getStock() < basicEntity.getLowerLimit()) { +// User pusher = UserCache.getUser(wtSpWarehouseEntity.getManager()); +// if (ObjectUtil.isEmpty(pusher)) { +// return; +// } +// //完善推送信息 +// String alert; +// if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit()) { +// alert = String.format("%s内的(%s)已达到上限,目前仓库内的库存为:%s,上限值为:%s。请及时处理!", +// wtSpWarehouseEntity.getName(), +// basicEntity.getName(), +// wtSpTotalEntity.getStock(), +// basicEntity.getUpperLimit() +// ); +// } else { +// alert = String.format("%s内的(%s)已达到下限,目前仓库内的库存为:%s,下限值为:%s。请及时处理!", +// wtSpWarehouseEntity.getName(), +// basicEntity.getName(), +// wtSpTotalEntity.getStock(), +// basicEntity.getLowerLimit() +// ); +// } +// //推送web消息 +// CompletableFuture.supplyAsync(() -> { +// this.warningPushWeb(alert, pusher); +// return "推送成功"; +// }); +// //推送App消息 +// CompletableFuture.supplyAsync(() -> { +// this.warningPushApp(alert, pusher); +// return "推送成功"; +// }); +// } +// })); +// executorService.shutdown(); +// } /** * 备品备件-预警app推送