增加operator user,提取事务方法成为单独service接口
This commit is contained in:
parent
02a455c08f
commit
0a3d17eb43
@ -78,6 +78,11 @@
|
||||
<artifactId>ruoyi-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>xhpc-common</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package com.xhpc.system;
|
||||
package com.xhpc;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import com.xhpc.common.security.annotation.EnableCustomConfig;
|
||||
import com.xhpc.common.security.annotation.EnableRyFeignClients;
|
||||
import com.xhpc.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 系统模块
|
||||
@ -0,0 +1,14 @@
|
||||
package com.xhpc.system.service;
|
||||
|
||||
import com.xhpc.system.api.domain.SysUser;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public interface SysUserPostRoleService {
|
||||
|
||||
@Transactional
|
||||
void insertUserPost(SysUser user);
|
||||
|
||||
@Transactional
|
||||
void insertUserRole(SysUser user);
|
||||
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
package com.xhpc.system.service.impl;
|
||||
|
||||
import com.xhpc.common.core.utils.StringUtils;
|
||||
import com.xhpc.system.api.domain.SysUser;
|
||||
import com.xhpc.system.domain.SysUserPost;
|
||||
import com.xhpc.system.domain.SysUserRole;
|
||||
import com.xhpc.system.mapper.SysUserPostMapper;
|
||||
import com.xhpc.system.mapper.SysUserRoleMapper;
|
||||
import com.xhpc.system.service.SysUserPostRoleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SysUserPostRoleServiceImpl implements SysUserPostRoleService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SysUserPostRoleServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserPostMapper userPostMapper;
|
||||
/**
|
||||
* 新增用户岗位信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void insertUserPost(SysUser user)
|
||||
{
|
||||
Long[] posts = user.getPostIds();
|
||||
if (StringUtils.isNotNull(posts))
|
||||
{
|
||||
// 新增用户与岗位管理
|
||||
List<SysUserPost> list = new ArrayList<SysUserPost>();
|
||||
for (Long postId : posts)
|
||||
{
|
||||
SysUserPost up = new SysUserPost();
|
||||
up.setUserId(user.getUserId());
|
||||
up.setPostId(postId);
|
||||
list.add(up);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
userPostMapper.batchUserPost(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户角色信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void insertUserRole(SysUser user)
|
||||
{
|
||||
Long[] roles = user.getRoleIds();
|
||||
if (StringUtils.isNotNull(roles))
|
||||
{
|
||||
// 新增用户与角色管理
|
||||
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
||||
for (Long roleId : roles)
|
||||
{
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(user.getUserId());
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
userRoleMapper.batchUserRole(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,18 +1,5 @@
|
||||
package com.xhpc.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.xhpc.system.domain.SysPost;
|
||||
import com.xhpc.system.domain.SysUserPost;
|
||||
import com.xhpc.system.domain.SysUserRole;
|
||||
import com.xhpc.system.service.ISysConfigService;
|
||||
import com.xhpc.system.service.ISysUserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.xhpc.common.core.constant.UserConstants;
|
||||
import com.xhpc.common.core.exception.CustomException;
|
||||
import com.xhpc.common.core.utils.SecurityUtils;
|
||||
@ -20,11 +7,20 @@ import com.xhpc.common.core.utils.StringUtils;
|
||||
import com.xhpc.common.datascope.annotation.DataScope;
|
||||
import com.xhpc.system.api.domain.SysRole;
|
||||
import com.xhpc.system.api.domain.SysUser;
|
||||
import com.xhpc.system.mapper.SysPostMapper;
|
||||
import com.xhpc.system.mapper.SysRoleMapper;
|
||||
import com.xhpc.system.mapper.SysUserMapper;
|
||||
import com.xhpc.system.mapper.SysUserPostMapper;
|
||||
import com.xhpc.system.mapper.SysUserRoleMapper;
|
||||
import com.xhpc.system.domain.SysPost;
|
||||
import com.xhpc.system.domain.SysUserRole;
|
||||
import com.xhpc.system.mapper.*;
|
||||
import com.xhpc.system.service.ISysConfigService;
|
||||
import com.xhpc.system.service.ISysUserService;
|
||||
import com.xhpc.system.service.SysUserPostRoleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户 业务层处理
|
||||
@ -54,6 +50,9 @@ public class SysUserServiceImpl implements ISysUserService
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private SysUserPostRoleService sysUserPostRoleService;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
@ -241,9 +240,9 @@ public class SysUserServiceImpl implements ISysUserService
|
||||
// 新增用户信息
|
||||
int rows = userMapper.insertUser(user);
|
||||
// 新增用户岗位关联
|
||||
insertUserPost(user);
|
||||
sysUserPostRoleService.insertUserPost(user);
|
||||
// 新增用户与角色管理
|
||||
insertUserRole(user);
|
||||
sysUserPostRoleService.insertUserRole(user);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@ -261,11 +260,11 @@ public class SysUserServiceImpl implements ISysUserService
|
||||
// 删除用户与角色关联
|
||||
userRoleMapper.deleteUserRoleByUserId(userId);
|
||||
// 新增用户与角色管理
|
||||
insertUserRole(user);
|
||||
sysUserPostRoleService.insertUserRole(user);
|
||||
// 删除用户与岗位关联
|
||||
userPostMapper.deleteUserPostByUserId(userId);
|
||||
// 新增用户与岗位管理
|
||||
insertUserPost(user);
|
||||
sysUserPostRoleService.insertUserPost(user);
|
||||
return userMapper.updateUser(user);
|
||||
}
|
||||
|
||||
@ -344,58 +343,6 @@ public class SysUserServiceImpl implements ISysUserService
|
||||
return userMapper.resetUserPwd(userName, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户角色信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
public void insertUserRole(SysUser user)
|
||||
{
|
||||
Long[] roles = user.getRoleIds();
|
||||
if (StringUtils.isNotNull(roles))
|
||||
{
|
||||
// 新增用户与角色管理
|
||||
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
||||
for (Long roleId : roles)
|
||||
{
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(user.getUserId());
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
userRoleMapper.batchUserRole(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户岗位信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
public void insertUserPost(SysUser user)
|
||||
{
|
||||
Long[] posts = user.getPostIds();
|
||||
if (StringUtils.isNotNull(posts))
|
||||
{
|
||||
// 新增用户与岗位管理
|
||||
List<SysUserPost> list = new ArrayList<SysUserPost>();
|
||||
for (Long postId : posts)
|
||||
{
|
||||
SysUserPost up = new SysUserPost();
|
||||
up.setUserId(user.getUserId());
|
||||
up.setPostId(postId);
|
||||
list.add(up);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
userPostMapper.batchUserPost(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户角色信息
|
||||
*
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.xhpc.user;
|
||||
package com.xhpc;
|
||||
|
||||
import com.xhpc.common.security.annotation.EnableCustomConfig;
|
||||
import com.xhpc.common.security.annotation.EnableRyFeignClients;
|
||||
Loading…
x
Reference in New Issue
Block a user