@ -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 < SpRecordEntity > ) 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 < SpRecordEntity > spRecordEntityList ) {
try {
Runnable runnable = new Runnable ( ) {
@Override
public void run ( ) {
//异步任务
pushWarehouseWarningV2 ( warehouseId , spRecordEntityList ) ;
}
} ;
Thread thread = new Thread ( runnable ) ;
thread . start ( ) ;
// Callable<String> 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 < SpRecordEntity > spRecordEntityList ) {
//开启线程池推送消息
executorService . execute ( ( ) - > spRecordEntityList . forEach ( spRecordEntity - > {
spRecordEntityList . forEach ( spRecordEntity - > {
//查询该仓库是否有备品备件超出上下限
WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService . selectById ( warehouseId ) ;
WtSpTotalEntity wtSpTotalEntity = wtSpTotalService . getOne ( Wrappers . < WtSpTotalEntity > lambdaQuery ( )
@ -139,13 +164,9 @@ public class LimitRemindAspect {
) ;
}
//推送消息
CompletableFuture . supplyAsync ( ( ) - > {
this . warningPush ( alert , pusher , warehouseId ) ;
return "推送成功" ;
} ) ;
}
} ) ) ;
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 < SpRecordEntity > spRecordEntityList ) {
//开启线程池推送消息
executorService . execute ( ( ) - > spRecordEntityList . forEach ( spRecordEntity - > {
//查询该仓库是否有备品备件超出上下限
WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService . selectById ( warehouseId ) ;
WtSpTotalEntity wtSpTotalEntity = wtSpTotalService . getOne ( Wrappers . < WtSpTotalEntity > 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<SpRecordEntity> spRecordEntityList) {
// //开启线程池推送消息
// executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> {
// //查询该仓库是否有备品备件超出上下限
// WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId);
// WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.<WtSpTotalEntity>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推送