mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -46,6 +46,10 @@
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
|
||||
16
src/main/java/cn/lihongjie/coal/annotation/SysLog.java
Normal file
16
src/main/java/cn/lihongjie/coal/annotation/SysLog.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.annotation;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
public @interface SysLog {
|
||||
|
||||
String module() default "";
|
||||
|
||||
String msg() default "";
|
||||
|
||||
|
||||
|
||||
}
|
||||
155
src/main/java/cn/lihongjie/coal/aop/ControllerAop.java
Normal file
155
src/main/java/cn/lihongjie/coal/aop/ControllerAop.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package cn.lihongjie.coal.aop;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.common.RequestUtils;
|
||||
import cn.lihongjie.coal.dto.R;
|
||||
import cn.lihongjie.coal.entity.SysLogEntity;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.service.SysLogService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ControllerAop {
|
||||
|
||||
|
||||
|
||||
@Pointcut("execution (* cn.lihongjie.coal.controller.*.*(..))")
|
||||
public void controllerMethods() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Around("controllerMethods()")
|
||||
public Object call(ProceedingJoinPoint proceedingJoinPoint) {
|
||||
|
||||
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
SysLogEntity sysLogEntity = createSysLog(method, request);
|
||||
try {
|
||||
|
||||
|
||||
return proceedingJoinPoint.proceed();
|
||||
|
||||
} catch (Throwable e) {
|
||||
|
||||
|
||||
|
||||
logException(e, proceedingJoinPoint);
|
||||
|
||||
|
||||
updateSysLog(e, sysLogEntity);
|
||||
|
||||
if (e instanceof BizException) {
|
||||
return R.fail("bizError", e.getMessage());
|
||||
} else if (e instanceof RuntimeException) {
|
||||
|
||||
return R.fail("sysError", "系统异常");
|
||||
} else {
|
||||
|
||||
return R.fail("sysError", "系统异常");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} finally {
|
||||
|
||||
|
||||
saveSysLog(sysLogEntity, System.currentTimeMillis(), start);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void saveSysLog(SysLogEntity sysLogEntity, long end, long start) {
|
||||
if (sysLogEntity != null) {
|
||||
sysLogEntity.setTimeCost((int) (end - start));
|
||||
|
||||
sysLogService.save(sysLogEntity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateSysLog(Throwable e, SysLogEntity sysLogEntity) {
|
||||
if (sysLogEntity != null) {
|
||||
sysLogEntity.setStatus(1);
|
||||
sysLogEntity.setStacktrace(ExceptionUtils.getStackTrace(e));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static SysLogEntity createSysLog(Method method, HttpServletRequest request) {
|
||||
SysLog sysLog = AnnotationUtils.findAnnotation(method, SysLog.class);
|
||||
|
||||
SysLogEntity sysLogEntity = null;
|
||||
if (sysLog != null) {
|
||||
|
||||
|
||||
String module = sysLog.module();
|
||||
String msg = sysLog.msg();
|
||||
|
||||
if (StringUtils.isEmpty(module)) {
|
||||
SysLog classLog = AnnotationUtils.findAnnotation(method.getClass(), SysLog.class);
|
||||
if (classLog != null) {
|
||||
|
||||
module = classLog.module();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sysLogEntity = new SysLogEntity();
|
||||
|
||||
sysLogEntity.setIp(RequestUtils.getIp(request));
|
||||
sysLogEntity.setIpLocation(RequestUtils.getIp(request));
|
||||
sysLogEntity.setUrl(request.getRequestURI());
|
||||
sysLogEntity.setStatus(0);
|
||||
sysLogEntity.setTimeCost(0);
|
||||
sysLogEntity.setUserAgent(RequestUtils.getUa(request));
|
||||
|
||||
}
|
||||
return sysLogEntity;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
SysLogService sysLogService;
|
||||
|
||||
private void logException(Throwable ex, ProceedingJoinPoint proceedingJoinPoint) {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
|
||||
Object[] args = proceedingJoinPoint.getArgs();
|
||||
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
|
||||
|
||||
log.info("接口调用异常: {}\nurl:{} {}\nmethod: {}\nargs: {}",
|
||||
ex.getMessage() == null ? "no message" : ex.getMessage(),
|
||||
request.getMethod(),
|
||||
request.getRequestURL(),
|
||||
method,
|
||||
Arrays.toString(args),
|
||||
|
||||
|
||||
ex);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
16
src/main/java/cn/lihongjie/coal/common/RequestUtils.java
Normal file
16
src/main/java/cn/lihongjie/coal/common/RequestUtils.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class RequestUtils {
|
||||
|
||||
public static String getIp(HttpServletRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getUa(HttpServletRequest request) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
7
src/main/java/cn/lihongjie/coal/config/AopConfig.java
Normal file
7
src/main/java/cn/lihongjie/coal/config/AopConfig.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package cn.lihongjie.coal.config;
|
||||
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
public class AopConfig {
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package cn.lihongjie.coal.config;
|
||||
|
||||
import cn.lihongjie.coal.dto.R;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
|
||||
@ExceptionHandler(BizException.class)
|
||||
public R handleException(BizException ex, HttpServletRequest request, HandlerMethod handlerMethod) {
|
||||
logException(ex, request, handlerMethod);
|
||||
return R.fail("bizError", ex.getMessage());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public R handleException(RuntimeException ex, HttpServletRequest request,HandlerMethod handlerMethod) {
|
||||
logException(ex, request, handlerMethod);
|
||||
return R.fail("sysError", "系统异常");
|
||||
}
|
||||
@ExceptionHandler(Exception.class)
|
||||
public R handleException(Exception ex, HttpServletRequest request,HandlerMethod handlerMethod) {
|
||||
logException(ex, request, handlerMethod);
|
||||
return R.fail("sysError", "系统异常");
|
||||
}
|
||||
|
||||
|
||||
private void logException(Throwable ex, HttpServletRequest request, HandlerMethod handlerMethod) {
|
||||
|
||||
// Arrays.stream(handlerMethod.getMethodParameters()).map(x -> x.getParameterName() + ": ")
|
||||
|
||||
log.info("接口调用异常: {}\nurl:{} {}\nmethod: {}\nrequestBody: {}",
|
||||
ex.getMessage() == null ? "no message" : ex.getMessage(),
|
||||
request.getMethod(),
|
||||
request.getRequestURL(),
|
||||
handlerMethod.toString(),
|
||||
RequestContextHolder.currentRequestAttributes().getAttribute("__request_body",
|
||||
RequestAttributes.SCOPE_REQUEST),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package cn.lihongjie.coal.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class LogRequestBodyAdvice implements RequestBodyAdvice {
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
|
||||
return inputMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
RequestContextHolder.currentRequestAttributes().setAttribute("__request_body", body, RequestAttributes.SCOPE_REQUEST);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
34
src/main/java/cn/lihongjie/coal/config/SecurityConfig.java
Normal file
34
src/main/java/cn/lihongjie/coal/config/SecurityConfig.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package cn.lihongjie.coal.config;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig {
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Bean
|
||||
SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) {
|
||||
|
||||
|
||||
return httpSecurity.authorizeHttpRequests(x -> {
|
||||
|
||||
x.requestMatchers("/**/*").permitAll();
|
||||
|
||||
})
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.build();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.dto.IdRequest;
|
||||
import cn.lihongjie.coal.entity.base.BaseEntity;
|
||||
import cn.lihongjie.coal.service.BaseService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
public abstract class BaseController<Repository extends BaseRepository<Entity>, Service extends BaseService< Entity, Repository>, Entity extends BaseEntity> {
|
||||
|
||||
@Autowired
|
||||
Service service;
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
public Entity create(Entity entity){
|
||||
|
||||
return service.create(entity);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Entity update(Entity entity){
|
||||
|
||||
return service.update(entity);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/deleteAllById")
|
||||
public Object deleteAllById(IdRequest request){
|
||||
|
||||
service.deleteAllById(request);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Object list(CommonQuery request){
|
||||
|
||||
return service.list(request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.DepartmentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,23 +12,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/department")
|
||||
@RestController
|
||||
@SysLog(module = "部门管理")
|
||||
public class DepartmentController {
|
||||
|
||||
@Autowired
|
||||
DepartmentService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public DepartmentDto create(@RequestBody CreateDepartmentDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public DepartmentDto update(@RequestBody UpdateDepartmentDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
|
||||
@@ -1,12 +1,54 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dao.DictionaryRepository;
|
||||
import cn.lihongjie.coal.entity.DictionaryEntity;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.DictionaryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dictionary")
|
||||
public class DictionaryController extends BaseController<DictionaryRepository, DictionaryService, DictionaryEntity> {
|
||||
@SysLog(module = "数据字典管理")
|
||||
public class DictionaryController {
|
||||
|
||||
|
||||
@Autowired
|
||||
DictionaryService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public DictionaryDto create(@RequestBody CreateDictionaryDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public DictionaryDto update(@RequestBody UpdateDictionaryDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<DictionaryDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public DictionaryDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.OrganizationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,23 +12,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/organization")
|
||||
@RestController
|
||||
@SysLog(module = "机构管理")
|
||||
public class OrganizationController {
|
||||
|
||||
@Autowired
|
||||
OrganizationService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public OrganizationDto create(@RequestBody CreateOrganizationDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public OrganizationDto update(@RequestBody UpdateOrganizationDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.PermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,23 +12,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/permission")
|
||||
@RestController
|
||||
@SysLog(module = "权限管理")
|
||||
public class PermissionController {
|
||||
|
||||
@Autowired
|
||||
PermissionService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public PermissionDto create(@RequestBody CreatePermissionDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public PermissionDto update(@RequestBody UpdatePermissionDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.ResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,23 +12,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/resource")
|
||||
@RestController
|
||||
@SysLog(module = "资源管理")
|
||||
public class ResourceController {
|
||||
|
||||
@Autowired
|
||||
ResourceService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public ResourceDto create(@RequestBody CreateResourceDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public ResourceDto update(@RequestBody UpdateResourceDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.RoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,23 +12,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/role")
|
||||
@RestController
|
||||
@SysLog(module = "角色管理")
|
||||
public class RoleController {
|
||||
|
||||
@Autowired
|
||||
RoleService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public RoleDto create(@RequestBody CreateRoleDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public RoleDto update(@RequestBody UpdateRoleDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.SysConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,23 +12,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/sysConfig")
|
||||
@RestController
|
||||
@SysLog(module = "系统参数")
|
||||
public class SysConfigController {
|
||||
|
||||
@Autowired
|
||||
SysConfigService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public SysConfigDto create(@RequestBody CreateSysConfigDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public SysConfigDto update(@RequestBody UpdateSysConfigDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.dto.IdRequest;
|
||||
import cn.lihongjie.coal.dto.ChangeUserPwdDto;
|
||||
@@ -16,23 +17,27 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/user")
|
||||
@RestController
|
||||
@SysLog(module = "用户管理")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
UserService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public UserDto create(@RequestBody CreateUserDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public UserDto update(@RequestBody UpdateUserDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(msg = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
@@ -45,15 +50,12 @@ public class UserController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<UserDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public UserDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.SysLogEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SysLogRepository extends BaseRepository<SysLogEntity> {
|
||||
}
|
||||
22
src/main/java/cn/lihongjie/coal/dto/CreateDictionaryDto.java
Normal file
22
src/main/java/cn/lihongjie/coal/dto/CreateDictionaryDto.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateDictionaryDto extends CommonDto
|
||||
{
|
||||
|
||||
private List<DictionaryItemDto> item;
|
||||
|
||||
@Data
|
||||
public static class DictionaryItemDto extends CommonDto {
|
||||
|
||||
|
||||
|
||||
private List<DictionaryItemDto> children;
|
||||
|
||||
}
|
||||
}
|
||||
33
src/main/java/cn/lihongjie/coal/dto/CreateSysLogDto.java
Normal file
33
src/main/java/cn/lihongjie/coal/dto/CreateSysLogDto.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreateSysLogDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
@Comment("ip")
|
||||
private String ip;
|
||||
@Comment("ip定位")
|
||||
private String ipLocation;
|
||||
|
||||
@Comment("userAgent")
|
||||
private String userAgent;
|
||||
|
||||
|
||||
@Comment("耗时")
|
||||
private Integer timeCost;
|
||||
|
||||
@Comment("URL")
|
||||
private String url;
|
||||
|
||||
|
||||
@Comment("操作状态 0 成功 1 失败")
|
||||
private Integer status;
|
||||
|
||||
@Comment("错误堆栈")
|
||||
private String stacktrace;
|
||||
|
||||
}
|
||||
22
src/main/java/cn/lihongjie/coal/dto/DictionaryDto.java
Normal file
22
src/main/java/cn/lihongjie/coal/dto/DictionaryDto.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DictionaryDto extends CommonDto
|
||||
{
|
||||
|
||||
private List<DictionaryItemDto> item;
|
||||
|
||||
@Data
|
||||
public static class DictionaryItemDto extends CommonDto {
|
||||
|
||||
|
||||
|
||||
private List<DictionaryItemDto> children;
|
||||
|
||||
}
|
||||
}
|
||||
33
src/main/java/cn/lihongjie/coal/dto/SysLogDto.java
Normal file
33
src/main/java/cn/lihongjie/coal/dto/SysLogDto.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class SysLogDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
@Comment("ip")
|
||||
private String ip;
|
||||
@Comment("ip定位")
|
||||
private String ipLocation;
|
||||
|
||||
@Comment("userAgent")
|
||||
private String userAgent;
|
||||
|
||||
|
||||
@Comment("耗时")
|
||||
private Integer timeCost;
|
||||
|
||||
@Comment("URL")
|
||||
private String url;
|
||||
|
||||
|
||||
@Comment("操作状态 0 成功 1 失败")
|
||||
private Integer status;
|
||||
|
||||
@Comment("错误堆栈")
|
||||
private String stacktrace;
|
||||
|
||||
}
|
||||
22
src/main/java/cn/lihongjie/coal/dto/UpdateDictionaryDto.java
Normal file
22
src/main/java/cn/lihongjie/coal/dto/UpdateDictionaryDto.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateDictionaryDto extends CommonDto
|
||||
{
|
||||
|
||||
private List<DictionaryItemDto> item;
|
||||
|
||||
@Data
|
||||
public static class DictionaryItemDto extends CommonDto {
|
||||
|
||||
|
||||
|
||||
private List<DictionaryItemDto> children;
|
||||
|
||||
}
|
||||
}
|
||||
33
src/main/java/cn/lihongjie/coal/dto/UpdateSysLogDto.java
Normal file
33
src/main/java/cn/lihongjie/coal/dto/UpdateSysLogDto.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateSysLogDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
@Comment("ip")
|
||||
private String ip;
|
||||
@Comment("ip定位")
|
||||
private String ipLocation;
|
||||
|
||||
@Comment("userAgent")
|
||||
private String userAgent;
|
||||
|
||||
|
||||
@Comment("耗时")
|
||||
private Integer timeCost;
|
||||
|
||||
@Comment("URL")
|
||||
private String url;
|
||||
|
||||
|
||||
@Comment("操作状态 0 成功 1 失败")
|
||||
private Integer status;
|
||||
|
||||
@Comment("错误堆栈")
|
||||
private String stacktrace;
|
||||
|
||||
}
|
||||
@@ -2,14 +2,13 @@ package cn.lihongjie.coal.entity;
|
||||
|
||||
import cn.lihongjie.coal.entity.base.OrgBaseEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Comment("操作日志")
|
||||
public class OperationLog extends OrgBaseEntity {
|
||||
public class SysLogEntity extends OrgBaseEntity {
|
||||
|
||||
@Comment("ip")
|
||||
private String ip;
|
||||
@@ -27,9 +26,8 @@ public class OperationLog extends OrgBaseEntity {
|
||||
private String url;
|
||||
|
||||
|
||||
@Comment("操作状态")
|
||||
@OneToOne
|
||||
private DictionaryItemEntity status;
|
||||
@Comment("操作状态 0 成功 1 失败")
|
||||
private Integer status;
|
||||
|
||||
@Comment("错误堆栈")
|
||||
private String stacktrace;
|
||||
@@ -1,12 +0,0 @@
|
||||
package cn.lihongjie.coal.log;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface SysLog {
|
||||
|
||||
String msg();
|
||||
}
|
||||
@@ -32,9 +32,9 @@ public interface CommonMapper {
|
||||
|
||||
}
|
||||
|
||||
public default OperationLog createOperat(String id) {
|
||||
public default SysLogEntity createOperat(String id) {
|
||||
|
||||
OperationLog e = new OperationLog();
|
||||
SysLogEntity e = new SysLogEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/DictionaryMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/DictionaryMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateDictionaryDto;
|
||||
import cn.lihongjie.coal.dto.UpdateDictionaryDto;
|
||||
import cn.lihongjie.coal.dto.DictionaryDto;
|
||||
import cn.lihongjie.coal.entity.DictionaryEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface DictionaryMapper {
|
||||
DictionaryDto toDto(DictionaryEntity user);
|
||||
|
||||
DictionaryEntity toEntity(CreateDictionaryDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget DictionaryEntity entity, UpdateDictionaryDto dto);
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/SysLogMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/SysLogMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateSysLogDto;
|
||||
import cn.lihongjie.coal.dto.UpdateSysLogDto;
|
||||
import cn.lihongjie.coal.dto.SysLogDto;
|
||||
import cn.lihongjie.coal.entity.SysLogEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface SysLogMapper {
|
||||
SysLogDto toDto(SysLogEntity user);
|
||||
|
||||
SysLogEntity toEntity(CreateSysLogDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget SysLogEntity entity, UpdateSysLogDto dto);
|
||||
}
|
||||
@@ -1,59 +1,48 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.dto.IdRequest;
|
||||
import cn.lihongjie.coal.entity.base.BaseEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseService<Entity extends BaseEntity, Repository extends BaseRepository<Entity>> {
|
||||
|
||||
@Autowired
|
||||
Repository dao;
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Entity get(String id){
|
||||
|
||||
return dao.get(id);
|
||||
}
|
||||
|
||||
|
||||
public Entity create(Entity entity){
|
||||
|
||||
public void save(Entity entity){
|
||||
|
||||
dao.save(entity);
|
||||
|
||||
return entity;
|
||||
|
||||
}
|
||||
|
||||
public Entity update(Entity entity){
|
||||
|
||||
|
||||
dao.save(entity);
|
||||
|
||||
return entity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void delete(String id) {
|
||||
dao.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
public void deleteAllById(IdRequest idRequest){
|
||||
dao.deleteAllById(idRequest.getIds());
|
||||
public void delete(List<String> id) {
|
||||
dao.deleteAllById(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Page<Entity> list(CommonQuery query){
|
||||
|
||||
Page<Entity> page = dao.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page;
|
||||
|
||||
|
||||
public Page<Entity> search(Specification<Entity> spec, Pageable page){
|
||||
return dao.findAll(spec, page);
|
||||
}
|
||||
public List<Entity> search(Specification<Entity> spec){
|
||||
return dao.findAll(spec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DepartmentService {
|
||||
public class DepartmentService extends BaseService<DepartmentEntity, DepartmentRepository>{
|
||||
|
||||
@Autowired
|
||||
DepartmentRepository repository;
|
||||
|
||||
@@ -1,11 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.DictionaryRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.DictionaryEntity;
|
||||
import cn.lihongjie.coal.mapper.DictionaryMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DictionaryService extends BaseService<DictionaryEntity, DictionaryRepository> {
|
||||
|
||||
@Autowired
|
||||
DictionaryRepository repository;
|
||||
|
||||
@Autowired
|
||||
DictionaryMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public DictionaryDto create(CreateDictionaryDto request) {
|
||||
|
||||
|
||||
DictionaryEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public DictionaryDto update(UpdateDictionaryDto request) {
|
||||
DictionaryEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public DictionaryDto getById(String id) {
|
||||
|
||||
DictionaryEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<DictionaryDto> list(CommonQuery query) {
|
||||
|
||||
Page<DictionaryEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OrganizationService {
|
||||
public class OrganizationService extends BaseService<OrganizationEntity, OrganizationRepository>{
|
||||
|
||||
@Autowired
|
||||
OrganizationRepository repository;
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PermissionService {
|
||||
public class PermissionService extends BaseService<PermissionEntity, PermissionRepository>{
|
||||
|
||||
@Autowired
|
||||
PermissionRepository repository;
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ResourceService {
|
||||
public class ResourceService extends BaseService<ResourceEntity, ResourceRepository>{
|
||||
|
||||
@Autowired
|
||||
ResourceRepository repository;
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RoleService {
|
||||
public class RoleService extends BaseService<RoleEntity, RoleRepository>{
|
||||
|
||||
@Autowired
|
||||
RoleRepository repository;
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysConfigService {
|
||||
public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepository>{
|
||||
|
||||
@Autowired
|
||||
SysConfigRepository repository;
|
||||
|
||||
91
src/main/java/cn/lihongjie/coal/service/SysLogService.java
Normal file
91
src/main/java/cn/lihongjie/coal/service/SysLogService.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.SysLogRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.SysLogEntity;
|
||||
import cn.lihongjie.coal.mapper.SysLogMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysLogService extends BaseService<SysLogEntity, SysLogRepository>{
|
||||
|
||||
@Autowired
|
||||
SysLogRepository repository;
|
||||
|
||||
@Autowired
|
||||
SysLogMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public SysLogDto create(CreateSysLogDto request) {
|
||||
|
||||
|
||||
SysLogEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SysLogDto update(UpdateSysLogDto request) {
|
||||
SysLogEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SysLogDto getById(String id) {
|
||||
|
||||
SysLogEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void save(SysLogEntity entity) {
|
||||
|
||||
super.save(entity);
|
||||
}
|
||||
|
||||
public Page<SysLogDto> list(CommonQuery query) {
|
||||
|
||||
Page<SysLogEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.UserRepository;
|
||||
import cn.lihongjie.coal.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.dto.IdRequest;
|
||||
import cn.lihongjie.coal.dto.ChangeUserPwdDto;
|
||||
import cn.lihongjie.coal.dto.CreateUserDto;
|
||||
import cn.lihongjie.coal.dto.UpdateUserDto;
|
||||
import cn.lihongjie.coal.dto.UserDto;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.UserEntity;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.mapper.UserMapper;
|
||||
@@ -23,7 +18,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserService {
|
||||
public class UserService extends BaseService<UserEntity, UserRepository>{
|
||||
|
||||
@Autowired
|
||||
UserRepository repository;
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -84,10 +85,7 @@ public class UserSessionService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Optional<UserSessionEntity> getById(String sessionId) {
|
||||
return repository.findById(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user