Commit e4ca7afc authored by dqjdda's avatar dqjdda
Browse files

阿里巴巴代码规范

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