first commit

This commit is contained in:
abcv7
2026-02-25 15:08:40 +08:00
commit 7f1d83ada7
2003 changed files with 144362 additions and 0 deletions
@@ -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"]
+92
View File
@@ -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>
@@ -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);
}
}
@@ -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();
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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> {
}
@@ -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> {
}
@@ -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> {
}
@@ -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);
}
@@ -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> {
}
@@ -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);
}
@@ -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);
}
@@ -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> {
}
@@ -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);
}
@@ -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> {
}
@@ -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);
}
@@ -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> {
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -0,0 +1,129 @@
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.CustomerVO;
import com.itheima.sfbx.framework.commons.dto.security.CustomerVO;
import com.itheima.sfbx.framework.commons.dto.security.UserVO;
import com.itheima.sfbx.framework.commons.enums.security.CustomerEnum;
import com.itheima.sfbx.framework.commons.utils.BeanConv;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.framework.commons.utils.SubjectContent;
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.List;
/**
* @Description:客户前端控制器
*/
@Slf4j
@Api(tags = "客户管理")
@RestController
@RequestMapping("customer")
public class CustomerController {
@Autowired
ICustomerService customerService;
/***
* @description 多条件查询客户分页列表
* @param customerVO 客户Vo查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return: Page<CustomerVO>
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "客户分页",notes = "客户分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "customerVO",value = "客户Vo对象",required = true,dataType = "CustomerVO"),
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
})
public ResponseResult<Page<CustomerVO>> findCustomerVOPage(
@RequestBody CustomerVO customerVO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<CustomerVO> customerVOPage = customerService.findCustomerPage(customerVO, pageNum, pageSize);
return ResponseResultBuild.build(CustomerEnum.SUCCEED,customerVOPage);
}
/**
* @Description 修改客户
* @param customerVO 客户Vo对象
* @return Boolean 是否修改成功
*/
@PatchMapping
@ApiOperation(value = "客户修改",notes = "客户修改")
@ApiImplicitParam(name = "customerVO",value = "客户Vo对象",required = true,dataType = "CustomerVO")
public ResponseResult<Boolean> updateCustomer(@RequestBody CustomerVO customerVO) {
Boolean flag = customerService.updateCustomer(customerVO);
return ResponseResultBuild.build(CustomerEnum.SUCCEED,flag);
}
/***
* @description 多条件查询客户列表
* @param customerVO 客户Vo对象
* @return List<CustomerVO>
*/
@PostMapping("list")
@ApiOperation(value = "客户列表",notes = "客户列表")
@ApiImplicitParam(name = "customerVO",value = "客户Vo对象",required = true,dataType = "CustomerVO")
public ResponseResult<List<CustomerVO>> customerList(@RequestBody CustomerVO customerVO) {
List<CustomerVO> customerVOList = customerService.findCustomerList(customerVO);
return ResponseResultBuild.build(CustomerEnum.SUCCEED,customerVOList);
}
@PostMapping("current-customer")
@ApiOperation(value = "当前客户",notes = "当前客户")
ResponseResult<CustomerVO> findCurrentCustomer() {
CustomerVO customerVO = BeanConv.toBean(SubjectContent.getUserVO(),CustomerVO.class);
return ResponseResultBuild.build(CustomerEnum.SUCCEED,customerVO);
}
/**
* @Description 重置密码
* @param customerId 客户Vo对象
* @return Boolean 是否修改成功
*/
@PostMapping("reset-passwords/{customerId}")
@ApiOperation(value = "密码重置",notes = "密码重置")
@ApiImplicitParam(paramType = "path",name = "customerId",value = "用戶Id",required = true,dataType = "String")
public ResponseResult<Boolean> resetPasswords(@PathVariable("customerId") String customerId) {
Boolean flag = customerService.resetPasswords(customerId);
return ResponseResultBuild.build(CustomerEnum.SUCCEED,flag);
}
/**
* @Description 登录验证码
* @param mobile 手机号码
* @return
*/
@PostMapping("loginCode/{mobile}")
@ApiOperation(value = "登录验证码",notes = "登录验证码")
@ApiImplicitParam(name = "mobile",value = "手机号",required = true,dataType = "String")
ResponseResult<Boolean> loginCode(@PathVariable("mobile")String mobile) {
Boolean flag = customerService.sendLoginCode(mobile);
return ResponseResultBuild.build(CustomerEnum.SUCCEED,flag);
}
/**
* @Description 注册
* @param customerVO 客户信息
* @return
*/
@ApiOperation(value = "注册客户",notes = "注册客户")
@ApiImplicitParam(name = "customerVO",value = "客户Vo对象",required = true,dataType = "CustomerVO")
@PostMapping("register-user")
ResponseResult<UserVO> registerUser(@RequestBody CustomerVO customerVO){
return ResponseResultBuild.build(CustomerEnum.SUCCEED,BeanConv.toBean(customerService.createCustomer(customerVO),UserVO.class));
}
}
@@ -0,0 +1,111 @@
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.DeptVO;
import com.itheima.sfbx.framework.commons.enums.security.DeptEnum;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.security.service.IDeptService;
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("dept")
public class DeptController {
@Autowired
IDeptService deptService;
/***
* @description 多条件查询部门分页列表
* @param deptVO 部门Vo查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return: Page<DeptVO>
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "部门分页",notes = "部门分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "deptVO",value = "部门Vo对象",required = true,dataType = "DeptVO"),
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
})
public ResponseResult<Page<DeptVO>> findDeptVOPage(
@RequestBody DeptVO deptVO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<DeptVO> deptVOPage = deptService.findDeptPage(deptVO, pageNum, pageSize);
return ResponseResultBuild.build(DeptEnum.SUCCEED,deptVOPage);
}
/**
* @Description 保存部门
* @param deptVO 部门Vo对象
* @return DeptVO
*/
@PutMapping
@ApiOperation(value = "部门添加",notes = "部门添加")
@ApiImplicitParam(name = "deptVO",value = "部门Vo对象",required = true,dataType = "DeptVO")
@ApiOperationSupport(includeParameters ={"deptVO.parentDeptNo",
"deptVO.deptName","deptVO.sortNo","deptVO.updateBy","deptVO.createBy"} )
public ResponseResult<DeptVO> createDept(@RequestBody DeptVO deptVO) {
DeptVO deptVOResult = deptService.createDept(deptVO);
return ResponseResultBuild.build(DeptEnum.SUCCEED,deptVOResult);
}
/**
* @Description 修改部门
* @param deptVO 部门Vo对象
* @return Boolean 是否修改成功
*/
@PatchMapping
@ApiOperation(value = "部门修改",notes = "部门修改")
@ApiImplicitParam(name = "deptVO",value = "部门Vo对象",required = true,dataType = "DeptVO")
public ResponseResult<Boolean> updateDept(@RequestBody DeptVO deptVO) {
Boolean flag = deptService.updateDept(deptVO);
return ResponseResultBuild.build(DeptEnum.SUCCEED,flag);
}
/***
* @description 多条件查询部门列表
* @param deptVO 部门Vo对象
* @return List<DeptVO>
*/
@PostMapping("list")
@ApiOperation(value = "部门列表",notes = "部门列表")
@ApiImplicitParam(name = "deptVO",value = "部门Vo对象",required = true,dataType = "DeptVO")
public ResponseResult<List<DeptVO>> deptList(@RequestBody DeptVO deptVO) {
List<DeptVO> deptVOList = deptService.findDeptList(deptVO);
return ResponseResultBuild.build(DeptEnum.SUCCEED,deptVOList);
}
/**
* @Description 组织部门树形
* @param deptVO 组织部门对象
* @return
*/
@PostMapping("tree")
@ApiOperation(value = "部门树形",notes = "部门树形")
@ApiImplicitParam(name = "deptVO",value = "组织部门对象",required = false,dataType = "DeptVO")
public ResponseResult<TreeVO> deptTreeVO(@RequestBody DeptVO deptVO) {
TreeVO treeVO = deptService.deptTreeVO(deptVO.getParentDeptNo(),deptVO.getCheckedDeptNos());
return ResponseResultBuild.build(DeptEnum.SUCCEED,treeVO);
}
}
@@ -0,0 +1,94 @@
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.PostVO;
import com.itheima.sfbx.framework.commons.enums.security.DeptEnum;
import com.itheima.sfbx.framework.commons.enums.security.PostEnum;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.security.service.IPostService;
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("post")
public class PostController {
@Autowired
IPostService postService;
/***
* @description 多条件查询岗位分页列表
* @param postVO 岗位Vo查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return: Page<PostVO>
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "岗位分页",notes = "岗位分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "postVO",value = "岗位Vo对象",required = true,dataType = "PostVO"),
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
})
public ResponseResult<Page<PostVO>> findPostVOPage(
@RequestBody PostVO postVO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<PostVO> postVOPage = postService.findPostPage(postVO, pageNum, pageSize);
return ResponseResultBuild.build(PostEnum.SUCCEED,postVOPage);
}
/**
* @Description 保存岗位
* @param postVO 岗位Vo对象
* @return PostVO
*/
@PutMapping
@ApiOperation(value = "岗位添加",notes = "岗位添加")
@ApiImplicitParam(name = "postVO",value = "岗位Vo对象",required = true,dataType = "PostVO")
public ResponseResult<PostVO> createPost(@RequestBody PostVO postVO) {
PostVO postVOResult = postService.createPost(postVO);
return ResponseResultBuild.build(PostEnum.SUCCEED,postVOResult);
}
/**
* @Description 修改岗位
* @param postVO 岗位Vo对象
* @return Boolean 是否修改成功
*/
@PatchMapping
@ApiOperation(value = "岗位修改",notes = "岗位修改")
@ApiImplicitParam(name = "postVO",value = "岗位Vo对象",required = true,dataType = "PostVO")
public ResponseResult<Boolean> updatePost(@RequestBody PostVO postVO) {
Boolean flag = postService.updatePost(postVO);
return ResponseResultBuild.build(PostEnum.SUCCEED,flag);
}
/***
* @description 多条件查询岗位列表
* @param postVO 岗位Vo对象
* @return List<PostVO>
*/
@PostMapping("list")
@ApiOperation(value = "岗位列表",notes = "岗位列表")
@ApiImplicitParam(name = "postVO",value = "岗位Vo对象",required = true,dataType = "PostVO")
public ResponseResult<List<PostVO>> postList(@RequestBody PostVO postVO) {
List<PostVO> postVOList = postService.findPostList(postVO);
return ResponseResultBuild.build(PostEnum.SUCCEED,postVOList);
}
}
@@ -0,0 +1,121 @@
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.basic.TreeVO;
import com.itheima.sfbx.framework.commons.dto.security.MenuVO;
import com.itheima.sfbx.framework.commons.dto.security.ResourceVO;
import com.itheima.sfbx.framework.commons.enums.security.DeptEnum;
import com.itheima.sfbx.framework.commons.enums.security.ResourceEnum;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.security.service.IResourceService;
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("resource")
public class ResourceController {
@Autowired
IResourceService resourceService;
/***
* @description 多条件资源分页查询
* @param resourceVO 资源Vo查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return: Page<ResourceVO>
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "资源分页",notes = "资源分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "resourceVO",value = "资源Vo对象",required = true,dataType = "ResourceVO"),
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
})
public ResponseResult<Page<ResourceVO>> findResourceVOPage(
@RequestBody ResourceVO resourceVO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<ResourceVO> resourceVOPage = resourceService.findResourcePage(resourceVO, pageNum, pageSize);
return ResponseResultBuild.build(ResourceEnum.SUCCEED,resourceVOPage);
}
/**
* @Description 保存资源
* @param resourceVO 资源Vo对象
* @return ResourceVO
*/
@PutMapping
@ApiOperation(value = "资源添加",notes = "资源添加")
@ApiImplicitParam(name = "resourceVO",value = "资源Vo对象",required = true,dataType = "ResourceVO")
public ResponseResult<ResourceVO> createResource(@RequestBody ResourceVO resourceVO) {
ResourceVO resourceVOResult = resourceService.createResource(resourceVO);
return ResponseResultBuild.build(ResourceEnum.SUCCEED,resourceVOResult);
}
/**
* @Description 修改资源
* @param resourceVO 资源Vo对象
* @return Boolean 是否修改成功
*/
@PatchMapping
@ApiOperation(value = "资源修改",notes = "资源修改")
@ApiImplicitParam(name = "resourceVO",value = "资源Vo对象",required = true,dataType = "ResourceVO")
public ResponseResult<Boolean> updateResource(@RequestBody ResourceVO resourceVO) {
Boolean flag = resourceService.updateResource(resourceVO);
return ResponseResultBuild.build(ResourceEnum.SUCCEED,flag);
}
/***
* @description 多条件查询资源列表
* @param resourceVO 资源Vo对象
* @return List<ResourceVO>
*/
@PostMapping("list")
@ApiOperation(value = "资源列表",notes = "资源列表")
@ApiImplicitParam(name = "resourceVO",value = "资源Vo对象",required = true,dataType = "ResourceVO")
public ResponseResult<List<ResourceVO>> resourceList(@RequestBody ResourceVO resourceVO) {
List<ResourceVO> resourceVOList = resourceService.findResourceList(resourceVO);
return ResponseResultBuild.build(ResourceEnum.SUCCEED,resourceVOList);
}
/**
* @Description 资源树形
* @param resourceVO 资源对象
* @return
*/
@PostMapping("tree")
@ApiOperation(value = "资源树形",notes = "资源树形")
@ApiImplicitParam(name = "resourceVO",value = "资源对象",required = false,dataType = "ResourceVO")
public ResponseResult<TreeVO> resourceTreeVO(@RequestBody ResourceVO resourceVO) {
TreeVO treeVO = resourceService.resourceTreeVO(resourceVO.getParentResourceNo(), resourceVO.getCheckedResourceNos());
return ResponseResultBuild.build(ResourceEnum.SUCCEED,treeVO);
}
/**
* @Description 左侧菜单
* @return
*/
@PostMapping("menus/{systemCode}")
@ApiOperation(value = "左侧菜单",notes = "左侧菜单")
@ApiImplicitParam(name = "systemCode",value = "系统code",required = false,dataType = "systemCode")
public ResponseResult<List<MenuVO>> menus(@PathVariable("systemCode") String systemCode) {
List<MenuVO> menus = resourceService.menus(systemCode);
return ResponseResultBuild.build(ResourceEnum.SUCCEED,menus);
}
}
@@ -0,0 +1,93 @@
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.RoleVO;
import com.itheima.sfbx.framework.commons.enums.security.RoleEnum;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.security.service.IRoleService;
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("role")
public class RoleController {
@Autowired
IRoleService roleService;
/***
* @description 多条件查询角色分页列表
* @param roleVO 角色Vo查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return: Page<RoleVO>
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "角色分页",notes = "角色分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "roleVO",value = "角色Vo对象",required = true,dataType = "RoleVO"),
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
})
public ResponseResult<Page<RoleVO>> findRoleVOPage(
@RequestBody RoleVO roleVO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<RoleVO> roleVOPage = roleService.findRolePage(roleVO, pageNum, pageSize);
return ResponseResultBuild.build(RoleEnum.SUCCEED,roleVOPage);
}
/**
* @Description 保存角色
* @param roleVO 角色Vo对象
* @return RoleVO
*/
@PutMapping
@ApiOperation(value = "角色添加",notes = "角色添加")
@ApiImplicitParam(name = "roleVO",value = "角色Vo对象",required = true,dataType = "RoleVO")
public ResponseResult<RoleVO> createRole(@RequestBody RoleVO roleVO) {
RoleVO roleVOResult = roleService.createRole(roleVO);
return ResponseResultBuild.build(RoleEnum.SUCCEED,roleVOResult);
}
/**
* @Description 修改角色
* @param roleVO 角色Vo对象
* @return Boolean 是否修改成功
*/
@PatchMapping
@ApiOperation(value = "角色修改",notes = "角色修改")
@ApiImplicitParam(name = "roleVO",value = "角色Vo对象",required = true,dataType = "RoleVO")
public ResponseResult<Boolean> updateRole(@RequestBody RoleVO roleVO) {
Boolean flag = roleService.updateRole(roleVO);
return ResponseResultBuild.build(RoleEnum.SUCCEED,flag);
}
/***
* @description 多条件查询角色列表
* @param roleVO 角色Vo对象
* @return List<RoleVO>
*/
@PostMapping("list")
@ApiOperation(value = "角色列表",notes = "角色列表")
@ApiImplicitParam(name = "roleVO",value = "角色Vo对象",required = true,dataType = "RoleVO")
public ResponseResult<List<RoleVO>> roleList(@RequestBody RoleVO roleVO) {
List<RoleVO> roleVOList = roleService.findRoleList(roleVO);
return ResponseResultBuild.build(RoleEnum.SUCCEED,roleVOList);
}
}
@@ -0,0 +1,114 @@
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.UserVO;
import com.itheima.sfbx.framework.commons.enums.security.UserEnum;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.framework.commons.utils.SubjectContent;
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;
/**
* @Description:用户前端控制器
*/
@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserController {
@Autowired
IUserService userService;
/***
* @description 多条件查询用户分页列表
* @param userVO 用户Vo查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return: Page<UserVO>
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "用户分页",notes = "用户分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "userVO",value = "用户Vo对象",required = true,dataType = "UserVO"),
@ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
@ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
})
public ResponseResult<Page<UserVO>> findUserVOPage(
@RequestBody UserVO userVO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<UserVO> userVOPage = userService.findUserPage(userVO, pageNum, pageSize);
return ResponseResultBuild.build(UserEnum.SUCCEED,userVOPage);
}
/**
* @Description 保存用户
* @param userVO 用户Vo对象
* @return UserVO
*/
@PutMapping
@ApiOperation(value = "用户添加",notes = "用户添加")
@ApiImplicitParam(name = "userVO",value = "用户Vo对象",required = true,dataType = "UserVO")
public ResponseResult<UserVO> createUser(@RequestBody UserVO userVO) {
UserVO userVOResult = userService.createUser(userVO);
return ResponseResultBuild.build(UserEnum.SUCCEED,userVOResult);
}
/**
* @Description 修改用户
* @param userVO 用户Vo对象
* @return Boolean 是否修改成功
*/
@PatchMapping
@ApiOperation(value = "用户修改",notes = "用户修改")
@ApiImplicitParam(name = "userVO",value = "用户Vo对象",required = true,dataType = "UserVO")
public ResponseResult<Boolean> updateUser(@RequestBody UserVO userVO) {
Boolean flag = userService.updateUser(userVO);
return ResponseResultBuild.build(UserEnum.SUCCEED,flag);
}
/***
* @description 多条件查询用户列表
* @param userVO 用户Vo对象
* @return List<UserVO>
*/
@PostMapping("list")
@ApiOperation(value = "用户列表",notes = "用户列表")
@ApiImplicitParam(name = "userVO",value = "用户Vo对象",required = true,dataType = "UserVO")
public ResponseResult<List<UserVO>> userList(@RequestBody UserVO userVO) {
List<UserVO> userVOList = userService.findUserList(userVO);
return ResponseResultBuild.build(UserEnum.SUCCEED,userVOList);
}
@PostMapping("current-user")
@ApiOperation(value = "当前用户",notes = "当前用户")
ResponseResult<UserVO> findCurrentUser() {
UserVO userVO = SubjectContent.getUserVO();
return ResponseResultBuild.build(UserEnum.SUCCEED,userVO);
}
/**
* @Description 重置密码
* @param userId 用户Vo对象
* @return Boolean 是否修改成功
*/
@PostMapping("reset-passwords/{userId}")
@ApiOperation(value = "密码重置",notes = "密码重置")
@ApiImplicitParam(paramType = "path",name = "userId",value = "用戶Id",required = true,dataType = "String")
public ResponseResult<Boolean> resetPasswords(@PathVariable("userId") String userId) {
Boolean flag = userService.resetPasswords(userId);
return ResponseResultBuild.build(UserEnum.SUCCEED,flag);
}
}
@@ -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,52 @@
#服务配置
server:
#端口
port: 7079
#服务编码
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-web
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-seata.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
- data-id: shared-spring-task.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
- data-id: shared-redisson.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
- data-id: shared-mybatis-plus.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,46 @@
#服务配置
server:
#端口
port: 7079
#服务编码
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-web
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-seata.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
- data-id: shared-spring-task.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
- data-id: shared-redisson.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
- data-id: shared-mybatis-plus.yml #配置文件名-DataId
group: SEATA_GROUP
refresh: false
logging:
config: classpath:logback.xml
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 -->
<property name="LOG_HOME" value="/data/logs/security-web" />
<!-- 控制台输出 -->
<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-web.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>