diff --git a/ebts/ebts-common/src/main/java/com/ebts/common/core/entity/Result.java b/ebts/ebts-common/src/main/java/com/ebts/common/core/entity/Result.java index 1ab2b51..fc13707 100644 --- a/ebts/ebts-common/src/main/java/com/ebts/common/core/entity/Result.java +++ b/ebts/ebts-common/src/main/java/com/ebts/common/core/entity/Result.java @@ -3,13 +3,15 @@ package com.ebts.common.core.entity; import com.ebts.common.constant.HttpStatus; +import java.io.Serializable; + /** * @description: some desc * @author: Binlin B Wang * @email: binlin.b.wang@cn.pwc.com * @date: 2022/5/31 10:00 */ -public class Result { +public class Result implements Serializable { private int code; private boolean success; private String msg; diff --git a/ebts/ebts-common/src/main/java/com/ebts/common/core/page/TableDataInfo.java b/ebts/ebts-common/src/main/java/com/ebts/common/core/page/TableDataInfo.java index f1bfbc2..e13e413 100644 --- a/ebts/ebts-common/src/main/java/com/ebts/common/core/page/TableDataInfo.java +++ b/ebts/ebts-common/src/main/java/com/ebts/common/core/page/TableDataInfo.java @@ -8,7 +8,7 @@ import java.util.List; * * @author binlin */ -public class TableDataInfo implements Serializable { +public class TableDataInfo implements Serializable { /** @@ -19,7 +19,7 @@ public class TableDataInfo implements Serializable { /** * 列表数据 */ - private List rows; + private List rows; /** * 消息状态码 @@ -43,7 +43,7 @@ public class TableDataInfo implements Serializable { * @param list 列表数据 * @param total 总记录数 */ - public TableDataInfo(List list, int total) { + public TableDataInfo(List list, int total) { this.rows = list; this.total = total; } @@ -60,7 +60,7 @@ public class TableDataInfo implements Serializable { return rows; } - public void setRows(List rows) { + public void setRows(List rows) { this.rows = rows; } diff --git a/ebts/ebts-common/src/main/java/com/ebts/common/utils/poi/ExcelUtil.java b/ebts/ebts-common/src/main/java/com/ebts/common/utils/poi/ExcelUtil.java index 6d8f724..592c0bf 100644 --- a/ebts/ebts-common/src/main/java/com/ebts/common/utils/poi/ExcelUtil.java +++ b/ebts/ebts-common/src/main/java/com/ebts/common/utils/poi/ExcelUtil.java @@ -19,6 +19,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; +import com.ebts.common.core.entity.Result; import com.ebts.common.core.entity.ResultBackI; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.BorderStyle; @@ -267,6 +268,18 @@ public class ExcelUtil { return exportExcel(); } + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @return 结果 + */ + public Result exportExcelRest(List list, String sheetName) { + this.init(list, sheetName, Type.EXPORT); + return exportExcelRest(); + } + /** * 对list数据源将其里面的数据导入到excel表单 * @@ -329,6 +342,58 @@ public class ExcelUtil { } } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @return 结果 + */ + public Result 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数据 * diff --git a/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java b/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java index 21a3501..401e3ec 100644 --- a/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java +++ b/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java @@ -1,6 +1,8 @@ package com.ebts.framework.web.exception; 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.exception.BaseException; import com.ebts.common.exception.CustomException; @@ -12,6 +14,7 @@ import org.slf4j.LoggerFactory; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.AccountExpiredException; import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Component; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -80,13 +83,6 @@ public class GlobalExceptionHandler { log.error(e.getMessage(), e); 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) { return ResultBackI.error("演示模式,不允许操作"); } + + @ExceptionHandler(Exception.class) + public Result handleException(Exception e) { + log.error(e.getMessage(), e); + return Result.error(ReturnConstants.SYS_ERROR); + } + } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java index 63b2222..9208f63 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java @@ -2,6 +2,7 @@ package com.ebts.generator.controller; import com.ebts.common.annotation.Log; 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.enums.BusinessType; import com.ebts.common.utils.ServerResult; @@ -42,17 +43,12 @@ public class TopQueryController extends BaseController { */ @PreAuthorize("@ebts.hasPermi('top:query')") @GetMapping(value = "/{id}") - public ResultBackI getInfo(@PathVariable("id") Long id) { - ServerResult ServerResult = uniQueryService.selectUniQueryById(id); - if (ServerResult.isStart()) { - return ResultBackI.success(ServerResult.getData()); - } else { - return ResultBackI.info(ServerResult.getMsg()); - } + public Result getInfo(@PathVariable("id") Long id) { + return uniQueryService.selectUniQueryById(id); } @GetMapping("/online/{id}") - public ResultBackI online(@PathVariable("id") Long id){ + public ResultBackI online(@PathVariable("id") Long id) { // ServerResult ServerResult = queryService.updateQueryInfo(uniQuery); // if (ServerResult.isStart()) { // return AjaxResult.success(ServerResult.getData()); @@ -71,8 +67,8 @@ public class TopQueryController extends BaseController { */ @PreAuthorize("@ebts.hasPermi('top:table')") @GetMapping("/table") - public ResultBackI table() { - return ResultBackI.success(topQueryService.selectTopSearchTables()); + public Result> table() { + return Result.ok(topQueryService.selectTopSearchTables()); } /** @@ -81,35 +77,20 @@ public class TopQueryController extends BaseController { @PreAuthorize("@ebts.hasPermi('top:edit')") @Log(title = "top万能查询", businessType = BusinessType.UPDATE) @PutMapping - public ResultBackI edit(@RequestBody UniQuery uniQuery) { - if (uniQuery.getId()<0){ - return ResultBackI.error("缺少关键字段"); - } - if (StringUtils.isNull(uniQuery.getTopJson())){ - return ResultBackI.error("缺少关键字段"); - } - ServerResult ServerResult = uniQueryService.updateUniQuery(uniQuery); - if (ServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(ServerResult.getMsg()); - } + public Result edit(@RequestBody UniQuery uniQuery) { + return uniQueryService.updateUniQuery(uniQuery); } + /** * 简单修改top万能能查询 */ @PreAuthorize("@ebts.hasPermi('top:preview')") @Log(title = "top预览", businessType = BusinessType.OTHER) @PostMapping("/preview") - public Serializable preview(@RequestBody Map params){ - if (StringUtils.isNull(params.get("jsonData"))){ + public Serializable preview(@RequestBody Map params) { + if (StringUtils.isNull(params.get("jsonData"))) { return ResultBackI.error("缺少必要参数!"); } - ServerResult serverResult = 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()); - } + return topQueryService.preview(params.get("jsonData"), params.get("id")); } } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopSearchTableController.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopSearchTableController.java index e9fe48a..29ff131 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopSearchTableController.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopSearchTableController.java @@ -6,6 +6,7 @@ import java.util.Map; 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.text.Convert; import com.ebts.common.utils.ServerResult; @@ -23,7 +24,7 @@ import com.ebts.common.utils.poi.ExcelUtil; /** * top万能查询主Controller - * + * * @author clay * @date 2021-07-20 */ @@ -42,18 +43,22 @@ public class TopSearchTableController extends EBTSController { @PreAuthorize("@ebts.hasPermi('tool:table:list')") @PostMapping("/list") public Serializable list(@Validated @RequestBody TopSearchTable topSearchTable) { +// if (topSearchTable.getRoleIds()==null){ +// return Result.error("角色列表不能为空!"); +// } startPage(topSearchTable.getPageInfo()); - ServerResult> genServerResult = topSearchTableService.selectTopSearchTableList(topSearchTable); - if (genServerResult.isStart()) { - return getDataTable(genServerResult.getData()); + Result> result = topSearchTableService.selectTopSearchTableList(topSearchTable); + if (result.isSuccess()) { + return getDataTable(result.getData()); } else { - return ResultBackI.info(genServerResult.getMsg()); + return result; } } + @PreAuthorize("@ebts.hasPermi('tool:table:cloumns')") @GetMapping("/columns/{id}") - public ResultBackI columns(@PathVariable("id") Long id){ - return ResultBackI.success(topSearchTableService.selectTableColumns(id)); + public Result columns(@PathVariable("id") Long id) { + return Result.ok(topSearchTableService.selectTableColumns(id)); } @@ -63,11 +68,11 @@ public class TopSearchTableController extends EBTSController { @PreAuthorize("@ebts.hasPermi('tool:table:info')") @PostMapping("/info") public Serializable info() { - ServerResult> genServerResult = topSearchTableService.selectTopSearchTableInfo(); - if (genServerResult.isStart()) { - return getDataTable(genServerResult.getData()); + Result> result = topSearchTableService.selectTopSearchTableInfo(); + if (result.isSuccess()) { + return getDataTable(result.getData()); } else { - return ResultBackI.info(genServerResult.getMsg()); + return result; } } @@ -77,13 +82,13 @@ public class TopSearchTableController extends EBTSController { @PreAuthorize("@ebts.hasPermi('tool:table:export')") @Log(title = "top万能查询主", businessType = BusinessType.EXPORT) @PostMapping("/export") - public ResultBackI export(@Validated @RequestBody TopSearchTable topSearchTable) { - ServerResult> genServerResult = topSearchTableService.selectTopSearchTableList(topSearchTable); - ExcelUtil util = new ExcelUtil(TopSearchTable. class); - if (genServerResult.isStart()) { - return util.exportExcel(genServerResult.getData(), "table"); + public Result export(@Validated @RequestBody TopSearchTable topSearchTable) { + Result> result = topSearchTableService.selectTopSearchTableList(topSearchTable); + ExcelUtil util = new ExcelUtil(TopSearchTable.class); + if (result.isSuccess()) { + return util.exportExcelRest(result.getData(), "table"); } 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')") @GetMapping(value = "/{id}") - public ResultBackI getInfo(@PathVariable("id") Long id) { - ServerResult genServerResult = topSearchTableService.selectTopSearchTableById(id); - if (genServerResult.isStart()) { - return ResultBackI.success(genServerResult.getData()); - } else { - return ResultBackI.info(genServerResult.getMsg()); - } + public Result getInfo(@PathVariable("id") Long id) { + return topSearchTableService.selectTopSearchTableById(id); } /** @@ -107,13 +107,8 @@ public class TopSearchTableController extends EBTSController { @PreAuthorize("@ebts.hasPermi('tool:table:add')") @Log(title = "top万能查询主", businessType = BusinessType.INSERT) @PostMapping - public ResultBackI add(@Validated @RequestBody TopSearchTable topSearchTable) { - ServerResult genServerResult = topSearchTableService.insertTopSearchTable(topSearchTable); - if (genServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(genServerResult.getMsg()); - } + public Result add(@Validated @RequestBody TopSearchTable topSearchTable) { + return topSearchTableService.insertTopSearchTable(topSearchTable); } /** @@ -122,16 +117,11 @@ public class TopSearchTableController extends EBTSController { @PreAuthorize("@ebts.hasPermi('tool:table:edit')") @Log(title = "top万能查询主", businessType = BusinessType.UPDATE) @PutMapping - public ResultBackI edit(@Validated @RequestBody TopSearchTable topSearchTable) { - if (topSearchTable.getRoleIds().length==0){ - return ResultBackI.error("角色不能为空!"); - } - ServerResult genServerResult = topSearchTableService.updateTopSearchTable(topSearchTable); - if (genServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(genServerResult.getMsg()); + public Result edit(@Validated @RequestBody TopSearchTable topSearchTable) { + if (topSearchTable.getRoleIds().length == 0){ + return Result.error("角色不能为空!"); } + return topSearchTableService.updateTopSearchTable(topSearchTable); } /** @@ -139,30 +129,25 @@ public class TopSearchTableController extends EBTSController { */ @PreAuthorize("@ebts.hasPermi('tool:table:remove')") @Log(title = "top万能查询主", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public ResultBackI remove(@PathVariable Long[] ids) { - if (ids.length<0){ - return ResultBackI.error("id不能为空!"); - } - ServerResult genServerResult = topSearchTableService.deleteTopSearchTableByIds(ids); - if (genServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(genServerResult.getMsg()); + @DeleteMapping("/{ids}") + public Result remove(@PathVariable Long[] ids) { + if (ids.length == 0) { + return Result.error("id不能为空!"); } + return topSearchTableService.deleteTopSearchTableByIds(ids); } + /** * 导入表结构(保存) */ @PreAuthorize("@ebts.hasPermi('tool:table:import')") @Log(title = "代码生成", businessType = BusinessType.IMPORT) @PostMapping("/importTopTable") - public ResultBackI importTableSave(String tables) { + public Result importTableSave(String tables) { String[] tableNames = Convert.toStrArray(tables); // 查询表信息 - List tableList = topSearchTableService.selectDbTableListByNames(tableNames); - topSearchTableService.importGenTable(tableList); - return ResultBackI.success(); + topSearchTableService.importGenTable(tableNames); + return Result.ok(); } @@ -171,12 +156,11 @@ public class TopSearchTableController extends EBTSController { */ @PreAuthorize("@ebts.hasPermi('tool:table:db:list')") @PostMapping("/db/list") - public Serializable dbList(@RequestBody Map params){ + public Serializable dbList(@RequestBody Map params) { startPage(params); - List> list = topSearchTableService.selectDbTableList(params); + List> list = topSearchTableService.selectDbTableList(params); return getDataTable(list); } - } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/UniQueryController.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/UniQueryController.java index e0affca..02ab907 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/UniQueryController.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/UniQueryController.java @@ -6,6 +6,7 @@ import java.util.List; import com.ebts.common.annotation.Log; 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.enums.BusinessType; import com.ebts.common.utils.ServerResult; @@ -16,6 +17,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.prepost.PreAuthorize; 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.PostMapping; 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.RestController; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * 万能查询Controller * @@ -46,11 +51,11 @@ public class UniQueryController extends BaseController { @GetMapping("/list") public Serializable list(UniQuery uniQuery) { startPage(); - ServerResult> ServerResult = uniQueryService.selectUniQueryList(uniQuery); - if (ServerResult.isStart()) { - return getDataTable(ServerResult.getData()); + Result> result = uniQueryService.selectUniQueryList(uniQuery); + if (result.isSuccess()) { + return getDataTable(result.getData()); } else { - return ResultBackI.info(ServerResult.getMsg()); + return result; } } @@ -60,13 +65,13 @@ public class UniQueryController extends BaseController { @PreAuthorize("@ebts.hasPermi('tool:query:export')") @Log(title = "万能查询", businessType = BusinessType.EXPORT) @GetMapping("/export") - public ResultBackI export(UniQuery uniQuery) { - ServerResult> ServerResult = uniQueryService.selectUniQueryList(uniQuery); + public Result export(UniQuery uniQuery) { + Result> result = uniQueryService.selectUniQueryList(uniQuery); ExcelUtil util = new ExcelUtil(UniQuery.class); - if (ServerResult.isStart()) { - return util.exportExcel(ServerResult.getData(), "query"); + if (result.isSuccess()) { + return util.exportExcelRest(result.getData(), "query"); } 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')") @GetMapping(value = "/{id}") - public ResultBackI getInfo(@PathVariable("id") Long id) { - ServerResult ServerResult = uniQueryService.selectUniQueryById(id); - if (ServerResult.isStart()) { - return ResultBackI.success(ServerResult.getData()); - } else { - return ResultBackI.info(ServerResult.getMsg()); - } + public Result getInfo(@PathVariable("id") Long id) { + Result result = uniQueryService.selectUniQueryById(id); + return result; } /** @@ -90,19 +91,8 @@ public class UniQueryController extends BaseController { @PreAuthorize("@ebts.hasPermi('tool:query:add')") @Log(title = "万能查询", businessType = BusinessType.INSERT) @PostMapping - public ResultBackI add(@RequestBody UniQuery uniQuery) { - if (uniQuery.getUqName() == null || uniQuery.getUqName().equals("")) { - return ResultBackI.error("名称不能为空!"); - } - if (uniQuery.getUqDescribe() == null || uniQuery.getUqDescribe().equals("")) { - return ResultBackI.error("描述不能为空!"); - } - ServerResult ServerResult = uniQueryService.insertUniQuery(uniQuery); - if (ServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(ServerResult.getMsg()); - } + public Result add(@RequestBody @Validated UniQuery uniQuery) { + return uniQueryService.insertUniQuery(uniQuery); } /** @@ -111,19 +101,8 @@ public class UniQueryController extends BaseController { @PreAuthorize("@ebts.hasPermi('tool:query:edit')") @Log(title = "万能查询", businessType = BusinessType.UPDATE) @PutMapping - public ResultBackI edit(@RequestBody UniQuery uniQuery) { - if (uniQuery.getUqName() == null || uniQuery.getUqName().equals("")) { - return ResultBackI.error("名称不能为空!"); - } - if (uniQuery.getUqDescribe() == null || uniQuery.getUqDescribe().equals("")) { - return ResultBackI.error("描述不能为空!"); - } - ServerResult ServerResult = uniQueryService.updateUniQuery(uniQuery); - if (ServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(ServerResult.getMsg()); - } + public Result edit(@RequestBody @Validated UniQuery uniQuery) { + return uniQueryService.updateUniQuery(uniQuery); } /** @@ -132,15 +111,7 @@ public class UniQueryController extends BaseController { @PreAuthorize("@ebts.hasPermi('tool:query:remove')") @Log(title = "万能查询", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") - public ResultBackI remove(@PathVariable Long[] ids) { - if (ids.length < 0) { - return ResultBackI.error("id不能为空!"); - } - ServerResult ServerResult = uniQueryService.deleteUniQueryByIds(ids); - if (ServerResult.isStart()) { - return ResultBackI.success(); - } else { - return ResultBackI.error(ServerResult.getMsg()); - } + public Result remove(@PathVariable @NotNull @NotBlank(message = "id不能为空!") Long[] ids) { + return uniQueryService.deleteUniQueryByIds(ids); } } \ No newline at end of file diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/dao/UniQueryDao.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/dao/UniQueryDao.java index 6f2a56c..e551dc8 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/dao/UniQueryDao.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/dao/UniQueryDao.java @@ -58,7 +58,9 @@ public interface UniQueryDao { * @param ids 需要删除的数据ID * @return 结果 */ - public int deleteUniQueryByIds(Long[] ids); + int deleteUniQueryByIds(Long[] ids); + + int deleteUniQueryByUqIds(Long[] ids); int deleteUniQueryByUqId(Long id); diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/TopSearchTable.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/TopSearchTable.java index 8d54176..7b16f7b 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/TopSearchTable.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/TopSearchTable.java @@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; /** diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/UniQuery.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/UniQuery.java index 6b48876..702212d 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/UniQuery.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/entity/UniQuery.java @@ -4,6 +4,7 @@ import com.ebts.common.core.entity.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.List; @@ -23,6 +24,7 @@ public class UniQuery extends BaseEntity { /** * 名称 */ + @NotBlank(message = "名称不能为空!") private String uqName; /** @@ -33,6 +35,7 @@ public class UniQuery extends BaseEntity { /** * 描述 */ + @NotBlank(message = "描述不能为空!") private String uqDescribe; private String topJson; diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java index 023151c..77b231b 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java @@ -1,5 +1,6 @@ package com.ebts.generator.service; +import com.ebts.common.core.entity.Result; import com.ebts.common.utils.ServerResult; import com.ebts.generator.dto.TopResult; @@ -15,7 +16,7 @@ public interface TopQueryService { Map selectTopSearchTables(); - ServerResult preview(String jsonData, String id); + Result preview(String jsonData, String id); ServerResult online(Long id); } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java index 8fb33c6..b9bcf3b 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java @@ -3,6 +3,7 @@ package com.ebts.generator.service; import java.util.List; import java.util.Map; +import com.ebts.common.core.entity.Result; import com.ebts.common.utils.ServerResult; import com.ebts.generator.entity.TopSearchColumn; import com.ebts.generator.entity.TopSearchTable; @@ -20,7 +21,7 @@ public interface TopSearchTableService { * @param id top万能查询主ID * @return top万能查询主 */ - ServerResult selectTopSearchTableById(Long id); + Result selectTopSearchTableById(Long id); /** * 查询top万能查询主列表 @@ -28,12 +29,12 @@ public interface TopSearchTableService { * @param topSearchTable top万能查询主 * @return top万能查询主集合 */ - ServerResult> selectTopSearchTableList(TopSearchTable topSearchTable); + Result> selectTopSearchTableList(TopSearchTable topSearchTable); /** * @return */ - ServerResult> selectTopSearchTableInfo(); + Result> selectTopSearchTableInfo(); List selectTableColumns(Long id); @@ -43,7 +44,7 @@ public interface TopSearchTableService { * @param topSearchTable top万能查询主 * @return 结果 */ - ServerResult insertTopSearchTable(TopSearchTable topSearchTable); + Result insertTopSearchTable(TopSearchTable topSearchTable); /** * 修改top万能查询主 @@ -51,13 +52,11 @@ public interface TopSearchTableService { * @param topSearchTable top万能查询主 * @return 结果 */ - ServerResult updateTopSearchTable(TopSearchTable topSearchTable); + Result updateTopSearchTable(TopSearchTable topSearchTable); - List selectDbTableListByNames(String[] tableNames); + List> selectDbTableList(Map params); - List> selectDbTableList(Map params); - - void importGenTable(List tableList); + void importGenTable(String[] tableNames); /** * 批量删除top万能查询主 @@ -65,7 +64,7 @@ public interface TopSearchTableService { * @param ids 需要删除的top万能查询主ID * @return 结果 */ - ServerResult deleteTopSearchTableByIds(Long[] ids); + Result deleteTopSearchTableByIds(Long[] ids); /** * 删除top万能查询主信息 diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/UniQueryService.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/UniQueryService.java index 64618c8..96b3189 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/UniQueryService.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/UniQueryService.java @@ -2,7 +2,7 @@ package com.ebts.generator.service; import java.util.List; -import com.ebts.common.utils.ServerResult; +import com.ebts.common.core.entity.Result; import com.ebts.generator.entity.UniQuery; /** @@ -18,7 +18,7 @@ public interface UniQueryService { * @param id 万能查询ID * @return 万能查询 */ - ServerResult selectUniQueryById(Long id); + Result selectUniQueryById(Long id); /** * 查询万能查询列表 @@ -26,7 +26,7 @@ public interface UniQueryService { * @param uniQuery 万能查询 * @return 万能查询集合 */ - ServerResult> selectUniQueryList(UniQuery uniQuery); + Result> selectUniQueryList(UniQuery uniQuery); /** * 新增万能查询 @@ -34,7 +34,7 @@ public interface UniQueryService { * @param uniQuery 万能查询 * @return 结果 */ - ServerResult insertUniQuery(UniQuery uniQuery); + Result insertUniQuery(UniQuery uniQuery); /** * 修改万能查询 @@ -42,7 +42,7 @@ public interface UniQueryService { * @param uniQuery 万能查询 * @return 结果 */ - ServerResult updateUniQuery(UniQuery uniQuery); + Result updateUniQuery(UniQuery uniQuery); /** * 批量删除万能查询 @@ -50,7 +50,7 @@ public interface UniQueryService { * @param ids 需要删除的万能查询ID * @return 结果 */ - ServerResult deleteUniQueryByIds(Long[] ids); + Result deleteUniQueryByIds(Long[] ids); /** * 删除万能查询信息 @@ -58,5 +58,5 @@ public interface UniQueryService { * @param id 万能查询ID * @return 结果 */ - ServerResult deleteUniQueryById(Long id); + Result deleteUniQueryById(Long id); } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java index 5cce30b..906fde0 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java @@ -3,6 +3,7 @@ package com.ebts.generator.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.ebts.common.core.entity.Result; import com.ebts.common.utils.SecurityUtils; import com.ebts.common.utils.ServerResult; import com.ebts.generator.dao.QueryDao; @@ -49,106 +50,99 @@ public class TopQueryServiceImpl implements TopQueryService { Map modeMap = new HashMap<>(); //采用原子式获取到forEach中的值,原子式能够允许其他线程进行尝试性的修改值 AtomicReference roleIds = new AtomicReference<>(""); - SecurityUtils.getLoginUser().getUser().getRoles().forEach(role->{ - roleIds.updateAndGet(v -> v + role.getRoleId()+","); + SecurityUtils.getLoginUser().getUser().getRoles().forEach(role -> { + 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())); return modeMap; } @Override @Transactional(rollbackFor = Exception.class) - public ServerResult preview(String jsonData, String id) { - try { - - JSONObject graphData = JSON.parseObject(jsonData); - //将数据格式化为自定义的java类列表 - List topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class); - List topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class); - if (topNodes.size() == 0) { - return new ServerResult<>(false, "top图结构有误,请整理后在试"); - } - //整理连线的关系 - StringBuffer sql = new StringBuffer(""); - StringBuilder selectSql = new StringBuilder("select "); - StringBuilder selectQuery = new StringBuilder(" where 1=1 "); - TopNode mainNode = null; - if (topNodes.size() > 1) { - for (int i = 0; i < topEdges.size(); i++) { - for (int j = 0; j < topEdges.size(); j++) { - if (i != j) { - TopEdge topEdgeJ = topEdges.get(j); - if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) { - topEdges.get(i).setSourceEdge(topEdgeJ.getId()); - } + public Result preview(String jsonData, String id) { + JSONObject graphData = JSON.parseObject(jsonData); + //将数据格式化为自定义的java类列表 + List topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class); + List topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class); + if (topNodes.size() == 0) { + return Result.error("top图结构有误,请整理后在试"); + } + //整理连线的关系 + StringBuffer sql = new StringBuffer(""); + StringBuilder selectSql = new StringBuilder("select "); + StringBuilder selectQuery = new StringBuilder(" where 1=1 "); + TopNode mainNode = null; + if (topNodes.size() > 1) { + for (int i = 0; i < topEdges.size(); i++) { + for (int j = 0; j < topEdges.size(); j++) { + if (i != j) { + TopEdge topEdgeJ = topEdges.get(j); + if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) { + topEdges.get(i).setSourceEdge(topEdgeJ.getId()); } } } - // 解析出top图中与主表的连线,可能为多条 - List 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(); - uniQuery.setId(Long.valueOf(id)); - uniQuery.setUqSql(sql.toString()); - uniQuery.setIsPreview(1); - List 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); - } + // 解析出top图中与主表的连线,可能为多条 + List targets = new ArrayList<>(); + for (int i = 0; i < topEdges.size(); i++) { + if (topEdges.get(i).getSourceEdge() == null) { + targets.add(topEdges.get(i)); } } - int query = uniQueryDao.updateUniQuery(uniQuery); - if (query > 0) { - if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) { - queryDao.deleteUniCon(uniQuery.getId()); - queryDao.insertUniCon(uniCons); - } + 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(selectQuery); - PageHelper.startPage(1, 10, ""); - List> dataMap = queryDao.UniQuery(sql.toString()); - TopResult topResult = new TopResult(dataMap,uniCons); - return new ServerResult<>(true, topResult); - } catch (RuntimeException e) { - e.printStackTrace(); - logger.error(e.getMessage()); - return new ServerResult<>(false, e.getMessage()); + 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(); + uniQuery.setId(Long.valueOf(id)); + uniQuery.setUqSql(sql.toString()); + uniQuery.setIsPreview(1); + List 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> dataMap = queryDao.UniQuery(sql.toString()); + TopResult topResult = new TopResult(dataMap, uniCons); + return Result.ok(topResult); } @Override @@ -163,7 +157,7 @@ public class TopQueryServiceImpl implements TopQueryService { if (node.getId().equals(mainNode.getId())) { continue; } - if (node.getTableSQL().trim().equals("")){ + if (node.getTableSQL().trim().equals("")) { continue; } selectSql.append(", ").append(node.getTableSQL()); @@ -204,7 +198,7 @@ public class TopQueryServiceImpl implements TopQueryService { sql.append(" ").append(edge.getAppConfig().getString("associated")).append(" join ") .append(target.getTable()).append(" ").append(target.getRelTable()).append(" on ") .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")); // 获取到target 连接表的连线 targetEdge = getEdgeListById(edges, edge.getTarget()); diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopSearchTableServiceImpl.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopSearchTableServiceImpl.java index b47629f..e71f050 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopSearchTableServiceImpl.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopSearchTableServiceImpl.java @@ -3,6 +3,7 @@ package com.ebts.generator.service.impl; import java.util.List; import com.ebts.common.constant.ReturnConstants; +import com.ebts.common.core.entity.Result; import com.ebts.common.exception.EbtsException; import com.ebts.common.utils.SecurityUtils; import com.ebts.common.utils.ServerResult; @@ -19,6 +20,7 @@ import java.util.ArrayList; import java.util.Map; import com.ebts.common.utils.StringUtils; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.ebts.generator.entity.TopSearchColumn; import com.ebts.generator.dao.TopSearchTableDao; @@ -49,23 +51,19 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { * @return top万能查询主 */ @Override - public ServerResult selectTopSearchTableById(Long id) { - try { - TopSearchTable topSearchTable = topSearchTableDao.selectTopSearchTableById(id); - List roleList = searchTableRoleDao.selectSearchTableRoleList(new SearchTableRole(id, null)); - Long[] roles = new Long[roleList.size()]; - for (int i = 0; i < roleList.size(); i++) { - roles[i] = roleList.get(i).getRoleId(); - } - topSearchTable.setRoleIds(roles); - if (topSearchTable != null) { - return new ServerResult<>(true, topSearchTable); - } else { - return new ServerResult<>(false, ReturnConstants.RESULT_EMPTY); - } - } catch (RuntimeException e) { - logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR, e); + @Transactional(propagation = Propagation.SUPPORTS) + public Result selectTopSearchTableById(Long id) { + TopSearchTable topSearchTable = topSearchTableDao.selectTopSearchTableById(id); + List roleList = searchTableRoleDao.selectSearchTableRoleList(new SearchTableRole(id, null)); + Long[] roles = new Long[roleList.size()]; + for (int i = 0; i < roleList.size(); i++) { + roles[i] = roleList.get(i).getRoleId(); + } + topSearchTable.setRoleIds(roles); + if (topSearchTable != null) { + return Result.ok(topSearchTable); + } else { + return Result.info(ReturnConstants.RESULT_EMPTY); } } @@ -76,29 +74,21 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { * @return top万能查询主 */ @Override - public ServerResult> selectTopSearchTableList(TopSearchTable topSearchTable) { - try { - List topSearchTableList = topSearchTableDao.selectTopSearchTableList(topSearchTable); - if (topSearchTableList.size() > 0) { - return new ServerResult<>(true, topSearchTableList); - } else { - return new ServerResult<>(false, ReturnConstants.RESULT_EMPTY); - } - } catch (RuntimeException e) { - logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR, e); + @Transactional(propagation = Propagation.SUPPORTS) + public Result> selectTopSearchTableList(TopSearchTable topSearchTable) { + List topSearchTableList = topSearchTableDao.selectTopSearchTableList(topSearchTable); + if (topSearchTableList.size() > 0) { + return Result.ok(topSearchTableList); + } else { + return Result.info(ReturnConstants.RESULT_EMPTY); } } @Override - public ServerResult> selectTopSearchTableInfo() { - try { - List tableList = topSearchTableDao.selectTopSearchTableInfo(); - return new ServerResult<>(true, tableList); - } catch (RuntimeException e) { - logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR, e); - } + @Transactional(propagation = Propagation.SUPPORTS) + public Result> selectTopSearchTableInfo() { + List tableList = topSearchTableDao.selectTopSearchTableInfo(); + return Result.ok(tableList); } public List selectTableColumns(Long id) { @@ -111,24 +101,15 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { * @param topSearchTable top万能查询主 * @return 结果 */ - @Transactional @Override - public ServerResult insertTopSearchTable(TopSearchTable topSearchTable) { - try { - topSearchTable.setCreateBy(SecurityUtils.getUserId()); - int renewal = topSearchTableDao.insertTopSearchTable(topSearchTable); - if (insertTopSearchColumn(topSearchTable)) { - return new ServerResult<>(false, ReturnConstants.DB_EX); - } - 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); + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + public Result insertTopSearchTable(TopSearchTable topSearchTable) { + topSearchTable.setCreateBy(SecurityUtils.getUserId()); + topSearchTableDao.insertTopSearchTable(topSearchTable); + if (insertTopSearchColumn(topSearchTable)) { + return Result.error(ReturnConstants.SYS_FAILL); } + return Result.ok(); } /** @@ -137,40 +118,28 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { * @param topSearchTable top万能查询主 * @return 结果 */ - @Transactional @Override - public ServerResult updateTopSearchTable(TopSearchTable topSearchTable) { - try { - topSearchTable.setUpdateBy(SecurityUtils.getUserId()); - topSearchTableDao.deleteTopSearchColumnBySearchTableId(topSearchTable.getId()); - if (insertTopSearchColumn(topSearchTable)) { - return new ServerResult<>(false, ReturnConstants.DB_EX); - } - List searchTableRoles = new ArrayList<>(); - for (Long roleId : topSearchTable.getRoleIds()) { - searchTableRoles.add(new SearchTableRole(topSearchTable.getId(), roleId)); - } - relationalMapDao.deleteRelationalMapById(topSearchTable.getId()); - List 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); + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + public Result updateTopSearchTable(TopSearchTable topSearchTable) { + topSearchTable.setUpdateBy(SecurityUtils.getUserId()); + topSearchTableDao.deleteTopSearchColumnBySearchTableId(topSearchTable.getId()); + insertTopSearchColumn(topSearchTable); + List searchTableRoles = new ArrayList<>(); + for (Long roleId : topSearchTable.getRoleIds()) { + searchTableRoles.add(new SearchTableRole(topSearchTable.getId(), roleId)); } + relationalMapDao.deleteRelationalMapById(topSearchTable.getId()); + List 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){ // try { @@ -180,15 +149,6 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { // } // } - @Override - public List selectDbTableListByNames(String[] tableNames) { - try { - return topSearchTableDao.selectDbTableListByNames(tableNames); - } catch (RuntimeException e) { - logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR, e); - } - } @Override public List> selectDbTableList(Map params) { @@ -201,29 +161,24 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { } @Override - @Transactional(rollbackFor = Exception.class) - public void importGenTable(List tableList) { - try { - Long createBy = SecurityUtils.getUserId(); - for (TopSearchTable table : tableList) { - String tableName = table.getTableName(); - table.setCreateBy(createBy); - int row = topSearchTableDao.insertTopSearchTable(table); - if (row > 0) { - List searchColumns = topSearchTableDao.selectDbTableColumnsByName(tableName); - for (TopSearchColumn searchColumn : searchColumns) { - searchColumn.setSearchTableId(table.getId()); - } - if (searchColumns.size() > 0) { - topSearchTableDao.batchTopSearchColumn(searchColumns); - } + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + public void importGenTable(String[] tableNames) { + List tableList = topSearchTableDao.selectDbTableListByNames(tableNames); + Long createBy = SecurityUtils.getUserId(); + for (TopSearchTable table : tableList) { + String tableName = table.getTableName(); + table.setCreateBy(createBy); + int row = topSearchTableDao.insertTopSearchTable(table); + if (row > 0) { + List searchColumns = topSearchTableDao.selectDbTableColumnsByName(tableName); + for (TopSearchColumn searchColumn : searchColumns) { + searchColumn.setSearchTableId(table.getId()); + } + if (searchColumns.size() > 0) { + 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 @Override - public ServerResult deleteTopSearchTableByIds(Long[] ids) { - try { - //批量删除子表数据 - topSearchTableDao.deleteTopSearchColumnBySearchTableIds(ids); - searchTableRoleDao.deleteSearchTableRoleByIds(ids); - Integer renewal = topSearchTableDao.deleteTopSearchTableByIds(ids); - 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); - } + public Result deleteTopSearchTableByIds(Long[] ids) { + //批量删除子表数据 + topSearchTableDao.deleteTopSearchColumnBySearchTableIds(ids); + searchTableRoleDao.deleteSearchTableRoleByIds(ids); + topSearchTableDao.deleteTopSearchTableByIds(ids); + return Result.ok(); } /** @@ -274,24 +220,20 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { } } + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public boolean inserTopTableRole(List roleList) { if (StringUtils.isNotNull(roleList)) { - Integer renewal = searchTableRoleDao.batchSearchTableRole(roleList); - if (renewal > 0) { - return true; - } + searchTableRoleDao.batchSearchTableRole(roleList); } - return false; + return true; } + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public boolean insertRelationalMap(List relationalMaps) { if (StringUtils.isNotNull(relationalMaps) && relationalMaps.size() > 0) { - Integer renewal = relationalMapDao.batchRelationalMap(relationalMaps); - if (renewal > 0) { - return true; - } + relationalMapDao.batchRelationalMap(relationalMaps); } - return false; + return true; } /** @@ -299,6 +241,7 @@ public class TopSearchTableServiceImpl implements TopSearchTableService { * * @param topSearchTable top万能查询主对象 */ + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public boolean insertTopSearchColumn(TopSearchTable topSearchTable) { List topSearchColumnList = topSearchTable.getTopSearchColumnList(); Long id = topSearchTable.getId(); diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/UniQueryServiceImpl.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/UniQueryServiceImpl.java index 4db111e..4d181ff 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/UniQueryServiceImpl.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/UniQueryServiceImpl.java @@ -3,6 +3,7 @@ package com.ebts.generator.service.impl; import java.util.List; import com.ebts.common.constant.ReturnConstants; +import com.ebts.common.core.entity.Result; import com.ebts.common.exception.EbtsException; import com.ebts.common.utils.SecurityUtils; import com.ebts.common.utils.ServerResult; @@ -36,17 +37,13 @@ public class UniQueryServiceImpl implements UniQueryService { * @return 万能查询 */ @Override - public ServerResult selectUniQueryById(Long id) { - try { - UniQuery uniQuery = uniQueryDao.selectUniQueryById(id); - if (uniQuery != null) { - return new ServerResult(true, uniQuery); - } else { - return new ServerResult(false, ReturnConstants.RESULT_EMPTY); - } - } catch (RuntimeException e) { - logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR,e); + public Result selectUniQueryById(Long id) { + UniQuery uniQuery = uniQueryDao.selectUniQueryById(id); + System.out.println(1/0); + if (uniQuery != null) { + return Result.ok(uniQuery); + } else { + return Result.info(ReturnConstants.RESULT_EMPTY); } } @@ -57,17 +54,12 @@ public class UniQueryServiceImpl implements UniQueryService { * @return 万能查询 */ @Override - public ServerResult> selectUniQueryList(UniQuery uniQuery) { - try { - List uniQueryList = uniQueryDao.selectUniQueryList(uniQuery); - if (uniQueryList.size() > 0) { - return new ServerResult>(true, uniQueryList); - } else { - return new ServerResult>(false, ReturnConstants.RESULT_EMPTY); - } - } catch (RuntimeException e) { - logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR,e); + public Result> selectUniQueryList(UniQuery uniQuery) { + List uniQueryList = uniQueryDao.selectUniQueryList(uniQuery); + if (uniQueryList.size() > 0) { + return Result.ok(uniQueryList); + } else { + return Result.info(ReturnConstants.RESULT_EMPTY); } } @@ -78,19 +70,10 @@ public class UniQueryServiceImpl implements UniQueryService { * @return 结果 */ @Override - public ServerResult insertUniQuery(UniQuery uniQuery) { - try { - uniQuery.setCreateBy(SecurityUtils.getUserId()); - Integer renewal = uniQueryDao.insertUniQuery(uniQuery); - 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); - } + public Result insertUniQuery(UniQuery uniQuery) { + uniQuery.setCreateBy(SecurityUtils.getUserId()); + uniQueryDao.insertUniQuery(uniQuery); + return Result.ok(); } /** @@ -100,19 +83,10 @@ public class UniQueryServiceImpl implements UniQueryService { * @return 结果 */ @Override - public ServerResult updateUniQuery(UniQuery uniQuery) { - try { - uniQuery.setUpdateBy(SecurityUtils.getUserId()); - Integer renewal = uniQueryDao.updateUniQuery(uniQuery); - 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); - } + public Result updateUniQuery(UniQuery uniQuery) { + uniQuery.setUpdateBy(SecurityUtils.getUserId()); + uniQueryDao.updateUniQuery(uniQuery); + return Result.ok(); } /** @@ -123,22 +97,10 @@ public class UniQueryServiceImpl implements UniQueryService { */ @Override @Transactional(rollbackFor = Exception.class) - public ServerResult deleteUniQueryByIds(Long[] ids) { - try { - Integer renewal = uniQueryDao.deleteUniQueryByIds(ids); - for (Long id : ids) { - 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); - } + public Result deleteUniQueryByIds(Long[] ids) { + uniQueryDao.deleteUniQueryByIds(ids); + uniQueryDao.deleteUniQueryByUqIds(ids); + return Result.ok(); } /** @@ -149,18 +111,9 @@ public class UniQueryServiceImpl implements UniQueryService { */ @Override @Transactional(rollbackFor = Exception.class) - public ServerResult deleteUniQueryById(Long id) { - try { - Integer renewal = uniQueryDao.deleteUniQueryById(id); - uniQueryDao.deleteUniQueryByUqId(id); - 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); - } + public Result deleteUniQueryById(Long id) { + uniQueryDao.deleteUniQueryById(id); + uniQueryDao.deleteUniQueryByUqId(id); + return Result.ok(); } } \ No newline at end of file diff --git a/ebts/ebts-generator/src/main/resources/mapper/generator/UniQueryMapper.xml b/ebts/ebts-generator/src/main/resources/mapper/generator/UniQueryMapper.xml index 4d2e61d..f90351f 100644 --- a/ebts/ebts-generator/src/main/resources/mapper/generator/UniQueryMapper.xml +++ b/ebts/ebts-generator/src/main/resources/mapper/generator/UniQueryMapper.xml @@ -79,7 +79,14 @@ - delete from gen_uni_con where uq_id = #{id} + delete from gen_uni_con where uq_id in #{id} + + + + delete from gen_uni_con where uq_id in + + #{id} +