Conflicts:
	ym-gateway/pom.xml
This commit is contained in:
caixiang 2022-06-22 09:14:41 +08:00
commit 3b7b592a16
21 changed files with 332 additions and 97 deletions

View File

@ -1,9 +1,25 @@
package com.cnbm.admin.config;
import com.cnbm.common.utils.DateUtils;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;
/**
* @Author weihongyang
* @Date 2022/6/8 10:47 AM
@ -27,4 +43,35 @@ public class CorsConfig implements WebMvcConfigurer {
// 跨域允许时间
.maxAge(3600);
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
converters.add(new ResourceHttpMessageConverter());
converters.add(new AllEncompassingFormHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
converters.add(jackson2HttpMessageConverter());
}
@Bean
public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = new ObjectMapper();
//日期格式转换
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setDateFormat(new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN));
mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//Long类型转String类型
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
mapper.registerModule(simpleModule);
converter.setObjectMapper(mapper);
return converter;
}
}

View File

@ -1,10 +1,14 @@
package com.cnbm.admin.config;
import com.cnbm.admin.filter.JwtAuthenticationTokenFilter;
import com.cnbm.admin.service.impl.UserDetailsServiceImpl;
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.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
@ -38,6 +42,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AccessDeniedHandler accessDeniedHandler;
@Autowired
private UserDetailsServiceImpl userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
@ -48,7 +56,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.authorizeRequests()
// 对于登录接口 允许匿名访问
.antMatchers("/login").anonymous()
.antMatchers("/login","/swagger/**","/v2/**",
"/doc.html",
"/swagger-resources/**",
"/swagger-ui/**",
"/webjars/**").anonymous()
// .antMatchers("/testCors").hasAuthority("system:dept:list222")
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();
@ -71,4 +83,22 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public AuthenticationProvider daoAuthenticationProvider() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService(userDetailsService);
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
daoAuthenticationProvider.setHideUserNotFoundExceptions(false);
return daoAuthenticationProvider;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// 加入自定义认证, 无需配置userDetailsService否则会执行默认的provider
// auth.authenticationProvider(myAuthenticationProvider());
/* auth.userDetailsService(userService)
.passwordEncoder(passwordEncoder());*/
auth.authenticationProvider(daoAuthenticationProvider());
}
}

View File

@ -36,12 +36,12 @@ public class SysDictDataController {
@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")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = "dictLabel", value = "字典标签", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "dictValue", value = "字典值", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('sys:dept:page')")
public Result<PageData<SysDictDataDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){

View File

@ -38,12 +38,12 @@ public class SysDictTypeController {
@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")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = "dictType", value = "字典类型", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "dictName", value = "字典名称", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('sys:dict:page')")
public Result<PageData<SysDictTypeDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){

View File

@ -38,10 +38,10 @@ public class SysLogErrorController {
@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 = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class)
})
public Result<PageData<SysLogErrorDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysLogErrorDTO> page = sysLogErrorService.page(params);

View File

@ -38,11 +38,11 @@ public class SysLogOperationController {
@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")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = "status", value = "状态 0失败 1成功", paramType = "query", dataTypeClass=String.class)
})
public Result<PageData<SysLogOperationDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<SysLogOperationDTO> page = sysLogOperationService.page(params);

View File

@ -60,7 +60,7 @@ public class SysMenuController {
@GetMapping("list")
@ApiOperation("列表")
@ApiImplicitParam(name = "type", value = "菜单类型 0菜单 1按钮 null全部", paramType = "query", dataType="int")
@ApiImplicitParam(name = "type", value = "菜单类型 0菜单 1按钮 null全部", paramType = "query", dataTypeClass=Integer.class)
@PreAuthorize("@ex.hasAuthority('sys:menu:list')")
public Result<List<SysMenuDTO>> list(Integer type){
List<SysMenuDTO> list = sysMenuService.getAllMenuList(type);

View File

@ -41,11 +41,11 @@ public class SysParamsController {
@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")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('sys:params:page')")
public Result<PageData<SysParamsDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
@ -105,7 +105,7 @@ public class SysParamsController {
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String")
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataTypeClass=String.class)
@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);

View File

@ -45,11 +45,11 @@ public class SysRoleController {
@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")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = "name", value = "角色名", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('sys:role:page')")
public Result<PageData<SysRoleDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){

View File

@ -53,13 +53,13 @@ public class SysUserController {
@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")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "gender", value = "性别", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "deptId", value = "部门ID", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('sys:user:page')")
public Result<PageData<SysUserDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
@ -153,7 +153,7 @@ public class SysUserController {
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataType="String")
@ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataTypeClass=String.class)
@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);

View File

@ -26,40 +26,40 @@ import java.util.Map;
* @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);
//
@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();
// }
return new Result().error();
}
//
// /**
// * 保存异常日志
@ -84,4 +84,4 @@ import java.util.Map;
// //保存
// sysLogErrorService.save(log);
// }
//}
}

View File

@ -11,6 +11,7 @@ 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.authentication.DisabledException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@ -46,6 +47,9 @@ public class UserDetailsServiceImpl implements UserDetailsService {
if (Objects.isNull(sysUserEntity)) {
throw new UsernameNotFoundException("用户名不存在");
}
if (sysUserEntity.getStatus() == 0) {
throw new DisabledException("该账户已被禁用,请联系管理员");
}
log.info("sysUserEntity的值是"+sysUserEntity.toString());
log.info("sysUserEntity.getSuperAdmin()=="+sysUserEntity.getSuperAdmin());
Set<String> userPermissions = sysMenuService.getUserPermissions(sysUserEntity);

View File

@ -5,6 +5,7 @@ import com.github.kwhat.jnativehook.NativeHookException;
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import java.util.List;
@ -19,6 +20,7 @@ import java.util.stream.Collectors;
*/
@Log4j2
@Component
@Profile("prod")
public class GlobalKeyListenerExample implements NativeKeyListener {
static {
@ -48,14 +50,17 @@ public class GlobalKeyListenerExample implements NativeKeyListener {
return NativeKeyEvent.getKeyText(n);
}).collect(Collectors.toList());
for (String s : collect) {
result = result + s;
}
if (queue.size() == 5) {
log.info("符合标准的扫码是:"+ result.replace("Enter",""));
for (String s : collect) {
result = result + s;
}
}else {
log.info("符合标准的扫码是:"+ result.substring(1).replace("Enter",""));
for (int i = 1; i < collect.size(); i++) {
result = result + collect.get(i);
}
}
log.info("符合标准的扫码是:"+ result.replace("Enter",""));
queue.clear();
}
if (queue.size() == 6){

View File

@ -32,6 +32,27 @@
<artifactId>ym-barcode</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cnbm</groupId>
<artifactId>ym-basic</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
</dependencies>
</project>

View File

@ -2,6 +2,7 @@ package com.cnbm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.oas.annotations.EnableOpenApi;
/**
* @Author weihongyang
@ -9,9 +10,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @Version 1.0
*/
@SpringBootApplication
public class AdminApplication {
@EnableOpenApi
public class YmApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class,args);
SpringApplication.run(YmApplication.class,args);
}
}

View File

@ -0,0 +1,87 @@
package com.cnbm.config;
import com.cnbm.common.constant.Constant;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.Arrays;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
/**
* @Author weihongyang
* @Date 2022/6/21 10:56 AM
* @Version 1.0
*/
@Configuration
@EnableOpenApi
@Profile("dev")
public class SwaggerConfig {
/**
* 创建API应用
* apiInfo() 增加API相关信息
* 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现
* 本例采用指定扫描的包路径来定义指定要建立API的目录
*
* @return
*/
@Bean
public Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("标准接口")
.apiInfo(apiInfo("Spring Boot中使用Swagger2构建RESTful APIs", "1.0"))
.useDefaultResponseMessages(true)
.forCodeGeneration(false)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build()
.securityContexts(Arrays.asList(securityContext()))
// ApiKey的name需与SecurityReference的reference保持一致
.securitySchemes(Arrays.asList(new ApiKey("token", "token", "header")));
}
/**
* 创建该API的基本信息这些基本信息会展现在文档页面中
* 访问地址http://ip:port/swagger-ui.html
*
* @return
*/
private ApiInfo apiInfo(String title, String version) {
return new ApiInfoBuilder()
.title(title)
.description("ym-pass文档")
.termsOfServiceUrl("https://www.baidu.com/")
.version(version)
.build();
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.build();
}
List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope
= new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Lists.newArrayList(
new SecurityReference(Constant.TOKEN_HEADER, authorizationScopes));
}
}

View File

@ -0,0 +1,40 @@
spring:
datasource:
#MySQL
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://mysql.picaiba.com:30307/ym_pass?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
username: root
password: 1qaz@WSX3edc$RFV
# #Oracle
# driver-class-name: oracle.jdbc.OracleDriver
# url: jdbc:oracle:thin:@192.168.10.10:1521:xe
# username: renren_security
# password: 123456
# #SQLServer
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# url: jdbc:sqlserver://localhost:1433;DatabaseName=renren_security
# username: sa
# password: 123456
# #postgresql
# driver-class-name: org.postgresql.Driver
# url: jdbc:postgresql://192.168.10.10:5432/postgres
# username: postgres
# password: 123456
hikari:
pool-name: GrowUpHikariCP
minimum-idle: 1
maximum-pool-size: 10
##多数据源的配置需要引用renren-dynamic-datasource
#dynamic:
# datasource:
# slave1:
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# url: jdbc:sqlserver://123456:1433;DatabaseName=renren_security
# username: sa
# password: 123456
# slave2:
# driver-class-name: org.postgresql.Driver
# url: jdbc:postgresql://123456:5432/renren_security
# username: postgres
# password: 123456

View File

@ -7,14 +7,14 @@ server:
min-spare: 30
port: 8080
servlet:
context-path: /ym-admin
context-path: /ym-pass
session:
cookie:
http-only: true
spring:
application:
name: ym-admin
name: ym-pass
# 环境 dev|test|prod
profiles:
active: dev
@ -31,9 +31,9 @@ spring:
enabled: true
redis:
database: 0
host: 124.221.241.144
port: 6379
password: why123456 # 密码(默认为空)
host: redis.picaiba.com
port: 6380
password: '@WSXcde3' # 密码(默认为空)
timeout: 6000ms # 连接超时时长(毫秒)
jedis:
pool:

View File

@ -48,8 +48,8 @@ public class CodeGenerator {
})
.packageConfig(builder -> {
//设置父包名
builder.parent("com.cnbm")
.moduleName("generator")
builder.parent("com.cnbm.generator")
.moduleName("code")
.service("service")
.serviceImpl("service.impl")
.entity("entity")

View File

@ -24,10 +24,10 @@ public class EnhanceVelocityTemplateEngine extends VelocityTemplateEngine {
customFile.forEach((key, value) -> {
String fileName = "";
if ("DTO".equals(key)) {
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator"+ File.separator + "dto" + File.separator + entityName + "%s" + ".java"), key);
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator/code"+ File.separator + "dto" + File.separator + entityName + "%s" + ".java"), key);
}
if ("Excel".equals(key)) {
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator"+ File.separator + "excel" + File.separator + entityName + "%s" + ".java"), key);
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator/code"+ File.separator + "excel" + File.separator + entityName + "%s" + ".java"), key);
}
this.outputFile(new File(fileName), objectMap, value);
});

View File

@ -43,10 +43,10 @@ public class ${table.controllerName} {
@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 = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:page')")
public Result<PageData<${entity}DTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){