mirror of
https://github.com/abcv7/sfbx-cloud.git
synced 2026-08-16 11:47:00 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>sfbx-cloud</artifactId>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<!--权限处理模块-->
|
||||
<artifactId>sfbx-security</artifactId>
|
||||
<name>sfbx-security</name>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<!--权限处理:接口模块-->
|
||||
<module>security-interface</module>
|
||||
<!--权限处理:认证模块-->
|
||||
<module>security-oauth</module>
|
||||
<!--权限处理:web模块-->
|
||||
<module>security-web</module>
|
||||
</modules>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>sfbx-security</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<!--权限处理:接口模块-->
|
||||
<artifactId>security-interface</artifactId>
|
||||
<name>security-interface</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-feign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.itheima.sfbx.security.config;
|
||||
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @ClassName DictFenginConfig.java
|
||||
* @Description feign的最优化配置
|
||||
*/
|
||||
@EnableFeignClients(basePackages = "com.itheima.sfbx.security.feign")
|
||||
@Configuration
|
||||
public class SecurityFeignConfig {
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.AuthChannelVO;
|
||||
import com.itheima.sfbx.security.hystrix.UserHtstrix;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @ClassName AuthChannelFeign.java
|
||||
* @Description TODO
|
||||
*/
|
||||
@FeignClient(value = "security-web", fallback = UserHtstrix.class)
|
||||
public interface AuthChannelFeign {
|
||||
|
||||
/**
|
||||
* @Description 按企业编号和配置类型查询对应的企业信息
|
||||
* @param companyNo 企业编号
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("auth-channel-feign/find-auth-channel/{companyNo}/{channelLabel}")
|
||||
public AuthChannelVO findAuthChannelByCompanyNoAndChannelLabel(@PathVariable("companyNo") String companyNo,
|
||||
@PathVariable("channelLabel") String channelLabel);
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.security.hystrix.UserHtstrix;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:用户权限适配服务接口定义
|
||||
*/
|
||||
@FeignClient(value = "security-web", fallback = UserHtstrix.class)
|
||||
public interface CompanyFeign {
|
||||
|
||||
/***
|
||||
* @description 按企业号查询公司
|
||||
* @param companyNo 企业号
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("company-feign/find-company/{companyNo}")
|
||||
CompanyVO findCompanyByNo(@PathVariable("companyNo") String companyNo);
|
||||
|
||||
/***
|
||||
* @description 按多个企业号查询公司
|
||||
* @param companyNos 企业号
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("company-feign/find-company")
|
||||
List<CompanyVO> findCompanyByNos(@RequestBody List<String> companyNos);
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CustomerVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.hystrix.UserHtstrix;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @Description:用户权限适配服务接口定义
|
||||
*/
|
||||
@FeignClient(value = "security-web",fallback = UserHtstrix.class)
|
||||
public interface CustomerFeign {
|
||||
|
||||
/**
|
||||
* @Description 按用客户查找用户
|
||||
* @param username 登录名
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("customer-feign/username-login/{username}/{company}")
|
||||
UserVO usernameLogin(@PathVariable("username") String username,@PathVariable("company") String company);
|
||||
|
||||
/**
|
||||
* @Description 按用户手机查找用户
|
||||
* @param mobile 登录名
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("customer-feign/mobile-login/{mobile}/{company}")
|
||||
UserVO mobileLogin(@PathVariable("mobile") String mobile,@PathVariable("company") String company);
|
||||
|
||||
/**
|
||||
* @Description 按微信openId查找客户
|
||||
* @param openId 登录名
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("customer-feign/wechat-login/{openId}/{company}")
|
||||
UserVO wechatLogin(@PathVariable("openId") String openId,@PathVariable("company") String company);
|
||||
|
||||
/**
|
||||
* @Description 注册客户
|
||||
* @param customerVO 客户信息
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("customer-feign/register-user")
|
||||
UserVO registerUser(@RequestBody CustomerVO customerVO);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("reset-passwords/{customerId}")
|
||||
Boolean resetPasswords(@PathVariable("customerId") String customerId);
|
||||
|
||||
|
||||
/**
|
||||
* 修改用户真实姓名
|
||||
* @param userId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("customer-feign/update-real-name")
|
||||
Boolean updateRealName(@RequestParam("userId") String userId,@RequestParam("name") String name);
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.*;
|
||||
import com.itheima.sfbx.security.hystrix.UserHtstrix;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:用户权限适配服务接口定义
|
||||
*/
|
||||
@FeignClient(value = "security-web",fallback = UserHtstrix.class)
|
||||
public interface UserFeign {
|
||||
|
||||
/**
|
||||
* @Description 按用户名查找用户
|
||||
* @param username 登录名
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("user-feign/username-login/{username}/{company}")
|
||||
UserVO usernameLogin(@PathVariable("username") String username,@PathVariable("company") String company);
|
||||
|
||||
/**
|
||||
* @Description 按用户手机查找用户
|
||||
* @param mobile 登录名
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("user-feign/mobile-login/{mobile}/{company}")
|
||||
UserVO mobileLogin(@PathVariable("mobile") String mobile,@PathVariable("company") String company);
|
||||
|
||||
/**
|
||||
* @Description 按微信openId查找客户
|
||||
* @param openId 登录名
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("user-feign/wechat-login/{openId}/{company}")
|
||||
UserVO wechatLogin(@PathVariable("openId") String openId,@PathVariable("company") String company);
|
||||
/**
|
||||
* @Description 查找用户所有角色
|
||||
* @param userId 用户Id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("user-feign/find-role-user/{userId}")
|
||||
List<RoleVO> findRoleByUserId(@PathVariable("userId") Long userId);
|
||||
|
||||
/**
|
||||
* @Description 查询用户有资源
|
||||
* @param userId 用户Id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("user-feign/find-resoure-user/{userId}")
|
||||
List<ResourceVO> findResourceByUserId(@PathVariable("userId") Long userId);
|
||||
|
||||
/***
|
||||
* @description 查询用户数据权限
|
||||
* @param queryDataSecurityVO 查询对象Vo
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "user-feign/user-data-security")
|
||||
DataSecurityVO userDataSecurity(@RequestBody QueryDataSecurityVO queryDataSecurityVO);
|
||||
|
||||
|
||||
/***
|
||||
* @description 查询用户数据权限
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "user-feign/find-user-by-id")
|
||||
UserVO findUserById(@RequestParam("userId") Long userId);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.itheima.sfbx.security.hystrix;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.AuthChannelVO;
|
||||
import com.itheima.sfbx.security.feign.AuthChannelFeign;
|
||||
import com.itheima.sfbx.security.feign.CompanyFeign;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @ClassName AuthChannelFeign.java
|
||||
* @Description TODO
|
||||
*/
|
||||
public class AuthChannelHystrix implements AuthChannelFeign {
|
||||
|
||||
|
||||
@Override
|
||||
public AuthChannelVO findAuthChannelByCompanyNoAndChannelLabel(String companyNo, String channelLabel) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.itheima.sfbx.security.hystrix;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.feign.CompanyFeign;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName CompanyFeign.java
|
||||
* @Description CompanyFeign的Htstrix
|
||||
*/
|
||||
@Component
|
||||
public class CompanyHtstrix implements CompanyFeign {
|
||||
|
||||
|
||||
@Override
|
||||
public CompanyVO findCompanyByNo(String companyNo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompanyVO> findCompanyByNos(List<String> companyNos) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.itheima.sfbx.security.hystrix;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CustomerVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.feign.CustomerFeign;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName CustomerFeign.java
|
||||
* @Description CustomerFeign的Htstrix
|
||||
*/
|
||||
@Component
|
||||
public class CustomerHtstrix implements CustomerFeign {
|
||||
|
||||
|
||||
@Override
|
||||
public UserVO usernameLogin(String username, String company) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO mobileLogin(String mobile, String company) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO wechatLogin(String openId, String company) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO registerUser(CustomerVO customerVO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean resetPasswords(String customerId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateRealName(String userId, String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.itheima.sfbx.security.hystrix;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.*;
|
||||
import com.itheima.sfbx.security.feign.UserFeign;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName UserHtstrix.java
|
||||
* @Description UserFeign的Htstrix
|
||||
*/
|
||||
@Component
|
||||
public class UserHtstrix implements UserFeign {
|
||||
|
||||
|
||||
@Override
|
||||
public UserVO usernameLogin(String username, String company) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO mobileLogin(String mobile, String company) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO wechatLogin(String openId, String company) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleVO> findRoleByUserId(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceVO> findResourceByUserId(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSecurityVO userDataSecurity(QueryDataSecurityVO queryDataSecurityVO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO findUserById(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
FROM openjdk:11-jdk
|
||||
LABEL maintainer="研究院研发组 <research@itcast.cn>"
|
||||
|
||||
# 时区修改为东八区
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
WORKDIR /security-oauth
|
||||
ARG PACKAGE_PATH=./target/security-oauth.jar
|
||||
ADD ${PACKAGE_PATH:-./} security-oauth.jar
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENV JAVA_OPTS="\
|
||||
-server \
|
||||
-Xms256m \
|
||||
-Xmx512m \
|
||||
-XX:MetaspaceSize=256m \
|
||||
-XX:MaxMetaspaceSize=512m\
|
||||
-Dspring.profiles.active=test"
|
||||
ENTRYPOINT ["sh","-c","java -Djava.security.egd=file:/dev/./urandom -jar $JAVA_OPTS security-oauth.jar"]
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>sfbx-security</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<!--权限处理:认证模块-->
|
||||
<artifactId>security-oauth</artifactId>
|
||||
<name>security-oauth</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-mybatis-plus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security.oauth.boot</groupId>
|
||||
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-oauth2-jose</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>security-interface</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.jks</include>
|
||||
<include>**/*.yml</include>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.yaml</include>
|
||||
<include>**/*.txt</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>security-oauth</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.itheima.sfbx.security;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
/**
|
||||
* 前后端都需要使用到的登录认证中心
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "com.itheima.sfbx")
|
||||
@EnableDiscoveryClient
|
||||
public class SecurityOauthStart {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SecurityOauthStart.class);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.itheima.sfbx.security.adepter;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName LoginAuthAdepter.java
|
||||
* @Description 登录适配接口
|
||||
*/
|
||||
public interface LoginAuthAdepter {
|
||||
|
||||
/***
|
||||
* @description 适配路由
|
||||
* @param principal 认证主体
|
||||
* @param parameters 登录参数
|
||||
* @return
|
||||
*/
|
||||
UserVO adepterRoutes(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException;
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.itheima.sfbx.security.adepter.impl;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CompanyCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.RegisterBeanHandler;
|
||||
import com.itheima.sfbx.security.handler.LoginAuthHandler;
|
||||
import com.itheima.sfbx.security.adepter.LoginAuthAdepter;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.codec.JsonJacksonCodec;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName LoginAuthAdepterImpl.java
|
||||
* @Description 登录适配器
|
||||
*/
|
||||
@Component
|
||||
public class LoginAuthAdepterImpl implements LoginAuthAdepter {
|
||||
|
||||
@Autowired
|
||||
RegisterBeanHandler registerBeanHandler;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@Autowired
|
||||
HttpServletRequest httpServletRequest;
|
||||
|
||||
@Override
|
||||
public UserVO adepterRoutes(Principal principal, Map<String, String> parameters)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
//获得域名
|
||||
String host = httpServletRequest.getHeaders("x-forwarded-host").nextElement().split(",")[0].split(":")[0];
|
||||
String key = CompanyCacheConstant.WEBSITE+host;
|
||||
//域名校验
|
||||
RBucket<CompanyVO> bucket = redissonClient.getBucket(key);
|
||||
CompanyVO companyVO = bucket.get();
|
||||
if (EmptyUtil.isNullOrEmpty(companyVO)){
|
||||
throw new ProjectException(AuthEnum.HSOT_FAIL);
|
||||
}
|
||||
//适配登录方式
|
||||
String loginType = parameters.get(OauthConstant.LOGIN_TYPE_KEY);
|
||||
if (EmptyUtil.isNullOrEmpty(loginType)){
|
||||
throw new ProjectException(AuthEnum.LOGIN_FAIL);
|
||||
}
|
||||
String loginBeanName = OauthConstant.loginBeanNames.get(loginType.split("-")[1]);
|
||||
LoginAuthHandler loginAuthHandler = registerBeanHandler.getBean(loginBeanName,LoginAuthHandler.class);
|
||||
return loginAuthHandler.loginHandler(principal,parameters,loginBeanName,companyVO);
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package com.itheima.sfbx.security.base;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DataSecurityVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptPostUserVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @ClassName AuthUser.java
|
||||
* @Description 自定认证用户
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class UserAuth implements UserDetails {
|
||||
|
||||
private String id;
|
||||
|
||||
//"用户账号
|
||||
private String username;
|
||||
|
||||
//"密码
|
||||
private String password;
|
||||
|
||||
//权限内置
|
||||
private Collection<SimpleGrantedAuthority> authorities;
|
||||
|
||||
//"用户昵称
|
||||
private String nickName;
|
||||
|
||||
//"用户邮箱
|
||||
private String email;
|
||||
|
||||
//"真实姓名
|
||||
private String realName;
|
||||
|
||||
//"手机号码
|
||||
private String mobile;
|
||||
|
||||
//"用户性别(0男 1女 2未知)
|
||||
private String sex;
|
||||
|
||||
//"创建者
|
||||
private Long createBy;
|
||||
|
||||
//"创建时间
|
||||
private LocalDateTime createTime;
|
||||
|
||||
//"更新者
|
||||
private Long updateBy;
|
||||
|
||||
//"更新时间
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
//"备注
|
||||
private String remark;
|
||||
|
||||
//"三方openId
|
||||
private String openId;
|
||||
|
||||
//"查询用户:所属单位职位
|
||||
private Set<DeptPostUserVO> deptPostUserVOset;
|
||||
|
||||
//"构建令牌:用户角色标识
|
||||
private Set<String> roleLabels;
|
||||
|
||||
//"构建令牌:用户权限路径
|
||||
private Set<String> resourceRequestPaths;
|
||||
|
||||
//"部门编号【当前】
|
||||
private String deptNo;
|
||||
|
||||
//"职位编号【当前】
|
||||
private String postNo;
|
||||
|
||||
private String clientId;
|
||||
|
||||
private DataSecurityVO dataSecurityVO;
|
||||
|
||||
private Boolean onlyAuthenticate ;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
public UserAuth(UserVO userVO) {
|
||||
this.setId(userVO.getId().toString());
|
||||
this.setUsername(userVO.getUsername());
|
||||
this.setPassword(userVO.getPassword());
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getResourceRequestPaths())) {
|
||||
authorities = new ArrayList<>();
|
||||
userVO.getResourceRequestPaths().forEach(resourceRequestPath -> authorities.add(new SimpleGrantedAuthority(resourceRequestPath)));
|
||||
}
|
||||
this.setNickName(userVO.getNickName());
|
||||
this.setEmail(userVO.getEmail());
|
||||
this.setRealName(userVO.getRealName());
|
||||
this.setMobile(userVO.getMobile());
|
||||
this.setSex(userVO.getSex());
|
||||
this.setCreateTime(userVO.getCreateTime());
|
||||
this.setCreateBy(userVO.getCreateBy());
|
||||
this.setUpdateTime(userVO.getUpdateTime());
|
||||
this.setUpdateBy(userVO.getUpdateBy());
|
||||
this.setRemark(userVO.getRemark());
|
||||
this.setOpenId(userVO.getOpenId());
|
||||
this.setDeptPostUserVOset(userVO.getDeptPostUserVOs());
|
||||
this.setRoleLabels(userVO.getRoleLabels());
|
||||
this.setResourceRequestPaths(userVO.getResourceRequestPaths());
|
||||
this.setDeptNo(userVO.getDeptNo());
|
||||
this.setPostNo(userVO.getPostNo());
|
||||
this.setClientId(userVO.getClientId());
|
||||
this.setDataSecurityVO(userVO.getDataSecurityVO());
|
||||
this.setOnlyAuthenticate(userVO.getOnlyAuthenticate());
|
||||
this.setCompanyNo(userVO.getCompanyNo());
|
||||
this.setRealName(userVO.getRealName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return this.authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
package com.itheima.sfbx.security.config;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthEnum;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
|
||||
import com.itheima.sfbx.security.base.UserAuth;
|
||||
import com.itheima.sfbx.security.details.JdbcClientDetailsServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
|
||||
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
|
||||
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
|
||||
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
||||
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
|
||||
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
||||
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
|
||||
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.security.KeyPair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 授权服务配置
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAuthorizationServer
|
||||
@EnableConfigurationProperties(SecurityConfigProperties.class)
|
||||
public class Oauth2ServerConfig extends AuthorizationServerConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
@Autowired
|
||||
private UserDetailsService oauth2UserDetailsService;
|
||||
|
||||
@Autowired
|
||||
SecurityConfigProperties securityConfigProperties;
|
||||
|
||||
/***
|
||||
* @description 客户端信息到数据库中
|
||||
* @param clients 客户端配置形象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
|
||||
clients.withClientDetails(jdbcClientDetailsService());
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 客户端信息JDBC管理
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public JdbcClientDetailsService jdbcClientDetailsService(){
|
||||
JdbcClientDetailsService jdbcClientDetailsService = new JdbcClientDetailsServiceImpl(dataSource);
|
||||
jdbcClientDetailsService.setFindClientDetailsSql(OauthConstant.FIND_CLIENT_DETAILS_SQL);
|
||||
jdbcClientDetailsService.setSelectClientDetailsSql(OauthConstant.SELECT_CLIENT_DETAILS_SQL);
|
||||
return jdbcClientDetailsService;
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 授权服务器端点的非安全特性如令牌存储、令牌自定义、用户批准和授权类型
|
||||
* @param endpoints 认证服务令牌站点
|
||||
*/
|
||||
@Override
|
||||
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
|
||||
endpoints
|
||||
.authenticationManager(authenticationManager)//配置认证管理器
|
||||
.userDetailsService(oauth2UserDetailsService)//配置oauth2User查询明细
|
||||
.accessTokenConverter(jwtAccessTokenConverter())//配置令牌转换器
|
||||
.tokenServices(jwtTokenService())//配置令牌服务(token services)
|
||||
.reuseRefreshTokens(true);//是否沿用刷新令牌直到过期,这里每次刷新直接后使用新的刷新令牌下次刷新
|
||||
}
|
||||
|
||||
/**
|
||||
* 令牌服务:持久化令牌相关服务
|
||||
*/
|
||||
@Bean
|
||||
public DefaultTokenServices jwtTokenService() {
|
||||
DefaultTokenServices service=new DefaultTokenServices();
|
||||
//存储策略
|
||||
JwtTokenStore jwtTokenStore = new JwtTokenStore(jwtAccessTokenConverter());
|
||||
service.setTokenStore(jwtTokenStore);//令牌存储的持久性策略。
|
||||
service.setClientDetailsService(jdbcClientDetailsService());//指定客戶端明细信息
|
||||
service.setSupportRefreshToken(true);//是否支持刷新令牌
|
||||
service.setTokenEnhancer(tokenEnhancerChain());//在将新令牌保存到令牌存储区之前,将应用于新令牌的访问令牌增强器。
|
||||
service.setAccessTokenValiditySeconds(securityConfigProperties.getAccessTokenValiditySeconds()); // 令牌默认有效期2小时
|
||||
service.setRefreshTokenValiditySeconds(securityConfigProperties.getRefreshTokenValiditySeconds()); // 刷新令牌默认有效期3天
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* @description 复合令牌增强器:把构建的JWT令牌及增强属性填充到OAuth2AccessToken中
|
||||
*/
|
||||
@Bean
|
||||
public TokenEnhancerChain tokenEnhancerChain(){
|
||||
//token令牌增强者List
|
||||
List<TokenEnhancer> tokenEnhancers = new ArrayList<>();
|
||||
//扩展JWT内容增强,可携带更多对象信息:企业号、门店ID等
|
||||
tokenEnhancers.add(tokenEnhancer());
|
||||
//使用非对称加密算法对token签名
|
||||
tokenEnhancers.add(jwtAccessTokenConverter());
|
||||
//构建增强链:填入token令牌增强者List
|
||||
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
|
||||
tokenEnhancerChain.setTokenEnhancers(tokenEnhancers);
|
||||
return tokenEnhancerChain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用非对称加密算法对token签名
|
||||
*/
|
||||
@Bean
|
||||
public JwtAccessTokenConverter jwtAccessTokenConverter() {
|
||||
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
|
||||
//从classpath下的密钥库中获取密钥对(公钥+私钥)
|
||||
converter.setKeyPair(keyPair());
|
||||
return converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从classpath下的密钥库中获取密钥对(公钥+私钥)
|
||||
*/
|
||||
@Bean
|
||||
public KeyPair keyPair() {
|
||||
KeyStoreKeyFactory factory = new KeyStoreKeyFactory(
|
||||
new ClassPathResource("itheima.jks"), "shuwenqi".toCharArray());
|
||||
KeyPair keyPair = factory.getKeyPair(
|
||||
"itheima", "shuwenqi".toCharArray());
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* JWT内容增强
|
||||
*/
|
||||
@Bean
|
||||
public TokenEnhancer tokenEnhancer() {
|
||||
return (accessToken, authentication) -> {
|
||||
Map<String, Object> map = new HashMap<>(10);
|
||||
Object principal = authentication.getUserAuthentication().getPrincipal();
|
||||
if (principal instanceof UserAuth){
|
||||
UserAuth userAuth = (UserAuth)principal ;
|
||||
map.put(OauthConstant.USER_ID_KEY, userAuth.getId());
|
||||
map.put(OauthConstant.REAL_NAME_KEY, userAuth.getRealName());
|
||||
map.put(OauthConstant.CLIENT_ID_KEY, userAuth.getClientId());
|
||||
map.put(OauthConstant.USER_NAME_KEY,userAuth.getUsername());
|
||||
map.put(OauthConstant.SEX_KEY,userAuth.getSex());
|
||||
map.put(OauthConstant.RESOURCS_KEY,userAuth.getResourceRequestPaths());
|
||||
map.put(OauthConstant.ROLES_KEY,userAuth.getRoleLabels());
|
||||
map.put(OauthConstant.OPEN_ID_KEY,userAuth.getOpenId());
|
||||
map.put(OauthConstant.DEPT_NO_KEY,userAuth.getDeptNo());
|
||||
map.put(OauthConstant.POST_NO_KEY,userAuth.getPostNo());
|
||||
map.put(OauthConstant.MOBILE_KEY,userAuth.getMobile());
|
||||
map.put(OauthConstant.ONLY_AUTHENTICATE_KEY,userAuth.getOnlyAuthenticate());
|
||||
map.put(OauthConstant.DATA_SECURITY_KEY,userAuth.getDataSecurityVO());
|
||||
map.put(OauthConstant.COMPANY_NO_KEY,userAuth.getCompanyNo());
|
||||
map.put(OauthConstant.EXPIRES_IN_KEY,securityConfigProperties.getAccessTokenValiditySeconds());
|
||||
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(map);
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
};
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 认证异常处理配置
|
||||
* @return:
|
||||
*/
|
||||
@Override
|
||||
public void configure(AuthorizationServerSecurityConfigurer security) {
|
||||
security.authenticationEntryPoint(authenticationEntryPoint())//异常处理
|
||||
.tokenKeyAccess("permitAll()")
|
||||
.checkTokenAccess("permitAll()")
|
||||
.allowFormAuthenticationForClients();
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* @description 自定义认证异常响应数据
|
||||
* @return: org.springframework.security.web.AuthenticationEntryPoint
|
||||
*/
|
||||
@Bean
|
||||
public AuthenticationEntryPoint authenticationEntryPoint() {
|
||||
return (request, response, e) -> {
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
ResponseResult<Boolean> responseWrap = ResponseResultBuild.build(AuthEnum.NEED_LOGIN, false);
|
||||
String result = JSONObject.toJSONString(responseWrap);
|
||||
response.getWriter().print(result);
|
||||
response.getWriter().flush();
|
||||
};
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.itheima.sfbx.security.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @ClassName RestTemplateConfig.java
|
||||
* @Description 远程调用
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
//请求客户端
|
||||
@Bean
|
||||
public RestTemplate restTemplate(){
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.itheima.sfbx.security.config;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
* @ClassName ReactiveSecurityConfig.java
|
||||
* @Description 支持web的权限配置
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableConfigurationProperties(SecurityConfigProperties.class)
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
SecurityConfigProperties securityConfigProperties;
|
||||
|
||||
@Autowired
|
||||
UserDetailsService oauth2UserDetailsService;
|
||||
|
||||
/**
|
||||
* BCrypt密码编码
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public BCryptPasswordEncoder bcryptPasswordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义身份认证逻辑
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
//指定用户明细查询及密码处理者
|
||||
auth.userDetailsService(oauth2UserDetailsService).passwordEncoder(bcryptPasswordEncoder());
|
||||
super.configure(auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证管理器
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Override
|
||||
public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||
//使用默认的认证管理器
|
||||
return super.authenticationManagerBean();
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 过滤器链定义
|
||||
* @param http
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.cors()
|
||||
.and()
|
||||
.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()//站点请求处理
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers(securityConfigProperties.getIgnoreUrl()
|
||||
.toArray(new String[securityConfigProperties.getIgnoreUrl().size()]))//忽略配置
|
||||
.permitAll()
|
||||
.anyRequest().authenticated()//其他请求都需要校验
|
||||
.and()
|
||||
.csrf().disable();
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.itheima.sfbx.security.details;
|
||||
|
||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/***
|
||||
* @description 对JdbcClientDetailsService的增强
|
||||
*/
|
||||
public class JdbcClientDetailsServiceImpl extends JdbcClientDetailsService {
|
||||
|
||||
//使用数据库中配置进行对象构建
|
||||
public JdbcClientDetailsServiceImpl(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 加载指定客户端配置信息
|
||||
* @param clientId
|
||||
* @return
|
||||
* @return: org.springframework.security.oauth2.provider.ClientDetails
|
||||
*/
|
||||
@Override
|
||||
public ClientDetails loadClientByClientId(String clientId) {
|
||||
return super.loadClientByClientId(clientId);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.itheima.sfbx.security.details;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.*;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.RegisterBeanHandler;
|
||||
import com.itheima.sfbx.security.feign.CustomerFeign;
|
||||
import com.itheima.sfbx.security.feign.UserFeign;
|
||||
import com.itheima.sfbx.security.handler.LoginAuthHandler;
|
||||
import com.itheima.sfbx.security.base.UserAuth;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.DisabledException;
|
||||
import org.springframework.security.authentication.LockedException;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @ClassName ReactiveUserDetailsServiceImpl.java
|
||||
* @Description 支持flum的身份类实现ReactiveUserDetailsService接口
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("oauth2UserDetailsService")
|
||||
public class Oauth2UserDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
UserFeign userFeign;
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
CustomerFeign customerFeign;
|
||||
|
||||
@Autowired
|
||||
RegisterBeanHandler registerBeanHandler;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String principal) throws UsernameNotFoundException {
|
||||
UsernameVO usernameVO = JSONObject.parseObject(principal,UsernameVO.class);
|
||||
//查询用户明细
|
||||
LoginAuthHandler loginAuthHandler = registerBeanHandler
|
||||
.getBean(usernameVO.getLoginBeanName(),LoginAuthHandler.class);
|
||||
UserVO userVO = loginAuthHandler.findUserDetail(usernameVO.getLoginType(),
|
||||
usernameVO.getUsername(),usernameVO.getCompanyNo());
|
||||
//UserAuth构建
|
||||
if (EmptyUtil.isNullOrEmpty(userVO)) {
|
||||
throw new DisabledException("无效的账号");
|
||||
}
|
||||
if (SuperConstant.DATA_STATE_1.equals(userVO.getDataState())) {
|
||||
throw new LockedException("账户被禁用");
|
||||
}
|
||||
//客户端
|
||||
userVO.setClientId(usernameVO.getClientId());
|
||||
//资源
|
||||
List<ResourceVO> resourceVOs = userFeign.findResourceByUserId(userVO.getId());
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVOs)){
|
||||
Set<String> resources = resourceVOs.stream().map(ResourceVO::getRequestPath).collect(Collectors.toSet());
|
||||
userVO.setResourceRequestPaths(resources);
|
||||
}
|
||||
//角色
|
||||
List<RoleVO> roleVOs = userFeign.findRoleByUserId(userVO.getId());
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVOs)){
|
||||
Set<String> roleLabel = roleVOs.stream().map(RoleVO::getLabel).collect(Collectors.toSet());
|
||||
userVO.setRoleLabels(roleLabel);
|
||||
}
|
||||
//数据权限
|
||||
QueryDataSecurityVO queryDataSecurityVO = QueryDataSecurityVO.builder()
|
||||
.userId(userVO.getId())
|
||||
.roleVOs(roleVOs)
|
||||
.build();
|
||||
DataSecurityVO dataSecurityVO = userFeign.userDataSecurity(queryDataSecurityVO);
|
||||
if (!EmptyUtil.isNullOrEmpty(dataSecurityVO)){
|
||||
userVO.setDataSecurityVO(dataSecurityVO);
|
||||
}
|
||||
|
||||
return new UserAuth(userVO);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.itheima.sfbx.security.handler;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
|
||||
/**
|
||||
* @ClassName CacheTokenHandler.java
|
||||
* @Description 缓存token处理器
|
||||
*/
|
||||
public interface CacheTokenHandler {
|
||||
|
||||
|
||||
/***
|
||||
* @description 缓存token
|
||||
* @param oAuth2AccessToken
|
||||
* @return
|
||||
*/
|
||||
UserVO cacheToken(OAuth2AccessToken oAuth2AccessToken);
|
||||
|
||||
/***
|
||||
* @description 缓存token
|
||||
* @param userVO 用户
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteToken(UserVO userVO);
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.itheima.sfbx.security.handler;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName LoginAdapter.java
|
||||
* @Description 登陆处理器接口
|
||||
*/
|
||||
public interface LoginAuthHandler {
|
||||
|
||||
/***
|
||||
* @description 登录处理
|
||||
* @param parameters 登录参数
|
||||
* @return
|
||||
*/
|
||||
UserVO loginHandler(Principal principal, Map<String, String> parameters,
|
||||
String loginBeanName, CompanyVO companyVO)
|
||||
throws HttpRequestMethodNotSupportedException;
|
||||
|
||||
/***
|
||||
* @description 用户信息查询
|
||||
* @param loginType 登录类型
|
||||
* @param username 账号信息:用户名或者手机号或者openId
|
||||
* @param companyNo 企业号
|
||||
* @return: com.itheima.easy.vo.security.UserVO
|
||||
*/
|
||||
UserVO findUserDetail(String loginType,String username,String companyNo);
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.itheima.sfbx.security.handler;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
|
||||
/**
|
||||
* @ClassName LogoutHandler.java
|
||||
* @Description 退出处理器
|
||||
*/
|
||||
public interface LogoutHandler {
|
||||
|
||||
/***
|
||||
* @description 退出
|
||||
* @param userVO 退出用户
|
||||
* @return
|
||||
*/
|
||||
Boolean logout(UserVO userVO);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.itheima.sfbx.security.handler;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName RefreshTokenHandler.java
|
||||
* @Description 刷新令牌处理
|
||||
*/
|
||||
public interface RefreshTokenHandler {
|
||||
|
||||
/***
|
||||
* @description 刷新令牌
|
||||
* @return
|
||||
*/
|
||||
public UserVO refreshToken(Principal principal, Map<String, String> parameters);
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.itheima.sfbx.security.handler.impl;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.security.handler.CacheTokenHandler;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DataSecurityVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName CacheTokenHandlerImpl.java
|
||||
* @Description Token缓存处理
|
||||
*/
|
||||
@Component
|
||||
@EnableConfigurationProperties(SecurityConfigProperties.class)
|
||||
public class CacheTokenHandlerImpl implements CacheTokenHandler {
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@Autowired
|
||||
SecurityConfigProperties securityConfigProperties;
|
||||
|
||||
@Override
|
||||
public UserVO cacheToken(OAuth2AccessToken oAuth2AccessToken){
|
||||
//登录成功后获得oAuth2AccessToken中增强信息
|
||||
Long id = Long.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.USER_ID_KEY).toString());
|
||||
String userToken =String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.JTI_KEY));
|
||||
String mobile =String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.MOBILE_KEY));
|
||||
String openId =String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.OPEN_ID_KEY));
|
||||
Set<String> resources = (Set<String>) oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.RESOURCS_KEY);
|
||||
Set<String> roles = (Set<String>) oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.ROLES_KEY);
|
||||
String username = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.USER_NAME_KEY));
|
||||
String sex = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.SEX_KEY));
|
||||
String clientId = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.CLIENT_ID_KEY));
|
||||
String realName = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.REAL_NAME_KEY));
|
||||
String deptNo = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.DEPT_NO_KEY));
|
||||
String postNo = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.POST_NO_KEY));
|
||||
Boolean onlyAuthenticate = (Boolean) oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.ONLY_AUTHENTICATE_KEY);
|
||||
DataSecurityVO dataSecurityVO = (DataSecurityVO) oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.DATA_SECURITY_KEY);
|
||||
String companyNo = String.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.COMPANY_NO_KEY));
|
||||
//设置accessToken到redis,获得时使用userToken获取
|
||||
String accessToken = oAuth2AccessToken.getValue();
|
||||
RBucket<String> accessTokenBucket = redissonClient.getBucket(OauthCacheConstant.ACCESS_TOKEN + userToken);
|
||||
long accessTokenExpiresIn = Long.valueOf(oAuth2AccessToken.getAdditionalInformation().get(OauthConstant.EXPIRES_IN_KEY).toString());
|
||||
accessTokenBucket.set(accessToken,accessTokenExpiresIn, TimeUnit.SECONDS);
|
||||
//设置refreshToken到redis,获得时使用userToken获取
|
||||
OAuth2RefreshToken oAuth2RefreshToken = oAuth2AccessToken.getRefreshToken();
|
||||
String refreshToken = oAuth2RefreshToken.getValue();
|
||||
long refreshTokenExpiresIn = securityConfigProperties.getRefreshTokenValiditySeconds();
|
||||
RBucket<String> refreshTokenBucket = redissonClient.getBucket(OauthCacheConstant.REFRESH_TOKEN + userToken);
|
||||
refreshTokenBucket.set(refreshToken,refreshTokenExpiresIn, TimeUnit.SECONDS);
|
||||
//绑定username与userToken,用于剔除设置
|
||||
RBucket<String> usernameBucket = redissonClient.getBucket(OauthCacheConstant.USER_TOKEN_BIND + username);
|
||||
usernameBucket.set(userToken,refreshTokenExpiresIn, TimeUnit.SECONDS);
|
||||
//构建返回对象
|
||||
UserVO userVO = UserVO.builder()
|
||||
.id(id)
|
||||
.clientId(clientId)
|
||||
.companyNo(companyNo)
|
||||
.username(username)
|
||||
.userToken(userToken)
|
||||
.resourceRequestPaths(resources)
|
||||
.roleLabels(roles)
|
||||
.openId(openId)
|
||||
.mobile(mobile)
|
||||
.deptNo(deptNo)
|
||||
.postNo(postNo)
|
||||
.dataSecurityVO(dataSecurityVO)
|
||||
.onlyAuthenticate(onlyAuthenticate)
|
||||
.sex(sex)
|
||||
.realName(realName)
|
||||
.build();
|
||||
//设置userVO到redis,获得时候使用userToken获得
|
||||
RBucket<UserVO> userTokenBucket = redissonClient.getBucket(OauthCacheConstant.USER_TOKEN + userToken);
|
||||
userTokenBucket.set(userVO,refreshTokenExpiresIn, TimeUnit.SECONDS);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteToken(UserVO userVO) {
|
||||
//删除accessToken
|
||||
RBucket<String> accessTokenBucket = redissonClient.getBucket(OauthCacheConstant.ACCESS_TOKEN + userVO.getUserToken());
|
||||
boolean deleteAccessToken = accessTokenBucket.delete();
|
||||
//删除refreshToken
|
||||
RBucket<String> refreshTokenBucket = redissonClient.getBucket(OauthCacheConstant.REFRESH_TOKEN + userVO.getUserToken());
|
||||
boolean deleteRefreshToken = refreshTokenBucket.delete();
|
||||
//删除绑定username
|
||||
RBucket<String> usernameBucket = redissonClient.getBucket(OauthCacheConstant.USER_TOKEN_BIND + userVO.getUsername());
|
||||
boolean deleteUsername = usernameBucket.delete();
|
||||
//删除用户和userToken关联
|
||||
RBucket<UserVO> userTokenBucket = redissonClient.getBucket(OauthCacheConstant.USER_TOKEN + userVO.getUserToken());
|
||||
boolean deleteUserTokenBucket = userTokenBucket.delete();
|
||||
//清理完成
|
||||
if (deleteAccessToken&&deleteRefreshToken&&deleteUsername&&deleteUserTokenBucket){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.itheima.sfbx.security.handler.impl;
|
||||
|
||||
import com.itheima.sfbx.security.handler.CacheTokenHandler;
|
||||
import com.itheima.sfbx.security.handler.LogoutHandler;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName LogoutHandlerImpl.java
|
||||
* @Description 退出处理实现
|
||||
*/
|
||||
@Component
|
||||
public class LogoutHandlerImpl implements LogoutHandler {
|
||||
|
||||
@Autowired
|
||||
CacheTokenHandler cacheTokenHandler;
|
||||
|
||||
@Override
|
||||
public Boolean logout(UserVO userVO) {
|
||||
|
||||
return cacheTokenHandler.deleteToken(userVO);
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package com.itheima.sfbx.security.handler.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UsernameVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.security.handler.CacheTokenHandler;
|
||||
import com.itheima.sfbx.security.handler.LoginAuthHandler;
|
||||
import com.itheima.sfbx.security.feign.CustomerFeign;
|
||||
import com.itheima.sfbx.security.feign.UserFeign;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName MobileLoginAuthHandlerImpl.java
|
||||
* @Description 手机验证码登录处理器实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("mobileLoginAuthHandler")
|
||||
public class MobileLoginAuthHandlerImpl implements LoginAuthHandler {
|
||||
|
||||
@Autowired
|
||||
TokenEndpoint tokenEndpoint;
|
||||
|
||||
@Autowired
|
||||
CacheTokenHandler cacheTokenHandler;
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
UserFeign userFeign;
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
CustomerFeign customerFeign;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@Autowired
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@Override
|
||||
public UserVO loginHandler(Principal principal, Map<String, String> parameters,
|
||||
String loginBeanName, CompanyVO companyVO)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
String mobile = parameters.get(OauthConstant.MOBILE_KEY);
|
||||
String clientId = parameters.get(OauthConstant.CLIENT_ID_KEY);
|
||||
String loginType = parameters.get(OauthConstant.LOGIN_TYPE_KEY);
|
||||
UsernameVO usernameVO = UsernameVO.builder()
|
||||
.username(mobile)
|
||||
.clientId(clientId)
|
||||
.companyNo(companyVO.getCompanyNo())
|
||||
.loginType(loginType)
|
||||
.loginBeanName(loginBeanName)
|
||||
.build();
|
||||
String username = JSONObject.toJSONString(usernameVO);
|
||||
parameters.put(OauthConstant.USER_NAME_KEY,username);
|
||||
OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
||||
return cacheTokenHandler.cacheToken(oAuth2AccessToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO findUserDetail(String loginType, String mobile,String companyNo) {
|
||||
//手机登录处理
|
||||
String key = OauthCacheConstant.LOGIN_CODE+mobile;
|
||||
//存储手机发送的验证码到存在中
|
||||
// RBucket<String> code = redissonClient.getBucket(key);
|
||||
// if (EmptyUtil.isNullOrEmpty(code.get())){
|
||||
// throw new ProjectException(AuthEnum.CODE_FAIL);
|
||||
// }
|
||||
// String password = bCryptPasswordEncoder.encode(code.get());
|
||||
String password = bCryptPasswordEncoder.encode("123456");
|
||||
//处理登录
|
||||
UserVO userVO = null;
|
||||
switch (loginType){
|
||||
case OauthConstant.USER_MOBILE:
|
||||
userVO = userFeign.mobileLogin(mobile,companyNo);
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO)){
|
||||
userVO.setPassword(password);
|
||||
userVO.setOnlyAuthenticate(false);
|
||||
}
|
||||
return userVO;
|
||||
case OauthConstant.CUSTOMER_MOBILE:
|
||||
userVO = customerFeign.mobileLogin(mobile,companyNo);
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO)){
|
||||
userVO.setPassword(password);
|
||||
userVO.setOnlyAuthenticate(true);
|
||||
}
|
||||
return userVO;
|
||||
default:
|
||||
throw new ProjectException(AuthEnum.LOGIN_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.itheima.sfbx.security.handler.impl;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.security.handler.CacheTokenHandler;
|
||||
import com.itheima.sfbx.security.handler.RefreshTokenHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName RefreshTokenHandlerImpl.java
|
||||
* @Description 刷新令牌处理实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RefreshTokenHandlerImpl implements RefreshTokenHandler {
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@Autowired
|
||||
TokenEndpoint tokenEndpoint;
|
||||
|
||||
@Autowired
|
||||
CacheTokenHandler cacheTokenHandler;
|
||||
|
||||
@Autowired
|
||||
UserDetailsService userDetailsService;
|
||||
|
||||
@Autowired
|
||||
SecurityConfigProperties securityConfigProperties;
|
||||
|
||||
@Override
|
||||
public UserVO refreshToken(Principal principal, Map<String, String> parameters) {
|
||||
Boolean flag = false;
|
||||
//通过jti获得refreshToken
|
||||
String userToken = parameters.get(OauthConstant.JTI_KEY);
|
||||
RBucket<String> refreshTokenBucket = redissonClient.getBucket(OauthCacheConstant.REFRESH_TOKEN + userToken);
|
||||
String refreshToken = refreshTokenBucket.get();
|
||||
if (EmptyUtil.isNullOrEmpty(refreshToken)){
|
||||
return null;
|
||||
}
|
||||
//使用refreshToken再次获得OAuth2AccessToken
|
||||
parameters.put("refresh_token",refreshToken);
|
||||
OAuth2AccessToken oAuth2AccessToken = null;
|
||||
try {
|
||||
oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
||||
} catch (HttpRequestMethodNotSupportedException e) {
|
||||
log.error("刷新令牌出错:{}", ExceptionsUtil.getErrorMessageWithNestedException(e));
|
||||
return null;
|
||||
}
|
||||
//重新构建jwt增强信息
|
||||
DefaultOAuth2AccessToken defaultOAuth2AccessToken = (DefaultOAuth2AccessToken) oAuth2AccessToken;
|
||||
RBucket<UserVO> jtiUserBucket = redissonClient.getBucket(OauthCacheConstant.USER_TOKEN + userToken);
|
||||
UserVO userVO = jtiUserBucket.get();
|
||||
Map<String, Object> map = new HashMap<>(11);
|
||||
map.put(OauthConstant.USER_ID_KEY, userVO.getId());
|
||||
map.put(OauthConstant.CLIENT_ID_KEY, userVO.getClientId());
|
||||
map.put(OauthConstant.USER_NAME_KEY,userVO.getUsername());
|
||||
map.put(OauthConstant.RESOURCS_KEY,userVO.getResourceRequestPaths());
|
||||
map.put(OauthConstant.ROLES_KEY,userVO.getRoleLabels());
|
||||
map.put(OauthConstant.OPEN_ID_KEY,userVO.getOpenId());
|
||||
map.put(OauthConstant.DEPT_NO_KEY,userVO.getDeptNo());
|
||||
map.put(OauthConstant.POST_NO_KEY,userVO.getPostNo());
|
||||
map.put(OauthConstant.MOBILE_KEY,userVO.getMobile());
|
||||
map.put(OauthConstant.COMPANY_NO_KEY,userVO.getCompanyNo());
|
||||
map.put(OauthConstant.DATA_SECURITY_KEY,userVO.getDataSecurityVO());
|
||||
//令牌自定过期时间
|
||||
map.put(OauthConstant.EXPIRES_IN_KEY,securityConfigProperties.getAccessTokenValiditySeconds());
|
||||
defaultOAuth2AccessToken.setAdditionalInformation(map);
|
||||
//处理缓存信息
|
||||
return cacheTokenHandler.cacheToken(defaultOAuth2AccessToken);
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.itheima.sfbx.security.handler.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.security.handler.CacheTokenHandler;
|
||||
import com.itheima.sfbx.security.handler.LoginAuthHandler;
|
||||
import com.itheima.sfbx.security.feign.CustomerFeign;
|
||||
import com.itheima.sfbx.security.feign.UserFeign;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UsernameVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName UserpasswordLoginAdapter.java
|
||||
* @Description 密码登录处理器实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("usernameLoginAuthHandler")
|
||||
public class UsernameLoginAuthHandlerImpl implements LoginAuthHandler {
|
||||
|
||||
@Autowired
|
||||
TokenEndpoint tokenEndpoint;
|
||||
|
||||
@Autowired
|
||||
CacheTokenHandler cacheTokenHandler;
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
UserFeign userFeign;
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
CustomerFeign customerFeign;
|
||||
|
||||
@Override
|
||||
public UserVO loginHandler(Principal principal, Map<String, String> parameters,
|
||||
String loginBeanName, CompanyVO companyVO)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
String username = parameters.get(OauthConstant.USER_NAME_KEY);
|
||||
String clientId = parameters.get(OauthConstant.CLIENT_ID_KEY);
|
||||
String loginType = parameters.get(OauthConstant.LOGIN_TYPE_KEY);
|
||||
UsernameVO usernameVO = UsernameVO.builder()
|
||||
.username(username)
|
||||
.companyNo(companyVO.getCompanyNo())
|
||||
.clientId(clientId)
|
||||
.loginType(loginType)
|
||||
.loginBeanName(loginBeanName)
|
||||
.build();
|
||||
username = JSONObject.toJSONString(usernameVO);
|
||||
parameters.put(OauthConstant.USER_NAME_KEY,username);
|
||||
OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
||||
return cacheTokenHandler.cacheToken(oAuth2AccessToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO findUserDetail(String loginType, String username,String companyNo) {
|
||||
UserVO userVO = null;
|
||||
//处理登录
|
||||
switch (loginType){
|
||||
case OauthConstant.USER_USERNAME:
|
||||
userVO = userFeign.usernameLogin(username,companyNo);
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO)){
|
||||
userVO.setOnlyAuthenticate(false);
|
||||
}
|
||||
return userVO;
|
||||
case OauthConstant.CUSTOMER_USERNAME:
|
||||
userVO = customerFeign.usernameLogin(username,companyNo);
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO)){
|
||||
userVO.setOnlyAuthenticate(true);
|
||||
}
|
||||
return userVO;
|
||||
default:
|
||||
throw new ProjectException(AuthEnum.LOGIN_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package com.itheima.sfbx.security.handler.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CompanyConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.*;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.security.feign.CustomerFeign;
|
||||
import com.itheima.sfbx.security.feign.UserFeign;
|
||||
import com.itheima.sfbx.security.handler.CacheTokenHandler;
|
||||
import com.itheima.sfbx.security.handler.LoginAuthHandler;
|
||||
import com.itheima.sfbx.security.wechat.WechatService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName WechatLoginAuthHandlerImpl.java
|
||||
* @Description 微信登录处理
|
||||
*/
|
||||
@Component("wechatLoginAuthHandler")
|
||||
public class WechatLoginAuthHandlerImpl implements LoginAuthHandler {
|
||||
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
UserFeign userFeign;
|
||||
|
||||
//调用RPC原创服务
|
||||
@Autowired
|
||||
CustomerFeign customerFeign;
|
||||
|
||||
@Autowired
|
||||
TokenEndpoint tokenEndpoint;
|
||||
|
||||
@Autowired
|
||||
CacheTokenHandler cacheTokenHandler;
|
||||
|
||||
@Autowired
|
||||
WechatService wechatService;
|
||||
|
||||
@Autowired
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@Override
|
||||
public UserVO loginHandler(Principal principal, Map<String, String> parameters,
|
||||
String loginBeanName, CompanyVO companyVO)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
String code = parameters.get(OauthConstant.CODE_KEY);
|
||||
String clientId = parameters.get(OauthConstant.CLIENT_ID_KEY);
|
||||
String loginType = parameters.get(OauthConstant.LOGIN_TYPE_KEY);
|
||||
//code兑换openId
|
||||
AuthChannelVO authChannelVO = companyVO.getAuthChannelVOs().stream().filter(n -> {
|
||||
return n.getChannelLabel().equals(CompanyConstant.CHANNEL_LABEL_WECHAT);
|
||||
}).findFirst().get();
|
||||
//微信拿openId
|
||||
String openId = wechatService.openId(authChannelVO.getAppId(), authChannelVO.getAppSecret(), code);
|
||||
UsernameVO usernameVO = UsernameVO.builder()
|
||||
.username(openId)
|
||||
.clientId(clientId)
|
||||
.companyNo(companyVO.getCompanyNo())
|
||||
.loginType(loginType)
|
||||
.loginBeanName(loginBeanName)
|
||||
.build();
|
||||
String username = JSONObject.toJSONString(usernameVO);
|
||||
parameters.put(OauthConstant.USER_NAME_KEY,username);
|
||||
parameters.put(OauthConstant.PASSWORD_KEY,openId);
|
||||
OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
||||
return cacheTokenHandler.cacheToken(oAuth2AccessToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO findUserDetail(String loginType, String openId,String companyNo) {
|
||||
//处理登录
|
||||
UserVO userVO = null;
|
||||
String password = bCryptPasswordEncoder.encode(openId);
|
||||
switch (loginType){
|
||||
case OauthConstant.USER_WECHAT:
|
||||
userVO = userFeign.wechatLogin(openId,companyNo);
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO)){
|
||||
userVO.setPassword(password);
|
||||
userVO.setOnlyAuthenticate(false);
|
||||
}
|
||||
return userVO;
|
||||
case OauthConstant.CUSTOMER_WECHAT:
|
||||
userVO = customerFeign.wechatLogin(openId,companyNo);
|
||||
//如果用户不存在则注册用户
|
||||
if (EmptyUtil.isNullOrEmpty(userVO)){
|
||||
CustomerVO customerVO = CustomerVO.builder()
|
||||
.username(openId)
|
||||
.openId(openId)
|
||||
.password(password)
|
||||
.build();
|
||||
return customerFeign.registerUser(customerVO);
|
||||
}
|
||||
userVO.setPassword(password);
|
||||
userVO.setOnlyAuthenticate(true);
|
||||
return userVO;
|
||||
default:
|
||||
throw new ProjectException(AuthEnum.LOGIN_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.itheima.sfbx.security.web;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.OauthConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.basic.BaseEnum;
|
||||
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
|
||||
import com.itheima.sfbx.framework.commons.utils.SubjectContent;
|
||||
import com.itheima.sfbx.security.adepter.LoginAuthAdepter;
|
||||
import com.itheima.sfbx.security.handler.LogoutHandler;
|
||||
import com.itheima.sfbx.security.handler.RefreshTokenHandler;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 自定义Oauth2获取令牌接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oauth")
|
||||
@Api(tags = "登录认证")
|
||||
public class AuthController {
|
||||
|
||||
@Autowired
|
||||
private LoginAuthAdepter loginAuthAdepter;
|
||||
|
||||
@Autowired
|
||||
private LogoutHandler logoutHandler;
|
||||
|
||||
@Autowired
|
||||
private RefreshTokenHandler refreshTokenHandler;
|
||||
|
||||
/**
|
||||
* Oauth2登录认证
|
||||
* 登录必传:
|
||||
* client_id:客户端
|
||||
* client_secret:客户端秘钥
|
||||
* grant_type:登录传入:password
|
||||
* login_type:OauthConstant中选择:USER_USERNAME、USER_MOBILE、CUSTOMER_USERNAME、CUSTOMER_MOBILE
|
||||
* username:用户账号【用户名、手机号】
|
||||
* password:用户密码【明文密码、手机验证码】
|
||||
* code:三方授权登录传入的授权码
|
||||
* 刷新必传:
|
||||
* client_id:客户端
|
||||
* grant_type:refresh_token
|
||||
* client_secret:客户端秘钥
|
||||
* jti:本次回话标识
|
||||
*/
|
||||
@ApiOperation(value = "登录认证",notes = "登录认证")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "grant_type", value = "授权模式", example = "password",required = true),
|
||||
@ApiImplicitParam(name = "client_id", value = "Oauth2客户端ID",example = "operators-pc", required = true),
|
||||
@ApiImplicitParam(name = "client_secret",value = "Oauth2客户端秘钥", example = "pass", required = true),
|
||||
@ApiImplicitParam(name = "username", value = "登录用户名",example = "admin@qq.com"),
|
||||
@ApiImplicitParam(name = "mobile", value = "登录用户名", example = "15156403088"),
|
||||
@ApiImplicitParam(name = "usetToken",value = "会话usetToken",required = true),
|
||||
@ApiImplicitParam(name = "password", value = "登录密码", example = "pass"),
|
||||
@ApiImplicitParam(name = "login_type", value = "登录类型", example = "详解OauthConstant登录类型"),
|
||||
@ApiImplicitParam(name = "code", value = "小程序code")
|
||||
})
|
||||
@RequestMapping(value = "/token", method = RequestMethod.POST)
|
||||
public ResponseResult<UserVO> postAccessToken(@ApiIgnore Principal principal,
|
||||
@ApiIgnore @RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
|
||||
UserVO userVO = null;
|
||||
boolean isRefreshToken = OauthConstant.GRANT_TYPE_REFRESH_TOKEN
|
||||
.equals(parameters.get(OauthConstant.GRANT_TYPE_KEY));
|
||||
//令牌刷新
|
||||
if (isRefreshToken){
|
||||
userVO =refreshTokenHandler.refreshToken(principal, parameters);
|
||||
//用户登录
|
||||
}else {
|
||||
userVO = loginAuthAdepter.adepterRoutes(principal, parameters);
|
||||
}
|
||||
return ResponseResultBuild.build(BaseEnum.SUCCEED, userVO);
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 退出接口
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "退出登录",notes = "退出登录")
|
||||
@RequestMapping(value = "/logout", method = RequestMethod.POST)
|
||||
public ResponseResult<Boolean> logout() {
|
||||
UserVO userVO = SubjectContent.getUserVO();
|
||||
Boolean flag = logoutHandler.logout(userVO);
|
||||
return ResponseResultBuild.build(BaseEnum.SUCCEED, flag);
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.itheima.sfbx.security.web;
|
||||
|
||||
import com.nimbusds.jose.jwk.JWKSet;
|
||||
import com.nimbusds.jose.jwk.RSAKey;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "获取公钥")
|
||||
@RestController
|
||||
@RequestMapping("rsa")
|
||||
public class PublicKeyController {
|
||||
|
||||
@Autowired
|
||||
private KeyPair keyPair;
|
||||
|
||||
@ApiOperation(value = "获取公钥",notes = "获取公钥")
|
||||
@GetMapping("/public-key")
|
||||
public Map<String, Object> loadPublicKey() {
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||
RSAKey key = new RSAKey.Builder(publicKey).build();
|
||||
Map<String, Object> map = new JWKSet(key).toJSONObject();
|
||||
log.info("========获得公钥的信息:{}===========",map.toString());
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.itheima.sfbx.security.wechat;
|
||||
|
||||
/**
|
||||
* @ClassName wechatServer.java
|
||||
* @Description 微信接口服务
|
||||
*/
|
||||
public interface WechatService {
|
||||
|
||||
/***
|
||||
* @description 查询用户openId
|
||||
* @param appId 应用
|
||||
* @param appSecret
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
String openId(String appId,String appSecret,String code);
|
||||
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.itheima.sfbx.security.wechat.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itheima.sfbx.security.wechat.WechatService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @ClassName WechatServiceImpl.java
|
||||
* @Description TODO
|
||||
*/
|
||||
@Service
|
||||
public class WechatServiceImpl implements WechatService {
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Override
|
||||
public String openId(String appId, String appSecret, String code) {
|
||||
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appId+
|
||||
"&secret="+appSecret+
|
||||
"&code="+code+
|
||||
"&grant_type=authorization_code" ;
|
||||
String wechatString = restTemplate.getForObject(url, String.class);
|
||||
JSONObject jsonObject = JSONObject.parseObject(wechatString);
|
||||
return jsonObject.getString("openid");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
_ __ __
|
||||
(_) /__________ ______/ /_
|
||||
/ / __/ ___/ __ `/ ___/ __/
|
||||
/ / /_/ /__/ /_/ (__ ) /_
|
||||
/_/\__/\___/\__,_/____/\__/
|
||||
:: Spring Boot :: (v-2.7.10)
|
||||
:: Spring Cloud :: (v-2021.0.6)
|
||||
:: Spring Cloud Alibaba :: (v-2021.0.1.0)
|
||||
:: Itheima Project Cloud :: (V-1.0.2-SNAPSHOT)
|
||||
:: 献给可爱的传智人 ::
|
||||
@@ -0,0 +1,45 @@
|
||||
#服务配置
|
||||
server:
|
||||
#端口
|
||||
port: 7078
|
||||
#服务编码
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile:
|
||||
- test
|
||||
main:
|
||||
allow-circular-references: true
|
||||
allow-bean-definition-overriding: true
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
#应用配置
|
||||
application:
|
||||
#应用名称
|
||||
name: security-oauth
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: ${NACOS_ADDRESS:nacos-service.yjy-public-sfbx-java.svc.cluster.local:20015} # nacos注册中心
|
||||
group: SEATA_GROUP
|
||||
service: ${spring.application.name}
|
||||
username: ${NACOS_USERNAME:nacos}
|
||||
password: ${NACOS_PASSWORD:PKsf*bxQ4;yP3a+}
|
||||
config:
|
||||
server-addr: ${NACOS_ADDRESS:nacos-service.yjy-public-sfbx-java.svc.cluster.local:20015} # nacos注册中心
|
||||
group: SEATA_GROUP
|
||||
file-extension: yml
|
||||
shared-configs: # 共享配置
|
||||
- data-id: shared-spring-task.yml #配置文件名-DataId
|
||||
group: SEATA_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-redisson.yml #配置文件名-DataId
|
||||
group: SEATA_GROUP
|
||||
refresh: false
|
||||
username: ${NACOS_USERNAME:nacos}
|
||||
password: ${NACOS_PASSWORD:PKsf*bxQ4;yP3a+}
|
||||
logging:
|
||||
config: classpath:logback.xml
|
||||
@@ -0,0 +1,39 @@
|
||||
#服务配置
|
||||
server:
|
||||
#端口
|
||||
port: 7078
|
||||
#服务编码
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
main:
|
||||
allow-circular-references: true
|
||||
allow-bean-definition-overriding: true
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
#应用配置
|
||||
application:
|
||||
#应用名称
|
||||
name: security-oauth
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.12.129:8848 # nacos注册中心
|
||||
group: SEATA_GROUP
|
||||
service: ${spring.application.name}
|
||||
config:
|
||||
server-addr: 192.168.12.129:8848 # nacos配置中心地址
|
||||
group: SEATA_GROUP
|
||||
file-extension: yml
|
||||
shared-configs: # 共享配置
|
||||
- data-id: shared-spring-task.yml #配置文件名-DataId
|
||||
group: SEATA_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-redisson.yml #配置文件名-DataId
|
||||
group: SEATA_GROUP
|
||||
refresh: false
|
||||
logging:
|
||||
config: classpath:logback.xml
|
||||
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false">
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 -->
|
||||
<property name="LOG_HOME" value="/data/logs/security-oauth" />
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}-%msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<appender name="FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/security-oauth.log.%d{yyyy-MM-dd}.log
|
||||
</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>30</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}-%msg%n</pattern>
|
||||
</encoder>
|
||||
<!--日志文件最大的大小 -->
|
||||
<triggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
<MaxFileSize>10MB</MaxFileSize>
|
||||
</triggeringPolicy>
|
||||
</appender>
|
||||
<!-- show parameters for hibernate sql 专为 Hibernate 定制 -->
|
||||
<logger name="org.hibernate.type.descriptor.sql.BasicBinder"
|
||||
level="TRACE" />
|
||||
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor"
|
||||
level="DEBUG" />
|
||||
<logger name="org.hibernate.SQL" level="DEBUG" />
|
||||
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
|
||||
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
|
||||
|
||||
<!--myibatis log configure -->
|
||||
<logger name="com.apache.ibatis" level="TRACE" />
|
||||
<logger name="java.sql.Connection" level="DEBUG" />
|
||||
<logger name="java.sql.Statement" level="DEBUG" />
|
||||
<logger name="java.sql.PreparedStatement" level="DEBUG" />
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
<!--日志异步到数据库 -->
|
||||
</configuration>
|
||||
@@ -0,0 +1,21 @@
|
||||
FROM openjdk:11-jdk
|
||||
LABEL maintainer="研究院研发组 <research@itcast.cn>"
|
||||
|
||||
# 时区修改为东八区
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
WORKDIR /security-web
|
||||
ARG PACKAGE_PATH=./target/security-web.jar
|
||||
ADD ${PACKAGE_PATH:-./} security-web.jar
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENV JAVA_OPTS="\
|
||||
-server \
|
||||
-Xms256m \
|
||||
-Xmx512m \
|
||||
-XX:MetaspaceSize=256m \
|
||||
-XX:MaxMetaspaceSize=512m\
|
||||
-Dspring.profiles.active=test"
|
||||
ENTRYPOINT ["sh","-c","java -Djava.security.egd=file:/dev/./urandom -jar $JAVA_OPTS security-web.jar"]
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>sfbx-security</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<!--权限处理:web模块-->
|
||||
<artifactId>security-web</artifactId>
|
||||
<name>security-web</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-mybatis-plus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>sms-interface</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>file-interface</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.jks</include>
|
||||
<include>**/*.yml</include>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.yaml</include>
|
||||
<include>**/*.txt</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>security-web</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.itheima.sfbx.security;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
/**
|
||||
* 后台管理中用户对应的基础数据,包括登录的用户等信息;所以如果要登录的话;该微服务需要启动
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "com.itheima.sfbx")
|
||||
public class SecurityWebStart {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SecurityWebStart.class);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.itheima.sfbx.security.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
* @ClassName BCryptConfig.java
|
||||
* @Description 加密对象配置
|
||||
*/
|
||||
@Configuration
|
||||
public class BCryptConfig {
|
||||
|
||||
/**
|
||||
* BCrypt密码编码
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public BCryptPasswordEncoder bcryptPasswordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.*;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.security.service.IAuthChannelService;
|
||||
import com.itheima.sfbx.security.service.IResourceService;
|
||||
import com.itheima.sfbx.security.service.IRoleService;
|
||||
import com.itheima.sfbx.security.service.IUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName AuthChannelFeignController.java
|
||||
* @Description 授权三方表Mapper接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("auth-channel-feign")
|
||||
@Api(tags = "用户feign管理")
|
||||
@Slf4j
|
||||
public class AuthChannelFeignController {
|
||||
|
||||
@Autowired
|
||||
IAuthChannelService authChannelService;
|
||||
|
||||
/**
|
||||
* @Description 按企业编号和配置类型查询对应的企业信息
|
||||
* @param companyNo 企业编号
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "企业配置",notes = "企业配置")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业编号",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "channelLabel",value = "配置标识",dataType = "String")
|
||||
})
|
||||
@PostMapping("find-auth-channel/{companyNo}/{channelLabel}")
|
||||
public AuthChannelVO findAuthChannelByCompanyNoAndChannelLabel(@PathVariable("companyNo") String companyNo,
|
||||
@PathVariable("channelLabel") String channelLabel){
|
||||
return authChannelService.findAuthChannelByCompanyNoAndChannelLabel(companyNo,channelLabel);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.pojo.Company;
|
||||
import com.itheima.sfbx.security.service.ICompanyService;
|
||||
import com.itheima.sfbx.security.service.ICustomerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* CompanyFeignController
|
||||
*
|
||||
* @author: wgl
|
||||
* @describe: 系统保险机构租户
|
||||
* @date: 2022/12/28 10:10
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("company-feign")
|
||||
@Api(tags = "企业feign管理")
|
||||
@Slf4j
|
||||
public class CompanyFeignController {
|
||||
|
||||
@Autowired
|
||||
ICompanyService companyService;
|
||||
|
||||
/**
|
||||
* @Description 按企业编号查询对应的企业信息
|
||||
* @param companyNo 企业编号
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据企业编号查找企业",notes = "根据企业编号查找企业信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业编号",dataType = "String")
|
||||
})
|
||||
@PostMapping("find-company/{companyNo}")
|
||||
public CompanyVO findCompanyByNo(@PathVariable("companyNo") String companyNo){
|
||||
return companyService.findCompanyByNo(companyNo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Description 按企业编号列表查询对应的企业信息
|
||||
* @param companyNos 企业编号列表
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据企业编号查找企业信息",notes = "按企业编号列表查询企业")
|
||||
@PostMapping("find-company")
|
||||
public List<CompanyVO> findCompanyByNos(@RequestBody List<String> companyNos){
|
||||
List<Long> validCompanyNos = new ArrayList<>();
|
||||
for (String companyNo : companyNos) {
|
||||
validCompanyNos.add(Long.parseLong(companyNo));
|
||||
}
|
||||
CompanyVO companyVO = CompanyVO.builder().
|
||||
checkIds(validCompanyNos.toArray(new Long[0])).
|
||||
dataState(SuperConstant.DATA_STATE_0).
|
||||
build();
|
||||
return companyService.findCompanyList(companyVO);
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.security.service.ICustomerService;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CustomerVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @ClassName CustomerAdapterController.java
|
||||
* @Description 客户适配controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("customer-feign")
|
||||
@Api(tags = "客户feign管理")
|
||||
@Slf4j
|
||||
public class CustomerFeignController {
|
||||
|
||||
@Autowired
|
||||
ICustomerService customerService;
|
||||
|
||||
/**
|
||||
* @Description 按用户名查找用户
|
||||
* @param username 登录名
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "按用户名查找用户",notes = "按用户名查找用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "username",value = "用户名称",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业号",dataType = "String")
|
||||
})
|
||||
@PostMapping("username-login/{username}/{companyNo}")
|
||||
UserVO usernameLogin(@PathVariable("username") String username,@PathVariable("companyNo") String companyNo){
|
||||
return customerService.usernameLogin(username,companyNo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 按用户手机查找用户
|
||||
* @param mobile 登录名
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "按用户手机查找用户",notes = "按用户手机查找用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "mobile",value = "用户手机",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业号",dataType = "String")
|
||||
})
|
||||
@PostMapping("mobile-login/{mobile}/{companyNo}")
|
||||
UserVO mobileLogin(@PathVariable("mobile")String mobile,@PathVariable("companyNo") String companyNo){
|
||||
return customerService.mobileLogin(mobile,companyNo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 按用户openid查找用户
|
||||
* @param openId 登录名
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "按用户openid查找用户",notes = "按用户openid查找用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "openId",value = "用户openid",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业号",dataType = "String")
|
||||
})
|
||||
@PostMapping("wechat-login/{openId}/{companyNo}")
|
||||
UserVO wechatLogin(@PathVariable("openId") String openId,@PathVariable("companyNo") String companyNo){
|
||||
return customerService.wechatLogin(openId,companyNo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Description 注册
|
||||
* @param customerVO 客户信息
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "注册客户",notes = "注册客户")
|
||||
@ApiImplicitParam(name = "customerVO",value = "客户Vo对象",required = true,dataType = "CustomerVO")
|
||||
@PostMapping("register-user")
|
||||
UserVO registerUser(@RequestBody CustomerVO customerVO){
|
||||
return BeanConv.toBean(customerService.createCustomer(customerVO),UserVO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户真实姓名
|
||||
* @param userId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("update-real-name")
|
||||
Boolean updateRealName(@RequestParam("userId") String userId,@RequestParam("name") String name){
|
||||
return customerService.updateRealName(userId,name);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package com.itheima.sfbx.security.feign;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.dto.security.*;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.security.pojo.User;
|
||||
import com.itheima.sfbx.security.service.IResourceService;
|
||||
import com.itheima.sfbx.security.service.IRoleService;
|
||||
import com.itheima.sfbx.security.service.IUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName UserAdapterController.java
|
||||
* @Description 用户适配controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("user-feign")
|
||||
@Api(tags = "用户feign管理")
|
||||
@Slf4j
|
||||
public class UserFeignController {
|
||||
|
||||
@Autowired
|
||||
IUserService userService;
|
||||
|
||||
@Autowired
|
||||
IRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
IResourceService resourceService;
|
||||
|
||||
/**
|
||||
* @Description 按用户名查找用户
|
||||
* @param username 登录名
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "按用户名查找用户",notes = "按用户名查找用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "username",value = "用户名称",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业号",dataType = "String")
|
||||
})
|
||||
@PostMapping("username-login/{username}/{companyNo}")
|
||||
UserVO usernameLogin(@PathVariable("username") String username,@PathVariable("companyNo") String companyNo){
|
||||
return userService.usernameLogin(username,companyNo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 按用户手机查找用户
|
||||
* @param mobile 登录名
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "按用户手机查找用户",notes = "按用户手机查找用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "mobile",value = "用户手机",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业号",dataType = "String")
|
||||
})
|
||||
@PostMapping("mobile-login/{mobile}/{companyNo}")
|
||||
UserVO mobileLogin(@PathVariable("mobile")String mobile,@PathVariable("companyNo") String companyNo){
|
||||
return userService.mobileLogin(mobile,companyNo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 按用户openid查找用户
|
||||
* @param openId 登录名
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "按用户openid查找用户",notes = "按用户openid查找用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path",name = "openId",value = "用户openid",dataType = "String"),
|
||||
@ApiImplicitParam(paramType = "path",name = "companyNo",value = "企业号",dataType = "String")
|
||||
})
|
||||
@PostMapping("wechat-login/{openId}/{companyNo}")
|
||||
UserVO wechatLogin(@PathVariable("openId") String openId,@PathVariable("companyNo") String companyNo){
|
||||
return userService.wechatLogin(openId,companyNo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 查找用户所有角色
|
||||
* @param userId 用户Id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("find-role-user/{userId}")
|
||||
@ApiOperation(value = "查找用户所有角色",notes = "查找用户所有角色")
|
||||
@ApiImplicitParam(paramType = "path",name = "userId",value = "用户id",dataType = "Long")
|
||||
List<RoleVO> findRoleByUserId(@PathVariable("userId")Long userId){
|
||||
return roleService.findRoleVOListByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 查询用户有资源
|
||||
* @param userId 用户Id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("find-resoure-user/{userId}")
|
||||
@ApiOperation(value = "查询用户有资源",notes = "查询用户有资源")
|
||||
@ApiImplicitParam(paramType = "path",name = "userId",value = "用户id",dataType = "Long")
|
||||
List<ResourceVO> findResourceByUserId(@PathVariable("userId")Long userId){
|
||||
return resourceService.findResourceVOListByUserId(userId);
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 查询用户数据权限
|
||||
* @param queryDataSecurityVO 角色列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "查询用户数据权限",notes = "查询用户数据权限")
|
||||
@ApiImplicitParam(name = "queryDataSecurityVO",value = "查询对象",required = true,dataType = "QueryDataSecurityVO")
|
||||
@PostMapping(value = "user-data-security")
|
||||
DataSecurityVO userDataSecurity(@RequestBody QueryDataSecurityVO queryDataSecurityVO ){
|
||||
return userService.userDataSecurity(queryDataSecurityVO.getRoleVOs(),queryDataSecurityVO.getUserId());
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 根据用户id查询出用户信息
|
||||
* @param userId 角色id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据用户id获取对应的用户对象信息",notes = "根据用户id获取对应的用户对象信息")
|
||||
@ApiImplicitParam(name = "userId",value = "用户id",required = true,dataType = "Long")
|
||||
@PostMapping(value = "find-user-by-id")
|
||||
UserVO userDataSecurity(@RequestParam("userId") Long userId){
|
||||
return BeanConv.toBean(userService.getById(userId),UserVO.class);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package com.itheima.sfbx.security.init;
|
||||
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CompanyCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.security.service.ICompanyService;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName initCompanyWebSIteInfo.java
|
||||
* @Description 初始化企业信息到redis中进行热加载
|
||||
*/
|
||||
@Component
|
||||
public class InitCompany {
|
||||
|
||||
@Autowired
|
||||
ICompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@Async
|
||||
@PostConstruct
|
||||
public void initDataDict(){
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new InitTask(timer),10*1000);
|
||||
}
|
||||
|
||||
class InitTask extends TimerTask {
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private InitTask(Timer timer) {
|
||||
this.timer= timer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//查找正式,适用且未有效所有企业
|
||||
List<CompanyVO> companyVOs = companyService.findCompanyVOValidation();
|
||||
//处理缓存
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVOs)){
|
||||
companyVOs.forEach(companyVO -> {
|
||||
String webSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getWebSite();
|
||||
RBucket<CompanyVO> webSiteBucket = redissonClient.getBucket(webSiteKey);
|
||||
String appSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getAppSite();
|
||||
RBucket<CompanyVO> appSiteBucket = redissonClient.getBucket(appSiteKey);
|
||||
Duration between = Duration.between(LocalDateTime.now(), companyVO.getExpireTime());
|
||||
if (between.toSeconds() > 0) {
|
||||
webSiteBucket.set(companyVO, between.toSeconds(), TimeUnit.SECONDS);
|
||||
appSiteBucket.set(companyVO, between.toSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 添加缓存中的站点
|
||||
* @param companyVO 企业号
|
||||
* @return:
|
||||
*/
|
||||
public void addWebSiteforRedis(CompanyVO companyVO){
|
||||
String webSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getWebSite();
|
||||
RBucket<CompanyVO> webSiteBucket = redissonClient.getBucket(webSiteKey);
|
||||
String appSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getAppSite();
|
||||
RBucket<CompanyVO> appSiteBucket = redissonClient.getBucket(appSiteKey);
|
||||
Duration between = Duration.between(LocalDateTime.now(), companyVO.getExpireTime());
|
||||
if (between.toSeconds() > 0) {
|
||||
webSiteBucket.set(companyVO, between.toSeconds(), TimeUnit.SECONDS);
|
||||
appSiteBucket.set(companyVO, between.toSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* @description 移除缓存中的站点
|
||||
* @param companyVO 企业号
|
||||
* @return:
|
||||
*/
|
||||
public void deleteWebSiteforRedis( CompanyVO companyVO){
|
||||
String webSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getWebSite();
|
||||
RBucket<CompanyVO> webSiteBucket = redissonClient.getBucket(webSiteKey);
|
||||
String appSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getAppSite();
|
||||
RBucket<CompanyVO> appSiteBucket = redissonClient.getBucket(appSiteKey);
|
||||
webSiteBucket.delete();
|
||||
appSiteBucket.delete();
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* @description 更新缓存中的站点
|
||||
* @param companyVO 企业号
|
||||
* @return:
|
||||
*/
|
||||
public void updataWebSiteforRedis(CompanyVO companyVO){
|
||||
String webSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getWebSite();
|
||||
RBucket<CompanyVO> webSiteBucket = redissonClient.getBucket(webSiteKey);
|
||||
String appSiteKey = CompanyCacheConstant.WEBSITE + companyVO.getAppSite();
|
||||
RBucket<CompanyVO> appSiteBucket = redissonClient.getBucket(appSiteKey);
|
||||
Duration between = Duration.between(LocalDateTime.now(), companyVO.getExpireTime());
|
||||
if (between.toSeconds() > 0) {
|
||||
webSiteBucket.set(companyVO, between.toSeconds(), TimeUnit.SECONDS);
|
||||
appSiteBucket.set(companyVO, between.toSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.AuthChannel;
|
||||
import com.itheima.sfbx.security.pojo.Customer;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description:授权三方表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthChannelMapper extends BaseMapper<AuthChannel> {
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.Company;
|
||||
import com.itheima.sfbx.security.pojo.Customer;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description:企业表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CompanyMapper extends BaseMapper<Company> {
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.Customer;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description:客户表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CustomerMapper extends BaseMapper<Customer> {
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.security.pojo.Dept;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptVO;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:部门表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface DeptMapper extends BaseMapper<Dept> {
|
||||
|
||||
@Select({"SELECT",
|
||||
"d.id,",
|
||||
"d.dept_no,",
|
||||
"d.dept_name,",
|
||||
"d.sort_no,",
|
||||
"d.data_state,",
|
||||
"d.create_by,",
|
||||
"d.create_time,",
|
||||
"d.update_by,",
|
||||
"d.update_time,",
|
||||
"FROM ",
|
||||
"tab_dept_post_user dpu ",
|
||||
"LEFT JOIN tab_dept d ON dpu.dept_no = d.dept_no ",
|
||||
"WHERE d.data_state = '"+ SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND dpu.user_id = #{userId}"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="dept_no", property="deptNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="dept_name", property="deptName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
|
||||
})
|
||||
List<DeptVO> findDeptVOListByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>" ,
|
||||
"SELECT",
|
||||
"d.id,",
|
||||
"d.dept_no,",
|
||||
"d.dept_name,",
|
||||
"d.sort_no,",
|
||||
"d.data_state,",
|
||||
"d.create_by,",
|
||||
"d.create_time,",
|
||||
"d.update_by,",
|
||||
"d.update_time,",
|
||||
"rd.role_id ",
|
||||
"FROM ",
|
||||
"tab_role_dept rd ",
|
||||
"LEFT JOIN tab_dept d ON rd.dept_no = d.dept_no ",
|
||||
"WHERE d.data_state = '"+ SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND rd.role_id in (",
|
||||
"<foreach collection='roleIds' separator=',' item='roleId'>",
|
||||
"#{roleId}",
|
||||
"</foreach>",
|
||||
")</script>"
|
||||
})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="dept_no", property="deptNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="dept_name", property="deptName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="role_id", property="roleId", jdbcType=JdbcType.BIGINT)
|
||||
})
|
||||
List<DeptVO> findDeptVOListInRoleId(@Param("roleIds") List<Long> roleIds);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.DeptPostUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description:部门岗位用户关联表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface DeptPostUserMapper extends BaseMapper<DeptPostUser> {
|
||||
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.security.pojo.Post;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.PostVO;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:岗位表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface PostMapper extends BaseMapper<Post> {
|
||||
|
||||
@Select({"SELECT ",
|
||||
"p.id,",
|
||||
"p.dept_no,",
|
||||
"p.post_no,",
|
||||
"p.post_name,",
|
||||
"p.sort_no,",
|
||||
"p.data_state,",
|
||||
"p.create_by,",
|
||||
"p.create_time,",
|
||||
"p.update_by,",
|
||||
"p.update_time,",
|
||||
"p.remark,",
|
||||
"FROM ",
|
||||
"tab_dept_post_user dpu ",
|
||||
"LEFT JOIN tab_post p ON dpu.post_no = p.post_no ",
|
||||
"WHERE p.data_state = '"+ SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND dpu.user_id = #{userId}"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="dept_no", property="deptNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="post_no", property="postNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="post_name", property="postName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<PostVO> findPostVOListByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.ResourceVO;
|
||||
import com.itheima.sfbx.security.pojo.Resource;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:权限表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface ResourceMapper extends BaseMapper<Resource> {
|
||||
|
||||
@Select({"<script>",
|
||||
"SELECT",
|
||||
"r.id,",
|
||||
"r.resource_no,",
|
||||
"r.parent_resource_no,",
|
||||
"r.resource_name,",
|
||||
"r.resource_type,",
|
||||
"r.request_path,",
|
||||
"r.label,",
|
||||
"r.data_state,",
|
||||
"r.sort_no,",
|
||||
"r.icon,",
|
||||
"r.create_by,",
|
||||
"r.create_time,",
|
||||
"r.update_by,",
|
||||
"r.update_time,",
|
||||
"r.remark,",
|
||||
"rr.role_id ",
|
||||
"FROM ",
|
||||
"tab_role_resource rr ",
|
||||
"LEFT JOIN tab_resource r ON rr.resource_no = r.resource_no ",
|
||||
"WHERE r.data_state = '"+SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND rr.role_id IN (" ,
|
||||
"<foreach collection='roleIds' separator=',' item='roleId'>",
|
||||
"#{roleId}",
|
||||
"</foreach> ",
|
||||
")</script>"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="resource_no", property="resourceNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="parent_resource_no", property="parentResourceNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="resource_name", property="resourceName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="resource_type", property="resourceType", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="request_path", property="requestPath", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="label", property="label", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.INTEGER),
|
||||
@Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="role_id", property="roleId", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<ResourceVO> findResourceVOListInRoleId(@Param("roleIds") List<Long> roleIds);
|
||||
|
||||
@Select({"SELECT",
|
||||
"r.id,",
|
||||
"r.resource_no,",
|
||||
"r.parent_resource_no,",
|
||||
"r.resource_name,",
|
||||
"r.resource_type,",
|
||||
"r.request_path,",
|
||||
"r.label,",
|
||||
"r.data_state,",
|
||||
"r.sort_no,",
|
||||
"r.icon,",
|
||||
"r.create_by,",
|
||||
"r.create_time,",
|
||||
"r.update_by,",
|
||||
"r.update_time,",
|
||||
"r.remark ",
|
||||
"FROM ",
|
||||
"tab_role_resource rr ",
|
||||
"LEFT JOIN tab_user_role ur ON ur.role_id = rr.role_id ",
|
||||
"LEFT JOIN tab_resource r ON rr.resource_no = r.resource_no ",
|
||||
"WHERE r.data_state = '"+SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND ur.user_id = #{userId}"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="resource_no", property="resourceNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="parent_resource_no", property="parentResourceNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="resource_name", property="resourceName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="resource_type", property="resourceType", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="request_path", property="requestPath", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="label", property="label", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.INTEGER),
|
||||
@Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<ResourceVO> findResourceVOListByUserId(@Param("userId") Long userId);
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.RoleDept;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @ClassName RoleDeptMapper.java
|
||||
* @Description 角色部门中间表
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleDeptMapper extends BaseMapper<RoleDept> {
|
||||
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.RoleVO;
|
||||
import com.itheima.sfbx.security.pojo.Role;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:角色表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleMapper extends BaseMapper<Role> {
|
||||
|
||||
@Select({"<script>",
|
||||
"SELECT",
|
||||
"r.id,",
|
||||
"r.role_name,",
|
||||
"r.label,",
|
||||
"r.sort_no,",
|
||||
"r.data_state,",
|
||||
"r.create_by,",
|
||||
"r.create_time,",
|
||||
"r.update_by,",
|
||||
"r.update_time,",
|
||||
"ur.user_id,",
|
||||
"r.remark ",
|
||||
"FROM ",
|
||||
"tab_user_role ur ",
|
||||
"LEFT JOIN tab_role r ON ur.role_id = r.id ",
|
||||
"WHERE r.data_state = '"+ SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND ur.user_id IN (" ,
|
||||
"<foreach collection='userIds' separator=',' item='userId'>",
|
||||
"#{userId}",
|
||||
"</foreach> ",
|
||||
")</script>"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="role_name", property="roleName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="label", property="label", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<RoleVO> findRoleVOListInUserId(@Param("userIds")List<Long> userIds);
|
||||
|
||||
@Select({"SELECT",
|
||||
"r.id,",
|
||||
"r.role_name,",
|
||||
"r.label,",
|
||||
"r.sort_no,",
|
||||
"r.data_state,",
|
||||
"r.create_by,",
|
||||
"r.create_time,",
|
||||
"r.update_by,",
|
||||
"r.update_time,",
|
||||
"r.remark ",
|
||||
"FROM ",
|
||||
"tab_role_resource rr ",
|
||||
"LEFT JOIN tab_role r ON rr.role_id = r.id ",
|
||||
"WHERE r.data_state = '"+ SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND rr.resource_no = #{resourceNo}"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="role_name", property="roleName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="label", property="label", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<RoleVO> findRoleVOListByResourceNo(String resourceNo);
|
||||
|
||||
@Select({"SELECT",
|
||||
"r.id,",
|
||||
"r.role_name,",
|
||||
"r.label,",
|
||||
"r.sort_no,",
|
||||
"r.data_state,",
|
||||
"r.create_by,",
|
||||
"r.create_time,",
|
||||
"r.update_by,",
|
||||
"r.update_time,",
|
||||
"r.remark,",
|
||||
"r.data_scope ",
|
||||
"FROM ",
|
||||
"tab_user_role ur ",
|
||||
"LEFT JOIN tab_role r ON ur.role_id = r.id ",
|
||||
"WHERE r.data_state = '"+ SuperConstant.DATA_STATE_0+"' ",
|
||||
"AND ur.user_id = #{userId}"})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="role_name", property="roleName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="label", property="label", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sort_no", property="sortNo", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="data_scope", property="dataScope", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<RoleVO> findRoleVOListByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.RoleResource;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description:角色资源关联表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleResourceMapper extends BaseMapper<RoleResource> {
|
||||
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.security.pojo.User;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:用户表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
@Select({"SELECT",
|
||||
"u.id ,",
|
||||
"u.user_name,",
|
||||
"u.open_id,",
|
||||
"u.password,",
|
||||
"u.user_type,",
|
||||
"u.avatar,",
|
||||
"u.nick_name,",
|
||||
"u.email,",
|
||||
"u.real_name,",
|
||||
"u.mobile,",
|
||||
"u.sex,",
|
||||
"u.data_state,",
|
||||
"u.create_by,",
|
||||
"u.create_time,",
|
||||
"u.update_by,",
|
||||
"u.update_time,",
|
||||
"u.remark,",
|
||||
"dpu.post_no",
|
||||
"FROM",
|
||||
"tab_dept_post_user dpu",
|
||||
"LEFT JOIN tab_user u ON dpu.user_id = u.id",
|
||||
"WHERE dpu.post_no = #{postNo} AND u.data_state='"+ SuperConstant.DATA_STATE_0+",",
|
||||
})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="open_id", property="openId", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="user_type", property="userType", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="nick_name", property="nickName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sex", property="sex", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="post_no", property="postNo", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<UserVO> findUserVOListByDeptNo(@Param("postNo") String postNo);
|
||||
|
||||
@Select({"SELECT",
|
||||
"u.id ,",
|
||||
"u.user_name,",
|
||||
"u.open_id,",
|
||||
"u.password,",
|
||||
"u.user_type,",
|
||||
"u.avatar,",
|
||||
"u.nick_name,",
|
||||
"u.email,",
|
||||
"u.real_name,",
|
||||
"u.mobile,",
|
||||
"u.sex,",
|
||||
"u.data_state,",
|
||||
"u.create_by,",
|
||||
"u.create_time,",
|
||||
"u.update_by,",
|
||||
"u.update_time,",
|
||||
"u.remark,",
|
||||
"ur.role_id ",
|
||||
"FROM ",
|
||||
"tab_user_role ur ",
|
||||
"LEFT JOIN tab_user u ON ur.user_id = u.id ",
|
||||
"WHERE ur.role_id = #{roleId} AND u.data_state='"+ SuperConstant.DATA_STATE_0+",",
|
||||
})
|
||||
@Results({
|
||||
@Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
|
||||
@Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="open_id", property="openId", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="user_type", property="userType", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="nick_name", property="nickName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="sex", property="sex", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="data_state", property="dataState", jdbcType=JdbcType.CHAR),
|
||||
@Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="role_id", property="roleId", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<UserVO> findUserVOListByRoleId(@Param("roleId")Long roleId);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.itheima.sfbx.security.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itheima.sfbx.security.pojo.UserRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description:用户角色关联表Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserRoleMapper extends BaseMapper<UserRole> {
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @ClassName AuthChannel.java
|
||||
* @Description 三方授权渠道信息
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@TableName("tab_auth_channel")
|
||||
@ApiModel(value="AuthChannel对象", description="三方渠道")
|
||||
public class AuthChannel extends BasePojo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public AuthChannel(String domain,Long id, String dataState, String channelName, String channelLabel, String appId, String appSecret, String otherConfig, String companyNo, String notifyUrl) {
|
||||
super(id, dataState);
|
||||
this.channelName = channelName;
|
||||
this.channelLabel = channelLabel;
|
||||
this.appId = appId;
|
||||
this.appSecret = appSecret;
|
||||
this.otherConfig = otherConfig;
|
||||
this.companyNo = companyNo;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "通道名称")
|
||||
private String channelName;
|
||||
|
||||
@ApiModelProperty(value = "通道唯一标记")
|
||||
private String channelLabel;
|
||||
|
||||
@ApiModelProperty(value = "商户appid")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "企业三方app秘钥")
|
||||
private String appSecret;
|
||||
|
||||
@ApiModelProperty(value = "其他配置")
|
||||
private String otherConfig;
|
||||
|
||||
@ApiModelProperty(value = "商户编号")
|
||||
private String companyNo;
|
||||
|
||||
@ApiModelProperty(value = "请求域名")
|
||||
private String domain;
|
||||
|
||||
@ApiModelProperty(value = "回调地址")
|
||||
private String notifyUrl;
|
||||
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description:企业账号管理
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_company")
|
||||
@ApiModel(value="Company对象", description="企业账号管理")
|
||||
public class Company extends BasePojo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public Company(Long id, String dataState, String companyNo, String companName, String registeredNo, String province, String area, String city, String address, String status, LocalDateTime expireTime, String webSite, String appSite, String email, String tel, String leaderMobile, String leaderName) {
|
||||
super(id, dataState);
|
||||
this.companyNo = companyNo;
|
||||
this.companName = companName;
|
||||
this.registeredNo = registeredNo;
|
||||
this.province = province;
|
||||
this.area = area;
|
||||
this.city = city;
|
||||
this.address = address;
|
||||
this.status = status;
|
||||
this.expireTime = expireTime;
|
||||
this.webSite = webSite;
|
||||
this.appSite = appSite;
|
||||
this.email = email;
|
||||
this.tel = tel;
|
||||
this.leaderMobile = leaderMobile;
|
||||
this.leaderName = leaderName;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "商户编号")
|
||||
private String companyNo;
|
||||
|
||||
@ApiModelProperty(value = "企业名称")
|
||||
private String companName;
|
||||
|
||||
@ApiModelProperty(value = "统一社会信用代码")
|
||||
private String registeredNo;
|
||||
|
||||
@ApiModelProperty(value = "地址(省)")
|
||||
private String province;
|
||||
|
||||
@ApiModelProperty(value = "地址(区)")
|
||||
private String area;
|
||||
|
||||
@ApiModelProperty(value = "地址(市)")
|
||||
private String city;
|
||||
|
||||
@ApiModelProperty(value = "详细地址")
|
||||
private String address;
|
||||
|
||||
@ApiModelProperty(value = "状态(停用:0,试用:1,,正式:2)")
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty(value = "到期时间 (试用下是默认七天后到期,状态改成停用)")
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")//set
|
||||
private LocalDateTime expireTime;
|
||||
|
||||
@ApiModelProperty(value = "商户门店web站点")
|
||||
private String webSite;
|
||||
|
||||
@ApiModelProperty(value = "商户app站点")
|
||||
private String appSite;
|
||||
|
||||
@ApiModelProperty(value = "联系邮箱")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "电话")
|
||||
private String tel;
|
||||
|
||||
@ApiModelProperty(value = "负责人手机")
|
||||
private String leaderMobile;
|
||||
|
||||
@ApiModelProperty(value = "负责人姓名")
|
||||
private String leaderName;
|
||||
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_customer")
|
||||
public class Customer extends BasePojo {
|
||||
|
||||
private String username;
|
||||
|
||||
private String openId;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String realName;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String sex;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public Customer(Long id, String dataState, String username, String openId, String password,
|
||||
String nickName, String email, String realName, String mobile, String sex) {
|
||||
super(id, dataState);
|
||||
this.username = username;
|
||||
this.openId = openId;
|
||||
this.password = password;
|
||||
this.nickName = nickName;
|
||||
this.email = email;
|
||||
this.realName = realName;
|
||||
this.mobile = mobile;
|
||||
this.sex = sex;
|
||||
this.companyNo=companyNo;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_dept")
|
||||
public class Dept extends BasePojo {
|
||||
|
||||
private String parentDeptNo;
|
||||
|
||||
private String deptNo;
|
||||
|
||||
private String deptName;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
private Long leaderId;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public Dept(Long id, String dataState, String parentDeptNo, String deptNo, String deptName, Integer sortNo, Long leaderId, String companyNo) {
|
||||
super(id, dataState);
|
||||
this.parentDeptNo = parentDeptNo;
|
||||
this.deptNo = deptNo;
|
||||
this.deptName = deptName;
|
||||
this.sortNo = sortNo;
|
||||
this.leaderId = leaderId;
|
||||
this.companyNo = companyNo;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_dept_post_user")
|
||||
public class DeptPostUser extends BasePojo {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String deptNo;
|
||||
|
||||
private String postNo;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public DeptPostUser(Long id, String dataState, Long userId, String deptNo, String postNo,String companyNo) {
|
||||
super(id, dataState);
|
||||
this.userId = userId;
|
||||
this.deptNo = deptNo;
|
||||
this.postNo = postNo;
|
||||
this.companyNo=companyNo;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_post")
|
||||
public class Post extends BasePojo {
|
||||
|
||||
private String deptNo;
|
||||
|
||||
private String postNo;
|
||||
|
||||
private String postName;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public Post(Long id, String dataState, String deptNo, String postNo, String postName, Integer sortNo, String remark, String companyNo) {
|
||||
super(id, dataState);
|
||||
this.deptNo = deptNo;
|
||||
this.postNo = postNo;
|
||||
this.postName = postName;
|
||||
this.sortNo = sortNo;
|
||||
this.remark = remark;
|
||||
this.companyNo = companyNo;
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_resource")
|
||||
public class Resource extends BasePojo {
|
||||
|
||||
private String resourceNo;
|
||||
|
||||
private String parentResourceNo;
|
||||
|
||||
private String resourceName;
|
||||
|
||||
private String resourceType;
|
||||
|
||||
private String requestPath;
|
||||
|
||||
private String label;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
private String icon;
|
||||
|
||||
private String remark;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public Resource(Long id, String dataState, String resourceNo, String parentResourceNo, String resourceName, String resourceType, String requestPath, String label, Integer sortNo, String icon, String remark) {
|
||||
super(id, dataState);
|
||||
this.resourceNo = resourceNo;
|
||||
this.parentResourceNo = parentResourceNo;
|
||||
this.resourceName = resourceName;
|
||||
this.resourceType = resourceType;
|
||||
this.requestPath = requestPath;
|
||||
this.label = label;
|
||||
this.sortNo = sortNo;
|
||||
this.icon = icon;
|
||||
this.remark = remark;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_role")
|
||||
public class Role extends BasePojo {
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String label;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
private String dataState;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String dataScope;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public Role(Long id, String dataState, String roleName, String label, Integer sortNo, String dataState1, String remark, String dataScope, String companyNo) {
|
||||
super(id, dataState);
|
||||
this.roleName = roleName;
|
||||
this.label = label;
|
||||
this.sortNo = sortNo;
|
||||
this.dataState = dataState1;
|
||||
this.remark = remark;
|
||||
this.dataScope = dataScope;
|
||||
this.companyNo = companyNo;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_role_dept")
|
||||
public class RoleDept extends BasePojo {
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private String deptNo;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public RoleDept(Long id, String dataState, Long roleId, String deptNo,String companyNo) {
|
||||
super(id, dataState);
|
||||
this.roleId = roleId;
|
||||
this.deptNo = deptNo;
|
||||
this.companyNo = companyNo;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_role_resource")
|
||||
public class RoleResource extends BasePojo {
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private String resourceNo;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public RoleResource(Long id, String dataState, Long roleId, String resourceNo,String companyNo) {
|
||||
super(id, dataState);
|
||||
this.roleId = roleId;
|
||||
this.resourceNo = resourceNo;
|
||||
this.companyNo=companyNo;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_user")
|
||||
public class User extends BasePojo {
|
||||
|
||||
private String username;
|
||||
|
||||
private String openId;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String realName;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String sex;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public User(Long id, String dataState, String username, String openId, String password,String nickName,
|
||||
String email, String realName, String mobile, String sex,String companyNo) {
|
||||
super(id, dataState);
|
||||
this.username = username;
|
||||
this.openId = openId;
|
||||
this.password = password;
|
||||
this.nickName = nickName;
|
||||
this.email = email;
|
||||
this.realName = realName;
|
||||
this.mobile = mobile;
|
||||
this.sex = sex;
|
||||
this.companyNo=companyNo;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.itheima.sfbx.security.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.itheima.sfbx.framework.mybatisplus.basic.BasePojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tab_user_role")
|
||||
public class UserRole extends BasePojo {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private String companyNo;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Builder
|
||||
public UserRole(Long id, String dataState, Long userId, Long roleId,String companyNo) {
|
||||
super(id, dataState);
|
||||
this.userId = userId;
|
||||
this.roleId = roleId;
|
||||
this.companyNo = companyNo;
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.AuthChannelVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.pojo.AuthChannel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:授权渠道服务类
|
||||
*/
|
||||
public interface IAuthChannelService extends IService<AuthChannel> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询授权渠道分页列表
|
||||
* @param authChannelVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<AuthChannel>
|
||||
*/
|
||||
Page<AuthChannelVO> findAuthChannelPage(AuthChannelVO authChannelVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建授权渠道
|
||||
* @param authChannelVO 对象信息
|
||||
* @return AuthChannel
|
||||
*/
|
||||
AuthChannelVO createAuthChannel(AuthChannelVO authChannelVO);
|
||||
|
||||
/**
|
||||
* @Description 修改授权渠道
|
||||
* @param authChannelVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateAuthChannel(AuthChannelVO authChannelVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询授权渠道列表
|
||||
* @param authChannelVO 查询条件
|
||||
* @return: List<AuthChannel>
|
||||
*/
|
||||
List<AuthChannelVO> findAuthChannelList(AuthChannelVO authChannelVO);
|
||||
|
||||
/***
|
||||
* @description 查询企业组中的所有配置
|
||||
*
|
||||
* @param companyNos 企业号
|
||||
* @return
|
||||
*/
|
||||
List<AuthChannelVO> findAuthChannelListInCompanyNos(List<String> companyNos);
|
||||
|
||||
/***
|
||||
* @description 移除企业对应的三方授权渠道
|
||||
*
|
||||
* @param companyNo
|
||||
* @return
|
||||
*/
|
||||
boolean delAuthChannelByCompanyNo(String companyNo);
|
||||
|
||||
/***
|
||||
* @description 按企业编号和配置类型查询对应的企业信息
|
||||
*
|
||||
* @param companyNo
|
||||
* @return
|
||||
*/
|
||||
AuthChannelVO findAuthChannelByCompanyNoAndChannelLabel(String companyNo, String channelLabel);
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.pojo.Company;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:企业服务类
|
||||
*/
|
||||
public interface ICompanyService extends IService<Company> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询客户分页列表
|
||||
* @param companyVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<Company>
|
||||
*/
|
||||
Page<CompanyVO> findCompanyPage(CompanyVO companyVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建客户
|
||||
* @param companyVO 对象信息
|
||||
* @return Company
|
||||
*/
|
||||
CompanyVO createCompany(CompanyVO companyVO);
|
||||
|
||||
/**
|
||||
* @Description 修改客户
|
||||
* @param companyVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateCompany(CompanyVO companyVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询客户列表
|
||||
* @param companyVO 查询条件
|
||||
* @return: List<Company>
|
||||
*/
|
||||
List<CompanyVO> findCompanyList(CompanyVO companyVO);
|
||||
|
||||
/***
|
||||
* @description 查找正式,适用且未有效所有企业
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<CompanyVO> findCompanyVOValidation();
|
||||
|
||||
/**
|
||||
* 根据企业编号查找企业数据
|
||||
* @param companyNo
|
||||
* @return
|
||||
*/
|
||||
CompanyVO findCompanyByNo(String companyNo);
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.security.pojo.Customer;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CustomerVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:客户服务类
|
||||
*/
|
||||
public interface ICustomerService extends IService<Customer> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询客户分页列表
|
||||
* @param customerVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<Customer>
|
||||
*/
|
||||
Page<CustomerVO> findCustomerPage(CustomerVO customerVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建客户
|
||||
* @param customerVO 对象信息
|
||||
* @return Customer
|
||||
*/
|
||||
CustomerVO createCustomer(CustomerVO customerVO);
|
||||
|
||||
/**
|
||||
* @Description 修改客户
|
||||
* @param customerVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateCustomer(CustomerVO customerVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询客户列表
|
||||
* @param customerVO 查询条件
|
||||
* @return: List<Customer>
|
||||
*/
|
||||
List<CustomerVO> findCustomerList(CustomerVO customerVO);
|
||||
|
||||
/***
|
||||
* @description 重置密码
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Boolean resetPassword(String userId);
|
||||
|
||||
/***
|
||||
* @description 用户名登录查询
|
||||
* @param username 用户名
|
||||
* @return
|
||||
*/
|
||||
UserVO usernameLogin(String username,String companyNo);
|
||||
|
||||
/***
|
||||
* @description 手机号登录查询
|
||||
* @param mobile 手机号
|
||||
* @return
|
||||
*/
|
||||
UserVO mobileLogin(String mobile,String companyNo);
|
||||
|
||||
/***
|
||||
* @description 微信号登录查询
|
||||
* @param openId 唯一识别号
|
||||
* @return
|
||||
*/
|
||||
UserVO wechatLogin(String openId,String companyNo);
|
||||
|
||||
/***
|
||||
* @description 重置密码
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Boolean resetPasswords(String userId);
|
||||
|
||||
/***
|
||||
* @description 发送登录验证码
|
||||
* @param mobile 手机号码
|
||||
* @return
|
||||
*/
|
||||
Boolean sendLoginCode(String mobile);
|
||||
|
||||
/**
|
||||
* 修改用户真实姓名
|
||||
* @param userId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
Boolean updateRealName(String userId, String name);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptPostUserVO;
|
||||
import com.itheima.sfbx.security.pojo.DeptPostUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:部门岗位用户关联表服务类
|
||||
*/
|
||||
public interface IDeptPostUserService extends IService<DeptPostUser> {
|
||||
|
||||
/**
|
||||
* @description 用户集合对应的部门岗位用户关联表列表
|
||||
* @param userIds 查询条件
|
||||
* @return: List<DeptPostUser>
|
||||
*/
|
||||
List<DeptPostUserVO> findDeptPostUserVOListInUserId(List<Long> userIds);
|
||||
|
||||
/***
|
||||
* @description 删除用户的部门职位
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteDeptPostUserByUserId(Long userId);
|
||||
|
||||
/***
|
||||
* @description 删除用户IDS的部门职位
|
||||
* @param userIds 用户id
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteDeptPostUserInUserId(List<String> userIds);
|
||||
|
||||
|
||||
/**
|
||||
* @description 用户的默认部门
|
||||
* @param userId 查询条件
|
||||
* @return: List<DeptPostUser>
|
||||
*/
|
||||
DeptPostUserVO findDeptPostUserVOByUserId(Long userId);
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptVO;
|
||||
import com.itheima.sfbx.security.pojo.Dept;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description:部门表服务类
|
||||
*/
|
||||
public interface IDeptService extends IService<Dept> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询部门表分页列表
|
||||
* @param deptVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<DeptVO>
|
||||
*/
|
||||
Page<DeptVO> findDeptPage(DeptVO deptVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建部门表
|
||||
* @param deptVO 对象信息
|
||||
* @return DeptVO
|
||||
*/
|
||||
DeptVO createDept(DeptVO deptVO);
|
||||
|
||||
/**
|
||||
* @Description 修改部门表
|
||||
* @param deptVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateDept(DeptVO deptVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询部门表列表
|
||||
* @param deptVO 查询条件
|
||||
* @return: List<DeptVO>
|
||||
*/
|
||||
List<DeptVO> findDeptList(DeptVO deptVO);
|
||||
|
||||
/**
|
||||
* @description 组织部门树形
|
||||
* @param parentDeptNo 根节点
|
||||
* @param checkedDeptNos 选择节点
|
||||
* @return: TreeVO
|
||||
*/
|
||||
TreeVO deptTreeVO(String parentDeptNo, String[] checkedDeptNos);
|
||||
|
||||
/**
|
||||
* @description 批量查詢部門
|
||||
* @param deptNos 查询条件
|
||||
* @return: TreeVO
|
||||
*/
|
||||
List<DeptVO> findDeptInDeptNos(Set<String> deptNos);
|
||||
|
||||
/**
|
||||
* @description 员工对应部门
|
||||
* @param userId 员工
|
||||
* @return: List<Dept>
|
||||
*/
|
||||
List<DeptVO> findDeptVOListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* @Description 创建编号
|
||||
* @param parentDeptNo 父部门编号
|
||||
* @return
|
||||
*/
|
||||
String createDeptNo(String parentDeptNo);
|
||||
|
||||
/***
|
||||
* @description 角色对应部门
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
List<DeptVO> findDeptVOListInRoleId(List<Long> roleIds);
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.security.pojo.Post;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.PostVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:岗位表服务类
|
||||
*/
|
||||
public interface IPostService extends IService<Post> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询岗位表分页列表
|
||||
* @param postVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<PostVO>
|
||||
*/
|
||||
Page<PostVO> findPostPage(PostVO postVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建岗位表
|
||||
* @param postVO 对象信息
|
||||
* @return PostVO
|
||||
*/
|
||||
PostVO createPost(PostVO postVO);
|
||||
|
||||
/**
|
||||
* @Description 修改岗位表
|
||||
* @param postVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updatePost(PostVO postVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询岗位表列表
|
||||
* @param postVO 查询条件
|
||||
* @return: List<PostVO>
|
||||
*/
|
||||
List<PostVO> findPostList(PostVO postVO);
|
||||
|
||||
/**
|
||||
* @description 人员对应职位
|
||||
* @param userId 查询条件
|
||||
* @return: List<PostVO>
|
||||
*/
|
||||
List<PostVO> findPostVOListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* @Description 创建编号
|
||||
* @param deptNo 部门编号
|
||||
* @return
|
||||
*/
|
||||
String createPostNo(String deptNo);
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.MenuVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.ResourceVO;
|
||||
import com.itheima.sfbx.security.pojo.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:权限表服务类
|
||||
*/
|
||||
public interface IResourceService extends IService<Resource> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询权限表分页列表
|
||||
* @param resourceVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<Resource>
|
||||
*/
|
||||
Page<ResourceVO> findResourcePage(ResourceVO resourceVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建权限表
|
||||
* @param resourceVO 对象信息
|
||||
* @return Resource
|
||||
*/
|
||||
ResourceVO createResource(ResourceVO resourceVO);
|
||||
|
||||
/**
|
||||
* @Description 修改权限表
|
||||
* @param resourceVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateResource(ResourceVO resourceVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询权限表列表
|
||||
* @param resourceVO 查询条件
|
||||
* @return: List<Resource>
|
||||
*/
|
||||
List<ResourceVO> findResourceList(ResourceVO resourceVO);
|
||||
|
||||
/**
|
||||
* @description 资源树形
|
||||
* @param parentResourceNo 根节点
|
||||
* @param checkedResourceNos 选择节点
|
||||
* @return: TreeVO
|
||||
*/
|
||||
TreeVO resourceTreeVO(String parentResourceNo, String[] checkedResourceNos);
|
||||
|
||||
/**
|
||||
* @description 角色对应资源
|
||||
* @param roleIds 角色s
|
||||
* @return: List<Resource>
|
||||
*/
|
||||
List<ResourceVO> findResourceVOListInRoleId(List<Long> roleIds);
|
||||
|
||||
/***
|
||||
* @description 查询左侧菜单
|
||||
* @param systemCode 系统编号
|
||||
* @return 菜单对象
|
||||
*/
|
||||
List<MenuVO> menus(String systemCode);
|
||||
|
||||
/**
|
||||
* @description 员工对应资源
|
||||
* @param userId 查询条件
|
||||
* @return: List<Resource>
|
||||
*/
|
||||
List<ResourceVO> findResourceVOListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* @Description 创建编号
|
||||
* @param parentResourceNo 父部门编号
|
||||
* @return
|
||||
*/
|
||||
String createResourceNo(String parentResourceNo);
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.security.pojo.RoleDept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName IRoleDeptService.java
|
||||
* @Description 角色部门关联表
|
||||
*/
|
||||
public interface IRoleDeptService extends IService<RoleDept> {
|
||||
|
||||
|
||||
/***
|
||||
* @description 删除角色对应数据权限
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteRoleDeptByRoleId(Long roleId);
|
||||
|
||||
/***
|
||||
* @description 批量删除
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteRoleDeptInRoleId(List<Long> roleIds);
|
||||
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.security.pojo.RoleResource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:角色资源关联表服务类
|
||||
*/
|
||||
public interface IRoleResourceService extends IService<RoleResource> {
|
||||
|
||||
/***
|
||||
* @description 按角色ID删除角色资源中间表
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteRoleResourceByRoleId(Long roleId);
|
||||
|
||||
/***
|
||||
* @description 按角色IDS删除角色资源中间表
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteRoleResourceInRoleId(List<Long> roleIds);
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.RoleVO;
|
||||
import com.itheima.sfbx.security.pojo.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:角色表服务类
|
||||
*/
|
||||
public interface IRoleService extends IService<Role> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询角色表分页列表
|
||||
* @param roleVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<ResourceVO>
|
||||
*/
|
||||
Page<RoleVO> findRolePage(RoleVO roleVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建角色表
|
||||
* @param roleVO 对象信息
|
||||
* @return ResourceVO
|
||||
*/
|
||||
RoleVO createRole(RoleVO roleVO);
|
||||
|
||||
/**
|
||||
* @Description 修改角色表
|
||||
* @param roleVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateRole(RoleVO roleVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询角色表列表
|
||||
* @param roleVO 查询条件
|
||||
* @return: List<ResourceVO>
|
||||
*/
|
||||
List<RoleVO> findRoleList(RoleVO roleVO);
|
||||
|
||||
/***
|
||||
* @description 员工们对应角色
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
List<RoleVO> findRoleVOListInUserId(List<Long> userIds);
|
||||
|
||||
/**
|
||||
* @description 员工对应角色
|
||||
* @param userId 查询条件
|
||||
* @return: List<Role>
|
||||
*/
|
||||
List<RoleVO> findRoleVOListByUserId(Long userId);
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.security.pojo.UserRole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:用户角色关联表服务类
|
||||
*/
|
||||
public interface IUserRoleService extends IService<UserRole> {
|
||||
|
||||
/***
|
||||
* @description 按用户ID删除用户角色中间表
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
*/
|
||||
boolean deleteUserRoleByUserId(Long userId);
|
||||
|
||||
/***
|
||||
* @description 按用户IDS删除用户角色中间表
|
||||
* @param userIds 用户id
|
||||
* @return
|
||||
*/
|
||||
boolean deleteUserRoleInUserId(List<Long> userIds);
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.itheima.sfbx.security.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DataSecurityVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.RoleVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.security.pojo.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:用户表服务类
|
||||
*/
|
||||
public interface IUserService extends IService<User> {
|
||||
|
||||
/**
|
||||
* @Description 多条件查询用户表分页列表
|
||||
* @param userVO 查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return Page<User>
|
||||
*/
|
||||
Page<UserVO> findUserPage(UserVO userVO, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* @Description 创建用户表
|
||||
* @param userVO 对象信息
|
||||
* @return User
|
||||
*/
|
||||
UserVO createUser(UserVO userVO);
|
||||
|
||||
/**
|
||||
* @Description 修改用户表
|
||||
* @param userVO 对象信息
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateUser(UserVO userVO);
|
||||
|
||||
/**
|
||||
* @description 多条件查询用户表列表
|
||||
* @param userVO 查询条件
|
||||
* @return: List<User>
|
||||
*/
|
||||
List<UserVO> findUserList(UserVO userVO);
|
||||
|
||||
/**
|
||||
* @description 部门下员工
|
||||
* @param deptNo 部门
|
||||
* @return: List<User>
|
||||
*/
|
||||
List<UserVO> findUserVOListByDeptNo(String deptNo);
|
||||
|
||||
/**
|
||||
* @description 角色下员工
|
||||
* @param roleId 角色
|
||||
* @return: List<User>
|
||||
*/
|
||||
List<UserVO> findUserVOListByRoleId(Long roleId);
|
||||
|
||||
/***
|
||||
* @description 重置密码
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Boolean resetPasswords(String userId);
|
||||
|
||||
/***
|
||||
* @description 查询用户数据权限
|
||||
* @param roleVOList 角色列表
|
||||
* @param userId 用户
|
||||
* @return
|
||||
*/
|
||||
DataSecurityVO userDataSecurity(List<RoleVO> roleVOList, Long userId);
|
||||
|
||||
/***
|
||||
* @description 用户名登录查询
|
||||
* @param username 用户名
|
||||
* @return: com.itheima.easy.vo.UserVO
|
||||
*/
|
||||
UserVO usernameLogin(String username,String companyNo);
|
||||
|
||||
/***
|
||||
* @description 手机号登录查询
|
||||
* @param mobile 手机号
|
||||
* @return: com.itheima.easy.vo.UserVO
|
||||
*/
|
||||
UserVO mobileLogin(String mobile,String companyNo);
|
||||
|
||||
/***
|
||||
* @description 微信号登录查询
|
||||
* @param openId 唯一识别号
|
||||
* @return: com.itheima.easy.vo.UserVO
|
||||
*/
|
||||
UserVO wechatLogin(String openId,String companyNo);
|
||||
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.AuthChannelCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.OtherConfigVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.AuthChannelVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthChannelEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.security.mapper.AuthChannelMapper;
|
||||
import com.itheima.sfbx.security.pojo.AuthChannel;
|
||||
import com.itheima.sfbx.security.service.IAuthChannelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:三方授权渠道信息
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AuthChannelServiceImpl extends ServiceImpl<AuthChannelMapper, AuthChannel> implements IAuthChannelService {
|
||||
|
||||
@Autowired
|
||||
AuthChannelMapper authChannelMapper;
|
||||
|
||||
/***
|
||||
* @description 构建多条件查询
|
||||
* @param queryWrapper 查询条件
|
||||
* @param authChannelVO 查询对象
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<AuthChannel> queryWrapper(QueryWrapper<AuthChannel> queryWrapper,AuthChannelVO authChannelVO){
|
||||
//渠道名称
|
||||
if (!EmptyUtil.isNullOrEmpty(authChannelVO.getChannelName())) {
|
||||
queryWrapper.lambda().likeRight(AuthChannel::getChannelName,authChannelVO.getChannelName());
|
||||
}
|
||||
//更新者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(authChannelVO.getAppId())) {
|
||||
queryWrapper.lambda().eq(AuthChannel::getAppId,authChannelVO.getAppId());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(authChannelVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(AuthChannel::getDataState,authChannelVO.getDataState());
|
||||
}
|
||||
//按创建时间降序
|
||||
queryWrapper.lambda().orderByDesc(AuthChannel::getCreateTime);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = AuthChannelCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#authChannelVO.hashCode()")
|
||||
public Page<AuthChannelVO> findAuthChannelPage(AuthChannelVO authChannelVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<AuthChannel> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<AuthChannel> queryWrapper = new QueryWrapper<>();
|
||||
//多条件查询
|
||||
this.queryWrapper(queryWrapper,authChannelVO);
|
||||
//执行分页查询
|
||||
Page<AuthChannelVO> pageVo = BeanConv.toPage(page(page, queryWrapper), AuthChannelVO.class);
|
||||
List<AuthChannelVO> records = pageVo.getRecords();
|
||||
if (!EmptyUtil.isNullOrEmpty(records)){
|
||||
records.forEach(n->{
|
||||
if (!EmptyUtil.isNullOrEmpty(n.getOtherConfig())){
|
||||
List<OtherConfigVO> list = JSONArray.parseArray(n.getOtherConfig(),OtherConfigVO.class);
|
||||
n.setOtherConfigVOs(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
pageVo.setRecords(records);
|
||||
return pageVo;
|
||||
}catch (Exception e){
|
||||
log.error("客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = AuthChannelCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = AuthChannelCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =AuthChannelCacheConstant.BASIC,key = "#result.id")})
|
||||
public AuthChannelVO createAuthChannel(AuthChannelVO authChannelVO) {
|
||||
try {
|
||||
//转换AuthChannelVO为AuthChannel
|
||||
AuthChannel authChannel = BeanConv.toBean(authChannelVO, AuthChannel.class);
|
||||
authChannel.setOtherConfig(JSONObject.toJSONString(authChannelVO.getOtherConfigVOs()));
|
||||
boolean flag = save(authChannel);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存客户信息出错");
|
||||
}
|
||||
return BeanConv.toBean(authChannel, AuthChannelVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("保存客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = AuthChannelCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = AuthChannelCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = AuthChannelCacheConstant.BASIC,key = "#authChannelVO.id")})
|
||||
public Boolean updateAuthChannel(AuthChannelVO authChannelVO) {
|
||||
try {
|
||||
//转换AuthChannelVO为AuthChannel
|
||||
AuthChannel authChannel = BeanConv.toBean(authChannelVO, AuthChannel.class);
|
||||
authChannel.setOtherConfig(JSONObject.toJSONString(authChannelVO.getOtherConfigVOs()));
|
||||
boolean flag = updateById(authChannel);
|
||||
if (!flag){
|
||||
throw new RuntimeException("修改客户信息出错");
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
log.error("修改客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.UPDATE_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = AuthChannelCacheConstant.LIST,key ="#authChannelVO.hashCode()")
|
||||
public List<AuthChannelVO> findAuthChannelList(AuthChannelVO authChannelVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<AuthChannel> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,authChannelVO);
|
||||
List<AuthChannelVO> records = BeanConv.toBeanList(list(queryWrapper), AuthChannelVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(records)){
|
||||
records.forEach(n->{
|
||||
if (!EmptyUtil.isNullOrEmpty(n.getOtherConfig())){
|
||||
List<OtherConfigVO> list = JSONArray.parseArray(n.getOtherConfig(),OtherConfigVO.class);
|
||||
n.setOtherConfigVOs(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
return records;
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.LIST_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = AuthChannelCacheConstant.LIST,key ="#companyNos.hashCode()")
|
||||
public List<AuthChannelVO> findAuthChannelListInCompanyNos(List<String> companyNos) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<AuthChannel> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().in(AuthChannel::getCompanyNo,companyNos);
|
||||
return BeanConv.toBeanList(list(queryWrapper),AuthChannelVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delAuthChannelByCompanyNo(String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
UpdateWrapper<AuthChannel> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().eq(AuthChannel::getCompanyNo,companyNo);
|
||||
return this.remove(updateWrapper);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.DEL_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthChannelVO findAuthChannelByCompanyNoAndChannelLabel(String companyNo, String channelLabel) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<AuthChannel> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(AuthChannel::getCompanyNo,companyNo)
|
||||
.eq(AuthChannel::getChannelLabel,channelLabel);
|
||||
return BeanConv.toBean(getOne(queryWrapper),AuthChannelVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(AuthChannelEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CompanyCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CompanyConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.AuthChannelVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.CompanyEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.security.init.InitCompany;
|
||||
import com.itheima.sfbx.security.mapper.AuthChannelMapper;
|
||||
import com.itheima.sfbx.security.mapper.CompanyMapper;
|
||||
import com.itheima.sfbx.security.pojo.AuthChannel;
|
||||
import com.itheima.sfbx.security.pojo.Company;
|
||||
import com.itheima.sfbx.security.service.IAuthChannelService;
|
||||
import com.itheima.sfbx.security.service.ICompanyService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:公司表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements ICompanyService {
|
||||
|
||||
@Autowired
|
||||
CompanyMapper companyMapper;
|
||||
|
||||
@Autowired
|
||||
IAuthChannelService authChannelService;
|
||||
|
||||
/**
|
||||
* @description 构建多条件查询
|
||||
* @param queryWrapper 查询条件
|
||||
* @param companyVO 查询对象
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<Company> queryWrapper(QueryWrapper<Company> queryWrapper,CompanyVO companyVO){
|
||||
//负责人手机
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getLeaderMobile())) {
|
||||
queryWrapper.lambda().likeRight(Company::getLeaderMobile,companyVO.getLeaderMobile());
|
||||
}
|
||||
//负责人姓名
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getLeaderName())) {
|
||||
queryWrapper.lambda().likeRight(Company::getLeaderName,companyVO.getLeaderName());
|
||||
}
|
||||
//公司编号
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getCompanyNo())) {
|
||||
queryWrapper.lambda().likeRight(Company::getCompanyNo,companyVO.getCompanyNo());
|
||||
}
|
||||
//公司名称
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getCompanName())) {
|
||||
queryWrapper.lambda().likeRight(Company::getCompanName,companyVO.getCompanName());
|
||||
}
|
||||
//统一社会信用代码
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getRegisteredNo())) {
|
||||
queryWrapper.lambda().likeRight(Company::getRegisteredNo,companyVO.getRegisteredNo());
|
||||
}
|
||||
//公司邮箱查询
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getEmail())) {
|
||||
queryWrapper.lambda().likeRight(Company::getEmail,companyVO.getEmail());
|
||||
}
|
||||
//创建者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(Company::getCreateBy,companyVO.getCreateBy());
|
||||
}
|
||||
//更新者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(Company::getUpdateBy,companyVO.getUpdateBy());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(Company::getDataState,companyVO.getDataState());
|
||||
}
|
||||
//公司id查询
|
||||
if (!EmptyUtil.isNullOrEmpty(companyVO.getCheckIds())) {
|
||||
queryWrapper.lambda().in(Company::getId,companyVO.getCheckIds());
|
||||
}
|
||||
//按创建时间降序
|
||||
queryWrapper.lambda().orderByDesc(Company::getCreateTime);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CompanyCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#companyVO.hashCode()")
|
||||
public Page<CompanyVO> findCompanyPage(CompanyVO companyVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<Company> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
|
||||
//多条件查询
|
||||
this.queryWrapper(queryWrapper,companyVO);
|
||||
//执行分页查询
|
||||
Page<CompanyVO> pageResult = BeanConv.toPage(page(page, queryWrapper),CompanyVO.class);
|
||||
return pageResult;
|
||||
}catch (Exception e){
|
||||
log.error("公司表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CompanyEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
InitCompany initCompany;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = CompanyCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = CompanyCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =CompanyCacheConstant.BASIC,key = "#result.id")})
|
||||
public CompanyVO createCompany(CompanyVO companyVO) {
|
||||
try {
|
||||
//转换CompanyVO为Company
|
||||
Company company = BeanConv.toBean(companyVO, Company.class);
|
||||
boolean flag = save(company);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存公司信息出错");
|
||||
}
|
||||
CompanyVO companyVOResult = BeanConv.toBean(company, CompanyVO.class);
|
||||
//同步缓存
|
||||
initCompany.addWebSiteforRedis(companyVOResult);
|
||||
return companyVOResult;
|
||||
} catch (Exception e) {
|
||||
log.error("保存公司表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CompanyEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = CompanyCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = CompanyCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = CompanyCacheConstant.BASIC,key = "#companyVO.id")})
|
||||
public Boolean updateCompany(CompanyVO companyVO) {
|
||||
try {
|
||||
//转换CompanyVO为Company
|
||||
Company company = BeanConv.toBean(companyVO, Company.class);
|
||||
boolean flag = updateById(company);
|
||||
if (!flag){
|
||||
throw new RuntimeException("修改公司信息出错");
|
||||
} else {
|
||||
initCompany.updataWebSiteforRedis(companyVO);
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
log.error("修改公司表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CompanyEnum.UPDATE_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CompanyCacheConstant.LIST,key ="#companyVO.hashCode()")
|
||||
public List<CompanyVO> findCompanyList(CompanyVO companyVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,companyVO);
|
||||
return BeanConv.toBeanList(list(queryWrapper), CompanyVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询公司表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CompanyEnum.LIST_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompanyVO> findCompanyVOValidation() {
|
||||
QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Company::getDataState, SuperConstant.DATA_STATE_0)
|
||||
.and(wrapper->wrapper
|
||||
.eq(Company::getStatus, CompanyConstant.status_1)
|
||||
.or()
|
||||
.eq(Company::getStatus,CompanyConstant.status_2));
|
||||
return BeanConv.toBeanList(list(queryWrapper), CompanyVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyVO findCompanyByNo(String companyNo) {
|
||||
QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Company::getCompanyNo,companyNo);
|
||||
CompanyVO companyVOs = BeanConv.toBean(getOne(queryWrapper), CompanyVO.class);
|
||||
return companyVOs;
|
||||
}
|
||||
}
|
||||
+354
@@ -0,0 +1,354 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.itheima.sfbx.file.feign.FileBusinessFeign;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CompanyCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.CustomerCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.sms.SmsConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.file.FileVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CustomerVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.sms.SendMessageVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.AuthEnum;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.CustomerEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.security.mapper.CustomerMapper;
|
||||
import com.itheima.sfbx.security.pojo.Customer;
|
||||
import com.itheima.sfbx.security.service.ICustomerService;
|
||||
import com.itheima.sfbx.sms.feign.SmsSendFeign;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Description:客户表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
|
||||
|
||||
@Autowired
|
||||
CustomerMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@Autowired
|
||||
SecurityConfigProperties securityConfigProperties;
|
||||
|
||||
@Autowired
|
||||
FileBusinessFeign fileBusinessFeign;
|
||||
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
/***
|
||||
* @description 构建多条件查询
|
||||
* @param queryWrapper 查询条件
|
||||
* @param customerVO 查询对象
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<Customer> queryWrapper(QueryWrapper<Customer> queryWrapper,CustomerVO customerVO){
|
||||
//客户账号查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getUsername())) {
|
||||
queryWrapper.lambda().eq(Customer::getUsername,customerVO.getUsername());
|
||||
}
|
||||
//open_id标识查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getOpenId())) {
|
||||
queryWrapper.lambda().eq(Customer::getOpenId,customerVO.getOpenId());
|
||||
}
|
||||
//客户昵称查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getNickName())) {
|
||||
queryWrapper.lambda().likeRight(Customer::getNickName,customerVO.getNickName());
|
||||
}
|
||||
//客户邮箱查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getEmail())) {
|
||||
queryWrapper.lambda().likeRight(Customer::getEmail,customerVO.getEmail());
|
||||
}
|
||||
//真实姓名查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getRealName())) {
|
||||
queryWrapper.lambda().likeRight(Customer::getRealName,customerVO.getRealName());
|
||||
}
|
||||
//手机号码查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getMobile())) {
|
||||
queryWrapper.lambda().likeRight(Customer::getMobile,customerVO.getMobile());
|
||||
}
|
||||
//客户性别(0男 1女 2未知)查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getSex())) {
|
||||
queryWrapper.lambda().eq(Customer::getSex,customerVO.getSex());
|
||||
}
|
||||
//创建者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(Customer::getCreateBy,customerVO.getCreateBy());
|
||||
}
|
||||
//更新者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(Customer::getUpdateBy,customerVO.getUpdateBy());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(Customer::getDataState,customerVO.getDataState());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(customerVO.getId())) {
|
||||
queryWrapper.lambda().like(Customer::getId,customerVO.getId());
|
||||
}
|
||||
//按创建时间降序
|
||||
queryWrapper.lambda().orderByDesc(Customer::getCreateTime);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CustomerCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#customerVO.hashCode()")
|
||||
public Page<CustomerVO> findCustomerPage(CustomerVO customerVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<Customer> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
|
||||
//多条件查询
|
||||
this.queryWrapper(queryWrapper,customerVO);
|
||||
//执行分页查询
|
||||
return BeanConv.toPage(page(page, queryWrapper),CustomerVO.class);
|
||||
}catch (Exception e){
|
||||
log.error("客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = CustomerCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = CustomerCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =CustomerCacheConstant.BASIC,key = "#result.id")})
|
||||
public CustomerVO createCustomer(CustomerVO customerVO) {
|
||||
try {
|
||||
//设置公司id--从request中获取域名
|
||||
String host = request.getHeaders("x-forwarded-host").nextElement().split(",")[0].split(":")[0];
|
||||
String key = CompanyCacheConstant.WEBSITE+host;
|
||||
//域名校验
|
||||
RBucket<CompanyVO> bucket = redissonClient.getBucket(key);
|
||||
CompanyVO companyVO = bucket.get();
|
||||
if (EmptyUtil.isNullOrEmpty(companyVO)){
|
||||
throw new ProjectException(AuthEnum.HSOT_FAIL);
|
||||
}
|
||||
customerVO.setCompanyNo(companyVO.getCompanyNo());
|
||||
//转换CustomerVO为Customer
|
||||
String password = bCryptPasswordEncoder.encode(securityConfigProperties.getPassworddDfaule());
|
||||
customerVO.setPassword(password);
|
||||
//保存账号
|
||||
Customer customer = BeanConv.toBean(customerVO, Customer.class);
|
||||
boolean flag = save(customer);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存客户信息出错");
|
||||
}
|
||||
// //保存附件信息
|
||||
// if (EmptyUtil.isNullOrEmpty(customerVO.getFileVOs())){
|
||||
// throw new RuntimeException("头像为空");
|
||||
// }
|
||||
// //构建附件对象
|
||||
// customerVO.getFileVOs().forEach(fileVO -> {
|
||||
// fileVO.setBusinessId(customer.getId());
|
||||
// });
|
||||
// //调用附件接口
|
||||
// List<FileVO> fileVOs = fileBusinessFeign.bindBatchFile(Lists.newArrayList(customerVO.getFileVOs()));
|
||||
// if (EmptyUtil.isNullOrEmpty(fileVOs)){
|
||||
// throw new RuntimeException("头像绑定失败");
|
||||
// }
|
||||
//转换返回对象VO
|
||||
return BeanConv.toBean(customer, CustomerVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("保存客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = CustomerCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = CustomerCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = CustomerCacheConstant.LOGIN,key = "#customerVO.username"),
|
||||
@CacheEvict(value = CustomerCacheConstant.LOGIN,key = "#customerVO.openId"),
|
||||
@CacheEvict(value = CustomerCacheConstant.LOGIN,key = "#customerVO.mobile"),
|
||||
@CacheEvict(value = CustomerCacheConstant.BASIC,key = "#customerVO.id")})
|
||||
public Boolean updateCustomer(CustomerVO customerVO) {
|
||||
try {
|
||||
//转换CustomerVO为Customer
|
||||
Customer user = BeanConv.toBean(customerVO, Customer.class);
|
||||
boolean flag = updateById(user);
|
||||
if (!flag){
|
||||
throw new RuntimeException("修改客户信息出错");
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
log.error("修改客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.UPDATE_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CustomerCacheConstant.LIST,key ="#customerVO.hashCode()")
|
||||
public List<CustomerVO> findCustomerList(CustomerVO customerVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,customerVO);
|
||||
return BeanConv.toBeanList(list(queryWrapper),CustomerVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.LIST_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean resetPassword(String customerId) {
|
||||
try {
|
||||
String password = bCryptPasswordEncoder.encode(securityConfigProperties.getPassworddDfaule());
|
||||
Customer customer = Customer.builder().id(Long.valueOf(customerId)).password(password).build();
|
||||
return updateById(customer);
|
||||
} catch (Exception e) {
|
||||
log.error("重置密码:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.RESET_PASSWORD_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CustomerCacheConstant.LOGIN,key ="#username+'-'+#companyNo")
|
||||
public UserVO usernameLogin(String username,String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Customer::getUsername,username).eq(Customer::getCompanyNo,companyNo)
|
||||
.eq(Customer::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper),UserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.FIND_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CustomerCacheConstant.LOGIN,key ="#mobile+'-'+#companyNo")
|
||||
public UserVO mobileLogin(String mobile,String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Customer::getMobile,mobile).eq(Customer::getCompanyNo,companyNo)
|
||||
.eq(Customer::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper),UserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.FIND_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CustomerCacheConstant.LOGIN,key ="#openId+'-'+#companyNo")
|
||||
public UserVO wechatLogin(String openId,String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Customer::getOpenId,openId).eq(Customer::getCompanyNo,companyNo)
|
||||
.eq(Customer::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper),UserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(CustomerEnum.FIND_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean resetPasswords(String userId) {
|
||||
//随机生成密码
|
||||
String password = bCryptPasswordEncoder.encode(securityConfigProperties.getPassworddDfaule());
|
||||
//短信通知:用户id查询手机号码
|
||||
Customer customer = Customer.builder().id(Long.valueOf(userId)).password(password).build();
|
||||
return updateById(customer);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
SmsSendFeign smsSendFeign;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@Override
|
||||
public Boolean sendLoginCode(String mobile) {
|
||||
String key = SuperConstant.LOGIN_CODE+mobile;
|
||||
RBucket<String> bucket = redissonClient.getBucket(key);
|
||||
//已经发送直接重置时间
|
||||
if (!EmptyUtil.isNullOrEmpty(bucket.get())){
|
||||
bucket.expire(300, TimeUnit.SECONDS);
|
||||
return true;
|
||||
}
|
||||
//存储手机发送的验证码到存在中
|
||||
String code = String.valueOf((int)((Math.random()*9+1)*100000));
|
||||
bucket.set(code,300, TimeUnit.SECONDS);
|
||||
String templateNo = "template_00001";
|
||||
String sginNo= "sign_0001";
|
||||
String loadBalancerType= SmsConstant.ROUND_ROBIN;
|
||||
Set<String> mobiles=new HashSet<>();
|
||||
mobiles.add(mobile);
|
||||
LinkedHashMap<String,String> templateParam = new LinkedHashMap<>();
|
||||
templateParam.put("code",code);
|
||||
SendMessageVO sendMessageVo = SendMessageVO.builder()
|
||||
.templateNo(templateNo)
|
||||
.sginNo(sginNo)
|
||||
.loadBalancerType(loadBalancerType)
|
||||
.mobiles(mobiles)
|
||||
.templateParam(templateParam)
|
||||
.build();
|
||||
System.out.println("验证码:" + sendMessageVo.toString());
|
||||
return true;
|
||||
//TODO 开发环境不真实发送手机短信验证码
|
||||
//return smsSendFeign.sendSmsForMq(sendMessageVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户真实姓名
|
||||
* @param userId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateRealName(String userId, String name) {
|
||||
LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Customer::getId,userId);
|
||||
queryWrapper.eq(Customer::getDataState,SuperConstant.DATA_STATE_0);
|
||||
Customer customer = getOne(queryWrapper);
|
||||
customer.setRealName(name);
|
||||
return updateById(customer);
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.DeptPostUserCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptPostUserVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.DeptPostUserEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.security.mapper.DeptPostUserMapper;
|
||||
import com.itheima.sfbx.security.pojo.DeptPostUser;
|
||||
import com.itheima.sfbx.security.service.IDeptPostUserService;
|
||||
import com.itheima.sfbx.security.service.IDeptService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:部门岗位用户关联表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeptPostUserServiceImpl extends ServiceImpl<DeptPostUserMapper, DeptPostUser> implements IDeptPostUserService {
|
||||
|
||||
@Autowired
|
||||
IDeptService deptService;
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptPostUserCacheConstant.DEPT_POST_USER_VO,key ="#userIds.hashCode()")
|
||||
public List<DeptPostUserVO> findDeptPostUserVOListInUserId(List<Long> userIds) {
|
||||
try {
|
||||
QueryWrapper<DeptPostUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().in(DeptPostUser::getUserId,userIds)
|
||||
.eq(DeptPostUser::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBeanList(list(queryWrapper),DeptPostUserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门职位人员异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptPostUserEnum.LIST_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@CacheEvict(value = DeptPostUserCacheConstant.DEPT_POST_USER_VO,key ="#userId")
|
||||
public Boolean deleteDeptPostUserByUserId(Long userId) {
|
||||
try {
|
||||
UpdateWrapper<DeptPostUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().eq(DeptPostUser::getUserId,userId);
|
||||
return remove(updateWrapper);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门职位人员异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptPostUserEnum.DEL_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@CacheEvict(value = DeptPostUserCacheConstant.DEPT_POST_USER_VO,allEntries = true)
|
||||
public Boolean deleteDeptPostUserInUserId(List<String> userIds) {
|
||||
try {
|
||||
UpdateWrapper<DeptPostUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().in(DeptPostUser::getUserId,userIds);
|
||||
return remove(updateWrapper);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门职位人员异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptPostUserEnum.DEL_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptPostUserCacheConstant.DEPT_POST_USER_VO,key ="#userId")
|
||||
public DeptPostUserVO findDeptPostUserVOByUserId(Long userId) {
|
||||
try {
|
||||
QueryWrapper<DeptPostUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda()
|
||||
.eq(DeptPostUser::getUserId,userId)
|
||||
.eq(DeptPostUser::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper),DeptPostUserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门职位人员异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptPostUserEnum.LIST_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.DeptCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.PostCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.RoleCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.UserCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeItemVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.DeptEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.NoProcessing;
|
||||
import com.itheima.sfbx.security.mapper.DeptMapper;
|
||||
import com.itheima.sfbx.security.pojo.Dept;
|
||||
import com.itheima.sfbx.security.service.IDeptService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:部门表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {
|
||||
|
||||
@Autowired
|
||||
DeptMapper deptMapper;
|
||||
|
||||
/***
|
||||
* @description 多条件查询
|
||||
* @param queryWrapper 条件对象
|
||||
* @param deptVO 查询条件
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<Dept> queryWrapper(QueryWrapper<Dept> queryWrapper, DeptVO deptVO){
|
||||
//父部门编号查询
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getParentDeptNo())) {
|
||||
queryWrapper.lambda().likeRight(Dept::getParentDeptNo, NoProcessing.processString(deptVO.getParentDeptNo()));
|
||||
}
|
||||
//部门编号
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getDeptNo())) {
|
||||
queryWrapper.lambda().likeRight(Dept::getDeptNo,deptVO.getDeptNo());
|
||||
}
|
||||
//部门名称查询
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getDeptName())) {
|
||||
queryWrapper.lambda().likeRight(Dept::getDeptName,deptVO.getDeptName());
|
||||
}
|
||||
//排序查询
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getSortNo())) {
|
||||
queryWrapper.lambda().eq(Dept::getSortNo,deptVO.getSortNo());
|
||||
}
|
||||
//创建者:username查询
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(Dept::getCreateBy,deptVO.getCreateBy());
|
||||
}
|
||||
//更新者:username查询
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(Dept::getUpdateBy,deptVO.getUpdateBy());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(Dept::getDataState,deptVO.getDataState());
|
||||
}
|
||||
//按sottNo降序
|
||||
queryWrapper.lambda().orderByAsc(Dept::getSortNo);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#deptVO.hashCode()")
|
||||
public Page<DeptVO> findDeptPage(DeptVO deptVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<Dept> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,deptVO);
|
||||
//执行分页查询
|
||||
return BeanConv.toPage(page(page, queryWrapper),DeptVO.class);
|
||||
}catch (Exception e){
|
||||
log.error("部门表PAGE异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.PAGE_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = DeptCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = DeptCacheConstant.TREE,allEntries = true),
|
||||
@CacheEvict(value = DeptCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =DeptCacheConstant.BASIC,key = "#result.id")})
|
||||
public DeptVO createDept(DeptVO deptVO) {
|
||||
try {
|
||||
//转换DeptVO为Dept
|
||||
Dept dept = BeanConv.toBean(deptVO, Dept.class);
|
||||
dept.setDeptNo(this.createDeptNo(dept.getParentDeptNo()));
|
||||
boolean flag = save(dept);
|
||||
if (flag){
|
||||
return BeanConv.toBean(dept,DeptVO.class);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("保存部门表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.SAVE_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = DeptCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = DeptCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = DeptCacheConstant.TREE,allEntries = true),
|
||||
@CacheEvict(value = PostCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = PostCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = RoleCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = RoleCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value =DeptCacheConstant.BASIC,key = "#deptVO.id")})
|
||||
public Boolean updateDept(DeptVO deptVO) {
|
||||
try {
|
||||
//转换DeptVO为Dept
|
||||
Dept dept = BeanConv.toBean(deptVO, Dept.class);
|
||||
return updateById(dept);
|
||||
} catch (Exception e) {
|
||||
log.error("修改部门表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.UPDATE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptCacheConstant.LIST,key ="#deptVO.hashCode()")
|
||||
public List<DeptVO> findDeptList(DeptVO deptVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,deptVO);
|
||||
return BeanConv.toBeanList(list(queryWrapper),DeptVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptCacheConstant.TREE,key ="#parentDeptNo+'-'+#checkedDeptNos")
|
||||
public TreeVO deptTreeVO(String parentDeptNo, String[] checkedDeptNos) {
|
||||
try {
|
||||
//根节点查询树形结构
|
||||
if (EmptyUtil.isNullOrEmpty(parentDeptNo)){
|
||||
parentDeptNo = SuperConstant.ROOT_PARENT_ID;
|
||||
}
|
||||
List<Dept> deptList = Lists.newLinkedList();
|
||||
QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
|
||||
//指定节点查询树形结构
|
||||
queryWrapper.lambda().eq(Dept::getDataState, SuperConstant.DATA_STATE_0)
|
||||
.likeRight(Dept::getParentDeptNo,NoProcessing.processString(parentDeptNo))
|
||||
.orderByAsc(Dept::getSortNo);
|
||||
deptList.addAll(list(queryWrapper));
|
||||
if (EmptyUtil.isNullOrEmpty(deptList)){
|
||||
throw new RuntimeException("部门信息为定义!");
|
||||
}
|
||||
List<TreeItemVO> treeItemVOList = new ArrayList<>();
|
||||
List<String> expandedIds = new ArrayList<>();
|
||||
//递归构建树形结构
|
||||
List<String> checkedDeptNoList = Lists.newArrayList();
|
||||
if (!EmptyUtil.isNullOrEmpty(checkedDeptNos)){
|
||||
checkedDeptNoList = Arrays.asList(checkedDeptNos);
|
||||
}
|
||||
Dept rootDept = deptList.stream()
|
||||
.filter(d -> SuperConstant.ROOT_PARENT_ID.equals(d.getParentDeptNo()))
|
||||
.collect(Collectors.toList()).get(0);
|
||||
recursionTreeItem(treeItemVOList,rootDept,deptList,checkedDeptNoList,expandedIds);
|
||||
return TreeVO.builder()
|
||||
.items(treeItemVOList)
|
||||
.checkedIds(checkedDeptNoList)
|
||||
.expandedIds(expandedIds)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门表TREE异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.TREE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
private void recursionTreeItem(List<TreeItemVO> treeItemVOList, Dept DeptRoot, List<Dept> deptList,
|
||||
List<String> checkedDeptNos, List<String> expandedIds) {
|
||||
TreeItemVO treeItem = TreeItemVO.builder()
|
||||
.id(DeptRoot.getDeptNo())
|
||||
.label(DeptRoot.getDeptName())
|
||||
.build();
|
||||
//判断是否选择
|
||||
if (!EmptyUtil.isNullOrEmpty(checkedDeptNos)&&checkedDeptNos.contains(DeptRoot.getDeptNo())){
|
||||
treeItem.setIsChecked(true);
|
||||
}else {
|
||||
treeItem.setIsChecked(false);
|
||||
}
|
||||
//是否默认展开:如果当前的部门为第二层或者第三层则展开
|
||||
if(NoProcessing.processString(DeptRoot.getDeptNo()).length()/3==3){
|
||||
expandedIds.add(DeptRoot.getDeptNo());
|
||||
}
|
||||
//获得当前部门下子部门
|
||||
List<Dept> childrenDept = deptList.stream()
|
||||
.filter(n -> n.getParentDeptNo().equals(DeptRoot.getDeptNo()))
|
||||
.collect(Collectors.toList());
|
||||
if (!EmptyUtil.isNullOrEmpty(childrenDept)){
|
||||
List<TreeItemVO> listChildren = Lists.newArrayList();
|
||||
childrenDept.forEach(n->{
|
||||
this.recursionTreeItem(listChildren,n,deptList,checkedDeptNos,expandedIds);});
|
||||
treeItem.setChildren(listChildren);
|
||||
}
|
||||
treeItemVOList.add(treeItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptCacheConstant.TREE,key ="#deptNos.hashCode()")
|
||||
public List<DeptVO> findDeptInDeptNos(Set<String> deptNos) {
|
||||
try {
|
||||
QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().in(Dept::getDeptNo,deptNos)
|
||||
.eq(Dept::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBeanList(list(queryWrapper),DeptVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门表TREE异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.TREE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptCacheConstant.LIST,key ="#userId")
|
||||
public List<DeptVO> findDeptVOListByUserId(Long userId) {
|
||||
try {
|
||||
return deptMapper.findDeptVOListByUserId(userId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(DeptEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = DeptCacheConstant.LIST,key ="#roleIds.hashCode()")
|
||||
public List<DeptVO> findDeptVOListInRoleId(List<Long> roleIds) {
|
||||
return deptMapper.findDeptVOListInRoleId(roleIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createDeptNo(String parentDeptNo) {
|
||||
QueryWrapper<Dept> queryWrapper = new QueryWrapper();
|
||||
queryWrapper.lambda().eq(Dept::getParentDeptNo,parentDeptNo);
|
||||
List<Dept> deptList = deptMapper.selectList(queryWrapper);
|
||||
//无下属节点则创建下属节点
|
||||
if (EmptyUtil.isNullOrEmpty(deptList)){
|
||||
return NoProcessing.createNo(parentDeptNo,false);
|
||||
//有下属节点则累加下属节点
|
||||
}else {
|
||||
Long deptNo = deptList.stream()
|
||||
.map(dept -> { return Long.valueOf(dept.getDeptNo());})
|
||||
.max(Comparator.comparing(i -> i)).get();
|
||||
return NoProcessing.createNo(String.valueOf(deptNo),true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.PostCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.PostVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.PostEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.NoProcessing;
|
||||
import com.itheima.sfbx.security.mapper.PostMapper;
|
||||
import com.itheima.sfbx.security.pojo.Dept;
|
||||
import com.itheima.sfbx.security.pojo.Post;
|
||||
import com.itheima.sfbx.security.service.IDeptService;
|
||||
import com.itheima.sfbx.security.service.IPostService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:岗位表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IPostService {
|
||||
|
||||
@Autowired
|
||||
PostMapper postMapper;
|
||||
|
||||
@Autowired
|
||||
IDeptService deptService;
|
||||
|
||||
/***
|
||||
* @description 多条件查询
|
||||
* @param queryWrapper
|
||||
* @param postVO
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<Post> queryWrapper(QueryWrapper<Post> queryWrapper, PostVO postVO){
|
||||
//部门编号
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getDeptNo())) {
|
||||
queryWrapper.lambda().likeRight(Post::getDeptNo, NoProcessing.processString(postVO.getDeptNo()));
|
||||
}
|
||||
//岗位编码:父部门编号+01【2位】查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getPostNo())) {
|
||||
queryWrapper.lambda().eq(Post::getPostNo,postVO.getPostNo());
|
||||
}
|
||||
//岗位名称查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getPostName())) {
|
||||
queryWrapper.lambda().likeRight(Post::getPostName,postVO.getPostName());
|
||||
}
|
||||
//显示顺序查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getSortNo())) {
|
||||
queryWrapper.lambda().eq(Post::getSortNo,postVO.getSortNo());
|
||||
}
|
||||
//创建者:username查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(Post::getCreateBy,postVO.getCreateBy());
|
||||
}
|
||||
//更新者:username查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(Post::getUpdateBy,postVO.getUpdateBy());
|
||||
}
|
||||
//备注查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getRemark())) {
|
||||
queryWrapper.lambda().eq(Post::getRemark,postVO.getRemark());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(postVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(Post::getDataState,postVO.getDataState());
|
||||
}
|
||||
//按sortNo降序
|
||||
queryWrapper.lambda().orderByAsc(Post::getSortNo);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = PostCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#postVO.hashCode()")
|
||||
public Page<PostVO> findPostPage(PostVO postVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//查询职位
|
||||
//构建分页对象
|
||||
Page<Post> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<Post> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,postVO);
|
||||
//执行分页查询
|
||||
Page<PostVO> pageVo = BeanConv.toPage(page(page, queryWrapper),PostVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(pageVo.getRecords())){
|
||||
//对应部门
|
||||
Set<String> deptNos = pageVo.getRecords().stream().map(PostVO::getDeptNo).collect(Collectors.toSet());
|
||||
List<DeptVO> deptVOList = deptService.findDeptInDeptNos(deptNos);
|
||||
pageVo.getRecords().forEach(n->{
|
||||
//装配部门
|
||||
deptVOList.forEach(d->{
|
||||
if (n.getDeptNo().equals(d.getDeptNo())){
|
||||
n.setDeptVO(BeanConv.toBean(d,DeptVO.class));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
return pageVo;
|
||||
}catch (Exception e){
|
||||
log.error("岗位表PAGE异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(PostEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = PostCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = PostCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =PostCacheConstant.BASIC,key = "#result.id")})
|
||||
public PostVO createPost(PostVO postVO) {
|
||||
try {
|
||||
//转换PostVO为Post
|
||||
Post post = BeanConv.toBean(postVO, Post.class);
|
||||
post.setPostNo(this.createPostNo(post.getDeptNo()));
|
||||
boolean flag = save(post);
|
||||
//装配部门
|
||||
if (flag){
|
||||
PostVO postVOResult = BeanConv.toBean(post, PostVO.class);
|
||||
QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Dept::getDataState,SuperConstant.DATA_STATE_0)
|
||||
.eq(Dept::getParentDeptNo,postVO.getDeptNo());
|
||||
Dept dept = deptService.getOne(queryWrapper);
|
||||
if (!EmptyUtil.isNullOrEmpty(dept)){
|
||||
postVOResult.setDeptVO(BeanConv.toBean(dept,DeptVO.class));
|
||||
}
|
||||
return postVOResult;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("保存岗位表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(PostEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = PostCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = PostCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value =PostCacheConstant.BASIC,key = "#postVO.id")})
|
||||
public Boolean updatePost(PostVO postVO) {
|
||||
try {
|
||||
//转换PostVO为Post
|
||||
Post post = BeanConv.toBean(postVO, Post.class);
|
||||
return updateById(post);
|
||||
} catch (Exception e) {
|
||||
log.error("修改岗位表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(PostEnum.UPDATE_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = PostCacheConstant.LIST,key ="#postVO.hashCode()")
|
||||
public List<PostVO> findPostList(PostVO postVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Post> queryWrapper = new QueryWrapper<>();
|
||||
this.queryWrapper(queryWrapper,postVO);
|
||||
List<PostVO> records = BeanConv.toBeanList(list(queryWrapper),PostVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(records)){
|
||||
//对应部门
|
||||
Set<String> deptNos = records.stream().map(PostVO::getDeptNo).collect(Collectors.toSet());
|
||||
List<DeptVO> deptVOList = deptService.findDeptInDeptNos(deptNos);
|
||||
records.forEach(n->{
|
||||
//装配部门
|
||||
deptVOList.forEach(d->{
|
||||
if (n.getDeptNo().equals(d.getDeptNo())){
|
||||
n.setDeptVO(BeanConv.toBean(d,DeptVO.class));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return records;
|
||||
} catch (Exception e) {
|
||||
log.error("查询岗位表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(PostEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = PostCacheConstant.LIST,key ="#userId")
|
||||
public List<PostVO> findPostVOListByUserId(Long userId) {
|
||||
try {
|
||||
return postMapper.findPostVOListByUserId(userId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户岗位异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(PostEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createPostNo(String deptNo) {
|
||||
try {
|
||||
QueryWrapper<Post> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Post::getDeptNo,deptNo);
|
||||
List<Post> postList = list(queryWrapper);
|
||||
//无下属节点则创建下属节点
|
||||
if (EmptyUtil.isNullOrEmpty(postList)){
|
||||
return NoProcessing.createNo(deptNo,false);
|
||||
//有下属节点则累加下属节点
|
||||
}else {
|
||||
Long postNo = postList.stream()
|
||||
.map(post -> { return Long.valueOf(post.getPostNo());})
|
||||
.max(Comparator.comparing(i -> i)).get();
|
||||
return NoProcessing.createNo(String.valueOf(postNo),true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("创建岗位编号异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(PostEnum.CREATE_POST_NO_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
+377
@@ -0,0 +1,377 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.ResourceCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.RoleCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeItemVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.MenuVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.MenuMetaVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.ResourceVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.RoleVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.ResourceEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.NoProcessing;
|
||||
import com.itheima.sfbx.security.mapper.ResourceMapper;
|
||||
import com.itheima.sfbx.security.mapper.RoleMapper;
|
||||
import com.itheima.sfbx.security.pojo.Resource;
|
||||
import com.itheima.sfbx.security.service.IResourceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:权限表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements IResourceService {
|
||||
|
||||
@Autowired
|
||||
ResourceMapper resourceMapper;
|
||||
|
||||
@Autowired
|
||||
RoleMapper roleMapper;
|
||||
|
||||
/***
|
||||
* @description 多条件查询
|
||||
* @param queryWrapper
|
||||
* @param resourceVO
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<Resource> queryWrapper(QueryWrapper<Resource> queryWrapper, ResourceVO resourceVO){
|
||||
//资源编号
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getResourceNo())) {
|
||||
queryWrapper.lambda().eq(Resource::getResourceNo,resourceVO.getResourceNo());
|
||||
}
|
||||
//父资源编号查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getParentResourceNo())) {
|
||||
queryWrapper.lambda().likeRight(Resource::getParentResourceNo,
|
||||
NoProcessing.processString(resourceVO.getParentResourceNo()));
|
||||
}
|
||||
//资源名称查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getResourceName())) {
|
||||
queryWrapper.lambda().likeRight(Resource::getResourceName,resourceVO.getResourceName());
|
||||
}
|
||||
//资源类型(m目录 c菜单 f按钮 r微服务)查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getResourceType())) {
|
||||
queryWrapper.lambda().eq(Resource::getResourceType,resourceVO.getResourceType());
|
||||
}
|
||||
//请求地址查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getRequestPath())) {
|
||||
queryWrapper.lambda().likeRight(Resource::getRequestPath,resourceVO.getRequestPath());
|
||||
}
|
||||
//权限标识查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getLabel())) {
|
||||
queryWrapper.lambda().likeRight(Resource::getLabel,resourceVO.getLabel());
|
||||
}
|
||||
//排序查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getSortNo())) {
|
||||
queryWrapper.lambda().eq(Resource::getSortNo,resourceVO.getSortNo());
|
||||
}
|
||||
//图标查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getIcon())) {
|
||||
queryWrapper.lambda().eq(Resource::getIcon,resourceVO.getIcon());
|
||||
}
|
||||
//创建者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(Resource::getCreateBy,resourceVO.getCreateBy());
|
||||
}
|
||||
//更新者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(Resource::getUpdateBy,resourceVO.getUpdateBy());
|
||||
}
|
||||
//备注查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getRemark())) {
|
||||
queryWrapper.lambda().eq(Resource::getRemark,resourceVO.getRemark());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(Resource::getDataState,resourceVO.getDataState());
|
||||
}
|
||||
//按创sortNo排序
|
||||
queryWrapper.lambda().orderByAsc(Resource::getSortNo);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ResourceCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#resourceVO.hashCode()")
|
||||
public Page<ResourceVO> findResourcePage(ResourceVO resourceVO, int pageNum, int pageSize) {
|
||||
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<Resource> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<Resource> queryWrapper = new QueryWrapper<>();
|
||||
//多条件查询
|
||||
this.queryWrapper(queryWrapper,resourceVO);
|
||||
//执行分页查询
|
||||
return BeanConv.toPage(page(page, queryWrapper),ResourceVO.class);
|
||||
}catch (Exception e){
|
||||
log.error("权限表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = ResourceCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.TREE,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.MENUS,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =ResourceCacheConstant.BASIC,key = "#result.id")})
|
||||
public ResourceVO createResource(ResourceVO resourceVO) {
|
||||
try {
|
||||
//转换ResourceVO为Resource
|
||||
Resource resource = BeanConv.toBean(resourceVO, Resource.class);
|
||||
resource.setResourceNo(this.createResourceNo(resource.getParentResourceNo()));
|
||||
boolean flag = save(resource);
|
||||
if (flag){
|
||||
return BeanConv.toBean(resource,ResourceVO.class);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("保存权限表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = ResourceCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.TREE,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.MENUS,allEntries = true),
|
||||
@CacheEvict(value = RoleCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = RoleCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value =ResourceCacheConstant.BASIC,key = "#resourceVO.id")})
|
||||
public Boolean updateResource(ResourceVO resourceVO) {
|
||||
try {
|
||||
//转换ResourceVO为Resource
|
||||
Resource resource = BeanConv.toBean(resourceVO, Resource.class);
|
||||
return updateById(resource);
|
||||
} catch (Exception e) {
|
||||
log.error("修改权限表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.UPDATE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ResourceCacheConstant.LIST,key ="#resourceVO.hashCode()")
|
||||
public List<ResourceVO> findResourceList(ResourceVO resourceVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Resource> queryWrapper = new QueryWrapper<>();
|
||||
this.queryWrapper(queryWrapper,resourceVO);
|
||||
return BeanConv.toBeanList(list(queryWrapper),ResourceVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("删除权限表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ResourceCacheConstant.TREE,key ="#parentResourceNo+'-'+#checkedResourceNos")
|
||||
public TreeVO resourceTreeVO(String parentResourceNo, String[] checkedResourceNos) {
|
||||
try {
|
||||
List<Resource> resourceList = Lists.newLinkedList();
|
||||
QueryWrapper<Resource> queryWrapper = new QueryWrapper<>();
|
||||
//根节点查询树形结构
|
||||
if (EmptyUtil.isNullOrEmpty(parentResourceNo)){
|
||||
parentResourceNo = SuperConstant.ROOT_PARENT_ID;
|
||||
}
|
||||
//指定节点查询树形结构
|
||||
queryWrapper.lambda()
|
||||
.eq(Resource::getDataState, SuperConstant.DATA_STATE_0)
|
||||
.likeRight(Resource::getParentResourceNo, NoProcessing.processString(parentResourceNo))
|
||||
.orderByAsc(Resource::getResourceNo);
|
||||
resourceList.addAll(list(queryWrapper));
|
||||
if (EmptyUtil.isNullOrEmpty(resourceList)){
|
||||
throw new RuntimeException("部门信息为定义!");
|
||||
}
|
||||
List<TreeItemVO> treeItemVOList = new ArrayList<>();
|
||||
List<String> expandedIds = new ArrayList<>();
|
||||
//递归构建树形结构
|
||||
List<String> checkedResourceNoList = Lists.newArrayList();
|
||||
if (!EmptyUtil.isNullOrEmpty(checkedResourceNos)){
|
||||
checkedResourceNoList = Arrays.asList(checkedResourceNos);
|
||||
}
|
||||
recursionTreeItem(treeItemVOList,resourceList.get(0),resourceList,checkedResourceNoList,expandedIds);
|
||||
return TreeVO.builder()
|
||||
.items(treeItemVOList)
|
||||
.checkedIds(checkedResourceNoList)
|
||||
.expandedIds(expandedIds)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.error("查询资源表TREE异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.TREE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
private void recursionTreeItem(List<TreeItemVO> treeItemVOList, Resource ResourceRoot, List<Resource> resourceList,
|
||||
List<String> checkedResourceNos, List<String> expandedIds) {
|
||||
TreeItemVO treeItem = TreeItemVO.builder()
|
||||
.id(ResourceRoot.getResourceNo())
|
||||
.label(ResourceRoot.getResourceName())
|
||||
.build();
|
||||
//判断是否选择
|
||||
if (!EmptyUtil.isNullOrEmpty(checkedResourceNos)&&
|
||||
checkedResourceNos.contains(ResourceRoot.getResourceNo())){
|
||||
treeItem.setIsChecked(true);
|
||||
}else {
|
||||
treeItem.setIsChecked(false);
|
||||
}
|
||||
//是否默认展开:如果当前的资源为第二层或者第三层则展开
|
||||
if(NoProcessing.processString(ResourceRoot.getResourceNo()).length()/3==2||
|
||||
NoProcessing.processString(ResourceRoot.getResourceNo()).length()/3==3){
|
||||
expandedIds.add(ResourceRoot.getResourceNo());
|
||||
}
|
||||
//获得当前资源下子资源
|
||||
List<Resource> childrenResource = resourceList.stream()
|
||||
.filter(n -> n.getParentResourceNo().equals(ResourceRoot.getResourceNo()))
|
||||
.collect(Collectors.toList());
|
||||
if (!EmptyUtil.isNullOrEmpty(childrenResource)){
|
||||
List<TreeItemVO> listChildren = Lists.newArrayList();
|
||||
childrenResource.forEach(n->{
|
||||
this.recursionTreeItem(listChildren,n,resourceList,checkedResourceNos,expandedIds);});
|
||||
treeItem.setChildren(listChildren);
|
||||
}
|
||||
treeItemVOList.add(treeItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ResourceCacheConstant.LIST,key ="#roleIds.hashCode()")
|
||||
public List<ResourceVO> findResourceVOListInRoleId(List<Long> roleIds) {
|
||||
try {
|
||||
return resourceMapper.findResourceVOListInRoleId(roleIds);
|
||||
} catch (Exception e) {
|
||||
log.error("删除权限表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ResourceCacheConstant.LIST,key ="#userId")
|
||||
public List<ResourceVO> findResourceVOListByUserId(Long userId) {
|
||||
try {
|
||||
return resourceMapper.findResourceVOListByUserId(userId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询权限表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ResourceCacheConstant.MENUS,key ="#systemCode")
|
||||
public List<MenuVO> menus(String systemCode) {
|
||||
try {
|
||||
//查询当前系统的根节点
|
||||
QueryWrapper<Resource> parentQueryWrapper =new QueryWrapper<>();
|
||||
parentQueryWrapper.lambda()
|
||||
.eq(Resource::getParentResourceNo, SuperConstant.ROOT_PARENT_ID)
|
||||
.eq(Resource::getDataState,SuperConstant.DATA_STATE_0)
|
||||
.eq(Resource::getResourceType,SuperConstant.SYSTEM)
|
||||
.orderByAsc(Resource::getSortNo);
|
||||
Resource parentResource = resourceMapper.selectOne(parentQueryWrapper);
|
||||
//构建一级菜单
|
||||
QueryWrapper<Resource> queryWrapper =new QueryWrapper<>();
|
||||
queryWrapper.lambda()
|
||||
.eq(Resource::getParentResourceNo,parentResource.getResourceNo())
|
||||
.eq(Resource::getDataState,SuperConstant.DATA_STATE_0)
|
||||
.eq(Resource::getResourceType,SuperConstant.CATALOGUE)
|
||||
.orderByAsc(Resource::getSortNo);
|
||||
List<Resource> resources = resourceMapper.selectList(queryWrapper);
|
||||
List<MenuVO> list = new ArrayList<>();
|
||||
recursionMenuVO(list,resources,SuperConstant.COMPONENT_LAYOUT);
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
log.error("查询资源表TREE异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(ResourceEnum.MENUS_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 递归菜单
|
||||
*/
|
||||
public List<MenuVO> recursionMenuVO(List<MenuVO> list,List<Resource> resources,String component){
|
||||
|
||||
for (Resource resource : resources) {
|
||||
List<RoleVO> roleVOList = roleMapper.findRoleVOListByResourceNo(resource.getResourceNo());
|
||||
List<String> roleLabels = new ArrayList<>();
|
||||
roleVOList.forEach(n->{
|
||||
roleLabels.add(n.getLabel());
|
||||
});
|
||||
MenuMetaVO menuMetaVO = MenuMetaVO.builder()
|
||||
.icon(resource.getIcon())
|
||||
.roles(roleLabels)
|
||||
.title(resource.getResourceName())
|
||||
.build();
|
||||
MenuVO menuVO = MenuVO.builder()
|
||||
.name(resource.getResourceName())
|
||||
.hidden(false)
|
||||
.component(resource.getRequestPath())
|
||||
.meta(menuMetaVO)
|
||||
.build();
|
||||
if (SuperConstant.COMPONENT_LAYOUT.equals(component)){
|
||||
menuVO.setPath("/"+resource.getRequestPath());
|
||||
menuVO.setComponent(SuperConstant.COMPONENT_LAYOUT);
|
||||
}else {
|
||||
menuVO.setPath(resource.getRequestPath());
|
||||
menuVO.setComponent(component+"/"+resource.getRequestPath());
|
||||
}
|
||||
QueryWrapper<Resource> queryWrapper =new QueryWrapper<>();
|
||||
queryWrapper.lambda()
|
||||
.eq(Resource::getParentResourceNo,resource.getResourceNo())
|
||||
.eq(Resource::getResourceType,SuperConstant.MENU)
|
||||
.eq(Resource::getDataState,SuperConstant.DATA_STATE_0)
|
||||
.orderByAsc(Resource::getSortNo);
|
||||
List<Resource> resourceChildren = resourceMapper.selectList(queryWrapper);
|
||||
if (resourceChildren.size()>0){
|
||||
menuVO.setRedirect("/"+resource.getResourceName()+"/"+resourceChildren.get(0).getResourceName());
|
||||
List<MenuVO> listChildren = new ArrayList<>();
|
||||
this.recursionMenuVO(listChildren,resourceChildren,resource.getRequestPath());
|
||||
menuVO.setChildren(listChildren);
|
||||
}
|
||||
list.add(menuVO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createResourceNo(String parentResourceNo) {
|
||||
ResourceVO resourceVO = ResourceVO.builder()
|
||||
.parentResourceNo(parentResourceNo)
|
||||
.build();
|
||||
QueryWrapper<Resource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Resource::getParentResourceNo,parentResourceNo);
|
||||
List<Resource> resourceList = list(queryWrapper);
|
||||
//无下属节点则创建下属节点
|
||||
if (EmptyUtil.isNullOrEmpty(resourceList)){
|
||||
return NoProcessing.createNo(parentResourceNo,false);
|
||||
//有下属节点则累加下属节点
|
||||
}else {
|
||||
Long resourceNo = resourceList.stream()
|
||||
.map(resource -> { return Long.valueOf(resource.getResourceNo());})
|
||||
.max(Comparator.comparing(i -> i)).get();
|
||||
return NoProcessing.createNo(String.valueOf(resourceNo),true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itheima.sfbx.security.mapper.RoleDeptMapper;
|
||||
import com.itheima.sfbx.security.pojo.RoleDept;
|
||||
import com.itheima.sfbx.security.service.IRoleDeptService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:权限表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class RoleDeptServiceImpl extends ServiceImpl<RoleDeptMapper, RoleDept> implements IRoleDeptService {
|
||||
|
||||
@Override
|
||||
public Boolean deleteRoleDeptByRoleId(Long roleId) {
|
||||
UpdateWrapper<RoleDept> updateWrapper = new UpdateWrapper();
|
||||
updateWrapper.lambda().eq(RoleDept::getRoleId,roleId);
|
||||
return remove(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteRoleDeptInRoleId(List<Long> roleIds) {
|
||||
UpdateWrapper<RoleDept> updateWrapper = new UpdateWrapper();
|
||||
updateWrapper.lambda().in(RoleDept::getRoleId,roleIds);
|
||||
return remove(updateWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itheima.sfbx.security.mapper.RoleResourceMapper;
|
||||
import com.itheima.sfbx.security.pojo.RoleResource;
|
||||
import com.itheima.sfbx.security.service.IRoleResourceService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:角色资源关联表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class RoleResourceServiceImpl extends ServiceImpl<RoleResourceMapper, RoleResource> implements IRoleResourceService {
|
||||
|
||||
@Override
|
||||
public Boolean deleteRoleResourceByRoleId(Long roleId) {
|
||||
UpdateWrapper<RoleResource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().eq(RoleResource::getRoleId,roleId);
|
||||
return remove(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteRoleResourceInRoleId(List<Long> roleIds) {
|
||||
UpdateWrapper<RoleResource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().in(RoleResource::getRoleId,roleIds);
|
||||
return remove(updateWrapper);
|
||||
}
|
||||
}
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.ResourceCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.RoleCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.SecurityConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.UserCacheConstant;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.ResourceVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.RoleVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.RoleEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.security.mapper.DeptMapper;
|
||||
import com.itheima.sfbx.security.mapper.ResourceMapper;
|
||||
import com.itheima.sfbx.security.mapper.RoleMapper;
|
||||
import com.itheima.sfbx.security.pojo.Role;
|
||||
import com.itheima.sfbx.security.pojo.RoleDept;
|
||||
import com.itheima.sfbx.security.pojo.RoleResource;
|
||||
import com.itheima.sfbx.security.service.IRoleDeptService;
|
||||
import com.itheima.sfbx.security.service.IRoleResourceService;
|
||||
import com.itheima.sfbx.security.service.IRoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:角色表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
|
||||
|
||||
@Autowired
|
||||
IRoleResourceService roleResourceService;
|
||||
|
||||
@Autowired
|
||||
IRoleDeptService roleDeptService;
|
||||
|
||||
@Autowired
|
||||
RoleMapper roleMapper;
|
||||
|
||||
@Autowired
|
||||
ResourceMapper resourceMapper;
|
||||
|
||||
@Autowired
|
||||
DeptMapper deptMapper;
|
||||
|
||||
/***
|
||||
* @description 多条件查询
|
||||
* @param queryWrapper
|
||||
* @param roleVO
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<Role> queryWrapper(QueryWrapper<Role> queryWrapper, RoleVO roleVO){
|
||||
//角色名称查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getRoleName())) {
|
||||
queryWrapper.lambda().likeRight(Role::getRoleName,roleVO.getRoleName());
|
||||
}
|
||||
//权限标识查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getLabel())) {
|
||||
queryWrapper.lambda().likeRight(Role::getLabel,roleVO.getLabel());
|
||||
}
|
||||
//排序查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getSortNo())) {
|
||||
queryWrapper.lambda().eq(Role::getSortNo,roleVO.getSortNo());
|
||||
}
|
||||
//创建者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(Role::getCreateBy,roleVO.getCreateBy());
|
||||
}
|
||||
//更新者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(Role::getUpdateBy,roleVO.getUpdateBy());
|
||||
}
|
||||
//备注查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getRemark())) {
|
||||
queryWrapper.lambda().eq(Role::getRemark,roleVO.getRemark());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(roleVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(Role::getDataState,roleVO.getDataState());
|
||||
}
|
||||
//按创建时间降序
|
||||
queryWrapper.lambda().orderByAsc(Role::getSortNo);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RoleCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#roleVO.hashCode()")
|
||||
public Page<RoleVO> findRolePage(RoleVO roleVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<Role> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询,代码生成后自己可自行调整
|
||||
this.queryWrapper(queryWrapper,roleVO);
|
||||
//执行分页查询
|
||||
Page<RoleVO> pageVo = BeanConv.toPage(page(page, queryWrapper),RoleVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(pageVo.getRecords())){
|
||||
List<Long> roleIds = pageVo.getRecords().stream().map(RoleVO::getId).collect(Collectors.toList());
|
||||
//查询对应资源
|
||||
List<ResourceVO> resourceList = resourceMapper.findResourceVOListInRoleId(roleIds);
|
||||
//查询对应数据权限
|
||||
List<DeptVO> deptVOList = deptMapper.findDeptVOListInRoleId(roleIds);
|
||||
pageVo.getRecords().forEach(n->{
|
||||
//装配资源
|
||||
Set<String> resourceNoSet = Sets.newHashSet();
|
||||
resourceList.forEach(r->{
|
||||
if (String.valueOf(n.getId()).equals(String.valueOf(r.getRoleId()))){
|
||||
resourceNoSet.add(r.getResourceNo());
|
||||
}
|
||||
});
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceNoSet))
|
||||
n.setCheckedResourceNos(resourceNoSet.toArray(new String[resourceNoSet.size()]));
|
||||
//装配数据权限
|
||||
Set<String> deptNoSet = Sets.newHashSet();
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVOList)){
|
||||
deptVOList.forEach(d->{
|
||||
if (String.valueOf(n.getId()).equals(String.valueOf(d.getRoleId()))){
|
||||
deptNoSet.add(d.getDeptNo());
|
||||
}
|
||||
});
|
||||
if (!EmptyUtil.isNullOrEmpty(deptNoSet)){
|
||||
n.setCheckedDeptNos(deptNoSet.toArray(new String[deptNoSet.size()]));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return pageVo;
|
||||
}catch (Exception e){
|
||||
log.error("角色表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(RoleEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = RoleCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = RoleCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =RoleCacheConstant.BASIC,key = "#result.id")})
|
||||
public RoleVO createRole(RoleVO roleVO) {
|
||||
try {
|
||||
//转换RoleVO为Role
|
||||
Role role = BeanConv.toBean(roleVO, Role.class);
|
||||
boolean flag = save(role);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存角色失败");
|
||||
}
|
||||
//保存角色资源中间信息
|
||||
List<RoleResource> roleResourceList = Lists.newArrayList();
|
||||
Arrays.asList(roleVO.getCheckedResourceNos()).forEach(n->{
|
||||
RoleResource roleResource = RoleResource.builder()
|
||||
.roleId(role.getId())
|
||||
.resourceNo(n)
|
||||
.build();
|
||||
roleResourceList.add(roleResource);
|
||||
});
|
||||
flag = roleResourceService.saveBatch(roleResourceList);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存角色资源信息出错");
|
||||
}
|
||||
//自定义权限:保存角色部门中间信息
|
||||
if (SecurityConstant.DATA_SCOPE_1.equals(roleVO.getDataScope())){
|
||||
//保存角色部门中间信息
|
||||
List<RoleDept> roleDeptList = Lists.newArrayList();
|
||||
Arrays.asList(roleVO.getCheckedDeptNos()).forEach(n->{
|
||||
RoleDept roleDept = RoleDept.builder()
|
||||
.roleId(role.getId())
|
||||
.deptNo(n)
|
||||
.dataState(SuperConstant.DATA_STATE_0)
|
||||
.build();
|
||||
roleDeptList.add(roleDept);
|
||||
});
|
||||
flag = roleDeptService.saveBatch(roleDeptList);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存角色部门中间信息出错");
|
||||
}
|
||||
}
|
||||
if (flag){
|
||||
return BeanConv.toBean(role,RoleVO.class);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("保存角色表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(RoleEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = RoleCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = RoleCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = ResourceCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.DATA_SECURITY,allEntries = true),
|
||||
@CacheEvict(value =RoleCacheConstant.BASIC,key = "#roleVO.id")})
|
||||
@Override
|
||||
public Boolean updateRole(RoleVO roleVO) {
|
||||
try {
|
||||
//转换RoleVO为Role
|
||||
Role role = BeanConv.toBean(roleVO, Role.class);
|
||||
Boolean flag = updateById(role);
|
||||
if (!flag){
|
||||
throw new RuntimeException("修改角色失败");
|
||||
}
|
||||
//删除原有角色资源中间信息
|
||||
flag = roleResourceService.deleteRoleResourceByRoleId(role.getId());
|
||||
if (!flag){
|
||||
throw new RuntimeException("删除原有角色资源中间信息失败");
|
||||
}
|
||||
//保存角色资源中间信息
|
||||
List<RoleResource> roleResourceList = Lists.newArrayList();
|
||||
Arrays.asList(roleVO.getCheckedResourceNos()).forEach(n->{
|
||||
RoleResource roleResource = RoleResource.builder()
|
||||
.roleId(role.getId())
|
||||
.resourceNo(n)
|
||||
.build();
|
||||
roleResourceList.add(roleResource);
|
||||
});
|
||||
flag = roleResourceService.saveBatch(roleResourceList);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存角色资源中间信息失败");
|
||||
}
|
||||
//删除原有角色数据权限:这里不需要判断返回结果,有可能之前就没有自定义数据权限
|
||||
roleDeptService.deleteRoleDeptByRoleId(role.getId());
|
||||
//保存先的数据权限
|
||||
if (SecurityConstant.DATA_SCOPE_1.equals(roleVO.getDataScope())){
|
||||
//保存角色部门中间信息
|
||||
List<RoleDept> roleDeptList = Lists.newArrayList();
|
||||
Arrays.asList(roleVO.getCheckedDeptNos()).forEach(n->{
|
||||
RoleDept roleDept = RoleDept.builder()
|
||||
.roleId(role.getId())
|
||||
.deptNo(n)
|
||||
.dataState(SuperConstant.DATA_STATE_0)
|
||||
.build();
|
||||
roleDeptList.add(roleDept);
|
||||
});
|
||||
flag = roleDeptService.saveBatch(roleDeptList);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存角色部门中间信息出错");
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
log.error("修改角色表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(RoleEnum.UPDATE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RoleCacheConstant.LIST,key ="#roleVO.hashCode()")
|
||||
public List<RoleVO> findRoleList(RoleVO roleVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
||||
//多条件查询
|
||||
this.queryWrapper(queryWrapper,roleVO);
|
||||
List<RoleVO> records = BeanConv.toBeanList(list(queryWrapper),RoleVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(records)){
|
||||
List<Long> roleIds = records.stream().map(RoleVO::getId).collect(Collectors.toList());
|
||||
//查询对应资源
|
||||
List<ResourceVO> resourceList = resourceMapper.findResourceVOListInRoleId(roleIds);
|
||||
//查询对应数据权限
|
||||
List<DeptVO> deptVOList = deptMapper.findDeptVOListInRoleId(roleIds);
|
||||
records.forEach(n->{
|
||||
//装配资源
|
||||
Set<String> resourceNoSet = Sets.newHashSet();
|
||||
resourceList.forEach(r->{
|
||||
if (n.getId().equals(r.getRoleId())){
|
||||
resourceNoSet.add(r.getResourceNo());
|
||||
}
|
||||
});
|
||||
if (!EmptyUtil.isNullOrEmpty(resourceNoSet))
|
||||
n.setCheckedResourceNos(resourceNoSet.toArray(new String[resourceNoSet.size()]));
|
||||
//装配数据权限
|
||||
Set<String> deptNoSet = Sets.newHashSet();
|
||||
if (!EmptyUtil.isNullOrEmpty(deptVOList)){
|
||||
deptVOList.forEach(d->{
|
||||
if (n.getId().equals(d.getRoleId())){
|
||||
deptNoSet.add(d.getDeptNo());
|
||||
}
|
||||
});
|
||||
if (!EmptyUtil.isNullOrEmpty(deptNoSet)){
|
||||
n.setCheckedDeptNos(deptNoSet.toArray(new String[deptNoSet.size()]));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return records;
|
||||
} catch (Exception e) {
|
||||
log.error("查询角色表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(RoleEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RoleCacheConstant.LIST,key ="#userIds.hashCode()")
|
||||
public List<RoleVO> findRoleVOListInUserId(List<Long> userIds) {
|
||||
try {
|
||||
return roleMapper.findRoleVOListInUserId(userIds);
|
||||
} catch (Exception e) {
|
||||
log.error("查询角色表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(RoleEnum.LIST_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RoleCacheConstant.LIST,key ="#userId")
|
||||
public List<RoleVO> findRoleVOListByUserId(Long userId) {
|
||||
try {
|
||||
return roleMapper.findRoleVOListByUserId(userId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询角色表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(RoleEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itheima.sfbx.security.mapper.UserRoleMapper;
|
||||
import com.itheima.sfbx.security.pojo.UserRole;
|
||||
import com.itheima.sfbx.security.service.IUserRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:用户角色关联表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {
|
||||
|
||||
@Override
|
||||
public boolean deleteUserRoleByUserId(Long userId) {
|
||||
UpdateWrapper<UserRole> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().eq(UserRole::getUserId,userId);
|
||||
return remove(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteUserRoleInUserId(List<Long> userIds) {
|
||||
UpdateWrapper<UserRole> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().in(UserRole::getUserId,userIds);
|
||||
return remove(updateWrapper);
|
||||
}
|
||||
}
|
||||
+449
@@ -0,0 +1,449 @@
|
||||
package com.itheima.sfbx.security.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.itheima.sfbx.framework.commons.constant.basic.SuperConstant;
|
||||
import com.itheima.sfbx.framework.commons.constant.security.*;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DataSecurityVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.DeptPostUserVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.RoleVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.UserEnum;
|
||||
import com.itheima.sfbx.framework.commons.exception.ProjectException;
|
||||
import com.itheima.sfbx.framework.commons.properties.SecurityConfigProperties;
|
||||
import com.itheima.sfbx.framework.commons.utils.BeanConv;
|
||||
import com.itheima.sfbx.framework.commons.utils.EmptyUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.ExceptionsUtil;
|
||||
import com.itheima.sfbx.framework.commons.utils.NoProcessing;
|
||||
import com.itheima.sfbx.security.mapper.RoleDeptMapper;
|
||||
import com.itheima.sfbx.security.mapper.RoleMapper;
|
||||
import com.itheima.sfbx.security.mapper.UserMapper;
|
||||
import com.itheima.sfbx.security.pojo.DeptPostUser;
|
||||
import com.itheima.sfbx.security.pojo.RoleDept;
|
||||
import com.itheima.sfbx.security.pojo.User;
|
||||
import com.itheima.sfbx.security.pojo.UserRole;
|
||||
import com.itheima.sfbx.security.service.IDeptPostUserService;
|
||||
import com.itheima.sfbx.security.service.IUserRoleService;
|
||||
import com.itheima.sfbx.security.service.IUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:用户表服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
|
||||
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
RoleDeptMapper roleDeptMapper;
|
||||
|
||||
@Autowired
|
||||
RoleMapper roleMapper;
|
||||
|
||||
@Autowired
|
||||
IUserRoleService userRoleService;
|
||||
|
||||
@Autowired
|
||||
IDeptPostUserService deptPostUserService;
|
||||
|
||||
@Autowired
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@Autowired
|
||||
SecurityConfigProperties securityConfigProperties;
|
||||
|
||||
/***
|
||||
* @description 构建多条件查询
|
||||
*
|
||||
* @param queryWrapper 查询条件
|
||||
* @param userVO 查询对象
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<User> queryWrapper(QueryWrapper<User> queryWrapper,UserVO userVO){
|
||||
//角色Id查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getRoleId())){
|
||||
QueryWrapper<UserRole> userRoleQueryWrapper = new QueryWrapper<>();
|
||||
userRoleQueryWrapper.lambda().eq(UserRole::getRoleId,userVO.getRoleId());
|
||||
List<UserRole> roles = userRoleService.list(userRoleQueryWrapper);
|
||||
if (!EmptyUtil.isNullOrEmpty(roles)){
|
||||
List<Long> userIds = roles.stream().map(UserRole::getUserId).collect(Collectors.toList());
|
||||
queryWrapper.lambda().in(User::getId,userIds);
|
||||
}else {
|
||||
queryWrapper.lambda().in(User::getId,-1L);
|
||||
}
|
||||
}
|
||||
//部门No查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getDeptNo())){
|
||||
QueryWrapper<DeptPostUser> deptPostUserQueryWrapper = new QueryWrapper<>();
|
||||
deptPostUserQueryWrapper.lambda().likeRight(DeptPostUser::getDeptNo,NoProcessing.processString(userVO.getDeptNo()));
|
||||
List<DeptPostUser> deptPostUsers = deptPostUserService.list(deptPostUserQueryWrapper);
|
||||
if (!EmptyUtil.isNullOrEmpty(deptPostUsers)){
|
||||
List<Long> userIds= deptPostUsers.stream().map(DeptPostUser::getUserId).collect(Collectors.toList());
|
||||
queryWrapper.lambda().in(User::getId,userIds);
|
||||
}else {
|
||||
queryWrapper.lambda().in(User::getId,-1L);
|
||||
}
|
||||
}
|
||||
//用户账号查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getUsername())) {
|
||||
queryWrapper.lambda().eq(User::getUsername,userVO.getUsername());
|
||||
}
|
||||
//open_id标识查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getOpenId())) {
|
||||
queryWrapper.lambda().eq(User::getOpenId,userVO.getOpenId());
|
||||
}
|
||||
//用户昵称查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getNickName())) {
|
||||
queryWrapper.lambda().likeRight(User::getNickName,userVO.getNickName());
|
||||
}
|
||||
//用户邮箱查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getEmail())) {
|
||||
queryWrapper.lambda().likeRight(User::getEmail,userVO.getEmail());
|
||||
}
|
||||
//真实姓名查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getRealName())) {
|
||||
queryWrapper.lambda().likeRight(User::getRealName,userVO.getRealName());
|
||||
}
|
||||
//手机号码查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getMobile())) {
|
||||
queryWrapper.lambda().likeRight(User::getMobile,userVO.getMobile());
|
||||
}
|
||||
//用户性别(0男 1女 2未知)查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getSex())) {
|
||||
queryWrapper.lambda().eq(User::getSex,userVO.getSex());
|
||||
}
|
||||
//创建者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getCreateBy())) {
|
||||
queryWrapper.lambda().eq(User::getCreateBy,userVO.getCreateBy());
|
||||
}
|
||||
//更新者查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getUpdateBy())) {
|
||||
queryWrapper.lambda().eq(User::getUpdateBy,userVO.getUpdateBy());
|
||||
}
|
||||
//状态查询
|
||||
if (!EmptyUtil.isNullOrEmpty(userVO.getDataState())) {
|
||||
queryWrapper.lambda().eq(User::getDataState,userVO.getDataState());
|
||||
}
|
||||
//按创建时间降序
|
||||
queryWrapper.lambda().orderByDesc(User::getCreateTime);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.PAGE,key ="#pageNum+'-'+#pageSize+'-'+#userVO.hashCode()")
|
||||
public Page<UserVO> findUserPage(UserVO userVO, int pageNum, int pageSize) {
|
||||
try {
|
||||
//构建分页对象
|
||||
Page<User> page = new Page<>(pageNum,pageSize);
|
||||
//构建查询条件
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
//多条件查询
|
||||
this.queryWrapper(queryWrapper,userVO);
|
||||
//执行分页查询
|
||||
Page<UserVO> pageVo = BeanConv.toPage(page(page, queryWrapper),UserVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(pageVo.getRecords())){
|
||||
List<Long> userIds = pageVo.getRecords().stream().map(UserVO::getId).collect(Collectors.toList());
|
||||
//查询对应角色
|
||||
List<RoleVO> roleVOList = roleMapper.findRoleVOListInUserId(userIds);
|
||||
//查询对应部门、职位
|
||||
List<DeptPostUserVO> deptPostUserVOList = deptPostUserService.findDeptPostUserVOListInUserId(userIds);
|
||||
//查询对应部门、职位
|
||||
pageVo.getRecords().forEach(n->{
|
||||
//装配角色
|
||||
Set<String> roleVOIds = Sets.newHashSet();
|
||||
roleVOList.forEach(r->{
|
||||
if (n.getId().equals(r.getUserId())){
|
||||
roleVOIds.add(String.valueOf(r.getId()));
|
||||
}
|
||||
});
|
||||
n.setRoleVOIds(roleVOIds);
|
||||
//装配对应部门、职位、数据权限
|
||||
Set<DeptPostUserVO> deptPostUserVOs = Sets.newHashSet();
|
||||
deptPostUserVOList.forEach(r->{
|
||||
if (n.getId().equals(r.getUserId())){
|
||||
deptPostUserVOs.add(r);
|
||||
}
|
||||
});
|
||||
n.setDeptPostUserVOs(deptPostUserVOs);
|
||||
});
|
||||
}
|
||||
return pageVo;
|
||||
}catch (Exception e){
|
||||
log.error("用户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.PAGE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = UserCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.LIST,allEntries = true)},
|
||||
put={@CachePut(value =UserCacheConstant.BASIC,key = "#result.id")})
|
||||
public UserVO createUser(UserVO userVO) {
|
||||
try {
|
||||
String password = bCryptPasswordEncoder.encode(securityConfigProperties.getPassworddDfaule());
|
||||
userVO.setPassword(password);
|
||||
//转换UserVO为User
|
||||
User user = BeanConv.toBean(userVO, User.class);
|
||||
user.setUsername(userVO.getEmail());
|
||||
boolean flag = save(user);
|
||||
if (!flag) {
|
||||
throw new RuntimeException("保存用户信息出错");
|
||||
}
|
||||
//保存用户角色中间表
|
||||
List<UserRole> userRoles = Lists.newArrayList();
|
||||
if(CollectionUtil.isEmpty(userVO.getRoleVOIds())){
|
||||
throw new ProjectException(UserEnum.ROLE_NOT_BE_NULL);
|
||||
}
|
||||
userVO.getRoleVOIds().forEach(r -> {
|
||||
userRoles.add(UserRole.builder().userId(user.getId()).roleId(Long.valueOf(r)).build());
|
||||
});
|
||||
flag = userRoleService.saveBatch(userRoles);
|
||||
if (!flag) {
|
||||
throw new RuntimeException("保存用户角色中间表出错");
|
||||
}
|
||||
//保存部门职位中间表
|
||||
List<DeptPostUser> deptPostUsers = Lists.newArrayList();
|
||||
if(CollectionUtil.isEmpty(userVO.getDeptPostUserVOs())){
|
||||
throw new ProjectException(UserEnum.POST_NOT_BE_NULL);
|
||||
}
|
||||
userVO.getDeptPostUserVOs().forEach(dpu -> {
|
||||
dpu.setUserId(user.getId());
|
||||
deptPostUsers.add(BeanConv.toBean(dpu, DeptPostUser.class));
|
||||
});
|
||||
flag = deptPostUserService.saveBatch(deptPostUsers);
|
||||
if (!flag) {
|
||||
throw new RuntimeException("保存部门职位中间表出错");
|
||||
}
|
||||
return BeanConv.toBean(user, UserVO.class);
|
||||
}catch (ProjectException e){
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("保存用户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.SAVE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Caching(evict = {@CacheEvict(value = UserCacheConstant.PAGE,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.LOGIN,allEntries = true),
|
||||
@CacheEvict(value = CustomerCacheConstant.LOGIN,allEntries = true),
|
||||
@CacheEvict(value = DeptCacheConstant.LIST,key = "#userVO.id"),
|
||||
@CacheEvict(value = PostCacheConstant.LIST,key = "#userVO.id"),
|
||||
@CacheEvict(value = ResourceCacheConstant.LIST,key = "#userVO.id"),
|
||||
@CacheEvict(value = RoleCacheConstant.LIST,allEntries = true),
|
||||
@CacheEvict(value = UserCacheConstant.LIST,key = "#userVO.id"),
|
||||
@CacheEvict(value = DeptPostUserCacheConstant.LIST,key ="#userVO.id"),
|
||||
@CacheEvict(value = DeptPostUserCacheConstant.DEPT_POST_USER_VO,key ="#userVO.id"),
|
||||
@CacheEvict(value = UserCacheConstant.BASIC,key = "#userVO.id")})
|
||||
public Boolean updateUser(UserVO userVO) {
|
||||
try {
|
||||
//转换UserVO为User
|
||||
User user = BeanConv.toBean(userVO, User.class);
|
||||
boolean flag = updateById(user);
|
||||
if (!flag){
|
||||
throw new RuntimeException("修改用户信息出错");
|
||||
}
|
||||
//删除角色中间表
|
||||
flag = userRoleService.deleteUserRoleByUserId(user.getId());
|
||||
if (!flag){
|
||||
throw new RuntimeException("删除角色中间表出错");
|
||||
}
|
||||
//重新保存角色中间表
|
||||
List<UserRole> userRoles = Lists.newArrayList();
|
||||
userVO.getRoleVOIds().forEach(r->{
|
||||
userRoles.add(UserRole.builder().userId(user.getId()).roleId(Long.valueOf(r)).build());
|
||||
});
|
||||
userRoleService.saveBatch(userRoles);
|
||||
//删除部门职位中间表
|
||||
flag = deptPostUserService.deleteDeptPostUserByUserId(user.getId());
|
||||
if (!flag){
|
||||
throw new RuntimeException("删除角色中间表出错");
|
||||
}
|
||||
//重新保存部门职位中间表
|
||||
List<DeptPostUser> deptPostUsers = Lists.newArrayList();
|
||||
userVO.getDeptPostUserVOs().forEach(dpu->{
|
||||
dpu.setUserId(user.getId());
|
||||
deptPostUsers.add(BeanConv.toBean(dpu,DeptPostUser.class));
|
||||
});
|
||||
flag = deptPostUserService.saveBatch(deptPostUsers);
|
||||
if (!flag){
|
||||
throw new RuntimeException("保存部门职位中间表出错");
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
log.error("修改用户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.UPDATE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.LIST,key ="#userVO.hashCode()")
|
||||
public List<UserVO> findUserList(UserVO userVO) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
//构建多条件查询
|
||||
this.queryWrapper(queryWrapper,userVO);
|
||||
List<UserVO> records = BeanConv.toBeanList(list(queryWrapper),UserVO.class);
|
||||
if (!EmptyUtil.isNullOrEmpty(records)){
|
||||
List<Long> userIds = records.stream().map(UserVO::getId).collect(Collectors.toList());
|
||||
//查询对应角色
|
||||
List<RoleVO> roleVOList = roleMapper.findRoleVOListInUserId(userIds);
|
||||
//查询对应部门、职位
|
||||
List<DeptPostUserVO> deptPostUserVOList = deptPostUserService.findDeptPostUserVOListInUserId(userIds);
|
||||
//查询对应部门、职位
|
||||
records.forEach(n->{
|
||||
//装配角色
|
||||
Set<String> roleVOIds = Sets.newHashSet();
|
||||
roleVOList.forEach(r->{
|
||||
if (n.getId().equals(r.getUserId())){
|
||||
roleVOIds.add(String.valueOf(r.getId()));
|
||||
}
|
||||
});
|
||||
n.setRoleVOIds(roleVOIds);
|
||||
//装配对应部门、职位、数据权限
|
||||
Set<DeptPostUserVO> deptPostUserVOs = Sets.newHashSet();
|
||||
deptPostUserVOList.forEach(r->{
|
||||
if (n.getId().equals(r.getUserId())){
|
||||
deptPostUserVOs.add(r);
|
||||
}
|
||||
});
|
||||
n.setDeptPostUserVOs(deptPostUserVOs);
|
||||
});
|
||||
}
|
||||
return records;
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户表列表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.LIST,key ="#deptNo")
|
||||
public List<UserVO> findUserVOListByDeptNo(String deptNo) {
|
||||
try {
|
||||
return userMapper.findUserVOListByDeptNo(deptNo);
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.LIST,key ="#roleId")
|
||||
public List<UserVO> findUserVOListByRoleId(Long roleId) {
|
||||
try {
|
||||
return userMapper.findUserVOListByRoleId(roleId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean resetPasswords(String userId) {
|
||||
String password = bCryptPasswordEncoder.encode(securityConfigProperties.getPassworddDfaule());
|
||||
User user = User.builder().id(Long.valueOf(userId)).password(password).build();
|
||||
return updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.DATA_SECURITY,key ="#userId")
|
||||
public DataSecurityVO userDataSecurity(List<RoleVO> roleVOList, Long userId) {
|
||||
try {
|
||||
//角色集合不存在,直接返回空
|
||||
if (EmptyUtil.isNullOrEmpty(roleVOList)){
|
||||
return null;
|
||||
}
|
||||
DataSecurityVO dataSecurityVO = new DataSecurityVO();
|
||||
//角色集合中是否有本人权限
|
||||
List<Long> roleIds = roleVOList.stream()
|
||||
.filter(n -> SecurityConstant.DATA_SCOPE_0.equals(n.getDataScope()))
|
||||
.map(RoleVO::getId).collect(Collectors.toList());
|
||||
//角色集合有本人权限,返回youselfData为true,只能查看本人权限
|
||||
if (EmptyUtil.isNullOrEmpty(roleIds)){
|
||||
dataSecurityVO.setYouselfData(Boolean.FALSE);
|
||||
//角色集合中有自定义数据权限,返回youselfData为false,查询角色对应的数据权限
|
||||
QueryWrapper<RoleDept> queryWrapper = new QueryWrapper<>();
|
||||
roleIds = roleVOList.stream().map(RoleVO::getId).collect(Collectors.toList());
|
||||
queryWrapper.lambda().in(RoleDept::getRoleId,roleIds);
|
||||
List<RoleDept> roleDeptList = roleDeptMapper.selectList(queryWrapper);
|
||||
dataSecurityVO.setDeptNos(roleDeptList.stream().map(RoleDept::getDeptNo ).collect(Collectors.toList()));
|
||||
}else {
|
||||
dataSecurityVO.setYouselfData(Boolean.TRUE);
|
||||
}
|
||||
return dataSecurityVO;
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.LIST_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.LOGIN,key ="#username+'-'+#companyNo")
|
||||
public UserVO usernameLogin(String username,String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(User::getUsername,username).eq(User::getCompanyNo,companyNo)
|
||||
.eq(User::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper), UserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.FIND_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.LOGIN,key ="#mobile+'-'+#companyNo")
|
||||
public UserVO mobileLogin(String mobile,String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(User::getMobile,mobile).eq(User::getCompanyNo,companyNo)
|
||||
.eq(User::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper), UserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.FIND_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = UserCacheConstant.LOGIN,key ="#openId+'-'+#companyNo")
|
||||
public UserVO wechatLogin(String openId,String companyNo) {
|
||||
try {
|
||||
//构建查询条件
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(User::getOpenId,openId).eq(User::getCompanyNo,companyNo)
|
||||
.eq(User::getDataState, SuperConstant.DATA_STATE_0);
|
||||
return BeanConv.toBean(getOne(queryWrapper), UserVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("查询客户表异常:{}", ExceptionsUtil.getStackTraceAsString(e));
|
||||
throw new ProjectException(UserEnum.FIND_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.itheima.sfbx.security.web;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.AuthChannelVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.basic.BaseEnum;
|
||||
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
|
||||
import com.itheima.sfbx.security.service.IAuthChannelService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @ClassName AuthChannelController.java
|
||||
* @Description 三方通道配置
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("auth-channel")
|
||||
@Slf4j
|
||||
@Api(tags = "三方通道配置")
|
||||
public class AuthChannelController {
|
||||
|
||||
@Autowired
|
||||
IAuthChannelService authChannelService;
|
||||
|
||||
/**
|
||||
* @Description 三方通道配置列表
|
||||
* @param authChannelVO 查询条件
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("page/{pageNum}/{pageSize}")
|
||||
@ApiOperation(value = "查询三方通道配置分页",notes = "查询三方通道配置分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "authChannelVO",value = "三方通道配置查询对象",required = true,dataType = "AuthChannelVO"),
|
||||
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",dataType = "Integer"),
|
||||
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",dataType = "Integer")
|
||||
})
|
||||
public ResponseResult<Page<AuthChannelVO>> findAuthChannelVOPage(
|
||||
@RequestBody AuthChannelVO authChannelVO,
|
||||
@PathVariable("pageNum") int pageNum,
|
||||
@PathVariable("pageSize") int pageSize) {
|
||||
Page<AuthChannelVO> authChannelVOPage = authChannelService.findAuthChannelPage(authChannelVO, pageNum, pageSize);
|
||||
return ResponseResultBuild.build(BaseEnum.SUCCEED,authChannelVOPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 添加三方通道配置
|
||||
* @param authChannelVO 对象信息
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation(value = "添加三方通道配置",notes = "添加三方通道配置")
|
||||
@ApiImplicitParam(name = "authChannelVO",value = "三方通道配置对象",required = true,dataType = "AuthChannelVO")
|
||||
ResponseResult<AuthChannelVO> createAuthChannel(@RequestBody AuthChannelVO authChannelVO) {
|
||||
AuthChannelVO authChannelVOResult = authChannelService.createAuthChannel(authChannelVO);
|
||||
return ResponseResultBuild.build(BaseEnum.SUCCEED,authChannelVOResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 修改三方通道配置
|
||||
* @param authChannelVO 对象信息
|
||||
* @return
|
||||
*/
|
||||
@PatchMapping
|
||||
@ApiOperation(value = "修改三方通道配置",notes = "修改三方通道配置")
|
||||
@ApiImplicitParam(name = "authChannelVO",value = "三方通道配置对象",required = true,dataType = "AuthChannelVO")
|
||||
ResponseResult<Boolean> updateAuthChannel(@RequestBody AuthChannelVO authChannelVO) {
|
||||
Boolean flag = authChannelService.updateAuthChannel(authChannelVO);
|
||||
return ResponseResultBuild.build(BaseEnum.SUCCEED,flag);
|
||||
}
|
||||
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.itheima.sfbx.security.web;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
|
||||
import com.itheima.sfbx.framework.commons.dto.basic.TreeVO;
|
||||
import com.itheima.sfbx.framework.commons.dto.security.CompanyVO;
|
||||
import com.itheima.sfbx.framework.commons.enums.security.CompanyEnum;
|
||||
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
|
||||
import com.itheima.sfbx.security.service.ICompanyService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:企业前端控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "企业管理")
|
||||
@RestController
|
||||
@RequestMapping("company")
|
||||
public class CompanyController {
|
||||
|
||||
@Autowired
|
||||
ICompanyService companyService;
|
||||
|
||||
/***
|
||||
* @description 多条件查询企业分页列表
|
||||
* @param companyVO 企业Vo查询条件
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return: Page<CompanyVO>
|
||||
*/
|
||||
@PostMapping("page/{pageNum}/{pageSize}")
|
||||
@ApiOperation(value = "企业分页",notes = "企业分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "companyVO",value = "企业Vo对象",required = true,dataType = "CompanyVO"),
|
||||
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
|
||||
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
|
||||
})
|
||||
public ResponseResult<Page<CompanyVO>> findCompanyVOPage(
|
||||
@RequestBody CompanyVO companyVO,
|
||||
@PathVariable("pageNum") int pageNum,
|
||||
@PathVariable("pageSize") int pageSize) {
|
||||
Page<CompanyVO> companyVOPage = companyService.findCompanyPage(companyVO, pageNum, pageSize);
|
||||
return ResponseResultBuild.build(CompanyEnum.SUCCEED,companyVOPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 保存企业
|
||||
* @param companyVO 企业Vo对象
|
||||
* @return CompanyVO
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation(value = "企业添加",notes = "企业添加")
|
||||
@ApiImplicitParam(name = "companyVO",value = "企业Vo对象",required = true,dataType = "CompanyVO")
|
||||
public ResponseResult<CompanyVO> createCompany(@RequestBody CompanyVO companyVO) {
|
||||
CompanyVO companyVOResult = companyService.createCompany(companyVO);
|
||||
return ResponseResultBuild.build(CompanyEnum.SUCCEED,companyVOResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 修改企业
|
||||
* @param companyVO 企业Vo对象
|
||||
* @return Boolean 是否修改成功
|
||||
*/
|
||||
@PatchMapping
|
||||
@ApiOperation(value = "企业修改",notes = "企业修改")
|
||||
@ApiImplicitParam(name = "companyVO",value = "企业Vo对象",required = true,dataType = "CompanyVO")
|
||||
public ResponseResult<Boolean> updateCompany(@RequestBody CompanyVO companyVO) {
|
||||
Boolean flag = companyService.updateCompany(companyVO);
|
||||
return ResponseResultBuild.build(CompanyEnum.SUCCEED,flag);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* @description 多条件查询企业列表
|
||||
* @param companyVO 企业Vo对象
|
||||
* @return List<CompanyVO>
|
||||
*/
|
||||
@PostMapping("list")
|
||||
@ApiOperation(value = "企业列表",notes = "企业列表")
|
||||
@ApiImplicitParam(name = "companyVO",value = "企业Vo对象",required = true,dataType = "CompanyVO")
|
||||
public ResponseResult<List<CompanyVO>> companyList(@RequestBody CompanyVO companyVO) {
|
||||
List<CompanyVO> companyVOList = companyService.findCompanyList(companyVO);
|
||||
return ResponseResultBuild.build(CompanyEnum.SUCCEED,companyVOList);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user