From 43505157645942225c3cf6c905040fb19d069326 Mon Sep 17 00:00:00 2001 From: pilltong22 Date: Mon, 26 Jan 2026 19:04:46 +0900 Subject: [PATCH] =?UTF-8?q?refact:=20#6=20SOMapper=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - N+1 문제 JOIN 으로 개선 - INDEX 추가 --- .ebextensions/app.config | 12 ++++ .gitignore | 4 +- .platform/nginx.conf | 59 +++++++++++++++++++ Procfile | 1 + appspec.yml | 34 +++++++++++ build.gradle | 4 +- .../werp/sero/order/query/dao/SOMapper.xml | 54 +++++++++++------ 7 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 .ebextensions/app.config create mode 100644 .platform/nginx.conf create mode 100644 Procfile create mode 100644 appspec.yml diff --git a/.ebextensions/app.config b/.ebextensions/app.config new file mode 100644 index 00000000..de8541c3 --- /dev/null +++ b/.ebextensions/app.config @@ -0,0 +1,12 @@ +files: + "/sbin/appstart" : + mode: "000755" + owner: webapp + group: webapp + content: | + #!/usr/bin/env bash + JAR_PATH=/var/app/current/application.jar + + # run app + killall java + java -Dfile.encoding=UTF-8 -jar $JAR_PATH diff --git a/.gitignore b/.gitignore index 536cae3e..0062db28 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,6 @@ out/ ### ETC ### src/main/resources/application.yml -src/main/resources/application-*.yml \ No newline at end of file +src/main/resources/application-*.yml +HANDOFF.md +CLAUDE.md \ No newline at end of file diff --git a/.platform/nginx.conf b/.platform/nginx.conf new file mode 100644 index 00000000..97070d83 --- /dev/null +++ b/.platform/nginx.conf @@ -0,0 +1,59 @@ +user nginx; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; +worker_processes auto; +worker_rlimit_nofile 33282; + +events { + use epoll; + worker_connections 1024; + multi_accept on; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + include conf.d/*.conf; + + map $http_upgrade $connection_upgrade { + default "upgrade"; + } + + upstream springboot { + server 127.0.0.1:8080; // 8080번으로 돌고 있는 백엔드 서버를 인지해라! + keepalive 1024; + } + + server { + listen 80 default_server; + listen [::]:80 default_server; + + location / { + proxy_pass http://springboot; + proxy_http_version 1.1; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Upgrade $http_upgrade; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; // 로그분석 (어디서 유입, 차단하고 싶은 사람) + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + } + + access_log /var/log/nginx/access.log main; + + client_header_timeout 60; + client_body_timeout 60; + keepalive_timeout 60; + gzip off; + + # Include the Elastic Beanstalk generated locations + include conf.d/elasticbeanstalk/healthd.conf; + } +} \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..ae5304ad --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: java -jar application.jar \ No newline at end of file diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 00000000..fedeb76c --- /dev/null +++ b/appspec.yml @@ -0,0 +1,34 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ec2-user/app/ + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ec2-user + group: ec2-user + +hooks: + BeforeInstall: + - location: scripts/stop.sh + timeout: 60 + runas: ec2-user + + AfterInstall: + - location: scripts/set-permissions.sh + timeout: 60 + runas: ec2-user + + ApplicationStart: + - location: scripts/start.sh + timeout: 120 + runas: ec2-user + + # ValidateService 임시 비활성화 (디버깅용) + # ValidateService: + # - location: scripts/health-check.sh + # timeout: 180 + # runas: ec2-user diff --git a/build.gradle b/build.gradle index d3675823..9688dd6b 100644 --- a/build.gradle +++ b/build.gradle @@ -39,8 +39,8 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' /* Database */ -// runtimeOnly 'com.mysql:mysql-connector-j' - runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' + runtimeOnly 'com.mysql:mysql-connector-j' +// runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' /* Swagger OpenAPI */ implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.14' diff --git a/src/main/resources/com/werp/sero/order/query/dao/SOMapper.xml b/src/main/resources/com/werp/sero/order/query/dao/SOMapper.xml index 429c8396..8b978824 100644 --- a/src/main/resources/com/werp/sero/order/query/dao/SOMapper.xml +++ b/src/main/resources/com/werp/sero/order/query/dao/SOMapper.xml @@ -184,13 +184,13 @@ D.total_price AS item_total_price, (SELECT IFNULL(SUM(F.available_stock), 0) - FROM warehouse_stock F - INNER JOIN material E ON F.material_id = E.id + FROM material E + INNER JOIN warehouse_stock F ON E.id = F.material_id WHERE E.material_code = D.item_code) AS available_stock, GREATEST(D.quantity - (SELECT IFNULL(SUM(F.available_stock), 0) - FROM warehouse_stock F - INNER JOIN material E ON F.material_id = E.id + FROM material E + INNER JOIN warehouse_stock F ON E.id = F.material_id WHERE E.material_code = D.item_code), 0) AS production_request FROM sales_order A @@ -245,20 +245,17 @@ B.spec, B.unit, B.quantity AS order_quantity, - (SELECT IFNULL(SUM(E.available_stock), 0) - FROM material D - INNER JOIN warehouse_stock E ON D.id = E.material_id - WHERE D.material_code = B.item_code) AS available_stock, + IFNULL(STOCK.total_stock, 0) AS available_stock, - - IFNULL((SELECT SUM(H.pr_quantity) FROM sales_order_item_history H WHERE H.so_item_id = B.id), 0) AS pr_quantity, - IFNULL((SELECT SUM(H.pi_quantity) FROM sales_order_item_history H WHERE H.so_item_id = B.id), 0) AS pi_quantity, - IFNULL((SELECT SUM(H.gi_quantity) FROM sales_order_item_history H WHERE H.so_item_id = B.id), 0) AS gi_quantity, - IFNULL((SELECT SUM(H.shipped_quantity) FROM sales_order_item_history H WHERE H.so_item_id = B.id), 0) AS shipped_quantity, - IFNULL((SELECT SUM(H.do_quantity) FROM sales_order_item_history H WHERE H.so_item_id = B.id), 0) AS do_quantity, - IFNULL((SELECT SUM(H.completed_quantity) FROM sales_order_item_history H WHERE H.so_item_id = B.id), 0) AS completed_quantity, + + IFNULL(HIST.total_pr, 0) AS pr_quantity, + IFNULL(HIST.total_pi, 0) AS pi_quantity, + IFNULL(HIST.total_gi, 0) AS gi_quantity, + IFNULL(HIST.total_shipped, 0) AS shipped_quantity, + IFNULL(HIST.total_do, 0) AS do_quantity, + IFNULL(HIST.total_completed, 0) AS completed_quantity, @@ -274,12 +271,33 @@ FROM sales_order A INNER JOIN sales_order_item B ON A.id = B.so_id + + LEFT JOIN ( + SELECT M.material_code, SUM(WS.available_stock) AS total_stock + FROM material M + INNER JOIN warehouse_stock WS ON M.id = WS.material_id + GROUP BY M.material_code + ) STOCK ON STOCK.material_code = B.item_code + + + LEFT JOIN ( + SELECT + so_item_id, + SUM(pr_quantity) AS total_pr, + SUM(pi_quantity) AS total_pi, + SUM(gi_quantity) AS total_gi, + SUM(shipped_quantity) AS total_shipped, + SUM(do_quantity) AS total_do, + SUM(completed_quantity) AS total_completed + FROM sales_order_item_history + GROUP BY so_item_id + ) HIST ON HIST.so_item_id = B.id LEFT JOIN sales_order_item_history C ON C.id = ( - SELECT MAX(id) - FROM sales_order_item_history - WHERE so_item_id = B.id + SELECT MAX(id) + FROM sales_order_item_history + WHERE so_item_id = B.id )