模块格式化,代码修正,补丁
This commit is contained in:
parent
58343a8aed
commit
268da3cdb0
@ -41,7 +41,7 @@ public class AuthControllerAspect {
|
|||||||
* @throws Throwable 异常
|
* @throws Throwable 异常
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
@Around("execution(* com.jsl.oa.controllers.*.*(..))")
|
@Around("execution(* com.jsl.oa.controllers.*.*(..)) && !execution(* com.jsl.oa.controllers.IndexController.*(..))")
|
||||||
public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
// 获取HttpServletRequest对象
|
// 获取HttpServletRequest对象
|
||||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||||
@ -56,6 +56,15 @@ public class AuthControllerAspect {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>Token检查切面</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 用于检查Token是否有效
|
||||||
|
*
|
||||||
|
* @param pjp ProceedingJoinPoint对象
|
||||||
|
* @return {@link Object}
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
@Around("execution(* com.jsl.oa.controllers.AuthController.authLogout(..)) || execution(* com.jsl.oa.controllers.AuthController.authChangePassword(..))")
|
@Around("execution(* com.jsl.oa.controllers.AuthController.authLogout(..)) || execution(* com.jsl.oa.controllers.AuthController.authChangePassword(..))")
|
||||||
public Object tokenControllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
public Object tokenControllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
// 获取 HttpServletRequest 对象
|
// 获取 HttpServletRequest 对象
|
||||||
@ -99,6 +108,6 @@ public class AuthControllerAspect {
|
|||||||
long nowTimestamp = System.currentTimeMillis();
|
long nowTimestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
// 时间误差允许前后五秒钟
|
// 时间误差允许前后五秒钟
|
||||||
return nowTimestamp - Long.parseLong(getTimestamp) <= 5000 && nowTimestamp - Long.parseLong(getTimestamp) >= -5000;
|
return nowTimestamp - Long.parseLong(getTimestamp) <= 10000 && nowTimestamp - Long.parseLong(getTimestamp) >= -10000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jsl.oa.config.redis;
|
package com.jsl.oa.config.redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
@ -21,9 +22,17 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RedisConfiguration {
|
public class RedisConfiguration {
|
||||||
|
@Value("${spring.redis.host}")
|
||||||
|
private String host;
|
||||||
|
@Value("${spring.redis.port}")
|
||||||
|
private Integer port;
|
||||||
|
@Value("${spring.redis.password}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JedisConnectionFactory jedisConnectionFactory() {
|
public JedisConnectionFactory jedisConnectionFactory() {
|
||||||
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration("localhost");
|
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
|
||||||
|
config.setPassword(password);
|
||||||
return new JedisConnectionFactory(config);
|
return new JedisConnectionFactory(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public class ShiroConfiguration {
|
|||||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||||
filterChainDefinitionMap.put("/auth/**/**", "anon"); // 登录接口允许匿名访问
|
filterChainDefinitionMap.put("/auth/**/**", "anon"); // 登录接口允许匿名访问
|
||||||
filterChainDefinitionMap.put("/unauthorized", "anon"); // 未授权接口允许匿名访问
|
filterChainDefinitionMap.put("/unauthorized", "anon"); // 未授权接口允许匿名访问
|
||||||
filterChainDefinitionMap.put("/", "jwt"); // 首页允许匿名访问
|
filterChainDefinitionMap.put("/", "anon"); // 首页允许匿名访问
|
||||||
filterChainDefinitionMap.put("/**/**", "jwt"); // 其他接口一律拦截(需要Token)
|
filterChainDefinitionMap.put("/**/**", "jwt"); // 其他接口一律拦截(需要Token)
|
||||||
|
|
||||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||||
|
@ -1,35 +1,54 @@
|
|||||||
package com.jsl.oa.controllers;
|
package com.jsl.oa.controllers;
|
||||||
|
|
||||||
import com.jsl.oa.model.voData.RoleAddUserVO;
|
|
||||||
import com.jsl.oa.model.voData.RoleRemoveUserVO;
|
|
||||||
import com.jsl.oa.services.RoleService;
|
import com.jsl.oa.services.RoleService;
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
import com.jsl.oa.utils.ErrorCode;
|
import com.jsl.oa.utils.ErrorCode;
|
||||||
import com.jsl.oa.utils.Processing;
|
|
||||||
import com.jsl.oa.utils.ResultUtil;
|
import com.jsl.oa.utils.ResultUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>角色控制器</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 角色控制器,包含角色获取接口
|
||||||
|
*
|
||||||
|
* @version v1.1.0
|
||||||
|
* @see RoleService
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
|
||||||
public class RoleController {
|
public class RoleController {
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>角色获取</h2>
|
||||||
|
* <hr/>
|
||||||
|
* 角色获取接口
|
||||||
|
*
|
||||||
|
* @param id 角色id
|
||||||
|
* @return {@link BaseResponse}
|
||||||
|
*/
|
||||||
|
@GetMapping("/role/get")
|
||||||
|
public BaseResponse roleGet(HttpServletRequest request, @RequestParam @Nullable String id) {
|
||||||
|
return roleService.roleGet(request, id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户权限授予
|
* 用户权限授予
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("role/user/add")
|
@PostMapping("role/user/add")
|
||||||
public BaseResponse roleAddUser(@RequestParam Long uid,@RequestParam Long rid){
|
public BaseResponse roleAddUser(@RequestParam Long uid, @RequestParam Long rid) {
|
||||||
// 判断是否有参数错误
|
// 判断是否有参数错误
|
||||||
if (uid == null || rid == null) {
|
if (uid == null || rid == null) {
|
||||||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||||
}
|
}
|
||||||
return roleService.roleAddUser(uid,rid);
|
return roleService.roleAddUser(uid, rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,9 +57,9 @@ public class RoleController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("role/user/remove")
|
@DeleteMapping("role/user/remove")
|
||||||
public BaseResponse roleRemoveUser(@RequestParam Long uid){
|
public BaseResponse roleRemoveUser(@RequestParam Long uid) {
|
||||||
// 判断是否有参数错误
|
// 判断是否有参数错误
|
||||||
if (uid==null) {
|
if (uid == null) {
|
||||||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||||
}
|
}
|
||||||
return roleService.roleRemoveUser(uid);
|
return roleService.roleRemoveUser(uid);
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
package com.jsl.oa.dao;
|
package com.jsl.oa.dao;
|
||||||
|
|
||||||
import com.jsl.oa.mapper.RoleMapper;
|
import com.jsl.oa.mapper.RoleMapper;
|
||||||
import com.jsl.oa.model.voData.RoleAddUserVO;
|
import com.jsl.oa.model.doData.RoleDO;
|
||||||
import com.jsl.oa.model.voData.RoleRemoveUserVO;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RoleDAO {
|
public class RoleDAO {
|
||||||
private final RoleMapper roleMapper;
|
public final RoleMapper roleMapper;
|
||||||
|
|
||||||
public void roleAddUser(Long uid,Long rid) {
|
public void roleAddUser(Long uid,Long rid) {
|
||||||
roleMapper.roleAddUser(uid,rid);
|
roleMapper.roleAddUser(uid,rid);
|
||||||
@ -18,4 +20,14 @@ public class RoleDAO {
|
|||||||
public void roleRemoveUser(Long uid) {
|
public void roleRemoveUser(Long uid) {
|
||||||
roleMapper.roleRemoveUser(uid);
|
roleMapper.roleRemoveUser(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RoleDO> getRoleById(String id) {
|
||||||
|
ArrayList<RoleDO> getRoleList = new ArrayList<>();
|
||||||
|
getRoleList.add(roleMapper.getRoleById(Long.valueOf(id)));
|
||||||
|
return getRoleList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RoleDO> getRole() {
|
||||||
|
return roleMapper.getRole();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import org.apache.ibatis.annotations.Insert;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface RoleMapper {
|
public interface RoleMapper {
|
||||||
|
|
||||||
@ -21,4 +23,10 @@ public interface RoleMapper {
|
|||||||
|
|
||||||
@Select("SELECT * FROM organize_oa.oa_role WHERE role_name=#{roleName}")
|
@Select("SELECT * FROM organize_oa.oa_role WHERE role_name=#{roleName}")
|
||||||
RoleDO getRoleByRoleName(String roleName);
|
RoleDO getRoleByRoleName(String roleName);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM organize_oa.oa_role WHERE id=#{id}")
|
||||||
|
RoleDO getRoleById(Long id);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM organize_oa.oa_role ORDER BY id DESC")
|
||||||
|
List<RoleDO> getRole();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.jsl.oa.model.doData;
|
package com.jsl.oa.model.doData;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
@ -17,7 +16,6 @@ import java.sql.Timestamp;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
||||||
public class RoleDO {
|
public class RoleDO {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
@ -40,8 +40,7 @@ public interface MailService {
|
|||||||
*
|
*
|
||||||
* @param email 邮箱
|
* @param email 邮箱
|
||||||
* @param code 验证码
|
* @param code 验证码
|
||||||
* @return 是否发送成功
|
|
||||||
*/
|
*/
|
||||||
boolean sendMailAboutUserLogin(String email, Integer code);
|
void sendMailAboutUserLogin(String email, Integer code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,21 @@
|
|||||||
package com.jsl.oa.services;
|
package com.jsl.oa.services;
|
||||||
|
|
||||||
import com.jsl.oa.model.voData.RoleAddUserVO;
|
|
||||||
import com.jsl.oa.model.voData.RoleRemoveUserVO;
|
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>角色控制器接口</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 该接口用于定义角色控制器的方法
|
||||||
|
*
|
||||||
|
* @version 1.1.0
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
public interface RoleService {
|
public interface RoleService {
|
||||||
BaseResponse roleAddUser(Long uid,Long rid);
|
BaseResponse roleAddUser(Long uid, Long rid);
|
||||||
|
|
||||||
BaseResponse roleRemoveUser(Long uid);
|
BaseResponse roleRemoveUser(Long uid);
|
||||||
|
|
||||||
|
BaseResponse roleGet(HttpServletRequest request, String id);
|
||||||
}
|
}
|
||||||
|
@ -138,11 +138,8 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
// 存储验证码
|
// 存储验证码
|
||||||
if (emailRedisUtil.setData(BusinessConstants.BUSINESS_LOGIN, email, code, 5)) {
|
if (emailRedisUtil.setData(BusinessConstants.BUSINESS_LOGIN, email, code, 5)) {
|
||||||
// 发送邮件
|
// 发送邮件
|
||||||
if (mailService.sendMailAboutUserLogin(email, code)) {
|
mailService.sendMailAboutUserLogin(email, code);
|
||||||
return ResultUtil.success("验证码已发送");
|
return ResultUtil.success("验证码已发送");
|
||||||
} else {
|
|
||||||
return ResultUtil.error(ErrorCode.EMAIL_LOGIN_NOT_SUPPORT);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thymeleaf.TemplateEngine;
|
import org.thymeleaf.TemplateEngine;
|
||||||
import org.thymeleaf.context.Context;
|
import org.thymeleaf.context.Context;
|
||||||
@ -60,7 +61,8 @@ public class MailServiceImpl implements MailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sendMailAboutUserLogin(String email, Integer code) {
|
@Async
|
||||||
|
public void sendMailAboutUserLogin(String email, Integer code) {
|
||||||
// 发送邮件带HTML模块部分
|
// 发送邮件带HTML模块部分
|
||||||
try {
|
try {
|
||||||
MimeMessage message = javaMailSender.createMimeMessage();
|
MimeMessage message = javaMailSender.createMimeMessage();
|
||||||
@ -72,14 +74,12 @@ public class MailServiceImpl implements MailService {
|
|||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
context.setVariable("code", code);
|
context.setVariable("code", code);
|
||||||
context.setVariable("email", email);
|
context.setVariable("email", email);
|
||||||
String emailContent = templateEngine.process("/mail/user-login.html", context);
|
String emailContent = templateEngine.process("./mail/user-login.html", context);
|
||||||
mimeMessage.setText(emailContent, true);
|
mimeMessage.setText(emailContent, true);
|
||||||
|
|
||||||
javaMailSender.send(message);
|
javaMailSender.send(message);
|
||||||
return true;
|
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
//TODO: 10001-发送邮件失败处理
|
//TODO: 10001-发送邮件失败处理
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,19 @@ package com.jsl.oa.services.impl;
|
|||||||
|
|
||||||
import com.jsl.oa.dao.RoleDAO;
|
import com.jsl.oa.dao.RoleDAO;
|
||||||
import com.jsl.oa.dao.UserDAO;
|
import com.jsl.oa.dao.UserDAO;
|
||||||
import com.jsl.oa.model.voData.RoleAddUserVO;
|
import com.jsl.oa.model.doData.RoleDO;
|
||||||
import com.jsl.oa.model.voData.RoleRemoveUserVO;
|
|
||||||
import com.jsl.oa.services.RoleService;
|
import com.jsl.oa.services.RoleService;
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
import com.jsl.oa.utils.ErrorCode;
|
import com.jsl.oa.utils.ErrorCode;
|
||||||
|
import com.jsl.oa.utils.Processing;
|
||||||
import com.jsl.oa.utils.ResultUtil;
|
import com.jsl.oa.utils.ResultUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RoleServiceImpl implements RoleService {
|
public class RoleServiceImpl implements RoleService {
|
||||||
@ -19,18 +23,42 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
private final UserDAO userDAO;
|
private final UserDAO userDAO;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse roleAddUser(Long uid,Long rid) {
|
public BaseResponse roleAddUser(Long uid, Long rid) {
|
||||||
if(userDAO.isExistUser(uid)) {
|
if (userDAO.isExistUser(uid)) {
|
||||||
roleDAO.roleAddUser(uid,rid);
|
roleDAO.roleAddUser(uid, rid);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse roleRemoveUser(Long uid) {
|
public BaseResponse roleRemoveUser(Long uid) {
|
||||||
if(userDAO.isExistUser(uid)) {
|
if (userDAO.isExistUser(uid)) {
|
||||||
roleDAO.roleRemoveUser(uid);
|
roleDAO.roleRemoveUser(uid);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseResponse roleGet(HttpServletRequest request, String id) {
|
||||||
|
// 检查用户权限
|
||||||
|
if (!Processing.checkUserIsAdmin(request, roleDAO.roleMapper)) {
|
||||||
|
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
||||||
|
}
|
||||||
|
// 获取 Role 权限组
|
||||||
|
ArrayList<RoleDO> getRoleList;
|
||||||
|
if (id != null && !id.isEmpty()) {
|
||||||
|
if (Pattern.matches("^[0-9]+$", id)) {
|
||||||
|
getRoleList = (ArrayList<RoleDO>) roleDAO.getRoleById(id);
|
||||||
|
} else {
|
||||||
|
ArrayList<String> error = new ArrayList<>();
|
||||||
|
error.add("id 只能为数字");
|
||||||
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR, error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getRoleList = (ArrayList<RoleDO>) roleDAO.getRole();
|
||||||
|
getRoleList.add(getRoleList.size(), new RoleDO().setId(0L).setRoleName("none"));
|
||||||
|
}
|
||||||
|
// 返回数据
|
||||||
|
return ResultUtil.success(getRoleList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.jsl.oa.services.impl;
|
|||||||
import com.jsl.oa.dao.UserDAO;
|
import com.jsl.oa.dao.UserDAO;
|
||||||
import com.jsl.oa.exception.BusinessException;
|
import com.jsl.oa.exception.BusinessException;
|
||||||
import com.jsl.oa.mapper.RoleMapper;
|
import com.jsl.oa.mapper.RoleMapper;
|
||||||
import com.jsl.oa.model.doData.RoleDO;
|
|
||||||
import com.jsl.oa.model.doData.RoleUserDO;
|
import com.jsl.oa.model.doData.RoleUserDO;
|
||||||
import com.jsl.oa.model.doData.UserCurrentDO;
|
import com.jsl.oa.model.doData.UserCurrentDO;
|
||||||
import com.jsl.oa.model.doData.UserDO;
|
import com.jsl.oa.model.doData.UserDO;
|
||||||
@ -33,10 +32,10 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse userDelete(HttpServletRequest request,Long id) {
|
public BaseResponse userDelete(HttpServletRequest request, Long id) {
|
||||||
//判断用户是否存在
|
//判断用户是否存在
|
||||||
if (userDAO.isExistUser(id)) {
|
if (userDAO.isExistUser(id)) {
|
||||||
if(!Processing.checkUserIsAdmin(request,roleMapper)){
|
if (!Processing.checkUserIsAdmin(request, roleMapper)) {
|
||||||
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
||||||
}
|
}
|
||||||
userDAO.userDelete(id);
|
userDAO.userDelete(id);
|
||||||
@ -45,10 +44,10 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse userLock(HttpServletRequest request,Long id) {
|
public BaseResponse userLock(HttpServletRequest request, Long id) {
|
||||||
//判断用户是否存在
|
//判断用户是否存在
|
||||||
if (userDAO.isExistUser(id)) {
|
if (userDAO.isExistUser(id)) {
|
||||||
if (!Processing.checkUserIsAdmin(request,roleMapper)){
|
if (!Processing.checkUserIsAdmin(request, roleMapper)) {
|
||||||
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
||||||
}
|
}
|
||||||
userDAO.userLock(id);
|
userDAO.userLock(id);
|
||||||
@ -127,19 +126,17 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse userAdd(UserAddVo userAddVo, HttpServletRequest request) {
|
public BaseResponse userAdd(UserAddVo userAddVo, HttpServletRequest request) {
|
||||||
|
|
||||||
//检测用户是否为管理员
|
//检测用户是否为管理员
|
||||||
BaseResponse checkManagerResult = isManager(request);
|
BaseResponse checkManagerResult = isManager(request);
|
||||||
if(checkManagerResult.getCode() != 200){
|
if (checkManagerResult.getCode() != 200) {
|
||||||
return checkManagerResult;
|
return checkManagerResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果用户不重复,添加用户
|
//如果用户不重复,添加用户
|
||||||
if(!userDAO.isRepeatUser(userAddVo.getUsername())){
|
if (!userDAO.isRepeatUser(userAddVo.getUsername())) {
|
||||||
// 生成工号
|
// 生成工号
|
||||||
String userNum;
|
String userNum;
|
||||||
do {
|
do {
|
||||||
@ -164,27 +161,26 @@ public class UserServiceImpl implements UserService {
|
|||||||
} else {
|
} else {
|
||||||
throw new BusinessException(ErrorCode.DATABASE_INSERT_ERROR);
|
throw new BusinessException(ErrorCode.DATABASE_INSERT_ERROR);
|
||||||
}
|
}
|
||||||
}else return ResultUtil.error(ErrorCode.USER_EXIST);
|
} else return ResultUtil.error(ErrorCode.USER_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse userEdit(UserEditVo userEditVo, HttpServletRequest request) {
|
public BaseResponse userEdit(UserEditVo userEditVo, HttpServletRequest request) {
|
||||||
//检测用户是否为管理员
|
//检测用户是否为管理员
|
||||||
BaseResponse checkManagerResult = isManager(request);
|
BaseResponse checkManagerResult = isManager(request);
|
||||||
if(checkManagerResult.getCode() != 200){
|
if (checkManagerResult.getCode() != 200) {
|
||||||
return checkManagerResult;
|
return checkManagerResult;
|
||||||
}
|
}
|
||||||
//根据id获取用户信息
|
//根据id获取用户信息
|
||||||
UserDO userDO = userDAO.getUserById(userEditVo.getId());
|
UserDO userDO = userDAO.getUserById(userEditVo.getId());
|
||||||
if(userDO == null){
|
if (userDO == null) {
|
||||||
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
//修改非空属性
|
//修改非空属性
|
||||||
try {
|
try {
|
||||||
Processing.copyProperties(userEditVo,userDO);
|
Processing.copyProperties(userEditVo, userDO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -199,12 +195,12 @@ public class UserServiceImpl implements UserService {
|
|||||||
public BaseResponse userProflieGet(Long id) {
|
public BaseResponse userProflieGet(Long id) {
|
||||||
|
|
||||||
UserDO userDO = userDAO.getUserById(id);
|
UserDO userDO = userDAO.getUserById(id);
|
||||||
if(userDO == null){
|
if (userDO == null) {
|
||||||
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
UserProfile userProfile = new UserProfile();
|
UserProfile userProfile = new UserProfile();
|
||||||
try {
|
try {
|
||||||
Processing.copyProperties(userDO,userProfile);
|
Processing.copyProperties(userDO, userProfile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -218,18 +214,18 @@ public class UserServiceImpl implements UserService {
|
|||||||
* @Date: 2024/1/18
|
* @Date: 2024/1/18
|
||||||
* @Param request: 请求头
|
* @Param request: 请求头
|
||||||
**/
|
**/
|
||||||
public BaseResponse isManager(HttpServletRequest request){
|
public BaseResponse isManager(HttpServletRequest request) {
|
||||||
//获取token
|
//获取token
|
||||||
String originalAuthorization = request.getHeader("Authorization");
|
String originalAuthorization = request.getHeader("Authorization");
|
||||||
String token = originalAuthorization.replace("Bearer ", "");
|
String token = originalAuthorization.replace("Bearer ", "");
|
||||||
//获取操作用户的权限
|
//获取操作用户的权限
|
||||||
RoleUserDO roleUserDO = userDAO.getRoleFromUser(JwtUtil.getUserId(token));
|
RoleUserDO roleUserDO = userDAO.getRoleFromUser(JwtUtil.getUserId(token));
|
||||||
//用户权限不为空
|
//用户权限不为空
|
||||||
if(roleUserDO == null){
|
if (roleUserDO == null) {
|
||||||
return ResultUtil.error(ErrorCode.USER_ROLE_NOT_EXIST);
|
return ResultUtil.error(ErrorCode.USER_ROLE_NOT_EXIST);
|
||||||
}
|
}
|
||||||
//用户权限应为管理员
|
//用户权限应为管理员
|
||||||
if(!userDAO.isManagerByRoleId(roleUserDO.getRid())){
|
if (!userDAO.isManagerByRoleId(roleUserDO.getRid())) {
|
||||||
return ResultUtil.error(ErrorCode.USER_ROLE_NOT_MANAGER);
|
return ResultUtil.error(ErrorCode.USER_ROLE_NOT_MANAGER);
|
||||||
}
|
}
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
|
@ -12,7 +12,7 @@ spring:
|
|||||||
host: localhost
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: test
|
||||||
mail:
|
mail:
|
||||||
host: 171.38.91.172
|
host: 171.38.91.172
|
||||||
username: zrx
|
username: zrx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user