diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java index 55e40e5..5999022 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java +++ b/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java @@ -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> 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; + } + } diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java index 3c66bed..d6fb33b 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java +++ b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java @@ -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()); + } } diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java index 3f799cd..982d63d 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java @@ -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> page(@ApiIgnore @RequestParam Map params){ diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java index 222fcff..0a547ea 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java @@ -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> page(@ApiIgnore @RequestParam Map params){ diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java index 6aef1ec..21c7e7e 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java @@ -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> page(@ApiIgnore @RequestParam Map params){ PageData page = sysLogErrorService.page(params); diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java index 6034d18..f571fee 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java @@ -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> page(@ApiIgnore @RequestParam Map params){ PageData page = sysLogOperationService.page(params); diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java index dcea161..61f88b3 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java @@ -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(Integer type){ List list = sysMenuService.getAllMenuList(type); diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java index cfa9adb..68af592 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java @@ -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> page(@ApiIgnore @RequestParam Map 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 params, HttpServletResponse response) throws Exception { List list = sysParamsService.list(params); diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java index 5e87715..1ac3763 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java @@ -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> page(@ApiIgnore @RequestParam Map params){ diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java index 8bf9bc1..7e93314 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java @@ -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> page(@ApiIgnore @RequestParam Map 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 params, HttpServletResponse response) throws Exception { List list = sysUserService.list(params); diff --git a/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java b/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java index 3c2b5d8..9d5f48b 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java +++ b/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java @@ -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); // } -//} +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java index a71bb7c..dcee45d 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java @@ -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 userPermissions = sysMenuService.getUserPermissions(sysUserEntity); diff --git a/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java b/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java index 1bc1d10..e031e4b 100644 --- a/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java +++ b/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java @@ -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){ diff --git a/ym-gateway/pom.xml b/ym-gateway/pom.xml index e7e1a31..9a4f017 100644 --- a/ym-gateway/pom.xml +++ b/ym-gateway/pom.xml @@ -32,6 +32,27 @@ ym-barcode 1.0-SNAPSHOT + + com.cnbm + ym-basic + 1.0-SNAPSHOT + + + io.springfox + springfox-boot-starter + 3.0.0 + + + io.swagger + swagger-models + + + + + io.swagger + swagger-models + 1.5.21 + \ No newline at end of file diff --git a/ym-gateway/src/main/java/com/cnbm/AdminApplication.java b/ym-gateway/src/main/java/com/cnbm/YmApplication.java similarity index 63% rename from ym-gateway/src/main/java/com/cnbm/AdminApplication.java rename to ym-gateway/src/main/java/com/cnbm/YmApplication.java index afa4a80..120e277 100644 --- a/ym-gateway/src/main/java/com/cnbm/AdminApplication.java +++ b/ym-gateway/src/main/java/com/cnbm/YmApplication.java @@ -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); } } diff --git a/ym-gateway/src/main/java/com/cnbm/config/SwaggerConfig.java b/ym-gateway/src/main/java/com/cnbm/config/SwaggerConfig.java new file mode 100644 index 0000000..5ddb652 --- /dev/null +++ b/ym-gateway/src/main/java/com/cnbm/config/SwaggerConfig.java @@ -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 defaultAuth() { + AuthorizationScope authorizationScope + = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + return Lists.newArrayList( + new SecurityReference(Constant.TOKEN_HEADER, authorizationScopes)); + } + +} diff --git a/ym-gateway/src/main/resources/application-prod.yml b/ym-gateway/src/main/resources/application-prod.yml new file mode 100644 index 0000000..b443abc --- /dev/null +++ b/ym-gateway/src/main/resources/application-prod.yml @@ -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 \ No newline at end of file diff --git a/ym-gateway/src/main/resources/application.yml b/ym-gateway/src/main/resources/application.yml index 84fb44c..7fd704b 100644 --- a/ym-gateway/src/main/resources/application.yml +++ b/ym-gateway/src/main/resources/application.yml @@ -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: diff --git a/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java b/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java index 32f792d..4f80800 100644 --- a/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java +++ b/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java @@ -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") diff --git a/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java b/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java index 5dc7229..7d79c0f 100644 --- a/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java +++ b/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java @@ -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); }); diff --git a/ym-generator/src/main/resources/templates/controller.java.vm b/ym-generator/src/main/resources/templates/controller.java.vm index f4e622c..fc2f2b1 100644 --- a/ym-generator/src/main/resources/templates/controller.java.vm +++ b/ym-generator/src/main/resources/templates/controller.java.vm @@ -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> page(@ApiIgnore @RequestParam Map params){