From ccb701579c47f65f985b2a43542245150763c5f9 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo Date: Fri, 17 May 2024 15:29:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E5=A2=9E=E5=8A=A0=E6=9E=97?= =?UTF-8?q?=E6=B0=8F=E5=B7=A5=E5=8E=82=E7=9A=84=E8=AE=A2=E5=8D=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8E=A5=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/ModuleNameConstant.java | 4 + .../factorydata/FactoryDataConstants.java | 8 + .../logpm/factorydata/enums/BrandEnums.java | 4 +- .../factorydata/jinpai/vo/DeliveryNoteVO.java | 2 + .../logpm-factory-data-linsy/pom.xml | 97 +++++++++++ .../logpm-factory-data-linsy/src/Dockerfile | 14 ++ .../FactoryDataLinSyApplication.java | 20 +++ .../linsy/aspect/AsyncAnnotationAspect.java | 51 ++++++ .../linsy/aspect/RabbitAnnotationAspect.java | 48 +++++ .../linsy/config/CustomMessageConverter.java | 161 +++++++++++++++++ .../linsy/config/ExecutorConfig.java | 79 +++++++++ .../config/FactoryDataOloConfiguration.java | 40 +++++ .../config/InterceptorAdapterConfig.java | 32 ++++ .../linsy/config/RabbitConfig.java | 17 ++ .../linsy/controller/OrderController.java | 71 ++++++++ .../factorydata/linsy/dto/PushOrderDTO.java | 23 +++ .../factorydata/linsy/dto/PushPackageDTO.java | 21 +++ .../linsy/entity/DeliveryNoteEntity.java | 89 ++++++++++ .../linsy/entity/FactoryOrderLogEntity.java | 58 +++++++ .../linsy/entity/FactoryToken.java | 32 ++++ .../linsy/entity/PackageInfoEntity.java | 70 ++++++++ .../linsy/enums/PushStatusEnums.java | 27 +++ .../FactoryAccountsInterceptor.java | 87 ++++++++++ .../LocalServerLoginAccountsInterceptor.java | 100 +++++++++++ .../FactoryDataBaseLauncherServiceImpl.java | 60 +++++++ .../linsy/mapper/DeliveryNoteMapper.java | 16 ++ .../linsy/mapper/FactoryNodeOrderMapper.xml | 5 + .../linsy/mapper/FactoryOrderLogMapper.java | 16 ++ .../linsy/mapper/FactoryOrderLogMapper.xml | 5 + .../linsy/mapper/FactoryTokenMapper.java | 31 ++++ .../linsy/mapper/FactoryTokenMapper.xml | 20 +++ .../linsy/mapper/PackageInfoMapper.java | 16 ++ .../linsy/mapper/PackageInfoMapper.xml | 5 + .../linsy/mq/FactoryOrderListener.java | 141 +++++++++++++++ .../linsy/pros/FactoryDataProperties.java | 20 +++ .../linsy/service/DeliveryNoteService.java | 20 +++ .../linsy/service/FactoryOrderLogService.java | 19 ++ .../linsy/service/IFactoryTokenService.java | 15 ++ .../linsy/service/PackageInfoService.java | 14 ++ .../service/impl/DeliveryNoteServiceImpl.java | 164 ++++++++++++++++++ .../impl/FactoryOrderLogServiceImpl.java | 120 +++++++++++++ .../service/impl/FactoryTokenServiceImpl.java | 62 +++++++ .../service/impl/PackageInfoServiceImpl.java | 22 +++ .../factorydata/linsy/vo/CancelOrderVO.java | 24 +++ .../factorydata/linsy/vo/DeliveryNoteVO.java | 24 +++ .../factorydata/linsy/vo/PackageInfoVO.java | 18 ++ .../CustomHttpServletRequestWrapper.java | 38 ++++ .../linsy/wrapper/RequestWrapper.java | 75 ++++++++ .../src/main/resources/application-dev.yml | 73 ++++++++ .../src/main/resources/application-prod.yml | 47 +++++ .../src/main/resources/application-test.yml | 73 ++++++++ .../src/main/resources/application.yml | 31 ++++ .../src/main/resources/logback.xml | 40 +++++ blade-service/logpm-factory-data/pom.xml | 1 + 54 files changed, 2369 insertions(+), 1 deletion(-) create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/pom.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/Dockerfile create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/FactoryDataLinSyApplication.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/AsyncAnnotationAspect.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/RabbitAnnotationAspect.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/CustomMessageConverter.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/ExecutorConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/FactoryDataOloConfiguration.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/InterceptorAdapterConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/RabbitConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/controller/OrderController.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushOrderDTO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushPackageDTO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/DeliveryNoteEntity.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryOrderLogEntity.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryToken.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/PackageInfoEntity.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/enums/PushStatusEnums.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/FactoryAccountsInterceptor.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/LocalServerLoginAccountsInterceptor.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/launcher/FactoryDataBaseLauncherServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/DeliveryNoteMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryNodeOrderMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mq/FactoryOrderListener.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/pros/FactoryDataProperties.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/DeliveryNoteService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/FactoryOrderLogService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/IFactoryTokenService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/PackageInfoService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/DeliveryNoteServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryOrderLogServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryTokenServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/PackageInfoServiceImpl.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/CancelOrderVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/DeliveryNoteVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/PackageInfoVO.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/CustomHttpServletRequestWrapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/RequestWrapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-dev.yml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-prod.yml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-test.yml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application.yml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/logback.xml diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java b/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java index f3c9d0a48..2da46fb02 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java @@ -105,6 +105,10 @@ public interface ModuleNameConstant { * 我乐工厂数据模块 */ String LOGPM_FACTORY_DATA_OLO_NAME = "logpm-factory-data-olo" + DEVAUTH; + /** + * 林氏工厂数据模块 + */ + String LOGPM_FACTORY_DATA_LINSY_NAME = "logpm-factory-data-linsy" + DEVAUTH; /** * 金牌工厂数据模块 */ diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/factorydata/FactoryDataConstants.java b/blade-biz-common/src/main/java/org/springblade/common/constant/factorydata/FactoryDataConstants.java index d73575d69..63c14937e 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/factorydata/FactoryDataConstants.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/factorydata/FactoryDataConstants.java @@ -65,6 +65,10 @@ public abstract class FactoryDataConstants { * 我乐工厂订单 */ String OLO_FACTORY_ORDER = "factory.data.queue.olo.factoryOrder" + DEVAUTH; + /** + * 林氏工厂订单 + */ + String LINSY_FACTORY_ORDER = "factory.data.queue.linsy.factoryOrder" + DEVAUTH; /** * 金牌工厂订单 */ @@ -104,6 +108,10 @@ public abstract class FactoryDataConstants { * 我乐工厂订单 */ String OLO_FACTORY_ORDER = "olo.factoryOrder" + DEVAUTH; + /** + * 林氏工厂订单 + */ + String LINSY_FACTORY_ORDER = "linsy.factoryOrder" + DEVAUTH; /** * 金牌工厂订单 */ diff --git a/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/enums/BrandEnums.java b/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/enums/BrandEnums.java index 1f04ee1a7..a154a1252 100644 --- a/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/enums/BrandEnums.java +++ b/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/enums/BrandEnums.java @@ -22,7 +22,9 @@ public enum BrandEnums implements Serializable { SFY(6, "索菲亚"), JP(7, "金牌"), OLO(8, "我乐"), - MHJ(9, "曼好家"); + MHJ(9, "曼好家"), + LINSY(10, "林氏家居"), + ; private Integer code; private String value; diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/DeliveryNoteVO.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/DeliveryNoteVO.java index 54b7e019a..d5d0be51b 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/DeliveryNoteVO.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/DeliveryNoteVO.java @@ -21,4 +21,6 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) public class DeliveryNoteVO extends DeliveryNoteEntity { + + } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/pom.xml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/pom.xml new file mode 100644 index 000000000..0295ee098 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/pom.xml @@ -0,0 +1,97 @@ + + + + logpm-factory-data + org.springblade + 3.2.0.RELEASE + + 4.0.0 + + logpm-factory-data-linsy + + + 8 + 8 + + + + + org.springblade + blade-core-boot + + + org.springblade + blade-core-auto + provided + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springblade + logpm-factory-data-api + 3.2.0.RELEASE + + + com.xuxueli + xxl-job-core + + + org.springblade + blade-starter-swagger + + + org.springblade + logpm-trunkline-api + 3.2.0.RELEASE + + + org.springblade + logpm-factory-data-base-api + ${bladex.project.version} + + + org.springblade + blade-starter-oss + + + io.minio + minio + + + org.springblade + blade-resource-api + 3.2.0.RELEASE + compile + + + + + + + + com.spotify + dockerfile-maven-plugin + + ${docker.username} + ${docker.password} + ${docker.registry.url}/${docker.namespace}/${project.artifactId} + ${project.version} + true + + target/${project.build.finalName}.jar + + false + + + + org.apache.maven.plugins + maven-antrun-plugin + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/Dockerfile b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/Dockerfile new file mode 100644 index 000000000..cae45a474 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/Dockerfile @@ -0,0 +1,14 @@ +FROM bladex/alpine-java:openjdk8-openj9_cn_slim + +MAINTAINER h5u@163.com + +RUN mkdir -p /logpm/logpm-factory-data-linsy + +WORKDIR /logpm/logpm-factory-data-linsy + +EXPOSE 18950 + +ADD ./target/logpm-factory-data-linsy.jar ./app.jar + +ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar","-Xms128m","-Xmx512m", "app.jar"] +CMD ["--spring.profiles.active=test"] diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/FactoryDataLinSyApplication.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/FactoryDataLinSyApplication.java new file mode 100644 index 000000000..fc019aa4a --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/FactoryDataLinSyApplication.java @@ -0,0 +1,20 @@ +package com.logpm.factorydata; + +import org.springblade.common.constant.ModuleNameConstant; +import org.springblade.core.cloud.client.BladeCloudApplication; +import org.springblade.core.launch.BladeApplication; + +/** + * 林氏工厂数据启动类 + * + * @author zhaoqiaobo + * @create 2024-4-26 + */ +@BladeCloudApplication +public class FactoryDataLinSyApplication { + + public static void main(String[] args) { + BladeApplication.run(ModuleNameConstant.LOGPM_FACTORY_DATA_LINSY_NAME, FactoryDataLinSyApplication.class, args); + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/AsyncAnnotationAspect.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/AsyncAnnotationAspect.java new file mode 100644 index 000000000..e6402a23f --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/AsyncAnnotationAspect.java @@ -0,0 +1,51 @@ +package com.logpm.factorydata.linsy.aspect; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import lombok.extern.slf4j.Slf4j; +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.annotations.LogpmAsync; +import org.springblade.core.secure.utils.AuthUtil; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; + +@Aspect +@Component +@Slf4j +@Order(-1) +public class AsyncAnnotationAspect { + + /** + * 定义一个切点,匹配所有带有@LogpmAsync("asyncExecutor")注解的方法。 + * 注意:实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理,直接这样配置可能会导致预期之外的行为。 + */ + @Around("@annotation(org.springblade.common.annotations.LogpmAsync)") + public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable { + + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + + LogpmAsync myAsync = method.getAnnotation(LogpmAsync.class); + String annotationValue = myAsync.value(); + log.info(">>>>>>>>>>>>>>>>>> annotationValue={}",annotationValue); + + log.info("@LogpmAsync注解的值为asyncExecutor,进行数据源切换 "); + + // 在方法执行前的操作 + String tenantId = AuthUtil.getTenantId(); + log.info(">> tenandId {} ",tenantId); + DynamicDataSourceContextHolder.push(tenantId); + + // 执行原方法 + Object result = joinPoint.proceed(); + + // 在方法执行后的操作 + DynamicDataSourceContextHolder.poll(); + return result; + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/RabbitAnnotationAspect.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/RabbitAnnotationAspect.java new file mode 100644 index 000000000..985e3ce14 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/RabbitAnnotationAspect.java @@ -0,0 +1,48 @@ +package com.logpm.factorydata.linsy.aspect; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springblade.core.secure.utils.AuthUtil; +import org.springframework.stereotype.Component; + +@Aspect +@Component +@Slf4j +public class RabbitAnnotationAspect { + + + /** + * 该方法为一个切面,用于对标记了@RabbitListener注解的方法进行增强,主要增加了日志记录和数据源上下文处理的功能。 + * + * @param joinPoint 切面的连接点,表示当前被拦截的方法。 + * @return 返回被拦截方法的执行结果。 + * @throws Throwable 如果执行过程中发生异常,则抛出。 + */ + @Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener)") + public Object rabbitMethods(ProceedingJoinPoint joinPoint) throws Throwable { + // 在方法执行前,获取当前租户ID并设置到数据源上下文中 + String tenantId = AuthUtil.getTenantId(); + DynamicDataSourceContextHolder.push(tenantId); + // 执行原方法 + Object result = joinPoint.proceed(); + // 在方法执行后,从数据源上下文中移除租户ID + DynamicDataSourceContextHolder.poll(); + return result; + } + + @Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitHandler)") + public Object rabbitHandlerMethods(ProceedingJoinPoint joinPoint) throws Throwable { + // 在方法执行前,获取当前租户ID并设置到数据源上下文中 + String tenantId = AuthUtil.getTenantId(); + DynamicDataSourceContextHolder.push(tenantId); + // 执行原方法 + Object result = joinPoint.proceed(); + // 在方法执行后,从数据源上下文中移除租户ID + DynamicDataSourceContextHolder.poll(); + return result; + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/CustomMessageConverter.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/CustomMessageConverter.java new file mode 100644 index 000000000..85bda2900 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/CustomMessageConverter.java @@ -0,0 +1,161 @@ +package com.logpm.factorydata.linsy.config; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import org.springblade.core.secure.BladeUser; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessageProperties; +import org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter; +import org.springframework.amqp.support.converter.MessageConversionException; +import org.springframework.amqp.utils.SerializationUtils; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.http.HttpHeaders; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.remoting.rmi.CodebaseAwareObjectInputStream; +import org.springframework.stereotype.Component; +import org.springframework.util.ClassUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; +import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.Map; + +/** + * @author zhaoqiaobo + * @create 2024-05-08 + */ +@Component +public class CustomMessageConverter extends AllowedListDeserializingMessageConverter implements BeanClassLoaderAware { + + private volatile String defaultCharset = "UTF-8"; + private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private String codebaseUrl; + + @Deprecated + public void setCodebaseUrl(String codebaseUrl) { + this.codebaseUrl = codebaseUrl; + } + + @Override + public Object fromMessage(Message message) throws MessageConversionException { + Object content = null; + MessageProperties properties = message.getMessageProperties(); + if (properties != null) { + String contentType = properties.getContentType(); + if (contentType != null && contentType.startsWith("text")) { + String encoding = properties.getContentEncoding(); + if (encoding == null) { + encoding = "UTF-8"; + } + + try { + content = new String(message.getBody(), encoding); + } catch (UnsupportedEncodingException var8) { + throw new MessageConversionException("failed to convert text-based Message content", var8); + } + } else if (contentType != null && contentType.equals("application/x-java-serialized-object")) { + try { + content = SerializationUtils.deserialize(this.createObjectInputStream(new ByteArrayInputStream(message.getBody()), this.codebaseUrl)); + } catch (IllegalArgumentException | IllegalStateException | IOException var7) { + throw new MessageConversionException("failed to convert serialized Message content", var7); + } + } + } + Map headers = properties.getHeaders(); + HttpHeaders httpHeaders = new HttpHeaders(); + for (Map.Entry entry : headers.entrySet()) { + if (StrUtil.equals("Blade-Auth", entry.getKey()) + || StrUtil.equals("Authorization", entry.getKey()) + || StrUtil.equals("blade-auth", entry.getKey()) + || StrUtil.equals("authorization", entry.getKey())) { + List value = (List) entry.getValue(); + for (Object o : value) { + httpHeaders.add(entry.getKey(), String.valueOf(o)); + } + } + } + ThreadLocalUtil.put("bladeContext", httpHeaders); + Object bladeUser = headers.get("bladeUser"); + MockHttpServletRequest request = new MockHttpServletRequest(); + BladeUser bladeUser1 = JSONUtil.toBean(bladeUser.toString(), BladeUser.class); + request.setAttribute("_BLADE_USER_REQUEST_ATTR_", bladeUser1); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); + if (content == null) { + content = message.getBody(); + } + return content; + } + + @Override + protected Message createMessage(Object object, MessageProperties messageProperties) throws MessageConversionException { + byte[] bytes = null; + if (object instanceof byte[]) { + bytes = (byte[]) object; + messageProperties.setContentType("application/octet-stream"); + } else if (object instanceof String) { + try { + bytes = ((String) object).getBytes(this.defaultCharset); + } catch (UnsupportedEncodingException var6) { + throw new MessageConversionException("failed to convert to Message content", var6); + } + + messageProperties.setContentType("text/plain"); + messageProperties.setContentEncoding(this.defaultCharset); + } else if (object instanceof Serializable) { + try { + bytes = SerializationUtils.serialize(object); + } catch (IllegalArgumentException var5) { + throw new MessageConversionException("failed to convert to serialized Message content", var5); + } + + messageProperties.setContentType("application/x-java-serialized-object"); + } + HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext"); + if (headers != null && !headers.isEmpty()) { + headers.forEach((key, values) -> { + values.forEach((value) -> { + messageProperties.setHeader(key, new String[]{value}); + }); + }); + } + BladeUser user = AuthUtil.getUser(); + BladeUser bladeUser = new BladeUser(); + bladeUser.setTenantId(user.getTenantId()); + bladeUser.setUserId(user.getUserId()); + bladeUser.setAccount(user.getAccount()); + bladeUser.setRoleId(user.getRoleId()); + messageProperties.setHeader("bladeUser", JSONUtil.toJsonStr(bladeUser)); + + if (bytes != null) { + messageProperties.setContentLength((long) bytes.length); + return new Message(bytes, messageProperties); + } else { + throw new IllegalArgumentException(this.getClass().getSimpleName() + " only supports String, byte[] and Serializable payloads, received: " + object.getClass().getName()); + } + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.beanClassLoader = beanClassLoader; + } + + protected ObjectInputStream createObjectInputStream(InputStream is, String codebaseUrl) throws IOException { + return new CodebaseAwareObjectInputStream(is, this.beanClassLoader, codebaseUrl) { + @Override + protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { + Class clazz = super.resolveClass(classDesc); + CustomMessageConverter.this.checkAllowedList(clazz); + return clazz; + } + }; + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/ExecutorConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/ExecutorConfig.java new file mode 100644 index 000000000..2cd0c061b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/ExecutorConfig.java @@ -0,0 +1,79 @@ +package com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/config/FactoryDataOloConfiguration.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/FactoryDataOloConfiguration.java new file mode 100644 index 000000000..d2fa931d3 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/FactoryDataOloConfiguration.java @@ -0,0 +1,40 @@ +/* + * 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.linsy.config; + + +import com.logpm.factorydata.linsy.pros.FactoryDataProperties; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * 配置feign、mybatis包名、properties + * + * @author chaos + */ +@Configuration(proxyBeanMethods = false) +@ComponentScan({"org.springblade", "com.logpm"}) +@EnableFeignClients({"org.springblade", "com.logpm"}) +@MapperScan({"org.springblade.**.mapper.**", "com.logpm.**.mapper.**"}) +@EnableConfigurationProperties(FactoryDataProperties.class) +public class FactoryDataOloConfiguration { + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/InterceptorAdapterConfig.java new file mode 100644 index 000000000..ef8d1e97d --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/InterceptorAdapterConfig.java @@ -0,0 +1,32 @@ +package com.logpm.factorydata.linsy.config; + +import com.logpm.factorydata.linsy.interceptor.FactoryAccountsInterceptor; +import com.logpm.factorydata.linsy.interceptor.LocalServerLoginAccountsInterceptor; +import com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/config/RabbitConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/RabbitConfig.java new file mode 100644 index 000000000..4c0022753 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/RabbitConfig.java @@ -0,0 +1,17 @@ +package com.logpm.factorydata.linsy.config; + +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RabbitConfig { + + @Bean + public RabbitTemplate rabbitTemplate(ConnectionFactory factory, CustomMessageConverter converter) { + RabbitTemplate template = new RabbitTemplate(factory); + template.setMessageConverter(converter); + return template; + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/controller/OrderController.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/controller/OrderController.java new file mode 100644 index 000000000..bfb407caf --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/controller/OrderController.java @@ -0,0 +1,71 @@ +package com.logpm.factorydata.linsy.controller; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.json.JSONUtil; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.logpm.factorydata.linsy.service.DeliveryNoteService; +import com.logpm.factorydata.linsy.service.FactoryOrderLogService; +import com.logpm.factorydata.linsy.vo.CancelOrderVO; +import com.logpm.factorydata.linsy.vo.DeliveryNoteVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.annotations.Delete; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +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; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 工厂订单 前端控制器 + * + * @author zhaoqiaobo + * @create 2024-03-21 19:27 + */ +@Slf4j +@RestController +@RequestMapping("/factory/order/v1") +@AllArgsConstructor +@Api(value = "工厂订单", tags = "工厂订单") +public class OrderController { + + private final FactoryOrderLogService service; + + @ResponseBody + @PostMapping + @ApiOperationSupport(order = 1) + @ApiOperation(value = "工厂订单", notes = "工厂订单") + public R order(@RequestBody DeliveryNoteVO vo) { + log.info("接收工厂订单:{} ", JSONUtil.toJsonStr(vo)); + String res = ""; + try { + res = service.order(vo); + } catch (Exception e) { + log.error("工厂订单异常:{} ", e); + return R.success("服务器异常"); + } + return R.success(res); + } + + @ResponseBody + @PatchMapping + @ApiOperationSupport(order = 2) + @ApiOperation(value = "取消订单", notes = "取消订单") + public R cancelOrder(@RequestBody CancelOrderVO vo) { + log.info("取消订单:{} ", JSONUtil.toJsonStr(vo)); + String res = ""; + res = service.cancelOrder(vo); + return R.success(res); + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushOrderDTO.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushOrderDTO.java new file mode 100644 index 000000000..ff469ea4a --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushOrderDTO.java @@ -0,0 +1,23 @@ +package com.logpm.factorydata.linsy.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 回传订单状态 + * + * @author zhaoqiaobo + * @create 2024-05-16 + */ +@Data +public class PushOrderDTO implements Serializable { + + private String billCode; + + private String status; + + private List packages; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushPackageDTO.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushPackageDTO.java new file mode 100644 index 000000000..7f0e19627 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/dto/PushPackageDTO.java @@ -0,0 +1,21 @@ +package com.logpm.factorydata.linsy.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 回传包件 + * + * @author zhaoqiaobo + * @create 2024-05-16 + */ +@Data +public class PushPackageDTO implements Serializable { + + /** + * 包条码 + */ + private String barcode; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/DeliveryNoteEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/DeliveryNoteEntity.java new file mode 100644 index 000000000..cfe7b8d89 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/DeliveryNoteEntity.java @@ -0,0 +1,89 @@ +package com.logpm.factorydata.linsy.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("linsy_delivery_note") +@ApiModel(value = "林氏发运单", description = "林氏发运单") +@EqualsAndHashCode(callSuper = true) +public class DeliveryNoteEntity extends BaseEntity { + + @ApiModelProperty("日志id") + private String logId; + + @ApiModelProperty(value = "单据编号") + private String billCode; + @ApiModelProperty(value = "单据日期") + private String billDate; + @ApiModelProperty(value = "总包件数") + private String totalPackage; + @ApiModelProperty(value = "总体积") + private String totalVolume; + @ApiModelProperty(value = "经销商") + private String agencyName; + @ApiModelProperty(value = "定制单号") + private String customizedBillCode; + @ApiModelProperty(value = "供应商") + private String supplierName; + @ApiModelProperty(value = "店铺") + private String shopName; + @ApiModelProperty(value = "收货人") + private String receiverName; + @ApiModelProperty(value = "电话") + private String receiverTelephone; + @ApiModelProperty(value = "收货省") + private String receiverProvinceName; + @ApiModelProperty(value = "收货市") + private String receiverCityName; + @ApiModelProperty(value = "收货区") + private String receiverDistrictName; + @ApiModelProperty(value = "收货街道") + private String receiverStreetName; + @ApiModelProperty(value = "收货详细地址") + private String receiverDetailAddress; + @ApiModelProperty(value = "业务员") + private String customerSalesman; + @ApiModelProperty(value = "业务联系电话") + private String customerSalesmanTelephone; + @ApiModelProperty(value = "发货省") + private String senderProvinceName; + @ApiModelProperty(value = "发货市") + private String senderCityName; + @ApiModelProperty(value = "发货区") + private String senderDistrictName; + @ApiModelProperty(value = "发货详细地址") + private String senderDetailAddress; + @ApiModelProperty(value = "发货人") + private String senderName; + @ApiModelProperty(value = "发货人电话") + private String senderTelephone; + @ApiModelProperty(value = "创建时间") + private String createdTime; + @ApiModelProperty(value = "原单编号") + private String sourceBillCode; + @ApiModelProperty(value = "合并单号") + private String mergeOrderCode; + + @ApiModelProperty(value = "预留1", notes = "") + private String reserve1; + @ApiModelProperty(value = "预留2", notes = "") + private String reserve2; + @ApiModelProperty(value = "预留3", notes = "") + private String reserve3; + @ApiModelProperty(value = "预留4", notes = "") + private String reserve4; + @ApiModelProperty(value = "预留5", notes = "") + private String reserve5; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryOrderLogEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryOrderLogEntity.java new file mode 100644 index 000000000..b73f91240 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryOrderLogEntity.java @@ -0,0 +1,58 @@ +package com.logpm.factorydata.linsy.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; + +@Data +@TableName("linsy_factory_log") +@ApiModel(value = "接收工厂订单日志", description = "接收工厂订单日志") +@EqualsAndHashCode(callSuper = true) +public class FactoryOrderLogEntity extends BaseEntity { + + /** + * 预留1 + */ + @ApiModelProperty(name = "预留1", notes = "") + private String reserve1; + /** + * 预留2 + */ + @ApiModelProperty(name = "预留2", notes = "") + private String reserve2; + /** + * 预留3 + */ + @ApiModelProperty(name = "预留3", notes = "") + private String reserve3; + /** + * 预留4 + */ + @ApiModelProperty(name = "预留4", notes = "") + private String reserve4; + /** + * 预留5 + */ + @ApiModelProperty(name = "预留5", notes = "") + private String reserve5; + /** + * 日志文件存放地址 + */ + @ApiModelProperty(name = "日志文件存放地址", notes = "") + private String logUrl; + /** + * 数据类型 1.入库数据 + */ + @ApiModelProperty(name = "数据类型 1.入库数据", notes = "") + private Integer type; + /** + * 解析状态 0 未解析 1 解析失败 2 已解析 + */ + @ApiModelProperty(name = "解析状态 0 未解析 1 解析失败 2 已解析", notes = "") + private Integer saxStatus; + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryToken.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryToken.java new file mode 100644 index 000000000..50de6360c --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/FactoryToken.java @@ -0,0 +1,32 @@ +package com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/entity/PackageInfoEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/PackageInfoEntity.java new file mode 100644 index 000000000..3f1598be9 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/entity/PackageInfoEntity.java @@ -0,0 +1,70 @@ +package com.logpm.factorydata.linsy.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("linsy_package_info") +@ApiModel(value = "包件信息", description = "包件信息") +@EqualsAndHashCode(callSuper = true) +public class PackageInfoEntity extends BaseEntity { + + @ApiModelProperty(value = "日志id") + private String logId; + @ApiModelProperty(value = "发货单id") + private String deliveryNoteId; + @ApiModelProperty(value = "父项物料编码") + private String parentMaterialCode; + @ApiModelProperty(value = "父项物料名称") + private String parentMaterialName; + @ApiModelProperty(value = "检验单号") + private String checkBillCode; + @ApiModelProperty(value = "采购单号") + private String sellerBillCode; + @ApiModelProperty(value = "批号") + private String lotCode; + @ApiModelProperty(value = "客户业务员") + private String customerSalesman; + @ApiModelProperty(value = "外部原单行号") + private String outSourceCode; + @ApiModelProperty(value = "定制单号") + private String customizedBillCode; + @ApiModelProperty(value = "物料编码") + private String materialCode; + @ApiModelProperty(value = "物料名称") + private String materialName; + @ApiModelProperty(value = "包件条码") + private String barcode; + @ApiModelProperty(value = "体积") + private String volume; + @ApiModelProperty(value = "重量") + private String weight; + @ApiModelProperty(value = "长度") + private String length; + @ApiModelProperty(value = "宽度") + private String width; + @ApiModelProperty(value = "高度") + private String height; + + @ApiModelProperty(value = "预留1", notes = "") + private String reserve1; + @ApiModelProperty(value = "预留2", notes = "") + private String reserve2; + @ApiModelProperty(value = "预留3", notes = "") + private String reserve3; + @ApiModelProperty(value = "预留4", notes = "") + private String reserve4; + @ApiModelProperty(value = "预留5", notes = "") + private String reserve5; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/enums/PushStatusEnums.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/enums/PushStatusEnums.java new file mode 100644 index 000000000..b50ecfddb --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/enums/PushStatusEnums.java @@ -0,0 +1,27 @@ +package com.logpm.factorydata.linsy.enums; + +import org.springblade.common.model.IDict; + +/** + * 回传状态码表 + * + * @author zhaoqiaobo + * @create 2024-04-01 + */ +public enum PushStatusEnums implements IDict { + + /** + * 已交接 + */ + DELIVERIED("Deliveried", "已交接"), + /** + * 收货完成 + */ + RECEIVED("Received", "收货完成"), + ; + + PushStatusEnums(String code, String text) { + init(code, text); + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/FactoryAccountsInterceptor.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/FactoryAccountsInterceptor.java new file mode 100644 index 000000000..831ed3bc8 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/FactoryAccountsInterceptor.java @@ -0,0 +1,87 @@ +package com.logpm.factorydata.linsy.interceptor; + +import com.alibaba.fastjson.JSONObject; +import com.logpm.factorydata.linsy.service.IFactoryTokenService; +import com.logpm.factorydata.linsy.wrapper.RequestWrapper; +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(401,"认证不通过,token有误"))); + return false; + } + if(!StringUtil.hasLength(corpId)){ + returnJson(response,JSONObject.toJSONString(R.fail(401,"认证不通过,corpId有误"))); + return false; + } + + log.info("##########preHandle: token={}",token); + //验证token + boolean b = factoryTokenService.verifyToken(token,corpId); + if(!b){ + returnJson(response,JSONObject.toJSONString(R.fail(401,"认证不通过,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-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/LocalServerLoginAccountsInterceptor.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/LocalServerLoginAccountsInterceptor.java new file mode 100644 index 000000000..d5c29323e --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/LocalServerLoginAccountsInterceptor.java @@ -0,0 +1,100 @@ +package com.logpm.factorydata.linsy.interceptor; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONObject; +import com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/launcher/FactoryDataBaseLauncherServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/launcher/FactoryDataBaseLauncherServiceImpl.java new file mode 100644 index 000000000..9ab059148 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/launcher/FactoryDataBaseLauncherServiceImpl.java @@ -0,0 +1,60 @@ +/* + * 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.linsy.launcher; + +import org.springblade.core.auto.service.AutoService; +import org.springblade.core.launch.constant.NacosConstant; +import org.springblade.core.launch.service.LauncherService; +import org.springblade.core.launch.utils.PropsUtil; +import org.springframework.boot.builder.SpringApplicationBuilder; + +import java.util.Properties; + +/** + * 启动参数拓展 + * + * @author Chill + */ +@AutoService(LauncherService.class) +public class FactoryDataBaseLauncherServiceImpl implements LauncherService { + + @Override + public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) { + Properties props = System.getProperties(); + // 开启多数据源 + PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "true"); + // 指定注册配置信息 + PropsUtil.setProperty(props, "spring.cloud.nacos.config.extension-configs[0].data-id", NacosConstant.dataId(appName, profile)); + PropsUtil.setProperty(props, "spring.cloud.nacos.config.extension-configs[0].group", NacosConstant.NACOS_CONFIG_GROUP); + PropsUtil.setProperty(props, "spring.cloud.nacos.config.extension-configs[0].refresh", NacosConstant.NACOS_CONFIG_REFRESH); + // 指定注册IP + // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.ip", "127.0.0.1"); + // 指定注册端口 + // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.port", "8200"); + // 自定义命名空间 + // PropsUtil.setProperty(props, "spring.cloud.nacos.config.namespace", LauncherConstant.NACOS_NAMESPACE); + // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.namespace", LauncherConstant.NACOS_NAMESPACE); + // 自定义分组 + // PropsUtil.setProperty(props, "spring.cloud.nacos.config.group", NacosConstant.NACOS_CONFIG_GROUP); + // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.group", NacosConstant.NACOS_CONFIG_GROUP); + } + + @Override + public int getOrder() { + return 20; + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/DeliveryNoteMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/DeliveryNoteMapper.java new file mode 100644 index 000000000..0bb77b8a4 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/DeliveryNoteMapper.java @@ -0,0 +1,16 @@ +package com.logpm.factorydata.linsy.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.linsy.entity.DeliveryNoteEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 发货单 mapper + * + * @author zqb + * @since 2024-03-26 + */ +@Mapper +public interface DeliveryNoteMapper extends BaseMapper { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryNodeOrderMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryNodeOrderMapper.xml new file mode 100644 index 000000000..255ceb64c --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryNodeOrderMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.java new file mode 100644 index 000000000..2c8dc0462 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.java @@ -0,0 +1,16 @@ +package com.logpm.factorydata.linsy.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.linsy.entity.FactoryOrderLogEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 工厂订单日志 mapper + * + * @author zqb + * @since 2024-03-26 + */ +@Mapper +public interface FactoryOrderLogMapper extends BaseMapper { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.xml new file mode 100644 index 000000000..fd53c5269 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryOrderLogMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.java new file mode 100644 index 000000000..63e3dca60 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/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.linsy.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.xml new file mode 100644 index 000000000..76416cd84 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/FactoryTokenMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.java new file mode 100644 index 000000000..b5e266b6a --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.java @@ -0,0 +1,16 @@ +package com.logpm.factorydata.linsy.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.linsy.entity.PackageInfoEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 装箱包信息 mapper + * + * @author zqb + * @since 2024-03-26 + */ +@Mapper +public interface PackageInfoMapper extends BaseMapper { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.xml new file mode 100644 index 000000000..3cd3ffca7 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mapper/PackageInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mq/FactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mq/FactoryOrderListener.java new file mode 100644 index 000000000..8d8b983c9 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/mq/FactoryOrderListener.java @@ -0,0 +1,141 @@ +package com.logpm.factorydata.linsy.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.NumberUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.URLUtil; +import cn.hutool.json.JSONConfig; +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.linsy.entity.DeliveryNoteEntity; +import com.logpm.factorydata.linsy.entity.FactoryOrderLogEntity; +import com.logpm.factorydata.linsy.entity.PackageInfoEntity; +import com.logpm.factorydata.linsy.service.DeliveryNoteService; +import com.logpm.factorydata.linsy.service.FactoryOrderLogService; +import com.logpm.factorydata.linsy.service.PackageInfoService; +import com.logpm.factorydata.linsy.vo.DeliveryNoteVO; +import com.logpm.factorydata.linsy.vo.PackageInfoVO; +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.annotations.LogpmAsync; +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.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 监听订单数据 + * + * @author zhaoqiaobo + * @create 2024-03-18 + */ +@Slf4j +@Component +@AllArgsConstructor +public class FactoryOrderListener { + + private final DeliveryNoteService deliveryNoteService; + private final FactoryOrderLogService logService; + private final PackageInfoService packageInfoService; + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FactoryDataConstants.Mq.Queues.LINSY_FACTORY_ORDER), + exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER, type = ExchangeTypes.TOPIC), + key = FactoryDataConstants.Mq.RoutingKeys.LINSY_FACTORY_ORDER + )) + @Transactional(rollbackFor = Exception.class) + public void factoryOrder(String msg) { + log.info("处理林氏订单:{}", msg); + if (StrUtil.isEmpty(msg)) { + log.error("消息内容为空"); + return; + } + FactoryOrderLogEntity logEntity = JSONUtil.toBean(msg, FactoryOrderLogEntity.class); + if (ObjectUtil.isEmpty(logEntity)) { + log.error("消息内容为空"); + return; + } + // 去 minio 下载文件到本地,然后解析文件内容为实体对象 + DeliveryNoteVO vo = null; + Long logId = logEntity.getId(); + String logUrl = logEntity.getLogUrl(); + 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)) { + JSONConfig config = new JSONConfig(); + config.setIgnoreCase(Boolean.TRUE); + vo = JSONUtil.toBean(content, DeliveryNoteVO.class); + } + } + } + if (ObjectUtil.isEmpty(vo)) { + log.error("消息内容为空"); + return; + } + // 1 解析数据保存入库 + // 车次号唯一 + String billCode = vo.getBillCode(); + List list = deliveryNoteService.list(Wrappers.lambdaQuery() + .eq(DeliveryNoteEntity::getBillCode, billCode)); + if (CollUtil.isNotEmpty(list)) { + log.error("单号{} 数据已经处理过了, logId: {}", billCode, logId); + return; + } + vo.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + deliveryNoteService.save(vo); + List orderInfos = vo.getPackages(); + if (CollUtil.isNotEmpty(orderInfos)) { + List infoEntities = new ArrayList<>(); + for (PackageInfoVO orderInfo : orderInfos) { + PackageInfoEntity orderInfoEntity = new PackageInfoEntity(); + BeanUtil.copyProperties(orderInfo, orderInfoEntity); + orderInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + orderInfoEntity.setDeliveryNoteId(vo.getId().toString()); + infoEntities.add(orderInfoEntity); + } + packageInfoService.saveBatch(infoEntities); + } + // 2 构建暂存单,发送 mq 消息 + FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity(); + logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode()); + logEntity1.setId(logId); + logService.saveOrUpdate(logEntity1); + // 结果回传 + + // 处理暂存单 + deliveryNoteService.buildAdvance(vo); + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/pros/FactoryDataProperties.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/pros/FactoryDataProperties.java new file mode 100644 index 000000000..e1f3f2c72 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/pros/FactoryDataProperties.java @@ -0,0 +1,20 @@ +package com.logpm.factorydata.linsy.pros; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * FactoryProperties + * + * @author pref + */ +@Data +@ConfigurationProperties(prefix = "logpm") +public class FactoryDataProperties { + /** + * 名称 + */ + private String name; + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/DeliveryNoteService.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/DeliveryNoteService.java new file mode 100644 index 000000000..441ca7fb0 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/DeliveryNoteService.java @@ -0,0 +1,20 @@ +package com.logpm.factorydata.linsy.service; + +import com.logpm.factorydata.linsy.entity.DeliveryNoteEntity; +import com.logpm.factorydata.linsy.vo.DeliveryNoteVO; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * 索菲亚发货单 服务类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +public interface DeliveryNoteService extends BaseService { + + + void buildAdvance(DeliveryNoteVO entities); + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/FactoryOrderLogService.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/FactoryOrderLogService.java new file mode 100644 index 000000000..487a90088 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/FactoryOrderLogService.java @@ -0,0 +1,19 @@ +package com.logpm.factorydata.linsy.service; + +import com.logpm.factorydata.linsy.entity.FactoryOrderLogEntity; +import com.logpm.factorydata.linsy.vo.CancelOrderVO; +import com.logpm.factorydata.linsy.vo.DeliveryNoteVO; +import org.springblade.core.mp.base.BaseService; + +/** + * 工厂订单日志 服务类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +public interface FactoryOrderLogService extends BaseService { + + String order(DeliveryNoteVO vo); + + String cancelOrder(CancelOrderVO vo); +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/IFactoryTokenService.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/IFactoryTokenService.java new file mode 100644 index 000000000..e9f013bd8 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/IFactoryTokenService.java @@ -0,0 +1,15 @@ +package com.logpm.factorydata.linsy.service; + +import com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/service/PackageInfoService.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/PackageInfoService.java new file mode 100644 index 000000000..e4c66673c --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/PackageInfoService.java @@ -0,0 +1,14 @@ +package com.logpm.factorydata.linsy.service; + +import com.logpm.factorydata.linsy.entity.PackageInfoEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * 装箱包信息 服务类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +public interface PackageInfoService extends BaseService { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/DeliveryNoteServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/DeliveryNoteServiceImpl.java new file mode 100644 index 000000000..d8f351077 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/DeliveryNoteServiceImpl.java @@ -0,0 +1,164 @@ +package com.logpm.factorydata.linsy.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +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.linsy.entity.DeliveryNoteEntity; +import com.logpm.factorydata.linsy.mapper.DeliveryNoteMapper; +import com.logpm.factorydata.linsy.service.DeliveryNoteService; +import com.logpm.factorydata.linsy.vo.DeliveryNoteVO; +import com.logpm.factorydata.linsy.vo.PackageInfoVO; +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.annotations.LogpmAsync; +import org.springblade.common.constant.HttpConstants; +import org.springblade.common.constant.factorydata.FactoryDataConstants; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + * 发货单 业务实现类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +@Slf4j +@Service +@AllArgsConstructor +public class DeliveryNoteServiceImpl extends BaseServiceImpl implements DeliveryNoteService { + + private final IFactoryDataBaseClient baseClient; + private final IFactoryDataClient factoryDataClient; + + @Override + @LogpmAsync("asyncExecutor") + public void buildAdvance(DeliveryNoteVO vo) { + // 新起线程构建暂存单发送mq + Long startWarehouseId = null; + String startWarehouseName = null; + String tenantId = null; + // 获取工厂基地绑定的始发仓信息 + R warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(BrandEnums.LINSY.getValue(), vo.getSupplierName()); + 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(); + } + } + List packages = vo.getPackages(); + // 组装暂存单数据 + List advances = new ArrayList<>(); + TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); + advanceEntity.setTenantId(tenantId); + advanceEntity.setStatus(0); + advanceEntity.setIsDeleted(0); + advanceEntity.setHasPackage(CollUtil.isNotEmpty(packages) ? 1 : 0); + advanceEntity.setOrderType(""); + advanceEntity.setBrand(BrandEnums.LINSY.getValue()); + advanceEntity.setSiteName(vo.getSupplierName()); + advanceEntity.setArea(""); + advanceEntity.setTotalNum(CollUtil.isNotEmpty(packages) ? packages.size() : 0); + + advanceEntity.setPackCode(""); + advanceEntity.setWarehouseId(startWarehouseId); + advanceEntity.setWarehouseName(startWarehouseName); + + advanceEntity.setIsGcp(0); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setWaybillNo(""); + advanceEntity.setFreezeStatus("0"); + advanceEntity.setPackName(""); + advanceEntity.setCarrierName("汇通"); + advanceEntity.setSenderName(""); + advanceEntity.setSenderPhone(""); + advanceEntity.setSenderAddress(""); + advanceEntity.setTrainNumber(StrUtil.replace(DateUtil.today(), "-", "")); + advanceEntity.setSenderFactory(BrandEnums.LINSY.getValue()); + advanceEntity.setOrderCode(vo.getBillCode()); + advanceEntity.setDealerCode(""); + advanceEntity.setDealerName(vo.getShopName()); + advanceEntity.setStoreCode(""); + advanceEntity.setStoreName(vo.getShopName()); + advanceEntity.setServiceNum(vo.getCustomizedBillCode()); + advanceEntity.setCustomerName(vo.getReceiverName()); + advanceEntity.setCustomerPhone(vo.getReceiverTelephone()); + advanceEntity.setCustomerAddress(vo.getReceiverDetailAddress()); + advanceEntity.setSenderName(vo.getSenderName()); + advanceEntity.setSenderPhone(vo.getSenderTelephone()); + advanceEntity.setSenderAddress(vo.getSenderDetailAddress()); + List packageList = new ArrayList<>(); + for (PackageInfoVO orderPackageDTO : packages) { + // 封装包件 + TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); + advanceDetailEntity.setWarehouseId(startWarehouseId); + advanceDetailEntity.setWarehouseName(startWarehouseName); +// advanceDetailEntity.setIncomingWarehouseId(0L); +// advanceDetailEntity.setIncomingWarehouseName(""); + advanceDetailEntity.setOrderCode(vo.getBillCode()); + advanceDetailEntity.setBrand(BrandEnums.LINSY.getValue()); + advanceDetailEntity.setSystemType("线上"); + advanceDetailEntity.setFirstPackName(orderPackageDTO.getMaterialName()); + //二级品类名称 + advanceDetailEntity.setSecondPackName(orderPackageDTO.getMaterialName()); + //三级品类名称 + advanceDetailEntity.setThirdPackName(orderPackageDTO.getMaterialName()); + advanceDetailEntity.setMaterialName(orderPackageDTO.getMaterialName()); + advanceDetailEntity.setMaterialCode(orderPackageDTO.getMaterialCode()); + advanceDetailEntity.setSiteName(vo.getSupplierName()); + advanceDetailEntity.setSiteCode(""); + advanceDetailEntity.setQuantity(1); + advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getBarcode()); + advanceDetailEntity.setTrainNumber(StrUtil.replace(DateUtil.today(), "-", "")); + advanceDetailEntity.setServiceNum(vo.getCustomizedBillCode()); + 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); + } + } + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryOrderLogServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryOrderLogServiceImpl.java new file mode 100644 index 000000000..820d0e96b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryOrderLogServiceImpl.java @@ -0,0 +1,120 @@ +package com.logpm.factorydata.linsy.service.impl; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONUtil; +import com.logpm.factorydata.enums.SaxStatusEnums; +import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.linsy.entity.FactoryOrderLogEntity; +import com.logpm.factorydata.linsy.mapper.FactoryOrderLogMapper; +import com.logpm.factorydata.linsy.service.FactoryOrderLogService; +import com.logpm.factorydata.linsy.vo.CancelOrderVO; +import com.logpm.factorydata.linsy.vo.DeliveryNoteVO; +import com.logpm.factorydata.vo.SendMsg; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.io.IOUtils; +import org.jetbrains.annotations.NotNull; +import org.springblade.common.constant.factorydata.FactoryDataConstants; +import org.springblade.common.utils.FileLogsUtil; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.oss.model.BladeFile; +import org.springblade.core.tool.api.R; +import org.springblade.resource.feign.IOssClient; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; + +/** + * 工厂订单日志 业务实现类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +@Slf4j +@Service +@AllArgsConstructor +public class FactoryOrderLogServiceImpl extends BaseServiceImpl implements FactoryOrderLogService { + + private final IFactoryDataClient factoryDataClient; + private final IOssClient ossClient; + + @Override + public String order(DeliveryNoteVO vo) { + + // 1 上传数据到 minio 获取到地址 + String url = uploadFile(JSONUtil.toJsonStr(vo)); + // 2 保存地址到数据库 + FactoryOrderLogEntity logEntity = new FactoryOrderLogEntity(); + logEntity.setType(1); + logEntity.setSaxStatus(SaxStatusEnums.NOMAL.getCode()); + logEntity.setLogUrl(url); + this.save(logEntity); + + // 3 将消息发送给 mq,解析保存 + SendMsg build = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER) + .routingKey(FactoryDataConstants.Mq.RoutingKeys.LINSY_FACTORY_ORDER) + .message(JSONUtil.toJsonStr(logEntity)).build(); + factoryDataClient.sendMessage(build); + return "成功"; + } + + @Override + public String cancelOrder(CancelOrderVO vo) { + // TODO 取消订单逻辑后续实现 同步接口,实时返回取消状态 + if (ObjectUtil.equal(vo.getSourceCode(), "1")) { + return "取消成功"; + } else { + throw new ServiceException("取消失败"); + } + } + + private String uploadFile(String body) { + //文本内容和保存为本地文件 并上传 + String logPath = FileLogsUtil.saveFileLogs(body); + log.info(">>> 文件路径 {}", logPath); + + MultipartFile multi = getMultipartFile(logPath); + //上传到服务器 + R r = ossClient.fileUpload(multi, "olo-order-logs"); + if (r.isSuccess()) { + BladeFile data = (BladeFile) r.getData(); + // 删除本地文件 + FileUtil.del(logPath); + return data.getLink(); + } + return null; + } + + @NotNull + private MultipartFile getMultipartFile(String logPath) { + File file = new File(logPath); + + // File 转 MultipartFile + FileItem item = new DiskFileItemFactory().createItem("file" + , MediaType.MULTIPART_FORM_DATA_VALUE + , true + , file.getName()); + try ( + InputStream input = Files.newInputStream(file.toPath()); + OutputStream os = item.getOutputStream()) { + // 流转移 + IOUtils.copy(input, os); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid file: " + e, e); + } + + return new CommonsMultipartFile(item); + } + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryTokenServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryTokenServiceImpl.java new file mode 100644 index 000000000..7f0a1531e --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/FactoryTokenServiceImpl.java @@ -0,0 +1,62 @@ +package com.logpm.factorydata.linsy.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.logpm.factorydata.linsy.entity.FactoryToken; +import com.logpm.factorydata.linsy.mapper.FactoryTokenMapper; +import com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/PackageInfoServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/PackageInfoServiceImpl.java new file mode 100644 index 000000000..05f0d63d8 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/service/impl/PackageInfoServiceImpl.java @@ -0,0 +1,22 @@ +package com.logpm.factorydata.linsy.service.impl; + +import com.logpm.factorydata.linsy.entity.PackageInfoEntity; +import com.logpm.factorydata.linsy.mapper.PackageInfoMapper; +import com.logpm.factorydata.linsy.service.PackageInfoService; +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 PackageInfoServiceImpl extends BaseServiceImpl implements PackageInfoService { + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/CancelOrderVO.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/CancelOrderVO.java new file mode 100644 index 000000000..48d9c8d9a --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/CancelOrderVO.java @@ -0,0 +1,24 @@ +package com.logpm.factorydata.linsy.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; + +/** + * 取消订单 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@ApiModel(value = "取消订单", description = "取消订单") +public class CancelOrderVO implements Serializable { + + @ApiModelProperty("订单编号") + @NotEmpty(message = "订单编号不能为空") + private String sourceCode; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/DeliveryNoteVO.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/DeliveryNoteVO.java new file mode 100644 index 000000000..82e066525 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/DeliveryNoteVO.java @@ -0,0 +1,24 @@ +package com.logpm.factorydata.linsy.vo; + +import com.logpm.factorydata.linsy.entity.DeliveryNoteEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 送货单 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@ApiModel(value = "林氏发运信息", description = "林氏发运信息") +public class DeliveryNoteVO extends DeliveryNoteEntity { + + @ApiModelProperty("包件列表") + private List packages; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/PackageInfoVO.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/PackageInfoVO.java new file mode 100644 index 000000000..e50f4b219 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/vo/PackageInfoVO.java @@ -0,0 +1,18 @@ +package com.logpm.factorydata.linsy.vo; + +import com.logpm.factorydata.linsy.entity.PackageInfoEntity; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 装箱包信息 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@ApiModel(value = "装箱包信息", description = "装箱包信息") +@EqualsAndHashCode(callSuper = true) +public class PackageInfoVO extends PackageInfoEntity { +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/CustomHttpServletRequestWrapper.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/CustomHttpServletRequestWrapper.java new file mode 100644 index 000000000..131e5ad50 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/CustomHttpServletRequestWrapper.java @@ -0,0 +1,38 @@ +package com.logpm.factorydata.linsy.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-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/RequestWrapper.java b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/RequestWrapper.java new file mode 100644 index 000000000..261d6bbf3 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/wrapper/RequestWrapper.java @@ -0,0 +1,75 @@ +package com.logpm.factorydata.linsy.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-linsy/src/main/resources/application-dev.yml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-dev.yml new file mode 100644 index 000000000..d27167512 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-dev.yml @@ -0,0 +1,73 @@ +#服务器端口 +server: + port: 18950 + +#数据源配置 +#spring: +# datasource: +# url: ${blade.datasource.dev.url} +# username: ${blade.datasource.dev.username} +# password: ${blade.datasource.dev.password} + +spring: + #rabbitmq配置 + rabbitmq: + host: 192.168.2.46 + port: 5672 + username: admin + password: admin + #虚拟host 可以不设置,使用server默认host + virtual-host: / + #确认消息已发送到队列(Queue) + publisher-returns: true + publisher-confirm-type: correlated + # 手动提交消息 + listener: + simple: + acknowledge-mode: auto + default-requeue-rejected: false + retry: + enabled: true # 开启消费者失败重试 + initial-interval: 1000 # 初识的失败等待时长为1秒 + multiplier: 1 # 失败的等待时长倍数,下次等待时长 = multiplier * last-interval + max-attempts: 3 # 最大重试次数 + stateless: true # true无状态;false有状态。如果业务中包含事务,这里改为false + direct: + acknowledge-mode: manual + template: + mandatory: true + #排除DruidDataSourceAutoConfigure + autoconfigure: + exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure,com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration + datasource: + dynamic: + druid: + #通用校验配置 + validation-query: select 1 + #启用sql日志拦截器 + proxy-filters: + - sqlLogInterceptor + #设置默认的数据源或者数据源组,默认值即为master + primary: master + datasource: + master: + druid: + #独立校验配置 + validation-query: select 1 + #oracle校验 + #validation-query: select 1 from dual + url: ${blade.datasource.factorydata-linsy.master.url} + username: ${blade.datasource.factorydata-linsy.master.username} + password: ${blade.datasource.factorydata-linsy.master.password} + 627683: + druid: + #独立校验配置 + validation-query: select 1 + #oracle校验 + #validation-query: select 1 from dual + url: ${blade.datasource.factorydata-linsy.627683.url} + username: ${blade.datasource.factorydata-linsy.627683.username} + password: ${blade.datasource.factorydata-linsy.627683.password} +blade: + data-scope: + enabled: false diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-prod.yml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-prod.yml new file mode 100644 index 000000000..28d6724a2 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-prod.yml @@ -0,0 +1,47 @@ +#服务器端口 +server: + port: 18950 + +#数据源配置 +#spring: +# datasource: +# url: ${blade.datasource.dev.url} +# username: ${blade.datasource.dev.username} +# password: ${blade.datasource.dev.password} + +spring: + #排除DruidDataSourceAutoConfigure + autoconfigure: + exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure,com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration + datasource: + dynamic: + druid: + #通用校验配置 + validation-query: select 1 + #启用sql日志拦截器 + proxy-filters: + - sqlLogInterceptor + #设置默认的数据源或者数据源组,默认值即为master + primary: master + datasource: + master: + druid: + #独立校验配置 + validation-query: select 1 + #oracle校验 + #validation-query: select 1 from dual + url: ${blade.datasource.factorydata-linsy.master.url} + username: ${blade.datasource.factorydata-linsy.master.username} + password: ${blade.datasource.factorydata-linsy.master.password} + 627683: + druid: + #独立校验配置 + validation-query: select 1 + #oracle校验 + #validation-query: select 1 from dual + url: ${blade.datasource.factorydata-linsy.627683.url} + username: ${blade.datasource.factorydata-linsy.627683.username} + password: ${blade.datasource.factorydata-linsy.627683.password} +blade: + data-scope: + enabled: false diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-test.yml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-test.yml new file mode 100644 index 000000000..b781b45f0 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application-test.yml @@ -0,0 +1,73 @@ +#服务器端口 +server: + port: 18950 + +#数据源配置 +#spring: +# datasource: +# url: ${blade.datasource.dev.url} +# username: ${blade.datasource.dev.username} +# password: ${blade.datasource.dev.password} + +spring: + #rabbitmq配置 + rabbitmq: + host: 192.168.2.110 + port: 5672 + username: admin + password: Slwk@123654 + #虚拟host 可以不设置,使用server默认host + virtual-host: / + #确认消息已发送到队列(Queue) + publisher-returns: true + publisher-confirm-type: correlated + # 手动提交消息 + listener: + simple: + acknowledge-mode: auto + default-requeue-rejected: false + retry: + enabled: true # 开启消费者失败重试 + initial-interval: 1000 # 初识的失败等待时长为1秒 + multiplier: 1 # 失败的等待时长倍数,下次等待时长 = multiplier * last-interval + max-attempts: 3 # 最大重试次数 + stateless: true # true无状态;false有状态。如果业务中包含事务,这里改为false + direct: + acknowledge-mode: manual + template: + mandatory: true + #排除DruidDataSourceAutoConfigure + autoconfigure: + exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure,com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration + datasource: + dynamic: + druid: + #通用校验配置 + validation-query: select 1 + #启用sql日志拦截器 + proxy-filters: + - sqlLogInterceptor + #设置默认的数据源或者数据源组,默认值即为master + primary: master + datasource: + master: + druid: + #独立校验配置 + validation-query: select 1 + #oracle校验 + #validation-query: select 1 from dual + url: ${blade.datasource.factorydata-linsy.master.url} + username: ${blade.datasource.factorydata-linsy.master.username} + password: ${blade.datasource.factorydata-linsy.master.password} + 627683: + druid: + #独立校验配置 + validation-query: select 1 + #oracle校验 + #validation-query: select 1 from dual + url: ${blade.datasource.factorydata-linsy.627683.url} + username: ${blade.datasource.factorydata-linsy.627683.username} + password: ${blade.datasource.factorydata-linsy.627683.password} +blade: + data-scope: + enabled: false diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application.yml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application.yml new file mode 100644 index 000000000..33da94b58 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/application.yml @@ -0,0 +1,31 @@ +#mybatis-plus配置 +mybatis-plus: + mapper-locations: classpath:com/logpm/**/mapper/*Mapper.xml + #实体扫描,多个package用逗号或者分号分隔 + typeAliasesPackage: com.logpm.**.entity + +#swagger扫描路径配置 +swagger: + base-packages: + - org.springblade + - com.logpm + +#oss配置 +oss: + enabled: true + name: minio + tenant-mode: false + endpoint: http://8.137.14.82:9000 + access-key: minio + secret-key: 123123123 + bucket-name: bladex + + +logging: + config: classpath:logback.xml + + +spring: + main: + allow-circular-references: true + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/logback.xml b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/logback.xml new file mode 100644 index 000000000..7170050de --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/resources/logback.xml @@ -0,0 +1,40 @@ + + + + logback + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + + + ${log.path} + + ${log.path}.%d{yyyy-MM-dd}.zip + + + %date %level [%thread] %logger{36} [%file : %line] %msg%n + + + + + + + + + + diff --git a/blade-service/logpm-factory-data/pom.xml b/blade-service/logpm-factory-data/pom.xml index ad5529046..12dc09041 100644 --- a/blade-service/logpm-factory-data/pom.xml +++ b/blade-service/logpm-factory-data/pom.xml @@ -17,6 +17,7 @@ logpm-factory-data-suofeiya logpm-factory-data-olo logpm-factory-data-jinpai + logpm-factory-data-linsy