parent
3c439b31e0
commit
cbbbfc123b
Binary file not shown.
@ -1,55 +0,0 @@
|
||||
package cn.iocoder.yudao.module.annotation.controller.admin.yolo;
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.ExportResult;
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.PredictionResult;
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.ValidationResult;
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.YoloConfig;
|
||||
import cn.iocoder.yudao.module.annotation.service.yolo.AsyncYoloService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
// YoloController.java
|
||||
@RestController
|
||||
@RequestMapping("/api/yolo")
|
||||
public class YoloController {
|
||||
|
||||
private final AsyncYoloService yoloService;
|
||||
|
||||
public YoloController(AsyncYoloService yoloService) {
|
||||
this.yoloService = yoloService;
|
||||
}
|
||||
|
||||
@PostMapping("/train")
|
||||
public ResponseEntity<String> trainAsync(@RequestBody YoloConfig config) {
|
||||
yoloService.trainAsync(config)
|
||||
.thenAccept(result -> {
|
||||
if (result.isSuccess()) {
|
||||
System.out.println("Training completed successfully");
|
||||
} else {
|
||||
System.err.println("Training failed: " + result.getMessage());
|
||||
}
|
||||
});
|
||||
return ResponseEntity.ok("Training started asynchronously");
|
||||
}
|
||||
|
||||
@PostMapping("/validate")
|
||||
public CompletableFuture<ValidationResult> validateAsync(@RequestBody YoloConfig config) {
|
||||
return yoloService.validateAsync(config);
|
||||
}
|
||||
|
||||
@PostMapping("/predict")
|
||||
public CompletableFuture<PredictionResult> predictAsync(
|
||||
@RequestBody YoloConfig config,
|
||||
@RequestParam String imagePath) {
|
||||
return yoloService.predictAsync(config, imagePath);
|
||||
}
|
||||
|
||||
@PostMapping("/export")
|
||||
public CompletableFuture<ExportResult> exportAsync(
|
||||
@RequestBody YoloConfig config,
|
||||
@RequestParam String format) {
|
||||
return yoloService.exportAsync(config, format);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
// AsyncYoloService.java
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.*;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface AsyncYoloService extends YoloService {
|
||||
CompletableFuture<TrainingResult> trainAsync(YoloConfig config);
|
||||
CompletableFuture<ValidationResult> validateAsync(YoloConfig config);
|
||||
CompletableFuture<PredictionResult> predictAsync(YoloConfig config, String imagePath);
|
||||
CompletableFuture<ExportResult> exportAsync(YoloConfig config, String format);
|
||||
}
|
||||
@ -1,205 +0,0 @@
|
||||
// AsyncYoloServiceImpl.java
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.*;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service
|
||||
public class AsyncYoloServiceImpl implements AsyncYoloService {
|
||||
|
||||
@Override
|
||||
@Async("yoloTaskExecutor")
|
||||
public CompletableFuture<TrainingResult> trainAsync(YoloConfig config) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
ProcessBuilder pb = buildTrainCommand(config);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
System.out.println(line); // 可用于日志记录
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode == 0) {
|
||||
return new TrainingResult(true, "Training completed successfully", output.toString());
|
||||
} else {
|
||||
return new TrainingResult(false, "Training failed with exit code: " + exitCode, output.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new TrainingResult(false, "Training error: " + e.getMessage(), "");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("yoloTaskExecutor")
|
||||
public CompletableFuture<ValidationResult> validateAsync(YoloConfig config) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
ProcessBuilder pb = buildValidateCommand(config);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return new ValidationResult(exitCode == 0, output.toString());
|
||||
} catch (Exception e) {
|
||||
return new ValidationResult(false, "Validation error: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("yoloTaskExecutor")
|
||||
public CompletableFuture<PredictionResult> predictAsync(YoloConfig config, String imagePath) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
ProcessBuilder pb = buildPredictCommand(config, imagePath);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return new PredictionResult(exitCode == 0, output.toString(), imagePath);
|
||||
} catch (Exception e) {
|
||||
return new PredictionResult(false, "Prediction error: " + e.getMessage(), imagePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("yoloTaskExecutor")
|
||||
public CompletableFuture<ExportResult> exportAsync(YoloConfig config, String format) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
ProcessBuilder pb = buildExportCommand(config, format);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return new ExportResult(exitCode == 0, output.toString(), format);
|
||||
} catch (Exception e) {
|
||||
return new ExportResult(false, "Export error: " + e.getMessage(), format);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 同步方法实现(可选)
|
||||
@Override
|
||||
public TrainingResult train(YoloConfig config) {
|
||||
return trainAsync(config).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult validate(YoloConfig config) {
|
||||
return validateAsync(config).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PredictionResult predict(YoloConfig config, String imagePath) {
|
||||
return predictAsync(config, imagePath).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportResult export(YoloConfig config, String format) {
|
||||
return exportAsync(config, format).join();
|
||||
}
|
||||
|
||||
private ProcessBuilder buildTrainCommand(YoloConfig config) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "train",
|
||||
"--model", config.getModelPath(),
|
||||
"--data", config.getDatasetPath(),
|
||||
"--epochs", String.valueOf(config.getEpochs()),
|
||||
"--batch", String.valueOf(config.getBatchSize()),
|
||||
"--lr", String.valueOf(config.getLearningRate()),
|
||||
"--device", config.getDevice(),
|
||||
"--project", config.getOutputPath()
|
||||
);
|
||||
|
||||
if (config.isPretrained()) {
|
||||
pb.command().add("--pretrained");
|
||||
pb.command().add("True");
|
||||
}
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private ProcessBuilder buildValidateCommand(YoloConfig config) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "val",
|
||||
"--model", config.getModelPath(),
|
||||
"--data", config.getDatasetPath(),
|
||||
"--device", config.getDevice()
|
||||
);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private ProcessBuilder buildPredictCommand(YoloConfig config, String imagePath) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "predict",
|
||||
"--model", config.getModelPath(),
|
||||
"--source", imagePath,
|
||||
"--device", config.getDevice(),
|
||||
"--project", config.getOutputPath()
|
||||
);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private ProcessBuilder buildExportCommand(YoloConfig config, String format) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "export",
|
||||
"--model", config.getModelPath(),
|
||||
"--format", format
|
||||
);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,9 +0,0 @@
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.YoloProgress;
|
||||
|
||||
public interface YoloProgressListener {
|
||||
void onProgressUpdate(YoloProgress progress);
|
||||
void onComplete(YoloProgress finalProgress);
|
||||
void onError(Exception e);
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
// YoloProgressParser.java
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.YoloProgress;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class YoloProgressParser {
|
||||
|
||||
// 匹配训练进度的正则表达式
|
||||
private static final Pattern EPOCH_PATTERN = Pattern.compile("Epoch\\s+(\\d+)/(\\d+)");
|
||||
private static final Pattern PROGRESS_PATTERN = Pattern.compile("(\\d+)/(\\d+)\\s+\\[.*?([0-9.]+)%.*?\\]");
|
||||
private static final Pattern LOSS_PATTERN = Pattern.compile("loss:\\s*([0-9.]+)");
|
||||
|
||||
public static YoloProgress parseLine(String line, YoloProgress currentProgress) {
|
||||
if (currentProgress == null) {
|
||||
currentProgress = new YoloProgress();
|
||||
}
|
||||
|
||||
// 解析Epoch信息
|
||||
Matcher epochMatcher = EPOCH_PATTERN.matcher(line);
|
||||
if (epochMatcher.find()) {
|
||||
currentProgress.setCurrentEpoch(Integer.parseInt(epochMatcher.group(1)));
|
||||
currentProgress.setTotalEpochs(Integer.parseInt(epochMatcher.group(2)));
|
||||
currentProgress.setStatusMessage("Training epoch " +
|
||||
currentProgress.getCurrentEpoch() + "/" + currentProgress.getTotalEpochs());
|
||||
}
|
||||
|
||||
// 解析进度条信息
|
||||
Matcher progressMatcher = PROGRESS_PATTERN.matcher(line);
|
||||
if (progressMatcher.find()) {
|
||||
currentProgress.setProcessedItems(Integer.parseInt(progressMatcher.group(1)));
|
||||
currentProgress.setTotalItems(Integer.parseInt(progressMatcher.group(2)));
|
||||
currentProgress.setProgress(Double.parseDouble(progressMatcher.group(3)));
|
||||
}
|
||||
|
||||
// 解析Loss信息
|
||||
Matcher lossMatcher = LOSS_PATTERN.matcher(line);
|
||||
if (lossMatcher.find()) {
|
||||
currentProgress.setStatusMessage(currentProgress.getStatusMessage() +
|
||||
" | Loss: " + lossMatcher.group(1));
|
||||
}
|
||||
|
||||
return currentProgress;
|
||||
}
|
||||
|
||||
public static boolean isCompletionIndicator(String line) {
|
||||
return line.contains("Training completed") ||
|
||||
line.contains("completed successfully") ||
|
||||
line.contains("finished");
|
||||
}
|
||||
|
||||
public static boolean isErrorIndicator(String line) {
|
||||
return line.contains("error") ||
|
||||
line.contains("failed") ||
|
||||
line.contains("exception") ||
|
||||
line.contains("Error");
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.*;
|
||||
|
||||
// YoloService.java
|
||||
public interface YoloService {
|
||||
/**
|
||||
* 训练模型
|
||||
*/
|
||||
TrainingResult train(YoloConfig config);
|
||||
|
||||
/**
|
||||
* 验证模型
|
||||
*/
|
||||
ValidationResult validate(YoloConfig config);
|
||||
|
||||
/**
|
||||
* 进行预测
|
||||
*/
|
||||
PredictionResult predict(YoloConfig config, String imagePath);
|
||||
|
||||
/**
|
||||
* 导出模型
|
||||
*/
|
||||
ExportResult export(YoloConfig config, String format);
|
||||
}
|
||||
@ -1,219 +0,0 @@
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.YoloConfig;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* YOLO服务客户端 - 通过socket与Python长连接服务通信
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class YoloServiceClient {
|
||||
|
||||
private static final String DEFAULT_HOST = "localhost";
|
||||
private static final int DEFAULT_PORT = 9999;
|
||||
private static final int CONNECTION_TIMEOUT = 30000; // 30秒超时
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 通过socket服务执行预测
|
||||
*/
|
||||
public YoloConfig predictViaSocket(String modelPath, String inputPath, String outputPath, YoloConfig config) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("model_path", modelPath);
|
||||
params.put("input_path", inputPath);
|
||||
if (outputPath != null) {
|
||||
params.put("output_path", outputPath);
|
||||
}
|
||||
|
||||
// 添加其他YOLO配置参数
|
||||
addYoloConfigParams(params, config);
|
||||
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("command", "predict");
|
||||
request.put("params", params);
|
||||
|
||||
String response = sendRequest(request);
|
||||
JsonNode responseJson = objectMapper.readTree(response);
|
||||
|
||||
if ("success".equals(responseJson.get("status").asText())) {
|
||||
config.setStatus("completed");
|
||||
config.setLogMessage(responseJson.get("message").asText());
|
||||
if (responseJson.has("output_path")) {
|
||||
config.setOutputPath(responseJson.get("output_path").asText());
|
||||
}
|
||||
return config;
|
||||
} else {
|
||||
config.setStatus("failed");
|
||||
config.setErrorMessage(responseJson.get("message").asText());
|
||||
return config;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Socket预测失败", e);
|
||||
config.setStatus("failed");
|
||||
config.setErrorMessage("Socket预测失败: " + e.getMessage());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过socket服务执行训练
|
||||
*/
|
||||
public YoloConfig trainViaSocket(String modelPath, String dataPath, YoloConfig config) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("model_path", modelPath);
|
||||
params.put("data_path", dataPath);
|
||||
params.put("epochs", config.getEpochs());
|
||||
|
||||
// 添加其他训练配置参数
|
||||
addYoloConfigParams(params, config);
|
||||
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("command", "train");
|
||||
request.put("params", params);
|
||||
|
||||
String response = sendRequest(request);
|
||||
JsonNode responseJson = objectMapper.readTree(response);
|
||||
|
||||
if ("success".equals(responseJson.get("status").asText())) {
|
||||
config.setStatus("completed");
|
||||
config.setLogMessage(responseJson.get("message").asText());
|
||||
if (responseJson.has("results_path")) {
|
||||
config.setOutputPath(responseJson.get("results_path").asText());
|
||||
}
|
||||
return config;
|
||||
} else {
|
||||
config.setStatus("failed");
|
||||
config.setErrorMessage(responseJson.get("message").asText());
|
||||
return config;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Socket训练失败", e);
|
||||
config.setStatus("failed");
|
||||
config.setErrorMessage("Socket训练失败: " + e.getMessage());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过socket服务执行验证
|
||||
*/
|
||||
public YoloConfig validateViaSocket(String modelPath, String dataPath, YoloConfig config) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("model_path", modelPath);
|
||||
if (dataPath != null) {
|
||||
params.put("data_path", dataPath);
|
||||
}
|
||||
|
||||
// 添加其他验证配置参数
|
||||
addYoloConfigParams(params, config);
|
||||
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("command", "validate");
|
||||
request.put("params", params);
|
||||
|
||||
String response = sendRequest(request);
|
||||
JsonNode responseJson = objectMapper.readTree(response);
|
||||
|
||||
if ("success".equals(responseJson.get("status").asText())) {
|
||||
config.setStatus("completed");
|
||||
config.setLogMessage(responseJson.get("message").asText());
|
||||
if (responseJson.has("metrics")) {
|
||||
config.setMetrics(responseJson.get("metrics").asText());
|
||||
}
|
||||
return config;
|
||||
} else {
|
||||
config.setStatus("failed");
|
||||
config.setErrorMessage(responseJson.get("message").asText());
|
||||
return config;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Socket验证失败", e);
|
||||
config.setStatus("failed");
|
||||
config.setErrorMessage("Socket验证失败: " + e.getMessage());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加YOLO配置参数到请求中
|
||||
*/
|
||||
private void addYoloConfigParams(Map<String, Object> params, YoloConfig config) {
|
||||
if (config.getImgsz() > 0) {
|
||||
params.put("imgsz", config.getImgsz());
|
||||
}
|
||||
if (config.getConfThresh() > 0) {
|
||||
params.put("conf", config.getConfThresh());
|
||||
}
|
||||
if (config.getIouThresh() > 0) {
|
||||
params.put("iou", config.getIouThresh());
|
||||
}
|
||||
if (config.getDevice() != null) {
|
||||
params.put("device", config.getDevice());
|
||||
}
|
||||
if (config.getBatchSize() > 0) {
|
||||
params.put("batch", config.getBatchSize());
|
||||
}
|
||||
params.put("save", config.isSave());
|
||||
params.put("save_txt", config.isSaveTxt());
|
||||
params.put("save_crops", config.isSaveCrops());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求到socket服务
|
||||
*/
|
||||
private String sendRequest(Map<String, Object> request) throws IOException {
|
||||
try (Socket socket = new Socket(DEFAULT_HOST, DEFAULT_PORT);
|
||||
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
|
||||
|
||||
// 设置超时
|
||||
socket.setSoTimeout(CONNECTION_TIMEOUT);
|
||||
|
||||
// 发送请求
|
||||
String requestJson = objectMapper.writeValueAsString(request);
|
||||
out.println(requestJson);
|
||||
|
||||
// 读取响应
|
||||
StringBuilder response = new StringBuilder();
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查服务是否可用
|
||||
*/
|
||||
public boolean isServiceAvailable() {
|
||||
try {
|
||||
try (Socket socket = new Socket()) {
|
||||
socket.connect(new java.net.InetSocketAddress(DEFAULT_HOST, DEFAULT_PORT), 3000);
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,172 +0,0 @@
|
||||
package cn.iocoder.yudao.module.annotation.service.yolo;
|
||||
// YoloServiceImpl.java
|
||||
|
||||
import cn.iocoder.yudao.module.annotation.dal.yolo.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class YoloServiceImpl implements YoloService {
|
||||
|
||||
@Override
|
||||
public TrainingResult train(YoloConfig config) {
|
||||
try {
|
||||
// 构建训练命令
|
||||
ProcessBuilder pb = buildTrainCommand(config);
|
||||
Process process = pb.start();
|
||||
|
||||
// 读取输出
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
// 可以在这里解析训练进度
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode == 0) {
|
||||
return new TrainingResult(true, "Training completed successfully", output.toString());
|
||||
} else {
|
||||
return new TrainingResult(false, "Training failed with exit code: " + exitCode, output.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new TrainingResult(false, "Training error: " + e.getMessage(), "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult validate(YoloConfig config) {
|
||||
try {
|
||||
ProcessBuilder pb = buildValidateCommand(config);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return new ValidationResult(exitCode == 0, output.toString());
|
||||
} catch (Exception e) {
|
||||
return new ValidationResult(false, "Validation error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PredictionResult predict(YoloConfig config, String imagePath) {
|
||||
try {
|
||||
ProcessBuilder pb = buildPredictCommand(config, imagePath);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return new PredictionResult(exitCode == 0, output.toString(), imagePath);
|
||||
} catch (Exception e) {
|
||||
return new PredictionResult(false, "Prediction error: " + e.getMessage(), imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportResult export(YoloConfig config, String format) {
|
||||
try {
|
||||
ProcessBuilder pb = buildExportCommand(config, format);
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream())
|
||||
);
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return new ExportResult(exitCode == 0, output.toString(), format);
|
||||
} catch (Exception e) {
|
||||
return new ExportResult(false, "Export error: " + e.getMessage(), format);
|
||||
}
|
||||
}
|
||||
|
||||
private ProcessBuilder buildTrainCommand(YoloConfig config) {
|
||||
// 假设使用Python脚本调用YOLO
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "train",
|
||||
"--model", config.getModelPath(),
|
||||
"--data", config.getDatasetPath(),
|
||||
"--epochs", String.valueOf(config.getEpochs()),
|
||||
"--batch", String.valueOf(config.getBatchSize()),
|
||||
"--lr", String.valueOf(config.getLearningRate()),
|
||||
"--device", config.getDevice(),
|
||||
"--project", config.getOutputPath()
|
||||
);
|
||||
|
||||
if (config.isPretrained()) {
|
||||
pb.command().add("--pretrained");
|
||||
pb.command().add("True");
|
||||
}
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private ProcessBuilder buildValidateCommand(YoloConfig config) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "val",
|
||||
"--model", config.getModelPath(),
|
||||
"--data", config.getDatasetPath(),
|
||||
"--device", config.getDevice()
|
||||
);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private ProcessBuilder buildPredictCommand(YoloConfig config, String imagePath) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "predict",
|
||||
"--model", config.getModelPath(),
|
||||
"--source", imagePath,
|
||||
"--device", config.getDevice(),
|
||||
"--project", config.getOutputPath()
|
||||
);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private ProcessBuilder buildExportCommand(YoloConfig config, String format) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(
|
||||
"python", "-m", "ultralytics", "export",
|
||||
"--model", config.getModelPath(),
|
||||
"--format", format
|
||||
);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
return pb;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,121 @@
|
||||
package cn.iocoder.yudao.module.logistics.controller.admin.checkconf;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.camera.dal.entity.ScanData;
|
||||
import cn.iocoder.yudao.module.camera.service.plc.PLCService;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfPageReqVO;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfRespVO;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfSaveReqVO;
|
||||
import cn.iocoder.yudao.module.logistics.dal.dataobject.checkconf.CheckConfDO;
|
||||
import cn.iocoder.yudao.module.logistics.service.checkconf.CheckConfService;
|
||||
import cn.iocoder.yudao.module.system.util.RedisUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 盘点配置")
|
||||
@RestController
|
||||
@RequestMapping("/logistics/check-conf")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class CheckConfController {
|
||||
|
||||
@Resource
|
||||
private CheckConfService checkConfService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建盘点配置")
|
||||
@PreAuthorize("@ss.hasPermission('logistics:check-conf:create')")
|
||||
public CommonResult<Integer> createCheckConf(@Valid @RequestBody CheckConfSaveReqVO createReqVO) {
|
||||
return success(checkConfService.createCheckConf(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新盘点配置")
|
||||
@PreAuthorize("@ss.hasPermission('logistics:check-conf:update')")
|
||||
public CommonResult<Boolean> updateCheckConf(@Valid @RequestBody CheckConfSaveReqVO updateReqVO) {
|
||||
checkConfService.updateCheckConf(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除盘点配置")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('logistics:check-conf:delete')")
|
||||
public CommonResult<Boolean> deleteCheckConf(@RequestParam("id") Integer id) {
|
||||
checkConfService.deleteCheckConf(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得盘点配置")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('logistics:check-conf:query')")
|
||||
public CommonResult<CheckConfRespVO> getCheckConf(@RequestParam("id") Integer id) {
|
||||
CheckConfDO checkConf = checkConfService.getCheckConf(id);
|
||||
return success(BeanUtils.toBean(checkConf, CheckConfRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得盘点配置分页")
|
||||
@PreAuthorize("@ss.hasPermission('logistics:check-conf:query')")
|
||||
public CommonResult<PageResult<CheckConfRespVO>> getCheckConfPage(@Valid CheckConfPageReqVO pageReqVO) {
|
||||
PageResult<CheckConfDO> pageResult = checkConfService.getCheckConfPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, CheckConfRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出盘点配置 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('logistics:check-conf:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportCheckConfExcel(@Valid CheckConfPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<CheckConfDO> list = checkConfService.getCheckConfPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "盘点配置.xls", "数据", CheckConfRespVO.class,
|
||||
BeanUtils.toBean(list, CheckConfRespVO.class));
|
||||
}
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
PLCService plcService;
|
||||
|
||||
@PostMapping("/check")
|
||||
@Operation(summary = "导出盘点配置 Excel")
|
||||
@PermitAll
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void checkReturn(@Valid ScanData scanData) throws IOException {
|
||||
String code = scanData != null ? scanData.getCode() : null;
|
||||
redisUtil.hset("stock:task:" + scanData.getTaskId(), scanData.getType(), code);
|
||||
log.info("同步扫码完成, taskId: {}, scanType: {}, code: {}", scanData.getTaskId(), scanData.getType(), code);
|
||||
|
||||
Map<String, String> result = redisUtil.hmget("stock:task:" + scanData.getTaskId());
|
||||
if (result != null && !result.containsValue(null) && !result.containsValue("")) {
|
||||
plcService.stopCheck(scanData.getTaskId(), result);
|
||||
redisUtil.del("stock:task:" + scanData.getTaskId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 盘点配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CheckConfPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "盘点排序")
|
||||
private Integer checkOrder;
|
||||
|
||||
@Schema(description = "异步类型")
|
||||
private String checkAsyn;
|
||||
|
||||
@Schema(description = "盘点编码")
|
||||
private String checkCode;
|
||||
|
||||
@Schema(description = "盘点名称", example = "李四")
|
||||
private String checkName;
|
||||
|
||||
@Schema(description = "盘点类型", example = "1")
|
||||
private String checkScanType;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "上位状态码", example = "1")
|
||||
private String checkType;
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 盘点配置 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CheckConfRespVO {
|
||||
|
||||
|
||||
@Schema(description = "id")
|
||||
@ExcelProperty("id")
|
||||
private Integer id;
|
||||
@Schema(description = "盘点排序")
|
||||
@ExcelProperty("盘点排序")
|
||||
private Integer checkOrder;
|
||||
|
||||
@Schema(description = "异步类型")
|
||||
@ExcelProperty(value = "异步类型", converter = DictConvert.class)
|
||||
@DictFormat("infra_config_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private String checkAsyn;
|
||||
|
||||
@Schema(description = "盘点编码")
|
||||
@ExcelProperty("盘点编码")
|
||||
private String checkCode;
|
||||
|
||||
@Schema(description = "盘点名称", example = "李四")
|
||||
@ExcelProperty("盘点名称")
|
||||
private String checkName;
|
||||
|
||||
@Schema(description = "盘点类型", example = "1")
|
||||
@ExcelProperty("盘点类型")
|
||||
private String checkScanType;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
@ExcelProperty("是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "上位状态码", example = "1")
|
||||
@ExcelProperty(value = "上位状态码", converter = DictConvert.class)
|
||||
@DictFormat("cssc_code") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private String checkType;
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 盘点配置新增/修改 Request VO")
|
||||
@Data
|
||||
public class CheckConfSaveReqVO {
|
||||
|
||||
@Schema(description = "盘点排序")
|
||||
private Integer id;
|
||||
|
||||
|
||||
@Schema(description = "盘点排序")
|
||||
private Integer checkOrder;
|
||||
|
||||
@Schema(description = "异步类型")
|
||||
private String checkAsyn;
|
||||
|
||||
@Schema(description = "盘点编码")
|
||||
private String checkCode;
|
||||
|
||||
@Schema(description = "盘点名称", example = "李四")
|
||||
private String checkName;
|
||||
|
||||
@Schema(description = "盘点类型", example = "1")
|
||||
private String checkScanType;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "上位状态码", example = "1")
|
||||
private String checkType;
|
||||
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package cn.iocoder.yudao.module.logistics.dal.dataobject.checkconf;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 盘点配置 DO
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@TableName("logistics_check_conf")
|
||||
@KeySequence("logistics_check_conf_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CheckConfDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 盘点排序
|
||||
*/
|
||||
private Integer checkOrder;
|
||||
/**
|
||||
* 异步类型
|
||||
*
|
||||
* 枚举 {@link TODO infra_config_type 对应的类}
|
||||
*/
|
||||
private String checkAsyn;
|
||||
/**
|
||||
* 盘点编码
|
||||
*/
|
||||
private String checkCode;
|
||||
/**
|
||||
* 盘点名称
|
||||
*/
|
||||
private String checkName;
|
||||
/**
|
||||
* 盘点类型
|
||||
*/
|
||||
private String checkScanType;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean isEnable;
|
||||
/**
|
||||
* 上位状态码
|
||||
*
|
||||
* 枚举 {@link TODO cssc_code 对应的类}
|
||||
*/
|
||||
private String checkType;
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.logistics.dal.mysql.checkconf;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.logistics.dal.dataobject.checkconf.CheckConfDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.*;
|
||||
|
||||
/**
|
||||
* 盘点配置 Mapper
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Mapper
|
||||
public interface CheckConfMapper extends BaseMapperX<CheckConfDO> {
|
||||
|
||||
default PageResult<CheckConfDO> selectPage(CheckConfPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CheckConfDO>()
|
||||
.eqIfPresent(CheckConfDO::getCheckOrder, reqVO.getCheckOrder())
|
||||
.eqIfPresent(CheckConfDO::getCheckAsyn, reqVO.getCheckAsyn())
|
||||
.eqIfPresent(CheckConfDO::getCheckCode, reqVO.getCheckCode())
|
||||
.likeIfPresent(CheckConfDO::getCheckName, reqVO.getCheckName())
|
||||
.eqIfPresent(CheckConfDO::getCheckScanType, reqVO.getCheckScanType())
|
||||
.eqIfPresent(CheckConfDO::getIsEnable, reqVO.getIsEnable())
|
||||
.eqIfPresent(CheckConfDO::getCheckType, reqVO.getCheckType())
|
||||
.orderByDesc(CheckConfDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.logistics.service.checkconf;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfPageReqVO;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfSaveReqVO;
|
||||
import cn.iocoder.yudao.module.logistics.dal.dataobject.checkconf.CheckConfDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* 盘点配置 Service 接口
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
public interface CheckConfService extends IService<CheckConfDO> {
|
||||
|
||||
/**
|
||||
* 创建盘点配置
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createCheckConf(@Valid CheckConfSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新盘点配置
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateCheckConf(@Valid CheckConfSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除盘点配置
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteCheckConf(Integer id);
|
||||
|
||||
/**
|
||||
* 获得盘点配置
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 盘点配置
|
||||
*/
|
||||
CheckConfDO getCheckConf(Integer id);
|
||||
|
||||
/**
|
||||
* 获得盘点配置分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 盘点配置分页
|
||||
*/
|
||||
PageResult<CheckConfDO> getCheckConfPage(CheckConfPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.logistics.service.checkconf;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfPageReqVO;
|
||||
import cn.iocoder.yudao.module.logistics.controller.admin.checkconf.vo.CheckConfSaveReqVO;
|
||||
import cn.iocoder.yudao.module.logistics.dal.dataobject.checkconf.CheckConfDO;
|
||||
import cn.iocoder.yudao.module.logistics.dal.mysql.checkconf.CheckConfMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 盘点配置 Service 实现类
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CheckConfServiceImpl extends ServiceImpl<CheckConfMapper, CheckConfDO> implements CheckConfService {
|
||||
|
||||
@Resource
|
||||
private CheckConfMapper checkConfMapper;
|
||||
|
||||
@Override
|
||||
public Integer createCheckConf(CheckConfSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
CheckConfDO checkConf = BeanUtils.toBean(createReqVO, CheckConfDO.class);
|
||||
checkConfMapper.insert(checkConf);
|
||||
// 返回
|
||||
return checkConf.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCheckConf(CheckConfSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
// validateCheckConfExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CheckConfDO updateObj = BeanUtils.toBean(updateReqVO, CheckConfDO.class);
|
||||
checkConfMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCheckConf(Integer id) {
|
||||
// 校验存在
|
||||
validateCheckConfExists(id);
|
||||
// 删除
|
||||
checkConfMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateCheckConfExists(Integer id) {
|
||||
if (checkConfMapper.selectById(id) == null) {
|
||||
throw exception(ErrorCodeConstants.CHECK_CONF_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckConfDO getCheckConf(Integer id) {
|
||||
return checkConfMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CheckConfDO> getCheckConfPage(CheckConfPageReqVO pageReqVO) {
|
||||
return checkConfMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.api.mail.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 邮件发送 Request DTO
|
||||
*
|
||||
* @author wangjingqi
|
||||
*/
|
||||
@Data
|
||||
public class MailSendSingleToUserReqDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Email
|
||||
private String mail;
|
||||
|
||||
/**
|
||||
* 邮件模板编号
|
||||
*/
|
||||
@NotNull(message = "邮件模板编号不能为空")
|
||||
private String templateCode;
|
||||
/**
|
||||
* 邮件模板参数
|
||||
*/
|
||||
private Map<String, Object> templateParams;
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue