提交新修改
This commit is contained in:
parent
8262b7c054
commit
0c64c11b58
@ -1,10 +1,12 @@
|
||||
package com.yfd.business.css.controller;
|
||||
|
||||
import com.yfd.business.css.domain.Device;
|
||||
import com.yfd.business.css.domain.Event;
|
||||
import com.yfd.business.css.service.EventService;
|
||||
import com.yfd.platform.system.service.IUserService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
@ -26,15 +28,13 @@ import com.yfd.business.css.dto.EventAttrPoint;
|
||||
@RequestMapping("/events")
|
||||
public class EventController {
|
||||
|
||||
private final EventService eventService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final IUserService userService;
|
||||
@Resource
|
||||
private EventService eventService;
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
@Resource
|
||||
private IUserService userService;
|
||||
|
||||
public EventController(EventService eventService, ObjectMapper objectMapper, IUserService userService) {
|
||||
this.eventService = eventService;
|
||||
this.objectMapper = objectMapper;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增始发事件
|
||||
@ -58,24 +58,10 @@ public class EventController {
|
||||
* @param event 事件对象
|
||||
* @return 修改结果
|
||||
*/
|
||||
@PutMapping("/{eventId}")
|
||||
public ResponseEntity<Map<String, Object>> updateEvent(@PathVariable String eventId,
|
||||
@RequestBody Event event) {
|
||||
event.setEventId(eventId);
|
||||
@PutMapping
|
||||
public boolean update(@RequestBody Event event) {
|
||||
event.setModifier(currentUsername());
|
||||
event.setUpdatedAt(LocalDateTime.now());
|
||||
boolean ok = eventService.updateById(event);
|
||||
if (!ok) {
|
||||
return ResponseEntity.badRequest().body(Map.of(
|
||||
"code", 1,
|
||||
"msg", "修改失败"
|
||||
));
|
||||
}
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"code", 0,
|
||||
"msg", "修改成功",
|
||||
"data", event
|
||||
));
|
||||
return eventService.updateById(event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -19,12 +19,6 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@RestController
|
||||
|
||||
@ -487,11 +487,13 @@ public class ProjectServiceImpl
|
||||
out.put("scenarioId", scenarioId);
|
||||
List<String> issues = new ArrayList<>();
|
||||
out.put("issues", issues);
|
||||
List<Map<String, Object>> frames = new ArrayList<>();
|
||||
try {
|
||||
Project p = this.getById(projectId);
|
||||
if (p == null || p.getTopology() == null || p.getTopology().isBlank()) {
|
||||
issues.add("topology为空");
|
||||
out.put("generated", Map.of("events", 0, "snapshots", 0));
|
||||
out.put("frames", frames);
|
||||
return out;
|
||||
}
|
||||
JsonNode root = objectMapper.readTree(p.getTopology());
|
||||
@ -503,6 +505,7 @@ public class ProjectServiceImpl
|
||||
if (devs.isEmpty()) {
|
||||
issues.add("devices为空");
|
||||
out.put("generated", Map.of("events", 0, "snapshots", 0));
|
||||
out.put("frames", frames);
|
||||
return out;
|
||||
}
|
||||
Map<String, Map<String, Double>> devStatic = new HashMap<>();
|
||||
@ -517,7 +520,6 @@ public class ProjectServiceImpl
|
||||
.eq("scenario_id", scenarioId)
|
||||
);
|
||||
Map<String, Object> valueProviders = buildValueProviders(events, issues);
|
||||
List<ScenarioResult> all = new ArrayList<>();
|
||||
int snapshots = 0;
|
||||
for (long t = start; t <= end; t += stepSec) {
|
||||
int stepIndex = (int) ((t - start) / stepSec);
|
||||
@ -582,22 +584,21 @@ public class ProjectServiceImpl
|
||||
}
|
||||
state.put("materials", materialsState);
|
||||
deviceStates.put(did, state);
|
||||
ScenarioResult sr = new ScenarioResult();
|
||||
sr.setScenarioId(scenarioId);
|
||||
sr.setDeviceId(did);
|
||||
sr.setStep(stepIndex);
|
||||
sr.setAttrState(objectMapper.writeValueAsString(state));
|
||||
sr.setKeffValue(null);
|
||||
all.add(sr);
|
||||
}
|
||||
snapshots += devs.size();
|
||||
Map<String, Object> frame = new HashMap<>();
|
||||
frame.put("time", t);
|
||||
frame.put("step", stepIndex);
|
||||
frame.put("devices", deviceStates);
|
||||
frames.add(frame);
|
||||
}
|
||||
if (!all.isEmpty()) scenarioResultService.saveBatch(all);
|
||||
out.put("generated", Map.of("events", events.size(), "snapshots", snapshots));
|
||||
out.put("frames", frames);
|
||||
return out;
|
||||
} catch (Exception ex) {
|
||||
issues.add("初始化失败:" + ex.getMessage());
|
||||
out.put("generated", Map.of("events", 0, "snapshots", 0));
|
||||
out.put("frames", frames);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user