Commit e4ca7afc authored by dqjdda's avatar dqjdda
Browse files

阿里巴巴代码规范

parent 6d941c09
...@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
* @author Zhang houying * @author Zhang houying
* @date 2019-11-03 * @date 2019-11-03
*/ */
@Api(tags = "Server管理") @Api(tags = "服务监控管理")
@RestController @RestController
@RequestMapping("/api/server") @RequestMapping("/api/server")
public class ServerController { public class ServerController {
...@@ -29,24 +29,24 @@ public class ServerController { ...@@ -29,24 +29,24 @@ public class ServerController {
} }
@GetMapping @GetMapping
@Log("查询Server") @Log("查询服务监控")
@ApiOperation("查询Server") @ApiOperation("查询服务监控")
@PreAuthorize("@el.check('server:list')") @PreAuthorize("@el.check('server:list')")
public ResponseEntity getServers(ServerQueryCriteria criteria, Pageable pageable){ public ResponseEntity getServers(ServerQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(serverService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(serverService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@PostMapping @PostMapping
@Log("新增Server") @Log("新增服务监控")
@ApiOperation("新增Server") @ApiOperation("新增服务监控")
@PreAuthorize("@el.check('server:add')") @PreAuthorize("@el.check('server:add')")
public ResponseEntity create(@Validated @RequestBody Server resources){ public ResponseEntity create(@Validated @RequestBody Server resources){
return new ResponseEntity<>(serverService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(serverService.create(resources),HttpStatus.CREATED);
} }
@PutMapping @PutMapping
@Log("修改Server") @Log("修改服务监控")
@ApiOperation("修改Server") @ApiOperation("修改服务监控")
@PreAuthorize("@el.check('server:edit')") @PreAuthorize("@el.check('server:edit')")
public ResponseEntity update(@Validated @RequestBody Server resources){ public ResponseEntity update(@Validated @RequestBody Server resources){
serverService.update(resources); serverService.update(resources);
...@@ -54,8 +54,8 @@ public class ServerController { ...@@ -54,8 +54,8 @@ public class ServerController {
} }
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
@Log("删除Server") @Log("删除服务监控")
@ApiOperation("删除Server") @ApiOperation("删除服务监控")
@PreAuthorize("@el.check('server:del')") @PreAuthorize("@el.check('server:del')")
public ResponseEntity delete(@PathVariable Integer id){ public ResponseEntity delete(@PathVariable Integer id){
serverService.delete(id); serverService.delete(id);
......
...@@ -16,8 +16,9 @@ import java.util.List; ...@@ -16,8 +16,9 @@ import java.util.List;
public interface RedisService { public interface RedisService {
/** /**
* findById * 根据KEY查询
* @param key 键 * @param key 键
* @param pageable 分页参数
* @return / * @return /
*/ */
Page findByKey(String key, Pageable pageable); Page findByKey(String key, Pageable pageable);
...@@ -55,9 +56,10 @@ public interface RedisService { ...@@ -55,9 +56,10 @@ public interface RedisService {
void deleteAll(); void deleteAll();
/** /**
* * 导出数据
* @param redisVos / * @param redisVos /
* @param response / * @param response /
* @throws IOException /
*/ */
void download(List<RedisVo> redisVos, HttpServletResponse response) throws IOException; void download(List<RedisVo> redisVos, HttpServletResponse response) throws IOException;
} }
...@@ -36,10 +36,23 @@ public interface ServerService { ...@@ -36,10 +36,23 @@ public interface ServerService {
*/ */
ServerDTO findById(Integer id); ServerDTO findById(Integer id);
/**
* 创建服务监控
* @param resources /
* @return /
*/
ServerDTO create(Server resources); ServerDTO create(Server resources);
/**
* 编辑服务监控
* @param resources /
*/
void update(Server resources); void update(Server resources);
/**
* 删除
* @param id /
*/
void delete(Integer id); void delete(Integer id);
} }
...@@ -11,45 +11,39 @@ import java.io.Serializable; ...@@ -11,45 +11,39 @@ import java.io.Serializable;
@Data @Data
public class ServerDTO implements Serializable { public class ServerDTO implements Serializable {
// 编号
private Integer id; private Integer id;
// 名称
private String name; private String name;
// IP地址
private String address; private String address;
// 访问端口
private Integer port; private Integer port;
// 状态
private String state; private String state;
// CPU使用率 /** CPU使用率 */
private Float cpuRate; private Float cpuRate;
// CPU内核数 /** CPU内核数 */
private Integer cpuCore; private Integer cpuCore;
// 内存总数 /** 内存总数 */
private Float memTotal; private Float memTotal;
// 内存使用量 /** 内存使用量 */
private Float memUsed; private Float memUsed;
// 磁盘总量 /** 磁盘总量 */
private Float diskTotal; private Float diskTotal;
// 磁盘使用量 /** 磁盘使用量 */
private Float diskUsed; private Float diskUsed;
// 交换区总量 /** 交换区总量 */
private Float swapTotal; private Float swapTotal;
// 交换区使用量 /** 交换区使用量 */
private Float swapUsed; private Float swapUsed;
// 排序
private Integer sort; private Integer sort;
} }
...@@ -10,7 +10,6 @@ import me.zhengjie.annotation.Query; ...@@ -10,7 +10,6 @@ import me.zhengjie.annotation.Query;
@Data @Data
public class ServerQueryCriteria{ public class ServerQueryCriteria{
// 模糊
@Query(blurry = "name,address") @Query(blurry = "name,address")
private String blurry; private String blurry;
} }
\ No newline at end of file
...@@ -16,7 +16,6 @@ import org.springframework.data.domain.Pageable; ...@@ -16,7 +16,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
......
...@@ -6,7 +6,6 @@ import me.zhengjie.modules.monitor.repository.VisitsRepository; ...@@ -6,7 +6,6 @@ import me.zhengjie.modules.monitor.repository.VisitsRepository;
import me.zhengjie.modules.monitor.service.VisitsService; import me.zhengjie.modules.monitor.service.VisitsService;
import me.zhengjie.repository.LogRepository; import me.zhengjie.repository.LogRepository;
import me.zhengjie.utils.StringUtils; import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -61,7 +60,7 @@ public class VisitsServiceImpl implements VisitsService { ...@@ -61,7 +60,7 @@ public class VisitsServiceImpl implements VisitsService {
@Override @Override
public Object get() { public Object get() {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>(4);
LocalDate localDate = LocalDate.now(); LocalDate localDate = LocalDate.now();
Visits visits = visitsRepository.findByDate(localDate.toString()); Visits visits = visitsRepository.findByDate(localDate.toString());
List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString()); List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString());
...@@ -80,7 +79,7 @@ public class VisitsServiceImpl implements VisitsService { ...@@ -80,7 +79,7 @@ public class VisitsServiceImpl implements VisitsService {
@Override @Override
public Object getChartData() { public Object getChartData() {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>(3);
LocalDate localDate = LocalDate.now(); LocalDate localDate = LocalDate.now();
List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString()); List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString());
map.put("weekDays",list.stream().map(Visits::getWeekDay).collect(Collectors.toList())); map.put("weekDays",list.stream().map(Visits::getWeekDay).collect(Collectors.toList()));
......
...@@ -26,34 +26,34 @@ public class QuartzJob implements Serializable { ...@@ -26,34 +26,34 @@ public class QuartzJob implements Serializable {
@NotNull(groups = {Update.class}) @NotNull(groups = {Update.class})
private Long id; private Long id;
// 定时器名称 /** 定时器名称 */
@Column(name = "job_name") @Column(name = "job_name")
private String jobName; private String jobName;
// Bean名称 /** Bean名称 */
@Column(name = "bean_name") @Column(name = "bean_name")
@NotBlank @NotBlank
private String beanName; private String beanName;
// 方法名称 /** 方法名称 */
@Column(name = "method_name") @Column(name = "method_name")
@NotBlank @NotBlank
private String methodName; private String methodName;
// 参数 /** 参数 */
@Column(name = "params") @Column(name = "params")
private String params; private String params;
// cron表达式 /** cron表达式 */
@Column(name = "cron_expression") @Column(name = "cron_expression")
@NotBlank @NotBlank
private String cronExpression; private String cronExpression;
// 状态 /** 状态 */
@Column(name = "is_pause") @Column(name = "is_pause")
private Boolean isPause = false; private Boolean isPause = false;
// 备注 /** 备注 */
@Column(name = "remark") @Column(name = "remark")
@NotBlank @NotBlank
private String remark; private String remark;
......
...@@ -20,38 +20,38 @@ public class QuartzLog implements Serializable { ...@@ -20,38 +20,38 @@ public class QuartzLog implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
// 任务名称 /** 任务名称 */
@Column(name = "job_name") @Column(name = "job_name")
private String jobName; private String jobName;
// Bean名称 /** Bean名称 */
@Column(name = "baen_name") @Column(name = "baen_name")
private String beanName; private String beanName;
// 方法名称 /** 方法名称 */
@Column(name = "method_name") @Column(name = "method_name")
private String methodName; private String methodName;
// 参数 /** 参数 */
@Column(name = "params") @Column(name = "params")
private String params; private String params;
// cron表达式 /** cron表达式 */
@Column(name = "cron_expression") @Column(name = "cron_expression")
private String cronExpression; private String cronExpression;
// 状态 /** 状态 */
@Column(name = "is_success") @Column(name = "is_success")
private Boolean isSuccess; private Boolean isSuccess;
// 异常详细 /** 异常详细 */
@Column(name = "exception_detail",columnDefinition = "text") @Column(name = "exception_detail",columnDefinition = "text")
private String exceptionDetail; private String exceptionDetail;
// 耗时(毫秒) /** 耗时(毫秒) */
private Long time; private Long time;
// 创建日期 /** 创建日期 */
@CreationTimestamp @CreationTimestamp
@Column(name = "create_time") @Column(name = "create_time")
private Timestamp createTime; private Timestamp createTime;
......
...@@ -15,20 +15,60 @@ import java.util.List; ...@@ -15,20 +15,60 @@ import java.util.List;
*/ */
public interface QuartzJobService { public interface QuartzJobService {
/**
* 分页查询
* @param criteria 条件
* @param pageable 分页参数
* @return /
*/
Object queryAll(JobQueryCriteria criteria, Pageable pageable); Object queryAll(JobQueryCriteria criteria, Pageable pageable);
/**
* 查询全部
* @param criteria 条件
* @return /
*/
List<QuartzJob> queryAll(JobQueryCriteria criteria); List<QuartzJob> queryAll(JobQueryCriteria criteria);
/**
* 分页查询日志
* @param criteria 条件
* @param pageable 分页参数
* @return /
*/
Object queryAllLog(JobQueryCriteria criteria, Pageable pageable); Object queryAllLog(JobQueryCriteria criteria, Pageable pageable);
/**
* 查询全部
* @param criteria 条件
* @return /
*/
List<QuartzLog> queryAllLog(JobQueryCriteria criteria); List<QuartzLog> queryAllLog(JobQueryCriteria criteria);
/**
* 创建
* @param resources /
* @return /
*/
QuartzJob create(QuartzJob resources); QuartzJob create(QuartzJob resources);
/**
* 编辑
* @param resources /
*/
void update(QuartzJob resources); void update(QuartzJob resources);
/**
* 删除任务
* @param quartzJob /
*/
void delete(QuartzJob quartzJob); void delete(QuartzJob quartzJob);
/**
* 根据ID查询
* @param id ID
* @return /
*/
QuartzJob findById(Long id); QuartzJob findById(Long id);
/** /**
...@@ -43,7 +83,19 @@ public interface QuartzJobService { ...@@ -43,7 +83,19 @@ public interface QuartzJobService {
*/ */
void execution(QuartzJob quartzJob); void execution(QuartzJob quartzJob);
/**
* 导出定时任务
* @param queryAll 待导出的数据
* @param response /
* @throws IOException /
*/
void download(List<QuartzJob> queryAll, HttpServletResponse response) throws IOException; void download(List<QuartzJob> queryAll, HttpServletResponse response) throws IOException;
/**
* 导出定时任务日志
* @param queryAllLog 待导出的数据
* @param response /
* @throws IOException /
*/
void downloadLog(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException; void downloadLog(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException;
} }
...@@ -125,7 +125,7 @@ public class QuartzJobServiceImpl implements QuartzJobService { ...@@ -125,7 +125,7 @@ public class QuartzJobServiceImpl implements QuartzJobService {
if(quartzJob.getId().equals(1L)){ if(quartzJob.getId().equals(1L)){
throw new BadRequestException("该任务不可操作"); throw new BadRequestException("该任务不可操作");
} }
quartzManage.runAJobNow(quartzJob); quartzManage.runJobNow(quartzJob);
} }
@Override @Override
......
...@@ -25,8 +25,8 @@ public class ExecutionJob extends QuartzJobBean { ...@@ -25,8 +25,8 @@ public class ExecutionJob extends QuartzJobBean {
private Logger logger = LoggerFactory.getLogger(this.getClass()); private Logger logger = LoggerFactory.getLogger(this.getClass());
// 该处仅供参考 /** 该处仅供参考 */
private final static ThreadPoolExecutor executor = ThreadPoolExecutorUtil.getPoll(); private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -48,7 +48,7 @@ public class ExecutionJob extends QuartzJobBean { ...@@ -48,7 +48,7 @@ public class ExecutionJob extends QuartzJobBean {
logger.info("任务准备执行,任务名称:{}", quartzJob.getJobName()); logger.info("任务准备执行,任务名称:{}", quartzJob.getJobName());
QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(), QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(),
quartzJob.getParams()); quartzJob.getParams());
Future<?> future = executor.submit(task); Future<?> future = EXECUTOR.submit(task);
future.get(); future.get();
long times = System.currentTimeMillis() - startTime; long times = System.currentTimeMillis() - startTime;
log.setTime(times); log.setTime(times);
......
...@@ -109,8 +109,9 @@ public class QuartzManage { ...@@ -109,8 +109,9 @@ public class QuartzManage {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务 // 如果不存在则创建一个定时任务
if(trigger == null) if(trigger == null) {
addJob(quartzJob); addJob(quartzJob);
}
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
scheduler.resumeJob(jobKey); scheduler.resumeJob(jobKey);
} catch (Exception e){ } catch (Exception e){
...@@ -123,13 +124,14 @@ public class QuartzManage { ...@@ -123,13 +124,14 @@ public class QuartzManage {
* 立即执行job * 立即执行job
* @param quartzJob / * @param quartzJob /
*/ */
public void runAJobNow(QuartzJob quartzJob){ public void runJobNow(QuartzJob quartzJob){
try { try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务 // 如果不存在则创建一个定时任务
if(trigger == null) if(trigger == null) {
addJob(quartzJob); addJob(quartzJob);
}
JobDataMap dataMap = new JobDataMap(); JobDataMap dataMap = new JobDataMap();
dataMap.put(QuartzJob.JOB_KEY, quartzJob); dataMap.put(QuartzJob.JOB_KEY, quartzJob);
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
......
...@@ -3,7 +3,7 @@ package me.zhengjie.modules.security.config; ...@@ -3,7 +3,7 @@ package me.zhengjie.modules.security.config;
import me.zhengjie.annotation.AnonymousAccess; import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.security.security.JwtAuthenticationEntryPoint; import me.zhengjie.modules.security.security.JwtAuthenticationEntryPoint;
import me.zhengjie.modules.security.security.JwtAuthorizationTokenFilter; import me.zhengjie.modules.security.security.JwtAuthorizationTokenFilter;
import me.zhengjie.modules.security.service.JwtUserDetailsService; import me.zhengjie.modules.security.service.JwtUserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
...@@ -25,11 +25,13 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic ...@@ -25,11 +25,13 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/**
* @author Zheng Jie
*/
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true)
...@@ -37,17 +39,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -37,17 +39,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final JwtAuthenticationEntryPoint unauthorizedHandler; private final JwtAuthenticationEntryPoint unauthorizedHandler;
private final JwtUserDetailsService jwtUserDetailsService; private final JwtUserDetailsServiceImpl jwtUserDetailsService;
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
// 自定义基于JWT的安全过滤器 /** 自定义基于JWT的安全过滤器 */
private final JwtAuthorizationTokenFilter authenticationTokenFilter; private final JwtAuthorizationTokenFilter authenticationTokenFilter;
@Value("${jwt.header}") @Value("${jwt.header}")
private String tokenHeader; private String tokenHeader;
public SecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler, JwtUserDetailsService jwtUserDetailsService, JwtAuthorizationTokenFilter authenticationTokenFilter, ApplicationContext applicationContext) { public SecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler, JwtUserDetailsServiceImpl jwtUserDetailsService, JwtAuthorizationTokenFilter authenticationTokenFilter, ApplicationContext applicationContext) {
this.unauthorizedHandler = unauthorizedHandler; this.unauthorizedHandler = unauthorizedHandler;
this.jwtUserDetailsService = jwtUserDetailsService; this.jwtUserDetailsService = jwtUserDetailsService;
this.authenticationTokenFilter = authenticationTokenFilter; this.authenticationTokenFilter = authenticationTokenFilter;
......
...@@ -50,7 +50,7 @@ public class AuthenticationController { ...@@ -50,7 +50,7 @@ public class AuthenticationController {
private final OnlineUserService onlineUserService; private final OnlineUserService onlineUserService;
public AuthenticationController(JwtTokenUtil jwtTokenUtil, RedisService redisService, @Qualifier("jwtUserDetailsService") UserDetailsService userDetailsService, OnlineUserService onlineUserService) { public AuthenticationController(JwtTokenUtil jwtTokenUtil, RedisService redisService, @Qualifier("jwtUserDetailsServiceImpl") UserDetailsService userDetailsService, OnlineUserService onlineUserService) {
this.jwtTokenUtil = jwtTokenUtil; this.jwtTokenUtil = jwtTokenUtil;
this.redisService = redisService; this.redisService = redisService;
this.userDetailsService = userDetailsService; this.userDetailsService = userDetailsService;
......
...@@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.*; ...@@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/**
* @author Zheng Jie
*/
@RestController @RestController
@RequestMapping("/auth/online") @RequestMapping("/auth/online")
@Api(tags = "系统:在线用户管理") @Api(tags = "系统:在线用户管理")
......
...@@ -9,6 +9,9 @@ import javax.servlet.http.HttpServletResponse; ...@@ -9,6 +9,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
/**
* @author Zheng Jie
*/
@Component @Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable { public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {
......
...@@ -19,6 +19,9 @@ import javax.servlet.http.HttpServletRequest; ...@@ -19,6 +19,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/**
* @author Zheng Jie
*/
@Slf4j @Slf4j
@Component @Component
public class JwtAuthorizationTokenFilter extends OncePerRequestFilter { public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
...@@ -31,7 +34,7 @@ public class JwtAuthorizationTokenFilter extends OncePerRequestFilter { ...@@ -31,7 +34,7 @@ public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
private final JwtTokenUtil jwtTokenUtil; private final JwtTokenUtil jwtTokenUtil;
private final RedisTemplate redisTemplate; private final RedisTemplate redisTemplate;
public JwtAuthorizationTokenFilter(@Qualifier("jwtUserDetailsService") UserDetailsService userDetailsService, JwtTokenUtil jwtTokenUtil, RedisTemplate redisTemplate) { public JwtAuthorizationTokenFilter(@Qualifier("jwtUserDetailsServiceImpl") UserDetailsService userDetailsService, JwtTokenUtil jwtTokenUtil, RedisTemplate redisTemplate) {
this.userDetailsService = userDetailsService; this.userDetailsService = userDetailsService;
this.jwtTokenUtil = jwtTokenUtil; this.jwtTokenUtil = jwtTokenUtil;
this.redisTemplate = redisTemplate; this.redisTemplate = redisTemplate;
......
...@@ -3,7 +3,7 @@ package me.zhengjie.modules.security.service; ...@@ -3,7 +3,7 @@ package me.zhengjie.modules.security.service;
import me.zhengjie.modules.system.domain.Menu; import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.repository.RoleRepository; import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.system.service.dto.UserDTO; import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.utils.StringUtils; import me.zhengjie.utils.StringUtils;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
...@@ -11,17 +11,19 @@ import org.springframework.security.core.GrantedAuthority; ...@@ -11,17 +11,19 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* @author Zheng Jie
*/
@Service @Service
@CacheConfig(cacheNames = "role") @CacheConfig(cacheNames = "role")
public class JwtPermissionService { public class JwtPermissionServiceImpl {
private final RoleRepository roleRepository; private final RoleRepository roleRepository;
public JwtPermissionService(RoleRepository roleRepository) { public JwtPermissionServiceImpl(RoleRepository roleRepository) {
this.roleRepository = roleRepository; this.roleRepository = roleRepository;
} }
...@@ -31,7 +33,7 @@ public class JwtPermissionService { ...@@ -31,7 +33,7 @@ public class JwtPermissionService {
* @return Collection * @return Collection
*/ */
@Cacheable(key = "'loadPermissionByUser:' + #p0.username") @Cacheable(key = "'loadPermissionByUser:' + #p0.username")
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDTO user) { public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDto user) {
System.out.println("--------------------loadPermissionByUser:" + user.getUsername() + "---------------------"); System.out.println("--------------------loadPermissionByUser:" + user.getUsername() + "---------------------");
......
...@@ -17,13 +17,13 @@ import java.util.Optional; ...@@ -17,13 +17,13 @@ import java.util.Optional;
*/ */
@Service @Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class JwtUserDetailsService implements UserDetailsService { public class JwtUserDetailsServiceImpl implements UserDetailsService {
private final UserService userService; private final UserService userService;
private final JwtPermissionService permissionService; private final JwtPermissionServiceImpl permissionService;
public JwtUserDetailsService(UserService userService, JwtPermissionService permissionService) { public JwtUserDetailsServiceImpl(UserService userService, JwtPermissionServiceImpl permissionService) {
this.userService = userService; this.userService = userService;
this.permissionService = permissionService; this.permissionService = permissionService;
} }
...@@ -31,7 +31,7 @@ public class JwtUserDetailsService implements UserDetailsService { ...@@ -31,7 +31,7 @@ public class JwtUserDetailsService implements UserDetailsService {
@Override @Override
public UserDetails loadUserByUsername(String username){ public UserDetails loadUserByUsername(String username){
UserDTO user = userService.findByName(username); UserDto user = userService.findByName(username);
if (user == null) { if (user == null) {
throw new BadRequestException("账号不存在"); throw new BadRequestException("账号不存在");
} else { } else {
...@@ -39,7 +39,7 @@ public class JwtUserDetailsService implements UserDetailsService { ...@@ -39,7 +39,7 @@ public class JwtUserDetailsService implements UserDetailsService {
} }
} }
public UserDetails createJwtUser(UserDTO user) { public UserDetails createJwtUser(UserDto user) {
return new JwtUser( return new JwtUser(
user.getId(), user.getId(),
user.getUsername(), user.getUsername(),
...@@ -47,8 +47,8 @@ public class JwtUserDetailsService implements UserDetailsService { ...@@ -47,8 +47,8 @@ public class JwtUserDetailsService implements UserDetailsService {
user.getAvatar(), user.getAvatar(),
user.getEmail(), user.getEmail(),
user.getPhone(), user.getPhone(),
Optional.ofNullable(user.getDept()).map(DeptSmallDTO::getName).orElse(null), Optional.ofNullable(user.getDept()).map(DeptSmallDto::getName).orElse(null),
Optional.ofNullable(user.getJob()).map(JobSmallDTO::getName).orElse(null), Optional.ofNullable(user.getJob()).map(JobSmallDto::getName).orElse(null),
permissionService.mapToGrantedAuthorities(user), permissionService.mapToGrantedAuthorities(user),
user.getEnabled(), user.getEnabled(),
user.getCreateTime(), user.getCreateTime(),
......
Supports Markdown
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