岗位名称编码唯一校验

This commit is contained in:
RuoYi
2018-08-05 11:05:26 +08:00
parent 32975b3ed7
commit 92fffea429
14 changed files with 257 additions and 28 deletions

View File

@@ -48,11 +48,19 @@ public class UserConstants
/** 角色名称是否唯一的返回结果码 */
public final static String ROLE_NAME_UNIQUE = "0";
public final static String ROLE_NAME_NOT_UNIQUE = "1";
/** 岗位名称是否唯一的返回结果码 */
public final static String POST_NAME_UNIQUE = "0";
public final static String POST_NAME_NOT_UNIQUE = "1";
/** 角色权限是否唯一的返回结果码 */
public final static String ROLE_KEY_UNIQUE = "0";
public final static String ROLE_KEY_NOT_UNIQUE = "1";
/** 岗位编码是否唯一的返回结果码 */
public final static String POST_CODE_UNIQUE = "0";
public final static String POST_CODE_NOT_UNIQUE = "1";
/** 菜单名称是否唯一的返回结果码 */
public final static String MENU_NAME_UNIQUE = "0";
public final static String MENU_NAME_NOT_UNIQUE = "1";

View File

@@ -1,6 +1,7 @@
package com.ruoyi.project.system.post.controller;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -10,6 +11,8 @@ 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.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
@@ -127,4 +130,34 @@ public class PostController extends BaseController
return toAjax(postService.updatePost(post));
}
/**
* 校验岗位名称
*/
@PostMapping("/checkPostNameUnique")
@ResponseBody
public String checkPostNameUnique(Post post)
{
String uniqueFlag = "0";
if (StringUtils.isNotNull(post))
{
uniqueFlag = postService.checkPostNameUnique(post);
}
return uniqueFlag;
}
/**
* 校验岗位编码
*/
@PostMapping("/checkPostCodeUnique")
@ResponseBody
public String checkPostCodeUnique(Post post)
{
String uniqueFlag = "0";
if (StringUtils.isNotNull(post))
{
uniqueFlag = postService.checkPostCodeUnique(post);
}
return uniqueFlag;
}
}

View File

@@ -66,4 +66,20 @@ public interface PostMapper
*/
public int insertPost(Post post);
/**
* 校验岗位名称
*
* @param post 岗位信息
* @return 结果
*/
public Post checkPostNameUnique(String postName);
/**
* 校验岗位编码
*
* @param post 岗位信息
* @return 结果
*/
public Post checkPostCodeUnique(String postCode);
}

View File

@@ -73,4 +73,20 @@ public interface IPostService
* @return 结果
*/
public int countUserPostById(Long postId);
/**
* 校验岗位名称
*
* @param post 岗位信息
* @return 结果
*/
public String checkPostNameUnique(Post post);
/**
* 校验岗位编码
*
* @param post 岗位信息
* @return 结果
*/
public String checkPostCodeUnique(Post post);
}

View File

@@ -3,7 +3,9 @@ package com.ruoyi.project.system.post.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.post.domain.Post;
import com.ruoyi.project.system.post.mapper.PostMapper;
@@ -142,4 +144,40 @@ public class PostServiceImpl implements IPostService
return userPostMapper.countUserPostById(postId);
}
/**
* 校验岗位名称是否唯一
*
* @param post 岗位信息
* @return 结果
*/
@Override
public String checkPostNameUnique(Post post)
{
Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
Post info = postMapper.checkPostNameUnique(post.getPostName());
if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
{
return UserConstants.POST_NAME_NOT_UNIQUE;
}
return UserConstants.POST_NAME_UNIQUE;
}
/**
* 校验岗位编码是否唯一
*
* @param post 岗位信息
* @return 结果
*/
@Override
public String checkPostCodeUnique(Post post)
{
Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
Post info = postMapper.checkPostCodeUnique(post.getPostCode());
if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
{
return UserConstants.POST_CODE_NOT_UNIQUE;
}
return UserConstants.POST_CODE_UNIQUE;
}
}