新增自定义数据校验

This commit is contained in:
RuoYi
2019-07-19 10:11:45 +08:00
parent 45738d4516
commit ed8f039106
22 changed files with 198 additions and 42 deletions

View File

@@ -512,7 +512,7 @@ create table sys_config (
config_id int(5) not null auto_increment comment '参数主键',
config_name varchar(100) default '' comment '参数名称',
config_key varchar(100) default '' comment '参数键名',
config_value varchar(100) default '' comment '参数键值',
config_value varchar(500) default '' comment '参数键值',
config_type char(1) default 'N' comment '系统内置Y是 N否',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',

View File

@@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -93,6 +94,17 @@ public class GlobalExceptionHandler
}
}
/**
* 自定义验证异常
*/
@ExceptionHandler(BindException.class)
public AjaxResult validatedBindException(BindException e)
{
log.error(e.getMessage(), e);
String message = e.getAllErrors().get(0).getDefaultMessage();
return AjaxResult.error(message);
}
/**
* 演示模式异常
*/

View File

@@ -6,6 +6,7 @@ import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -125,7 +126,7 @@ public class JobController extends BaseController
@RequiresPermissions("monitor:job:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Job job) throws SchedulerException, TaskException
public AjaxResult addSave(@Validated Job job) throws SchedulerException, TaskException
{
return toAjax(jobService.insertJob(job));
}
@@ -147,7 +148,7 @@ public class JobController extends BaseController
@RequiresPermissions("monitor:job:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Job job) throws SchedulerException, TaskException
public AjaxResult editSave(@Validated Job job) throws SchedulerException, TaskException
{
return toAjax(jobService.updateJob(job));
}

View File

@@ -2,6 +2,7 @@ package com.ruoyi.project.monitor.job.domain;
import java.io.Serializable;
import java.util.Date;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.constant.ScheduleConstants;
@@ -61,6 +62,8 @@ public class Job extends BaseEntity implements Serializable
this.jobId = jobId;
}
@NotBlank(message = "任务名称不能为空")
@Size(min = 0, max = 64, message = "任务名称不能超过64个字符")
public String getJobName()
{
return jobName;
@@ -81,6 +84,8 @@ public class Job extends BaseEntity implements Serializable
this.jobGroup = jobGroup;
}
@NotBlank(message = "调用目标字符串不能为空")
@Size(min = 0, max = 1000, message = "调用目标字符串长度不能超过500个字符")
public String getInvokeTarget()
{
return invokeTarget;
@@ -91,6 +96,8 @@ public class Job extends BaseEntity implements Serializable
this.invokeTarget = invokeTarget;
}
@NotBlank(message = "Cron执行表达式不能为空")
@Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符")
public String getCronExpression()
{
return cronExpression;

View File

@@ -5,11 +5,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
@@ -80,8 +82,12 @@ public class ConfigController extends BaseController
@Log(title = "参数管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Config config)
public AjaxResult addSave(@Validated Config config)
{
if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
return toAjax(configService.insertConfig(config));
}
@@ -102,8 +108,12 @@ public class ConfigController extends BaseController
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Config config)
public AjaxResult editSave(@Validated Config config)
{
if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
return toAjax(configService.updateConfig(config));
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.project.system.config.domain;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
@@ -44,6 +45,8 @@ public class Config extends BaseEntity
this.configId = configId;
}
@NotBlank(message = "参数名称不能为空")
@Size(min = 0, max = 100, message = "参数名称不能超过100个字符")
public String getConfigName()
{
return configName;
@@ -54,6 +57,8 @@ public class Config extends BaseEntity
this.configName = configName;
}
@NotBlank(message = "参数键名长度不能为空")
@Size(min = 0, max = 100, message = "参数键名长度不能超过100个字符")
public String getConfigKey()
{
return configKey;
@@ -64,6 +69,8 @@ public class Config extends BaseEntity
this.configKey = configKey;
}
@NotBlank(message = "参数键值不能为空")
@Size(min = 0, max = 500, message = "参数键值长度不能超过500个字符")
public String getConfigValue()
{
return configValue;

View File

@@ -5,11 +5,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
@@ -42,7 +44,7 @@ public class DeptController extends BaseController
}
@RequiresPermissions("system:dept:list")
@GetMapping("/list")
@PostMapping("/list")
@ResponseBody
public List<Dept> list(Dept dept)
{
@@ -67,8 +69,12 @@ public class DeptController extends BaseController
@RequiresPermissions("system:dept:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Dept dept)
public AjaxResult addSave(@Validated Dept dept)
{
if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
return toAjax(deptService.insertDept(dept));
}
@@ -94,8 +100,12 @@ public class DeptController extends BaseController
@RequiresPermissions("system:dept:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Dept dept)
public AjaxResult editSave(@Validated Dept dept)
{
if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
return toAjax(deptService.updateDept(dept));
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.project.system.dept.domain;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.web.domain.BaseEntity;
@@ -33,7 +34,7 @@ public class Dept extends BaseEntity
/** 联系电话 */
private String phone;
/** 邮箱 */
private String email;
@@ -76,6 +77,8 @@ public class Dept extends BaseEntity
this.ancestors = ancestors;
}
@NotBlank(message = "部门名称不能为空")
@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
public String getDeptName()
{
return deptName;
@@ -86,6 +89,7 @@ public class Dept extends BaseEntity
this.deptName = deptName;
}
@NotBlank(message = "显示顺序不能为空")
public String getOrderNum()
{
return orderNum;
@@ -106,6 +110,7 @@ public class Dept extends BaseEntity
this.leader = leader;
}
@Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
public String getPhone()
{
return phone;
@@ -116,6 +121,8 @@ public class Dept extends BaseEntity
this.phone = phone;
}
@Email(message = "邮箱格式不正确")
@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
public String getEmail()
{
return email;

View File

@@ -5,6 +5,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -78,7 +79,7 @@ public class DictDataController extends BaseController
@RequiresPermissions("system:dict:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(DictData dict)
public AjaxResult addSave(@Validated DictData dict)
{
return toAjax(dictDataService.insertDictData(dict));
}
@@ -100,7 +101,7 @@ public class DictDataController extends BaseController
@RequiresPermissions("system:dict:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(DictData dict)
public AjaxResult editSave(@Validated DictData dict)
{
return toAjax(dictDataService.updateDictData(dict));
}

View File

@@ -5,16 +5,19 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.domain.Ztree;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.dict.domain.DictType;
import com.ruoyi.project.system.dict.service.IDictTypeService;
@@ -78,8 +81,12 @@ public class DictTypeController extends BaseController
@RequiresPermissions("system:dict:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(DictType dict)
public AjaxResult addSave(@Validated DictType dict)
{
if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
{
return error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
return toAjax(dictTypeService.insertDictType(dict));
}
@@ -100,8 +107,12 @@ public class DictTypeController extends BaseController
@RequiresPermissions("system:dict:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(DictType dict)
public AjaxResult editSave(@Validated DictType dict)
{
if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
{
return error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
return toAjax(dictTypeService.updateDictType(dict));
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.project.system.dict.domain;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.constant.UserConstants;
@@ -35,7 +36,7 @@ public class DictData extends BaseEntity
@Excel(name = "字典类型")
private String dictType;
/** 字典样式 */
/** 样式属性(其他样式扩展) */
@Excel(name = "字典样式")
private String cssClass;
@@ -70,6 +71,8 @@ public class DictData extends BaseEntity
this.dictSort = dictSort;
}
@NotBlank(message = "字典标签不能为空")
@Size(min = 0, max = 100, message = "字典标签长度不能超过100个字符")
public String getDictLabel()
{
return dictLabel;
@@ -80,6 +83,8 @@ public class DictData extends BaseEntity
this.dictLabel = dictLabel;
}
@NotBlank(message = "字典键值不能为空")
@Size(min = 0, max = 100, message = "字典键值长度不能超过100个字符")
public String getDictValue()
{
return dictValue;
@@ -90,6 +95,8 @@ public class DictData extends BaseEntity
this.dictValue = dictValue;
}
@NotBlank(message = "字典类型不能为空")
@Size(min = 0, max = 100, message = "字典类型长度不能超过100个字符")
public String getDictType()
{
return dictType;
@@ -100,6 +107,7 @@ public class DictData extends BaseEntity
this.dictType = dictType;
}
@Size(min = 0, max = 100, message = "样式属性长度不能超过100个字符")
public String getCssClass()
{
return cssClass;
@@ -164,4 +172,4 @@ public class DictData extends BaseEntity
.append("remark", getRemark())
.toString();
}
}
}

View File

@@ -1,12 +1,13 @@
package com.ruoyi.project.system.dict.domain;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
/**
* 字典类型对象 sys_dict_type
* 字典类型 sys_dict_type
*
* @author ruoyi
*/
@@ -40,6 +41,8 @@ public class DictType extends BaseEntity
this.dictId = dictId;
}
@NotBlank(message = "字典名称不能为空")
@Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符")
public String getDictName()
{
return dictName;
@@ -50,6 +53,8 @@ public class DictType extends BaseEntity
this.dictName = dictName;
}
@NotBlank(message = "字典类型不能为空")
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符")
public String getDictType()
{
return dictType;

View File

@@ -5,11 +5,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
@@ -41,7 +43,7 @@ public class MenuController extends BaseController
}
@RequiresPermissions("system:menu:list")
@GetMapping("/list")
@PostMapping("/list")
@ResponseBody
public List<Menu> list(Menu menu)
{
@@ -97,8 +99,12 @@ public class MenuController extends BaseController
@RequiresPermissions("system:menu:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Menu menu)
public AjaxResult addSave(@Validated Menu menu)
{
if (UserConstants.MENU_NAME_NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
return toAjax(menuService.insertMenu(menu));
}
@@ -119,8 +125,12 @@ public class MenuController extends BaseController
@RequiresPermissions("system:menu:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Menu menu)
public AjaxResult editSave(@Validated Menu menu)
{
if (UserConstants.MENU_NAME_NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
return toAjax(menuService.updateMenu(menu));
}

View File

@@ -1,9 +1,10 @@
package com.ruoyi.project.system.menu.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.web.domain.BaseEntity;
/**
@@ -61,6 +62,8 @@ public class Menu extends BaseEntity
this.menuId = menuId;
}
@NotBlank(message = "菜单名称不能为空")
@Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
public String getMenuName()
{
return menuName;
@@ -91,6 +94,7 @@ public class Menu extends BaseEntity
this.parentId = parentId;
}
@NotBlank(message = "显示顺序不能为空")
public String getOrderNum()
{
return orderNum;
@@ -101,6 +105,7 @@ public class Menu extends BaseEntity
this.orderNum = orderNum;
}
@Size(min = 0, max = 200, message = "请求地址不能超过200个字符")
public String getUrl()
{
return url;
@@ -121,6 +126,7 @@ public class Menu extends BaseEntity
this.target = target;
}
@NotBlank(message = "菜单类型不能为空")
public String getMenuType()
{
return menuType;
@@ -141,6 +147,7 @@ public class Menu extends BaseEntity
this.visible = visible;
}
@Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符")
public String getPerms()
{
return perms;

View File

@@ -1,5 +1,7 @@
package com.ruoyi.project.system.notice.domain;
import javax.validation.constraints.*;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.web.domain.BaseEntity;
@@ -15,12 +17,16 @@ public class Notice extends BaseEntity
/** 公告ID */
private Long noticeId;
/** 公告标题 */
private String noticeTitle;
/** 公告类型1通知 2公告 */
private String noticeType;
/** 公告内容 */
private String noticeContent;
/** 公告状态0正常 1关闭 */
private String status;
@@ -39,6 +45,8 @@ public class Notice extends BaseEntity
this.noticeTitle = noticeTitle;
}
@NotBlank(message = "公告标题不能为空")
@Size(min = 0, max = 50, message = "公告标题不能超过50个字符")
public String getNoticeTitle()
{
return noticeTitle;
@@ -73,7 +81,7 @@ public class Notice extends BaseEntity
{
return status;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

View File

@@ -5,11 +5,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
@@ -93,8 +95,16 @@ public class PostController extends BaseController
@Log(title = "岗位管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Post post)
public AjaxResult addSave(@Validated Post post)
{
if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
}
else if (UserConstants.POST_CODE_NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
{
return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
}
return toAjax(postService.insertPost(post));
}
@@ -115,8 +125,16 @@ public class PostController extends BaseController
@Log(title = "岗位管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Post post)
public AjaxResult editSave(@Validated Post post)
{
if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
}
else if (UserConstants.POST_CODE_NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
{
return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
}
return toAjax(postService.updatePost(post));
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.project.system.post.domain;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
@@ -47,6 +48,8 @@ public class Post extends BaseEntity
this.postId = postId;
}
@NotBlank(message = "岗位编码不能为空")
@Size(min = 0, max = 64, message = "岗位编码长度不能超过64个字符")
public String getPostCode()
{
return postCode;
@@ -57,6 +60,8 @@ public class Post extends BaseEntity
this.postCode = postCode;
}
@NotBlank(message = "岗位名称不能为空")
@Size(min = 0, max = 50, message = "岗位名称长度不能超过50个字符")
public String getPostName()
{
return postName;
@@ -67,6 +72,7 @@ public class Post extends BaseEntity
this.postName = postName;
}
@NotBlank(message = "显示顺序不能为空")
public String getPostSort()
{
return postSort;

View File

@@ -5,11 +5,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
@@ -83,8 +85,16 @@ public class RoleController extends BaseController
@Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Role role)
public AjaxResult addSave(@Validated Role role)
{
if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
return toAjax(roleService.insertRole(role));
}
@@ -106,8 +116,16 @@ public class RoleController extends BaseController
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Role role)
public AjaxResult editSave(@Validated Role role)
{
if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
return toAjax(roleService.updateRole(role));
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.project.system.role.domain;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
@@ -70,6 +71,8 @@ public class Role extends BaseEntity
this.dataScope = dataScope;
}
@NotBlank(message = "角色名称不能为空")
@Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符")
public String getRoleName()
{
return roleName;
@@ -80,6 +83,8 @@ public class Role extends BaseEntity
this.roleName = roleName;
}
@NotBlank(message = "权限字符不能为空")
@Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符")
public String getRoleKey()
{
return roleKey;
@@ -90,6 +95,7 @@ public class Role extends BaseEntity
this.roleKey = roleKey;
}
@NotBlank(message = "显示顺序不能为空")
public String getRoleSort()
{
return roleSort;

View File

@@ -5,6 +5,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -112,23 +113,19 @@ public class UserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(User user)
public AjaxResult addSave(@Validated User user)
{
if (StringUtils.isNotNull(user.getUserId()) && User.isAdmin(user.getUserId()))
if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName())))
{
return error("不允许修改超级管理员用户");
}
else if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName())))
{
return error("保存用户'" + user.getLoginName() + "'失败,登录账号已存在");
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
}
else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return error("保存用户'" + user.getLoginName() + "'失败,手机号码已存在");
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return error("保存用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
return toAjax(userService.insertUser(user));
}
@@ -152,7 +149,7 @@ public class UserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(User user)
public AjaxResult editSave(@Validated User user)
{
if (StringUtils.isNotNull(user.getUserId()) && User.isAdmin(user.getUserId()))
{
@@ -160,11 +157,11 @@ public class UserController extends BaseController
}
else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return error("保存用户'" + user.getLoginName() + "'失败,手机号码已存在");
return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return error("保存用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
return toAjax(userService.updateUser(user));
}

View File

@@ -2,6 +2,7 @@ package com.ruoyi.project.system.user.domain;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
@@ -78,14 +79,14 @@ public class User extends BaseEntity
/** 最后登陆时间 */
@Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
private Date loginDate;
/** 部门对象 */
@Excels({
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
})
private Dept dept;
/** 角色集合 */
private List<Role> roles;
/** 角色组 */
@@ -144,6 +145,8 @@ public class User extends BaseEntity
this.roleId = roleId;
}
@NotBlank(message = "登录账号不能为空")
@Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
public String getLoginName()
{
return loginName;
@@ -154,6 +157,7 @@ public class User extends BaseEntity
this.loginName = loginName;
}
@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
public String getUserName()
{
return userName;
@@ -164,6 +168,8 @@ public class User extends BaseEntity
this.userName = userName;
}
@Email(message = "邮箱格式不正确")
@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
public String getEmail()
{
return email;
@@ -174,6 +180,7 @@ public class User extends BaseEntity
this.email = email;
}
@Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
public String getPhonenumber()
{
return phonenumber;

View File

@@ -429,7 +429,7 @@
$.bttTable = $('#' + options.id).bootstrapTreeTable({
code: options.code, // 用于设置父子关系
parentCode: options.parentCode, // 用于设置父子关系
type: 'get', // 请求方式(*
type: 'post', // 请求方式(*
url: options.url, // 请求后台的URL*
ajaxParams: options.ajaxParams, // 请求数据的ajax的data属性
rootIdValue: options.rootIdValue, // 设置指定根节点id值
@@ -845,7 +845,7 @@
},
// 添加访问地址
addUrl: function(id) {
var url = $.common.isEmpty(id) ? $.table._option.createUrl : $.table._option.createUrl.replace("{id}", id);
var url = $.common.isEmpty(id) ? $.table._option.createUrl.replace("{id}", "") : $.table._option.createUrl.replace("{id}", id);
return url;
},
// 修改信息