feat(m1): add customer freeze/unfreeze

This commit is contained in:
2026-05-25 15:03:23 +08:00
parent d3d26ba9b4
commit ca1279162b
4 changed files with 46 additions and 0 deletions
@@ -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) {
@@ -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() {}
}
@@ -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());