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.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) {

@ -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<ItemRespDTO> 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.");

@ -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.");

@ -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<ThreadPoolRespDTO> queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) {

@ -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);

Loading…
Cancel
Save