浏览代码

fix 拦截日志

he2802 4 年之前
父节点
当前提交
0b101ce3d1

+ 18 - 2
zhongzheng-admin/src/main/java/com/zhongzheng/controller/course/MajorCategoryController.java

@@ -1,7 +1,13 @@
 package com.zhongzheng.controller.course;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Arrays;
+import java.util.Map;
 
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.zhongzheng.modules.course.bo.MajorCategoryAddBo;
@@ -10,6 +16,9 @@ import com.zhongzheng.modules.course.bo.MajorCategoryQueryBo;
 import com.zhongzheng.modules.course.service.IMajorCategoryService;
 import com.zhongzheng.modules.course.vo.MajorCategoryVo;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.expression.EvaluationContext;
+import org.springframework.expression.spel.support.StandardEvaluationContext;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
@@ -87,8 +96,10 @@ public class MajorCategoryController extends BaseController {
     @PreAuthorize("@ss.hasPermi('course:category:add')")
     @Log(title = "【专业分类】", businessType = BusinessType.INSERT)
     @PostMapping()
-    public AjaxResult<Long> add(@Validated  @RequestBody MajorCategoryAddBo bo) {
-        return AjaxResult.success(iMajorCategoryService.insertByAddBo(bo));
+    public AjaxResult add(@Validated  @RequestBody MajorCategoryAddBo bo) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
+        Long id = iMajorCategoryService.insertByAddBo(bo);
+        String content = "新增分类:"+bo.getCategoryName();
+        return AjaxResult.success_log(id,content);
     }
 
     /**
@@ -100,6 +111,11 @@ public class MajorCategoryController extends BaseController {
     @Log(title = "【专业分类】", businessType = BusinessType.UPDATE)
     @PostMapping("/edit")
     public AjaxResult<Void> edit(@Validated @RequestBody MajorCategoryEditBo bo) {
+        if(iMajorCategoryService.updateByEditBo(bo)){
+            Long id = bo.getCategoryId();
+            String content = "修改分类:"+bo.getCategoryName();
+            return AjaxResult.success_log(id,content);
+        }
         return toAjax(iMajorCategoryService.updateByEditBo(bo) ? 1 : 0);
     }
 

+ 5 - 2
zhongzheng-common/src/main/java/com/zhongzheng/common/annotation/Log.java

@@ -10,7 +10,7 @@ import com.zhongzheng.common.enums.OperatorType;
 
 /**
  * 自定义操作日志记录注解
- * 
+ *
  * @author zhongzheng
  *
  */
@@ -20,7 +20,7 @@ import com.zhongzheng.common.enums.OperatorType;
 public @interface Log
 {
     /**
-     * 模块 
+     * 模块
      */
     public String title() default "";
 
@@ -38,4 +38,7 @@ public @interface Log
      * 是否保存请求的参数
      */
     public boolean isSaveRequestData() default true;
+
+
+
 }

+ 27 - 11
zhongzheng-common/src/main/java/com/zhongzheng/common/core/domain/AjaxResult.java

@@ -5,10 +5,11 @@ import cn.hutool.http.HttpStatus;
 import lombok.Data;
 
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 操作消息提醒
- * 
+ *
  * @author zhongzheng
  */
 public class AjaxResult<T> extends HashMap<String, Object>
@@ -44,7 +45,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 初始化一个新创建的 AjaxResult 对象
-     * 
+     *
      * @param code 状态码
      * @param msg 返回内容
      */
@@ -56,7 +57,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 初始化一个新创建的 AjaxResult 对象
-     * 
+     *
      * @param code 状态码
      * @param msg 返回内容
      * @param data 数据对象
@@ -73,7 +74,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回成功消息
-     * 
+     *
      * @return 成功消息
      */
     public static AjaxResult<Void> success()
@@ -81,9 +82,24 @@ public class AjaxResult<T> extends HashMap<String, Object>
         return AjaxResult.success("操作成功");
     }
 
+    /**
+     * 返回成功拦截日志消息
+     *
+     * @return 成功拦截日志消息
+     */
+    public static AjaxResult<Void> success_log(Long primary_key_id,String oper_content)
+    {
+        Map<String,Object> logMap = new HashMap<>();
+        logMap.put("primary_key_id", primary_key_id);
+        logMap.put("oper_content", oper_content);
+        AjaxResult ajax = AjaxResult.success();
+        ajax.put("log", logMap);
+        return ajax;
+    }
+
     /**
      * 返回成功数据
-     * 
+     *
      * @return 成功消息
      */
     public static <T> AjaxResult<T> success(T data)
@@ -93,7 +109,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回成功消息
-     * 
+     *
      * @param msg 返回内容
      * @return 成功消息
      */
@@ -104,7 +120,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回成功消息
-     * 
+     *
      * @param msg 返回内容
      * @param data 数据对象
      * @return 成功消息
@@ -116,7 +132,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回错误消息
-     * 
+     *
      * @return
      */
     public static AjaxResult<Void> error()
@@ -126,7 +142,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param msg 返回内容
      * @return 警告消息
      */
@@ -137,7 +153,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param msg 返回内容
      * @param data 数据对象
      * @return 警告消息
@@ -149,7 +165,7 @@ public class AjaxResult<T> extends HashMap<String, Object>
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param code 状态码
      * @param msg 返回内容
      * @return 警告消息

+ 1 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/aspectj/LogAspect.java

@@ -146,6 +146,7 @@ public class LogAspect
         operLog.setTitle(log.title());
         // 设置操作人类别
         operLog.setOperatorType(log.operatorType().ordinal());
+
         // 是否需要保存request,参数和值
         if (log.isSaveRequestData())
         {

+ 6 - 22
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/domain/SysOperLog.java

@@ -151,29 +151,13 @@ public class SysOperLog implements Serializable {
 
     //日志PUT POST方法会触发
     public void addPrimaryIdAndContent(){
-        String params = getOperParam();
-        //专业分类模块
-        if(getOperUrl().startsWith("/course/category")&&getStatus()==0){
-            //新增分类
-            if(getOperUrl().equals("/course/category")){
-                JSONObject jsonObject = JSONObject.parseObject(params);
-                JSONObject resultObject = JSONObject.parseObject(getJsonResult());
-                if (jsonObject.containsKey("categoryName")){
-                    setPrimaryKeyId((Integer)resultObject.get("data"));
-                    setOperContent("新增分类:"+ jsonObject.get("categoryName"));
-                }
-            }
-            //修改分类
-            if(getOperUrl().equals("/course/category/edit")){
-                JSONObject jsonObject = JSONObject.parseObject(params);
-                if (jsonObject.containsKey("categoryId")){
-                    setPrimaryKeyId((Integer)jsonObject.get("categoryId"));
-                    String content = "修改分类:"+ jsonObject.get("categoryName");
-                    setOperContent(content);
-                }
+        if(getStatus()==0){
+            JSONObject resultObject = JSONObject.parseObject(getJsonResult());
+            if (resultObject.containsKey("log")){
+                Map entry = (Map)resultObject.get("log");
+                setPrimaryKeyId((Integer)entry.get("primary_key_id"));
+                setOperContent((String) entry.get("oper_content"));
             }
         }
-
-
     }
 }