Răsfoiți Sursa

增加复制表功能

Baolei 3 ani în urmă
părinte
comite
3a29dd8087

+ 45 - 0
src/main/java/com/goer/project/model/modelEntity/controller/ModelEntityController.java

@@ -10,6 +10,8 @@ import com.goer.common.command.impl.DBReverseGetAllTablesListImpl;
 import com.goer.common.command.impl.PingLoadDriverClassImpl;
 import com.goer.project.model.modelDbs.domain.ModelDbs;
 import com.goer.project.model.modelDbs.service.IModelDbsService;
+import com.goer.project.model.modelField.domain.ModelField;
+import com.goer.project.model.modelField.service.IModelFieldService;
 import com.goer.project.model.modelProject.domain.ModelProject;
 import com.goer.project.model.modelProject.service.IModelProjectService;
 import com.goer.project.system.user.domain.User;
@@ -47,6 +49,9 @@ public class ModelEntityController extends BaseController
     private IModelEntityService modelEntityService;
 
     @Autowired
+    private IModelFieldService modelFieldService;
+
+    @Autowired
     private IModelDbsService modelDbsService;
 
     @RequiresPermissions("model:modelEntity:view")
@@ -129,6 +134,46 @@ public class ModelEntityController extends BaseController
         return toAjax(modelEntityService.insertModelEntity(modelEntity));
     }
 
+
+    /**
+     * 新增数据
+     */
+    @GetMapping("/copy/{id}")
+    public String copy(@PathVariable("id") Long id, ModelMap mmap)
+    {
+        ModelEntity modelEntity = modelEntityService.selectModelEntityById(id);
+        ModelProject modelProject = modelProjectService.selectModelProjectById(modelEntity.getProjectId());
+        modelProject.setOrgEntityid(id);
+        mmap.put("modelProject", modelProject);
+        return prefix + "/copy";
+    }
+
+    /**
+     * 新增保存数据
+     */
+    @RequiresPermissions("model:modelEntity:add")
+    @Log(title = "数据", businessType = BusinessType.INSERT)
+    @PostMapping("/copy")
+    @ResponseBody
+    public AjaxResult copySave(ModelEntity modelEntity)
+    {
+
+        ModelField condMf = new ModelField();
+        condMf.setEntityId(modelEntity.getOrgEntityId());
+        List<ModelField> mfs = modelFieldService.selectModelFieldList(condMf);
+
+        modelEntity.setVersionId(0L);
+        modelEntity.setParentVersionId(0L);
+        modelEntity.setCreateBy(getLoginName());
+        for (ModelField mf : mfs) {
+            mf.setCreateBy(getLoginName());
+        }
+        modelEntity.setFields(mfs);
+        modelEntityService.copyModelEntity(modelEntity);
+
+        return AjaxResult.success();
+    }
+
     /**
      * 修改数据
      */

+ 12 - 0
src/main/java/com/goer/project/model/modelEntity/domain/ModelEntity.java

@@ -143,4 +143,16 @@ public class ModelEntity extends BaseEntity
             .append("updateTime", getUpdateTime())
             .toString();
     }
+
+    public Long getOrgEntityId() {
+        return orgEntityId;
+    }
+
+    public void setOrgEntityId(Long orgEntityId) {
+        this.orgEntityId = orgEntityId;
+    }
+
+    private Long orgEntityId;
+
+
 }

+ 1 - 0
src/main/java/com/goer/project/model/modelEntity/service/IModelEntityService.java

@@ -36,6 +36,7 @@ public interface IModelEntityService
      * @return 结果
      */
     public int insertModelEntity(ModelEntity modelEntity);
+    public int copyModelEntity(ModelEntity modelEntity);
 
     /**
      * 修改数据

+ 22 - 0
src/main/java/com/goer/project/model/modelEntity/service/impl/ModelEntityServiceImpl.java

@@ -88,6 +88,28 @@ public class ModelEntityServiceImpl implements IModelEntityService
     }
 
     /**
+     * 复制数据
+     *
+     * @param modelEntity 数据
+     * @return 结果
+     */
+    @Override
+    public int copyModelEntity(ModelEntity modelEntity)
+    {
+        int rtn = 0;
+        int sort = modelEntityMapper.selectMaxEntitySort(modelEntity);
+        modelEntity.setEntitySort(sort);
+        modelEntity.setCreateTime(DateUtils.getNowDate());
+        rtn = modelEntityMapper.insertModelEntity(modelEntity);
+        for (ModelField mf : modelEntity.getFields()) {
+            mf.setEntityId(modelEntity.getId());
+            mf.setCreateTime(DateUtils.getNowDate());
+            rtn = rtn + modelFieldMapper.insertModelField(mf);
+        }
+        return rtn;
+    }
+
+    /**
      * 修改数据
      * 
      * @param modelEntity 数据

+ 9 - 0
src/main/java/com/goer/project/model/modelProject/domain/ModelProject.java

@@ -18,6 +18,15 @@ public class ModelProject extends BaseEntity
     /** 主键 */
     private Long id;
 
+    public Long getOrgEntityid() {
+        return orgEntityid;
+    }
+
+    public void setOrgEntityid(Long orgEntityid) {
+        this.orgEntityid = orgEntityid;
+    }
+
+    private Long orgEntityid;
     /** 模型名称 */
     @Excel(name = "模型名称")
     private String modelName;

+ 77 - 0
src/main/resources/templates/model/modelEntity/copy.html

@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('复制数据')" />
+</head>
+<body class="white-bg">
+<div class="wrapper wrapper-content animated fadeInRight ibox-content">
+    <form class="form-horizontal m" id="form-modelEntity-copy">
+        <input type="hidden" id="projectId" name="projectId" th:value="${modelProject.id}">
+        <input type="hidden" id="orgEntityId" name="orgEntityId" th:value="${modelProject.orgEntityid}">
+
+        <div class="form-group">
+            <label class="col-sm-3 control-label is-required">表名称:</label>
+            <div class="col-sm-8">
+                <input id="entityName" name="entityName" placeholder="表名称" class="form-control" type="text" required>
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="col-sm-3 control-label is-required">表逻辑名:</label>
+            <div class="col-sm-8">
+                <input id="entityCode" name="entityCode" placeholder="m_tablename" class="form-control" type="text" required>
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="col-sm-3 control-label">描述:</label>
+            <div class="col-sm-8">
+                <textarea id="remark" name="remark" class="form-control"></textarea>
+            </div>
+        </div>
+    </form>
+</div>
+<th:block th:include="include :: footer" />
+<script th:inline="javascript">
+    var prefix = ctx + "model/modelEntity"
+    $("#form-modelEntity-add").validate({
+        onkeyup: false,
+        rules:{
+            entityCode:{
+                maxlength: 50,
+                remote: {
+                    url: prefix + "/checkEntityCodeUnique",
+                    type: "post",
+                    dataType: "json",
+                    data: {
+                        "projectId":$("#projectId").val(),
+                        "entityCode": function() {
+                            return $.common.trim($("#entityCode").val());
+                        }
+                    },
+                    dataFilter: function(data, type) {
+                        return $.validate.unique(data);
+                    }
+                }
+            },
+            entityName:{
+                maxlength: 25
+            },
+            remark:{
+                maxlength: 100
+            },
+        },
+        messages: {
+            "entityCode": {
+                remote: "数据表已经存在"
+            },
+        },
+        focusCleanup: true
+    });
+
+    function submitHandler() {
+        if ($.validate.form()) {
+            $.operate.save(prefix + "/copy", $('#form-modelEntity-copy').serialize());
+        }
+    }
+</script>
+</body>
+</html>

+ 7 - 0
src/main/resources/templates/model/modelEntity/modelEntity.html

@@ -72,6 +72,7 @@
     <th:block th:include="include :: footer" />
      <th:block th:include="include :: bootstrap-table-reorder-rows-js" />
     <script th:inline="javascript">
+        var addFlag = [[${@permission.hasPermi('model:modelEntity:add')}]];
         var editFlag = [[${@permission.hasPermi('model:modelEntity:edit')}]];
         var removeFlag = [[${@permission.hasPermi('model:modelEntity:remove')}]];
         var modelFieldFlag = [[${@permission.hasPermi('model:modelField:view')}]];
@@ -140,6 +141,7 @@
                     formatter: function(value, row, index) {
                         var actions = [];
                         actions.push('<a class="btn btn-warning btn-xs ' + modelFieldFlag + '" href="javascript:void(0)" onclick="modelField(\'' + row.projectId + '\',\'' + row.id + '\')"><i class="fa fa-list"></i> 字段列表 </a> ');
+                        actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="copy(\'' + row.id + '\',\'' + row.entityName + '\')"><i class="fa fa-edit"></i>复制</a> ');
                         actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                         return actions.join('');
@@ -155,6 +157,11 @@
             $.operate.add(projectId);
         }
 
+        /*复制表结构*/
+        function copy(id,entityName) {
+            $.modal.open("复制" + entityName, prefix + "/copy/"+ id);
+        }
+
         /** 字段列表 */
         function modelField(projectId, entityId) {
             var data = $("#bootstrap-table").bootstrapTable('getRowByUniqueId', entityId);