diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java index c5efffc15..da402196e 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java @@ -80,5 +80,5 @@ public interface CommonConstant { /** * 验证码前缀 */ - String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY"; + String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY_"; } diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java index 0018fe5b5..b658f04cc 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java @@ -60,12 +60,19 @@ public interface SecurityConstants { */ String FROM = "from"; + /** + * OAUTH URL + */ + String OAUTH_TOKEN_URL = "/oauth/token"; + /** * 手机号登录URL */ - String MOBILE_TOKEN_URL = "/mobile/token"; - - + String SMS_TOKEN_URL = "/mobile/token/sms"; + /** + * 自定义登录URL + */ + String MOBILE_TOKEN_URL = "/mobile/token/*"; /** * oauth 客户端信息 */ diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumLoginType.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumLoginType.java index 878cae171..6752cd802 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumLoginType.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumLoginType.java @@ -33,6 +33,11 @@ public enum EnumLoginType { */ PWD("PWD", "账号密码登录"), + /** + * 验证码登录 + */ + SMS("SMS", "验证码登录"), + /** * QQ登录 */ @@ -46,9 +51,9 @@ public enum EnumLoginType { /** * 类型 */ - private final String type; + private String type; /** * 描述 */ - private final String description; + private String description; } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationEntryPoint.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationEntryPoint.java deleted file mode 100644 index 6397d0127..000000000 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationEntryPoint.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - -package com.pig4cloud.pigx.common.security.mobile; - -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.oauth2.common.OAuth2AccessToken; -import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; -import org.springframework.security.oauth2.provider.error.AbstractOAuth2SecurityExceptionHandler; -import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.util.StringUtils; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * @author lengleng - * @date 2018/8/16 - * 手机号登录异常处理 - */ -public class MobileAuthenticationEntryPoint extends AbstractOAuth2SecurityExceptionHandler implements - AuthenticationEntryPoint { - private static final String WWW_AUTHENTICATE = "WWW-Authenticate"; - private static final String SUFFIX = ","; - - @Override - public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) - throws IOException, ServletException { - doHandle(request, response, authException); - } - - @Override - protected ResponseEntity enhanceResponse(ResponseEntity response, Exception exception) { - HttpHeaders headers = response.getHeaders(); - String existing = null; - if (headers.containsKey(WWW_AUTHENTICATE)) { - existing = extractTypePrefix(headers.getFirst("WWW-Authenticate")); - } - StringBuilder builder = new StringBuilder(); - String typeName = OAuth2AccessToken.BEARER_TYPE; - builder.append(typeName + " "); - String realmName = "oauth"; - builder.append("realm=\"" + realmName + "\""); - if (existing != null) { - builder.append(", " + existing); - } - HttpHeaders update = new HttpHeaders(); - update.putAll(response.getHeaders()); - update.set("WWW-Authenticate", builder.toString()); - return new ResponseEntity<>(response.getBody(), update, HttpStatus.EXPECTATION_FAILED); - } - - private String extractTypePrefix(String header) { - String existing = header; - String[] tokens = existing.split(" +"); - if (tokens.length > 1 && !tokens[0].endsWith(SUFFIX)) { - existing = StringUtils.arrayToDelimitedString(tokens, " ").substring(existing.indexOf(" ") + 1); - } - return existing; - } - -} - diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationFilter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationFilter.java index 085dffd03..2b0230ac1 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationFilter.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationFilter.java @@ -43,7 +43,6 @@ import javax.servlet.http.HttpServletResponse; */ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessingFilter { private static final String SPRING_SECURITY_FORM_MOBILE_KEY = "mobile"; - private AuthenticationEntryPoint authenticationEntryPoint = new MobileAuthenticationEntryPoint(); @Getter @Setter private String mobileParameter = SPRING_SECURITY_FORM_MOBILE_KEY; @@ -53,6 +52,10 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing @Getter @Setter private AuthenticationEventPublisher eventPublisher; + @Getter + @Setter + private AuthenticationEntryPoint authenticationEntryPoint; + public MobileAuthenticationFilter() { super(new AntPathRequestMatcher(SecurityConstants.MOBILE_TOKEN_URL, "POST")); diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java index 25a67aaed..78333169a 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java @@ -17,6 +17,8 @@ package com.pig4cloud.pigx.common.security.mobile; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint; import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import lombok.Getter; import lombok.Setter; @@ -39,6 +41,8 @@ import org.springframework.stereotype.Component; @Setter @Component public class MobileSecurityConfigurer extends SecurityConfigurerAdapter { + @Autowired + private ObjectMapper objectMapper; @Autowired private AuthenticationEventPublisher defaultAuthenticationEventPublisher; private AuthenticationSuccessHandler mobileLoginSuccessHandler; @@ -50,6 +54,7 @@ public class MobileSecurityConfigurer extends SecurityConfigurerAdapter { @TableLogic private String delFlag; - /** - * 主键值 - */ - @Override - protected Serializable pkVal() { - return this.id; - } + /** + * 租户ID + */ + private Integer tenantId; + + /** + * 主键值 + */ + @Override + protected Serializable pkVal() { + return this.id; + } } diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java index 526d93777..0bfb7a559 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java @@ -50,7 +50,7 @@ public interface RemoteUserService { , @RequestHeader(SecurityConstants.FROM) String from); /** - * 通过社交账号查询用户、角色信息 + * 通过社交账号或手机号查询用户、角色信息 * * @param inStr appid@code * @return diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java index 20ff9e616..1390dd68d 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java @@ -111,15 +111,14 @@ public class SysSocialDetailsController { } /** - * 通过社交账号查询用户、角色信息 + * 通过社交账号、手机号查询用户、角色信息 * * @param inStr appid@code * @return */ @GetMapping("/info/{inStr}") public R social(@PathVariable String inStr) { - Map result = sysSocialDetailsService.findOpenId(inStr); - return new R<>(sysUserService.findUserInfo(result.get("type"), result.get("openId"))); + return new R<>(sysSocialDetailsService.findUserInfo(inStr)); } /** diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java index ff832f2f0..6d52482d1 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java @@ -30,7 +30,6 @@ import com.pig4cloud.pigx.admin.api.vo.UserVO; import com.pig4cloud.pigx.admin.service.SysUserService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; -import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType; import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.common.core.util.R; import com.pig4cloud.pigx.common.log.annotation.SysLog; @@ -81,7 +80,13 @@ public class UserController { username = SecurityUtils.getUser().getUsername(); } - return new R<>(userService.findUserInfo(EnumLoginType.PWD.getType(), username)); + SysUser condition = new SysUser(); + condition.setUsername(username); + SysUser sysUser = userService.selectOne(new EntityWrapper<>(condition)); + if (sysUser == null) { + return new R<>(); + } + return new R<>(userService.findUserInfo(sysUser)); } /** diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/AbstractLoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/AbstractLoginHandler.java new file mode 100644 index 000000000..68c7cad69 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/AbstractLoginHandler.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import com.pig4cloud.pigx.admin.api.dto.UserInfo; + +/** + * @author lengleng + * @date 2018/11/18 + */ +public abstract class AbstractLoginHandler implements LoginHandler { + + /** + * 处理方法 + * + * @param loginStr 登录参数 + * @return + */ + @Override + public UserInfo handle(String loginStr) { + String identify = identify(loginStr); + return info(identify); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/LoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/LoginHandler.java new file mode 100644 index 000000000..9787000ec --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/LoginHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import com.pig4cloud.pigx.admin.api.dto.UserInfo; + +/** + * @author lengleng + * @date 2018/11/18 + *

+ * 登录处理器 + */ +public interface LoginHandler { + + /** + * 通过用户传入获取唯一标识 + * + * @param loginStr + * @return + */ + String identify(String loginStr); + + /** + * 通过openId 获取用户信息 + * + * @param identify + * @return + */ + UserInfo info(String identify); + + /** + * 处理方法 + * + * @param loginStr 登录参数 + * @return + */ + UserInfo handle(String loginStr); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/SmsLoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/SmsLoginHandler.java new file mode 100644 index 000000000..d073f7dbb --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/SmsLoginHandler.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.service.SysUserService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/11/18 + */ +@Slf4j +@Component("SMS") +@AllArgsConstructor +public class SmsLoginHandler extends AbstractLoginHandler { + private final SysUserService sysUserService; + + /** + * 验证码登录传入为手机号 + * 不用不处理 + * + * @param mobile + * @return + */ + @Override + public String identify(String mobile) { + return mobile; + } + + /** + * 通过mobile 获取用户信息 + * + * @param identify + * @return + */ + @Override + public UserInfo info(String identify) { + SysUser condition = new SysUser(); + condition.setPhone(identify); + SysUser sysUser = sysUserService + .selectOne(new EntityWrapper<>(condition)); + + if (sysUser == null) { + log.info("手机号未注册:{}", identify); + return null; + } + return sysUserService.findUserInfo(sysUser); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatLoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatLoginHandler.java new file mode 100644 index 000000000..55d9364bb --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatLoginHandler.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper; +import com.pig4cloud.pigx.admin.service.SysUserService; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +/** + * @author lengleng + * @date 2018/11/18 + */ +@Slf4j +@Component("WX") +@AllArgsConstructor +public class WeChatLoginHandler extends AbstractLoginHandler { + private final RestTemplate restTemplate; + private final SysUserService sysUserService; + private final SysSocialDetailsMapper sysSocialDetailsMapper; + + /** + * 微信登录传入code + *

+ * 通过code 调用qq 获取唯一标识 + * + * @param code + * @return + */ + @Override + public String identify(String code) { + SysSocialDetails condition = new SysSocialDetails(); + condition.setType(EnumLoginType.WECHAT.getType()); + SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(condition); + + String url = String.format(SecurityConstants.WX_AUTHORIZATION_CODE_URL + , socialDetails.getAppId(), socialDetails.getAppSecret(), code); + String result = restTemplate.getForObject(url, String.class); + log.debug("微信响应报文:{}", result); + + Object obj = JSONUtil.parseObj(result).get("openid"); + return obj.toString(); + } + + /** + * openId 获取用户信息 + * + * @param openId + * @return + */ + @Override + public UserInfo info(String openId) { + SysUser condition = new SysUser(); + condition.setWxOpenid(openId); + SysUser sysUser = sysUserService + .selectOne(new EntityWrapper<>(condition)); + + if (sysUser == null) { + log.info("微信未绑定:{}", openId); + return null; + } + return sysUserService.findUserInfo(sysUser); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java index f6b1d8a67..d5f10a04f 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java @@ -18,10 +18,9 @@ package com.pig4cloud.pigx.admin.service; import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; -import java.util.Map; - /** * 系统社交登录账号表 * @@ -40,11 +39,11 @@ public interface SysSocialDetailsService extends IService { Boolean bindSocial(String state, String code); /** - * 通过客户端信息查询openId + * 根据入参查询用户信息 * - * @param inStr appid @ code + * @param inStr * @return */ - Map findOpenId(String inStr); + UserInfo findUserInfo(String inStr); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java index 1f0b84eff..f8110da01 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java @@ -38,11 +38,10 @@ public interface SysUserService extends IService { /** * 查询用户信息 * - * @param type 类型 - * @param username 用户名 + * @param sysUser 用户 * @return userInfo */ - UserInfo findUserInfo(String type, String username); + UserInfo findUserInfo(SysUser sysUser); /** * 分页查询用户信息(含有角色信息) diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/MobileServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/MobileServiceImpl.java index c3bb1775a..374b0b82f 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/MobileServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/MobileServiceImpl.java @@ -25,6 +25,7 @@ import com.pig4cloud.pigx.admin.mapper.SysUserMapper; import com.pig4cloud.pigx.admin.service.MobileService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType; import com.pig4cloud.pigx.common.core.util.R; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -75,8 +76,9 @@ public class MobileServiceImpl implements MobileService { String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE)); log.debug("手机号生成验证码成功:{},{}", mobile, code); - redisTemplate.opsForValue().set(CommonConstant.DEFAULT_CODE_KEY + mobile, code - , SecurityConstants.CODE_TIME, TimeUnit.SECONDS); + redisTemplate.opsForValue().set( + CommonConstant.DEFAULT_CODE_KEY + EnumLoginType.SMS.getType() + "@" + mobile + , code, SecurityConstants.CODE_TIME, TimeUnit.SECONDS); return new R<>(Boolean.TRUE, code); } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java index 67fec8072..e845c412d 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java @@ -19,6 +19,7 @@ package com.pig4cloud.pigx.admin.service.impl; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.pig4cloud.pigx.admin.api.entity.SysDept; @@ -62,7 +63,9 @@ public class SysDeptRelationServiceImpl extends ServiceImpl impl @Override @Transactional(rollbackFor = Exception.class) public Boolean deleteDeptById(Integer id) { - this.deleteById(id); + //级联删除部门 + SysDeptRelation condition = new SysDeptRelation(); + condition.setAncestor(id); + List idList = sysDeptRelationService + .selectList(new EntityWrapper<>(condition)) + .stream() + .map(SysDeptRelation::getDescendant) + .collect(Collectors.toList()); + + if (CollUtil.isNotEmpty(idList)) { + this.deleteBatchIds(idList); + } + + //删除部门级联关系 sysDeptRelationService.deleteAllDeptRealtion(id); return Boolean.TRUE; } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java index da6309221..9b6fac869 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java @@ -19,8 +19,10 @@ package com.pig4cloud.pigx.admin.service.impl; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.handler.LoginHandler; import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper; import com.pig4cloud.pigx.admin.mapper.SysUserMapper; import com.pig4cloud.pigx.admin.service.SysSocialDetailsService; @@ -44,22 +46,11 @@ import java.util.Map; @AllArgsConstructor @Service("sysSocialDetailsService") public class SysSocialDetailsServiceImpl extends ServiceImpl implements SysSocialDetailsService { + private final Map loginHandlerMap; private final CacheManager cacheManager; private final RestTemplate restTemplate; private final SysUserMapper sysUserMapper; - /** - * 通过客户端信息查询openId - * - * @param inStr appid @ code - * @return - */ - @Override - public Map findOpenId(String inStr) { - String[] inStrs = inStr.split("@"); - return getOpenId(inStrs[0], inStrs[1]); - } - /** * 绑定社交账号 * @@ -80,6 +71,20 @@ public class SysSocialDetailsServiceImpl extends ServiceImpl impl private final SysDeptRelationService sysDeptRelationService; /** - * 通过用户名查用户的全部信息 + * 通过查用户的全部信息 * - * @param username 用户名 + * @param sysUser 用户 * @return */ @Override - @Cacheable(value = "user_details", key = "#username", unless = "#result == null") - public UserInfo findUserInfo(String type, String username) { - SysUser condition = new SysUser(); - if (EnumLoginType.PWD.getType().equals(type)) { - condition.setUsername(username); - } else if (EnumLoginType.WECHAT.getType().equals(type)) { - condition.setWxOpenid(username); - } else { - condition.setQqOpenid(username); - } - SysUser sysUser = this.selectOne(new EntityWrapper<>(condition)); + @Cacheable(value = "user_details", key = "#sysUser.username", unless = "#result == null") + public UserInfo findUserInfo(SysUser sysUser) { if (sysUser == null) { return null; }