- ํ๋งค์๊ฐ "ํฝ์ ์๋ฃ" ์ํ๋ก ๋ถ๋ฅํ ์ฃผ๋ฌธ์ ์ฃผ๋ฌธ๋ด์ญํ๋ฉด์์ ์กฐํ๊ฐ๋ฅํ๋๋ก ๊ตฌํํ์๋ค.
- ์๋ต ๋ฐ๋
- ์ฃผ๋ฌธ ๋ด์ญ ์กฐํ ํ๋ฉด์์ ํ์ํ ์ ๋ณด๋ [์ฃผ๋ฌธ๋ ์ง, ์ฃผ๋ฌธ ํ๊ฐ๊ฒ, ์ฃผ๋ฌธ ๋ด์ฉ, ์ฃผ๋ฌธ ๊ธ์ก, ๋ฆฌ๋ทฐ ์์ฑ ์ฌ๋ถ] ๋ฑ์ด ํฌํจ๋๋ค.
- ์ปจํธ๋กค๋ฌ
- ์๋น์ค
public List<GetOrderListRes> getOrderList(int customerIdx) throws BaseException { String[] weekDays = new String[]{"์ผ", "์", "ํ", "์", "๋ชฉ", "๊ธ", "ํ "}; // ์ฃผ๋ฌธ ๋ด์ญ ๊ฐ์ ธ์ค๊ธฐ List<GetOrderListRes> orderList; try{ orderList = appOrderDao.getOrderList(customerIdx, weekDays); }catch (Exception e){ throw new BaseException(DATABASE_ERROR); } // ์ฃผ๋ฌธ๋ด์ญ s3 try{ for(GetOrderListRes order : orderList){ if(order.getMenuUrl() != null && !order.getMenuUrl().equals("")){ order.setMenuUrl(""+s3Client.getUrl(bucketName, order.getMenuUrl())); } } }catch (Exception e){ throw new BaseException(DATABASE_ERROR); } return orderList; }
- ์ฃผ๋ฌธ ๋ด์ญ์ ์์ผ์ด ํฌํจ๋์ด ์๊ธฐ ๋๋ฌธ์, DB์์ ์กฐํ ์ ๋ ์ง+์์ผ ์ ๋ณด๋ฅผ ๊ฐ์ด ๊ฐ์ ธ์ค๋๋ก ํ์๋ค.
- ๊ฐ DBํ ์ด๋ธ์ joinํด์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ด
- ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ๋์ง๋ ๋ทฐ์์ ์๋ณํด์ผํ๊ธฐ ๋๋ฌธ์, ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ์ง ์์๋ค๋ฉด ์กฐ์ธ ํ ์ด๋ธ์ ๋ํ๋์ง ์์์ null ๊ฐ์ ํตํด ์๋ณํ์๋ค.
- Dao
// ์ฃผ๋ฌธ๋ด์ญ ์กฐํ public List<GetOrderListRes> getOrderList(int customerIdx, String[] weekDays) { String query = "SELECT\n" + " O.orderIdx,\n" + " DATE_FORMAT(O.created, '%Y.%m.%d') as orderDate,\n" + " DATE_FORMAT(O.created, '%w') as weekDay,\n" + " S.storeIdx,\n" + " S.store_name,\n" + " M.menu_name,\n" + " M.menu_url,\n" + " TM.price,\n" + " COUNT(OL.orderIdx) as orerItemCount,\n" + " reviewIdx\n" + "FROM Orders O\n" + "LEFT JOIN OrderLists OL on O.orderIdx = OL.orderIdx\n" + "LEFT JOIN TodayMenu TM on TM.todaymenuIdx = OL.todaymenuIdx\n" + "LEFT JOIN Menu M on M.menuIdx = TM.menuIdx\n" + "LEFT JOIN Stores S on O.storeIdx = S.storeIdx\n" + "LEFT JOIN Review R on O.orderIdx = R.orderIdx\n" + "WHERE O.customerIdx = ? AND O.status LIKE '%A%'\n" + "GROUP BY O.orderIdx\n" + "ORDER BY O.created DESC"; return this.jdbcTemplate.query(query, (rs, rowNum) -> new GetOrderListRes( rs.getInt("orderIdx"), rs.getString("orderDate"), rs.getInt("weekDay"), weekDays[rs.getInt("weekDay")], rs.getInt("storeIdx"), rs.getString("store_name"), rs.getString("menu_name"), rs.getString("menu_url"), rs.getInt("price"), rs.getInt("orerItemCount"), rs.getInt("reviewIdx") != 0 ? 1 : 0 ), customerIdx); }
- ์ฃผ๋ฌธ์ ํตํด ๋ณธ์ธ์ด ํ ์ฃผ๋ฌธ ์ ๋ณด๋ฅผ ์์ธํ๊ฒ ์กฐํ
- ์๋ต ๋ฐ๋
- ์ปจํธ๋กค๋ฌ
- ์๋น์ค
public OrderDetailRes getOrderDetail(int orderIdx) throws BaseException{ // 1. ์ฃผ๋ฌธ ์์ธ ๊ธฐ๋ณธ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ OrderDetailRes orderDetails; try{ orderDetails = appOrderDao.getOrderDetail(orderIdx); }catch (Exception e){ throw new BaseException(DATABASE_ERROR); } // 2. ์ฃผ๋ฌธ์ ๋ธ๋ฆฐ ๋ฉ๋ด ์์ธ ์ ๋ด ๊ฐ์ ธ์ค๊ธฐ try{ List<OrderMenuItem> orderItems = appOrderDao.getOrderItems(orderIdx); orderDetails.setOrderMenus(orderItems); return orderDetails; }catch (Exception e){ throw new BaseException(DATABASE_ERROR); } }
- ์ฃผ๋ฌธ ์์ธ๋ฅผ ์ํ ๊ธฐ๋ณธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๊ณ
- ์ฃผ๋ฌธ์ ๋ธ๋ฆฐ ์ฃผ๋ฌธ ํ๋ชฉ ๋ด์ญ๋ค์ ๊ฐ์ด ์กฐํ
- Dao
// ์ฃผ๋ฌธ ์์ธ ๊ธฐ๋ณธ ์ ๋ณด(์๊ฐ, ๊ฐ๊ฒIdx, ๊ฐ๊ฒ์ด๋ฆ, ๊ฐ๊ฒ ์ ํ๋ฒํธ, ๊ธ์ก, ๊ฐ์, ์์ฒญ์ฌํญ, ๊ฒฐ์ ์ ๋ณด) public OrderDetailRes getOrderDetail(int orderIdx) { String query = "SELECT\n" + " DATE_FORMAT(O.created, '%Y๋ %m์ %d์ผ') as orderDate,\n" + " DATE_FORMAT(O.created, '%h:%i:%s') as orderTime,\n" + " DATE_FORMAT(O.created, '%p') as pmam,\n" + " S.storeIdx, S.store_name, S.store_phone,\n" + " CONCAT( M.menu_name, ' ', TM.price, '์') simpleMenu,\n" + " COUNT(OL.orderIdx) count,\n" + " SUM(OL.cnt * TM.price) as totalPrice,\n" + " O.payment_status,\n" + " O.request\n" + "FROM Orders O\n" + " LEFT JOIN OrderLists OL on O.orderIdx = OL.orderIdx\n" + " LEFT JOIN TodayMenu TM on TM.todaymenuIdx = OL.todaymenuIdx\n" + " LEFT JOIN Menu M on M.menuIdx = TM.menuIdx\n" + " LEFT JOIN Stores S on O.storeIdx = S.storeIdx\n" + "WHERE O.orderIdx = ?"; return this.jdbcTemplate.queryForObject(query, (rs, rowNum) -> new OrderDetailRes( rs.getString("orderDate") + " "+ rs.getString("orderTime") + (rs.getString("pmam").equals("AM") ? "AM" : "PM"), rs.getInt("storeIdx"), rs.getString("store_name"), rs.getString("store_phone"), rs.getString("simpleMenu") + (rs.getInt("count") >= 2 ? " ์ธ" + (rs.getInt("count") -1) + "๊ฐ": ""), null, rs.getInt("count"), rs.getInt("totalPrice"), rs.getString("payment_status"), rs.getString("request") ), orderIdx); }
// ๊ฐ๊ฒ ์ด๋ฆ, ์ฃผ๋ฌธํ ๋ฉ๋ด ๊ฐ์, ๋ฉ๋ด ๊ฐ๊ฒฉ, ํ ์ธ์จ, ํ ์ธ๊ฐ๊ฒฉ public List<OrderMenuItem> getOrderItems(int orderIdx) { String query = "SELECT\n" + " M.menu_name, \n" + " OL.cnt,\n" + " M.price, TM.discount, TM.price as todayPrice\n" + "FROM Orders O \n" + " LEFT JOIN OrderLists OL on O.orderIdx = OL.orderIdx\n" + " LEFT JOIN TodayMenu TM on TM.todaymenuIdx = OL.todaymenuIdx\n" + " LEFT JOIN Menu M on M.menuIdx = TM.menuIdx\n" + "WHERE O.orderIdx = ?"; return this.jdbcTemplate.query(query, (rs, rowNum) -> new OrderMenuItem( rs.getString("menu_name"), rs.getInt("cnt"), rs.getInt("price"), rs.getInt("discount"), rs.getInt("todayPrice") ), orderIdx); }
์ฃผ๋ฌธ ๋ด์ญ์ ์กด์ฌํ๋ ์ํ๊ฐ์ 'AD'๋ก ๋ณ๊ฒฝ
'AD' ์ ํจํ ์ฃผ๋ฌธ์ด๋, ๊ตฌ๋งค์๊ฐ ์ฃผ๋ฌธ ๋ด์ญ์ ์ญ์ ํ ์ํ
๊ตฌ๋งค์๋ ๋งค์ถ ์กฐํ ์, ํฝ์ ์๋ฃ ์ฃผ๋ฌธ ์กฐํ์์ ์ํ์ 'A'๊ฐ ํฌํจ๋ ์ฃผ๋ฌธ์ ์กฐํํ๊ฒ ๋จ
์ด๋ฏธ ์ฃผ๋ฌธ ๋๋ฉ์ธ์ ๋ค๋ฃจ๊ธฐ๋ํ์๊ณ , ์ํ๋ณ๋ก ๊ตฌ๋ถํ ํ์ ์์ด ์๋ฃ๋ ์ฃผ๋ฌธ์ ๊ธฐ์ค์ผ๋ก ํ
์ด๋ธ์ ์กฐ์ธ๋ง ํ๋ ์กฐํ๊ฐ ๋๋ถ๋ถ์ด์ฌ์ ๋ณ๋ก ๊ตฌํ์ด ์ด๋ ต์ง ์์!
๊ฒฐ์ ์ ๋ณด ๋ฐ์์ ์ฌํ ํ์ํ๊ธด ํ์ง๋ง ์ฌ์
์ ๋ฑ๋ก์ฆ ์ด์ ๋๋ฌธ์ ๋ถ๊ฐ๋ฅํ๋ ์ด์ฉ์๊ฐ ์๋ค..