|
|
|
@ -1,14 +1,16 @@ |
|
|
|
package com.hxhq.system.service.impl; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import javax.validation.Validator; |
|
|
|
|
|
|
|
import com.hxhq.business.domain.SystemLog; |
|
|
|
import com.hxhq.business.dto.select.BzListDto; |
|
|
|
import com.hxhq.business.dto.select.DeptUserTreeDto; |
|
|
|
import com.hxhq.business.service.ISystemLogService; |
|
|
|
import com.hxhq.business.utils.ObjectCompareUtil; |
|
|
|
import com.hxhq.system.api.domain.SysDept; |
|
|
|
import com.hxhq.system.domain.SysMenu; |
|
|
|
import com.hxhq.system.domain.SysPost; |
|
|
|
import com.hxhq.system.domain.SysUserPost; |
|
|
|
import com.hxhq.system.domain.SysUserRole; |
|
|
|
@ -70,6 +72,9 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
@Autowired |
|
|
|
protected Validator validator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISystemLogService systemLogService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据条件分页查询用户列表 |
|
|
|
* |
|
|
|
@ -271,6 +276,8 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
insertUserPost(user); |
|
|
|
// 新增用户与角色管理 |
|
|
|
insertUserRole(user); |
|
|
|
|
|
|
|
systemLogService.saveInfo(user.getUserName(),"新增用户","Create User",null,null,SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); |
|
|
|
return rows; |
|
|
|
} |
|
|
|
|
|
|
|
@ -296,6 +303,9 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public int updateUser(SysUser user) |
|
|
|
{ |
|
|
|
SysUser old = selectUserById(user.getUserId()); |
|
|
|
List<Long> oldRoleIdList = roleMapper.selectRoleListByUserId(user.getUserId()); |
|
|
|
|
|
|
|
Long userId = user.getUserId(); |
|
|
|
// 删除用户与角色关联 |
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId); |
|
|
|
@ -305,7 +315,15 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
userPostMapper.deleteUserPostByUserId(userId); |
|
|
|
// 新增用户与岗位管理 |
|
|
|
insertUserPost(user); |
|
|
|
return userMapper.updateUser(user); |
|
|
|
|
|
|
|
int row = userMapper.updateUser(user); |
|
|
|
|
|
|
|
List<SystemLog> logList = getModifyLogList(user,old,oldRoleIdList); |
|
|
|
if(logList.size()>0){ |
|
|
|
systemLogService.saveBatch(logList); |
|
|
|
} |
|
|
|
|
|
|
|
return row; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -331,7 +349,11 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
@Override |
|
|
|
public int updateUserStatus(SysUser user) |
|
|
|
{ |
|
|
|
return userMapper.updateUserStatus(user.getUserId(), user.getStatus()); |
|
|
|
SysUser info = selectUserById(user.getUserId()); |
|
|
|
|
|
|
|
int row = userMapper.updateUserStatus(user.getUserId(), user.getStatus()); |
|
|
|
systemLogService.saveInfo(info.getUserName(),"0".equals(user.getStatus())?"启用用户":"禁用用户","0".equals(user.getStatus())?"Enable User":"Disable User",null,null,SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); |
|
|
|
return row; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -462,11 +484,14 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public int deleteUserById(Long userId) |
|
|
|
{ |
|
|
|
SysUser sysUser =selectUserById(userId); |
|
|
|
// 删除用户与角色关联 |
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId); |
|
|
|
// 删除用户与岗位表 |
|
|
|
userPostMapper.deleteUserPostByUserId(userId); |
|
|
|
return userMapper.deleteUserById(userId); |
|
|
|
int row = userMapper.deleteUserById(userId); |
|
|
|
systemLogService.saveInfo(sysUser.getUserName(),"删除用户","Remove User",null,null,SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); |
|
|
|
return row; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -612,4 +637,99 @@ public class SysUserServiceImpl implements ISysUserService |
|
|
|
public List<String> selectNamesByIdList(List<Long> idList) { |
|
|
|
return userMapper.selectNamesByIdList(idList); |
|
|
|
} |
|
|
|
|
|
|
|
private List<SystemLog> getModifyLogList(SysUser info, SysUser old, List<Long> oldRoleIdList){ |
|
|
|
List<SystemLog> list = new ArrayList<>(); |
|
|
|
|
|
|
|
List<ObjectCompareUtil.FieldChange> fieldChanges = ObjectCompareUtil.compareObjects(old, info); |
|
|
|
for (ObjectCompareUtil.FieldChange fieldChange : fieldChanges) { |
|
|
|
SystemLog log = getLogInfo(old); |
|
|
|
log.setJcnr(fieldChange.toString()); |
|
|
|
log.setJcnrEn(fieldChange.toEnString()); |
|
|
|
list.add(log); |
|
|
|
} |
|
|
|
if(!info.getStatus().equals(old.getStatus())){ |
|
|
|
SystemLog log = getLogInfo(old); |
|
|
|
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); |
|
|
|
} |
|
|
|
if(!info.getDeptId().equals(old.getDeptId())){ |
|
|
|
SysDept oldDept = deptService.selectDeptById(old.getDeptId()); |
|
|
|
SysDept newDept = deptService.selectDeptById(info.getDeptId()); |
|
|
|
|
|
|
|
SystemLog log = getLogInfo(old); |
|
|
|
log.setJcnr("[{\"name\":\"字段名\",\"value\":\"所属部门/学科\"},{\"name\":\"原值\",\"value\":\""+oldDept.getDeptName()+"\"},{\"name\":\"新值\",\"value\":\""+newDept.getDeptName()+"\"}]"); |
|
|
|
log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Department\"},{\"name\":\"Old Value\",\"value\":\""+oldDept.getDeptName()+"\"},{\"name\":\"New Value\",\"value\":\""+newDept.getDeptName()+"\"}]"); |
|
|
|
list.add(log); |
|
|
|
} |
|
|
|
|
|
|
|
//判断菜单修改 |
|
|
|
Boolean updateRole = false; |
|
|
|
if(info.getRoleIds().length!=oldRoleIdList.size()){ |
|
|
|
updateRole = true; |
|
|
|
}else{ |
|
|
|
for(Long newMenuId : info.getRoleIds()){ |
|
|
|
if(!oldRoleIdList.contains(newMenuId)){ |
|
|
|
updateRole = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(updateRole){ |
|
|
|
List<SysRole> allRoleList = roleMapper.selectRoleList(new SysRole()); |
|
|
|
|
|
|
|
List<SysRole> oldRoleList = new ArrayList<>(); |
|
|
|
List<SysRole> newRoleList = new ArrayList<>(); |
|
|
|
if(info.getRoleIds()!=null && info.getRoleIds().length>0){ |
|
|
|
for(Long newRoleId : info.getRoleIds()){ |
|
|
|
newRoleList.add(allRoleList.stream().filter(o->o.getRoleId().equals(newRoleId)).collect(Collectors.toList()).get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
if(oldRoleIdList.size()>0){ |
|
|
|
for(Long oldRoleId : oldRoleIdList){ |
|
|
|
oldRoleList.add(allRoleList.stream().filter(o->o.getRoleId().equals(oldRoleId)).collect(Collectors.toList()).get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<String> addNameList = new ArrayList<>(); |
|
|
|
List<String> deleteNameList = new ArrayList<>(); |
|
|
|
for(SysRole newRole : newRoleList){ |
|
|
|
if(!oldRoleIdList.contains(newRole.getRoleId())){ |
|
|
|
addNameList.add(newRole.getRoleName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<Long> newMenuIdList = Arrays.asList(info.getRoleIds()); |
|
|
|
for(SysRole oldRole : oldRoleList){ |
|
|
|
if(!newMenuIdList.contains(oldRole.getRoleId())){ |
|
|
|
deleteNameList.add(oldRole.getRoleName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(addNameList.size()>0 || deleteNameList.size()>0){ |
|
|
|
SystemLog log = getLogInfo(old); |
|
|
|
log.setJcnr((addNameList.size()>0?("新增角色:"+String.join(",",addNameList)):"")+(deleteNameList.size()>0?(";删除角色:"+String.join(",",deleteNameList)):"")); |
|
|
|
log.setJcnrEn((addNameList.size()>0?("Add Role:"+String.join(",",addNameList)):"")+(deleteNameList.size()>0?(";Remove Role:"+String.join(",",deleteNameList)):"")); |
|
|
|
list.add(log); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取日志基础信息 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private SystemLog getLogInfo(SysUser sysUser){ |
|
|
|
SystemLog log = new SystemLog(); |
|
|
|
log.setName(sysUser.getNickName()); |
|
|
|
log.setJcmc("修改用户"); |
|
|
|
log.setJcmcEn("Modify User"); |
|
|
|
log.setQmrId(SecurityUtils.getUserId()); |
|
|
|
log.setQmrMc(SecurityUtils.getNickName()); |
|
|
|
log.setQmrMcEn(SecurityUtils.getUsername()); |
|
|
|
return log; |
|
|
|
} |
|
|
|
} |