新增部分功能

This commit is contained in:
wenc000 2019-11-18 17:14:52 +08:00
parent 6bf63c46d3
commit c1c1dd308c
8 changed files with 77 additions and 1 deletions

View File

@ -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}")

View File

@ -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);
/**
* 修改列
*

View File

@ -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 {

View File

@ -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;
/**
* 修改列
*

View File

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

View File

@ -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<String, Object> getHashMap(int initSize) {
return new HashMap<>(initSize);
}
}

View File

@ -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";
}

View File

@ -1,5 +1,8 @@
package com.cm.common.pojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**