From a4722d86d25b291802fcac8f70f32e61fa1a867c Mon Sep 17 00:00:00 2001 From: zhenghaoyu Date: Tue, 13 Jun 2023 17:30:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=9A=AE=E9=98=BF=E8=AF=BA=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3=202.?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=B7=A5=E5=8E=82token=E6=8E=A5=E5=8F=A3=203?= =?UTF-8?q?.=E4=B8=AD=E8=BD=AC=E8=AE=A2=E5=8D=95=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-biz-common/pom.xml | 31 ++++ .../common/constant/RabbitConstant.java | 58 ++++++ .../springblade/common/utils/CommonUtil.java | 24 +++ .../springblade/common/utils/TokenUtil.java | 67 +++++++ blade-service/logpm-factory/pom.xml | 5 + .../com/logpm/factory/FactoryApplication.java | 2 +- .../config/InterceptorAdapterConfig.java | 25 +++ .../factory/config/RabbitMqConfiguration.java | 53 ++++++ .../logpm/factory/config/RequestWrapper.java | 67 +++++++ .../factory/filer/HttpServletFilter.java | 29 +++ .../FactoryAccountsInterceptor.java | 86 +++++++++ .../factory/props/PanFactoryProperties.java | 20 ++ .../receiver/DirectQueueOneHandler.java | 30 +++ .../logpm/factory/snm/bean/MessageStruct.java | 23 +++ .../java/com/logpm/factory/snm/bean/Resp.java | 19 ++ .../snm/controller/FactoryAuthController.java | 77 ++++++++ .../controller/PanFactoryDataController.java | 173 ++++++++++++++++++ .../factory/snm/dto/FactoryAccountDTO.java | 9 + .../logpm/factory/snm/dto/OrderInfoDTO.java | 23 +-- .../logpm/factory/snm/dto/OrderStatusDTO.java | 57 ++++++ .../factory/snm/dto/PanFactoryOrderDTO.java | 20 ++ .../factory/snm/dto/PanPackageInfoDTO.java | 20 ++ .../factory/snm/dto/PanPackageListDTO.java | 6 + .../snm/mapper/FactoryAccountMapper.java | 17 +- .../snm/mapper/FactoryAccountMapper.xml | 20 ++ .../snm/mapper/FactoryTokenMapper.java} | 17 +- .../factory/snm/mapper/FactoryTokenMapper.xml | 20 ++ .../snm/mapper/PanFactoryOrderMapper.java} | 19 +- .../snm/mapper/PanFactoryOrderMapper.xml | 20 ++ .../snm/mapper/PanOrderStatusLogMapper.java | 31 ++++ .../snm/mapper/PanOrderStatusLogMapper.xml | 20 ++ .../snm/mapper/PanPackageInfoMapper.java | 31 ++++ .../snm/mapper/PanPackageInfoMapper.xml | 20 ++ .../snm/mapper/PanPackageListMapper.java | 31 ++++ .../snm/mapper/PanPackageListMapper.xml | 20 ++ .../snm/service/IFactoryAccountService.java | 12 ++ .../snm/service/IFactoryAuthService.java | 11 ++ .../snm/service/IFactoryTokenService.java | 15 ++ .../snm/service/IPanFactoryDataService.java | 16 ++ .../snm/service/IPanFactoryOrderService.java | 12 ++ .../service/IPanOrderStatusLogService.java | 8 + .../snm/service/IPanPackageInfoService.java | 12 ++ .../snm/service/IPanPackageListService.java | 7 + .../impl/FactoryAccountServiceImpl.java | 19 ++ .../service/impl/FactoryAuthServiceImpl.java | 78 ++++++++ .../service/impl/FactoryTokenServiceImpl.java | 49 +++++ .../impl/PanFactoryDataServiceImpl.java | 166 +++++++++++++++++ .../impl/PanFactoryOrderServiceImpl.java | 19 ++ .../impl/PanOrderStatusLogServiceImpl.java | 19 ++ .../impl/PanPackageInfoServiceImpl.java | 19 ++ .../impl/PanPackageListServiceImpl.java | 19 ++ .../src/main/resources/application-dev.yml | 6 + .../src/main/resources/application.yml | 14 +- 53 files changed, 1644 insertions(+), 47 deletions(-) create mode 100644 blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java create mode 100644 blade-biz-common/src/main/java/org/springblade/common/utils/TokenUtil.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RabbitMqConfiguration.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RequestWrapper.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/FactoryAccountsInterceptor.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/props/PanFactoryProperties.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/DirectQueueOneHandler.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/MessageStruct.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/Resp.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/FactoryAuthController.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/PanFactoryDataController.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/FactoryAccountDTO.java rename blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamGroupVO.java => blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderInfoDTO.java (69%) create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderStatusDTO.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanFactoryOrderDTO.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageInfoDTO.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageListDTO.java rename blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamStaffVO.java => blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.java (71%) create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.xml rename blade-service/{logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamStaffDTO.java => logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.java} (70%) create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.xml rename blade-service/{logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamGroupDTO.java => logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.java} (69%) create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.xml create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.xml create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.xml create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.xml create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAccountService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAuthService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryTokenService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryDataService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryOrderService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanOrderStatusLogService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageInfoService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageListService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAccountServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAuthServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryTokenServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryDataServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryOrderServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanOrderStatusLogServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageInfoServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageListServiceImpl.java diff --git a/blade-biz-common/pom.xml b/blade-biz-common/pom.xml index 34dcaa4e2..16ceeec07 100644 --- a/blade-biz-common/pom.xml +++ b/blade-biz-common/pom.xml @@ -29,6 +29,7 @@ provided + cn.hutool hutool-all @@ -45,6 +46,8 @@ javase 3.3.3 + + commons-lang commons-lang @@ -55,6 +58,34 @@ org.springframework.boot spring-boot-starter-data-redis + + + + + + + + + org.springframework.boot + spring-boot-starter-freemarker + + + org.xhtmlrenderer + core-renderer + R8 + + + commons-io + commons-io + 2.8.0 + + + + + com.auth0 + java-jwt + 3.8.2 + diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java b/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java new file mode 100644 index 000000000..6d22799d6 --- /dev/null +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java @@ -0,0 +1,58 @@ +package org.springblade.common.constant; + +/** + * RabbitMQ常量池 + * + * @author yangkai.shen + */ +public interface RabbitConstant { + /** + * 直接模式1 + */ + String DIRECT_MODE_QUEUE_ONE = "queue.direct.1"; + + /** + * 队列2 + */ + String QUEUE_TWO = "queue.2"; + + /** + * 队列3 + */ + String QUEUE_THREE = "3.queue"; + + /** + * 分列模式 + */ + String FANOUT_MODE_QUEUE = "fanout.mode"; + + /** + * 主题模式 + */ + String TOPIC_MODE_QUEUE = "topic.mode"; + + /** + * 路由1 + */ + String TOPIC_ROUTING_KEY_ONE = "queue.#"; + + /** + * 路由2 + */ + String TOPIC_ROUTING_KEY_TWO = "*.queue"; + + /** + * 路由3 + */ + String TOPIC_ROUTING_KEY_THREE = "3.queue"; + + /** + * 延迟队列 + */ + String DELAY_QUEUE = "delay.queue"; + + /** + * 延迟队列交换器 + */ + String DELAY_MODE_QUEUE = "delay.mode"; +} diff --git a/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java b/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java index 593c93427..3bd699c93 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java +++ b/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java @@ -22,6 +22,8 @@ import org.springframework.util.StringUtils; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.Random; import java.util.TimeZone; /** @@ -65,6 +67,28 @@ public class CommonUtil { return null; } + public static String createOrderCode() { + int START = 100000; //定义范围开始数字 + int END = 999999; //定义范围结束数字 + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); + String orderIdStart = format.format(new Date()); + System.out.println(orderIdStart); + Random rand = new Random(); + int i = rand.nextInt(END - START + 1) + START; + orderIdStart = orderIdStart + i + getRandomString(2); + return orderIdStart; + } + + private static String getRandomString(int length) { + String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + Random random = new Random(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + int number = random.nextInt(62); + sb.append(str.charAt(number)); + } + return sb.toString().toUpperCase(); + } } diff --git a/blade-biz-common/src/main/java/org/springblade/common/utils/TokenUtil.java b/blade-biz-common/src/main/java/org/springblade/common/utils/TokenUtil.java new file mode 100644 index 000000000..842a59554 --- /dev/null +++ b/blade-biz-common/src/main/java/org/springblade/common/utils/TokenUtil.java @@ -0,0 +1,67 @@ +package org.springblade.common.utils; + +import com.alibaba.nacos.common.utils.MD5Utils; +import com.auth0.jwt.JWT; +import com.auth0.jwt.algorithms.Algorithm; + +import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class TokenUtil { + + public static String token (String username,String password,String secrte){ + + String token = ""; + try { + Date date = new Date(); + //秘钥及加密算法 + Algorithm algorithm = Algorithm.HMAC256(secrte); + //设置头部信息 + Map header = new HashMap<>(); + header.put("typ","JWT"); + header.put("alg","HS256"); + //携带username,password信息,生成签名 + token = JWT.create() + .withHeader(header) + .withClaim("username",username) + .withClaim("password",password) + .withClaim("createtimestamp",date.getTime()) + .sign(algorithm); + }catch (Exception e){ + e.printStackTrace(); + return null; + } + return token; + } + +// public static boolean verify(String token){ +// /** +// * @desc 验证token,通过返回true +// * @params [token]需要校验的串 +// **/ +// try { +// Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET); +// JWTVerifier verifier = JWT.require(algorithm).build(); +// DecodedJWT jwt = verifier.verify(token); +// return true; +// }catch (Exception e){ +// e.printStackTrace(); +// return false; +// } +// } + public static void main(String[] args) throws NoSuchAlgorithmException { +// String username ="zhangsan"; +// String password = "123"; +// String token = token(username,password,"23123123"); +// System.out.println(token); +// boolean b = verify("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXNzd22yZCI6IjEyMyIsImV4cCI6MTU3ODE5NzQxMywidXNlcm5hbWUiOiJ6aGFuZ3NhbiJ9.IyTZT0tISQQZhGhsNuaqHGV8LD7idjUYjn3MGbulmJg"); +// System.out.println(b); + + String s = MD5Utils.encodeHexString("123456".getBytes(StandardCharsets.UTF_8)); + s = MD5Utils.md5Hex("123456".getBytes(StandardCharsets.UTF_8)); + System.out.println(s); + } +} diff --git a/blade-service/logpm-factory/pom.xml b/blade-service/logpm-factory/pom.xml index d7b881cfb..5677d0d6f 100644 --- a/blade-service/logpm-factory/pom.xml +++ b/blade-service/logpm-factory/pom.xml @@ -75,6 +75,11 @@ com.xuxueli xxl-job-core + + + + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java index d5181a390..24579a781 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java @@ -29,7 +29,7 @@ import org.springblade.core.launch.BladeApplication; public class FactoryApplication { public static void main(String[] args) { - BladeApplication.run(ModuleNameConstant.APPLICATION_FACTORY_NAME, FactoryApplication.class, args); + BladeApplication.run(ModuleNameConstant.APPLICATION_FACTORY_NAME+"-zhy", FactoryApplication.class, args); } } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java new file mode 100644 index 000000000..c73a0215b --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java @@ -0,0 +1,25 @@ +package com.logpm.factory.config; + +import com.logpm.factory.interceptor.FactoryAccountsInterceptor; +import com.logpm.factory.snm.service.IFactoryTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class InterceptorAdapterConfig implements WebMvcConfigurer { + + @Autowired + IFactoryTokenService factoryTokenService; + + @Override + public void addInterceptors(InterceptorRegistry interceptorRegistry) { + InterceptorRegistration registry = interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(factoryTokenService)); + registry.addPathPatterns("/factory/**"). + excludePathPatterns("/factory/auth/token") + .excludePathPatterns("/factory/**/sendOrders") + .excludePathPatterns("/factory/**/sendOrderStatus"); + } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RabbitMqConfiguration.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RabbitMqConfiguration.java new file mode 100644 index 000000000..41615f918 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RabbitMqConfiguration.java @@ -0,0 +1,53 @@ +package com.logpm.factory.config; + +/** + * RabbitMQ配置,主要是配置队列,如果提前存在该队列,可以省略本配置类 + * + * @author yangkai.shen + */ +//@Slf4j +//@Configuration(proxyBeanMethods = false) +public class RabbitMqConfiguration { + +// @Bean +// public RabbitTemplate rabbitTemplate() { +// CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); +// connectionFactory.setPublisherConfirms(true); +// connectionFactory.setPublisherReturns(true); +// RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); +// rabbitTemplate.setMandatory(true); +// rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> log.info("消息发送成功:correlationData({}),ack({}),cause({})", correlationData, ack, cause)); +// rabbitTemplate.setReturnCallback((message, replyCode, replyText, exchange, routingKey) -> log.info("消息丢失:exchange({}),route({}),replyCode({}),replyText({}),message:{}", exchange, routingKey, replyCode, replyText, message)); +// return rabbitTemplate; +// } + + /** + * 延迟队列 + */ +// @Bean +// public Queue delayQueue() { +// return new Queue(RabbitConstant.DIRECT_MODE_QUEUE_ONE, true); +// } + + /** + * 延迟队列交换器, x-delayed-type 和 x-delayed-message 固定 + */ +// @Bean +// public CustomExchange delayExchange() { +// Map args = Maps.newHashMap(); +// args.put("x-delayed-type", "direct"); +// return new CustomExchange("TestDirectExchange", "x-delayed-message", true, false, args); +// } + + /** + * 延迟队列绑定自定义交换器 + * + * @param delayQueue 队列 + * @param delayExchange 延迟交换器 + */ +// @Bean +// public Binding delayBinding(Queue delayQueue, CustomExchange delayExchange) { +// return BindingBuilder.bind(delayQueue).to(delayExchange).with("TestDirectRouting").noargs(); +// } + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RequestWrapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RequestWrapper.java new file mode 100644 index 000000000..6beed0a9e --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/RequestWrapper.java @@ -0,0 +1,67 @@ +package com.logpm.factory.config; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.*; + +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() { + public boolean isFinished() { + return false; + } + public boolean isReady() { + return false; + } + public void setReadListener(ReadListener readListener) {} + 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/src/main/java/com/logpm/factory/filer/HttpServletFilter.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java new file mode 100644 index 000000000..e0efd0d83 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java @@ -0,0 +1,29 @@ +package com.logpm.factory.filer; + +import com.logpm.factory.config.RequestWrapper; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +@WebFilter(urlPatterns = "/*") +public class HttpServletFilter implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + } + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + ServletRequest requestWrapper = null; + if(request instanceof HttpServletRequest) { + requestWrapper = new RequestWrapper((HttpServletRequest) request); + } + if(requestWrapper == null) { + chain.doFilter(request, response); + } else { + chain.doFilter(requestWrapper, response); + } + } + public void destroy() { + + } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/FactoryAccountsInterceptor.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/FactoryAccountsInterceptor.java new file mode 100644 index 000000000..b8c4999e4 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/FactoryAccountsInterceptor.java @@ -0,0 +1,86 @@ +package com.logpm.factory.interceptor; + +import com.alibaba.fastjson.JSONObject; +import com.logpm.factory.config.RequestWrapper; +import com.logpm.factory.snm.service.IFactoryTokenService; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +@Log4j2 +@AllArgsConstructor +public class FactoryAccountsInterceptor implements HandlerInterceptor { + + private final IFactoryTokenService factoryTokenService; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { + try { + + RequestWrapper myRequestWrapper = new RequestWrapper(request); + String body = myRequestWrapper.getBody(); + JSONObject jsonObject = JSONObject.parseObject(body); + //获取头中参数 + String token = request.getHeader("Authorization"); + String corpId = request.getHeader("corpid"); + if(StringUtil.isBlank(corpId)){ + corpId = jsonObject.getString("corpid"); + } + if(!StringUtil.hasLength(token)){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token有误"))); + return false; + } + if(!StringUtil.hasLength(corpId)){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,corpId有误"))); + return false; + } + + log.info("##########preHandle: token={}",token); + //验证token + boolean b = factoryTokenService.verifyToken(token,corpId); + if(!b){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token不存在或已过期"))); + return false; + } + return true; + } catch (Exception e) { + returnJson(response,JSONObject.toJSONString(R.fail(500,"服务异常,请联系管理员"))); + return false; + } + } + + private void returnJson(HttpServletResponse response, String json) { + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + try { + writer = response.getWriter(); + writer.print(json); + + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + if (writer != null) + writer.close(); + } + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + HandlerInterceptor.super.afterCompletion(request, response, handler, ex); + } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/props/PanFactoryProperties.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/props/PanFactoryProperties.java new file mode 100644 index 000000000..ff1dd4910 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/props/PanFactoryProperties.java @@ -0,0 +1,20 @@ +package com.logpm.factory.props; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Data +@ConfigurationProperties(prefix = "pan") +@Component +public class PanFactoryProperties { + + private String url; + + private String clientId; + + private String clientSecret; + + private String grantType; + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/DirectQueueOneHandler.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/DirectQueueOneHandler.java new file mode 100644 index 000000000..9c644acab --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/DirectQueueOneHandler.java @@ -0,0 +1,30 @@ +package com.logpm.factory.receiver; + +/** + * 直接队列1 处理器 + * + * @author yangkai.shen + */ +//@Slf4j +//@RabbitListener(queues = RabbitConstant.DIRECT_MODE_QUEUE_ONE) +//@Component +public class DirectQueueOneHandler { + +// @RabbitHandler +// public void directHandlerManualAck(PanFactoryOrderDTO factoryOrderDTO, Message message, Channel channel) { +// // 如果手动ACK,消息会被监听消费,但是消息在队列中依旧存在,如果 未配置 acknowledge-mode 默认是会在消费完毕后自动ACK掉 +// final long deliveryTag = message.getMessageProperties().getDeliveryTag(); +// try { +// log.info("直接队列1,手动ACK,接收消息:{}", factoryOrderDTO); +// //通知 MQ 消息已被成功消费,可以ACK了 +// channel.basicAck(deliveryTag, false); +// } catch (IOException e) { +// try { +// // 处理失败,重新压入MQ +// channel.basicRecover(); +// } catch (IOException e1) { +// e1.printStackTrace(); +// } +// } +// } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/MessageStruct.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/MessageStruct.java new file mode 100644 index 000000000..8f11e6ee6 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/MessageStruct.java @@ -0,0 +1,23 @@ +package com.logpm.factory.snm.bean; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 测试消息体 + * + * @author yangkai.shen + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MessageStruct implements Serializable { + private static final long serialVersionUID = 392365881428311040L; + + private String message; +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/Resp.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/Resp.java new file mode 100644 index 000000000..8ff501472 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/bean/Resp.java @@ -0,0 +1,19 @@ +package com.logpm.factory.snm.bean; + +import lombok.Data; +import org.springblade.core.tool.api.R; + +@Data +public class Resp extends R { + + private String orderNo; + + public static Resp successOrderNo(String orderNo,String msg){ + Resp resp = new Resp(); + resp.setMsg(msg); + resp.setCode(1); + resp.setSuccess(true); + resp.setOrderNo(orderNo); + return resp; + } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/FactoryAuthController.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/FactoryAuthController.java new file mode 100644 index 000000000..01fc484c5 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/FactoryAuthController.java @@ -0,0 +1,77 @@ +/* + * 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.factory.snm.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.logpm.factory.snm.dto.FactoryAccountDTO; +import com.logpm.factory.snm.service.IFactoryAuthService; +import com.logpm.factory.snm.service.IPanFactoryDataService; +import com.logpm.factory.snm.vo.FactoryTokenVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.tool.api.R; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; + +/** + * 皮阿诺数据 控制器 + * + * @author zhy + * @since 2023-06-06 + */ +@Log4j2 +@RestController +@AllArgsConstructor +@RequestMapping("/factory/auth") +@Api(value = "工厂授权数据", tags = "工厂授权接口") +public class FactoryAuthController extends BladeController { + + private final IFactoryAuthService factoryAuthService; + + @ResponseBody + @PostMapping("/token") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "获取token推送", notes = "传入factoryAccountDTO") + public R token(@Validated @RequestBody FactoryAccountDTO factoryAccountDTO, HttpServletResponse response) { + log.info("############token: 获取账号token"); + //通过企业id 应用id 秘钥 获取对应的token + String corpid = factoryAccountDTO.getCorpid();//企业id + String appkey = factoryAccountDTO.getAppkey();//应用id + String appsecret = factoryAccountDTO.getAppsecret();//秘钥 + + try{ + FactoryTokenVO factoryTokenVO = factoryAuthService.getToken(corpid,appkey,appsecret); + String token = factoryTokenVO.getToken(); + //把token放入头 + response.setHeader("Authorization",token); + return R.data(factoryTokenVO); + }catch (CustomerException e){ + log.error(e.getMessage(),e); + return R.fail(e.code,e.message); + }catch (Exception e){ + log.error(e.getMessage(),e); + return R.fail(400,e.getMessage()); + } + } + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/PanFactoryDataController.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/PanFactoryDataController.java new file mode 100644 index 000000000..2b1bbe90c --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/controller/PanFactoryDataController.java @@ -0,0 +1,173 @@ +/* + * 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.factory.snm.controller; + +import cn.hutool.core.bean.BeanUtil; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.logpm.factory.snm.bean.Resp; +import com.logpm.factory.snm.dto.*; +import com.logpm.factory.snm.entity.PanFactoryOrder; +import com.logpm.factory.snm.entity.PanPackageInfo; +import com.logpm.factory.snm.entity.PanPackageList; +import com.logpm.factory.snm.service.IPanFactoryDataService; +import com.logpm.factory.snm.service.IPanFactoryOrderService; +import com.logpm.factory.snm.service.IPanPackageInfoService; +import com.logpm.factory.snm.service.IPanPackageListService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.tool.api.R; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; + +/** + * 皮阿诺数据 控制器 + * + * @author zhy + * @since 2023-06-06 + */ +@Log4j2 +@RestController +@AllArgsConstructor +@RequestMapping("/factory/pan") +@Api(value = "工厂数据", tags = "工厂数据接口") +public class PanFactoryDataController extends BladeController { + + private final IPanFactoryOrderService factoryOrderService; + private final IPanPackageInfoService packageInfoService; + private final IPanPackageListService packageListService; + + + private final IPanFactoryDataService factoryDataService; + +// @ResponseBody +// @PostMapping("/token") +// @ApiOperationSupport(order = 1) +// @ApiOperation(value = "获取token推送", notes = "传入factoryAccountDTO") +// public R token(@Validated @RequestBody FactoryAccountDTO factoryAccountDTO, HttpServletResponse response) { +// log.info("############token: 获取账号token"); +// //通过企业id 应用id 秘钥 获取对应的token +// String corpid = factoryAccountDTO.getCorpid();//企业id +// String appkey = factoryAccountDTO.getAppkey();//应用id +// String appsecret = factoryAccountDTO.getAppsecret();//秘钥 +// +// try{ +// FactoryTokenVO factoryTokenVO = factoryDataService.getToken(corpid,appkey,appsecret); +// String token = factoryTokenVO.getToken(); +// //把token放入头 +// response.setHeader("Authorization",token); +// return R.data(factoryTokenVO); +// }catch (CustomerException e){ +// log.error(e.getMessage(),e); +// return R.fail(e.code,e.message); +// }catch (Exception e){ +// log.error(e.getMessage(),e); +// return R.fail(400,e.getMessage()); +// } +// } + + + + /** + * 工厂数据推送接口 + */ + @ResponseBody + @PostMapping("/data") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "通常数据推送", notes = "传入factoryOrderDTO") + public Resp data(@Validated @RequestBody PanFactoryOrderDTO factoryOrderDTO, HttpServletRequest request) { + log.info("############data: "); + String corpId = request.getHeader("corpId"); + + PanFactoryOrder factoryOrder = new PanFactoryOrder(); + BeanUtil.copyProperties(factoryOrderDTO,factoryOrder); + factoryOrder.setCorpid(corpId); + //保存订单数据 + factoryOrderService.save(factoryOrder); + + List packageInfos = factoryOrderDTO.getORDER_ATTRIBUTES(); + + for (PanPackageInfoDTO dto:packageInfos){ + PanPackageInfo packageInfo = new PanPackageInfo(); + BeanUtil.copyProperties(dto,packageInfo); + packageInfo.setOrderId(factoryOrder.getId()); + //保存包件信息数据 + //因为需要先保存包件明细需要包件的id + packageInfoService.save(packageInfo); + + //再存入包件明细 + List PanPackagelist = new ArrayList<>(); + List order_attributes_line = dto.getORDER_ATTRIBUTES_LINE(); + for (PanPackageListDTO panPackageListDTO:order_attributes_line){ + PanPackageList panPackageList = new PanPackageList(); + BeanUtil.copyProperties(panPackageListDTO,panPackageList); + panPackageList.setPackageId(packageInfo.getId()); + PanPackagelist.add(panPackageList); + } + packageListService.saveBatch(PanPackagelist); + } + + return Resp.successOrderNo(factoryOrder.getOrderNo(),"SUCCESS"); + } + + + @ResponseBody + @PostMapping("/sendOrders") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "订单数据推送", notes = "传入orderInfoDTO") + public R sendOrders(@Validated @RequestBody OrderInfoDTO orderInfoDTO) { + log.info("############sendOrders: "); + try{ + factoryDataService.handleData(orderInfoDTO); + }catch (CustomerException e){ + log.error(e.message,e); + return R.fail(e.code,e.message); + }catch (Exception e){ + log.error("############sendOrders: 系统异常",e); + return R.fail(500,"############sendOrders: 系统异常"); + } + return R.success("SUCCESS"); + } + + + @ResponseBody + @PostMapping("/sendOrderStatus") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "订单状态推送", notes = "传入orderInfoDTO") + public R sendOrderStatus(@RequestBody OrderStatusDTO orderStatusDTO) { + log.info("############sendOrderStatus: "); + try{ + factoryDataService.handleStatusData(orderStatusDTO); + }catch (CustomerException e){ + log.error(e.message,e); + return R.fail(e.code,e.message); + }catch (Exception e){ + log.error("############sendOrderStatus: 系统异常",e); + return R.fail(500,"############sendOrderStatus: 系统异常"); + } + return Resp.success("SUCCESS"); + } + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/FactoryAccountDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/FactoryAccountDTO.java new file mode 100644 index 000000000..a0fb26e44 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/FactoryAccountDTO.java @@ -0,0 +1,9 @@ +package com.logpm.factory.snm.dto; + +import com.logpm.factory.snm.entity.FactoryAccount; +import lombok.Data; + +@Data +public class FactoryAccountDTO extends FactoryAccount { + +} diff --git a/blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamGroupVO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderInfoDTO.java similarity index 69% rename from blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamGroupVO.java rename to blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderInfoDTO.java index 4875503bd..63c2575b6 100644 --- a/blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamGroupVO.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderInfoDTO.java @@ -14,26 +14,27 @@ * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ -package com.logpm.basic.vo; +package com.logpm.factory.snm.dto; -import com.logpm.basic.entity.BasicTeamGroupEntity; import lombok.Data; -import lombok.EqualsAndHashCode; -import java.util.ArrayList; -import java.util.List; +import javax.validation.constraints.NotEmpty; /** - * 基础班组表 视图实体类 + * PHP传过来的OrderInfo * - * @author BladeX - * @since 2023-05-25 + * @author zhy + * @since 2023-06-12 */ @Data -@EqualsAndHashCode(callSuper = true) -public class BasicTeamGroupVO extends BasicTeamGroupEntity { +public class OrderInfoDTO { private static final long serialVersionUID = 1L; - private List staffs = new ArrayList<>(); + @NotEmpty(message = "客户订单号不能为空") + private String orderNo;//客户订单号 + private String loadingList;//WMS装车清单号 + + @NotEmpty(message = "物流单号不能为空") + private String logiBillNo;//物流单号 } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderStatusDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderStatusDTO.java new file mode 100644 index 000000000..a0074e0d8 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/OrderStatusDTO.java @@ -0,0 +1,57 @@ +/* + * 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.factory.snm.dto; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +/** + * OrderStatus + * + * @author zhy + * @since 2023-06-12 + */ +@Data +public class OrderStatusDTO { + private static final long serialVersionUID = 1L; + + @NotEmpty(message = "派车单号不能为空") + private String dispatchNumber;//派车单号 + + @NotEmpty(message = "客户订单号不能为空") + private String orderNo;//客户订单号 + + @NotEmpty(message = "物流单号不能为空") + private String logiBillNo;//物流单号 + + @NotEmpty(message = "包件码不能为空") + private String unitNo;//包件码 + + @NotEmpty(message = "操作时间不能为空") + private String operationTime;//操作时间 + + @NotEmpty(message = "当前仓库不能为空") + private String currentWarehouse;//当前仓库 + + @NotEmpty(message = "目的仓库") + private String destinationWarehouse;//目的仓库 + + @NotEmpty(message = "状态") + private String status;//状态 + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanFactoryOrderDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanFactoryOrderDTO.java new file mode 100644 index 000000000..fea348d58 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanFactoryOrderDTO.java @@ -0,0 +1,20 @@ +package com.logpm.factory.snm.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.logpm.factory.snm.entity.PanFactoryOrder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = true) +public class PanFactoryOrderDTO extends PanFactoryOrder { + + @Valid + @JsonProperty("ORDER_ATTRIBUTES") + private List ORDER_ATTRIBUTES = new ArrayList<>(); + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageInfoDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageInfoDTO.java new file mode 100644 index 000000000..02bc61e44 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageInfoDTO.java @@ -0,0 +1,20 @@ +package com.logpm.factory.snm.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.logpm.factory.snm.entity.PanPackageInfo; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = true) +public class PanPackageInfoDTO extends PanPackageInfo { + + @Valid + @JsonProperty("ORDER_ATTRIBUTES_LINE") + private List ORDER_ATTRIBUTES_LINE = new ArrayList<>(); + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageListDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageListDTO.java new file mode 100644 index 000000000..21f97d68a --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/dto/PanPackageListDTO.java @@ -0,0 +1,6 @@ +package com.logpm.factory.snm.dto; + +import com.logpm.factory.snm.entity.PanPackageList; + +public class PanPackageListDTO extends PanPackageList { +} diff --git a/blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamStaffVO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.java similarity index 71% rename from blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamStaffVO.java rename to blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.java index f5e4ff43b..f1af7eb5f 100644 --- a/blade-service-api/logpm-basic-api/src/main/java/com/logpm/basic/vo/BasicTeamStaffVO.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.java @@ -14,21 +14,18 @@ * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ -package com.logpm.basic.vo; +package com.logpm.factory.snm.mapper; -import com.logpm.basic.entity.BasicTeamStaffEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.snm.entity.FactoryAccount; /** - * 班组人员表 视图实体类 + * 工厂账号接口日志 Mapper 接口 * * @author zhy - * @since 2023-05-29 + * @since 2023-03-28 */ -@Data -@EqualsAndHashCode(callSuper = true) -public class BasicTeamStaffVO extends BasicTeamStaffEntity { - private static final long serialVersionUID = 1L; +public interface FactoryAccountMapper extends BaseMapper { + } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.xml new file mode 100644 index 000000000..a61c851ff --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryAccountMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamStaffDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.java similarity index 70% rename from blade-service/logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamStaffDTO.java rename to blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.java index 3711ab418..25c4b28e8 100644 --- a/blade-service/logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamStaffDTO.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.java @@ -14,21 +14,18 @@ * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ -package com.logpm.basic.dto; +package com.logpm.factory.snm.mapper; -import com.logpm.basic.entity.BasicTeamStaffEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.snm.entity.FactoryToken; /** - * 班组人员表 数据传输对象实体类 + * 工厂账号接口日志 Mapper 接口 * * @author zhy - * @since 2023-05-29 + * @since 2023-03-28 */ -@Data -@EqualsAndHashCode(callSuper = true) -public class BasicTeamStaffDTO extends BasicTeamStaffEntity { - private static final long serialVersionUID = 1L; +public interface FactoryTokenMapper extends BaseMapper { + } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.xml new file mode 100644 index 000000000..cf1083dff --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/FactoryTokenMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamGroupDTO.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.java similarity index 69% rename from blade-service/logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamGroupDTO.java rename to blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.java index 9a9351533..2fed1de42 100644 --- a/blade-service/logpm-basic/src/main/java/com/logpm/basic/dto/BasicTeamGroupDTO.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.java @@ -14,21 +14,18 @@ * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ -package com.logpm.basic.dto; +package com.logpm.factory.snm.mapper; -import com.logpm.basic.entity.BasicTeamGroupEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.snm.entity.PanFactoryOrder; /** - * 基础班组表 数据传输对象实体类 + * 工厂推送数据接口日志 Mapper 接口 * - * @author BladeX - * @since 2023-05-25 + * @author zhy + * @since 2023-03-28 */ -@Data -@EqualsAndHashCode(callSuper = true) -public class BasicTeamGroupDTO extends BasicTeamGroupEntity { - private static final long serialVersionUID = 1L; +public interface PanFactoryOrderMapper extends BaseMapper { + } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.xml new file mode 100644 index 000000000..bd0c7d410 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanFactoryOrderMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.java new file mode 100644 index 000000000..231109f40 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.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.factory.snm.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.snm.entity.PanOrderStatusLog; + +/** + * 工厂推送数据接口日志 Mapper 接口 + * + * @author zhy + * @since 2023-03-28 + */ +public interface PanOrderStatusLogMapper extends BaseMapper { + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.xml new file mode 100644 index 000000000..ce887dc99 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanOrderStatusLogMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.java new file mode 100644 index 000000000..0fc1935bd --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.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.factory.snm.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.snm.entity.PanPackageInfo; + +/** + * 工厂推送数据接口日志 Mapper 接口 + * + * @author zhy + * @since 2023-03-28 + */ +public interface PanPackageInfoMapper extends BaseMapper { + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.xml new file mode 100644 index 000000000..0c5fd7074 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageInfoMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.java new file mode 100644 index 000000000..820831ab6 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.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.factory.snm.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.snm.entity.PanPackageList; + +/** + * 工厂推送数据接口日志 Mapper 接口 + * + * @author zhy + * @since 2023-03-28 + */ +public interface PanPackageListMapper extends BaseMapper { + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.xml new file mode 100644 index 000000000..cbd578f9b --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/PanPackageListMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAccountService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAccountService.java new file mode 100644 index 000000000..f737da042 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAccountService.java @@ -0,0 +1,12 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.entity.FactoryAccount; +import org.springblade.core.mp.base.BaseService; + +/** + * 工厂推送数据接口 + */ +public interface IFactoryAccountService extends BaseService { + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAuthService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAuthService.java new file mode 100644 index 000000000..63b3f2a16 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryAuthService.java @@ -0,0 +1,11 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.vo.FactoryTokenVO; + +import java.security.NoSuchAlgorithmException; + +public interface IFactoryAuthService { + + FactoryTokenVO getToken(String corpId, String appKey, String appSecret) throws NoSuchAlgorithmException; + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryTokenService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryTokenService.java new file mode 100644 index 000000000..6e6982cc9 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IFactoryTokenService.java @@ -0,0 +1,15 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.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/src/main/java/com/logpm/factory/snm/service/IPanFactoryDataService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryDataService.java new file mode 100644 index 000000000..4291ce42d --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryDataService.java @@ -0,0 +1,16 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.dto.OrderInfoDTO; +import com.logpm.factory.snm.dto.OrderStatusDTO; + +/** + * 工厂推送数据接口 + */ +public interface IPanFactoryDataService { + + + + void handleData(OrderInfoDTO orderInfoDTO); + + void handleStatusData(OrderStatusDTO orderStatusDTO); +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryOrderService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryOrderService.java new file mode 100644 index 000000000..8e0ec1d52 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanFactoryOrderService.java @@ -0,0 +1,12 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.entity.PanFactoryOrder; +import org.springblade.core.mp.base.BaseService; + +/** + * 工厂推送数据接口 + */ +public interface IPanFactoryOrderService extends BaseService { + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanOrderStatusLogService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanOrderStatusLogService.java new file mode 100644 index 000000000..d4c4bf09b --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanOrderStatusLogService.java @@ -0,0 +1,8 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.entity.PanOrderStatusLog; +import org.springblade.core.mp.base.BaseService; + +public interface IPanOrderStatusLogService extends BaseService { + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageInfoService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageInfoService.java new file mode 100644 index 000000000..8a135d893 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageInfoService.java @@ -0,0 +1,12 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.entity.PanPackageInfo; +import org.springblade.core.mp.base.BaseService; + +/** + * 工厂推送包件数据接口 + */ +public interface IPanPackageInfoService extends BaseService { + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageListService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageListService.java new file mode 100644 index 000000000..828040571 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IPanPackageListService.java @@ -0,0 +1,7 @@ +package com.logpm.factory.snm.service; + +import com.logpm.factory.snm.entity.PanPackageList; +import org.springblade.core.mp.base.BaseService; + +public interface IPanPackageListService extends BaseService { +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAccountServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAccountServiceImpl.java new file mode 100644 index 000000000..56f1e4a77 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAccountServiceImpl.java @@ -0,0 +1,19 @@ +package com.logpm.factory.snm.service.impl; + +import com.logpm.factory.snm.entity.FactoryAccount; +import com.logpm.factory.snm.mapper.FactoryAccountMapper; +import com.logpm.factory.snm.service.IFactoryAccountService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +@AllArgsConstructor +@Service +public class FactoryAccountServiceImpl extends BaseServiceImpl implements IFactoryAccountService { + + private static final Logger logger = LoggerFactory.getLogger(FactoryAccountServiceImpl.class); + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAuthServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAuthServiceImpl.java new file mode 100644 index 000000000..ae76876b8 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryAuthServiceImpl.java @@ -0,0 +1,78 @@ +package com.logpm.factory.snm.service.impl; + +import com.alibaba.nacos.common.utils.MD5Utils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.logpm.factory.snm.entity.FactoryAccount; +import com.logpm.factory.snm.entity.FactoryToken; +import com.logpm.factory.snm.service.IFactoryAccountService; +import com.logpm.factory.snm.service.IFactoryAuthService; +import com.logpm.factory.snm.service.IFactoryTokenService; +import com.logpm.factory.snm.vo.FactoryTokenVO; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.common.exception.CustomerException; +import org.springblade.common.utils.TokenUtil; +import org.springframework.stereotype.Service; + +import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.Objects; + +@AllArgsConstructor +@Service +public class FactoryAuthServiceImpl implements IFactoryAuthService { + + private static final Logger logger = LoggerFactory.getLogger(FactoryAuthServiceImpl.class); + + private final IFactoryAccountService factoryAccountService; + private final IFactoryTokenService factoryTokenService; + + @Override + public FactoryTokenVO getToken(String corpId, String appKey, String appSecret) throws NoSuchAlgorithmException { + + FactoryTokenVO factoryTokenVO = new FactoryTokenVO(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("corpid",corpId) + .eq("appkey",appKey) + .eq("appsecret",appSecret); + FactoryAccount factoryAccount = factoryAccountService.getOne(queryWrapper); + if(Objects.isNull(factoryAccount)){ + logger.warn("未存在对应账户corpid={},appkey={},appsecret={}",corpId,appKey,appSecret); + throw new CustomerException(400,"未存在对应账户,请联系管理员"); + } + + //生成token + String token = TokenUtil.token(corpId, appKey, appSecret); + //生成token摘要 + String tokenAbst = MD5Utils.md5Hex(token.getBytes(StandardCharsets.UTF_8)); + //过期时间生成 + LocalDateTime start = LocalDateTime.now(); + LocalDateTime end = start.plusMinutes(30); + Date date = Date.from( end.atZone( ZoneId.systemDefault()).toInstant()); + + //查询是否有当前账户的token数据 + QueryWrapper queryTokenWrapper = new QueryWrapper<>(); + queryWrapper.eq("corpid",corpId); + FactoryToken factoryToken = factoryTokenService.getOne(queryTokenWrapper); + if(Objects.isNull(factoryToken)){ + factoryToken = new FactoryToken(); + } + //保存新的token + factoryToken.setToken(token); + factoryToken.setTokenAbst(tokenAbst); + factoryToken.setCorpid(corpId); + factoryToken.setExpireTime(date); + factoryTokenService.saveOrUpdate(factoryToken); + + factoryTokenVO.setToken(token); + factoryTokenVO.setExpireTime(date); + factoryTokenVO.setExpireTimeLong(date.getTime()); + return factoryTokenVO; + } + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryTokenServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryTokenServiceImpl.java new file mode 100644 index 000000000..2138208ef --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/FactoryTokenServiceImpl.java @@ -0,0 +1,49 @@ +package com.logpm.factory.snm.service.impl; + +import com.alibaba.nacos.common.utils.MD5Utils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.logpm.factory.snm.entity.FactoryToken; +import com.logpm.factory.snm.mapper.FactoryTokenMapper; +import com.logpm.factory.snm.service.IFactoryTokenService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.Objects; + +@AllArgsConstructor +@Service +public class FactoryTokenServiceImpl extends BaseServiceImpl implements IFactoryTokenService { + + private static final Logger logger = LoggerFactory.getLogger(FactoryTokenServiceImpl.class); + + @Override + public boolean verifyToken(String token, String corpId) throws NoSuchAlgorithmException { + logger.info("#########verifyToken: 验证token开始"); + //先生成token摘要 + String tokenAbst = MD5Utils.md5Hex(token.getBytes(StandardCharsets.UTF_8)); + + //编写查询条件 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("token_abst",tokenAbst) + .eq("corpid",corpId); + FactoryToken factoryToken = baseMapper.selectOne(queryWrapper); + if(Objects.isNull(factoryToken)){ + logger.warn("#########verifyToken: token验证不通过 token={},corpid={}",token,corpId); + return false; + } + Long expireTimeLong = factoryToken.getExpireTime().getTime(); + Long now = new Date().getTime(); + //判断是否过期 + if(now > expireTimeLong){ + logger.warn("#########verifyToken: token验证不通过 已过期 token={},corpId={}",token,corpId); + return false; + } + return true; + } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryDataServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryDataServiceImpl.java new file mode 100644 index 000000000..6910b1aaa --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryDataServiceImpl.java @@ -0,0 +1,166 @@ +package com.logpm.factory.snm.service.impl; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.logpm.factory.props.PanFactoryProperties; +import com.logpm.factory.snm.dto.OrderInfoDTO; +import com.logpm.factory.snm.dto.OrderStatusDTO; +import com.logpm.factory.snm.entity.PanFactoryOrder; +import com.logpm.factory.snm.entity.PanOrderStatusLog; +import com.logpm.factory.snm.service.*; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@AllArgsConstructor +@Service +public class PanFactoryDataServiceImpl implements IPanFactoryDataService { + + private static final Logger logger = LoggerFactory.getLogger(PanFactoryDataServiceImpl.class); + +// private final IFactoryAccountService factoryAccountService; +// private final IFactoryTokenService factoryTokenService; + + private final IPanFactoryOrderService factoryOrderService; + + private final PanFactoryProperties panFactoryProperties; + private final IPanOrderStatusLogService panOrderStatusLogService; + +// @Override +// public FactoryTokenVO getToken(String corpId, String appKey, String appSecret) throws NoSuchAlgorithmException { +// +// FactoryTokenVO factoryTokenVO = new FactoryTokenVO(); +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("corpid",corpId) +// .eq("appkey",appKey) +// .eq("appsecret",appSecret); +// FactoryAccount factoryAccount = factoryAccountService.getOne(queryWrapper); +// if(Objects.isNull(factoryAccount)){ +// logger.warn("未存在对应账户corpid={},appkey={},appsecret={}",corpId,appKey,appSecret); +// throw new CustomerException(400,"未存在对应账户,请联系管理员"); +// } +// +// //生成token +// String token = TokenUtil.token(corpId, appKey, appSecret); +// //生成token摘要 +// String tokenAbst = MD5Utils.md5Hex(token.getBytes(StandardCharsets.UTF_8)); +// //过期时间生成 +// LocalDateTime start = LocalDateTime.now(); +// LocalDateTime end = start.plusMinutes(30); +// Date date = Date.from( end.atZone( ZoneId.systemDefault()).toInstant()); +// +// //查询是否有当前账户的token数据 +// QueryWrapper queryTokenWrapper = new QueryWrapper<>(); +// queryWrapper.eq("corpid",corpId); +// FactoryToken factoryToken = factoryTokenService.getOne(queryTokenWrapper); +// if(Objects.isNull(factoryToken)){ +// factoryToken = new FactoryToken(); +// } +// //保存新的token +// factoryToken.setToken(token); +// factoryToken.setTokenAbst(tokenAbst); +// factoryToken.setCorpid(corpId); +// factoryToken.setExpireTime(date); +// factoryTokenService.saveOrUpdate(factoryToken); +// +// factoryTokenVO.setToken(token); +// factoryTokenVO.setExpireTime(date); +// factoryTokenVO.setExpireTimeLong(date.getTime()); +// return factoryTokenVO; +// } + + @Transactional(rollbackFor = Exception.class) + @Override + public void handleData(OrderInfoDTO orderInfoDTO) { + //根据客户订单号去查询WMS装车清单号 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("order_no",orderInfoDTO.getOrderNo()); + PanFactoryOrder panFactoryOrder = factoryOrderService.getOne(queryWrapper); + String loadingList = panFactoryOrder.getLoadingList();//装车清单编号 + orderInfoDTO.setLoadingList(loadingList); + + //推送到皮阿诺系统 + String url = ""; +// String result = HttpRequest.post(url+"/oauth/oauth/token").form(map).timeout(5 * 1000).execute().body(); + + } + + @Override + public void handleStatusData(OrderStatusDTO orderStatusDTO) { + + //先保存原始请求数据 + PanOrderStatusLog panOrderStatusLog = new PanOrderStatusLog(); + panOrderStatusLog.setArgs(JSONObject.toJSONString(orderStatusDTO)); + panOrderStatusLog.setStatus(1); + panOrderStatusLogService.save(panOrderStatusLog); + + //拼接参数 + Map map = new HashMap<>(); + map.put("payload",JSONObject.toJSONString(orderStatusDTO)); + + //先获取token + String panToken = getPanToken(); + //处理逻辑 + String result = HttpRequest.post(panFactoryProperties.getUrl()+"/hitf/v1/rest/invoke?namespace=HZERO&serverCode=OPEN&interfaceCode=HUITONG_RECEIVE") + .header("Authorization","Bearer "+panToken) +// .header("Content-Type","application/json") + .form(map).timeout(5 * 1000) + .execute() + .body(); + + logger.info("##############handleStatusData: 推送包件状态返回参数 {}",result); + + //把结果字符串转为json对象 + JSONObject jsonObject = JSONObject.parseObject(result); + JSONObject payload = jsonObject.getJSONObject("payload"); + if(!Objects.isNull(payload)){ + Integer code = payload.getInteger("code"); + String message = payload.getString("data"); + if(code.equals(1)){ + logger.info("##########handleStatusData: 物流状态传递成功"); + panOrderStatusLog.setStatus(0); + panOrderStatusLogService.saveOrUpdate(panOrderStatusLog); + }else{ + throw new CustomerException(400,message); + } + }else{ + throw new CustomerException(400,"返回格式有误:"+result); + } + } + + + private String getPanToken(){ + Map map = new HashMap<>(); + map.put("client_id",panFactoryProperties.getClientId()); + map.put("client_secret",panFactoryProperties.getClientSecret()); + map.put("grant_type",panFactoryProperties.getGrantType()); + + String result = HttpRequest.post(panFactoryProperties.getUrl()+"/oauth/oauth/token") + .header("Content-Type","application/x-www-form-urlencoded") + .form(map).timeout(5 * 1000) + .execute() + .body(); + + logger.info("##############getPanToken: 获取皮阿诺token返回参数 {}",result); + + //获取的结果转成json对象 + JSONObject jsonObject = JSONObject.parseObject(result); + String access_token = jsonObject.getString("access_token"); + if(StringUtil.hasLength(access_token)){ + return access_token; + }else{ + throw new CustomerException(402,"获取皮阿诺token失败"); + } + } + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryOrderServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryOrderServiceImpl.java new file mode 100644 index 000000000..7aa0d94ad --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanFactoryOrderServiceImpl.java @@ -0,0 +1,19 @@ +package com.logpm.factory.snm.service.impl; + +import com.logpm.factory.snm.entity.PanFactoryOrder; +import com.logpm.factory.snm.mapper.PanFactoryOrderMapper; +import com.logpm.factory.snm.service.IPanFactoryOrderService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +@AllArgsConstructor +@Service +public class PanFactoryOrderServiceImpl extends BaseServiceImpl implements IPanFactoryOrderService { + + private static final Logger logger = LoggerFactory.getLogger(PanFactoryOrderServiceImpl.class); + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanOrderStatusLogServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanOrderStatusLogServiceImpl.java new file mode 100644 index 000000000..c69058c1a --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanOrderStatusLogServiceImpl.java @@ -0,0 +1,19 @@ +package com.logpm.factory.snm.service.impl; + +import com.logpm.factory.snm.entity.PanOrderStatusLog; +import com.logpm.factory.snm.mapper.PanOrderStatusLogMapper; +import com.logpm.factory.snm.service.IPanOrderStatusLogService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +@AllArgsConstructor +@Service +public class PanOrderStatusLogServiceImpl extends BaseServiceImpl implements IPanOrderStatusLogService { + + private static final Logger logger = LoggerFactory.getLogger(PanOrderStatusLogServiceImpl.class); + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageInfoServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageInfoServiceImpl.java new file mode 100644 index 000000000..22d759968 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageInfoServiceImpl.java @@ -0,0 +1,19 @@ +package com.logpm.factory.snm.service.impl; + +import com.logpm.factory.snm.entity.PanPackageInfo; +import com.logpm.factory.snm.mapper.PanPackageInfoMapper; +import com.logpm.factory.snm.service.IPanPackageInfoService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +@AllArgsConstructor +@Service +public class PanPackageInfoServiceImpl extends BaseServiceImpl implements IPanPackageInfoService { + + private static final Logger logger = LoggerFactory.getLogger(PanPackageInfoServiceImpl.class); + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageListServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageListServiceImpl.java new file mode 100644 index 000000000..f4de7b4f1 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/PanPackageListServiceImpl.java @@ -0,0 +1,19 @@ +package com.logpm.factory.snm.service.impl; + +import com.logpm.factory.snm.entity.PanPackageList; +import com.logpm.factory.snm.mapper.PanPackageListMapper; +import com.logpm.factory.snm.service.IPanPackageListService; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +@AllArgsConstructor +@Service +public class PanPackageListServiceImpl extends BaseServiceImpl implements IPanPackageListService { + + private static final Logger logger = LoggerFactory.getLogger(PanPackageListServiceImpl.class); + + +} diff --git a/blade-service/logpm-factory/src/main/resources/application-dev.yml b/blade-service/logpm-factory/src/main/resources/application-dev.yml index ffd7f1130..88c70d307 100644 --- a/blade-service/logpm-factory/src/main/resources/application-dev.yml +++ b/blade-service/logpm-factory/src/main/resources/application-dev.yml @@ -42,3 +42,9 @@ spring: url: ${blade.datasource.factory.slave.url} username: ${blade.datasource.factory.slave.username} password: ${blade.datasource.factory.slave.password} + +pan: + url: http://157.122.179.34:15019 + clientId: hzero-front-dev + clientSecret: c2VjcmV0 + grantType: client_credentials diff --git a/blade-service/logpm-factory/src/main/resources/application.yml b/blade-service/logpm-factory/src/main/resources/application.yml index 6c0998ed4..ed6606aa2 100644 --- a/blade-service/logpm-factory/src/main/resources/application.yml +++ b/blade-service/logpm-factory/src/main/resources/application.yml @@ -35,16 +35,22 @@ logging: spring: main: allow-circular-references: true - - + #rabbitmq配置 +# rabbitmq: +# host: 192.168.2.100 +# port: 5672 +# username: admin +# password: admin +# #虚拟host 可以不设置,使用server默认host +# virtual-host: / xxl: job: accessToken: '' admin: - addresses: http://192.168.2.110:7009/xxl-job-admin + addresses: http://127.0.0.1:7009/xxl-job-admin executor: appname: logpm-factory-xxljob - ip: 192.168.2.110 + ip: 127.0.0.1 logpath: ../data/applogs/logpm-factory-xxljob/jobhandler logretentiondays: -1 port: 7018