feat(m1): add customer detail aggregation view

This commit is contained in:
2026-05-25 01:28:36 +08:00
parent bfb8f23399
commit b5317d8f58
6 changed files with 109 additions and 7 deletions
@@ -8,6 +8,7 @@ import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import org.springframework.http.HttpStatus;
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;
@@ -20,6 +21,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 客户 API。{@code DELETE /{id}} 为<strong>软删除</strong>:将 {@code status} 置为 {@code INACTIVE}(可重复调用)。
*/
@@ -53,6 +56,11 @@ public class CustomerController {
return customerService.getById(id);
}
@GetMapping("/{id}/summary")
public ResponseEntity<Map<String, Object>> getSummary(@PathVariable Long id) {
return ResponseEntity.ok(customerService.getCustomerSummary(id));
}
@PutMapping("/{id}")
public CustomerResponse update(
@PathVariable("id") long id, @Valid @RequestBody CustomerRequest request) {
@@ -3,6 +3,8 @@ package cn.craftlabs.platform.api.service;
import cn.craftlabs.platform.api.domain.CustomerStatus;
import cn.craftlabs.platform.api.persistence.customer.PlatformCustomer;
import cn.craftlabs.platform.api.persistence.customer.PlatformCustomerMapper;
import cn.craftlabs.platform.api.persistence.project.PlatformProject;
import cn.craftlabs.platform.api.persistence.project.PlatformProjectMapper;
import cn.craftlabs.platform.api.web.dto.CustomerRequest;
import cn.craftlabs.platform.api.web.dto.CustomerResponse;
import cn.craftlabs.platform.api.web.dto.PageResponse;
@@ -18,15 +20,18 @@ import org.springframework.web.server.ResponseStatusException;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class CustomerService {
private final PlatformCustomerMapper customerMapper;
private final PlatformProjectMapper projectMapper;
public CustomerService(PlatformCustomerMapper customerMapper) {
public CustomerService(PlatformCustomerMapper customerMapper, PlatformProjectMapper projectMapper) {
this.customerMapper = customerMapper;
this.projectMapper = projectMapper;
}
@Transactional(readOnly = true)
@@ -113,6 +118,18 @@ public class CustomerService {
customerMapper.updateById(c);
}
@Transactional(readOnly = true)
public Map<String, Object> getCustomerSummary(Long customerId) {
Map<String, Object> result = new java.util.LinkedHashMap<>();
var projectQuery = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<PlatformProject>();
projectQuery.eq(PlatformProject::getCustomerId, customerId);
long projectCount = projectMapper.selectCount(projectQuery);
result.put("projectCount", projectCount);
result.put("contractCount", 0);
result.put("snCount", 0);
return result;
}
@Transactional(readOnly = true)
public void requireExists(long id) {
if (customerMapper.selectById(id) == null) {