feat(商城): 部署脚本优化

master
wayn 1 year ago
parent 108eaeeb5e
commit 3522d6a38d

@ -1,4 +1,4 @@
package com.wayn.mobile.framework.config;
package com.wayn.common.config;
import com.wayn.common.task.ThreadPoolExecutorMdcWrapper;
import com.wayn.common.util.ThreadUtil;
@ -31,12 +31,12 @@ public class ThreadPoolConfig {
// 线程池维护线程所允许的空闲时间
private final int keepAliveSeconds = 300;
@Bean(name = "homeThreadPoolTaskExecutor")
@Bean(name = "commonThreadPoolTaskExecutor")
public ThreadPoolTaskExecutor homeThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = getThreadPoolTaskExecutor();
BasicThreadFactory build = new BasicThreadFactory.Builder()
.namingPattern("home-task-%d")
.uncaughtExceptionHandler((t, e) -> log.error("dongXinTaskExecutor:{},error:{}", t.getName(), e.getMessage(), e))
.uncaughtExceptionHandler((t, e) -> log.error("commonTaskExecutor:{},error:{}", t.getName(), e.getMessage(), e))
.build();
executor.setThreadFactory(build);
executor.initialize();
@ -57,18 +57,6 @@ public class ThreadPoolConfig {
return executor;
}
@Bean(name = "categoryThreadPoolTaskExecutor")
public ThreadPoolTaskExecutor categoryThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = getThreadPoolTaskExecutor();
BasicThreadFactory build = new BasicThreadFactory.Builder()
.namingPattern("category-task-%d")
.uncaughtExceptionHandler((t, e) -> log.error("dongXinTaskExecutor:{},error:{}", t.getName(), e.getMessage(), e))
.build();
executor.setThreadFactory(build);
executor.initialize();
return executor;
}
/**
*
*/

@ -9,7 +9,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future;
/**
* 线reqest_id
* 线request_id
*/
public class ThreadPoolExecutorMdcWrapper extends ThreadPoolTaskExecutor {

@ -3,6 +3,7 @@ package com.wayn.common.util.mail;
import com.sun.mail.util.MailSSLSocketFactory;
import com.wayn.common.core.domain.tool.EmailConfig;
import com.wayn.common.core.domain.vo.SendMailVO;
import com.wayn.common.util.spring.SpringContextUtil;
import jakarta.mail.Authenticator;
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;
@ -11,6 +12,7 @@ import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.List;
import java.util.Properties;
@ -22,53 +24,60 @@ import java.util.Properties;
public class MailUtil {
public static void sendMail(EmailConfig emailConfig, SendMailVO mailVO, boolean isHtml, boolean ssl) {
try {
// 设置发件人
String from = emailConfig.getFromUser();
// 设置收件人
List<String> tos = mailVO.getTos();
for (String to : tos) {
// 设置邮件发送的服务器这里为QQ邮件服务器
String host = emailConfig.getHost();
// 获取系统属性
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getPort()));
// SSL加密
if (ssl) {
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.ssl.socketFactory", sf);
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getSslPort()));
}
// 设置系统属性
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.transport.protocol", "smtp");
properties.put("mail.smtp.auth", "true");
// 获取发送邮件会话、获取第三方登录授权码
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, emailConfig.getPass());
if (emailConfig == null) {
log.warn("emailConfig is null");
return;
}
ThreadPoolTaskExecutor commonThreadPoolTaskExecutor = SpringContextUtil.getBean("commonThreadPoolTaskExecutor");
commonThreadPoolTaskExecutor.execute(() -> {
try {
// 设置发件人
String from = emailConfig.getFromUser();
// 设置收件人
List<String> tos = mailVO.getTos();
for (String to : tos) {
// 设置邮件发送的服务器这里为QQ邮件服务器
String host = emailConfig.getHost();
// 获取系统属性
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getPort()));
// SSL加密
if (ssl) {
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.ssl.socketFactory", sf);
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getSslPort()));
}
});
session.setDebug(false);
// 创建默认的 MimeMessage 对象
MimeMessage message = new MimeMessage(session);
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
// Set From: 头部头字段
helper.setFrom(new InternetAddress(from));
// Set To: 头部头字段
helper.setTo(to);
// Set Subject: 头部头字段
helper.setSubject(mailVO.getSubject());
// 设置消息体
helper.setText(mailVO.getContent(), isHtml);
Transport.send(message);
log.info("邮件发送成功");
// 设置系统属性
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.transport.protocol", "smtp");
properties.put("mail.smtp.auth", "true");
// 获取发送邮件会话、获取第三方登录授权码
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, emailConfig.getPass());
}
});
session.setDebug(false);
// 创建默认的 MimeMessage 对象
MimeMessage message = new MimeMessage(session);
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
// Set From: 头部头字段
helper.setFrom(new InternetAddress(from));
// Set To: 头部头字段
helper.setTo(to);
// Set Subject: 头部头字段
helper.setSubject(mailVO.getSubject());
// 设置消息体
helper.setText(mailVO.getContent(), isHtml);
Transport.send(message);
log.info("邮件发送成功");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
}

@ -32,7 +32,7 @@ public class CategoryController extends BaseController {
private ICategoryService iCategoryService;
private IGoodsService iGoodsService;
private ThreadPoolTaskExecutor categoryThreadPoolTaskExecutor;
private ThreadPoolTaskExecutor commonThreadPoolTaskExecutor;
@GetMapping("index")
public R index(@RequestParam(required = false) Long id) {
@ -49,8 +49,8 @@ public class CategoryController extends BaseController {
}
FutureTask<Category> currentCategoryTask = new FutureTask<>(currentCategoryCallable);
FutureTask<List<VanTreeSelectVo>> subCategoryListTask = new FutureTask<>(subCategoryListCallable);
categoryThreadPoolTaskExecutor.submit(currentCategoryTask);
categoryThreadPoolTaskExecutor.submit(subCategoryListTask);
commonThreadPoolTaskExecutor.submit(currentCategoryTask);
commonThreadPoolTaskExecutor.submit(subCategoryListTask);
try {
success.add("categoryList", categoryList);
success.add("currentCategory", currentCategoryTask.get());
@ -69,8 +69,8 @@ public class CategoryController extends BaseController {
Callable<List<VanTreeSelectVo>> subCategoryListCallable = () -> iCategoryService.selectCategoryByPid(id);
FutureTask<Category> currentCategoryTask = new FutureTask<>(currentCategoryCallable);
FutureTask<List<VanTreeSelectVo>> subCategoryListTask = new FutureTask<>(subCategoryListCallable);
categoryThreadPoolTaskExecutor.submit(currentCategoryTask);
categoryThreadPoolTaskExecutor.submit(subCategoryListTask);
commonThreadPoolTaskExecutor.submit(currentCategoryTask);
commonThreadPoolTaskExecutor.submit(subCategoryListTask);
try {
success.add("currentCategory", currentCategoryTask.get());
success.add("subCategoryList", subCategoryListTask.get());

@ -29,7 +29,7 @@ public class GoodsDetailServiceImpl implements IGoodsDetailService {
private IGoodsSpecificationService iGoodsSpecificationService;
private IGoodsProductService iGoodsProductService;
private IGoodsAttributeService iGoodsAttributeService;
private ThreadPoolTaskExecutor homeThreadPoolTaskExecutor;
private ThreadPoolTaskExecutor commonThreadPoolTaskExecutor;
@Override
public R getGoodsDetailData(Long goodsId) {
@ -41,9 +41,9 @@ public class GoodsDetailServiceImpl implements IGoodsDetailService {
FutureTask<Object> specificationTask = new FutureTask<>(specificationCall);
FutureTask<List<GoodsProduct>> productTask = new FutureTask<>(productCall);
FutureTask<List<GoodsAttribute>> attrTask = new FutureTask<>(attrCall);
homeThreadPoolTaskExecutor.submit(specificationTask);
homeThreadPoolTaskExecutor.submit(productTask);
homeThreadPoolTaskExecutor.submit(attrTask);
commonThreadPoolTaskExecutor.submit(specificationTask);
commonThreadPoolTaskExecutor.submit(productTask);
commonThreadPoolTaskExecutor.submit(attrTask);
try {
success.add("info", iGoodsService.getById(goodsId));
success.add("specificationList", specificationTask.get());

@ -41,7 +41,7 @@ public class IHomeServiceImpl implements IHomeService {
private RedisCache redisCache;
private RedisTemplate<String, Object> redisTemplate;
private IDiamondService iDiamondService;
private ThreadPoolTaskExecutor homeThreadPoolTaskExecutor;
private ThreadPoolTaskExecutor commonThreadPoolTaskExecutor;
@Override
@ -60,7 +60,7 @@ public class IHomeServiceImpl implements IHomeService {
}
List<CompletableFuture<Void>> list = new ArrayList<>(4);
CompletableFuture<Void> f1 = CompletableFuture.supplyAsync(
() -> iBannerService.list(Wrappers.lambdaQuery(Banner.class).eq(Banner::getStatus, 0).orderByAsc(Banner::getSort)), homeThreadPoolTaskExecutor)
() -> iBannerService.list(Wrappers.lambdaQuery(Banner.class).eq(Banner::getStatus, 0).orderByAsc(Banner::getSort)), commonThreadPoolTaskExecutor)
.thenAccept(data -> {
String key = "bannerList";
redisCache.setCacheMapValue(SHOP_HOME_INDEX_HASH, key, data);
@ -68,7 +68,7 @@ public class IHomeServiceImpl implements IHomeService {
success.add(key, data);
});
CompletableFuture<Void> f2 = CompletableFuture.supplyAsync(
() -> iDiamondService.list(Wrappers.lambdaQuery(Diamond.class).orderByAsc(Diamond::getSort).last("limit 10")), homeThreadPoolTaskExecutor)
() -> iDiamondService.list(Wrappers.lambdaQuery(Diamond.class).orderByAsc(Diamond::getSort).last("limit 10")), commonThreadPoolTaskExecutor)
.thenAccept(data -> {
String key = "categoryList";
redisCache.setCacheMapValue(SHOP_HOME_INDEX_HASH, key, data);
@ -76,7 +76,7 @@ public class IHomeServiceImpl implements IHomeService {
success.add(key, data);
});
CompletableFuture<Void> f3 = CompletableFuture.supplyAsync(
() -> iGoodsService.selectHomeIndexGoods(Goods.builder().isNew(true).build()), homeThreadPoolTaskExecutor)
() -> iGoodsService.selectHomeIndexGoods(Goods.builder().isNew(true).build()), commonThreadPoolTaskExecutor)
.thenAccept(data -> {
String key = "newGoodsList";
redisCache.setCacheMapValue(SHOP_HOME_INDEX_HASH, key, data);
@ -84,7 +84,7 @@ public class IHomeServiceImpl implements IHomeService {
success.add(key, data);
});
CompletableFuture<Void> f4 = CompletableFuture.supplyAsync(
() -> iGoodsService.selectHomeIndexGoods(Goods.builder().isHot(true).build()), homeThreadPoolTaskExecutor)
() -> iGoodsService.selectHomeIndexGoods(Goods.builder().isHot(true).build()), commonThreadPoolTaskExecutor)
.thenAccept(data -> {
String key = "hotGoodsList";
redisCache.setCacheMapValue(SHOP_HOME_INDEX_HASH, key, data);

@ -5,7 +5,7 @@ import com.wayn.common.core.domain.shop.Member;
import com.wayn.common.core.service.shop.IMemberService;
import com.wayn.common.enums.UserStatusEnum;
import com.wayn.common.util.ip.IpUtils;
import com.wayn.mobile.framework.config.ThreadPoolConfig;
import com.wayn.common.config.ThreadPoolConfig;
import com.wayn.mobile.framework.manager.thread.AsyncManager;
import com.wayn.mobile.framework.security.LoginUserDetail;
import lombok.AllArgsConstructor;

Loading…
Cancel
Save