From a4bb6696f25b2aa6eb4813a969aa4fc69b2d5fc1 Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Thu, 4 Jun 2020 23:21:09 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E5=85=B8=E6=A0=87=E7=AD=BE=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/DictDataController.java | 61 +++++++++++++++++-- .../system/controller/DictTypeController.java | 25 +++++--- .../system/controller/MenuController.java | 2 +- .../system/controller/RoleController.java | 3 +- .../system/controller/UserController.java | 3 +- .../wayn/project/system/domain/SysDict.java | 4 +- .../project/system/mapper/DictMapper.java | 4 ++ .../project/system/service/IDictService.java | 12 ++-- .../system/service/impl/DictServiceImpl.java | 26 ++++++-- .../resources/mapper/system/DictMapper.xml | 22 +++++++ 10 files changed, 135 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/wayn/project/system/controller/DictDataController.java b/src/main/java/com/wayn/project/system/controller/DictDataController.java index 293c01f..fc95938 100644 --- a/src/main/java/com/wayn/project/system/controller/DictDataController.java +++ b/src/main/java/com/wayn/project/system/controller/DictDataController.java @@ -3,18 +3,19 @@ package com.wayn.project.system.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.wayn.common.base.BaseController; +import com.wayn.common.constant.SysConstants; import com.wayn.common.util.R; +import com.wayn.common.util.SecurityUtils; import com.wayn.project.system.domain.SysDict; import com.wayn.project.system.service.IDictService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; @@ -28,17 +29,67 @@ public class DictDataController extends BaseController { @PreAuthorize("@ss.hasPermi('system:dict:list')") - @ApiOperation(value = "字典数据列表", notes = "字典数据列表") + @ApiOperation(value = "字典数据分页", notes = "字典数据分页") @GetMapping("/list") public R list(SysDict dict) { Page page = getPage(); return R.success().add("page", iDictService.listDictDataPage(page, dict)); } + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @ApiOperation(value = "字典类型列表", notes = "字典类型列表") + @GetMapping("/selectTypeList") + public R selectTypeList() { + List typeList = iDictService.list(new QueryWrapper().eq("type", 1)); + return R.success().add("typeList", typeList); + } + @GetMapping("/type/{parentType}") public R dictType(@PathVariable String parentType) { List dicts = iDictService.list(new QueryWrapper().eq("type", 2).eq("parent_type", parentType)); return R.success().add("data", dicts); } + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @ApiOperation(value = "保存字典数据", notes = "保存字典数据") + @PostMapping + public R addDict(@Validated @RequestBody SysDict dict) { + if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) { + return R.error("新增标签名'" + dict.getName() + "'失败,标签名已存在"); + } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) { + return R.error("新增标签值'" + dict.getValue() + "'失败,标签值已存在"); + } + dict.setCreateBy(SecurityUtils.getUsername()); + dict.setCreateTime(new Date()); + return R.result(iDictService.save(dict)); + } + + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @ApiOperation(value = "保存字典数据", notes = "保存字典数据") + @PutMapping + public R updateDict(@Validated @RequestBody SysDict dict) { + if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) { + return R.error("更新标签名'" + dict.getName() + "'失败,标签名已存在"); + } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) { + return R.error("更新标签值'" + dict.getValue() + "'失败,标签值已存在"); + } + dict.setUpdateBy(SecurityUtils.getUsername()); + dict.setUpdateTime(new Date()); + return R.result(iDictService.updateById(dict)); + } + + @PreAuthorize("@ss.hasPermi('system:dict:query')") + @ApiOperation(value = "获取字典数据详细", notes = "获取字典数据详细") + @GetMapping("{dictId}") + public R getDict(@PathVariable Long dictId) { + return R.success().add("data", iDictService.getById(dictId)); + } + + @PreAuthorize("@ss.hasPermi('system:dict:delete')") + @ApiOperation(value = "删除字典数据", notes = "删除字典数据") + @DeleteMapping("{dictId}") + public R deleteDict(@PathVariable Long dictId) { + return R.result(iDictService.removeById(dictId)); + } + } diff --git a/src/main/java/com/wayn/project/system/controller/DictTypeController.java b/src/main/java/com/wayn/project/system/controller/DictTypeController.java index b3be42c..8aa69f7 100644 --- a/src/main/java/com/wayn/project/system/controller/DictTypeController.java +++ b/src/main/java/com/wayn/project/system/controller/DictTypeController.java @@ -5,6 +5,7 @@ import com.wayn.common.base.BaseController; import com.wayn.common.constant.SysConstants; import com.wayn.common.util.R; import com.wayn.common.util.SecurityUtils; +import com.wayn.common.util.excel.ExcelUtil; import com.wayn.project.system.domain.SysDict; import com.wayn.project.system.service.IDictService; import io.swagger.annotations.Api; @@ -15,6 +16,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.Date; +import java.util.List; @Api("字典类型接口") @@ -27,7 +29,7 @@ public class DictTypeController extends BaseController { @PreAuthorize("@ss.hasPermi('system:dict:list')") - @ApiOperation(value = "字典类型列表", notes = "字典类型列表") + @ApiOperation(value = "字典类型分页", notes = "字典类型分页") @GetMapping("/list") public R list(SysDict dict) { Page page = getPage(); @@ -39,9 +41,9 @@ public class DictTypeController extends BaseController { @ApiOperation(value = "保存字典类型", notes = "保存字典类型") @PostMapping public R addDict(@Validated @RequestBody SysDict dict) { - if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeNameUnique(dict))) { + if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) { return R.error("新增字典名称'" + dict.getName() + "'失败,字典名称已存在"); - } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeValueUnique(dict))) { + } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) { return R.error("新增字典类型'" + dict.getValue() + "'失败,字典类型已存在"); } dict.setCreateBy(SecurityUtils.getUsername()); @@ -53,9 +55,9 @@ public class DictTypeController extends BaseController { @ApiOperation(value = "更新字典类型", notes = "更新字典类型") @PutMapping public R updateDict(@Validated @RequestBody SysDict dict) { - if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeNameUnique(dict))) { + if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) { return R.error("更新字典名称'" + dict.getName() + "'失败,字典名称已存在"); - } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeValueUnique(dict))) { + } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) { return R.error("更新字典类型'" + dict.getValue() + "'失败,字典类型已存在"); } dict.setUpdateBy(SecurityUtils.getUsername()); @@ -66,7 +68,7 @@ public class DictTypeController extends BaseController { @PreAuthorize("@ss.hasPermi('system:dict:query')") @ApiOperation(value = "获取字典类型详细", notes = "获取字典类型详细") @GetMapping("{dictId}") - public R getDept(@PathVariable Long dictId) { + public R getDict(@PathVariable Long dictId) { return R.success().add("data", iDictService.getById(dictId)); } @@ -74,6 +76,15 @@ public class DictTypeController extends BaseController { @ApiOperation(value = "删除字典类型", notes = "删除字典类型") @DeleteMapping("{dictId}") public R deleteDict(@PathVariable Long dictId) { - return R.success().add("data", iDictService.removeById(dictId)); +// return R.result(iDictService.removeById(dictId)); + return R.success(); + } + + + @PreAuthorize("@ss.hasPermi('system:dict:export')") + @GetMapping("/export") + public R export(SysDict dict) { + List list = iDictService.list(dict); + return R.success(ExcelUtil.exportExcel(list, SysDict.class, "字典数据.xls")); } } diff --git a/src/main/java/com/wayn/project/system/controller/MenuController.java b/src/main/java/com/wayn/project/system/controller/MenuController.java index 19a88fe..dd400b1 100644 --- a/src/main/java/com/wayn/project/system/controller/MenuController.java +++ b/src/main/java/com/wayn/project/system/controller/MenuController.java @@ -105,6 +105,6 @@ public class MenuController extends BaseController { if (iMenuService.checkMenuExistRole(menuId)) { return R.error("菜单已分配,不允许删除"); } - return R.success().add("data", iMenuService.removeById(menuId)); + return R.result(iMenuService.removeById(menuId)); } } diff --git a/src/main/java/com/wayn/project/system/controller/RoleController.java b/src/main/java/com/wayn/project/system/controller/RoleController.java index 7369a99..f54324a 100644 --- a/src/main/java/com/wayn/project/system/controller/RoleController.java +++ b/src/main/java/com/wayn/project/system/controller/RoleController.java @@ -85,8 +85,7 @@ public class RoleController extends BaseController { @ApiOperation("删除角色") @DeleteMapping("/{roleIds}") public R deleteRole(@PathVariable List roleIds) { - iRoleService.deleteRoleByIds(roleIds); - return R.success(); + return R.result(iRoleService.deleteRoleByIds(roleIds)); } @PreAuthorize("@ss.hasPermi('system:role:export')") diff --git a/src/main/java/com/wayn/project/system/controller/UserController.java b/src/main/java/com/wayn/project/system/controller/UserController.java index 0d0d813..f25ff35 100644 --- a/src/main/java/com/wayn/project/system/controller/UserController.java +++ b/src/main/java/com/wayn/project/system/controller/UserController.java @@ -111,8 +111,7 @@ public class UserController extends BaseController { @ApiOperation("删除用户") @DeleteMapping("/{userIds}") public R deleteUser(@PathVariable List userIds) { - iUserService.removeByIds(userIds); - return R.success(); + return R.result(iUserService.removeByIds(userIds)); } @PreAuthorize("@ss.hasPermi('system:user:export')") diff --git a/src/main/java/com/wayn/project/system/domain/SysDict.java b/src/main/java/com/wayn/project/system/domain/SysDict.java index 5e67e23..2336568 100644 --- a/src/main/java/com/wayn/project/system/domain/SysDict.java +++ b/src/main/java/com/wayn/project/system/domain/SysDict.java @@ -35,8 +35,8 @@ public class SysDict extends BaseEntity implements Serializable { /** * 字典值 */ - @NotBlank(message = "字典值不能为空") - @Excel(name = "字典值") + @NotBlank(message = "字典类型不能为空") + @Excel(name = "字典类型") private String value; /** diff --git a/src/main/java/com/wayn/project/system/mapper/DictMapper.java b/src/main/java/com/wayn/project/system/mapper/DictMapper.java index 21192ee..cb6a7d0 100644 --- a/src/main/java/com/wayn/project/system/mapper/DictMapper.java +++ b/src/main/java/com/wayn/project/system/mapper/DictMapper.java @@ -5,9 +5,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.wayn.project.system.domain.SysDict; +import java.util.List; + public interface DictMapper extends BaseMapper { IPage selectDictTypeListPage(Page page, SysDict dict); IPage selectDictDataListPage(Page page, SysDict dict); + + List selectDictTypeList(SysDict dict); } diff --git a/src/main/java/com/wayn/project/system/service/IDictService.java b/src/main/java/com/wayn/project/system/service/IDictService.java index f7b1ed2..8dccf29 100644 --- a/src/main/java/com/wayn/project/system/service/IDictService.java +++ b/src/main/java/com/wayn/project/system/service/IDictService.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.wayn.project.system.domain.SysDict; +import java.util.List; + public interface IDictService extends IService { /** @@ -26,19 +28,21 @@ public interface IDictService extends IService { IPage listDictDataPage(Page page, SysDict dict); /** - * 校验字典名称是否唯一 + * 校验字典name是否唯一 * * @param dict 字典类型 * @return 结果 */ - String checkDictTypeNameUnique(SysDict dict); + String checkDictNameUnique(SysDict dict); /** - * 校验字典类型称是否唯一 + * 校验字典value是否唯一 * * @param dict 字典类型 * @return 结果 */ - String checkDictTypeValueUnique(SysDict dict); + String checkDictValueUnique(SysDict dict); + + List list(SysDict dict); } diff --git a/src/main/java/com/wayn/project/system/service/impl/DictServiceImpl.java b/src/main/java/com/wayn/project/system/service/impl/DictServiceImpl.java index 403627f..1ea4e8f 100644 --- a/src/main/java/com/wayn/project/system/service/impl/DictServiceImpl.java +++ b/src/main/java/com/wayn/project/system/service/impl/DictServiceImpl.java @@ -11,6 +11,7 @@ import com.wayn.project.system.service.IDictService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Objects; @Service @@ -30,9 +31,15 @@ public class DictServiceImpl extends ServiceImpl implements } @Override - public String checkDictTypeNameUnique(SysDict dict) { + public String checkDictNameUnique(SysDict dict) { long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId(); - SysDict sysDict = getOne(new QueryWrapper().eq("name", dict.getName()).eq("type", 1)); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (dict.getType() == 1) { + queryWrapper.eq("name", dict.getName()).eq("type", 1); + } else { + queryWrapper.eq("name", dict.getName()).eq("type", 2).eq("parent_type", dict.getParentType()); + } + SysDict sysDict = getOne(queryWrapper); if (sysDict != null && sysDict.getDictId() != dictId) { return SysConstants.NOT_UNIQUE; } @@ -40,12 +47,23 @@ public class DictServiceImpl extends ServiceImpl implements } @Override - public String checkDictTypeValueUnique(SysDict dict) { + public String checkDictValueUnique(SysDict dict) { long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId(); - SysDict sysDict = getOne(new QueryWrapper().eq("value", dict.getValue()).eq("type", 1)); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (dict.getType() == 1) { + queryWrapper.eq("value", dict.getValue()).eq("type", 1); + } else { + queryWrapper.eq("value", dict.getValue()).eq("type", 2).eq("parent_type", dict.getParentType()); + } + SysDict sysDict = getOne(queryWrapper); if (sysDict != null && sysDict.getDictId() != dictId) { return SysConstants.NOT_UNIQUE; } return SysConstants.UNIQUE; } + + @Override + public List list(SysDict dict) { + return dictMapper.selectDictTypeList(dict); + } } diff --git a/src/main/resources/mapper/system/DictMapper.xml b/src/main/resources/mapper/system/DictMapper.xml index e527ce4..3308f15 100644 --- a/src/main/resources/mapper/system/DictMapper.xml +++ b/src/main/resources/mapper/system/DictMapper.xml @@ -71,4 +71,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by d.sort + + \ No newline at end of file