重构返回结果集

This commit is contained in:
Binlin B Wang 2022-07-18 11:42:24 +08:00
parent 97a965a71e
commit 711b258f12
17 changed files with 380 additions and 471 deletions

View File

@ -3,13 +3,15 @@ package com.ebts.common.core.entity;
import com.ebts.common.constant.HttpStatus; import com.ebts.common.constant.HttpStatus;
import java.io.Serializable;
/** /**
* @description: some desc * @description: some desc
* @author: Binlin B Wang * @author: Binlin B Wang
* @email: binlin.b.wang@cn.pwc.com * @email: binlin.b.wang@cn.pwc.com
* @date: 2022/5/31 10:00 * @date: 2022/5/31 10:00
*/ */
public class Result<T> { public class Result<T> implements Serializable {
private int code; private int code;
private boolean success; private boolean success;
private String msg; private String msg;

View File

@ -8,7 +8,7 @@ import java.util.List;
* *
* @author binlin * @author binlin
*/ */
public class TableDataInfo implements Serializable { public class TableDataInfo<T> implements Serializable {
/** /**
@ -19,7 +19,7 @@ public class TableDataInfo implements Serializable {
/** /**
* 列表数据 * 列表数据
*/ */
private List<?> rows; private List<T> rows;
/** /**
* 消息状态码 * 消息状态码
@ -43,7 +43,7 @@ public class TableDataInfo implements Serializable {
* @param list 列表数据 * @param list 列表数据
* @param total 总记录数 * @param total 总记录数
*/ */
public TableDataInfo(List<?> list, int total) { public TableDataInfo(List<T> list, int total) {
this.rows = list; this.rows = list;
this.total = total; this.total = total;
} }
@ -60,7 +60,7 @@ public class TableDataInfo implements Serializable {
return rows; return rows;
} }
public void setRows(List<?> rows) { public void setRows(List<T> rows) {
this.rows = rows; this.rows = rows;
} }

View File

@ -19,6 +19,7 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.ebts.common.core.entity.Result;
import com.ebts.common.core.entity.ResultBackI; import com.ebts.common.core.entity.ResultBackI;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.BorderStyle;
@ -267,6 +268,18 @@ public class ExcelUtil<T> {
return exportExcel(); return exportExcel();
} }
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param list 导出数据集合
* @param sheetName 工作表的名称
* @return 结果
*/
public Result<T> exportExcelRest(List<T> list, String sheetName) {
this.init(list, sheetName, Type.EXPORT);
return exportExcelRest();
}
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *
@ -329,6 +342,58 @@ public class ExcelUtil<T> {
} }
} }
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @return 结果
*/
public Result<T> exportExcelRest() {
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 (Object[] os : fields) {
Excel excel = (Excel) os[1];
this.createCell(excel, row, column++);
}
if (Type.EXPORT.equals(type)) {
fillExcelData(index, row);
addStatisticsRow();
}
}
String filename = encodingFilename(sheetName);
out = new FileOutputStream(getAbsoluteFile(filename));
wb.write(out);
return Result.ok(filename);
} catch (Exception e) {
log.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();
}
}
}
}
/** /**
* 填充excel数据 * 填充excel数据
* *

View File

@ -1,6 +1,8 @@
package com.ebts.framework.web.exception; package com.ebts.framework.web.exception;
import com.ebts.common.constant.HttpStatus; import com.ebts.common.constant.HttpStatus;
import com.ebts.common.constant.ReturnConstants;
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.BaseException; import com.ebts.common.exception.BaseException;
import com.ebts.common.exception.CustomException; import com.ebts.common.exception.CustomException;
@ -12,6 +14,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AccountExpiredException; import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
@ -80,13 +83,6 @@ public class GlobalExceptionHandler {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return ResultBackI.error(e.getMessage()); return ResultBackI.error(e.getMessage());
} }
@ExceptionHandler(Exception.class)
public ResultBackI handleException(Exception e) {
log.error(e.getMessage(), e);
return ResultBackI.error(e.getMessage());
}
/** /**
* 自定义验证异常 * 自定义验证异常
*/ */
@ -114,4 +110,11 @@ public class GlobalExceptionHandler {
public ResultBackI demoModeException(DemoModeException e) { public ResultBackI demoModeException(DemoModeException e) {
return ResultBackI.error("演示模式,不允许操作"); return ResultBackI.error("演示模式,不允许操作");
} }
@ExceptionHandler(Exception.class)
public Result<String> handleException(Exception e) {
log.error(e.getMessage(), e);
return Result.error(ReturnConstants.SYS_ERROR);
}
} }

View File

@ -2,6 +2,7 @@ package com.ebts.generator.controller;
import com.ebts.common.annotation.Log; import com.ebts.common.annotation.Log;
import com.ebts.common.core.controller.BaseController; import com.ebts.common.core.controller.BaseController;
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.enums.BusinessType; import com.ebts.common.enums.BusinessType;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
@ -42,17 +43,12 @@ public class TopQueryController extends BaseController {
*/ */
@PreAuthorize("@ebts.hasPermi('top:query')") @PreAuthorize("@ebts.hasPermi('top:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public ResultBackI getInfo(@PathVariable("id") Long id) { public Result<UniQuery> getInfo(@PathVariable("id") Long id) {
ServerResult<UniQuery> ServerResult = uniQueryService.selectUniQueryById(id); return uniQueryService.selectUniQueryById(id);
if (ServerResult.isStart()) {
return ResultBackI.success(ServerResult.getData());
} else {
return ResultBackI.info(ServerResult.getMsg());
}
} }
@GetMapping("/online/{id}") @GetMapping("/online/{id}")
public ResultBackI online(@PathVariable("id") Long id){ public ResultBackI online(@PathVariable("id") Long id) {
// ServerResult ServerResult = queryService.updateQueryInfo(uniQuery); // ServerResult ServerResult = queryService.updateQueryInfo(uniQuery);
// if (ServerResult.isStart()) { // if (ServerResult.isStart()) {
// return AjaxResult.success(ServerResult.getData()); // return AjaxResult.success(ServerResult.getData());
@ -71,8 +67,8 @@ public class TopQueryController extends BaseController {
*/ */
@PreAuthorize("@ebts.hasPermi('top:table')") @PreAuthorize("@ebts.hasPermi('top:table')")
@GetMapping("/table") @GetMapping("/table")
public ResultBackI table() { public Result<Map<String,Object>> table() {
return ResultBackI.success(topQueryService.selectTopSearchTables()); return Result.ok(topQueryService.selectTopSearchTables());
} }
/** /**
@ -81,35 +77,20 @@ public class TopQueryController extends BaseController {
@PreAuthorize("@ebts.hasPermi('top:edit')") @PreAuthorize("@ebts.hasPermi('top:edit')")
@Log(title = "top万能查询", businessType = BusinessType.UPDATE) @Log(title = "top万能查询", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public ResultBackI edit(@RequestBody UniQuery uniQuery) { public Result<Integer> edit(@RequestBody UniQuery uniQuery) {
if (uniQuery.getId()<0){ return uniQueryService.updateUniQuery(uniQuery);
return ResultBackI.error("缺少关键字段");
}
if (StringUtils.isNull(uniQuery.getTopJson())){
return ResultBackI.error("缺少关键字段");
}
ServerResult<Integer> ServerResult = uniQueryService.updateUniQuery(uniQuery);
if (ServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(ServerResult.getMsg());
}
} }
/** /**
* 简单修改top万能能查询 * 简单修改top万能能查询
*/ */
@PreAuthorize("@ebts.hasPermi('top:preview')") @PreAuthorize("@ebts.hasPermi('top:preview')")
@Log(title = "top预览", businessType = BusinessType.OTHER) @Log(title = "top预览", businessType = BusinessType.OTHER)
@PostMapping("/preview") @PostMapping("/preview")
public Serializable preview(@RequestBody Map<String,String> params){ public Serializable preview(@RequestBody Map<String, String> params) {
if (StringUtils.isNull(params.get("jsonData"))){ if (StringUtils.isNull(params.get("jsonData"))) {
return ResultBackI.error("缺少必要参数!"); return ResultBackI.error("缺少必要参数!");
} }
ServerResult<TopResult> serverResult = topQueryService.preview(params.get("jsonData"),params.get("id")); return topQueryService.preview(params.get("jsonData"), params.get("id"));
if (serverResult.isStart()){
return getDataTable(serverResult.getData().getDataMap(),serverResult.getData().getUniCons());
}else {
return ResultBackI.error(serverResult.getMsg());
}
} }
} }

View File

@ -6,6 +6,7 @@ import java.util.Map;
import com.ebts.common.core.controller.EBTSController; import com.ebts.common.core.controller.EBTSController;
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.core.text.Convert; import com.ebts.common.core.text.Convert;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
@ -23,7 +24,7 @@ import com.ebts.common.utils.poi.ExcelUtil;
/** /**
* top万能查询主Controller * top万能查询主Controller
* *
* @author clay * @author clay
* @date 2021-07-20 * @date 2021-07-20
*/ */
@ -42,18 +43,22 @@ public class TopSearchTableController extends EBTSController {
@PreAuthorize("@ebts.hasPermi('tool:table:list')") @PreAuthorize("@ebts.hasPermi('tool:table:list')")
@PostMapping("/list") @PostMapping("/list")
public Serializable list(@Validated @RequestBody TopSearchTable topSearchTable) { public Serializable list(@Validated @RequestBody TopSearchTable topSearchTable) {
// if (topSearchTable.getRoleIds()==null){
// return Result.error("角色列表不能为空!");
// }
startPage(topSearchTable.getPageInfo()); startPage(topSearchTable.getPageInfo());
ServerResult<List<TopSearchTable>> genServerResult = topSearchTableService.selectTopSearchTableList(topSearchTable); Result<List<TopSearchTable>> result = topSearchTableService.selectTopSearchTableList(topSearchTable);
if (genServerResult.isStart()) { if (result.isSuccess()) {
return getDataTable(genServerResult.getData()); return getDataTable(result.getData());
} else { } else {
return ResultBackI.info(genServerResult.getMsg()); return result;
} }
} }
@PreAuthorize("@ebts.hasPermi('tool:table:cloumns')") @PreAuthorize("@ebts.hasPermi('tool:table:cloumns')")
@GetMapping("/columns/{id}") @GetMapping("/columns/{id}")
public ResultBackI columns(@PathVariable("id") Long id){ public Result columns(@PathVariable("id") Long id) {
return ResultBackI.success(topSearchTableService.selectTableColumns(id)); return Result.ok(topSearchTableService.selectTableColumns(id));
} }
@ -63,11 +68,11 @@ public class TopSearchTableController extends EBTSController {
@PreAuthorize("@ebts.hasPermi('tool:table:info')") @PreAuthorize("@ebts.hasPermi('tool:table:info')")
@PostMapping("/info") @PostMapping("/info")
public Serializable info() { public Serializable info() {
ServerResult<List<TopSearchTable>> genServerResult = topSearchTableService.selectTopSearchTableInfo(); Result<List<TopSearchTable>> result = topSearchTableService.selectTopSearchTableInfo();
if (genServerResult.isStart()) { if (result.isSuccess()) {
return getDataTable(genServerResult.getData()); return getDataTable(result.getData());
} else { } else {
return ResultBackI.info(genServerResult.getMsg()); return result;
} }
} }
@ -77,13 +82,13 @@ public class TopSearchTableController extends EBTSController {
@PreAuthorize("@ebts.hasPermi('tool:table:export')") @PreAuthorize("@ebts.hasPermi('tool:table:export')")
@Log(title = "top万能查询主", businessType = BusinessType.EXPORT) @Log(title = "top万能查询主", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public ResultBackI export(@Validated @RequestBody TopSearchTable topSearchTable) { public Result<TopSearchTable> export(@Validated @RequestBody TopSearchTable topSearchTable) {
ServerResult<List<TopSearchTable>> genServerResult = topSearchTableService.selectTopSearchTableList(topSearchTable); Result<List<TopSearchTable>> result = topSearchTableService.selectTopSearchTableList(topSearchTable);
ExcelUtil<TopSearchTable> util = new ExcelUtil<TopSearchTable>(TopSearchTable. class); ExcelUtil<TopSearchTable> util = new ExcelUtil<TopSearchTable>(TopSearchTable.class);
if (genServerResult.isStart()) { if (result.isSuccess()) {
return util.exportExcel(genServerResult.getData(), "table"); return util.exportExcelRest(result.getData(), "table");
} else { } else {
return ResultBackI.error(genServerResult.getMsg()); return Result.error(result.getMsg());
} }
} }
@ -92,13 +97,8 @@ public class TopSearchTableController extends EBTSController {
*/ */
@PreAuthorize("@ebts.hasPermi('tool:table:query')") @PreAuthorize("@ebts.hasPermi('tool:table:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public ResultBackI getInfo(@PathVariable("id") Long id) { public Result<TopSearchTable> getInfo(@PathVariable("id") Long id) {
ServerResult<TopSearchTable> genServerResult = topSearchTableService.selectTopSearchTableById(id); return topSearchTableService.selectTopSearchTableById(id);
if (genServerResult.isStart()) {
return ResultBackI.success(genServerResult.getData());
} else {
return ResultBackI.info(genServerResult.getMsg());
}
} }
/** /**
@ -107,13 +107,8 @@ public class TopSearchTableController extends EBTSController {
@PreAuthorize("@ebts.hasPermi('tool:table:add')") @PreAuthorize("@ebts.hasPermi('tool:table:add')")
@Log(title = "top万能查询主", businessType = BusinessType.INSERT) @Log(title = "top万能查询主", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public ResultBackI add(@Validated @RequestBody TopSearchTable topSearchTable) { public Result<Integer> add(@Validated @RequestBody TopSearchTable topSearchTable) {
ServerResult<Integer> genServerResult = topSearchTableService.insertTopSearchTable(topSearchTable); return topSearchTableService.insertTopSearchTable(topSearchTable);
if (genServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(genServerResult.getMsg());
}
} }
/** /**
@ -122,16 +117,11 @@ public class TopSearchTableController extends EBTSController {
@PreAuthorize("@ebts.hasPermi('tool:table:edit')") @PreAuthorize("@ebts.hasPermi('tool:table:edit')")
@Log(title = "top万能查询主", businessType = BusinessType.UPDATE) @Log(title = "top万能查询主", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public ResultBackI edit(@Validated @RequestBody TopSearchTable topSearchTable) { public Result<Integer> edit(@Validated @RequestBody TopSearchTable topSearchTable) {
if (topSearchTable.getRoleIds().length==0){ if (topSearchTable.getRoleIds().length == 0){
return ResultBackI.error("角色不能为空!"); return Result.error("角色不能为空!");
}
ServerResult<Integer> genServerResult = topSearchTableService.updateTopSearchTable(topSearchTable);
if (genServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(genServerResult.getMsg());
} }
return topSearchTableService.updateTopSearchTable(topSearchTable);
} }
/** /**
@ -139,30 +129,25 @@ public class TopSearchTableController extends EBTSController {
*/ */
@PreAuthorize("@ebts.hasPermi('tool:table:remove')") @PreAuthorize("@ebts.hasPermi('tool:table:remove')")
@Log(title = "top万能查询主", businessType = BusinessType.DELETE) @Log(title = "top万能查询主", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public ResultBackI remove(@PathVariable Long[] ids) { public Result<Integer> remove(@PathVariable Long[] ids) {
if (ids.length<0){ if (ids.length == 0) {
return ResultBackI.error("id不能为空!"); return Result.error("id不能为空!");
}
ServerResult<Integer> genServerResult = topSearchTableService.deleteTopSearchTableByIds(ids);
if (genServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(genServerResult.getMsg());
} }
return topSearchTableService.deleteTopSearchTableByIds(ids);
} }
/** /**
* 导入表结构保存 * 导入表结构保存
*/ */
@PreAuthorize("@ebts.hasPermi('tool:table:import')") @PreAuthorize("@ebts.hasPermi('tool:table:import')")
@Log(title = "代码生成", businessType = BusinessType.IMPORT) @Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTopTable") @PostMapping("/importTopTable")
public ResultBackI importTableSave(String tables) { public Result<String> importTableSave(String tables) {
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
// 查询表信息 // 查询表信息
List<TopSearchTable> tableList = topSearchTableService.selectDbTableListByNames(tableNames); topSearchTableService.importGenTable(tableNames);
topSearchTableService.importGenTable(tableList); return Result.ok();
return ResultBackI.success();
} }
@ -171,12 +156,11 @@ public class TopSearchTableController extends EBTSController {
*/ */
@PreAuthorize("@ebts.hasPermi('tool:table:db:list')") @PreAuthorize("@ebts.hasPermi('tool:table:db:list')")
@PostMapping("/db/list") @PostMapping("/db/list")
public Serializable dbList(@RequestBody Map<String,Object> params){ public Serializable dbList(@RequestBody Map<String, Object> params) {
startPage(params); startPage(params);
List<Map<String,Object>> list = topSearchTableService.selectDbTableList(params); List<Map<String, Object>> list = topSearchTableService.selectDbTableList(params);
return getDataTable(list); return getDataTable(list);
} }
} }

View File

@ -6,6 +6,7 @@ import java.util.List;
import com.ebts.common.annotation.Log; import com.ebts.common.annotation.Log;
import com.ebts.common.core.controller.BaseController; import com.ebts.common.core.controller.BaseController;
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.enums.BusinessType; import com.ebts.common.enums.BusinessType;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
@ -16,6 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
@ -25,6 +27,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** /**
* 万能查询Controller * 万能查询Controller
* *
@ -46,11 +51,11 @@ public class UniQueryController extends BaseController {
@GetMapping("/list") @GetMapping("/list")
public Serializable list(UniQuery uniQuery) { public Serializable list(UniQuery uniQuery) {
startPage(); startPage();
ServerResult<List<UniQuery>> ServerResult = uniQueryService.selectUniQueryList(uniQuery); Result<List<UniQuery>> result = uniQueryService.selectUniQueryList(uniQuery);
if (ServerResult.isStart()) { if (result.isSuccess()) {
return getDataTable(ServerResult.getData()); return getDataTable(result.getData());
} else { } else {
return ResultBackI.info(ServerResult.getMsg()); return result;
} }
} }
@ -60,13 +65,13 @@ public class UniQueryController extends BaseController {
@PreAuthorize("@ebts.hasPermi('tool:query:export')") @PreAuthorize("@ebts.hasPermi('tool:query:export')")
@Log(title = "万能查询", businessType = BusinessType.EXPORT) @Log(title = "万能查询", businessType = BusinessType.EXPORT)
@GetMapping("/export") @GetMapping("/export")
public ResultBackI export(UniQuery uniQuery) { public Result<UniQuery> export(UniQuery uniQuery) {
ServerResult<List<UniQuery>> ServerResult = uniQueryService.selectUniQueryList(uniQuery); Result<List<UniQuery>> result = uniQueryService.selectUniQueryList(uniQuery);
ExcelUtil<UniQuery> util = new ExcelUtil<UniQuery>(UniQuery.class); ExcelUtil<UniQuery> util = new ExcelUtil<UniQuery>(UniQuery.class);
if (ServerResult.isStart()) { if (result.isSuccess()) {
return util.exportExcel(ServerResult.getData(), "query"); return util.exportExcelRest(result.getData(), "query");
} else { } else {
return ResultBackI.error(ServerResult.getMsg()); return Result.error(result.getMsg());
} }
} }
@ -75,13 +80,9 @@ public class UniQueryController extends BaseController {
*/ */
@PreAuthorize("@ebts.hasPermi('tool:query:query')") @PreAuthorize("@ebts.hasPermi('tool:query:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public ResultBackI getInfo(@PathVariable("id") Long id) { public Result<UniQuery> getInfo(@PathVariable("id") Long id) {
ServerResult<UniQuery> ServerResult = uniQueryService.selectUniQueryById(id); Result<UniQuery> result = uniQueryService.selectUniQueryById(id);
if (ServerResult.isStart()) { return result;
return ResultBackI.success(ServerResult.getData());
} else {
return ResultBackI.info(ServerResult.getMsg());
}
} }
/** /**
@ -90,19 +91,8 @@ public class UniQueryController extends BaseController {
@PreAuthorize("@ebts.hasPermi('tool:query:add')") @PreAuthorize("@ebts.hasPermi('tool:query:add')")
@Log(title = "万能查询", businessType = BusinessType.INSERT) @Log(title = "万能查询", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public ResultBackI add(@RequestBody UniQuery uniQuery) { public Result add(@RequestBody @Validated UniQuery uniQuery) {
if (uniQuery.getUqName() == null || uniQuery.getUqName().equals("")) { return uniQueryService.insertUniQuery(uniQuery);
return ResultBackI.error("名称不能为空!");
}
if (uniQuery.getUqDescribe() == null || uniQuery.getUqDescribe().equals("")) {
return ResultBackI.error("描述不能为空!");
}
ServerResult<Integer> ServerResult = uniQueryService.insertUniQuery(uniQuery);
if (ServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(ServerResult.getMsg());
}
} }
/** /**
@ -111,19 +101,8 @@ public class UniQueryController extends BaseController {
@PreAuthorize("@ebts.hasPermi('tool:query:edit')") @PreAuthorize("@ebts.hasPermi('tool:query:edit')")
@Log(title = "万能查询", businessType = BusinessType.UPDATE) @Log(title = "万能查询", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public ResultBackI edit(@RequestBody UniQuery uniQuery) { public Result<Integer> edit(@RequestBody @Validated UniQuery uniQuery) {
if (uniQuery.getUqName() == null || uniQuery.getUqName().equals("")) { return uniQueryService.updateUniQuery(uniQuery);
return ResultBackI.error("名称不能为空!");
}
if (uniQuery.getUqDescribe() == null || uniQuery.getUqDescribe().equals("")) {
return ResultBackI.error("描述不能为空!");
}
ServerResult<Integer> ServerResult = uniQueryService.updateUniQuery(uniQuery);
if (ServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(ServerResult.getMsg());
}
} }
/** /**
@ -132,15 +111,7 @@ public class UniQueryController extends BaseController {
@PreAuthorize("@ebts.hasPermi('tool:query:remove')") @PreAuthorize("@ebts.hasPermi('tool:query:remove')")
@Log(title = "万能查询", businessType = BusinessType.DELETE) @Log(title = "万能查询", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public ResultBackI remove(@PathVariable Long[] ids) { public Result<Integer> remove(@PathVariable @NotNull @NotBlank(message = "id不能为空!") Long[] ids) {
if (ids.length < 0) { return uniQueryService.deleteUniQueryByIds(ids);
return ResultBackI.error("id不能为空!");
}
ServerResult<Integer> ServerResult = uniQueryService.deleteUniQueryByIds(ids);
if (ServerResult.isStart()) {
return ResultBackI.success();
} else {
return ResultBackI.error(ServerResult.getMsg());
}
} }
} }

View File

@ -58,7 +58,9 @@ public interface UniQueryDao {
* @param ids 需要删除的数据ID * @param ids 需要删除的数据ID
* @return 结果 * @return 结果
*/ */
public int deleteUniQueryByIds(Long[] ids); int deleteUniQueryByIds(Long[] ids);
int deleteUniQueryByUqIds(Long[] ids);
int deleteUniQueryByUqId(Long id); int deleteUniQueryByUqId(Long id);

View File

@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
/** /**

View File

@ -4,6 +4,7 @@ import com.ebts.common.core.entity.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -23,6 +24,7 @@ public class UniQuery extends BaseEntity {
/** /**
* 名称 * 名称
*/ */
@NotBlank(message = "名称不能为空!")
private String uqName; private String uqName;
/** /**
@ -33,6 +35,7 @@ public class UniQuery extends BaseEntity {
/** /**
* 描述 * 描述
*/ */
@NotBlank(message = "描述不能为空!")
private String uqDescribe; private String uqDescribe;
private String topJson; private String topJson;

View File

@ -1,5 +1,6 @@
package com.ebts.generator.service; package com.ebts.generator.service;
import com.ebts.common.core.entity.Result;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
import com.ebts.generator.dto.TopResult; import com.ebts.generator.dto.TopResult;
@ -15,7 +16,7 @@ public interface TopQueryService {
Map<String, Object> selectTopSearchTables(); Map<String, Object> selectTopSearchTables();
ServerResult<TopResult> preview(String jsonData, String id); Result<TopResult> preview(String jsonData, String id);
ServerResult<String> online(Long id); ServerResult<String> online(Long id);
} }

View File

@ -3,6 +3,7 @@ package com.ebts.generator.service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.ebts.common.core.entity.Result;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
import com.ebts.generator.entity.TopSearchColumn; import com.ebts.generator.entity.TopSearchColumn;
import com.ebts.generator.entity.TopSearchTable; import com.ebts.generator.entity.TopSearchTable;
@ -20,7 +21,7 @@ public interface TopSearchTableService {
* @param id top万能查询主ID * @param id top万能查询主ID
* @return top万能查询主 * @return top万能查询主
*/ */
ServerResult<TopSearchTable> selectTopSearchTableById(Long id); Result<TopSearchTable> selectTopSearchTableById(Long id);
/** /**
* 查询top万能查询主列表 * 查询top万能查询主列表
@ -28,12 +29,12 @@ public interface TopSearchTableService {
* @param topSearchTable top万能查询主 * @param topSearchTable top万能查询主
* @return top万能查询主集合 * @return top万能查询主集合
*/ */
ServerResult<List<TopSearchTable>> selectTopSearchTableList(TopSearchTable topSearchTable); Result<List<TopSearchTable>> selectTopSearchTableList(TopSearchTable topSearchTable);
/** /**
* @return * @return
*/ */
ServerResult<List<TopSearchTable>> selectTopSearchTableInfo(); Result<List<TopSearchTable>> selectTopSearchTableInfo();
List<TopSearchColumn> selectTableColumns(Long id); List<TopSearchColumn> selectTableColumns(Long id);
@ -43,7 +44,7 @@ public interface TopSearchTableService {
* @param topSearchTable top万能查询主 * @param topSearchTable top万能查询主
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> insertTopSearchTable(TopSearchTable topSearchTable); Result<Integer> insertTopSearchTable(TopSearchTable topSearchTable);
/** /**
* 修改top万能查询主 * 修改top万能查询主
@ -51,13 +52,11 @@ public interface TopSearchTableService {
* @param topSearchTable top万能查询主 * @param topSearchTable top万能查询主
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> updateTopSearchTable(TopSearchTable topSearchTable); Result<Integer> updateTopSearchTable(TopSearchTable topSearchTable);
List<TopSearchTable> selectDbTableListByNames(String[] tableNames); List<Map<String, Object>> selectDbTableList(Map<String, Object> params);
List<Map<String,Object>> selectDbTableList(Map<String,Object> params); void importGenTable(String[] tableNames);
void importGenTable(List<TopSearchTable> tableList);
/** /**
* 批量删除top万能查询主 * 批量删除top万能查询主
@ -65,7 +64,7 @@ public interface TopSearchTableService {
* @param ids 需要删除的top万能查询主ID * @param ids 需要删除的top万能查询主ID
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> deleteTopSearchTableByIds(Long[] ids); Result<Integer> deleteTopSearchTableByIds(Long[] ids);
/** /**
* 删除top万能查询主信息 * 删除top万能查询主信息

View File

@ -2,7 +2,7 @@ package com.ebts.generator.service;
import java.util.List; import java.util.List;
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;
/** /**
@ -18,7 +18,7 @@ public interface UniQueryService {
* @param id 万能查询ID * @param id 万能查询ID
* @return 万能查询 * @return 万能查询
*/ */
ServerResult<UniQuery> selectUniQueryById(Long id); Result<UniQuery> selectUniQueryById(Long id);
/** /**
* 查询万能查询列表 * 查询万能查询列表
@ -26,7 +26,7 @@ public interface UniQueryService {
* @param uniQuery 万能查询 * @param uniQuery 万能查询
* @return 万能查询集合 * @return 万能查询集合
*/ */
ServerResult<List<UniQuery>> selectUniQueryList(UniQuery uniQuery); Result<List<UniQuery>> selectUniQueryList(UniQuery uniQuery);
/** /**
* 新增万能查询 * 新增万能查询
@ -34,7 +34,7 @@ public interface UniQueryService {
* @param uniQuery 万能查询 * @param uniQuery 万能查询
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> insertUniQuery(UniQuery uniQuery); Result<Integer> insertUniQuery(UniQuery uniQuery);
/** /**
* 修改万能查询 * 修改万能查询
@ -42,7 +42,7 @@ public interface UniQueryService {
* @param uniQuery 万能查询 * @param uniQuery 万能查询
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> updateUniQuery(UniQuery uniQuery); Result<Integer> updateUniQuery(UniQuery uniQuery);
/** /**
* 批量删除万能查询 * 批量删除万能查询
@ -50,7 +50,7 @@ public interface UniQueryService {
* @param ids 需要删除的万能查询ID * @param ids 需要删除的万能查询ID
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> deleteUniQueryByIds(Long[] ids); Result<Integer> deleteUniQueryByIds(Long[] ids);
/** /**
* 删除万能查询信息 * 删除万能查询信息
@ -58,5 +58,5 @@ public interface UniQueryService {
* @param id 万能查询ID * @param id 万能查询ID
* @return 结果 * @return 结果
*/ */
ServerResult<Integer> deleteUniQueryById(Long id); Result<Integer> deleteUniQueryById(Long id);
} }

View File

@ -3,6 +3,7 @@ package com.ebts.generator.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ebts.common.core.entity.Result;
import com.ebts.common.utils.SecurityUtils; import com.ebts.common.utils.SecurityUtils;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
import com.ebts.generator.dao.QueryDao; import com.ebts.generator.dao.QueryDao;
@ -49,106 +50,99 @@ public class TopQueryServiceImpl implements TopQueryService {
Map<String, Object> modeMap = new HashMap<>(); Map<String, Object> modeMap = new HashMap<>();
//采用原子式获取到forEach中的值,原子式能够允许其他线程进行尝试性的修改值 //采用原子式获取到forEach中的值,原子式能够允许其他线程进行尝试性的修改值
AtomicReference<String> roleIds = new AtomicReference<>(""); AtomicReference<String> roleIds = new AtomicReference<>("");
SecurityUtils.getLoginUser().getUser().getRoles().forEach(role->{ SecurityUtils.getLoginUser().getUser().getRoles().forEach(role -> {
roleIds.updateAndGet(v -> v + role.getRoleId()+","); roleIds.updateAndGet(v -> v + role.getRoleId() + ",");
}); });
modeMap.put("tables", topSearchTableDao.selectTopSearchTables(roleIds.get().substring(0,roleIds.get().length()-1).split(","))); modeMap.put("tables", topSearchTableDao.selectTopSearchTables(roleIds.get().substring(0, roleIds.get().length() - 1).split(",")));
modeMap.put("relationalMap", relationalMapDao.selectRelationalMapList(new RelationalMap())); modeMap.put("relationalMap", relationalMapDao.selectRelationalMapList(new RelationalMap()));
return modeMap; return modeMap;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ServerResult<TopResult> preview(String jsonData, String id) { public Result<TopResult> preview(String jsonData, String id) {
try { JSONObject graphData = JSON.parseObject(jsonData);
//将数据格式化为自定义的java类列表
JSONObject graphData = JSON.parseObject(jsonData); List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class);
//将数据格式化为自定义的java类列表 List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class);
List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class); if (topNodes.size() == 0) {
List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class); return Result.error("top图结构有误,请整理后在试");
if (topNodes.size() == 0) { }
return new ServerResult<>(false, "top图结构有误,请整理后在试"); //整理连线的关系
} StringBuffer sql = new StringBuffer("");
//整理连线的关系 StringBuilder selectSql = new StringBuilder("select ");
StringBuffer sql = new StringBuffer(""); StringBuilder selectQuery = new StringBuilder(" where 1=1 ");
StringBuilder selectSql = new StringBuilder("select "); TopNode mainNode = null;
StringBuilder selectQuery = new StringBuilder(" where 1=1 "); if (topNodes.size() > 1) {
TopNode mainNode = null; for (int i = 0; i < topEdges.size(); i++) {
if (topNodes.size() > 1) { for (int j = 0; j < topEdges.size(); j++) {
for (int i = 0; i < topEdges.size(); i++) { if (i != j) {
for (int j = 0; j < topEdges.size(); j++) { TopEdge topEdgeJ = topEdges.get(j);
if (i != j) { if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) {
TopEdge topEdgeJ = topEdges.get(j); topEdges.get(i).setSourceEdge(topEdgeJ.getId());
if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) {
topEdges.get(i).setSourceEdge(topEdgeJ.getId());
}
} }
} }
} }
// 解析出top图中与主表的连线,可能为多条
List<TopEdge> targets = new ArrayList<>();
for (int i = 0; i < topEdges.size(); i++) {
if (topEdges.get(i).getSourceEdge() == null) {
targets.add(topEdges.get(i));
}
}
mainNode = getNode(topNodes, targets.get(0).getSource());
// 组合查询字段信息
ParseSelectSQL(mainNode, topNodes, selectSql, selectQuery);
// 组合表与表之间得到关联关系sql
String relSql = "";
for (int i = 0; i < targets.size(); i++) {
relSql += getRelSql(topNodes, topEdges, targets.get(i));
}
sql.append(selectSql).append(" from ").append(mainNode.getTable()).append(" ")
.append(mainNode.getRelTable()).append(relSql);
} else {
mainNode = topNodes.get(0);
selectSql.append(mainNode.getTableSQL());
selectQuery.append(mainNode.getQuerySql());
sql.append(selectSql).append(" from ").append(mainNode.getTable()).append(" ")
.append(mainNode.getRelTable());
} }
UniQuery uniQuery = new UniQuery(); // 解析出top图中与主表的连线,可能为多条
uniQuery.setId(Long.valueOf(id)); List<TopEdge> targets = new ArrayList<>();
uniQuery.setUqSql(sql.toString()); for (int i = 0; i < topEdges.size(); i++) {
uniQuery.setIsPreview(1); if (topEdges.get(i).getSourceEdge() == null) {
List<UniCon> uniCons = uniQuery.getUniCons(); targets.add(topEdges.get(i));
for (TopNode node : topNodes) {
JSONArray columns = node.getColumns();
for (int i = 0; i < columns.size(); i++) {
if (columns.getJSONObject(i).getInteger("isQuery") == 1) {
JSONObject column = columns.getJSONObject(i);
UniCon uniCon = new UniCon(uniQuery.getId(), column.getString("ucName"), node.getRelTable() + "." + column.getString("columnName"), column.getString("ucCon"), column.getString("ucType"), column.getInteger("type"));
uniCons.add(uniCon);
}
} }
} }
int query = uniQueryDao.updateUniQuery(uniQuery); mainNode = getNode(topNodes, targets.get(0).getSource());
if (query > 0) { // 组合查询字段信息
if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) { ParseSelectSQL(mainNode, topNodes, selectSql, selectQuery);
queryDao.deleteUniCon(uniQuery.getId());
queryDao.insertUniCon(uniCons); // 组合表与表之间得到关联关系sql
} String relSql = "";
for (int i = 0; i < targets.size(); i++) {
relSql += getRelSql(topNodes, topEdges, targets.get(i));
} }
sql.append(selectQuery); sql.append(selectSql).append(" from ").append(mainNode.getTable()).append(" ")
PageHelper.startPage(1, 10, ""); .append(mainNode.getRelTable()).append(relSql);
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
TopResult topResult = new TopResult(dataMap,uniCons); } else {
return new ServerResult<>(true, topResult); mainNode = topNodes.get(0);
} catch (RuntimeException e) { selectSql.append(mainNode.getTableSQL());
e.printStackTrace(); selectQuery.append(mainNode.getQuerySql());
logger.error(e.getMessage()); sql.append(selectSql).append(" from ").append(mainNode.getTable()).append(" ")
return new ServerResult<>(false, e.getMessage()); .append(mainNode.getRelTable());
} }
UniQuery uniQuery = new UniQuery();
uniQuery.setId(Long.valueOf(id));
uniQuery.setUqSql(sql.toString());
uniQuery.setIsPreview(1);
List<UniCon> uniCons = uniQuery.getUniCons();
for (TopNode node : topNodes) {
JSONArray columns = node.getColumns();
for (int i = 0; i < columns.size(); i++) {
if (columns.getJSONObject(i).getInteger("isQuery") == 1) {
JSONObject column = columns.getJSONObject(i);
UniCon uniCon = new UniCon(uniQuery.getId(), column.getString("ucName"), node.getRelTable() + "." + column.getString("columnName"), column.getString("ucCon"), column.getString("ucType"), column.getInteger("type"));
uniCons.add(uniCon);
}
}
}
int query = uniQueryDao.updateUniQuery(uniQuery);
if (query > 0) {
if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) {
queryDao.deleteUniCon(uniQuery.getId());
queryDao.insertUniCon(uniCons);
}
}
sql.append(selectQuery);
PageHelper.startPage(1, 10, "");
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
TopResult topResult = new TopResult(dataMap, uniCons);
return Result.ok(topResult);
} }
@Override @Override
@ -163,7 +157,7 @@ public class TopQueryServiceImpl implements TopQueryService {
if (node.getId().equals(mainNode.getId())) { if (node.getId().equals(mainNode.getId())) {
continue; continue;
} }
if (node.getTableSQL().trim().equals("")){ if (node.getTableSQL().trim().equals("")) {
continue; continue;
} }
selectSql.append(", ").append(node.getTableSQL()); selectSql.append(", ").append(node.getTableSQL());
@ -204,7 +198,7 @@ public class TopQueryServiceImpl implements TopQueryService {
sql.append(" ").append(edge.getAppConfig().getString("associated")).append(" join ") sql.append(" ").append(edge.getAppConfig().getString("associated")).append(" join ")
.append(target.getTable()).append(" ").append(target.getRelTable()).append(" on ") .append(target.getTable()).append(" ").append(target.getRelTable()).append(" on ")
.append(target.getRelTable()).append(".").append(edge.getAppConfig() .append(target.getRelTable()).append(".").append(edge.getAppConfig()
.getString("relComment")).append(" = ").append(source.getRelTable()) .getString("relComment")).append(" = ").append(source.getRelTable())
.append(".").append(edge.getAppConfig().getString("tableComment")); .append(".").append(edge.getAppConfig().getString("tableComment"));
// 获取到target 连接表的连线 // 获取到target 连接表的连线
targetEdge = getEdgeListById(edges, edge.getTarget()); targetEdge = getEdgeListById(edges, edge.getTarget());

View File

@ -3,6 +3,7 @@ package com.ebts.generator.service.impl;
import java.util.List; import java.util.List;
import com.ebts.common.constant.ReturnConstants; import com.ebts.common.constant.ReturnConstants;
import com.ebts.common.core.entity.Result;
import com.ebts.common.exception.EbtsException; 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.common.utils.ServerResult;
@ -19,6 +20,7 @@ import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import com.ebts.common.utils.StringUtils; import com.ebts.common.utils.StringUtils;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.ebts.generator.entity.TopSearchColumn; import com.ebts.generator.entity.TopSearchColumn;
import com.ebts.generator.dao.TopSearchTableDao; import com.ebts.generator.dao.TopSearchTableDao;
@ -49,23 +51,19 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
* @return top万能查询主 * @return top万能查询主
*/ */
@Override @Override
public ServerResult<TopSearchTable> selectTopSearchTableById(Long id) { @Transactional(propagation = Propagation.SUPPORTS)
try { public Result<TopSearchTable> selectTopSearchTableById(Long id) {
TopSearchTable topSearchTable = topSearchTableDao.selectTopSearchTableById(id); TopSearchTable topSearchTable = topSearchTableDao.selectTopSearchTableById(id);
List<SearchTableRole> roleList = searchTableRoleDao.selectSearchTableRoleList(new SearchTableRole(id, null)); List<SearchTableRole> roleList = searchTableRoleDao.selectSearchTableRoleList(new SearchTableRole(id, null));
Long[] roles = new Long[roleList.size()]; Long[] roles = new Long[roleList.size()];
for (int i = 0; i < roleList.size(); i++) { for (int i = 0; i < roleList.size(); i++) {
roles[i] = roleList.get(i).getRoleId(); roles[i] = roleList.get(i).getRoleId();
} }
topSearchTable.setRoleIds(roles); topSearchTable.setRoleIds(roles);
if (topSearchTable != null) { if (topSearchTable != null) {
return new ServerResult<>(true, topSearchTable); return Result.ok(topSearchTable);
} 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);
} }
} }
@ -76,29 +74,21 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
* @return top万能查询主 * @return top万能查询主
*/ */
@Override @Override
public ServerResult<List<TopSearchTable>> selectTopSearchTableList(TopSearchTable topSearchTable) { @Transactional(propagation = Propagation.SUPPORTS)
try { public Result<List<TopSearchTable>> selectTopSearchTableList(TopSearchTable topSearchTable) {
List<TopSearchTable> topSearchTableList = topSearchTableDao.selectTopSearchTableList(topSearchTable); List<TopSearchTable> topSearchTableList = topSearchTableDao.selectTopSearchTableList(topSearchTable);
if (topSearchTableList.size() > 0) { if (topSearchTableList.size() > 0) {
return new ServerResult<>(true, topSearchTableList); return Result.ok(topSearchTableList);
} 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
public ServerResult<List<TopSearchTable>> selectTopSearchTableInfo() { @Transactional(propagation = Propagation.SUPPORTS)
try { public Result<List<TopSearchTable>> selectTopSearchTableInfo() {
List<TopSearchTable> tableList = topSearchTableDao.selectTopSearchTableInfo(); List<TopSearchTable> tableList = topSearchTableDao.selectTopSearchTableInfo();
return new ServerResult<>(true, tableList); return Result.ok(tableList);
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR, e);
}
} }
public List<TopSearchColumn> selectTableColumns(Long id) { public List<TopSearchColumn> selectTableColumns(Long id) {
@ -111,24 +101,15 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
* @param topSearchTable top万能查询主 * @param topSearchTable top万能查询主
* @return 结果 * @return 结果
*/ */
@Transactional
@Override @Override
public ServerResult<Integer> insertTopSearchTable(TopSearchTable topSearchTable) { @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
try { public Result<Integer> insertTopSearchTable(TopSearchTable topSearchTable) {
topSearchTable.setCreateBy(SecurityUtils.getUserId()); topSearchTable.setCreateBy(SecurityUtils.getUserId());
int renewal = topSearchTableDao.insertTopSearchTable(topSearchTable); topSearchTableDao.insertTopSearchTable(topSearchTable);
if (insertTopSearchColumn(topSearchTable)) { if (insertTopSearchColumn(topSearchTable)) {
return new ServerResult<>(false, ReturnConstants.DB_EX); return Result.error(ReturnConstants.SYS_FAILL);
}
if (renewal > 0) {
return new ServerResult<>(true, renewal);
} else {
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR, e);
} }
return Result.ok();
} }
/** /**
@ -137,40 +118,28 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
* @param topSearchTable top万能查询主 * @param topSearchTable top万能查询主
* @return 结果 * @return 结果
*/ */
@Transactional
@Override @Override
public ServerResult<Integer> updateTopSearchTable(TopSearchTable topSearchTable) { @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
try { public Result<Integer> updateTopSearchTable(TopSearchTable topSearchTable) {
topSearchTable.setUpdateBy(SecurityUtils.getUserId()); topSearchTable.setUpdateBy(SecurityUtils.getUserId());
topSearchTableDao.deleteTopSearchColumnBySearchTableId(topSearchTable.getId()); topSearchTableDao.deleteTopSearchColumnBySearchTableId(topSearchTable.getId());
if (insertTopSearchColumn(topSearchTable)) { insertTopSearchColumn(topSearchTable);
return new ServerResult<>(false, ReturnConstants.DB_EX); List<SearchTableRole> searchTableRoles = new ArrayList<>();
} for (Long roleId : topSearchTable.getRoleIds()) {
List<SearchTableRole> searchTableRoles = new ArrayList<>(); searchTableRoles.add(new SearchTableRole(topSearchTable.getId(), roleId));
for (Long roleId : topSearchTable.getRoleIds()) {
searchTableRoles.add(new SearchTableRole(topSearchTable.getId(), roleId));
}
relationalMapDao.deleteRelationalMapById(topSearchTable.getId());
List<RelationalMap> relationalMapList = topSearchTable.getRelationalMapList();
for (RelationalMap relationalMap : relationalMapList) {
relationalMap.setMainId(topSearchTable.getId());
}
insertRelationalMap(relationalMapList);
searchTableRoleDao.deleteSearchTableRoleById(topSearchTable.getId());
boolean renewalRole = inserTopTableRole(searchTableRoles);
Integer renewal = topSearchTableDao.updateTopSearchTable(topSearchTable);
if (renewal > 0 && renewalRole) {
return new ServerResult<>(true, renewal);
} else {
return new ServerResult<>(false, ReturnConstants.OP_ERROR);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
e.printStackTrace();
throw new EbtsException(ReturnConstants.OP_ERROR, e);
} }
relationalMapDao.deleteRelationalMapById(topSearchTable.getId());
List<RelationalMap> relationalMapList = topSearchTable.getRelationalMapList();
for (RelationalMap relationalMap : relationalMapList) {
relationalMap.setMainId(topSearchTable.getId());
}
insertRelationalMap(relationalMapList);
searchTableRoleDao.deleteSearchTableRoleById(topSearchTable.getId());
inserTopTableRole(searchTableRoles);
topSearchTableDao.updateTopSearchTable(topSearchTable);
return Result.ok();
} }
// void deleteSearchTableRoleById(Long id){ // void deleteSearchTableRoleById(Long id){
// try { // try {
@ -180,15 +149,6 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
// } // }
// } // }
@Override
public List<TopSearchTable> selectDbTableListByNames(String[] tableNames) {
try {
return topSearchTableDao.selectDbTableListByNames(tableNames);
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR, e);
}
}
@Override @Override
public List<Map<String, Object>> selectDbTableList(Map<String, Object> params) { public List<Map<String, Object>> selectDbTableList(Map<String, Object> params) {
@ -201,29 +161,24 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void importGenTable(List<TopSearchTable> tableList) { public void importGenTable(String[] tableNames) {
try { List<TopSearchTable> tableList = topSearchTableDao.selectDbTableListByNames(tableNames);
Long createBy = SecurityUtils.getUserId(); Long createBy = SecurityUtils.getUserId();
for (TopSearchTable table : tableList) { for (TopSearchTable table : tableList) {
String tableName = table.getTableName(); String tableName = table.getTableName();
table.setCreateBy(createBy); table.setCreateBy(createBy);
int row = topSearchTableDao.insertTopSearchTable(table); int row = topSearchTableDao.insertTopSearchTable(table);
if (row > 0) { if (row > 0) {
List<TopSearchColumn> searchColumns = topSearchTableDao.selectDbTableColumnsByName(tableName); List<TopSearchColumn> searchColumns = topSearchTableDao.selectDbTableColumnsByName(tableName);
for (TopSearchColumn searchColumn : searchColumns) { for (TopSearchColumn searchColumn : searchColumns) {
searchColumn.setSearchTableId(table.getId()); searchColumn.setSearchTableId(table.getId());
} }
if (searchColumns.size() > 0) { if (searchColumns.size() > 0) {
topSearchTableDao.batchTopSearchColumn(searchColumns); topSearchTableDao.batchTopSearchColumn(searchColumns);
}
} }
} }
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException("导入失败:" + e.getMessage(), e);
} }
} }
/** /**
@ -234,21 +189,12 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
*/ */
@Transactional @Transactional
@Override @Override
public ServerResult<Integer> deleteTopSearchTableByIds(Long[] ids) { public Result<Integer> deleteTopSearchTableByIds(Long[] ids) {
try { //批量删除子表数据
//批量删除子表数据 topSearchTableDao.deleteTopSearchColumnBySearchTableIds(ids);
topSearchTableDao.deleteTopSearchColumnBySearchTableIds(ids); searchTableRoleDao.deleteSearchTableRoleByIds(ids);
searchTableRoleDao.deleteSearchTableRoleByIds(ids); topSearchTableDao.deleteTopSearchTableByIds(ids);
Integer renewal = topSearchTableDao.deleteTopSearchTableByIds(ids); return Result.ok();
if (renewal > 0) {
return new ServerResult<>(true, renewal);
} else {
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR, e);
}
} }
/** /**
@ -274,24 +220,20 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
} }
} }
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public boolean inserTopTableRole(List<SearchTableRole> roleList) { public boolean inserTopTableRole(List<SearchTableRole> roleList) {
if (StringUtils.isNotNull(roleList)) { if (StringUtils.isNotNull(roleList)) {
Integer renewal = searchTableRoleDao.batchSearchTableRole(roleList); searchTableRoleDao.batchSearchTableRole(roleList);
if (renewal > 0) {
return true;
}
} }
return false; return true;
} }
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public boolean insertRelationalMap(List<RelationalMap> relationalMaps) { public boolean insertRelationalMap(List<RelationalMap> relationalMaps) {
if (StringUtils.isNotNull(relationalMaps) && relationalMaps.size() > 0) { if (StringUtils.isNotNull(relationalMaps) && relationalMaps.size() > 0) {
Integer renewal = relationalMapDao.batchRelationalMap(relationalMaps); relationalMapDao.batchRelationalMap(relationalMaps);
if (renewal > 0) {
return true;
}
} }
return false; return true;
} }
/** /**
@ -299,6 +241,7 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
* *
* @param topSearchTable top万能查询主对象 * @param topSearchTable top万能查询主对象
*/ */
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public boolean insertTopSearchColumn(TopSearchTable topSearchTable) { public boolean insertTopSearchColumn(TopSearchTable topSearchTable) {
List<TopSearchColumn> topSearchColumnList = topSearchTable.getTopSearchColumnList(); List<TopSearchColumn> topSearchColumnList = topSearchTable.getTopSearchColumnList();
Long id = topSearchTable.getId(); Long id = topSearchTable.getId();

View File

@ -3,6 +3,7 @@ package com.ebts.generator.service.impl;
import java.util.List; import java.util.List;
import com.ebts.common.constant.ReturnConstants; import com.ebts.common.constant.ReturnConstants;
import com.ebts.common.core.entity.Result;
import com.ebts.common.exception.EbtsException; 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.common.utils.ServerResult;
@ -36,17 +37,13 @@ public class UniQueryServiceImpl implements UniQueryService {
* @return 万能查询 * @return 万能查询
*/ */
@Override @Override
public ServerResult<UniQuery> selectUniQueryById(Long id) { public Result<UniQuery> selectUniQueryById(Long id) {
try { UniQuery uniQuery = uniQueryDao.selectUniQueryById(id);
UniQuery uniQuery = uniQueryDao.selectUniQueryById(id); System.out.println(1/0);
if (uniQuery != null) { if (uniQuery != null) {
return new ServerResult<UniQuery>(true, uniQuery); return Result.ok(uniQuery);
} else { } else {
return new ServerResult<UniQuery>(false, ReturnConstants.RESULT_EMPTY); return Result.info(ReturnConstants.RESULT_EMPTY);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e);
} }
} }
@ -57,17 +54,12 @@ public class UniQueryServiceImpl implements UniQueryService {
* @return 万能查询 * @return 万能查询
*/ */
@Override @Override
public ServerResult<List<UniQuery>> selectUniQueryList(UniQuery uniQuery) { public Result<List<UniQuery>> selectUniQueryList(UniQuery uniQuery) {
try { List<UniQuery> uniQueryList = uniQueryDao.selectUniQueryList(uniQuery);
List<UniQuery> uniQueryList = uniQueryDao.selectUniQueryList(uniQuery); if (uniQueryList.size() > 0) {
if (uniQueryList.size() > 0) { return Result.ok(uniQueryList);
return new ServerResult<List<UniQuery>>(true, uniQueryList); } else {
} else { return Result.info(ReturnConstants.RESULT_EMPTY);
return new ServerResult<List<UniQuery>>(false, ReturnConstants.RESULT_EMPTY);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e);
} }
} }
@ -78,19 +70,10 @@ public class UniQueryServiceImpl implements UniQueryService {
* @return 结果 * @return 结果
*/ */
@Override @Override
public ServerResult<Integer> insertUniQuery(UniQuery uniQuery) { public Result<Integer> insertUniQuery(UniQuery uniQuery) {
try { uniQuery.setCreateBy(SecurityUtils.getUserId());
uniQuery.setCreateBy(SecurityUtils.getUserId()); uniQueryDao.insertUniQuery(uniQuery);
Integer renewal = uniQueryDao.insertUniQuery(uniQuery); return Result.ok();
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e);
}
} }
/** /**
@ -100,19 +83,10 @@ public class UniQueryServiceImpl implements UniQueryService {
* @return 结果 * @return 结果
*/ */
@Override @Override
public ServerResult<Integer> updateUniQuery(UniQuery uniQuery) { public Result<Integer> updateUniQuery(UniQuery uniQuery) {
try { uniQuery.setUpdateBy(SecurityUtils.getUserId());
uniQuery.setUpdateBy(SecurityUtils.getUserId()); uniQueryDao.updateUniQuery(uniQuery);
Integer renewal = uniQueryDao.updateUniQuery(uniQuery); return Result.ok();
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e);
}
} }
/** /**
@ -123,22 +97,10 @@ public class UniQueryServiceImpl implements UniQueryService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ServerResult<Integer> deleteUniQueryByIds(Long[] ids) { public Result<Integer> deleteUniQueryByIds(Long[] ids) {
try { uniQueryDao.deleteUniQueryByIds(ids);
Integer renewal = uniQueryDao.deleteUniQueryByIds(ids); uniQueryDao.deleteUniQueryByUqIds(ids);
for (Long id : ids) { return Result.ok();
uniQueryDao.deleteUniQueryByUqId(id);
}
if (renewal > 0) {
return new ServerResult<>(true, renewal);
} else {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e);
}
} }
/** /**
@ -149,18 +111,9 @@ public class UniQueryServiceImpl implements UniQueryService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ServerResult<Integer> deleteUniQueryById(Long id) { public Result<Integer> deleteUniQueryById(Long id) {
try { uniQueryDao.deleteUniQueryById(id);
Integer renewal = uniQueryDao.deleteUniQueryById(id); uniQueryDao.deleteUniQueryByUqId(id);
uniQueryDao.deleteUniQueryByUqId(id); return Result.ok();
if (renewal > 0) {
return new ServerResult<>(true, renewal);
} else {
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e);
}
} }
} }

View File

@ -79,7 +79,14 @@
</delete> </delete>
<delete id="deleteUniQueryByUqId" parameterType="Long"> <delete id="deleteUniQueryByUqId" parameterType="Long">
delete from gen_uni_con where uq_id = #{id} delete from gen_uni_con where uq_id in #{id}
</delete>
<delete id="deleteUniQueryByUqIds" parameterType="Long">
delete from gen_uni_con where uq_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete> </delete>
<delete id="deleteUniQueryByIds" parameterType="String"> <delete id="deleteUniQueryByIds" parameterType="String">