完成表的动态编辑
This commit is contained in:
parent
6161ed0e8f
commit
bc6cbc0d55
@ -32,14 +32,6 @@ public class DynamicFormController extends AbstractController {
|
||||
@Autowired
|
||||
private IDynamicFormService dynamicFormService;
|
||||
|
||||
@ApiOperation(value = "保存动态表单", notes = "保存动态表单接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("savedynamicform")
|
||||
@CheckRequestBodyAnnotation
|
||||
public SuccessResult saveDynamicForm(@RequestBody DynamicFormVO dynamicFormVO) throws Exception {
|
||||
return dynamicFormService.saveDynamicForm(dynamicFormVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "列表显示的字段", notes = "列表显示的字段接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path"),
|
||||
|
@ -34,7 +34,7 @@ public class DynamicConfigTableController extends AbstractController {
|
||||
|
||||
@Autowired
|
||||
private IDynamicConfigTableService dynamicConfigTableService;
|
||||
|
||||
|
||||
@ApiOperation(value = "表新增", notes = "表新增接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("savetable")
|
||||
@ -43,6 +43,16 @@ public class DynamicConfigTableController extends AbstractController {
|
||||
return dynamicConfigTableService.saveTable(dynamicConfigTableVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "建动态表", notes = "建动态表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "id", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("savedynamictable/{id}")
|
||||
public SuccessResult saveDynamicTable(@PathVariable("id") String id) {
|
||||
return dynamicConfigTableService.saveDynamicTable(id);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "表删除", notes = "通过id列表批量删除表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "表ID列表,用下划线分隔", paramType = "path", example = "1_2_3")
|
||||
@ -64,6 +74,16 @@ public class DynamicConfigTableController extends AbstractController {
|
||||
return dynamicConfigTableService.updateTable(id, dynamicConfigTableVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改动态表", notes = "修改动态表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "id", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PutMapping("updatedynamictable/{id}")
|
||||
public SuccessResult updateDynamicTable(@PathVariable("id") String id) throws Exception {
|
||||
return dynamicConfigTableService.updateDynamicTable(id);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "表详情(ID查询)", notes = "表详情(ID查询)接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "dictionaryId", value = "表ID", paramType = "path")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.cm.common.plugin.dao.dynamic;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.common.plugin.pojo.dtos.database.table.TableColumnDTO;
|
||||
@ -45,6 +46,14 @@ public interface IDynamicTableDao {
|
||||
*/
|
||||
void updateTableColumnType(String toString) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 删列
|
||||
*
|
||||
* @param toString
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void deleteTableColumnType(String toString) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 通过表名获取表
|
||||
*
|
||||
@ -62,4 +71,5 @@ public interface IDynamicTableDao {
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<TableColumnDTO> listTableColumns(String tableName) throws SearchException;
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ public class DynamicConfigTableDTO {
|
||||
private String tableExplain;
|
||||
@ApiModelProperty(name = "tableTemplate", value = "模板")
|
||||
private String tableTemplate;
|
||||
@ApiModelProperty(name = "isCreate", value = "已创建")
|
||||
private Integer isCreate;
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id.trim();
|
||||
@ -67,6 +69,14 @@ public class DynamicConfigTableDTO {
|
||||
this.tableTemplate = tableTemplate;
|
||||
}
|
||||
|
||||
public Integer getIsCreate() {
|
||||
return isCreate;
|
||||
}
|
||||
|
||||
public void setIsCreate(Integer isCreate) {
|
||||
this.isCreate = isCreate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
@ -80,6 +90,8 @@ public class DynamicConfigTableDTO {
|
||||
.append("\"").append(tableExplain).append("\"");
|
||||
sb.append(",\"tableTemplate\":")
|
||||
.append("\"").append(tableTemplate).append("\"");
|
||||
sb.append(",\"isCreate\":")
|
||||
.append(isCreate);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.cm.common.plugin.service.dynamic;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormDTO;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormFormShowFieldDTO;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormListShowFieldDTO;
|
||||
@ -26,9 +29,17 @@ public interface IDynamicFormService {
|
||||
*
|
||||
* @param dynamicFormVO
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @throws SaveException
|
||||
*/
|
||||
SuccessResult saveDynamicForm(DynamicFormVO dynamicFormVO) throws Exception;
|
||||
void saveDynamicForm(DynamicFormVO dynamicFormVO) throws SaveException;
|
||||
|
||||
/**
|
||||
* 更新动态表单
|
||||
*
|
||||
* @param dynamicFormVO
|
||||
* @throws UpdateException
|
||||
*/
|
||||
void updateDynamicForm(DynamicFormVO dynamicFormVO) throws Exception;
|
||||
|
||||
/**
|
||||
* 动态表单详情
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.cm.common.plugin.service.dynamic;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
@ -50,8 +51,18 @@ public interface IDynamicTableService {
|
||||
*
|
||||
* @param tableName
|
||||
* @param tableColumnVO
|
||||
* @throws UpdateException
|
||||
*/
|
||||
void updateTableColumnType(String tableName, TableColumnVO tableColumnVO);
|
||||
void updateTableColumnType(String tableName, TableColumnVO tableColumnVO) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 删列
|
||||
*
|
||||
* @param tableName
|
||||
* @param deleteDynamicFormField
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void deleteTableColumnType(String tableName, String deleteDynamicFormField) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 通过表名获取表
|
||||
|
@ -34,6 +34,16 @@ public interface IDynamicConfigTableService {
|
||||
*/
|
||||
SuccessResult saveTable(DynamicConfigTableVO dynamicConfigTableVO) throws Exception;
|
||||
|
||||
/**
|
||||
* 建动态表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws SearchException
|
||||
* @throws UpdateException
|
||||
*/
|
||||
SuccessResult saveDynamicTable(String id) throws SearchException, UpdateException;
|
||||
|
||||
/**
|
||||
* 表删除
|
||||
*
|
||||
@ -53,6 +63,16 @@ public interface IDynamicConfigTableService {
|
||||
*/
|
||||
SuccessResult updateTable(String id, DynamicConfigTableVO dynamicConfigTableVO) throws Exception;
|
||||
|
||||
/**
|
||||
* 修改动态表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws SearchException
|
||||
* @throws UpdateException
|
||||
*/
|
||||
SuccessResult updateDynamicTable(String id) throws Exception;
|
||||
|
||||
/**
|
||||
* 表详情
|
||||
*
|
||||
|
@ -2,11 +2,20 @@ package com.cm.common.plugin.service.dynamic.config.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.common.plugin.dao.dynamic.config.IDynamicConfigTableDao;
|
||||
import com.cm.common.plugin.pojo.dtos.database.table.TableDTO;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.config.DynamicConfigTableDTO;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.config.form.DynamicConfigFormDTO;
|
||||
import com.cm.common.plugin.pojo.vos.dynamic.DynamicFormFieldVO;
|
||||
import com.cm.common.plugin.pojo.vos.dynamic.DynamicFormVO;
|
||||
import com.cm.common.plugin.pojo.vos.dynamic.config.DynamicConfigTableVO;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicFormService;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicTableService;
|
||||
import com.cm.common.plugin.service.dynamic.config.IDynamicConfigTableService;
|
||||
import com.cm.common.plugin.service.dynamic.config.form.IDynamicConfigFormService;
|
||||
import com.cm.common.pojo.ListPage;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import com.cm.common.result.SuccessResultList;
|
||||
@ -17,6 +26,7 @@ import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -36,16 +46,47 @@ public class DynamicConfigTableServiceImpl extends AbstractService implements ID
|
||||
|
||||
@Autowired
|
||||
private IDynamicConfigTableDao dynamicConfigTableDao;
|
||||
@Autowired
|
||||
private IDynamicConfigFormService dynamicConfigFormService;
|
||||
@Autowired
|
||||
private IDynamicTableService dynamicTableService;
|
||||
@Autowired
|
||||
private IDynamicFormService dynamicFormService;
|
||||
|
||||
@Override
|
||||
public SuccessResult saveTable(DynamicConfigTableVO dynamicConfigTableVO) throws Exception {
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(dynamicConfigTableVO);
|
||||
params.put("id", UUIDUtil.getUUID());
|
||||
params.put("isCreate", 0);
|
||||
setSaveInfo(params);
|
||||
dynamicConfigTableDao.saveTable(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult saveDynamicTable(String id) throws SearchException, SaveException {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
params.put("id", id);
|
||||
LOG.debug("获取动态表信息");
|
||||
DynamicConfigTableDTO dynamicConfigTableDTO = dynamicConfigTableDao.getTableById(params);
|
||||
TableDTO tableDTO = dynamicTableService.getTableByTableName(dynamicConfigTableDTO.getTableName());
|
||||
if (tableDTO != null) {
|
||||
throw new SaveException("该动态表已经存在");
|
||||
}
|
||||
params.clear();
|
||||
params.put("tableName", dynamicConfigTableDTO.getTableName());
|
||||
List<DynamicConfigFormDTO> dynamicConfigFormDTOList = dynamicConfigFormService.listForm(params);
|
||||
DynamicFormVO dynamicFormVO = getDynamicFormVO(dynamicConfigTableDTO.getTableName(), dynamicConfigFormDTOList);
|
||||
dynamicFormService.saveDynamicForm(dynamicFormVO);
|
||||
LOG.debug("更新状态");
|
||||
params.clear();
|
||||
params.put("id", id);
|
||||
params.put("isCreate", 1);
|
||||
setUpdateInfo(params);
|
||||
dynamicConfigTableDao.updateTable(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult removeTable(String ids) throws RemoveException {
|
||||
Map<String, Object> params = getHashMap(3);
|
||||
@ -64,6 +105,24 @@ public class DynamicConfigTableServiceImpl extends AbstractService implements ID
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult updateDynamicTable(String id) throws Exception {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
params.put("id", id);
|
||||
LOG.debug("获取动态表信息");
|
||||
DynamicConfigTableDTO dynamicConfigTableDTO = dynamicConfigTableDao.getTableById(params);
|
||||
TableDTO tableDTO = dynamicTableService.getTableByTableName(dynamicConfigTableDTO.getTableName());
|
||||
if (tableDTO == null) {
|
||||
throw new UpdateException("表不存在,修改失败");
|
||||
}
|
||||
params.clear();
|
||||
params.put("tableName", dynamicConfigTableDTO.getTableName());
|
||||
List<DynamicConfigFormDTO> dynamicConfigFormDTOList = dynamicConfigFormService.listForm(params);
|
||||
DynamicFormVO dynamicFormVO = getDynamicFormVO(dynamicConfigTableDTO.getTableName(), dynamicConfigFormDTOList);
|
||||
dynamicFormService.updateDynamicForm(dynamicFormVO);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicConfigTableDTO getTableById(String id) throws SearchException {
|
||||
Map<String, Object> params = super.getHashMap(1);
|
||||
@ -83,4 +142,27 @@ public class DynamicConfigTableServiceImpl extends AbstractService implements ID
|
||||
PageInfo<DynamicConfigTableDTO> pageInfo = new PageInfo<>(dynamicConfigTableDTOList);
|
||||
return new SuccessResultList<>(dynamicConfigTableDTOList, pageInfo.getPageNum(), page.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取建表对象
|
||||
*
|
||||
* @param tableName
|
||||
* @param dynamicConfigFormDTOList
|
||||
* @return
|
||||
*/
|
||||
private DynamicFormVO getDynamicFormVO(String tableName, List<DynamicConfigFormDTO> dynamicConfigFormDTOList) {
|
||||
List<DynamicFormFieldVO> dynamicFormFieldVOList = new ArrayList<>(0);
|
||||
DynamicFormVO dynamicFormVO = new DynamicFormVO();
|
||||
dynamicFormVO.setTableName(tableName);
|
||||
dynamicFormVO.setDynamicFormFields(dynamicFormFieldVOList);
|
||||
for (DynamicConfigFormDTO dynamicConfigFormDTO : dynamicConfigFormDTOList) {
|
||||
DynamicFormFieldVO dynamicFormFieldVO = new DynamicFormFieldVO();
|
||||
dynamicFormFieldVO.setFieldName(dynamicConfigFormDTO.getFieldName());
|
||||
dynamicFormFieldVO.setFieldDefault(dynamicConfigFormDTO.getFieldDefault());
|
||||
dynamicFormFieldVO.setFieldExplain(dynamicConfigFormDTO.getFieldExplain());
|
||||
dynamicFormFieldVO.setFieldType(dynamicConfigFormDTO.getFieldType());
|
||||
dynamicFormFieldVOList.add(dynamicFormFieldVO);
|
||||
}
|
||||
return dynamicFormVO;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.cm.common.plugin.service.dynamic.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.common.plugin.dao.dynamic.IDynamicFormDao;
|
||||
import com.cm.common.plugin.enums.database.table.ColumnDataTypeEnum;
|
||||
import com.cm.common.plugin.enums.dynamic.FieldTypeEnum;
|
||||
@ -47,17 +49,13 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
|
||||
private IDynamicTableService dynamicTableService;
|
||||
|
||||
@Override
|
||||
public SuccessResult saveDynamicForm(DynamicFormVO dynamicFormVO) throws Exception {
|
||||
LOG.debug("添加字段");
|
||||
TableDTO tableDTO = dynamicTableService.getTableByTableName(dynamicFormVO.getTableName());
|
||||
if (tableDTO == null) {
|
||||
LOG.debug("表不存在,新增表和字段信息");
|
||||
saveDynamicFormInfo(dynamicFormVO);
|
||||
} else {
|
||||
LOG.debug("表存在,更新表字段信息");
|
||||
updateDynamicFormInfo(StringUtils.removeStart(tableDTO.getTableName(), IDynamicTableService.DYNAMIC_TABLE_PREFIX), dynamicFormVO);
|
||||
}
|
||||
return new SuccessResult();
|
||||
public void saveDynamicForm(DynamicFormVO dynamicFormVO) throws SaveException {
|
||||
saveDynamicFormInfo(dynamicFormVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDynamicForm(DynamicFormVO dynamicFormVO) throws Exception {
|
||||
updateDynamicFormInfo(StringUtils.removeStart(dynamicFormVO.getTableName(), IDynamicTableService.DYNAMIC_TABLE_PREFIX), dynamicFormVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,8 +128,7 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
|
||||
* @param dynamicFormVO
|
||||
* @throws Exception
|
||||
*/
|
||||
private void saveDynamicFormInfo(DynamicFormVO dynamicFormVO) throws Exception {
|
||||
Map<String, Object> params;
|
||||
private void saveDynamicFormInfo(DynamicFormVO dynamicFormVO) throws SaveException {
|
||||
List<TableColumnVO> tableColumns = new ArrayList<>();
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormVO.getDynamicFormFields()) {
|
||||
TableColumnVO tableColumn = getTableColumn(dynamicFormFieldVO);
|
||||
@ -142,13 +139,6 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
|
||||
tableVO.setTableName(dynamicFormVO.getTableName());
|
||||
tableVO.setTableColumns(tableColumns);
|
||||
dynamicTableService.createTable(tableVO);
|
||||
LOG.debug("新增字段信息");
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormVO.getDynamicFormFields()) {
|
||||
params = HashMapUtil.beanToMap(dynamicFormFieldVO);
|
||||
params.put("id", UUIDUtil.getUUID());
|
||||
params.put("tableName", dynamicFormVO.getTableName());
|
||||
dynamicFormDao.saveDynamicForm(params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,39 +147,48 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
|
||||
private void updateDynamicFormInfo(String tableName, DynamicFormVO dynamicFormVO) throws Exception {
|
||||
List<DynamicFormFieldVO> dynamicFormFields = dynamicFormVO.getDynamicFormFields();
|
||||
List<TableColumnDTO> tableColumnDTOs = dynamicTableService.listTableColumns(tableName);
|
||||
List<DynamicFormFieldVO> saveDynamicFormField = new ArrayList<>(0);
|
||||
List<DynamicFormFieldVO> updateDynamicFormField = new ArrayList<>(0);
|
||||
List<DynamicFormFieldVO> saveDynamicFormFieldList = new ArrayList<>(0);
|
||||
List<DynamicFormFieldVO> updateDynamicFormFieldList = new ArrayList<>(0);
|
||||
List<String> deleteDynamicFormFieldList = new ArrayList<>(0);
|
||||
LOG.debug("获取新增和修改的字段");
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormFields) {
|
||||
int checkTableColumn = checkTableColumn(dynamicFormFieldVO, tableColumnDTOs);
|
||||
if (-1 == checkTableColumn) {
|
||||
updateDynamicFormField.add(dynamicFormFieldVO);
|
||||
} else if (1 == checkTableColumn) {
|
||||
saveDynamicFormField.add(dynamicFormFieldVO);
|
||||
if (checkTableColumn == -1) {
|
||||
updateDynamicFormFieldList.add(dynamicFormFieldVO);
|
||||
} else if (checkTableColumn == 1) {
|
||||
saveDynamicFormFieldList.add(dynamicFormFieldVO);
|
||||
}
|
||||
}
|
||||
LOG.debug("获取删除的字段");
|
||||
String tableId = String.format("%s_id", WStringUtil.lowerUpper2UnderLine(tableName));
|
||||
for (TableColumnDTO tableColumnDTO : tableColumnDTOs) {
|
||||
if (StringUtils.equals("id", tableColumnDTO.getColumnName()) ||
|
||||
StringUtils.equals(tableId, tableColumnDTO.getColumnName()) ||
|
||||
StringUtils.equals("gmt_create", tableColumnDTO.getColumnName()) ||
|
||||
StringUtils.equals("creator", tableColumnDTO.getColumnName()) ||
|
||||
StringUtils.equals("gmt_modified", tableColumnDTO.getColumnName()) ||
|
||||
StringUtils.equals("modifier", tableColumnDTO.getColumnName()) ||
|
||||
StringUtils.equals("is_delete", tableColumnDTO.getColumnName())) {
|
||||
continue;
|
||||
}
|
||||
int checkDeleteTableColumn = checkDeleteTableColumn(tableColumnDTO, dynamicFormFields);
|
||||
if (checkDeleteTableColumn == 1) {
|
||||
deleteDynamicFormFieldList.add(tableColumnDTO.getColumnName());
|
||||
}
|
||||
}
|
||||
LOG.debug("新增表字段");
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : saveDynamicFormField) {
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : saveDynamicFormFieldList) {
|
||||
TableColumnVO tableColumnVO = getTableColumn(dynamicFormFieldVO);
|
||||
dynamicTableService.saveTableColumn(tableName, tableColumnVO);
|
||||
}
|
||||
LOG.debug("更新表字段");
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : updateDynamicFormField) {
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : updateDynamicFormFieldList) {
|
||||
TableColumnVO tableColumnVO = getTableColumn(dynamicFormFieldVO);
|
||||
dynamicTableService.updateTableColumnType(tableName, tableColumnVO);
|
||||
}
|
||||
Map<String, Object> params = getHashMap(0);
|
||||
LOG.debug("新增表字段信息");
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : saveDynamicFormField) {
|
||||
params = HashMapUtil.beanToMap(dynamicFormFieldVO);
|
||||
params.put("id", UUIDUtil.getUUID());
|
||||
params.put("tableName", dynamicFormVO.getTableName());
|
||||
dynamicFormDao.saveDynamicForm(params);
|
||||
}
|
||||
LOG.debug("更新表字段信息");
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : updateDynamicFormField) {
|
||||
params = HashMapUtil.beanToMap(dynamicFormFieldVO);
|
||||
params.put("tableName", dynamicFormVO.getTableName());
|
||||
dynamicFormDao.updateDynamicForm(params);
|
||||
LOG.debug("删除表字段");
|
||||
for (String deleteDynamicFormField : deleteDynamicFormFieldList) {
|
||||
dynamicTableService.deleteTableColumnType(tableName, deleteDynamicFormField);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,6 +212,22 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查需要删除的table列
|
||||
*
|
||||
* @param tableColumnDTO
|
||||
* @param dynamicFormFields
|
||||
* @return 0:无需修改,1:需要删除
|
||||
*/
|
||||
private int checkDeleteTableColumn(TableColumnDTO tableColumnDTO, List<DynamicFormFieldVO> dynamicFormFields) {
|
||||
for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormFields) {
|
||||
if (StringUtils.equals(tableColumnDTO.getColumnName(), WStringUtil.lowerUpper2UnderLine(dynamicFormFieldVO.getFieldName()))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段类型是否相同
|
||||
*
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.cm.common.plugin.service.dynamic.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
@ -49,11 +50,17 @@ public class DynamicTableServiceImpl extends AbstractService implements IDynamic
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTableColumnType(String tableName, TableColumnVO tableColumnVO) {
|
||||
public void updateTableColumnType(String tableName, TableColumnVO tableColumnVO) throws UpdateException {
|
||||
StringBuilder updateTableColumnTypeSQL = new StringBuilder(String.format("ALTER TABLE `%s%s` MODIFY ", DYNAMIC_TABLE_PREFIX, WStringUtil.lowerUpper2UnderLine(tableName))).append(getSaveColumnSql(tableColumnVO));
|
||||
dynamicTableDao.updateTableColumnType(updateTableColumnTypeSQL.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTableColumnType(String tableName, String deleteDynamicFormField) throws RemoveException {
|
||||
StringBuilder deleteTableColumnTypeSQL = new StringBuilder(String.format("ALTER TABLE `%s%s` DROP %s", DYNAMIC_TABLE_PREFIX, WStringUtil.lowerUpper2UnderLine(tableName), deleteDynamicFormField));
|
||||
dynamicTableDao.deleteTableColumnType(deleteTableColumnTypeSQL.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDTO getTableByTableName(String tableName) throws SearchException {
|
||||
return dynamicTableDao.getTableByTableName(String.format("%s%s", DYNAMIC_TABLE_PREFIX, WStringUtil.lowerUpper2UnderLine(tableName)));
|
||||
|
@ -8,6 +8,7 @@
|
||||
<result property="tableType" column="table_type"/>
|
||||
<result property="tableExplain" column="table_explain"/>
|
||||
<result property="tableTemplate" column="table_template"/>
|
||||
<result property="isCreate" column="is_create"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 表新增 -->
|
||||
@ -18,6 +19,7 @@
|
||||
table_type,
|
||||
table_explain,
|
||||
table_template,
|
||||
is_create,
|
||||
gmt_create,
|
||||
creator,
|
||||
gmt_modified,
|
||||
@ -29,6 +31,7 @@
|
||||
#{tableType},
|
||||
#{tableExplain},
|
||||
#{tableTemplate},
|
||||
#{isCreate},
|
||||
#{gmtCreate},
|
||||
#{creator},
|
||||
#{gmtModified},
|
||||
@ -65,6 +68,9 @@
|
||||
</if>
|
||||
<if test="tableTemplate != null">
|
||||
table_template = #{tableTemplate},
|
||||
</if>
|
||||
<if test="isCreate != null">
|
||||
is_create = #{isCreate},
|
||||
</if>
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
|
@ -68,7 +68,10 @@
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
WHERE
|
||||
id = #{id}
|
||||
id IN
|
||||
<foreach collection="ids" index="index" open="(" separator="," close=")">
|
||||
#{ids[${index}]}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 表单修改 -->
|
||||
|
@ -77,6 +77,8 @@
|
||||
dynamic_form
|
||||
WHERE
|
||||
table_name = #{_parameter}
|
||||
ORDER BY
|
||||
field_sort
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -37,6 +37,11 @@
|
||||
${_parameter}
|
||||
</update>
|
||||
|
||||
<!-- 删列 -->
|
||||
<update id="deleteTableColumnType" parameterType="string">
|
||||
${_parameter}
|
||||
</update>
|
||||
|
||||
<!-- 通过表名获取表 -->
|
||||
<select id="getTableByTableName" parameterType="string" resultMap="tableDTO">
|
||||
SELECT
|
||||
|
@ -89,7 +89,7 @@
|
||||
[
|
||||
{type:'checkbox', fixed: 'left'},
|
||||
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
||||
{field:'tableName', width:120, title: '表名', align:'center', fixed: 'left'},
|
||||
// {field:'tableName', width:120, title: '表名', align:'center', fixed: 'left'},
|
||||
{field:'fieldName', width:120, title: '字段名称', align:'center', fixed: 'left'},
|
||||
{field:'fieldExplain', width: 160, title: '字段说明', align:'center'},
|
||||
{field:'fieldType', width:100, title: '字段类型', align:'center',
|
||||
@ -173,7 +173,7 @@
|
||||
},
|
||||
{field:'verifyRegular', width:140, title: '校验正则', align:'center'},
|
||||
{field:'fieldSort', width:80, title: '排序', align:'center'},
|
||||
{field:'listShow', width:100, title: '列表显示', align:'center',
|
||||
{field:'listShow', width:100, title: '列表显示', align:'center', fixed: 'right',
|
||||
templet: function(row) {
|
||||
if(row.listShow == 1) {
|
||||
return '<input type="checkbox" data-id="'+ row.id +'" lay-filter="listShow" lay-skin="switch" lay-text="开启|关闭" checked>';
|
||||
@ -181,7 +181,7 @@
|
||||
return '<input type="checkbox" data-id="'+ row.id +'" lay-filter="listShow" lay-skin="switch" lay-text="开启|关闭">';
|
||||
}
|
||||
},
|
||||
{field:'formShow', width:100, title: '表单显示', align:'center',
|
||||
{field:'formShow', width:100, title: '表单显示', align:'center', fixed: 'right',
|
||||
templet: function(row) {
|
||||
if(row.formShow == 1) {
|
||||
return '<input type="checkbox" data-id="'+ row.id +'" lay-filter="formShow" lay-skin="switch" lay-text="开启|关闭" checked>';
|
||||
|
@ -90,8 +90,16 @@
|
||||
{field:'tableTemplate', width: 120, title: '模板', align:'center'},
|
||||
{field:'tableExplain', width:250, title: '说明', align:'center'},
|
||||
{field:'dynamicForm', width:100, title: '表单', align:'center',
|
||||
templet: function() {
|
||||
return '<button type="button" class="layui-btn layui-btn-xs" lay-event="dynamicForm"><i class="fa fa-pencil-square-o"></i> 编辑</button>';
|
||||
templet: function(row) {
|
||||
return '<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="dynamicForm"><i class="fa fa-wpforms"></i> 编辑</button>';
|
||||
}
|
||||
},
|
||||
{field:'createTable', width:100, title: '数据表', align:'center',
|
||||
templet: function(row) {
|
||||
if(row.isCreate === 1) {
|
||||
return '<button type="button" class="layui-btn layui-btn-xs" lay-event="updateDynamicTable"><i class="fa fa-table"></i> 更新表</button>';
|
||||
}
|
||||
return '<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="saveDynamicTable"><i class="fa fa-table"></i> 创建表</button>';
|
||||
}
|
||||
},
|
||||
]
|
||||
@ -225,10 +233,34 @@
|
||||
if(layEvent === 'dynamicForm') {
|
||||
top.dialog.open({
|
||||
url: top.restAjax.path('route/dynamicconfigtable/dynamicconfigform/list/{tableName}', [data.tableName]),
|
||||
title: '表单列表',
|
||||
title: '表单列表【'+ data.tableName +'表】',
|
||||
width: '1000px',
|
||||
height: '500px'
|
||||
});
|
||||
} else if(layEvent === 'saveDynamicTable') {
|
||||
var layIndex;
|
||||
top.restAjax.post(top.restAjax.path('api/dynamicconfigtable/savedynamictable/{id}', [data.id]), {}, null, function(code, data) {
|
||||
top.dialog.msg('建表成功');
|
||||
reloadTable();
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function () {
|
||||
layIndex = top.dialog.msg('正在建表,请稍后...', {icon: 16, time: 0, shade: 0.3});
|
||||
}, function () {
|
||||
top.dialog.close(layIndex);
|
||||
});
|
||||
} else if(layEvent === 'updateDynamicTable') {
|
||||
var layIndex;
|
||||
top.restAjax.put(top.restAjax.path('api/dynamicconfigtable/updatedynamictable/{id}', [data.id]), {}, null, function(code, data) {
|
||||
top.dialog.msg('更新成功');
|
||||
reloadTable();
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function () {
|
||||
layIndex = top.dialog.msg('正在更新,请稍后...', {icon: 16, time: 0, shade: 0.3});
|
||||
}, function () {
|
||||
top.dialog.close(layIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user