81,092
社区成员
发帖
与我相关
我的任务
分享
// 创建出库单
@Transactional(rollbackFor = Exception.class)
public boolean insert(Long userId, StockOut entity, List<StockOutItem> stockOutItemList) {
Date currentTime = new Date();
boolean result = retBool(baseMapper.insert(entity));
for (StockOutItem stockOutItem : stockOutItemList) {
stockOutItem.setStockOutId(entity.getId());
stockOutItem.setQualityGrade(1);
stockOutItem.setCreater(userId);
stockOutItem.setCreateTime(currentTime);
stockOutItem.setEnable(true);
result = retBool(stockOutItemMapper.insert(stockOutItem));
}
ThreadUtils.distributionInventory(entity.getId(), userId); // 执行多线程 分配库存
return result;
}
public class ThreadUtils {
public static void distributionInventory(Long stockOutId, Long modifier) {
ThreadPoolExecutor threadPool = ThreadPoolUtil.getThreadPool(); //获取线程池
threadPool.execute(new DistributionThread(stockOutId, modifier));
}
}
public class DistributionThread implements Runnable {
public void run(){
// 执行方法用到上面生成的 StockOut 和 StockOutItem
}
}