commit init

This commit is contained in:
weihongyang 2022-06-20 16:26:51 +08:00
commit 7aaa6700b3
171 changed files with 9178 additions and 0 deletions

25
.gitignore vendored Normal file
View File

@ -0,0 +1,25 @@
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
target
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
*.iml
.idea
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

227
pom.xml Normal file
View File

@ -0,0 +1,227 @@
<?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>
<groupId>com.cnbm</groupId>
<artifactId>ym-pass</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>ym-common</module>
<module>ym-admin</module>
<module>ym-generator</module>
<module>ym-gateway</module>
<module>ym-barcode</module>
<module>ym-basic</module>
</modules>
<packaging>pom</packaging>
<name>ym-pass</name>
<description>轻工业自动化研究所springboot框架</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<junit.version>4.13.2</junit.version>
<jedis.version>4.2.2</jedis.version>
<!-- <druid.version>1.2.9</druid.version>-->
<mybatisplus.version>3.5.1</mybatisplus.version>
<sqlserver.version>4.0</sqlserver.version>
<oracle.version>11.2.0.3</oracle.version>
<commons.lang.version>3.12.0</commons.lang.version>
<commons.fileupload.version>1.4</commons.fileupload.version>
<commons.io.version>2.11.0</commons.io.version>
<commons.codec.version>1.15</commons.codec.version>
<guava.version>31.0-jre</guava.version>
<joda.time.version>2.10.14</joda.time.version>
<hutool.version>5.7.22</hutool.version>
<gson.version>2.9.0</gson.version>
<jsoup.version>1.14.3</jsoup.version>
<knife4j.version>2.0.2</knife4j.version>
<lombok.version>1.18.24</lombok.version>
<docker.plugin.version>1.1.1</docker.plugin.version>
<easypoi.version>4.4.0</easypoi.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- oracle驱动 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.version}</version>
</dependency>
<!-- sqlserver驱动 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>${sqlserver.version}</version>
</dependency>
<!-- postgresql驱动 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>${easypoi.version}</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>${easypoi.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatisplus.version}</version>
<exclusions>
<exclusion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons.fileupload.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<!-- 阿里云maven仓库 -->
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>https://maven.aliyun.com/repository/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>https://maven.aliyun.com/repository/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

44
ym-admin/pom.xml Normal file
View File

@ -0,0 +1,44 @@
<?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">
<parent>
<artifactId>ym-pass</artifactId>
<groupId>com.cnbm</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ym-admin</artifactId>
<packaging>jar</packaging>
<properties>
<quartz.version>2.3.2</quartz.version>
<shiro.version>1.9.0</shiro.version>
<captcha.version>1.6.2</captcha.version>
<easypoi.version>4.1.0</easypoi.version>
<qiniu.version>7.2.27</qiniu.version>
<aliyun.oss.version>2.8.3</aliyun.oss.version>
<aliyun.core.version>3.2.2</aliyun.core.version>
<qcloud.cos.version>5.4.4</qcloud.cos.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>com.cnbm</groupId>
<artifactId>ym-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,28 @@
package com.cnbm.admin.Expression;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysMenuEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author weihongyang
* @Date 2022/6/13 8:29 AM
* @Version 1.0
*/
@Component("ex")
public class SGExpressionRoot {
public boolean hasAuthority(String authority){
//获取当前用户的权限
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
List<String> permissions = loginUser.getPermissions();
//判断用户权限集合中是否存在authority
return permissions.contains(authority);
}
}

View File

@ -0,0 +1,16 @@
package com.cnbm.admin.annotation;
import java.lang.annotation.*;
/**
* @Author weihongyang
* @Date 2022/6/10 9:40 AM
* @Version 1.0
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LogOperation {
String value() default "";
}

View File

@ -0,0 +1,105 @@
package com.cnbm.admin.aspect;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysLogOperationEntity;
import com.cnbm.admin.enums.OperationStatusEnum;
import com.cnbm.admin.service.SysLogOperationService;
import com.cnbm.common.utils.HttpContextUtils;
import com.cnbm.common.utils.IpUtils;
import com.cnbm.common.utils.JsonUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
/**
* @Author weihongyang
* @Date 2022/6/10 9:41 AM
* @Version 1.0
*/
@Aspect
@Component
public class LogOperationAspect {
@Autowired
private SysLogOperationService sysLogOperationService;
@Pointcut("@annotation(com.cnbm.admin.annotation.LogOperation)")
public void logPointCut() {
}
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
long beginTime = System.currentTimeMillis();
try {
//执行方法
Object result = point.proceed();
//执行时长(毫秒)
long time = System.currentTimeMillis() - beginTime;
//保存日志
saveLog(point, time, OperationStatusEnum.SUCCESS.value());
return result;
}catch(Exception e) {
//执行时长(毫秒)
long time = System.currentTimeMillis() - beginTime;
//保存日志
saveLog(point, time, OperationStatusEnum.FAIL.value());
throw e;
}
}
private void saveLog(ProceedingJoinPoint joinPoint, long time, Integer status) throws Exception {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes());
LogOperation annotation = method.getAnnotation(LogOperation.class);
SysLogOperationEntity log = new SysLogOperationEntity();
if(annotation != null){
//注解上的描述
log.setOperation(annotation.value());
}
//登录用户信息
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
if(loginUser != null){
log.setCreatorName(loginUser.getUsername());
}
log.setStatus(status);
log.setRequestTime((int)time);
//请求相关信息
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
log.setIp(IpUtils.getIpAddr(request));
log.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
log.setRequestUri(request.getRequestURI());
log.setRequestMethod(request.getMethod());
//请求参数
Object[] args = joinPoint.getArgs();
try{
String params = JsonUtils.toJsonString(args[0]);
log.setRequestParams(params);
}catch (Exception e){
}
//保存到DB
sysLogOperationService.save(log);
}
}

View File

@ -0,0 +1,30 @@
package com.cnbm.admin.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Author weihongyang
* @Date 2022/6/8 10:47 AM
* @Version 1.0
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
// 设置允许跨域请求的域名
.allowedOriginPatterns("*")
// 是否允许cookie
.allowCredentials(true)
// 设置允许的请求方式
.allowedMethods("GET", "POST", "DELETE", "PUT")
// 设置允许的header属性
.allowedHeaders("*")
// 跨域允许时间
.maxAge(3600);
}
}

View File

@ -0,0 +1,74 @@
package com.cnbm.admin.config;
import com.cnbm.admin.filter.JwtAuthenticationTokenFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
/**
* @Author weihongyang
* @Date 2022/6/8 1:51 PM
* @Version 1.0
*/
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//创建BCryptPasswordEncoder注入容器
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Autowired
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
@Autowired
private AuthenticationEntryPoint authenticationEntryPoint;
@Autowired
private AccessDeniedHandler accessDeniedHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
//关闭csrf
.csrf().disable()
//不通过Session获取SecurityContext
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
// 对于登录接口 允许匿名访问
.antMatchers("/login").anonymous()
// .antMatchers("/testCors").hasAuthority("system:dept:list222")
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();
//添加过滤器
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
//配置异常处理器
http.exceptionHandling()
//配置认证失败处理器
.authenticationEntryPoint(authenticationEntryPoint)
.accessDeniedHandler(accessDeniedHandler);
//允许跨域
http.cors();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}

View File

@ -0,0 +1,43 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.params.LoginParam;
import com.cnbm.admin.service.LoginService;
import com.cnbm.admin.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* @Author weihongyang
* @Date 2022/6/7 3:55 PM
* @Version 1.0
*/
@RestController
@Api(tags="登录管理")
@Log4j2
public class LoginController {
@Autowired
private LoginService loginService;
@RequestMapping("/hello")
@PreAuthorize("@ex.hasAuthority('sys:user:page')")
public String hello(){
log.info("hello");
return "hello";
}
@PostMapping("/login")
@ApiOperation(value = "登录")
public ResponseResult login(HttpServletRequest request, @RequestBody LoginParam loginParam) {
return loginService.login(request,loginParam);
}
}

View File

@ -0,0 +1,90 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysDeptDTO;
import com.cnbm.admin.service.SysDeptService;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 1:40 PM
* @Version 1.0
*/
@RestController
@RequestMapping("/sys/dept")
@Api(tags="部门管理")
public class SysDeptController {
@Autowired
private SysDeptService sysDeptService;
@GetMapping("list")
@ApiOperation("列表")
@PreAuthorize("@ex.hasAuthority('sys:dept:list')")
public Result<List<SysDeptDTO>> list(){
List<SysDeptDTO> list = sysDeptService.list(new HashMap<>(1));
return new Result<List<SysDeptDTO>>().ok(list);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:dept:info')")
public Result<SysDeptDTO> get(@PathVariable("id") Long id){
SysDeptDTO data = sysDeptService.get(id);
return new Result<SysDeptDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:dept:save')")
public Result save(@RequestBody SysDeptDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysDeptService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:dept:update')")
public Result update(@RequestBody SysDeptDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysDeptService.update(dto);
return new Result();
}
@DeleteMapping("{id}")
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:dept:delete')")
public Result delete(@PathVariable("id") Long id){
//效验数据
AssertUtils.isNull(id, "id");
sysDeptService.delete(id);
return new Result();
}
}

View File

@ -0,0 +1,102 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysDictDataDTO;
import com.cnbm.admin.service.SysDictDataService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:55 AM
* @Version 1.0
*/
@RestController
@RequestMapping("sys/dict/data")
@Api(tags="字典数据")
public class SysDictDataController {
@Autowired
private SysDictDataService sysDictDataService;
@GetMapping("page")
@ApiOperation("字典数据")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = "dictLabel", value = "字典标签", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "dictValue", value = "字典值", paramType = "query", dataType="String")
})
@PreAuthorize("@ex.hasAuthority('sys:dept:page')")
public Result<PageData<SysDictDataDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
//字典类型
PageData<SysDictDataDTO> page = sysDictDataService.page(params);
return new Result<PageData<SysDictDataDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:dict:info')")
public Result<SysDictDataDTO> get(@PathVariable("id") Long id){
SysDictDataDTO data = sysDictDataService.get(id);
return new Result<SysDictDataDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:dict:save')")
public Result save(@RequestBody SysDictDataDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, DefaultGroup.class);
sysDictDataService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:dict:update')")
public Result update(@RequestBody SysDictDataDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysDictDataService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:dict:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
sysDictDataService.delete(ids);
return new Result();
}
}

View File

@ -0,0 +1,112 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysDictTypeDTO;
import com.cnbm.admin.entity.DictType;
import com.cnbm.admin.service.SysDictTypeService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:55 AM
* @Version 1.0
*/
@RestController
@RequestMapping("sys/dict/type")
@Api(tags="字典类型")
public class SysDictTypeController {
@Autowired
private SysDictTypeService sysDictTypeService;
@GetMapping("page")
@ApiOperation("字典类型")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = "dictType", value = "字典类型", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "dictName", value = "字典名称", paramType = "query", dataType="String")
})
@PreAuthorize("@ex.hasAuthority('sys:dict:page')")
public Result<PageData<SysDictTypeDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
//字典类型
PageData<SysDictTypeDTO> page = sysDictTypeService.page(params);
return new Result<PageData<SysDictTypeDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:dict:info')")
public Result<SysDictTypeDTO> get(@PathVariable("id") Long id){
SysDictTypeDTO data = sysDictTypeService.get(id);
return new Result<SysDictTypeDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:dict:save')")
public Result save(@RequestBody SysDictTypeDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, DefaultGroup.class);
sysDictTypeService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:dict:update')")
public Result update(@RequestBody SysDictTypeDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysDictTypeService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:dict:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
sysDictTypeService.delete(ids);
return new Result();
}
@GetMapping("all")
@ApiOperation("所有字典数据")
public Result<List<DictType>> all(){
List<DictType> list = sysDictTypeService.getAllList();
return new Result<List<DictType>>().ok(list);
}
}

View File

@ -0,0 +1,61 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysLogErrorDTO;
import com.cnbm.admin.execl.SysLogErrorExcel;
import com.cnbm.admin.service.SysLogErrorService;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 2:06 PM
* @Version 1.0
*/
@RestController
@RequestMapping("sys/log/error")
@Api(tags="异常日志")
public class SysLogErrorController {
@Autowired
private SysLogErrorService sysLogErrorService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
public Result<PageData<SysLogErrorDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysLogErrorDTO> page = sysLogErrorService.page(params);
return new Result<PageData<SysLogErrorDTO>>().ok(page);
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<SysLogErrorDTO> list = sysLogErrorService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, SysLogErrorExcel.class);
}
}

View File

@ -0,0 +1,62 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysLogOperationDTO;
import com.cnbm.admin.execl.SysLogOperationExcel;
import com.cnbm.admin.service.SysLogOperationService;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 9:51 AM
* @Version 1.0
*/
@RestController
@RequestMapping("sys/log/operation")
@Api(tags="操作日志")
public class SysLogOperationController {
@Autowired
private SysLogOperationService sysLogOperationService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = "status", value = "状态 0失败 1成功", paramType = "query", dataType="int")
})
public Result<PageData<SysLogOperationDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysLogOperationDTO> page = sysLogOperationService.page(params);
return new Result<PageData<SysLogOperationDTO>>().ok(page);
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<SysLogOperationDTO> list = sysLogOperationService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, SysLogOperationExcel.class);
}
}

View File

@ -0,0 +1,136 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysMenuDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.enums.MenuTypeEnum;
import com.cnbm.admin.service.SysMenuService;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.DefaultGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @Author weihongyang
* @Date 2022/6/10 2:32 PM
* @Version 1.0
*/
@RestController
@RequestMapping("/sys/menu")
@Api(tags="菜单管理")
public class SysMenuController {
@Autowired
private SysMenuService sysMenuService;
@GetMapping("nav")
@ApiOperation("导航")
public Result<List<SysMenuDTO>> nav(){
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
List<SysMenuDTO> list = sysMenuService.getUserMenuList(user, MenuTypeEnum.MENU.value());
return new Result<List<SysMenuDTO>>().ok(list);
}
@GetMapping("permissions")
@ApiOperation("权限标识")
public Result<Set<String>> permissions(){
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
Set<String> set = sysMenuService.getUserPermissions(user);
return new Result<Set<String>>().ok(set);
}
@GetMapping("list")
@ApiOperation("列表")
@ApiImplicitParam(name = "type", value = "菜单类型 0菜单 1按钮 null全部", paramType = "query", dataType="int")
@PreAuthorize("@ex.hasAuthority('sys:menu:list')")
public Result<List<SysMenuDTO>> list(Integer type){
List<SysMenuDTO> list = sysMenuService.getAllMenuList(type);
return new Result<List<SysMenuDTO>>().ok(list);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:menu:info')")
public Result<SysMenuDTO> get(@PathVariable("id") Long id){
SysMenuDTO data = sysMenuService.get(id);
return new Result<SysMenuDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:menu:save')")
public Result save(@RequestBody SysMenuDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, DefaultGroup.class);
sysMenuService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:menu:update')")
public Result update(@RequestBody SysMenuDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, DefaultGroup.class);
sysMenuService.update(dto);
return new Result();
}
@DeleteMapping("{id}")
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:menu:delete')")
public Result delete(@PathVariable("id") Long id){
//效验数据
AssertUtils.isNull(id, "id");
//判断是否有子菜单或按钮
List<SysMenuDTO> list = sysMenuService.getListPid(id);
if(list.size() > 0){
return new Result().error(ErrorCode.SUB_MENU_EXIST);
}
sysMenuService.delete(id);
return new Result();
}
@GetMapping("select")
@ApiOperation("角色菜单权限")
@PreAuthorize("@ex.hasAuthority('sys:menu:select')")
public Result<List<SysMenuDTO>> select(){
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
List<SysMenuDTO> list = sysMenuService.getUserMenuList(user, null);
return new Result<List<SysMenuDTO>>().ok(list);
}
}

View File

@ -0,0 +1,116 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysParamsDTO;
import com.cnbm.admin.execl.SysParamsExcel;
import com.cnbm.admin.service.SysParamsService;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:20 AM
* @Version 1.0
*/
@RestController
@RequestMapping("sys/params")
@Api(tags="参数管理")
public class SysParamsController {
@Autowired
private SysParamsService sysParamsService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String")
})
@PreAuthorize("@ex.hasAuthority('sys:params:page')")
public Result<PageData<SysParamsDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysParamsDTO> page = sysParamsService.page(params);
return new Result<PageData<SysParamsDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:params:info')")
public Result<SysParamsDTO> get(@PathVariable("id") Long id){
SysParamsDTO data = sysParamsService.get(id);
return new Result<SysParamsDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:params:save')")
public Result save(@RequestBody SysParamsDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysParamsService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:params:update')")
public Result update(@RequestBody SysParamsDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysParamsService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:params:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
sysParamsService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String")
@PreAuthorize("@ex.hasAuthority('sys:params:export')")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<SysParamsDTO> list = sysParamsService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, SysParamsExcel.class);
}
}

View File

@ -0,0 +1,125 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.SysRoleDTO;
import com.cnbm.admin.service.SysRoleDataScopeService;
import com.cnbm.admin.service.SysRoleMenuService;
import com.cnbm.admin.service.SysRoleService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:04 AM
* @Version 1.0
*/
@RestController
@RequestMapping("/sys/role")
@Api(tags="角色管理")
public class SysRoleController {
@Autowired
private SysRoleService sysRoleService;
@Autowired
private SysRoleMenuService sysRoleMenuService;
@Autowired
private SysRoleDataScopeService sysRoleDataScopeService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = "name", value = "角色名", paramType = "query", dataType="String")
})
@PreAuthorize("@ex.hasAuthority('sys:role:page')")
public Result<PageData<SysRoleDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysRoleDTO> page = sysRoleService.page(params);
return new Result<PageData<SysRoleDTO>>().ok(page);
}
@GetMapping("list")
@ApiOperation("列表")
@PreAuthorize("@ex.hasAuthority('sys:role:list')")
public Result<List<SysRoleDTO>> list(){
List<SysRoleDTO> data = sysRoleService.list(new HashMap<>(1));
return new Result<List<SysRoleDTO>>().ok(data);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:role:info')")
public Result<SysRoleDTO> get(@PathVariable("id") Long id){
SysRoleDTO data = sysRoleService.get(id);
//查询角色对应的菜单
List<Long> menuIdList = sysRoleMenuService.getMenuIdList(id);
data.setMenuIdList(menuIdList);
//查询角色对应的数据权限
List<Long> deptIdList = sysRoleDataScopeService.getDeptIdList(id);
data.setDeptIdList(deptIdList);
return new Result<SysRoleDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:role:save')")
public Result save(@RequestBody SysRoleDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysRoleService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:role:update')")
public Result update(@RequestBody SysRoleDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysRoleService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:role:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
sysRoleService.delete(ids);
return new Result();
}
}

View File

@ -0,0 +1,163 @@
package com.cnbm.admin.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.admin.dto.PasswordDTO;
import com.cnbm.admin.dto.SysUserDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.execl.SysUserExcel;
import com.cnbm.admin.service.SysRoleUserService;
import com.cnbm.admin.service.SysUserService;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.admin.utils.PasswordUtils;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:23 PM
* @Version 1.0
*/
@RestController
@RequestMapping("/sys/user")
@Api(tags="用户管理")
public class SysUserController {
@Autowired
private SysUserService sysUserService;
@Autowired
private SysRoleUserService sysRoleUserService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "gender", value = "性别", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "deptId", value = "部门ID", paramType = "query", dataType="String")
})
@PreAuthorize("@ex.hasAuthority('sys:user:page')")
public Result<PageData<SysUserDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysUserDTO> page = sysUserService.page(params);
return new Result<PageData<SysUserDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('sys:user:info')")
public Result<SysUserDTO> get(@PathVariable("id") Long id){
SysUserDTO data = sysUserService.get(id);
//用户角色列表
List<Long> roleIdList = sysRoleUserService.getRoleIdList(id);
data.setRoleIdList(roleIdList);
return new Result<SysUserDTO>().ok(data);
}
@GetMapping("info")
@ApiOperation("登录用户信息")
public Result<SysUserDTO> info(){
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserDTO data = ConvertUtils.sourceToTarget(loginUser.getSysUserEntity(), SysUserDTO.class);
return new Result<SysUserDTO>().ok(data);
}
@PutMapping("password")
@ApiOperation("修改密码")
@LogOperation("修改密码")
public Result password(@RequestBody PasswordDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto);
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
//原密码不正确
if(!PasswordUtils.matches(dto.getPassword(), user.getPassword())){
return new Result().error(ErrorCode.PASSWORD_ERROR);
}
sysUserService.updatePassword(user.getId(), dto.getNewPassword());
return new Result();
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('sys:user:save')")
public Result save(@RequestBody SysUserDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysUserService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('sys:user:update')")
public Result update(@RequestBody SysUserDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysUserService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('sys:user:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
sysUserService.deleteBatchIds(Arrays.asList(ids));
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataType="String")
@PreAuthorize("@ex.hasAuthority('sys:user:export')")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<SysUserDTO> list = sysUserService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, SysUserExcel.class);
}
}

View File

@ -0,0 +1,14 @@
package com.cnbm.admin.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cnbm.admin.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author weihongyang
* @Date 2022/6/8 9:20 AM
* @Version 1.0
*/
@Mapper
public interface LoginDao extends BaseMapper<SysUserEntity> {
}

View File

@ -0,0 +1,33 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysDeptEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:40 PM
* @Version 1.0
*/
@Mapper
public interface SysDeptDao extends BaseDao<SysDeptEntity> {
List<SysDeptEntity> getList(Map<String, Object> params);
SysDeptEntity getById(Long id);
/**
* 获取所有部门的idpid列表
*/
List<SysDeptEntity> getIdAndPidList();
/**
* 根据部门ID获取所有子部门ID列表
* @param id 部门ID
*/
List<Long> getSubDeptIdList(String id);
}

View File

@ -0,0 +1,22 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.DictData;
import com.cnbm.admin.entity.SysDictDataEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:56 AM
* @Version 1.0
*/
@Mapper
public interface SysDictDataDao extends BaseDao<SysDictDataEntity> {
/**
* 字典数据列表
*/
List<DictData> getDictDataList();
}

View File

@ -0,0 +1,23 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.DictType;
import com.cnbm.admin.entity.SysDictTypeEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:56 AM
* @Version 1.0
*/
@Mapper
public interface SysDictTypeDao extends BaseDao<SysDictTypeEntity> {
/**
* 字典类型列表
*/
List<DictType> getDictTypeList();
}

View File

@ -0,0 +1,15 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysLogErrorEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author weihongyang
* @Date 2022/6/10 2:07 PM
* @Version 1.0
*/
@Mapper
public interface SysLogErrorDao extends BaseDao<SysLogErrorEntity> {
}

View File

@ -0,0 +1,15 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysLogOperationEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author weihongyang
* @Date 2022/6/10 9:54 AM
* @Version 1.0
*/
@Mapper
public interface SysLogOperationDao extends BaseDao<SysLogOperationEntity> {
}

View File

@ -0,0 +1,52 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysMenuEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 2:33 PM
* @Version 1.0
*/
@Mapper
public interface SysMenuDao extends BaseDao<SysMenuEntity> {
SysMenuEntity getById(@Param("id") Long id);
/**
* 查询所有菜单列表
*
* @param type 菜单类型
*/
List<SysMenuEntity> getMenuList(@Param("type") Integer type);
/**
* 查询用户菜单列表
*
* @param userId 用户ID
* @param type 菜单类型
*/
List<SysMenuEntity> getUserMenuList(@Param("userId") Long userId, @Param("type") Integer type);
/**
* 查询用户权限列表
* @param userId 用户ID
*/
List<String> getUserPermissionsList(Long userId);
/**
* 查询所有权限列表
*/
List<String> getPermissionsList();
/**
* 根据父菜单查询子菜单
* @param pid 父菜单ID
*/
List<SysMenuEntity> getListPid(Long pid);
}

View File

@ -0,0 +1,37 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysParamsEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:21 AM
* @Version 1.0
*/
@Mapper
public interface SysParamsDao extends BaseDao<SysParamsEntity> {
/**
* 根据参数编码查询value
* @param paramCode 参数编码
* @return 参数值
*/
String getValueByCode(String paramCode);
/**
* 获取参数编码列表
* @param ids ids
* @return 返回参数编码列表
*/
List<String> getParamCodeList(Long[] ids);
/**
* 根据参数编码更新value
* @param paramCode 参数编码
* @param paramValue 参数值
*/
int updateValueByCode(@Param("paramCode") String paramCode, @Param("paramValue") String paramValue);
}

View File

@ -0,0 +1,16 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysRoleEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author weihongyang
* @Date 2022/6/12 10:05 AM
* @Version 1.0
*/
@Mapper
public interface SysRoleDao extends BaseDao<SysRoleEntity> {
}

View File

@ -0,0 +1,32 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysRoleDataScopeEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:15 AM
* @Version 1.0
*/
@Mapper
public interface SysRoleDataScopeDao extends BaseDao<SysRoleDataScopeEntity> {
/**
* 根据角色ID获取部门ID列表
*/
List<Long> getDeptIdList(Long roleId);
/**
* 获取用户的部门数据权限列表
*/
List<Long> getDataScopeList(Long userId);
/**
* 根据角色id删除角色数据权限关系
* @param roleIds 角色ids
*/
void deleteByRoleIds(Long[] roleIds);
}

View File

@ -0,0 +1,34 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysRoleMenuEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 2:15 PM
* @Version 1.0
*/
@Mapper
public interface SysRoleMenuDao extends BaseDao<SysRoleMenuEntity> {
/**
* 根据角色ID获取菜单ID列表
*/
List<Long> getMenuIdList(Long roleId);
/**
* 根据角色id删除角色菜单关系
* @param roleIds 角色ids
*/
void deleteByRoleIds(Long[] roleIds);
/**
* 根据菜单id删除角色菜单关系
* @param menuId 菜单id
*/
void deleteByMenuId(Long menuId);
}

View File

@ -0,0 +1,36 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysRoleUserEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 1:35 PM
* @Version 1.0
*/
@Mapper
public interface SysRoleUserDao extends BaseDao<SysRoleUserEntity> {
/**
* 根据角色ids删除角色用户关系
* @param roleIds 角色ids
*/
void deleteByRoleIds(Long[] roleIds);
/**
* 根据用户id删除角色用户关系
* @param userIds 用户ids
*/
void deleteByUserIds(Long[] userIds);
/**
* 角色ID列表
* @param userId 用户ID
*
* @return
*/
List<Long> getRoleIdList(Long userId);
}

View File

@ -0,0 +1,36 @@
package com.cnbm.admin.dao;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.common.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:27 PM
* @Version 1.0
*/
@Mapper
public interface SysUserDao extends BaseDao<SysUserEntity> {
List<SysUserEntity> getList(Map<String, Object> params);
SysUserEntity getById(Long id);
SysUserEntity getByUsername(String username);
int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword);
/**
* 根据部门ID查询用户数
*/
int getCountByDeptId(Long deptId);
/**
* 根据部门ID,查询用户ID列表
*/
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
}

View File

@ -0,0 +1,14 @@
package com.cnbm.admin.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cnbm.admin.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author weihongyang
* @Date 2022/6/9 8:57 AM
* @Version 1.0
*/
@Mapper
public interface UserDao extends BaseMapper<SysUserEntity> {
}

View File

@ -0,0 +1,28 @@
package com.cnbm.admin.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author weihongyang
* @Date 2022/6/10 1:59 PM
* @Version 1.0
*/
@Data
@ApiModel(value = "修改密码")
public class PasswordDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "原密码")
@NotBlank(message="{sysuser.password.require}")
private String password;
@ApiModelProperty(value = "新密码")
@NotBlank(message="{sysuser.password.require}")
private String newPassword;
}

View File

@ -0,0 +1,102 @@
package com.cnbm.admin.dto;
import com.cnbm.common.utils.TreeNode;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 1:39 PM
* @Version 1.0
*/
@ApiModel(value = "部门管理")
public class SysDeptDTO extends TreeNode implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "上级ID")
@NotNull(message="{sysdept.pid.require}", groups = DefaultGroup.class)
private Long pid;
@ApiModelProperty(value = "部门名称")
@NotBlank(message="{sysdept.name.require}", groups = DefaultGroup.class)
private String name;
@ApiModelProperty(value = "排序")
@Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class)
private Integer sort;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "上级部门名称")
private String parentName;
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@Override
public Long getPid() {
return pid;
}
@Override
public void setPid(Long pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
}

View File

@ -0,0 +1,58 @@
package com.cnbm.admin.dto;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:57 AM
* @Version 1.0
*/
@Data
@ApiModel(value = "字典数据")
public class SysDictDataDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "字典类型ID")
@NotNull(message="{sysdict.type.require}", groups = DefaultGroup.class)
private Long dictTypeId;
@ApiModelProperty(value = "字典标签")
@NotBlank(message="{sysdict.label.require}", groups = DefaultGroup.class)
private String dictLabel;
@ApiModelProperty(value = "字典值")
private String dictValue;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "排序")
@Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class)
private Integer sort;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "更新时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date updateDate;
}

View File

@ -0,0 +1,55 @@
package com.cnbm.admin.dto;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:57 AM
* @Version 1.0
*/
@Data
@ApiModel(value = "字典类型")
public class SysDictTypeDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "字典类型")
@NotBlank(message="{sysdict.type.require}", groups = DefaultGroup.class)
private String dictType;
@ApiModelProperty(value = "字典名称")
@NotBlank(message="{sysdict.name.require}", groups = DefaultGroup.class)
private String dictName;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "排序")
@Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class)
private Integer sort;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "更新时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date updateDate;
}

View File

@ -0,0 +1,37 @@
package com.cnbm.admin.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 2:07 PM
* @Version 1.0
*/
@Data
@ApiModel(value = "异常日志")
public class SysLogErrorDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "请求URI")
private String requestUri;
@ApiModelProperty(value = "请求方式")
private String requestMethod;
@ApiModelProperty(value = "请求参数")
private String requestParams;
@ApiModelProperty(value = "用户代理")
private String userAgent;
@ApiModelProperty(value = "操作IP")
private String ip;
@ApiModelProperty(value = "异常信息")
private String errorInfo;
@ApiModelProperty(value = "创建时间")
private Date createDate;
}

View File

@ -0,0 +1,53 @@
package com.cnbm.admin.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 9:53 AM
* @Version 1.0
*/
@Data
@ApiModel(value = "操作日志")
public class SysLogOperationDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "用户操作")
private String operation;
@ApiModelProperty(value = "请求URI")
private String requestUri;
@ApiModelProperty(value = "请求方式")
private String requestMethod;
@ApiModelProperty(value = "请求参数")
private String requestParams;
@ApiModelProperty(value = "请求时长(毫秒)")
private Integer requestTime;
@ApiModelProperty(value = "用户代理")
private String userAgent;
@ApiModelProperty(value = "操作IP")
private String ip;
@ApiModelProperty(value = "状态 0失败 1成功")
private Integer status;
@ApiModelProperty(value = "用户名")
private String creatorName;
@ApiModelProperty(value = "创建时间")
private Date createDate;
}

View File

@ -0,0 +1,148 @@
package com.cnbm.admin.dto;
import com.cnbm.common.utils.TreeNode;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 2:33 PM
* @Version 1.0
*/
@ApiModel(value = "菜单管理")
public class SysMenuDTO extends TreeNode<SysMenuDTO> implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "上级ID")
@NotNull(message="{sysmenu.pid.require}", groups = DefaultGroup.class)
private Long pid;
@ApiModelProperty(value = "菜单名称")
@NotBlank(message="{sysmenu.name.require}", groups = DefaultGroup.class)
private String name;
@ApiModelProperty(value = "菜单URL")
private String url;
@ApiModelProperty(value = "类型 0菜单 1按钮")
@Range(min=0, max=1, message = "{sysmenu.type.range}", groups = DefaultGroup.class)
private Integer type;
@ApiModelProperty(value = "菜单图标")
private String icon;
@ApiModelProperty(value = "授权(多个用逗号分隔sys:user:list,sys:user:save)")
private String permissions;
@ApiModelProperty(value = "排序")
@Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class)
private Integer sort;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "上级菜单名称")
private String parentName;
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@Override
public Long getPid() {
return pid;
}
@Override
public void setPid(Long pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getPermissions() {
return permissions;
}
public void setPermissions(String permissions) {
this.permissions = permissions;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
}

View File

@ -0,0 +1,51 @@
package com.cnbm.admin.dto;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:21 AM
* @Version 1.0
*/
@Data
@ApiModel(value = "参数管理")
public class SysParamsDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "参数编码")
@NotBlank(message="{sysparams.paramcode.require}", groups = DefaultGroup.class)
private String paramCode;
@ApiModelProperty(value = "参数值")
@NotBlank(message="{sysparams.paramvalue.require}", groups = DefaultGroup.class)
private String paramValue;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "更新时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date updateDate;
}

View File

@ -0,0 +1,50 @@
package com.cnbm.admin.dto;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:06 AM
* @Version 1.0
*/
@Data
@ApiModel(value = "角色管理")
public class SysRoleDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "角色名称")
@NotBlank(message="{sysrole.name.require}", groups = DefaultGroup.class)
private String name;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "菜单ID列表")
private List<Long> menuIdList;
@ApiModelProperty(value = "部门ID列表")
private List<Long> deptIdList;
}

View File

@ -0,0 +1,84 @@
package com.cnbm.admin.dto;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 1:26 PM
* @Version 1.0
*/
@Data
@ApiModel(value = "用户管理")
public class SysUserDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message="{id.null}", groups = AddGroup.class)
@NotNull(message="{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "用户名", required = true)
@NotBlank(message="{sysuser.username.require}", groups = DefaultGroup.class)
private String username;
@ApiModelProperty(value = "密码")
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@NotBlank(message="{sysuser.password.require}", groups = AddGroup.class)
private String password;
@ApiModelProperty(value = "姓名", required = true)
@NotBlank(message="{sysuser.realname.require}", groups = DefaultGroup.class)
private String realName;
@ApiModelProperty(value = "头像")
private String headUrl;
@ApiModelProperty(value = "性别 0男 1女 2保密", required = true)
@Range(min=0, max=2, message = "{sysuser.gender.range}", groups = DefaultGroup.class)
private Integer gender;
@ApiModelProperty(value = "邮箱")
@Email(message="{sysuser.email.error}", groups = DefaultGroup.class)
private String email;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "部门ID", required = true)
@NotNull(message="{sysuser.deptId.require}", groups = DefaultGroup.class)
private Long deptId;
@ApiModelProperty(value = "状态 0停用 1正常", required = true)
@Range(min=0, max=1, message = "{sysuser.status.range}", groups = DefaultGroup.class)
private Integer status;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
@ApiModelProperty(value = "超级管理员 0否 1")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Integer superAdmin;
@ApiModelProperty(value = "角色ID列表")
private List<Long> roleIdList;
@ApiModelProperty(value = "部门名称")
private String deptName;
}

View File

@ -0,0 +1,17 @@
package com.cnbm.admin.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
/**
* @Author weihongyang
* @Date 2022/6/12 11:01 AM
* @Version 1.0
*/
@Data
public class DictData {
@JsonIgnore
private Long dictTypeId;
private String dictLabel;
private String dictValue;
}

View File

@ -0,0 +1,20 @@
package com.cnbm.admin.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 11:00 AM
* @Version 1.0
*/
@Data
public class DictType {
@JsonIgnore
private Long id;
private String dictType;
private List<DictData> dataList = new ArrayList<>();
}

View File

@ -0,0 +1,83 @@
package com.cnbm.admin.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author weihongyang
* @Date 2022/6/8 1:56 PM
* @Version 1.0
*/
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class LoginUser implements UserDetails {
private SysUserEntity sysUserEntity;
private List<String> permissions;
public LoginUser(SysUserEntity sysUserEntity, List<String> permissions) {
this.sysUserEntity = sysUserEntity;
this.permissions = permissions;
}
@JsonIgnore
private List<SimpleGrantedAuthority> authorities;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
if(authorities!=null){
return authorities;
}
//把permissions中String类型的权限信息封装成SimpleGrantedAuthority对象
// authorities = new ArrayList<>();
// for (String permission : permissions) {
// SimpleGrantedAuthority authority = new SimpleGrantedAuthority(permission);
// authorities.add(authority);
// }
authorities = permissions.stream()
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
return authorities;
}
@Override
public String getPassword() {
return sysUserEntity.getPassword();
}
@Override
public String getUsername() {
return sysUserEntity.getUsername();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}

View File

@ -0,0 +1,55 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 1:39 PM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_dept")
public class SysDeptEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 上级ID
*/
private Long pid;
/**
* 所有上级ID用逗号分开
*/
private String pids;
/**
* 部门名称
*/
private String name;
/**
* 排序
*/
private Integer sort;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
/**
* 上级部门名称
*/
@TableField(exist = false)
private String parentName;
}

View File

@ -0,0 +1,52 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:57 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_dict_data")
public class SysDictDataEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 字典类型ID
*/
private Long dictTypeId;
/**
* 字典标签
*/
private String dictLabel;
/**
* 字典值
*/
private String dictValue;
/**
* 备注
*/
private String remark;
/**
* 排序
*/
private Integer sort;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
}

View File

@ -0,0 +1,48 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:58 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_dict_type")
public class SysDictTypeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 字典类型
*/
private String dictType;
/**
* 字典名称
*/
private String dictName;
/**
* 备注
*/
private String remark;
/**
* 排序
*/
private Integer sort;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
}

View File

@ -0,0 +1,44 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @Author weihongyang
* @Date 2022/6/10 2:08 PM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_log_error")
public class SysLogErrorEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 请求URI
*/
private String requestUri;
/**
* 请求方式
*/
private String requestMethod;
/**
* 请求参数
*/
private String requestParams;
/**
* 用户代理
*/
private String userAgent;
/**
* 操作IP
*/
private String ip;
/**
* 异常信息
*/
private String errorInfo;
}

View File

@ -0,0 +1,55 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @Author weihongyang
* @Date 2022/6/10 9:49 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_log_operation")
public class SysLogOperationEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 用户操作
*/
private String operation;
/**
* 请求URI
*/
private String requestUri;
/**
* 请求方式
*/
private String requestMethod;
/**
* 请求参数
*/
private String requestParams;
/**
* 请求时长(毫秒)
*/
private Integer requestTime;
/**
* 用户代理
*/
private String userAgent;
/**
* 操作IP
*/
private String ip;
/**
* 状态 0失败 1成功
*/
private Integer status;
/**
* 用户名
*/
private String creatorName;
}

View File

@ -0,0 +1,67 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 2:28 PM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_menu")
public class SysMenuEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 父菜单ID一级菜单为0
*/
private Long pid;
/**
* 菜单名称
*/
private String name;
/**
* 菜单URL
*/
private String url;
/**
* 授权(多个用逗号分隔sys:user:list,sys:user:save)
*/
private String permissions;
/**
* 类型 0菜单 1按钮
*/
private Integer type;
/**
* 菜单图标
*/
private String icon;
/**
* 排序
*/
private Integer sort;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
/**
* 上级菜单名称
*/
@TableField(exist = false)
private String parentName;
}

View File

@ -0,0 +1,50 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:22 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_params")
public class SysParamsEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 参数编码
*/
private String paramCode;
/**
* 参数值
*/
private String paramValue;
/**
* 类型 0系统参数 1非系统参数
*/
private Integer paramType;
/**
* 备注
*/
private String remark;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
}

View File

@ -0,0 +1,28 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @Author weihongyang
* @Date 2022/6/12 10:14 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_role_data_scope")
public class SysRoleDataScopeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 角色ID
*/
private Long roleId;
/**
* 部门ID
*/
private Long deptId;
}

View File

@ -0,0 +1,46 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/12 10:06 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_role")
public class SysRoleEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 角色名称
*/
private String name;
/**
* 备注
*/
private String remark;
/**
* 部门ID
*/
@TableField(fill = FieldFill.INSERT)
private Long deptId;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
}

View File

@ -0,0 +1,27 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @Author weihongyang
* @Date 2022/6/10 2:16 PM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_role_menu")
public class SysRoleMenuEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 角色ID
*/
private Long roleId;
/**
* 菜单ID
*/
private Long menuId;
}

View File

@ -0,0 +1,29 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @Author weihongyang
* @Date 2022/6/10 1:34 PM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_role_user")
public class SysRoleUserEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 角色ID
*/
private Long roleId;
/**
* 用户ID
*/
private Long userId;
}

View File

@ -0,0 +1,80 @@
package com.cnbm.admin.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnbm.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/8 9:19 AM
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("sys_user")
public class SysUserEntity extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
/**
* 姓名
*/
private String realName;
/**
* 头像
*/
private String headUrl;
/**
* 性别 0 1 2保密
*/
private Integer gender;
/**
* 邮箱
*/
private String email;
/**
* 手机号
*/
private String mobile;
/**
* 部门ID
*/
private Long deptId;
/**
* 超级管理员 0 1
*/
private Integer superAdmin;
/**
* 状态 0停用 1正常
*/
private Integer status;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
/**
* 部门名称
*/
@TableField(exist=false)
private String deptName;
}

View File

@ -0,0 +1,27 @@
package com.cnbm.admin.enums;
/**
* @Author weihongyang
* @Date 2022/6/10 3:01 PM
* @Version 1.0
*/
public enum MenuTypeEnum {
/**
* 菜单
*/
MENU(0),
/**
* 按钮
*/
BUTTON(1);
private int value;
MenuTypeEnum(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}

View File

@ -0,0 +1,27 @@
package com.cnbm.admin.enums;
/**
* @Author weihongyang
* @Date 2022/6/10 10:10 AM
* @Version 1.0
*/
public enum OperationStatusEnum {
/**
* 失败
*/
FAIL(0),
/**
* 成功
*/
SUCCESS(1);
private int value;
OperationStatusEnum(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}

View File

@ -0,0 +1,21 @@
package com.cnbm.admin.enums;
/**
* @Author weihongyang
* @Date 2022/6/10 2:02 PM
* @Version 1.0
*/
public enum SuperAdminEnum {
YES(1),
NO(0);
private int value;
SuperAdminEnum(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}

View File

@ -0,0 +1,87 @@
package com.cnbm.admin.exception;
import cn.hutool.core.map.MapUtil;
import com.cnbm.admin.entity.SysLogErrorEntity;
import com.cnbm.admin.service.SysLogErrorService;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.exception.ExceptionUtils;
import com.cnbm.common.exception.RenException;
import com.cnbm.common.utils.HttpContextUtils;
import com.cnbm.common.utils.IpUtils;
import com.cnbm.common.utils.JsonUtils;
import com.cnbm.common.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 2:05 PM
* @Version 1.0
*/
//@RestControllerAdvice
//public class RenExceptionHandler {
// private static final Logger logger = LoggerFactory.getLogger(RenExceptionHandler.class);
//
// @Autowired
// private SysLogErrorService sysLogErrorService;
//
// /**
// * 处理自定义异常
// */
// @ExceptionHandler(RenException.class)
// public Result handleRenException(RenException ex){
// Result result = new Result();
// result.error(ex.getCode(), ex.getMsg());
//
// return result;
// }
//
// @ExceptionHandler(DuplicateKeyException.class)
// public Result handleDuplicateKeyException(DuplicateKeyException ex){
// Result result = new Result();
// result.error(ErrorCode.DB_RECORD_EXISTS);
//
// return result;
// }
//
// @ExceptionHandler(Exception.class)
// public Result handleException(Exception ex){
// logger.error(ex.getMessage(), ex);
//
// saveLog(ex);
//
// return new Result().error();
// }
//
// /**
// * 保存异常日志
// */
// private void saveLog(Exception ex){
// SysLogErrorEntity log = new SysLogErrorEntity();
//
// //请求相关信息
// HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
// log.setIp(IpUtils.getIpAddr(request));
// log.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
// log.setRequestUri(request.getRequestURI());
// log.setRequestMethod(request.getMethod());
// Map<String, String> params = HttpContextUtils.getParameterMap(request);
// if(MapUtil.isNotEmpty(params)){
// log.setRequestParams(JsonUtils.toJsonString(params));
// }
//
// //异常信息
// log.setErrorInfo(ExceptionUtils.getErrorStackTrace(ex));
//
// //保存
// sysLogErrorService.save(log);
// }
//}

View File

@ -0,0 +1,28 @@
package com.cnbm.admin.execl;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 2:14 PM
* @Version 1.0
*/
@Data
public class SysLogErrorExcel {
@Excel(name = "请求URI")
private String requestUri;
@Excel(name = "请求方式")
private String requestMethod;
@Excel(name = "请求参数")
private String requestParams;
@Excel(name = "User-Agent")
private String userAgent;
@Excel(name = "操作IP")
private String ip;
@Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss")
private Date createDate;
}

View File

@ -0,0 +1,36 @@
package com.cnbm.admin.execl;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 10:06 AM
* @Version 1.0
*/
@Data
public class SysLogOperationExcel {
@Excel(name = "用户操作")
private String operation;
@Excel(name = "请求URI")
private String requestUri;
@Excel(name = "请求方式")
private String requestMethod;
@Excel(name = "请求参数")
private String requestParams;
@Excel(name = "请求时长(毫秒)")
private Integer requestTime;
@Excel(name = "User-Agent")
private String userAgent;
@Excel(name = "操作IP")
private String ip;
@Excel(name = "状态", replace = {"失败_0", "成功_1"})
private Integer status;
@Excel(name = "用户名")
private String creatorName;
@Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss")
private Date createDate;
}

View File

@ -0,0 +1,20 @@
package com.cnbm.admin.execl;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
/**
* @Author weihongyang
* @Date 2022/6/12 10:26 AM
* @Version 1.0
*/
@Data
public class SysParamsExcel {
@Excel(name = "参数编码")
private String paramCode;
@Excel(name = "参数值")
private String paramValue;
@Excel(name = "备注")
private String remark;
}

View File

@ -0,0 +1,34 @@
package com.cnbm.admin.execl;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* @Author weihongyang
* @Date 2022/6/10 1:25 PM
* @Version 1.0
*/
@Data
public class SysUserExcel {
@Excel(name = "用户名")
private String username;
@Excel(name = "姓名")
private String realName;
@Excel(name = "性别", replace = {"男_0", "女_1", "保密_2"})
private Integer gender;
@Excel(name = "邮箱")
private String email;
@Excel(name = "手机号")
private String mobile;
@Excel(name = "部门名称")
private String deptName;
@Excel(name = "状态", replace = {"停用_0", "正常_1"})
private Integer status;
@Excel(name = "备注")
private String remark;
@Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss")
private Date createDate;
}

View File

@ -0,0 +1,65 @@
package com.cnbm.admin.filter;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;
/**
* @Author weihongyang
* @Date 2022/6/8 1:51 PM
* @Version 1.0
*/
@Component
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
@Autowired
private RedisTemplate redisTemplate;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//获取token
// String token = request.getHeader("Authorization");
String token = request.getHeader("token");
if (!StringUtils.hasText(token)) {
//放行
filterChain.doFilter(request, response);
return;
}
//解析token
String userid;
try {
Claims claims = JwtUtil.parseJWT(token);
userid = claims.getSubject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("token非法");
}
//从redis中获取用户信息
String redisKey = "login:" + userid;
LoginUser loginUser = (LoginUser) redisTemplate.opsForValue().get(redisKey);
if(Objects.isNull(loginUser)){
throw new RuntimeException("用户未登录");
}
//存入SecurityContextHolder
//TODO 获取权限信息封装到Authentication中
UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken(loginUser,null,loginUser.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
//放行
filterChain.doFilter(request, response);
}
}

View File

@ -0,0 +1,30 @@
package com.cnbm.admin.handler;
import com.cnbm.admin.utils.ResponseResult;
import com.cnbm.admin.utils.WebUtils;
import com.cnbm.common.utils.JsonUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @Author weihongyang
* @Date 2022/6/9 11:55 AM
* @Version 1.0
*/
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
ResponseResult result = new ResponseResult(HttpStatus.FORBIDDEN.value(),"您的权限不足");
String json = JsonUtils.toJsonString(result);
//处理异常
WebUtils.renderString(response,json);
}
}

View File

@ -0,0 +1,30 @@
package com.cnbm.admin.handler;
import com.cnbm.admin.utils.ResponseResult;
import com.cnbm.admin.utils.WebUtils;
import com.cnbm.common.utils.JsonUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @Author weihongyang
* @Date 2022/6/9 1:27 PM
* @Version 1.0
*/
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
ResponseResult result = new ResponseResult(HttpStatus.UNAUTHORIZED.value(),"用户认证失败请查询登录");
String json = JsonUtils.toJsonString(result);
//处理异常
WebUtils.renderString(response,json);
}
}

View File

@ -0,0 +1,36 @@
package com.cnbm.admin.params;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author weihongyang
* @Date 2022/6/8 9:29 AM
* @Version 1.0
*/
@Data
@ApiModel(value = "登录表单")
public class LoginParam implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "用户名", required = true)
@NotBlank(message="用户名不能为空")
private String username;
@ApiModelProperty(value = "密码" , required = true)
@NotBlank(message="密码不能为空")
private String password;
@ApiModelProperty(value = "验证码" , required = true)
@NotBlank(message="验证码不能为空")
private String captcha;
@ApiModelProperty(value = "唯一标识" , required = true)
@NotBlank(message="uuid不能为空")
private String uuid;
}

View File

@ -0,0 +1,36 @@
package com.cnbm.admin.redis;
import com.cnbm.common.redis.RedisKeys;
import com.cnbm.common.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author weihongyang
* @Date 2022/6/12 10:48 AM
* @Version 1.0
*/
@Component
public class SysParamsRedis {
@Autowired
private RedisUtils redisUtils;
public void delete(Object[] paramCodes) {
String key = RedisKeys.getSysParamsKey();
redisUtils.hDel(key, paramCodes);
}
public void set(String paramCode, String paramValue){
if(paramValue == null){
return ;
}
String key = RedisKeys.getSysParamsKey();
redisUtils.hSet(key, paramCode, paramValue);
}
public String get(String paramCode){
String key = RedisKeys.getSysParamsKey();
return (String)redisUtils.hGet(key, paramCode);
}
}

View File

@ -0,0 +1,9 @@
package com.cnbm.admin.service;
/**
* @Author weihongyang
* @Date 2022/6/8 8:55 AM
* @Version 1.0
*/
public interface CaptchaService {
}

View File

@ -0,0 +1,16 @@
package com.cnbm.admin.service;
import com.cnbm.admin.params.LoginParam;
import com.cnbm.admin.utils.ResponseResult;
import javax.servlet.http.HttpServletRequest;
/**
* @Author weihongyang
* @Date 2022/6/8 9:17 AM
* @Version 1.0
*/
public interface LoginService {
ResponseResult login(HttpServletRequest request, LoginParam loginParam);
}

View File

@ -0,0 +1,32 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysDeptDTO;
import com.cnbm.admin.entity.SysDeptEntity;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:38 PM
* @Version 1.0
*/
public interface SysDeptService extends BaseService<SysDeptEntity> {
List<SysDeptDTO> list(Map<String, Object> params);
SysDeptDTO get(Long id);
void save(SysDeptDTO dto);
void update(SysDeptDTO dto);
void delete(Long id);
/**
* 根据部门ID获取本部门及子部门ID列表
* @param id 部门ID
*/
List<Long> getSubDeptIdList(Long id);
}

View File

@ -0,0 +1,27 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysDictDataDTO;
import com.cnbm.admin.entity.SysDictDataEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:58 AM
* @Version 1.0
*/
public interface SysDictDataService extends BaseService<SysDictDataEntity> {
PageData<SysDictDataDTO> page(Map<String, Object> params);
SysDictDataDTO get(Long id);
void save(SysDictDataDTO dto);
void update(SysDictDataDTO dto);
void delete(Long[] ids);
}

View File

@ -0,0 +1,34 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysDictTypeDTO;
import com.cnbm.admin.entity.DictType;
import com.cnbm.admin.entity.SysDictTypeEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:58 AM
* @Version 1.0
*/
public interface SysDictTypeService extends BaseService<SysDictTypeEntity> {
PageData<SysDictTypeDTO> page(Map<String, Object> params);
SysDictTypeDTO get(Long id);
void save(SysDictTypeDTO dto);
void update(SysDictTypeDTO dto);
void delete(Long[] ids);
/**
* 获取所有字典
*/
List<DictType> getAllList();
}

View File

@ -0,0 +1,24 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysLogErrorDTO;
import com.cnbm.admin.entity.SysLogErrorEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 2:08 PM
* @Version 1.0
*/
public interface SysLogErrorService extends BaseService<SysLogErrorEntity> {
PageData<SysLogErrorDTO> page(Map<String, Object> params);
List<SysLogErrorDTO> list(Map<String, Object> params);
void save(SysLogErrorEntity entity);
}

View File

@ -0,0 +1,23 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysLogOperationDTO;
import com.cnbm.admin.entity.SysLogOperationEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 9:52 AM
* @Version 1.0
*/
public interface SysLogOperationService extends BaseService<SysLogOperationEntity> {
PageData<SysLogOperationDTO> page(Map<String, Object> params);
List<SysLogOperationDTO> list(Map<String, Object> params);
void save(SysLogOperationEntity entity);
}

View File

@ -0,0 +1,48 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysMenuDTO;
import com.cnbm.admin.entity.SysMenuEntity;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Set;
/**
* @Author weihongyang
* @Date 2022/6/10 2:34 PM
* @Version 1.0
*/
public interface SysMenuService extends BaseService<SysMenuEntity> {
SysMenuDTO get(Long id);
void save(SysMenuDTO dto);
void update(SysMenuDTO dto);
void delete(Long id);
/**
* 菜单列表
*
* @param type 菜单类型
*/
List<SysMenuDTO> getAllMenuList(Integer type);
/**
* 用户菜单列表
*
* @param user 用户
* @param type 菜单类型
*/
List<SysMenuDTO> getUserMenuList(SysUserEntity user, Integer type);
/**
* 根据父菜单查询子菜单
* @param pid 父菜单ID
*/
List<SysMenuDTO> getListPid(Long pid);
Set<String> getUserPermissions(SysUserEntity user);
}

View File

@ -0,0 +1,50 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysParamsDTO;
import com.cnbm.admin.entity.SysParamsEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:23 AM
* @Version 1.0
*/
public interface SysParamsService extends BaseService<SysParamsEntity> {
PageData<SysParamsDTO> page(Map<String, Object> params);
List<SysParamsDTO> list(Map<String, Object> params);
SysParamsDTO get(Long id);
void save(SysParamsDTO dto);
void update(SysParamsDTO dto);
void delete(Long[] ids);
/**
* 根据参数编码获取参数的value值
*
* @param paramCode 参数编码
*/
String getValue(String paramCode);
/**
* 根据参数编码获取value的Object对象
* @param paramCode 参数编码
* @param clazz Object对象
*/
<T> T getValueObject(String paramCode, Class<T> clazz);
/**
* 根据参数编码更新value
* @param paramCode 参数编码
* @param paramValue 参数值
*/
int updateValueByCode(String paramCode, String paramValue);
}

View File

@ -0,0 +1,32 @@
package com.cnbm.admin.service;
import com.cnbm.admin.entity.SysRoleDataScopeEntity;
import com.cnbm.common.service.BaseService;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:13 AM
* @Version 1.0
*/
public interface SysRoleDataScopeService extends BaseService<SysRoleDataScopeEntity> {
/**
* 根据角色ID获取部门ID列表
*/
List<Long> getDeptIdList(Long roleId);
/**
* 保存或修改
* @param roleId 角色ID
* @param deptIdList 部门ID列表
*/
void saveOrUpdate(Long roleId, List<Long> deptIdList);
/**
* 根据角色id删除角色数据权限关系
* @param roleId 角色ids
*/
void deleteByRoleIds(Long[] roleId);
}

View File

@ -0,0 +1,38 @@
package com.cnbm.admin.service;
import com.cnbm.admin.entity.SysRoleMenuEntity;
import com.cnbm.common.service.BaseService;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 3:02 PM
* @Version 1.0
*/
public interface SysRoleMenuService extends BaseService<SysRoleMenuEntity> {
/**
* 根据角色ID获取菜单ID列表
*/
List<Long> getMenuIdList(Long roleId);
/**
* 保存或修改
* @param roleId 角色ID
* @param menuIdList 菜单ID列表
*/
void saveOrUpdate(Long roleId, List<Long> menuIdList);
/**
* 根据角色id删除角色菜单关系
* @param roleIds 角色ids
*/
void deleteByRoleIds(Long[] roleIds);
/**
* 根据菜单id删除角色菜单关系
* @param menuId 菜单id
*/
void deleteByMenuId(Long menuId);
}

View File

@ -0,0 +1,30 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysRoleDTO;
import com.cnbm.admin.entity.SysRoleEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:07 AM
* @Version 1.0
*/
public interface SysRoleService extends BaseService<SysRoleEntity> {
PageData<SysRoleDTO> page(Map<String, Object> params);
List<SysRoleDTO> list(Map<String, Object> params);
SysRoleDTO get(Long id);
void save(SysRoleDTO dto);
void update(SysRoleDTO dto);
void delete(Long[] ids);
}

View File

@ -0,0 +1,39 @@
package com.cnbm.admin.service;
import com.cnbm.admin.entity.SysRoleUserEntity;
import com.cnbm.common.service.BaseService;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 1:33 PM
* @Version 1.0
*/
public interface SysRoleUserService extends BaseService<SysRoleUserEntity> {
/**
* 保存或修改
* @param userId 用户ID
* @param roleIdList 角色ID列表
*/
void saveOrUpdate(Long userId, List<Long> roleIdList);
/**
* 根据角色ids删除角色用户关系
* @param roleIds 角色ids
*/
void deleteByRoleIds(Long[] roleIds);
/**
* 根据用户id删除角色用户关系
* @param userIds 用户ids
*/
void deleteByUserIds(Long[] userIds);
/**
* 角色ID列表
* @param userId 用户ID
*/
List<Long> getRoleIdList(Long userId);
}

View File

@ -0,0 +1,49 @@
package com.cnbm.admin.service;
import com.cnbm.admin.dto.SysUserDTO;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.BaseService;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:24 PM
* @Version 1.0
*/
public interface SysUserService extends BaseService<SysUserEntity> {
PageData<SysUserDTO> page(Map<String, Object> params);
List<SysUserDTO> list(Map<String, Object> params);
SysUserDTO get(Long id);
SysUserDTO getByUsername(String username);
void save(SysUserDTO dto);
void update(SysUserDTO dto);
void delete(Long[] ids);
/**
* 修改密码
* @param id 用户ID
* @param newPassword 新密码
*/
void updatePassword(Long id, String newPassword);
/**
* 根据部门ID查询用户数
*/
int getCountByDeptId(Long deptId);
/**
* 根据部门ID,查询用户Id列表
*/
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
}

View File

@ -0,0 +1,51 @@
package com.cnbm.admin.service.impl;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.params.LoginParam;
import com.cnbm.admin.utils.JwtUtil;
import com.cnbm.admin.service.LoginService;
import com.cnbm.admin.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* @Author weihongyang
* @Date 2022/6/8 9:17 AM
* @Version 1.0
*/
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private AuthenticationManager authenticationManager;
@Override
public ResponseResult login(HttpServletRequest request, LoginParam loginParam) {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginParam.getUsername(),loginParam.getPassword());
Authentication authenticate = authenticationManager.authenticate(authenticationToken);
if (Objects.isNull(authenticate)) {
throw new RuntimeException("登录失败");
}
//如果认证通过了使用userid生成一个jwt jwt存入ResponseResult返回
LoginUser loginUser = (LoginUser) authenticate.getPrincipal();
String userid = loginUser.getSysUserEntity().getId().toString();
String jwt = JwtUtil.createJWT(userid);
Map<String,String> map = new HashMap<>();
map.put("token",jwt);
//把完整的用户信息存入redis userid作为key
redisTemplate.opsForValue().set("login:"+userid,loginUser);
return new ResponseResult(200,"登录成功",map);
}
}

View File

@ -0,0 +1,165 @@
package com.cnbm.admin.service.impl;
import com.cnbm.admin.dao.SysDeptDao;
import com.cnbm.admin.dao.SysUserDao;
import com.cnbm.admin.dto.SysDeptDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysDeptEntity;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.enums.SuperAdminEnum;
import com.cnbm.admin.service.SysDeptService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.exception.RenException;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.common.utils.TreeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:38 PM
* @Version 1.0
*/
@Service
public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntity> implements SysDeptService {
@Autowired
private SysUserDao sysUserDao;
@Override
public List<SysDeptDTO> list(Map<String, Object> params) {
//普通管理员只能查询所属部门及子部门的数据
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", getSubDeptIdList(user.getDeptId()));
}
//查询部门列表
List<SysDeptEntity> entityList = baseDao.getList(params);
List<SysDeptDTO> dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class);
return TreeUtils.build(dtoList);
}
@Override
public SysDeptDTO get(Long id) {
//超级管理员部门ID为null
if(id == null){
return null;
}
SysDeptEntity entity = baseDao.getById(id);
return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysDeptDTO dto) {
SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class);
entity.setPids(getPidList(entity.getPid()));
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysDeptDTO dto) {
SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class);
//上级部门不能为自身
if(entity.getId().equals(entity.getPid())){
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
}
//上级部门不能为下级部门
List<Long> subDeptList = getSubDeptIdList(entity.getId());
if(subDeptList.contains(entity.getPid())){
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
}
entity.setPids(getPidList(entity.getPid()));
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
//判断是否有子部门
List<Long> subList = getSubDeptIdList(id);
if(subList.size() > 1){
throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR);
}
//判断部门下面是否有用户
int count = sysUserDao.getCountByDeptId(id);
if(count > 0){
throw new RenException(ErrorCode.DEPT_USER_DELETE_ERROR);
}
//删除
baseDao.deleteById(id);
}
@Override
public List<Long> getSubDeptIdList(Long id) {
List<Long> deptIdList = baseDao.getSubDeptIdList("%" + id + "%");
deptIdList.add(id);
return deptIdList;
}
/**
* 获取所有上级部门ID
* @param pid 上级ID
*/
private String getPidList(Long pid){
//顶级部门无上级部门
if(Constant.DEPT_ROOT.equals(pid)){
return Constant.DEPT_ROOT + "";
}
//所有部门的idpid列表
List<SysDeptEntity> deptList = baseDao.getIdAndPidList();
//list转map
Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
for(SysDeptEntity entity : deptList){
map.put(entity.getId(), entity);
}
//递归查询所有上级部门ID列表
List<Long> pidList = new ArrayList<>();
getPidTree(pid, map, pidList);
return StringUtils.join(pidList, ",");
}
private void getPidTree(Long pid, Map<Long, SysDeptEntity> map, List<Long> pidList) {
//顶级部门无上级部门
if(Constant.DEPT_ROOT.equals(pid)){
return ;
}
//上级部门存在
SysDeptEntity parent = map.get(pid);
if(parent != null){
getPidTree(parent.getPid(), map, pidList);
}
pidList.add(pid);
}
}

View File

@ -0,0 +1,80 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysDictDataDao;
import com.cnbm.admin.dto.SysDictDataDTO;
import com.cnbm.admin.entity.SysDictDataEntity;
import com.cnbm.admin.service.SysDictDataService;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:59 AM
* @Version 1.0
*/
@Service
public class SysDictDataServiceImpl extends BaseServiceImpl<SysDictDataDao, SysDictDataEntity> implements SysDictDataService {
@Override
public PageData<SysDictDataDTO> page(Map<String, Object> params) {
IPage<SysDictDataEntity> page = baseDao.selectPage(
getPage(params, "sort", true),
getWrapper(params)
);
return getPageData(page, SysDictDataDTO.class);
}
private QueryWrapper<SysDictDataEntity> getWrapper(Map<String, Object> params){
String dictTypeId = (String) params.get("dictTypeId");
String dictLabel = (String) params.get("dictLabel");
String dictValue = (String) params.get("dictValue");
QueryWrapper<SysDictDataEntity> wrapper = new QueryWrapper<>();
wrapper.eq("dict_type_id", dictTypeId);
wrapper.like(StringUtils.isNotBlank(dictLabel), "dict_label", dictLabel);
wrapper.like(StringUtils.isNotBlank(dictValue), "dict_value", dictValue);
return wrapper;
}
@Override
public SysDictDataDTO get(Long id) {
SysDictDataEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, SysDictDataDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysDictDataDTO dto) {
SysDictDataEntity entity = ConvertUtils.sourceToTarget(dto, SysDictDataEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysDictDataDTO dto) {
SysDictDataEntity entity = ConvertUtils.sourceToTarget(dto, SysDictDataEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long[] ids) {
//删除
deleteBatchIds(Arrays.asList(ids));
}
}

View File

@ -0,0 +1,98 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysDictDataDao;
import com.cnbm.admin.dao.SysDictTypeDao;
import com.cnbm.admin.dto.SysDictTypeDTO;
import com.cnbm.admin.entity.DictData;
import com.cnbm.admin.entity.DictType;
import com.cnbm.admin.entity.SysDictTypeEntity;
import com.cnbm.admin.service.SysDictTypeService;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:59 AM
* @Version 1.0
*/
@Service
public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysDictTypeEntity> implements SysDictTypeService {
@Autowired
private SysDictDataDao sysDictDataDao;
@Override
public PageData<SysDictTypeDTO> page(Map<String, Object> params) {
IPage<SysDictTypeEntity> page = baseDao.selectPage(
getPage(params, "sort", true),
getWrapper(params)
);
return getPageData(page, SysDictTypeDTO.class);
}
private QueryWrapper<SysDictTypeEntity> getWrapper(Map<String, Object> params){
String dictType = (String) params.get("dictType");
String dictName = (String) params.get("dictName");
QueryWrapper<SysDictTypeEntity> wrapper = new QueryWrapper<>();
wrapper.like(StringUtils.isNotBlank(dictType), "dict_type", dictType);
wrapper.like(StringUtils.isNotBlank(dictName), "dict_name", dictName);
return wrapper;
}
@Override
public SysDictTypeDTO get(Long id) {
SysDictTypeEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, SysDictTypeDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysDictTypeDTO dto) {
SysDictTypeEntity entity = ConvertUtils.sourceToTarget(dto, SysDictTypeEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysDictTypeDTO dto) {
SysDictTypeEntity entity = ConvertUtils.sourceToTarget(dto, SysDictTypeEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long[] ids) {
//删除
deleteBatchIds(Arrays.asList(ids));
}
@Override
public List<DictType> getAllList() {
List<DictType> typeList = baseDao.getDictTypeList();
List<DictData> dataList = sysDictDataDao.getDictDataList();
for(DictType type : typeList){
for(DictData data : dataList){
if(type.getId().equals(data.getDictTypeId())){
type.getDataList().add(data);
}
}
}
return typeList;
}
}

View File

@ -0,0 +1,55 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysLogErrorDao;
import com.cnbm.admin.dto.SysLogErrorDTO;
import com.cnbm.admin.entity.SysLogErrorEntity;
import com.cnbm.admin.service.SysLogErrorService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 2:09 PM
* @Version 1.0
*/
@Service
public class SysLogErrorServiceImpl extends BaseServiceImpl<SysLogErrorDao, SysLogErrorEntity> implements SysLogErrorService {
@Override
public PageData<SysLogErrorDTO> page(Map<String, Object> params) {
IPage<SysLogErrorEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, SysLogErrorDTO.class);
}
@Override
public List<SysLogErrorDTO> list(Map<String, Object> params) {
List<SysLogErrorEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, SysLogErrorDTO.class);
}
private QueryWrapper<SysLogErrorEntity> getWrapper(Map<String, Object> params){
QueryWrapper<SysLogErrorEntity> wrapper = new QueryWrapper<>();
return wrapper;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysLogErrorEntity entity) {
insert(entity);
}
}

View File

@ -0,0 +1,60 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysLogOperationDao;
import com.cnbm.admin.dto.SysLogOperationDTO;
import com.cnbm.admin.entity.SysLogOperationEntity;
import com.cnbm.admin.service.SysLogOperationService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 9:52 AM
* @Version 1.0
*/
@Service
public class SysLogOperationServiceImpl extends BaseServiceImpl<SysLogOperationDao, SysLogOperationEntity> implements SysLogOperationService {
@Override
public PageData<SysLogOperationDTO> page(Map<String, Object> params) {
IPage<SysLogOperationEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, SysLogOperationDTO.class);
}
@Override
public List<SysLogOperationDTO> list(Map<String, Object> params) {
List<SysLogOperationEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, SysLogOperationDTO.class);
}
private QueryWrapper<SysLogOperationEntity> getWrapper(Map<String, Object> params){
String status = (String) params.get("status");
QueryWrapper<SysLogOperationEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(status), "status", status);
return wrapper;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysLogOperationEntity entity) {
insert(entity);
}
}

View File

@ -0,0 +1,136 @@
package com.cnbm.admin.service.impl;
import com.cnbm.admin.dao.SysMenuDao;
import com.cnbm.admin.dto.SysMenuDTO;
import com.cnbm.admin.entity.SysMenuEntity;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.enums.SuperAdminEnum;
import com.cnbm.admin.service.SysMenuService;
import com.cnbm.admin.service.SysRoleMenuService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.exception.RenException;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.common.utils.TreeUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* @Author weihongyang
* @Date 2022/6/10 2:35 PM
* @Version 1.0
*/
@Service
@Log4j2
public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuDao, SysMenuEntity> implements SysMenuService {
@Autowired
private SysRoleMenuService sysRoleMenuService;
@Autowired
private SysMenuDao sysMenuDao;
@Override
public SysMenuDTO get(Long id) {
SysMenuEntity entity = baseDao.getById(id);
SysMenuDTO dto = ConvertUtils.sourceToTarget(entity, SysMenuDTO.class);
return dto;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysMenuDTO dto) {
SysMenuEntity entity = ConvertUtils.sourceToTarget(dto, SysMenuEntity.class);
//保存菜单
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysMenuDTO dto) {
SysMenuEntity entity = ConvertUtils.sourceToTarget(dto, SysMenuEntity.class);
//上级菜单不能为自身
if(entity.getId().equals(entity.getPid())){
throw new RenException(ErrorCode.SUPERIOR_MENU_ERROR);
}
//更新菜单
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
//删除菜单
deleteById(id);
//删除角色菜单关系
sysRoleMenuService.deleteByMenuId(id);
}
@Override
public List<SysMenuDTO> getAllMenuList(Integer type) {
List<SysMenuEntity> menuList = baseDao.getMenuList(type);
List<SysMenuDTO> dtoList = ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class);
return TreeUtils.build(dtoList, Constant.MENU_ROOT);
}
@Override
public List<SysMenuDTO> getUserMenuList(SysUserEntity user, Integer type) {
List<SysMenuEntity> menuList = new ArrayList<>();
//系统管理员拥有最高权限
if(!Objects.isNull(user.getSuperAdmin()) && user.getSuperAdmin() == SuperAdminEnum.YES.value()){
menuList = baseDao.getMenuList(type);
}else {
menuList = baseDao.getUserMenuList(user.getId(), type);
}
List<SysMenuDTO> dtoList = ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class);
return TreeUtils.build(dtoList);
}
@Override
public List<SysMenuDTO> getListPid(Long pid) {
List<SysMenuEntity> menuList = baseDao.getListPid(pid);
return ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class);
}
@Override
public Set<String> getUserPermissions(SysUserEntity user) {
//系统管理员拥有最高权限
List<String> permissionsList;
if(user.getSuperAdmin() == SuperAdminEnum.YES.value()) {
permissionsList = sysMenuDao.getPermissionsList();
}else{
permissionsList = sysMenuDao.getUserPermissionsList(user.getId());
}
//用户权限列表
Set<String> permsSet = new HashSet<>();
for(String permissions : permissionsList){
if(StringUtils.isBlank(permissions)){
continue;
}
permsSet.addAll(Arrays.asList(permissions.trim().split(",")));
}
return permsSet;
}
}

View File

@ -0,0 +1,133 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysParamsDao;
import com.cnbm.admin.dto.SysParamsDTO;
import com.cnbm.admin.entity.SysParamsEntity;
import com.cnbm.admin.redis.SysParamsRedis;
import com.cnbm.admin.service.SysParamsService;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.exception.RenException;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.common.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/12 10:24 AM
* @Version 1.0
*/
@Service
public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParamsEntity> implements SysParamsService {
@Autowired
private SysParamsRedis sysParamsRedis;
@Override
public PageData<SysParamsDTO> page(Map<String, Object> params) {
IPage<SysParamsEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, SysParamsDTO.class);
}
@Override
public List<SysParamsDTO> list(Map<String, Object> params) {
List<SysParamsEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, SysParamsDTO.class);
}
private QueryWrapper<SysParamsEntity> getWrapper(Map<String, Object> params){
String paramCode = (String) params.get("paramCode");
QueryWrapper<SysParamsEntity> wrapper = new QueryWrapper<>();
wrapper.eq("param_type", 1);
wrapper.like(StringUtils.isNotBlank(paramCode), "param_code", paramCode);
return wrapper;
}
@Override
public SysParamsDTO get(Long id) {
SysParamsEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, SysParamsDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysParamsDTO dto) {
SysParamsEntity entity = ConvertUtils.sourceToTarget(dto, SysParamsEntity.class);
insert(entity);
sysParamsRedis.set(entity.getParamCode(), entity.getParamValue());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysParamsDTO dto) {
SysParamsEntity entity = ConvertUtils.sourceToTarget(dto, SysParamsEntity.class);
updateById(entity);
sysParamsRedis.set(entity.getParamCode(), entity.getParamValue());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long[] ids) {
//删除Redis数据
List<String> paramCodeList = baseDao.getParamCodeList(ids);
String[] paramCodes = paramCodeList.toArray(new String[paramCodeList.size()]);
sysParamsRedis.delete(paramCodes);
//删除
deleteBatchIds(Arrays.asList(ids));
}
@Override
public String getValue(String paramCode) {
String paramValue = sysParamsRedis.get(paramCode);
if(paramValue == null){
paramValue = baseDao.getValueByCode(paramCode);
sysParamsRedis.set(paramCode, paramValue);
}
return paramValue;
}
@Override
public <T> T getValueObject(String paramCode, Class<T> clazz) {
String paramValue = getValue(paramCode);
if(StringUtils.isNotBlank(paramValue)){
return JsonUtils.parseObject(paramValue, clazz);
}
try {
return clazz.newInstance();
} catch (Exception e) {
throw new RenException(ErrorCode.PARAMS_GET_ERROR);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public int updateValueByCode(String paramCode, String paramValue) {
int count = baseDao.updateValueByCode(paramCode, paramValue);
sysParamsRedis.set(paramCode, paramValue);
return count;
}
}

View File

@ -0,0 +1,53 @@
package com.cnbm.admin.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.cnbm.admin.dao.SysRoleDataScopeDao;
import com.cnbm.admin.entity.SysRoleDataScopeEntity;
import com.cnbm.admin.service.SysRoleDataScopeService;
import com.cnbm.common.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/12 10:13 AM
* @Version 1.0
*/
@Service
public class SysRoleDataScopeServiceImpl extends BaseServiceImpl<SysRoleDataScopeDao, SysRoleDataScopeEntity>
implements SysRoleDataScopeService {
@Override
public List<Long> getDeptIdList(Long roleId) {
return baseDao.getDeptIdList(roleId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(Long roleId, List<Long> deptIdList) {
//先删除角色数据权限关系
deleteByRoleIds(new Long[]{roleId});
//角色没有一个数据权限的情况
if(CollUtil.isEmpty(deptIdList)){
return ;
}
//保存角色数据权限关系
for(Long deptId : deptIdList){
SysRoleDataScopeEntity sysRoleDataScopeEntity = new SysRoleDataScopeEntity();
sysRoleDataScopeEntity.setDeptId(deptId);
sysRoleDataScopeEntity.setRoleId(roleId);
//保存
insert(sysRoleDataScopeEntity);
}
}
@Override
public void deleteByRoleIds(Long[] roleIds) {
baseDao.deleteByRoleIds(roleIds);
}
}

View File

@ -0,0 +1,60 @@
package com.cnbm.admin.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.cnbm.admin.dao.SysRoleMenuDao;
import com.cnbm.admin.entity.SysRoleMenuEntity;
import com.cnbm.admin.service.SysRoleMenuService;
import com.cnbm.common.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 3:04 PM
* @Version 1.0
*/
@Service
public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenuDao, SysRoleMenuEntity> implements SysRoleMenuService {
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
//先删除角色菜单关系
deleteByRoleIds(new Long[]{roleId});
//角色没有一个菜单权限的情况
if(CollUtil.isEmpty(menuIdList)){
return ;
}
//保存角色菜单关系
for(Long menuId : menuIdList){
SysRoleMenuEntity sysRoleMenuEntity = new SysRoleMenuEntity();
sysRoleMenuEntity.setMenuId(menuId);
sysRoleMenuEntity.setRoleId(roleId);
//保存
insert(sysRoleMenuEntity);
}
}
@Override
public List<Long> getMenuIdList(Long roleId){
return baseDao.getMenuIdList(roleId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteByRoleIds(Long[] roleIds) {
baseDao.deleteByRoleIds(roleIds);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteByMenuId(Long menuId) {
baseDao.deleteByMenuId(menuId);
}
}

View File

@ -0,0 +1,132 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysRoleDao;
import com.cnbm.admin.dto.SysRoleDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysRoleEntity;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.enums.SuperAdminEnum;
import com.cnbm.admin.service.*;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @Author weihongyang
* @Date 2022/6/12 10:08 AM
* @Version 1.0
*/
@Service
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {
@Autowired
private SysRoleMenuService sysRoleMenuService;
@Autowired
private SysRoleDataScopeService sysRoleDataScopeService;
@Autowired
private SysRoleUserService sysRoleUserService;
@Autowired
private SysDeptService sysDeptService;
@Override
public PageData<SysRoleDTO> page(Map<String, Object> params) {
IPage<SysRoleEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, SysRoleDTO.class);
}
@Override
public List<SysRoleDTO> list(Map<String, Object> params) {
List<SysRoleEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class);
}
private QueryWrapper<SysRoleEntity> getWrapper(Map<String, Object> params){
String name = (String)params.get("name");
QueryWrapper<SysRoleEntity> wrapper = new QueryWrapper<>();
wrapper.like(StringUtils.isNotBlank(name), "name", name);
//普通管理员只能查询所属部门及子部门的数据
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
if(!Objects.isNull(user.getSuperAdmin()) && user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
List<Long> deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId());
wrapper.in(deptIdList != null, "dept_id", deptIdList);
}
return wrapper;
}
@Override
public SysRoleDTO get(Long id) {
SysRoleEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, SysRoleDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysRoleDTO dto) {
SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class);
//保存角色
insert(entity);
//保存角色菜单关系
sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList());
//保存角色数据权限关系
sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysRoleDTO dto) {
SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class);
//更新角色
updateById(entity);
//更新角色菜单关系
sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList());
//更新角色数据权限关系
sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long[] ids) {
//删除角色
baseDao.deleteBatchIds(Arrays.asList(ids));
//删除角色用户关系
sysRoleUserService.deleteByRoleIds(ids);
//删除角色菜单关系
sysRoleMenuService.deleteByRoleIds(ids);
//删除角色数据权限关系
sysRoleDataScopeService.deleteByRoleIds(ids);
}
}

View File

@ -0,0 +1,56 @@
package com.cnbm.admin.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.cnbm.admin.dao.SysRoleUserDao;
import com.cnbm.admin.entity.SysRoleUserEntity;
import com.cnbm.admin.service.SysRoleUserService;
import com.cnbm.common.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author weihongyang
* @Date 2022/6/10 1:34 PM
* @Version 1.0
*/
@Service
public class SysRoleUserServiceImpl extends BaseServiceImpl<SysRoleUserDao, SysRoleUserEntity> implements SysRoleUserService {
@Override
public void saveOrUpdate(Long userId, List<Long> roleIdList) {
//先删除角色用户关系
deleteByUserIds(new Long[]{userId});
//用户没有一个角色权限的情况
if(CollUtil.isEmpty(roleIdList)){
return ;
}
//保存角色用户关系
for(Long roleId : roleIdList){
SysRoleUserEntity sysRoleUserEntity = new SysRoleUserEntity();
sysRoleUserEntity.setUserId(userId);
sysRoleUserEntity.setRoleId(roleId);
//保存
insert(sysRoleUserEntity);
}
}
@Override
public void deleteByRoleIds(Long[] roleIds) {
baseDao.deleteByRoleIds(roleIds);
}
@Override
public void deleteByUserIds(Long[] userIds) {
baseDao.deleteByUserIds(userIds);
}
@Override
public List<Long> getRoleIdList(Long userId) {
return baseDao.getRoleIdList(userId);
}
}

View File

@ -0,0 +1,154 @@
package com.cnbm.admin.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.dao.SysUserDao;
import com.cnbm.admin.dto.SysUserDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.enums.SuperAdminEnum;
import com.cnbm.admin.service.SysDeptService;
import com.cnbm.admin.service.SysRoleUserService;
import com.cnbm.admin.service.SysUserService;
import com.cnbm.admin.utils.PasswordUtils;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.BaseServiceImpl;
import com.cnbm.common.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Author weihongyang
* @Date 2022/6/10 1:24 PM
* @Version 1.0
*/
@Service
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
@Autowired
private SysRoleUserService sysRoleUserService;
@Autowired
private SysDeptService sysDeptService;
@Override
public PageData<SysUserDTO> page(Map<String, Object> params) {
//转换成like
paramsToLike(params, "username");
//分页
IPage<SysUserEntity> page = getPage(params, Constant.CREATE_DATE, false);
//普通管理员只能查询所属部门及子部门的数据
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
}
//查询
List<SysUserEntity> list = baseDao.getList(params);
return getPageData(list, page.getTotal(), SysUserDTO.class);
}
@Override
public List<SysUserDTO> list(Map<String, Object> params) {
//普通管理员只能查询所属部门及子部门的数据
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SysUserEntity user = loginUser.getSysUserEntity();
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
}
List<SysUserEntity> entityList = baseDao.getList(params);
return ConvertUtils.sourceToTarget(entityList, SysUserDTO.class);
}
@Override
public SysUserDTO get(Long id) {
SysUserEntity entity = baseDao.getById(id);
return ConvertUtils.sourceToTarget(entity, SysUserDTO.class);
}
@Override
public SysUserDTO getByUsername(String username) {
SysUserEntity entity = baseDao.getByUsername(username);
return ConvertUtils.sourceToTarget(entity, SysUserDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysUserDTO dto) {
SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class);
//密码加密
String password = PasswordUtils.encode(entity.getPassword());
entity.setPassword(password);
//保存用户
entity.setSuperAdmin(SuperAdminEnum.NO.value());
insert(entity);
//保存角色用户关系
sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysUserDTO dto) {
SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class);
//密码加密
if(StringUtils.isBlank(dto.getPassword())){
entity.setPassword(null);
}else{
String password = PasswordUtils.encode(entity.getPassword());
entity.setPassword(password);
}
//更新用户
updateById(entity);
//更新角色用户关系
sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList());
}
@Override
public void delete(Long[] ids) {
//删除用户
baseDao.deleteBatchIds(Arrays.asList(ids));
//删除角色用户关系
sysRoleUserService.deleteByUserIds(ids);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updatePassword(Long id, String newPassword) {
newPassword = PasswordUtils.encode(newPassword);
baseDao.updatePassword(id, newPassword);
}
@Override
public int getCountByDeptId(Long deptId) {
return baseDao.getCountByDeptId(deptId);
}
@Override
public List<Long> getUserIdListByDeptId(List<Long> deptIdList) {
return baseDao.getUserIdListByDeptId(deptIdList);
}
}

View File

@ -0,0 +1,57 @@
package com.cnbm.admin.service.impl;
import com.cnbm.admin.dao.UserDao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cnbm.admin.dto.SysMenuDTO;
import com.cnbm.admin.dto.SysUserDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.entity.SysMenuEntity;
import com.cnbm.admin.entity.SysUserEntity;
import com.cnbm.admin.service.SysMenuService;
import com.cnbm.common.utils.ConvertUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @Author weihongyang
* @Date 2022/6/8 8:57 AM
* @Version 1.0
*/
@Service
@Log4j2
public class UserDetailsServiceImpl implements UserDetailsService {
@Autowired
private UserDao userDao;
@Autowired
private SysMenuService sysMenuService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
LambdaQueryWrapper<SysUserEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysUserEntity::getUsername,username);
SysUserEntity sysUserEntity = userDao.selectOne(lambdaQueryWrapper);
if (Objects.isNull(sysUserEntity)) {
throw new UsernameNotFoundException("用户名不存在");
}
log.info("sysUserEntity的值是"+sysUserEntity.toString());
log.info("sysUserEntity.getSuperAdmin()=="+sysUserEntity.getSuperAdmin());
Set<String> userPermissions = sysMenuService.getUserPermissions(sysUserEntity);
List<String> list = userPermissions.stream().collect(Collectors.toList());
log.info("list==="+list.toString());
return new LoginUser(sysUserEntity,list);
}
}

View File

@ -0,0 +1,115 @@
package com.cnbm.admin.utils;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
import java.util.Date;
import java.util.UUID;
/**
* @Author weihongyang
* @Date 2022/6/8 1:43 PM
* @Version 1.0
*/
public class JwtUtil {
//有效期为
public static final Long JWT_TTL = 60 * 60 *1000L;// 60 * 60 *1000 一个小时
//设置秘钥明文
public static final String JWT_KEY = "why";
public static String getUUID(){
String token = UUID.randomUUID().toString().replaceAll("-", "");
return token;
}
/**
* 生成jtw
* @param subject token中要存放的数据json格式
* @return
*/
public static String createJWT(String subject) {
JwtBuilder builder = getJwtBuilder(subject, null, getUUID());// 设置过期时间
return builder.compact();
}
/**
* 生成jtw
* @param subject token中要存放的数据json格式
* @param ttlMillis token超时时间
* @return
*/
public static String createJWT(String subject, Long ttlMillis) {
JwtBuilder builder = getJwtBuilder(subject, ttlMillis, getUUID());// 设置过期时间
return builder.compact();
}
private static JwtBuilder getJwtBuilder(String subject, Long ttlMillis, String uuid) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
SecretKey secretKey = generalKey();
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
if(ttlMillis==null){
ttlMillis=JwtUtil.JWT_TTL;
}
long expMillis = nowMillis + ttlMillis;
Date expDate = new Date(expMillis);
return Jwts.builder()
.setId(uuid) //唯一的ID
.setSubject(subject) // 主题 可以是JSON数据
.setIssuer("why") // 签发者
.setIssuedAt(now) // 签发时间
.signWith(signatureAlgorithm, secretKey) //使用HS256对称加密算法签名, 第二个参数为秘钥
.setExpiration(expDate);
}
/**
* 创建token
* @param id
* @param subject
* @param ttlMillis
* @return
*/
public static String createJWT(String id, String subject, Long ttlMillis) {
JwtBuilder builder = getJwtBuilder(subject, ttlMillis, id);// 设置过期时间
return builder.compact();
}
public static void main(String[] args) throws Exception {
// String jwt = createJWT("123");
Claims claims = parseJWT("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI5OWNhNGJhMjg5ZjU0OTVjODE5YTM0N2ExZmNlZjc0YSIsInN1YiI6IjEyMyIsImlzcyI6IndoeSIsImlhdCI6MTY1NDc1OTg5NiwiZXhwIjoxNjU0NzYzNDk2fQ.CTgS6yQjfXSGPJUTu-_rqjkh_KB_F9SzPThFfnvB5yg");
String subject = claims.getSubject();
System.out.println(subject);
// System.out.println(claims);
}
/**
* 生成加密后的秘钥 secretKey
* @return
*/
public static SecretKey generalKey() {
byte[] encodedKey = Base64.getDecoder().decode(JwtUtil.JWT_KEY);
SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
return key;
}
/**
* 解析
*
* @param jwt
* @return
* @throws Exception
*/
public static Claims parseJWT(String jwt) throws Exception {
SecretKey secretKey = generalKey();
return Jwts.parser()
.setSigningKey(secretKey)
.parseClaimsJws(jwt)
.getBody();
}
}

View File

@ -0,0 +1,43 @@
package com.cnbm.admin.utils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
* @Author weihongyang
* @Date 2022/6/10 1:57 PM
* @Version 1.0
*/
public class PasswordUtils {
private static PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
/**
* 加密
* @param str 字符串
* @return 返回加密字符串
*/
public static String encode(String str){
return passwordEncoder.encode(str);
}
/**
* 比较密码是否相等
* @param str 明文密码
* @param password 加密后密码
* @return true成功 false失败
*/
public static boolean matches(String str, String password){
return passwordEncoder.matches(str, password);
}
public static void main(String[] args) {
String str = "admin";
String password = encode(str);
System.out.println(password);
System.out.println(matches(str, password));
}
}

Some files were not shown because too many files have changed in this diff Show More