๊ฐœ๋ฐœ์ผ์ง€-19 [๐Ÿ“‡์ฃผ๋ฌธ ๋„๋ฉ”์ธ: ์กฐํšŒ]

๊น€์„ฑ์ธยท2023๋…„ 9์›” 14์ผ
0

์ฃผ๋ฌธ ๋„๋ฉ”์ธ ๊ธฐ๋Šฅ ์ •์˜ ํฌ์ŠคํŒ…


์ฃผ๋ฌธ ์ ‘์ˆ˜ ๋Œ€๊ธฐ ํ™”๋ฉด

์ฃผ๋ฌธ ์ ‘์ˆ˜ ํ™”๋ฉด

์ฃผ๋ฌธ ์ฒ˜๋ฆฌ ์™„๋ฃŒ ํ™”๋ฉด


1. [GET] /jat/orders/wait, process, complete

์ฃผ๋ฌธ ์ ‘์ˆ˜ ํ˜„ํ™ฉ ์กฐํšŒ

  • ์ฃผ๋ฌธ ์ ‘์ˆ˜ ๋Œ€๊ธฐ, ์ฒ˜๋ฆฌ ์ค‘, ์™„๋ฃŒ ํ•ญ๋ชฉ ๋“ค์€ ๋ชจ๋‘ ๋˜‘๊ฐ™์€ ๋กœ์ง์œผ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋‹ค.
  • ์ฐจ๋ณ„์ ์ด ์žˆ๋‹ค๋ฉด, ์ฃผ๋ฌธ ์ ‘์ˆ˜ ํ›„์—๋Š” ์ฃผ๋ฌธ ๋ฒˆํ˜ธ๊ฐ€ ํ• ๋‹น ๋œ๋‹ค๋Š” ๊ฒƒ.
  • ํ˜„์žฌ ๊ตฌ๋งค์ž๊ฐ€ ์—†์œผ๋ฏ€๋กœ ๋”๋ฏธ๋ฐ์ดํ„ฐ๋ฅผ DB์— ๋ฐ˜์˜ํ•˜์ง€ ์•Š์€ ์ƒํƒœ๋ผ์„œ ์ฝ”๋“œ ๊ตฌํ˜„๋งŒ ์„ค๋ช…ํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.
  • ์‘๋‹ต ๋ฐ”๋””
    ์ œ๋„ค๋ฆญ์œผ๋กœ ๊ฐ’์„ ์„ค์ •ํ•ด์ค€ ์ด์œ ๋Š” ์ฒ˜์Œ์— ์ฃผ๋ฌธ ์ ‘์ˆ˜ ๋Œ€๊ธฐ, ์ ‘์ˆ˜ ์ค‘ , ์™„๋ฃŒ๋ฅผ ๋ชจ๋‘ ๋‹ค๋ฅธ ์‘๋‹ต ๋ฐ”๋””๋กœ ๋งŒ๋“ค์–ด์„œ ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ์˜ ์ œ๋„ค๋ฆญ์„ ์‚ฌ์šฉํ–ˆ๋‹ค.
    ํ™”๋ฉด์„ ๋‹ค์‹œ๋ณด๋‹ˆ ์ฃผ๋ฌธ ๋ฒˆํ˜ธ ๋บด๊ณ ๋Š” ๋ณ„๋กœ ๋‹ค๋ฅธ ๊ฐ’์ด ์—†์–ด์„œ ๋ชจ๋“  ์‘๋‹ต ๋ฐ”๋”” ํ˜•ํƒœ๋ฅผ ํ†ต์ผ ์‹œ์ผฐ๋‹ค.
  • OrderController.java
    ์ฃผ๋ฌธ ์ ‘์ˆ˜ ๋Œ€๊ธฐ, ์ ‘์ˆ˜์ค‘, ์™„๋ฃŒ ๋Š” ์„œ๋น„์Šค ํ•จ์ˆ˜์— ์ƒํƒœ๊ฐ’์„ ํ†ตํ•ด์„œ ์‹๋ณ„ํ•œ๋‹ค.
    "W" :์ฃผ๋ฌธ ์ ‘์ˆ˜ ๋Œ€๊ธฐ, "P" : ์ฃผ๋ฌธ ์ฒ˜๋ฆฌ ์ค‘, "A" : ์ฃผ๋ฌธ ์ฒ˜๋ฆฌ ์™„๋ฃŒ
  • OrderService.java
  1. ์‚ฌ์šฉ์ž ๊ฐ€๊ฒŒ์˜ ์ฃผ๋ฌธ ์ •๋ณด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์กฐ์ธ์„ ์œ„ํ•œ ๊ฐ€๊ฒŒ Idx๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ , ์ฃผ๋ฌธ ๊ธฐ๋ณธ ์ •๋ณด๋ฅผ ๋ชจ๋‘ ๊ฐ€์ ธ์˜จ๋‹ค.
    public GetOrderListRes getOrdersBySellerIdx(int sellerIdx, String status) throws BaseException {
        // 1) ์‚ฌ์šฉ์ž ๊ฐ€๊ฒŒ ์กฐํšŒ
        int storeIdx;
        try{
            storeIdx = storeDao.storeIdxBySellerIdx(sellerIdx);
        } catch (Exception e) {
            throw new BaseException(POST_STORES_NOT_REGISTERD); // 2030 : ์‚ฌ์šฉ์ž์˜ ๊ฐ€๊ฒŒ๊ฐ€ ๋“ฑ๋ก๋˜์–ด์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
        }

        // 2) ์ฃผ๋ฌธ๊ด€๋ จ๋œ ์ •๋ณด ๋ชจ๋‘ ๊ฐ€์ ธ์˜ค๊ธฐ (์ ‘์ˆ˜ ๋Œ€๊ธฐ์ค‘ W)
        // ์ฃผ๋ฌธIdx, ์ฃผ๋ฌธ/ํ”ฝ์—… ์‹œ๊ฐ„, ์š”์ฒญ์‚ฌํ•ญ, ์ด ๊ฒฐ์ œ๊ธˆ์•ก, ๊ฒฐ์ œ์ƒํƒœ, ๋ฉ”๋‰ด์ด๋ฆ„, ์ด ๊ฐ€๊ฒฉ
        List<GetOrderItemRes> getOrdersResList;
        try {
            getOrdersResList = orderDao.getOrdersByStoreIdx(storeIdx, status);
        } catch (Exception e){
            throw new BaseException(BaseResponseStatus.RESPONSE_ERROR); // ์ฃผ๋ฌธ ๋Œ€๊ธฐ ์กฐํšŒ์— ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
        }
  1. ๊ฐ ์ฃผ๋ฌธ ์ •๋ณด์— ๋“ค์–ด๊ฐ€๋Š” ๋‚ด์šฉ์„ ํ™•์ธํ•ด๋ณด๋ฉด(์™ผ์ชฝ์œ„ -> ์˜ค๋ฅธ์ชฝ ์•„๋ž˜)
  • ์ฃผ๋ฌธ ์‹œ๊ฐ„
  • ์ฃผ๋ฌธํ•œ ๋ฉ”๋‰ด ์ข…๋ฅ˜ ๊ฐœ์ˆ˜
  • ์ด ๊ธˆ์•ก
  • ๊ฒฐ์ œ์ •๋ณด
  • ์š”์ฒญ์‚ฌํ•ญ์—ฌ๋ถ€
  • ์ฃผ๋ฌธ๋ฒˆํ˜ธ
  • ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜
  • ํ”ฝ์—…์˜ˆ์ •์‹œ๊ฐ„
  • ์š”์ฒญ ๋‚ด์šฉ
        // 3) ์ฃผ๋ฌธ๊ด€๋ จ ์ •๋ณด ์กฐํ•ฉํ•˜๊ธฐ
        HashMap<Integer, GetOrderRes> orderHash = new LinkedHashMap<>();
        try{
            for(GetOrderItemRes orders : getOrdersResList){
                if (!orderHash.containsKey(orders.getOrderIdx())){
                    GetOrderRes orderInfo = new GetOrderRes(
                            orders.getOrderIdx(), // ์ฃผ๋ฌธ ์‹๋ณ„์ž
                            orders.getOrderSequence(), // ์ฃผ๋ฌธ ๋ฒˆํ˜ธ
                            orders.getOrderTime(), // ์ฃผ๋ฌธ ์‹œ๊ฐ„
                            orders.getPickUpTime(), // ํ”ฝ์—… ์‹œ๊ฐ„
                            orders.getRequest(), // ์š”์ฒญ ์‚ฌํ•ญ
                            1, // ์ฃผ๋ฌธ๋‹น ๋ฉ”๋‰ด ์ข…๋ฅ˜ ๊ฐœ์ˆ˜ 1 ๋กœ ์‹œ์ž‘
                            orders.getTotalPrice(), // ์ „์ฒด ๊ธˆ์•ก
                            orders.getPayStatus(), // ๊ฒฐ์ œ ์ƒํƒœ
                            new ArrayList<>()// ๋‹ด์„ ๋ฉ”๋‰ด ๋ชฉ๋ก
                    );
                    // ๊ฐ ์ฃผ๋ฌธ์— ๋Œ€ํ•œ ๋ฉ”๋‰ด ์ •๋ณด๋ฅผ ํ•ด์‹œ๋กœ ์œ ์ง€
                    // ๋ฉ”๋‰ด ๋ชฉ๋ก ๋ฆฌ์ŠคํŠธ ์ถ”๊ฐ€
                    orderInfo.getOrderItem().add(new OrderMenuCntPrirce(orders.getMenuName(), orders.getMenuCount(), orders.getDiscountedPrice()));

                    orderHash.put(orders.getOrderIdx(), orderInfo);

                }else{
                    // ์ฃผ๋ฌธ ๋‚ด ๋ฉ”๋‰ด ๊ฐœ์ˆ˜ 1 ์ฆ๊ฐ€
                    orderHash.get(orders.getOrderIdx())
                            .setMenuDiverse(orderHash.get(orders.getOrderIdx()).getMenuDiverse() + 1);

                    // ์ด ์ฃผ๋ฌธ ๊ฐ€๊ฒฉ ํ•ฉ์‚ฐ
                    orderHash.get(orders.getOrderIdx())
                            .setTotalPrice(orderHash.get(orders.getOrderIdx()).getTotalPrice() + orders.getTotalPrice());

                    // ๋ฉ”๋‰ด ์ด๋ฆ„, ๊ฐœ์ˆ˜๋ชฉ๋ก ์ถ”๊ฐ€
                    orderHash.get(orders.getOrderIdx())
                            .getOrderItem().add(new OrderMenuCntPrirce(orders.getMenuName(), orders.getMenuCount(), orders.getDiscountedPrice()));
                }
            }
        }catch (Exception e){
            throw new BaseException(BaseResponseStatus.RESPONSE_ERROR); // ์ฃผ๋ฌธ ๋Œ€๊ธฐ ๋ชฉ๋ก์„ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
        }

        return new GetOrderListRes<>(storeIdx, new ArrayList<>(orderHash.values()));
    }
  • OrderDao.java
    ์กฐ์ธ ์ˆœ์„œ :
    ๊ฐ€๊ฒŒ Idx : ๊ฐ€๊ฒŒ์— ๋“ค์–ด์˜จ ์ฃผ๋ฌธ ํ™•์ธ
    -> ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ชฉ๋ก : ์ฃผ๋ฌธ์— ๋“ค์–ด์˜จ ๋ฉ”๋‰ด ๊ธฐ์ค€
    -> ์ฃผ๋ฌธ Idx : ์ฃผ๋ฌธ ๋‹จ์œ„๋กœ ์ด ์ฃผ๋ฌธ ๊ฐ€๊ฒฉ์ด ์–ผ๋งˆ์ธ์ง€ ์ง‘๊ณ„ํ•จ์ˆ˜๋ฅผ ๋‚ด๊ธฐ์œ„ํ•จ
    -> ์˜ค๋Š˜์˜ ๋ฉ”๋‰ด Idx : ๊ฐ ๋ฉ”๋‰ด๊ฐ€ ์–ด๋–ค ๋–จ์ด ๋ฉ”๋‰ด ๊ธฐ์ค€์ธ์ง€
    -> ๋ฉ”๋‰ด : ๋–จ์ด๋ฉ”๋‰ด์—๋Š” ๋‹จ์ˆœ ํ• ์ธ์œจ, ๊ฐ€๊ฒฉ, ์ˆ˜๋Ÿ‰๋งŒ ์žˆ๊ธฐ๋–„๋ฌธ์— ๋ฉ”๋‰ด์˜ ์ด๋ฆ„ ๋“ฑ์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•จ
    -> ๊ตฌ๋งค์ž ํ˜•ํƒœ : ์–ด๋Š ๊ตฌ๋งค์ž๊ฐ€ ์š”์ฒญํ–ˆ๋Š”์ง€
    ๋กœ ์กฐ์ธํ•˜์˜€๋‹ค.
// ์ „์ฒด ๊ธˆ์•ก์„ ์กฐ์ธ์„ ํ†ตํ•ด์„œ ์ง‘๊ณ„ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ตฌํ•˜์˜€๋‹ค.
    public List<GetOrderItemRes> getOrdersByStoreIdx(int storeIdx, String status){
        String OrdersQuery ="SELECT\n" +
                "    *\n" +
                "FROM(\n" +
                "    SELECT O.orderIdx, O.order_sequence, O.order_time, O.pickup_time,\n" +
                "           O.request, SUM(OL.cnt * TM.price) AS total_price,\n" +
                "           O.payment_status,\n" +
                "           M.menu_name,\n" +
                "           M.price as menu_price,\n" +
                "           TM.discount,\n" +
                "           TM.price as today_menu_price,\n" +
                "           OL.cnt,\n" +
                "           O.status,\n" +
                "           C.customerIdx\n" +
                "    FROM OrderLists OL\n" +
                "    LEFT JOIN Orders O on OL.orderIdx = O.orderIdx\n" +
                "    LEFT JOIN TodayMenu TM on OL.todaymenuIdx = TM.todaymenuIdx\n" +
                "    LEFT JOIN Menu M on TM.menuIdx = M.menuIdx\n" +
                "    LEFT JOIN Customers C on O.customerIdx = C.customerIdx\n" +
                "    WHERE O.storeIdx = ? AND O.status = ?\n" +
                "    GROUP BY O.orderIdx, OL.orderlistIdx) R\n" +
                "    ORDER BY R.order_sequence;";
        return this.jdbcTemplate.query(OrdersQuery,
                (rs, rowNum) -> new GetOrderItemRes(
                        rs.getInt("orderIdx"),
                        rs.getInt("order_sequence") == 0 ? 0 : rs.getInt("order_sequence"),
                        rs.getString("order_time"),
                        rs.getString("pickup_time"),
                        rs.getString("request") == null ? "": rs.getString("request"),
                        rs.getInt("total_price"),
                        rs.getString("payment_status"),
                        rs.getString("menu_name"),
                        rs.getInt("cnt"),
                        rs.getInt("today_menu_price")
                ), storeIdx, status);
    }

ํ…Œ์ŠคํŠธ

๊ตฌ๋งค์ž์˜ ์ฃผ๋ฌธ ๊ด€๋ จ ๋„๋ฉ”์ธ ํฌ์ŠคํŒ…๊ณผ ํ•จ๊ป˜ํ•œ ํ…Œ์ŠคํŠธ
https://velog.io/@99_insung/%EA%B0%9C%EB%B0%9C%EC%9D%BC%EC%A7%80-34-%EC%9E%A5%EB%B0%94%EA%B5%AC%EB%8B%88-%EB%8F%84%EB%A9%94%EC%9D%B8-%EC%9E%A5%EB%B0%94%EA%B5%AC%EB%8B%88-%EC%A3%BC%EB%AC%B8

0๊ฐœ์˜ ๋Œ“๊ธ€