|
|
@@ -0,0 +1,77 @@
|
|
|
+package com.fs.app.controller;
|
|
|
+
|
|
|
+import com.fs.app.taskService.SopLogsTaskService;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * SOP测试接口
|
|
|
+ * 用于测试指定SOP的待执行记录生成
|
|
|
+ */
|
|
|
+@Api(tags = "SOP测试接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/app/sop/test")
|
|
|
+@Slf4j
|
|
|
+public class SopTestController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SopLogsTaskService sopLogsTaskService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试单个或多个SOP
|
|
|
+ *
|
|
|
+ * @param sopIds SOP ID,多个用逗号分隔,例如:9e8afad5bde019b34006a33105dd2509
|
|
|
+ * @param testTime 测试时间,格式:yyyy-MM-dd HH:mm:ss,不传则使用当前时间(精确到小时)
|
|
|
+ * @return 执行结果
|
|
|
+ */
|
|
|
+ @ApiOperation("测试指定SOP")
|
|
|
+ @GetMapping("/executeSop")
|
|
|
+ public R executeSop(
|
|
|
+ @ApiParam(value = "SOP ID,多个用逗号分隔", required = true, example = "9e8afad5bde019b34006a33105dd2509")
|
|
|
+ @RequestParam String sopIds,
|
|
|
+ @ApiParam(value = "测试时间,格式:yyyy-MM-dd HH:mm:ss,不传则使用当前时间", example = "2025-12-27 10:00:00")
|
|
|
+ @RequestParam(required = false) String testTime) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析SOP ID列表
|
|
|
+ List<String> sopIdList = Arrays.asList(sopIds.split(","));
|
|
|
+
|
|
|
+ // 解析测试时间
|
|
|
+ LocalDateTime executeTime;
|
|
|
+ if (testTime != null && !testTime.trim().isEmpty()) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ executeTime = LocalDateTime.parse(testTime, formatter);
|
|
|
+ } else {
|
|
|
+ // 默认使用当前时间,精确到小时
|
|
|
+ executeTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("========== 开始测试SOP ==========");
|
|
|
+ log.info("SOP ID列表: {}", sopIdList);
|
|
|
+ log.info("测试时间: {}", executeTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+
|
|
|
+ // 执行SOP任务
|
|
|
+ sopLogsTaskService.selectSopUserLogsListByTime(executeTime, sopIdList);
|
|
|
+
|
|
|
+ log.info("========== SOP测试执行完成 ==========");
|
|
|
+
|
|
|
+ return R.ok().put("message", "SOP测试执行成功!")
|
|
|
+ .put("sopIds", sopIds)
|
|
|
+ .put("executeTime", executeTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SOP测试执行失败", e);
|
|
|
+ return R.error("SOP测试执行失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|