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