feat: 功能持续更新.

pull/161/head
chen.ma 3 years ago
parent 0e713a370e
commit 4f3d59b187

@ -0,0 +1,90 @@
package io.dynamic.threadpool.common.toolkit;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Collection;
import java.util.Map;
/**
*
*
* @author chen.ma
* @date 2021/6/29 09:36
*/
public class Assert {
public static void isTrue(boolean expression, String message) {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
public static void isTrue(boolean expression) {
isTrue(expression, "[Assertion failed] - this expression must be true");
}
public static void isNull(Object object, String message) {
if (object != null) {
throw new IllegalArgumentException(message);
}
}
public static void isNull(Object object) {
isNull(object, "[Assertion failed] - the object argument must be null");
}
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
public static void notNull(Object object) {
notNull(object, "[Assertion failed] - this argument is required; it must not be null");
}
public static void notEmpty(Collection<?> collection, String message) {
if (CollectionUtils.isEmpty(collection)) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(Collection<?> collection) {
notEmpty(collection,
"[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
}
public static void notEmpty(Map<?, ?> map, String message) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(Map<?, ?> map) {
notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
}
public static void notEmpty(String str, String message) {
if (StringUtils.isEmpty(str)) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(String str) {
if (StringUtils.isEmpty(str)) {
notEmpty(str, "[Assertion failed] - this string must not be empty");
}
}
public static void hasText(String text, String message) {
if (!StringUtils.hasText(text)) {
throw new IllegalArgumentException(message);
}
}
public static void hasText(String text) {
hasText(text,
"[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
}
}

@ -4,4 +4,4 @@ spring:
enabled: true
server-addr: http://localhost:6691
namespace: common
item-id: message
item-id: message-center

@ -15,11 +15,13 @@
<java.version>1.8</java.version>
<revision>1.0.0-SNAPSHOT</revision>
<dozer.version>6.5.0</dozer.version>
<okhttp3.version>3.8.1</okhttp3.version>
<hutool-core.version>5.4.7</hutool-core.version>
<fastjson.version>1.2.75</fastjson.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<mybatis-plus.version>3.4.2</mybatis-plus.version>
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
</properties>
@ -70,6 +72,18 @@
<artifactId>common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.github.dozermapper</groupId>
<artifactId>dozer-core</artifactId>
<version>${dozer.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

@ -27,8 +27,8 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
@ -51,6 +51,11 @@
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>com.github.dozermapper</groupId>
<artifactId>dozer-core</artifactId>
</dependency>
</dependencies>
<build>

@ -1,5 +1,6 @@
package io.dynamic.threadpool.server;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -7,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
scanBasePackages = {
"io.dynamic.threadpool.common.config", "io.dynamic.threadpool.server"
})
@MapperScan("io.dynamic.threadpool.server.mapper")
public class ServerApplication {
public static void main(String[] args) {

@ -0,0 +1,25 @@
package io.dynamic.threadpool.server.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Mybatis Plus Config.
*
* @author chen.ma
* @date 2021/6/29 20:22
*/
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
}

@ -1,17 +0,0 @@
package io.dynamic.threadpool.server.controller;
import io.dynamic.threadpool.common.constant.Constants;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author chen.ma
* @date 2021/6/25 18:31
*/
@RestController
@RequestMapping(Constants.BASE_PATH)
public class BizController {
}

@ -0,0 +1,54 @@
package io.dynamic.threadpool.server.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.dynamic.threadpool.common.constant.Constants;
import io.dynamic.threadpool.common.web.base.Result;
import io.dynamic.threadpool.common.web.base.Results;
import io.dynamic.threadpool.server.model.biz.item.ItemQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemRespDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemSaveReqDTO;
import io.dynamic.threadpool.server.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* Item Controller.
*
* @author chen.ma
* @date 2021/6/29 21:42
*/
@RestController
@RequestMapping(Constants.BASE_PATH)
public class ItemController {
@Autowired
private ItemService itemService;
@PostMapping("/item/query/page")
public Result<IPage<ItemRespDTO>> queryItemPage(@RequestBody ItemQueryReqDTO reqDTO) {
return Results.success(itemService.queryItemPage(reqDTO));
}
@GetMapping("/item/query/{itemId}")
public Result queryItemById(@PathVariable("itemId") String itemId) {
return Results.success(itemService.queryItemById(itemId));
}
@PostMapping("/item/save")
public Result saveItem(@RequestBody ItemSaveReqDTO reqDTO) {
itemService.saveItem(reqDTO);
return Results.success();
}
@PostMapping("/item/update")
public Result updateItem() {
return Results.success();
}
@DeleteMapping("/item/delete/{itemId}")
public Result deleteItem(@PathVariable("itemId") String itemId) {
return Results.success();
}
}

@ -0,0 +1,55 @@
package io.dynamic.threadpool.server.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.dynamic.threadpool.common.constant.Constants;
import io.dynamic.threadpool.common.web.base.Result;
import io.dynamic.threadpool.common.web.base.Results;
import io.dynamic.threadpool.server.model.biz.tenant.TenantQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantRespDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantSaveReqDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantUpdateReqDTO;
import io.dynamic.threadpool.server.service.TenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
*
*
* @author chen.ma
* @date 2021/6/25 18:31
*/
@RestController
@RequestMapping(Constants.BASE_PATH)
public class TenantController {
@Autowired
private TenantService tenantService;
@PostMapping("/namespace/query/page")
public Result<IPage<TenantRespDTO>> queryNameSpacePage(@RequestBody TenantQueryReqDTO reqDTO) {
return Results.success(tenantService.queryNameSpacePage(reqDTO));
}
@GetMapping("/namespace/query/{namespaceId}")
public Result<TenantRespDTO> queryNameSpace(@PathVariable("namespaceId") String namespaceId) {
return Results.success(tenantService.getNameSpaceById(namespaceId));
}
@PostMapping("/namespace/save")
public Result saveNameSpace(@RequestBody TenantSaveReqDTO reqDTO) {
tenantService.saveNameSpace(reqDTO);
return Results.success();
}
@PostMapping("/namespace/update")
public Result updateNameSpace(@RequestBody TenantUpdateReqDTO reqDTO) {
tenantService.updateNameSpace(reqDTO);
return Results.success();
}
@DeleteMapping("/item/delete/{namespaceId}")
public Result deleteNameSpace(@PathVariable("namespaceId") String namespaceId) {
tenantService.deleteNameSpaceById(namespaceId);
return Results.success();
}
}

@ -0,0 +1,40 @@
package io.dynamic.threadpool.server.enums;
/**
*
*
* @author chen.ma
* @date 2021/3/26 18:45
*/
public enum DelEnum {
/**
*
*/
NORMAL("0"),
/**
*
*/
DELETE("1");
private final String statusCode;
DelEnum(String statusCode) {
this.statusCode = statusCode;
}
public String getCode() {
return this.statusCode;
}
public Integer getIntCode() {
return Integer.parseInt(this.statusCode);
}
@Override
public String toString() {
return statusCode;
}
}

@ -0,0 +1,15 @@
package io.dynamic.threadpool.server.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.dynamic.threadpool.server.model.ConfigAllInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* Config Info Mapper.
*
* @author chen.ma
* @date 2021/6/29 22:44
*/
@Mapper
public interface ConfigInfoMapper extends BaseMapper<ConfigAllInfo> {
}

@ -0,0 +1,15 @@
package io.dynamic.threadpool.server.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.dynamic.threadpool.server.model.ItemInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* Item Info Mapper.
*
* @author chen.ma
* @date 2021/6/29 21:53
*/
@Mapper
public interface ItemInfoMapper extends BaseMapper<ItemInfo> {
}

@ -1,43 +0,0 @@
package io.dynamic.threadpool.server.mapper;
import io.dynamic.threadpool.server.model.ConfigAllInfo;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* ConfigAllInfoRowMapper
*
* @author chen.ma
* @date 2021/6/20 15:57
*/
public final class RowMapperManager {
public static final ConfigAllInfoRowMapper CONFIG_ALL_INFO_ROW_MAPPER = new ConfigAllInfoRowMapper();
public static class ConfigAllInfoRowMapper implements RowMapper<ConfigAllInfo> {
@Override
public ConfigAllInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
ConfigAllInfo configAllInfo = new ConfigAllInfo();
configAllInfo.setTpId(rs.getString("tp_id"));
configAllInfo.setItemId(rs.getString("item_id"));
configAllInfo.setNamespace(rs.getString("tenant_id"));
configAllInfo.setContent(rs.getString("content"));
configAllInfo.setCoreSize(rs.getInt("core_size"));
configAllInfo.setMaxSize(rs.getInt("max_size"));
configAllInfo.setQueueType(rs.getInt("queue_type"));
configAllInfo.setCapacity(rs.getInt("capacity"));
configAllInfo.setKeepAliveTime(rs.getInt("keep_alive_time"));
configAllInfo.setIsAlarm(rs.getInt("is_alarm"));
configAllInfo.setCapacityAlarm(rs.getInt("capacity_alarm"));
configAllInfo.setLivenessAlarm(rs.getInt("liveness_alarm"));
configAllInfo.setMd5(rs.getString("md5"));
configAllInfo.setCreateTime(rs.getTimestamp("gmt_modified").getTime());
configAllInfo.setModifyTime(rs.getTimestamp("gmt_modified").getTime());
return configAllInfo;
}
}
}

@ -0,0 +1,15 @@
package io.dynamic.threadpool.server.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.dynamic.threadpool.server.model.TenantInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* Tenant Info Mapper.
*
* @author chen.ma
* @date 2021/6/29 22:44
*/
@Mapper
public interface TenantInfoMapper extends BaseMapper<TenantInfo> {
}

@ -1,9 +1,14 @@
package io.dynamic.threadpool.server.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.dynamic.threadpool.common.model.PoolParameter;
import lombok.Data;
import java.util.Date;
/**
*
*
@ -11,19 +16,18 @@ import lombok.Data;
* @date 2021/6/20 15:14
*/
@Data
@TableName("config_info")
public class ConfigAllInfo extends ConfigInfo implements PoolParameter {
private static final long serialVersionUID = -2417394244017463665L;
@JSONField(serialize = false)
private String createUser;
@JSONField(serialize = false)
@TableField(exist = false, fill = FieldFill.UPDATE)
private String desc;
@JSONField(serialize = false)
private Long createTime;
private Date gmtCreate;
@JSONField(serialize = false)
private Long modifyTime;
private Date gmtModified;
}

@ -13,5 +13,4 @@ public class ConfigInfo extends ConfigInfoBase {
private static final long serialVersionUID = -3504960832191834675L;
private String namespace;
}

@ -1,6 +1,7 @@
package io.dynamic.threadpool.server.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.Serializable;
@ -16,9 +17,15 @@ public class ConfigInfoBase implements Serializable {
private static final long serialVersionUID = -1892597426099265730L;
/**
* ID
*/
private Integer id;
/**
* namespace
*/
@TableField(value = "tenant_id")
private String namespace;
/**

@ -0,0 +1,33 @@
package io.dynamic.threadpool.server.model;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
* Item Info.
*
* @author chen.ma
* @date 2021/6/29 21:53
*/
@Data
@TableName("item_info")
public class ItemInfo {
private Integer id;
private String tenantId;
private String itemId;
private String itemName;
private String itemDesc;
private String owner;
private Date gmtCreate;
private Date gmtModified;
}

@ -0,0 +1,60 @@
package io.dynamic.threadpool.server.model;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
* 线
*
* @author chen.ma
* @date 2021/6/29 22:04
*/
@Data
@TableName("tenant_info")
public class TenantInfo {
/**
* ID
*/
private Integer id;
/**
* ID
*/
private String tenantId;
/**
*
*/
private String tenantName;
/**
*
*/
private String tenantDesc;
/**
*
*/
private String owner;
/**
*
*/
private Date gmtCreate;
/**
*
*/
private Date gmtModified;
/**
*
*/
@TableLogic
private Integer delFlag;
}

@ -0,0 +1,22 @@
package io.dynamic.threadpool.server.model.biz.item;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
/**
* Item Query Req DTO.
*
* @author chen.ma
* @date 2021/6/29 22:28
*/
@Data
public class ItemQueryReqDTO extends Page {
private String tenantId;
private String itemId;
private String itemName;
private String owner;
}

@ -0,0 +1,13 @@
package io.dynamic.threadpool.server.model.biz.item;
import lombok.Data;
/**
*
*
* @author chen.ma
* @date 2021/6/29 21:15
*/
@Data
public class ItemRespDTO {
}

@ -0,0 +1,24 @@
package io.dynamic.threadpool.server.model.biz.item;
import lombok.Data;
/**
* Item Save Req DTO.
*
* @author chen.ma
* @date 2021/6/29 22:05
*/
@Data
public class ItemSaveReqDTO {
private String tenantId;
private String itemId;
private String itemName;
private String itemDesc;
private String owner;
}

@ -0,0 +1,22 @@
package io.dynamic.threadpool.server.model.biz.item;
import lombok.Data;
/**
* Item Update Req DTO.
*
* @author chen.ma
* @date 2021/6/29 22:05
*/
@Data
public class ItemUpdateReqDTO {
private String itemId;
private String itemName;
private String itemDesc;
private String owner;
}

@ -0,0 +1,20 @@
package io.dynamic.threadpool.server.model.biz.tenant;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
/**
* Tenant Query Req DTO.
*
* @author chen.ma
* @date 2021/6/29 22:28
*/
@Data
public class TenantQueryReqDTO extends Page {
private String tenantId;
private String tenantName;
private String owner;
}

@ -0,0 +1,50 @@
package io.dynamic.threadpool.server.model.biz.tenant;
import lombok.Data;
import java.util.Date;
/**
* 线
*
* @author chen.ma
* @date 2021/6/29 21:16
*/
@Data
public class TenantRespDTO {
/**
* ID
*/
private Integer id;
/**
* ID
*/
private String tenantId;
/**
*
*/
private String tenantName;
/**
*
*/
private String tenantDesc;
/**
*
*/
private String owner;
/**
*
*/
private Date gmtCreate;
/**
*
*/
private Date gmtModified;
}

@ -0,0 +1,34 @@
package io.dynamic.threadpool.server.model.biz.tenant;
import lombok.Data;
/**
* Tenant Save Req DTO.
*
* @author chen.ma
* @date 2021/6/29 20:40
*/
@Data
public class TenantSaveReqDTO {
/**
* ID
*/
private String tenantId;
/**
*
*/
private String tenantName;
/**
*
*/
private String tenantDesc;
/**
*
*/
private String owner;
}

@ -0,0 +1,34 @@
package io.dynamic.threadpool.server.model.biz.tenant;
import lombok.Data;
/**
* Tenant Save Req DTO.
*
* @author chen.ma
* @date 2021/6/29 20:40
*/
@Data
public class TenantUpdateReqDTO {
/**
* ID
*/
private String namespaceId;
/**
*
*/
private String tenantName;
/**
*
*/
private String tenantDesc;
/**
*
*/
private String owner;
}

@ -0,0 +1,57 @@
package io.dynamic.threadpool.server.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.dynamic.threadpool.server.model.biz.item.ItemQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemRespDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemSaveReqDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemUpdateReqDTO;
import java.util.List;
/**
* Item Service.
*
* @author chen.ma
* @date 2021/6/29 21:57
*/
public interface ItemService {
/**
*
*
* @param reqDTO
* @return
*/
IPage<ItemRespDTO> queryItemPage(ItemQueryReqDTO reqDTO);
/**
* Id
*
* @param itemId
* @return
*/
ItemRespDTO queryItemById(String itemId);
/**
*
*
* @param reqDTO
* @return
*/
List<ItemRespDTO> queryItem(ItemQueryReqDTO reqDTO);
/**
*
*
* @param reqDTO
*/
void saveItem(ItemSaveReqDTO reqDTO);
/**
*
*
* @param reqDTO
*/
void updateItem(ItemUpdateReqDTO reqDTO);
}

@ -0,0 +1,54 @@
package io.dynamic.threadpool.server.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.dynamic.threadpool.server.model.biz.tenant.TenantQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantRespDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantSaveReqDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantUpdateReqDTO;
/**
*
*
* @author chen.ma
* @date 2021/6/29 21:59
*/
public interface TenantService {
/**
* Id 线
*
* @param namespaceId
* @return
*/
TenantRespDTO getNameSpaceById(String namespaceId);
/**
* 线
*
* @param reqDTO
* @return
*/
IPage<TenantRespDTO> queryNameSpacePage(TenantQueryReqDTO reqDTO);
/**
* 线
*
* @param reqDTO
*/
void saveNameSpace(TenantSaveReqDTO reqDTO);
/**
* 线
*
* @param reqDTO
*/
void updateNameSpace(TenantUpdateReqDTO reqDTO);
/**
* Id 线
*
* @param namespaceId
*/
void deleteNameSpaceById(String namespaceId);
}

@ -1,20 +1,16 @@
package io.dynamic.threadpool.server.service.impl;
import io.dynamic.threadpool.common.toolkit.ContentUtil;
import io.dynamic.threadpool.common.toolkit.Md5Util;
import io.dynamic.threadpool.server.mapper.RowMapperManager;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import io.dynamic.threadpool.server.mapper.ConfigInfoMapper;
import io.dynamic.threadpool.server.model.ConfigAllInfo;
import io.dynamic.threadpool.server.service.ConfigService;
import io.dynamic.threadpool.server.toolkit.Md5ConfigUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Service;
import java.sql.PreparedStatement;
import java.sql.Statement;
import javax.annotation.Resource;
/**
*
@ -26,16 +22,16 @@ import java.sql.Statement;
@Service
public class ConfigServiceImpl implements ConfigService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Resource
private ConfigInfoMapper configInfoMapper;
@Override
public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String namespace) {
ConfigAllInfo configAllInfo = jdbcTemplate.queryForObject(
"select * from config_info where tp_id = ? and item_id = ? and tenant_id = ?",
new Object[]{tpId, itemId, namespace},
RowMapperManager.CONFIG_ALL_INFO_ROW_MAPPER);
LambdaQueryWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
.eq(ConfigAllInfo::getTpId, tpId)
.eq(ConfigAllInfo::getItemId, itemId)
.eq(ConfigAllInfo::getNamespace, namespace);
ConfigAllInfo configAllInfo = configInfoMapper.selectOne(wrapper);
return configAllInfo;
}
@ -48,50 +44,26 @@ public class ConfigServiceImpl implements ConfigService {
}
}
private Long addConfigInfo(ConfigAllInfo config) {
final String sql = "INSERT INTO `config_info` (`tenant_id`, `item_id`, `tp_id`, `core_size`, `max_size`, `queue_type`, `capacity`, `keep_alive_time`, `content`, `md5`, `is_alarm`, `capacity_alarm`, `liveness_alarm`) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
KeyHolder keyHolder = new GeneratedKeyHolder();
private Integer addConfigInfo(ConfigAllInfo config) {
try {
jdbcTemplate.update(con -> {
PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, config.getNamespace());
ps.setString(2, config.getItemId());
ps.setString(3, config.getTpId());
ps.setInt(4, config.getCoreSize());
ps.setInt(5, config.getMaxSize());
ps.setInt(6, config.getQueueType());
ps.setInt(7, config.getCapacity());
ps.setInt(8, config.getKeepAliveTime());
ps.setString(9, config.getContent());
ps.setString(10, Md5ConfigUtil.getTpContentMd5(config));
ps.setInt(11, config.getIsAlarm());
ps.setInt(12, config.getCapacityAlarm());
ps.setInt(13, config.getLivenessAlarm());
return ps;
}, keyHolder);
Number number = keyHolder.getKey();
if (number == null) {
throw new IllegalArgumentException("insert config_info fail");
if (SqlHelper.retBool(configInfoMapper.insert(config))) {
return config.getId();
}
return number.longValue();
} catch (Exception ex) {
log.error("[db-error] message :: {}", ex.getMessage(), ex);
throw ex;
}
return null;
}
private void updateConfigInfo(ConfigAllInfo config) {
LambdaUpdateWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaUpdate(ConfigAllInfo.class)
.eq(ConfigAllInfo::getTpId, config.getTpId())
.eq(ConfigAllInfo::getItemId, config.getItemId())
.eq(ConfigAllInfo::getNamespace, config.getNamespace());
try {
String poolContent = ContentUtil.getPoolContent(config);
String md5 = Md5Util.md5Hex(poolContent, "UTF-8");
jdbcTemplate.update("update config_info set core_size = ?, max_size = ?, queue_type = ?, capacity = ?, keep_alive_time = ?, content = ?, md5 = ?, is_alarm = ?, capacity_alarm = ?, liveness_alarm = ? " +
"where tenant_id = ? and item_id = ? and tp_id = ?",
config.getCoreSize(), config.getMaxSize(), config.getQueueType(), config.getCapacity(), config.getKeepAliveTime(),
poolContent, md5, config.getIsAlarm(), config.getCapacityAlarm(),
config.getLivenessAlarm(), config.getNamespace(), config.getItemId(), config.getTpId());
configInfoMapper.update(config, wrapper);
} catch (Exception ex) {
log.error("[db-error] message :: {}", ex.getMessage(), ex);
throw ex;

@ -0,0 +1,88 @@
package io.dynamic.threadpool.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import io.dynamic.threadpool.server.mapper.ItemInfoMapper;
import io.dynamic.threadpool.server.model.ItemInfo;
import io.dynamic.threadpool.server.model.biz.item.ItemQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemRespDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemSaveReqDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemUpdateReqDTO;
import io.dynamic.threadpool.server.service.ItemService;
import io.dynamic.threadpool.server.toolkit.BeanUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* Item Service Impl.
*
* @author chen.ma
* @date 2021/6/29 21:58
*/
@Service
public class ItemServiceImpl implements ItemService {
@Resource
private ItemInfoMapper itemInfoMapper;
@Override
public IPage<ItemRespDTO> queryItemPage(ItemQueryReqDTO reqDTO) {
LambdaQueryWrapper<ItemInfo> wrapper = Wrappers.lambdaQuery(ItemInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getItemId()), ItemInfo::getItemId, reqDTO.getItemId())
.eq(!StringUtils.isEmpty(reqDTO.getItemName()), ItemInfo::getItemName, reqDTO.getItemName())
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId())
.eq(!StringUtils.isEmpty(reqDTO.getOwner()), ItemInfo::getOwner, reqDTO.getOwner());
Page resultPage = itemInfoMapper.selectPage(reqDTO, wrapper);
return resultPage.convert(each -> BeanUtil.convert(each, ItemRespDTO.class));
}
@Override
public ItemRespDTO queryItemById(String itemId) {
LambdaQueryWrapper<ItemInfo> queryWrapper = Wrappers
.lambdaQuery(ItemInfo.class).eq(ItemInfo::getItemId, itemId);
ItemInfo itemInfo = itemInfoMapper.selectOne(queryWrapper);
ItemRespDTO result = BeanUtil.convert(itemInfo, ItemRespDTO.class);
return result;
}
@Override
public List<ItemRespDTO> queryItem(ItemQueryReqDTO reqDTO) {
LambdaQueryWrapper<ItemInfo> wrapper = Wrappers.lambdaQuery(ItemInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getItemId()), ItemInfo::getItemId, reqDTO.getItemId())
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId());
List<ItemInfo> itemInfos = itemInfoMapper.selectList(wrapper);
return BeanUtil.convert(itemInfos, ItemRespDTO.class);
}
@Override
public void saveItem(ItemSaveReqDTO reqDTO) {
ItemInfo itemInfo = BeanUtil.convert(reqDTO, ItemInfo.class);
int insertResult = itemInfoMapper.insert(itemInfo);
boolean retBool = SqlHelper.retBool(insertResult);
if (!retBool) {
throw new RuntimeException("插入失败.");
}
}
@Override
public void updateItem(ItemUpdateReqDTO reqDTO) {
ItemInfo itemInfo = BeanUtil.convert(reqDTO, ItemInfo.class);
int updateResult = itemInfoMapper.update(itemInfo, Wrappers
.lambdaUpdate(ItemInfo.class).eq(ItemInfo::getItemId, reqDTO.getItemId()));
boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) {
throw new RuntimeException("修改失败.");
}
}
}

@ -0,0 +1,104 @@
package io.dynamic.threadpool.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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 io.dynamic.threadpool.server.enums.DelEnum;
import io.dynamic.threadpool.server.mapper.TenantInfoMapper;
import io.dynamic.threadpool.server.model.TenantInfo;
import io.dynamic.threadpool.server.model.biz.item.ItemQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.item.ItemRespDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantQueryReqDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantRespDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantSaveReqDTO;
import io.dynamic.threadpool.server.model.biz.tenant.TenantUpdateReqDTO;
import io.dynamic.threadpool.server.service.ItemService;
import io.dynamic.threadpool.server.service.TenantService;
import io.dynamic.threadpool.server.toolkit.BeanUtil;
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;
/**
*
*
* @author chen.ma
* @date 2021/6/29 21:12
*/
@Service
public class TenantServiceImpl implements TenantService {
@Autowired
private ItemService itemService;
@Resource
private TenantInfoMapper tenantInfoMapper;
@Override
public TenantRespDTO getNameSpaceById(String namespaceId) {
LambdaQueryWrapper<TenantInfo> queryWrapper = Wrappers
.lambdaQuery(TenantInfo.class).eq(TenantInfo::getTenantId, namespaceId);
TenantInfo tenantInfo = tenantInfoMapper.selectOne(queryWrapper);
TenantRespDTO result = BeanUtil.convert(tenantInfo, TenantRespDTO.class);
return result;
}
@Override
public IPage<TenantRespDTO> queryNameSpacePage(TenantQueryReqDTO reqDTO) {
LambdaQueryWrapper<TenantInfo> wrapper = Wrappers.lambdaQuery(TenantInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), TenantInfo::getTenantId, reqDTO.getTenantId())
.eq(!StringUtils.isEmpty(reqDTO.getTenantName()), TenantInfo::getTenantName, reqDTO.getTenantName())
.eq(!StringUtils.isEmpty(reqDTO.getOwner()), TenantInfo::getOwner, reqDTO.getOwner());
Page resultPage = tenantInfoMapper.selectPage(reqDTO, wrapper);
return resultPage.convert(each -> BeanUtil.convert(each, TenantRespDTO.class));
}
@Override
public void saveNameSpace(TenantSaveReqDTO reqDTO) {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int insertResult = tenantInfoMapper.insert(tenantInfo);
boolean retBool = SqlHelper.retBool(insertResult);
if (!retBool) {
throw new RuntimeException("插入失败.");
}
}
@Override
public void updateNameSpace(TenantUpdateReqDTO reqDTO) {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers
.lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, reqDTO.getNamespaceId()));
boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) {
throw new RuntimeException("修改失败.");
}
}
@Override
public void deleteNameSpaceById(String namespaceId) {
TenantInfo tenantInfo = new TenantInfo();
tenantInfo.setDelFlag(DelEnum.DELETE.getIntCode());
ItemQueryReqDTO reqDTO = new ItemQueryReqDTO();
reqDTO.setTenantId(namespaceId);
List<ItemRespDTO> itemList = itemService.queryItem(reqDTO);
if (CollectionUtils.isNotEmpty(itemList)) {
throw new RuntimeException("业务线包含项目引用, 删除失败.");
}
int updateResult = tenantInfoMapper.update(tenantInfo,
Wrappers.lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, namespaceId));
boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) {
throw new RuntimeException("删除失败.");
}
}
}

@ -0,0 +1,142 @@
package io.dynamic.threadpool.server.toolkit;
import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.core.loader.api.BeanMappingBuilder;
import java.lang.reflect.Array;
import java.util.*;
import static com.github.dozermapper.core.loader.api.TypeMappingOptions.mapEmptyString;
import static com.github.dozermapper.core.loader.api.TypeMappingOptions.mapNull;
/**
*
*
* @author chen.ma
* @date 2021/3/19 15:40
*/
public class BeanUtil {
private BeanUtil() {
}
protected static Mapper BEAN_MAPPER_BUILDER;
static {
BEAN_MAPPER_BUILDER = DozerBeanMapperBuilder.buildDefault();
}
/**
*
*
* @param source
* @param clazz
* @param <T>
* @param <S>
* @return
*/
public static <T, S> T convert(S source, Class<T> clazz) {
return Optional.ofNullable(source)
.map(each -> BEAN_MAPPER_BUILDER.map(each, clazz))
.orElse(null);
}
/**
*
*
* @param sources
* @param clazz
* @param <T>
* @param <S>
* @return
*/
public static <T, S> List<T> convert(List<S> sources, Class<T> clazz) {
return Optional.ofNullable(sources)
.map(each -> {
List<T> targetList = new ArrayList<T>(each.size());
each.parallelStream()
.forEach(item -> targetList.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
return targetList;
})
.orElse(null);
}
/**
*
*
* @param sources
* @param clazz
* @param <T>
* @param <S>
* @return
*/
public static <T, S> Set<T> convert(Set<S> sources, Class<T> clazz) {
return Optional.ofNullable(sources)
.map(each -> {
Set<T> targetSize = new HashSet<T>(each.size());
each.parallelStream()
.forEach(item -> targetSize.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
return targetSize;
})
.orElse(null);
}
/**
*
*
* @param sources
* @param clazz
* @param <T>
* @param <S>
* @return
*/
public static <T, S> T[] convert(S[] sources, Class<T> clazz) {
return Optional.ofNullable(sources)
.map(each -> {
@SuppressWarnings("unchecked")
T[] targetArray = (T[]) Array.newInstance(clazz, sources.length);
for (int i = 0; i < targetArray.length; i++) {
targetArray[i] = BEAN_MAPPER_BUILDER.map(sources[i], clazz);
}
return targetArray;
})
.orElse(null);
}
/**
*
*
* @param source
* @param target
*/
public static void convertIgnoreNullAndBlank(Object source, Object target) {
DozerBeanMapperBuilder dozerBeanMapperBuilder = DozerBeanMapperBuilder.create();
Mapper mapper = dozerBeanMapperBuilder.withMappingBuilders(new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(source.getClass(), target.getClass(), mapNull(false), mapEmptyString(false));
}
}).build();
mapper.map(source, target);
}
/**
*
*
* @param source
* @param target
*/
public static void convertIgnoreNull(Object source, Object target) {
DozerBeanMapperBuilder dozerBeanMapperBuilder = DozerBeanMapperBuilder.create();
Mapper mapper = dozerBeanMapperBuilder.withMappingBuilders(new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(source.getClass(), target.getClass(), mapNull(false));
}
}).build();
mapper.map(source, target);
}
}

@ -7,3 +7,9 @@ spring:
url: jdbc:mysql://localhost:3306/dynamic-thread-pool
username: root
password: root
mybatis-plus:
global-config:
db-config:
logic-delete-value: 1
logic-not-delete-value: 0
Loading…
Cancel
Save