新增校验

This commit is contained in:
RuoYi
2018-05-04 20:25:14 +08:00
parent c7613a9ff5
commit 66a904d71e
41 changed files with 238 additions and 48 deletions

View File

@ -2,9 +2,8 @@ package com.ruoyi;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* 启动程序
@ -12,7 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
* @author ruoyi
*/
@SpringBootApplication
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
@EnableTransactionManagement
@MapperScan("com.ruoyi.project.*.*.dao")
public class RuoYiApplication
{

View File

@ -11,7 +11,7 @@ import com.ruoyi.framework.web.page.PageDomain;
public class JobLog extends PageDomain
{
/** ID */
private Integer jobLogId;
private Long jobLogId;
/** 任务名称 */
private String jobName;
/** 任务组名 */
@ -29,12 +29,12 @@ public class JobLog extends PageDomain
/** 创建时间 */
private Date createTime;
public Integer getJobLogId()
public Long getJobLogId()
{
return jobLogId;
}
public void setJobLogId(Integer jobLogId)
public void setJobLogId(Long jobLogId)
{
this.jobLogId = jobLogId;
}

View File

@ -102,7 +102,6 @@ public class DeptController extends BaseController
{
return Message.error(1, "存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId))
{
return Message.error(1, "部门存在用户,不允许删除");

View File

@ -25,7 +25,6 @@ public interface IDeptService
* @return 所有部门信息
*/
public List<Map<String, Object>> selectDeptTree();
/**
* 查询部门人数

View File

@ -58,14 +58,19 @@ public class MenuController extends BaseController
@ResponseBody
public Message remove(@PathVariable("menuId") Long menuId)
{
if (menuService.selectCountMenuByParentId(menuId) > 0)
{
return Message.error(1, "存在子菜单,不允许删除");
}
if (menuService.selectCountRoleMenuByMenuId(menuId) > 0)
{
return Message.error(1, "菜单已分配,不允许删除");
}
if (menuService.deleteMenuById(menuId) > 0)
{
return Message.ok();
}
else
{
return Message.error(1, "删除失败");
}
return Message.error();
}
/**

View File

@ -57,6 +57,14 @@ public interface IMenuDao
* @return 菜单信息
*/
public Menu selectMenuById(Long menuId);
/**
* 查询子菜单数量
*
* @param menuId 菜单ID
* @return 结果
*/
public int selectCountMenuByParentId(Long parentId);
/**
* 新增菜单信息

View File

@ -76,6 +76,22 @@ public interface IMenuService
*/
public Menu selectMenuById(Long menuId);
/**
* 查询子菜单数量
*
* @param menuId 菜单ID
* @return 结果
*/
public int selectCountMenuByParentId(Long parentId);
/**
* 查询菜单使用数量
*
* @param menuId 菜单ID
* @return 结果
*/
public int selectCountRoleMenuByMenuId(Long menuId);
/**
* 保存菜单信息
*

View File

@ -19,6 +19,7 @@ import com.ruoyi.common.utils.TreeUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.menu.dao.IMenuDao;
import com.ruoyi.project.system.menu.domain.Menu;
import com.ruoyi.project.system.role.dao.IRoleMenuDao;
import com.ruoyi.project.system.role.domain.Role;
/**
@ -34,6 +35,9 @@ public class MenuServiceImpl implements IMenuService
@Autowired
private IMenuDao menuDao;
@Autowired
private IRoleMenuDao roleMenuDao;
/**
* 根据用户ID查询菜单
*
@ -205,6 +209,30 @@ public class MenuServiceImpl implements IMenuService
return menuDao.selectMenuById(menuId);
}
/**
* 查询子菜单数量
*
* @param menuId 菜单ID
* @return 结果
*/
@Override
public int selectCountMenuByParentId(Long parentId)
{
return menuDao.selectCountMenuByParentId(parentId);
}
/**
* 查询菜单使用数量
*
* @param menuId 菜单ID
* @return 结果
*/
@Override
public int selectCountRoleMenuByMenuId(Long menuId)
{
return roleMenuDao.selectCountRoleMenuByMenuId(menuId);
}
/**
* 保存菜单信息
*

View File

@ -63,6 +63,10 @@ public class PostController extends BaseController
{
return Message.error("岗位不存在");
}
if (postService.selectCountPostById(postId) > 0)
{
return Message.error("岗位已分配,不能删除");
}
if (postService.deletePostById(postId) > 0)
{
return Message.ok();

View File

@ -64,4 +64,12 @@ public interface IPostService
* @return 结果
*/
public int savePost(Post post);
/**
* 通过岗位ID查询岗位使用数量
*
* @param postId 岗位ID
* @return 结果
*/
public int selectCountPostById(Long postId);
}

View File

@ -1,12 +1,15 @@
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.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.post.dao.IPostDao;
import com.ruoyi.project.system.post.domain.Post;
import com.ruoyi.project.system.user.dao.IUserPostDao;
/**
* 岗位信息 服务层处理
@ -18,6 +21,9 @@ public class PostServiceImpl implements IPostService
{
@Autowired
private IPostDao postDao;
@Autowired
private IUserPostDao userPostDao;
/**
* 查询岗位信息集合
@ -66,8 +72,6 @@ public class PostServiceImpl implements IPostService
}
return posts;
}
/**
* 通过岗位ID查询岗位信息
@ -131,4 +135,16 @@ public class PostServiceImpl implements IPostService
return count;
}
/**
* 通过岗位ID查询岗位使用数量
*
* @param postId 岗位ID
* @return 结果
*/
@Override
public int selectCountPostById(Long postId)
{
return userPostDao.selectCountPostById(postId);
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -32,7 +33,7 @@ public class RoleController extends BaseController
@Autowired
private IRoleService roleService;
@RequiresPermissions("system:role:view")
@GetMapping()
public String role()
@ -49,7 +50,7 @@ public class RoleController extends BaseController
List<Role> list = roleService.selectRoleList(role);
return getDataTable(list);
}
/**
* 新增角色
*/
@ -80,6 +81,7 @@ public class RoleController extends BaseController
@RequiresPermissions("system:role:save")
@Log(title = "系统管理", action = "角色管理-保存角色")
@PostMapping("/save")
@Transactional
@ResponseBody
public Message save(Role role)
{
@ -93,6 +95,7 @@ public class RoleController extends BaseController
@RequiresPermissions("system:role:remove")
@Log(title = "系统管理", action = "角色管理-删除角色")
@RequestMapping("/remove/{roleId}")
@Transactional
@ResponseBody
public Message remove(@PathVariable("roleId") Long roleId)
{
@ -101,6 +104,10 @@ public class RoleController extends BaseController
{
return Message.error("角色不存在");
}
if (roleService.selectCountUserRoleByRoleId(roleId) > 0)
{
return Message.error("角色已分配,不能删除");
}
if (roleService.deleteRoleById(roleId) > 0)
{
return Message.ok();
@ -121,7 +128,7 @@ public class RoleController extends BaseController
}
return Message.error();
}
/**
* 校验角色名称
*/

View File

@ -19,6 +19,22 @@ public interface IRoleMenuDao
*/
public int deleteRoleMenuByRoleId(Long roleId);
/**
* 批量角色角色菜单关联信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteRoleMenu(Long[] ids);
/**
* 查询菜单使用数量
*
* @param menuId 菜单ID
* @return 结果
*/
public int selectCountRoleMenuByMenuId(Long menuId);
/**
* 批量新增角色菜单信息
*

View File

@ -82,5 +82,13 @@ public interface IRoleService
* @return 结果
*/
public String checkRoleNameUnique(Role role);
/**
* 通过角色ID查询角色使用数量
*
* @param roleId 角色ID
* @return 结果
*/
public int selectCountUserRoleByRoleId(Long roleId);
}

View File

@ -126,7 +126,6 @@ public class RoleServiceImpl implements IRoleService
@Override
public int deleteRoleById(Long roleId)
{
userRoleDao.deleteUserRoleByRoleId(roleId);
roleMenuDao.deleteRoleMenuByRoleId(roleId);
return roleDao.deleteRoleById(roleId);
}
@ -140,6 +139,7 @@ public class RoleServiceImpl implements IRoleService
@Override
public int batchDeleteRole(Long[] ids)
{
roleMenuDao.deleteRoleMenu(ids);
return roleDao.batchDeleteRole(ids);
}
@ -193,7 +193,7 @@ public class RoleServiceImpl implements IRoleService
}
return rows;
}
/**
* 校验角色名称是否唯一
*
@ -205,11 +205,23 @@ public class RoleServiceImpl implements IRoleService
{
Long roleId = role.getRoleId();
Role info = roleDao.checkRoleNameUnique(role.getRoleName());
if (StringUtils.isNotNull(info) && StringUtils.isNotNull(info.getRoleId()) && info.getRoleId() != roleId)
if (StringUtils.isNotNull(info) && StringUtils.isNotNull(info.getRoleId()) && info.getRoleId() != roleId)
{
return UserConstants.NAME_NOT_UNIQUE;
}
return UserConstants.NAME_UNIQUE;
}
/**
* 通过角色ID查询角色使用数量
*
* @param roleId 角色ID
* @return 结果
*/
@Override
public int selectCountUserRoleByRoleId(Long roleId)
{
return userRoleDao.selectCountUserRoleByRoleId(roleId);
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -119,6 +120,7 @@ public class UserController extends BaseController
@RequiresPermissions("system:user:remove")
@Log(title = "系统管理", action = "用户管理-删除用户")
@RequestMapping("/remove/{userId}")
@Transactional
@ResponseBody
public Message remove(@PathVariable("userId") Long userId)
{
@ -137,6 +139,7 @@ public class UserController extends BaseController
@RequiresPermissions("system:user:batchRemove")
@Log(title = "系统管理", action = "用户管理-批量删除")
@PostMapping("/batchRemove")
@Transactional
@ResponseBody
public Message batchRemove(@RequestParam("ids[]") Long[] ids)
{
@ -154,6 +157,7 @@ public class UserController extends BaseController
@RequiresPermissions("system:user:save")
@Log(title = "系统管理", action = "部门管理-保存部门")
@PostMapping("/save")
@Transactional
@ResponseBody
public Message save(User user)
{

View File

@ -18,6 +18,22 @@ public interface IUserPostDao
* @return 结果
*/
public int deleteUserPostByUserId(Long userId);
/**
* 通过岗位ID查询岗位使用数量
*
* @param postId 岗位ID
* @return 结果
*/
public int selectCountPostById(Long postId);
/**
* 批量删除用户和岗位关联
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteUserPost(Long[] ids);
/**
* 批量新增用户岗位信息

View File

@ -20,12 +20,20 @@ public interface IUserRoleDao
public int deleteUserRoleByUserId(Long userId);
/**
* 通过角色ID删除用户和角色关联
* 批量删除用户和角色关联
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteUserRole(Long[] ids);
/**
* 通过角色ID查询角色使用数量
*
* @param roleId 角色ID
* @return 结果
*/
public int deleteUserRoleByRoleId(Long roleId);
public int selectCountUserRoleByRoleId(Long roleId);
/**
* 批量新增用户角色信息

View File

@ -86,6 +86,8 @@ public class UserServiceImpl implements IUserService
{
// 删除用户与角色关联
userRoleDao.deleteUserRoleByUserId(userId);
// 删除用户与岗位表
userPostDao.deleteUserPostByUserId(userId);
return userDao.deleteUserById(userId);
}
@ -98,6 +100,8 @@ public class UserServiceImpl implements IUserService
@Override
public int batchDeleteUser(Long[] ids)
{
userRoleDao.deleteUserRole(ids);
userPostDao.deleteUserPost(ids);
return userDao.batchDeleteUser(ids);
}