Compare commits

..

2 Commits

  1. 39
      ant-design-vue-jeecg/src/views/fieldx/FieldxList.vue
  2. 47
      ant-design-vue-jeecg/src/views/tablex/TablexList.vue
  3. 205
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java
  4. 17
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/controller/TablexController.java
  5. 4
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/mapper/TablexMapper.java
  6. 2
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/service/ITablexService.java
  7. 8
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/service/impl/TablexServiceImpl.java

@ -4,6 +4,27 @@
<div class="table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="中文名称">
<a-input placeholder="中文名称" v-model="queryParam.fieldName"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="英文名称">
<a-input placeholder="英文名称" v-model="queryParam.fieldEnName"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="实体状态">
<j-dict-select-tag type="list" v-model="queryParam.status" dictCode="a_status" placeholder="请选择实体状态" />
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
<a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
</span>
</a-col>
</a-row>
</a-form>
</div>
@ -71,19 +92,11 @@
<a @click="handleEdit(record)">编辑</a>
<a-divider type="vertical" />
<a-dropdown>
<a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
<a-menu slot="overlay">
<a-menu-item>
<a @click="handleDetail(record)">详情</a>
</a-menu-item>
<a-menu-item>
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
<a>删除</a>
</a-popconfirm>
</a-menu-item>
</a-menu>
</a-dropdown>
<a @click="handleDetail(record)">详情</a>
<a-divider type="vertical" />
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
<a>删除</a>
</a-popconfirm>
</span>
</a-table>

@ -4,6 +4,27 @@
<div class="table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="中文名称">
<a-input placeholder="中文名称" v-model="queryParam.tableName"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="英文名称">
<a-input placeholder="英文名称" v-model="queryParam.tableEnName"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="实体状态">
<j-dict-select-tag type="list" v-model="queryParam.status" dictCode="a_status" placeholder="请选择实体状态" />
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
<a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
</span>
</a-col>
</a-row>
</a-form>
</div>
@ -71,19 +92,11 @@
<a @click="handleEdit(record)">编辑</a>
<a-divider type="vertical" />
<a-dropdown>
<a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
<a-menu slot="overlay">
<a-menu-item>
<a @click="handleDetail(record)">详情</a>
</a-menu-item>
<a-menu-item>
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
<a>删除</a>
</a-popconfirm>
</a-menu-item>
</a-menu>
</a-dropdown>
<a @click="handleDetail(record)">详情</a>
<a-divider type="vertical" />
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
<a>删除</a>
</a-popconfirm>
</span>
</a-table>
@ -100,14 +113,17 @@
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TablexModal from './modules/TablexModal'
import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
import JEllipsis from '@/components/jeecg/JEllipsis'
export default {
name: 'TablexList',
mixins:[JeecgListMixin, mixinDevice],
components: {
TablexModal
TablexModal,
JEllipsis,
},
data () {
let ellipsis = (v, l = 20) => (<j-ellipsis value={v} length={l}/>)
return {
description: '实体表管理页面',
//
@ -140,7 +156,8 @@
{
title:'表结构SQL',
align:"center",
dataIndex: 'tableStructure'
dataIndex: 'tableStructure',
customRender: (t)=>ellipsis(t)
},
{
title:'结构图',

@ -20,6 +20,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.tablex.entity.Tablex;
import org.jeecg.modules.tablex.service.ITablexService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
@ -49,6 +51,8 @@ import org.jeecg.common.aspect.annotation.AutoLog;
public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
@Autowired
private IFieldxService fieldxService;
@Autowired
private ITablexService tablexService;
/**
* 分页列表查询
@ -82,9 +86,23 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
@ApiOperation(value="字段管理-添加", notes="字段管理-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody Fieldx fieldx) {
fieldx.setVerison(1);
if (fieldx.getTableId() != null){
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()));
for (Fieldx fieldx1 : fieldxList){
if (fieldx1.getFieldName().equals(fieldx.getFieldName())){
return Result.error("添加失败,所属实体已有该中文名称");
}
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())){
return Result.error("添加失败,所属实体已有该英文名称");
}
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1){
return Result.error("该实体已经有主键,添加失败");
}
}
}
fieldxService.save(fieldx);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("添加成功!");
}
@ -99,6 +117,7 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody Fieldx fieldx) {
fieldxService.updateById(fieldx);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("编辑成功!");
}
@ -113,6 +132,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
fieldxService.removeById(id);
Fieldx fieldx = fieldxService.getById(id);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("删除成功!");
}
@ -127,6 +148,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.fieldxService.removeByIds(Arrays.asList(ids.split(",")));
Fieldx fieldx = fieldxService.getById(ids.split(",")[0]);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("批量删除成功!");
}
@ -170,4 +193,184 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
return super.importExcel(request, response, Fieldx.class);
}
// 生成sql
public String createSql(String tableId){
Tablex tablex = tablexService.getById(tableId);
String tableEnName = tablex.getTableEnName();
String sql = "DROP TABLE IF EXISTS "+"'"+tableEnName+"';"+" CREATE TABLE '"+tableEnName+"' (";
String primary = "";
String unique = "";
String foreign = "";
String pre_foreign ="";
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", tableId));
for (Fieldx fieldx : fieldxList){
String fieldEnName = fieldx.getFieldEnName();
String fieldName = fieldx.getFieldName();
String dateType = dateType(fieldx.getType(), fieldx.getLength(), fieldx.getAccuracy());
String isnull = "";
// 判断是否为空
if (fieldx.getIsNull() == 1){
isnull = " NULL";
}else {
isnull = " NOT NULL";
}
// 判断是否是主键
if (fieldx.getIsPk() == 1){
if (primary != ""){
primary = primary+" ,'"+fieldEnName+"'";
}else {
primary ="'"+fieldEnName+"'";
}
}
// 判断是否是唯一 并且不是主键的
if (fieldx.getIsUniqueness() == 0 && fieldx.getIsPk() != 1){
if (unique != ""){
unique = unique+" UNIQUE INDEX('"+fieldEnName+"'),";
}else {
unique = " UNIQUE INDEX('"+fieldEnName+"'),";
}
}
// 判断是否是外键
Fieldx fieldx_foreign = fieldxService.getById(fieldx.getAssociateField());
Tablex tablex_foreign = tablexService.getById(fieldx.getAssociateTable());
if (fieldx.getIsFk() == 1 && fieldx.getAssociateTable() != null && fieldx.getAssociateField() != null){
if (foreign != ""){
foreign = foreign+" FOREIGN KEY ('"+fieldEnName+"') REFERENCES '"+tablex_foreign.getTableEnName()+"' ('"+fieldx_foreign.getFieldEnName()+"'),";
}else {
foreign = " FOREIGN KEY ('"+fieldEnName+"') REFERENCES '"+tablex_foreign.getTableEnName()+"' ('"+fieldx_foreign.getFieldEnName()+"'),";
}
// 判断外键关联的字段是否是主键
if (fieldx_foreign.getIsPk() ==0){
pre_foreign = pre_foreign+"ALTER TABLE '"+tablex_foreign.getTableEnName()+"' ADD INDEX('"+fieldx_foreign.getFieldEnName()+"');";
}
}
// 拼装sql
sql = sql+"'"+fieldEnName+"' "+dateType+isnull+" COMMENT '"+fieldName+"',";
}
if (pre_foreign != ""){
sql = pre_foreign+sql;
}
if (primary != ""){
sql = sql+" PRIMARY KEY ("+primary+"), ";
}
if (unique != ""){
sql = sql+unique;
}
if (foreign != ""){
sql = sql+foreign;
}
// 移除逗号
String a = sql.substring(0, sql.length() - 1);
sql = a+");";
return sql;
}
public String dateType(Integer type,Integer length,Integer accuracy) {
/**
* 数据类型对应编号
* 1 tinyint2 smallint3 mediumint4 int5 bigint6 float7 double8 decimal9 year10 time
* 11 date12 datetime13 timestamp14 char15 varchar16 binary17 varbinary18 blob19 text20 enum
* 21 set 22 bit23 tinyblob24 blob25 mediumblob26 longblob
*/
if (type == 1) {
if (length != null) {
return "tinyint" + "(" + length + ")";
} else return "tinyint";
} else if (type == 2) {
if (length != null) {
return "smallint" + "(" + length + ")";
} else return "smallint" + "(" + length + ")";
} else if (type == 3) {
if (length != null) {
return "mediumint" + "(" + length + ")";
} else return "mediumint" + "(" + length + ")";
} else if (type == 4) {
if (length != null) {
return "int" + "(" + length + ")";
} else return "int" + "(" + length + ")";
} else if (type == 5) {
if (length != null) {
return "bigint" + "(" + length + ")";
} else return "bigint" + "(" + length + ")";
} else if (type == 6) {
if (length != null) {
if (accuracy != null) {
return "float" + "(" + length + " ," + accuracy + ")";
} else return "float" + "(" + length + ")";
} else {
return "float";
}
} else if (type == 7) {
if (length != null) {
if (accuracy != null) {
return "double" + "(" + length + " ," + accuracy + ")";
} else return "double" + "(" + length + ")";
} else {
return "double";
}
} else if (type == 8) {
if (length != null) {
if (accuracy != null) {
return "decimal" + "(" + length + " ," + accuracy + ")";
} else return "decimal" + "(" + length + ")";
} else {
return "decimal";
}
} else if (type == 9) {
return "year";
} else if (type == 10) {
if (length != null) {
return "time" + "(" + length + ")";
} else return "time";
} else if (type == 11) {
return "date";
} else if (type == 12) {
if (length != null) {
return "datetime" + "(" + length + ")";
} else return "datetime";
} else if (type == 13) {
if (length != null) {
return "timestamp" + "(" + length + ")";
} else return "timestamp";
} else if (type == 14) {
if (length != null) {
return "char" + "(" + length + ")";
} else return "char";
} else if (type == 15) {
if (length != null) {
return "varchar" + "(" + length + ")";
} else return "varchar";
} else if (type == 16) {
if (length != null) {
return "binary" + "(" + length + ")";
} else return "binary";
} else if (type == 17) {
if (length != null) {
return "varbinary" + "(" + length + ")";
} else return "varbinary";
} else if (type == 18) {
return "blob";
} else if (type == 19) {
return "text";
} else if (type == 20) {
return "enum";
} else if (type == 21) {
return "set";
} else if (type == 22) {
if (length != null) {
return "bit" + "(" + length + ")";
} else return "bit";
} else if (type == 23) {
return "tinyblob";
} else if (type == 24) {
return "blob";
} else if (type == 25) {
return "mediumblob";
} else if (type == 26) {
return "longblob";
} else return null;
}
}

@ -9,9 +9,14 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.swagger.models.auth.In;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.fieldx.controller.FieldxController;
import org.jeecg.modules.fieldx.entity.Fieldx;
import org.jeecg.modules.fieldx.service.IFieldxService;
import org.jeecg.modules.modulex.entity.Modulex;
import org.jeecg.modules.modulex.service.IModulexService;
import org.jeecg.modules.tablex.entity.Tablex;
@ -54,6 +59,11 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
@Autowired
private IModulexService modulexService;
@Autowired
private IFieldxService fieldxService;
@Autowired
private FieldxController fieldxController;
/**
* 分页列表查询
@ -93,6 +103,7 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
tablex.setTableEnName(modulex.getModuleEnName());
}
tablex.setVerison(1);
tablex.setTableStructure("CREATE TABLE '"+tablex.getTableEnName()+"' ();");
tablexService.save(tablex);
return Result.OK("添加成功!");
}
@ -107,7 +118,13 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
@ApiOperation(value="实体表-编辑", notes="实体表-编辑")
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody Tablex tablex) {
if (tablex.getModuleId() != null){
Modulex modulex = modulexService.getById(tablex.getModuleId());
tablex.setTableName(modulex.getModuleName());
tablex.setTableEnName(modulex.getModuleEnName());
}
tablexService.updateById(tablex);
tablexService.updateSql(tablex.getId(),fieldxController.createSql(tablex.getId()));
return Result.OK("编辑成功!");
}

@ -3,6 +3,8 @@ package org.jeecg.modules.tablex.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.checkerframework.checker.guieffect.qual.UI;
import org.jeecg.modules.tablex.entity.Tablex;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -14,4 +16,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface TablexMapper extends BaseMapper<Tablex> {
@Update("update tablex set table_structure = #{sql} where id = #{tableId}")
void updateSql(String tableId, String sql);
}

@ -11,4 +11,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface ITablexService extends IService<Tablex> {
void updateSql(String tableId, String sql);
}

@ -3,6 +3,7 @@ package org.jeecg.modules.tablex.service.impl;
import org.jeecg.modules.tablex.entity.Tablex;
import org.jeecg.modules.tablex.mapper.TablexMapper;
import org.jeecg.modules.tablex.service.ITablexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -16,4 +17,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class TablexServiceImpl extends ServiceImpl<TablexMapper, Tablex> implements ITablexService {
@Autowired
private TablexMapper tablexMapper;
@Override
public void updateSql(String tableId, String sql) {
tablexMapper.updateSql(tableId,sql);
}
}

Loading…
Cancel
Save