[Customer]

- DTO Projection 에러 수정
This commit is contained in:
Hyojin Ahn 2025-11-28 14:22:45 -05:00
parent 332195ce58
commit c8854d8a13
4 changed files with 11 additions and 24 deletions

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.goi.erp"})
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EntityScan(basePackages = {"com.goi.erp.entity"})
@EnableJpaRepositories(basePackages = {"com.goi.erp.repository"})

View File

@ -1,11 +1,13 @@
package com.goi.erp.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDate;
@Data
@NoArgsConstructor
public class CustomerRequestDto {
private String cusNo; // c_accountno
@ -56,7 +58,7 @@ public class CustomerRequestDto {
private String cusComment;
private Integer cusLastPickupMin;
private String loginUser;
private String cusLoginUser;
}

View File

@ -1,12 +1,10 @@
package com.goi.erp.repository;
import com.goi.erp.dto.CustomerResponseDto;
import com.goi.erp.entity.Customer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@ -14,25 +12,10 @@ import java.util.UUID;
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Query("SELECT new com.goi.erp.dto.CustomerResponseDto(" +
"c.cusUuid, c.cusNo, c.cusName, c.cusStatus, c.cusAreaId, " +
"c.cusAddress1, c.cusAddress2, c.cusPostalCode, c.cusCity, c.cusProvince, " +
"c.cusGeoLat, c.cusGeoLon, c.cusEmail, c.cusPhone, c.cusPhoneExt, " +
"c.cusOpenTime, c.cusComment, c.cusContractDate, c.cusContractedBy, c.cusInstallDate, c.cusInstallLocation) " +
"FROM Customer c WHERE c.cusUuid = :uuid")
Optional<CustomerResponseDto> findCustomerDtoByCusUuid(UUID uuid);
@Query("SELECT new com.goi.erp.dto.CustomerResponseDto(" +
"c.cusUuid, c.cusNo, c.cusName, c.cusStatus, c.cusAreaId, " +
"c.cusAddress1, c.cusAddress2, c.cusPostalCode, c.cusCity, c.cusProvince, " +
"c.cusGeoLat, c.cusGeoLon, c.cusEmail, c.cusPhone, c.cusPhoneExt, " +
"c.cusOpenTime, c.cusComment, c.cusContractDate, c.cusContractedBy, c.cusInstallDate, c.cusInstallLocation) " +
"FROM Customer c")
Page<CustomerResponseDto> findAllCustomerDtos(Pageable pageable);
Page<Customer> findAll(Pageable pageable);
Optional<Customer> findByCusUuid(UUID cusUuid);
// from MIS
Optional<Customer> findByCusNo(String cusNo);
boolean existsByCusNo(String cusNo);

View File

@ -83,12 +83,14 @@ public class CustomerService {
public Page<CustomerResponseDto> getAllCustomers(int page, int size) {
Pageable pageable = PageRequest.of(page, size);
return customerRepository.findAllCustomerDtos(pageable); // DTO 바로 조회
Page<Customer> customers = customerRepository.findAll(pageable);
return customers.map(this::mapToDto); // 기존 mapToDto 사용
}
public CustomerResponseDto getCustomerByUuid(UUID uuid) {
return customerRepository.findCustomerDtoByCusUuid(uuid)
Customer customer = customerRepository.findByCusUuid(uuid)
.orElseThrow(() -> new RuntimeException("Customer not found"));
return mapToDto(customer);
}
public CustomerResponseDto updateCustomer(UUID uuid, CustomerRequestDto dto) {
@ -226,7 +228,7 @@ public class CustomerService {
CustomerResponseDto response = updateCustomerInternal(oldCustomer, newCustomer);
// 4. 변경 비교 (old vs new)
String misLoginUser = newCustomer.getLoginUser(); // todo: 내부 loginId 변경
String misLoginUser = newCustomer.getCusLoginUser(); // todo: 내부 loginId 변경
String loginId = SecurityContextHolder.getContext().getAuthentication().getName(); // 현재는 MIS login user
compareAndLogChanges(beforeUpdate, oldCustomer, misLoginUser, loginId);