diff --git a/.gitignore b/.gitignore index 549e00a..c12e8ef 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ build/ ### VS Code ### .vscode/ +/http/ +/logs/ +/jwt-security.drawio diff --git a/http/change-password.http b/http/change-password.http deleted file mode 100644 index 66f47d2..0000000 --- a/http/change-password.http +++ /dev/null @@ -1,45 +0,0 @@ -### Register User -POST http://localhost:8080/api/v1/auth/register -Content-Type: application/json - -{ - "firstname": "Ali", - "lastname": "Bouali", - "email": "alibou@mail.com", - "password": "password", - "role": "ADMIN" -} - -> {% client.global.set("auth-token", response.body.access_token); %} - -### Query the Demo endpoint -GET http://localhost:8080/api/v1/demo-controller -Authorization: Bearer {{auth-token}} - - -### Change the password -PATCH http://localhost:8080/api/v1/users -Content-Type: application/json -Authorization: Bearer {{auth-token}} - -{ - "currentPassword": "password", - "newPassword": "newPassword", - "confirmationPassword": "newPassword" -} - -### Login again and update the token -POST http://localhost:8080/api/v1/auth/authenticate -Content-Type: application/json - -{ - "email": "alibou@mail.com", - "password": "newPassword" -} - -> {% client.global.set("new-auth-token", response.body.access_token); %} - - -### Query the Demo endpoint after password change -GET http://localhost:8080/api/v1/demo-controller -Authorization: Bearer {{new-auth-token}} diff --git a/http/http-test.http b/http/http-test.http deleted file mode 100644 index 918cb2e..0000000 --- a/http/http-test.http +++ /dev/null @@ -1,17 +0,0 @@ -### Register User -POST http://localhost:8080/api/v1/auth/register -Content-Type: application/json - -{ - "firstname": "Ali", - "lastname": "Bouali", - "email": "alibou21@mail.com", - "password": "password", - "role": "ADMIN" -} - -> {% client.global.set("auth-token", response.body.access_token); %} - -### Query the Demo endpoint -GET http://localhost:8080/api/v1/demo-controller -Authorization: Bearer {{auth-token}} diff --git a/http/jpa-auditing.http b/http/jpa-auditing.http deleted file mode 100644 index a8245bb..0000000 --- a/http/jpa-auditing.http +++ /dev/null @@ -1,44 +0,0 @@ -### Register User -POST http://localhost:8080/api/v1/auth/register -Content-Type: application/json - -{ - "firstname": "Ali", - "lastname": "Bouali", - "email": "alibou@mail.com", - "password": "password", - "role": "ADMIN" -} - -> {% client.global.set("auth-token", response.body.access_token); %} - - -###Create a new book -POST http://localhost:8080/api/v1/books -Authorization: Bearer {{auth-token}} -Content-Type: application/json - -{ - "author": "Alibou", - "isbn": "12345" -} - -### Query Books -GET http://localhost:8080/api/v1/books -Authorization: Bearer {{auth-token}} - -### Update one book -POST http://localhost:8080/api/v1/books -Authorization: Bearer {{auth-token}} -Content-Type: application/json - -{ - "id": 1, - "author": "Alibou 2", - "isbn": "12345" -} - - -### Query the Books one more time -GET http://localhost:8080/api/v1/books -Authorization: Bearer {{auth-token}} diff --git a/jwt-security.drawio b/jwt-security.drawio deleted file mode 100644 index 75c044a..0000000 --- a/jwt-security.drawio +++ /dev/null @@ -1,517 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/logs/integration-service.log b/logs/integration-service.log deleted file mode 100644 index 02a4341..0000000 --- a/logs/integration-service.log +++ /dev/null @@ -1,25 +0,0 @@ -2026-05-20T08:25:45.241-04:00 INFO 5596 --- [main] com.goi.erp.SecurityApplication : Starting SecurityApplication using Java 17.0.16 with PID 5596 (D:\workspace-eclipse\crm-rest-api\target\classes started by Hyojin Ahn in D:\workspace-eclipse\crm-rest-api) -2026-05-20T08:25:45.246-04:00 INFO 5596 --- [main] com.goi.erp.SecurityApplication : The following 1 profile is active: "default" -2026-05-20T08:25:45.694-04:00 INFO 5596 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. -2026-05-20T08:25:45.786-04:00 INFO 5596 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 87 ms. Found 3 JPA repository interfaces. -2026-05-20T08:25:46.383-04:00 INFO 5596 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http) -2026-05-20T08:25:46.389-04:00 INFO 5596 --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat] -2026-05-20T08:25:46.389-04:00 INFO 5596 --- [main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.13] -2026-05-20T08:25:46.457-04:00 INFO 5596 --- [main] o.a.c.c.C.[.[localhost].[/crm-rest-api] : Initializing Spring embedded WebApplicationContext -2026-05-20T08:25:46.457-04:00 INFO 5596 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1173 ms -2026-05-20T08:25:46.602-04:00 INFO 5596 --- [main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] -2026-05-20T08:25:46.632-04:00 INFO 5596 --- [main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.2.9.Final -2026-05-20T08:25:46.635-04:00 INFO 5596 --- [main] org.hibernate.cfg.Environment : HHH000406: Using bytecode reflection optimizer -2026-05-20T08:25:46.716-04:00 INFO 5596 --- [main] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy -2026-05-20T08:25:46.783-04:00 INFO 5596 --- [main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer -2026-05-20T08:25:46.793-04:00 INFO 5596 --- [main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... -2026-05-20T08:25:46.891-04:00 INFO 5596 --- [main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@674e4c82 -2026-05-20T08:25:46.892-04:00 INFO 5596 --- [main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. -2026-05-20T08:25:47.044-04:00 INFO 5596 --- [main] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy -2026-05-20T08:25:47.499-04:00 INFO 5596 --- [main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] -2026-05-20T08:25:47.549-04:00 INFO 5596 --- [main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' -2026-05-20T08:25:47.931-04:00 WARN 5596 --- [main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning -2026-05-20T08:25:48.177-04:00 INFO 5596 --- [main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator' -2026-05-20T08:25:48.210-04:00 INFO 5596 --- [main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@466fd19b, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@348d1a5e, org.springframework.security.web.context.SecurityContextHolderFilter@3fc92211, org.springframework.security.web.header.HeaderWriterFilter@227ae4e4, org.springframework.security.web.authentication.logout.LogoutFilter@3ae5cbb9, org.springframework.web.filter.CorsFilter@7f746160, com.goi.erp.config.JwtAuthenticationFilter@16ea0f22, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@117bfeb8, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@31aec04a, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@17524c36, org.springframework.security.web.session.SessionManagementFilter@440309c5, org.springframework.security.web.access.ExceptionTranslationFilter@1b2213b2, org.springframework.security.web.access.intercept.AuthorizationFilter@24e0bdb] -2026-05-20T08:25:48.496-04:00 INFO 5596 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8082 (http) with context path '/crm-rest-api' -2026-05-20T08:25:48.505-04:00 INFO 5596 --- [main] com.goi.erp.SecurityApplication : Started SecurityApplication in 3.548 seconds (process running for 3.992) diff --git a/logs/integration-service.log.2026-03-19.0.gz b/logs/integration-service.log.2026-03-19.0.gz deleted file mode 100644 index 7e30c44..0000000 Binary files a/logs/integration-service.log.2026-03-19.0.gz and /dev/null differ diff --git a/logs/integration-service.log.2026-03-30.0.gz b/logs/integration-service.log.2026-03-30.0.gz deleted file mode 100644 index 0364b6b..0000000 Binary files a/logs/integration-service.log.2026-03-30.0.gz and /dev/null differ diff --git a/src/main/java/com/goi/erp/config/JwtAuthenticationFilter.java b/src/main/java/com/goi/erp/config/JwtAuthenticationFilter.java index a204963..1d12892 100644 --- a/src/main/java/com/goi/erp/config/JwtAuthenticationFilter.java +++ b/src/main/java/com/goi/erp/config/JwtAuthenticationFilter.java @@ -13,6 +13,7 @@ import org.springframework.web.filter.OncePerRequestFilter; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; +import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; @@ -32,13 +33,22 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { @NonNull FilterChain filterChain ) throws ServletException, IOException { - final String authHeader = request.getHeader("Authorization"); - if (authHeader == null || !authHeader.startsWith("Bearer ")) { - filterChain.doFilter(request, response); - return; - } + String jwt = null; - final String jwt = authHeader.substring(7); + if (request.getCookies() != null) { + for (Cookie cookie : request.getCookies()) { + + if ("AUTH_TOKEN".equals(cookie.getName())) { + jwt = cookie.getValue(); + break; + } + } + } + + if (jwt == null || jwt.isBlank()) { + filterChain.doFilter(request, response); + return; + } try { // 기존 인증 정보 확인 diff --git a/src/main/java/com/goi/erp/controller/CustomerContainerController.java b/src/main/java/com/goi/erp/controller/CustomerContainerController.java new file mode 100644 index 0000000..889f0f6 --- /dev/null +++ b/src/main/java/com/goi/erp/controller/CustomerContainerController.java @@ -0,0 +1,93 @@ +package com.goi.erp.controller; + +import com.goi.erp.common.permission.PermissionChecker; +import com.goi.erp.common.permission.PermissionSet; +import com.goi.erp.dto.CustomerContainerRequestDto; +import com.goi.erp.dto.CustomerContainerResponseDto; +import com.goi.erp.service.CustomerContainerService; +import com.goi.erp.token.PermissionAuthenticationToken; + +import lombok.RequiredArgsConstructor; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.context.SecurityContextHolder; + +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/customer-container") +@RequiredArgsConstructor +public class CustomerContainerController { + + private final CustomerContainerService service; + + private PermissionSet getPermission() { + + PermissionAuthenticationToken auth = + (PermissionAuthenticationToken) + SecurityContextHolder.getContext().getAuthentication(); + + if (auth == null || auth.getPermissionSet() == null) { + throw new AccessDeniedException("Permission missing"); + } + + return auth.getPermissionSet(); + } + + @PostMapping + public ResponseEntity create( + @RequestBody CustomerContainerRequestDto dto + ) { + + if (!PermissionChecker.canCreateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return new ResponseEntity<>( + service.create(dto), + HttpStatus.CREATED + ); + } + + @GetMapping("/customer/{customerId}") + public ResponseEntity> getByCustomerId( + @PathVariable Long customerId + ) { + + if (!PermissionChecker.canReadCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.getByCustomerId(customerId)); + } + + @PatchMapping("/{id}") + public ResponseEntity update( + @PathVariable Long id, + @RequestBody CustomerContainerRequestDto dto + ) { + + if (!PermissionChecker.canUpdateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.update(id, dto)); + } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable Long id) { + + if (!PermissionChecker.canDeleteCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + service.delete(id); + + return ResponseEntity.noContent().build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/controller/CustomerDailyInstallContainerController.java b/src/main/java/com/goi/erp/controller/CustomerDailyInstallContainerController.java new file mode 100644 index 0000000..19c30e5 --- /dev/null +++ b/src/main/java/com/goi/erp/controller/CustomerDailyInstallContainerController.java @@ -0,0 +1,96 @@ +package com.goi.erp.controller; + +import com.goi.erp.common.permission.PermissionChecker; +import com.goi.erp.common.permission.PermissionSet; +import com.goi.erp.dto.CustomerDailyInstallContainerRequestDto; +import com.goi.erp.dto.CustomerDailyInstallContainerResponseDto; +import com.goi.erp.service.CustomerDailyInstallContainerService; +import com.goi.erp.token.PermissionAuthenticationToken; + +import lombok.RequiredArgsConstructor; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.context.SecurityContextHolder; + +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/customer-daily-install-container") +@RequiredArgsConstructor +public class CustomerDailyInstallContainerController { + + private final CustomerDailyInstallContainerService service; + + private PermissionSet getPermission() { + + PermissionAuthenticationToken auth = + (PermissionAuthenticationToken) + SecurityContextHolder.getContext().getAuthentication(); + + if (auth == null || auth.getPermissionSet() == null) { + throw new AccessDeniedException("Permission missing"); + } + + return auth.getPermissionSet(); + } + + @PostMapping + public ResponseEntity create( + @RequestBody CustomerDailyInstallContainerRequestDto dto + ) { + + if (!PermissionChecker.canCreateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return new ResponseEntity<>( + service.create(dto), + HttpStatus.CREATED + ); + } + + @GetMapping("/daily-install/{dailyInstallId}") + public ResponseEntity> + getByDailyInstallId( + @PathVariable Long dailyInstallId + ) { + + if (!PermissionChecker.canReadCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok( + service.getByDailyInstallId(dailyInstallId) + ); + } + + @PatchMapping("/{id}") + public ResponseEntity update( + @PathVariable Long id, + @RequestBody CustomerDailyInstallContainerRequestDto dto + ) { + + if (!PermissionChecker.canUpdateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.update(id, dto)); + } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable Long id) { + + if (!PermissionChecker.canDeleteCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + service.delete(id); + + return ResponseEntity.noContent().build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/controller/CustomerDailyInstallController.java b/src/main/java/com/goi/erp/controller/CustomerDailyInstallController.java new file mode 100644 index 0000000..6cff7a9 --- /dev/null +++ b/src/main/java/com/goi/erp/controller/CustomerDailyInstallController.java @@ -0,0 +1,99 @@ +package com.goi.erp.controller; + +import com.goi.erp.common.permission.PermissionChecker; +import com.goi.erp.common.permission.PermissionSet; +import com.goi.erp.dto.CustomerDailyInstallRequestDto; +import com.goi.erp.dto.CustomerDailyInstallResponseDto; +import com.goi.erp.service.CustomerDailyInstallService; +import com.goi.erp.token.PermissionAuthenticationToken; + +import lombok.RequiredArgsConstructor; + +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.context.SecurityContextHolder; + +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDate; +import java.util.List; + +@RestController +@RequestMapping("/customer-daily-install") +@RequiredArgsConstructor +public class CustomerDailyInstallController { + + private final CustomerDailyInstallService service; + + private PermissionSet getPermission() { + + PermissionAuthenticationToken auth = + (PermissionAuthenticationToken) + SecurityContextHolder.getContext().getAuthentication(); + + if (auth == null || auth.getPermissionSet() == null) { + throw new AccessDeniedException("Permission missing"); + } + + return auth.getPermissionSet(); + } + + @PostMapping + public ResponseEntity create( + @RequestBody CustomerDailyInstallRequestDto dto + ) { + + if (!PermissionChecker.canCreateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return new ResponseEntity<>( + service.create(dto), + HttpStatus.CREATED + ); + } + + @GetMapping("/date/{installDate}") + public ResponseEntity> getByInstallDate( + @PathVariable + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) + LocalDate installDate + ) { + + if (!PermissionChecker.canReadCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok( + service.getByInstallDate(installDate) + ); + } + + @PatchMapping("/{id}") + public ResponseEntity update( + @PathVariable Long id, + @RequestBody CustomerDailyInstallRequestDto dto + ) { + + if (!PermissionChecker.canUpdateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.update(id, dto)); + } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable Long id) { + + if (!PermissionChecker.canDeleteCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + service.delete(id); + + return ResponseEntity.noContent().build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/controller/CustomerRegionController.java b/src/main/java/com/goi/erp/controller/CustomerRegionController.java new file mode 100644 index 0000000..cd77c02 --- /dev/null +++ b/src/main/java/com/goi/erp/controller/CustomerRegionController.java @@ -0,0 +1,103 @@ +package com.goi.erp.controller; + +import com.goi.erp.common.permission.PermissionChecker; +import com.goi.erp.common.permission.PermissionSet; +import com.goi.erp.dto.CustomerRegionRequestDto; +import com.goi.erp.dto.CustomerRegionResponseDto; +import com.goi.erp.service.CustomerRegionService; +import com.goi.erp.token.PermissionAuthenticationToken; + +import lombok.RequiredArgsConstructor; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.context.SecurityContextHolder; + +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/customer-region") +@RequiredArgsConstructor +public class CustomerRegionController { + + private final CustomerRegionService service; + + private PermissionSet getPermission() { + + PermissionAuthenticationToken auth = + (PermissionAuthenticationToken) + SecurityContextHolder.getContext().getAuthentication(); + + if (auth == null || auth.getPermissionSet() == null) { + throw new AccessDeniedException("Permission information is missing"); + } + + return auth.getPermissionSet(); + } + + @PostMapping + public ResponseEntity create( + @RequestBody CustomerRegionRequestDto dto + ) { + + if (!PermissionChecker.canCreateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return new ResponseEntity<>( + service.create(dto), + HttpStatus.CREATED + ); + } + + @GetMapping + public ResponseEntity> getAll() { + + if (!PermissionChecker.canReadCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.getAll()); + } + + @GetMapping("/{id}") + public ResponseEntity getById( + @PathVariable Long id + ) { + + if (!PermissionChecker.canReadCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.getById(id)); + } + + @PatchMapping("/{id}") + public ResponseEntity update( + @PathVariable Long id, + @RequestBody CustomerRegionRequestDto dto + ) { + + if (!PermissionChecker.canUpdateCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + return ResponseEntity.ok(service.update(id, dto)); + } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable Long id) { + + if (!PermissionChecker.canDeleteCRM(getPermission())) { + throw new AccessDeniedException("No permission"); + } + + service.delete(id); + + return ResponseEntity.noContent().build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerContainerRequestDto.java b/src/main/java/com/goi/erp/dto/CustomerContainerRequestDto.java new file mode 100644 index 0000000..bbd13fa --- /dev/null +++ b/src/main/java/com/goi/erp/dto/CustomerContainerRequestDto.java @@ -0,0 +1,42 @@ +package com.goi.erp.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerContainerRequestDto { + + private Long ccoCustomerId; + + private String ccoType; + private Integer ccoCapacity; + + private String ccoOwnerType; + private String ccoIsUsed; + + private String ccoHasLock; + private String ccoHasWheel; + private String ccoHasWoodframe; + + private String ccoStatus; + + private String ccoCreateddate; + private String ccoUpdateddate; + + private String ccoInstallNote; + private String ccoPickupNote; + + private LocalDate ccoInstallDate; + private LocalDate ccoPickupDate; + + private LocalDateTime ccoInstallAt; + private LocalDateTime ccoPickupAt; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerContainerResponseDto.java b/src/main/java/com/goi/erp/dto/CustomerContainerResponseDto.java new file mode 100644 index 0000000..d346175 --- /dev/null +++ b/src/main/java/com/goi/erp/dto/CustomerContainerResponseDto.java @@ -0,0 +1,46 @@ +package com.goi.erp.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerContainerResponseDto { + + private Long ccoId; + + private Long ccoCustomerId; + + private String ccoType; + private Integer ccoCapacity; + + private String ccoOwnerType; + private String ccoIsUsed; + + private String ccoHasLock; + private String ccoHasWheel; + private String ccoHasWoodframe; + + private String ccoStatus; + + private String ccoCreateddate; + private String ccoUpdateddate; + + private String ccoInstallNote; + private String ccoPickupNote; + + private LocalDate ccoInstallDate; + private LocalDate ccoPickupDate; + + private LocalDateTime ccoInstallAt; + private LocalDateTime ccoPickupAt; + + private LocalDateTime ccoModifiedAt; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerDailyInstallContainerRequestDto.java b/src/main/java/com/goi/erp/dto/CustomerDailyInstallContainerRequestDto.java new file mode 100644 index 0000000..c4328b9 --- /dev/null +++ b/src/main/java/com/goi/erp/dto/CustomerDailyInstallContainerRequestDto.java @@ -0,0 +1,31 @@ +package com.goi.erp.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDailyInstallContainerRequestDto { + + private Long cdicDailyInstallId; + + private String cdicAction; + + private String cdicType; + + private Integer cdicCapacity; + + private String cdicIsUsed; + + private String cdicHasLock; + + private String cdicHasWheel; + + private String cdicHasWoodframe; + + private String cdicOwnerType; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerDailyInstallContainerResponseDto.java b/src/main/java/com/goi/erp/dto/CustomerDailyInstallContainerResponseDto.java new file mode 100644 index 0000000..70ddbc9 --- /dev/null +++ b/src/main/java/com/goi/erp/dto/CustomerDailyInstallContainerResponseDto.java @@ -0,0 +1,33 @@ +package com.goi.erp.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDailyInstallContainerResponseDto { + + private Long cdicId; + + private Long cdicDailyInstallId; + + private String cdicAction; + + private String cdicType; + + private Integer cdicCapacity; + + private String cdicIsUsed; + + private String cdicHasLock; + + private String cdicHasWheel; + + private String cdicHasWoodframe; + + private String cdicOwnerType; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerDailyInstallRequestDto.java b/src/main/java/com/goi/erp/dto/CustomerDailyInstallRequestDto.java new file mode 100644 index 0000000..65a7e4a --- /dev/null +++ b/src/main/java/com/goi/erp/dto/CustomerDailyInstallRequestDto.java @@ -0,0 +1,63 @@ +package com.goi.erp.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDailyInstallRequestDto { + + private Integer cdiOrderSeq; + + private Long cdiDriverId; + + private LocalDate cdiInstallDate; + + private LocalTime cdiInstallTime; + + private Long cdiCustomerId; + + private String cdiAccountNo; + + private String cdiCustomerName; + + private String cdiPhone; + + private String cdiAddress; + + private String cdiCity; + + private String cdiPostalCode; + + private BigDecimal cdiGeoLat; + + private BigDecimal cdiGeoLon; + + private Long cdiCustomerDriverId; + + private String cdiWorkType; + + private Integer cdiOilPickup; + + private Integer cdiSludge; + + private String cdiRequestNote; + + private String cdiWorkNote; + + private String cdiInstallNote; + + private String cdiCsNote; + + private String cdiStatus; + + private String cdiCreatedBy; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerDailyInstallResponseDto.java b/src/main/java/com/goi/erp/dto/CustomerDailyInstallResponseDto.java new file mode 100644 index 0000000..9b9d3e1 --- /dev/null +++ b/src/main/java/com/goi/erp/dto/CustomerDailyInstallResponseDto.java @@ -0,0 +1,46 @@ +package com.goi.erp.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDailyInstallResponseDto { + + private UUID cdiUuid; // UUID + private Integer cdiOrderSeq; + private Long cdiDriverId; + private LocalDate cdiInstallDate; + private LocalTime cdiInstallTime; + private Long cdiCustomerId; + private String cdiAccountNo; + private String cdiCustomerName; + private String cdiPhone; + private String cdiAddress; + private String cdiCity; + private String cdiPostalCode; + private BigDecimal cdiGeoLat; + private BigDecimal cdiGeoLon; + private Long cdiCustomerDriverId; + private String cdiWorkType; + private Integer cdiOilPickup; + private Integer cdiSludge; + private String cdiRequestNote; + private String cdiWorkNote; + private String cdiInstallNote; + private String cdiCsNote; + private String cdiStatus; + private String cdiCreatedBy; + private LocalDateTime cdiCreatedAt; + private LocalDateTime cdiUpdatedAt; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/dto/CustomerDailyOrderRequestDto.java b/src/main/java/com/goi/erp/dto/CustomerDailyOrderRequestDto.java index 2e7c670..3845949 100644 --- a/src/main/java/com/goi/erp/dto/CustomerDailyOrderRequestDto.java +++ b/src/main/java/com/goi/erp/dto/CustomerDailyOrderRequestDto.java @@ -12,14 +12,16 @@ import java.util.UUID; @NoArgsConstructor public class CustomerDailyOrderRequestDto { - private LocalDate cdoOrderDate; // 주문 날짜 (YYYY-MM-DD) - private String cdoOrderType; // 주문 타입 ('N' 등) - private String cdoRequestNote; // 주문 요청 메모 + private LocalDate cdoOrderDate; // 주문 날짜 (YYYY-MM-DD) + private String cdoJobType; // UCO | INSTALL + private String cdoOrderType; // 주문 타입 ('N' 등) + private String cdoRequestNote; // 주문 요청 메모 private String cdoExternalDriverId; // MIS 에서 driverId 로 호출해서 employee_external_map 참조해야함 private String cdoExternalCreatedBy; // MIS 에서 memberId 로 호출해서 employee_external_map 참조해야함 - private Long cdoDriverId; // 배정된 driver id - private UUID cdoDriverUuid; // ERP 에서는 uuid 로 호출 - private Long cdoCustomerId; // 고객 ID + private Long cdoRegionId; // 배정 지역 + private Long cdoDriverId; // 배정된 driver id + private UUID cdoDriverUuid; // ERP 에서는 uuid 로 호출 + private Long cdoCustomerId; // 고객 ID private String cdoCustomerNo; private UUID cdoCustomerUuid; private String cdoPaymentType; // 결제 타입 diff --git a/src/main/java/com/goi/erp/dto/CustomerDailyOrderResponseDto.java b/src/main/java/com/goi/erp/dto/CustomerDailyOrderResponseDto.java index 4611fe7..69aa68a 100644 --- a/src/main/java/com/goi/erp/dto/CustomerDailyOrderResponseDto.java +++ b/src/main/java/com/goi/erp/dto/CustomerDailyOrderResponseDto.java @@ -17,10 +17,12 @@ import java.util.UUID; public class CustomerDailyOrderResponseDto { private UUID cdoUuid; // UUID - private LocalDate cdoOrderDate; // YYYYMMDD + private LocalDate cdoOrderDate; // YYYYMMDD + private String cdoJobType; // UCO | INSTALL private String cdoOrderType; // 주문 타입 private String cdoRequestNote; // 요청 메모 - //private Long cdoDriverId; // Driver ID + private Long cdoRegionId; // 지역 ID + private Long cdoDriverId; // Driver ID //private Long cdoCustomerId; // private String cdoCustomerNo; private String cdoPaymentType; // 결제 방식 diff --git a/src/main/java/com/goi/erp/entity/CustomerContainer.java b/src/main/java/com/goi/erp/entity/CustomerContainer.java new file mode 100644 index 0000000..253276d --- /dev/null +++ b/src/main/java/com/goi/erp/entity/CustomerContainer.java @@ -0,0 +1,84 @@ +package com.goi.erp.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Entity +@Table(schema = "crm", name = "customer_container") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerContainer { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cco_id") + private Long ccoId; + + @Column(name = "cco_customer_id", nullable = false) + private Long ccoCustomerId; + + @Column(name = "cco_type", nullable = false, length = 10) + private String ccoType; + + @Column(name = "cco_capacity") + private Integer ccoCapacity; + + @Column(name = "cco_owner_type", length = 1) + private String ccoOwnerType; + + @Column(name = "cco_is_used", length = 1) + private String ccoIsUsed; + + @Column(name = "cco_has_lock", length = 1) + private String ccoHasLock; + + @Column(name = "cco_has_wheel", length = 1) + private String ccoHasWheel; + + @Column(name = "cco_has_woodframe", length = 1) + private String ccoHasWoodframe; + + @Column(name = "cco_status", length = 1) + private String ccoStatus; + + @Column(name = "cco_createddate", length = 14) + private String ccoCreateddate; + + @Column(name = "cco_updateddate", length = 14) + private String ccoUpdateddate; + + @Column(name = "cco_install_note", length = 500) + private String ccoInstallNote; + + @Column(name = "cco_pickup_note", length = 500) + private String ccoPickupNote; + + @Column(name = "cco_install_date") + private LocalDate ccoInstallDate; + + @Column(name = "cco_pickup_date") + private LocalDate ccoPickupDate; + + @Column(name = "cco_install_at") + private LocalDateTime ccoInstallAt; + + @Column(name = "cco_pickup_at") + private LocalDateTime ccoPickupAt; + + @Column(name = "cco_modified_at") + private LocalDateTime ccoModifiedAt; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/entity/CustomerDailyInstall.java b/src/main/java/com/goi/erp/entity/CustomerDailyInstall.java new file mode 100644 index 0000000..f2fb040 --- /dev/null +++ b/src/main/java/com/goi/erp/entity/CustomerDailyInstall.java @@ -0,0 +1,110 @@ +package com.goi.erp.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.UUID; + +@Entity +@Table(schema = "crm", name = "customer_daily_install") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDailyInstall { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cdi_id") + private Long cdiId; + + private UUID cdiUuid; + + @Column(name = "cdi_order_seq", nullable = false) + private Integer cdiOrderSeq; + + @Column(name = "cdi_driver_id", nullable = false) + private Long cdiDriverId; + + @Column(name = "cdi_install_date", nullable = false) + private LocalDate cdiInstallDate; + + @Column(name = "cdi_install_time") + private LocalTime cdiInstallTime; + + @Column(name = "cdi_customer_id", nullable = false) + private Long cdiCustomerId; + + @Column(name = "cdi_account_no", length = 20) + private String cdiAccountNo; + + @Column(name = "cdi_customer_name", length = 100) + private String cdiCustomerName; + + @Column(name = "cdi_phone", length = 50) + private String cdiPhone; + + @Column(name = "cdi_address", length = 200) + private String cdiAddress; + + @Column(name = "cdi_city", length = 50) + private String cdiCity; + + @Column(name = "cdi_postal_code", length = 20) + private String cdiPostalCode; + + @Column(name = "cdi_geo_lat", precision = 10, scale = 8) + private BigDecimal cdiGeoLat; + + @Column(name = "cdi_geo_lon", precision = 11, scale = 8) + private BigDecimal cdiGeoLon; + + @Column(name = "cdi_customer_driver_id") + private Long cdiCustomerDriverId; + + @Column(name = "cdi_work_type", length = 10) + private String cdiWorkType; + + @Column(name = "cdi_oil_pickup") + private Integer cdiOilPickup; + + @Column(name = "cdi_sludge") + private Integer cdiSludge; + + @Column(name = "cdi_request_note") + private String cdiRequestNote; + + @Column(name = "cdi_work_note") + private String cdiWorkNote; + + @Column(name = "cdi_install_note") + private String cdiInstallNote; + + @Column(name = "cdi_cs_note") + private String cdiCsNote; + + @Column(name = "cdi_status", length = 1) + private String cdiStatus; + + @Column(name = "cdi_created_by", length = 50) + private String cdiCreatedBy; + + @Column(name = "cdi_created_at") + private LocalDateTime cdiCreatedAt; + + @Column(name = "cdi_updated_at") + private LocalDateTime cdiUpdatedAt; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/entity/CustomerDailyInstallContainer.java b/src/main/java/com/goi/erp/entity/CustomerDailyInstallContainer.java new file mode 100644 index 0000000..a868226 --- /dev/null +++ b/src/main/java/com/goi/erp/entity/CustomerDailyInstallContainer.java @@ -0,0 +1,54 @@ +package com.goi.erp.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(schema = "crm", name = "customer_daily_install_container") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDailyInstallContainer { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cdic_id") + private Long cdicId; + + @Column(name = "cdic_daily_install_id", nullable = false) + private Long cdicDailyInstallId; + + @Column(name = "cdic_action", nullable = false, length = 10) + private String cdicAction; + + @Column(name = "cdic_type", nullable = false, length = 10) + private String cdicType; + + @Column(name = "cdic_capacity") + private Integer cdicCapacity; + + @Column(name = "cdic_is_used", length = 1) + private String cdicIsUsed; + + @Column(name = "cdic_has_lock", length = 1) + private String cdicHasLock; + + @Column(name = "cdic_has_wheel", length = 1) + private String cdicHasWheel; + + @Column(name = "cdic_has_woodframe", length = 1) + private String cdicHasWoodframe; + + @Column(name = "cdic_owner_type", length = 1) + private String cdicOwnerType; +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/entity/CustomerDailyOrder.java b/src/main/java/com/goi/erp/entity/CustomerDailyOrder.java index 6c4fd8e..239729a 100644 --- a/src/main/java/com/goi/erp/entity/CustomerDailyOrder.java +++ b/src/main/java/com/goi/erp/entity/CustomerDailyOrder.java @@ -39,12 +39,15 @@ public class CustomerDailyOrder { private UUID cdoUuid; private LocalDate cdoOrderDate; + + private String cdoJobType; @Column(length = 1) private String cdoOrderType; private String cdoRequestNote; + private Long cdoRegionId; private Long cdoDriverId; private Long cdoCustomerId; diff --git a/src/main/java/com/goi/erp/repository/CustomerContainerRepository.java b/src/main/java/com/goi/erp/repository/CustomerContainerRepository.java new file mode 100644 index 0000000..83b464a --- /dev/null +++ b/src/main/java/com/goi/erp/repository/CustomerContainerRepository.java @@ -0,0 +1,15 @@ +package com.goi.erp.repository; + +import com.goi.erp.entity.CustomerContainer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CustomerContainerRepository extends JpaRepository { + + List findByCcoCustomerId(Long ccoCustomerId); + + List findByCcoCustomerIdAndCcoStatus(Long ccoCustomerId, String ccoStatus); +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/repository/CustomerDailyInstallContainerRepository.java b/src/main/java/com/goi/erp/repository/CustomerDailyInstallContainerRepository.java new file mode 100644 index 0000000..23bdde8 --- /dev/null +++ b/src/main/java/com/goi/erp/repository/CustomerDailyInstallContainerRepository.java @@ -0,0 +1,19 @@ +package com.goi.erp.repository; + +import com.goi.erp.entity.CustomerDailyInstallContainer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CustomerDailyInstallContainerRepository + extends JpaRepository { + + List findByCdicDailyInstallId(Long cdicDailyInstallId); + + List findByCdicDailyInstallIdAndCdicAction( + Long cdicDailyInstallId, + String cdicAction + ); +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/repository/CustomerDailyInstallRepository.java b/src/main/java/com/goi/erp/repository/CustomerDailyInstallRepository.java new file mode 100644 index 0000000..4bcf281 --- /dev/null +++ b/src/main/java/com/goi/erp/repository/CustomerDailyInstallRepository.java @@ -0,0 +1,25 @@ +package com.goi.erp.repository; + +import com.goi.erp.entity.CustomerDailyInstall; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.time.LocalDate; +import java.util.List; + +@Repository +public interface CustomerDailyInstallRepository extends JpaRepository { + + List findByCdiInstallDate(LocalDate cdiInstallDate); + + List findByCdiDriverId(Long cdiDriverId); + + List findByCdiDriverIdAndCdiInstallDate( + Long cdiDriverId, + LocalDate cdiInstallDate + ); + + List findByCdiCustomerId(Long cdiCustomerId); + + List findByCdiStatus(String cdiStatus); +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/repository/CustomerRegionRepository.java b/src/main/java/com/goi/erp/repository/CustomerRegionRepository.java new file mode 100644 index 0000000..c946f3d --- /dev/null +++ b/src/main/java/com/goi/erp/repository/CustomerRegionRepository.java @@ -0,0 +1,15 @@ +package com.goi.erp.repository; + +import com.goi.erp.entity.CustomerRegion; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CustomerRegionRepository extends JpaRepository { + + List findByCreStatus(String creStatus); + + boolean existsByCreName(String creName); +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/service/CustomerContainerService.java b/src/main/java/com/goi/erp/service/CustomerContainerService.java new file mode 100644 index 0000000..cd1bfb4 --- /dev/null +++ b/src/main/java/com/goi/erp/service/CustomerContainerService.java @@ -0,0 +1,101 @@ +package com.goi.erp.service; + +import com.goi.erp.dto.CustomerContainerRequestDto; +import com.goi.erp.dto.CustomerContainerResponseDto; +import com.goi.erp.entity.CustomerContainer; +import com.goi.erp.repository.CustomerContainerRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CustomerContainerService { + + private final CustomerContainerRepository customerContainerRepository; + + public CustomerContainerResponseDto create(CustomerContainerRequestDto dto) { + + CustomerContainer entity = CustomerContainer.builder() + .ccoCustomerId(dto.getCcoCustomerId()) + .ccoType(dto.getCcoType()) + .ccoCapacity(dto.getCcoCapacity()) + .ccoOwnerType(dto.getCcoOwnerType()) + .ccoIsUsed(dto.getCcoIsUsed()) + .ccoHasLock(dto.getCcoHasLock()) + .ccoHasWheel(dto.getCcoHasWheel()) + .ccoHasWoodframe(dto.getCcoHasWoodframe()) + .ccoStatus(dto.getCcoStatus()) + .ccoInstallNote(dto.getCcoInstallNote()) + .ccoPickupNote(dto.getCcoPickupNote()) + .ccoInstallDate(dto.getCcoInstallDate()) + .ccoPickupDate(dto.getCcoPickupDate()) + .ccoInstallAt(dto.getCcoInstallAt()) + .ccoPickupAt(dto.getCcoPickupAt()) + .build(); + + entity = customerContainerRepository.save(entity); + + return mapToDto(entity); + } + + public List getByCustomerId(Long customerId) { + + return customerContainerRepository.findByCcoCustomerId(customerId) + .stream() + .map(this::mapToDto) + .collect(Collectors.toList()); + } + + @Transactional + public CustomerContainerResponseDto update(Long id, CustomerContainerRequestDto dto) { + + CustomerContainer entity = customerContainerRepository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerContainer not found")); + + updateInternal(entity, dto); + + return mapToDto(entity); + } + + public void delete(Long id) { + + CustomerContainer entity = customerContainerRepository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerContainer not found")); + + customerContainerRepository.delete(entity); + } + + private void updateInternal(CustomerContainer entity, CustomerContainerRequestDto dto) { + + if (dto.getCcoType() != null) entity.setCcoType(dto.getCcoType()); + if (dto.getCcoCapacity() != null) entity.setCcoCapacity(dto.getCcoCapacity()); + if (dto.getCcoOwnerType() != null) entity.setCcoOwnerType(dto.getCcoOwnerType()); + if (dto.getCcoIsUsed() != null) entity.setCcoIsUsed(dto.getCcoIsUsed()); + if (dto.getCcoHasLock() != null) entity.setCcoHasLock(dto.getCcoHasLock()); + if (dto.getCcoHasWheel() != null) entity.setCcoHasWheel(dto.getCcoHasWheel()); + if (dto.getCcoHasWoodframe() != null) entity.setCcoHasWoodframe(dto.getCcoHasWoodframe()); + if (dto.getCcoStatus() != null) entity.setCcoStatus(dto.getCcoStatus()); + } + + private CustomerContainerResponseDto mapToDto(CustomerContainer entity) { + + return CustomerContainerResponseDto.builder() + .ccoId(entity.getCcoId()) + .ccoCustomerId(entity.getCcoCustomerId()) + .ccoType(entity.getCcoType()) + .ccoCapacity(entity.getCcoCapacity()) + .ccoOwnerType(entity.getCcoOwnerType()) + .ccoIsUsed(entity.getCcoIsUsed()) + .ccoHasLock(entity.getCcoHasLock()) + .ccoHasWheel(entity.getCcoHasWheel()) + .ccoHasWoodframe(entity.getCcoHasWoodframe()) + .ccoStatus(entity.getCcoStatus()) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/service/CustomerDailyInstallContainerService.java b/src/main/java/com/goi/erp/service/CustomerDailyInstallContainerService.java new file mode 100644 index 0000000..df03fd9 --- /dev/null +++ b/src/main/java/com/goi/erp/service/CustomerDailyInstallContainerService.java @@ -0,0 +1,100 @@ +package com.goi.erp.service; + +import com.goi.erp.dto.CustomerDailyInstallContainerRequestDto; +import com.goi.erp.dto.CustomerDailyInstallContainerResponseDto; +import com.goi.erp.entity.CustomerDailyInstallContainer; +import com.goi.erp.repository.CustomerDailyInstallContainerRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CustomerDailyInstallContainerService { + + private final CustomerDailyInstallContainerRepository repository; + + public CustomerDailyInstallContainerResponseDto create( + CustomerDailyInstallContainerRequestDto dto + ) { + + CustomerDailyInstallContainer entity = + CustomerDailyInstallContainer.builder() + .cdicDailyInstallId(dto.getCdicDailyInstallId()) + .cdicAction(dto.getCdicAction()) + .cdicType(dto.getCdicType()) + .cdicCapacity(dto.getCdicCapacity()) + .cdicIsUsed(dto.getCdicIsUsed()) + .cdicHasLock(dto.getCdicHasLock()) + .cdicHasWheel(dto.getCdicHasWheel()) + .cdicHasWoodframe(dto.getCdicHasWoodframe()) + .cdicOwnerType(dto.getCdicOwnerType()) + .build(); + + entity = repository.save(entity); + + return mapToDto(entity); + } + + public List getByDailyInstallId( + Long dailyInstallId + ) { + + return repository.findByCdicDailyInstallId(dailyInstallId) + .stream() + .map(this::mapToDto) + .collect(Collectors.toList()); + } + + @Transactional + public CustomerDailyInstallContainerResponseDto update( + Long id, + CustomerDailyInstallContainerRequestDto dto + ) { + + CustomerDailyInstallContainer entity = repository.findById(id) + .orElseThrow(() -> new RuntimeException("Container not found")); + + updateInternal(entity, dto); + + return mapToDto(entity); + } + + public void delete(Long id) { + + CustomerDailyInstallContainer entity = repository.findById(id) + .orElseThrow(() -> new RuntimeException("Container not found")); + + repository.delete(entity); + } + + private void updateInternal( + CustomerDailyInstallContainer entity, + CustomerDailyInstallContainerRequestDto dto + ) { + + if (dto.getCdicAction() != null) entity.setCdicAction(dto.getCdicAction()); + if (dto.getCdicType() != null) entity.setCdicType(dto.getCdicType()); + if (dto.getCdicCapacity() != null) entity.setCdicCapacity(dto.getCdicCapacity()); + if (dto.getCdicIsUsed() != null) entity.setCdicIsUsed(dto.getCdicIsUsed()); + } + + private CustomerDailyInstallContainerResponseDto mapToDto( + CustomerDailyInstallContainer entity + ) { + + return CustomerDailyInstallContainerResponseDto.builder() + .cdicId(entity.getCdicId()) + .cdicDailyInstallId(entity.getCdicDailyInstallId()) + .cdicAction(entity.getCdicAction()) + .cdicType(entity.getCdicType()) + .cdicCapacity(entity.getCdicCapacity()) + .cdicIsUsed(entity.getCdicIsUsed()) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/service/CustomerDailyInstallService.java b/src/main/java/com/goi/erp/service/CustomerDailyInstallService.java new file mode 100644 index 0000000..719d5ea --- /dev/null +++ b/src/main/java/com/goi/erp/service/CustomerDailyInstallService.java @@ -0,0 +1,96 @@ +package com.goi.erp.service; + +import com.goi.erp.dto.CustomerDailyInstallRequestDto; +import com.goi.erp.dto.CustomerDailyInstallResponseDto; +import com.goi.erp.entity.CustomerDailyInstall; +import com.goi.erp.repository.CustomerDailyInstallRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CustomerDailyInstallService { + + private final CustomerDailyInstallRepository repository; + + public CustomerDailyInstallResponseDto create(CustomerDailyInstallRequestDto dto) { + + CustomerDailyInstall entity = CustomerDailyInstall.builder() + .cdiOrderSeq(dto.getCdiOrderSeq()) + .cdiDriverId(dto.getCdiDriverId()) + .cdiInstallDate(dto.getCdiInstallDate()) + .cdiInstallTime(dto.getCdiInstallTime()) + .cdiCustomerId(dto.getCdiCustomerId()) + .cdiAccountNo(dto.getCdiAccountNo()) + .cdiCustomerName(dto.getCdiCustomerName()) + .cdiPhone(dto.getCdiPhone()) + .cdiAddress(dto.getCdiAddress()) + .cdiCity(dto.getCdiCity()) + .cdiPostalCode(dto.getCdiPostalCode()) + .cdiGeoLat(dto.getCdiGeoLat()) + .cdiGeoLon(dto.getCdiGeoLon()) + .cdiWorkType(dto.getCdiWorkType()) + .cdiStatus(dto.getCdiStatus()) + .build(); + + entity = repository.save(entity); + + return mapToDto(entity); + } + + public List getByInstallDate(LocalDate date) { + + return repository.findByCdiInstallDate(date) + .stream() + .map(this::mapToDto) + .collect(Collectors.toList()); + } + + @Transactional + public CustomerDailyInstallResponseDto update(Long id, CustomerDailyInstallRequestDto dto) { + + CustomerDailyInstall entity = repository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerDailyInstall not found")); + + updateInternal(entity, dto); + + return mapToDto(entity); + } + + public void delete(Long id) { + + CustomerDailyInstall entity = repository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerDailyInstall not found")); + + repository.delete(entity); + } + + private void updateInternal(CustomerDailyInstall entity, CustomerDailyInstallRequestDto dto) { + + if (dto.getCdiDriverId() != null) entity.setCdiDriverId(dto.getCdiDriverId()); + if (dto.getCdiInstallTime() != null) entity.setCdiInstallTime(dto.getCdiInstallTime()); + if (dto.getCdiStatus() != null) entity.setCdiStatus(dto.getCdiStatus()); + if (dto.getCdiWorkNote() != null) entity.setCdiWorkNote(dto.getCdiWorkNote()); + } + + private CustomerDailyInstallResponseDto mapToDto(CustomerDailyInstall entity) { + + return CustomerDailyInstallResponseDto.builder() + .cdiUuid(entity.getCdiUuid()) + .cdiOrderSeq(entity.getCdiOrderSeq()) + .cdiDriverId(entity.getCdiDriverId()) + .cdiInstallDate(entity.getCdiInstallDate()) + .cdiInstallTime(entity.getCdiInstallTime()) + .cdiCustomerId(entity.getCdiCustomerId()) + .cdiCustomerName(entity.getCdiCustomerName()) + .cdiStatus(entity.getCdiStatus()) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/goi/erp/service/CustomerDailyOrderService.java b/src/main/java/com/goi/erp/service/CustomerDailyOrderService.java index 1e9cb27..64b3bda 100644 --- a/src/main/java/com/goi/erp/service/CustomerDailyOrderService.java +++ b/src/main/java/com/goi/erp/service/CustomerDailyOrderService.java @@ -44,8 +44,10 @@ public class CustomerDailyOrderService { CustomerDailyOrder order = CustomerDailyOrder.builder() .cdoUuid(UUID.randomUUID()) .cdoOrderDate(dto.getCdoOrderDate()) + .cdoJobType(dto.getCdoJobType()) .cdoOrderType(dto.getCdoOrderType()) .cdoRequestNote(dto.getCdoRequestNote()) + .cdoRegionId(dto.getCdoRegionId()) .cdoDriverId(driverId) .cdoCustomerId(customerId) .cdoCustomerNo(dto.getCdoCustomerNo()) @@ -166,8 +168,10 @@ public class CustomerDailyOrderService { Long driverId = resolveDriverId(dto); // null 이 아닌 경우만 업데이트 + if (dto.getCdoJobType() != null) order.setCdoJobType(dto.getCdoJobType()); if (dto.getCdoOrderType() != null) order.setCdoOrderType(dto.getCdoOrderType()); if (dto.getCdoRequestNote() != null) order.setCdoRequestNote(dto.getCdoRequestNote()); + if (dto.getCdoRegionId() != null) order.setCdoRegionId(dto.getCdoRegionId()); if (dto.getCdoDriverId() != null || dto.getCdoExternalDriverId() != null || dto.getCdoDriverUuid() != null) order.setCdoDriverId(driverId); if (dto.getCdoPaymentType() != null) order.setCdoPaymentType(dto.getCdoPaymentType()); if (dto.getCdoCycle() != null) order.setCdoCycle(dto.getCdoCycle()); @@ -199,9 +203,11 @@ public class CustomerDailyOrderService { return CustomerDailyOrderResponseDto.builder() .cdoUuid(order.getCdoUuid()) .cdoOrderDate(order.getCdoOrderDate()) + .cdoJobType(order.getCdoJobType()) .cdoOrderType(order.getCdoOrderType()) .cdoRequestNote(order.getCdoRequestNote()) -// .cdoDriverId(order.getCdoDriverId()) + .cdoRegionId(order.getCdoRegionId()) + .cdoDriverId(order.getCdoDriverId()) .cdoCustomerNo(order.getCdoCustomerNo()) .cdoPaymentType(order.getCdoPaymentType()) .cdoCycle(order.getCdoCycle()) diff --git a/src/main/java/com/goi/erp/service/CustomerRegionService.java b/src/main/java/com/goi/erp/service/CustomerRegionService.java new file mode 100644 index 0000000..a982025 --- /dev/null +++ b/src/main/java/com/goi/erp/service/CustomerRegionService.java @@ -0,0 +1,97 @@ +package com.goi.erp.service; + +import com.goi.erp.dto.CustomerRegionRequestDto; +import com.goi.erp.dto.CustomerRegionResponseDto; +import com.goi.erp.entity.CustomerRegion; +import com.goi.erp.repository.CustomerRegionRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CustomerRegionService { + + private final CustomerRegionRepository customerRegionRepository; + + /** + * CREATE + */ + public CustomerRegionResponseDto create(CustomerRegionRequestDto dto) { + + CustomerRegion entity = CustomerRegion.builder() + .creName(dto.getCreName()) + .creStatus(dto.getCreStatus()) + .build(); + + entity = customerRegionRepository.save(entity); + + return mapToDto(entity); + } + + /** + * GET ALL + */ + public List getAll() { + return customerRegionRepository.findAll() + .stream() + .map(this::mapToDto) + .collect(Collectors.toList()); + } + + /** + * GET BY ID + */ + public CustomerRegionResponseDto getById(Long id) { + + CustomerRegion entity = customerRegionRepository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerRegion not found")); + + return mapToDto(entity); + } + + /** + * UPDATE + */ + @Transactional + public CustomerRegionResponseDto update(Long id, CustomerRegionRequestDto dto) { + + CustomerRegion entity = customerRegionRepository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerRegion not found")); + + updateInternal(entity, dto); + + return mapToDto(entity); + } + + /** + * DELETE + */ + public void delete(Long id) { + + CustomerRegion entity = customerRegionRepository.findById(id) + .orElseThrow(() -> new RuntimeException("CustomerRegion not found")); + + customerRegionRepository.delete(entity); + } + + private void updateInternal(CustomerRegion entity, CustomerRegionRequestDto dto) { + + if (dto.getCreName() != null) entity.setCreName(dto.getCreName()); + if (dto.getCreStatus() != null) entity.setCreStatus(dto.getCreStatus()); + } + + private CustomerRegionResponseDto mapToDto(CustomerRegion entity) { + + return CustomerRegionResponseDto.builder() + .creId(entity.getCreId()) + .creName(entity.getCreName()) + .creStatus(entity.getCreStatus()) + .build(); + } +} \ No newline at end of file