修复与优化

master
面包骑士 2024-08-21 13:59:28 +08:00
parent 74b7b37bf7
commit 64ee9ea99e
15 changed files with 542 additions and 665 deletions

View File

@ -1,8 +1,8 @@
package com.muyu.gen.controller; package com.muyu.gen.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.text.Convert; import com.muyu.common.core.text.Convert;
import com.muyu.common.core.web.controller.BaseController; import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log; import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType; import com.muyu.common.log.enums.BusinessType;
@ -11,12 +11,12 @@ import com.muyu.gen.domain.GenTable;
import com.muyu.gen.domain.GenTableColumn; import com.muyu.gen.domain.GenTableColumn;
import com.muyu.gen.service.IGenTableColumnService; import com.muyu.gen.service.IGenTableColumnService;
import com.muyu.gen.service.IGenTableService; import com.muyu.gen.service.IGenTableService;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -25,11 +25,12 @@ import java.util.Map;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
@RequestMapping("/gen") @RequestMapping("/gen")
@RestController @RestController
public class GenController extends BaseController { public class GenController extends BaseController
{
@Autowired @Autowired
private IGenTableService genTableService; private IGenTableService genTableService;
@ -41,19 +42,20 @@ public class GenController extends BaseController {
*/ */
@RequiresPermissions("tool:gen:list") @RequiresPermissions("tool:gen:list")
@GetMapping("/list") @GetMapping("/list")
public Result<TableDataInfo<GenTable>> genList (GenTable genTable) { public TableDataInfo genList(GenTable genTable)
{
startPage(); startPage();
List<GenTable> list = genTableService.selectGenTableList(genTable); List<GenTable> list = genTableService.selectGenTableList(genTable);
return getDataTable(list); return getDataTable(list).getData();
} }
/** /**
* *
*/ */
@RequiresPermissions("tool:gen:query") @RequiresPermissions("tool:gen:query")
@GetMapping(value = "/{tableId}") @GetMapping(value = "/{tableId}")
public Result getInfo (@PathVariable("tableId") Long tableId) { public Result getInfo(@PathVariable Long tableId)
{
GenTable table = genTableService.selectGenTableById(tableId); GenTable table = genTableService.selectGenTableById(tableId);
List<GenTable> tables = genTableService.selectGenTableAll(); List<GenTable> tables = genTableService.selectGenTableAll();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
@ -69,24 +71,24 @@ public class GenController extends BaseController {
*/ */
@RequiresPermissions("tool:gen:list") @RequiresPermissions("tool:gen:list")
@GetMapping("/db/list") @GetMapping("/db/list")
public Result<TableDataInfo<GenTable>> dataList (GenTable genTable) { public TableDataInfo dataList(GenTable genTable)
{
startPage(); startPage();
List<GenTable> list = genTableService.selectDbTableList(genTable); List<GenTable> list = genTableService.selectDbTableList(genTable);
return getDataTable(list); return getDataTable(list).getData();
} }
/** /**
* *
*/ */
@GetMapping(value = "/column/{tableId}") @GetMapping(value = "/column/{tableId}")
public Result<TableDataInfo<GenTableColumn>> columnList (Long tableId) { public TableDataInfo columnList(Long tableId)
{
TableDataInfo dataInfo = new TableDataInfo();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
return Result.success( dataInfo.setRows(list);
TableDataInfo.<GenTableColumn>builder() dataInfo.setTotal(list.size());
.total(list.size()) return dataInfo;
.rows(list)
.build()
);
} }
/** /**
@ -95,10 +97,11 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:import") @RequiresPermissions("tool:gen:import")
@Log(title = "代码生成", businessType = BusinessType.IMPORT) @Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable") @PostMapping("/importTable")
public Result importTableSave (String tables) { public Result importTableSave(@RequestParam("tables") String tables, @RequestParam("dbName") String dbName)
{
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
// 查询表信息 // 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames,dbName);
genTableService.importGenTable(tableList); genTableService.importGenTable(tableList);
return success(); return success();
} }
@ -109,7 +112,8 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:edit") @RequiresPermissions("tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE) @Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public Result editSave (@Validated @RequestBody GenTable genTable) { public Result editSave(@Validated @RequestBody GenTable genTable)
{
genTableService.validateEdit(genTable); genTableService.validateEdit(genTable);
genTableService.updateGenTable(genTable); genTableService.updateGenTable(genTable);
return success(); return success();
@ -121,7 +125,8 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:remove") @RequiresPermissions("tool:gen:remove")
@Log(title = "代码生成", businessType = BusinessType.DELETE) @Log(title = "代码生成", businessType = BusinessType.DELETE)
@DeleteMapping("/{tableIds}") @DeleteMapping("/{tableIds}")
public Result remove (@PathVariable("tableIds") Long[] tableIds) { public Result remove(@PathVariable Long[] tableIds)
{
genTableService.deleteGenTableByIds(tableIds); genTableService.deleteGenTableByIds(tableIds);
return success(); return success();
} }
@ -131,7 +136,8 @@ public class GenController extends BaseController {
*/ */
@RequiresPermissions("tool:gen:preview") @RequiresPermissions("tool:gen:preview")
@GetMapping("/preview/{tableId}") @GetMapping("/preview/{tableId}")
public Result preview (@PathVariable("tableId") Long tableId) throws IOException { public Result preview(@PathVariable("tableId") Long tableId) throws IOException
{
Map<String, String> dataMap = genTableService.previewCode(tableId); Map<String, String> dataMap = genTableService.previewCode(tableId);
return success(dataMap); return success(dataMap);
} }
@ -142,7 +148,8 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:code") @RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/download/{tableName}") @GetMapping("/download/{tableName}")
public void download (HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
{
byte[] data = genTableService.downloadCode(tableName); byte[] data = genTableService.downloadCode(tableName);
genCode(response, data); genCode(response, data);
} }
@ -153,7 +160,8 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:code") @RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableName}") @GetMapping("/genCode/{tableName}")
public Result genCode (@PathVariable("tableName") String tableName) { public Result genCode(@PathVariable("tableName") String tableName)
{
genTableService.generatorCode(tableName); genTableService.generatorCode(tableName);
return success(); return success();
} }
@ -163,9 +171,10 @@ public class GenController extends BaseController {
*/ */
@RequiresPermissions("tool:gen:edit") @RequiresPermissions("tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE) @Log(title = "代码生成", businessType = BusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}") @GetMapping("/synchDb/{tableName}/{dbName}")
public Result synchDb (@PathVariable("tableName") String tableName) { public Result synchDb(@PathVariable("tableName") String tableName,@PathVariable("dbName") String dbName)
genTableService.synchDb(tableName); {
genTableService.synchDb(tableName,dbName);
return success(); return success();
} }
@ -175,7 +184,8 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:code") @RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode") @GetMapping("/batchGenCode")
public void batchGenCode (HttpServletResponse response, String tables) throws IOException { public void batchGenCode(HttpServletResponse response, String tables) throws IOException
{
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.downloadCode(tableNames); byte[] data = genTableService.downloadCode(tableNames);
genCode(response, data); genCode(response, data);
@ -184,11 +194,20 @@ public class GenController extends BaseController {
/** /**
* zip * zip
*/ */
private void genCode (HttpServletResponse response, byte[] data) throws IOException { private void genCode(HttpServletResponse response, byte[] data) throws IOException
{
response.reset(); response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"muyu.zip\""); response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", String.valueOf(data.length)); response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8"); response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream()); IOUtils.write(data, response.getOutputStream());
} }
/**
*
*/
@GetMapping("/selDbNameAll")
public Result<List<String>> selDbNameAll(){
return Result.success(genTableService.selDbNameAll());
}
} }

View File

@ -35,6 +35,8 @@ public class GenTable extends BaseEntity {
*/ */
private Long tableId; private Long tableId;
private String dbName;
/** /**
* *
*/ */

View File

@ -1,67 +1,64 @@
package com.muyu.gen.mapper; package com.muyu.gen.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.gen.domain.GenTableColumn; import com.muyu.gen.domain.GenTableColumn;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> { public interface GenTableColumnMapper
{
/** /**
* *
* *
* @param tableName * @param tableName
* * @param dbName
* @return * @return
*/ */
List<GenTableColumn> selectDbTableColumnsByName (String tableName); public List<GenTableColumn> selectDbTableColumnsByName(@Param("tableName") String tableName, @Param("dbName") String dbName);
/** /**
* *
* *
* @param tableId * @param tableId
*
* @return * @return
*/ */
List<GenTableColumn> selectGenTableColumnListByTableId (Long tableId); public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
*
* @return * @return
*/ */
int insertGenTableColumn (GenTableColumn genTableColumn); public int insertGenTableColumn(GenTableColumn genTableColumn);
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
*
* @return * @return
*/ */
int updateGenTableColumn (GenTableColumn genTableColumn); public int updateGenTableColumn(GenTableColumn genTableColumn);
/** /**
* *
* *
* @param genTableColumns * @param genTableColumns
*
* @return * @return
*/ */
int deleteGenTableColumns (List<GenTableColumn> genTableColumns); public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
/** /**
* *
* *
* @param ids ID * @param ids ID
*
* @return * @return
*/ */
int deleteGenTableColumnByIds (Long[] ids); public int deleteGenTableColumnByIds(Long[] ids);
} }

View File

@ -1,92 +1,88 @@
package com.muyu.gen.mapper; package com.muyu.gen.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.gen.domain.GenTable; import com.muyu.gen.domain.GenTable;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
public interface GenTableMapper extends BaseMapper<GenTable> { public interface GenTableMapper
{
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
List<GenTable> selectGenTableList (GenTable genTable); public List<GenTable> selectGenTableList(GenTable genTable);
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
List<GenTable> selectDbTableList (GenTable genTable); public List<GenTable> selectDbTableList(GenTable genTable);
/** /**
* *
* *
* @param tableNames * @param tableNames
* * @param dbName
* @return * @return
*/ */
List<GenTable> selectDbTableListByNames (String[] tableNames); public List<GenTable> selectDbTableListByNames(@Param("tableNames") String[] tableNames, @Param("dbName") String dbName);
/** /**
* *
* *
* @return * @return
*/ */
List<GenTable> selectGenTableAll (); public List<GenTable> selectGenTableAll();
/** /**
* ID * ID
* *
* @param id ID * @param id ID
*
* @return * @return
*/ */
GenTable selectGenTableById (Long id); public GenTable selectGenTableById(Long id);
/** /**
* *
* *
* @param tableName * @param tableName
*
* @return * @return
*/ */
GenTable selectGenTableByName (String tableName); public GenTable selectGenTableByName(String tableName);
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
int insertGenTable (GenTable genTable); public int insertGenTable(GenTable genTable);
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
int updateGenTable (GenTable genTable); public int updateGenTable(GenTable genTable);
/** /**
* *
* *
* @param ids ID * @param ids ID
*
* @return * @return
*/ */
int deleteGenTableByIds (Long[] ids); public int deleteGenTableByIds(Long[] ids);
List<String> selDbNameAll();
} }

View File

@ -11,58 +11,59 @@ import java.util.List;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
@Service @Service
public class GenTableColumnServiceImpl implements IGenTableColumnService { public class GenTableColumnServiceImpl implements IGenTableColumnService
@Autowired {
private GenTableColumnMapper genTableColumnMapper; @Autowired
private GenTableColumnMapper genTableColumnMapper;
/** /**
* *
* *
* @param tableId * @param tableId
*
* @return * @return
*/ */
@Override @Override
public List<GenTableColumn> selectGenTableColumnListByTableId (Long tableId) { public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); {
} return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
}
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
*
* @return * @return
*/ */
@Override @Override
public int insertGenTableColumn (GenTableColumn genTableColumn) { public int insertGenTableColumn(GenTableColumn genTableColumn)
return genTableColumnMapper.insertGenTableColumn(genTableColumn); {
} return genTableColumnMapper.insertGenTableColumn(genTableColumn);
}
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
*
* @return * @return
*/ */
@Override @Override
public int updateGenTableColumn (GenTableColumn genTableColumn) { public int updateGenTableColumn(GenTableColumn genTableColumn)
return genTableColumnMapper.updateGenTableColumn(genTableColumn); {
} return genTableColumnMapper.updateGenTableColumn(genTableColumn);
}
/** /**
* *
* *
* @param ids ID * @param ids ID
*
* @return * @return
*/ */
@Override @Override
public int deleteGenTableColumnByIds (String ids) { public int deleteGenTableColumnByIds(String ids)
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); {
} return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
}
} }

View File

@ -41,10 +41,11 @@ import java.util.zip.ZipOutputStream;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
@Service @Service
public class GenTableServiceImpl implements IGenTableService { public class GenTableServiceImpl implements IGenTableService
{
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
@Autowired @Autowired
@ -53,31 +54,15 @@ public class GenTableServiceImpl implements IGenTableService {
@Autowired @Autowired
private GenTableColumnMapper genTableColumnMapper; private GenTableColumnMapper genTableColumnMapper;
/**
*
*
* @param table
* @param template
*
* @return
*/
public static String getGenPath (GenTable table, String template) {
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/")) {
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
/** /**
* *
* *
* @param id ID * @param id ID
*
* @return * @return
*/ */
@Override @Override
public GenTable selectGenTableById (Long id) { public GenTable selectGenTableById(Long id)
{
GenTable genTable = genTableMapper.selectGenTableById(id); GenTable genTable = genTableMapper.selectGenTableById(id);
setTableFromOptions(genTable); setTableFromOptions(genTable);
return genTable; return genTable;
@ -87,11 +72,11 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
@Override @Override
public List<GenTable> selectGenTableList (GenTable genTable) { public List<GenTable> selectGenTableList(GenTable genTable)
{
return genTableMapper.selectGenTableList(genTable); return genTableMapper.selectGenTableList(genTable);
} }
@ -99,11 +84,11 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
@Override @Override
public List<GenTable> selectDbTableList (GenTable genTable) { public List<GenTable> selectDbTableList(GenTable genTable)
{
return genTableMapper.selectDbTableList(genTable); return genTableMapper.selectDbTableList(genTable);
} }
@ -111,12 +96,13 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param tableNames * @param tableNames
* * @param dbName
* @return * @return
*/ */
@Override @Override
public List<GenTable> selectDbTableListByNames (String[] tableNames) { public List<GenTable> selectDbTableListByNames(String[] tableNames, String dbName)
return genTableMapper.selectDbTableListByNames(tableNames); {
return genTableMapper.selectDbTableListByNames(tableNames,dbName);
} }
/** /**
@ -125,7 +111,8 @@ public class GenTableServiceImpl implements IGenTableService {
* @return * @return
*/ */
@Override @Override
public List<GenTable> selectGenTableAll () { public List<GenTable> selectGenTableAll()
{
return genTableMapper.selectGenTableAll(); return genTableMapper.selectGenTableAll();
} }
@ -133,17 +120,19 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateGenTable (GenTable genTable) { public void updateGenTable(GenTable genTable)
{
String options = JSON.toJSONString(genTable.getParams()); String options = JSON.toJSONString(genTable.getParams());
genTable.setOptions(options); genTable.setOptions(options);
int row = genTableMapper.updateGenTable(genTable); int row = genTableMapper.updateGenTable(genTable);
if (row > 0) { if (row > 0)
for (GenTableColumn cenTableColumn : genTable.getColumns()) { {
for (GenTableColumn cenTableColumn : genTable.getColumns())
{
genTableColumnMapper.updateGenTableColumn(cenTableColumn); genTableColumnMapper.updateGenTableColumn(cenTableColumn);
} }
} }
@ -153,12 +142,12 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param tableIds ID * @param tableIds ID
*
* @return * @return
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteGenTableByIds (Long[] tableIds) { public void deleteGenTableByIds(Long[] tableIds)
{
genTableMapper.deleteGenTableByIds(tableIds); genTableMapper.deleteGenTableByIds(tableIds);
genTableColumnMapper.deleteGenTableColumnByIds(tableIds); genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
} }
@ -170,23 +159,31 @@ public class GenTableServiceImpl implements IGenTableService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void importGenTable (List<GenTable> tableList) { public void importGenTable(List<GenTable> tableList)
{
String operName = SecurityUtils.getUsername(); String operName = SecurityUtils.getUsername();
try { try
for (GenTable table : tableList) { {
for (GenTable table : tableList)
{
String dbName = table.getDbName();
String tableName = table.getTableName(); String tableName = table.getTableName();
GenUtils.initTable(table, operName); GenUtils.initTable(table, operName);
int row = genTableMapper.insertGenTable(table); int row = genTableMapper.insertGenTable(table);
if (row > 0) { if (row > 0)
{
// 保存列信息 // 保存列信息
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName, dbName);
for (GenTableColumn column : genTableColumns) { for (GenTableColumn column : genTableColumns)
{
GenUtils.initColumnField(column, table); GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(column); genTableColumnMapper.insertGenTableColumn(column);
} }
} }
} }
} catch (Exception e) { }
catch (Exception e)
{
throw new ServiceException("导入失败:" + e.getMessage()); throw new ServiceException("导入失败:" + e.getMessage());
} }
} }
@ -195,11 +192,11 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param tableId * @param tableId
*
* @return * @return
*/ */
@Override @Override
public Map<String, String> previewCode (Long tableId) { public Map<String, String> previewCode(Long tableId)
{
Map<String, String> dataMap = new LinkedHashMap<>(); Map<String, String> dataMap = new LinkedHashMap<>();
// 查询表信息 // 查询表信息
GenTable table = genTableMapper.selectGenTableById(tableId); GenTable table = genTableMapper.selectGenTableById(tableId);
@ -213,7 +210,8 @@ public class GenTableServiceImpl implements IGenTableService {
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates) { for (String template : templates)
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
@ -227,11 +225,11 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param tableName * @param tableName
*
* @return * @return
*/ */
@Override @Override
public byte[] downloadCode (String tableName) { public byte[] downloadCode(String tableName)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
generatorCode(tableName, zip); generatorCode(tableName, zip);
@ -245,7 +243,8 @@ public class GenTableServiceImpl implements IGenTableService {
* @param tableName * @param tableName
*/ */
@Override @Override
public void generatorCode (String tableName) { public void generatorCode(String tableName)
{
// 查询表信息 // 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName); GenTable table = genTableMapper.selectGenTableByName(tableName);
// 设置主子表信息 // 设置主子表信息
@ -259,16 +258,21 @@ public class GenTableServiceImpl implements IGenTableService {
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates) { for (String template : templates)
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { {
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw); tpl.merge(context, sw);
try { try
{
String path = getGenPath(table, template); String path = getGenPath(table, template);
FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
} catch (IOException e) { }
catch (IOException e)
{
throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
} }
} }
@ -279,45 +283,54 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param tableName * @param tableName
* @param dbName
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void synchDb (String tableName) { public void synchDb(String tableName, String dbName)
{
GenTable table = genTableMapper.selectGenTableByName(tableName); GenTable table = genTableMapper.selectGenTableByName(tableName);
List<GenTableColumn> tableColumns = table.getColumns(); List<GenTableColumn> tableColumns = table.getColumns();
Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName, dbName);
if (StringUtils.isEmpty(dbTableColumns)) { if (StringUtils.isEmpty(dbTableColumns))
{
throw new ServiceException("同步数据失败,原表结构不存在"); throw new ServiceException("同步数据失败,原表结构不存在");
} }
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
dbTableColumns.forEach(column -> { dbTableColumns.forEach(column -> {
GenUtils.initColumnField(column, table); GenUtils.initColumnField(column, table);
if (tableColumnMap.containsKey(column.getColumnName())) { if (tableColumnMap.containsKey(column.getColumnName()))
{
GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
column.setColumnId(prevColumn.getColumnId()); column.setColumnId(prevColumn.getColumnId());
if (column.isList()) { if (column.isList())
{
// 如果是列表,继续保留查询方式/字典类型选项 // 如果是列表,继续保留查询方式/字典类型选项
column.setDictType(prevColumn.getDictType()); column.setDictType(prevColumn.getDictType());
column.setQueryType(prevColumn.getQueryType()); column.setQueryType(prevColumn.getQueryType());
} }
if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()
&& (column.isInsert() || column.isEdit()) && (column.isInsert() || column.isEdit())
&& ((column.isUsableColumn()) || (!column.isSuperColumn()))) { && ((column.isUsableColumn()) || (!column.isSuperColumn())))
{
// 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
column.setIsRequired(prevColumn.getIsRequired()); column.setIsRequired(prevColumn.getIsRequired());
column.setHtmlType(prevColumn.getHtmlType()); column.setHtmlType(prevColumn.getHtmlType());
} }
genTableColumnMapper.updateGenTableColumn(column); genTableColumnMapper.updateGenTableColumn(column);
} else { }
else
{
genTableColumnMapper.insertGenTableColumn(column); genTableColumnMapper.insertGenTableColumn(column);
} }
}); });
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (StringUtils.isNotEmpty(delColumns)) { if (StringUtils.isNotEmpty(delColumns))
{
genTableColumnMapper.deleteGenTableColumns(delColumns); genTableColumnMapper.deleteGenTableColumns(delColumns);
} }
} }
@ -326,14 +339,15 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* *
* @param tableNames * @param tableNames
*
* @return * @return
*/ */
@Override @Override
public byte[] downloadCode (String[] tableNames) { public byte[] downloadCode(String[] tableNames)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames) { for (String tableName : tableNames)
{
generatorCode(tableName, zip); generatorCode(tableName, zip);
} }
IOUtils.closeQuietly(zip); IOUtils.closeQuietly(zip);
@ -343,7 +357,8 @@ public class GenTableServiceImpl implements IGenTableService {
/** /**
* *
*/ */
private void generatorCode (String tableName, ZipOutputStream zip) { private void generatorCode(String tableName, ZipOutputStream zip)
{
// 查询表信息 // 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName); GenTable table = genTableMapper.selectGenTableByName(tableName);
// 设置主子表信息 // 设置主子表信息
@ -357,19 +372,23 @@ public class GenTableServiceImpl implements IGenTableService {
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates) { for (String template : templates)
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw); tpl.merge(context, sw);
try { try
{
// 添加到zip // 添加到zip
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.write(sw.toString(), zip, Constants.UTF8);
IOUtils.closeQuietly(sw); IOUtils.closeQuietly(sw);
zip.flush(); zip.flush();
zip.closeEntry(); zip.closeEntry();
} catch (IOException e) { }
catch (IOException e)
{
log.error("渲染模板失败,表名:" + table.getTableName(), e); log.error("渲染模板失败,表名:" + table.getTableName(), e);
} }
} }
@ -381,49 +400,74 @@ public class GenTableServiceImpl implements IGenTableService {
* @param genTable * @param genTable
*/ */
@Override @Override
public void validateEdit (GenTable genTable) { public void validateEdit(GenTable genTable)
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { {
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
{
String options = JSON.toJSONString(genTable.getParams()); String options = JSON.toJSONString(genTable.getParams());
JSONObject paramsObj = JSON.parseObject(options); JSONObject paramsObj = JSON.parseObject(options);
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
{
throw new ServiceException("树编码字段不能为空"); throw new ServiceException("树编码字段不能为空");
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { }
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
{
throw new ServiceException("树父编码字段不能为空"); throw new ServiceException("树父编码字段不能为空");
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { }
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
{
throw new ServiceException("树名称字段不能为空"); throw new ServiceException("树名称字段不能为空");
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { }
if (StringUtils.isEmpty(genTable.getSubTableName())) { else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
{
if (StringUtils.isEmpty(genTable.getSubTableName()))
{
throw new ServiceException("关联子表的表名不能为空"); throw new ServiceException("关联子表的表名不能为空");
} else if (StringUtils.isEmpty(genTable.getSubTableFkName())) { }
else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
{
throw new ServiceException("子表关联的外键名不能为空"); throw new ServiceException("子表关联的外键名不能为空");
} }
} }
} }
} }
@Override
public List<String> selDbNameAll() {
return genTableMapper.selDbNameAll();
}
/** /**
* *
* *
* @param table * @param table
*/ */
public void setPkColumn (GenTable table) { public void setPkColumn(GenTable table)
for (GenTableColumn column : table.getColumns()) { {
if (column.isPk()) { for (GenTableColumn column : table.getColumns())
{
if (column.isPk())
{
table.setPkColumn(column); table.setPkColumn(column);
break; break;
} }
} }
if (StringUtils.isNull(table.getPkColumn())) { if (StringUtils.isNull(table.getPkColumn()))
{
table.setPkColumn(table.getColumns().get(0)); table.setPkColumn(table.getColumns().get(0));
} }
if (GenConstants.TPL_SUB.equals(table.getTplCategory())) { if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
for (GenTableColumn column : table.getSubTable().getColumns()) { {
if (column.isPk()) { for (GenTableColumn column : table.getSubTable().getColumns())
{
if (column.isPk())
{
table.getSubTable().setPkColumn(column); table.getSubTable().setPkColumn(column);
break; break;
} }
} }
if (StringUtils.isNull(table.getSubTable().getPkColumn())) { if (StringUtils.isNull(table.getSubTable().getPkColumn()))
{
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
} }
} }
@ -434,9 +478,11 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* @param table * @param table
*/ */
public void setSubTable (GenTable table) { public void setSubTable(GenTable table)
{
String subTableName = table.getSubTableName(); String subTableName = table.getSubTableName();
if (StringUtils.isNotEmpty(subTableName)) { if (StringUtils.isNotEmpty(subTableName))
{
table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
} }
} }
@ -446,9 +492,11 @@ public class GenTableServiceImpl implements IGenTableService {
* *
* @param genTable * @param genTable
*/ */
public void setTableFromOptions (GenTable genTable) { public void setTableFromOptions(GenTable genTable)
{
JSONObject paramsObj = JSON.parseObject(genTable.getOptions()); JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
if (StringUtils.isNotNull(paramsObj)) { if (StringUtils.isNotNull(paramsObj))
{
String treeCode = paramsObj.getString(GenConstants.TREE_CODE); String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
String treeName = paramsObj.getString(GenConstants.TREE_NAME); String treeName = paramsObj.getString(GenConstants.TREE_NAME);
@ -462,4 +510,21 @@ public class GenTableServiceImpl implements IGenTableService {
genTable.setParentMenuName(parentMenuName); genTable.setParentMenuName(parentMenuName);
} }
} }
/**
*
*
* @param table
* @param template
* @return
*/
public static String getGenPath(GenTable table, String template)
{
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/"))
{
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
} }

View File

@ -7,42 +7,39 @@ import java.util.List;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
public interface IGenTableColumnService { public interface IGenTableColumnService
{
/** /**
* *
* *
* @param tableId * @param tableId
*
* @return * @return
*/ */
List<GenTableColumn> selectGenTableColumnListByTableId (Long tableId); public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
*
* @return * @return
*/ */
int insertGenTableColumn (GenTableColumn genTableColumn); public int insertGenTableColumn(GenTableColumn genTableColumn);
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
*
* @return * @return
*/ */
int updateGenTableColumn (GenTableColumn genTableColumn); public int updateGenTableColumn(GenTableColumn genTableColumn);
/** /**
* *
* *
* @param ids ID * @param ids ID
*
* @return * @return
*/ */
int deleteGenTableColumnByIds (String ids); public int deleteGenTableColumnByIds(String ids);
} }

View File

@ -8,124 +8,119 @@ import java.util.Map;
/** /**
* *
* *
* @author muyu * @author ruoyi
*/ */
public interface IGenTableService { public interface IGenTableService
{
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
List<GenTable> selectGenTableList (GenTable genTable); public List<GenTable> selectGenTableList(GenTable genTable);
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
List<GenTable> selectDbTableList (GenTable genTable); public List<GenTable> selectDbTableList(GenTable genTable);
/** /**
* *
* *
* @param tableNames * @param tableNames
* * @param dbName
* @return * @return
*/ */
List<GenTable> selectDbTableListByNames (String[] tableNames); public List<GenTable> selectDbTableListByNames(String[] tableNames, String dbName);
/** /**
* *
* *
* @return * @return
*/ */
List<GenTable> selectGenTableAll (); public List<GenTable> selectGenTableAll();
/** /**
* *
* *
* @param id ID * @param id ID
*
* @return * @return
*/ */
GenTable selectGenTableById (Long id); public GenTable selectGenTableById(Long id);
/** /**
* *
* *
* @param genTable * @param genTable
*
* @return * @return
*/ */
void updateGenTable (GenTable genTable); public void updateGenTable(GenTable genTable);
/** /**
* *
* *
* @param tableIds ID * @param tableIds ID
*
* @return * @return
*/ */
void deleteGenTableByIds (Long[] tableIds); public void deleteGenTableByIds(Long[] tableIds);
/** /**
* *
* *
* @param tableList * @param tableList
*/ */
void importGenTable (List<GenTable> tableList); public void importGenTable(List<GenTable> tableList);
/** /**
* *
* *
* @param tableId * @param tableId
*
* @return * @return
*/ */
Map<String, String> previewCode (Long tableId); public Map<String, String> previewCode(Long tableId);
/** /**
* *
* *
* @param tableName * @param tableName
*
* @return * @return
*/ */
byte[] downloadCode (String tableName); public byte[] downloadCode(String tableName);
/** /**
* *
* *
* @param tableName * @param tableName
*
* @return * @return
*/ */
void generatorCode (String tableName); public void generatorCode(String tableName);
/** /**
* *
* *
* @param tableName * @param tableName
* @param dbName
*/ */
void synchDb (String tableName); public void synchDb(String tableName, String dbName);
/** /**
* *
* *
* @param tableNames * @param tableNames
*
* @return * @return
*/ */
byte[] downloadCode (String[] tableNames); public byte[] downloadCode(String[] tableNames);
/** /**
* *
* *
* @param genTable * @param genTable
*/ */
void validateEdit (GenTable genTable); public void validateEdit(GenTable genTable);
List<String> selDbNameAll();
} }

View File

@ -5,8 +5,6 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 10.0.1.97:8848 addr: 10.0.1.97:8848
user-name: nacos
password: nacos
namespace: cloud-2112 namespace: cloud-2112
# Spring # Spring
@ -24,20 +22,11 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: ${nacos.addr} server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间 # 命名空间
namespace: ${nacos.namespace} namespace: ${nacos.namespace}
ip: 47.116.173.119
config: config:
# 服务注册地址 # 服务注册地址
server-addr: ${nacos.addr} server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间 # 命名空间
namespace: ${nacos.namespace} namespace: ${nacos.namespace}
# 配置文件格式 # 配置文件格式

View File

@ -1,58 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.gen.mapper.GenTableColumnMapper"> <mapper namespace="com.muyu.gen.mapper.GenTableColumnMapper">
<resultMap type="com.muyu.gen.domain.GenTableColumn" id="GenTableColumnResult"> <resultMap type="com.muyu.gen.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id"/> <id property="columnId" column="column_id" />
<result property="tableId" column="table_id"/> <result property="tableId" column="table_id" />
<result property="columnName" column="column_name"/> <result property="columnName" column="column_name" />
<result property="columnComment" column="column_comment"/> <result property="columnComment" column="column_comment" />
<result property="columnType" column="column_type"/> <result property="columnType" column="column_type" />
<result property="javaType" column="java_type"/> <result property="javaType" column="java_type" />
<result property="javaField" column="java_field"/> <result property="javaField" column="java_field" />
<result property="isPk" column="is_pk"/> <result property="isPk" column="is_pk" />
<result property="isIncrement" column="is_increment"/> <result property="isIncrement" column="is_increment" />
<result property="isRequired" column="is_required"/> <result property="isRequired" column="is_required" />
<result property="isInsert" column="is_insert"/> <result property="isInsert" column="is_insert" />
<result property="isEdit" column="is_edit"/> <result property="isEdit" column="is_edit" />
<result property="isList" column="is_list"/> <result property="isList" column="is_list" />
<result property="isQuery" column="is_query"/> <result property="isQuery" column="is_query" />
<result property="queryType" column="query_type"/> <result property="queryType" column="query_type" />
<result property="htmlType" column="html_type"/> <result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type"/> <result property="dictType" column="dict_type" />
<result property="sort" column="sort"/> <result property="sort" column="sort" />
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time" />
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time" />
</resultMap> </resultMap>
<sql id="selectGenTableColumnVo"> <sql id="selectGenTableColumnVo">
select column_id, select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
table_id,
column_name,
column_comment,
column_type,
java_type,
java_field,
is_pk,
is_increment,
is_required,
is_insert,
is_edit,
is_list,
is_query,
query_type,
html_type,
dict_type,
sort,
create_by,
create_time,
update_by,
update_time
from gen_table_column
</sql> </sql>
<select id="selectGenTableColumnListByTableId" parameterType="com.muyu.gen.domain.GenTableColumn" resultMap="GenTableColumnResult"> <select id="selectGenTableColumnListByTableId" parameterType="com.muyu.gen.domain.GenTableColumn" resultMap="GenTableColumnResult">
@ -62,61 +40,55 @@
</select> </select>
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
select column_name, select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
(case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, from information_schema.columns where
(case when column_key = 'PRI' then '1' else '0' end) as is_pk, <include refid="com.muyu.gen.mapper.GenTableMapper.select_dbName"/>
ordinal_position as sort, and table_name = (#{tableName})
column_comment, order by ordinal_position
(case when extra = 'auto_increment' then '1' else '0' end) as is_increment, </select>
column_type
from information_schema.columns
where table_schema = (select database())
and table_name = (#{tableName})
order by ordinal_position
</select>
<insert id="insertGenTableColumn" parameterType="com.muyu.gen.domain.GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> <insert id="insertGenTableColumn" parameterType="com.muyu.gen.domain.GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
insert into gen_table_column ( insert into gen_table_column (
<if test="tableId != null and tableId != ''">table_id,</if> <if test="tableId != null and tableId != ''">table_id,</if>
<if test="columnName != null and columnName != ''">column_name,</if> <if test="columnName != null and columnName != ''">column_name,</if>
<if test="columnComment != null and columnComment != ''">column_comment,</if> <if test="columnComment != null and columnComment != ''">column_comment,</if>
<if test="columnType != null and columnType != ''">column_type,</if> <if test="columnType != null and columnType != ''">column_type,</if>
<if test="javaType != null and javaType != ''">java_type,</if> <if test="javaType != null and javaType != ''">java_type,</if>
<if test="javaField != null and javaField != ''">java_field,</if> <if test="javaField != null and javaField != ''">java_field,</if>
<if test="isPk != null and isPk != ''">is_pk,</if> <if test="isPk != null and isPk != ''">is_pk,</if>
<if test="isIncrement != null and isIncrement != ''">is_increment,</if> <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
<if test="isRequired != null and isRequired != ''">is_required,</if> <if test="isRequired != null and isRequired != ''">is_required,</if>
<if test="isInsert != null and isInsert != ''">is_insert,</if> <if test="isInsert != null and isInsert != ''">is_insert,</if>
<if test="isEdit != null and isEdit != ''">is_edit,</if> <if test="isEdit != null and isEdit != ''">is_edit,</if>
<if test="isList != null and isList != ''">is_list,</if> <if test="isList != null and isList != ''">is_list,</if>
<if test="isQuery != null and isQuery != ''">is_query,</if> <if test="isQuery != null and isQuery != ''">is_query,</if>
<if test="queryType != null and queryType != ''">query_type,</if> <if test="queryType != null and queryType != ''">query_type,</if>
<if test="htmlType != null and htmlType != ''">html_type,</if> <if test="htmlType != null and htmlType != ''">html_type,</if>
<if test="dictType != null and dictType != ''">dict_type,</if> <if test="dictType != null and dictType != ''">dict_type,</if>
<if test="sort != null">sort,</if> <if test="sort != null">sort,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
create_time create_time
)values( )values(
<if test="tableId != null and tableId != ''">#{tableId},</if> <if test="tableId != null and tableId != ''">#{tableId},</if>
<if test="columnName != null and columnName != ''">#{columnName},</if> <if test="columnName != null and columnName != ''">#{columnName},</if>
<if test="columnComment != null and columnComment != ''">#{columnComment},</if> <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
<if test="columnType != null and columnType != ''">#{columnType},</if> <if test="columnType != null and columnType != ''">#{columnType},</if>
<if test="javaType != null and javaType != ''">#{javaType},</if> <if test="javaType != null and javaType != ''">#{javaType},</if>
<if test="javaField != null and javaField != ''">#{javaField},</if> <if test="javaField != null and javaField != ''">#{javaField},</if>
<if test="isPk != null and isPk != ''">#{isPk},</if> <if test="isPk != null and isPk != ''">#{isPk},</if>
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
<if test="isRequired != null and isRequired != ''">#{isRequired},</if> <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
<if test="isInsert != null and isInsert != ''">#{isInsert},</if> <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
<if test="isEdit != null and isEdit != ''">#{isEdit},</if> <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
<if test="isList != null and isList != ''">#{isList},</if> <if test="isList != null and isList != ''">#{isList},</if>
<if test="isQuery != null and isQuery != ''">#{isQuery},</if> <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
<if test="queryType != null and queryType != ''">#{queryType},</if> <if test="queryType != null and queryType != ''">#{queryType},</if>
<if test="htmlType != null and htmlType != ''">#{htmlType},</if> <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if> <if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="sort != null">#{sort},</if> <if test="sort != null">#{sort},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate() sysdate()
) )
</insert> </insert>
<update id="updateGenTableColumn" parameterType="com.muyu.gen.domain.GenTableColumn"> <update id="updateGenTableColumn" parameterType="com.muyu.gen.domain.GenTableColumn">

View File

@ -1,291 +1,200 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.gen.mapper.GenTableMapper"> <mapper namespace="com.muyu.gen.mapper.GenTableMapper">
<resultMap type="com.muyu.gen.domain.GenTable" id="GenTableResult"> <resultMap type="com.muyu.gen.domain.GenTable" id="GenTableResult">
<id property="tableId" column="table_id"/> <id property="tableId" column="table_id" />
<result property="tableName" column="table_name"/> <result property="dbName" column="db_name" />
<result property="tableComment" column="table_comment"/> <result property="tableName" column="table_name" />
<result property="subTableName" column="sub_table_name"/> <result property="tableComment" column="table_comment" />
<result property="subTableFkName" column="sub_table_fk_name"/> <result property="subTableName" column="sub_table_name" />
<result property="className" column="class_name"/> <result property="subTableFkName" column="sub_table_fk_name" />
<result property="tplCategory" column="tpl_category"/> <result property="className" column="class_name" />
<result property="packageName" column="package_name"/> <result property="tplCategory" column="tpl_category" />
<result property="moduleName" column="module_name"/> <result property="packageName" column="package_name" />
<result property="businessName" column="business_name"/> <result property="moduleName" column="module_name" />
<result property="functionName" column="function_name"/> <result property="businessName" column="business_name" />
<result property="functionAuthor" column="function_author"/> <result property="functionName" column="function_name" />
<result property="genType" column="gen_type"/> <result property="functionAuthor" column="function_author" />
<result property="genPath" column="gen_path"/> <result property="genType" column="gen_type" />
<result property="options" column="options"/> <result property="genPath" column="gen_path" />
<result property="createBy" column="create_by"/> <result property="options" column="options" />
<result property="createTime" column="create_time"/> <result property="createBy" column="create_by" />
<result property="updateBy" column="update_by"/> <result property="createTime" column="create_time" />
<result property="updateTime" column="update_time"/> <result property="updateBy" column="update_by" />
<result property="remark" column="remark"/> <result property="updateTime" column="update_time" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/> <result property="remark" column="remark" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
</resultMap>
<resultMap type="com.muyu.gen.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" />
<result property="tableId" column="table_id" />
<result property="columnName" column="column_name" />
<result property="columnComment" column="column_comment" />
<result property="columnType" column="column_type" />
<result property="javaType" column="java_type" />
<result property="javaField" column="java_field" />
<result property="isPk" column="is_pk" />
<result property="isIncrement" column="is_increment" />
<result property="isRequired" column="is_required" />
<result property="isInsert" column="is_insert" />
<result property="isEdit" column="is_edit" />
<result property="isList" column="is_list" />
<result property="isQuery" column="is_query" />
<result property="queryType" column="query_type" />
<result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type" />
<result property="sort" column="sort" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap> </resultMap>
<resultMap type="com.muyu.gen.domain.GenTableColumn" id="GenTableColumnResult"> <sql id="selectGenTableVo">
<id property="columnId" column="column_id"/> select table_id, db_name, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
<result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/>
<result property="columnComment" column="column_comment"/>
<result property="columnType" column="column_type"/>
<result property="javaType" column="java_type"/>
<result property="javaField" column="java_field"/>
<result property="isPk" column="is_pk"/>
<result property="isIncrement" column="is_increment"/>
<result property="isRequired" column="is_required"/>
<result property="isInsert" column="is_insert"/>
<result property="isEdit" column="is_edit"/>
<result property="isList" column="is_list"/>
<result property="isQuery" column="is_query"/>
<result property="queryType" column="query_type"/>
<result property="htmlType" column="html_type"/>
<result property="dictType" column="dict_type"/>
<result property="sort" column="sort"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectGenTableVo">
select table_id,
table_name,
table_comment,
sub_table_name,
sub_table_fk_name,
class_name,
tpl_category,
package_name,
module_name,
business_name,
function_name,
function_author,
gen_type,
gen_path,
options,
create_by,
create_time,
update_by,
update_time,
remark
from gen_table
</sql> </sql>
<sql id="select_dbName">
<choose>
<when test="dbName!=null and dbName!=''">
table_schema = #{dbName}
</when>
<otherwise>
table_schema = (select database())
</otherwise>
</choose>
</sql>
<select id="selectGenTableList" parameterType="com.muyu.gen.domain.GenTable" resultMap="GenTableResult"> <select id="selectGenTableList" parameterType="com.muyu.gen.domain.GenTable" resultMap="GenTableResult">
<include refid="selectGenTableVo"/> <include refid="selectGenTableVo"/>
<where> <where>
<if test="tableName != null and tableName != ''"> <if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%')) AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if> </if>
<if test="tableComment != null and tableComment != ''"> <if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if> </if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>
</select> </select>
<select id="selectDbTableList" parameterType="com.muyu.gen.domain.GenTable" resultMap="GenTableResult"> <select id="selectDbTableList" parameterType="com.muyu.gen.domain.GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database()) where
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' <include refid="select_dbName"/>
AND table_name NOT IN (select table_name from gen_table) AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
<if test="tableName != null and tableName != ''"> AND table_name NOT IN (select table_name from gen_table)
AND lower(table_name) like lower(concat('%', #{tableName}, '%')) <if test="tableName != null and tableName != ''">
</if> AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
<if test="tableComment != null and tableComment != ''"> </if>
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) <if test="tableComment != null and tableComment != ''">
</if> AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> </if>
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
</if> AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> </if>
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
</if> AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
order by create_time desc order by create_time desc
</select> </select>
<select id="selectDbTableListByNames" resultMap="GenTableResult"> <select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables select table_name, table_schema db_name, table_comment, create_time, update_time from information_schema.tables
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database()) where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%'
and table_name in and <include refid="select_dbName"/>
<foreach collection="array" item="name" open="(" separator="," close=")"> and table_name in
#{name} <foreach collection="tableNames" item="name" open="(" separator="," close=")">
#{name}
</foreach> </foreach>
</select> </select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> <select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time select table_name, table_comment, create_time, update_time from information_schema.tables
from information_schema.tables where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
where table_comment <![CDATA[ <> ]]> '' and table_name = #{tableName}
and table_schema = (select database()) </select>
and table_name = #{tableName}
</select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
SELECT t.table_id, SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
t.table_name, c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
t.table_comment, FROM gen_table t
t.sub_table_name, LEFT JOIN gen_table_column c ON t.table_id = c.table_id
t.sub_table_fk_name, where t.table_id = #{tableId} order by c.sort
t.class_name, </select>
t.tpl_category,
t.package_name,
t.module_name,
t.business_name,
t.function_name,
t.function_author,
t.gen_type,
t.gen_path,
t.options,
t.remark,
c.column_id,
c.column_name,
c.column_comment,
c.column_type,
c.java_type,
c.java_field,
c.is_pk,
c.is_increment,
c.is_required,
c.is_insert,
c.is_edit,
c.is_list,
c.is_query,
c.query_type,
c.html_type,
c.dict_type,
c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_id = #{tableId}
order by c.sort
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
t.table_name, c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
t.table_comment, FROM gen_table t
t.sub_table_name, LEFT JOIN gen_table_column c ON t.table_id = c.table_id
t.sub_table_fk_name, where t.table_name = #{tableName} order by c.sort
t.class_name, </select>
t.tpl_category,
t.package_name,
t.module_name,
t.business_name,
t.function_name,
t.function_author,
t.gen_type,
t.gen_path,
t.options,
t.remark,
c.column_id,
c.column_name,
c.column_comment,
c.column_type,
c.java_type,
c.java_field,
c.is_pk,
c.is_increment,
c.is_required,
c.is_insert,
c.is_edit,
c.is_list,
c.is_query,
c.query_type,
c.html_type,
c.dict_type,
c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_name = #{tableName}
order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
t.table_name, c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
t.table_comment, FROM gen_table t
t.sub_table_name, LEFT JOIN gen_table_column c ON t.table_id = c.table_id
t.sub_table_fk_name, order by c.sort
t.class_name, </select>
t.tpl_category, <select id="selDbNameAll" resultType="java.lang.String">
t.package_name, select table_schema from information_schema.tables
t.module_name, WHERE table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
t.business_name, GROUP BY table_schema
t.function_name, </select>
t.function_author,
t.options,
t.remark,
c.column_id,
c.column_name,
c.column_comment,
c.column_type,
c.java_type,
c.java_field,
c.is_pk,
c.is_increment,
c.is_required,
c.is_insert,
c.is_edit,
c.is_list,
c.is_query,
c.query_type,
c.html_type,
c.dict_type,
c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
order by c.sort
</select>
<insert id="insertGenTable" parameterType="com.muyu.gen.domain.GenTable" useGeneratedKeys="true" keyProperty="tableId"> <insert id="insertGenTable" parameterType="com.muyu.gen.domain.GenTable" useGeneratedKeys="true" keyProperty="tableId">
insert into gen_table ( insert into gen_table (
<if test="tableName != null">table_name,</if> <if test="dbName != null">db_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if> <if test="tableName != null">table_name,</if>
<if test="className != null and className != ''">class_name,</if> <if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if> <if test="className != null and className != ''">class_name,</if>
<if test="packageName != null and packageName != ''">package_name,</if> <if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if> <if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
<if test="businessName != null and businessName != ''">business_name,</if> <if test="packageName != null and packageName != ''">package_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if> <if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if> <if test="businessName != null and businessName != ''">business_name,</if>
<if test="genType != null and genType != ''">gen_type,</if> <if test="functionName != null and functionName != ''">function_name,</if>
<if test="genPath != null and genPath != ''">gen_path,</if> <if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
<if test="remark != null and remark != ''">remark,</if> <if test="genType != null and genType != ''">gen_type,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="genPath != null and genPath != ''">gen_path,</if>
create_time <if test="remark != null and remark != ''">remark,</if>
)values( <if test="createBy != null and createBy != ''">create_by,</if>
<if test="tableName != null">#{tableName},</if> create_time
<if test="tableComment != null and tableComment != ''">#{tableComment},</if> )values(
<if test="className != null and className != ''">#{className},</if> <if test="dbName != null">#{dbName},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> <if test="tableName != null">#{tableName},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if> <if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if> <if test="className != null and className != ''">#{className},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if> <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if> <if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> <if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="genType != null and genType != ''">#{genType},</if> <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if> <if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="remark != null and remark != ''">#{remark},</if> <if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
sysdate() <if test="genType != null and genType != ''">#{genType},</if>
) <if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert> </insert>
<update id="updateGenTable" parameterType="com.muyu.gen.domain.GenTable"> <update id="updateGenTable" parameterType="com.muyu.gen.domain.GenTable">
update gen_table update gen_table
<set> <set>
<if test="dbName != null">db_name = #{dbName},</if>
<if test="tableName != null">table_name = #{tableName},</if> <if test="tableName != null">table_name = #{tableName},</if>
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="subTableName != null">sub_table_name = #{subTableName},</if> <if test="subTableName != null">sub_table_name = #{subTableName},</if>
@ -295,6 +204,7 @@
<if test="genType != null and genType != ''">gen_type = #{genType},</if> <if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if> <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if> <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if> <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>

View File

@ -9,7 +9,7 @@ import ${packageName}.domain.${ClassName};
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
public interface I${ClassName}Service public interface ${ClassName}Service
{ {
/** /**
* 查询${functionName} * 查询${functionName}

View File

@ -26,7 +26,7 @@ import ${packageName}.service.I${ClassName}Service;
* @date ${datetime} * @date ${datetime}
*/ */
@Service @Service
public class ${ClassName}ServiceImpl implements I${ClassName}Service public class ${ClassName}ServiceImpl implements ${ClassName}Service
{ {
@Autowired @Autowired
private ${ClassName}Mapper ${className}Mapper; private ${ClassName}Mapper ${className}Mapper;

View File

@ -1,44 +0,0 @@
import request from '@/utils/request'
// 查询${functionName}列表
export function list${BusinessName}(query) {
return request({
url: '/${moduleName}/${businessName}/list',
method: 'get',
params: query
})
}
// 查询${functionName}详细
export function get${BusinessName}(${pkColumn.javaField}) {
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'get'
})
}
// 新增${functionName}
export function add${BusinessName}(data) {
return request({
url: '/${moduleName}/${businessName}',
method: 'post',
data: data
})
}
// 修改${functionName}
export function update${BusinessName}(data) {
return request({
url: '/${moduleName}/${businessName}',
method: 'put',
data: data
})
}
// 删除${functionName}
export function del${BusinessName}(${pkColumn.javaField}) {
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'delete'
})
}

View File

@ -1,22 +0,0 @@
-- 菜单 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
-- 按钮父菜单ID
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, '');
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, '');
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, '');
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, '');
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, '');