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,6 +24,12 @@ import java.util.Properties;
public class MailUtil {
public static void sendMail(EmailConfig emailConfig, SendMailVO mailVO, boolean isHtml, boolean ssl) {
if (emailConfig == null) {
log.warn("emailConfig is null");
return;
}
ThreadPoolTaskExecutor commonThreadPoolTaskExecutor = SpringContextUtil.getBean("commonThreadPoolTaskExecutor");
commonThreadPoolTaskExecutor.execute(() -> {
try {
// 设置发件人
String from = emailConfig.getFromUser();
@ -70,5 +78,6 @@ public class MailUtil {
} 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