Compare commits

2 Commits

Author SHA1 Message Date
dc
ddf44f9d2c 前端添加、查询修改 2025-06-30 14:40:02 +08:00
dc
12f602dc45 前端请求接收bug修复 2025-06-25 10:51:25 +08:00
13 changed files with 167 additions and 88 deletions

16
pom.xml

@ -103,7 +103,11 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.3</version>
</dependency>
<!-- 测试依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -182,6 +186,16 @@
<artifactId>lombok</artifactId>
<version>1.18.38</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

@ -1,6 +1,9 @@
package com.bipt.intelligentapplicationorchestrationservice.config;
import ch.qos.logback.classic.Logger;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.lettuce.core.ClientOptions;
import io.lettuce.core.SocketOptions;
import org.slf4j.LoggerFactory;
@ -86,6 +89,9 @@ public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(){
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
RedisTemplate<String, Object> template = new RedisTemplate<>();
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
log.info("开始创建redis模板对象...");

@ -13,7 +13,7 @@ import java.util.List;
public class GpuResourceController {
@Autowired
private GpuManageService gpuManageService;
@PostMapping
@PostMapping(value = "/add", produces = "application/json")
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
return gpuManageService.createGpuResource(dto);
}
@ -21,10 +21,13 @@ public class GpuResourceController {
public ResponseVO removeGpu(@PathVariable("gpuId") Long gpuId){
return gpuManageService.deleteGpuResource(gpuId);
}
@PutMapping("/{gpuId}")
@PutMapping(value = "/update/{gpuId}", produces = "application/json")
public void updateGpuResource(
@PathVariable Long gpuId,
@PathVariable("gpuId") Long gpuId,
@Valid @RequestBody GpuUpdateDTO dto){
if (gpuId == null) {
throw new IllegalArgumentException("GPU ID cannot be null");
}
dto.setGPUId(gpuId);
gpuManageService.updateGpuResource(dto);
}

@ -1,14 +1,14 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper;
package com.bipt.intelligentapplicationorchestrationservice.entity;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.springframework.stereotype.Component;
@Component
@Mapper(componentModel = "spring")
public interface GpuMapper {
public interface GpuEntityTransfer {
GpuResource toEntity(GpuCreateDTO dto);
GpuResource toEntity(GpuUpdateDTO dto);
GpuResource toEntity(GpuResponseDTO dto);

@ -2,7 +2,6 @@ package com.bipt.intelligentapplicationorchestrationservice.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
@ -10,43 +9,12 @@ import java.time.LocalDateTime;
@Setter
@Data
public class GpuResource {
@Getter
@TableField("GPUId")
private Long GPUId;
@Getter
@TableField("GPUModel")
private String GPUModel;
public Integer getGPUMemorySize() {
return GPUMemorySize;
}
public Long getGPUId() {
return GPUId;
}
public String getGPUModel() {
return GPUModel;
}
public String getIp() {
return Ip;
}
public LocalDateTime getCreateTime() {
return CreateTime;
}
public LocalDateTime getUpdateTime() {
return UpdateTime;
}
public Integer getGPUMaxMemory() {
return GPUMaxMemory;
}
@Getter
@TableField("GPUMemorySize")
private Integer GPUMemorySize;
@ -56,15 +24,12 @@ public class GpuResource {
@TableField("Ip")
private String Ip;
@Getter
@TableField("CreatedTime")
private LocalDateTime CreateTime;
@TableField("created_time")
private LocalDateTime createTime;
@Getter
@TableField("update_time")
private LocalDateTime UpdateTime;
@Getter
@TableField("GPUMaxMemory")
private Integer GPUMaxMemory;
@ -88,11 +53,35 @@ public class GpuResource {
this.GPUModel = Model;
this.GPUMemorySize = MemorySize;
this.Ip = ip;
this.CreateTime = create_time;
this.createTime = create_time;
}
public GpuResource() {}
public Integer getGPUMemorySize() {
return GPUMemorySize;
}
public Long getGPUId() {
return GPUId;
}
public String getGPUModel() {
return GPUModel;
}
public String getIp() {
return Ip;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public Integer getGPUMaxMemory() {
return GPUMaxMemory;
}
public void setGPUId(Long GPUId) {
this.GPUId = GPUId;
}
@ -114,11 +103,7 @@ public class GpuResource {
}
public void setCreateTime(LocalDateTime createTime) {
CreateTime = createTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
UpdateTime = updateTime;
this.createTime = createTime;
}

@ -11,8 +11,8 @@ import java.util.Map;
@Mapper
public interface GpuResourceDao {
//---------------------- 基础CRUD ------------------------
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
"VALUES (#{model}, #{memory}, #{ip})")
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip, created_time) " +
"VALUES (#{GPUModel}, #{GPUMemorySize}, #{Ip}, NOW())")
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
Integer insert(GpuResource entity);
@ -27,7 +27,7 @@ public interface GpuResourceDao {
Integer isDeleted(@Param("gpuId") Long gpuId);
@Update("UPDATE Ipz.public.gpu_resource " +
"SET GPUModel = #{model}, GPUMemorySize = #{memory}, Ip = #{ip} " +
"SET GPUModel = #{GPUModel}, GPUMemorySize = #{GPUMemorySize}, Ip = #{Ip} " +
"WHERE GPUId = #{GPUId}")
Integer updateById(GpuResource entity);

@ -1,5 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
@ -14,14 +15,17 @@ public class GpuCreateDTO {
@NotBlank(message = "GPU型号不能为空")
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
@JsonProperty("GPUModel") // 显示指定JSON映射名称
private String GPUModel;
@NotNull(message = "显存容量不能为空")
@JsonProperty("GPUMemorySize")
private Integer GPUMemorySize;
@NotBlank(message = "IP地址不能为空")
@Pattern(regexp = "^\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}$",
@Pattern(regexp = "^(\\d{1,3}\\.){3}\\d{1,3}$",
message = "IP地址格式无效")
@JsonProperty("Ip") // 显示指定JSON映射名称
private String Ip;
}

@ -1,23 +1,30 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class GpuResponseDTO {
private Long id;
@JsonView
private Long GPUId;
private String GPUModel;
private Integer GPUMemorySize;
private String Ip;
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createTime;
// Builder类
public static class Builder {
private Long id;
private String model;
private Integer memory;
private String ip;
private LocalDateTime createdTime;
private LocalDateTime createTime = LocalDateTime.now(); // 统一命名为createTime
public Builder id(Long id) {
this.id = id;
@ -39,19 +46,29 @@ public class GpuResponseDTO {
return this;
}
public Builder createdTime(LocalDateTime createdTime) {
this.createdTime = createdTime;
public Builder createTime(LocalDateTime createTime) {
this.createTime = createTime;
return this;
}
public GpuResponseDTO build() {
// 必填字段校验如网页2的推荐
// 必填字段校验
if (id == null) {
throw new IllegalArgumentException("GPU ID必须填写");
}
return new GpuResponseDTO();
GpuResponseDTO dto = new GpuResponseDTO();
dto.setGPUId(id);
dto.setGPUModel(model);
dto.setGPUMemorySize(memory);
dto.setIp(ip);
dto.setCreateTime(createTime); // 正确赋值createTime
return dto;
}
}
public String getCreateTimeStr(){
return "GPU创建时间" + createTime.toString();
public String getCreateTimeStr() {
return "GPU创建时间" + (createTime != null ? createTime.toString() : "未设置");
}
}
}

@ -10,11 +10,30 @@ import lombok.*;
//@Setter
//@Getter
public class GpuUpdateDTO {
public @NotNull(message = "GPU ID cannot be null") Long getGPUId() {
return GPUId;
private Long GPUId;
public @Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") String getGPUModel() {
return GPUModel;
}
public void setGPUId(@NotNull(message = "GPU ID cannot be null") Long GPUId) {
public @Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
message = "IP地址格式无效") String getIp() {
return Ip;
}
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
private String GPUModel;
private Integer GPUMemorySize;
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
message = "IP地址格式无效")
private String Ip;
public void setGPUId(Long GPUId) {
this.GPUId = GPUId;
}
@ -27,18 +46,15 @@ public class GpuUpdateDTO {
message = "IP地址格式无效") String ip) {
Ip = ip;
}
public Long getGPUId() {
return GPUId;
}
@NotNull(message = "GPU ID cannot be null")
private Long GPUId;
public Integer getGPUMemorySize() {
return GPUMemorySize;
}
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
private String GPUModel;
@Setter
private Integer GPUMemorySize;
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
message = "IP地址格式无效")
private String Ip;
public void setGPUMemorySize(Integer GPUMemorySize) {
this.GPUMemorySize = GPUMemorySize;
}
}

@ -33,6 +33,30 @@ public class ResponseVO<T> implements Serializable {
}
//失败响应(基于预定义错误枚举)
public static <T> ResponseVO<T> error(ErrorCodeEnum errorCode) {
return new ResponseVO<>(errorCode.getCode(), errorCode.getMessage(), null);
return new ResponseVO<>(errorCode.getCode(), errorCode.getMessage(), null);
}
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}

@ -1,7 +1,7 @@
package com.bipt.intelligentapplicationorchestrationservice.service.impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuMapper;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuEntityTransfer;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
@ -28,7 +28,7 @@ public class GpuManageServiceImpl implements GpuManageService {
private GpuResourceDao gpuDao;
@Autowired
private GpuMapper gpuMapper;
private GpuEntityTransfer gpuEntityTransfer;
@Transactional
@Override
@ -36,7 +36,7 @@ public class GpuManageServiceImpl implements GpuManageService {
try {
logger.info("创建GPU资源请求: {}", dto);
GpuResource entity = gpuMapper.toEntity(dto);
GpuResource entity = gpuEntityTransfer.toEntity(dto);
gpuDao.insert(entity);
logger.info("创建GPU资源成功, ID: {}", entity.getGPUId());
@ -76,7 +76,7 @@ public class GpuManageServiceImpl implements GpuManageService {
logger.info("更新GPU资源请求: {}", dto);
try {
GpuResource entity = gpuMapper.toEntity(dto);
GpuResource entity = gpuEntityTransfer.toEntity(dto);
gpuDao.updateById(entity);
logger.info("更新GPU资源成功, ID: {}", entity.getGPUId());
@ -100,7 +100,7 @@ public class GpuManageServiceImpl implements GpuManageService {
logger.info("查询到 {} 条GPU资源", entities.size());
return entities.stream()
.map(gpuMapper::toDTO)
.map(gpuEntityTransfer::toDTO)
.collect(Collectors.toList());
} catch (Exception e) {

@ -9,6 +9,7 @@ spring.datasource.driver-class-name=com.kingbase8.Driver
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-timeout=30000
spring.mvc.contentnegotiation.default-content-type=application/json
# MyBatis??
mybatis.mapper-locations=classpath:mapper/*.xml

@ -2,10 +2,19 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao">
<resultMap id="gpuResourceMap" type="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
<id property="GPUId" column="GPUId" /> <!-- 强制映射 -->
<result property="createTime" column="created_time"/>
<result property="UpdateTime" column="update_time"/>
<result property="GPUModel" column="GPUModel"/>
<result property="GPUMemorySize" column="GPUMemorySize"/>
<result property="Ip" column="Ip"/>
<result property="isDeleted" column="is_deleted"/>
<result property="GPUMaxMemory" column="GPUMaxMemory"/>
</resultMap>
<!-- 动态条件查询 -->
<select id="selectByFields"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
resultMap="gpuResourceMap">
SELECT *
FROM Ipz.public.gpu_resource
<where>