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 enabled: true
server-addr: http://localhost:6691 server-addr: http://localhost:6691
namespace: common namespace: common
item-id: message item-id: message-center

@ -15,11 +15,13 @@
<java.version>1.8</java.version> <java.version>1.8</java.version>
<revision>1.0.0-SNAPSHOT</revision> <revision>1.0.0-SNAPSHOT</revision>
<dozer.version>6.5.0</dozer.version>
<okhttp3.version>3.8.1</okhttp3.version> <okhttp3.version>3.8.1</okhttp3.version>
<hutool-core.version>5.4.7</hutool-core.version> <hutool-core.version>5.4.7</hutool-core.version>
<fastjson.version>1.2.75</fastjson.version> <fastjson.version>1.2.75</fastjson.version>
<commons-lang3.version>3.12.0</commons-lang3.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> <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
</properties> </properties>
@ -70,6 +72,18 @@
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </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> </dependencies>
</dependencyManagement> </dependencyManagement>

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

@ -1,5 +1,6 @@
package io.dynamic.threadpool.server; package io.dynamic.threadpool.server;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -7,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
scanBasePackages = { scanBasePackages = {
"io.dynamic.threadpool.common.config", "io.dynamic.threadpool.server" "io.dynamic.threadpool.common.config", "io.dynamic.threadpool.server"
}) })
@MapperScan("io.dynamic.threadpool.server.mapper")
public class ServerApplication { public class ServerApplication {
public static void main(String[] args) { 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; package io.dynamic.threadpool.server.model;
import com.alibaba.fastjson.annotation.JSONField; 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 io.dynamic.threadpool.common.model.PoolParameter;
import lombok.Data; import lombok.Data;
import java.util.Date;
/** /**
* *
* *
@ -11,19 +16,18 @@ import lombok.Data;
* @date 2021/6/20 15:14 * @date 2021/6/20 15:14
*/ */
@Data @Data
@TableName("config_info")
public class ConfigAllInfo extends ConfigInfo implements PoolParameter { public class ConfigAllInfo extends ConfigInfo implements PoolParameter {
private static final long serialVersionUID = -2417394244017463665L; private static final long serialVersionUID = -2417394244017463665L;
@JSONField(serialize = false) @JSONField(serialize = false)
private String createUser; @TableField(exist = false, fill = FieldFill.UPDATE)
@JSONField(serialize = false)
private String desc; private String desc;
@JSONField(serialize = false) @JSONField(serialize = false)
private Long createTime; private Date gmtCreate;
@JSONField(serialize = false) @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 static final long serialVersionUID = -3504960832191834675L;
private String namespace;
} }

@ -1,6 +1,7 @@
package io.dynamic.threadpool.server.model; package io.dynamic.threadpool.server.model;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@ -16,9 +17,15 @@ public class ConfigInfoBase implements Serializable {
private static final long serialVersionUID = -1892597426099265730L; private static final long serialVersionUID = -1892597426099265730L;
/**
* ID
*/
private Integer id;
/** /**
* namespace * namespace
*/ */
@TableField(value = "tenant_id")
private String namespace; 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; package io.dynamic.threadpool.server.service.impl;
import io.dynamic.threadpool.common.toolkit.ContentUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.dynamic.threadpool.common.toolkit.Md5Util; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.dynamic.threadpool.server.mapper.RowMapperManager; 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.model.ConfigAllInfo;
import io.dynamic.threadpool.server.service.ConfigService; import io.dynamic.threadpool.server.service.ConfigService;
import io.dynamic.threadpool.server.toolkit.Md5ConfigUtil;
import lombok.extern.slf4j.Slf4j; 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 org.springframework.stereotype.Service;
import java.sql.PreparedStatement; import javax.annotation.Resource;
import java.sql.Statement;
/** /**
* *
@ -26,16 +22,16 @@ import java.sql.Statement;
@Service @Service
public class ConfigServiceImpl implements ConfigService { public class ConfigServiceImpl implements ConfigService {
@Autowired @Resource
private JdbcTemplate jdbcTemplate; private ConfigInfoMapper configInfoMapper;
@Override @Override
public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String namespace) { public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String namespace) {
ConfigAllInfo configAllInfo = jdbcTemplate.queryForObject( LambdaQueryWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
"select * from config_info where tp_id = ? and item_id = ? and tenant_id = ?", .eq(ConfigAllInfo::getTpId, tpId)
new Object[]{tpId, itemId, namespace}, .eq(ConfigAllInfo::getItemId, itemId)
RowMapperManager.CONFIG_ALL_INFO_ROW_MAPPER); .eq(ConfigAllInfo::getNamespace, namespace);
ConfigAllInfo configAllInfo = configInfoMapper.selectOne(wrapper);
return configAllInfo; return configAllInfo;
} }
@ -48,50 +44,26 @@ public class ConfigServiceImpl implements ConfigService {
} }
} }
private Long addConfigInfo(ConfigAllInfo config) { private Integer 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();
try { try {
jdbcTemplate.update(con -> { if (SqlHelper.retBool(configInfoMapper.insert(config))) {
PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); return config.getId();
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");
} }
return number.longValue();
} catch (Exception ex) { } catch (Exception ex) {
log.error("[db-error] message :: {}", ex.getMessage(), ex); log.error("[db-error] message :: {}", ex.getMessage(), ex);
throw ex; throw ex;
} }
return null;
} }
private void updateConfigInfo(ConfigAllInfo config) { 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 { try {
String poolContent = ContentUtil.getPoolContent(config); configInfoMapper.update(config, wrapper);
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());
} catch (Exception ex) { } catch (Exception ex) {
log.error("[db-error] message :: {}", ex.getMessage(), ex); log.error("[db-error] message :: {}", ex.getMessage(), ex);
throw 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);
}
}

@ -6,4 +6,10 @@ spring:
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/dynamic-thread-pool url: jdbc:mysql://localhost:3306/dynamic-thread-pool
username: root username: root
password: root password: root
mybatis-plus:
global-config:
db-config:
logic-delete-value: 1
logic-not-delete-value: 0
Loading…
Cancel
Save