Browse Source

库存推送预警代码修改

zhongwei
tyty 1 year ago
parent
commit
ff4391f403
  1. 143
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/aspect/LimitRemindAspect.java

143
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.lang.reflect.Field;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.*;
/** /**
* @author hx * @author hx
@ -86,7 +85,7 @@ public class LimitRemindAspect {
basicList = (List<SpRecordEntity>) basicListField.get(args[0]); basicList = (List<SpRecordEntity>) basicListField.get(args[0]);
warehouseId = (Long) warehouseIdField.get(args[0]); warehouseId = (Long) warehouseIdField.get(args[0]);
if (CollectionUtil.isNotEmpty(basicList) && ObjectUtil.isNotEmpty(warehouseId)) { if (CollectionUtil.isNotEmpty(basicList) && ObjectUtil.isNotEmpty(warehouseId)) {
this.pushWarehouseWarningV2(warehouseId, basicList); this.pushWarehouseThread(warehouseId, basicList);
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
@ -101,11 +100,37 @@ public class LimitRemindAspect {
* @param spRecordEntityList 出入库备品备件列表 * @param spRecordEntityList 出入库备品备件列表
* @param warehouseId 仓库ID * @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) { private void pushWarehouseWarningV2(Long warehouseId, List<SpRecordEntity> spRecordEntityList) {
//开启线程池推送消息 spRecordEntityList.forEach(spRecordEntity -> {
executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> {
//查询该仓库是否有备品备件超出上下限 //查询该仓库是否有备品备件超出上下限
WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId); WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId);
WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.<WtSpTotalEntity>lambdaQuery() WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.<WtSpTotalEntity>lambdaQuery()
@ -139,13 +164,9 @@ public class LimitRemindAspect {
); );
} }
//推送消息 //推送消息
CompletableFuture.supplyAsync(() -> { this.warningPush(alert, pusher,warehouseId);
this.warningPush(alert, pusher,warehouseId);
return "推送成功";
});
} }
})); });
executorService.shutdown();
} }
private void warningPush(String alert, User pusher,Long warehouseId) { private void warningPush(String alert, User pusher,Long warehouseId) {
@ -177,56 +198,56 @@ public class LimitRemindAspect {
} }
//此接口已经弃用20230608 //此接口已经弃用20230608
@Deprecated // @Deprecated
private void pushWarehouseWarning(Long warehouseId, List<SpRecordEntity> spRecordEntityList) { // private void pushWarehouseWarning(Long warehouseId, List<SpRecordEntity> spRecordEntityList) {
//开启线程池推送消息 // //开启线程池推送消息
executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> { // executorService.execute(() -> spRecordEntityList.forEach(spRecordEntity -> {
//查询该仓库是否有备品备件超出上下限 // //查询该仓库是否有备品备件超出上下限
WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId); // WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.selectById(warehouseId);
WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.<WtSpTotalEntity>lambdaQuery() // WtSpTotalEntity wtSpTotalEntity = wtSpTotalService.getOne(Wrappers.<WtSpTotalEntity>lambdaQuery()
.eq(WtSpTotalEntity::getSpBasicId, spRecordEntity.getSpBasicId()) // .eq(WtSpTotalEntity::getSpBasicId, spRecordEntity.getSpBasicId())
.eq(WtSpTotalEntity::getWarehouseId, warehouseId) // .eq(WtSpTotalEntity::getWarehouseId, warehouseId)
.last("limit 1;") // .last("limit 1;")
); // );
WtSpBasicEntity basicEntity = wtSpBasicService.getById(spRecordEntity.getSpBasicId()); // WtSpBasicEntity basicEntity = wtSpBasicService.getById(spRecordEntity.getSpBasicId());
//超出上限/下限发送消息提醒 // //超出上限/下限发送消息提醒
log.info("仓库id为:{},库存为:{},上限为:{},下限为:{}", warehouseId, wtSpTotalEntity.getStock(), basicEntity.getUpperLimit(), basicEntity.getLowerLimit()); // log.info("仓库id为:{},库存为:{},上限为:{},下限为:{}", warehouseId, wtSpTotalEntity.getStock(), basicEntity.getUpperLimit(), basicEntity.getLowerLimit());
if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit() || wtSpTotalEntity.getStock() < basicEntity.getLowerLimit()) { // if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit() || wtSpTotalEntity.getStock() < basicEntity.getLowerLimit()) {
User pusher = UserCache.getUser(wtSpWarehouseEntity.getManager()); // User pusher = UserCache.getUser(wtSpWarehouseEntity.getManager());
if (ObjectUtil.isEmpty(pusher)) { // if (ObjectUtil.isEmpty(pusher)) {
return; // return;
} // }
//完善推送信息 // //完善推送信息
String alert; // String alert;
if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit()) { // if (wtSpTotalEntity.getStock() > basicEntity.getUpperLimit()) {
alert = String.format("%s内的(%s)已达到上限,目前仓库内的库存为:%s,上限值为:%s。请及时处理!", // alert = String.format("%s内的(%s)已达到上限,目前仓库内的库存为:%s,上限值为:%s。请及时处理!",
wtSpWarehouseEntity.getName(), // wtSpWarehouseEntity.getName(),
basicEntity.getName(), // basicEntity.getName(),
wtSpTotalEntity.getStock(), // wtSpTotalEntity.getStock(),
basicEntity.getUpperLimit() // basicEntity.getUpperLimit()
); // );
} else { // } else {
alert = String.format("%s内的(%s)已达到下限,目前仓库内的库存为:%s,下限值为:%s。请及时处理!", // alert = String.format("%s内的(%s)已达到下限,目前仓库内的库存为:%s,下限值为:%s。请及时处理!",
wtSpWarehouseEntity.getName(), // wtSpWarehouseEntity.getName(),
basicEntity.getName(), // basicEntity.getName(),
wtSpTotalEntity.getStock(), // wtSpTotalEntity.getStock(),
basicEntity.getLowerLimit() // basicEntity.getLowerLimit()
); // );
} // }
//推送web消息 // //推送web消息
CompletableFuture.supplyAsync(() -> { // CompletableFuture.supplyAsync(() -> {
this.warningPushWeb(alert, pusher); // this.warningPushWeb(alert, pusher);
return "推送成功"; // return "推送成功";
}); // });
//推送App消息 // //推送App消息
CompletableFuture.supplyAsync(() -> { // CompletableFuture.supplyAsync(() -> {
this.warningPushApp(alert, pusher); // this.warningPushApp(alert, pusher);
return "推送成功"; // return "推送成功";
}); // });
} // }
})); // }));
executorService.shutdown(); // executorService.shutdown();
} // }
/** /**
* 备品备件-预警app推送 * 备品备件-预警app推送

Loading…
Cancel
Save