From d4dcc3c5ddba3cdf116a244b5de2072bfd452981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 Apr 2026 11:09:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(qms):=20=E6=96=B0=E5=A2=9EQMS=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建QMS管理后台应用模块(nflg-qms-admin) - 添加序列号生成服务支持重试机制 - 集成分布式追踪和Loki日志收集 - 配置Nacos服务发现和SSO单点登录 - 添加部署测试工具类用于SIT环境发布 - 生成TSID唯一标识工具类 - 创建数据库操作仓库模块(nflg-wms-repository) - 更新父级项目配置添加QMS模块支持 - 修改WMS管理后台名称标识区分 --- nflg-qms-admin/.apifox-helper.properties | 1 + nflg-qms-admin/pom.xml | 277 +++++++++++++++ .../com/nflg/qms/admin/AdminApplication.java | 27 ++ .../BasdeSerialNumberControllerService.java | 48 +++ .../java/com/nflg/qms/admin/util/KeyUtil.java | 14 + .../src/main/resources/application-dev.yml | 30 ++ .../src/main/resources/application-prod.yml | 30 ++ .../src/main/resources/application-sit.yml | 30 ++ .../src/main/resources/application.yml | 48 +++ .../src/main/resources/logback-spring.xml | 106 ++++++ .../src/test/java/DeploySitTest.java | 332 ++++++++++++++++++ nflg-wms-admin/pom.xml | 2 +- .../com/nflg/wms/admin/AdminApplication.java | 2 +- nflg-wms-repository/pom.xml | 1 - .../shipment/config/RestTemplateConfig.java | 21 -- .../starter}/config/RestTemplateConfig.java | 2 +- pom.xml | 1 + 17 files changed, 947 insertions(+), 25 deletions(-) create mode 100644 nflg-qms-admin/.apifox-helper.properties create mode 100644 nflg-qms-admin/pom.xml create mode 100644 nflg-qms-admin/src/main/java/com/nflg/qms/admin/AdminApplication.java create mode 100644 nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/BasdeSerialNumberControllerService.java create mode 100644 nflg-qms-admin/src/main/java/com/nflg/qms/admin/util/KeyUtil.java create mode 100644 nflg-qms-admin/src/main/resources/application-dev.yml create mode 100644 nflg-qms-admin/src/main/resources/application-prod.yml create mode 100644 nflg-qms-admin/src/main/resources/application-sit.yml create mode 100644 nflg-qms-admin/src/main/resources/application.yml create mode 100644 nflg-qms-admin/src/main/resources/logback-spring.xml create mode 100644 nflg-qms-admin/src/test/java/DeploySitTest.java delete mode 100644 nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/config/RestTemplateConfig.java rename {nflg-wms-admin/src/main/java/com/nflg/wms/admin => nflg-wms-starter/src/main/java/com/nflg/wms/starter}/config/RestTemplateConfig.java (94%) diff --git a/nflg-qms-admin/.apifox-helper.properties b/nflg-qms-admin/.apifox-helper.properties new file mode 100644 index 00000000..2538d9f3 --- /dev/null +++ b/nflg-qms-admin/.apifox-helper.properties @@ -0,0 +1 @@ +method.return[#response]=groovy: "com.nflg.wms.common.pojo.ApiResult<" + helper.resolveLink(it.doc("response")) +">" \ No newline at end of file diff --git a/nflg-qms-admin/pom.xml b/nflg-qms-admin/pom.xml new file mode 100644 index 00000000..8c31f78e --- /dev/null +++ b/nflg-qms-admin/pom.xml @@ -0,0 +1,277 @@ + + + 4.0.0 + + com.nflg + nflg-wms + 1.0.0-SNAPSHOT + + + nflg-qms-admin + 服务-qms管理后台 + 管理后台服务 + jar + + + + com.nflg + nflg-wms-common + + + com.nflg + nflg-wms-starter + + + org.springframework.boot + spring-boot-starter-web + + + io.github.biezhi + TinyPinyin + 2.0.3.RELEASE + compile + + + org.springframework.boot + spring-boot-starter-data-ldap + + + org.junit.jupiter + junit-jupiter + test + + + org.springframework.boot + spring-boot-test + test + + + org.springframework + spring-test + test + + + com.google.zxing + core + + + com.google.zxing + javase + + + org.springframework.boot + spring-boot-starter-mail + + + commons-io + commons-io + 2.11.0 + compile + + + org.apache.commons + commons-lang3 + + + tech.powerjob + powerjob-client + + + checker-qual + org.checkerframework + + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.xhtmlrenderer + flying-saucer-pdf + 9.13.3 + + + bcprov-jdk14 + org.bouncycastle + + + commons-io + commons-io + + + + + com.itextpdf + itext7-core + 7.2.6 + pom + + + com.itextpdf + font-asian + 7.2.6 + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + + + + + + + + + + com.alibaba + easyexcel + 3.3.4 + + + org.springframework.retry + spring-retry + + + org.springframework.boot + spring-boot-starter-aop + + + com.github.loki4j + loki-logback-appender + + + org.springframework.boot + spring-boot-starter-actuator + + + org.redisson + redisson-spring-boot-starter + 3.52.0 + + + org.springframework.boot + spring-boot-starter-validation + + + com.github.mwiede + jsch + 2.27.3 + test + + + io.micrometer + micrometer-tracing-bridge-otel + + + io.opentelemetry + opentelemetry-exporter-otlp + + + io.opentelemetry + opentelemetry-sdk-extension-autoconfigure + + + io.hypersistence + hypersistence-tsid + 2.1.4 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-external-libs + process-resources + + copy-resources + + + + + + ${project.basedir}/lib + false + + + + ${project.build.directory}/lib + + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + ${project.groupId} + runtime + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + lib/ + com.nflg.qms.admin.AdminApplication + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + ${project.groupId}:* + + + false + + + + + + + + \ No newline at end of file diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/AdminApplication.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/AdminApplication.java new file mode 100644 index 00000000..de01f92b --- /dev/null +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/AdminApplication.java @@ -0,0 +1,27 @@ +package com.nflg.qms.admin; + +import cn.dev33.satoken.sso.SaSsoManager; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.retry.annotation.EnableRetry; +import org.springframework.scheduling.annotation.EnableScheduling; + +@Slf4j +@SpringBootApplication +@ComponentScan(basePackages = {"com.nflg.qms.admin","com.nflg.wms.starter","com.nflg.wms.repository"}) +@EnableDiscoveryClient +@EnableScheduling +@EnableRetry +public class AdminApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminApplication.class, args); + log.info("【QMS】服务已启动"); + log.info("---------------------- Sa-Token SSO 模式二 Client 端启动成功 ----------------------"); + log.info("配置信息:" + SaSsoManager.getClientConfig()); + } + +} \ No newline at end of file diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/BasdeSerialNumberControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/BasdeSerialNumberControllerService.java new file mode 100644 index 00000000..100e128f --- /dev/null +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/BasdeSerialNumberControllerService.java @@ -0,0 +1,48 @@ +package com.nflg.qms.admin.service; + +import cn.hutool.core.util.StrUtil; +import com.nflg.wms.repository.entity.BasdeSerialNumber; +import com.nflg.wms.repository.service.IBasdeSerialNumberService; +import jakarta.annotation.Resource; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Objects; + +@Component +public class BasdeSerialNumberControllerService { + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd"); + private static final int MAX_RETRY = 5; // 最大重试次数 + + @Resource + private IBasdeSerialNumberService basdeSerialNumberService; + + @Retryable( + maxAttempts = 5, // 最大重试次数(包括第一次调用) + backoff = @Backoff(delay = 1000) // 重试间隔1秒 + ) + public String generateSerialNumber(Integer businessType) { + String currentDate = LocalDate.now().format(DATE_FORMATTER); + + BasdeSerialNumber serialNumber = basdeSerialNumberService.lambdaQuery() + .eq(BasdeSerialNumber::getBusinessType, businessType) + .one(); + + if (Objects.isNull(serialNumber)) { + return null; + } + int nextSerial = 0; + if (StrUtil.equals(currentDate, serialNumber.getCurrentDateStr())) { + nextSerial = serialNumber.getMaxSerial(); + } + nextSerial = nextSerial + 1; + serialNumber.setMaxSerial(nextSerial); + serialNumber.setCurrentDateStr(currentDate); + basdeSerialNumberService.updateById(serialNumber); + // 格式化为4位数字,不足补零 + return serialNumber.getBusinessPrefixNumber() + currentDate + String.format("%04d", nextSerial); + } +} diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/util/KeyUtil.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/util/KeyUtil.java new file mode 100644 index 00000000..9be7a4b7 --- /dev/null +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/util/KeyUtil.java @@ -0,0 +1,14 @@ +package com.nflg.qms.admin.util; + +import io.hypersistence.tsid.TSID; + +public class KeyUtil { + + public static String next(){ + return TSID.Factory.getTsid().toString(); + } + + public static String nextBase62(){ + return TSID.Factory.getTsid().encode(62); + } +} \ No newline at end of file diff --git a/nflg-qms-admin/src/main/resources/application-dev.yml b/nflg-qms-admin/src/main/resources/application-dev.yml new file mode 100644 index 00000000..446f955a --- /dev/null +++ b/nflg-qms-admin/src/main/resources/application-dev.yml @@ -0,0 +1,30 @@ +logging: + loki: + url: http://192.168.163.83:3100/loki/api/v1/push + level: + root: info + com: + nflg: trace + alibaba: + cloud: + nacos: debug + org: + springframework: debug +# sa-token配置 +sa-token: + # SSO-相关配置 + sso-client: + # SSO-Server 用户中心地址 + server-url: http://sa-sso-server.com:9000 +# LDAP +#spring: +# ldap: +# urls: +# - ldap://192.168.0.2:389 +# base: dc=nflg +# username: commpub@nflg +# password: Nflg2019# +management: + otlp: + tracing: + endpoint: http://192.168.163.83:4318/v1/traces \ No newline at end of file diff --git a/nflg-qms-admin/src/main/resources/application-prod.yml b/nflg-qms-admin/src/main/resources/application-prod.yml new file mode 100644 index 00000000..67231bbc --- /dev/null +++ b/nflg-qms-admin/src/main/resources/application-prod.yml @@ -0,0 +1,30 @@ +logging: + loki: + url: http://192.168.163.83:3100/loki/api/v1/push + level: + root: info + com: + nflg: debug + alibaba: + cloud: + nacos: info + org: + springframework: info +# sa-token配置 +sa-token: + # SSO-相关配置 + sso-client: + # SSO-Server 用户中心地址 + server-url: http://sa-sso-server.com:9000 +# LDAP +#spring: +# ldap: +# urls: +# - ldap://192.168.0.2:389 +# base: dc=nflg +# username: commpub@nflg +# password: Nflg2019# +management: + otlp: + tracing: + endpoint: http://192.168.163.83:4318/v1/traces \ No newline at end of file diff --git a/nflg-qms-admin/src/main/resources/application-sit.yml b/nflg-qms-admin/src/main/resources/application-sit.yml new file mode 100644 index 00000000..446f955a --- /dev/null +++ b/nflg-qms-admin/src/main/resources/application-sit.yml @@ -0,0 +1,30 @@ +logging: + loki: + url: http://192.168.163.83:3100/loki/api/v1/push + level: + root: info + com: + nflg: trace + alibaba: + cloud: + nacos: debug + org: + springframework: debug +# sa-token配置 +sa-token: + # SSO-相关配置 + sso-client: + # SSO-Server 用户中心地址 + server-url: http://sa-sso-server.com:9000 +# LDAP +#spring: +# ldap: +# urls: +# - ldap://192.168.0.2:389 +# base: dc=nflg +# username: commpub@nflg +# password: Nflg2019# +management: + otlp: + tracing: + endpoint: http://192.168.163.83:4318/v1/traces \ No newline at end of file diff --git a/nflg-qms-admin/src/main/resources/application.yml b/nflg-qms-admin/src/main/resources/application.yml new file mode 100644 index 00000000..9c7d81c0 --- /dev/null +++ b/nflg-qms-admin/src/main/resources/application.yml @@ -0,0 +1,48 @@ +server: + port: 8105 + tomcat: + max-http-form-post-size: 200MB +spring: + main: + allow-bean-definition-overriding: true + application: + name: qms-local + profiles: + active: dev + config: + import: nacos:shared.properties?group=${spring.profiles.active}&refreshEnabled=true + cloud: + nacos: + config: + server-addr: ${nacos.server-addr:192.168.163.83:8848} + namespace: wms + group: ${spring.profiles.active} + discovery: + server-addr: ${nacos.server-addr:192.168.163.83:8848} + namespace: wms + group: ${spring.profiles.active} + servlet: + multipart: + max-file-size: 200MB + max-request-size: 200MB +logging: + level: + root: info +management: + endpoints: + web: + exposure: + include: '*' + enabled-by-default: on + endpoint: + health: + show-details: always + health: + db: + enabled: true + redis: + enabled: true + tracing: + enabled: true + sampling: + probability: 1.0 \ No newline at end of file diff --git a/nflg-qms-admin/src/main/resources/logback-spring.xml b/nflg-qms-admin/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..5e7e8da6 --- /dev/null +++ b/nflg-qms-admin/src/main/resources/logback-spring.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n + UTF-8 + + + + + + ${logDir}/nflg-qms-admin.log + + + ${logDir}/%d{yyyy-MM-dd}.%i.log + + 10MB + + 7 + + 1GB + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${logDir}/powerjob-worker.log + + ${logDir}/powerjob-worker.%d{yyyy-MM-dd}.log + 7 + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + true + + + + + ${LOKI_URL} + + + service_name = qms + app = ${appName} + profile = ${profile} + host = ${HOSTIP} + + + traceId = %X{traceId} + level = %level + thread = %thread + class = %logger + + + true + 5 + 10000 + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{50} - %msg %ex + + false + + + + + 1024 + + 0 + + true + false + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nflg-qms-admin/src/test/java/DeploySitTest.java b/nflg-qms-admin/src/test/java/DeploySitTest.java new file mode 100644 index 00000000..63f29e56 --- /dev/null +++ b/nflg-qms-admin/src/test/java/DeploySitTest.java @@ -0,0 +1,332 @@ +import cn.hutool.core.util.StrUtil; +import com.jcraft.jsch.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; +import org.junit.jupiter.api.Test; + +import java.io.*; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class DeploySitTest { + + private static final String serviceName = "admin"; + private static final String localPath = System.getProperty("user.dir") + "//target//"; + private static final String remotePath = "/mnt/app/qms/" + serviceName + "/"; + private static final String jarName = "nflg-qms-" + serviceName + "-1.0.0-SNAPSHOT.jar"; + + @Test + public void DeployToSit() throws Exception { + SSHUtil sshUtil = new SSHUtil(); + sshUtil.connect("192.168.163.84", 22, "root", "CMP2025nf"); + //处理主jar包 + handleFile(sshUtil, localPath + jarName, remotePath + jarName); + //处理字体目录 +// handleDir(sshUtil, localPath, remotePath, "fonts"); + //处理lib目录 +// handleDir(sshUtil, localPath, remotePath, "lib"); + //执行脚本启动服务 + sshUtil.exec("cd " + remotePath + " && ./restart.sh"); + sshUtil.disconnect(); + } + + private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { + printInfo("处理目录:" + dirName); + List files = getFileList(localPath + "lib"); + for (Path file : files) { + handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); + } + printInfo("处理目录完成"); + } + + public List getFileList(String folderPath) throws IOException { + Path path = Paths.get(folderPath); + if (Files.exists(path) && Files.isDirectory(path)) { + List fileList = new ArrayList<>(); + try (DirectoryStream stream = Files.newDirectoryStream(path)) { + for (Path entry : stream) { + fileList.add(entry); + } + } + return fileList; + } + return null; + } + + private void handleFile(SSHUtil sshUtil, String localPath, String remotePath) throws Exception { + BasicFileAttributes localFileAttr = Files.readAttributes(Paths.get(localPath), BasicFileAttributes.class); + printInfo("处理文件:{},大小:{}", localPath, getSize(localFileAttr.size())); + if (sshUtil.fileExists(remotePath)) { + if (!StrUtil.equals(getRemoteFileMD5(sshUtil, remotePath), getLocalFileMD5(localPath), true)) { + printError("文件不一致,开始上传"); + sshUtil.uploadFile(localPath, remotePath); + } else { + printInfo("文件一致"); + } + } else { + printError("文件不存在,开始上传"); + sshUtil.uploadFile(localPath, remotePath); + } + printInfo("处理完成"); + } + + private String getRemoteFileMD5(SSHUtil sshUtil, String remotePath) throws Exception { + String md5 = StrUtil.subPre(sshUtil.execWithReturn("md5sum " + remotePath), 32); + printInfo("远程文件MD5为" + md5); + return md5; + } + + private String getLocalFileMD5(String localPath) throws Exception { + String md5 = DigestUtils.md5Hex(new FileInputStream(localPath)); + printInfo("本地文件MD5为" + md5); + return md5; + } + + private String getSize(long size) { + long s = 1024; + if (size < s) { + return size + "B"; + } + s = s * 1024; + if (size < s) { + return String.format("%.2f", size / 1.00 / 1024) + "KB"; + } + s = s * 1024; + if (size < s) { + return String.format("%.2f", size / 1.00 / 1024 / 1024) + "MB"; + } + s = s * 1024; + return String.format("%.2f", size / 1.00 / 1024 / 1024 / 1024) + "GB"; + } + + private static class SSHUtil { + + private Session session; + private ChannelSftp channelSftp; + + /** + * 建立SSH连接 + */ + public void connect(String host, int port, String userName, String password) throws JSchException { + printInfo("开始连接服务器,ip:{},port:{},userName:{},password:{}", host, port, userName, password); + JSch jsch = new JSch(); + session = jsch.getSession(userName, host, port); + session.setPassword(password); + session.setConfig("StrictHostKeyChecking", "no"); + session.connect(); + printInfo("连接成功"); + + Channel channel = session.openChannel("sftp"); + channel.connect(); + channelSftp = (ChannelSftp) channel; + } + + public String execWithReturn(String command) throws Exception { + printInfo("开始执行命令:{}", command); + if (session == null || !session.isConnected()) { + throw new IllegalStateException("SSH未连接"); + } + ChannelExec channel = null; + BufferedReader reader = null; + try { + // 创建执行命令的通道 + channel = (ChannelExec) session.openChannel("exec"); + channel.setCommand(command); + // 获取输入流以读取命令输出 + InputStream in = channel.getInputStream(); + InputStream err = channel.getExtInputStream(); + channel.connect(); + reader = new BufferedReader(new InputStreamReader(in)); + String data = reader.readLine(); +// log.info("执行命令成功,返回数据:" + data); + BufferedReader errReader = new BufferedReader(new InputStreamReader(err)); + String errData = errReader.readLine(); +// log.info("执行命令失败,返回数据:" + errData); + if (StrUtil.isBlank(errData)) { + return data; + } else { + errReader.close(); + throw new Exception("执行命令失败:" + errData); + } + } finally { + if (channel != null) { + channel.disconnect(); + } + if (reader != null) { + try { + reader.close(); + } catch (Exception ignored) { + } + } + printInfo("执行命令完毕"); + } + } + + /** + * 执行远程命令并返回输出 + */ + public void exec(String command) { + printInfo("开始执行命令:{}", command); + if (session == null || !session.isConnected()) { + throw new IllegalStateException("SSH未连接"); + } + ChannelExec channel = null; + SshResultCallback callback = new SshResultCallback() { + @Override + public void onOutput(String output) { + printInfo(false, output); + } + + @Override + public void onErrorOutput(String errorOutput) { + printError(false, errorOutput); + } + + @Override + public void onCompleted(int exitStatus) { + printInfo("输出完毕,退出状态:" + exitStatus); + } + + @Override + public void onError(Exception e) { + printError(false, e.getMessage()); + } + }; + try { + // 创建执行命令的通道 + channel = (ChannelExec) session.openChannel("exec"); + channel.setCommand(command); + + // 获取输入流以读取命令输出 + InputStream in = channel.getInputStream(); + InputStream err = channel.getExtInputStream(); + + channel.connect(); + + // 读取命令输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + BufferedReader errReader = new BufferedReader(new InputStreamReader(err)); + + String line; + while ((line = reader.readLine()) != null) { + callback.onOutput(line); + } + + // 读取错误输出 + String errLine; + while ((errLine = errReader.readLine()) != null) { + callback.onErrorOutput(errLine); + } + + // 获取退出状态 + int exitStatus = channel.getExitStatus(); + callback.onCompleted(exitStatus); + } catch (JSchException | IOException e) { + callback.onError(e); + } finally { + if (channel != null) { + channel.disconnect(); + } + if (session != null) { + session.disconnect(); + } + printInfo("执行命令完毕"); + } + } + + /** + * 检查远程文件是否存在 + */ + public boolean fileExists(String remotePath) throws SftpException { + try { + channelSftp.stat(remotePath); + return true; + } catch (SftpException e) { + if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { + return false; + } + throw e; + } + } + + /** + * 上传文件 + */ + public void uploadFile(String localPath, String remotePath) throws SftpException { + printInfo("开始上传本地文件{}到远程{}", localPath, remotePath); + channelSftp.put(localPath, remotePath); + printInfo("上传完成"); + } + + /** + * 关闭连接 + */ + public void disconnect() { + if (channelSftp != null) { + channelSftp.disconnect(); + } + if (session != null) { + session.disconnect(); + } + } + } + + public interface SshResultCallback { + void onOutput(String output); + + void onErrorOutput(String errorOutput); + + void onCompleted(int exitStatus); + + void onError(Exception e); + } + + private static void printError(String msg) { + if (StrUtil.isNotBlank(msg)) { + System.out.println(red + msg + reset); + } + } + + private static void printError(boolean addTime, String msg) { + if (addTime) { + System.out.println(red + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " " + msg + reset); + } else { + System.out.println(red + msg + reset); + } + } + + private static void printInfo(String msg) { + printInfo(true, msg); + } + + private static void printInfo(boolean addTime, String msg) { + if (addTime) { + System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " " + msg); + } else { + System.out.println(msg); + } + } + + private static void printInfo(String format, Object... args) { + printInfo(true, format, args); + } + + private static void printInfo(boolean addTime, String format, Object... args) { + if (addTime) { + System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " " + StrUtil.format(format, args)); + } else { + System.out.println(StrUtil.format(format, args)); + } + } + + public static final String red = "\u001B[31m"; + public static final String reset = "\u001B[0m"; +} diff --git a/nflg-wms-admin/pom.xml b/nflg-wms-admin/pom.xml index d8cfbe93..85b45213 100644 --- a/nflg-wms-admin/pom.xml +++ b/nflg-wms-admin/pom.xml @@ -8,7 +8,7 @@ 1.0.0-SNAPSHOT nflg-wms-admin - 服务-管理后台 + 服务-wms管理后台 管理后台服务 jar diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/AdminApplication.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/AdminApplication.java index b426d929..17b71ffe 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/AdminApplication.java +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/AdminApplication.java @@ -19,7 +19,7 @@ public class AdminApplication { public static void main(String[] args) { SpringApplication.run(AdminApplication.class, args); - log.info("服务已启动"); + log.info("【WMS】服务已启动"); log.info("---------------------- Sa-Token SSO 模式二 Client 端启动成功 ----------------------"); log.info("配置信息:" + SaSsoManager.getClientConfig()); } diff --git a/nflg-wms-repository/pom.xml b/nflg-wms-repository/pom.xml index e407b220..d58fe05d 100644 --- a/nflg-wms-repository/pom.xml +++ b/nflg-wms-repository/pom.xml @@ -8,7 +8,6 @@ 1.0.0-SNAPSHOT nflg-wms-repository - 1.0.0-SNAPSHOT 模块-db 封装数据库操作 jar diff --git a/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/config/RestTemplateConfig.java b/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/config/RestTemplateConfig.java deleted file mode 100644 index 63f63791..00000000 --- a/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/config/RestTemplateConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.nflg.wms.shipment.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; - -@Configuration -public class RestTemplateConfig { - - @Bean - @Lazy - public RestTemplate restTemplate() { - SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); - factory.setConnectTimeout(3_000); - factory.setReadTimeout(10_000); - return new RestTemplate(factory); - } - -} \ No newline at end of file diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/config/RestTemplateConfig.java b/nflg-wms-starter/src/main/java/com/nflg/wms/starter/config/RestTemplateConfig.java similarity index 94% rename from nflg-wms-admin/src/main/java/com/nflg/wms/admin/config/RestTemplateConfig.java rename to nflg-wms-starter/src/main/java/com/nflg/wms/starter/config/RestTemplateConfig.java index c9f53176..4852493d 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/config/RestTemplateConfig.java +++ b/nflg-wms-starter/src/main/java/com/nflg/wms/starter/config/RestTemplateConfig.java @@ -1,4 +1,4 @@ -package com.nflg.wms.admin.config; +package com.nflg.wms.starter.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/pom.xml b/pom.xml index d511511e..c20f9a9a 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ nflg-wms-scheduled nflg-wms-srm-receive nflg-wms-shipment + nflg-qms-admin 17