|
@@ -1,8 +1,11 @@
|
|
|
package com.xvji.web.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.xvji.common.core.domain.AjaxResult;
|
|
|
import com.xvji.domain.Component;
|
|
|
import com.xvji.domain.PredictTask;
|
|
|
+import com.xvji.domain.vo.PageResult;
|
|
|
+import com.xvji.domain.vo.PredictTaskVO;
|
|
|
import com.xvji.mapper.PredictTaskMapper;
|
|
|
import com.xvji.service.ComponentService;
|
|
|
import com.xvji.service.PredictTaskService;
|
|
@@ -10,11 +13,16 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/task/predict")
|
|
@@ -163,6 +171,60 @@ public class PredictTaskController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分页查询预测任务及关联组件信息
|
|
|
+ * @param pageNum 页码(默认1)
|
|
|
+ * @param pageSize 每页条数(默认10)
|
|
|
+ * @param taskName 任务名称(可选,用于模糊查询)
|
|
|
+ */
|
|
|
+ @GetMapping("/queryTasks")
|
|
|
+ public AjaxResult queryPredictTasks(
|
|
|
+ @RequestParam(defaultValue = "1") int pageNum,
|
|
|
+ @RequestParam(defaultValue = "10") int pageSize,
|
|
|
+ @RequestParam(required = false) String taskName) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ Page<PredictTask> page = new Page<>(pageNum, pageSize);
|
|
|
+ QueryWrapper<PredictTask> queryWrapper = new QueryWrapper<>();
|
|
|
+ if (StringUtils.hasText(taskName)) {
|
|
|
+ queryWrapper.like("P_TASK_NAME", taskName); // 预测任务名称字段
|
|
|
+ }
|
|
|
+ //按创建时间降序排序
|
|
|
+ queryWrapper.orderByDesc("P_CREATE_TIME");
|
|
|
+
|
|
|
+ //执行分页查询
|
|
|
+ Page<PredictTask> taskPage = predictTaskService.page(page, queryWrapper);
|
|
|
+
|
|
|
+ List<PredictTaskVO> taskVOList = taskPage.getRecords().stream().map(task -> {
|
|
|
+ PredictTaskVO vo = new PredictTaskVO();
|
|
|
+ BeanUtils.copyProperties(task, vo); // 复制基本属性
|
|
|
+
|
|
|
+ String componentIds = task.getPComponentIds(); // 预测任务的组件ID字段
|
|
|
+ if (StringUtils.hasText(componentIds)) {
|
|
|
+ List<Long> ids = Arrays.stream(componentIds.split(","))
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Component> components = componentService.listByIds(ids);
|
|
|
+ vo.setComponents(components); // 设置关联的组件列表
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 5. 封装分页结果
|
|
|
+ PageResult<PredictTaskVO> result = new PageResult<>(
|
|
|
+ taskPage.getTotal(), // 总记录数
|
|
|
+ pageNum, // 当前页码
|
|
|
+ pageSize, // 每页条数
|
|
|
+ taskVOList // 分页数据列表
|
|
|
+ );
|
|
|
+
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResult.error("查询预测任务失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
////////////////////////////////////////// 辅助方法 //////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
/**
|