基础类修改
This commit is contained in:
parent
200222165a
commit
7bb9d657f9
@ -0,0 +1,29 @@
|
||||
package com.yfd.business.css.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class MybatisConfig {
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
||||
MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
|
||||
.getResources("classpath*:/mapper/**/*.xml"));
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
|
||||
return new SqlSessionTemplate(sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,9 @@ import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilde
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -38,6 +41,9 @@ public class OpenApiConfig {
|
||||
builder.deserializers(new LocalDateTimeDeserializer(fmt));
|
||||
builder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
builder.serializationInclusion(JsonInclude.Include.ALWAYS);
|
||||
builder.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE);
|
||||
builder.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY);
|
||||
builder.propertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE);
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.setSerializerModifier(new BeanSerializerModifier() {
|
||||
@Override
|
||||
|
||||
@ -115,6 +115,7 @@ public class EventController {
|
||||
public List<Event> listByScenario(@RequestParam String scenarioId) {
|
||||
return eventService.list(
|
||||
new QueryWrapper<Event>()
|
||||
.select("event_id","scenario_id","device_id","material_id","attr_changes","trigger_time","created_at","modifier")
|
||||
.eq("scenario_id", scenarioId)
|
||||
.orderByDesc("created_at")
|
||||
);
|
||||
|
||||
@ -91,7 +91,7 @@ public class MaterialController {
|
||||
@GetMapping("/search")
|
||||
public Page<Material> search(@RequestParam(required = false) String name,
|
||||
@RequestParam(defaultValue = "1") long pageNum,
|
||||
@RequestParam(defaultValue = "10") long pageSize) {
|
||||
@RequestParam(defaultValue = "20") long pageSize) {
|
||||
QueryWrapper<Material> wrapper = new QueryWrapper<>();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
wrapper.like("name", name);
|
||||
@ -99,4 +99,17 @@ public class MaterialController {
|
||||
Page<Material> page = new Page<>(pageNum, pageSize);
|
||||
return materialService.page(page, wrapper.orderByDesc("created_at"));
|
||||
}
|
||||
|
||||
@GetMapping("/by-project")
|
||||
public Page<Material> pageByProject(@RequestParam String projectId,
|
||||
@RequestParam(defaultValue = "1") long pageNum,
|
||||
@RequestParam(defaultValue = "20") long pageSize) {
|
||||
QueryWrapper<Material> wrapper = new QueryWrapper<Material>()
|
||||
.eq("project_id", projectId)
|
||||
.orderByDesc("created_at");
|
||||
Page<Material> page = new Page<>(pageNum, pageSize);
|
||||
return materialService.page(page, wrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.business.css.domain.Project;
|
||||
import com.yfd.business.css.service.ProjectService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -21,6 +24,7 @@ import java.time.format.DateTimeFormatter;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/projects")
|
||||
@Tag(name = "项目接口", description = "项目增删改查、拓扑解析与模拟初始化")
|
||||
public class ProjectController {
|
||||
|
||||
@Resource
|
||||
@ -36,6 +40,7 @@ public class ProjectController {
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "新增项目", description = "请求体传入项目对象,返回是否新增成功")
|
||||
public boolean create(@RequestBody Project project) {
|
||||
return projectService.save(project);
|
||||
}
|
||||
@ -48,6 +53,7 @@ public class ProjectController {
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@PutMapping
|
||||
@Operation(summary = "修改项目", description = "请求体传入项目对象(需包含主键),返回是否修改成功")
|
||||
public boolean update(@RequestBody Project project) {
|
||||
return projectService.updateById(project);
|
||||
}
|
||||
@ -60,7 +66,8 @@ public class ProjectController {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public boolean delete(@PathVariable String id) {
|
||||
@Operation(summary = "删除项目(单条)", description = "根据项目ID删除项目")
|
||||
public boolean delete(@PathVariable @Parameter(description = "项目ID", required = true) String id) {
|
||||
return projectService.removeById(id);
|
||||
}
|
||||
|
||||
@ -72,6 +79,7 @@ public class ProjectController {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除项目(批量)", description = "请求体传入项目ID列表,批量删除项目")
|
||||
public boolean deleteBatch(@RequestBody List<String> ids) {
|
||||
return projectService.removeByIds(ids);
|
||||
}
|
||||
@ -85,6 +93,7 @@ public class ProjectController {
|
||||
* @return 附件响应,文件名为 projects.xlsx
|
||||
*/
|
||||
@GetMapping("/exportAllExports")
|
||||
@Operation(summary = "导出所有项目(Excel)", description = "返回所有项目的 Excel 附件 projects.xlsx")
|
||||
public ResponseEntity<byte[]> exportAllExports() {
|
||||
byte[] bytes = projectService.exportAllProjectsExcel();
|
||||
return ResponseEntity.ok()
|
||||
@ -108,7 +117,8 @@ public class ProjectController {
|
||||
* @return 附件响应,文件名为 project_{id}.xlsx
|
||||
*/
|
||||
@GetMapping("/{id}/exportProject")
|
||||
public ResponseEntity<byte[]> exportProjectExcel(@PathVariable String id) {
|
||||
@Operation(summary = "导出项目工程(多Sheet)", description = "根据项目ID导出工程数据,返回 Excel 附件 project_{id}.xlsx")
|
||||
public ResponseEntity<byte[]> exportProjectExcel(@PathVariable @Parameter(description = "项目ID", required = true) String id) {
|
||||
byte[] bytes = projectService.exportProjectEngineeringExcel(id);
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=project_" + id + ".xlsx")
|
||||
@ -126,9 +136,10 @@ public class ProjectController {
|
||||
* @return 项目分页列表
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public Page<Project> search(@RequestParam(required = false) String name,
|
||||
@RequestParam(defaultValue = "1") long pageNum,
|
||||
@RequestParam(defaultValue = "10") long pageSize) {
|
||||
@Operation(summary = "搜索项目并分页返回", description = "按名称关键词模糊查询,返回分页结果")
|
||||
public Page<Project> search(@RequestParam(required = false) @Parameter(description = "项目名称关键词,可为空") String name,
|
||||
@RequestParam(defaultValue = "1") @Parameter(description = "页码,默认1") long pageNum,
|
||||
@RequestParam(defaultValue = "10") @Parameter(description = "每页条数,默认10") long pageSize) {
|
||||
QueryWrapper<Project> wrapper = new QueryWrapper<>();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
wrapper.like("name", name);
|
||||
@ -145,7 +156,8 @@ public class ProjectController {
|
||||
* @return 项目对象
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Project getById(@PathVariable String id) {
|
||||
@Operation(summary = "根据项目ID获取项目信息", description = "项目不存在时返回空对象")
|
||||
public Project getById(@PathVariable @Parameter(description = "项目ID", required = true) String id) {
|
||||
return projectService.getById(id);
|
||||
}
|
||||
|
||||
@ -158,7 +170,8 @@ public class ProjectController {
|
||||
* @return 标准响应结构
|
||||
*/
|
||||
@PutMapping("/{id}/topology")
|
||||
public ResponseEntity<Map<String, Object>> updateTopology(@PathVariable String id,
|
||||
@Operation(summary = "更新项目拓扑结构", description = "请求体需包含合法的 topology JSON(对象或字符串)")
|
||||
public ResponseEntity<Map<String, Object>> updateTopology(@PathVariable @Parameter(description = "项目ID", required = true) String id,
|
||||
@RequestBody Map<String, Object> requestBody) {
|
||||
Object topology = requestBody.get("topology");
|
||||
if (topology == null) {
|
||||
@ -199,7 +212,8 @@ public class ProjectController {
|
||||
* @param id 项目ID
|
||||
* @return 标准响应结构,data 为 TopologyParseResult
|
||||
*/
|
||||
public ResponseEntity<Map<String, Object>> parseTopology(@PathVariable String id) {
|
||||
@Operation(summary = "解析项目拓扑结构", description = "返回属性节点、影响边与线性计算计划")
|
||||
public ResponseEntity<Map<String, Object>> parseTopology(@PathVariable @Parameter(description = "项目ID", required = true) String id) {
|
||||
var result = projectService.parseTopology(id);
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"code", 0,
|
||||
@ -214,7 +228,8 @@ public class ProjectController {
|
||||
* @param id 项目ID
|
||||
* @return 标准响应结构,data 为 List<Device>
|
||||
*/
|
||||
public ResponseEntity<Map<String, Object>> parseDeviceOrder(@PathVariable String id) {
|
||||
@Operation(summary = "解析拓扑设备顺序", description = "根据 devices 出现顺序返回设备列表")
|
||||
public ResponseEntity<Map<String, Object>> parseDeviceOrder(@PathVariable @Parameter(description = "项目ID", required = true) String id) {
|
||||
var list = projectService.parseDeviceOrder(id);
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"code", 0,
|
||||
@ -229,7 +244,8 @@ public class ProjectController {
|
||||
* @param id 项目ID
|
||||
* @return 标准响应结构,data 为视图对象(devices/pipelines/boundaries/display)
|
||||
*/
|
||||
public ResponseEntity<Map<String, Object>> parseCanvas(@PathVariable String id) {
|
||||
@Operation(summary = "解析画布视图数据", description = "返回设备/管线/边界与显示配置")
|
||||
public ResponseEntity<Map<String, Object>> parseCanvas(@PathVariable @Parameter(description = "项目ID", required = true) String id) {
|
||||
var view = projectService.parseCanvasView(id);
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"code", 0,
|
||||
@ -238,11 +254,12 @@ public class ProjectController {
|
||||
));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/scenarios/{scenarioId}/simulation/init")
|
||||
public ResponseEntity<Map<String, Object>> initSimulation(@PathVariable String id,
|
||||
@PathVariable String scenarioId,
|
||||
@PostMapping("/simulation/init")
|
||||
@Operation(summary = "初始化项目模拟数据", description = "按时间范围与步长生成快照并落库,返回统计与问题列表")
|
||||
public ResponseEntity<Map<String, Object>> initSimulation(@RequestParam @Parameter(description = "项目ID", required = true) String projectId,
|
||||
@RequestParam @Parameter(description = "情景ID", required = true) String scenarioId,
|
||||
@RequestBody(required = false) Map<String, Object> params) {
|
||||
var res = projectService.initSimulation(id, scenarioId, params == null ? Map.of() : params);
|
||||
var res = projectService.initSimulation(projectId, scenarioId, params == null ? Map.of() : params);
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"code", 0,
|
||||
"msg", "初始化完成",
|
||||
|
||||
@ -36,6 +36,6 @@ public class Event implements Serializable {
|
||||
@TableField("created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@TableField("modifer")
|
||||
@TableField("modifier")
|
||||
private String modifier;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -26,12 +27,14 @@ public class Material implements Serializable {
|
||||
private String name;
|
||||
|
||||
@TableField("u_concentration")
|
||||
@JsonProperty("uConcentration")
|
||||
private BigDecimal uConcentration;
|
||||
|
||||
@TableField("uo2_density")
|
||||
private BigDecimal uo2Density;
|
||||
|
||||
@TableField("u_enrichment")
|
||||
@JsonProperty("uEnrichment")
|
||||
private BigDecimal uEnrichment;
|
||||
|
||||
@TableField("pu_concentration")
|
||||
|
||||
@ -69,7 +69,9 @@ public class SimulationInitTest {
|
||||
.andExpect(MockMvcResultMatchers.status().isOk());
|
||||
|
||||
String initBody = "{\"startTime\":0,\"endTime\":18,\"step\":2}";
|
||||
String initResp = mockMvc.perform(MockMvcRequestBuilders.post("/projects/" + projectId + "/scenarios/" + scenarioId + "/simulation/init")
|
||||
String initResp = mockMvc.perform(MockMvcRequestBuilders.post("/projects/simulation/init")
|
||||
.param("projectId", projectId)
|
||||
.param("scenarioId", scenarioId)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(initBody))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
@ -95,7 +97,9 @@ public class SimulationInitTest {
|
||||
String projectId = "proj-0001-uuid";
|
||||
String scenarioId = "scen-001-uuid";
|
||||
String initBody = "{\"startTime\":0,\"endTime\":10,\"step\":2}";
|
||||
String initResp = mockMvc.perform(MockMvcRequestBuilders.post("/projects/" + projectId + "/scenarios/" + scenarioId + "/simulation/init")
|
||||
String initResp = mockMvc.perform(MockMvcRequestBuilders.post("/projects/simulation/init")
|
||||
.param("projectId", projectId)
|
||||
.param("scenarioId", scenarioId)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(initBody))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
@ -120,7 +124,9 @@ public class SimulationInitTest {
|
||||
String projectId = "proj-0001-uuid";
|
||||
String scenarioId = "scen-001-uuid";
|
||||
String initBody = "{\"startTime\":0,\"endTime\":12,\"step\":3}";
|
||||
String initResp = mockMvc.perform(MockMvcRequestBuilders.post("/projects/" + projectId + "/scenarios/" + scenarioId + "/simulation/init")
|
||||
String initResp = mockMvc.perform(MockMvcRequestBuilders.post("/projects/simulation/init")
|
||||
.param("projectId", projectId)
|
||||
.param("scenarioId", scenarioId)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(initBody))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user