当前位置:网站首页>(记录)异步并发,多线程处理表的统计
(记录)异步并发,多线程处理表的统计
2022-08-04 13:06:00 【Leo丶fei】
结果集对象
package com.huike.report.domain.vo;
import lombok.Data;
/**
* 首页基本数据VO对象
*/
@Data
public class IndexBaseInfoVO {
private Integer cluesNum=0; //线索数目
private Integer businessNum=0; //商机数目
private Integer contractNum=0; //合同数目
private Double salesAmount=0.0; //销售金额
}
安全工具类(获得登录用户信息)
package com.huike.common.utils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import com.huike.common.constant.HttpStatus;
import com.huike.common.core.domain.model.LoginUser;
import com.huike.common.exception.CustomException;
/**
* 安全服务工具类
*
*
*/
public class SecurityUtils
{
/**
* 获取用户账户
**/
public static String getUsername()
{
try
{
return getLoginUser().getUsername();
}
catch (Exception e)
{
throw new CustomException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
}
}
public static Long getUserId()
{
try
{
return getLoginUser().getUser().getUserId();
}
catch (Exception e)
{
throw new CustomException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
}
}
public static Long getDeptId()
{
try
{
return getLoginUser().getUser().getDeptId();
}
catch (Exception e)
{
throw new CustomException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
}
}
/**
* 获取用户
**/
public static LoginUser getLoginUser()
{
try
{
return (LoginUser) getAuthentication().getPrincipal();
}
catch (Exception e)
{
throw new CustomException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
}
}
/**
* 获取Authentication
*/
public static Authentication getAuthentication()
{
return SecurityContextHolder.getContext().getAuthentication();
}
/**
* 生成BCryptPasswordEncoder密码
*
* @param password 密码
* @return 加密字符串
*/
public static String encryptPassword(String password)
{
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder.encode(password);
}
/**
* 判断密码是否相同
*
* @param rawPassword 真实密码
* @param encodedPassword 加密后字符
* @return 结果
*/
public static boolean matchesPassword(String rawPassword, String encodedPassword)
{
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder.matches(rawPassword, encodedPassword);
}
/**
* 是否为管理员
*
* @param userId 用户ID
* @return 结果
*/
public static boolean isAdmin(Long userId)
{
return userId != null && 1L == userId;
}
public static Long getAdmin()
{
return 1L;
}
}
引入一个utils
异步并发,多线程处理表的统计
/**
* 获取首页基本数据
* 异步的并发,多线程处理表的统计
* @param beginCreateTime
* @param endCreateTime
* @return
*/
@Override
public IndexBaseInfoVO getBaseInfo(String beginCreateTime, String endCreateTime) {
//1)构建一个空的结果集对象
IndexBaseInfoVO result = new IndexBaseInfoVO();
//封装结果集属性
// 2.1 由于查询需要用到用户名 调用工具类获取用户名
String username = SecurityUtils.getUsername();
try {
CompletableFuture<Integer> cluesNum=CompletableFuture.supplyAsync(()->{
//查询第一个属性 线索数量
return reportMpper.getCluesNum(beginCreateTime, endCreateTime, username);
});
CompletableFuture<Integer> businessNum=CompletableFuture.supplyAsync(()->{
//查询第一个属性 商机数量
return reportMpper.getBusinessNum(beginCreateTime, endCreateTime, username);
});
CompletableFuture<Integer> contractNum=CompletableFuture.supplyAsync(()->{
//查询第一个属性 合同数量
return reportMpper.getContractNum(beginCreateTime, endCreateTime, username);
});
CompletableFuture<Double> salesAmount=CompletableFuture.supplyAsync(()->{
//查询第一个属性,销售金额
return reportMpper.getSalesAmount(beginCreateTime, endCreateTime, username);
});
//join 等待所有线程全部执行完
CompletableFuture
.allOf(cluesNum,businessNum,contractNum,salesAmount)
.join();
//封装结果集对象
result.setCluesNum(cluesNum.get());
result.setBusinessNum(businessNum.get());
result.setContractNum(contractNum.get());
result.setSalesAmount(salesAmount.get());
} catch (Exception e) {
e.printStackTrace();
return null;
}
//4 返回结果集对象
return result;
}
边栏推荐
- 关于mysql join 的一些说明
- ReentrantLock 原理
- 视觉SLAM十四讲学习笔记 第7讲 视觉里程计
- Interviewer: Tell me the difference between NIO and BIO
- du命令_set命令选项
- Escape character is ‘^]’什么意思?怎么使用telnet
- 绩效考核带给员工的不能只是压力
- Chinese valentine's day of young people crazy to make money, earn 140000 a week
- “蔚来杯“2022牛客暑期多校训练营3 C
- 封装、继承、多态的联合使用实现不同等级学生分数信息的统计
猜你喜欢
ShanDong Multi-University Training #4 A、B、C、G
视觉SLAM十四讲学习笔记 第7讲 视觉里程计
This article sorts out the development of the main models of NLP
nVisual二次开发——第二章 nVisual API操作指南Swagger使用
一文梳理NLP主要模型发展脉络
持续交付(二)PipeLine基本使用
LeetCode 1403 Minimum subsequence in non-increasing order [greedy] HERODING's LeetCode road
倒计时 3 天|一起看云原生 Meetup 的六大议题
"Lonely Walking on the Moon" is a powerful medicine, it can't cure the internal friction of happy twist
CReFF缓解长尾数据联邦学习(IJCAI 2022)
随机推荐
03 多线程与高并发 - ReentrantLock 源码解析
内存定位利器-ASAN使用小结
du命令_set命令选项
【VSCode】一文详解vscode下安装vim后无法使用Ctrl+CV复制粘贴 使用Vim插件的配置记录
yum 查看已经安装过的包并卸载
一文梳理NLP主要模型发展脉络
Js获取当前页面url参数
TS---类型设置
做项目管理有且有必要了解并学习的重要知识--PMP项目管理
JSX use
MFC的相机双目标定界面设计
Utility function---string processing
手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
Two years of independent development experience Programmers tell us the experience of making money (listen to the masters who really make money)
The head module of the yolo series
ReentrantLock 原理
router---mode
Oracle 19c 单实例 19.3.0 升级到19.11.0 详细教程
汉诺塔怎么玩
【PHP实现微信公众平台开发—基础篇】第2章 微信公众账号及申请流程详解