feat(后台管理): 添加字典管理,优化逻辑字段

master
wayn 5 years ago
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,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;
}

@ -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;
}
}

@ -30,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDeptList" parameterType="com.wayn.project.system.domain.SysDept" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.del_flag = '0'
where d.del_flag = 0
<if test="parentId != null and parentId != 0">
AND parent_id = #{parentId}
</if>

@ -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>

@ -26,7 +26,7 @@
<select id="selectRoleByUserId" parameterType="Long" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and ur.user_id = #{userId}
WHERE r.del_flag = 0 and ur.user_id = #{userId}
</select>
<select id="selectRoleListByUserId" parameterType="Long" resultType="Integer">
@ -79,6 +79,6 @@
</select>
<select id="selectRolesByUserName" parameterType="string" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and u.user_name = #{userName}
WHERE r.del_flag = 0 and u.user_name = #{userName}
</select>
</mapper>

@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUserListPage" parameterType="com.wayn.project.system.domain.SysUser" resultMap="SysUserResult">
<include refid="selectUserVo"></include>
where u.del_flag = '0'
where u.del_flag = 0
<if test="user.userName != null and user.userName != ''">
AND u.user_name like concat('%', #{user.userName}, '%')
</if>
@ -65,7 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUserList" parameterType="com.wayn.project.system.domain.SysUser" resultMap="SysUserResult">
<include refid="selectUserVo"></include>
where u.del_flag = '0'
where u.del_flag = 0
<if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%')
</if>

Loading…
Cancel
Save