feat(后台管理): 添加字典管理,优化逻辑字段
parent
9db6c7495a
commit
0d9c4bae19
@ -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<SysDict> page = getPage();
|
||||
return R.success().add("page", iDictService.listDictDataPage(page, dict));
|
||||
}
|
||||
|
||||
@GetMapping("/type/{parentType}")
|
||||
public R dictType(@PathVariable String parentType) {
|
||||
List<SysDict> dicts = iDictService.list(new QueryWrapper<SysDict>().eq("type", 2).eq("parent_type", parentType));
|
||||
return R.success().add("data", dicts);
|
||||
}
|
||||
}
|
@ -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<SysDict> 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));
|
||||
}
|
||||
}
|
@ -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<SysDict> {
|
||||
|
||||
IPage<SysDict> selectDictTypeListPage(Page<SysDict> page, SysDict dict);
|
||||
|
||||
IPage<SysDict> selectDictDataListPage(Page<SysDict> page, SysDict dict);
|
||||
}
|
@ -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<SysDict> {
|
||||
|
||||
/**
|
||||
* 查询字典类型列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param dict 查询参数
|
||||
* @return 字典类型列表
|
||||
*/
|
||||
IPage<SysDict> listDictTypePage(Page<SysDict> page, SysDict dict);
|
||||
|
||||
/**
|
||||
* 查询字典数据列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param dict 查询参数
|
||||
* @return 字典数据列表
|
||||
*/
|
||||
IPage<SysDict> listDictDataPage(Page<SysDict> page, SysDict dict);
|
||||
|
||||
/**
|
||||
* 校验字典名称是否唯一
|
||||
*
|
||||
* @param dict 字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
String checkDictTypeNameUnique(SysDict dict);
|
||||
|
||||
|
||||
/**
|
||||
* 校验字典类型称是否唯一
|
||||
*
|
||||
* @param dict 字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
String checkDictTypeValueUnique(SysDict dict);
|
||||
}
|
@ -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<DictMapper, SysDict> implements IDictService {
|
||||
|
||||
@Autowired
|
||||
private DictMapper dictMapper;
|
||||
|
||||
@Override
|
||||
public IPage<SysDict> listDictTypePage(Page<SysDict> page, SysDict dict) {
|
||||
return dictMapper.selectDictTypeListPage(page, dict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<SysDict> listDictDataPage(Page<SysDict> 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<SysDict>().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<SysDict>().eq("value", dict.getValue()).eq("type", 1));
|
||||
if (sysDict != null && sysDict.getDictId() != dictId) {
|
||||
return SysConstants.NOT_UNIQUE;
|
||||
}
|
||||
return SysConstants.UNIQUE;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.wayn.project.system.mapper.DictMapper">
|
||||
|
||||
<resultMap type="com.wayn.project.system.domain.SysDict" id="SysDictResult">
|
||||
<id property="dictId" column="dict_id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="value" column="value" />
|
||||
<result property="type" column="type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="dictStatus" column="dict_status" />
|
||||
<result property="parentType" column="parent_type" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDictVo">
|
||||
select d.dict_id, d.name, d.value, d.type, d.sort, d.dict_status, d.parent_type,
|
||||
d.del_flag, d.create_by, d.create_time, d.update_by, d.update_time, d.remark
|
||||
from sys_dict d
|
||||
</sql>
|
||||
|
||||
<select id="selectDictTypeListPage" parameterType="com.wayn.project.system.domain.SysDict" resultMap="SysDictResult">
|
||||
<include refid="selectDictVo"/>
|
||||
where d.del_flag = 0
|
||||
and d.type = 1
|
||||
<if test="dict.name != null and dict.name != ''">
|
||||
AND d.name like concat('%', #{dict.name}, '%')
|
||||
</if>
|
||||
<if test="dict.value != null and dict.value != ''">
|
||||
AND d.value like concat('%', #{dict.value}, '%')
|
||||
</if>
|
||||
<if test="dict.dictStatus != null">
|
||||
AND dict_status = #{dict.dictStatus}
|
||||
</if>
|
||||
<if test="dict.startTime != null and dict.startTime != ''">
|
||||
and DATE_FORMAT(d.create_time,'%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(#{dict.startTime},'%Y-%m-%d')
|
||||
</if>
|
||||
<if test="dict.endTime != null and dict.endTime != ''">
|
||||
and DATE_FORMAT(d.create_time,'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(#{dict.endTime},'%Y-%m-%d')
|
||||
</if>
|
||||
order by d.sort
|
||||
</select>
|
||||
|
||||
<select id="selectDictDataListPage" parameterType="com.wayn.project.system.domain.SysDict" resultMap="SysDictResult">
|
||||
<include refid="selectDictVo"/>
|
||||
where d.del_flag = 0
|
||||
and d.type = 2
|
||||
<if test="dict.name != null and dict.name != ''">
|
||||
AND dept_name like concat('%', #{dict.name}, '%')
|
||||
</if>
|
||||
<if test="dict.dictStatus != null">
|
||||
AND dict_status = #{dict.dictStatus}
|
||||
</if>
|
||||
order by d.sort
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue