重构返回结果集
This commit is contained in:
parent
711b258f12
commit
4a388770b0
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ebts.common.utils;
|
package com.ebts.common.utils;
|
||||||
|
|
||||||
import com.ebts.common.config.EBTSConfig;
|
import com.ebts.common.config.EBTSConfig;
|
||||||
|
import com.ebts.common.core.entity.Result;
|
||||||
import com.ebts.common.core.entity.ResultBackI;
|
import com.ebts.common.core.entity.ResultBackI;
|
||||||
import com.ebts.common.exception.CustomException;
|
import com.ebts.common.exception.CustomException;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
|
@ -68,6 +69,17 @@ public class MapExcelUtil {
|
||||||
this.init(list, sheetName);
|
this.init(list, sheetName);
|
||||||
return exportExcel();
|
return exportExcel();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*
|
||||||
|
* @param list 导出数据集合
|
||||||
|
* @param sheetName 工作表的名称
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public Result exportExcelResult(List<Map<String, Object>> list, String sheetName) {
|
||||||
|
this.init(list, sheetName);
|
||||||
|
return exportExcelResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void init(List<Map<String, Object>> list, String sheetName) {
|
public void init(List<Map<String, Object>> list, String sheetName) {
|
||||||
|
|
@ -292,4 +304,53 @@ public class MapExcelUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public Result exportExcelResult() {
|
||||||
|
OutputStream out = null;
|
||||||
|
try {
|
||||||
|
// 取出一共有多少个sheet.
|
||||||
|
double sheetNo = Math.ceil(list.size() / sheetSize);
|
||||||
|
for (int index = 0; index <= sheetNo; index++) {
|
||||||
|
createSheet(sheetNo, index);
|
||||||
|
|
||||||
|
// 产生一行
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
int column = 0;
|
||||||
|
// 写入各个字段的列头名称
|
||||||
|
for (String herder : herders) {
|
||||||
|
//设置列名称
|
||||||
|
this.createCell(row, herder, column++);
|
||||||
|
}
|
||||||
|
fillExcelData(index, row);
|
||||||
|
}
|
||||||
|
String filename = encodingFilename(sheetName);
|
||||||
|
out = new FileOutputStream(getAbsoluteFile(filename));
|
||||||
|
wb.write(out);
|
||||||
|
return Result.ok(filename);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("导出Excel异常{}", e.getMessage());
|
||||||
|
throw new CustomException("导出Excel失败,请联系网站管理员!");
|
||||||
|
} finally {
|
||||||
|
if (wb != null) {
|
||||||
|
try {
|
||||||
|
wb.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package com.ebts.generator.controller;
|
package com.ebts.generator.controller;
|
||||||
|
|
||||||
import com.ebts.common.core.controller.BaseController;
|
import com.ebts.common.core.controller.BaseController;
|
||||||
import com.ebts.common.core.entity.ResultBackI;
|
import com.ebts.common.core.entity.Result;
|
||||||
import com.ebts.common.utils.MapExcelUtil;
|
import com.ebts.common.utils.MapExcelUtil;
|
||||||
import com.ebts.common.utils.ServerResult;
|
|
||||||
import com.ebts.common.utils.StringUtils;
|
import com.ebts.common.utils.StringUtils;
|
||||||
import com.ebts.generator.utils.sql.GenSqlUtil;
|
import com.ebts.generator.utils.sql.GenSqlUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
|
@ -31,8 +30,6 @@ import java.util.Map;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/query")
|
@RequestMapping("/query")
|
||||||
public class QueryController extends BaseController {
|
public class QueryController extends BaseController {
|
||||||
private Logger logger = LoggerFactory.getLogger(QueryController.class);
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QueryService queryService;
|
private QueryService queryService;
|
||||||
|
|
@ -45,18 +42,18 @@ public class QueryController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ebts.hasPermi('query:list')")
|
@PreAuthorize("@ebts.hasPermi('query:list')")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ResultBackI Info(@PathVariable("id") Long id) {
|
public Result<Map<String, Object>> Info(@PathVariable("id") Long id) {
|
||||||
ServerResult<UniQuery> ServerResult = queryService.selectQueryById(id);
|
Result<UniQuery> result = queryService.selectQueryById(id);
|
||||||
if (ServerResult.isStart()) {
|
if (result.isSuccess()) {
|
||||||
UniQuery uniQuery = ServerResult.getData();
|
UniQuery uniQuery = result.getData();
|
||||||
Map<String, Object> modeMap = new HashMap<>();
|
Map<String, Object> modeMap = new HashMap<>();
|
||||||
List<UniCon> uniCons = uniQuery.getUniCons();
|
List<UniCon> uniCons = uniQuery.getUniCons();
|
||||||
uniQuery.setUniCons(null);
|
uniQuery.setUniCons(null);
|
||||||
modeMap.put("info", uniQuery);
|
modeMap.put("info", uniQuery);
|
||||||
modeMap.put("list", uniCons);
|
modeMap.put("list", uniCons);
|
||||||
return ResultBackI.success(modeMap);
|
return Result.ok(modeMap);
|
||||||
} else {
|
} else {
|
||||||
return ResultBackI.error(ServerResult.getMsg());
|
return Result.error(result.getMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,13 +65,8 @@ public class QueryController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ebts.hasPermi('query:edit')")
|
@PreAuthorize("@ebts.hasPermi('query:edit')")
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public ResultBackI edit(@Validated @RequestBody UniQuery uniQuery) {
|
public Result<Integer> edit(@Validated @RequestBody UniQuery uniQuery) {
|
||||||
ServerResult ServerResult = queryService.updateQueryInfo(uniQuery);
|
return queryService.updateQueryInfo(uniQuery);
|
||||||
if (ServerResult.isStart()) {
|
|
||||||
return ResultBackI.success();
|
|
||||||
} else {
|
|
||||||
return ResultBackI.error(ServerResult.getMsg());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -85,12 +77,12 @@ public class QueryController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ebts.hasAnyPermi('query:export')")
|
@PreAuthorize("@ebts.hasAnyPermi('query:export')")
|
||||||
@PutMapping("export")
|
@PutMapping("export")
|
||||||
public ResultBackI export(@Validated @RequestBody UniQuery uniQuery) {
|
public Serializable export(@Validated @RequestBody UniQuery uniQuery) {
|
||||||
ServerResult<List<Map<String, Object>>> ServerResult = queryService.previewQuery(uniQuery);
|
Result<List<Map<String, Object>>> result = queryService.previewQuery(uniQuery);
|
||||||
if (ServerResult.isStart()) {
|
if (result.isSuccess()) {
|
||||||
return new MapExcelUtil().exportExcel(ServerResult.getData(), uniQuery.getUqName());
|
return new MapExcelUtil().exportExcelResult(result.getData(), uniQuery.getUqName());
|
||||||
} else {
|
} else {
|
||||||
return ResultBackI.error(ServerResult.getMsg());
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,11 +96,11 @@ public class QueryController extends BaseController {
|
||||||
@PutMapping("preview")
|
@PutMapping("preview")
|
||||||
public Serializable Preview(@Validated @RequestBody UniQuery uniQuery) {
|
public Serializable Preview(@Validated @RequestBody UniQuery uniQuery) {
|
||||||
startPage(uniQuery);
|
startPage(uniQuery);
|
||||||
ServerResult<List<Map<String, Object>>> ServerResult = queryService.previewQuery(uniQuery);
|
Result<List<Map<String, Object>>> result = queryService.previewQuery(uniQuery);
|
||||||
if (ServerResult.isStart()) {
|
if (result.isSuccess()) {
|
||||||
return getDataTable(ServerResult.getData());
|
return getDataTable(result.getData());
|
||||||
} else {
|
} else {
|
||||||
return ResultBackI.error(ServerResult.getMsg());
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,20 +112,14 @@ public class QueryController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ebts.hasPermi('query:release')")
|
@PreAuthorize("@ebts.hasPermi('query:release')")
|
||||||
@PutMapping("/release")
|
@PutMapping("/release")
|
||||||
public ResultBackI Release(@RequestBody UniQuery uniQuery) {
|
public Result<Integer> Release(@RequestBody UniQuery uniQuery) {
|
||||||
if (uniQuery.getId() == null) {
|
if (uniQuery.getId() == null) {
|
||||||
return ResultBackI.error("id不能为空!");
|
return Result.error("id不能为空!");
|
||||||
|
}
|
||||||
|
if (uniQuery.getIsRelease() == 1 || uniQuery.getIsRelease() == 2) {
|
||||||
|
return queryService.Release(uniQuery);
|
||||||
} else {
|
} else {
|
||||||
if (uniQuery.getIsRelease() == 1 || uniQuery.getIsRelease() == 2) {
|
return Result.error("状态输入错误!");
|
||||||
ServerResult<Integer> ServerResult = queryService.Release(uniQuery);
|
|
||||||
if (ServerResult.isStart()) {
|
|
||||||
return ResultBackI.success();
|
|
||||||
} else {
|
|
||||||
return ResultBackI.error(ServerResult.getMsg());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ResultBackI.error("状态输入错误!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.ebts.generator.service;
|
package com.ebts.generator.service;
|
||||||
|
|
||||||
import com.ebts.common.utils.ServerResult;
|
import com.ebts.common.core.entity.Result;
|
||||||
import com.ebts.generator.entity.UniQuery;
|
import com.ebts.generator.entity.UniQuery;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -18,7 +18,7 @@ public interface QueryService {
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<UniQuery> selectQueryById(Long id);
|
Result<UniQuery> selectQueryById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改基础信息
|
* 修改基础信息
|
||||||
|
|
@ -26,7 +26,7 @@ public interface QueryService {
|
||||||
* @param uniQuery
|
* @param uniQuery
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<Integer> updateQueryInfo(UniQuery uniQuery);
|
Result<Integer> updateQueryInfo(UniQuery uniQuery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览万能查询数据
|
* 预览万能查询数据
|
||||||
|
|
@ -34,11 +34,13 @@ public interface QueryService {
|
||||||
* @param uniQuery
|
* @param uniQuery
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<List<Map<String, Object>>> previewQuery(UniQuery uniQuery);
|
Result<List<Map<String, Object>>> previewQuery(UniQuery uniQuery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 发布
|
||||||
|
*
|
||||||
* @param uniQuery
|
* @param uniQuery
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<Integer> Release(UniQuery uniQuery);
|
Result<Integer> Release(UniQuery uniQuery);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@ package com.ebts.generator.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ebts.common.constant.ReturnConstants;
|
import com.ebts.common.constant.ReturnConstants;
|
||||||
|
import com.ebts.common.core.entity.Result;
|
||||||
import com.ebts.common.core.entity.entity.Menu;
|
import com.ebts.common.core.entity.entity.Menu;
|
||||||
import com.ebts.common.exception.EbtsException;
|
|
||||||
import com.ebts.common.utils.SecurityUtils;
|
import com.ebts.common.utils.SecurityUtils;
|
||||||
import com.ebts.common.utils.ServerResult;
|
|
||||||
import com.ebts.generator.dao.QueryDao;
|
import com.ebts.generator.dao.QueryDao;
|
||||||
import com.ebts.generator.dao.UniQueryDao;
|
import com.ebts.generator.dao.UniQueryDao;
|
||||||
import com.ebts.generator.entity.UniCon;
|
import com.ebts.generator.entity.UniCon;
|
||||||
|
|
@ -13,11 +12,12 @@ import com.ebts.generator.entity.UniQuery;
|
||||||
import com.ebts.generator.service.QueryService;
|
import com.ebts.generator.service.QueryService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -30,10 +30,10 @@ import java.util.Map;
|
||||||
public class QueryServiceImpl implements QueryService {
|
public class QueryServiceImpl implements QueryService {
|
||||||
private final Logger logger = LoggerFactory.getLogger(QueryServiceImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(QueryServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private QueryDao queryDao;
|
private QueryDao queryDao;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private UniQueryDao uniQueryDao;
|
private UniQueryDao uniQueryDao;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -41,54 +41,45 @@ public class QueryServiceImpl implements QueryService {
|
||||||
* 查询万能查询的基本信息和条件信息
|
* 查询万能查询的基本信息和条件信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<UniQuery> selectQueryById(Long id) {
|
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
|
||||||
try {
|
public Result<UniQuery> selectQueryById(Long id) {
|
||||||
UniQuery uniQuery = queryDao.selectQueryInfo(id);
|
UniQuery uniQuery = queryDao.selectQueryInfo(id);
|
||||||
if (uniQuery != null) {
|
if (uniQuery != null) {
|
||||||
return new ServerResult<>(true, uniQuery);
|
return Result.ok(uniQuery);
|
||||||
} else {
|
} else {
|
||||||
return new ServerResult<>(false, ReturnConstants.RESULT_EMPTY);
|
return Result.info(ReturnConstants.RESULT_EMPTY);
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new EbtsException(ReturnConstants.OP_ERROR,e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
|
||||||
public ServerResult<Integer> Release(UniQuery uniQuery) {
|
public Result<Integer> Release(UniQuery uniQuery) {
|
||||||
try {
|
Integer isRelease = queryDao.Release(uniQuery.getId());
|
||||||
Integer isRelease = queryDao.Release(uniQuery.getId());
|
if ((isRelease == 1 && uniQuery.getIsRelease() == 2) || (isRelease == 2 && uniQuery.getIsRelease() == 1)) {
|
||||||
if ((isRelease == 1 && uniQuery.getIsRelease() == 2) || (isRelease == 2 && uniQuery.getIsRelease() == 1)) {
|
if (uniQuery.getIsRelease() == 1) {
|
||||||
if (uniQuery.getIsRelease() == 1) {
|
UniQuery query = uniQueryDao.selectUniQueryById(uniQuery.getId());
|
||||||
UniQuery query = uniQueryDao.selectUniQueryById(uniQuery.getId());
|
Menu Menu = new Menu(query.getId(), query.getUqName(), SecurityUtils.getUserId());
|
||||||
Menu Menu = new Menu(query.getId(), query.getUqName(), SecurityUtils.getUserId());
|
Integer insermenu = queryDao.insertMenu(Menu);
|
||||||
Integer insermenu = queryDao.insertMenu(Menu);
|
if (insermenu == 0) {
|
||||||
if (insermenu == 0) {
|
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
||||||
return new ServerResult<>(false, ReturnConstants.OP_ERROR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Integer deleteMenu = queryDao.deleteMenu("data/" + uniQuery.getId());
|
|
||||||
if (deleteMenu == 0) {
|
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
||||||
return new ServerResult<>(false, ReturnConstants.OP_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Integer release = queryDao.changeRelease(uniQuery);
|
|
||||||
if (release > 0) {
|
|
||||||
return new ServerResult<>(true);
|
|
||||||
} else {
|
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
return new ServerResult<>(false, ReturnConstants.OP_ERROR);
|
return Result.error(ReturnConstants.OP_ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new ServerResult<>(false, ReturnConstants.STATE_ERROR);
|
Integer deleteMenu = queryDao.deleteMenu("data/" + uniQuery.getId());
|
||||||
|
if (deleteMenu == 0) {
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
return Result.error(ReturnConstants.OP_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
Integer release = queryDao.changeRelease(uniQuery);
|
||||||
logger.error(e.getMessage());
|
if (release > 0) {
|
||||||
throw new EbtsException(ReturnConstants.OP_ERROR,e);
|
return Result.ok();
|
||||||
|
} else {
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
return Result.error(ReturnConstants.OP_ERROR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Result.error(ReturnConstants.STATE_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,51 +87,41 @@ public class QueryServiceImpl implements QueryService {
|
||||||
* 更新万能查询基本信息和条件
|
* 更新万能查询基本信息和条件
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
||||||
public ServerResult<Integer> updateQueryInfo(UniQuery uniQuery) {
|
public Result<Integer> updateQueryInfo(UniQuery uniQuery) {
|
||||||
try {
|
int uqrenewal = uniQueryDao.updateUniQuery(uniQuery);
|
||||||
int uqrenewal = uniQueryDao.updateUniQuery(uniQuery);
|
if (uqrenewal > 0) {
|
||||||
if (uqrenewal > 0) {
|
if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) {
|
||||||
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) {
|
return Result.error(ReturnConstants.OP_ERROR);
|
||||||
return new ServerResult<>(false, ReturnConstants.OP_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new ServerResult<>(true);
|
|
||||||
}
|
}
|
||||||
return new ServerResult<>(false, ReturnConstants.OP_ERROR);
|
return Result.ok();
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new EbtsException(ReturnConstants.OP_ERROR,e);
|
|
||||||
}
|
}
|
||||||
|
return Result.error(ReturnConstants.OP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<List<Map<String, Object>>> previewQuery(UniQuery uniQuery) {
|
public Result<List<Map<String, Object>>> previewQuery(UniQuery uniQuery) {
|
||||||
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 ") ||
|
||||||
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("drop ") || sql.toString().contains("database ") || sql.toString().contains("create ") ||
|
sql.toString().contains("view ") || sql.toString().contains("alter ") || sql.toString().contains("gen_")) {
|
||||||
sql.toString().contains("view ") || sql.toString().contains("alter ") || sql.toString().contains("gen_")) {
|
return Result.error("sql语句含有insert,delete,update,drop,database,view,alter,gen_等特殊字符!");
|
||||||
return new ServerResult<>(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("") && uniCon.getUcMock() != null) {
|
||||||
if (!uniCon.getUcMock().equals("") && uniCon.getUcMock() != null) {
|
sql.append(conversionPreview(uniCon));
|
||||||
sql.append(conversionPreview(uniCon));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
|
|
||||||
return new ServerResult<>(true, dataMap);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
return new ServerResult<>(false, e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
|
||||||
|
return Result.ok(dataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ public class UniQueryServiceImpl implements UniQueryService {
|
||||||
@Override
|
@Override
|
||||||
public Result<UniQuery> selectUniQueryById(Long id) {
|
public Result<UniQuery> selectUniQueryById(Long id) {
|
||||||
UniQuery uniQuery = uniQueryDao.selectUniQueryById(id);
|
UniQuery uniQuery = uniQueryDao.selectUniQueryById(id);
|
||||||
System.out.println(1/0);
|
|
||||||
if (uniQuery != null) {
|
if (uniQuery != null) {
|
||||||
return Result.ok(uniQuery);
|
return Result.ok(uniQuery);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue