From 0d9c4bae19aa045c6be17bcf91d8d4327d405bda Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Sun, 31 May 2020 22:21:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=97=E5=85=B8=E7=AE=A1=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/DictDataController.java | 43 +++++++++++ .../system/controller/DictTypeController.java | 72 +++++++++++++++++++ .../wayn/project/system/domain/SysDict.java | 66 +++++++++++++++++ .../project/system/mapper/DictMapper.java | 13 ++++ .../project/system/service/IDictService.java | 44 ++++++++++++ .../system/service/impl/DictServiceImpl.java | 51 +++++++++++++ .../resources/mapper/system/DeptMapper.xml | 2 +- .../resources/mapper/system/DictMapper.xml | 64 +++++++++++++++++ .../resources/mapper/system/RoleMapper.xml | 4 +- .../resources/mapper/system/UserMapper.xml | 4 +- 10 files changed, 358 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/wayn/project/system/controller/DictDataController.java create mode 100644 src/main/java/com/wayn/project/system/controller/DictTypeController.java create mode 100644 src/main/java/com/wayn/project/system/domain/SysDict.java create mode 100644 src/main/java/com/wayn/project/system/mapper/DictMapper.java create mode 100644 src/main/java/com/wayn/project/system/service/IDictService.java create mode 100644 src/main/java/com/wayn/project/system/service/impl/DictServiceImpl.java create mode 100644 src/main/resources/mapper/system/DictMapper.xml diff --git a/src/main/java/com/wayn/project/system/controller/DictDataController.java b/src/main/java/com/wayn/project/system/controller/DictDataController.java new file mode 100644 index 0000000..97b16bf --- /dev/null +++ b/src/main/java/com/wayn/project/system/controller/DictDataController.java @@ -0,0 +1,43 @@ +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.util.R; +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 java.util.List; + + +@Api("字典数据接口") +@RestController +@RequestMapping("system/dict/data") +public class DictDataController extends BaseController { + + @Autowired + private IDictService iDictService; + + + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @ApiOperation(value = "字典数据列表", notes = "字典数据列表") + @GetMapping("/list") + public R list(SysDict dict) { + Page page = getPage(); + return R.success().add("page", iDictService.listDictDataPage(page, dict)); + } + + @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); + } +} diff --git a/src/main/java/com/wayn/project/system/controller/DictTypeController.java b/src/main/java/com/wayn/project/system/controller/DictTypeController.java new file mode 100644 index 0000000..4908b34 --- /dev/null +++ b/src/main/java/com/wayn/project/system/controller/DictTypeController.java @@ -0,0 +1,72 @@ +package com.wayn.project.system.controller; + +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Date; + + +@Api("字典类型接口") +@RestController +@RequestMapping("system/dict/type") +public class DictTypeController extends BaseController { + + @Autowired + private IDictService iDictService; + + + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @ApiOperation(value = "字典类型列表", notes = "字典类型列表") + @GetMapping("/list") + public R list(SysDict dict) { + Page page = getPage(); + return R.success().add("page", iDictService.listDictTypePage(page, dict)); + } + + + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @ApiOperation(value = "保存字典类型", notes = "保存字典类型") + @PostMapping + public R addDict(@Validated @RequestBody SysDict dict) { + if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeNameUnique(dict))) { + return R.error("新增字典名称'" + dict.getName() + "'失败,字典名称已存在"); + }else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeValueUnique(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:update')") + @ApiOperation(value = "更新字典类型", notes = "更新字典类型") + @PutMapping + public R updateDict(@Validated @RequestBody SysDict dict) { + if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeNameUnique(dict))) { + return R.error("更新字典名称'" + dict.getName() + "'失败,字典名称已存在"); + }else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeValueUnique(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 getDept(@PathVariable Long dictId) { + return R.success().add("data", iDictService.getById(dictId)); + } +} diff --git a/src/main/java/com/wayn/project/system/domain/SysDict.java b/src/main/java/com/wayn/project/system/domain/SysDict.java new file mode 100644 index 0000000..5e67e23 --- /dev/null +++ b/src/main/java/com/wayn/project/system/domain/SysDict.java @@ -0,0 +1,66 @@ +package com.wayn.project.system.domain; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.wayn.common.base.BaseEntity; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +@Data +@ApiModel("角色实体") +@EqualsAndHashCode(callSuper = true) +public class SysDict extends BaseEntity implements Serializable { + private static final long serialVersionUID = -7521690041693138642L; + + /** + * 菜单ID + */ + @TableId(type = IdType.AUTO) + @Excel(name = "字典编号", type = 10) + private Long dictId; + + /** + * 字典名称 + */ + @NotBlank(message = "字典名称不能为空") + @Excel(name = "字典名称") + private String name; + + /** + * 字典值 + */ + @NotBlank(message = "字典值不能为空") + @Excel(name = "字典值") + private String value; + + /** + * 字典状态(0正常 1停用) + */ + @Excel(name = "字典状态", replace = {"启用_0", "禁用_1"}) + private Integer dictStatus; + + /** + * 字典类型(1字典类型 2类型数据) + */ + private Integer type; + + /** + * 字典排序 + */ + @DecimalMin(value = "0", message = "字典排序不能小于0") + @Excel(name = "字典排序", type = 10) + private Integer sort; + + private String parentType; + + /** + * 删除标志(0代表存在 2代表删除) + */ + private Integer delFlag; +} diff --git a/src/main/java/com/wayn/project/system/mapper/DictMapper.java b/src/main/java/com/wayn/project/system/mapper/DictMapper.java new file mode 100644 index 0000000..21192ee --- /dev/null +++ b/src/main/java/com/wayn/project/system/mapper/DictMapper.java @@ -0,0 +1,13 @@ +package com.wayn.project.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.wayn.project.system.domain.SysDict; + +public interface DictMapper extends BaseMapper { + + IPage selectDictTypeListPage(Page page, SysDict dict); + + IPage selectDictDataListPage(Page page, 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 new file mode 100644 index 0000000..f7b1ed2 --- /dev/null +++ b/src/main/java/com/wayn/project/system/service/IDictService.java @@ -0,0 +1,44 @@ +package com.wayn.project.system.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.wayn.project.system.domain.SysDict; + +public interface IDictService extends IService { + + /** + * 查询字典类型列表 + * + * @param page 分页对象 + * @param dict 查询参数 + * @return 字典类型列表 + */ + IPage listDictTypePage(Page page, SysDict dict); + + /** + * 查询字典数据列表 + * + * @param page 分页对象 + * @param dict 查询参数 + * @return 字典数据列表 + */ + IPage listDictDataPage(Page page, SysDict dict); + + /** + * 校验字典名称是否唯一 + * + * @param dict 字典类型 + * @return 结果 + */ + String checkDictTypeNameUnique(SysDict dict); + + + /** + * 校验字典类型称是否唯一 + * + * @param dict 字典类型 + * @return 结果 + */ + String checkDictTypeValueUnique(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 new file mode 100644 index 0000000..403627f --- /dev/null +++ b/src/main/java/com/wayn/project/system/service/impl/DictServiceImpl.java @@ -0,0 +1,51 @@ +package com.wayn.project.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.wayn.common.constant.SysConstants; +import com.wayn.project.system.domain.SysDict; +import com.wayn.project.system.mapper.DictMapper; +import com.wayn.project.system.service.IDictService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +@Service +public class DictServiceImpl extends ServiceImpl implements IDictService { + + @Autowired + private DictMapper dictMapper; + + @Override + public IPage listDictTypePage(Page page, SysDict dict) { + return dictMapper.selectDictTypeListPage(page, dict); + } + + @Override + public IPage listDictDataPage(Page page, SysDict dict) { + return dictMapper.selectDictDataListPage(page, dict); + } + + @Override + public String checkDictTypeNameUnique(SysDict dict) { + long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId(); + SysDict sysDict = getOne(new QueryWrapper().eq("name", dict.getName()).eq("type", 1)); + if (sysDict != null && sysDict.getDictId() != dictId) { + return SysConstants.NOT_UNIQUE; + } + return SysConstants.UNIQUE; + } + + @Override + public String checkDictTypeValueUnique(SysDict dict) { + long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId(); + SysDict sysDict = getOne(new QueryWrapper().eq("value", dict.getValue()).eq("type", 1)); + if (sysDict != null && sysDict.getDictId() != dictId) { + return SysConstants.NOT_UNIQUE; + } + return SysConstants.UNIQUE; + } +} diff --git a/src/main/resources/mapper/system/DeptMapper.xml b/src/main/resources/mapper/system/DeptMapper.xml index 55351b3..193a068 100644 --- a/src/main/resources/mapper/system/DeptMapper.xml +++ b/src/main/resources/mapper/system/DeptMapper.xml @@ -30,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + where d.del_flag = 0 + and d.type = 1 + + AND d.name like concat('%', #{dict.name}, '%') + + + AND d.value like concat('%', #{dict.value}, '%') + + + AND dict_status = #{dict.dictStatus} + + + and DATE_FORMAT(d.create_time,'%Y-%m-%d') = ]]> DATE_FORMAT(#{dict.startTime},'%Y-%m-%d') + + + and DATE_FORMAT(d.create_time,'%Y-%m-%d') DATE_FORMAT(#{dict.endTime},'%Y-%m-%d') + + order by d.sort + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/system/RoleMapper.xml b/src/main/resources/mapper/system/RoleMapper.xml index 500a38f..7188434 100644 --- a/src/main/resources/mapper/system/RoleMapper.xml +++ b/src/main/resources/mapper/system/RoleMapper.xml @@ -26,7 +26,7 @@ \ No newline at end of file diff --git a/src/main/resources/mapper/system/UserMapper.xml b/src/main/resources/mapper/system/UserMapper.xml index 5cbdc01..2b80530 100644 --- a/src/main/resources/mapper/system/UserMapper.xml +++ b/src/main/resources/mapper/system/UserMapper.xml @@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - where u.del_flag = '0' + where u.del_flag = 0 AND u.user_name like concat('%', #{userName}, '%')