feat(ticket): 添加工单撤销功能并优化文件上传进度显示
- 在admin和gongfu模块的TicketController中添加revokedTicket接口 - 为SFTP文件上传添加控制台进度条显示功能 - 优化OSS文件上传服务,添加文件元数据设置 - 修复文件上传过程中缺少进度反馈的问题
This commit is contained in:
parent
c3589983f9
commit
8a0f4620c8
|
|
@ -474,6 +474,16 @@ public class TicketController extends ControllerBase {
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 撤销工单
|
||||||
|
* @param id 工单编号
|
||||||
|
**/
|
||||||
|
@GetMapping("revokedTicket")
|
||||||
|
public ApiResult<Void> revokedTicket(@Valid @RequestParam @NotNull Integer id) {
|
||||||
|
ticketService.revoked(id);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 关闭工单
|
// * 关闭工单
|
||||||
// * @param request 请求参数
|
// * @param request 请求参数
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ public class DeployTest {
|
||||||
*/
|
*/
|
||||||
public void uploadFile(String localPath, String remotePath) throws SftpException {
|
public void uploadFile(String localPath, String remotePath) throws SftpException {
|
||||||
printInfo("开始上传本地文件{}到远程{}", localPath, remotePath);
|
printInfo("开始上传本地文件{}到远程{}", localPath, remotePath);
|
||||||
channelSftp.put(localPath, remotePath);
|
channelSftp.put(localPath, remotePath, new ConsoleProgressBar());
|
||||||
printInfo("上传完成");
|
printInfo("上传完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,6 +277,50 @@ public class DeployTest {
|
||||||
session.disconnect();
|
session.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ConsoleProgressBar implements SftpProgressMonitor {
|
||||||
|
private long max = 0;
|
||||||
|
private int percentTransferred = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(int op, String src, String dest, long max) {
|
||||||
|
this.max = max;
|
||||||
|
System.out.println("正在传输: " + src + " -> " + dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean count(long count) {
|
||||||
|
if (max > 0) {
|
||||||
|
int newPercent = (int) ((count * 100) / max);
|
||||||
|
// 只有当百分比变化时才更新输出(避免频繁刷新控制台)
|
||||||
|
if (newPercent > percentTransferred) {
|
||||||
|
percentTransferred = newPercent;
|
||||||
|
printProgressBar(percentTransferred);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printProgressBar(int percent) {
|
||||||
|
StringBuilder bar = new StringBuilder("[");
|
||||||
|
for (int i = 0; i < 50; i++) {
|
||||||
|
if (i < (percent / 2)) {
|
||||||
|
bar.append("=");
|
||||||
|
} else if (i == (percent / 2)) {
|
||||||
|
bar.append(">");
|
||||||
|
} else {
|
||||||
|
bar.append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bar.append("] ").append(percent).append("%");
|
||||||
|
System.out.print("\r" + bar); // 使用 \r 回到行首覆盖输出
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void end() {
|
||||||
|
System.out.println("\r传输完成。");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface SshResultCallback {
|
public interface SshResultCallback {
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,16 @@ public class TicketController extends ControllerBase {
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 撤销工单
|
||||||
|
* @param id 工单编号
|
||||||
|
**/
|
||||||
|
@GetMapping("revokedTicket")
|
||||||
|
public ApiResult<Void> revokedTicket(@Valid @RequestParam @NotNull Long id) {
|
||||||
|
ticketService.revoked(id);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出工单为pdf
|
* 导出工单为pdf
|
||||||
* @param id 工单id
|
* @param id 工单id
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,12 @@ public class OSSFileUploadService implements FileUploadService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String upload(String filePath, InputStream stream) {
|
public String upload(String filePath, InputStream stream) throws IOException {
|
||||||
// 上传文件到OSS
|
// 上传文件到OSS
|
||||||
PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, filePath, stream));
|
ObjectMetadata metadata = new ObjectMetadata();
|
||||||
|
metadata.setContentLength(stream.available());
|
||||||
|
metadata.setContentDisposition("attachment");
|
||||||
|
PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, filePath, stream, metadata));
|
||||||
//log.debug("上传文件结果: " + result);
|
//log.debug("上传文件结果: " + result);
|
||||||
return StrUtil.format("{}/{}",domain, filePath);
|
return StrUtil.format("{}/{}",domain, filePath);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue