Feat: 调整 Spring Bean 注入方式为构造器注入, 优化样式.

pull/161/head
chen.ma 3 years ago
parent 0bf0af68c9
commit 056c403da3

@ -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.mapper.ConfigInfoMapper;
import com.github.dynamic.threadpool.config.model.ConfigAllInfo; import com.github.dynamic.threadpool.config.model.ConfigAllInfo;
import com.github.dynamic.threadpool.config.service.ConfigChangePublisher; import com.github.dynamic.threadpool.config.service.ConfigChangePublisher;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/** /**
* Config service impl. * Config service impl.
* *
@ -24,10 +23,10 @@ import javax.annotation.Resource;
*/ */
@Slf4j @Slf4j
@Service @Service
@AllArgsConstructor
public class ConfigServiceImpl implements ConfigService { public class ConfigServiceImpl implements ConfigService {
@Resource private final ConfigInfoMapper configInfoMapper;
private ConfigInfoMapper configInfoMapper;
@Override @Override
public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String tenantId) { public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String tenantId) {
@ -47,8 +46,7 @@ public class ConfigServiceImpl implements ConfigService {
updateConfigInfo(configAllInfo); updateConfigInfo(configAllInfo);
} }
ConfigChangePublisher ConfigChangePublisher.notifyConfigChange(new LocalDataChangeEvent(ContentUtil.getGroupKey(configAllInfo)));
.notifyConfigChange(new LocalDataChangeEvent(ContentUtil.getGroupKey(configAllInfo)));
} }
private Integer addConfigInfo(ConfigAllInfo config) { private Integer addConfigInfo(ConfigAllInfo config) {
@ -74,6 +72,7 @@ public class ConfigServiceImpl implements ConfigService {
config.setGmtCreate(null); config.setGmtCreate(null);
config.setContent(ContentUtil.getPoolContent(config)); config.setContent(ContentUtil.getPoolContent(config));
config.setMd5(Md5Util.getTpContentMd5(config)); config.setMd5(Md5Util.getTpContentMd5(config));
try { try {
configInfoMapper.update(config, wrapper); configInfoMapper.update(config, wrapper);
} catch (Exception ex) { } catch (Exception ex) {

@ -6,20 +6,19 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; 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.ItemQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.item.ItemRespDTO; 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.ItemSaveReqDTO;
import com.github.dynamic.threadpool.config.model.biz.item.ItemUpdateReqDTO; 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.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 com.github.dynamic.threadpool.config.toolkit.BeanUtil;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
@ -29,13 +28,12 @@ import java.util.List;
* @date 2021/6/29 21:58 * @date 2021/6/29 21:58
*/ */
@Service @Service
@AllArgsConstructor
public class ItemServiceImpl implements ItemService { public class ItemServiceImpl implements ItemService {
@Resource private final ItemInfoMapper itemInfoMapper;
private ItemInfoMapper itemInfoMapper;
@Autowired private final ThreadPoolService threadPoolService;
private ThreadPoolService threadPoolService;
@Override @Override
public IPage<ItemRespDTO> queryItemPage(ItemQueryReqDTO reqDTO) { public IPage<ItemRespDTO> queryItemPage(ItemQueryReqDTO reqDTO) {
@ -108,6 +106,7 @@ public class ItemServiceImpl implements ItemService {
.eq(ItemInfo::getTenantId, namespace) .eq(ItemInfo::getTenantId, namespace)
.eq(ItemInfo::getItemId, itemId) .eq(ItemInfo::getItemId, itemId)
.set(ItemInfo::getDelFlag, DelEnum.DELETE.getIntCode())); .set(ItemInfo::getDelFlag, DelEnum.DELETE.getIntCode()));
boolean retBool = SqlHelper.retBool(updateResult); boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) { if (!retBool) {
throw new RuntimeException("Delete error."); throw new RuntimeException("Delete error.");

@ -6,21 +6,20 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; 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.ItemQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.item.ItemRespDTO; 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.TenantQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.tenant.TenantRespDTO; 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.TenantSaveReqDTO;
import com.github.dynamic.threadpool.config.model.biz.tenant.TenantUpdateReqDTO; 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 com.github.dynamic.threadpool.config.toolkit.BeanUtil;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
@ -30,13 +29,12 @@ import java.util.List;
* @date 2021/6/29 21:12 * @date 2021/6/29 21:12
*/ */
@Service @Service
@AllArgsConstructor
public class TenantServiceImpl implements TenantService { public class TenantServiceImpl implements TenantService {
@Autowired private final ItemService itemService;
private ItemService itemService;
@Resource private final TenantInfoMapper tenantInfoMapper;
private TenantInfoMapper tenantInfoMapper;
@Override @Override
public TenantRespDTO getTenantById(String tenantId) { public TenantRespDTO getTenantById(String tenantId) {
@ -75,6 +73,7 @@ public class TenantServiceImpl implements TenantService {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class); TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers
.lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, reqDTO.getTenantId())); .lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, reqDTO.getTenantId()));
boolean retBool = SqlHelper.retBool(updateResult); boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) { if (!retBool) {
throw new RuntimeException("Update Error."); throw new RuntimeException("Update Error.");
@ -94,6 +93,7 @@ public class TenantServiceImpl implements TenantService {
Wrappers.lambdaUpdate(TenantInfo.class) Wrappers.lambdaUpdate(TenantInfo.class)
.eq(TenantInfo::getTenantId, tenantId) .eq(TenantInfo::getTenantId, tenantId)
.set(TenantInfo::getDelFlag, DelEnum.DELETE.getIntCode())); .set(TenantInfo::getDelFlag, DelEnum.DELETE.getIntCode()));
boolean retBool = SqlHelper.retBool(updateResult); boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) { if (!retBool) {
throw new RuntimeException("Delete error."); throw new RuntimeException("Delete error.");

@ -4,16 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.ThreadPoolQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO; 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.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 com.github.dynamic.threadpool.config.toolkit.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
@ -23,13 +22,12 @@ import java.util.List;
* @date 2021/6/30 21:26 * @date 2021/6/30 21:26
*/ */
@Service @Service
@AllArgsConstructor
public class ThreadPoolServiceImpl implements ThreadPoolService { public class ThreadPoolServiceImpl implements ThreadPoolService {
@Autowired private final ConfigService configService;
private ConfigService configService;
@Resource private final ConfigInfoMapper configInfoMapper;
private ConfigInfoMapper configInfoMapper;
@Override @Override
public IPage<ThreadPoolRespDTO> queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) { public IPage<ThreadPoolRespDTO> queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) {

@ -15,8 +15,7 @@ import java.util.concurrent.TimeUnit;
public class ConfigExecutor { public class ConfigExecutor {
private static final ScheduledExecutorService LONG_POLLING_EXECUTOR = ExecutorFactory.Managed private static final ScheduledExecutorService LONG_POLLING_EXECUTOR = ExecutorFactory.Managed
.newSingleScheduledExecutorService("default group", .newSingleScheduledExecutorService("default group", r -> new Thread(r, "long-polling"));
r -> new Thread(r, "long-polling"));
public static void executeLongPolling(Runnable runnable) { public static void executeLongPolling(Runnable runnable) {
LONG_POLLING_EXECUTOR.execute(runnable); LONG_POLLING_EXECUTOR.execute(runnable);

Loading…
Cancel
Save