feat(修改-记录日志): 为请求加上日志
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
7b060d309c
commit
e62c75b188
|
@ -10,7 +10,6 @@ import java.lang.annotation.Target;
|
|||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log { // 自定义操作日志记录注解
|
||||
|
||||
String title(); // 模块名称
|
||||
|
||||
OperatorType operatorType() default OperatorType.MANAGE; // 操作人类别
|
||||
|
@ -20,5 +19,4 @@ public @interface Log { // 自定义操作日志记录注解
|
|||
boolean isSaveRequestData() default true; // 是否保存请求的参数
|
||||
|
||||
boolean isSaveResponseData() default true; // 是否保存响应的参数
|
||||
|
||||
}
|
|
@ -21,12 +21,14 @@ public class LogAspect {
|
|||
|
||||
@Around(value = "@annotation(sysLog)")
|
||||
public Object doAroundAdvice(ProceedingJoinPoint joinPoint, Log sysLog) {
|
||||
String title = sysLog.title();
|
||||
log.info("请求了===>:{}", title);
|
||||
|
||||
// 构建前置参数
|
||||
SysOperLog sysOperLog = new SysOperLog();
|
||||
|
||||
LogUtil.beforeHandleLog(sysLog, joinPoint, sysOperLog);
|
||||
|
||||
Object proceed = null;
|
||||
|
||||
try {
|
||||
proceed = joinPoint.proceed();
|
||||
// 执行业务方法
|
||||
|
|
|
@ -17,9 +17,7 @@ import java.util.Arrays;
|
|||
public class LogUtil {
|
||||
|
||||
// 操作执行之后调用
|
||||
public static void afterHandleLog(Log sysLog, Object proceed,
|
||||
SysOperLog sysOperLog, int status,
|
||||
String errorMsg) {
|
||||
public static void afterHandleLog(Log sysLog, Object proceed, SysOperLog sysOperLog, int status, String errorMsg) {
|
||||
if (sysLog.isSaveResponseData()) {
|
||||
sysOperLog.setJsonResult(JSON.toJSONString(proceed));
|
||||
}
|
||||
|
@ -28,9 +26,7 @@ public class LogUtil {
|
|||
}
|
||||
|
||||
// 操作执行之前调用
|
||||
public static void beforeHandleLog(Log sysLog,
|
||||
ProceedingJoinPoint joinPoint,
|
||||
SysOperLog sysOperLog) {
|
||||
public static void beforeHandleLog(Log sysLog, ProceedingJoinPoint joinPoint, SysOperLog sysOperLog) {
|
||||
|
||||
// 设置操作模块名称
|
||||
sysOperLog.setTitle(sysLog.title());
|
||||
|
@ -40,15 +36,12 @@ public class LogUtil {
|
|||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = methodSignature.getMethod();
|
||||
sysOperLog.setMethod(method.getDeclaringClass().getName());
|
||||
|
||||
// 获取请求相关参数
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes)
|
||||
RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = requestAttributes.getRequest();
|
||||
sysOperLog.setRequestMethod(request.getMethod());
|
||||
sysOperLog.setOperUrl(request.getRequestURI());
|
||||
sysOperLog.setOperIp(request.getRemoteAddr());
|
||||
|
||||
// 设置请求参数
|
||||
if (sysLog.isSaveRequestData()) {
|
||||
String requestMethod = sysOperLog.getRequestMethod();
|
||||
|
|
|
@ -11,15 +11,14 @@ import org.springframework.context.annotation.Configuration;
|
|||
public class Knife4jConfig {
|
||||
@Bean
|
||||
public GroupedOpenApi adminApi() {
|
||||
return GroupedOpenApi.builder() // 分组名称
|
||||
.group("admin请求接口").pathsToMatch("/admin/**") // 接口请求路径规则
|
||||
.build();
|
||||
// 分组名称
|
||||
return GroupedOpenApi.builder().group("admin请求接口").pathsToMatch("/admin/**").build();// 接口请求路径规则
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
// 设定作者
|
||||
return new OpenAPI().info(new Info().title("尚品甑选API接口文档")
|
||||
.version("1.0").description("尚品甑选API接口文档")
|
||||
.contact(new Contact().name("bunny"))); // 设定作者
|
||||
.version("1.0").description("尚品甑选API接口文档").contact(new Contact().name("bunny")));
|
||||
}
|
||||
}
|
|
@ -36,6 +36,8 @@ public class RedisConfiguration {
|
|||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory connectionFactory) {
|
||||
log.info("RedisConfiguration===>使用StringRedisSerializer序列化为字符串");
|
||||
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(connectionFactory);
|
||||
// 设置key序列化为string
|
||||
|
@ -54,6 +56,8 @@ public class RedisConfiguration {
|
|||
@Bean
|
||||
@SuppressWarnings("all")
|
||||
public CacheManager cacheManager(RedisConnectionFactory factory) {
|
||||
log.info("RedisConfiguration===>解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题");
|
||||
|
||||
StringRedisSerializer redisSerializer = new StringRedisSerializer();
|
||||
// json序列化
|
||||
Jackson2JsonRedisSerializer<Object> serializer = jsonRedisSerializer();
|
||||
|
@ -72,6 +76,8 @@ public class RedisConfiguration {
|
|||
* 指定的日期模式
|
||||
*/
|
||||
public Jackson2JsonRedisSerializer<Object> jsonRedisSerializer() {
|
||||
log.info("RedisConfiguration===>指定的日期模式");
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// 设置ObjectMapper访问权限
|
||||
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
|||
public class ResourceConfiguration extends WebMvcConfiguration {
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
log.info("设置静态资源映射");
|
||||
|
||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
*/
|
||||
protected void addCorsMappings(CorsRegistry registry) {
|
||||
log.info("WebMvcConfiguration===>开始跨域注册表...");
|
||||
|
||||
registry.addMapping("/**")// 添加路径规则
|
||||
.allowCredentials(true)// 是否允许在跨域的情况下传递Cookie
|
||||
.allowedOriginPatterns("*")// 允许请求来源的域规则
|
||||
|
@ -37,6 +38,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
*/
|
||||
protected void addInterceptors(InterceptorRegistry registry) {
|
||||
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
||||
|
||||
// 需要拦截的
|
||||
registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**")
|
||||
.excludePathPatterns(interceptorsProperties.getNoAuthUrls());
|
||||
|
|
|
@ -21,6 +21,7 @@ public class GlobalExceptionHandler {
|
|||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(BunnyException exception) {
|
||||
log.error("GlobalExceptionHandler===>自定义异常信息:{}", exception.getMessage());
|
||||
|
||||
Integer code = exception.getCode() != null ? exception.getCode() : 500;
|
||||
return Result.error(null, code, exception.getMessage());
|
||||
}
|
||||
|
@ -48,6 +49,7 @@ public class GlobalExceptionHandler {
|
|||
@ResponseBody
|
||||
public Result<Object> error(ArithmeticException exception) {
|
||||
log.error("GlobalExceptionHandler===>特定异常信息:{}", exception.getMessage());
|
||||
|
||||
return Result.error(null, 500, exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -56,6 +58,7 @@ public class GlobalExceptionHandler {
|
|||
@ResponseBody
|
||||
public Result<String> error(AccessDeniedException exception) throws AccessDeniedException {
|
||||
log.error("GlobalExceptionHandler===>spring security异常:{}", exception.getMessage());
|
||||
|
||||
return Result.error(ResultCodeEnum.PERMISSION);
|
||||
}
|
||||
|
||||
|
@ -64,6 +67,7 @@ public class GlobalExceptionHandler {
|
|||
@ResponseBody
|
||||
public Result<String> exceptionHandler(SQLIntegrityConstraintViolationException exception) {
|
||||
log.error("GlobalExceptionHandler===>处理SQL异常:{}", exception.getMessage());
|
||||
|
||||
String message = exception.getMessage();
|
||||
if (message.contains("Duplicate entry")) {
|
||||
// 截取用户名
|
||||
|
|
|
@ -26,6 +26,8 @@ public class LoginAuthInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler) throws Exception {
|
||||
log.info("LoginAuthInterceptor===>preHandle拦截请求前");
|
||||
|
||||
String method = request.getMethod();
|
||||
String token = request.getHeader("token");
|
||||
|
||||
|
@ -63,6 +65,8 @@ public class LoginAuthInterceptor implements HandlerInterceptor {
|
|||
*/
|
||||
@Override
|
||||
public void afterCompletion(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler, @Nullable Exception ex) throws Exception {
|
||||
log.info("LoginAuthInterceptor===>请求完成后删除ThreadLocal");
|
||||
|
||||
BaseContext.removeSysUser();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,12 @@ public class MenuHelper {
|
|||
*/
|
||||
public static List<SysMenuVo> buildMenus(List<SysMenu> menus) {
|
||||
LinkedList<SysMenuVo> sysMenuVos = new LinkedList<>();
|
||||
|
||||
menus.forEach(menu -> {
|
||||
SysMenuVo menuVo = new SysMenuVo();
|
||||
menuVo.setTitle(menu.getTitle());
|
||||
menuVo.setName(menu.getComponent());
|
||||
|
||||
List<SysMenu> children = menu.getChildren();
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
menuVo.setChildren(buildMenus(children));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.BrandService;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
|
@ -18,13 +19,15 @@ public class BrandController {
|
|||
@Autowired
|
||||
private BrandService brandService;
|
||||
|
||||
@Operation(summary = "品牌列表查询", description = "品牌列表查询")
|
||||
@Log(title = "品牌列表分页查询", businessType = 0)
|
||||
@Operation(summary = "品牌列表分页查询", description = "品牌列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
|
||||
PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "品牌添加", businessType = 1)
|
||||
@Operation(summary = "品牌添加", description = "品牌添加")
|
||||
@PostMapping("save")
|
||||
public Result<Brand> save(@RequestBody Brand brand) {
|
||||
|
@ -32,6 +35,7 @@ public class BrandController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改品牌", businessType = 2)
|
||||
@Operation(summary = "修改品牌", description = "修改品牌")
|
||||
@PutMapping("updateById")
|
||||
public Result<Brand> updateById(@RequestBody Brand brand) {
|
||||
|
@ -39,6 +43,7 @@ public class BrandController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "删除品牌", businessType = 3)
|
||||
@Operation(summary = "删除品牌", description = "删除品牌")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> deleteById(@PathVariable Long id) {
|
||||
|
@ -46,6 +51,7 @@ public class BrandController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "品牌列表", businessType = 0)
|
||||
@Operation(summary = "品牌列表", description = "品牌列表接口")
|
||||
@GetMapping("findAll")
|
||||
public Result<List<Brand>> findAll() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.CategoryBrandService;
|
||||
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
|
||||
import com.atguigu.spzx.model.entity.product.CategoryBrand;
|
||||
|
@ -17,6 +18,7 @@ public class CategoryBrandController {
|
|||
@Autowired
|
||||
private CategoryBrandService categoryBrandService;
|
||||
|
||||
@Log(title = "分类品牌列表", businessType = 0)
|
||||
@Operation(summary = "分类品牌列表", description = "分类品牌列表接口")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, CategoryBrandDto dto) {
|
||||
|
@ -24,6 +26,7 @@ public class CategoryBrandController {
|
|||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 1)
|
||||
@Operation(summary = "添加功能", description = "添加功能")
|
||||
@PostMapping("save")
|
||||
public Result<CategoryBrand> save(@RequestBody CategoryBrand categoryBrand) {
|
||||
|
@ -31,6 +34,7 @@ public class CategoryBrandController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 2)
|
||||
@Operation(summary = "修改功能", description = "修改功能")
|
||||
@PutMapping("updateById")
|
||||
public Result<CategoryBrand> updateById(@RequestBody CategoryBrand categoryBrand) {
|
||||
|
@ -38,6 +42,7 @@ public class CategoryBrandController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 3)
|
||||
@Operation(summary = "删除功能", description = "删除功能")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> deleteById(@PathVariable Long id) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.log.enums.OperatorType;
|
||||
import com.atguigu.spzx.manger.service.CategoryService;
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
|
@ -20,9 +19,8 @@ import java.util.List;
|
|||
public class CategoryController {
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
|
||||
@Log(title = "根据parentId获取下级节点", businessType = 0, operatorType = OperatorType.MANAGE)
|
||||
|
||||
@Log(title = "根据parentId获取下级节点", businessType = 0)
|
||||
@Operation(summary = "根据parentId获取下级节点", description = "根据parentId获取下级节点")
|
||||
@GetMapping(value = "findCategoryList/{parentId}")
|
||||
public Result<List<Category>> findByParentId(@PathVariable Long parentId) {
|
||||
|
@ -30,12 +28,14 @@ public class CategoryController {
|
|||
return Result.success(list);
|
||||
}
|
||||
|
||||
@Log(title = "根据parentId获取下级节点", businessType = 0)
|
||||
@Operation(summary = "导出数据", description = "导出数据")
|
||||
@GetMapping(value = "/exportData")
|
||||
public void exportData(HttpServletResponse response) {
|
||||
categoryService.exportData(response);
|
||||
}
|
||||
|
||||
@Log(title = "根据parentId获取下级节点", businessType = 0)
|
||||
@Operation(summary = "导入功能", description = "导入功能")
|
||||
@PostMapping("importData")
|
||||
public Result<String> importData(MultipartFile file) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.FileUploadService;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -18,6 +19,7 @@ public class FileUploadController {
|
|||
@Autowired
|
||||
private FileUploadService fileUploadService;
|
||||
|
||||
@Log(title = "上传文件", businessType = 0)
|
||||
@Operation(summary = "上传文件", description = "上传文件内容")
|
||||
@PostMapping("fileUpload")
|
||||
public Result<String> fileUploadService(@RequestParam(value = "file") MultipartFile file) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||
import com.atguigu.spzx.manger.service.SysUserService;
|
||||
import com.atguigu.spzx.manger.service.ValidateCodeService;
|
||||
|
@ -42,6 +43,7 @@ public class IndexController {
|
|||
return Result.success(vo);
|
||||
}
|
||||
|
||||
@Log(title = "获取登录用户信息", businessType = 0)
|
||||
@Operation(summary = "获取登录用户信息", description = "获取当前登录用户信息")
|
||||
@GetMapping("getUserInfo")
|
||||
public Result<SysUser> getUserInfo() {
|
||||
|
@ -56,6 +58,7 @@ public class IndexController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "动态菜单", businessType = 0)
|
||||
@Operation(summary = "动态菜单", description = "动态菜单")
|
||||
@GetMapping("menus")
|
||||
public Result<List<SysMenuVo>> menus() {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.OrderInfoService;
|
||||
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
|
||||
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -20,10 +20,11 @@ public class OrderInfoController {
|
|||
@Autowired
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@Log(title = "统计查询", businessType = 0)
|
||||
@Operation(summary = "统计查询", description = "统计查询")
|
||||
@GetMapping("/getOrderStatisticsData")
|
||||
public Result<OrderStatisticsVo> getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
|
||||
OrderStatisticsVo orderStatisticsVo = orderInfoService.getOrderStatisticsData(orderStatisticsDto);
|
||||
return Result.build(orderStatisticsVo, ResultCodeEnum.SUCCESS);
|
||||
return Result.success(orderStatisticsVo);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.log.enums.OperatorType;
|
||||
import com.atguigu.spzx.manger.service.CategoryBrandService;
|
||||
import com.atguigu.spzx.manger.service.ProductService;
|
||||
import com.atguigu.spzx.model.dto.product.ProductDto;
|
||||
|
@ -27,6 +26,7 @@ public class ProductController {
|
|||
@Autowired
|
||||
private CategoryBrandService categoryBrandService;
|
||||
|
||||
@Log(title = "列表查询", businessType = 0)
|
||||
@Operation(summary = "列表查询", description = "列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<Product>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, ProductDto dto) {
|
||||
|
@ -34,6 +34,7 @@ public class ProductController {
|
|||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 1)
|
||||
@Operation(summary = "添加功能", description = "添加功能")
|
||||
@GetMapping("findBrandByCategoryId/{categoryId}")
|
||||
public Result<List<Brand>> findBrandByCategoryId(@PathVariable Long categoryId) {
|
||||
|
@ -41,6 +42,7 @@ public class ProductController {
|
|||
return Result.success(brandList);
|
||||
}
|
||||
|
||||
@Log(title = "保存商品数据接口", businessType = 2)
|
||||
@Operation(summary = "保存商品数据接口", description = "保存商品数据接口")
|
||||
@PostMapping("save")
|
||||
public Result<Product> save(@RequestBody Product product) {
|
||||
|
@ -48,7 +50,7 @@ public class ProductController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "查询商品详情", businessType = 0, operatorType = OperatorType.MANAGE)
|
||||
@Log(title = "查询商品详情", businessType = 0)
|
||||
@Operation(summary = "查询商品详情", description = "查询商品详情")
|
||||
@GetMapping("getById/{id}")
|
||||
public Result<Product> getById(@PathVariable Long id) {
|
||||
|
@ -56,6 +58,7 @@ public class ProductController {
|
|||
return Result.success(product);
|
||||
}
|
||||
|
||||
@Log(title = "查询商品详情", businessType = 1)
|
||||
@Operation(summary = "保存修改数据接口", description = "保存修改数据接口")
|
||||
@PutMapping("updateById")
|
||||
public Result<Product> updateById(@Parameter(name = "product", description = "请求参数实体类", required = true) @RequestBody Product product) {
|
||||
|
@ -63,6 +66,7 @@ public class ProductController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "查询商品详情", businessType = 3)
|
||||
@Operation(summary = "删除商品", description = "删除商品")
|
||||
@DeleteMapping("/deleteById/{id}")
|
||||
public Result<Long> deleteById(@Parameter(name = "id", description = "商品id", required = true) @PathVariable Long id) {
|
||||
|
@ -70,6 +74,7 @@ public class ProductController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "商品审核", businessType = 0)
|
||||
@Operation(summary = "商品审核", description = "商品审核")
|
||||
@GetMapping("/updateAuditStatus/{id}/{auditStatus}")
|
||||
public Result<Product> updateAuditStatus(@PathVariable Long id, @PathVariable Integer auditStatus) {
|
||||
|
@ -77,6 +82,7 @@ public class ProductController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "商品上下架", businessType = 0)
|
||||
@Operation(summary = "商品上下架", description = "商品上下架")
|
||||
@GetMapping("/updateStatus/{id}/{status}")
|
||||
public Result<Product> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.ProductSpecService;
|
||||
import com.atguigu.spzx.model.entity.product.ProductSpec;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
|
@ -18,6 +19,7 @@ public class ProductSpecController {
|
|||
@Autowired
|
||||
private ProductSpecService productSpecService;
|
||||
|
||||
@Log(title = "列表查询", businessType = 0)
|
||||
@Operation(summary = "列表查询", description = "列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<ProductSpec>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
|
||||
|
@ -25,6 +27,7 @@ public class ProductSpecController {
|
|||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 1)
|
||||
@Operation(summary = "添加功能", description = "添加功能")
|
||||
@PostMapping("save")
|
||||
public Result<ProductSpec> save(@RequestBody ProductSpec productSpec) {
|
||||
|
@ -32,6 +35,7 @@ public class ProductSpecController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改功能", businessType = 2)
|
||||
@Operation(summary = "修改功能", description = "修改功能")
|
||||
@PutMapping("updateById")
|
||||
public Result<ProductSpec> updateById(@RequestBody ProductSpec productSpec) {
|
||||
|
@ -39,6 +43,7 @@ public class ProductSpecController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "删除功能", businessType = 3)
|
||||
@Operation(summary = "删除功能", description = "删除功能")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> removeById(@PathVariable Long id) {
|
||||
|
@ -46,6 +51,7 @@ public class ProductSpecController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "加载商品规格数据", businessType = 0)
|
||||
@Operation(summary = "加载商品规格数据", description = "加载商品规格数据")
|
||||
@GetMapping("findAll")
|
||||
public Result<List<ProductSpec>> findAll() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.ProductUnitService;
|
||||
import com.atguigu.spzx.model.entity.base.ProductUnit;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
|
@ -19,6 +20,7 @@ public class ProductUnitController {
|
|||
@Autowired
|
||||
private ProductUnitService productUnitService;
|
||||
|
||||
@Log(title = "加载商品单元数据", businessType = 0)
|
||||
@Operation(summary = "加载商品单元数据", description = "加载商品单元数据")
|
||||
@GetMapping("findAll")
|
||||
public Result<List<ProductUnit>> findAll() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
|
@ -19,6 +20,7 @@ public class SysMenuController {
|
|||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Log(title = "查询菜单", businessType = 0)
|
||||
@Operation(summary = "查询菜单", description = "查询菜单内容")
|
||||
@GetMapping("/findNodes")
|
||||
public Result<List<SysMenu>> findNodes() {
|
||||
|
@ -26,6 +28,7 @@ public class SysMenuController {
|
|||
return Result.build(list, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Log(title = "添加菜单", businessType = 1)
|
||||
@Operation(summary = "添加菜单", description = "添加菜单")
|
||||
@PostMapping("save")
|
||||
public Result<SysMenu> save(@RequestBody SysMenu sysMenu) {
|
||||
|
@ -33,6 +36,7 @@ public class SysMenuController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改菜单", businessType = 2)
|
||||
@Operation(summary = "修改菜单", description = "修改菜单")
|
||||
@PutMapping("updateById")
|
||||
public Result<SysMenu> updateById(@RequestBody SysMenu sysMenu) {
|
||||
|
@ -40,6 +44,7 @@ public class SysMenuController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "删除菜单", businessType = 3)
|
||||
@Operation(summary = "删除菜单", description = "删除菜单")
|
||||
@PutMapping("removeById/{id}")
|
||||
public Result<Long> removeById(@PathVariable Long id) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysRoleService;
|
||||
import com.atguigu.spzx.model.dto.system.AssginRoleDto;
|
||||
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
||||
|
@ -19,6 +20,7 @@ public class SysRoleController {
|
|||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Log(title = "查询角色分页", businessType = 0)
|
||||
@Operation(summary = "查询角色分页", description = "查询角色信息返回分页")
|
||||
@PostMapping("findByPage/{pageNum}/{pageSize}")
|
||||
public Result<PageInfo<SysRole>> findByPage(@RequestBody SysRoleDto sysRoleDto,
|
||||
|
@ -27,6 +29,7 @@ public class SysRoleController {
|
|||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加角色", businessType = 1)
|
||||
@Operation(summary = "添加角色", description = "添加角色相关内容")
|
||||
@PostMapping(value = "saveSysRole")
|
||||
public Result<SysRole> saveSysRole(@RequestBody SysRole sysRole) {
|
||||
|
@ -34,20 +37,23 @@ public class SysRoleController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改角色", businessType = 2)
|
||||
@Operation(summary = "修改角色", description = "修改角色相关信息")
|
||||
@PutMapping(value = "updateSysRole")
|
||||
public Result updateSysRole(@RequestBody SysRole sysRole) {
|
||||
public Result<SysRole> updateSysRole(@RequestBody SysRole sysRole) {
|
||||
sysRoleService.updateSysRole(sysRole);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "根据角色id删除角色", businessType = 3)
|
||||
@Operation(summary = "根据角色id删除角色", description = "根据角色id删除角色信息")
|
||||
@DeleteMapping(value = "deleteById/{roleId}")
|
||||
public Result deleteById(@PathVariable(value = "roleId") Long roleId) {
|
||||
public Result<AssginRoleDto> deleteById(@PathVariable(value = "roleId") Long roleId) {
|
||||
sysRoleService.deleteById(roleId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "查询所有角色", businessType = 0)
|
||||
@Operation(summary = "查询所有角色", description = "查询所有角色信息")
|
||||
@GetMapping(value = "findAllRoles/{userId}")
|
||||
public Result<AllRolesVo> findAllRoles(@PathVariable(value = "userId") Long userId) {
|
||||
|
@ -55,9 +61,10 @@ public class SysRoleController {
|
|||
return Result.success(allRolesList);
|
||||
}
|
||||
|
||||
@Log(title = "保存角色数据", businessType = 1)
|
||||
@Operation(summary = "保存角色数据", description = "保存角色数据信息")
|
||||
@PostMapping("doAssign")
|
||||
public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
|
||||
public Result<AssginRoleDto> doAssign(@RequestBody AssginRoleDto assginRoleDto) {
|
||||
sysRoleService.doAssign(assginRoleDto);
|
||||
return Result.success();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysRoleMenuService;
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
|
@ -16,6 +17,7 @@ public class SysRoleMenuController {
|
|||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
@Log(title = "查询菜单", businessType = 0)
|
||||
@Operation(summary = "查询菜单", description = "查询菜单")
|
||||
@GetMapping(value = "findSysRoleMenuByRoleId/{roleId}")
|
||||
public Result<SysRoleMenuVo> findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
|
||||
|
@ -23,6 +25,7 @@ public class SysRoleMenuController {
|
|||
return Result.success(sysRoleMenuList);
|
||||
}
|
||||
|
||||
@Log(title = "保存菜单", businessType = 1)
|
||||
@Operation(summary = "保存菜单", description = "保存菜单")
|
||||
@PostMapping("doAssign")
|
||||
public Result<AssginMenuDto> doAssign(@RequestBody AssginMenuDto assginMenuDto) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysUserService;
|
||||
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
|
@ -17,6 +18,7 @@ public class SysUserController {
|
|||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Log(title = "查询用户", businessType = 0)
|
||||
@Operation(summary = "查询用户", description = "查询用户信息")
|
||||
@GetMapping(value = "findByPage/{pageNum}/{pageSize}")
|
||||
public Result<PageInfo<SysUser>> findByPage(SysUserDto sysUserDto,
|
||||
|
@ -26,6 +28,7 @@ public class SysUserController {
|
|||
return Result.success(userPageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "根据id删除用户", businessType = 3)
|
||||
@Operation(summary = "添加用户", description = "添加用户信息")
|
||||
@PostMapping(value = "saveSysUser")
|
||||
public Result<SysUser> saveSysUser(@RequestBody SysUser sysUser) {
|
||||
|
@ -33,6 +36,7 @@ public class SysUserController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "根据id删除用户", businessType = 3)
|
||||
@Operation(summary = "修改用户", description = "修改用户信息")
|
||||
@PutMapping("updateSysUser")
|
||||
public Result<SysUser> updateSysUser(@RequestBody SysUser sysUser) {
|
||||
|
@ -40,6 +44,7 @@ public class SysUserController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "根据id删除用户", businessType = 3)
|
||||
@Operation(summary = "根据id删除用户", description = "删除用户信息")
|
||||
@DeleteMapping(value = "deleteById/{userId}")
|
||||
public Result<SysUser> deleteById(@PathVariable(value = "userId") Long userId) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
public interface CategoryService {
|
||||
/**
|
||||
* 根据父级id查找
|
||||
*
|
||||
* @param parentId 父级id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
|
@ -16,12 +17,14 @@ public interface CategoryService {
|
|||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
void exportData(HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 导入功能
|
||||
*
|
||||
* @param file Excel文件
|
||||
*/
|
||||
void importData(MultipartFile file);
|
||||
|
|
|
@ -30,6 +30,7 @@ public class BrandServiceImpl implements BrandService {
|
|||
@Override
|
||||
public PageInfo<Brand> findByPage(Integer page, Integer limit) {
|
||||
Page<Brand> startPage = PageHelper.startPage(page, limit);
|
||||
|
||||
// 查找分页品牌
|
||||
List<Brand> brandList = brandMapper.findByPage();
|
||||
startPage.close();
|
||||
|
@ -53,6 +54,7 @@ public class BrandServiceImpl implements BrandService {
|
|||
*/
|
||||
@Override
|
||||
public void updateById(Brand brand) {
|
||||
// 插入时不能为空
|
||||
emptyUtil.isEmpty(brand, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
|
||||
brandMapper.updateById(brand);
|
||||
|
@ -65,7 +67,9 @@ public class BrandServiceImpl implements BrandService {
|
|||
*/
|
||||
@Override
|
||||
public void deleteById(Long id) {
|
||||
// 判断ID不能为空
|
||||
emptyUtil.isEmpty(id, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
|
||||
brandMapper.deleteById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,12 +58,15 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
// 设置响应结果类型
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
||||
String filename = URLEncoder.encode("分类数据", StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + filename + ".xlsx");
|
||||
|
||||
// 查询数据库中的数据
|
||||
List<Category> categoryList = categoryMapper.selectAll();
|
||||
ArrayList<CategoryExcelVo> excelVoArrayList = new ArrayList<>();
|
||||
|
||||
// 将从数据库中查询到的Category对象转换成CategoryExcelVo对象
|
||||
categoryList.forEach(category -> {
|
||||
CategoryExcelVo vo = new CategoryExcelVo();
|
||||
|
|
|
@ -6,11 +6,9 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(description = "搜索条件实体类")
|
||||
public class CategoryBrandDto {
|
||||
@Schema(description = "品牌id")
|
||||
private Long brandId;
|
||||
|
||||
@Schema(description = "品牌id")
|
||||
private Long brandId;
|
||||
|
||||
@Schema(description = "分类id")
|
||||
private Long categoryId;
|
||||
|
||||
@Schema(description = "分类id")
|
||||
private Long categoryId;
|
||||
}
|
Loading…
Reference in New Issue