全部转换为自增id

master
chen 2 years ago
parent 7f97d853b9
commit af5e89cb23
  1. 26
      pom.xml
  2. 4
      src/main/java/com/huoran/iasf/common/aop/aspect/DataScopeAspect.java
  3. 4
      src/main/java/com/huoran/iasf/common/aop/aspect/SysLogAspect.java
  4. 25
      src/main/java/com/huoran/iasf/common/filter/AuthFilter.java
  5. 22
      src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java
  6. 15
      src/main/java/com/huoran/iasf/common/shiro/ShiroConfig.java
  7. 70
      src/main/java/com/huoran/iasf/common/utils/EmailUtils.java
  8. 64
      src/main/java/com/huoran/iasf/common/utils/RandomUtil.java
  9. 34
      src/main/java/com/huoran/iasf/common/utils/SMSTemplate.java
  10. 51
      src/main/java/com/huoran/iasf/common/utils/SendSMSUtils.java
  11. 4
      src/main/java/com/huoran/iasf/controller/RoleController.java
  12. 70
      src/main/java/com/huoran/iasf/controller/UserController.java
  13. 8
      src/main/java/com/huoran/iasf/entity/SysDept.java
  14. 6
      src/main/java/com/huoran/iasf/entity/SysPermission.java
  15. 8
      src/main/java/com/huoran/iasf/entity/SysRole.java
  16. 49
      src/main/java/com/huoran/iasf/entity/SysRoleDeptEntity.java
  17. 11
      src/main/java/com/huoran/iasf/entity/SysRolePermission.java
  18. 17
      src/main/java/com/huoran/iasf/entity/SysUser.java
  19. 11
      src/main/java/com/huoran/iasf/entity/SysUserRole.java
  20. 4
      src/main/java/com/huoran/iasf/entity/UserDept.java
  21. 15
      src/main/java/com/huoran/iasf/mapper/SysRoleDeptMapper.java
  22. 24
      src/main/java/com/huoran/iasf/service/HttpSessionService.java
  23. 14
      src/main/java/com/huoran/iasf/service/PermissionService.java
  24. 6
      src/main/java/com/huoran/iasf/service/RoleService.java
  25. 4
      src/main/java/com/huoran/iasf/service/UserRoleService.java
  26. 37
      src/main/java/com/huoran/iasf/service/UserService.java
  27. 4
      src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java
  28. 24
      src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java
  29. 2
      src/main/java/com/huoran/iasf/service/impl/RolePermissionServiceImpl.java
  30. 12
      src/main/java/com/huoran/iasf/service/impl/RoleServiceImpl.java
  31. 1
      src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java
  32. 14
      src/main/java/com/huoran/iasf/service/impl/SysRoleDeptServiceImpl.java
  33. 6
      src/main/java/com/huoran/iasf/service/impl/UserRoleServiceImpl.java
  34. 194
      src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java
  35. 37
      src/main/java/com/huoran/iasf/vo/CheckVo.java
  36. 4
      src/main/java/com/huoran/iasf/vo/req/RolePermissionOperationReqVO.java
  37. 30
      src/main/java/com/huoran/iasf/vo/req/UpdatePhoneOrEmailReq.java
  38. 4
      src/main/java/com/huoran/iasf/vo/req/UserRoleOperationReqVO.java
  39. 2
      src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java
  40. 2
      src/main/resources/whiteList.properties
  41. 6
      src/test/java/com/company/project/CodeGenerator.java

@ -37,8 +37,34 @@
<easypoi-annotation.version>4.1.3</easypoi-annotation.version>
</properties>
<dependencyManagement>
<dependencies>
<!--Spring Cloud-alibaba-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- 发送邮箱 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.3.3</version>
</dependency>
<!--短信发送-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>

@ -54,7 +54,7 @@ public class DataScopeAspect {
protected void handleDataScope(final JoinPoint joinPoint) {
//获取当前登陆人
String id = sessionService.getCurrentUserId();
Integer id = sessionService.getCurrentUserId();
//获取当前登陆人角色, 如果无角色, 那么不限制
List<SysRole> sysRoles = roleService.getRoleInfoByUserId(id);
if (CollectionUtils.isEmpty(sysRoles) || sysRoles.size() == 0) {
@ -86,7 +86,7 @@ public class DataScopeAspect {
* @param userId 当前用户id
* @return 用户id集合
*/
private List<String> getUserIdsByRoles(List<com.huoran.iasf.entity.SysRole> sysRoles, String userId) {
private List<String> getUserIdsByRoles(List<SysRole> sysRoles, Integer userId) {
//本人
SysUser sysUser = userService.getById(userId);
//本部门

@ -104,10 +104,10 @@ public class SysLogAspect {
sysLog.setIp(IPUtils.getIpAddr(request));
log.info("Ip{},接口地址{},请求方式{},入参:{}", sysLog.getIp(), request.getRequestURL(), request.getMethod(), sysLog.getParams());
//用户名
String userId = httpSessionService.getCurrentUserId();
Integer userId = httpSessionService.getCurrentUserId();
String username = httpSessionService.getCurrentUsername();
sysLog.setUsername(username);
sysLog.setUserId(userId);
sysLog.setUserId(userId.toString());
sysLog.setTime((int) time);
log.info(sysLog.toString());
sysLogMapper.insert(sysLog);

@ -1,4 +1,3 @@
/*
package com.huoran.iasf.common.filter;
import com.alibaba.fastjson.JSON;
@ -24,12 +23,13 @@ import static com.huoran.iasf.service.HttpApiSessionService.USER_USERNAME_KEY;
@WebFilter(filterName = "authFilter", urlPatterns = "/iasf/*")
@Order(1)
public class AuthFilter implements Filter {
*/
/**
* 白名单*//*
/**
* 白名单
*/
private static final String[] whiteList =
{"/iasf/sys/user/login",
"/iasf/sys/exportFailure"};
private static final String[] whiteList = {"/iasf/app/api/login", "/iasf/app/api/open/test"};
@Resource
HttpApiSessionService httpApiSessionService;
//需要拦截的地址
@ -55,12 +55,14 @@ public class AuthFilter implements Filter {
}
//token为空返回
if (StringUtils.isBlank(token)) {
resp.setStatus(401);
responseResult(resp, R.fail("token不能为空"));
}
// 校验并解析token,如果token过期或者篡改,则会返回null
Claims claims = httpApiSessionService.checkJWT(token);
if (null == claims) {
responseResult(resp, R.fail("登陆失效, 请重新登陆"));
resp.setStatus(401);
responseResult(resp, R.fail("登陆失效,请重新登陆"));
}
//TODO 校验用户状态等
@ -72,18 +74,14 @@ public class AuthFilter implements Filter {
}
*/
/**
* responseResult
* @param response
* @param result
*//*
* @param result*/
private void responseResult(HttpServletResponse response, R result) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(200);
// response.setStatus(200);
try {
response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) {
@ -91,4 +89,3 @@ public class AuthFilter implements Filter {
}
}
}
*/

@ -59,39 +59,39 @@ public class CustomAccessControlFilter extends AccessControlFilter {
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(token, token);
getSubject(servletRequest, servletResponse).login(usernamePasswordToken);
} catch (BusinessException exception) {
/* if (HttpContextUtils.isAjaxRequest(request)) {
customResponse(exception.getBaseResponseCode(), exception.getMessage(), servletResponse);
} else if (exception.getMessageCode() == BaseResponseCode.TOKEN_ERROR.getCode()) {
if (HttpContextUtils.isAjaxRequest(request)) {
customResponse(exception.getBaseResponseCode().getCode(), exception.getMessage(), servletResponse);
} else if (exception.getBaseResponseCode().getCode() == BaseResponseCode.TOKEN_ERROR.getCode()) {
servletRequest.getRequestDispatcher("/index/login").forward(servletRequest, servletResponse);
} else if (exception.getMessageCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) {
} else if (exception.getBaseResponseCode().getCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) {
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse);
} else {
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse);
}*/
}
return false;
} catch (AuthenticationException e) {
/*if (HttpContextUtils.isAjaxRequest(request)) {
if (HttpContextUtils.isAjaxRequest(request)) {
if (e.getCause() instanceof BusinessException) {
BusinessException exception = (BusinessException) e.getCause();
customResponse(exception.getBaseResponseCode(), exception.getMessage(), servletResponse);
customResponse(exception.getBaseResponseCode().getCode(), exception.getMessage(), servletResponse);
} else {
customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse);
}
} else {
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse);
}*/
}
return false;
} catch (Exception e) {
/*if (HttpContextUtils.isAjaxRequest(request)) {
if (HttpContextUtils.isAjaxRequest(request)) {
if (e.getCause() instanceof BusinessException) {
BusinessException exception = (BusinessException) e.getCause();
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse);
customResponse(exception.getBaseResponseCode().getCode(), exception.getMessage(), servletResponse);
} else {
customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse);
}
} else {
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse);
}*/
}
return false;
}
return true;

@ -24,7 +24,6 @@ import java.util.Map;
* @date 2022年7月28日
*//*
@Configuration
@EnableConfigurationProperties(FileUploadProperties.class)
public class ShiroConfig {
@ -41,7 +40,6 @@ public class ShiroConfig {
/**
* 创建realm*//*
@Bean
public CustomRealm customRealm() {
CustomRealm customRealm = new CustomRealm();
@ -51,7 +49,6 @@ public class ShiroConfig {
@Bean
public SecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//关联realm
securityManager.setRealm(customRealm());
@ -73,7 +70,8 @@ public class ShiroConfig {
shiroFilterFactoryBean.setFilters(filtersMap);
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
// 配置不会被拦截的链接 顺序判断
filterChainDefinitionMap.put("/sys/user/login", "anon");
*/
/*filterChainDefinitionMap.put("/sys/user/login", "anon");
filterChainDefinitionMap.put("/sys/user/token", "anon");
filterChainDefinitionMap.put("/sys/getVerify", "anon");
filterChainDefinitionMap.put("/sys/checkVerify", "anon");
@ -96,9 +94,12 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/layui/**", "anon");
filterChainDefinitionMap.put("/css/**", "anon");
filterChainDefinitionMap.put("/layui-ext/**", "anon");
filterChainDefinitionMap.put("/app/api/**", "anon");
filterChainDefinitionMap.put("/app/api/**", "anon");*//*
filterChainDefinitionMap.put("/sys/getVerify", "anon");
filterChainDefinitionMap.put("/sys/user/login", "anon");
filterChainDefinitionMap.put("/**", "token,authc");
shiroFilterFactoryBean.setLoginUrl("/index/login");
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
@ -110,8 +111,6 @@ public class ShiroConfig {
*
* @return org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor*//*
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();

@ -0,0 +1,70 @@
package com.huoran.iasf.common.utils;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.HtmlEmail;
public class EmailUtils {
//服务器地址
private static final String SERVER_ADDRESS = "smtp.mxhichina.com";
//邮箱地址
private static final String EMAILADDRESS = "postmaster@huorantech.cn";
//发生邮箱密码
private static final String EMAILPASSWORD = "HR111aaa";
//发送人姓名
private static final String EMAILUSERNAME = "DataForward";
//授权码
//private static final String AUTHORIZATION_CODE = "smtp.mxhichina.com";
//邮件标题
private static final String EMAILHEAD = "粒子研究院";
//邮件信息(后接验证码)头部信息
private static final String EMAILMASSAGEHEAD = "尊敬的用户,欢迎使用粒子研究院,您本次的验证码是: ";
//邮件信息(后接验证码)尾部信息
private static final String EMAILMASSAGETAIL = ",有效时间为5分钟";
//邮箱验证码
public static boolean sendEmail(String emailaddress,String code){
try {
HtmlEmail email = new HtmlEmail();
email.setHostName(SERVER_ADDRESS);
email.setSSLOnConnect(true); //使用ssl加密true
email.setSslSmtpPort("465"); //使用465端口
email.setCharset("UTF-8");
email.addTo(emailaddress);
email.setFrom(EMAILADDRESS, EMAILUSERNAME);
// -- 使用阿里企业邮箱无授权码
// email.setAuthentication(EMAILADDRESS, AUTHORIZATION_CODE);
email.setAuthenticator(new DefaultAuthenticator(EMAILADDRESS,EMAILPASSWORD));
email.setSubject(EMAILHEAD);
email.setMsg( EMAILMASSAGEHEAD + code + EMAILMASSAGETAIL);
email.send();
return true;
}
catch(Exception e){
e.printStackTrace();
return false;
}
}
/**
* 描述是否是邮箱.
*
* @param str 指定的字符串
* @return 是否是邮箱:是为true否则false
*/
public static Boolean isEmail(String str) {
Boolean isEmail = false;
String expr = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$";
if (str.matches(expr)) {
isEmail = true;
}
return isEmail;
}
}

@ -0,0 +1,64 @@
package com.huoran.iasf.common.utils;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
/**
* 获取随机数
*
* @author cheney
*
*/
public class RandomUtil {
private static final Random random = new Random();
private static final DecimalFormat fourdf = new DecimalFormat("0000");
private static final DecimalFormat sixdf = new DecimalFormat("000000");
public static String getFourBitRandom() {
return fourdf.format(random.nextInt(10000));
}
public static String getSixBitRandom() {
return sixdf.format(random.nextInt(1000000));
}
/**
* 给定数组抽取n个数据
* @param list
* @param n
* @return
*/
public static ArrayList getRandom(List list, int n) {
Random random = new Random();
HashMap<Object, Object> hashMap = new HashMap<Object, Object>();
// 生成随机数字并存入HashMap
for (int i = 0; i < list.size(); i++) {
int number = random.nextInt(100) + 1;
hashMap.put(number, i);
}
// 从HashMap导入数组
Object[] robjs = hashMap.values().toArray();
ArrayList r = new ArrayList();
// 遍历数组并打印数据
for (int i = 0; i < n; i++) {
r.add(list.get((int) robjs[i]));
System.out.print(list.get((int) robjs[i]) + "\t");
}
System.out.print("\n");
return r;
}
}

@ -0,0 +1,34 @@
package com.huoran.iasf.common.utils;
/**
* @Author chen
* @DATE 2021/7/7 14:14
* @Version 1.0
*/
public interface SMSTemplate {
// 短信签名
String SMS_SIGNATURE = "或然科技";
// 找回密码验证码
String RETRIEVE_PASSWORD_CODE = "SMS_219310031";
// 身份验证验证码
String AUTHENTICATION_CODE = "SMS_221515019";
// 登录确认验证码
String LOGIN_VERIFICATION_CODE = "SMS_204155296";
// 登录异常验证码
String LOGIN_EXCEPTION_CODE = "SMS_204155295";
// 用户注册验证码
String USER_REGISTRATION_CODE = "SMS_204155294";
// 修改密码验证码
String MODIFY_PASSWORD_CODE = "SMS_204155293";
// 信息变更验证码
String INFORMATION_CHANGE_CODE = "SMS_204155292";
}

@ -0,0 +1,51 @@
package com.huoran.iasf.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
@Slf4j
public class SendSMSUtils {
public static boolean send(String PhoneNumbers, String templateCode, Map<String,Object> param) {
if(StringUtils.isEmpty(PhoneNumbers)) {
return false;
}
DefaultProfile profile =
DefaultProfile.getProfile("default", "LTAI4FzqQHnk4rozqLZ8jCNj", "mveW7B1OyFoKUkHm8WsxmrjHmkJWHq");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.GET);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("PhoneNumbers", PhoneNumbers);
request.putQueryParameter("SignName", SMSTemplate.SMS_SIGNATURE);
request.putQueryParameter("TemplateCode", templateCode);
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
return response.getHttpResponse().isSuccess();
} catch (ClientException e) {
e.printStackTrace();
}
return false;
}
}

@ -69,7 +69,7 @@ public class RoleController {
@ApiOperation(value = "删除角色接口")
@LogAnnotation(title = "角色管理", action = "删除角色")
@RequiresPermissions("sys:role:deleted")
public R deleted(@PathVariable("id") String id) {
public R deleted(@PathVariable("id") Integer id) {
roleService.deletedRole(id);
return R.success();
}
@ -100,7 +100,7 @@ public class RoleController {
QueryWrapper<SysRolePermission> wrapper = new QueryWrapper<>();
wrapper.eq("role_id", id).select("permission_id");
List<SysRolePermission> list = rolePermissionService.list(wrapper);
List<String> permissionList = new ArrayList<>();
List<Integer> permissionList = new ArrayList<>();
list.forEach(rolePermission -> {
permissionList.add(rolePermission.getPermissionId());
});

@ -6,8 +6,9 @@ import com.huoran.iasf.common.aop.annotation.LogAnnotation;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.service.HttpSessionService;
import com.huoran.iasf.service.UserRoleService;
import com.huoran.iasf.service.UserService;
import com.huoran.iasf.vo.CheckVo;
import com.huoran.iasf.vo.req.UpdatePhoneOrEmailReq;
import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.resp.UserListResp;
import io.swagger.annotations.Api;
@ -43,8 +44,7 @@ import java.util.Map;
public class UserController {
@Resource
private UserService userService;
@Resource
private UserRoleService userRoleService;
@Resource
private HttpSessionService httpSessionService;
@ -61,7 +61,6 @@ public class UserController {
return R.success();
}*/
@PutMapping("/user")
@ApiOperation(value = "更新用户信息接口")
@LogAnnotation(title = "用户管理", action = "更新用户信息")
@ -74,7 +73,6 @@ public class UserController {
return R.success();
}
@GetMapping("/user/{id}")
@ApiOperation(value = "查询用户详情接口")
@LogAnnotation(title = "用户管理", action = "查询用户详情")
@ -106,7 +104,7 @@ public class UserController {
public R checkJobNumber(@RequestParam String jobNumber) {
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getJobNumber, jobNumber));
if (sysUser != null) {
R.fail("工号已存在,请勿重复添加!");
return R.fail("工号已存在,请勿重复添加!");
}
return R.success();
}
@ -116,7 +114,7 @@ public class UserController {
public R checkUsername(@RequestParam String userName) {
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userName));
if (sysUser != null) {
R.fail("账号已存在,请勿重复添加!");
return R.fail("账号已存在,请勿重复添加!");
}
return R.success();
}
@ -126,7 +124,7 @@ public class UserController {
public R checkEmail(@RequestParam String email) {
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getEmail, email));
if (sysUser != null) {
R.fail("邮箱已存在,请勿重复添加!");
return R.fail("邮箱已存在,请勿重复添加!");
}
return R.success();
}
@ -136,7 +134,7 @@ public class UserController {
public R checkPhone(@RequestParam String phone) {
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phone));
if (sysUser != null) {
R.fail("手机号已存在,请勿重复添加!");
return R.fail("手机号已存在,请勿重复添加!");
}
return R.success();
}
@ -164,7 +162,7 @@ public class UserController {
if (StringUtils.isEmpty(vo.getOldPwd()) || StringUtils.isEmpty(vo.getNewPwd())) {
return R.fail("旧密码与新密码不能为空");
}
String userId = httpSessionService.getCurrentUserId();
Integer userId = httpSessionService.getCurrentUserId();
vo.setId(userId);
userService.updatePwd(vo);
return R.success();
@ -174,7 +172,7 @@ public class UserController {
@ApiOperation(value = "删除用户接口")
@LogAnnotation(title = "用户管理", action = "删除用户")
@RequiresPermissions("sys:user:deleted")
public R deletedUser(@RequestBody @ApiParam(value = "用户id集合") List<String> userIds) {
public R deletedUser(@RequestBody @ApiParam(value = "用户id集合") List<Integer> userIds) {
//删除用户, 删除redis的绑定的角色跟权限
httpSessionService.abortUserByUserIds(userIds);
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
@ -183,37 +181,6 @@ public class UserController {
return R.success();
}
/*@GetMapping("/user/roles/{userId}")
@ApiOperation(value = "赋予角色-获取所有角色接口")
@LogAnnotation(title = "用户管理", action = "赋予角色-获取所有角色接口")
@RequiresPermissions("sys:user:role:detail")
public R getUserOwnRole(@PathVariable("userId") String userId) {
R result = R.success();
result.setData(userService.getUserOwnRole(userId));
return result;
}
@PutMapping("/user/roles/{userId}")
@ApiOperation(value = "赋予角色-用户赋予角色接口")
@LogAnnotation(title = "用户管理", action = "赋予角色-用户赋予角色接口")
@RequiresPermissions("sys:user:update:role")
public R setUserOwnRole(@PathVariable("userId") String userId, @RequestBody List<String> roleIds) {
LambdaQueryWrapper<SysUserRole> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysUserRole::getUserId, userId);
userRoleService.remove(queryWrapper);
if (!CollectionUtils.isEmpty(roleIds)) {
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
reqVO.setUserId(userId);
reqVO.setRoleIds(roleIds);
userRoleService.addUserRoleInfo(reqVO);
}
//刷新权限
httpSessionService.refreshUerId(userId);
return R.success();
}*/
@PostMapping("/importStaff")
@ApiOperation("批量导入员工")
public R importStaff(@RequestParam(name = "file") MultipartFile file, HttpServletRequest request) throws IOException {
@ -229,4 +196,23 @@ public class UserController {
public void exportFailureRecord(HttpServletResponse response, @ApiParam(name = "exportCode", value = "importQuestion接口返回的exportCode", required = true) @RequestParam String exportCode) throws Exception {
userService.exportFailureRecord(response, exportCode);
}
@ApiOperation(value = "更换手机号或邮箱--发送验证码")
@PostMapping("/sendPhoneOrEmailCode")
public R sendPhoneOrEmailCode(@RequestBody CheckVo checkVo) {
return userService.sendCheckPhoneCode(checkVo);
}
@ApiOperation(value = "更新手机号或邮箱")
@PostMapping("/updatePhoneOrEmail")
public R updatePhoneOrEmail(@RequestBody UpdatePhoneOrEmailReq updatePhoneOrEmailReq) {
return userService.updatePhoneOrEmail(updatePhoneOrEmailReq);
}
@ApiOperation(value = "修改用户头像")
@PostMapping("/updateUserAvatars")
public R updateUserAvatars(@RequestParam String userId, MultipartFile file) {
return userService.updateUserAvatars(userId, file);
}
}

@ -1,6 +1,7 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
@ -19,8 +20,9 @@ import java.util.Date;
*/
@Data
public class SysDept implements Serializable {
@TableId
private String id;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)")
private String deptNo;
@ -31,7 +33,7 @@ public class SysDept implements Serializable {
@NotBlank(message = "父级不能为空")
@ApiModelProperty(value = "父级id")
private String pid;
private Integer pid;
@TableField(exist = false)
@ApiModelProperty(value = "父级部门名称")

@ -1,6 +1,7 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
@ -22,8 +23,9 @@ import java.util.List;
@Data
public class SysPermission implements Serializable {
@TableId
private String id;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@NotBlank(message = "菜单权限名称不能为空")
@ApiModelProperty(value = "菜单权限名称")

@ -1,6 +1,7 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
@ -24,8 +25,9 @@ import java.util.List;
@Data
@Accessors(chain = true)
public class SysRole extends BaseEntity implements Serializable {
@TableId
private String id;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@NotBlank(message = "名称不能为空")
@ApiModelProperty(value = "角色名称")
@ -54,7 +56,7 @@ public class SysRole extends BaseEntity implements Serializable {
@TableField(exist = false)
@ApiModelProperty(value = "权限")
private List<String> permissions;
private List<Integer> permissions;
}

@ -1,49 +0,0 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 角色部门
*
* @author cheney
* @email *****@mail.com
* @date 2020-09-27 17:30:15
*/
@Data
@TableName("sys_role_dept")
public class SysRoleDeptEntity extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId("id")
private String id;
/**
* 角色id
*/
@TableField("role_id")
private String roleId;
/**
* 菜单权限id
*/
@TableField("dept_id")
private String deptId;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
}

@ -1,8 +1,10 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@ -17,12 +19,13 @@ import java.util.Date;
*/
@Data
public class SysRolePermission implements Serializable {
@TableId
private String id;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String roleId;
private Integer roleId;
private String permissionId;
private Integer permissionId;
@TableField(fill = FieldFill.INSERT)
private Date createTime;

@ -1,6 +1,7 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
@ -22,9 +23,9 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUser extends BaseEntity implements Serializable {
@TableId
@ApiModelProperty(value = "用户id")
private String id;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@NotBlank(message = "账号不能为空")
@ApiModelProperty(value = "账户名称")
@ -73,7 +74,7 @@ public class SysUser extends BaseEntity implements Serializable {
private String email;
@ApiModelProperty(value = "用户组id")
private String groupId;
private Integer groupId;
@TableField(exist = false)
@ApiModelProperty(value = "用户组名称")
@ -90,10 +91,10 @@ public class SysUser extends BaseEntity implements Serializable {
private Integer deleted;
@ApiModelProperty(value = "创建人")
private String createId;
private Integer createId;
@ApiModelProperty(value = "更新人")
private String updateId;
private Integer updateId;
@ApiModelProperty(value = "创建来源(1.web 2.android 3.ios )")
private Integer createWhere;
@ -119,11 +120,11 @@ public class SysUser extends BaseEntity implements Serializable {
@TableField(exist = false)
@ApiModelProperty(value = "角色id")
private List<String> roleIds;
private List<Integer> roleIds;
@TableField(exist = false)
@ApiModelProperty(value = "组织架构id(多个部门id)")
private List<String> deptArchitectureId;
private List<Integer> deptArchitectureId;
@TableField(exist = false)
@ApiModelProperty("随机数")

@ -1,8 +1,10 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@ -17,12 +19,13 @@ import java.util.Date;
*/
@Data
public class SysUserRole implements Serializable {
@TableId
private String id;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String userId;
private Integer userId;
private String roleId;
private Integer roleId;
@TableField(fill = FieldFill.INSERT)
private Date createTime;

@ -30,10 +30,10 @@ public class UserDept implements Serializable {
private Integer id;
@ApiModelProperty(value = "用户员工id")
private String userId;
private Integer userId;
@ApiModelProperty(value = "部门id")
private String deptId;
private Integer deptId;
@ApiModelProperty(value = "创建时间")
@TableField(fill = FieldFill.INSERT)

@ -1,15 +0,0 @@
package com.huoran.iasf.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huoran.iasf.entity.SysRoleDeptEntity;
/**
* 角色部门
*
* @author cheney
* @email *****@mail.com
* @date 2020-09-27 17:30:15
*/
public interface SysRoleDeptMapper extends BaseMapper<SysRoleDeptEntity> {
}

@ -130,9 +130,9 @@ public class HttpSessionService {
*
* @return UserId
*/
public String getCurrentUserId() {
public Integer getCurrentUserId() {
if (getCurrentSession() != null) {
return getCurrentSession().getString(Constant.USERID_KEY);
return Integer.parseInt(getCurrentSession().getString(Constant.USERID_KEY));
} else {
return null;
}
@ -159,16 +159,16 @@ public class HttpSessionService {
/**
* 使用户的token失效
*/
public void abortUserById(String userId) {
public void abortUserById(Integer userId) {
redisService.delKeys(userTokenPrefix + "*#" + userId);
}
/**
* 使多个用户的token失效
*/
public void abortUserByUserIds(List<String> userIds) {
public void abortUserByUserIds(List<Integer> userIds) {
if (CollectionUtils.isNotEmpty(userIds)) {
for (String id : userIds) {
for (Integer id : userIds) {
redisService.delKeys(userTokenPrefix + "*#" + id);
}
@ -180,7 +180,7 @@ public class HttpSessionService {
*
* @param userId userId
*/
public void refreshUerId(String userId) {
public void refreshUerId(Integer userId) {
redisService.delKeys(userTokenPrefix + "*#" + userId);
@ -207,8 +207,8 @@ public class HttpSessionService {
*
* @param roleId roleId
*/
public void refreshRolePermission(String roleId) {
List<String> userIds = userRoleService.getUserIdsByRoleId(roleId);
public void refreshRolePermission(Integer roleId) {
List<Integer> userIds = userRoleService.getUserIdsByRoleId(roleId);
if (!CollectionUtils.isEmpty(userIds)) {
userIds.parallelStream().forEach(this::refreshUerId);
}
@ -219,8 +219,8 @@ public class HttpSessionService {
*
* @param permissionId permissionId
*/
public void refreshPermission(String permissionId) {
List<String> userIds = permissionService.getUserIdsById(permissionId);
public void refreshPermission(Integer permissionId) {
List<Integer> userIds = permissionService.getUserIdsById(permissionId);
if (!CollectionUtils.isEmpty(userIds)) {
userIds.parallelStream().forEach(this::refreshUerId);
}
@ -254,11 +254,11 @@ public class HttpSessionService {
}
private List<String> getRolesByUserId(String userId) {
private List<String> getRolesByUserId(Integer userId) {
return roleService.getRoleNames(userId);
}
private Set<String> getPermissionsByUserId(String userId) {
private Set<String> getPermissionsByUserId(Integer userId) {
return permissionService.getPermissionsByUserId(userId);
}

@ -22,14 +22,14 @@ public interface PermissionService extends IService<SysPermission> {
* @param userId userId
* @return 权限
*/
List<SysPermission> getPermission(String userId);
List<SysPermission> getPermission(Integer userId);
/**
* 删除权限
*
* @param permissionId 权限id
*/
void deleted(String permissionId);
void deleted(Integer permissionId);
/**
* 获取所有
@ -44,7 +44,7 @@ public interface PermissionService extends IService<SysPermission> {
* @param userId userId
* @return Set
*/
Set<String> getPermissionsByUserId(String userId);
Set<String> getPermissionsByUserId(Integer userId);
/**
* 根据userId获取权限树
@ -52,7 +52,7 @@ public interface PermissionService extends IService<SysPermission> {
* @param userId
* @return List
*/
List<PermissionRespNode> permissionTreeList(String userId);
List<PermissionRespNode> permissionTreeList(Integer userId);
/**
* 根据权限树
@ -67,7 +67,7 @@ public interface PermissionService extends IService<SysPermission> {
* @param permissionId permissionId
* @return List
*/
List<PermissionRespNode> selectAllMenuByTree(String permissionId);
List<PermissionRespNode> selectAllMenuByTree(Integer permissionId);
/**
@ -76,7 +76,7 @@ public interface PermissionService extends IService<SysPermission> {
* @param permissionId permissionId
* @return List
*/
List<String> getUserIdsById(String permissionId);
List<Integer> getUserIdsById(Integer permissionId);
/**
* 更新
@ -85,5 +85,5 @@ public interface PermissionService extends IService<SysPermission> {
*/
void updatePermission(SysPermission vo);
List<SysPermission> permissionList(String id);
List<SysPermission> permissionList(Integer id);
}

@ -33,7 +33,7 @@ public interface RoleService extends IService<SysRole> {
*
* @param id id
*/
void deletedRole(String id);
void deletedRole(Integer id);
/**
* 根据userId获取绑定的角色
@ -41,7 +41,7 @@ public interface RoleService extends IService<SysRole> {
* @param userId userId
* @return List
*/
List<SysRole> getRoleInfoByUserId(String userId);
List<SysRole> getRoleInfoByUserId(Integer userId);
/**
* 根据userId获取绑定的角色名
@ -49,7 +49,7 @@ public interface RoleService extends IService<SysRole> {
* @param userId userId
* @return List
*/
List<String> getRoleNames(String userId);
List<String> getRoleNames(Integer userId);
boolean checkDeptRepeat(SysRole vo);
}

@ -21,7 +21,7 @@ public interface UserRoleService extends IService<SysUserRole> {
* @param userId userId
* @return List
*/
List<String> getRoleIdsByUserId(String userId);
List getRoleIdsByUserId(Integer userId);
/**
* 用户绑定角色
@ -36,5 +36,5 @@ public interface UserRoleService extends IService<SysUserRole> {
* @param roleId roleId
* @return List
*/
List<String> getUserIdsByRoleId(String roleId);
List<Integer> getUserIdsByRoleId(Integer roleId);
}

@ -3,10 +3,11 @@ package com.huoran.iasf.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.vo.CheckVo;
import com.huoran.iasf.vo.req.UpdatePhoneOrEmailReq;
import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.resp.LoginRespVO;
import com.huoran.iasf.vo.resp.UserListResp;
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
@ -24,62 +25,34 @@ public interface UserService extends IService<SysUser> {
/**
* 注册
*
* @param vo vo
*/
void register(SysUser vo);
/**
* 登陆
*
* @param vo vo
* @return LoginRespVO
*/
LoginRespVO login(SysUser vo);
/**
* 更新用户信息
*
* @param vo vo
*/
void updateUserInfo(SysUser vo);
/**
* 分页
*
* @return IPage
*/
R pageInfo(UserListReq userListReq);
/**
* 添加用户
*
* @param vo vo
*/
void addUser(SysUser vo);
/**
* 修改密码
*
* @param vo vo
*/
void updatePwd(SysUser vo);
/**
* 根据userid获取绑定角色
*
* @param userId userId
* @return UserOwnRoleRespVO
*/
UserOwnRoleRespVO getUserOwnRole(String userId);
/**
* 修改自己信息
*
* @param vo vo
*/
void updateUserInfoMy(SysUser vo);
UserListResp detailInfo(String id);
R resetPwd(String userId);
@ -87,4 +60,10 @@ public interface UserService extends IService<SysUser> {
Map<String, String> importStaff(MultipartFile file);
void exportFailureRecord(HttpServletResponse response, String exportCode) throws IOException;
R sendCheckPhoneCode(CheckVo checkVo);
R updatePhoneOrEmail(UpdatePhoneOrEmailReq updatePhoneOrEmailReq);
R updateUserAvatars(String userId, MultipartFile file);
}

@ -67,7 +67,7 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", sysDept.getName());
queryWrapper.eq("pid", sysDept.getPid());
if (StrUtil.isNotEmpty(sysDept.getId())) {
if (StrUtil.isNotEmpty(sysDept.getId().toString())) {
queryWrapper.last(" and id != " + sysDept.getId());
}
List<SysDept> sysDepts = baseMapper.selectList(queryWrapper);
@ -173,7 +173,7 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
return list;
}
private List<DeptRespNodeVO> getChild(String id, List<SysDept> all) {
private List<DeptRespNodeVO> getChild(Integer id, List<SysDept> all) {
List<DeptRespNodeVO> list = new ArrayList<>();
for (SysDept sysDept : all) {
if (sysDept.getPid().equals(id)) {

@ -56,8 +56,8 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
* 也可以多表关联查询
*/
@Override
public List<SysPermission> getPermission(String userId) {
List<String> roleIds = userRoleService.getRoleIdsByUserId(userId);
public List<SysPermission> getPermission(Integer userId) {
List<Integer> roleIds = userRoleService.getRoleIdsByUserId(userId);
if (CollectionUtils.isEmpty(roleIds)) {
return null;
}
@ -77,9 +77,9 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void deleted(String permissionId) {
public void deleted(Integer permissionId) {
//获取关联userId
List<String> userIds = getUserIdsById(permissionId);
List<Integer> userIds = getUserIdsById(permissionId);
SysPermission sysPermission = sysPermissionMapper.selectById(permissionId);
if (null == sysPermission) {
log.error("传入 的 id:{}不合法", permissionId);
@ -102,7 +102,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
}
@Override
public List<SysPermission> permissionList(String userId) {
public List<SysPermission> permissionList(Integer userId) {
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id",userId);
List<SysUserRole> userRoles = userRoleService.list(queryWrapper);
@ -146,7 +146,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
* 获取权限标识
*/
@Override
public Set<String> getPermissionsByUserId(String userId) {
public Set<String> getPermissionsByUserId(Integer userId) {
List<SysPermission> list = getPermission(userId);
Set<String> permissions = new HashSet<>();
@ -166,7 +166,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
* 以树型的形式把用户拥有的菜单权限返回给客户端
*/
@Override
public List<PermissionRespNode> permissionTreeList(String userId) {
public List<PermissionRespNode> permissionTreeList(Integer userId) {
List<SysPermission> list = getPermission(userId);
return getTree(list, true);
}
@ -200,7 +200,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
/**
* 递归遍历所有
*/
private List<PermissionRespNode> getChildAll(String id, List<SysPermission> all) {
private List<PermissionRespNode> getChildAll(Integer id, List<SysPermission> all) {
List<PermissionRespNode> list = new ArrayList<>();
for (SysPermission sysPermission : all) {
@ -218,7 +218,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
/**
* 只递归获取目录和菜单
*/
private List<PermissionRespNode> getChildExcBtn(String id, List<SysPermission> all) {
private List<PermissionRespNode> getChildExcBtn(Integer id, List<SysPermission> all) {
List<PermissionRespNode> list = new ArrayList<>();
for (SysPermission sysPermission : all) {
@ -289,7 +289,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
* 选择自己和它的子类
*/
@Override
public List<PermissionRespNode> selectAllMenuByTree(String permissionId) {
public List<PermissionRespNode> selectAllMenuByTree(Integer permissionId) {
List<SysPermission> list = selectAll();
if (!CollectionUtils.isEmpty(list) && !StringUtils.isEmpty(permissionId)) {
@ -303,7 +303,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
List<PermissionRespNode> result = new ArrayList<>();
//新增顶级目录是为了方便添加一级目录
PermissionRespNode respNode = new PermissionRespNode();
respNode.setId("0");
respNode.setId(0);
respNode.setName("默认顶级菜单");
// respNode.setSpread(true);
respNode.setChildren(getTree(list, true));
@ -312,7 +312,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
}
@Override
public List getUserIdsById(String id) {
public List getUserIdsById(Integer id) {
//根据权限id,获取所有角色id
//根据权限id,获取所有角色id
List<Object> roleIds = rolePermissionService.listObjs(Wrappers.<SysRolePermission>lambdaQuery().select(SysRolePermission::getRoleId).eq(SysRolePermission::getPermissionId, id));

@ -23,7 +23,7 @@ public class RolePermissionServiceImpl extends ServiceImpl<SysRolePermissionMapp
@Override
public void addRolePermission(RolePermissionOperationReqVO vo) {
List<SysRolePermission> list = new ArrayList<>();
for (String permissionId : vo.getPermissionIds()) {
for (Integer permissionId : vo.getPermissionIds()) {
SysRolePermission sysRolePermission = new SysRolePermission();
sysRolePermission.setPermissionId(permissionId);
sysRolePermission.setRoleId(vo.getRoleId());

@ -102,9 +102,9 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
@Transactional(rollbackFor = Exception.class)
@Override
public void deletedRole(String id) {
public void deletedRole(Integer id) {
//获取关联userId
List<String> userIds = userRoleService.getUserIdsByRoleId(id);
List<Integer> userIds = userRoleService.getUserIdsByRoleId(id);
//删除角色
sysRoleMapper.deleteById(id);
//删除角色权限关联
@ -118,9 +118,9 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
}
@Override
public List<SysRole> getRoleInfoByUserId(String userId) {
public List<SysRole> getRoleInfoByUserId(Integer userId) {
List<String> roleIds = userRoleService.getRoleIdsByUserId(userId);
List<Integer> roleIds = userRoleService.getRoleIdsByUserId(userId);
if (CollectionUtils.isEmpty(roleIds)) {
return null;
}
@ -128,7 +128,7 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
}
@Override
public List<String> getRoleNames(String userId) {
public List<String> getRoleNames(Integer userId) {
List<SysRole> sysRoles = getRoleInfoByUserId(userId);
if (CollectionUtils.isEmpty(sysRoles)) {
return null;
@ -140,7 +140,7 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
public boolean checkDeptRepeat(SysRole vo) {
QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", vo.getName());
if (StrUtil.isNotEmpty(vo.getId())) {
if (StrUtil.isNotEmpty(vo.getId().toString())) {
queryWrapper.last(" and id != " + vo.getId());
}
List<SysRole> sysRoles = baseMapper.selectList(queryWrapper);

@ -103,7 +103,6 @@ public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFilesEnt
uEditorResult.setTitle(fileNameNew);
uEditorResult.setOriginal(fileName);
return uEditorResult;
// return R.success(resultMap);
} catch (Exception e) {
throw new BusinessException(BaseResponseCode.UPLOAD_FAILED);
}

@ -1,14 +0,0 @@
package com.huoran.iasf.service.impl;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.entity.SysRoleDeptEntity;
import com.huoran.iasf.mapper.SysRoleDeptMapper;
import org.springframework.stereotype.Service;
@Service("sysRoleDeptService")
public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDeptEntity> implements IService<SysRoleDeptEntity> {
}

@ -28,7 +28,7 @@ public class UserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserR
private SysUserRoleMapper sysUserRoleMapper;
@Override
public List getRoleIdsByUserId(String userId) {
public List getRoleIdsByUserId(Integer userId) {
LambdaQueryWrapper<SysUserRole> queryWrapper = Wrappers.<SysUserRole>lambdaQuery().select(SysUserRole::getRoleId).eq(SysUserRole::getUserId, userId);
return sysUserRoleMapper.selectObjs(queryWrapper);
}
@ -40,7 +40,7 @@ public class UserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserR
return;
}
List<SysUserRole> list = new ArrayList<>();
for (String roleId : vo.getRoleIds()) {
for (Integer roleId : vo.getRoleIds()) {
SysUserRole sysUserRole = new SysUserRole();
sysUserRole.setUserId(vo.getUserId());
sysUserRole.setRoleId(roleId);
@ -52,7 +52,7 @@ public class UserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserR
}
@Override
public List getUserIdsByRoleId(String roleId) {
public List getUserIdsByRoleId(Integer roleId) {
return sysUserRoleMapper.selectObjs(Wrappers.<SysUserRole>lambdaQuery().select(SysUserRole::getUserId).eq(SysUserRole::getRoleId, roleId));
}
}

@ -16,23 +16,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.ExcelImportHelper;
import com.huoran.iasf.common.utils.ExcelStyleUtil;
import com.huoran.iasf.common.utils.PasswordUtils;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.common.utils.*;
import com.huoran.iasf.entity.*;
import com.huoran.iasf.mapper.SysDeptMapper;
import com.huoran.iasf.mapper.SysUserMapper;
import com.huoran.iasf.mapper.UserDeptMapper;
import com.huoran.iasf.mapper.UserGroupMapper;
import com.huoran.iasf.service.*;
import com.huoran.iasf.vo.CheckVo;
import com.huoran.iasf.vo.ImportUserFailureVo;
import com.huoran.iasf.vo.req.ExcelImpUserReq;
import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.req.UserRoleOperationReqVO;
import com.huoran.iasf.vo.UEditorResultVO;
import com.huoran.iasf.vo.req.*;
import com.huoran.iasf.vo.resp.LoginRespVO;
import com.huoran.iasf.vo.resp.UserListResp;
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
@ -78,6 +74,10 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
@Resource
private SysDeptMapper sysDeptMapper;
@Resource
private SysFilesService sysFilesService;
@Resource
private HttpSessionService httpSessionService;
@ -92,8 +92,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
@Value("${spring.redis.allowMultipleLogin}")
private Boolean allowMultipleLogin;
@Value("${spring.profiles.active}")
private String env;
@Override
public void register(SysUser sysUser) {
@ -184,18 +182,27 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
httpSessionService.abortUserById(vo.getId());
}
if (!StringUtils.isEmpty(vo.getPassword())) {
if (StringUtils.isNotEmpty(vo.getPassword())) {
String newPassword = PasswordUtils.encode(vo.getPassword(), sysUser.getSalt());
vo.setPassword(newPassword);
} else {
vo.setPassword(null);
}
if (StringUtils.isNotEmpty(vo.getEmail())) {
vo.setEmail(vo.getEmail());
}
if (StringUtils.isNotEmpty(vo.getPhone())) {
vo.setEmail(vo.getPhone());
}
//删除所有部门
userDeptMapper.delete(Wrappers.<UserDept>lambdaQuery().eq(UserDept::getUserId, vo.getId()));
//更新部门
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) {
List<String> deptArchitectureId = vo.getDeptArchitectureId();
for (String deptId : deptArchitectureId) {
List<Integer> deptArchitectureId = vo.getDeptArchitectureId();
for (Integer deptId : deptArchitectureId) {
UserDept userDept = new UserDept();
userDept.setUserId(vo.getId());
userDept.setDeptId(deptId);
@ -220,25 +227,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}
@Override
public void updateUserInfoMy(SysUser vo) {
SysUser user = sysUserMapper.selectById(httpSessionService.getCurrentUserId());
if (null == user) {
throw new BusinessException(BaseResponseCode.DATA_ERROR);
}
if (!StringUtils.isEmpty(vo.getPassword())) {
String newPassword = PasswordUtils.encode(vo.getPassword(), user.getSalt());
vo.setPassword(newPassword);
} else {
vo.setPassword(null);
}
vo.setUpdateId(httpSessionService.getCurrentUserId());
sysUserMapper.updateById(vo);
}
@Override
public UserListResp detailInfo(String id) {
return baseMapper.detailInfo(id);
@ -277,8 +265,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
sysUserMapper.insert(vo);
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) {
List<String> deptArchitectureId = vo.getDeptArchitectureId();
for (String deptId : deptArchitectureId) {
List<Integer> deptArchitectureId = vo.getDeptArchitectureId();
for (Integer deptId : deptArchitectureId) {
UserDept userDept = new UserDept();
userDept.setUserId(vo.getId());
userDept.setDeptId(deptId);
@ -315,16 +303,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}
@Override
public UserOwnRoleRespVO getUserOwnRole(String userId) {
List<String> roleIdsByUserId = userRoleService.getRoleIdsByUserId(userId);
List<SysRole> list = roleService.list();
UserOwnRoleRespVO vo = new UserOwnRoleRespVO();
vo.setAllRole(list);
vo.setOwnRoles(roleIdsByUserId);
return vo;
}
@Override
@Transactional
public Map<String, String> importStaff(MultipartFile file) {
@ -389,7 +367,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}
//账号id
String usernameId = "0";
Integer usernameId = 0;
vo1.setIndex(ii);
//检验姓名
@ -426,7 +404,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}
}
List<String> roleIds = new ArrayList<>();
List<Integer> roleIds = new ArrayList<>();
//检验角色
if ("".equals(getRoleName)) {
@ -545,7 +523,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
vo1.setEmail(getEmail);
}
ArrayList<String> architectureIds = new ArrayList<>();
ArrayList<Integer> architectureIds = new ArrayList<>();
//检验所在部门
if ("".equals(dept)) {
++countNum;
@ -574,9 +552,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}else {
//保存架构id
Object architectureId = hashMap.get("architectureId");
String id = "0";
Integer id = 0;
if (architectureId!=null){
id = (String) architectureId;
id = (Integer)architectureId;
architectureIds.add(id);
}
}
@ -598,9 +576,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}else {
//保存架构id
Object architectureId = hashMap.get("architectureId");
String id = "0";
Integer id = 0;
if (architectureId!=null){
id = (String) architectureId;
id = (Integer) architectureId;
architectureIds.add(id);
}
}
@ -629,12 +607,12 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
vo.setStatus(1);
vo.setCreateWhere(1);
if (groupId!=0){
vo.setGroupId(groupId.toString());
vo.setGroupId(groupId);
}
sysUserMapper.insert(vo);
if (!CollectionUtils.isEmpty(architectureIds)) {
for (String deptId : architectureIds) {
for (Integer deptId : architectureIds) {
UserDept userDept = new UserDept();
userDept.setUserId(vo.getId());
userDept.setDeptId(deptId);
@ -653,11 +631,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
List<UserDept> userDepts = userDeptMapper.
selectList(new QueryWrapper<UserDept>().eq("user_id", usernameId));
ArrayList<String> staffDepartmentIds = new ArrayList<>();
ArrayList<Integer> staffDepartmentIds = new ArrayList<>();
for ( UserDept userDept : userDepts) {
staffDepartmentIds.add(userDept.getDeptId());
}
for (String architectureId : architectureIds) {
for (Integer architectureId : architectureIds) {
if (!staffDepartmentIds.contains(architectureId)){
UserDept userDept = new UserDept();
userDept.setUserId(usernameId);
@ -709,7 +687,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
* 组织架构判重,返回下一层级的父id
*
*/
public String checkArchitectureRepeat(String name ,String pid){
public Integer checkArchitectureRepeat(String name ,Integer pid){
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name",name).eq("pid",pid);
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper);
@ -741,7 +719,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper1);
if (sysDept == null) {
//为空表示不存在该部门,一级部门不存在,表示子级部门都能直接新增,达底端返回部门id
String pid = "0";
Integer pid = 0;
for (int j = 0; j < split.length; j++) {
SysDept sysDept1 = new SysDept();
sysDept1.setName(split[j]);
@ -757,11 +735,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}
}
} else {
String nextLevelPid = sysDept.getId();
Integer nextLevelPid = sysDept.getId();
//存在一级部门,循环查询下一层级,存在则继续向下判断,否则进行新增,到达底端返回部门id
int pid = 1;
for (int j = 1; j < split.length; j++) {
String nextPid = checkArchitectureRepeat(split[j],nextLevelPid);
Integer nextPid = checkArchitectureRepeat(split[j],nextLevelPid);
//都存在,最后一次循环返回部门id
if (split.length-1==j){
map.put("architectureId",nextPid);
@ -866,4 +844,102 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
exportParams.setStyle(ExcelStyleUtil.class);
workbook.write(response.getOutputStream());
}
@Override
public R sendCheckPhoneCode(CheckVo checkVo) {
boolean re = false;
boolean isSend;
String phoneOrEmail = "";
String msg = "";
if (checkVo.getTypes().equals(1)) {//邮箱验证码
phoneOrEmail = checkVo.getEmail();
Integer count = baseMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getEmail, checkVo.getEmail()));
if (count>0){
msg = "邮箱已存在!";
re = true;
}
} else {//手机验证码
phoneOrEmail = checkVo.getPhone();
Integer count = baseMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, checkVo.getPhone()));
if (count>0){
msg = "手机号已存在!";
re = true;
}
}
if (re) {
return R.fail(msg);
}
//先从redis中查询该手机号的验证码是否过期,未过期直接返回发送成功,防重放
//为了保证该手机号5分钟内在其他场景下内正常使用,存入的key需要与短信模板进行拼接
String key = org.apache.commons.lang3.StringUtils.join(phoneOrEmail, SMSTemplate.AUTHENTICATION_CODE);
System.out.println(key);
String code = stringRedisTemplate.opsForValue().get(key);
if (!StringUtils.isEmpty(code)) {
return R.success("验证码已发,请勿重复操作!");
}
code = RandomUtil.getSixBitRandom();
Map<String, Object> param = new HashMap<>();
param.put("code", code);
if (checkVo.getTypes().equals(1)) {//邮箱验证码
isSend = EmailUtils.sendEmail(phoneOrEmail, code);
} else {//手机验证码
isSend = SendSMSUtils.send(phoneOrEmail, SMSTemplate.AUTHENTICATION_CODE, param);
}
if (isSend) {
stringRedisTemplate.opsForValue().set(key, code, 5, TimeUnit.MINUTES);
CheckVo checkVo1 = new CheckVo();
checkVo1.setOpener(key);
return R.success(checkVo1);
} else {
return R.fail("短信发送失败,请稍后重试!");
}
}
@Override
public R updatePhoneOrEmail(UpdatePhoneOrEmailReq updatePhoneOrEmailReq) {
String phoneOrEmail = "";
SysUser user = new SysUser();
user.setId(updatePhoneOrEmailReq.getUserId());
if (updatePhoneOrEmailReq.getTypes().equals(1)) {//邮箱验证码
phoneOrEmail = updatePhoneOrEmailReq.getEmail();
user.setEmail(updatePhoneOrEmailReq.getEmail());
} else {//手机验证码
phoneOrEmail = updatePhoneOrEmailReq.getPhone();
user.setPhone(updatePhoneOrEmailReq.getPhone());
}
//从redis中查询该手机号的验证码是否过期
//为了保证该手机号5分钟内在其他场景下内正常使用,存入的key需要与短信模板进行拼接
String key = org.apache.commons.lang3.StringUtils.join(phoneOrEmail, SMSTemplate.AUTHENTICATION_CODE);
System.out.println(key);
String code = stringRedisTemplate.opsForValue().get(key);
if (StringUtils.isEmpty(code)) {
return R.fail("验证码已过期!");
}
if (code.equals(updatePhoneOrEmailReq.getCode())){
//更新用户手机号
baseMapper.updateById(user);
return R.success();
}
return R.fail("验证码错误!");
}
@Override
public R updateUserAvatars(String userId, MultipartFile file) {
SysUser sysUser = baseMapper.selectById(userId);
FileParameters fileParameters = new FileParameters();
fileParameters.setQuote("个人资料");
fileParameters.setSite("管理后台");
fileParameters.setUploader(sysUser.getRealName());
UEditorResultVO uEditorResultVO = sysFilesService.saveFile(file, fileParameters);
sysUser.setUserAvatars(uEditorResultVO.getUrl());
int update = baseMapper.updateById(sysUser);
return update > 0 ? R.success(uEditorResultVO.getUrl()) : R.fail("更新失败");
}
}

@ -0,0 +1,37 @@
package com.huoran.iasf.vo;
/**
* @description
* @author: Mr.JK
* @create: 2021-07-05 18:25
**/
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
@ApiModel(value = "CheckVo",description = "验证码校验参数")
public class CheckVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("用户的邮箱地址")
private String email;
@ApiModelProperty("用户电话号码")
private String phone;
@ApiModelProperty("验证码类型(1邮箱验证码,2手机验证码)")
private Integer types;
@ApiModelProperty(value = "验证key")
private String opener;
}

@ -18,8 +18,8 @@ import java.util.List;
public class RolePermissionOperationReqVO {
@ApiModelProperty(value = "角色id")
@NotBlank(message = "角色id不能为空")
private String roleId;
private Integer roleId;
@ApiModelProperty(value = "菜单权限集合")
@NotEmpty(message = "菜单权限集合不能为空")
private List<String> permissionIds;
private List<Integer> permissionIds;
}

@ -0,0 +1,30 @@
package com.huoran.iasf.vo.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author chen
* @DATE 2022/8/29 15:31
* @Version 1.0
*/
@Data
public class UpdatePhoneOrEmailReq {
@ApiModelProperty("用户id")
private Integer userId;
@ApiModelProperty("用户的邮箱地址")
private String email;
@ApiModelProperty("用户电话号码")
private String phone;
@ApiModelProperty("验证码类型(1邮箱验证码,2手机验证码)")
private Integer types;
@ApiModelProperty("用户输入的验证码")
private String code;
@ApiModelProperty(value = "验证key")
private String opener;
}

@ -19,9 +19,9 @@ public class UserRoleOperationReqVO {
@ApiModelProperty(value = "用户id")
@NotBlank(message = "用户id不能为空")
private String userId;
private Integer userId;
@ApiModelProperty(value = "角色id集合")
@NotEmpty(message = "角色id集合不能为空")
private List<String> roleIds;
private List<Integer> roleIds;
}

@ -15,7 +15,7 @@ import java.util.List;
@Data
public class PermissionRespNode {
@ApiModelProperty(value = "id")
private String id;
private Integer id;
@ApiModelProperty(value = "菜单权限名称")
private String name;

@ -0,0 +1,2 @@
whiteList=/iasf/sys/user/login,\
/iasf/sys/exportFailure

@ -41,10 +41,10 @@ public class CodeGenerator {
// 3、数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://139.9.47.170:3306/iasf?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8");
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/iasf?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("HuoRan@2021");
dsc.setPassword("123456");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
@ -61,7 +61,7 @@ public class CodeGenerator {
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("sys_user_dept");
strategy.setInclude("sys_site");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀

Loading…
Cancel
Save