From 8699674c7201186272efd484789e429a99b6b294 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo Date: Fri, 10 May 2024 14:05:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E4=BF=AE=E6=94=B9=E9=87=91?= =?UTF-8?q?=E7=89=8C=E6=8E=A5=E6=94=B6=E8=AE=A2=E5=8D=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jinpai/aspect/AnnotationAspect.java | 56 +- .../jinpai/config/ExecutorConfig.java | 79 +++ .../config/InterceptorAdapterConfig.java | 32 + .../jinpai/config/XxlJobConfig.java | 74 ++ .../jinpai/controller/OrderController.java | 31 +- .../jinpai/entity/DeliveryNoteEntity.java | 16 + .../jinpai/entity/FactoryOrderLogEntity.java | 4 +- .../jinpai/entity/FactoryToken.java | 32 + .../jinpai/entity/PackageInfoEntity.java | 2 + .../jinpai/entity/PushOrderDetailEntity.java | 109 +++ .../jinpai/entity/PushOrderEntity.java | 62 ++ .../jinpai/enums/BusSourceEnums.java | 24 + .../FactoryAccountsInterceptor.java | 87 +++ .../LocalServerLoginAccountsInterceptor.java | 100 +++ .../factorydata/jinpai/job/AdvanceJob.java | 300 ++++++++ .../jinpai/mapper/DeliveryNoteMapper.java | 6 + .../jinpai/mapper/FactoryNodeOrderMapper.xml | 5 + .../jinpai/mapper/FactoryTokenMapper.java | 31 + .../jinpai/mapper/FactoryTokenMapper.xml | 20 + .../jinpai/mapper/OrderInfoMapper.java | 1 + .../jinpai/mapper/PushOrderDetailMapper.java | 16 + .../jinpai/mapper/PushOrderDetailMapper.xml | 5 + .../jinpai/mapper/PushOrderMapper.java | 16 + .../jinpai/mapper/PushOrderMapper.xml | 5 + .../jinpai/mq/FactoryOrderListener.java | 657 ++++++++++-------- .../jinpai/service/DeliveryNoteService.java | 14 +- .../jinpai/service/IFactoryTokenService.java | 15 + .../service/PushOrderDetailService.java | 14 + .../jinpai/service/PushOrderService.java | 14 + .../service/impl/DeliveryNoteServiceImpl.java | 41 +- .../service/impl/FactoryTokenServiceImpl.java | 62 ++ .../impl/PushOrderDetailServiceImpl.java | 22 + .../service/impl/PushOrderServiceImpl.java | 22 + .../jinpai/util/ThreadPoolUtil.java | 43 -- .../jinpai/vo/PackageCategoryVO.java | 26 + .../jinpai/vo/PushOrderDetailVO.java | 28 + .../factorydata/jinpai/vo/PushOrderVO.java | 25 + .../jinpai/vo/ThirdPlWarehouseMappingVO.java | 32 + .../CustomHttpServletRequestWrapper.java | 38 + .../jinpai/wrapper/RequestWrapper.java | 75 ++ .../src/main/resources/application-dev.yml | 12 +- .../src/main/resources/application-prod.yml | 12 +- .../src/main/resources/application-test.yml | 12 +- 43 files changed, 1917 insertions(+), 360 deletions(-) create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/ExecutorConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/InterceptorAdapterConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/XxlJobConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryToken.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderDetailEntity.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderEntity.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/enums/BusSourceEnums.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/FactoryAccountsInterceptor.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/IFactoryTokenService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderDetailService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/FactoryTokenServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderDetailServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderServiceImpl.java delete mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/util/ThreadPoolUtil.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PackageCategoryVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderDetailVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/ThirdPlWarehouseMappingVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/CustomHttpServletRequestWrapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/RequestWrapper.java diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java index 84cb0a40c..e3414918c 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java @@ -8,19 +8,22 @@ import lombok.AllArgsConstructor; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.reflect.MethodSignature; import org.springblade.common.cache.CacheNames; import org.springblade.common.constant.LauncherConstant; -import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.scheduling.annotation.Async; 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.HashMap; import java.util.Map; import java.util.Objects; @@ -31,6 +34,39 @@ import java.util.Objects; public class AnnotationAspect { private final BladeRedis bladeRedis; private final Environment environment; + + + /** + * 定义一个切点,匹配所有带有@Async("asyncExecutor")注解的方法。 + * 注意:实际上Spring Framework自带对@Async("asyncExecutor")的处理,直接这样配置可能会导致预期之外的行为。 + */ + @Around("@annotation(org.springframework.scheduling.annotation.Async)") + public Object asyncAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable { + + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + + Async myAsync = method.getAnnotation(Async.class); + String annotationValue = myAsync.value(); + + if (StringUtil.isNotBlank(annotationValue) && annotationValue.equals("asyncExecutor")) { + // 在方法执行前的操作 + String tenantId = AuthUtil.getTenantId(); + DynamicDataSourceContextHolder.push(tenantId); + + // 执行原方法 + Object result = joinPoint.proceed(); + + // 在方法执行后的操作 + DynamicDataSourceContextHolder.poll(); + + return result; + } else { + return joinPoint.proceed(); + } + + } + /** * 该方法为一个切面,用于对标记了@RabbitListener注解的方法进行增强,主要增加了日志记录和数据源上下文处理的功能。 * @@ -68,12 +104,12 @@ public class AnnotationAspect { JSONObject jsonObject = mockLogin(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); - mockRequest.addHeader("Blade-Auth", "bearer "+jsonObject.get("access_token")); + mockRequest.addHeader("Blade-Auth", "bearer " + jsonObject.get("access_token")); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockRequest)); HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.add("Blade-Auth","bearer "+jsonObject.get("access_token") ); - httpHeaders.add( "Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); + httpHeaders.add("Blade-Auth", "bearer " + jsonObject.get("access_token")); + httpHeaders.add("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); ThreadLocalUtil.put("bladeContext", httpHeaders); DynamicDataSourceContextHolder.push(jsonObject.getString("tenant_id")); @@ -87,12 +123,12 @@ public class AnnotationAspect { } - private JSONObject mockLogin(){ + private JSONObject mockLogin() { - String account ="shujutongbu"; - JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); - if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; + String account = "shujutongbu"; + JSONObject data = bladeRedis.get(CacheNames.LOCAL_SERVER_USER + account); + if (Objects.isNull(data)) { + String url = "http://" + LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0])) + "/blade-auth/oauth/token"; HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683"); @@ -105,7 +141,7 @@ public class AnnotationAspect { HttpResponse execute = urlRequest.form(params).execute(); String body = execute.body(); data = JSONObject.parseObject(body); - bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,3200L); + bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER + account, data, 3200L); } return data; } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/ExecutorConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/ExecutorConfig.java new file mode 100644 index 000000000..294c78ddd --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/ExecutorConfig.java @@ -0,0 +1,79 @@ +package com.logpm.factorydata.jinpai.config; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; +import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.TaskDecorator; +import org.springframework.http.HttpHeaders; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + +import javax.annotation.Nonnull; +import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +@Slf4j +@EnableAsync +public class ExecutorConfig { + + @Bean + public Executor asyncExecutor() { + log.info("start async executor"); + ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); +// 配置核心线程数 + threadPoolTaskExecutor.setCorePoolSize(10); +// 配置最大线程数 + threadPoolTaskExecutor.setMaxPoolSize(20); +// 配置队列大小 + threadPoolTaskExecutor.setQueueCapacity(50); +// 配置线程池中线程的名称前缀 + threadPoolTaskExecutor.setThreadNamePrefix("ASYNC_THREAD_"); +// HelloWorldServiceImpl rejection-policy: 当pool已经达到max size时,如何处理新任务: +// CallerRunsPolicy: 不在新线程中执行任务,而是由调用者所在的线程来执行; +// AbortPolicy: 拒绝执行新任务,并抛出RejectedExecutionException异常; +// DiscardPolicy:丢弃当前将要加入队列的任务; +// DiscardOldestPolicy:丢弃任务队列中最旧的任务; + threadPoolTaskExecutor.setRejectedExecutionHandler( + new ThreadPoolExecutor.CallerRunsPolicy() + ); + threadPoolTaskExecutor.setTaskDecorator(new ContextCopyingDecorator()); + threadPoolTaskExecutor.initialize(); + return threadPoolTaskExecutor; + } + + + static class ContextCopyingDecorator implements TaskDecorator { + @Nonnull + @Override + public Runnable decorate(@Nonnull Runnable runnable) { + RequestAttributes context = RequestContextHolder.currentRequestAttributes(); + HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext"); + Map mdcMap = MDC.getCopyOfContextMap(); + return () -> { + try { + ThreadLocalUtil.put("bladeContext", headers); + if (mdcMap != null && !mdcMap.isEmpty()) { + MDC.setContextMap(mdcMap); + } + RequestContextHolder.setRequestAttributes(context); + + runnable.run(); + } finally { + RequestContextHolder.resetRequestAttributes(); + if (mdcMap != null) { + mdcMap.clear(); + } + ThreadLocalUtil.clear(); + MDC.clear(); + } + }; + } + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/InterceptorAdapterConfig.java new file mode 100644 index 000000000..3b27885ea --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/InterceptorAdapterConfig.java @@ -0,0 +1,32 @@ +package com.logpm.factorydata.jinpai.config; + +import com.logpm.factorydata.jinpai.interceptor.FactoryAccountsInterceptor; +import com.logpm.factorydata.jinpai.interceptor.LocalServerLoginAccountsInterceptor; +import com.logpm.factorydata.jinpai.service.IFactoryTokenService; +import lombok.AllArgsConstructor; +import org.springblade.core.redis.cache.BladeRedis; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@AllArgsConstructor +public class InterceptorAdapterConfig implements WebMvcConfigurer { + + private final IFactoryTokenService factoryTokenService; + + private final BladeRedis redis; + + private final Environment environment; + + + @Override + public void addInterceptors(InterceptorRegistry interceptorRegistry) { +// interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(factoryTokenService)) +// .addPathPatterns("/**").order(1); + interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis, environment)) + .addPathPatterns("/**").order(2); + + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/XxlJobConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/XxlJobConfig.java new file mode 100644 index 000000000..8133b6a26 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/XxlJobConfig.java @@ -0,0 +1,74 @@ +package com.logpm.factorydata.jinpai.config; + +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * xxl-job config + * + * @author xuxueli 2017-04-28 + */ +@Configuration(proxyBeanMethods = false) +public class XxlJobConfig { + private final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); + + @Value("${xxl.job.admin.addresses}") + private String adminAddresses; + + @Value("${xxl.job.executor.appname}") + private String appName; + + @Value("${xxl.job.executor.ip}") + private String ip; + + @Value("${xxl.job.executor.port}") + private int port; + + @Value("${xxl.job.accessToken}") + private String accessToken; + + @Value("${xxl.job.executor.logpath}") + private String logPath; + + @Value("${xxl.job.executor.logretentiondays}") + private int logRetentionDays; + + + @Bean + public XxlJobSpringExecutor xxlJobExecutor() { + logger.info(">>>>>>>>>>> xxl-job config init."); + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + xxlJobSpringExecutor.setAdminAddresses(adminAddresses); + xxlJobSpringExecutor.setAppName(appName); + xxlJobSpringExecutor.setIp(ip); + xxlJobSpringExecutor.setPort(port); + xxlJobSpringExecutor.setAccessToken(accessToken); + xxlJobSpringExecutor.setLogPath(logPath); + xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); + + return xxlJobSpringExecutor; + } + + /** + * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP; + * + * 1、引入依赖: + * + * org.springframework.cloud + * spring-cloud-commons + * ${version} + * + * + * 2、配置文件,或者容器启动变量 + * spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' + * + * 3、获取IP + * String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + */ + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/controller/OrderController.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/controller/OrderController.java index 0504d7cd4..b5faf3da5 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/controller/OrderController.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/controller/OrderController.java @@ -1,5 +1,6 @@ package com.logpm.factorydata.jinpai.controller; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONUtil; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; @@ -7,6 +8,7 @@ import com.logpm.factorydata.jinpai.service.DeliveryNoteService; import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO; import com.logpm.factorydata.jinpai.vo.OrderInfoVO; import com.logpm.factorydata.jinpai.vo.PackageInfoVO; +import com.logpm.factorydata.jinpai.vo.PushOrderVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -18,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * 工厂订单 前端控制器 * @@ -37,11 +41,11 @@ public class OrderController { @PostMapping @ApiOperationSupport(order = 1) @ApiOperation(value = "工厂订单", notes = "工厂订单") - public R order(@RequestBody DeliveryNoteVO vo) { + public R order(@RequestBody List vo) { log.info("接收工厂订单:{} ", JSONUtil.toJsonStr(vo)); String res = ""; try { - if (ObjectUtil.isNotEmpty(vo)) { + if (CollUtil.isNotEmpty(vo)) { res = service.order(vo); } } catch (Exception e) { @@ -55,11 +59,11 @@ public class OrderController { @PostMapping("orderInfo") @ApiOperationSupport(order = 2) @ApiOperation(value = "工厂订单明细", notes = "工厂订单明细") - public R detail(@RequestBody OrderInfoVO vo) { + public R detail(@RequestBody List vo) { log.info("接收工厂订单明细:{} ", JSONUtil.toJsonStr(vo)); String res = ""; try { - if (ObjectUtil.isNotEmpty(vo)) { + if (CollUtil.isNotEmpty(vo)) { res = service.detail(vo); } } catch (Exception e) { @@ -72,11 +76,11 @@ public class OrderController { @PostMapping("packageInfo") @ApiOperationSupport(order = 3) @ApiOperation(value = "工厂包件信息", notes = "工厂包件信息") - public R packageInfo(@RequestBody PackageInfoVO vo) { + public R packageInfo(@RequestBody List vo) { log.info("接收工厂包件信息:{} ", JSONUtil.toJsonStr(vo)); String res = ""; try { - if (ObjectUtil.isNotEmpty(vo)) { + if (CollUtil.isNotEmpty(vo)) { res = service.packageInfo(vo); } } catch (Exception e) { @@ -85,5 +89,20 @@ public class OrderController { } return R.success(res); } + @ResponseBody + @PostMapping("pushOrder") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "工厂下单接口", notes = "工厂下单接口") + public R pushOrder(@RequestBody PushOrderVO vo) { + log.info("接收工厂下单接口信息:{} ", JSONUtil.toJsonStr(vo)); + String res = ""; + try { + res = service.pushOrder(vo); + } catch (Exception e) { + log.error("接收工厂下单接口信息异常:{} ", e); + return R.success("服务器异常"); + } + return R.success(res); + } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/DeliveryNoteEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/DeliveryNoteEntity.java index 1e029e844..319987dad 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/DeliveryNoteEntity.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/DeliveryNoteEntity.java @@ -111,6 +111,22 @@ public class DeliveryNoteEntity extends BaseEntity { private String trackingStatus; @ApiModelProperty(name = "运输车牌") private String vehicleNo; + @ApiModelProperty(name = "承运运输单位") + private String carrierUnit; + @ApiModelProperty(name = "承运商单号") + private String carrierOrderId; + @ApiModelProperty(name = "备注") + private String departRemark; + @ApiModelProperty(name = "异常签收类型(0:货损,1:少货,2:串货,)") + private String wrongSignType; + @ApiModelProperty(name = "签收状态:wqs=未签收 ycqs=异常签收 zcqs=正常签收") + private String orderSignStatus; + @ApiModelProperty(name = "回单状态 0 未回单 1 已回单") + private String receiptFlag; + @ApiModelProperty(name = "回单份数") + private String receiptNum; + @ApiModelProperty(name = "发货基地: 1=厦门基地,2=泗阳基地,4=橙鸟厦门仓,5=橙鸟佛山仓,6=成都基地") + private String busSource; @ApiModelProperty(name = "预留1", notes = "") private String reserve1; diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryOrderLogEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryOrderLogEntity.java index 48dbb1e03..cac3f0573 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryOrderLogEntity.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryOrderLogEntity.java @@ -44,9 +44,9 @@ public class FactoryOrderLogEntity extends BaseEntity { @ApiModelProperty(name = "日志文件存放地址", notes = "") private String logUrl; /** - * 数据类型 1.入库数据 + * 数据类型 1.拉取数据 2。推送数据 */ - @ApiModelProperty(name = "数据类型 1.入库数据", notes = "") + @ApiModelProperty(name = "数据类型 1.拉取数据 2。推送数据", notes = "") private Integer type; /** * 数据维度:1 订单 2 订单明细 3 包件 diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryToken.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryToken.java new file mode 100644 index 000000000..2e4e7c087 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/FactoryToken.java @@ -0,0 +1,32 @@ +package com.logpm.factorydata.jinpai.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.mp.base.BaseEntity; + +import java.util.Date; + +@Data +@TableName("factory_token") +@ApiModel(value = "FactoryToken对象", description = "工厂账户token") +public class FactoryToken extends BaseEntity { + + @ApiModelProperty("token") + private String token; + + @ApiModelProperty("token摘要") + private String tokenAbst; + + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty("过期时间") + private Date expireTime; + + @ApiModelProperty("企业id") + private String corpid; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PackageInfoEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PackageInfoEntity.java index d47ea6682..f0d7ea3d6 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PackageInfoEntity.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PackageInfoEntity.java @@ -19,6 +19,8 @@ import org.springblade.core.mp.base.BaseEntity; @EqualsAndHashCode(callSuper = true) public class PackageInfoEntity extends BaseEntity { + @ApiModelProperty(name = "推送状态 0 未推 1 已推") + private Integer sendStatus; @ApiModelProperty(name = "日志id") private String logId; @ApiModelProperty(name = "订单明细id") diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderDetailEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderDetailEntity.java new file mode 100644 index 000000000..e8835a3d2 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderDetailEntity.java @@ -0,0 +1,109 @@ +package com.logpm.factorydata.jinpai.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +/** + * 金牌订单明细 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@TableName("jp_push_order_detail") +@ApiModel(value = "金牌订单明细", description = "金牌订单明细") +@EqualsAndHashCode(callSuper = true) +public class PushOrderDetailEntity extends BaseEntity { + + @ApiModelProperty(name = "订单id") + private String orderId; + @ApiModelProperty(name = "日志id") + private String logId; + + @ApiModelProperty(name = "明细编号") + private String itemId; + @ApiModelProperty(name = "发运类型(gx:干线, zy:直运, db:短驳)") + private String transportType; + @ApiModelProperty(name = "发站") + private String sendSite; + @ApiModelProperty(name = "到站") + private String endSite; + @ApiModelProperty(name = "收货联系人名称") + private String recvLinker; + @ApiModelProperty(name = "收货联系人手机") + private String recvMobile; + @ApiModelProperty(name = "收货联系人电话") + private String recvPhone; + @ApiModelProperty(name = "收货地址") + private String recvAddr; + @ApiModelProperty(name = "代收款") + private String codAmount; + @ApiModelProperty(name = "物品名称") + private String goodsName; + @ApiModelProperty(name = "物品数量(件)") + private String goodsNumber; + @ApiModelProperty(name = "物品重量(吨)") + private String goodsWeight; + @ApiModelProperty(name = "物品毛重(吨)") + private String goodsGrossWeight; + @ApiModelProperty(name = "物品净重(吨)") + private String goodsNetWeight; + @ApiModelProperty(name = "物品体积(方)") + private String goodsVolume; + @ApiModelProperty(name = "货品类型") + private String goodsType; + @ApiModelProperty(name = "货品包装说明") + private String goodsPack; + @ApiModelProperty(name = "长") + private String carLength; + @ApiModelProperty(name = "宽") + private String carWidth; + @ApiModelProperty(name = "高") + private String carHeight; + @ApiModelProperty(name = "订单类型(1-零售正单、2-普通零售单、3-样块单、4-增补单、5-返修单、6-缺件单、7-售后单、8-精板或其他)") + private String orderType; + @ApiModelProperty(name = "承运类型编码(编码含义:sfwl- 三方物流;sczp- 干仓配)") + private String shipType; + @ApiModelProperty(name = "送货模式编码(编码含义:gc-wf-基地-外发;sc-zt-干仓配-自提;sc-ps-干仓配-2C;sc-wf-干仓配-2B)") + private String transType; + @ApiModelProperty(name = "门店名称") + private String shopName; + @ApiModelProperty(name = "门店编码") + private String shopCode; + @ApiModelProperty(name = "门店电话") + private String shopPhone; + @ApiModelProperty(name = "门店地址") + private String shopAddr; + @ApiModelProperty(name = "预约送货时间") + private String appointmentTime; + @ApiModelProperty(name = "安装地址") + private String installAddr; + @ApiModelProperty(name = "安装联系人") + private String installLinker; + @ApiModelProperty(name = "安装联系电话") + private String installPhone; + @ApiModelProperty(name = "客户单号(YS单号)") + private String customOrderNo; + @ApiModelProperty(name = "客户明细单号(DD单号)") + private String customItemNo; + @ApiModelProperty(name = "箱码列表") + private String boxCodeList; + @ApiModelProperty(name = "包件品类") + private String boxDetailList; + + @ApiModelProperty(name = "预留1", notes = "") + private String reserve1; + @ApiModelProperty(name = "预留2", notes = "") + private String reserve2; + @ApiModelProperty(name = "预留3", notes = "") + private String reserve3; + @ApiModelProperty(name = "预留4", notes = "") + private String reserve4; + @ApiModelProperty(name = "预留5", notes = "") + private String reserve5; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderEntity.java new file mode 100644 index 000000000..5f23a8cbd --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/PushOrderEntity.java @@ -0,0 +1,62 @@ +package com.logpm.factorydata.jinpai.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +/** + * 金牌推送的下单数据 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@TableName("jp_push_order") +@ApiModel(value = "金牌订单", description = "金牌订单") +@EqualsAndHashCode(callSuper = true) +public class PushOrderEntity extends BaseEntity { + + @ApiModelProperty(name = "日志id") + private String logId; + @ApiModelProperty(name = "装车单号") + private String transportNo; + @ApiModelProperty(name = "计划发车时间(yyyy-MM-dd HH:mm:ss)") + private String planBeginTime; + @ApiModelProperty(name = "计划到达时间(yyyy-MM-dd HH:mm:ss)") + private String planEndTime; + @ApiModelProperty(name = "货品总重量(吨)") + private String goodsTotalWeight; + @ApiModelProperty(name = "货品总数量(件)") + private String goodsTotalNumber; + @ApiModelProperty(name = "货品总体积(方)") + private String goodsTotalVolume; + @ApiModelProperty(name = "始发站") + private String sendSite; + @ApiModelProperty(name = "途经站") + private String passSite; + @ApiModelProperty(name = "终点站") + private String endSite; + @ApiModelProperty(name = "车型") + private String carType; + @ApiModelProperty(name = "车长") + private String carSize; + @ApiModelProperty(name = "制单人") + private String userName; + @ApiModelProperty(name = "基地") + private String orgName; + + @ApiModelProperty(name = "预留1", notes = "") + private String reserve1; + @ApiModelProperty(name = "预留2", notes = "") + private String reserve2; + @ApiModelProperty(name = "预留3", notes = "") + private String reserve3; + @ApiModelProperty(name = "预留4", notes = "") + private String reserve4; + @ApiModelProperty(name = "预留5", notes = "") + private String reserve5; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/enums/BusSourceEnums.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/enums/BusSourceEnums.java new file mode 100644 index 000000000..507198abf --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/enums/BusSourceEnums.java @@ -0,0 +1,24 @@ +package com.logpm.factorydata.jinpai.enums; + +import org.springblade.common.model.IDict; + +/** + * 金牌基地枚举 + * + * @author zhaoqiaobo + * @create 2024-04-28 + */ +public enum BusSourceEnums implements IDict { + + XIAMEN("1", "厦门基地"), + SIYANG("2", "泗阳基地"), + OB_XIAMEN("4", "橙鸟厦门仓"), + OB_FOSHAN("5", "橙鸟佛山仓"), + CHENGDU("6", "成都基地"), + ; + + BusSourceEnums(String code, String text) { + init(code, text); + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/FactoryAccountsInterceptor.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/FactoryAccountsInterceptor.java new file mode 100644 index 000000000..0fe683b2a --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/FactoryAccountsInterceptor.java @@ -0,0 +1,87 @@ +package com.logpm.factorydata.jinpai.interceptor; + +import com.alibaba.fastjson.JSONObject; +import com.logpm.factorydata.jinpai.wrapper.RequestWrapper; +import com.logpm.factorydata.jinpai.service.IFactoryTokenService; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +@Log4j2 +@AllArgsConstructor +public class FactoryAccountsInterceptor implements HandlerInterceptor { + + private final IFactoryTokenService factoryTokenService; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { + try { + + RequestWrapper myRequestWrapper = new RequestWrapper(request); + String body = myRequestWrapper.getBody(); + JSONObject jsonObject = JSONObject.parseObject(body); + //获取头中参数 + String token = request.getHeader("Authorization"); + String corpId = request.getHeader("corpid"); + if(StringUtil.isBlank(corpId)){ + corpId = jsonObject.getString("corpid"); + } + if(!StringUtil.hasLength(token)){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token有误"))); + return false; + } + if(!StringUtil.hasLength(corpId)){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,corpId有误"))); + return false; + } + + log.info("##########preHandle: token={}",token); + //验证token + boolean b = factoryTokenService.verifyToken(token,corpId); + if(!b){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token不存在或已过期"))); + return false; + } + return true; + } catch (Exception e) { + returnJson(response,JSONObject.toJSONString(R.fail(500,"服务异常,请联系管理员"))); + return false; + } + } + + private void returnJson(HttpServletResponse response, String json) { + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + try { + writer = response.getWriter(); + writer.print(json); + + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + if (writer != null){ + writer.close(); + } + } + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + HandlerInterceptor.super.afterCompletion(request, response, handler, ex); + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java new file mode 100644 index 000000000..ceea7ba59 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java @@ -0,0 +1,100 @@ +package com.logpm.factorydata.jinpai.interceptor; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONObject; +import com.logpm.factorydata.jinpai.wrapper.CustomHttpServletRequestWrapper; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.common.cache.CacheNames; +import org.springblade.common.constant.LauncherConstant; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.redis.cache.BladeRedis; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@Log4j2 +@AllArgsConstructor +public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter { + + private final BladeRedis bladeRedis; + private final Environment environment; + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { + + + try { + CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request); + String account ="shujutongbu"; + JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); + if(Objects.isNull(data)){ + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; + HttpRequest urlRequest = HttpRequest.post(url); + urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); + urlRequest.header("Tenant-Id", "627683"); + + Map params = new HashMap<>(); + params.put("grant_type", "local_server"); + params.put("scope", "all"); + params.put("username", account); + params.put("tenantId", "627683"); + HttpResponse execute = urlRequest.form(params).execute(); + String body = execute.body(); + data = JSONObject.parseObject(body); + bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,3200L); + } + + // 修改或添加header + + // 发送登录请求 + log.info("##########preHandle: request={}", request); + + wrappedRequest.addHeader("Blade-Auth", "bearer "+data.getString("access_token")); + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add("Blade-Auth","bearer "+data.get("access_token") ); + httpHeaders.add( "Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); + ThreadLocalUtil.put("bladeContext", httpHeaders); + + + // 用包装后的request替换原始request + request = wrappedRequest; + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); + return true; + } catch (Exception e) { + returnJson(response, JSONObject.toJSONString(R.fail(500, "服务异常,请联系管理员"))); + return false; + } + } + + private void returnJson(HttpServletResponse response, String json) { + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + try { + writer = response.getWriter(); + writer.print(json); + + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + if (writer != null) { + writer.close(); + } + } + } + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java new file mode 100644 index 000000000..27eb6003b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java @@ -0,0 +1,300 @@ +package com.logpm.factorydata.jinpai.job; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; +import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; +import com.logpm.factorydata.enums.BrandEnums; +import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity; +import com.logpm.factorydata.jinpai.entity.OrderInfoEntity; +import com.logpm.factorydata.jinpai.entity.PackageInfoEntity; +import com.logpm.factorydata.jinpai.enums.BusSourceEnums; +import com.logpm.factorydata.jinpai.service.DeliveryNoteService; +import com.logpm.factorydata.jinpai.service.OrderInfoService; +import com.logpm.factorydata.jinpai.service.PackageInfoService; +import com.logpm.factorydata.jinpai.vo.ThirdPlWarehouseMappingVO; +import com.logpm.factorydata.vo.SendMsg; +import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; +import com.logpm.trunkline.entity.TrunklineAdvanceEntity; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.common.constant.HttpConstants; +import org.springblade.common.constant.factorydata.FactoryDataConstants; +import org.springblade.common.model.IDict; +import org.springblade.core.tool.api.R; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author zhaoqiaobo + * @create 2024-04-02 + */ +@AllArgsConstructor +@Component +@Slf4j +public class AdvanceJob { + + private final DeliveryNoteService deliveryNoteService; + private final OrderInfoService orderInfoService; + private final PackageInfoService packageInfoService; + + private final IFactoryDataBaseClient baseClient; + private final IFactoryDataClient factoryDataClient; + + /** + * 定时扫描数据库,保存所有齐套未推送的数据 + * + * @param param + * @return + * @throws Exception + */ + @XxlJob("createAdvance") + public ReturnT createAdvance(String param) throws Exception { + // 查询出齐套未生成暂存单的订单数据 + Map deliveryNoteEntityMap = new HashMap<>(); + Map orderInfoEntityMap = new HashMap<>(); + Map> packageInfoEntityMap = new HashMap<>(); + + Set deliveryNoteSet = new HashSet<>(); + Set orderInfoSet = new HashSet<>(); + // 按dd编号分组 + List list = packageInfoService.list(Wrappers.lambdaQuery().eq(PackageInfoEntity::getSendStatus, 0)); + if (CollUtil.isNotEmpty(list)) { + for (PackageInfoEntity entity : list) { + deliveryNoteSet.add(entity.getOrderId()); + orderInfoSet.add(entity.getOmsExtOrderNo()); + // 将数据封装到packageInfoEntityMap中 其中omsExtOrderNo为key + packageInfoEntityMap.computeIfAbsent(entity.getOmsExtOrderNo(), k -> new ArrayList<>()).add(entity); + } + // 根据订单数据查询出所有订单明细和包件信息 + List deliveryNoteEntities = deliveryNoteService.list(Wrappers.lambdaQuery().in(DeliveryNoteEntity::getOrderId, deliveryNoteSet)); + if (CollUtil.isNotEmpty(deliveryNoteEntities)) { + for (DeliveryNoteEntity entity : deliveryNoteEntities) { + deliveryNoteEntityMap.put(entity.getOrderId(), entity); + } + } + List orderInfoEntities = orderInfoService.list(Wrappers.lambdaQuery().in(OrderInfoEntity::getOmsExtOrderNo, orderInfoSet)); + if (CollUtil.isNotEmpty(orderInfoEntities)) { + for (OrderInfoEntity entity : orderInfoEntities) { + orderInfoEntityMap.put(entity.getOmsExtOrderNo(), entity); + } + } + // 组装数据,然后生成暂存单 + buildAdvance(packageInfoEntityMap, deliveryNoteEntityMap, orderInfoEntityMap); + // 修改包件的发送状态 TODO 后面修改为暂存单消费完成之后回调更新状态 + List updatePackageList = new ArrayList<>(); + for (PackageInfoEntity entity : list) { + PackageInfoEntity updateEntity = new PackageInfoEntity(); + updateEntity.setSendStatus(1); + updateEntity.setId(entity.getId()); + updatePackageList.add(updateEntity); + } + if (CollUtil.isNotEmpty(updatePackageList)) { + packageInfoService.updateBatchById(updatePackageList); + } + } + + return ReturnT.SUCCESS; + } + + @Async("asyncExecutor") + public void buildAdvance(Map> packageMap, Map deliveryMap, + Map orderInfoMap) { + // 新起线程构建暂存单发送mq + // 获取非干线仓库映射表数据 + Map thirdPlWarehouseMapping = new HashMap<>(); + List warehouseMappingVOList = deliveryNoteService.getThirdPlWarehouseMappingVO(); + if (CollUtil.isNotEmpty(warehouseMappingVOList)) { + warehouseMappingVOList.forEach(vo -> { + thirdPlWarehouseMapping.put(vo.getArriveOrgName(), vo); + }); + } + Map warehouseBindVOMap = new HashMap<>(); + if (CollUtil.isNotEmpty(deliveryMap)) { + for (Map.Entry entry : deliveryMap.entrySet()) { + DeliveryNoteEntity deliveryNoteEntity = entry.getValue(); + if (ObjectUtil.isNotEmpty(deliveryNoteEntity)) { + // 获取工厂基地绑定的始发仓信息 + String textByCode = IDict.getTextByCode(BusSourceEnums.class, deliveryNoteEntity.getBusSource()); + R warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(BrandEnums.JP.getValue(), textByCode); + if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { + FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); + if (ObjectUtil.isNotNull(data)) { + warehouseBindVOMap.put(deliveryNoteEntity.getBusSource(), data); + } + } + } + } + } + // 组装暂存单数据 + List advances = new ArrayList<>(); + for (Map.Entry> stringListEntry : packageMap.entrySet()) { + String key = stringListEntry.getKey(); + OrderInfoEntity orderInfo = orderInfoMap.get(key); + if (ObjectUtil.isEmpty(orderInfo)) { + log.error("订单明细信息不存在,dd单号:{}", key); + continue; + } + DeliveryNoteEntity order = deliveryMap.get(orderInfo.getOrderId()); + if (ObjectUtil.isEmpty(order)) { + log.error("订单信息不存在,订单号:{}", orderInfo.getOrderId()); + continue; + } + List value = stringListEntry.getValue(); + TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); + // 承运商是汇通的数据 走干线,不是汇通的直接走仓配。 + String carrierName = order.getCarrierName(); + Long warehouseId = null; + String warehouseName = ""; + String tenantId = ""; + if (ObjectUtil.equal(carrierName, "广州市汇通运输有限公司")) { + if (ObjectUtil.isNotNull(warehouseBindVOMap.get(order.getBusSource()))) { + warehouseId = warehouseBindVOMap.get(order.getBusSource()).getWarehouseId(); + warehouseName = warehouseBindVOMap.get(order.getBusSource()).getWarehouseName(); + tenantId = warehouseBindVOMap.get(order.getBusSource()).getTenantId(); + } + } else { + if (ObjectUtil.isNotNull(thirdPlWarehouseMapping.get(order.getArriveOrgName()))) { + if (ObjectUtil.isNotEmpty(thirdPlWarehouseMapping.get(order.getArriveOrgName()).getWarehouseId())) { + warehouseId = Convert.toLong(thirdPlWarehouseMapping.get(order.getArriveOrgName()).getWarehouseId()); + } + warehouseName = thirdPlWarehouseMapping.get(order.getArriveOrgName()).getWarehouseName(); + tenantId = thirdPlWarehouseMapping.get(order.getArriveOrgName()).getTenantId(); + } + } + advanceEntity.setTenantId(tenantId); + advanceEntity.setStatus(0); + advanceEntity.setIsDeleted(0); + advanceEntity.setHasPackage(CollUtil.isNotEmpty(value) ? 1 : 0); + advanceEntity.setOrderType(orderInfo.getYjOrderType()); + advanceEntity.setBrand(BrandEnums.JP.getValue()); + advanceEntity.setSiteName(IDict.getTextByCode(BusSourceEnums.class, order.getBusSource())); + advanceEntity.setArea(""); + advanceEntity.setTotalNum(CollUtil.isNotEmpty(value) ? value.size() : 0); + advanceEntity.setPackName(""); + advanceEntity.setPackCode(""); + advanceEntity.setWarehouseId(warehouseId); + advanceEntity.setWarehouseName(warehouseName); + + if (StrUtil.equals("sczp", order.getDistributionMode())) { + advanceEntity.setIsGcp(1); + } else { + advanceEntity.setIsGcp(0); + } + advanceEntity.setCarrierName(carrierName); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setSenderName(order.getConsignerName()); + advanceEntity.setSenderPhone(order.getConsignerMobile()); + advanceEntity.setSenderAddress(order.getConsignerAddr()); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setWaybillNo(""); + advanceEntity.setTrainNumber(""); + advanceEntity.setFreezeStatus("0"); + + advanceEntity.setSenderFactory(IDict.getTextByCode(BusSourceEnums.class, order.getBusSource())); + + advanceEntity.setOrderCode(orderInfo.getOmsExtOrderNo()); + advanceEntity.setDealerCode(orderInfo.getShopCode()); + advanceEntity.setDealerName(orderInfo.getShopName()); + advanceEntity.setStoreCode(orderInfo.getShopCode()); + advanceEntity.setStoreName(orderInfo.getShopName()); + advanceEntity.setServiceNum(orderInfo.getOmsExtYsId()); + // 安装 + advanceEntity.setCustomerName(orderInfo.getYjInstallLinker()); + advanceEntity.setCustomerPhone(orderInfo.getYjInstallPhone()); + advanceEntity.setCustomerAddress(orderInfo.getYjInstallAddr()); + advanceEntity.setConsigneePerson(order.getReceiverContacts()); + advanceEntity.setConsigneeMobile(order.getReceiverMobile()); + advanceEntity.setConsigneeAddress(order.getReceiverMobile()); + List packageList = new ArrayList<>(); + + for (PackageInfoEntity orderPackageDTO : value) { + // 封装包件 + TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); + advanceDetailEntity.setWarehouseId(warehouseId); + advanceDetailEntity.setWarehouseName(warehouseName); + // 根据的一流单标识赋值 + advanceEntity.setLegacyStatus("0"); + advanceDetailEntity.setOrderCode(orderPackageDTO.getOmsExtOrderNo()); + advanceDetailEntity.setBrand(BrandEnums.JP.getValue()); + advanceDetailEntity.setSystemType("线上"); + String boxType1 = orderPackageDTO.getBoxType1(); + String boxType2 = orderPackageDTO.getBoxType2(); + String boxType3 = orderPackageDTO.getBoxType3(); + if (StrUtil.isNotEmpty(boxType1)) { + advanceDetailEntity.setFirstPackName(orderPackageDTO.getBoxType1()); + } + if (StrUtil.isNotEmpty(boxType2)) { + advanceDetailEntity.setSecondPackName(orderPackageDTO.getBoxType2()); + } else { + advanceDetailEntity.setSecondPackName(orderPackageDTO.getBoxType1()); + } + if (StrUtil.isNotEmpty(boxType3)) { + advanceDetailEntity.setThirdPackName(orderPackageDTO.getBoxType3()); + } else { + if (StrUtil.isNotEmpty(boxType2)) { + advanceDetailEntity.setThirdPackName(orderPackageDTO.getBoxType2()); + } else { + advanceDetailEntity.setThirdPackName(orderPackageDTO.getBoxType1()); + } + } + advanceDetailEntity.setSiteName(IDict.getTextByCode(BusSourceEnums.class, order.getBusSource())); + advanceDetailEntity.setSiteCode(""); + String planQty = orderPackageDTO.getGoodsNum(); + advanceDetailEntity.setQuantity((StrUtil.isNotBlank(planQty) && NumberUtil.isNumber(planQty)) ? Convert.toInt(planQty) : 0); + advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getExtBoxCode()); + advanceDetailEntity.setTrainNumber(""); + advanceDetailEntity.setServiceNum(orderInfo.getOmsExtYsId()); + advanceDetailEntity.setWaybillNo(""); + advanceDetailEntity.setPackageStatus("0"); + advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getGoodsWeight()) ? new BigDecimal(orderPackageDTO.getGoodsWeight()) : BigDecimal.ZERO); + advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getGoodsVolume()) ? new BigDecimal(orderPackageDTO.getGoodsVolume()) : BigDecimal.ZERO); +// advanceDetailEntity.setChargeType(0); + advanceDetailEntity.setSupple(""); + advanceDetailEntity.setManifest(""); + advanceDetailEntity.setReturnNum(""); + advanceDetailEntity.setSendDateStr(StrUtil.isNotBlank(order.getDepartTime()) ? order.getDepartTime() : DateUtil.formatLocalDateTime(LocalDateTime.now())); + advanceDetailEntity.setCarNumber(order.getCarNo()); + advanceDetailEntity.setGoodsMan(""); + advanceDetailEntity.setTenantId(tenantId); + advanceDetailEntity.setStatus(0); + advanceDetailEntity.setIsDeleted(0); + JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); + packageList.add(entries); + } + // 转成json对象,然后将包件明细放到detail中 + JSONObject entries = JSONUtil.parseObj(advanceEntity); + entries.set("details", JSONUtil.toJsonStr(packageList)); + advances.add(entries); + } + // 将组装好的暂存单发送到 MQ ,由暂存单服务统一消费SendMsg. + if (CollUtil.isNotEmpty(advances)) { + for (JSONObject advance : advances) { + SendMsg sendMsg = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER) + .routingKey(FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER).message(JSONUtil.toJsonStr(advance)).build(); + factoryDataClient.sendMessage(sendMsg); + } + } + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/DeliveryNoteMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/DeliveryNoteMapper.java index 54d3d81dd..a267f4ca1 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/DeliveryNoteMapper.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/DeliveryNoteMapper.java @@ -2,7 +2,11 @@ package com.logpm.factorydata.jinpai.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity; +import com.logpm.factorydata.jinpai.vo.ThirdPlWarehouseMappingVO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 发货单 mapper @@ -13,4 +17,6 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface DeliveryNoteMapper extends BaseMapper { + List getThirdPlWarehouseMappingVO(); + } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryNodeOrderMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryNodeOrderMapper.xml index d68257595..597931489 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryNodeOrderMapper.xml +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryNodeOrderMapper.xml @@ -2,4 +2,9 @@ + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.java new file mode 100644 index 000000000..273494666 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package com.logpm.factorydata.jinpai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.jinpai.entity.FactoryToken; + +/** + * 工厂账号接口日志 Mapper 接口 + * + * @author zhy + * @since 2023-03-28 + */ +public interface FactoryTokenMapper extends BaseMapper { + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.xml new file mode 100644 index 000000000..965bd16f7 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/FactoryTokenMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/OrderInfoMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/OrderInfoMapper.java index 2c2f23fd6..b5f8f9a4f 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/OrderInfoMapper.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/OrderInfoMapper.java @@ -2,6 +2,7 @@ package com.logpm.factorydata.jinpai.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.logpm.factorydata.jinpai.entity.OrderInfoEntity; +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; import org.apache.ibatis.annotations.Mapper; /** diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.java new file mode 100644 index 000000000..a21d2d20b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.java @@ -0,0 +1,16 @@ +package com.logpm.factorydata.jinpai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 订单信息 mapper + * + * @author zqb + * @since 2024-03-26 + */ +@Mapper +public interface PushOrderDetailMapper extends BaseMapper { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.xml new file mode 100644 index 000000000..8b6943909 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderDetailMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.java new file mode 100644 index 000000000..424159375 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.java @@ -0,0 +1,16 @@ +package com.logpm.factorydata.jinpai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 订单信息 mapper + * + * @author zqb + * @since 2024-03-26 + */ +@Mapper +public interface PushOrderMapper extends BaseMapper { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.xml new file mode 100644 index 000000000..28906b91b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/PushOrderMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java index ee60a11b1..a72ca15a7 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java @@ -1,28 +1,65 @@ package com.logpm.factorydata.jinpai.mq; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.URLUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; +import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; +import com.logpm.factorydata.enums.BrandEnums; +import com.logpm.factorydata.enums.SaxStatusEnums; import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity; import com.logpm.factorydata.jinpai.entity.FactoryOrderLogEntity; +import com.logpm.factorydata.jinpai.entity.OrderInfoEntity; +import com.logpm.factorydata.jinpai.entity.PackageInfoEntity; +import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; +import com.logpm.factorydata.jinpai.enums.DimensionEnums; +import com.logpm.factorydata.jinpai.service.DeliveryNoteService; +import com.logpm.factorydata.jinpai.service.FactoryOrderLogService; +import com.logpm.factorydata.jinpai.service.OrderInfoService; +import com.logpm.factorydata.jinpai.service.PackageInfoService; +import com.logpm.factorydata.jinpai.service.PushOrderDetailService; +import com.logpm.factorydata.jinpai.service.PushOrderService; +import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO; +import com.logpm.factorydata.jinpai.vo.OrderInfoVO; +import com.logpm.factorydata.jinpai.vo.PackageCategoryVO; +import com.logpm.factorydata.jinpai.vo.PackageInfoVO; +import com.logpm.factorydata.jinpai.vo.PushOrderDetailVO; +import com.logpm.factorydata.jinpai.vo.PushOrderVO; +import com.logpm.factorydata.vo.SendMsg; +import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; +import com.logpm.trunkline.entity.TrunklineAdvanceEntity; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.PatternConstant; +import org.springblade.common.constant.HttpConstants; import org.springblade.common.constant.factorydata.FactoryDataConstants; import org.springblade.core.redis.cache.BladeRedis; +import org.springblade.core.tool.api.R; import org.springframework.amqp.core.ExchangeTypes; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 监听索菲亚订单数据 @@ -35,6 +72,13 @@ import java.util.regex.Pattern; @AllArgsConstructor public class FactoryOrderListener { + private final PushOrderService pushOrderService; + private final PushOrderDetailService pushOrderDetailService; + private final DeliveryNoteService deliveryNoteService; + private final OrderInfoService orderInfoService; + private final PackageInfoService packageInfoService; + private final FactoryOrderLogService logService; + private final BladeRedis bladeRedis; private final IFactoryDataBaseClient baseClient; private final IFactoryDataClient factoryDataClient; @@ -51,284 +95,347 @@ public class FactoryOrderListener { log.error("消息内容为空"); return; } - FactoryOrderLogEntity vo = JSONUtil.toBean(msg, FactoryOrderLogEntity.class); - if (ObjectUtil.isEmpty(vo)) { + FactoryOrderLogEntity logEntity = JSONUtil.toBean(msg, FactoryOrderLogEntity.class); + if (ObjectUtil.isEmpty(logEntity)) { log.error("消息内容为空"); return; } - // 幂等控制,同一个入库单号只能入一次 + // 去 minio 下载文件到本地,然后解析文件内容为实体对象 + List deliveryNoteVOS = null; + List orderInfoVOS = null; + List packageInfoVOS = null; + PushOrderVO pushOrderVO = null; + Long logId = logEntity.getId(); + String logUrl = logEntity.getLogUrl(); + // 1 订单 2 订单明细 3 包件 + Integer dimension = logEntity.getDimension(); + if (StrUtil.isNotEmpty(logUrl)) { + List res = new ArrayList<>(); + FileUtil.readLines(URLUtil.url(logUrl), CharsetUtil.CHARSET_UTF_8, res); + if (CollUtil.isNotEmpty(res)) { + String content = res.get(0); + if (StrUtil.isNotEmpty(content)) { + // 拉取的数据 + if (ObjectUtil.equal(logEntity.getType(), 1)) { + if (ObjectUtil.equal(dimension, DimensionEnums.ORDER.getCode())) { + deliveryNoteVOS = new JSONArray(content).toList(DeliveryNoteVO.class); + } + if (ObjectUtil.equal(dimension, DimensionEnums.ORDER_DETAIL.getCode())) { + orderInfoVOS = new JSONArray(content).toList(OrderInfoVO.class); + } + if (ObjectUtil.equal(dimension, DimensionEnums.PACKAGE.getCode())) { + packageInfoVOS = new JSONArray(content).toList(PackageInfoVO.class); + } + } else if (ObjectUtil.equal(logEntity.getType(), 2)) { + // 推送的数据 + pushOrderVO = JSONUtil.toBean(content, PushOrderVO.class); + } + } + } + } + if (ObjectUtil.equal(logEntity.getType(), 1)) { + pullData(deliveryNoteVOS, orderInfoVOS, packageInfoVOS, logEntity); + } else if (ObjectUtil.equal(logEntity.getType(), 2)) { + pushData(pushOrderVO, logEntity); + } + } -// if (CollUtil.isNotEmpty(receiptService.list(Wrappers.lambdaQuery().eq(ZbReceiptEntity::getTaskCode, code)))) { -// log.error("渠道单号已推送过了"); -// return; -// } - // 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存 - Set packageCode = new HashSet<>(); -// List details = vo.getDetails(); -// if (CollUtil.isNotEmpty(details)) { -// // 收集包件编码 -// List collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList()); -// if (CollUtil.isNotEmpty(collect)) { -// List packageCodes = orderPackageService.findByPackageCodes(collect); -// if (CollUtil.isNotEmpty(packageCodes)) { -// // 将packageCodes中的数据存到packageCode中 -// packageCodes.forEach(item -> { -// packageCode.add(item.getPackageCode()); -// }); -// } -// } -// } -// ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity(); -// BeanUtil.copyProperties(vo, zbReceiptEntity); -// // 保存订单数据 -// receiptService.save(zbReceiptEntity); -// if (CollUtil.isNotEmpty(details)) { -// List packageEntities = new ArrayList<>(); -// List packageInfoEntities = new ArrayList<>(); -// for (OrderPackageDTO detail : details) { -// if (packageCode.contains(detail.getPackageCode())) { -// log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不保存。", detail.getPackageCode()); -// continue; -// } -// ZbOrderPackageEntity packageEntity = new ZbOrderPackageEntity(); -// BeanUtil.copyProperties(detail, packageEntity); -// packageEntity.setReceiptId(zbReceiptEntity.getId()); -// packageEntities.add(packageEntity); -// } -// // 保存包件数据 -// orderPackageService.saveBatch(packageEntities); -// for (OrderPackageDTO detail : details) { -// if (packageCode.contains(detail.getPackageCode())) { -// continue; -// } -// Long detailId = null; -// for (ZbOrderPackageEntity packageEntity : packageEntities) { -// if (ObjectUtil.equal(packageEntity.getPackageCode(), detail.getPackageCode())) { -// detailId = packageEntity.getId(); -// } -// } -// List items = detail.getItems(); -// if (CollUtil.isNotEmpty(items)) { -// for (PackageInfoDTO item : items) { -// ZbPackageInfoEntity packageInfoEntity = new ZbPackageInfoEntity(); -// BeanUtil.copyProperties(item, packageInfoEntity); -// packageInfoEntity.setPackageId(detailId); -// packageInfoEntities.add(packageInfoEntity); -// } -// } -// } -// // 保存物料数据 -// packageInfoService.saveBatch(packageInfoEntities); -// } - // 处理暂存单 -// buildAdvance(vo, packageCode); + private void pushData(PushOrderVO vo, FactoryOrderLogEntity logEntity) { + if (ObjectUtil.isNotEmpty(vo)) { + // 1 解析数据保存入库 + // 装车单号唯一 + Long logId = logEntity.getId(); + String truckNo = vo.getTransportNo(); + List list = pushOrderService.list(Wrappers.lambdaQuery().eq(PushOrderEntity::getTransportNo, truckNo)); + if (CollUtil.isNotEmpty(list)) { + log.error("装车单号{} 数据已经处理过了, logId: {}", truckNo, logId); + return; + } + vo.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + pushOrderService.save(vo); + List orderInfos = vo.getItems(); + if (CollUtil.isNotEmpty(orderInfos)) { + List infoEntities = new ArrayList<>(); + for (PushOrderDetailVO orderInfo : orderInfos) { + PushOrderDetailEntity orderInfoEntity = new PushOrderDetailEntity(); + BeanUtil.copyProperties(orderInfo, orderInfoEntity); + orderInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + orderInfoEntity.setOrderId(vo.getId().toString()); + List boxCodes = orderInfo.getBoxCodes(); + if (CollUtil.isNotEmpty(boxCodes)) { + orderInfoEntity.setBoxCodeList(JSONUtil.toJsonStr(boxCodes)); + } + List boxDetails = orderInfo.getBoxDetails(); + if (CollUtil.isNotEmpty(boxDetails)) { + orderInfoEntity.setBoxDetailList(JSONUtil.toJsonStr(boxDetails)); + } + infoEntities.add(orderInfoEntity); + } + pushOrderDetailService.saveBatch(infoEntities); + } + // 2 构建暂存单,发送 mq 消息 + FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity(); + logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode()); + logEntity1.setId(logId); + logService.saveOrUpdate(logEntity1); + // 处理暂存单 + buildAdvance(vo); + } } -// private void buildAdvance(DeliveryNoteVO vo, Set packageCode) { -// // 新起线程构建暂存单发送mq -// ThreadPoolUtil.getThreadPool().submit(() -> { -// Long startWarehouseId = null; -// String startWarehouseName = null; -// String tenantId = null; -// // 获取工厂基地绑定的始发仓信息 -// R warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(vo.getSenderName(), vo.getSenderName()); -// if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { -// FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); -// if (ObjectUtil.isNotNull(data)) { -// startWarehouseId = data.getWarehouseId(); -// startWarehouseName = data.getWarehouseName(); -// tenantId = data.getTenantId(); -// } -// } -// Map> advanceMap = new HashMap<>(); -// List details = vo.getDetails(); -// // 入库单号 + 订单自编号 + 发车单号 一个暂存单 -// for (OrderPackageDTO detail : details) { -// if (packageCode.contains(detail.getPackageCode())) { -// log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不生成暂存单。", detail.getPackageCode()); -// continue; -// } -// String taskCode = vo.getTaskCode(); -// String departCode = vo.getDepartCode(); -// String platformOrderCode = detail.getPlatformOrderCode(); -// String advanceKey = taskCode + departCode + platformOrderCode; -// if (advanceMap.containsKey(advanceKey)) { -// advanceMap.get(advanceKey).add(detail); -// } else { -// ArrayList orderPackageDTOS = new ArrayList<>(); -// orderPackageDTOS.add(detail); -// advanceMap.put(advanceKey, orderPackageDTOS); -// } -// } -// // 组装暂存单数据 -// List advances = new ArrayList<>(); -// for (Map.Entry> stringListEntry : advanceMap.entrySet()) { -// List value = stringListEntry.getValue(); -// TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); -// advanceEntity.setTenantId(tenantId); -// advanceEntity.setStatus(0); -// advanceEntity.setIsDeleted(0); -// advanceEntity.setHasPackage(CollUtil.isNotEmpty(vo.getDetails()) ? 1 : 0); -// advanceEntity.setOrderType(vo.getOrderType()); -// advanceEntity.setBrand(vo.getSenderName()); -// advanceEntity.setSiteName(""); -// advanceEntity.setArea(""); -// advanceEntity.setTotalNum(CollUtil.isNotEmpty(value) ? value.size() : 0); -// advanceEntity.setPackName(""); -// advanceEntity.setPackCode(""); -// advanceEntity.setWarehouseId(startWarehouseId); -// advanceEntity.setWarehouseName(startWarehouseName); -// -// advanceEntity.setIsGcp(0); -// advanceEntity.setCarrierName(vo.getVendorName()); -// advanceEntity.setSystemType("线上"); -// advanceEntity.setMatingType(""); -// advanceEntity.setSenderName(vo.getSenderName()); -// advanceEntity.setSenderPhone(vo.getSenderTel()); -// advanceEntity.setSenderAddress(vo.getSenderAddress()); -// advanceEntity.setWaybillStatus("0"); -// advanceEntity.setWaybillNo(""); -// advanceEntity.setTrainNumber(vo.getDepartCode()); -// advanceEntity.setFreezeStatus("0"); -// -// advanceEntity.setSenderFactory(vo.getSenderName()); -// List packageList = new ArrayList<>(); -// for (OrderPackageDTO orderPackageDTO : value) { -// advanceEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); -// advanceEntity.setDealerCode(orderPackageDTO.getCustomerCode()); -// advanceEntity.setDealerName(orderPackageDTO.getCustomerName()); -// advanceEntity.setStoreCode(orderPackageDTO.getCustomerCode()); -// advanceEntity.setStoreName(orderPackageDTO.getCustomerName()); -// advanceEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); -// advanceEntity.setCustomerName(orderPackageDTO.getReceiverName()); -// advanceEntity.setCustomerPhone(orderPackageDTO.getReceiverMobile()); -// advanceEntity.setCustomerAddress(orderPackageDTO.getReceiverAddress()); -// -// // 封装包件 -// TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); -// advanceDetailEntity.setWarehouseId(startWarehouseId); -// advanceDetailEntity.setWarehouseName(startWarehouseName); -//// advanceDetailEntity.setIncomingWarehouseId(0L); -//// advanceDetailEntity.setIncomingWarehouseName(""); -// // 根据志邦的一流单标识赋值 -// advanceEntity.setLegacyStatus("0"); -// if (ObjectUtil.equal(orderPackageDTO.getLegacyFlag(), "Y")) { -// advanceEntity.setLegacyStatus("1"); -// } -// -// advanceDetailEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); -// advanceDetailEntity.setBrand(vo.getSenderName()); -// advanceDetailEntity.setSystemType("线上"); -// advanceDetailEntity.setFirstPackName(orderPackageDTO.getPackageTypeName()); -// advanceDetailEntity.setFirstPackCode(orderPackageDTO.getPackageType()); -// // 获取映射志邦映射品类信息 -// ZbCategoryContrastEntity zbCategoryContrastEntity = buildZbCategoryContrastEntityCache(orderPackageDTO.getPackageClass()); -// if (zbCategoryContrastEntity != null) { -// advanceDetailEntity.setSecondPackName(zbCategoryContrastEntity.getSecondName());//二级品类名称 -// advanceDetailEntity.setSecondPackCode(zbCategoryContrastEntity.getSecondCode());//二级品类 -// advanceDetailEntity.setThirdPackName(zbCategoryContrastEntity.getThirdName());//三级品类名称 -// advanceDetailEntity.setThirdPackCode(zbCategoryContrastEntity.getThirdCode());//三级品类 -// } else { -// advanceDetailEntity.setSecondPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//二级品类名称 -// advanceDetailEntity.setSecondPackCode("");//二级品类 -// advanceDetailEntity.setThirdPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//三级品类名称 -// advanceDetailEntity.setThirdPackCode("");//三级品类 -// } -// advanceDetailEntity.setSiteName(""); -// advanceDetailEntity.setSiteCode(""); -// String planQty = orderPackageDTO.getPlanQty(); -// advanceDetailEntity.setQuantity((StrUtil.isNotBlank(planQty) && NumberUtil.isNumber(planQty)) ? Convert.toInt(planQty) : 0); -// advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getPackageCode()); -// advanceDetailEntity.setTrainNumber(vo.getDepartCode()); -// advanceDetailEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); -// advanceDetailEntity.setWaybillNo(""); -// advanceDetailEntity.setPackageStatus("0"); -// advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getTotalGrossWeight()) ? new BigDecimal(orderPackageDTO.getTotalGrossWeight()) : BigDecimal.ZERO); -// advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getTotalVolume()) ? new BigDecimal(orderPackageDTO.getTotalVolume()) : BigDecimal.ZERO); -//// advanceDetailEntity.setChargeType(0); -// advanceDetailEntity.setSupple(""); -// advanceDetailEntity.setManifest(""); -// advanceDetailEntity.setReturnNum(""); -// advanceDetailEntity.setSendDateStr(DateUtil.formatLocalDateTime(LocalDateTime.now())); -// advanceDetailEntity.setCarNumber(""); -// advanceDetailEntity.setGoodsMan(""); -// advanceDetailEntity.setTenantId(tenantId); -// advanceDetailEntity.setStatus(0); -// advanceDetailEntity.setIsDeleted(0); -// List itemJsons = new ArrayList<>(); -// List items = orderPackageDTO.getItems(); -// for (PackageInfoDTO item : items) { -// TrunklineDetailProductEntity detailProductEntity = new TrunklineDetailProductEntity(); -// detailProductEntity.setTenantId(tenantId); -// detailProductEntity.setWarehouseId(startWarehouseId); -// detailProductEntity.setWarehouseName(startWarehouseName); -// detailProductEntity.setUnitNo(orderPackageDTO.getPackageCode()); -// detailProductEntity.setProductCode(item.getItemCode()); -// detailProductEntity.setProductName(item.getItemName()); -// detailProductEntity.setQuantity(item.getPlanQty()); -// detailProductEntity.setTenantId(TenantNum.HUITONGCODE); -// detailProductEntity.setStatus(0); -// detailProductEntity.setIsDeleted(0); -// itemJsons.add(JSONUtil.parseObj(detailProductEntity)); -// } -// JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); -// entries.set("items", itemJsons); -// packageList.add(entries); -// } -// // 转成json对象,然后将包件明细放到detail中 -// JSONObject entries = JSONUtil.parseObj(advanceEntity); -// entries.set("details", JSONUtil.toJsonStr(packageList)); -// advances.add(entries); -// } -// // 将组装好的暂存单发送到 MQ ,由暂存单服务统一消费SendMsg. -// if (CollUtil.isNotEmpty(advances)) { -// for (JSONObject advance : advances) { -// SendMsg sendMsg = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER) -// .routingKey(FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER).message(JSONUtil.toJsonStr(advance)).build(); -// factoryDataClient.sendMessage(sendMsg); -// } -// } -// }); -// } -// -// private ZbCategoryContrastEntity buildZbCategoryContrastEntityCache(String packageClass) { -// -// -// if (StringUtil.isBlank(packageClass)) { -// return null; -// } -// if (containsChinese(packageClass)) { -// return null; -// } -// -// String key = TenantNum.HUITONGCODE + ":" + ZbCategoryContrastEntity.class.getName() + ":" + packageClass; -// ZbCategoryContrastEntity zbCategoryContrastEntity = bladeRedis.get(key); -// if (zbCategoryContrastEntity == null) { -// QueryWrapper queryWrapper = new QueryWrapper<>(); -// queryWrapper.eq("source_code", packageClass); -// queryWrapper.eq("status", "1"); -// zbCategoryContrastEntity = zbCategoryContrastMapper.selectOne(queryWrapper); -// if (!Objects.isNull(zbCategoryContrastEntity)) { -// // 缓存起来 -// bladeRedis.setEx(key, zbCategoryContrastEntity, 3600 * 24L); -// } -// } -// return zbCategoryContrastEntity; -// -// -// } + @Async("asyncExecutor") + public void buildAdvance(PushOrderVO vo) { + // 新起线程构建暂存单发送mq + Long startWarehouseId = null; + String startWarehouseName = null; + String tenantId = null; + // 获取工厂基地绑定的始发仓信息 + List details = vo.getItems(); + if (CollUtil.isEmpty(details)) { + return; + } + R warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(BrandEnums.JP.getValue(), vo.getOrgName()); + if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { + FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); + if (ObjectUtil.isNotNull(data)) { + startWarehouseId = data.getWarehouseId(); + startWarehouseName = data.getWarehouseName(); + tenantId = data.getTenantId(); + } + } + Map> advanceMap = new HashMap<>(); + // 一个dd单号 一个暂存单 + // 组装暂存单数据 + List advances = new ArrayList<>(); + for (PushOrderDetailVO orderInfoVO : details) { + List packageList = new ArrayList<>(); + TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); + List boxCodes = orderInfoVO.getBoxCodes(); + advanceEntity.setTenantId(tenantId); + advanceEntity.setStatus(0); + advanceEntity.setIsDeleted(0); + advanceEntity.setHasPackage(CollUtil.isNotEmpty(boxCodes) ? 1 : 0); + advanceEntity.setOrderType(""); + advanceEntity.setBrand(BrandEnums.JP.getValue()); + advanceEntity.setSiteName(vo.getOrgName()); + advanceEntity.setArea(""); + advanceEntity.setTotalNum(StrUtil.isNotEmpty(orderInfoVO.getGoodsNumber()) ? Convert.toInt(orderInfoVO.getGoodsNumber()) : 0); + advanceEntity.setPackName(""); + advanceEntity.setPackCode(""); + advanceEntity.setWarehouseId(startWarehouseId); + advanceEntity.setWarehouseName(startWarehouseName); + + advanceEntity.setIsGcp(0); + advanceEntity.setCarrierName(""); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setSenderName(""); + advanceEntity.setSenderPhone(""); + advanceEntity.setSenderAddress(""); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setWaybillNo(""); + advanceEntity.setTrainNumber(vo.getTransportNo()); + advanceEntity.setFreezeStatus("0"); + advanceEntity.setOrderCode(orderInfoVO.getCustomItemNo()); + advanceEntity.setServiceNum(orderInfoVO.getCustomOrderNo()); + advanceEntity.setSenderFactory(vo.getOrgName()); + // 门店是商场 + advanceEntity.setDealerCode(orderInfoVO.getShopCode()); + advanceEntity.setDealerName(orderInfoVO.getShopName()); + advanceEntity.setStoreCode(orderInfoVO.getShopCode()); + advanceEntity.setStoreName(orderInfoVO.getShopName()); + // 安装是客户 + advanceEntity.setCustomerName(orderInfoVO.getInstallLinker()); + advanceEntity.setCustomerPhone(orderInfoVO.getInstallPhone()); + advanceEntity.setCustomerAddress(orderInfoVO.getInstallAddr()); + // 收货人就是商场收货人 + advanceEntity.setConsigneePerson(orderInfoVO.getRecvLinker()); + advanceEntity.setConsigneeMobile(orderInfoVO.getRecvPhone()); + advanceEntity.setConsigneeAddress(orderInfoVO.getRecvAddr()); + // 根据遗留单标识赋值 + advanceEntity.setLegacyStatus("0"); + if (StrUtil.contains(orderInfoVO.getCustomItemNo(), "遗")) { + advanceEntity.setLegacyStatus("1"); + } + // 封装包件品类信息 + Map categoryVOMap = new HashMap<>(); + List boxDetails = orderInfoVO.getBoxDetails(); + if (CollUtil.isNotEmpty(boxDetails)) { + for (PackageCategoryVO packageCategoryVO : boxDetails) { + categoryVOMap.put(packageCategoryVO.getExtBoxCode(), packageCategoryVO); + } + } + for (String packageCode : boxCodes) { + // 封装包件 + TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); + advanceDetailEntity.setWarehouseId(startWarehouseId); + advanceDetailEntity.setWarehouseName(startWarehouseName); - /** - * 验证参数中是否包含中文 - * - * @param str 匹配参数 - * @return true 包含中文 false 不包含中文 - */ - private boolean containsChinese(String str) { - Pattern pattern = Pattern.compile(PatternConstant.REGEX_CHINESE); - Matcher matcher = pattern.matcher(str); - return matcher.find(); + advanceDetailEntity.setOrderCode(orderInfoVO.getCustomItemNo()); + advanceDetailEntity.setBrand(BrandEnums.JP.getValue()); + advanceDetailEntity.setSystemType("线上"); + // 获取映射品类信息 + PackageCategoryVO categoryVO = categoryVOMap.get(packageCode); + if (ObjectUtil.isNotEmpty(categoryVO)) { + // 一级品类名称 + if (StrUtil.isNotEmpty(categoryVO.getTypea())) { + advanceDetailEntity.setFirstPackName(categoryVO.getTypea()); + advanceDetailEntity.setMaterialName(categoryVO.getTypea()); + } + // 二级品类名称 + if (StrUtil.isNotEmpty(categoryVO.getTypeb())) { + advanceDetailEntity.setSecondPackName(categoryVO.getTypeb()); + } else { + advanceDetailEntity.setSecondPackName(categoryVO.getTypea()); + } + // 三级品类名称 + if (StrUtil.isNotEmpty(categoryVO.getTypec())) { + advanceDetailEntity.setThirdPackName(categoryVO.getTypec()); + } else { + if (StrUtil.isNotEmpty(categoryVO.getTypeb())) { + advanceDetailEntity.setThirdPackName(categoryVO.getTypeb()); + } else { + advanceDetailEntity.setThirdPackName(categoryVO.getTypea()); + } + } + } + advanceDetailEntity.setSiteName(vo.getOrgName()); + advanceDetailEntity.setSiteCode(""); + advanceDetailEntity.setQuantity(1); + advanceDetailEntity.setOrderPackageCode(packageCode); + advanceDetailEntity.setTrainNumber(vo.getTransportNo()); + advanceDetailEntity.setServiceNum(orderInfoVO.getCustomOrderNo()); + advanceDetailEntity.setWaybillNo(""); + advanceDetailEntity.setPackageStatus("0"); +// advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getWeight()) ? new BigDecimal(orderPackageDTO.getWeight()) : BigDecimal.ZERO); +// advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getVolume()) ? new BigDecimal(orderPackageDTO.getVolume()) : BigDecimal.ZERO); +// advanceDetailEntity.setChargeType(0); + advanceDetailEntity.setSupple(""); + advanceDetailEntity.setManifest(""); + advanceDetailEntity.setReturnNum(""); + advanceDetailEntity.setSendDateStr(DateUtil.formatLocalDateTime(LocalDateTime.now())); + advanceDetailEntity.setCarNumber(""); + advanceDetailEntity.setGoodsMan(""); + advanceDetailEntity.setTenantId(tenantId); + advanceDetailEntity.setStatus(0); + advanceDetailEntity.setIsDeleted(0); + JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); + packageList.add(entries); + } + // 转成json对象,然后将包件明细放到detail中 + JSONObject entries = JSONUtil.parseObj(advanceEntity); + entries.set("details", JSONUtil.toJsonStr(packageList)); + advances.add(entries); + } + // 将组装好的暂存单发送到 MQ ,由暂存单服务统一消费SendMsg. + if (CollUtil.isNotEmpty(advances)) { + for (JSONObject advance : advances) { + SendMsg sendMsg = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER) + .routingKey(FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER).message(JSONUtil.toJsonStr(advance)).build(); + factoryDataClient.sendMessage(sendMsg); + } + } + } + + private void pullData(List deliveryNoteVOS, List orderInfoVOS, List packageInfoVOS, FactoryOrderLogEntity logEntity) { + if (CollUtil.isNotEmpty(deliveryNoteVOS)) { + List entities = new ArrayList<>(); + List orderCodes = new ArrayList<>(); + for (DeliveryNoteVO deliveryNoteVO : deliveryNoteVOS) { + orderCodes.add(deliveryNoteVO.getOrderId()); + } + List list = deliveryNoteService.list(Wrappers.lambdaQuery() + .in(DeliveryNoteEntity::getOrderId, orderCodes)); + Map map = new HashMap<>(); + if (CollUtil.isNotEmpty(list)) { + // 将list中的数据封装到map中 + list.forEach(item -> { + map.put(item.getOrderId(), item.getOrderId()); + }); + } + for (DeliveryNoteVO deliveryNoteVO : deliveryNoteVOS) { + if (map.containsKey(deliveryNoteVO.getOrderId())) { + log.error("订单号:{},已推送过了", deliveryNoteVO.getOrderId()); + continue; + } + DeliveryNoteEntity deliveryNoteEntity = new DeliveryNoteEntity(); + BeanUtil.copyProperties(deliveryNoteVO, deliveryNoteEntity); + deliveryNoteEntity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null); + entities.add(deliveryNoteEntity); + } + if (CollUtil.isNotEmpty(entities)) { + deliveryNoteService.saveBatch(entities); + } + } + if (CollUtil.isNotEmpty(orderInfoVOS)) { + List entities = new ArrayList<>(); + List orderCodes = new ArrayList<>(); + for (OrderInfoVO orderInfoVO : orderInfoVOS) { + orderCodes.add(orderInfoVO.getOrderId()); + } + List list = orderInfoService.list(Wrappers.lambdaQuery() + .in(OrderInfoEntity::getOmsExtOrderNo, orderCodes)); + Map map = new HashMap<>(); + if (CollUtil.isNotEmpty(list)) { + // 将list中的数据封装到map中 + list.forEach(item -> { + map.put(item.getOmsExtOrderNo(), item.getOmsExtOrderNo()); + }); + } + for (OrderInfoVO vo : orderInfoVOS) { + if (map.containsKey(vo.getOmsExtOrderNo())) { + log.error("DD单号:{},已推送过了", vo.getOmsExtOrderNo()); + continue; + } + OrderInfoEntity deliveryNoteEntity = new OrderInfoEntity(); + BeanUtil.copyProperties(vo, deliveryNoteEntity); + deliveryNoteEntity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null); + entities.add(deliveryNoteEntity); + } + if (CollUtil.isNotEmpty(entities)) { + orderInfoService.saveBatch(entities); + } + } + if (CollUtil.isNotEmpty(packageInfoVOS)) { + List entities = new ArrayList<>(); + List orderCodes = new ArrayList<>(); + List packageCodes = new ArrayList<>(); + for (PackageInfoVO orderInfoVO : packageInfoVOS) { + orderCodes.add(orderInfoVO.getOmsExtOrderNo()); + packageCodes.add(orderInfoVO.getExtBoxCode()); + } + List list = packageInfoService.list(Wrappers.lambdaQuery() + .in(PackageInfoEntity::getOmsExtOrderNo, orderCodes) + .in(PackageInfoEntity::getExtBoxCode, packageCodes) + ); + Map map = new HashMap<>(); + if (CollUtil.isNotEmpty(list)) { + // 将list中的数据封装到map中 + list.forEach(item -> { + map.put(item.getOmsExtOrderNo() + item.getExtBoxCode(), item.getOmsExtOrderNo()); + }); + } + for (PackageInfoVO vo : packageInfoVOS) { + if (map.containsKey(vo.getOmsExtOrderNo() + vo.getExtBoxCode())) { + log.error("DD单号:{} + 箱码:{},已推送过了", vo.getOmsExtOrderNo(), vo.getExtBoxCode()); + continue; + } + PackageInfoEntity entity = new PackageInfoEntity(); + BeanUtil.copyProperties(vo, entity); + entity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null); + entities.add(entity); + } + if (CollUtil.isNotEmpty(entities)) { + packageInfoService.saveBatch(entities); + } + } + // 处理暂存单 通过定时任务扫描的方式判定是否齐套 然后创建暂存单 + FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity(); + logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode()); + logEntity1.setId(logEntity.getId()); + logService.saveOrUpdate(logEntity1); } + } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/DeliveryNoteService.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/DeliveryNoteService.java index 2e82cfcb2..95f14a8dc 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/DeliveryNoteService.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/DeliveryNoteService.java @@ -4,8 +4,12 @@ import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity; import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO; import com.logpm.factorydata.jinpai.vo.OrderInfoVO; import com.logpm.factorydata.jinpai.vo.PackageInfoVO; +import com.logpm.factorydata.jinpai.vo.PushOrderVO; +import com.logpm.factorydata.jinpai.vo.ThirdPlWarehouseMappingVO; import org.springblade.core.mp.base.BaseService; +import java.util.List; + /** * 索菲亚发货单 服务类 * @@ -14,9 +18,13 @@ import org.springblade.core.mp.base.BaseService; **/ public interface DeliveryNoteService extends BaseService { - String order(DeliveryNoteVO vo); + String order(List vo); + + String detail(List vo); + + String packageInfo(List vo); - String detail(OrderInfoVO vo); + List getThirdPlWarehouseMappingVO(); - String packageInfo(PackageInfoVO vo); + String pushOrder(PushOrderVO vo); } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/IFactoryTokenService.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/IFactoryTokenService.java new file mode 100644 index 000000000..83658b274 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/IFactoryTokenService.java @@ -0,0 +1,15 @@ +package com.logpm.factorydata.jinpai.service; + +import com.logpm.factorydata.jinpai.entity.FactoryToken; +import org.springblade.core.mp.base.BaseService; + +import java.security.NoSuchAlgorithmException; + +/** + * 工厂推送数据接口 + */ +public interface IFactoryTokenService extends BaseService { + + + boolean verifyToken(String token, String corpId) throws NoSuchAlgorithmException; +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderDetailService.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderDetailService.java new file mode 100644 index 000000000..855cf1541 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderDetailService.java @@ -0,0 +1,14 @@ +package com.logpm.factorydata.jinpai.service; + +import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * 订单 服务类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +public interface PushOrderDetailService extends BaseService { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderService.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderService.java new file mode 100644 index 000000000..7b2745f08 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/PushOrderService.java @@ -0,0 +1,14 @@ +package com.logpm.factorydata.jinpai.service; + +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * 订单 服务类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +public interface PushOrderService extends BaseService { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/DeliveryNoteServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/DeliveryNoteServiceImpl.java index 33b4be61e..4f37587ae 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/DeliveryNoteServiceImpl.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/DeliveryNoteServiceImpl.java @@ -14,6 +14,8 @@ import com.logpm.factorydata.jinpai.service.FactoryOrderLogService; import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO; import com.logpm.factorydata.jinpai.vo.OrderInfoVO; import com.logpm.factorydata.jinpai.vo.PackageInfoVO; +import com.logpm.factorydata.jinpai.vo.PushOrderVO; +import com.logpm.factorydata.jinpai.vo.ThirdPlWarehouseMappingVO; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -25,8 +27,10 @@ import org.springblade.common.constant.factorydata.FactoryDataConstants; import org.springblade.common.utils.FileLogsUtil; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.oss.model.BladeFile; +import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.tool.api.R; import org.springblade.resource.feign.IOssClient; +import org.springframework.cache.annotation.Cacheable; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -36,6 +40,7 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; +import java.util.List; /** * 发货单 业务实现类 @@ -51,11 +56,12 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl vo) { // 1 上传数据到 minio 获取到地址 - String url = uploadFile(JSONObject.toJSONString(vo)); + String url = uploadFile(JSONUtil.toJsonStr(vo)); // 2 保存地址到数据库 FactoryOrderLogEntity logEntity = new FactoryOrderLogEntity(); logEntity.setType(1); @@ -72,9 +78,9 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl vo) { // 1 上传数据到 minio 获取到地址 - String url = uploadFile(JSONObject.toJSONString(vo)); + String url = uploadFile(JSONUtil.toJsonStr(vo)); // 2 保存地址到数据库 FactoryOrderLogEntity logEntity = new FactoryOrderLogEntity(); logEntity.setType(1); @@ -91,9 +97,9 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl vo) { // 1 上传数据到 minio 获取到地址 - String url = uploadFile(JSONObject.toJSONString(vo)); + String url = uploadFile(JSONUtil.toJsonStr(vo)); // 2 保存地址到数据库 FactoryOrderLogEntity logEntity = new FactoryOrderLogEntity(); logEntity.setType(1); @@ -108,6 +114,29 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl getThirdPlWarehouseMappingVO() { + return this.baseMapper.getThirdPlWarehouseMappingVO(); + } + + @Override + public String pushOrder(PushOrderVO vo) { + // 1 上传数据到 minio 获取到地址 + String url = uploadFile(JSONUtil.toJsonStr(vo)); + // 2 保存地址到数据库 + FactoryOrderLogEntity logEntity = new FactoryOrderLogEntity(); + logEntity.setType(2); + logEntity.setSaxStatus(SaxStatusEnums.NOMAL.getCode()); + logEntity.setLogUrl(url); + factoryOrderLogService.save(logEntity); + // 3 将消息发送给 mq,解析保存 + SendMsg build = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER) + .routingKey(FactoryDataConstants.Mq.RoutingKeys.JP_FACTORY_ORDER).message(JSONUtil.toJsonStr(logEntity)).build(); + factoryDataClient.sendMessage(build); + return "成功"; + } + private String uploadFile(String body) { //文本内容和保存为本地文件 并上传 String logPath = FileLogsUtil.saveFileLogs(body); diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/FactoryTokenServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/FactoryTokenServiceImpl.java new file mode 100644 index 000000000..82493df5c --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/FactoryTokenServiceImpl.java @@ -0,0 +1,62 @@ +package com.logpm.factorydata.jinpai.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.logpm.factorydata.jinpai.entity.FactoryToken; +import com.logpm.factorydata.jinpai.mapper.FactoryTokenMapper; +import com.logpm.factorydata.jinpai.service.IFactoryTokenService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.redis.cache.BladeRedis; +import org.springframework.stereotype.Service; + +import java.security.NoSuchAlgorithmException; +import java.util.Objects; + +@AllArgsConstructor +@Service +public class FactoryTokenServiceImpl extends BaseServiceImpl implements IFactoryTokenService { + + private static final Logger logger = LoggerFactory.getLogger(FactoryTokenServiceImpl.class); + + private final BladeRedis bladeRedis; + + @Override + public boolean verifyToken(String token, String corpId) throws NoSuchAlgorithmException { + logger.info("#########verifyToken: 验证token开始"); + //先生成token摘要 +// String tokenAbst = MD5Utils.md5Hex(token.getBytes(StandardCharsets.UTF_8)); + + //编写查询条件 + String key = "corpId:" + corpId; + FactoryToken factoryToken = bladeRedis.get(key); + + if (Objects.isNull(factoryToken)) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("token", token); + factoryToken = baseMapper.selectOne(queryWrapper); + } + + + if (Objects.isNull(factoryToken)) { + logger.error("#########verifyToken: token1验证不通过 token={},corpid={}", token, corpId); + return false; + } + logger.info("#########verifyToken: 验证token 传入token {} 验证token {}", token, factoryToken.getToken()); + if (!factoryToken.getToken().equals(token)) { + logger.error("#########verifyToken: token2验证不通过 token={},corpid={}", token, corpId); + return false; + } + + + Long expireTimeLong = factoryToken.getExpireTime().getTime(); + Long now = System.currentTimeMillis(); + //判断是否过期 + if (now > expireTimeLong) { + logger.error("#########verifyToken: token验证不通过 已过期 token={},corpId={}", token, corpId); + return false; + } + return true; + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderDetailServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderDetailServiceImpl.java new file mode 100644 index 000000000..d19922bfd --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderDetailServiceImpl.java @@ -0,0 +1,22 @@ +package com.logpm.factorydata.jinpai.service.impl; + +import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; +import com.logpm.factorydata.jinpai.mapper.PushOrderDetailMapper; +import com.logpm.factorydata.jinpai.service.PushOrderDetailService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * 订单信息 业务实现类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +@Slf4j +@Service +@AllArgsConstructor +public class PushOrderDetailServiceImpl extends BaseServiceImpl implements PushOrderDetailService { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderServiceImpl.java new file mode 100644 index 000000000..af240be20 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/PushOrderServiceImpl.java @@ -0,0 +1,22 @@ +package com.logpm.factorydata.jinpai.service.impl; + +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; +import com.logpm.factorydata.jinpai.mapper.PushOrderMapper; +import com.logpm.factorydata.jinpai.service.PushOrderService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * 订单信息 业务实现类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +@Slf4j +@Service +@AllArgsConstructor +public class PushOrderServiceImpl extends BaseServiceImpl implements PushOrderService { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/util/ThreadPoolUtil.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/util/ThreadPoolUtil.java deleted file mode 100644 index 1c65fa628..000000000 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/util/ThreadPoolUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.logpm.factorydata.jinpai.util; - -import cn.hutool.core.thread.ExecutorBuilder; -import cn.hutool.core.thread.ThreadFactoryBuilder; -import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.ExecutorService; - -/** - * @author zhaoqiaobo - * @create 2024-03-14 10:26 - */ -@Slf4j -public class ThreadPoolUtil { - - private ThreadPoolUtil() { - } - - /** - * 线程池 - */ - public static ExecutorService executor = null; - - static { - init(); - } - - synchronized public static void init() { - if (null != executor) { - executor.shutdownNow(); - } - executor = ExecutorBuilder.create() - .setCorePoolSize(8) - .setMaxPoolSize(20) - .setThreadFactory(ThreadFactoryBuilder.create().setNamePrefix("logpm-factory-data-sfy-").build()) - .useSynchronousQueue().build(); - } - - public static ExecutorService getThreadPool() { - return executor; - } - -} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PackageCategoryVO.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PackageCategoryVO.java new file mode 100644 index 000000000..5ffbb7241 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PackageCategoryVO.java @@ -0,0 +1,26 @@ +package com.logpm.factorydata.jinpai.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author zhaoqiaobo + * @create 2024-04-30 + */ +@Data +public class PackageCategoryVO implements Serializable { + + @ApiModelProperty(name = "一级品类") + private String typea; + @ApiModelProperty(name = "二级品类") + private String typeb; + @ApiModelProperty(name = "三级品类") + private String typec; + @ApiModelProperty(name = "包件码") + private String extBoxCode; + @ApiModelProperty(name = "包件类型") + private String extBoxType; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderDetailVO.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderDetailVO.java new file mode 100644 index 000000000..766bf94ad --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderDetailVO.java @@ -0,0 +1,28 @@ +package com.logpm.factorydata.jinpai.vo; + +import cn.hutool.json.JSONObject; +import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * 金牌下单明细 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@ApiModel(value = "金牌下单明细", description = "金牌下单明细") +@EqualsAndHashCode(callSuper = true) +public class PushOrderDetailVO extends PushOrderDetailEntity { + + @ApiModelProperty(name = "箱码列表") + private List boxCodes; + @ApiModelProperty(name = "包件品类") + private List boxDetails; +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderVO.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderVO.java new file mode 100644 index 000000000..0ae37565b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/PushOrderVO.java @@ -0,0 +1,25 @@ +package com.logpm.factorydata.jinpai.vo; + +import com.logpm.factorydata.jinpai.entity.PushOrderEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * 金牌下单 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@ApiModel(value = "金牌下单", description = "金牌下单") +@EqualsAndHashCode(callSuper = true) +public class PushOrderVO extends PushOrderEntity { + + @ApiModelProperty(name = "订单明细") + private List items; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/ThirdPlWarehouseMappingVO.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/ThirdPlWarehouseMappingVO.java new file mode 100644 index 000000000..be79f933c --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/ThirdPlWarehouseMappingVO.java @@ -0,0 +1,32 @@ +package com.logpm.factorydata.jinpai.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 金牌三方物流仓库映射表 + * @author zhaoqiaobo + * @create 2024-04-30 + */ +@Data +public class ThirdPlWarehouseMappingVO implements Serializable { + + /** + * 到站网点 + */ + private String arriveOrgName; + /** + * 仓库id + */ + private String warehouseId; + /** + * 仓库名称 + */ + private String warehouseName; + /** + * 租户id + */ + private String tenantId; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/CustomHttpServletRequestWrapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/CustomHttpServletRequestWrapper.java new file mode 100644 index 000000000..8d6173eb6 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/CustomHttpServletRequestWrapper.java @@ -0,0 +1,38 @@ +package com.logpm.factorydata.jinpai.wrapper; + +import org.springframework.http.HttpHeaders; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +public class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper { + + private final HttpHeaders headers; + + public CustomHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + headers = new HttpHeaders(); + } + + @Override + public String getHeader(String name) { + String headerValue = headers.getFirst(name); + return headerValue != null ? headerValue : super.getHeader(name); + } + + @Override + public Enumeration getHeaderNames() { + List names = Collections.list(super.getHeaderNames()); + headers.forEach((key, value) -> names.add(key)); + return Collections.enumeration(names); + } + + // 其他需要覆盖的方法... + + public void addHeader(String name, String value) { + headers.add(name, value); + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/RequestWrapper.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/RequestWrapper.java new file mode 100644 index 000000000..ed7563049 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/wrapper/RequestWrapper.java @@ -0,0 +1,75 @@ +package com.logpm.factorydata.jinpai.wrapper; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class RequestWrapper extends HttpServletRequestWrapper { + private final String body; + public RequestWrapper(HttpServletRequest request) throws IOException { + super(request); + StringBuilder stringBuilder = new StringBuilder(); + BufferedReader bufferedReader = null; + try { + InputStream inputStream = request.getInputStream(); + if (inputStream != null) { + bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + char[] charBuffer = new char[128]; + int bytesRead = -1; + while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { + stringBuilder.append(charBuffer, 0, bytesRead); + } + } else { + stringBuilder.append(""); + } + } catch (IOException ex) { + throw ex; + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException ex) { + throw ex; + } + } + } + body = stringBuilder.toString(); + } + + @Override + public ServletInputStream getInputStream() throws IOException { + final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes()); + ServletInputStream servletInputStream = new ServletInputStream() { + @Override + public boolean isFinished() { + return false; + } + @Override + public boolean isReady() { + return false; + } + @Override + public void setReadListener(ReadListener readListener) {} + @Override + public int read() throws IOException { + return byteArrayInputStream.read(); + } + }; + return servletInputStream; + + } + @Override + public BufferedReader getReader() throws IOException { + return new BufferedReader(new InputStreamReader(this.getInputStream())); + } + public String getBody() { + return this.body; + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-dev.yml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-dev.yml index 6b1351188..5d1e3b74c 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-dev.yml +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-dev.yml @@ -59,13 +59,15 @@ spring: url: ${blade.datasource.factorydata-jinpai.master.url} username: ${blade.datasource.factorydata-jinpai.master.username} password: ${blade.datasource.factorydata-jinpai.master.password} - slave: + 627683: druid: #独立校验配置 validation-query: select 1 #oracle校验 #validation-query: select 1 from dual - url: ${blade.datasource.factorydata-jinpai.slave.url} - username: ${blade.datasource.factorydata-jinpai.slave.username} - password: ${blade.datasource.factorydata-jinpai.slave.password} - + url: ${blade.datasource.factorydata-jinpai.627683.url} + username: ${blade.datasource.factorydata-jinpai.627683.username} + password: ${blade.datasource.factorydata-jinpai.627683.password} +blade: + data-scope: + enabled: false diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-prod.yml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-prod.yml index 4d0394921..f1b3fd486 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-prod.yml +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-prod.yml @@ -33,13 +33,15 @@ spring: url: ${blade.datasource.factorydata-jinpai.master.url} username: ${blade.datasource.factorydata-jinpai.master.username} password: ${blade.datasource.factorydata-jinpai.master.password} - slave: + 627683: druid: #独立校验配置 validation-query: select 1 #oracle校验 #validation-query: select 1 from dual - url: ${blade.datasource.factorydata-jinpai.slave.url} - username: ${blade.datasource.factorydata-jinpai.slave.username} - password: ${blade.datasource.factorydata-jinpai.slave.password} - + url: ${blade.datasource.factorydata-jinpai.627683.url} + username: ${blade.datasource.factorydata-jinpai.627683.username} + password: ${blade.datasource.factorydata-jinpai.627683.password} +blade: + data-scope: + enabled: false diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-test.yml b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-test.yml index 608ff9bcd..27956ec48 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-test.yml +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/resources/application-test.yml @@ -59,13 +59,15 @@ spring: url: ${blade.datasource.factorydata-jinpai.master.url} username: ${blade.datasource.factorydata-jinpai.master.username} password: ${blade.datasource.factorydata-jinpai.master.password} - slave: + 627683: druid: #独立校验配置 validation-query: select 1 #oracle校验 #validation-query: select 1 from dual - url: ${blade.datasource.factorydata-jinpai.slave.url} - username: ${blade.datasource.factorydata-jinpai.slave.username} - password: ${blade.datasource.factorydata-jinpai.slave.password} - + url: ${blade.datasource.factorydata-jinpai.627683.url} + username: ${blade.datasource.factorydata-jinpai.627683.username} + password: ${blade.datasource.factorydata-jinpai.627683.password} +blade: + data-scope: + enabled: false