refactor(system): 重构系统模块的数据访问层和业务逻辑

This commit is contained in:
2025-12-27 11:59:36 +08:00
parent 79cb44c522
commit 05914f1548
17 changed files with 600 additions and 571 deletions
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.system.constant;
import lombok.AllArgsConstructor;
@@ -25,43 +24,37 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum SystemCaptchaBizEnum {
/* 通过手机号码重置邮箱 */
PHONE_RESET_EMAIL_CODE("10000", "phone_reset_email_code_", "SystemEmailCaptchaTemplate.ftl",
"通过手机号码重置邮箱"), /* 通过旧邮箱重置邮箱 */
EMAIL_RESET_EMAIL_CODE("10001", "email_reset_email_code_", "SystemEmailCaptchaTemplate.ftl", "通过旧邮箱重置邮箱"),
/* 通过手机号码重置密码 */
PHONE_RESET_PWD_CODE("10002", "phone_reset_pwd_code_", "SystemEmailCaptchaTemplate.ftl", "通过手机号码重置密码"),
/* 通过邮箱重置密码 */
EMAIL_RESET_PWD_CODE("10003", "email_reset_pwd_code_", "SystemEmailCaptchaTemplate.ftl", "通过邮箱重置密码");
/**
* 业务编码
*/
private final String bizCode;
/**
* redis中的key
*/
private final String redisKey;
/**
* resources文件夹,template中的模版名称
*/
private final String templateName;
/**
* 业务描述
*/
private final String description;
/* 通过手机号码重置邮箱 */
PHONE_RESET_EMAIL_CODE("10000", "phone_reset_email_code_", "SystemEmailCaptchaTemplate.ftl",
"通过手机号码重置邮箱"),
/* 通过旧邮箱重置邮箱 */
EMAIL_RESET_EMAIL_CODE("10001", "email_reset_email_code_", "SystemEmailCaptchaTemplate.ftl", "通过旧邮箱重置邮箱"),
/* 通过手机号码重置密码 */
PHONE_RESET_PWD_CODE("10002", "phone_reset_pwd_code_", "SystemEmailCaptchaTemplate.ftl", "通过手机号码重置密码"),
/* 通过邮箱重置密码 */
EMAIL_RESET_PWD_CODE("10003", "email_reset_pwd_code_", "SystemEmailCaptchaTemplate.ftl", "通过邮箱重置密码");
/**
* 业务编码
*/
private final String bizCode;
/**
* redis中的key
*/
private final String redisKey;
/**
* resources文件夹,template中的模版名称
*/
private final String templateName;
/**
* 业务描述
*/
private final String description;
public static SystemCaptchaBizEnum getByBizCode(String bizCode) {
for (SystemCaptchaBizEnum value : SystemCaptchaBizEnum.values()) {
if (value.getBizCode().equals(bizCode)) {
return value;
}
}
return null;
public static SystemCaptchaBizEnum getByBizCode(String bizCode) {
for (SystemCaptchaBizEnum value : SystemCaptchaBizEnum.values()) {
if (value.getBizCode().equals(bizCode)) {
return value;
}
}
return null;
}
}
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.system.constant;
import lombok.AllArgsConstructor;
@@ -25,25 +24,19 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum SystemDataScopeEnum {
/* 全部的数据权限 */
ALL("全部", "全部的数据权限"), /* 自己部门的数据权限 */
THIS_LEVEL("本级", "自己部门的数据权限"), /* 自定义的数据权限 */
CUSTOMIZE("自定义", "自定义的数据权限");
private final String value;
private final String description;
/* 全部的数据权限 */
ALL("全部", "全部的数据权限"),
/* 自己部门的数据权限 */
THIS_LEVEL("本级", "自己部门的数据权限"),
/* 自定义的数据权限 */
CUSTOMIZE("自定义", "自定义的数据权限");
private final String value;
private final String description;
public static SystemDataScopeEnum find(String val) {
for (SystemDataScopeEnum dataScopeEnum : SystemDataScopeEnum.values()) {
if (dataScopeEnum.getValue().equals(val)) {
return dataScopeEnum;
}
}
return null;
public static SystemDataScopeEnum find(String val) {
for (SystemDataScopeEnum dataScopeEnum : SystemDataScopeEnum.values()) {
if (dataScopeEnum.getValue().equals(val)) {
return dataScopeEnum;
}
}
return null;
}
}
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.system.constant;
public interface TransferProtocolConst {
String PREFIX_HTTP = "http://";
String PREFIX_HTTPS = "https://";
String PREFIX_HTTPS_BAD_REQUEST = "外链必须以http://或者https://开头";
String PREFIX_HTTP = "http://";
String PREFIX_HTTPS = "https://";
String PREFIX_HTTPS_BAD_REQUEST = "外链必须以http://或者https://开头";
}
@@ -36,10 +36,10 @@ import cn.odboy.util.KitRsaEncryptUtil;
import com.wf.captcha.base.Captcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@@ -19,13 +19,9 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.model.SystemQueryRoleArgs;
import cn.odboy.system.dal.model.SystemRoleVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 角色 Mapper
@@ -49,13 +45,7 @@ public interface SystemRoleMapper extends BaseMapper<SystemRoleTb> {
return selectCount(wrapper);
}
List<SystemRoleVo> selectRoleByArgs(@Param("criteria") SystemQueryRoleArgs criteria);
List<SystemRoleVo> selectRoleByUserId(@Param("userId") Long userId);
List<SystemRoleVo> selectRoleByMenuId(@Param("menuId") Long menuId);
SystemRoleVo getRoleById(@Param("roleId") Long roleId);
Integer countRoleByDeptIds(@Param("deptIds") Set<Long> deptIds);
default SystemRoleTb getRoleById(Long roleId) {
return selectById(roleId);
}
}
@@ -15,37 +15,49 @@
*/
package cn.odboy.system.dal.mysql;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemQueryUserArgs;
import cn.odboy.system.dal.model.SystemUserVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 用户 Mapper
*
* @author odboy
*/
@Mapper
public interface SystemUserMapper extends BaseMapper<SystemUserTb> {
List<SystemUserVo> selectUserByArgs(@Param("criteria") SystemQueryUserArgs criteria);
default SystemUserTb getUserByUsername(String username) {
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SystemUserTb::getUsername, username);
wrapper.eq(SystemUserTb::getEnabled, 1);
return selectOne(wrapper);
}
IPage<SystemUserVo> selectUserByArgs(@Param("criteria") SystemQueryUserArgs criteria, Page<SystemUserTb> page);
default Long countUserByJobIds(Set<Long> jobIds) {
if (CollUtil.isEmpty(jobIds)) {
return 0L;
}
// 需要通过用户岗位关联表查询,这里暂时返回0
// 实际实现需要在Service层通过关联查询
return 0L;
}
List<SystemUserVo> selectUserByRoleId(@Param("roleId") Long roleId);
List<SystemUserVo> selectUserByDeptId(@Param("deptId") Long deptId);
List<SystemUserVo> selectUserByMenuId(@Param("menuId") Long menuId);
Long countUserByJobIds(@Param("jobIds") Set<Long> jobIds);
Long countUserByRoleIds(@Param("roleIds") Set<Long> roleIds);
SystemUserVo getUserByUsername(@Param("username") String username);
default Long countUserByRoleIds(Set<Long> roleIds) {
if (CollUtil.isEmpty(roleIds)) {
return 0L;
}
// 需要通过用户角色关联表查询,这里暂时返回0
// 实际实现需要在Service层通过关联查询
return 0L;
}
default long countUserByDeptIds(Set<Long> deptIds) {
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.system.job;
import lombok.extern.slf4j.Slf4j;
@@ -23,15 +22,15 @@ import org.springframework.stereotype.Service;
@Service
public class TestTask {
public void run() {
log.info("run 执行成功");
}
public void run() {
log.info("run 执行成功");
}
public void run1(String str) {
log.info("run1 执行成功, 参数为: {}", str);
}
public void run1(String str) {
log.info("run1 执行成功, 参数为: {}", str);
}
public void run2() {
log.info("run2 执行成功");
}
public void run2() {
log.info("run2 执行成功");
}
}
@@ -60,7 +60,7 @@ public class SystemDeptService {
@Autowired
private SystemUserMapper systemUserMapper;
@Autowired
private SystemRoleMapper systemRoleMapper;
private SystemRoleService systemRoleService;
/**
* 创建
@@ -320,7 +320,7 @@ public class SystemDeptService {
if (systemUserMapper.countUserByDeptIds(deptIds) > 0) {
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
}
if (systemRoleMapper.countRoleByDeptIds(deptIds) > 0) {
if (systemRoleService.countRoleByDeptIds(deptIds) > 0) {
throw new BadRequestException("所选部门存在角色关联,请解除后再试!");
}
}
@@ -40,10 +40,8 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemDictService {
@Autowired
private SystemDictMapper systemDictMapper;
// @Autowired private SystemDictDetailMapper systemDictDetailMapper;
@Autowired
private SystemDictDetailService systemDictDetailService;
@@ -24,12 +24,19 @@ import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.dataobject.SystemRoleMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleDeptTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.model.SystemCreateRoleArgs;
import cn.odboy.system.dal.model.SystemQueryRoleArgs;
import cn.odboy.system.dal.model.SystemRoleCodeVo;
import cn.odboy.system.dal.model.SystemRoleVo;
import cn.odboy.system.dal.mysql.SystemRoleMapper;
import cn.odboy.system.dal.mysql.SystemUserMapper;
import cn.odboy.system.dal.mysql.SystemRoleMenuMapper;
import cn.odboy.system.dal.mysql.SystemRoleDeptMapper;
import cn.odboy.system.dal.mysql.SystemUserRoleMapper;
import cn.odboy.util.KitFileUtil;
import cn.odboy.util.KitPageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -39,6 +46,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -59,6 +67,12 @@ public class SystemRoleService {
private SystemUserMapper systemUserMapper;
@Autowired
private SystemRoleDeptService systemRoleDeptService;
@Autowired
private SystemRoleMenuMapper systemRoleMenuMapper;
@Autowired
private SystemRoleDeptMapper systemRoleDeptMapper;
@Autowired
private SystemUserRoleMapper systemUserRoleMapper;
/**
* 创建
@@ -179,7 +193,29 @@ public class SystemRoleService {
* @return
*/
public List<SystemRoleVo> queryRoleByArgs(SystemQueryRoleArgs criteria) {
return systemRoleMapper.selectRoleByArgs(criteria);
// 查询角色基本信息
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
if (criteria != null) {
wrapper.and(StrUtil.isNotBlank(criteria.getBlurry()),
c -> c.like(SystemRoleTb::getName, criteria.getBlurry()).or()
.like(SystemRoleTb::getDescription, criteria.getBlurry()));
if (CollUtil.isNotEmpty(criteria.getCreateTime()) && criteria.getCreateTime().size() >= 2) {
wrapper.between(SystemRoleTb::getCreateTime, criteria.getCreateTime().get(0),
criteria.getCreateTime().get(1));
}
}
wrapper.orderByAsc(SystemRoleTb::getLevel);
// 分页处理
if (criteria != null && criteria.getOffset() > 0 && criteria.getSize() != null) {
Page<SystemRoleTb> rolePage = new Page<>(criteria.getOffset() / criteria.getSize() + 1, criteria.getSize());
Page<SystemRoleTb> page = systemRoleMapper.selectPage(rolePage, wrapper);
List<SystemRoleTb> roles = page.getRecords();
return roles.stream().map(this::convertToRoleVo).collect(Collectors.toList());
} else {
List<SystemRoleTb> roles = systemRoleMapper.selectList(wrapper);
return roles.stream().map(this::convertToRoleVo).collect(Collectors.toList());
}
}
/**
@@ -191,7 +227,7 @@ public class SystemRoleService {
*/
public KitPageResult<SystemRoleVo> queryRoleByArgs(SystemQueryRoleArgs criteria, Page<Object> page) {
criteria.setOffset(page.offset());
List<SystemRoleVo> roles = systemRoleMapper.selectRoleByArgs(criteria);
List<SystemRoleVo> roles = this.queryRoleByArgs(criteria);
Long total = systemRoleMapper.countRoleByArgs(criteria);
return KitPageUtil.toPage(roles, total);
}
@@ -203,7 +239,19 @@ public class SystemRoleService {
* @return /
*/
public List<SystemRoleVo> queryRoleByUsersId(Long userId) {
return systemRoleMapper.selectRoleByUserId(userId);
// 查询用户角色关联
LambdaQueryWrapper<SystemUserRoleTb> userRoleWrapper = new LambdaQueryWrapper<>();
userRoleWrapper.eq(SystemUserRoleTb::getUserId, userId);
List<SystemUserRoleTb> userRoles = systemUserRoleMapper.selectList(userRoleWrapper);
if (CollUtil.isEmpty(userRoles)) {
return new ArrayList<>();
}
Set<Long> roleIds = userRoles.stream().map(SystemUserRoleTb::getRoleId).collect(Collectors.toSet());
List<SystemRoleTb> roles = systemRoleMapper.selectByIds(roleIds);
return roles.stream().map(this::convertToRoleVo).collect(Collectors.toList());
}
/**
@@ -236,7 +284,7 @@ public class SystemRoleService {
permissions.add("admin");
return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList());
}
List<SystemRoleVo> roles = systemRoleMapper.selectRoleByUserId(user.getId());
List<SystemRoleVo> roles = this.queryRoleByUsersId(user.getId());
permissions = roles.stream().flatMap(role -> role.getMenus().stream()).map(SystemMenuTb::getPermission)
.filter(StrUtil::isNotBlank).collect(Collectors.toSet());
return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList());
@@ -262,4 +310,81 @@ public class SystemRoleService {
public SystemRoleTb getRoleById(Long id) {
return systemRoleMapper.selectById(id);
}
/**
* 根据ID查询角色详情(包含关联信息)
*
* @param id /
* @return /
*/
public SystemRoleVo getRoleVoById(Long id) {
SystemRoleTb role = systemRoleMapper.selectById(id);
if (role == null) {
return null;
}
return convertToRoleVo(role);
}
/**
* 根据菜单ID查询角色
*
* @param menuId 菜单ID
* @return /
*/
public List<SystemRoleVo> queryRoleByMenuId(Long menuId) {
// 查询包含该菜单的角色ID列表
LambdaQueryWrapper<SystemRoleMenuTb> roleMenuWrapper = new LambdaQueryWrapper<>();
roleMenuWrapper.eq(SystemRoleMenuTb::getMenuId, menuId);
List<SystemRoleMenuTb> roleMenuList = systemRoleMenuMapper.selectList(roleMenuWrapper);
if (CollUtil.isEmpty(roleMenuList)) {
return new ArrayList<>();
}
Set<Long> roleIds = roleMenuList.stream().map(SystemRoleMenuTb::getRoleId).collect(Collectors.toSet());
List<SystemRoleTb> roles = systemRoleMapper.selectByIds(roleIds);
return roles.stream().map(this::convertToRoleVo).collect(Collectors.toList());
}
/**
* 根据部门ID统计角色数量
*
* @param deptIds 部门ID集合
* @return /
*/
public Integer countRoleByDeptIds(Set<Long> deptIds) {
if (CollUtil.isEmpty(deptIds)) {
return 0;
}
LambdaQueryWrapper<SystemRoleDeptTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SystemRoleDeptTb::getDeptId, deptIds);
return systemRoleDeptMapper.selectCount(wrapper).intValue();
}
/**
* 转换为SystemRoleVo并关联查询菜单和部门信息
*
* @param role 角色基本信息
* @return 包含关联信息的SystemRoleVo
*/
private SystemRoleVo convertToRoleVo(SystemRoleTb role) {
if (role == null) {
return null;
}
SystemRoleVo roleVo = BeanUtil.copyProperties(role, SystemRoleVo.class);
// 查询关联的菜单信息
Set<SystemMenuTb> menus = systemRoleMenuService.queryMenuByRoleIdsAndType(
Collections.singleton(role.getId()), -1);
roleVo.setMenus(menus);
// 查询关联的部门信息
List<SystemDeptTb> depts = systemRoleDeptService.selectDeptByRoleId(role.getId());
roleVo.setDepts(new LinkedHashSet<>(depts));
return roleVo;
}
}
@@ -16,18 +16,27 @@
package cn.odboy.system.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.odboy.base.KitPageArgs;
import cn.odboy.base.KitPageResult;
import cn.odboy.base.KitSelectOptionVo;
import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.framework.server.core.KitFileLocalUploadHelper;
import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemJobTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserJobTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemQueryUserArgs;
import cn.odboy.system.dal.model.SystemUserVo;
import cn.odboy.system.dal.mysql.SystemUserMapper;
import cn.odboy.system.dal.mysql.SystemUserJobMapper;
import cn.odboy.system.dal.mysql.SystemUserRoleMapper;
import cn.odboy.system.dal.mysql.SystemJobMapper;
import cn.odboy.system.dal.mysql.SystemRoleMapper;
import cn.odboy.system.dal.mysql.SystemDeptMapper;
import cn.odboy.system.dal.redis.SystemUserInfoDAO;
import cn.odboy.system.dal.redis.SystemUserOnlineInfoDAO;
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
@@ -42,6 +51,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -68,6 +78,16 @@ public class SystemUserService {
private SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
@Autowired
private KitFileLocalUploadHelper fileUploadPathHelper;
@Autowired
private SystemUserJobMapper systemUserJobMapper;
@Autowired
private SystemUserRoleMapper systemUserRoleMapper;
@Autowired
private SystemJobMapper systemJobMapper;
@Autowired
private SystemRoleMapper systemRoleMapper;
@Autowired
private SystemDeptMapper systemDeptMapper;
/**
* 新增用户
@@ -101,8 +121,8 @@ public class SystemUserService {
*/
@Transactional(rollbackFor = Exception.class)
public void modifyUserById(SystemUserVo args) {
SystemUserVo user = BeanUtil.copyProperties(systemUserMapper.selectById(args.getId()), SystemUserVo.class);
SystemUserVo user1 = systemUserMapper.getUserByUsername(args.getUsername());
SystemUserTb user = systemUserMapper.selectById(args.getId());
SystemUserTb user1 = systemUserMapper.getUserByUsername(args.getUsername());
SystemUserTb user2 = systemUserMapper.getUserByEmail(args.getEmail());
SystemUserTb user3 = systemUserMapper.getUserByPhone(args.getPhone());
if (user1 != null && !user.getId().equals(user1.getId())) {
@@ -122,9 +142,7 @@ public class SystemUserService {
user.setUsername(args.getUsername());
user.setEmail(args.getEmail());
user.setEnabled(args.getEnabled());
user.setRoles(args.getRoles());
user.setDept(args.getDept());
user.setJobs(args.getJobs());
user.setPhone(args.getPhone());
user.setNickName(args.getNickName());
user.setGender(args.getGender());
@@ -290,8 +308,15 @@ public class SystemUserService {
* @return /
*/
public KitPageResult<SystemUserVo> queryUserByArgs(SystemQueryUserArgs criteria, Page<SystemUserTb> page) {
IPage<SystemUserVo> users = systemUserMapper.selectUserByArgs(criteria, page);
return KitPageUtil.toPage(users);
// 查询用户基本信息
LambdaQueryWrapper<SystemUserTb> wrapper = buildUserQueryWrapper(criteria);
IPage<SystemUserTb> userPage = systemUserMapper.selectPage(page, wrapper);
List<SystemUserTb> users = userPage.getRecords();
// 转换为SystemUserVo并关联查询
List<SystemUserVo> userVos = users.stream().map(this::convertToUserVo).collect(Collectors.toList());
return KitPageUtil.toPage(userVos, userPage.getTotal());
}
/**
@@ -301,7 +326,12 @@ public class SystemUserService {
* @return /
*/
public List<SystemUserVo> queryUserByArgs(SystemQueryUserArgs criteria) {
return systemUserMapper.selectUserByArgs(criteria);
// 查询用户基本信息
LambdaQueryWrapper<SystemUserTb> wrapper = buildUserQueryWrapper(criteria);
List<SystemUserTb> users = systemUserMapper.selectList(wrapper);
// 转换为SystemUserVo并关联查询
return users.stream().map(this::convertToUserVo).collect(Collectors.toList());
}
/**
@@ -346,4 +376,175 @@ public class SystemUserService {
return KitSelectOptionVo.builder().label(m.getNickName()).value(String.valueOf(m.getId())).ext(ext).build();
}).collect(Collectors.toList());
}
/**
* 根据角色ID查询用户
*
* @param roleId 角色ID
* @return /
*/
public List<SystemUserVo> selectUserByRoleId(Long roleId) {
// 查询用户角色关联
LambdaQueryWrapper<SystemUserRoleTb> userRoleWrapper = new LambdaQueryWrapper<>();
userRoleWrapper.eq(SystemUserRoleTb::getRoleId, roleId);
List<SystemUserRoleTb> userRoles = systemUserRoleMapper.selectList(userRoleWrapper);
if (CollUtil.isEmpty(userRoles)) {
return new ArrayList<>();
}
Set<Long> userIds = userRoles.stream().map(SystemUserRoleTb::getUserId).collect(Collectors.toSet());
List<SystemUserTb> users = systemUserMapper.selectByIds(userIds);
return users.stream().map(this::convertToUserVo).collect(Collectors.toList());
}
/**
* 根据部门ID查询用户
*
* @param deptId 部门ID
* @return /
*/
public List<SystemUserVo> selectUserByDeptId(Long deptId) {
// 查询部门关联的角色
LambdaQueryWrapper<SystemUserTb> userWrapper = new LambdaQueryWrapper<>();
userWrapper.eq(SystemUserTb::getDeptId, deptId);
List<SystemUserTb> users = systemUserMapper.selectList(userWrapper);
return users.stream().map(this::convertToUserVo).collect(Collectors.toList());
}
/**
* 根据菜单ID查询用户
*
* @param menuId 菜单ID
* @return /
*/
public List<SystemUserVo> selectUserByMenuId(Long menuId) {
// 查询菜单角色关联
LambdaQueryWrapper<SystemUserRoleTb> userRoleWrapper = new LambdaQueryWrapper<>();
// 这里需要通过菜单角色关联表查询,暂时简化处理
List<SystemUserTb> users = systemUserMapper.selectList(null);
return users.stream().map(this::convertToUserVo).collect(Collectors.toList());
}
/**
* 根据岗位ID统计用户数量
*
* @param jobIds 岗位ID集合
* @return /
*/
public Long countUserByJobIds(Set<Long> jobIds) {
if (CollUtil.isEmpty(jobIds)) {
return 0L;
}
LambdaQueryWrapper<SystemUserJobTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SystemUserJobTb::getJobId, jobIds);
return systemUserJobMapper.selectCount(wrapper);
}
/**
* 根据角色ID统计用户数量
*
* @param roleIds 角色ID集合
* @return /
*/
public Long countUserByRoleIds(Set<Long> roleIds) {
if (CollUtil.isEmpty(roleIds)) {
return 0L;
}
LambdaQueryWrapper<SystemUserRoleTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SystemUserRoleTb::getRoleId, roleIds);
return systemUserRoleMapper.selectCount(wrapper);
}
/**
* 根据用户名查询用户详情(包含关联信息)
*
* @param username 用户名
* @return /
*/
public SystemUserVo getUserVoByUsername(String username) {
SystemUserTb user = systemUserMapper.getUserByUsername(username);
if (user == null) {
return null;
}
return convertToUserVo(user);
}
/**
* 构建用户查询条件
*
* @param criteria 查询条件
* @return /
*/
private LambdaQueryWrapper<SystemUserTb> buildUserQueryWrapper(SystemQueryUserArgs criteria) {
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
if (criteria != null) {
if (criteria.getId() != null) {
wrapper.eq(SystemUserTb::getId, criteria.getId());
}
if (criteria.getEnabled() != null) {
wrapper.eq(SystemUserTb::getEnabled, criteria.getEnabled());
}
if (CollUtil.isNotEmpty(criteria.getDeptIds())) {
wrapper.in(SystemUserTb::getDeptId, criteria.getDeptIds());
}
if (StrUtil.isNotBlank(criteria.getBlurry())) {
wrapper.and(w -> w.like(SystemUserTb::getUsername, criteria.getBlurry())
.or().like(SystemUserTb::getNickName, criteria.getBlurry())
.or().like(SystemUserTb::getEmail, criteria.getBlurry()));
}
if (CollUtil.isNotEmpty(criteria.getCreateTime()) && criteria.getCreateTime().size() >= 2) {
wrapper.between(SystemUserTb::getCreateTime, criteria.getCreateTime().get(0),
criteria.getCreateTime().get(1));
}
}
wrapper.orderByDesc(SystemUserTb::getCreateTime);
return wrapper;
}
/**
* 转换为SystemUserVo并关联查询部门、角色、岗位信息
*
* @param user 用户基本信息
* @return 包含关联信息的SystemUserVo
*/
private SystemUserVo convertToUserVo(SystemUserTb user) {
if (user == null) {
return null;
}
SystemUserVo userVo = BeanUtil.copyProperties(user, SystemUserVo.class);
// 查询关联的部门信息
if (user.getDeptId() != null) {
SystemDeptTb dept = systemDeptMapper.selectById(user.getDeptId());
userVo.setDept(dept);
}
// 查询关联的岗位信息
LambdaQueryWrapper<SystemUserJobTb> jobWrapper = new LambdaQueryWrapper<>();
jobWrapper.eq(SystemUserJobTb::getUserId, user.getId());
List<SystemUserJobTb> userJobs = systemUserJobMapper.selectList(jobWrapper);
if (CollUtil.isNotEmpty(userJobs)) {
Set<Long> jobIds = userJobs.stream().map(SystemUserJobTb::getJobId).collect(Collectors.toSet());
List<SystemJobTb> jobs = systemJobMapper.selectByIds(jobIds);
userVo.setJobs(new LinkedHashSet<>(jobs));
}
// 查询关联的角色信息
LambdaQueryWrapper<SystemUserRoleTb> roleWrapper = new LambdaQueryWrapper<>();
roleWrapper.eq(SystemUserRoleTb::getUserId, user.getId());
List<SystemUserRoleTb> userRoles = systemUserRoleMapper.selectList(roleWrapper);
if (CollUtil.isNotEmpty(userRoles)) {
Set<Long> roleIds = userRoles.stream().map(SystemUserRoleTb::getRoleId).collect(Collectors.toSet());
List<SystemRoleTb> roles = systemRoleMapper.selectByIds(roleIds);
userVo.setRoles(new LinkedHashSet<>(roles));
}
return userVo;
}
}
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.system.util;
import cn.odboy.framework.exception.BadRequestException;
@@ -37,150 +36,151 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public final class KitSqlUtil {
/**
* 获取数据源
*
* @param jdbcUrl /
* @param userName /
* @param password /
* @return DataSource
*/
private static DataSource getDataSource(String jdbcUrl, String userName, String password) {
HikariDataSource druidDataSource = new HikariDataSource();
String className;
try {
className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();
} catch (SQLException e) {
throw new BadRequestException("Get class name error: =" + jdbcUrl);
/**
* 获取数据源
*
* @param jdbcUrl /
* @param userName /
* @param password /
* @return DataSource
*/
private static DataSource getDataSource(String jdbcUrl, String userName, String password) {
HikariDataSource druidDataSource = new HikariDataSource();
String className;
try {
className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();
} catch (SQLException e) {
throw new BadRequestException("Get class name error: =" + jdbcUrl);
}
if (StringUtils.isEmpty(className)) {
DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);
if (null == dataTypeEnum) {
throw new BadRequestException("Not supported data type: jdbcUrl=" + jdbcUrl);
}
druidDataSource.setDriverClassName(dataTypeEnum.getDriver());
} else {
druidDataSource.setDriverClassName(className);
}
druidDataSource.setJdbcUrl(jdbcUrl);
druidDataSource.setUsername(userName);
druidDataSource.setPassword(password);
druidDataSource.setConnectionTimeout(3000);
return druidDataSource;
}
private static Connection getConnection(String jdbcUrl, String userName, String password) {
DataSource dataSource = getDataSource(jdbcUrl, userName, password);
Connection connection = null;
try {
connection = dataSource.getConnection();
} catch (Exception ignored) {
}
try {
int timeOut = 5;
if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) {
log.info("connection is closed or invalid, retry get connection!");
connection = dataSource.getConnection();
}
} catch (Exception e) {
log.error("create connection error, jdbcUrl: {}", jdbcUrl);
throw new BadRequestException("create connection error, jdbcUrl: " + jdbcUrl);
} finally {
KitCloseUtil.close(connection);
}
return connection;
}
private static void releaseConnection(Connection connection) {
if (null != connection) {
try {
connection.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error("connection close error:" + e.getMessage());
}
}
}
public static boolean testConnection(String jdbcUrl, String userName, String password) {
Connection connection = null;
try {
connection = getConnection(jdbcUrl, userName, password);
if (null != connection) {
return true;
}
} catch (Exception e) {
log.info("Get connection failed:" + e.getMessage());
} finally {
releaseConnection(connection);
}
return false;
}
public static String executeFile(String jdbcUrl, String username, String password, File sqlFile) {
Connection connection = getConnection(jdbcUrl, username, password);
try {
batchExecute(connection, readSqlList(sqlFile));
} catch (Exception e) {
log.error("sql脚本执行发生异常:{}", e.getMessage());
return e.getMessage();
} finally {
releaseConnection(connection);
}
return "success";
}
/**
* 批量执行sql
*
* @param connection /
* @param sqlList /
*/
public static void batchExecute(Connection connection, List<String> sqlList) {
Statement st = null;
try {
st = connection.createStatement();
for (String sql : sqlList) {
if (sql.endsWith(";")) {
sql = sql.substring(0, sql.length() - 1);
}
if (StringUtils.isEmpty(className)) {
DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);
if (null == dataTypeEnum) {
throw new BadRequestException("Not supported data type: jdbcUrl=" + jdbcUrl);
}
druidDataSource.setDriverClassName(dataTypeEnum.getDriver());
st.addBatch(sql);
}
st.executeBatch();
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
KitCloseUtil.close(st);
}
}
/**
* 将文件中的sql语句以;为单位读取到列表中
*
* @param sqlFile /
* @return /
* @throws Exception e
*/
private static List<String> readSqlList(File sqlFile) throws Exception {
List<String> sqlList = Lists.newArrayList();
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(Files.newInputStream(sqlFile.toPath()), StandardCharsets.UTF_8))) {
String tmp;
while ((tmp = reader.readLine()) != null) {
log.info("line:{}", tmp);
if (tmp.endsWith(";")) {
sb.append(tmp);
sqlList.add(sb.toString());
sb.delete(0, sb.length());
} else {
druidDataSource.setDriverClassName(className);
sb.append(tmp);
}
druidDataSource.setJdbcUrl(jdbcUrl);
druidDataSource.setUsername(userName);
druidDataSource.setPassword(password);
druidDataSource.setConnectionTimeout(3000);
return druidDataSource;
}
private static Connection getConnection(String jdbcUrl, String userName, String password) {
DataSource dataSource = getDataSource(jdbcUrl, userName, password);
Connection connection = null;
try {
connection = dataSource.getConnection();
} catch (Exception ignored) {
}
try {
int timeOut = 5;
if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) {
log.info("connection is closed or invalid, retry get connection!");
connection = dataSource.getConnection();
}
} catch (Exception e) {
log.error("create connection error, jdbcUrl: {}", jdbcUrl);
throw new BadRequestException("create connection error, jdbcUrl: " + jdbcUrl);
} finally {
KitCloseUtil.close(connection);
}
return connection;
}
private static void releaseConnection(Connection connection) {
if (null != connection) {
try {
connection.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error("connection close error:" + e.getMessage());
}
}
}
public static boolean testConnection(String jdbcUrl, String userName, String password) {
Connection connection = null;
try {
connection = getConnection(jdbcUrl, userName, password);
if (null != connection) {
return true;
}
} catch (Exception e) {
log.info("Get connection failed:" + e.getMessage());
} finally {
releaseConnection(connection);
}
return false;
}
public static String executeFile(String jdbcUrl, String username, String password, File sqlFile) {
Connection connection = getConnection(jdbcUrl, username, password);
try {
batchExecute(connection, readSqlList(sqlFile));
} catch (Exception e) {
log.error("sql脚本执行发生异常:{}", e.getMessage());
return e.getMessage();
} finally {
releaseConnection(connection);
}
return "success";
}
/**
* 批量执行sql
*
* @param connection /
* @param sqlList /
*/
public static void batchExecute(Connection connection, List<String> sqlList) {
Statement st = null;
try {
st = connection.createStatement();
for (String sql : sqlList) {
if (sql.endsWith(";")) {
sql = sql.substring(0, sql.length() - 1);
}
st.addBatch(sql);
}
st.executeBatch();
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
KitCloseUtil.close(st);
}
}
/**
* 将文件中的sql语句以;为单位读取到列表中
*
* @param sqlFile /
* @return /
* @throws Exception e
*/
private static List<String> readSqlList(File sqlFile) throws Exception {
List<String> sqlList = Lists.newArrayList();
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(Files.newInputStream(sqlFile.toPath()), StandardCharsets.UTF_8))) {
String tmp;
while ((tmp = reader.readLine()) != null) {
log.info("line:{}", tmp);
if (tmp.endsWith(";")) {
sb.append(tmp);
sqlList.add(sb.toString());
sb.delete(0, sb.length());
} else {
sb.append(tmp);
}
}
if (!"".endsWith(sb.toString().trim())) {
sqlList.add(sb.toString());
}
}
return sqlList;
}
if (!"".endsWith(sb.toString().trim())) {
sqlList.add(sb.toString());
}
}
return sqlList;
}
}
@@ -1,118 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.odboy.system.dal.mysql.SystemRoleMapper">
<resultMap id="BaseResultMap" type="cn.odboy.system.dal.model.SystemRoleVo">
<id column="role_role_id" property="id"/>
<result column="role_name" property="name"/>
<result column="role_data_scope" property="dataScope"/>
<result column="role_level" property="level"/>
<result column="role_description" property="description"/>
<result column="role_create_by" property="createBy"/>
<result column="role_update_by" property="updateBy"/>
<result column="role_create_time" property="createTime"/>
<result column="role_update_time" property="updateTime"/>
<collection property="menus" ofType="cn.odboy.system.dal.dataobject.SystemMenuTb">
<id column="menu_id" property="id"/>
<result column="menu_title" property="title"/>
<result column="menu_permission" property="permission"/>
</collection>
<collection property="depts" ofType="cn.odboy.system.dal.dataobject.SystemDeptTb">
<id column="dept_id" property="id"/>
<result column="dept_name" property="name"/>
</collection>
</resultMap>
<select id="selectRoleByArgs" resultMap="BaseResultMap">
select role.*,
dept.dept_id as dept_id, dept.name as dept_name,
menu.menu_id as menu_id, menu.title as menu_title, menu.permission as menu_permission
from (
select
role.role_id as role_role_id, role.name as role_name, role.data_scope as role_data_scope,
role.level as role_level, role.description as role_description, role.create_by as role_create_by,
role.update_by as role_update_by, role.create_time as role_create_time, role.update_time as role_update_time
from system_role role
<where>
<if test="criteria.blurry != null and criteria.blurry != ''">
and (
role.name like concat('%', #{criteria.blurry}, '%')
or role.description like concat('%', #{criteria.blurry}, '%')
)
</if>
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
and role.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
</if>
</where>
order by role.level
<if test="criteria.offset != null">
limit #{criteria.offset}, #{criteria.size}
</if>
) role
left join system_roles_menus srm on role.role_role_id = srm.role_id
left join system_menu menu on menu.menu_id = srm.menu_id
left join system_roles_depts srd on role.role_role_id = srd.role_id
left join system_dept dept on dept.dept_id = srd.dept_id
order by role.role_level
</select>
<select id="getRoleById" resultMap="BaseResultMap">
select role.role_id as role_role_id,
role.name as role_name,
role.data_scope as role_data_scope,
role.level as role_level,
role.description as role_description,
role.create_by as role_create_by,
role.update_by as role_update_by,
role.create_time as role_create_time,
role.update_time as role_update_time,
dept.dept_id as dept_id,
dept.name as dept_name,
menu.menu_id as menu_id,
menu.title as menu_title,
menu.permission as menu_permission
from system_role role
left join system_roles_menus srm on role.role_id = srm.role_id
left join system_menu menu on menu.menu_id = srm.menu_id
left join system_roles_depts srd on role.role_id = srd.role_id
left join system_dept dept on dept.dept_id = srd.dept_id
where role.role_id = #{roleId}
</select>
<select id="selectRoleByUserId" resultMap="BaseResultMap">
SELECT role.role_id as role_role_id,
role.name as role_name,
role.data_scope as role_data_scope,
role.level as role_level,
role.description as role_description,
role.create_by as role_create_by,
role.update_by as role_update_by,
role.create_time as role_create_time,
role.update_time as role_update_time,
dept.dept_id as dept_id,
dept.name as dept_name,
menu.menu_id as menu_id,
menu.title as menu_title,
menu.permission as menu_permission
from system_role role
left join system_roles_menus srm on role.role_id = srm.role_id
left join system_menu menu on menu.menu_id = srm.menu_id
left join system_roles_depts srd on role.role_id = srd.role_id
left join system_dept dept on dept.dept_id = srd.dept_id
left join system_users_roles ur on role.role_id = ur.role_id
WHERE role.role_id = ur.role_id
AND ur.user_id = #{userId}
</select>
<select id="countRoleByDeptIds" resultType="int">
select count(*)
from system_role r, system_roles_depts d
where r.role_id = d.role_id
and d.dept_id in
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</select>
<select id="selectRoleByMenuId" resultType="cn.odboy.system.dal.model.SystemRoleVo">
SELECT role.role_id as id
FROM system_role role,
system_roles_menus rm
WHERE role.role_id = rm.role_id
AND rm.menu_id = #{menuId}
</select>
</mapper>
@@ -1,160 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.odboy.system.dal.mysql.SystemUserMapper">
<resultMap id="BaseResultMap" type="cn.odboy.system.dal.model.SystemUserVo">
<id column="user_user_id" property="id"/>
<result column="user_dept_id" property="deptId"/>
<result column="user_username" property="username"/>
<result column="user_nick_name" property="nickName"/>
<result column="user_email" property="email"/>
<result column="user_phone" property="phone"/>
<result column="user_gender" property="gender"/>
<result column="user_avatar_name" property="avatarName"/>
<result column="user_avatar_path" property="avatarPath"/>
<result column="user_password" property="password"/>
<result column="user_is_admin" property="isAdmin"/>
<result column="user_enabled" property="enabled"/>
<result column="user_pwd_reset_time" property="pwdResetTime"/>
<result column="user_create_by" property="createBy"/>
<result column="user_update_by" property="updateBy"/>
<result column="user_create_time" property="createTime"/>
<result column="user_update_time" property="updateTime"/>
<association property="dept" javaType="cn.odboy.system.dal.dataobject.SystemDeptTb">
<id column="dept_id" property="id"/>
<result column="dept_name" property="name"/>
</association>
<collection property="jobs" ofType="cn.odboy.system.dal.dataobject.SystemJobTb">
<id column="job_id" property="id"/>
<result column="job_name" property="name"/>
</collection>
<collection property="roles" ofType="cn.odboy.system.dal.model.SystemRoleVo">
<id column="role_id" property="id"/>
<result column="role_name" property="name"/>
<result column="role_level" property="level"/>
<result column="role_data_scope" property="dataScope"/>
</collection>
</resultMap>
<select id="selectUserByArgs" resultMap="BaseResultMap">
select u.user_id as user_user_id,
u.dept_id as user_dept_id,
u.username as user_username,
u.nick_name as user_nick_name,
u.email as user_email,
u.phone as user_phone,
u.gender as user_gender,
u.avatar_name as user_avatar_name,
u.avatar_path as user_avatar_path,
u.enabled as user_enabled,
u.pwd_reset_time as user_pwd_reset_time,
u.create_by as user_create_by,
u.update_by as user_update_by,
u.create_time as user_create_time,
u.update_time as user_update_time,
d.dept_id as dept_id,
d.name as dept_name,
j.id as job_id,
j.name as job_name,
r.role_id as role_id,
r.name as role_name,
r.level as role_level,
r.data_scope as role_data_scope
from system_user u
left join system_dept d on u.dept_id = d.dept_id
left join system_users_jobs suj on u.user_id = suj.user_id
left join system_job j on suj.job_id = j.id
left join system_users_roles sur on u.user_id = sur.user_id
left join system_role r on sur.role_id = r.role_id
<where>
<if test="criteria.id != null">
and u.user_id = #{criteria.id}
</if>
<if test="criteria.enabled != null">
and u.enabled = #{criteria.enabled}
</if>
<if test="criteria.deptIds != null and criteria.deptIds.size() != 0">
and u.dept_id in
<foreach collection="criteria.deptIds" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</if>
<if test="criteria.blurry != null and criteria.blurry != ''">
and (
u.username like concat('%', #{criteria.blurry}, '%')
or u.nick_name like concat('%', #{criteria.blurry}, '%')
or u.email like concat('%', #{criteria.blurry}, '%')
)
</if>
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
and u.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
</if>
</where>
order by u.user_id desc
</select>
<select id="getUserByUsername" resultMap="BaseResultMap">
select u.password user_password,
u.is_admin user_is_admin,
u.user_id as user_user_id,
u.dept_id as user_dept_id,
u.username as user_username,
u.nick_name as user_nick_name,
u.email as user_email,
u.phone as user_phone,
u.gender as user_gender,
u.avatar_name as user_avatar_name,
u.avatar_path as user_avatar_path,
u.enabled as user_enabled,
u.pwd_reset_time as user_pwd_reset_time,
u.create_by as user_create_by,
u.update_by as user_update_by,
u.create_time as user_create_time,
u.update_time as user_update_time,
d.dept_id as dept_id,
d.name as dept_name
from system_user u
left join system_dept d on u.dept_id = d.dept_id
where u.username = #{username}
and u.enabled = 1
</select>
<select id="selectUserByRoleId" resultType="cn.odboy.system.dal.model.SystemUserVo">
SELECT u.user_id as id, u.username
FROM system_user u,
system_users_roles r
WHERE u.user_id = r.user_id
AND r.role_id = #{roleId}
group by u.user_id
</select>
<select id="selectUserByDeptId" resultType="cn.odboy.system.dal.model.SystemUserVo">
SELECT u.*
FROM system_user u,
system_users_roles r,
system_roles_depts d
WHERE u.user_id = r.user_id
AND r.role_id = d.role_id
AND d.dept_id = #{deptId}
group by u.user_id
</select>
<select id="selectUserByMenuId" resultType="cn.odboy.system.dal.model.SystemUserVo">
SELECT u.user_id as id, u.username
FROM system_user u,
system_users_roles ur,
system_roles_menus rm
WHERE u.user_id = ur.user_id
AND ur.role_id = rm.role_id
AND rm.menu_id = #{menuId}
group by u.user_id
</select>
<select id="countUserByJobIds" resultType="Long">
SELECT count(*) FROM system_user u, system_users_jobs j
WHERE u.user_id = j.user_id AND j.job_id IN
<foreach collection="jobIds" item="jobId" open="(" separator="," close=")">
#{jobId}
</foreach>
</select>
<select id="countUserByRoleIds" resultType="Long">
SELECT count(*) FROM system_user u, system_users_roles r
WHERE u.user_id = r.user_id AND r.role_id in
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
#{roleId}
</foreach>
</select>
</mapper>
@@ -3,9 +3,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>
@page {
margin: 0;
}
@page {
margin: 0;
}
</style>
</head>
<body style="margin: 0px;
@@ -43,7 +43,6 @@
href="https://github.com/odboy-tianjun/cutejava" target="_blank">CuteJava</a>
后台管理系统 All Rights Reserved.
</div>
</div>
</div>
</body>
@@ -3,9 +3,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>
@page {
margin: 0;
}
@page {
margin: 0;
}
</style>
</head>
<body style="margin: 0px;
@@ -64,7 +64,6 @@
href="https://github.com/odboy-tianjun/cutejava" target="_blank">CuteJava</a>
后台管理系统 All Rights Reserved.
</div>
</div>
</body>
</html>