feat(m6): add CRUD dialogs for environments and product lines

This commit is contained in:
2026-05-25 01:15:56 +08:00
parent ea233dd039
commit d0783aa893
7 changed files with 506 additions and 8 deletions
@@ -1,14 +1,21 @@
package cn.craftlabs.platform.api.integration;
import cn.craftlabs.platform.api.service.IntegrationCatalogService;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse;
import cn.craftlabs.platform.api.web.dto.PageResponse;
import cn.craftlabs.platform.api.web.dto.ProductLineRequest;
import cn.craftlabs.platform.api.web.dto.ProductLineResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -49,4 +56,36 @@ public class IntegrationCatalogController {
public IntegrationEnvironmentResponse getEnvironment(@PathVariable("id") long id) {
return integrationCatalogService.getEnvironment(id);
}
@PostMapping("/environments")
public IntegrationEnvironmentResponse createEnvironment(@Valid @RequestBody IntegrationEnvironmentRequest body) {
return integrationCatalogService.createEnvironment(body);
}
@PutMapping("/environments/{id}")
public IntegrationEnvironmentResponse updateEnvironment(
@PathVariable("id") long id, @Valid @RequestBody IntegrationEnvironmentRequest body) {
return integrationCatalogService.updateEnvironment(id, body);
}
@DeleteMapping("/environments/{id}")
public void deleteEnvironment(@PathVariable("id") long id) {
integrationCatalogService.deleteEnvironment(id);
}
@PostMapping("/product-lines")
public ProductLineResponse createProductLine(@Valid @RequestBody ProductLineRequest body) {
return integrationCatalogService.createProductLine(body);
}
@PutMapping("/product-lines/{id}")
public ProductLineResponse updateProductLine(
@PathVariable("id") long id, @Valid @RequestBody ProductLineRequest body) {
return integrationCatalogService.updateProductLine(id, body);
}
@DeleteMapping("/product-lines/{id}")
public void deleteProductLine(@PathVariable("id") long id) {
integrationCatalogService.deleteProductLine(id);
}
}
@@ -4,8 +4,10 @@ import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvi
import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironmentMapper;
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLine;
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLineMapper;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse;
import cn.craftlabs.platform.api.web.dto.PageResponse;
import cn.craftlabs.platform.api.web.dto.ProductLineRequest;
import cn.craftlabs.platform.api.web.dto.ProductLineResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -70,6 +72,72 @@ public class IntegrationCatalogService {
return toEnvironment(row);
}
@Transactional
public ProductLineResponse createProductLine(ProductLineRequest req) {
PlatformProductLine row = new PlatformProductLine();
row.setCode(req.getCode());
row.setName(req.getName());
row.setDescription(req.getDescription());
row.setEnabled(req.getEnabled() != null ? req.getEnabled() : Boolean.TRUE);
productLineMapper.insert(row);
return toProductLine(row);
}
@Transactional
public ProductLineResponse updateProductLine(long id, ProductLineRequest req) {
PlatformProductLine row = productLineMapper.selectById(id);
if (row == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "product line not found");
}
row.setCode(req.getCode());
row.setName(req.getName());
row.setDescription(req.getDescription());
row.setEnabled(req.getEnabled() != null ? req.getEnabled() : Boolean.TRUE);
productLineMapper.updateById(row);
return toProductLine(row);
}
@Transactional
public void deleteProductLine(long id) {
if (productLineMapper.selectById(id) == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "product line not found");
}
productLineMapper.deleteById(id);
}
@Transactional
public IntegrationEnvironmentResponse createEnvironment(IntegrationEnvironmentRequest req) {
PlatformIntegrationEnvironment row = new PlatformIntegrationEnvironment();
row.setCode(req.getCode());
row.setName(req.getName());
row.setBitanswerBaseUrl(req.getBitanswerBaseUrl());
row.setKind(req.getKind());
environmentMapper.insert(row);
return toEnvironment(row);
}
@Transactional
public IntegrationEnvironmentResponse updateEnvironment(long id, IntegrationEnvironmentRequest req) {
PlatformIntegrationEnvironment row = environmentMapper.selectById(id);
if (row == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "integration environment not found");
}
row.setCode(req.getCode());
row.setName(req.getName());
row.setBitanswerBaseUrl(req.getBitanswerBaseUrl());
row.setKind(req.getKind());
environmentMapper.updateById(row);
return toEnvironment(row);
}
@Transactional
public void deleteEnvironment(long id) {
if (environmentMapper.selectById(id) == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "integration environment not found");
}
environmentMapper.deleteById(id);
}
private ProductLineResponse toProductLine(PlatformProductLine row) {
ProductLineResponse r = new ProductLineResponse();
r.setId(row.getId());
@@ -0,0 +1,54 @@
package cn.craftlabs.platform.api.web.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
public class IntegrationEnvironmentRequest {
@NotBlank
@Size(max = 64)
private String code;
@NotBlank
@Size(max = 256)
private String name;
@Size(max = 512)
private String bitanswerBaseUrl;
@NotBlank
@Size(max = 16)
private String kind;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBitanswerBaseUrl() {
return bitanswerBaseUrl;
}
public void setBitanswerBaseUrl(String bitanswerBaseUrl) {
this.bitanswerBaseUrl = bitanswerBaseUrl;
}
public String getKind() {
return kind;
}
public void setKind(String kind) {
this.kind = kind;
}
}
@@ -0,0 +1,52 @@
package cn.craftlabs.platform.api.web.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
public class ProductLineRequest {
@NotBlank
@Size(max = 64)
private String code;
@NotBlank
@Size(max = 256)
private String name;
@Size(max = 1024)
private String description;
private Boolean enabled;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
}
@@ -274,6 +274,18 @@ export function getIntegrationEnvironment(id) {
return axios.get(`/api/v1/integration/environments/${id}`);
}
export function createIntegrationEnvironment(body) {
return axios.post("/api/v1/integration/environments", body);
}
export function updateIntegrationEnvironment(id, body) {
return axios.put(`/api/v1/integration/environments/${id}`, body);
}
export function deleteIntegrationEnvironment(id) {
return axios.delete(`/api/v1/integration/environments/${id}`);
}
/**
* @param {{ page?: number, size?: number }} params
*/
@@ -288,6 +300,18 @@ export function getProductLine(id) {
return axios.get(`/api/v1/integration/product-lines/${id}`);
}
export function createProductLine(body) {
return axios.post("/api/v1/integration/product-lines", body);
}
export function updateProductLine(id, body) {
return axios.put(`/api/v1/integration/product-lines/${id}`, body);
}
export function deleteProductLine(id) {
return axios.delete(`/api/v1/integration/product-lines/${id}`);
}
// —— M7 设备管理 ————————————————————————————
export function listDevices(params) {
return axios.get('/api/v1/devices', { params });
@@ -3,7 +3,10 @@
<template #header>
<div class="toolbar">
<span class="title">集成环境</span>
<div class="actions">
<el-button type="primary" :loading="loading" @click="load">刷新</el-button>
<el-button type="success" @click="openCreate">新建环境</el-button>
</div>
</div>
</template>
@@ -17,6 +20,12 @@
<el-table-column label="产品线 ID" width="120">
<template #default="{ row }">{{ row.productLineId ?? row.product_line_id ?? "—" }}</template>
</el-table-column>
<el-table-column label="操作" width="160" fixed="right">
<template #default="{ row }">
<el-button type="primary" link @click="openEdit(row)">编辑</el-button>
<el-button type="danger" link @click="onDelete(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="pager">
@@ -31,23 +40,68 @@
@size-change="onSizeChange"
/>
</div>
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="520px" destroy-on-close @closed="resetForm">
<el-form ref="formRef" :model="form" :rules="rules" label-width="140px">
<el-form-item label="编码" prop="code">
<el-input v-model="form.code" maxlength="64" show-word-limit placeholder="请输入环境编码" />
</el-form-item>
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" maxlength="256" show-word-limit placeholder="请输入环境名称" />
</el-form-item>
<el-form-item label="比特 URL" prop="bitanswerBaseUrl">
<el-input v-model="form.bitanswerBaseUrl" maxlength="512" clearable placeholder="选填" />
</el-form-item>
<el-form-item label="类型" prop="kind">
<el-select v-model="form.kind" placeholder="请选择" style="width: 100%">
<el-option label="DEV" value="DEV" />
<el-option label="TEST" value="TEST" />
<el-option label="PROD" value="PROD" />
</el-select>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
</el-card>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { ElMessage } from "element-plus";
import { ref, reactive, computed, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useAuthStore } from "../stores/auth";
import { listIntegrationEnvironments } from "../api/platform";
import { listIntegrationEnvironments, createIntegrationEnvironment, updateIntegrationEnvironment, deleteIntegrationEnvironment } from "../api/platform";
import { apiErrorMessage } from "../utils/apiErrorMessage";
const auth = useAuthStore();
const loading = ref(false);
const saving = ref(false);
const rows = ref([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(20);
const dialogVisible = ref(false);
const editingId = ref(null);
const formRef = ref(null);
const form = reactive({
code: "",
name: "",
bitanswerBaseUrl: "",
kind: "",
});
const rules = {
code: [{ required: true, message: "请输入环境编码", trigger: "blur" }],
name: [{ required: true, message: "请输入环境名称", trigger: "blur" }],
kind: [{ required: true, message: "请选择类型", trigger: "change" }],
};
const dialogTitle = computed(() => (editingId.value ? "编辑环境" : "新建环境"));
onMounted(async () => {
auth.restoreAxiosAuth();
await load();
@@ -76,6 +130,79 @@ async function load() {
loading.value = false;
}
}
function openCreate() {
editingId.value = null;
resetForm();
dialogVisible.value = true;
}
function openEdit(row) {
editingId.value = row.id;
form.code = row.code ?? "";
form.name = row.name ?? "";
form.bitanswerBaseUrl = row.bitanswerBaseUrl ?? row.bitanswer_base_url ?? "";
form.kind = row.kind ?? "";
dialogVisible.value = true;
}
function resetForm() {
form.code = "";
form.name = "";
form.bitanswerBaseUrl = "";
form.kind = "";
formRef.value?.resetFields?.();
}
async function submit() {
const f = formRef.value;
if (!f) return;
try {
await f.validate();
} catch {
return;
}
saving.value = true;
const payload = {
code: form.code.trim(),
name: form.name.trim(),
bitanswerBaseUrl: form.bitanswerBaseUrl?.trim() || undefined,
kind: form.kind,
};
try {
if (editingId.value != null) {
await updateIntegrationEnvironment(editingId.value, payload);
ElMessage.success("已保存");
} else {
await createIntegrationEnvironment(payload);
ElMessage.success("已创建");
}
dialogVisible.value = false;
await load();
} catch (e) {
ElMessage.error(apiErrorMessage(e, "保存失败"));
} finally {
saving.value = false;
}
}
function onDelete(row) {
ElMessageBox.confirm(`确定删除环境「${row.name || row.code || row.id}」吗?`, "提示", {
type: "warning",
confirmButtonText: "删除",
cancelButtonText: "取消",
})
.then(async () => {
try {
await deleteIntegrationEnvironment(row.id);
ElMessage.success("已删除");
await load();
} catch (e) {
ElMessage.error(apiErrorMessage(e, "删除失败"));
}
})
.catch(() => {});
}
</script>
<style scoped>
@@ -90,6 +217,12 @@ async function load() {
font-weight: 600;
font-size: 16px;
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.pager {
margin-top: 16px;
display: flex;
@@ -3,7 +3,10 @@
<template #header>
<div class="toolbar">
<span class="title">产品线</span>
<div class="actions">
<el-button type="primary" :loading="loading" @click="load">刷新</el-button>
<el-button type="success" @click="openCreate">新建产品线</el-button>
</div>
</div>
</template>
@@ -19,6 +22,12 @@
<el-tag v-else type="success" size="small"></el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="160" fixed="right">
<template #default="{ row }">
<el-button type="primary" link @click="openEdit(row)">编辑</el-button>
<el-button type="danger" link @click="onDelete(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="pager">
@@ -33,23 +42,63 @@
@size-change="onSizeChange"
/>
</div>
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="520px" destroy-on-close @closed="resetForm">
<el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
<el-form-item label="编码" prop="code">
<el-input v-model="form.code" maxlength="64" show-word-limit placeholder="请输入产品线编码" />
</el-form-item>
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" maxlength="256" show-word-limit placeholder="请输入产品线名称" />
</el-form-item>
<el-form-item label="描述" prop="description">
<el-input v-model="form.description" maxlength="1024" type="textarea" :rows="3" clearable placeholder="选填" />
</el-form-item>
<el-form-item label="启用" prop="enabled">
<el-switch v-model="form.enabled" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
</el-card>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { ElMessage } from "element-plus";
import { ref, reactive, computed, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useAuthStore } from "../stores/auth";
import { listProductLines } from "../api/platform";
import { listProductLines, createProductLine, updateProductLine, deleteProductLine } from "../api/platform";
import { apiErrorMessage } from "../utils/apiErrorMessage";
const auth = useAuthStore();
const loading = ref(false);
const saving = ref(false);
const rows = ref([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(20);
const dialogVisible = ref(false);
const editingId = ref(null);
const formRef = ref(null);
const form = reactive({
code: "",
name: "",
description: "",
enabled: true,
});
const rules = {
code: [{ required: true, message: "请输入产品线编码", trigger: "blur" }],
name: [{ required: true, message: "请输入产品线名称", trigger: "blur" }],
};
const dialogTitle = computed(() => (editingId.value ? "编辑产品线" : "新建产品线"));
onMounted(async () => {
auth.restoreAxiosAuth();
await load();
@@ -78,6 +127,79 @@ async function load() {
loading.value = false;
}
}
function openCreate() {
editingId.value = null;
resetForm();
dialogVisible.value = true;
}
function openEdit(row) {
editingId.value = row.id;
form.code = row.code ?? "";
form.name = row.name ?? "";
form.description = row.description ?? "";
form.enabled = row.enabled !== false;
dialogVisible.value = true;
}
function resetForm() {
form.code = "";
form.name = "";
form.description = "";
form.enabled = true;
formRef.value?.resetFields?.();
}
async function submit() {
const f = formRef.value;
if (!f) return;
try {
await f.validate();
} catch {
return;
}
saving.value = true;
const payload = {
code: form.code.trim(),
name: form.name.trim(),
description: form.description?.trim() || undefined,
enabled: form.enabled,
};
try {
if (editingId.value != null) {
await updateProductLine(editingId.value, payload);
ElMessage.success("已保存");
} else {
await createProductLine(payload);
ElMessage.success("已创建");
}
dialogVisible.value = false;
await load();
} catch (e) {
ElMessage.error(apiErrorMessage(e, "保存失败"));
} finally {
saving.value = false;
}
}
function onDelete(row) {
ElMessageBox.confirm(`确定删除产品线「${row.name || row.code || row.id}」吗?`, "提示", {
type: "warning",
confirmButtonText: "删除",
cancelButtonText: "取消",
})
.then(async () => {
try {
await deleteProductLine(row.id);
ElMessage.success("已删除");
await load();
} catch (e) {
ElMessage.error(apiErrorMessage(e, "删除失败"));
}
})
.catch(() => {});
}
</script>
<style scoped>
@@ -92,6 +214,12 @@ async function load() {
font-weight: 600;
font-size: 16px;
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.pager {
margin-top: 16px;
display: flex;