From 056c403da3b532d97fe1fb37c854d1cf74e20c2a Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sat, 23 Oct 2021 00:47:21 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E8=B0=83=E6=95=B4=20Spring=20Bean=20?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E6=96=B9=E5=BC=8F=E4=B8=BA=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E5=99=A8=E6=B3=A8=E5=85=A5,=20=E4=BC=98=E5=8C=96=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/service/biz/ConfigServiceImpl.java | 11 +++++------ .../config/service/biz/ItemServiceImpl.java | 17 ++++++++--------- .../config/service/biz/TenantServiceImpl.java | 18 +++++++++--------- .../service/biz/ThreadPoolServiceImpl.java | 14 ++++++-------- .../config/toolkit/ConfigExecutor.java | 3 +-- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ConfigServiceImpl.java b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ConfigServiceImpl.java index aba12baa..84343a0e 100644 --- a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ConfigServiceImpl.java +++ b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ConfigServiceImpl.java @@ -11,11 +11,10 @@ import com.github.dynamic.threadpool.config.event.LocalDataChangeEvent; import com.github.dynamic.threadpool.config.mapper.ConfigInfoMapper; import com.github.dynamic.threadpool.config.model.ConfigAllInfo; import com.github.dynamic.threadpool.config.service.ConfigChangePublisher; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import javax.annotation.Resource; - /** * Config service impl. * @@ -24,10 +23,10 @@ import javax.annotation.Resource; */ @Slf4j @Service +@AllArgsConstructor public class ConfigServiceImpl implements ConfigService { - @Resource - private ConfigInfoMapper configInfoMapper; + private final ConfigInfoMapper configInfoMapper; @Override public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String tenantId) { @@ -47,8 +46,7 @@ public class ConfigServiceImpl implements ConfigService { updateConfigInfo(configAllInfo); } - ConfigChangePublisher - .notifyConfigChange(new LocalDataChangeEvent(ContentUtil.getGroupKey(configAllInfo))); + ConfigChangePublisher.notifyConfigChange(new LocalDataChangeEvent(ContentUtil.getGroupKey(configAllInfo))); } private Integer addConfigInfo(ConfigAllInfo config) { @@ -74,6 +72,7 @@ public class ConfigServiceImpl implements ConfigService { config.setGmtCreate(null); config.setContent(ContentUtil.getPoolContent(config)); config.setMd5(Md5Util.getTpContentMd5(config)); + try { configInfoMapper.update(config, wrapper); } catch (Exception ex) { diff --git a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ItemServiceImpl.java b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ItemServiceImpl.java index e8df8d74..62d00995 100644 --- a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ItemServiceImpl.java +++ b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ItemServiceImpl.java @@ -6,20 +6,19 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; +import com.github.dynamic.threadpool.config.enums.DelEnum; +import com.github.dynamic.threadpool.config.mapper.ItemInfoMapper; +import com.github.dynamic.threadpool.config.model.ItemInfo; import com.github.dynamic.threadpool.config.model.biz.item.ItemQueryReqDTO; import com.github.dynamic.threadpool.config.model.biz.item.ItemRespDTO; import com.github.dynamic.threadpool.config.model.biz.item.ItemSaveReqDTO; import com.github.dynamic.threadpool.config.model.biz.item.ItemUpdateReqDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO; -import com.github.dynamic.threadpool.config.enums.DelEnum; -import com.github.dynamic.threadpool.config.mapper.ItemInfoMapper; -import com.github.dynamic.threadpool.config.model.ItemInfo; import com.github.dynamic.threadpool.config.toolkit.BeanUtil; +import lombok.AllArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.util.List; /** @@ -29,13 +28,12 @@ import java.util.List; * @date 2021/6/29 21:58 */ @Service +@AllArgsConstructor public class ItemServiceImpl implements ItemService { - @Resource - private ItemInfoMapper itemInfoMapper; + private final ItemInfoMapper itemInfoMapper; - @Autowired - private ThreadPoolService threadPoolService; + private final ThreadPoolService threadPoolService; @Override public IPage queryItemPage(ItemQueryReqDTO reqDTO) { @@ -108,6 +106,7 @@ public class ItemServiceImpl implements ItemService { .eq(ItemInfo::getTenantId, namespace) .eq(ItemInfo::getItemId, itemId) .set(ItemInfo::getDelFlag, DelEnum.DELETE.getIntCode())); + boolean retBool = SqlHelper.retBool(updateResult); if (!retBool) { throw new RuntimeException("Delete error."); diff --git a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/TenantServiceImpl.java b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/TenantServiceImpl.java index 5fbcef1b..03369f41 100644 --- a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/TenantServiceImpl.java +++ b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/TenantServiceImpl.java @@ -6,21 +6,20 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; +import com.github.dynamic.threadpool.config.enums.DelEnum; +import com.github.dynamic.threadpool.config.mapper.TenantInfoMapper; +import com.github.dynamic.threadpool.config.model.TenantInfo; import com.github.dynamic.threadpool.config.model.biz.item.ItemQueryReqDTO; import com.github.dynamic.threadpool.config.model.biz.item.ItemRespDTO; import com.github.dynamic.threadpool.config.model.biz.tenant.TenantQueryReqDTO; import com.github.dynamic.threadpool.config.model.biz.tenant.TenantRespDTO; import com.github.dynamic.threadpool.config.model.biz.tenant.TenantSaveReqDTO; import com.github.dynamic.threadpool.config.model.biz.tenant.TenantUpdateReqDTO; -import com.github.dynamic.threadpool.config.enums.DelEnum; -import com.github.dynamic.threadpool.config.mapper.TenantInfoMapper; -import com.github.dynamic.threadpool.config.model.TenantInfo; import com.github.dynamic.threadpool.config.toolkit.BeanUtil; +import lombok.AllArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.util.List; /** @@ -30,13 +29,12 @@ import java.util.List; * @date 2021/6/29 21:12 */ @Service +@AllArgsConstructor public class TenantServiceImpl implements TenantService { - @Autowired - private ItemService itemService; + private final ItemService itemService; - @Resource - private TenantInfoMapper tenantInfoMapper; + private final TenantInfoMapper tenantInfoMapper; @Override public TenantRespDTO getTenantById(String tenantId) { @@ -75,6 +73,7 @@ public class TenantServiceImpl implements TenantService { TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class); int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers .lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, reqDTO.getTenantId())); + boolean retBool = SqlHelper.retBool(updateResult); if (!retBool) { throw new RuntimeException("Update Error."); @@ -94,6 +93,7 @@ public class TenantServiceImpl implements TenantService { Wrappers.lambdaUpdate(TenantInfo.class) .eq(TenantInfo::getTenantId, tenantId) .set(TenantInfo::getDelFlag, DelEnum.DELETE.getIntCode())); + boolean retBool = SqlHelper.retBool(updateResult); if (!retBool) { throw new RuntimeException("Delete error."); diff --git a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ThreadPoolServiceImpl.java b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ThreadPoolServiceImpl.java index 16fa4e34..314cc111 100644 --- a/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ThreadPoolServiceImpl.java +++ b/config/src/main/java/com/github/dynamic/threadpool/config/service/biz/ThreadPoolServiceImpl.java @@ -4,16 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.github.dynamic.threadpool.config.mapper.ConfigInfoMapper; +import com.github.dynamic.threadpool.config.model.ConfigAllInfo; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolQueryReqDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO; -import com.github.dynamic.threadpool.config.mapper.ConfigInfoMapper; -import com.github.dynamic.threadpool.config.model.ConfigAllInfo; import com.github.dynamic.threadpool.config.toolkit.BeanUtil; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.util.List; /** @@ -23,13 +22,12 @@ import java.util.List; * @date 2021/6/30 21:26 */ @Service +@AllArgsConstructor public class ThreadPoolServiceImpl implements ThreadPoolService { - @Autowired - private ConfigService configService; + private final ConfigService configService; - @Resource - private ConfigInfoMapper configInfoMapper; + private final ConfigInfoMapper configInfoMapper; @Override public IPage queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) { diff --git a/config/src/main/java/com/github/dynamic/threadpool/config/toolkit/ConfigExecutor.java b/config/src/main/java/com/github/dynamic/threadpool/config/toolkit/ConfigExecutor.java index ba4b0af6..473080b3 100644 --- a/config/src/main/java/com/github/dynamic/threadpool/config/toolkit/ConfigExecutor.java +++ b/config/src/main/java/com/github/dynamic/threadpool/config/toolkit/ConfigExecutor.java @@ -15,8 +15,7 @@ import java.util.concurrent.TimeUnit; public class ConfigExecutor { private static final ScheduledExecutorService LONG_POLLING_EXECUTOR = ExecutorFactory.Managed - .newSingleScheduledExecutorService("default group", - r -> new Thread(r, "long-polling")); + .newSingleScheduledExecutorService("default group", r -> new Thread(r, "long-polling")); public static void executeLongPolling(Runnable runnable) { LONG_POLLING_EXECUTOR.execute(runnable);