数据库表设计
报障表 (fault_reports
)
CREATE TABLE fault_reports (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
instance_id VARCHAR(255) NOT NULL,
fault_details TEXT NOT NULL,
fault_description TEXT NOT NULL,
report_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(20) NOT NULL DEFAULT '待处理', -- '已处理'或'待处理'
reported_by VARCHAR(255) NOT NULL
);
处理记录表 (fault_process_records
)
CREATE TABLE fault_process_records (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
fault_id BIGINT NOT NULL,
process_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
process_details TEXT NOT NULL,
processed_by VARCHAR(255) NOT NULL,
FOREIGN KEY (fault_id) REFERENCES fault_reports(id)
);
图片表 (fault_images
)
CREATE TABLE fault_images (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
fault_id BIGINT NOT NULL,
image_url VARCHAR(255) NOT NULL,
uploaded_by VARCHAR(255) NOT NULL,
upload_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (fault_id) REFERENCES fault_reports(id)
);
Java接口设计
报障Controller (FaultReportController
)
@RestController
@RequestMapping("/api/fault-reports")
public class FaultReportController {
@Autowired
private FaultReportService faultReportService;
@GetMapping
public List<FaultReport> getFaultReports() {
return faultReportService.findAll();
}
@PostMapping
public ResponseEntity<FaultReport> createFaultReport(@RequestBody FaultReportRequest faultReportRequest) {
FaultReport createdReport = faultReportService.createFaultReport(faultReportRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(createdReport);
}
@PutMapping("/{id}/process")
public ResponseEntity<FaultProcessRecord> processFaultReport(@PathVariable Long id, @RequestBody FaultProcessRequest faultProcessRequest) {
FaultProcessRecord processRecord = faultReportService.processFaultReport(id, faultProcessRequest);
return ResponseEntity.ok(processRecord);
}
}
报障服务 (FaultReportService
)
@Service
public class FaultReportService {
@Autowired
private FaultReportMapper faultReportMapper;
@Autowired
private FaultProcessRecordMapper faultProcessRecordMapper;
@Autowired
private FaultImageMapper faultImageMapper;
public List<FaultReport> findAll() {
return faultReportMapper.selectList(null);
}
public FaultReport createFaultReport(FaultReportRequest request) {
FaultReport faultReport = new FaultReport();
faultReport.setInstanceId(request.getInstanceId());
faultReport.setFaultDetails(request.getFaultDetails());
faultReport.setFaultDescription(request.getFaultDescription());
faultReport.setReportedBy(request.getReportedBy());
faultReportMapper.insert(faultReport);
request.getImages().forEach(imageUrl -> {
FaultImage faultImage = new FaultImage();
faultImage.setFaultId(faultReport.getId());
faultImage.setImageUrl(imageUrl);
faultImage.setUploadedBy(request.getReportedBy());
faultImageMapper.insert(faultImage);
});
return faultReport;
}
public FaultProcessRecord processFaultReport(Long id, FaultProcessRequest request) {
FaultProcessRecord processRecord = new FaultProcessRecord();
processRecord.setFaultId(id);
processRecord.setProcessDetails(request.getProcessDetails());
processRecord.setProcessedBy(request.getProcessedBy());
faultProcessRecordMapper.insert(processRecord);
request.getImages().forEach(imageUrl -> {
FaultImage faultImage = new FaultImage();
faultImage.setFaultId(id);
faultImage.setImageUrl(imageUrl);
faultImage.setUploadedBy(request.getProcessedBy());
faultImageMapper.insert(faultImage);
});
FaultReport faultReport = faultReportMapper.selectById(id);
faultReport.setStatus("已处理");
faultReportMapper.updateById(faultReport);
return processRecord;
}
}
数据传输对象(DTO)
FaultReportRequest
(新建报障请求)
public class FaultReportRequest {
private String instanceId;
private String faultDetails;
private String faultDescription;
private String reportedBy;
private List<String> images;
// Getters and setters
}
FaultProcessRequest
(处理报障请求)
public class FaultProcessRequest {
private String processDetails;
private String processedBy;
private List<String> images;
// Getters and setters
}
Mapper接口
报障Mapper (FaultReportMapper
)
public interface FaultReportMapper extends BaseMapper<FaultReport> {
}
处理记录Mapper (FaultProcessRecordMapper
)
public interface FaultProcessRecordMapper extends BaseMapper<FaultProcessRecord> {
}
图片Mapper (FaultImageMapper
)
public interface FaultImageMapper extends BaseMapper<FaultImage> {
}
实体类
报障实体 (FaultReport
)
public class FaultReport {
private Long id;
private String instanceId;
private String faultDetails;
private String faultDescription;
private Timestamp reportTime;
private String status;
private String reportedBy;
// Getters and setters
}
处理记录实体 (FaultProcessRecord
)
public class FaultProcessRecord {
private Long id;
private Long faultId;
private Timestamp processTime;
private String processDetails;
private String processedBy;
// Getters and setters
}
图片实体 (FaultImage
)
public class FaultImage {
private Long id;
private Long faultId;
private String imageUrl;
private String uploadedBy;
private Timestamp uploadTime;
// Getters and setters
}
说明
- 报障表 (
fault_reports
): 存储报障的基本信息,包括实例ID、故障详情、故障描述、报障时间、状态和报障人。 - 处理记录表 (
fault_process_records
): 存储每次故障处理的记录,包括处理时间、处理详情和处理人以及关联的报障ID。 - 图片表 (
fault_images
): 用于存储故障相关的图片信息,包括图片的URL、上传人和上传时间,并通过 fault_id
与报障记录关联。