当前位置:网站首页>(记录)异步并发,多线程处理表的统计
(记录)异步并发,多线程处理表的统计
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;
}
边栏推荐
猜你喜欢
随机推荐
持续交付(二)PipeLine基本使用
CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔,可用于改善循环时间
Why don't young people like to buy Mengniu and Yili?
技术分享| 小程序实现音视频通话
Motion Rule (16)-Union Check Basic Questions-Relations
router---Programmatic navigation
持续交付(三)Jenkinsfile语法使用介绍
密码设置有关方法:不能相同字母,不能为连续字符
项目里的各种配置,你都了解吗?
微信小程序使用腾讯云对象储存上传图片
《会面》-凯瑟琳曼斯菲尔德(徐志摩译)
router---路由守卫
Interviewer: Tell me the difference between NIO and BIO
绩效考核带给员工的不能只是压力
“蔚来杯“2022牛客暑期多校训练营5 B、C、F、G、H、K
高手,云集在于REST、gRPC 和 GraphQL之间!
【自动微分实现】反向OO实现自动微分(Pytroch核心机制)
【毕设选题推荐】机器人工程专业毕设选题推荐
手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
c#学习_第二弹









