CS 홈 화면 추가
This commit is contained in:
parent
e7faffa262
commit
7377f7b663
|
|
@ -5,6 +5,7 @@ import com.goi.erp.common.permission.PermissionSet;
|
||||||
import com.goi.erp.dto.CustomerDailyOrderResponseDto;
|
import com.goi.erp.dto.CustomerDailyOrderResponseDto;
|
||||||
import com.goi.erp.dto.CustomerRequestDto;
|
import com.goi.erp.dto.CustomerRequestDto;
|
||||||
import com.goi.erp.dto.CustomerResponseDto;
|
import com.goi.erp.dto.CustomerResponseDto;
|
||||||
|
import com.goi.erp.dto.CustomerSummaryResponseDto;
|
||||||
import com.goi.erp.service.CustomerDailyOrderService;
|
import com.goi.erp.service.CustomerDailyOrderService;
|
||||||
import com.goi.erp.service.CustomerService;
|
import com.goi.erp.service.CustomerService;
|
||||||
import com.goi.erp.token.PermissionAuthenticationToken;
|
import com.goi.erp.token.PermissionAuthenticationToken;
|
||||||
|
|
@ -85,6 +86,24 @@ public class CustomerController {
|
||||||
return ResponseEntity.ok(customerService.getAllCustomers(p, s));
|
return ResponseEntity.ok(customerService.getAllCustomers(p, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SUMMARY (CS 홈: 전체 고객 수 + 오늘 추가된 고객 수)
|
||||||
|
@GetMapping("/summary")
|
||||||
|
public ResponseEntity<CustomerSummaryResponseDto> getCustomerSummary() {
|
||||||
|
// 권한 체크
|
||||||
|
PermissionAuthenticationToken auth = (PermissionAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
|
if (auth == null || auth.getPermissionSet() == null) {
|
||||||
|
throw new AccessDeniedException("Permission information is missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
PermissionSet permissionSet = auth.getPermissionSet();
|
||||||
|
if (!PermissionChecker.canReadCRMAll(permissionSet)) {
|
||||||
|
throw new AccessDeniedException("You do not have permission to read all CRM data");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok(customerService.getCustomerSummary());
|
||||||
|
}
|
||||||
|
|
||||||
// READ ONE
|
// READ ONE
|
||||||
@GetMapping("/uuid/{uuid}")
|
@GetMapping("/uuid/{uuid}")
|
||||||
public ResponseEntity<CustomerResponseDto> getCustomer(@PathVariable UUID uuid) {
|
public ResponseEntity<CustomerResponseDto> getCustomer(@PathVariable UUID uuid) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.goi.erp.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CustomerSummaryResponseDto {
|
||||||
|
|
||||||
|
// 전체 고객 수
|
||||||
|
private long totalCount;
|
||||||
|
|
||||||
|
// 오늘 추가된 고객 수 (cus_created_at 기준)
|
||||||
|
private long todayCount;
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -19,4 +20,10 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
|
||||||
Optional<Customer> findByCusNo(String cusNo);
|
Optional<Customer> findByCusNo(String cusNo);
|
||||||
|
|
||||||
boolean existsByCusNo(String cusNo);
|
boolean existsByCusNo(String cusNo);
|
||||||
|
|
||||||
|
// 현재(활성) 고객 수: cus_status = 'A'
|
||||||
|
long countByCusStatus(String cusStatus);
|
||||||
|
|
||||||
|
// 오늘 추가된 고객 수: cus_contract_date = 오늘
|
||||||
|
long countByCusContractDate(LocalDate cusContractDate);
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package com.goi.erp.service;
|
||||||
|
|
||||||
import com.goi.erp.dto.CustomerRequestDto;
|
import com.goi.erp.dto.CustomerRequestDto;
|
||||||
import com.goi.erp.dto.CustomerResponseDto;
|
import com.goi.erp.dto.CustomerResponseDto;
|
||||||
|
import com.goi.erp.dto.CustomerSummaryResponseDto;
|
||||||
import com.goi.erp.entity.Customer;
|
import com.goi.erp.entity.Customer;
|
||||||
import com.goi.erp.entity.EntityChangeLog;
|
import com.goi.erp.entity.EntityChangeLog;
|
||||||
import com.goi.erp.repository.CustomerRepository;
|
import com.goi.erp.repository.CustomerRepository;
|
||||||
|
|
@ -87,6 +88,20 @@ public class CustomerService {
|
||||||
return customers.map(this::mapToDto); // 기존 mapToDto 사용
|
return customers.map(this::mapToDto); // 기존 mapToDto 사용
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CS 홈 요약: 현재(활성) 고객 수 + 오늘 추가된 고객 수
|
||||||
|
public CustomerSummaryResponseDto getCustomerSummary() {
|
||||||
|
// 현재 고객 = cus_status 'A'
|
||||||
|
long total = customerRepository.countByCusStatus("A");
|
||||||
|
|
||||||
|
// 오늘 추가 = cus_contract_date 가 오늘 (서버 로컬 타임존 기준)
|
||||||
|
long todayCount = customerRepository.countByCusContractDate(LocalDate.now());
|
||||||
|
|
||||||
|
return CustomerSummaryResponseDto.builder()
|
||||||
|
.totalCount(total)
|
||||||
|
.todayCount(todayCount)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
public CustomerResponseDto getCustomerByUuid(UUID uuid) {
|
public CustomerResponseDto getCustomerByUuid(UUID uuid) {
|
||||||
Customer customer = customerRepository.findByCusUuid(uuid)
|
Customer customer = customerRepository.findByCusUuid(uuid)
|
||||||
.orElseThrow(() -> new RuntimeException("Customer not found"));
|
.orElseThrow(() -> new RuntimeException("Customer not found"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue