Forráskód Böngészése

[update] 每日统计司机库存bug修复

miajio 3 hete
szülő
commit
35f419102e

+ 4 - 7
pom.xml

@@ -72,19 +72,16 @@
                 <artifactId>apollo-client</artifactId>
                 <version>2.2.0</version>
             </dependency>
-
             <dependency>
                 <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-spring-boot-starter</artifactId>
-                <version>3.2.9</version>
+                <artifactId>dubbo-registry-nacos</artifactId>
+                <version>${dubbo.version}</version>
             </dependency>
-
             <dependency>
                 <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-registry-nacos</artifactId>
-                <version>3.2.9</version>
+                <artifactId>dubbo-spring-boot-starter</artifactId>
+                <version>${dubbo.version}</version>
             </dependency>
-
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-test</artifactId>

+ 1 - 3
warehouse-admin-component/src/main/java/com/yr/warehouse/admin/component/driver/DriverDeviceSalesComponent.java

@@ -1,6 +1,5 @@
 package com.yr.warehouse.admin.component.driver;
 
-import com.yr.bluecat.common.entity.response.Result;
 import com.yr.shopping.admin.support.DriverDeviceSalesApi;
 import com.yr.shopping.admin.support.request.DriverDeviceSalesRequest;
 import com.yr.shopping.admin.support.response.DriverDeviceSalesResponse;
@@ -32,8 +31,7 @@ public class DriverDeviceSalesComponent {
         request.setAppId(apolloConfigEvent.getAppId());
         request.setStartTime(startTime);
         request.setEndTime(endTime);
-        Result<List<DriverDeviceSalesResponse>> res = driverDeviceSalesApi.list(request);
-        return res.getData();
+        return driverDeviceSalesApi.list(request).getData();
     }
 
 }

+ 1 - 1
warehouse-admin-data/src/main/resources/mapper/driver/DriverOnRouteDetailLogMapper.xml

@@ -32,7 +32,7 @@
         (operatorId, operatorChain, areaStaffId, statDate, goodsLossRecordId, goodsId, createNum, unshippedCancelNum,
         shippedCancelNum, replenishNum, returnWarehouseNum, yesterdayStockNum, todayStockNum, profitLossNum)
         values
-        <foreach collection="driverOnRouteDetailLogs" item="item" open="(" close=")" separator=",">
+        <foreach collection="driverOnRouteDetailLogs" item="item" separator=",">
             (#{item.operatorId}, #{item.operatorChain}, #{item.areaStaffId}, #{item.statDate}, #{item.goodsLossRecordId}, #{item.goodsId}, #{item.createNum},
             #{item.unshippedCancelNum}, #{item.shippedCancelNum}, #{item.replenishNum}, #{item.returnWarehouseNum}, #{item.yesterdayStockNum}, #{item.todayStockNum},
             #{item.profitLossNum})

+ 8 - 1
warehouse-admin-event/src/main/java/com/yr/warehouse/admin/event/task/DriverCargoDamageStatisticsTask.java

@@ -1,6 +1,7 @@
 package com.yr.warehouse.admin.event.task;
 
 import com.xxl.job.core.handler.annotation.XxlJob;
+import com.yr.warehouse.admin.service.context.TransactionAwareComponent;
 import com.yr.warehouse.admin.service.statistics.DriverStatistics;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
@@ -18,13 +19,19 @@ public class DriverCargoDamageStatisticsTask {
     @Resource
     private DriverStatistics driverStatistics;
 
+    @Resource
+    private TransactionAwareComponent transactionAwareComponent;
+
     /**
      * 货损统计任务
      */
     @XxlJob("driverCargoDamageStatisticsTask")
     public void driverCargoDamageStatisticsTask() {
         log.info("开始执行司机货损统计任务");
-        driverStatistics.cargoDamageStatistics(LocalDate.now());
+        transactionAwareComponent.execute(status -> {
+            driverStatistics.cargoDamageStatistics(LocalDate.now());
+            return null;
+        });
         log.info("结束执行司机货损统计任务");
     }
 

+ 98 - 0
warehouse-admin-web/src/main/java/com/yr/warehouse/admin/web/filter/DubboExceptionFilter.java

@@ -0,0 +1,98 @@
+package com.yr.warehouse.admin.web.filter;
+
+import com.yr.bluecat.common.entity.request.AbstractRequest;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.ReflectUtils;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.*;
+import org.apache.dubbo.rpc.filter.ExceptionFilter;
+import org.apache.dubbo.rpc.service.GenericService;
+import org.apache.dubbo.rpc.support.RpcUtils;
+import org.springframework.validation.annotation.Validated;
+
+import java.lang.reflect.Method;
+
+/**
+ * 重新dubbo过滤器
+ *
+ * @Description
+ * @Author pete
+ * @Date 2024/2/22 15:53
+ **/
+@Activate(
+        group = {"provider"}
+)
+public class DubboExceptionFilter extends ExceptionFilter {
+
+    private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(DubboExceptionFilter.class);
+
+    @Override
+    @Validated
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+        Class<?> anInterface = invoker.getInterface();
+        if (anInterface.getName().contains("com.yr.warehouse")) {
+            Object[] args = invocation.getArguments();
+            boolean hasAppId = false;
+            for (Object arg : args) {
+                // 这个request要放到统一的包里
+                if (arg instanceof AbstractRequest) {
+                    if (StringUtils.isBlank(((AbstractRequest) arg).getAppId())) {
+                        // throw new MessageException("appId不能为空");
+                    }
+                    hasAppId = true;
+                }
+            }
+            if (!hasAppId) {
+                // throw new MessageException("appId不能为空");
+            }
+        }
+        return invoker.invoke(invocation);
+    }
+
+    @Override
+    public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
+        if (appResponse.hasException() && GenericService.class != invoker.getInterface()) {
+            try {
+                Throwable exception = appResponse.getException();
+                if (!(exception instanceof RuntimeException) && exception instanceof Exception) {
+                    return;
+                }
+                try {
+                    Method method = invoker.getInterface().getMethod(RpcUtils.getMethodName(invocation), invocation.getParameterTypes());
+                    Class<?>[] exceptionClasses = method.getExceptionTypes();
+
+                    for (Class<?> exceptionClass : exceptionClasses) {
+                        if (exception.getClass().equals(exceptionClass)) {
+                            return;
+                        }
+                    }
+                } catch (NoSuchMethodException var11) {
+                    return;
+                }
+
+                this.logger.error("5-36", "", "", "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception);
+                String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface());
+                String exceptionFile = ReflectUtils.getCodeBase(exception.getClass());
+                if (serviceFile != null && exceptionFile != null && !serviceFile.equals(exceptionFile)) {
+                    String className = exception.getClass().getName();
+                    // 自定义异常类,不要转运行时异常
+                    if (!className.startsWith("java.") && !className.startsWith("javax.") && !className.startsWith("jakarta.") && !className.startsWith("com.yr.bluecat.common.entity.exception.")) {
+                        if (exception instanceof RpcException) {
+                            return;
+                        }
+
+                        appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
+                        return;
+                    }
+
+                    return;
+                }
+            } catch (Throwable throwable) {
+                this.logger.warn("5-36", "", "", "Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + ", exception: " + throwable.getClass().getName() + ": " + throwable.getMessage(), throwable);
+            }
+        }
+
+    }
+}

+ 1 - 1
warehouse-admin-web/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter

@@ -1 +1 @@
-dubboExceptionFilter =
+dubboExceptionFilter = com.yr.warehouse.admin.web.filter.DubboExceptionFilter