From bc6cbc0d55e3cbd9d371cca9393aea6070b9f665 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Mon, 9 Dec 2019 23:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=A1=A8=E7=9A=84=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/dynamic/DynamicFormController.java | 8 -- .../config/DynamicConfigTableController.java | 22 ++++- .../plugin/dao/dynamic/IDynamicTableDao.java | 10 ++ .../dynamic/config/DynamicConfigTableDTO.java | 12 +++ .../service/dynamic/IDynamicFormService.java | 15 ++- .../service/dynamic/IDynamicTableService.java | 13 ++- .../config/IDynamicConfigTableService.java | 20 ++++ .../impl/DynamicConfigTableServiceImpl.java | 82 ++++++++++++++++ .../dynamic/impl/DynamicFormServiceImpl.java | 97 +++++++++++-------- .../dynamic/impl/DynamicTableServiceImpl.java | 9 +- .../config/dynamicconfigtable-mapper.xml | 6 ++ .../config/form/dynamicconfigform-mapper.xml | 5 +- .../mapper/dynamic/dynamicform-mapper.xml | 2 + .../mapper/dynamic/dynamictable-mapper.xml | 5 + .../templates/dynamic/config/form/list.html | 6 +- .../templates/dynamic/config/list.html | 38 +++++++- 16 files changed, 289 insertions(+), 61 deletions(-) diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/DynamicFormController.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/DynamicFormController.java index 266b5a6..78f3182 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/DynamicFormController.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/DynamicFormController.java @@ -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"), diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/config/DynamicConfigTableController.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/config/DynamicConfigTableController.java index 7e4a157..a44f459 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/config/DynamicConfigTableController.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/apis/dynamic/config/DynamicConfigTableController.java @@ -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") diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicTableDao.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicTableDao.java index 05cf66e..c24b8e9 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicTableDao.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicTableDao.java @@ -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 listTableColumns(String tableName) throws SearchException; + } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/DynamicConfigTableDTO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/DynamicConfigTableDTO.java index 27f8996..497258e 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/DynamicConfigTableDTO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/DynamicConfigTableDTO.java @@ -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(); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java index 9e38ed8..d1c1c03 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java @@ -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; /** * 动态表单详情 diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicTableService.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicTableService.java index b226c93..839e80f 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicTableService.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicTableService.java @@ -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; /** * 通过表名获取表 diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/IDynamicConfigTableService.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/IDynamicConfigTableService.java index 4815385..8cda226 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/IDynamicConfigTableService.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/IDynamicConfigTableService.java @@ -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; + /** * 表详情 * diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/impl/DynamicConfigTableServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/impl/DynamicConfigTableServiceImpl.java index ccf97ac..144ccc7 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/impl/DynamicConfigTableServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/config/impl/DynamicConfigTableServiceImpl.java @@ -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 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 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 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 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 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 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 params = super.getHashMap(1); @@ -83,4 +142,27 @@ public class DynamicConfigTableServiceImpl extends AbstractService implements ID PageInfo pageInfo = new PageInfo<>(dynamicConfigTableDTOList); return new SuccessResultList<>(dynamicConfigTableDTOList, pageInfo.getPageNum(), page.getTotal()); } + + /** + * 获取建表对象 + * + * @param tableName + * @param dynamicConfigFormDTOList + * @return + */ + private DynamicFormVO getDynamicFormVO(String tableName, List dynamicConfigFormDTOList) { + List 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; + } } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java index 7910eeb..2feb226 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java @@ -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 params; + private void saveDynamicFormInfo(DynamicFormVO dynamicFormVO) throws SaveException { List 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 dynamicFormFields = dynamicFormVO.getDynamicFormFields(); List tableColumnDTOs = dynamicTableService.listTableColumns(tableName); - List saveDynamicFormField = new ArrayList<>(0); - List updateDynamicFormField = new ArrayList<>(0); + List saveDynamicFormFieldList = new ArrayList<>(0); + List updateDynamicFormFieldList = new ArrayList<>(0); + List 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 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 dynamicFormFields) { + for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormFields) { + if (StringUtils.equals(tableColumnDTO.getColumnName(), WStringUtil.lowerUpper2UnderLine(dynamicFormFieldVO.getFieldName()))) { + return 0; + } + } + return 1; + } + /** * 字段类型是否相同 * diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicTableServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicTableServiceImpl.java index 2ab1d0e..86c4fae 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicTableServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicTableServiceImpl.java @@ -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))); diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/dynamicconfigtable-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/dynamicconfigtable-mapper.xml index 85060bc..b6a8d30 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/dynamicconfigtable-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/dynamicconfigtable-mapper.xml @@ -8,6 +8,7 @@ + @@ -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 @@ table_template = #{tableTemplate}, + + + is_create = #{isCreate}, modifier = #{modifier}, gmt_modified = #{gmtModified} diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml index bc1001b..7f31ad1 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml @@ -68,7 +68,10 @@ modifier = #{modifier}, gmt_modified = #{gmtModified} WHERE - id = #{id} + id IN + + #{ids[${index}]} + diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml index b35df13..acfff99 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml @@ -77,6 +77,8 @@ dynamic_form WHERE table_name = #{_parameter} + ORDER BY + field_sort \ No newline at end of file diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamictable-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamictable-mapper.xml index 8661ccc..cad063e 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamictable-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamictable-mapper.xml @@ -37,6 +37,11 @@ ${_parameter} + + + ${_parameter} + + '; @@ -181,7 +181,7 @@ return ''; } }, - {field:'formShow', width:100, title: '表单显示', align:'center', + {field:'formShow', width:100, title: '表单显示', align:'center', fixed: 'right', templet: function(row) { if(row.formShow == 1) { return ''; diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/config/list.html b/cloud-common-plugin/src/main/resources/templates/dynamic/config/list.html index 6c88040..589fe14 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/config/list.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/config/list.html @@ -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 ''; + templet: function(row) { + return ''; + } + }, + {field:'createTable', width:100, title: '数据表', align:'center', + templet: function(row) { + if(row.isCreate === 1) { + return ''; + } + return ''; } }, ] @@ -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); + }); } }); });