From 0841189aa3e92f0d3d0263ba1923a5c2e88a0b42 Mon Sep 17 00:00:00 2001 From: sws <15810472099@163.com> Date: 星期二, 27 九月 2022 14:32:18 +0800 Subject: [PATCH] 11 --- src/main/java/com/lf/server/controller/data/DictController.java | 215 ++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 162 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/lf/server/controller/data/DictController.java b/src/main/java/com/lf/server/controller/data/DictController.java index c61167f..c4ad7af 100644 --- a/src/main/java/com/lf/server/controller/data/DictController.java +++ b/src/main/java/com/lf/server/controller/data/DictController.java @@ -1,6 +1,8 @@ package com.lf.server.controller.data; +import com.lf.server.controller.BaseController; +import com.lf.server.entity.all.ResponseMsg; import com.lf.server.entity.data.DictEntity; import com.lf.server.service.data.DictService; import io.swagger.annotations.Api; @@ -14,87 +16,194 @@ /** * 瀛楀吀绠$悊 - * @author sws + * @author SWS + WWW * @date 2022-09.26 */ -@Api(tags = "DictController", description = "瀛楀吀绠$悊") +@Api(tags = "瀛楀吀绠$悊") @RestController -@RequestMapping("/Dict") -public class DictController { +@RequestMapping("/dict") +public class DictController extends BaseController { @Autowired DictService dictService; - @ApiOperation(value = "鏌ヨ璁板綍鏁�", notes = "鏌ヨ璁板綍鏁�") + @ApiOperation(value = "鏌ヨ璁板綍鏁�") @ApiImplicitParams({ @ApiImplicitParam(name = "tab", value = "琛ㄥ悕", dataType = "String", paramType = "query", required = false, example = "sys_dict") }) @GetMapping({"/selectCount"}) - public Integer selectCount(String tab) { - return dictService.selectCount(tab); + public ResponseMsg<Integer> selectCount(String tab) { + try { + int count = dictService.selectCount(tab); + + return success(count); + } catch (Exception ex) { + return fail(ex.getMessage(), -1); + } } - @ApiOperation(value = "鍒嗛〉鏌ヨ", notes = "鍒嗛〉鏌ヨ") + @ApiOperation(value = "鍒嗛〉鏌ヨ") @ApiImplicitParams({ - @ApiImplicitParam(name = "tab", value = "琛ㄥ悕", dataType = "String", paramType = "query", required = false, example = "sys_dict"), - @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", required = false, example = "10"), - @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉绱㈠紩锛堜粠0寮�濮嬶級", dataType = "Integer", paramType = "query", required = false, example = "0") + @ApiImplicitParam(name = "tab", value = "琛ㄥ悕", dataType = "String", paramType = "query", example = "sys_dict"), + @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), + @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉绱㈠紩锛堜粠0寮�濮嬶級", dataType = "Integer", paramType = "query", example = "0") }) @GetMapping(value = "/selectByPage") - public List<DictEntity> selectByPage(String tab, Integer pageSize, Integer pageIndex) { - if (pageSize < 1 || pageIndex < 0) { - return null; - } + public ResponseMsg<List<DictEntity>> selectByPage(String tab, Integer pageSize, Integer pageIndex) { + try { + if (pageSize < 1 || pageIndex < 0) { + return fail("鍒嗛〉鏁板皬浜�1鎴栧垎椤电储寮曞皬浜�0", null); + } - return dictService.selectByPage(tab, pageSize, pageSize * pageIndex); - } + List<DictEntity> rs = dictService.selectByPage(tab, pageSize, pageSize * pageIndex); - @RequestMapping(value = "/insertDict", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") - public Integer insertDict(DictEntity dictEntity) { - - return dictService.insertDict(dictEntity); - } - - @RequestMapping(value = "/insertDicts", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") - public Integer insertDicts(@RequestBody List<DictEntity> dictEntity) { - - return dictService.insertDicts(dictEntity); - } - - @ResponseBody - @RequestMapping(value = "/deleteDict", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") - public Integer deleteStyle(int id) { - return dictService.deleteDict(id); - } - - - @RequestMapping(value = "/deleteDicts", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") - public Integer deleteDicts(@RequestBody List<Integer> ids) { - if (!ids.isEmpty()) { - return dictService.deleteDicts(ids); - } else { - return -1; + return success(rs); + } catch (Exception ex) { + return fail(ex.getMessage(), null); } } - @ResponseBody - @RequestMapping(value = "/updateDict", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") - public Integer updateDict(DictEntity dictEntity) { - return dictService.updateDict(dictEntity); + @ApiOperation(value = "鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟") + @ApiImplicitParams({ + @ApiImplicitParam(name = "tab", value = "琛ㄥ悕", dataType = "String", paramType = "query", example = "sys_dict"), + @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), + @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉绱㈠紩锛堜粠0寮�濮嬶級", dataType = "Integer", paramType = "query", example = "0") + }) + @GetMapping(value = "/selectByPageAndCount") + public ResponseMsg<List<DictEntity>> selectByPageAndCount(String tab, Integer pageSize, Integer pageIndex) { + try { + if (pageSize < 1 || pageIndex < 0) { + return fail("鍒嗛〉鏁板皬浜�1鎴栧垎椤电储寮曞皬浜�0", null); + } + + int count = dictService.selectCount(tab); + if (count == 0) { + return success(0, null); + } + + List<DictEntity> rs = dictService.selectByPage(tab, pageSize, pageSize * pageIndex); + + return success(count, rs); + } catch (Exception ex) { + return fail(ex.getMessage(), null); + } } + @ApiOperation(value = "鎻掑叆瀛楀吀") + @ApiImplicitParams({ + @ApiImplicitParam(name = "dictEntity", value = "瀛楀吀瀹炰綋绫�", dataType = "com.lf.server.entity.data.DictEntity", paramType = "body", example = "") + }) + @PostMapping(value = "/insertDict", produces = "application/json; charset=UTF-8") + public ResponseMsg<Integer> insertDict(DictEntity dictEntity) { + try { + int count = dictService.insertDict(dictEntity); + + return success(count); + } catch (Exception ex) { + return fail(ex.getMessage(), -1); + } + } + + @ApiOperation(value = "鎻掑叆澶氭潯瀛楀吀") + @ApiImplicitParams({ + @ApiImplicitParam(name = "dictEntity", value = "瀛楀吀瀹炰綋绫婚泦鍚�", dataType = "List<DictEntity>", paramType = "body", example = "") + }) + @PostMapping(value = "/insertDicts", produces = "application/json; charset=UTF-8") + public ResponseMsg<Integer> insertDicts(@RequestBody List<DictEntity> dictEntity) { + try { + int count = dictService.insertDicts(dictEntity); + + return success(count); + } catch (Exception ex) { + return fail(ex.getMessage(), -1); + } + } + + @ApiOperation(value = "鍒犻櫎涓�鏉″瓧鍏�") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "瀛楀吀ID", dataType = "Integer", paramType = "query", example = "1") + }) + @GetMapping(value = "/deleteDict") + public ResponseMsg<Integer> deleteDict(int id) { + try { + int count = dictService.deleteDict(id); + + return success(count); + } catch (Exception ex) { + return fail(ex.getMessage(), -1); + } + } + + @ApiOperation(value = "鍒犻櫎澶氭潯瀛楀吀") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "瀛楀吀ID闆嗗悎", dataType = "List<Integer>", paramType = "query", example = "1,2") + }) + @GetMapping(value = "/deleteDicts") + public ResponseMsg<Integer> deleteDicts(List<Integer> ids) { + try { + if (ids == null || ids.isEmpty()) { + return fail("id鏁扮粍涓嶈兘涓虹┖", -1); + } + + int count = dictService.deleteDicts(ids); + + return success(count); + } catch (Exception ex) { + return fail(ex.getMessage(), -1); + } + } + + @ApiOperation(value = "鏇存柊涓�鏉″瓧鍏�") + @ApiImplicitParams({ + @ApiImplicitParam(name = "dictEntity", value = "瀛楀吀ID闆嗗悎", dataType = "DictEntity", paramType = "body", example = "") + }) + @ResponseBody + @PostMapping(value = "/updateDict", produces = "application/json; charset=UTF-8") + public ResponseMsg<Integer> updateDict(DictEntity dictEntity) { + try { + int count = dictService.updateDict(dictEntity); + + return success(count); + } catch (Exception ex) { + return fail(ex.getMessage(), -1); + } + } + + @ApiOperation(value = "鏍规嵁ID鏌ヨ瀛楀吀") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "瀛楀吀ID", dataType = "Integer", paramType = "query", example = "1") + }) @GetMapping(value = "/selectDict") - public DictEntity selectDict(int id) { - return dictService.selectDict(id); + public ResponseMsg<DictEntity> selectDict(int id) { + try { + DictEntity de = dictService.selectDict(id); + + return success(de); + } catch (Exception ex) { + return fail(ex.getMessage(), null); + } } + @ApiOperation(value = "鏌ヨ鎵�鏈夊瓧鍏�") @GetMapping(value = "/selectDictAll") - public List<DictEntity> selectDictAll() { - return dictService.selectDictAll(); + public ResponseMsg<List<DictEntity>> selectDictAll() { + try { + List<DictEntity> list = dictService.selectDictAll(); + + return success(list); + } catch (Exception ex) { + return fail(ex.getMessage(), null); + } } - + @ApiOperation(value = "鏌ヨ瀛楀吀涓殑鎵�鏈夎〃鍚�") @GetMapping(value = "/selectDictTab") - public List<DictEntity> selectDictTab() { - return dictService.selectDictTab(); + public ResponseMsg<List<DictEntity>> selectDictTab() { + try { + List<DictEntity> list = dictService.selectDictTab(); + + return success(list); + } catch (Exception ex) { + return fail(ex.getMessage(), null); + } } } -- Gitblit v1.9.3