2023-04-21 09:29:36

master
魔神煜修罗皇 2 years ago
parent 8ad66274a0
commit 48f3a398a1
  1. 157
      psdc-system/src/main/java/com/psdc/service/impl/SysRoleServiceImpl.java
  2. 1
      psdc-system/src/main/resources/mapper/system/SysRoleMapper.xml
  3. 35
      psdc-web/src/main/java/com/psdc/controller/system/SysConfigController.java
  4. 40
      psdc-web/src/main/java/com/psdc/controller/system/SysProfileController.java
  5. 69
      psdc-web/src/main/java/com/psdc/controller/system/SysRoleController.java

@ -5,6 +5,7 @@ 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 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;
@ -24,7 +25,7 @@ import com.psdc.service.ISysRoleService;
/** /**
* 角色 业务层处理 * 角色 业务层处理
* *
* @author * @author
*/ */
@Service @Service
@ -41,33 +42,28 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 根据条件分页查询角色数据 * 根据条件分页查询角色数据
* *
* @param role 角色信息 * @param role 角色信息
* @return 角色数据集合信息 * @return 角色数据集合信息
*/ */
@Override @Override
public List<SysRole> selectRoleList(SysRole role) public List<SysRole> selectRoleList(SysRole role) {
{
return roleMapper.selectRoleList(role); return roleMapper.selectRoleList(role);
} }
/** /**
* 根据用户ID查询角色 * 根据用户ID查询角色
* *
* @param userId 用户ID * @param userId 用户ID
* @return 角色列表 * @return 角色列表
*/ */
@Override @Override
public List<SysRole> selectRolesByUserId(Long userId) public List<SysRole> selectRolesByUserId(Long userId) {
{
List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId); List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
List<SysRole> roles = selectRoleAll(); List<SysRole> roles = selectRoleAll();
for (SysRole role : roles) for (SysRole role : roles) {
{ for (SysRole userRole : userRoles) {
for (SysRole userRole : userRoles) if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
{
if (role.getRoleId().longValue() == userRole.getRoleId().longValue())
{
role.setFlag(true); role.setFlag(true);
break; break;
} }
@ -78,19 +74,16 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 根据用户ID查询权限 * 根据用户ID查询权限
* *
* @param userId 用户ID * @param userId 用户ID
* @return 权限列表 * @return 权限列表
*/ */
@Override @Override
public Set<String> selectRolePermissionByUserId(Long userId) public Set<String> selectRolePermissionByUserId(Long userId) {
{
List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId); List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
Set<String> permsSet = new HashSet<>(); Set<String> permsSet = new HashSet<>();
for (SysRole perm : perms) for (SysRole perm : perms) {
{ if (StringUtils.isNotNull(perm)) {
if (StringUtils.isNotNull(perm))
{
permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
} }
} }
@ -99,52 +92,47 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 查询所有角色 * 查询所有角色
* *
* @return 角色列表 * @return 角色列表
*/ */
@Override @Override
public List<SysRole> selectRoleAll() public List<SysRole> selectRoleAll() {
{
return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
} }
/** /**
* 根据用户ID获取角色选择框列表 * 根据用户ID获取角色选择框列表
* *
* @param userId 用户ID * @param userId 用户ID
* @return 选中角色ID列表 * @return 选中角色ID列表
*/ */
@Override @Override
public List<Long> selectRoleListByUserId(Long userId) public List<Long> selectRoleListByUserId(Long userId) {
{
return roleMapper.selectRoleListByUserId(userId); return roleMapper.selectRoleListByUserId(userId);
} }
/** /**
* 通过角色ID查询角色 * 通过角色ID查询角色
* *
* @param roleId 角色ID * @param roleId 角色ID
* @return 角色对象信息 * @return 角色对象信息
*/ */
@Override @Override
public SysRole selectRoleById(Long roleId) public SysRole selectRoleById(Long roleId) {
{
return roleMapper.selectRoleById(roleId); return roleMapper.selectRoleById(roleId);
} }
/** /**
* 校验角色名称是否唯一 * 校验角色名称是否唯一
* *
* @param role 角色信息 * @param role 角色信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public boolean checkRoleNameUnique(SysRole role) public boolean checkRoleNameUnique(SysRole role) {
{
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
{
return UserConstants.NOT_UNIQUE; return UserConstants.NOT_UNIQUE;
} }
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
@ -152,17 +140,15 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 校验角色权限是否唯一 * 校验角色权限是否唯一
* *
* @param role 角色信息 * @param role 角色信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public boolean checkRoleKeyUnique(SysRole role) public boolean checkRoleKeyUnique(SysRole role) {
{
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
{
return UserConstants.NOT_UNIQUE; return UserConstants.NOT_UNIQUE;
} }
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
@ -170,33 +156,28 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 校验角色是否允许操作 * 校验角色是否允许操作
* *
* @param role 角色信息 * @param role 角色信息
*/ */
@Override @Override
public void checkRoleAllowed(SysRole role) public void checkRoleAllowed(SysRole role) {
{ if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) {
if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin())
{
throw new ServiceException("不允许操作超级管理员角色"); throw new ServiceException("不允许操作超级管理员角色");
} }
} }
/** /**
* 校验角色是否有数据权限 * 校验角色是否有数据权限
* *
* @param roleId 角色id * @param roleId 角色id
*/ */
@Override @Override
public void checkRoleDataScope(Long roleId) public void checkRoleDataScope(Long roleId) {
{ if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
if (!SysUser.isAdmin(SecurityUtils.getUserId()))
{
SysRole role = new SysRole(); SysRole role = new SysRole();
role.setRoleId(roleId); role.setRoleId(roleId);
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
if (StringUtils.isEmpty(roles)) if (StringUtils.isEmpty(roles)) {
{
throw new ServiceException("没有权限访问角色数据!"); throw new ServiceException("没有权限访问角色数据!");
} }
} }
@ -204,26 +185,24 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 通过角色ID查询角色使用数量 * 通过角色ID查询角色使用数量
* *
* @param roleId 角色ID * @param roleId 角色ID
* @return 结果 * @return 结果
*/ */
@Override @Override
public int countUserRoleByRoleId(Long roleId) public int countUserRoleByRoleId(Long roleId) {
{
return userRoleMapper.countUserRoleByRoleId(roleId); return userRoleMapper.countUserRoleByRoleId(roleId);
} }
/** /**
* 新增保存角色信息 * 新增保存角色信息
* *
* @param role 角色信息 * @param role 角色信息
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int insertRole(SysRole role) public int insertRole(SysRole role) {
{
// 新增角色信息 // 新增角色信息
roleMapper.insertRole(role); roleMapper.insertRole(role);
return insertRoleMenu(role); return insertRoleMenu(role);
@ -231,14 +210,13 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 修改保存角色信息 * 修改保存角色信息
* *
* @param role 角色信息 * @param role 角色信息
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int updateRole(SysRole role) public int updateRole(SysRole role) {
{
// 修改角色信息 // 修改角色信息
roleMapper.updateRole(role); roleMapper.updateRole(role);
// 删除角色与菜单关联 // 删除角色与菜单关联
@ -248,49 +226,44 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 修改角色状态 * 修改角色状态
* *
* @param role 角色信息 * @param role 角色信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateRoleStatus(SysRole role) public int updateRoleStatus(SysRole role) {
{
return roleMapper.updateRole(role); return roleMapper.updateRole(role);
} }
/** /**
* 修改数据权限信息 * 修改数据权限信息
* *
* @param role 角色信息 * @param role 角色信息
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int authDataScope(SysRole role) public int authDataScope(SysRole role) {
{
// 修改角色信息 // 修改角色信息
return roleMapper.updateRole(role); return roleMapper.updateRole(role);
} }
/** /**
* 新增角色菜单信息 * 新增角色菜单信息
* *
* @param role 角色对象 * @param role 角色对象
*/ */
public int insertRoleMenu(SysRole role) public int insertRoleMenu(SysRole role) {
{
int rows = 1; int rows = 1;
// 新增用户与角色管理 // 新增用户与角色管理
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
for (Long menuId : role.getMenuIds()) for (Long menuId : role.getMenuIds()) {
{
SysRoleMenu rm = new SysRoleMenu(); SysRoleMenu rm = new SysRoleMenu();
rm.setRoleId(role.getRoleId()); rm.setRoleId(role.getRoleId());
rm.setMenuId(menuId); rm.setMenuId(menuId);
list.add(rm); list.add(rm);
} }
if (list.size() > 0) if (list.size() > 0) {
{
rows = roleMenuMapper.batchRoleMenu(list); rows = roleMenuMapper.batchRoleMenu(list);
} }
return rows; return rows;
@ -299,14 +272,13 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 通过角色ID删除角色 * 通过角色ID删除角色
* *
* @param roleId 角色ID * @param roleId 角色ID
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int deleteRoleById(Long roleId) public int deleteRoleById(Long roleId) {
{
// 删除角色与菜单关联 // 删除角色与菜单关联
roleMenuMapper.deleteRoleMenuByRoleId(roleId); roleMenuMapper.deleteRoleMenuByRoleId(roleId);
return roleMapper.deleteRoleById(roleId); return roleMapper.deleteRoleById(roleId);
@ -314,21 +286,18 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 批量删除角色信息 * 批量删除角色信息
* *
* @param roleIds 需要删除的角色ID * @param roleIds 需要删除的角色ID
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int deleteRoleByIds(Long[] roleIds) public int deleteRoleByIds(Long[] roleIds) {
{ for (Long roleId : roleIds) {
for (Long roleId : roleIds)
{
checkRoleAllowed(new SysRole(roleId)); checkRoleAllowed(new SysRole(roleId));
checkRoleDataScope(roleId); checkRoleDataScope(roleId);
SysRole role = selectRoleById(roleId); SysRole role = selectRoleById(roleId);
if (countUserRoleByRoleId(roleId) > 0) if (countUserRoleByRoleId(roleId) > 0) {
{
throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
} }
} }
@ -340,43 +309,39 @@ public class SysRoleServiceImpl implements ISysRoleService {
/** /**
* 取消授权用户角色 * 取消授权用户角色
* *
* @param userRole 用户和角色关联信息 * @param userRole 用户和角色关联信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteAuthUser(SysUserRole userRole) public int deleteAuthUser(SysUserRole userRole) {
{
return userRoleMapper.deleteUserRoleInfo(userRole); return userRoleMapper.deleteUserRoleInfo(userRole);
} }
/** /**
* 批量取消授权用户角色 * 批量取消授权用户角色
* *
* @param roleId 角色ID * @param roleId 角色ID
* @param userIds 需要取消授权的用户数据ID * @param userIds 需要取消授权的用户数据ID
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteAuthUsers(Long roleId, Long[] userIds) public int deleteAuthUsers(Long roleId, Long[] userIds) {
{
return userRoleMapper.deleteUserRoleInfos(roleId, userIds); return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
} }
/** /**
* 批量选择授权用户角色 * 批量选择授权用户角色
* *
* @param roleId 角色ID * @param roleId 角色ID
* @param userIds 需要授权的用户数据ID * @param userIds 需要授权的用户数据ID
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertAuthUsers(Long roleId, Long[] userIds) public int insertAuthUsers(Long roleId, Long[] userIds) {
{
// 新增用户与角色管理 // 新增用户与角色管理
List<SysUserRole> list = new ArrayList<SysUserRole>(); List<SysUserRole> list = new ArrayList<SysUserRole>();
for (Long userId : userIds) for (Long userId : userIds) {
{
SysUserRole ur = new SysUserRole(); SysUserRole ur = new SysUserRole();
ur.setUserId(userId); ur.setUserId(userId);
ur.setRoleId(roleId); ur.setRoleId(roleId);

@ -121,7 +121,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if> <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
<if test="roleSort != null">role_sort = #{roleSort},</if> <if test="roleSort != null">role_sort = #{roleSort},</if>
<if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if> <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
<if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
<if test="status != null and status != ''">status = #{status},</if> <if test="status != null and status != ''">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>

@ -2,6 +2,7 @@ package com.psdc.controller.system;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -25,12 +26,10 @@ import com.psdc.service.ISysConfigService;
/** /**
* 参数配置 信息操作处理 * 参数配置 信息操作处理
*
*/ */
@RestController @RestController
@RequestMapping("/system/config") @RequestMapping("/system/config")
public class SysConfigController extends BaseController public class SysConfigController extends BaseController {
{
@Autowired @Autowired
private ISysConfigService configService; private ISysConfigService configService;
@ -39,8 +38,7 @@ public class SysConfigController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:config:list')") @PreAuthorize("@ss.hasPermi('system:config:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysConfig config) public TableDataInfo list(SysConfig config) {
{
startPage(); startPage();
List<SysConfig> list = configService.selectConfigList(config); List<SysConfig> list = configService.selectConfigList(config);
return getDataTable(list); return getDataTable(list);
@ -49,8 +47,7 @@ public class SysConfigController extends BaseController
@Log(title = "参数管理", businessType = BusinessType.EXPORT) @Log(title = "参数管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:config:export')") @PreAuthorize("@ss.hasPermi('system:config:export')")
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, SysConfig config) public void export(HttpServletResponse response, SysConfig config) {
{
List<SysConfig> list = configService.selectConfigList(config); List<SysConfig> list = configService.selectConfigList(config);
ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class); ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);
util.exportExcel(response, list, "参数数据"); util.exportExcel(response, list, "参数数据");
@ -61,8 +58,7 @@ public class SysConfigController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:config:query')") @PreAuthorize("@ss.hasPermi('system:config:query')")
@GetMapping(value = "/{configId}") @GetMapping(value = "/{configId}")
public AjaxResult getInfo(@PathVariable Long configId) public AjaxResult getInfo(@PathVariable Long configId) {
{
return success(configService.selectConfigById(configId)); return success(configService.selectConfigById(configId));
} }
@ -70,8 +66,7 @@ public class SysConfigController extends BaseController
* 根据参数键名查询参数值 * 根据参数键名查询参数值
*/ */
@GetMapping(value = "/configKey/{configKey}") @GetMapping(value = "/configKey/{configKey}")
public AjaxResult getConfigKey(@PathVariable String configKey) public AjaxResult getConfigKey(@PathVariable String configKey) {
{
return success(configService.selectConfigByKey(configKey)); return success(configService.selectConfigByKey(configKey));
} }
@ -81,10 +76,8 @@ public class SysConfigController extends BaseController
@PreAuthorize("@ss.hasPermi('system:config:add')") @PreAuthorize("@ss.hasPermi('system:config:add')")
@Log(title = "参数管理", businessType = BusinessType.INSERT) @Log(title = "参数管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@Validated @RequestBody SysConfig config) public AjaxResult add(@Validated @RequestBody SysConfig config) {
{ if (!configService.checkConfigKeyUnique(config)) {
if (!configService.checkConfigKeyUnique(config))
{
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在"); return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
} }
config.setCreateBy(getUsername()); config.setCreateBy(getUsername());
@ -97,10 +90,8 @@ public class SysConfigController extends BaseController
@PreAuthorize("@ss.hasPermi('system:config:edit')") @PreAuthorize("@ss.hasPermi('system:config:edit')")
@Log(title = "参数管理", businessType = BusinessType.UPDATE) @Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@Validated @RequestBody SysConfig config) public AjaxResult edit(@Validated @RequestBody SysConfig config) {
{ if (!configService.checkConfigKeyUnique(config)) {
if (!configService.checkConfigKeyUnique(config))
{
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在"); return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
} }
config.setUpdateBy(getUsername()); config.setUpdateBy(getUsername());
@ -113,8 +104,7 @@ public class SysConfigController extends BaseController
@PreAuthorize("@ss.hasPermi('system:config:remove')") @PreAuthorize("@ss.hasPermi('system:config:remove')")
@Log(title = "参数管理", businessType = BusinessType.DELETE) @Log(title = "参数管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{configIds}") @DeleteMapping("/{configIds}")
public AjaxResult remove(@PathVariable Long[] configIds) public AjaxResult remove(@PathVariable Long[] configIds) {
{
configService.deleteConfigByIds(configIds); configService.deleteConfigByIds(configIds);
return success(); return success();
} }
@ -125,8 +115,7 @@ public class SysConfigController extends BaseController
@PreAuthorize("@ss.hasPermi('system:config:remove')") @PreAuthorize("@ss.hasPermi('system:config:remove')")
@Log(title = "参数管理", businessType = BusinessType.CLEAN) @Log(title = "参数管理", businessType = BusinessType.CLEAN)
@DeleteMapping("/refreshCache") @DeleteMapping("/refreshCache")
public AjaxResult refreshCache() public AjaxResult refreshCache() {
{
configService.resetConfigCache(); configService.resetConfigCache();
return success(); return success();
} }

@ -26,12 +26,10 @@ import com.psdc.utils.file.MimeTypeUtils;
/** /**
* 个人信息 业务处理 * 个人信息 业务处理
*
*/ */
@RestController @RestController
@RequestMapping("/system/user/profile") @RequestMapping("/system/user/profile")
public class SysProfileController extends BaseController public class SysProfileController extends BaseController {
{
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@ -42,8 +40,7 @@ public class SysProfileController extends BaseController
* 个人信息 * 个人信息
*/ */
@GetMapping @GetMapping
public AjaxResult profile() public AjaxResult profile() {
{
LoginUser loginUser = getLoginUser(); LoginUser loginUser = getLoginUser();
SysUser user = loginUser.getUser(); SysUser user = loginUser.getUser();
AjaxResult ajax = AjaxResult.success(user); AjaxResult ajax = AjaxResult.success(user);
@ -56,24 +53,20 @@ public class SysProfileController extends BaseController
*/ */
@Log(title = "个人信息", businessType = BusinessType.UPDATE) @Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult updateProfile(@RequestBody SysUser user) public AjaxResult updateProfile(@RequestBody SysUser user) {
{
LoginUser loginUser = getLoginUser(); LoginUser loginUser = getLoginUser();
SysUser sysUser = loginUser.getUser(); SysUser sysUser = loginUser.getUser();
user.setUserName(sysUser.getUserName()); user.setUserName(sysUser.getUserName());
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
{
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
} }
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
{
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
user.setUserId(sysUser.getUserId()); user.setUserId(sysUser.getUserId());
user.setPassword(null); user.setPassword(null);
user.setAvatar(null); user.setAvatar(null);
if (userService.updateUserProfile(user) > 0) if (userService.updateUserProfile(user) > 0) {
{
// 更新缓存用户信息 // 更新缓存用户信息
sysUser.setNickName(user.getNickName()); sysUser.setNickName(user.getNickName());
sysUser.setPhonenumber(user.getPhonenumber()); sysUser.setPhonenumber(user.getPhonenumber());
@ -90,21 +83,17 @@ public class SysProfileController extends BaseController
*/ */
@Log(title = "个人信息", businessType = BusinessType.UPDATE) @Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd") @PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword) public AjaxResult updatePwd(String oldPassword, String newPassword) {
{
LoginUser loginUser = getLoginUser(); LoginUser loginUser = getLoginUser();
String userName = loginUser.getUsername(); String userName = loginUser.getUsername();
String password = loginUser.getPassword(); String password = loginUser.getPassword();
if (!SecurityUtils.matchesPassword(oldPassword, password)) if (!SecurityUtils.matchesPassword(oldPassword, password)) {
{
return error("修改密码失败,旧密码错误"); return error("修改密码失败,旧密码错误");
} }
if (SecurityUtils.matchesPassword(newPassword, password)) if (SecurityUtils.matchesPassword(newPassword, password)) {
{
return error("新密码不能与旧密码相同"); return error("新密码不能与旧密码相同");
} }
if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0) if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0) {
{
// 更新缓存用户密码 // 更新缓存用户密码
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword)); loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
tokenService.setLoginUser(loginUser); tokenService.setLoginUser(loginUser);
@ -118,14 +107,11 @@ public class SysProfileController extends BaseController
*/ */
@Log(title = "用户头像", businessType = BusinessType.UPDATE) @Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar") @PostMapping("/avatar")
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception {
{ if (!file.isEmpty()) {
if (!file.isEmpty())
{
LoginUser loginUser = getLoginUser(); LoginUser loginUser = getLoginUser();
String avatar = FileUploadUtils.upload(PsdcConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION); String avatar = FileUploadUtils.upload(PsdcConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
{
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("imgUrl", avatar); ajax.put("imgUrl", avatar);
// 更新缓存用户头像 // 更新缓存用户头像

@ -33,12 +33,10 @@ import com.psdc.service.ISysRoleService;
/** /**
* 角色信息 * 角色信息
*
*/ */
@RestController @RestController
@RequestMapping("/system/role") @RequestMapping("/system/role")
public class SysRoleController extends BaseController public class SysRoleController extends BaseController {
{
@Autowired @Autowired
private ISysRoleService roleService; private ISysRoleService roleService;
@ -52,11 +50,9 @@ public class SysRoleController extends BaseController
private ISysUserService userService; private ISysUserService userService;
@PreAuthorize("@ss.hasPermi('system:role:list')") @PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysRole role) public TableDataInfo list(SysRole role) {
{
startPage(); startPage();
List<SysRole> list = roleService.selectRoleList(role); List<SysRole> list = roleService.selectRoleList(role);
return getDataTable(list); return getDataTable(list);
@ -65,8 +61,7 @@ public class SysRoleController extends BaseController
@Log(title = "角色管理", businessType = BusinessType.EXPORT) @Log(title = "角色管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:role:export')") @PreAuthorize("@ss.hasPermi('system:role:export')")
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, SysRole role) public void export(HttpServletResponse response, SysRole role) {
{
List<SysRole> list = roleService.selectRoleList(role); List<SysRole> list = roleService.selectRoleList(role);
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class); ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
util.exportExcel(response, list, "角色数据"); util.exportExcel(response, list, "角色数据");
@ -77,8 +72,7 @@ public class SysRoleController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:role:query')") @PreAuthorize("@ss.hasPermi('system:role:query')")
@GetMapping(value = "/{roleId}") @GetMapping(value = "/{roleId}")
public AjaxResult getInfo(@PathVariable Long roleId) public AjaxResult getInfo(@PathVariable Long roleId) {
{
roleService.checkRoleDataScope(roleId); roleService.checkRoleDataScope(roleId);
return success(roleService.selectRoleById(roleId)); return success(roleService.selectRoleById(roleId));
} }
@ -89,14 +83,10 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:add')") @PreAuthorize("@ss.hasPermi('system:role:add')")
@Log(title = "角色管理", businessType = BusinessType.INSERT) @Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@Validated @RequestBody SysRole role) public AjaxResult add(@Validated @RequestBody SysRole role) {
{ if (!roleService.checkRoleNameUnique(role)) {
if (!roleService.checkRoleNameUnique(role))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
} } else if (!roleService.checkRoleKeyUnique(role)) {
else if (!roleService.checkRoleKeyUnique(role))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
} }
role.setCreateBy(getUsername()); role.setCreateBy(getUsername());
@ -110,26 +100,20 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')") @PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.UPDATE) @Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@Validated @RequestBody SysRole role) public AjaxResult edit(@Validated @RequestBody SysRole role) {
{
roleService.checkRoleAllowed(role); roleService.checkRoleAllowed(role);
roleService.checkRoleDataScope(role.getRoleId()); roleService.checkRoleDataScope(role.getRoleId());
if (!roleService.checkRoleNameUnique(role)) if (!roleService.checkRoleNameUnique(role)) {
{
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
} } else if (!roleService.checkRoleKeyUnique(role)) {
else if (!roleService.checkRoleKeyUnique(role))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
} }
role.setUpdateBy(getUsername()); role.setUpdateBy(getUsername());
if (roleService.updateRole(role) > 0) if (roleService.updateRole(role) > 0) {
{
// 更新缓存用户权限 // 更新缓存用户权限
LoginUser loginUser = getLoginUser(); LoginUser loginUser = getLoginUser();
if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) {
{
loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
tokenService.setLoginUser(loginUser); tokenService.setLoginUser(loginUser);
@ -145,8 +129,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')") @PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.UPDATE) @Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PutMapping("/dataScope") @PutMapping("/dataScope")
public AjaxResult dataScope(@RequestBody SysRole role) public AjaxResult dataScope(@RequestBody SysRole role) {
{
roleService.checkRoleAllowed(role); roleService.checkRoleAllowed(role);
roleService.checkRoleDataScope(role.getRoleId()); roleService.checkRoleDataScope(role.getRoleId());
return toAjax(roleService.authDataScope(role)); return toAjax(roleService.authDataScope(role));
@ -158,8 +141,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')") @PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.UPDATE) @Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus") @PutMapping("/changeStatus")
public AjaxResult changeStatus(@RequestBody SysRole role) public AjaxResult changeStatus(@RequestBody SysRole role) {
{
roleService.checkRoleAllowed(role); roleService.checkRoleAllowed(role);
roleService.checkRoleDataScope(role.getRoleId()); roleService.checkRoleDataScope(role.getRoleId());
role.setUpdateBy(getUsername()); role.setUpdateBy(getUsername());
@ -172,8 +154,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:remove')") @PreAuthorize("@ss.hasPermi('system:role:remove')")
@Log(title = "角色管理", businessType = BusinessType.DELETE) @Log(title = "角色管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{roleIds}") @DeleteMapping("/{roleIds}")
public AjaxResult remove(@PathVariable Long[] roleIds) public AjaxResult remove(@PathVariable Long[] roleIds) {
{
return toAjax(roleService.deleteRoleByIds(roleIds)); return toAjax(roleService.deleteRoleByIds(roleIds));
} }
@ -182,8 +163,7 @@ public class SysRoleController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:role:query')") @PreAuthorize("@ss.hasPermi('system:role:query')")
@GetMapping("/optionselect") @GetMapping("/optionselect")
public AjaxResult optionselect() public AjaxResult optionselect() {
{
return success(roleService.selectRoleAll()); return success(roleService.selectRoleAll());
} }
@ -192,8 +172,7 @@ public class SysRoleController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:role:list')") @PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/authUser/allocatedList") @GetMapping("/authUser/allocatedList")
public TableDataInfo allocatedList(SysUser user) public TableDataInfo allocatedList(SysUser user) {
{
startPage(); startPage();
List<SysUser> list = userService.selectAllocatedList(user); List<SysUser> list = userService.selectAllocatedList(user);
return getDataTable(list); return getDataTable(list);
@ -204,8 +183,7 @@ public class SysRoleController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:role:list')") @PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/authUser/unallocatedList") @GetMapping("/authUser/unallocatedList")
public TableDataInfo unallocatedList(SysUser user) public TableDataInfo unallocatedList(SysUser user) {
{
startPage(); startPage();
List<SysUser> list = userService.selectUnallocatedList(user); List<SysUser> list = userService.selectUnallocatedList(user);
return getDataTable(list); return getDataTable(list);
@ -217,8 +195,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')") @PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT) @Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/cancel") @PutMapping("/authUser/cancel")
public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) {
{
return toAjax(roleService.deleteAuthUser(userRole)); return toAjax(roleService.deleteAuthUser(userRole));
} }
@ -228,8 +205,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')") @PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT) @Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/cancelAll") @PutMapping("/authUser/cancelAll")
public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) {
{
return toAjax(roleService.deleteAuthUsers(roleId, userIds)); return toAjax(roleService.deleteAuthUsers(roleId, userIds));
} }
@ -239,8 +215,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')") @PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT) @Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/selectAll") @PutMapping("/authUser/selectAll")
public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) {
{
roleService.checkRoleDataScope(roleId); roleService.checkRoleDataScope(roleId);
return toAjax(roleService.insertAuthUsers(roleId, userIds)); return toAjax(roleService.insertAuthUsers(roleId, userIds));
} }

Loading…
Cancel
Save