| | |
| | | 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; |
| | |
| | | |
| | | /** |
| | | * 字典管理 |
| | | * @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); |
| | | } |
| | | } |
| | | } |