Compare commits

...

2 Commits

Author SHA1 Message Date
曹鹏飞 6a17f2c9e0 refactor(deploy): 重构部署测试类配置
- 将DeployTest重命名为DeployDevTest用于开发环境部署
- 新增DeploySitTest类用于SIT环境部署
- 修改开发环境服务名为admin-dev
- 移除未使用的Vector导入
- 注释掉字体目录处理逻辑
- 统一代码格式化和空格调整
2026-03-05 11:02:10 +08:00
zhangke edb067dc79 打包收货部分功能完成 2026-03-05 10:57:47 +08:00
6 changed files with 385 additions and 34 deletions

View File

@ -1304,7 +1304,7 @@ public class NormalPGIController extends BaseController {
*/ */
@PostMapping("getPackageOrderItems") @PostMapping("getPackageOrderItems")
@ApiMark(moduleName = "根据送货单单号和大码的ID获取到具体的物料信息", apiName = "根据送货单单号和大码的ID获取到具体的物料信息") @ApiMark(moduleName = "根据送货单单号和大码的ID获取到具体的物料信息", apiName = "根据送货单单号和大码的ID获取到具体的物料信息")
public ApiResult<List<PacagePoItemVO>> scanPackage(@Valid @RequestBody PackagePoSearchQO request) { public ApiResult<List<PacagePoItemVO>> getPackageOrderItems(@Valid @RequestBody PackagePoSearchQO request) {
return ApiResult.success(wmsPackageService.getPackageOrderItems(request.getPackageId(), request.getDeliveryNo())); return ApiResult.success(wmsPackageService.getPackageOrderItems(request.getPackageId(), request.getDeliveryNo()));
} }
@ -1313,9 +1313,9 @@ public class NormalPGIController extends BaseController {
* @param request id= 大码的ID * @param request id= 大码的ID
* @return * @return
*/ */
@PostMapping("getPackageOrderItems") @PostMapping("getPendingScanningItems")
@ApiMark(moduleName = "根据送货单单号和大码的ID获取到具体的物料信息", apiName = "根据送货单单号和大码的ID获取到具体的物料信息") @ApiMark(moduleName = "根据送货单单号和大码的ID获取到具体的物料信息", apiName = "根据送货单单号和大码的ID获取到具体的物料信息")
public ApiResult<List<PendingScanningVO>> scanPackage(@Valid @RequestBody FilterIdQO request) { public ApiResult<List<PendingScanningVO>> getPendingScanningItems(@Valid @RequestBody FilterIdQO request) {
List<PendingScanningVO> list = wmsPackageService.getPendingScannings(request.getId()); List<PendingScanningVO> list = wmsPackageService.getPendingScannings(request.getId());
if (CollectionUtil.isNotEmpty(list)) { if (CollectionUtil.isNotEmpty(list)) {
list.forEach(vo -> { list.forEach(vo -> {
@ -1350,14 +1350,25 @@ public class NormalPGIController extends BaseController {
VUtil.trueThrowBusinessError(count2 >= 0).throwMessage("存在必须扫码的包装"); VUtil.trueThrowBusinessError(count2 >= 0).throwMessage("存在必须扫码的包装");
List<PendingScanningItemDTO> items = wmsPackageService.getScanningItems(request.getBarcodeIds()); List<PendingScanningItemDTO> items = wmsPackageService.getScanningItems(request.getBarcodeIds());
//对箱码要做出来将箱码换成对应的物料码 //对箱码要做出来将箱码换成对应的物料码
List<> List<Long> materialCodes = items.stream().filter(item -> Objects.equals(item.getPackagingType(), 1))
.map(item -> item.getBarcodeId())
.distinct()
.collect(Collectors.toList());
// List<WmsQrCodeMaster> qrCodeMasters = wmsQrCodeMasterService.getByMaterialCodes(materialCodes);
// if(CollectionUtil.isEmpty(materialCodes))
// {
// //计算箱内物料的数量并判断是否是打包状态
//
//
//
// }
//根据包装信息获取对应的物料收货信息 //根据包装信息获取对应的物料收货信息
List<SrmMaterialReceiptQO> receiptQOS = new ArrayList<>(); List<SrmMaterialReceiptQO> receiptQOS = new ArrayList<>();
//首先要对上面的信息 按照 srmId进行分组汇总quantity //首先要对上面的信息 按照 srmId进行分组汇总quantity
for (PendingScanningItemDTO item : items) for (PendingScanningItemDTO item : items) {
{
SrmMaterialReceiptQO qo = new SrmMaterialReceiptQO() SrmMaterialReceiptQO qo = new SrmMaterialReceiptQO()
.setNoteNum(item.getDeliveryNo()) .setNoteNum(item.getDeliveryNo())
.setLineNumber(item.getDeliveryLineNo()) .setLineNumber(item.getDeliveryLineNo())
@ -1367,14 +1378,15 @@ public class NormalPGIController extends BaseController {
.setId(item.getSrmId()) .setId(item.getSrmId())
.setReceiptNum(item.getQuantity()); .setReceiptNum(item.getQuantity());
// .setScanCodes(item.getScanCodes()); // .setScanCodes(item.getScanCodes());
} }
return ApiResult.success();
} }
@PostMapping("takeDeliveryConfirmByScan") @PostMapping("takeDeliveryConfirmByScan")
@ApiMark(moduleName = "需扫码收货", apiName = "需扫码收货") @ApiMark(moduleName = "需扫码收货", apiName = "需扫码收货")
public ApiResult<Void> takeDeliveryConfirmByScan(@Valid @RequestBody List<PendingScanningQO> request) { public ApiResult<Void> takeDeliveryConfirmByScan(@Valid @RequestBody List<PendingScanningQO> request) {
return ApiResult.success();
} }
} }

View File

@ -96,7 +96,7 @@ public class PackingController extends BaseController {
.eq(WmsPackage::getId, request.getId()) .eq(WmsPackage::getId, request.getId())
.one(); .one();
VUtil.trueThrowBusinessError(ObjectUtil.isNull(wmsPackage)).throwMessage("打包码不存在"); VUtil.trueThrowBusinessError(ObjectUtil.isNull(wmsPackage)).throwMessage("打包码不存在");
VUtil.trueThrowBusinessError(wmsPackage.getSupplierId() != UserUtil.getUserId()).throwMessage("非登录供应商,不可编辑"); // VUtil.trueThrowBusinessError(wmsPackage.getSupplierId() != UserUtil.getUserId()).throwMessage("非登录供应商,不可编辑");
VUtil.trueThrowBusinessError(wmsPackage.getPackageStatus() == 2).throwMessage("已收货,不可以编辑"); VUtil.trueThrowBusinessError(wmsPackage.getPackageStatus() == 2).throwMessage("已收货,不可以编辑");
packageService.lambdaUpdate().eq(WmsPackage::getId, request.getId()) packageService.lambdaUpdate().eq(WmsPackage::getId, request.getId())
.set(WmsPackage::getPackageName, request.getPackingName()) .set(WmsPackage::getPackageName, request.getPackingName())
@ -117,10 +117,10 @@ public class PackingController extends BaseController {
.in(WmsPackage::getId, request.getId()) .in(WmsPackage::getId, request.getId())
.list(); .list();
List<WmsPackage> suppers = wmsPackage.stream().filter(wmsPackage1 -> // List<WmsPackage> suppers = wmsPackage.stream().filter(wmsPackage1 ->
wmsPackage1.getSupplierId().equals(UserUtil.getUserId())) // wmsPackage1.getSupplierId().equals(UserUtil.getUserId()))
.collect(Collectors.toList()); // .collect(Collectors.toList());
VUtil.trueThrowBusinessError(CollectionUtil.isNotEmpty(suppers)).throwMessage("存在非当前供应商的包装码"); // VUtil.trueThrowBusinessError(CollectionUtil.isNotEmpty(suppers)).throwMessage("存在非当前供应商的包装码");
List<WmsPackage> unPackings = List<WmsPackage> unPackings =
wmsPackage.stream().filter(wmsPackage1 -> wmsPackage.stream().filter(wmsPackage1 ->
@ -179,7 +179,7 @@ public class PackingController extends BaseController {
// 首先判断当前包是否已经收货了 // 首先判断当前包是否已经收货了
WmsPackage wmsPackage = packageService.lambdaQuery() WmsPackage wmsPackage = packageService.lambdaQuery()
.eq(WmsPackage::getPackageCode, request.getPackageCode()) .eq(WmsPackage::getPackageCode, request.getPackageCode())
.eq(WmsPackage::getSupplierId, UserUtil.getUserId()) // .eq(WmsPackage::getSupplierId, UserUtil.getUserId())
.one(); .one();
VUtil.trueThrowBusinessError(ObjectUtil.isNull(wmsPackage)).throwMessage("打包码不存在"); VUtil.trueThrowBusinessError(ObjectUtil.isNull(wmsPackage)).throwMessage("打包码不存在");
VUtil.trueThrowBusinessError(wmsPackage.getPackageStatus() == 2).throwMessage("此打包码已收货"); VUtil.trueThrowBusinessError(wmsPackage.getPackageStatus() == 2).throwMessage("此打包码已收货");

View File

@ -0,0 +1,334 @@
package com.nflg.wms.admin;
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 DeployDevTest {
private static final String serviceName = "admin-dev";
private static final String localPath = System.getProperty("user.dir") + "//target//";
private static final String remotePath = "/mnt/app/wms/" + serviceName + "/";
private static final String jarName = "nflg-wms-admin-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<Path> files = getFileList(localPath + "lib");
for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString());
}
printInfo("处理目录完成");
}
public List<Path> getFileList(String folderPath) throws IOException {
Path path = Paths.get(folderPath);
if (Files.exists(path) && Files.isDirectory(path)) {
List<Path> fileList = new ArrayList<>();
try (DirectoryStream<Path> 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";
}

View File

@ -16,10 +16,9 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Vector;
@Slf4j @Slf4j
public class DeployTest { public class DeploySitTest {
private static final String serviceName = "admin"; private static final String serviceName = "admin";
private static final String localPath = System.getProperty("user.dir") + "//target//"; private static final String localPath = System.getProperty("user.dir") + "//target//";
@ -33,9 +32,9 @@ public class DeployTest {
//处理主jar包 //处理主jar包
handleFile(sshUtil, localPath + jarName, remotePath + jarName); handleFile(sshUtil, localPath + jarName, remotePath + jarName);
//处理字体目录 //处理字体目录
handleDir(sshUtil, localPath, remotePath, "fonts"); // handleDir(sshUtil, localPath, remotePath, "fonts");
//处理lib目录 //处理lib目录
handleDir(sshUtil, localPath, remotePath, "lib"); // handleDir(sshUtil, localPath, remotePath, "lib");
//执行脚本启动服务 //执行脚本启动服务
sshUtil.exec("cd " + remotePath + " && ./restart.sh"); sshUtil.exec("cd " + remotePath + " && ./restart.sh");
sshUtil.disconnect(); sshUtil.disconnect();
@ -82,7 +81,7 @@ public class DeployTest {
} }
private String getRemoteFileMD5(SSHUtil sshUtil, String remotePath) throws Exception { private String getRemoteFileMD5(SSHUtil sshUtil, String remotePath) throws Exception {
String md5 = StrUtil.subPre(sshUtil.execWithReturn("md5sum " + remotePath),32); String md5 = StrUtil.subPre(sshUtil.execWithReturn("md5sum " + remotePath), 32);
printInfo("远程文件MD5为" + md5); printInfo("远程文件MD5为" + md5);
return md5; return md5;
} }

View File

@ -65,4 +65,9 @@ public class PendingScanningItemDTO {
* srm传入的送货单项ID * srm传入的送货单项ID
*/ */
private Long srmId; private Long srmId;
/**
* 物料码的二维码ID
*/
private Long barcodeId;
} }

View File

@ -154,22 +154,23 @@
<select id="getScanningItems" resultType="com.nflg.wms.common.pojo.dto.PendingScanningItemDTO"> <select id="getScanningItems" resultType="com.nflg.wms.common.pojo.dto.PendingScanningItemDTO">
select a.id, select a.id,
a.barcode_code, a.barcode_code,
b.quantity, b.quantity,
b.material_code, b.material_code,
b.packaging_type, b.packaging_type,
b.po_number, b.po_number,
b.po_line_number, b.po_line_number,
b.delivery_no, b.delivery_no,
b.delivery_line_no, b.delivery_line_no,
b.unit, b.unit,
b.serial_no, b.serial_no,
b.batch_no, b.batch_no,
b.material_description, b.material_description,
c.id as srm_id c.id as srm_id,
b.id as barcode_id
from wms_package_item a from wms_package_item a
left join wms_qr_code_master b on a.barcode_code = b.barcode_code left join wms_qr_code_master b on a.barcode_code = b.barcode_code
left join wms_srm_order_item c on b.delivery_no=c.note_num and b.delivery_line_no=c.line_number left join wms_srm_order_item c on b.delivery_no=c.note_num and b.delivery_line_no=c.line_number
where a.package_id in where a.package_id in
<foreach item="id" collection="barcodeIds" open="(" separator="," close=")"> <foreach item="id" collection="barcodeIds" open="(" separator="," close=")">
#{id} #{id}