|
|
@ -5,14 +5,16 @@ import java.util.Arrays; |
|
|
import java.util.HashSet; |
|
|
import java.util.HashSet; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import com.hxhq.business.domain.SystemLog; |
|
|
|
|
|
import com.hxhq.business.service.ISystemLogService; |
|
|
|
|
|
import com.hxhq.business.utils.ObjectCompareUtil; |
|
|
|
|
|
import com.hxhq.system.domain.SysMenu; |
|
|
import com.hxhq.system.domain.SysRoleDept; |
|
|
import com.hxhq.system.domain.SysRoleDept; |
|
|
import com.hxhq.system.domain.SysRoleMenu; |
|
|
import com.hxhq.system.domain.SysRoleMenu; |
|
|
import com.hxhq.system.domain.SysUserRole; |
|
|
import com.hxhq.system.domain.SysUserRole; |
|
|
import com.hxhq.system.mapper.SysRoleDeptMapper; |
|
|
|
|
|
import com.hxhq.system.mapper.SysRoleMapper; |
|
|
|
|
|
import com.hxhq.system.mapper.SysRoleMenuMapper; |
|
|
|
|
|
import com.hxhq.system.mapper.SysUserRoleMapper; |
|
|
|
|
|
|
|
|
import com.hxhq.system.mapper.*; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -46,6 +48,12 @@ public class SysRoleServiceImpl implements ISysRoleService |
|
|
@Autowired |
|
|
@Autowired |
|
|
private SysRoleDeptMapper roleDeptMapper; |
|
|
private SysRoleDeptMapper roleDeptMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private SysMenuMapper menuMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ISystemLogService systemLogService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 根据条件分页查询角色数据 |
|
|
* 根据条件分页查询角色数据 |
|
|
* |
|
|
* |
|
|
@ -237,7 +245,9 @@ public class SysRoleServiceImpl implements ISysRoleService |
|
|
{ |
|
|
{ |
|
|
// 新增角色信息 |
|
|
// 新增角色信息 |
|
|
roleMapper.insertRole(role); |
|
|
roleMapper.insertRole(role); |
|
|
return insertRoleMenu(role); |
|
|
|
|
|
|
|
|
int row = insertRoleMenu(role); |
|
|
|
|
|
systemLogService.saveInfo("新增角色","Add Role",role.getRoleName(),role.getRoleName(),SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); |
|
|
|
|
|
return row; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -250,11 +260,21 @@ public class SysRoleServiceImpl implements ISysRoleService |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public int updateRole(SysRole role) |
|
|
public int updateRole(SysRole role) |
|
|
{ |
|
|
{ |
|
|
|
|
|
SysRole old = selectRoleById(role.getRoleId()); |
|
|
|
|
|
List<SysMenu> oldMenuList = menuMapper.selectMenuByRoleId(role.getRoleId()); |
|
|
|
|
|
|
|
|
// 修改角色信息 |
|
|
// 修改角色信息 |
|
|
roleMapper.updateRole(role); |
|
|
roleMapper.updateRole(role); |
|
|
// 删除角色与菜单关联 |
|
|
// 删除角色与菜单关联 |
|
|
roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId()); |
|
|
roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId()); |
|
|
return insertRoleMenu(role); |
|
|
|
|
|
|
|
|
int row = insertRoleMenu(role); |
|
|
|
|
|
|
|
|
|
|
|
List<SystemLog> logList = getModifyLogList(role,old,oldMenuList); |
|
|
|
|
|
if(logList.size()>0){ |
|
|
|
|
|
systemLogService.saveBatch(logList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return row; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -266,7 +286,10 @@ public class SysRoleServiceImpl implements ISysRoleService |
|
|
@Override |
|
|
@Override |
|
|
public int updateRoleStatus(SysRole role) |
|
|
public int updateRoleStatus(SysRole role) |
|
|
{ |
|
|
{ |
|
|
return roleMapper.updateRole(role); |
|
|
|
|
|
|
|
|
SysRole info = selectRoleById(role.getRoleId()); |
|
|
|
|
|
int row = roleMapper.updateRole(role); |
|
|
|
|
|
systemLogService.saveInfo(role.getStatus().equals("0")?"启用角色":"禁用角色",role.getStatus().equals("0")?"Enable Role":"Disable Role",info.getRoleName(),info.getRoleName(),SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); |
|
|
|
|
|
return row; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -345,11 +368,17 @@ public class SysRoleServiceImpl implements ISysRoleService |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public int deleteRoleById(Long roleId) |
|
|
public int deleteRoleById(Long roleId) |
|
|
{ |
|
|
{ |
|
|
|
|
|
SysRole sysRole = selectRoleById(roleId); |
|
|
|
|
|
|
|
|
// 删除角色与菜单关联 |
|
|
// 删除角色与菜单关联 |
|
|
roleMenuMapper.deleteRoleMenuByRoleId(roleId); |
|
|
roleMenuMapper.deleteRoleMenuByRoleId(roleId); |
|
|
// 删除角色与部门关联 |
|
|
// 删除角色与部门关联 |
|
|
roleDeptMapper.deleteRoleDeptByRoleId(roleId); |
|
|
roleDeptMapper.deleteRoleDeptByRoleId(roleId); |
|
|
return roleMapper.deleteRoleById(roleId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int row = roleMapper.deleteRoleById(roleId); |
|
|
|
|
|
|
|
|
|
|
|
systemLogService.saveInfo("删除角色","Remove Role",sysRole.getRoleName(),sysRole.getRoleName(),SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); |
|
|
|
|
|
return row; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -425,4 +454,91 @@ public class SysRoleServiceImpl implements ISysRoleService |
|
|
} |
|
|
} |
|
|
return userRoleMapper.batchUserRole(list); |
|
|
return userRoleMapper.batchUserRole(list); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取修改日志 |
|
|
|
|
|
* @param info |
|
|
|
|
|
* @param old |
|
|
|
|
|
* @param oldMenuList |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<SystemLog> getModifyLogList(SysRole info, SysRole old,List<SysMenu> oldMenuList){ |
|
|
|
|
|
List<SystemLog> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
List<ObjectCompareUtil.FieldChange> fieldChanges = ObjectCompareUtil.compareObjects(old, info); |
|
|
|
|
|
for (ObjectCompareUtil.FieldChange fieldChange : fieldChanges) { |
|
|
|
|
|
SystemLog log = getLogInfo(); |
|
|
|
|
|
log.setJcnr(fieldChange.toString()); |
|
|
|
|
|
log.setJcnrEn(fieldChange.toEnString()); |
|
|
|
|
|
list.add(log); |
|
|
|
|
|
} |
|
|
|
|
|
if(!info.getStatus().equals(old.getStatus())){ |
|
|
|
|
|
SystemLog log = getLogInfo(); |
|
|
|
|
|
log.setJcnr("[{\"name\":\"字段名\",\"value\":\"状态\"},{\"name\":\"原值\",\"value\":\""+("0".equals(old.getStatus())?"启用":"禁用")+"\"},{\"name\":\"新值\",\"value\":\""+("0".equals(info.getStatus())?"启用":"禁用")+"\"}]"); |
|
|
|
|
|
log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Status\"},{\"name\":\"Old Value\",\"value\":\""+("0".equals(old.getStatus())?"Enabled":"Disabled")+"\"},{\"name\":\"New Value\",\"value\":\""+("0".equals(info.getStatus())?"Enabled":"Disabled")+"\"}]"); |
|
|
|
|
|
list.add(log); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断菜单修改 |
|
|
|
|
|
Boolean updateMenu = false; |
|
|
|
|
|
if(info.getMenuIds().length!=oldMenuList.size()){ |
|
|
|
|
|
updateMenu = true; |
|
|
|
|
|
}else{ |
|
|
|
|
|
List<Long> oldMenuIdList = oldMenuList.stream().map(o->o.getMenuId()).collect(Collectors.toList()); |
|
|
|
|
|
for(Long newMenuId : info.getMenuIds()){ |
|
|
|
|
|
if(!oldMenuIdList.contains(newMenuId)){ |
|
|
|
|
|
updateMenu = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(updateMenu){ |
|
|
|
|
|
List<SysMenu> newMenuList = new ArrayList<>(); |
|
|
|
|
|
if(info.getMenuIds()!=null && info.getMenuIds().length>0){ |
|
|
|
|
|
List<SysMenu> allMenuList = menuMapper.selectMenuList(new SysMenu()); |
|
|
|
|
|
for(Long newMenuId : info.getMenuIds()){ |
|
|
|
|
|
newMenuList.add(allMenuList.stream().filter(o->o.getMenuId().equals(newMenuId)).collect(Collectors.toList()).get(0)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<String> addNameList = new ArrayList<>(); |
|
|
|
|
|
List<String> deleteNameList = new ArrayList<>(); |
|
|
|
|
|
List<Long> oldMenuIdList = oldMenuList.stream().map(o->o.getMenuId()).collect(Collectors.toList()); |
|
|
|
|
|
List<Long> newMenuIdList = newMenuList.stream().map(o->o.getMenuId()).collect(Collectors.toList()); |
|
|
|
|
|
for(SysMenu newMenu : newMenuList){ |
|
|
|
|
|
if(!oldMenuIdList.contains(newMenu.getMenuId())){ |
|
|
|
|
|
addNameList.add(newMenu.getMenuName()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(SysMenu oldMenu : oldMenuList){ |
|
|
|
|
|
if(!newMenuIdList.contains(oldMenu.getMenuId())){ |
|
|
|
|
|
deleteNameList.add(oldMenu.getMenuName()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(addNameList.size()>0 || deleteNameList.size()>0){ |
|
|
|
|
|
SystemLog log = getLogInfo(); |
|
|
|
|
|
log.setJcnr((addNameList.size()>0?("新增权限:"+String.join(",",addNameList)):"")+(deleteNameList.size()>0?(";删除权限:"+String.join(",",deleteNameList)):"")); |
|
|
|
|
|
log.setJcnrEn((addNameList.size()>0?("Add Permit:"+String.join(",",addNameList)):"")+(deleteNameList.size()>0?(";Remove Permit:"+String.join(",",deleteNameList)):"")); |
|
|
|
|
|
list.add(log); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取日志基础信息 |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private SystemLog getLogInfo(){ |
|
|
|
|
|
SystemLog log = new SystemLog(); |
|
|
|
|
|
log.setJcmc("修改角色"); |
|
|
|
|
|
log.setJcmcEn("Modify Role"); |
|
|
|
|
|
log.setQmrId(SecurityUtils.getUserId()); |
|
|
|
|
|
log.setQmrMc(SecurityUtils.getNickName()); |
|
|
|
|
|
log.setQmrMcEn(SecurityUtils.getUsername()); |
|
|
|
|
|
return log; |
|
|
|
|
|
} |
|
|
} |
|
|
} |