From c1c1dd308c30c0a1f12090471f0531c765e88025 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Mon, 18 Nov 2019 17:14:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/database/table/TableController.java | 10 ++++++++++ .../plugin/dao/database/table/ITableDao.java | 10 ++++++++++ .../dao/database/table/impl/TableDaoImpl.java | 14 ++++++++++++++ .../service/database/table/ITableService.java | 10 ++++++++++ .../database/table/impl/TableServiceImpl.java | 8 ++++++++ .../java/com/cm/common/base/AbstractService.java | 10 ++++++++++ .../com/cm/common/constants/ISystemConstant.java | 13 ++++++++++++- .../src/main/java/com/cm/common/pojo/ListPage.java | 3 +++ 8 files changed, 77 insertions(+), 1 deletion(-) diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/database/table/TableController.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/database/table/TableController.java index bf74de8..7852434 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/database/table/TableController.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/database/table/TableController.java @@ -62,6 +62,16 @@ public class TableController extends AbstractController { return tableService.saveTableColumn(tableName, tableColumnVO); } + @ApiOperation(value = "删列", notes = "删列接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "tableName", value = "表名", paramType = "path"), + @ApiImplicitParam(name = "columnName", value = "列名", paramType = "path"), + }) + @DeleteMapping("removetablecolumn/{tableName}/{columnName}") + public SuccessResult removeTableColumn(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { + return tableService.removeTableColumn(tableName, columnName); + } + @ApiOperation(value = "修改列", notes = "修改列") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PutMapping("updatetablecolumn/{tableName}") diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/ITableDao.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/ITableDao.java index e0f8e21..1a6548f 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/ITableDao.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/ITableDao.java @@ -50,6 +50,16 @@ public interface ITableDao { */ void saveTableColumn(Connection connection, String databaseName, String tableName, TableColumnVO tableColumnVO); + /** + * 删列 + * + * @param connection + * @param databaseName + * @param tableName + * @param columnName + */ + void removeTableColumn(Connection connection, String databaseName, String tableName, String columnName); + /** * 修改列 * diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/impl/TableDaoImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/impl/TableDaoImpl.java index fd105fa..9c42595 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/impl/TableDaoImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/database/table/impl/TableDaoImpl.java @@ -90,6 +90,20 @@ public class TableDaoImpl implements ITableDao { } } + @Override + public void removeTableColumn(Connection connection, String databaseName, String tableName, String columnName) { + try { + connection.setAutoCommit(true); + StringBuilder sqlSB = new StringBuilder(String.format("ALTER TABLE `%s`.`%s` DROP COLUMN %s", databaseName, tableName, WStringUtil.lowerUpper2UnderLine(columnName))); + LOG.debug("sql: {}", sqlSB.toString()); + PreparedStatement preparedStatement = connection.prepareStatement(sqlSB.toString()); + preparedStatement.execute(); + } catch (SQLException e) { + LOG.error(e.getMessage(), e); + throw new SaveException("删除列失败"); + } + } + @Override public void updateTableColumn(Connection connection, String databaseName, String tableName, TableOldColumnVO tableOldColumnVO) { try { diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/ITableService.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/ITableService.java index 5656587..6907c5e 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/ITableService.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/ITableService.java @@ -55,6 +55,16 @@ public interface ITableService { */ SuccessResult saveTableColumn(String tableName, TableColumnVO tableColumnVO) throws SaveException; + /** + * 删列 + * + * @param tableName + * @param columnName + * @return + * @throws RemoveException + */ + SuccessResult removeTableColumn(String tableName, String columnName) throws RemoveException; + /** * 修改列 * diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/impl/TableServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/impl/TableServiceImpl.java index ac02aa5..3a6983b 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/impl/TableServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/database/table/impl/TableServiceImpl.java @@ -66,6 +66,14 @@ public class TableServiceImpl extends AbstractService implements ITableService { return new SuccessResult(); } + @Override + public SuccessResult removeTableColumn(String tableName, String columnName) throws RemoveException { + Connection connection = getConnectionFromSession(); + String databaseName = getHttpSession().getAttribute(IDatabaseService.DATABASE_NAME).toString(); + tableDao.removeTableColumn(connection, databaseName, tableName, columnName); + return new SuccessResult(); + } + @Override public SuccessResult updateTableColumn(String tableName, TableOldColumnVO tableOldColumnVO) throws UpdateException { Connection connection = getConnectionFromSession(); diff --git a/cloud-common/src/main/java/com/cm/common/base/AbstractService.java b/cloud-common/src/main/java/com/cm/common/base/AbstractService.java index be82dcd..2123e3e 100644 --- a/cloud-common/src/main/java/com/cm/common/base/AbstractService.java +++ b/cloud-common/src/main/java/com/cm/common/base/AbstractService.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import javax.servlet.http.HttpSession; +import java.util.HashMap; import java.util.Map; /** @@ -142,4 +143,13 @@ public abstract class AbstractService { protected HttpSession getHttpSession() { return httpSession; } + + /** + * 获取HashMap + * + * @return + */ + protected Map getHashMap(int initSize) { + return new HashMap<>(initSize); + } } diff --git a/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java b/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java index f6b4bf3..f18fa3d 100644 --- a/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java +++ b/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java @@ -68,10 +68,21 @@ public interface ISystemConstant { * app的token标识前缀 */ String APP_TOKEN_VERIFY = "CM_Token_"; - /** * 验证码 */ String VERIFICATION_CODE = "verificationCode"; + /** + * 树根节点ID值 + */ + String TREE_BASE_ROOT_ID_VALUE = "0"; + /** + * 参数parentId + */ + String PARAMS_PARENT_ID = "parentId"; + /** + * 参数id + */ + String PARAMS_ID = "id"; } diff --git a/cloud-common/src/main/java/com/cm/common/pojo/ListPage.java b/cloud-common/src/main/java/com/cm/common/pojo/ListPage.java index 947a39b..1d60a47 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/ListPage.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/ListPage.java @@ -1,5 +1,8 @@ package com.cm.common.pojo; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.util.Map; /**