1
0
Selaa lähdekoodia

fix:全局统一返回排除ExcludeGlobalResult注解标记的方法

wangzaijun 7 kuukautta sitten
vanhempi
commit
28a1a176a5

+ 16 - 0
service-base/src/main/java/com/simuwang/base/ano/ExcludeGlobalResult.java

@@ -0,0 +1,16 @@
+package com.simuwang.base.ano;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author wangzaijun
+ * @date 2024/9/21 15:39
+ * @description 排除的全局统一返回的方法
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ExcludeGlobalResult {
+}

+ 3 - 3
service-base/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -6,9 +6,9 @@
                sm.menu_name  as name
         from sys_menu sm
                  join sys_role_menu srm on sm.menu_id = srm.menu_id
-                 join sys_role sr on sr.role_id = srm.role_id and sr.isvalid = 1
+                 join sys_role sr on sr.role_id = srm.role_id and sr.isvalid = 1 and sr.status = 1
         where sr.role_id = #{roleId}
-          and sm.isvalid = 1
+          and sm.isvalid = 1 and sm.status = 1
         order by sm.menu_id
     </select>
 
@@ -16,7 +16,7 @@
         select sm.menu_id    as id,
                sm.menu_name  as name
         from sys_menu sm
-        where sm.isvalid = 1
+        where sm.isvalid = 1 and sm.status = 1
         order by sm.menu_id
     </select>
 

+ 10 - 10
service-base/src/main/resources/mapper/system/SysUserMapper.xml

@@ -6,9 +6,9 @@
                t.role_name  as name
         from sys_role t
                  join sys_user_role t1 on t.role_id = t1.role_id
-                 join sys_user t2 on t1.user_id = t2.user_id and t2.isvalid = 1
+                 join sys_user t2 on t1.user_id = t2.user_id and t2.isvalid = 1 and t2.status = 1
         where t2.user_id = #{userId}
-          and t.isvalid = 1
+          and t.isvalid = 1 and t.status = 1
         order by t.role_id
     </select>
 
@@ -16,7 +16,7 @@
         select t.role_id    as id,
                t.role_name  as name
         from sys_role t
-        where t.isvalid = 1
+        where t.isvalid = 1 and t.status = 1
         order by t.role_id
     </select>
 
@@ -34,9 +34,9 @@
                t.updatetime as updateTime
         from sys_role t
                  join sys_user_role t1 on t.role_id = t1.role_id
-                 join sys_user t2 on t1.user_id = t2.user_id and t2.isvalid = 1
+                 join sys_user t2 on t1.user_id = t2.user_id and t2.isvalid = 1 and t2.status = 1
         where t2.user_id = #{userId}
-          and t.isvalid = 1
+          and t.isvalid = 1 and t.status = 1
         order by t.role_id
     </select>
 
@@ -53,7 +53,7 @@
                t.updaterid  as updaterId,
                t.updatetime as updateTime
         from sys_role t
-        where t.isvalid = 1
+        where t.isvalid = 1 and t.status = 1
         order by t.role_id
     </select>
 
@@ -79,11 +79,11 @@
                sm.updatetime as updateTime
         from sys_menu sm
                  join sys_role_menu srm on sm.menu_id = srm.menu_id
-                 join sys_role sr on sr.role_id = srm.role_id and sr.isvalid = 1
+                 join sys_role sr on sr.role_id = srm.role_id and sr.isvalid = 1 and sr.status = 1
                  join sys_user_role t1 on sr.role_id = t1.role_id
-                 join sys_user t2 on t1.user_id = t2.user_id and t2.isvalid = 1
+                 join sys_user t2 on t1.user_id = t2.user_id and t2.isvalid = 1 and t2.status = 1
         where t2.user_id = #{userId}
-          and sm.isvalid = 1
+          and sm.isvalid = 1 and sm.status = 1
         order by sm.menu_id
     </select>
 
@@ -108,7 +108,7 @@
                sm.updaterid  as updaterId,
                sm.updatetime as updateTime
         from sys_menu sm
-        where sm.isvalid = 1
+        where sm.isvalid = 1 and sm.status = 1
         order by sm.menu_id
     </select>
 

+ 8 - 2
service-deploy/src/main/java/com/simuwang/deploy/components/ErrorInfoBuilder.java

@@ -81,8 +81,14 @@ public class ErrorInfoBuilder implements HandlerExceptionResolver, Ordered {
         } else if (error instanceof UnknownAccountException || error instanceof IncorrectCredentialsException) {
             msg = ResultCode.AUTH_FAILD.getMsg();
         } else if (error instanceof AuthenticationException) {
-            code = HttpStatus.UNAUTHORIZED.value();
-            msg = "登录认证失败";
+            Throwable cause = error.getCause();
+            if (cause instanceof APIException e) {
+                code = e.getCode();
+                msg = e.getMsg();
+            } else {
+                code = HttpStatus.UNAUTHORIZED.value();
+                msg = "登录认证失败";
+            }
         } else if (error instanceof APIException e) {
             msg = e.getMsg();
             code = e.getCode();

+ 6 - 2
service-deploy/src/main/java/com/simuwang/deploy/config/GlobalResponseBodyAdvice.java

@@ -1,6 +1,7 @@
 package com.simuwang.deploy.config;
 
 import cn.hutool.json.JSONUtil;
+import com.simuwang.base.ano.ExcludeGlobalResult;
 import com.smppw.common.pojo.ResultVo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -16,6 +17,8 @@ import org.springframework.lang.NonNull;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
 
+import java.lang.reflect.AnnotatedElement;
+
 /**
  * @author wangzaijun
  * @date 2023/8/12 16:39
@@ -27,8 +30,9 @@ public class GlobalResponseBodyAdvice implements ResponseBodyAdvice<Object> {
 
     @Override
     public boolean supports(@NonNull MethodParameter returnType, @NonNull Class<? extends HttpMessageConverter<?>> converterType) {
-        // 全部接口都要拦截
-        return true;
+        AnnotatedElement element = returnType.getAnnotatedElement();
+        // 除了被ExcludeGlobalResult标记的方法其他全部接口都要拦截
+        return !element.isAnnotationPresent(ExcludeGlobalResult.class);
     }
 
     @Override

+ 4 - 2
service-manage/src/main/java/com/simuwang/manage/api/deletion/DeletionController.java

@@ -1,5 +1,6 @@
 package com.simuwang.manage.api.deletion;
 
+import com.simuwang.base.ano.ExcludeGlobalResult;
 import com.simuwang.base.common.support.MybatisPage;
 import com.simuwang.base.common.util.EncodeUtil;
 import com.simuwang.base.common.util.ExcelUtil;
@@ -89,6 +90,7 @@ public class DeletionController {
      * @param fundDeletionListVO
      * @return
      */
+    @ExcludeGlobalResult
     @PostMapping("/download-fund-deletion")
     public void downloadFundDeletion(@RequestBody FundDeletionListVO fundDeletionListVO, HttpServletResponse response){
         List<ExcelDeletionInfoDTO> fundDeletionInfoVOList = deletionService.selectFundDeletionInfoVOList(fundDeletionListVO);
@@ -115,9 +117,9 @@ public class DeletionController {
         values.put(sheetName,dataList);
         HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName,head,values,null);
         try {
-            response.setContentType("application/vnd.ms-excel");
+            response.setContentType("application/x-xls");
             response.setCharacterEncoding("GBK");
-            response.addHeader("Content-Disposition", "attachment;filename=" + EncodeUtil.encodeUTF8("缺失明细.xlsx"));
+            response.addHeader("Content-Disposition", "attachment;filename=" + EncodeUtil.encodeUTF8("缺失明细.xls"));
             ServletOutputStream outputStream = response.getOutputStream();
             wb.write(outputStream);
             outputStream.flush();