Commit 808226c1 by yw

项目初始化

parent 0d1c3ea8
......@@ -31,6 +31,7 @@ public class DataWebSecurityConfigurer extends WebSecurityConfigurerAdapter {
"/actuator/**",
"/v2/api-docs/**",
"/swagger-ui.html",
"/doc.html",
"/swagger-resources/**",
"/webjars/**").permitAll()
.anyRequest().authenticated()
......
......@@ -79,10 +79,6 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.datax.common.base;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class BaseServiceImpl<M extends BaseDao<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {
@Autowired
protected M BaseDao;
}
package cn.datax.common.utils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
public class SecurityUtil {
/**
* 获取客户端
*
* @return clientId
*/
private String getClientId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof OAuth2Authentication) {
OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;
return auth2Authentication.getOAuth2Request().getClientId();
}
return null;
}
/**
* 获取用户名称
*
* @return username
*/
private String getUsername() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof OAuth2Authentication) {
OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;
return auth2Authentication.getName();
}
return null;
}
}
......@@ -6,7 +6,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@MapperScan("cn.datax.service.**.mapper")
@MapperScan("cn.datax.service.**.dao")
@EnableTransactionManagement
@Import({DataMetaObjectHandler.class})
public class DataBatisPlusConfig {
......
......@@ -24,7 +24,7 @@ spring:
- name: Hystrix
args:
name: authFallback
fallbackUri: forward:/fallback/data-auth
fallbackUri: forward:/fallback/datax-auth
# 系统配置中心
- id: datax-service-system
uri: lb://datax-service-system
......@@ -34,17 +34,27 @@ spring:
- name: Hystrix
args:
name: systemFallback
fallbackUri: forward:/fallback/data-service-system
fallbackUri: forward:/fallback/datax-service-system
# 邮件中心
- id: datax-service-mail
uri: lb://datax-service-mail
- id: datax-service-email
uri: lb://datax-service-email
predicates:
- Path=/mail/**
- Path=/email/**
filters:
- name: Hystrix
args:
name: mailFallback
fallbackUri: forward:/fallback/data-service-mail
name: emailFallback
fallbackUri: forward:/fallback/datax-service-email
# 邮件中心
- id: datax-service-file
uri: lb://datax-service-file
predicates:
- Path=/file/**
filters:
- name: Hystrix
args:
name: fileFallback
fallbackUri: forward:/fallback/datax-service-file
# 即时通讯消息中心
- id: datax-websocket-server
uri: ws://localhost:9876
......
......@@ -37,7 +37,7 @@ spring:
mybatis-plus:
mapper-locations: classpath*:mapper/*Mapper.xml
type-aliases-package: cn.datax.email.api.entity
type-aliases-package: cn.datax.service.email.api.entity
global-config:
db-config:
id-type: ID_WORKER_STR
......
......@@ -37,7 +37,7 @@ spring:
mybatis-plus:
mapper-locations: classpath*:mapper/*Mapper.xml
type-aliases-package: cn.datax.file.api.entity
type-aliases-package: cn.datax.service.file.api.entity
global-config:
db-config:
id-type: ID_WORKER_STR
......
......@@ -48,7 +48,7 @@ spring:
mybatis-plus:
mapper-locations: classpath*:mapper/*Mapper.xml
type-aliases-package: cn.datax.system.api.entity
type-aliases-package: cn.datax.service.system.api.entity
global-config:
db-config:
id-type: ID_WORKER_STR
......
......@@ -12,11 +12,6 @@
<artifactId>datax-gateway</artifactId>
<dependencies>
<!--web 模块-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<!--配置中心客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
......@@ -28,6 +23,11 @@
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>cn.datax</groupId>
<artifactId>datax-common-core</artifactId>
<version>${app.version}</version>
......
package cn.datax.gateway.config;
import lombok.AllArgsConstructor;
import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.support.NameUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import java.util.ArrayList;
import java.util.List;
@Component
@Primary
@AllArgsConstructor
public class SwaggerProvider implements SwaggerResourcesProvider {
public static final String API_URI = "/v2/api-docs";
private final RouteLocator routeLocator;
private final GatewayProperties gatewayProperties;
@Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources = new ArrayList<>();
List<String> routes = new ArrayList<>();
//取出gateway的route
routeLocator.getRoutes().subscribe(route -> routes.add(route.getId()));
//结合配置的route-路径(Path),和route过滤,只获取有效的route节点
gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId()))
.forEach(routeDefinition -> routeDefinition.getPredicates().stream()
.filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName()))
.forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(),
predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0")
.replace("/**", API_URI)))));
return resources;
}
private SwaggerResource swaggerResource(String name, String location) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion("1.0");
return swaggerResource;
}
}
package cn.datax.gateway.filter;
import cn.datax.gateway.config.SwaggerProvider;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
@Component
public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory {
private static final String HEADER_NAME = "X-Forwarded-Prefix";
@Override
public GatewayFilter apply(Object config) {
return (exchange, chain) -> {
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();
if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) {
return chain.filter(exchange);
}
String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI));
ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build();
ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
return chain.filter(newExchange);
};
}
}
......@@ -9,7 +9,6 @@ spring:
cloud:
config:
fail-fast: true
uri: http://localhost:8611
name: ${spring.application.name}
profile: ${spring.profiles.active}
discovery:
......
......@@ -38,11 +38,6 @@
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
......
package cn.datax.service.email.mapper;
import cn.datax.common.base.BaseDao;
import cn.datax.service.email.api.entity.EmailEntity;
public interface MailMapper extends BaseDao<EmailEntity> {
}
......@@ -9,7 +9,7 @@ spring:
cloud:
config:
fail-fast: true
uri: http://localhost:8611
# uri: http://localhost:8611
name: ${spring.application.name}
profile: ${spring.profiles.active}
discovery:
......
......@@ -51,11 +51,6 @@
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
......
package cn.datax.service.file.mapper;
import cn.datax.service.file.api.entity.FileEntity;
import cn.datax.common.base.BaseDao;
/**
* <p>
* Mapper 接口
* </p>
*
* @author yuwei
* @since 2019-09-17
*/
public interface FileMapper extends BaseDao<FileEntity> {
}
package cn.datax.service.file.service.impl;
import cn.datax.service.file.api.entity.FileEntity;
import cn.datax.service.file.mapper.FileMapper;
import cn.datax.service.file.dao.FileDao;
import cn.datax.service.file.service.FileService;
import cn.datax.common.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
......@@ -19,7 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public abstract class FileServiceImpl extends BaseServiceImpl<FileMapper, FileEntity> implements FileService {
public abstract class FileServiceImpl extends BaseServiceImpl<FileDao, FileEntity> implements FileService {
@Override
public FileEntity uploadFile(MultipartFile file) {
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.datax.service.file.mapper.FileMapper">
<mapper namespace="cn.datax.service.file.dao.FileDao">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.datax.service.file.api.entity.FileEntity">
......
......@@ -12,6 +12,26 @@
<artifactId>system-service-api</artifactId>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-bootstrap.version}</version>
</dependency>
<!--feign 依赖-->
<dependency>
<groupId>io.github.openfeign</groupId>
......
......@@ -2,22 +2,28 @@ package cn.datax.service.system.api.dto;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@ApiModel(value = "部门Model")
@Data
public class DeptDto implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "主键ID")
@NotBlank(message = "主键ID不能为空", groups = {ValidateGroupForUpdate.class})
private String id;
@ApiModelProperty(value = "父部门ID")
@NotBlank(message = "父部门ID不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String parentId;
@ApiModelProperty(value = "部门名称")
@NotBlank(message = "部门名称不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String deptName;
......
......@@ -2,37 +2,49 @@ package cn.datax.service.system.api.dto;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ApiModel(value = "资源Model")
@Data
public class MenuDto implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "主键ID")
@NotBlank(message = "主键ID不能为空", groups = {ValidateGroupForUpdate.class})
private String id;
@ApiModelProperty(value = "父资源ID")
@NotBlank(message = "父资源ID不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String parentId;
@ApiModelProperty(value = "资源名称")
@NotBlank(message = "资源名称不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String menuName;
@ApiModelProperty(value = "对应路由path")
private String menuPath;
@ApiModelProperty(value = "对应路由组件component")
private String menuComponent;
@ApiModelProperty(value = "权限标识")
private String menuPerms;
@ApiModelProperty(value = "图标")
private String menuIcon;
@ApiModelProperty(value = "类型")
@NotNull(message = "类型不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private Integer menuType;
@ApiModelProperty(value = "排序")
@NotNull(message = "排序不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private Integer menuSort;
}
......@@ -2,19 +2,24 @@ package cn.datax.service.system.api.dto;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@ApiModel(value = "岗位Model")
@Data
public class PostDto implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "主键ID")
@NotBlank(message = "主键ID不能为空", groups = {ValidateGroupForUpdate.class})
private String id;
@ApiModelProperty(value = "岗位名称")
@NotBlank(message = "岗位名称不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String postName;
......
......@@ -2,22 +2,28 @@ package cn.datax.service.system.api.dto;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@ApiModel(value = "角色Model")
@Data
public class RoleDto implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "主键ID")
@NotBlank(message = "主键ID不能为空", groups = {ValidateGroupForUpdate.class})
private String id;
@ApiModelProperty(value = "角色名称")
@NotBlank(message = "角色名称不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String roleName;
@ApiModelProperty(value = "角色编码")
@NotBlank(message = "角色编码不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String roleCode;
......
......@@ -2,6 +2,8 @@ package cn.datax.service.system.api.dto;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
......@@ -11,43 +13,54 @@ import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
@ApiModel(value = "用户Model")
@Data
public class UserDto implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "主键ID")
@NotBlank(message = "主键ID不能为空", groups = {ValidateGroupForUpdate.class})
private String id;
@ApiModelProperty(value = "用户名")
@NotBlank(message = "用户名不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
@Length(min=3, max = 12, message="用户名长度必须位于{min}-{max}之间")
private String username;
@ApiModelProperty(value = "昵称")
@NotBlank(message = "昵称不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String nickname;
@ApiModelProperty(value = "密码")
@NotBlank(message = "密码不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String password;
@ApiModelProperty(value = "电子邮箱")
@NotBlank(message = "电子邮箱不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
@Email(message = "请输入正确的邮箱")
private String email;
@ApiModelProperty(value = "手机号码")
@NotBlank(message = "手机号码不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
private String phone;
@ApiModelProperty(value = "出生日期", example = "2019-09-09")
@NotNull(message = "出生日期不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate birthday;
@ApiModelProperty(value = "部门")
@NotEmpty(message = "部门不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
@Size(min = 1, max = 1, message="部门长度必须位于{min}-{max}之间")
private List<String> depts;
@ApiModelProperty(value = "角色")
@NotEmpty(message = "角色不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
@Size(min = 1, max = 5, message="角色长度必须位于{min}-{max}之间")
private List<String> roles;
@ApiModelProperty(value = "岗位")
@NotEmpty(message = "岗位不能为空", groups = {ValidateGroupForSave.class, ValidateGroupForUpdate.class})
@Size(min = 1, max = 1, message="岗位长度必须位于{min}-{max}之间")
private List<String> posts;
......
package cn.datax.service.system.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@ApiModel(value = "用户密码Model")
@Data
public class UserPasswordDto implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "主键ID")
@NotBlank(message = "主键ID不能为空")
private String id;
@ApiModelProperty(value = "密码")
@NotBlank(message = "密码不能为空")
private String password;
@ApiModelProperty(value = "旧密码")
@NotBlank(message = "旧密码不能为空")
private String oldPassword;
}
package cn.datax.service.system.api.vo;
import cn.datax.service.system.api.entity.DeptEntity;
import cn.datax.service.system.api.entity.PostEntity;
import cn.datax.service.system.api.entity.RoleEntity;
import cn.datax.service.system.api.entity.UserEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.time.LocalDate;
......@@ -22,6 +18,7 @@ public class UserVo implements Serializable {
private String nickname;
private String email;
private String phone;
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private LocalDate birthday;
private List<DeptVo> depts;
private List<PostVo> posts;
......
......@@ -23,21 +23,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
......
package cn.datax.service.system;
import cn.datax.common.log.annotation.EnableDataLog;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataAuthExceptionHandler;
......@@ -10,12 +11,13 @@ import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableDataAuthExceptionHandler
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableDataLog
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@SpringBootApplication
public class DataxSystemApplication {
......
......@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
......@@ -44,4 +45,20 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
.authenticationEntryPoint(exceptionEntryPoint)
.accessDeniedHandler(accessDeniedHandler);
}
@Override
public void configure(HttpSecurity http) throws Exception {
//允许使用iframe 嵌套,避免swagger-ui 不被加载的问题
http.headers().frameOptions().disable();
http.authorizeRequests()
.antMatchers(
"/actuator/**",
"/v2/api-docs/**",
"/swagger-ui.html",
"/doc.html",
"/swagger-resources/**",
"/webjars/**").permitAll()
.anyRequest().authenticated()
.and().csrf().disable();
}
}
package cn.datax.service.system.config;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.*;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
/**
* 创建API应用
* apiInfo() 增加API相关信息
* 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
* 本例采用指定扫描的包路径来定义指定要建立API的目录。
*
* @return
*/
@Bean
public Docket createRestApi(){
//版本类型是swagger2
return new Docket(DocumentationType.SWAGGER_2)
//通过调用自定义方法apiInfo,获得文档的主要信息
.apiInfo(apiInfo())
//设置全局参数
.globalOperationParameters(globalParamBuilder())
//设置全局响应参数
.globalResponseMessage(RequestMethod.GET,responseBuilder())
.globalResponseMessage(RequestMethod.POST,responseBuilder())
.globalResponseMessage(RequestMethod.PUT,responseBuilder())
.globalResponseMessage(RequestMethod.DELETE,responseBuilder())
.select()
.apis(RequestHandlerSelectors.basePackage("cn.datax.service.system.controller"))//扫描该包下面的API注解
.paths(PathSelectors.any())
.build()
//设置安全认证
.securitySchemes(security());
}
/**
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
* 访问地址:http://项目实际地址/swagger-ui.html
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("系统管理中心") //接口管理文档首页显示
.description("系统管理中心接口文档") //API的描述
.version("1.0")
.build();
}
/**
* 安全认证参数
* @return
*/
private List<ApiKey> security() {
List<ApiKey> apiKeys = new ArrayList<>();
apiKeys.add(new ApiKey("Authorization", "Authorization", "header"));
return apiKeys;
}
/**
* 构建全局参数列表
* @return
*/
private List<Parameter> globalParamBuilder(){
List<Parameter> pars = new ArrayList<>();
pars.add(parameterBuilder("Authorization","令牌","string","header",false).build());
return pars;
}
/**
* 创建参数
* @return
*/
private ParameterBuilder parameterBuilder(String name, String desc, String type, String parameterType, boolean required) {
ParameterBuilder tokenPar = new ParameterBuilder();
tokenPar.name(name).description(desc).modelRef(new ModelRef(type)).parameterType(parameterType).required(required).build();
return tokenPar;
}
/**
* 创建全局响应值
* @return
*/
private List<ResponseMessage> responseBuilder() {
List<ResponseMessage> responseMessageList = new ArrayList<>();
responseMessageList.add(new ResponseMessageBuilder().code(200).message("响应成功").build());
responseMessageList.add(new ResponseMessageBuilder().code(500).message("服务器内部错误").build());
return responseMessageList;
}
}
......@@ -26,7 +26,7 @@ import cn.datax.common.base.BaseController;
* @author yuwei
* @since 2019-09-04
*/
@Api(tags = {"系统管理"})
@Api(value="系统管理接口", tags = {"系统管理"})
@RestController
@RequestMapping("/depts")
public class DeptController extends BaseController {
......
......@@ -26,7 +26,7 @@ import cn.datax.common.base.BaseController;
* @author yuwei
* @since 2019-09-11
*/
@Api(tags = {"系统管理"})
@Api(value="系统管理接口", tags = {"系统管理"})
@RestController
@RequestMapping("/menus")
public class MenuController extends BaseController {
......@@ -37,32 +37,32 @@ public class MenuController extends BaseController {
@Autowired
private MenuMapper menuMapper;
@ApiOperation(value = "获取菜单详细信息", notes = "根据url的id来获取菜单详细信息")
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, dataType = "String", paramType = "path")
@ApiOperation(value = "获取资源详细信息", notes = "根据url的id来获取资源详细信息")
@ApiImplicitParam(name = "id", value = "资源ID", required = true, dataType = "String", paramType = "path")
@GetMapping("/{id}")
public R getMenuById(@PathVariable String id) {
MenuEntity menuEntity = menuService.getById(id);
return R.ok().setData(menuMapper.toVO(menuEntity));
}
@ApiOperation(value = "获取菜单列表", notes = "")
@ApiOperation(value = "获取资源列表", notes = "")
@GetMapping()
public R getMenuList() {
return R.ok().setData(menuService.list(Wrappers.emptyWrapper()));
}
@ApiOperation(value = "创建菜单", notes = "根据menu对象创建菜单")
@ApiImplicitParam(name = "menu", value = "菜单详细实体menu", required = true, dataType = "MenuDto")
@ApiOperation(value = "创建资源", notes = "根据menu对象创建资源")
@ApiImplicitParam(name = "menu", value = "资源详细实体menu", required = true, dataType = "MenuDto")
@PostMapping()
public R saveMenu(@RequestBody @Validated({ValidateGroupForSave.class}) MenuDto menu) {
menuService.saveMenu(menu);
return R.ok();
}
@ApiOperation(value = "更新菜单详细信息", notes = "根据url的id来指定更新对象,并根据传过来的menu信息来更新菜单详细信息")
@ApiOperation(value = "更新资源详细信息", notes = "根据url的id来指定更新对象,并根据传过来的menu信息来更新资源详细信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "menu", value = "菜单详细实体menu", required = true, dataType = "MenuDto")
@ApiImplicitParam(name = "id", value = "资源ID", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "menu", value = "资源详细实体menu", required = true, dataType = "MenuDto")
})
@PutMapping("/{id}")
public R updateMenu(@PathVariable String id, @RequestBody @Validated({ValidateGroupForUpdate.class}) MenuDto menu) {
......@@ -70,8 +70,8 @@ public class MenuController extends BaseController {
return R.ok();
}
@ApiOperation(value = "删除菜单", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, dataType = "String", paramType = "path")
@ApiOperation(value = "删除资源", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(name = "id", value = "资源ID", required = true, dataType = "String", paramType = "path")
@DeleteMapping("/{id}")
public R deleteMenu(@PathVariable String id) {
menuService.deleteMenuById(id);
......
......@@ -30,7 +30,7 @@ import cn.datax.common.base.BaseController;
* @author yuwei
* @since 2019-09-11
*/
@Api(tags = {"系统管理"})
@Api(value="系统管理接口", tags = {"系统管理"})
@RestController
@RequestMapping("/posts")
public class PostController extends BaseController {
......
......@@ -30,7 +30,7 @@ import cn.datax.common.base.BaseController;
* @author yuwei
* @since 2019-09-04
*/
@Api(tags = {"系统管理"})
@Api(value="系统管理接口", tags = {"系统管理"})
@RestController
@RequestMapping("/roles")
public class RoleController extends BaseController {
......
......@@ -31,7 +31,7 @@ import cn.datax.common.base.BaseController;
* @author yuwei
* @since 2019-09-04
*/
@Api(tags = {"系统管理"})
@Api(value="系统管理接口", tags = {"系统管理"})
@RestController
@RequestMapping("/users")
public class UserController extends BaseController {
......
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.common.base.BaseDao;
import cn.datax.service.system.api.entity.DeptEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
......@@ -11,6 +12,7 @@ import cn.datax.service.system.api.entity.DeptEntity;
* @author yuwei
* @since 2019-09-04
*/
@Mapper
public interface DeptDao extends BaseDao<DeptEntity> {
}
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.service.system.api.entity.MenuEntity;
import cn.datax.common.base.BaseDao;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
......@@ -11,6 +12,7 @@ import cn.datax.common.base.BaseDao;
* @author yuwei
* @since 2019-09-11
*/
@Mapper
public interface MenuDao extends BaseDao<MenuEntity> {
}
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.service.system.api.entity.PostEntity;
import cn.datax.common.base.BaseDao;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
......@@ -11,6 +12,7 @@ import cn.datax.common.base.BaseDao;
* @author yuwei
* @since 2019-09-11
*/
@Mapper
public interface PostDao extends BaseDao<PostEntity> {
}
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.common.base.BaseDao;
import cn.datax.service.system.api.entity.RoleEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
......@@ -11,6 +12,7 @@ import cn.datax.service.system.api.entity.RoleEntity;
* @author yuwei
* @since 2019-09-04
*/
@Mapper
public interface RoleDao extends BaseDao<RoleEntity> {
}
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.service.system.api.entity.RoleMenuEntity;
import cn.datax.common.base.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
......@@ -13,6 +14,7 @@ import java.util.List;
* @author yuwei
* @since 2019-09-11
*/
@Mapper
public interface RoleMenuDao extends BaseDao<RoleMenuEntity> {
void insertBatch(List<RoleMenuEntity> list);
......
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.common.base.BaseDao;
import cn.datax.service.system.api.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
......@@ -12,6 +13,7 @@ import org.apache.ibatis.annotations.Param;
* @author yuwei
* @since 2019-09-04
*/
@Mapper
public interface UserDao extends BaseDao<UserEntity> {
void updateUserPassword(@Param("password") String passwordEncode, @Param("id")String id);
......
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.service.system.api.entity.UserDeptEntity;
import cn.datax.common.base.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
......@@ -13,6 +14,7 @@ import java.util.List;
* @author yuwei
* @since 2019-09-11
*/
@Mapper
public interface UserDeptDao extends BaseDao<UserDeptEntity> {
void insertBatch(List<UserDeptEntity> list);
......
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.service.system.api.entity.UserPostEntity;
import cn.datax.common.base.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
......@@ -13,6 +14,7 @@ import java.util.List;
* @author yuwei
* @since 2019-09-11
*/
@Mapper
public interface UserPostDao extends BaseDao<UserPostEntity> {
void insertBatch(List<UserPostEntity> list);
......
......@@ -2,6 +2,7 @@ package cn.datax.service.system.dao;
import cn.datax.common.base.BaseDao;
import cn.datax.service.system.api.entity.UserRoleEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
......@@ -13,6 +14,7 @@ import java.util.List;
* @author yuwei
* @since 2019-09-04
*/
@Mapper
public interface UserRoleDao extends BaseDao<UserRoleEntity> {
void insertBatch(List<UserRoleEntity> list);
......
......@@ -26,33 +26,35 @@ import org.springframework.transaction.annotation.Transactional;
public class DeptServiceImpl extends BaseServiceImpl<DeptDao, DeptEntity> implements DeptService {
@Autowired
private DeptDao deptDao;
@Autowired
private DeptMapper deptMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDept(DeptDto deptDto) {
DeptEntity dept = deptMapper.toEntity(deptDto);
int n = baseMapper.selectCount(Wrappers.<DeptEntity>lambdaQuery().eq(DeptEntity::getDeptName, dept.getDeptName()));
int n = deptDao.selectCount(Wrappers.<DeptEntity>lambdaQuery().eq(DeptEntity::getDeptName, dept.getDeptName()));
if(n > 0){
throw new DataException("该部门名已存在");
}
baseMapper.insert(dept);
deptDao.insert(dept);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDept(DeptDto deptDto) {
DeptEntity dept = deptMapper.toEntity(deptDto);
baseMapper.updateById(dept);
deptDao.updateById(dept);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDeptById(String id) {
int n = baseMapper.selectCount(Wrappers.<DeptEntity>lambdaQuery().eq(DeptEntity::getParentId, id));
int n = deptDao.selectCount(Wrappers.<DeptEntity>lambdaQuery().eq(DeptEntity::getParentId, id));
if(n > 0){
throw new DataException("该部门下存在子部门数据");
}
baseMapper.deleteById(id);
deptDao.deleteById(id);
}
}
......@@ -26,29 +26,31 @@ import org.springframework.transaction.annotation.Transactional;
public class MenuServiceImpl extends BaseServiceImpl<MenuDao, MenuEntity> implements MenuService {
@Autowired
private MenuDao menuDao;
@Autowired
private MenuMapper menuMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveMenu(MenuDto menuDto) {
MenuEntity menu = menuMapper.toEntity(menuDto);
baseMapper.insert(menu);
menuDao.insert(menu);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMenu(MenuDto menuDto) {
MenuEntity menu = menuMapper.toEntity(menuDto);
baseMapper.updateById(menu);
menuDao.updateById(menu);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteMenuById(String id) {
int n = baseMapper.selectCount(Wrappers.<MenuEntity>lambdaQuery().eq(MenuEntity::getParentId, id));
int n = menuDao.selectCount(Wrappers.<MenuEntity>lambdaQuery().eq(MenuEntity::getParentId, id));
if(n > 0){
throw new DataException("该菜单下存在子菜单数据");
}
baseMapper.deleteById(id);
menuDao.deleteById(id);
}
}
......@@ -26,29 +26,31 @@ import org.springframework.transaction.annotation.Transactional;
public class PostServiceImpl extends BaseServiceImpl<PostDao, PostEntity> implements PostService {
@Autowired
private PostDao postDao;
@Autowired
private PostMapper postMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void savePost(PostDto postDto) {
PostEntity post = postMapper.toEntity(postDto);
int n = baseMapper.selectCount(Wrappers.<PostEntity>lambdaQuery().eq(PostEntity::getPostName, post.getPostName()));
int n = postDao.selectCount(Wrappers.<PostEntity>lambdaQuery().eq(PostEntity::getPostName, post.getPostName()));
if(n > 0){
throw new DataException("该岗位名已存在");
}
baseMapper.insert(post);
postDao.insert(post);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updatePost(PostDto postDto) {
PostEntity post = postMapper.toEntity(postDto);
baseMapper.updateById(post);
postDao.updateById(post);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePostById(String id) {
baseMapper.deleteById(id);
postDao.deleteById(id);
}
}
......@@ -26,30 +26,32 @@ import org.springframework.transaction.annotation.Transactional;
public class RoleServiceImpl extends BaseServiceImpl<RoleDao, RoleEntity> implements RoleService {
@Autowired
private RoleDao roleDao;
@Autowired
private RoleMapper roleMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveRole(RoleDto roleDto) {
RoleEntity role = roleMapper.toEntity(roleDto);
int n = baseMapper.selectCount(Wrappers.<RoleEntity>lambdaQuery().eq(RoleEntity::getRoleName, role.getRoleName()));
int n = roleDao.selectCount(Wrappers.<RoleEntity>lambdaQuery().eq(RoleEntity::getRoleName, role.getRoleName()));
if(n > 0){
throw new DataException("该角色名已存在");
}
baseMapper.insert(role);
roleDao.insert(role);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateRole(RoleDto roleDto) {
RoleEntity role = roleMapper.toEntity(roleDto);
baseMapper.updateById(role);
roleDao.updateById(role);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteRoleById(String id) {
baseMapper.deleteById(id);
roleDao.deleteById(id);
}
}
......@@ -38,11 +38,13 @@ import java.util.stream.Collectors;
public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implements UserService {
@Autowired
private UserDeptDao userDeptMapper;
private UserDao userDao;
@Autowired
private UserPostDao userPostMapper;
private UserDeptDao userDeptDao;
@Autowired
private UserRoleDao userRoleMapper;
private UserPostDao userPostDao;
@Autowired
private UserRoleDao userRoleDao;
@Autowired
private UserMapper userMapper;
......@@ -50,13 +52,13 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
@Transactional(rollbackFor = Exception.class)
public void saveUser(UserDto userDto) {
UserEntity user = userMapper.toEntity(userDto);
int n = baseMapper.selectCount(Wrappers.<UserEntity>lambdaQuery().eq(UserEntity::getUsername, user.getUsername()));
int n = userDao.selectCount(Wrappers.<UserEntity>lambdaQuery().eq(UserEntity::getUsername, user.getUsername()));
if(n > 0){
throw new DataException("该用户名已存在");
}
String passwordEncode = new BCryptPasswordEncoder().encode(user.getPassword());
user.setPassword(passwordEncode);
baseMapper.insert(user);
userDao.insert(user);
insertBatchRole(userDto.getRoles(), user.getId());
insertBatchDept(userDto.getDepts(), user.getId());
insertBatchPost(userDto.getPosts(), user.getId());
......@@ -70,7 +72,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
userPost.setPostId(postId);
return userPost;
}).collect(Collectors.toList());
userPostMapper.insertBatch(userPostList);
userPostDao.insertBatch(userPostList);
}
private void insertBatchDept(List<String> deptss, String userId) {
......@@ -81,7 +83,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
userDept.setDeptId(deptId);
return userDept;
}).collect(Collectors.toList());
userDeptMapper.insertBatch(userDeptList);
userDeptDao.insertBatch(userDeptList);
}
private void insertBatchRole(List<String> roles, String userId) {
......@@ -92,21 +94,21 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
userRole.setRoleId(roleId);
return userRole;
}).collect(Collectors.toList());
userRoleMapper.insertBatch(userRoleList);
userRoleDao.insertBatch(userRoleList);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateUser(UserDto userDto) {
UserEntity user = userMapper.toEntity(userDto);
baseMapper.updateById(user);
userRoleMapper.delete(Wrappers.<UserRoleEntity>lambdaQuery()
userDao.updateById(user);
userRoleDao.delete(Wrappers.<UserRoleEntity>lambdaQuery()
.eq(UserRoleEntity::getUserId, userDto.getId()));
insertBatchRole(userDto.getRoles(), user.getId());
userDeptMapper.delete(Wrappers.<UserDeptEntity>lambdaQuery()
userDeptDao.delete(Wrappers.<UserDeptEntity>lambdaQuery()
.eq(UserDeptEntity::getUserId, userDto.getId()));
insertBatchDept(userDto.getDepts(), user.getId());
userPostMapper.delete(Wrappers.<UserPostEntity>lambdaQuery()
userPostDao.delete(Wrappers.<UserPostEntity>lambdaQuery()
.eq(UserPostEntity::getUserId, userDto.getId()));
insertBatchPost(userDto.getPosts(), user.getId());
}
......@@ -114,18 +116,18 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteUserById(String id) {
baseMapper.deleteById(id);
userDao.deleteById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateUserPassword(UserPasswordDto userPasswordDto) {
UserEntity userEntity = baseMapper.selectById(userPasswordDto.getId());
UserEntity userEntity = userDao.selectById(userPasswordDto.getId());
if(!StrUtil.equals(userEntity.getPassword(), new BCryptPasswordEncoder().encode(userPasswordDto.getOldPassword()))){
throw new DataException("旧密码不正确");
}
String passwordEncode = new BCryptPasswordEncoder().encode(userPasswordDto.getPassword());
baseMapper.updateUserPassword(passwordEncode, userPasswordDto.getId());
userDao.updateUserPassword(passwordEncode, userPasswordDto.getId());
}
}
......@@ -9,7 +9,6 @@ spring:
cloud:
config:
fail-fast: true
uri: http://localhost:8611
name: ${spring.application.name}
profile: ${spring.profiles.active}
discovery:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment