feat(m6): add JSON template CRUD with versioning

This commit is contained in:
2026-05-25 01:36:40 +08:00
parent ae880c47b2
commit 46f28d2d97
8 changed files with 412 additions and 1 deletions
@@ -1,6 +1,7 @@
package cn.craftlabs.platform.api.integration;
import cn.craftlabs.platform.api.persistence.integration.PlatformBitanswerIdMapping;
import cn.craftlabs.platform.api.persistence.integration.PlatformJsonTemplate;
import cn.craftlabs.platform.api.service.IntegrationCatalogService;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse;
@@ -117,4 +118,33 @@ public class IntegrationCatalogController {
integrationCatalogService.deleteIdMapping(id);
return ResponseEntity.ok().build();
}
@GetMapping("/json-templates")
public ResponseEntity<java.util.List<PlatformJsonTemplate>> listJsonTemplates() {
return ResponseEntity.ok(integrationCatalogService.listJsonTemplates());
}
@GetMapping("/json-templates/{id}")
public ResponseEntity<PlatformJsonTemplate> getJsonTemplate(@PathVariable Long id) {
PlatformJsonTemplate t = integrationCatalogService.getJsonTemplate(id);
return t != null ? ResponseEntity.ok(t) : ResponseEntity.notFound().build();
}
@PostMapping("/json-templates")
public ResponseEntity<PlatformJsonTemplate> createJsonTemplate(@RequestBody PlatformJsonTemplate body) {
return ResponseEntity.ok(integrationCatalogService.createJsonTemplate(body));
}
@PutMapping("/json-templates/{id}")
public ResponseEntity<PlatformJsonTemplate> updateJsonTemplate(
@PathVariable Long id, @RequestBody PlatformJsonTemplate body) {
PlatformJsonTemplate result = integrationCatalogService.updateJsonTemplate(id, body);
return result != null ? ResponseEntity.ok(result) : ResponseEntity.notFound().build();
}
@DeleteMapping("/json-templates/{id}")
public ResponseEntity<Void> deleteJsonTemplate(@PathVariable Long id) {
integrationCatalogService.deleteJsonTemplate(id);
return ResponseEntity.ok().build();
}
}
@@ -0,0 +1,109 @@
package cn.craftlabs.platform.api.persistence.integration;
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 java.time.OffsetDateTime;
@TableName("platform_json_template")
public class PlatformJsonTemplate {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private Integer version;
@TableField("template_content")
private String templateContent;
@TableField("schema_version")
private Integer schemaVersion;
@TableField("change_notes")
private String changeNotes;
@TableField("created_by")
private String createdBy;
@TableField("created_at")
private OffsetDateTime createdAt;
@TableField("updated_at")
private OffsetDateTime updatedAt;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String getTemplateContent() {
return templateContent;
}
public void setTemplateContent(String templateContent) {
this.templateContent = templateContent;
}
public Integer getSchemaVersion() {
return schemaVersion;
}
public void setSchemaVersion(Integer schemaVersion) {
this.schemaVersion = schemaVersion;
}
public String getChangeNotes() {
return changeNotes;
}
public void setChangeNotes(String changeNotes) {
this.changeNotes = changeNotes;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public OffsetDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(OffsetDateTime createdAt) {
this.createdAt = createdAt;
}
public OffsetDateTime getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(OffsetDateTime updatedAt) {
this.updatedAt = updatedAt;
}
}
@@ -0,0 +1,7 @@
package cn.craftlabs.platform.api.persistence.integration;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PlatformJsonTemplateMapper extends BaseMapper<PlatformJsonTemplate> {}
@@ -4,6 +4,8 @@ import cn.craftlabs.platform.api.persistence.integration.PlatformBitanswerIdMapp
import cn.craftlabs.platform.api.persistence.integration.PlatformBitanswerIdMappingMapper;
import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironment;
import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironmentMapper;
import cn.craftlabs.platform.api.persistence.integration.PlatformJsonTemplate;
import cn.craftlabs.platform.api.persistence.integration.PlatformJsonTemplateMapper;
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLine;
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLineMapper;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest;
@@ -27,14 +29,17 @@ public class IntegrationCatalogService {
private final PlatformProductLineMapper productLineMapper;
private final PlatformIntegrationEnvironmentMapper environmentMapper;
private final PlatformBitanswerIdMappingMapper idMappingMapper;
private final PlatformJsonTemplateMapper jsonTemplateMapper;
public IntegrationCatalogService(
PlatformProductLineMapper productLineMapper,
PlatformIntegrationEnvironmentMapper environmentMapper,
PlatformBitanswerIdMappingMapper idMappingMapper) {
PlatformBitanswerIdMappingMapper idMappingMapper,
PlatformJsonTemplateMapper jsonTemplateMapper) {
this.productLineMapper = productLineMapper;
this.environmentMapper = environmentMapper;
this.idMappingMapper = idMappingMapper;
this.jsonTemplateMapper = jsonTemplateMapper;
}
@Transactional(readOnly = true)
@@ -174,6 +179,42 @@ public class IntegrationCatalogService {
idMappingMapper.deleteById(id);
}
@Transactional
public PlatformJsonTemplate createJsonTemplate(PlatformJsonTemplate template) {
template.setVersion(1);
template.setSchemaVersion(1);
template.setCreatedAt(java.time.OffsetDateTime.now());
template.setUpdatedAt(java.time.OffsetDateTime.now());
jsonTemplateMapper.insert(template);
return template;
}
public java.util.List<PlatformJsonTemplate> listJsonTemplates() {
return jsonTemplateMapper.selectList(
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(PlatformJsonTemplate.class)
.orderByDesc(PlatformJsonTemplate::getCreatedAt));
}
public PlatformJsonTemplate getJsonTemplate(Long id) {
return jsonTemplateMapper.selectById(id);
}
@Transactional
public PlatformJsonTemplate updateJsonTemplate(Long id, PlatformJsonTemplate template) {
PlatformJsonTemplate existing = jsonTemplateMapper.selectById(id);
if (existing == null) return null;
template.setId(id);
template.setVersion(existing.getVersion() + 1);
template.setUpdatedAt(java.time.OffsetDateTime.now());
jsonTemplateMapper.updateById(template);
return jsonTemplateMapper.selectById(id);
}
@Transactional
public void deleteJsonTemplate(Long id) {
jsonTemplateMapper.deleteById(id);
}
private ProductLineResponse toProductLine(PlatformProductLine row) {
ProductLineResponse r = new ProductLineResponse();
r.setId(row.getId());
@@ -0,0 +1,12 @@
-- V14__m6_json_template.sql
CREATE TABLE platform_json_template (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(128) NOT NULL,
version INT NOT NULL DEFAULT 1,
template_content TEXT NOT NULL,
schema_version INT NOT NULL DEFAULT 1,
change_notes TEXT,
created_by VARCHAR(256),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);