This commit is contained in:
20932067@zju.edu.cn 2021-04-10 22:03:41 +08:00
parent 35063a87df
commit ff4156d965
5 changed files with 26 additions and 30 deletions

View File

@ -38,7 +38,6 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
os.write(b, 0, length); os.write(b, 0, length);
} }
} catch (IOException e) { } catch (IOException e) {
System.out.println(e);
throw e; throw e;
} finally { } finally {
if (os != null) { if (os != null) {

View File

@ -21,13 +21,6 @@ public class Config {
private static String profile; private static String profile;
public void setProfile(String profile){
Config.profile = profile;
}
public static String getProfile() { public static String getProfile() {
return profile; return profile;
} }

View File

@ -72,9 +72,9 @@ public class GenController extends GenBaseController {
List<GenTable> tables = genTableService.selectGenTableAll(); List<GenTable> tables = genTableService.selectGenTableAll();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("info" , table); map.put("info", table);
map.put("rows" , list); map.put("rows", list);
map.put("tables" , tables); map.put("tables", tables);
return AjaxResult.success(map); return AjaxResult.success(map);
} }
@ -106,7 +106,7 @@ public class GenController extends GenBaseController {
* 导入表结构保存 * 导入表结构保存
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:list')") @PreAuthorize("@hchyun.hasPermi('tool:gen:list')")
@Log(title = "代码生成" , businessType = GenBusinessType.IMPORT) @Log(title = "代码生成", businessType = GenBusinessType.IMPORT)
@PostMapping("/importTable") @PostMapping("/importTable")
public AjaxResult importTableSave(String tables) { public AjaxResult importTableSave(String tables) {
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
@ -121,7 +121,7 @@ public class GenController extends GenBaseController {
* 修改保存代码生成业务 * 修改保存代码生成业务
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:edit')") @PreAuthorize("@hchyun.hasPermi('tool:gen:edit')")
@Log(title = "代码生成" , businessType = GenBusinessType.UPDATE) @Log(title = "代码生成", businessType = GenBusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult editSave(@Validated @RequestBody GenTable genTable) { public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
genTableService.validateEdit(genTable); genTableService.validateEdit(genTable);
@ -133,7 +133,7 @@ public class GenController extends GenBaseController {
* 删除代码生成 * 删除代码生成
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:remove')") @PreAuthorize("@hchyun.hasPermi('tool:gen:remove')")
@Log(title = "代码生成" , businessType = GenBusinessType.DELETE) @Log(title = "代码生成", businessType = GenBusinessType.DELETE)
@DeleteMapping("/{tableIds}") @DeleteMapping("/{tableIds}")
public AjaxResult remove(@PathVariable Long[] tableIds) { public AjaxResult remove(@PathVariable Long[] tableIds) {
try { try {
@ -163,20 +163,18 @@ public class GenController extends GenBaseController {
* 生成代码下载方式 * 生成代码下载方式
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:code')") @PreAuthorize("@hchyun.hasPermi('tool:gen:code')")
@Log(title = "代码生成" , businessType = GenBusinessType.GENCODE) @Log(title = "代码生成", businessType = GenBusinessType.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);
} }
/** /**
* 生成代码自定义路径 * 生成代码自定义路径
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:code')") @PreAuthorize("@hchyun.hasPermi('tool:gen:code')")
@Log(title = "代码生成" , businessType = GenBusinessType.GENCODE) @Log(title = "代码生成", businessType = GenBusinessType.GENCODE)
@GetMapping("/genCode/{tableName}") @GetMapping("/genCode/{tableName}")
public AjaxResult genCode(@PathVariable("tableName") String tableName) { public AjaxResult genCode(@PathVariable("tableName") String tableName) {
boolean start = genTableService.generatorCode(tableName); boolean start = genTableService.generatorCode(tableName);
@ -191,7 +189,7 @@ public class GenController extends GenBaseController {
* 同步数据库 * 同步数据库
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:edit')") @PreAuthorize("@hchyun.hasPermi('tool:gen:edit')")
@Log(title = "代码生成" , businessType = GenBusinessType.UPDATE) @Log(title = "代码生成", businessType = GenBusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}") @GetMapping("/synchDb/{tableName}")
public AjaxResult synchDb(@PathVariable("tableName") String tableName) { public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
genTableService.synchDb(tableName); genTableService.synchDb(tableName);
@ -202,7 +200,7 @@ public class GenController extends GenBaseController {
* 批量生成代码 * 批量生成代码
*/ */
@PreAuthorize("@hchyun.hasPermi('tool:gen:code')") @PreAuthorize("@hchyun.hasPermi('tool:gen:code')")
@Log(title = "代码生成" , businessType = GenBusinessType.GENCODE) @Log(title = "代码生成", businessType = GenBusinessType.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);
@ -217,11 +215,12 @@ public class GenController extends GenBaseController {
/** /**
* 将bytes流写入到本地 * 将bytes流写入到本地
*
* @param bytes * @param bytes
*/ */
public boolean compress(byte[] bytes) { public boolean compress(byte[] bytes) {
try { try {
String dir = Config.getProfile()+"/hchyun.zip"; String dir = Config.getProfile() + "/hchyun.zip";
FileOutputStream fileOutputStream = new FileOutputStream(dir); FileOutputStream fileOutputStream = new FileOutputStream(dir);
fileOutputStream.write(bytes); fileOutputStream.write(bytes);
fileOutputStream.flush(); fileOutputStream.flush();
@ -268,10 +267,10 @@ public class GenController extends GenBaseController {
*/ */
private void genCode(HttpServletResponse response, byte[] data) throws IOException { private void genCode(HttpServletResponse response, byte[] data) throws IOException {
response.reset(); response.reset();
response.addHeader("Access-Control-Allow-Origin" , "*"); response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers" , "Content-Disposition"); response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition" , "attachment; filename=\"hchyun.zip\""); response.setHeader("Content-Disposition", "attachment; filename=\"hchyun.zip\"");
response.addHeader("Content-Length" , "" + 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());
} }

View File

@ -559,6 +559,8 @@ public class GenTableServiceImpl implements GenTableService {
} else if (GenStringUtils.isEmpty(genTable.getSubTableFkName())) { } else if (GenStringUtils.isEmpty(genTable.getSubTableFkName())) {
throw new GenCustomException("子表关联的外键名不能为空"); throw new GenCustomException("子表关联的外键名不能为空");
} }
} else if (GenConstants.TPL_ASS.equals(genTable.getTplCategory())) {
// todo 规则校验
} }
} }
} }

View File

@ -101,7 +101,7 @@ public class QueryServiceImpl implements QueryService {
try { try {
int uqrenewal = uniQueryDao.updateUniQuery(uniQuery); int uqrenewal = uniQueryDao.updateUniQuery(uniQuery);
if (uqrenewal > 0) { if (uqrenewal > 0) {
if (uniQuery.getUniCons() != null) { if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) {
queryDao.deleteUniCon(uniQuery.getId()); queryDao.deleteUniCon(uniQuery.getId());
Integer ucrenewal = queryDao.insertUniCon(uniQuery.getUniCons()); Integer ucrenewal = queryDao.insertUniCon(uniQuery.getUniCons());
if (ucrenewal == 0) { if (ucrenewal == 0) {
@ -123,16 +123,19 @@ public class QueryServiceImpl implements QueryService {
try { try {
StringBuilder sql = new StringBuilder(uniQuery.getUqSql().toLowerCase()); StringBuilder sql = new StringBuilder(uniQuery.getUqSql().toLowerCase());
List<UniCon> uniConList = uniQuery.getUniCons(); List<UniCon> uniConList = uniQuery.getUniCons();
if (sql.toString().contains("insert") || sql.toString().contains("delete ") || sql.toString().contains("update ") || sql.toString().contains("drop ") || sql.toString().contains("database ") || sql.toString().contains("create ") || sql.toString().contains("view ") || sql.toString().contains("alter ")) { if (sql.toString().contains("insert") || sql.toString().contains("delete ") || sql.toString().contains("update ") ||
return new GenServerResult<>(false, "sql语句含有insert,delete,update,drop,database,view,alter等特殊字符!"); sql.toString().contains("drop ") || sql.toString().contains("database ") || sql.toString().contains("create ") ||
sql.toString().contains("view ") || sql.toString().contains("alter ")|| sql.toString().contains("gen_")) {
return new GenServerResult<>(false, "sql语句含有insert,delete,update,drop,database,view,alter,gen_等特殊字符!");
} }
if (uniConList.size() > 0) { if (uniConList.size() > 0) {
sql.append(" where 1 = 1"); sql.append(" where 1 = 1");
for (UniCon uniCon : uniConList) { for (UniCon uniCon : uniConList) {
if(!uniCon.getUcMock().equals("")){
sql.append(conversionPreview(uniCon)); sql.append(conversionPreview(uniCon));
} }
} }
}
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString()); List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
return new GenServerResult<>(true, dataMap); return new GenServerResult<>(true, dataMap);
} catch (RuntimeException e) { } catch (RuntimeException e) {