mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 01:50:30 +08:00
feat(m1): add customer freeze/unfreeze
This commit is contained in:
+13
@@ -12,6 +12,7 @@ import org.springframework.http.ResponseEntity;
|
||||
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.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
@@ -67,6 +68,18 @@ public class CustomerController {
|
||||
return customerService.update(id, request);
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}/freeze")
|
||||
public ResponseEntity<Void> freeze(@PathVariable Long id) {
|
||||
customerService.toggleFreeze(id, true);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}/unfreeze")
|
||||
public ResponseEntity<Void> unfreeze(@PathVariable Long id) {
|
||||
customerService.toggleFreeze(id, false);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void delete(@PathVariable("id") long id) {
|
||||
|
||||
+1
@@ -4,6 +4,7 @@ public final class CustomerStatus {
|
||||
|
||||
public static final String ACTIVE = "ACTIVE";
|
||||
public static final String INACTIVE = "INACTIVE";
|
||||
public static final String FROZEN = "FROZEN";
|
||||
|
||||
private CustomerStatus() {}
|
||||
}
|
||||
|
||||
+14
@@ -58,6 +58,7 @@ public class CustomerService {
|
||||
c.setAddress(blankToNull(request.getAddress()));
|
||||
c.setBillingInfo(blankToNull(request.getBillingInfo()));
|
||||
c.setCustomerCode(blankToNull(request.getCustomerCode()));
|
||||
c.setOwnerUserId(blankToNull(request.getOwnerUserId()));
|
||||
c.setStatus(resolveStatusForCreate(request.getStatus()));
|
||||
c.setCreatedAt(now);
|
||||
c.setUpdatedAt(now);
|
||||
@@ -96,6 +97,9 @@ public class CustomerService {
|
||||
if (request.getCustomerCode() != null) {
|
||||
c.setCustomerCode(blankToNull(request.getCustomerCode()));
|
||||
}
|
||||
if (request.getOwnerUserId() != null) {
|
||||
c.setOwnerUserId(blankToNull(request.getOwnerUserId()));
|
||||
}
|
||||
if (StringUtils.hasText(request.getStatus())) {
|
||||
c.setStatus(request.getStatus().trim());
|
||||
}
|
||||
@@ -130,6 +134,15 @@ public class CustomerService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void toggleFreeze(Long id, boolean frozen) {
|
||||
PlatformCustomer customer = customerMapper.selectById(id);
|
||||
if (customer == null) throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
customer.setStatus(frozen ? CustomerStatus.FROZEN : CustomerStatus.ACTIVE);
|
||||
customer.setUpdatedAt(OffsetDateTime.now(ZoneOffset.UTC));
|
||||
customerMapper.updateById(customer);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public void requireExists(long id) {
|
||||
if (customerMapper.selectById(id) == null) {
|
||||
@@ -157,6 +170,7 @@ public class CustomerService {
|
||||
r.setAddress(c.getAddress());
|
||||
r.setBillingInfo(c.getBillingInfo());
|
||||
r.setCustomerCode(c.getCustomerCode());
|
||||
r.setOwnerUserId(c.getOwnerUserId());
|
||||
r.setStatus(c.getStatus());
|
||||
r.setCreatedAt(c.getCreatedAt());
|
||||
r.setUpdatedAt(c.getUpdatedAt());
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="goDetail(row.id)">详情</el-button>
|
||||
<el-button type="primary" link v-permission="'customer:rw'" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button v-permission="'customer:freeze'" type="warning" link
|
||||
@click="toggleFreeze(row)">{{ row.status === 'FROZEN' ? '解冻' : '冻结' }}</el-button>
|
||||
<el-button type="danger" link v-permission="'customer:delete'" @click="onDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -78,6 +80,7 @@ import { useRouter } from "vue-router";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { listCustomers, createCustomer, updateCustomer, deleteCustomer } from "../api/platform";
|
||||
import { apiErrorMessage } from "../utils/apiErrorMessage";
|
||||
import axios from "axios";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const router = useRouter();
|
||||
@@ -203,6 +206,21 @@ async function submit() {
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleFreeze(row) {
|
||||
try {
|
||||
if (row.status === 'FROZEN') {
|
||||
await axios.patch(`/api/v1/customers/${row.id}/unfreeze`);
|
||||
ElMessage.success('已解冻');
|
||||
} else {
|
||||
await axios.patch(`/api/v1/customers/${row.id}/freeze`);
|
||||
ElMessage.success('已冻结');
|
||||
}
|
||||
await load();
|
||||
} catch (e) {
|
||||
ElMessage.error(apiErrorMessage(e, '操作失败'));
|
||||
}
|
||||
}
|
||||
|
||||
function onDelete(row) {
|
||||
ElMessageBox.confirm(`确定删除客户「${row.name || row.id}」吗?`, "提示", {
|
||||
type: "warning",
|
||||
|
||||
Reference in New Issue
Block a user