๐โ ๋ธ๋ฐ์น ์นดํ๋ฅผ ์ด์์ค์ธ ๋น์ , ๋งค์ผ ์๋ก์ด ์ฌ๋ฃ๋ฅผ ์ฌ๋ฌ ์ ์ฒด์์ ๊ณต๊ธ๋ฐ์ ์์์ ์กฐ๋ฆฌํฉ๋๋ค. ๊ฐ๊ฐ์ ์ ์ฒด์์ ์ฌ๋ฃ๋ฅผ ์ฃผ๋ฌธํ๊ณ ๊ด๋ฆฌํ๋ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด ๋์ฑ ์์ฝ๊ฒ ์ฌ๋ฃ๋ฅผ ์ค๋ํด์! :)
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
username=C##FOOD_PRODUCTS
password=FOOD_PRODUCTS
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--connection-info.properties๋ฅผ ์ฝ์ด์ฌ ๊ฒ
(์๋ value์ ์ง์ ์
๋ ฅํ์ง์๊ณ ${}๋ฅผ ์ด์ฉํ์ฌ ์์ฑ(๋ณด์์ ์ํด ๋ถ๋ฆฌํ์ฌ ์ฌ์ฉ))-->
<properties resource="connection-info.properties"/>
<!-- ๋ณ์นญ ์ค์ -->
<typeAliases>
<typeAlias type="com.joyhyonie.common.SearchCriteria" alias="SerchCriteria"/>
<!-- type="ํด๋์ค๊ฒฝ๋ก" alias="๋ณ์นญ"-->
</typeAliases>
<environments default="dev">
<environment id="dev">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<!-- package์ ๋ช
์นญ์ ์์ฑํ์ฌ ํด๋น ํจํค์ง ํ์์ ์๋ ๋ชจ๋ ํ์ผ์ mapper๋ก ์ฌ์ฉ -->
<package name="com.joyhyonie.foodProducts.mapper"/>
</mappers>
</configuration>
public class SearchCriteria { // ๊ฒ์ ๊ธฐ์ค
private String condition; // ๊ฒ์ ์กฐ๊ฑด
private String value; // ๊ฒ์ํ๋ ค๋ ๋จ์ด
public SearchCriteria() {}
public SearchCriteria(String value) {
super();
this.value = value;
}
public SearchCriteria(String condition, String value) {
super();
this.condition = condition;
this.value = value;
}
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "SearchCriteria [condition=" + condition + ", value=" + value + "]";
}
}
public class Template {
private static SqlSessionFactory sqlSessionFactory;
public static SqlSession getSqlSession() {
if(sqlSessionFactory == null) {
String resource = "mybatis-config.xml";
try {
InputStream inputStream = Resources.getResourceAsStream(resource);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
return sqlSessionFactory.openSession(false);
}
}
-- ํ
์ด๋ธ ์์ฑ
--[ TBL_FOOD_CATEGORY ]
CREATE TABLE TBL_FOOD_CATEGORY(
CATEGORY_CODE NUMBER CONSTRAINT PK_CATEGORY_CODE PRIMARY KEY
, CATEGORY VARCHAR2(30) NOT NULL
);
COMMENT ON COLUMN TBL_FOOD_CATEGORY.CATEGORY_CODE IS '์ํ ์ข
๋ฅ ์ฝ๋';
COMMENT ON COLUMN TBL_FOOD_CATEGORY.CATEGORY IS '์ข
๋ฅ๋ช
';
--[ TBL_SUPPLIER ]
CREATE TABLE TBL_SUPPLIER(
CATEGORY_CODE NUMBER
, SUPPLIER_CODE VARCHAR2(10)
, SUPPLIER_NAME VARCHAR2(30) UNIQUE
, ADDRESS VARCHAR2(80)
, CONTACT_NUMBER VARCHAR2(20) NOT NULL
, ORDER_YN VARCHAR2(10) DEFAULT 'Y' CHECK (ORDER_YN IN('Y', 'N'))
, CONSTRAINT FK_CATEGORY_CODE FOREIGN KEY(CATEGORY_CODE) REFERENCES TBL_FOOD_CATEGORY(CATEGORY_CODE)
, CONSTRAINT PK_SUPPLIER_CODE PRIMARY KEY(SUPPLIER_CODE)
);
COMMENT ON COLUMN TBL_SUPPLIER.CATEGORY_CODE IS '์ํ ์ข
๋ฅ ์ฝ๋';
COMMENT ON COLUMN TBL_SUPPLIER.SUPPLIER_CODE IS '์
์ฒด ์ฝ๋';
COMMENT ON COLUMN TBL_SUPPLIER.SUPPLIER_NAME IS '์
์ฒด๋ช
';
COMMENT ON COLUMN TBL_SUPPLIER.ADDRESS IS '์ฃผ์';
COMMENT ON COLUMN TBL_SUPPLIER.CONTACT_NUMBER IS '์ฐ๋ฝ์ฒ';
COMMENT ON COLUMN TBL_SUPPLIER.ORDER_YN IS '๊ฑฐ๋ ๊ฐ๋ฅ ์ฌ๋ถ';
--[ TBL_PRODUCTS ]
CREATE TABLE TBL_PRODUCTS(
PROD_CODE NUMBER
, PROD_NAME VARCHAR2(30) NOT NULL
, PRICE NUMBER
, SUPPLIER_NAME VARCHAR2(30) NOT NULL
, CONSTRAINT PK_PROD_CODE PRIMARY KEY(PROD_CODE)
);
COMMENT ON COLUMN TBL_PRODUCTS.PROD_CODE IS '์ฌ๋ฃ ์ฝ๋';
COMMENT ON COLUMN TBL_PRODUCTS.PROD_NAME IS '์ฌ๋ฃ๋ช
';
COMMENT ON COLUMN TBL_PRODUCTS.PRICE IS '์ฌ๋ฃ๊ฐ๊ฒฉ';
COMMENT ON COLUMN TBL_PRODUCTS.SUPPLIER_NAME IS '์
์ฒด๋ช
';
--[ TBL_STORAGE ]
CREATE TABLE TBL_STORAGE(
PROD_CODE NUMBER NOT NULL
, PROD_NAME VARCHAR2(30) NOT NULL
, INCOMING_DATE VARCHAR2(10) NOT NULL
);
COMMENT ON COLUMN TBL_STORAGE.PROD_CODE IS '์ฌ๋ฃ ์ฝ๋';
COMMENT ON COLUMN TBL_STORAGE.PROD_NAME IS '์ฌ๋ฃ๋ช
';
COMMENT ON COLUMN TBL_STORAGE.INCOMING_DATE IS '์
๊ณ ๋ ์ง';
--[ TBL_ORDER_HISTORY ]
CREATE TABLE TBL_ORDER_HISTORY(
ORDER_CODE NUMBER
, ORDER_DATE VARCHAR2(10) NOT NULL
, ORDER_TIME VARCHAR2(10)
, TOTAL_PRICE NUMBER NOT NULL
, CONSTRAINT PK_ORDER_CODE PRIMARY KEY(ORDER_CODE)
);
COMMENT ON COLUMN TBL_ORDER_HISTORY.ORDER_CODE IS '์ฃผ๋ฌธ์ฝ๋';
COMMENT ON COLUMN TBL_ORDER_HISTORY.ORDER_DATE IS '์ฃผ๋ฌธ์ผ์';
COMMENT ON COLUMN TBL_ORDER_HISTORY.ORDER_TIME IS '์ฃผ๋ฌธ์๊ฐ';
COMMENT ON COLUMN TBL_ORDER_HISTORY.TOTAL_PRICE IS '์ฃผ๋ฌธ์ด์ก';
--์ํ์ค ์์ฑ
--[ CATEGORY_CODE ]
CREATE SEQUENCE SEQ_CATEGORY_CODE
START WITH 1
INCREMENT BY 1
MAXVALUE 10
NOCYCLE
NOCACHE;
--[ PROD_CODE ]
CREATE SEQUENCE SEQ_PROD_CODE
START WITH 100
INCREMENT BY 1
MAXVALUE 999
NOCYCLE
NOCACHE;
--[ ORDER_CODE ]
CREATE SEQUENCE SEQ_ORDER_CODE
START WITH 1000
INCREMENT BY 1
MAXVALUE 9999
NOCYCLE
NOCACHE;
--์ปฌ๋ผ ๊ฐ ์ฝ์
--[ TBL_FOOD_CATEGORY ]
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '์ก๋ฅ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '์ด๋ฅ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๊ณผ์ผ,์ฑ์๋ฅ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '์ ์ ํ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๋๋์ํ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๊ฑด์กฐ์ํ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๊ธฐํ');
--[ TBL_SUPPLIER ]
INSERT INTO TBL_SUPPLIER VALUES(1, '1A', '๊ตฝ๋ค์ ์ก', '์์ธ์ ์ฑ๋๊ตฌ ๋ง์ฅ๋ ๊ณ ๊น๊ธธ 79', '02-6549-2341', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(2, '2A', '๋ฐ๋คํ์ฌ๋', '์์ธ์ ๋์๊ตฌ ๋
ธ๋์ง์์ฐ๋ฌผ๋๋งค์์ฅ 7-A', '02-4061-0605', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(3, '3A', 'SING์ฑ์ฑ์' , '์์ธ์ ๋๋๋ฌธ๊ตฌ ์ ๊ธฐ๋ ์ฒญ๋๋ฆฌ์ฒญ๊ณผ๋ฌผ์์ฅ 185ํธ', '070-3059-4953', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(3, '3B', '๋ฒ ์ง์ํ', '๊ฒฝ๊ธฐ๋ ๋จ์์ฃผ์ ์ผ์ฑ๋ก2๊ธธ 71', '031-3421-5800', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(4, '4A', '์น์ฆFARM', '๊ฒฝ๊ธฐ๋ ํ์ฃผ์ ์ฐ์ ๋ฆฌ 921-12', '031-9372-0221', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(5, '5A', '์ผ์๋กํธ๋', '์์ธ์ ์ข
๋ก๊ตฌ ๊ฝ๊ฝ3๊ฐ 2-38', '02-5068-4480', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(6, '6A', '์งฑ๊ตฌ๋๋ง๋ ค', '๊ฒฝ๊ธฐ๋ ํ๋จ์ ํฐ๋ฅ๋ก 600', '070-3242-1666', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(7, '7A', '๊ผฌ์๋ด๋ฐฉ์๊ฐ', '๊ฒฝ๊ธฐ๋ ์ด์ฒ์ ๋ฌด์ด๋ฆฌ 52-7', '031-2221-5838', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(7, '7B', 'EGG๋จธ๋๋', '์์ธ์ ๋๋ด๊ตฌ ๋ณ์๋ฆฌ๊ธธ 92', '02-7483-8812', DEFAULT);
--[ TBL_PRODUCTS ]
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ ๋ฑ์ฌ', 20000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ ์์ฌ', 23000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ ๋ค์ง์ก', 15000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ผ์ง ๋ฑ์ฌ', 10000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ผ์ง ์์ฌ', 15000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ผ์ง ๋ค์ง์ก', 8000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ญ ์์ฌ', 7000, '๊ตฝ๋ค์ ์ก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ฐ์ด', 20000, '๋ฐ๋คํ์ฌ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์์ฐ', 11000, '๋ฐ๋คํ์ฌ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ค์ง์ด', 5000, '๋ฐ๋คํ์ฌ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฐ์๋ฏธ', 10000, '๋ฐ๋คํ์ฌ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฐ์ง๋ฝ', 5000, '๋ฐ๋คํ์ฌ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ชจ์์กฐ๊ฐ', 6000, '๋ฐ๋คํ์ฌ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋น๊ทผ', 3000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ํ', 4000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์๋ฌ๋ฆฌ', 3000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์๋ฐฐ์ถ', 6000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋นํธ', 3000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฐ์', 4000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ณ ๊ตฌ๋ง', 4000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํธ๋ฐ', 8000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ธ๊ธฐ', 7000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฐ๋๋', 4000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํค์', 8000, 'SING์ฑ์ฑ์');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ก์ฆ๋ง๋ฆฌ', 7000, '๋ฒ ์ง์ํ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ชฝํ', 4000, '๋ฒ ์ง์ํ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊นป์', 2000, '๋ฒ ์ง์ํ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฌด์', 4000, '๋ฒ ์ง์ํ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์์ก์ด๋ฒ์ฏ', 5000, '๋ฒ ์ง์ํ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋', 7000, '๋ฒ ์ง์ํ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ฐ์ ', 4000, '์น์ฆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ํฌ๋ฆผ', 7000, '์น์ฆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ฒด๋ค์น์ฆ', 5000, '์น์ฆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํฌ๋ฆผ์น์ฆ', 7000, '์น์ฆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฆฌ์ฝํ์น์ฆ', 9000, '์น์ฆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋๋๊ฐ์ํ๊น', 10000, '์ผ์๋กํธ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋๋๊ณ ๊ตฌ๋งํ๊น', 12000, '์ผ์๋กํธ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋๋๋ง๋', 7000, '์ผ์๋กํธ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋๋๋ธ๋ฃจ๋ฒ ๋ฆฌ', 15000, '์ผ์๋กํธ๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํธ๋ฐ์จ', 5000, '์งฑ๊ตฌ๋๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํด๋ฐ๋ผ๊ธฐ์จ', 4000, '์งฑ๊ตฌ๋๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฑดํฌ๋', 4000, '์งฑ๊ตฌ๋๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฑดํฌ๋๋ฒ ๋ฆฌ', 6000, '์งฑ๊ตฌ๋๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ณฐํ๋ฐ๊ฐ๋ฃจ', 6000, '๊ผฌ์๋ด๋ฐฉ์๊ฐ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์๊ฐ๋ฃจ', 8000, '๊ผฌ์๋ด๋ฐฉ์๊ฐ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋นต๊ฐ๋ฃจ', 4000, '๊ผฌ์๋ด๋ฐฉ์๊ฐ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ฝฉ๊ฐ๋ฃจ', 3000, '๊ผฌ์๋ด๋ฐฉ์๊ฐ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ ๊ธฐ๋ ๋ฌ๊ฑ', 10000, 'EGG๋จธ๋๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํ์ ๋ฌ๊ฑ', 8000, 'EGG๋จธ๋๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํน๋ ๋ฌ๊ฑ', 7000, 'EGG๋จธ๋๋');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ผ๋ฐ ๋ฌ๊ฑ', 5000, 'EGG๋จธ๋๋');
--[ TBL_STORAGE ]
INSERT INTO TBL_STORAGE VALUES(101, '์ ์์ฌ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(105, '๋ผ์ง ๋ค์ง์ก', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(108, '์์ฐ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(112, '๋ชจ์์กฐ๊ฐ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(116, '์๋ฐฐ์ถ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(122, '๋ฐ๋๋', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(131, '์ํฌ๋ฆผ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(138, '๋๋๋ธ๋ฃจ๋ฒ ๋ฆฌ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(143, '๋ฐ๊ฐ๋ฃจ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(147, '์ ๊ธฐ๋ ๋ฌ๊ฑ', SYSDATE);
COMMIT;
public class FoodCategoryDTO {
private int categoryCode;
private String category;
/* ๊ธฐ๋ณธ ์์ฑ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์์ฑ์ */
/* getter & setter */
/* toStirng */
}
public class FoodProductsDTO {
private int prodCode;
private String prodName;
private int price;
private String supplierName;
/* ๊ธฐ๋ณธ ์์ฑ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์์ฑ์ */
/* getter & setter */
@Override
public String toString() {
return "-----------------------\n" + "|" + prodCode + "| " + prodName + " | " + price
+ "์ | [" + supplierName + "]";
}
}
public class StorageDTO {
private int prodCode;
private String prodName;
private String incomingDate;
/* ๊ธฐ๋ณธ ์์ฑ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์์ฑ์ */
/* getter & setter */
@Override
public String toString() {
return "[" + incomingDate + "์
๊ณ ] " + "|" + prodCode + "| " + prodName;
}
}
public class SupplierDTO {
private int categoryCode;
private String supplierCode;
private String supplierName;
private String address;
private String contactNumber;
private String orderYn;
private FoodCategoryDTO foodCategory; // TBL_FOOD_CATEGORY์ category๋ฅผ ํจ๊ป ์ถ๋ ฅํ๊ธฐ ์ํด ์ถ๊ฐ <association>
/* ๊ธฐ๋ณธ ์์ฑ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์์ฑ์ */
/* getter & setter */
@Override
public String toString() {
return "[" + supplierName + "]-----------------------\n* " + foodCategory + "์
์ฒด(" + categoryCode + ")\n* ์
์ฒด์ฝ๋ : " + supplierCode + "\n* ์ฃผ์ : " + address +
"\n* ์ฐ๋ฝ์ฒ : " + contactNumber + "\n* ๊ฑฐ๋๊ฐ๋ฅ์ฌ๋ถ : " + orderYn + "\n";
}
}
public class OrderHistoryDTO {
private int orderCode;
private String orderDate;
private String orderTime;
private int totalPrice;
private List<StorageDTO> storageDTO;
// ์ฃผ๋ฌธ๋ด์ญ๊ณผ ์ฃผ๋ฌธํ ์ฌ๋ฃ๋ฅผ ํ๋์ ํธ๋์ญ์
์์์ INSERTํ๊ธฐ ์ํด List<StorageDTO> ํ๋ ์์ฑ
/* ๊ธฐ๋ณธ ์์ฑ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์์ฑ์ */
/* getter & setter */
@Override
public String toString() {
return "|" + orderCode + "|์ฃผ๋ฌธ์ผ์ " + orderDate + "|์ฃผ๋ฌธ์๊ฐ " + orderTime
+ "|์ด์ก " + totalPrice + "์";
}
}
/* ํ
์ด๋ธ์ ์ํ DTO๊ฐ ์๋ ์ค๋ํ ๋ชฉ๋ก์ ์ถ๋ ฅ ๋ฐ ๋ด๊ธฐ ์ํ DTO */
public class OrderProductsDTO {
private int prodCode;
private String prodName;
private int price;
private String supplierName;
/* ๊ธฐ๋ณธ ์์ฑ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์์ฑ์ */
/* getter & setter */
@Override
public String toString() {
return "-----------------------\n" + "|" + prodCode + "| " + prodName + " | " + price
+ "์ | [" + supplierName + "]";
}
}
public class MainView {
private static Scanner sc = new Scanner(System.in);
private static FoodProductsController fpController = new FoodProductsController();
public void displayView() {
do {
System.out.println("");
System.out.println("=====[ ์ฌ๋ฃ ์ฃผ๋ฌธ ๋ฐ ๊ด๋ฆฌ ํ๋ก๊ทธ๋จ ]=====");
System.out.println("[A] ์ฌ๋ฃ ์ฃผ๋ฌธํ๊ธฐ");
System.out.println("[B] ์ฌ๋ฃ ๊ด๋ฆฌํ๊ธฐ");
System.out.println("[C] ์ํ๋ ์ฌ๋ฃ ํ๋งค ์ ์ํ๊ธฐ");
System.out.println("[D] ์
์ฒด ๊ด๋ฆฌํ๊ธฐ");
System.out.println("[E] ์ฃผ๋ฌธ๋ด์ญ ์กฐํํ๊ธฐ");
System.out.println("[Z] ํ๋ก๊ทธ๋จ ์ข
๋ฃํ๊ธฐ");
System.out.print("๋ฉ๋ด ์ ํ : ");
char ch = sc.nextLine().toUpperCase().charAt(0);
switch(ch) {
case 'A': orderNewProduct(); break;
case 'B': manageStorage(); break;
case 'C': suggestNewProduct(); break;
case 'D': manageSupplier(); break;
case 'E': fpController.selectOrderHistory(manageOrderHistory()); break;
case 'Z': System.out.println("ํ๋ก๊ทธ๋จ์ด ์ข
๋ฃ๋์์ต๋๋ค :D"); return;
default : System.out.println("์๋ชป ๋ ๋ฒํธ์
๋๋ค! ๋ค์ ์
๋ ฅํด์ฃผ์ธ์ :(");
}
} while(true);
}
/* [1] ์ฌ๋ฃ ์ฃผ๋ฌธํ๊ธฐ */
private static void orderNewProduct() {
do {
System.out.println("");
System.out.println("=====[ ์ฌ๋ฃ ์ฃผ๋ฌธํ๊ธฐ ]=====");
System.out.println("[A] ์ค๋์ ์ฌ๋ฃ ๋จผ์ ์ถ์ฒ๋ฐ๊ธฐ");
System.out.println("[B] ๊ฐ ์
์ฒด๋ง๋ค์ ์ฌ๋ฃ ์กฐํํ๊ธฐ");
System.out.println("[C] ์ฃผ๋ฌธ ์์ํ๊ธฐ");
System.out.println("[Z] โ ๋์๊ฐ๊ธฐ");
System.out.print("๋ฉ๋ด ์ ํ : ");
char ch = sc.nextLine().toUpperCase().charAt(0);
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
switch(ch) {
case 'A' : fpController.selectRandomProducts(pickRandomProducts()); break;
case 'B' : fpController.selectProductsBySupplier(pickSupplier()); break;
case 'C' : fpController.insertOrderedProducts(OrderedProducts()); break;
case 'Z' : return;
}
} while(true);
}
/* [1-1] ์ค๋์ ์ฌ๋ฃ ์ถ์ฒ๋ฐ๊ธฐ */
private static List<Integer> pickRandomProducts() {
Set<Integer> set = new HashSet<>();
while(set.size() < 3) {
int temp = ((int) (Math.random() * 50)) + 100;
set.add(temp);
}
List<Integer> list = new ArrayList<>(set);
return list;
}
/* [1-2] ๊ฐ ์
์ฒด๋ง๋ค์ ์ฌ๋ฃ ์กฐํํ๊ธฐ */
private static SearchCriteria pickSupplier() {
System.out.println("");
System.out.println("=====[ ์
์ฒด ์ ํํ๊ธฐ ]=====");
System.out.println("[A] ๊ตฝ๋ค์ ์ก");
System.out.println("[B] ๋ฐ๋คํ์ฌ๋");
System.out.println("[C] SING์ฑ์ฑ์");
System.out.println("[D] ๋ฒ ์ง์ํ");
System.out.println("[E] ์น์ฆFARM");
System.out.println("[F] ์ผ์๋กํธ๋");
System.out.println("[G] ์งฑ๊ตฌ๋๋ง๋ ค");
System.out.println("[H] ๊ผฌ์๋ด๋ฐฉ์๊ฐ");
System.out.println("[I] EGG๋จธ๋๋");
System.out.print("๋ฉ๋ด ์ ํ : ");
String value = sc.nextLine().toUpperCase();
return new SearchCriteria(value);
}
/* [1-3] ์ฃผ๋ฌธ ์์ํ๊ธฐ */
private static OrderHistoryDTO OrderedProducts() {
/* [1-3A] ์ ์ฒด ์ฌ๋ฃ ์กฐํํ์ฌ ๋ฆฌ์คํธ์ ๋ด๊ธฐ */
List<FoodProductsDTO> allProductsList = fpController.selectAllProducts();
/* ์ฃผ๋ฌธ๋ค์ ๋ด๊ธฐ ์ํ ๋ฆฌ์คํธ */
List<OrderProductsDTO> orderProductsList = new ArrayList<>();
int totalPrice = 0;
/* ์ฃผ๋ฌธํ ์ฌ๋ฃ๋ค ๋ด๊ธฐ์ฉ */
List<StorageDTO> productsToStorageList = new ArrayList<>();
do {
System.out.println("");
System.out.println("=====[ ์ฃผ๋ฌธ์ค... ]=====");
System.out.print("์ฃผ๋ฌธํ ์ฌ๋ฃ๋ช
์
๋ ฅ : ");
String prodName = sc.nextLine();
int prodCode = 0;
int prodPrice = 0;
String suppName = null;
for(FoodProductsDTO prod : allProductsList) {
if(prod.getProdName().equals(prodName)) {
prodCode = prod.getProdCode();
prodPrice = prod.getPrice();
suppName = prod.getSupplierName();
}
}
/* ์ฃผ๋ฌธํ ์ฌ๋ฃ(๋ค) ์ ์ฅ */
OrderProductsDTO orderProducts = new OrderProductsDTO();
orderProducts.setProdName(prodName);
orderProducts.setProdCode(prodCode);
orderProducts.setPrice(prodPrice);
orderProducts.setSupplierName(suppName);
orderProductsList.add(orderProducts); // orderProductsList์ ์ฃผ๋ฌธํ ๊ฒ๋ค ์ถ๊ฐ
totalPrice += prodPrice; // ์ด์ก ๊ณ์ฐ
System.out.print("๊ณ์ ์ฃผ๋ฌธํ์๊ฒ ์ด์? :)\n(Y/N) : ");
boolean isContinue = sc.nextLine().toUpperCase().equals("Y");
/* [1-3C] ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
java.util.Date orderDate = new java.util.Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd");
String incomingDate = dateFormat.format(orderDate);
StorageDTO storage = new StorageDTO();
storage.setProdCode(prodCode);
storage.setProdName(prodName);
storage.setIncomingDate(incomingDate);
productsToStorageList.add(storage);
if(!isContinue) break;
} while(true);
// fpController.insertProductsToStorage(productsToStorageList);
// ์ฌ๋ฃ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ ์ฃผ๋ฌธ๋ด์ญ๊ณผ ํจ๊ป INSERT ๋์ด์ผํจ
for(OrderProductsDTO orderMenu : orderProductsList) {
System.out.println(orderMenu);
}
System.out.println("-----------------------\n์ด์ก : " + totalPrice + "์");
/* [1-3B] ์ฃผ๋ฌธํ ๋ด์ญ ์ ์ฅํ๊ธฐ */
java.util.Date orderTime = new java.util.Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd");
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
String date = dateFormat.format(orderTime);
String time = timeFormat.format(orderTime);
OrderHistoryDTO order = new OrderHistoryDTO();
order.setOrderDate(date);
order.setOrderTime(time);
order.setTotalPrice(totalPrice);
order.setStorageDTO(productsToStorageList);
/* ์ฃผ๋ฌธ๋ด์ญ๊ณผ ์ฃผ๋ฌธํ ์ฌ๋ฃ๋ฅผ ํ๋์ ํธ๋์ญ์
์์์ INSERTํ๊ธฐ ์ํด
(๋ ์ค์ ํ๋๋ผ๋ ๋ฌธ์ ๊ฐ ์๋ค๋ฉด, ๋๋จธ์ง ํ๋๋ ์๋๋์ด์ ์๋จ)
* StorageDTO๋ฅผ OrderHistoryDTO์ ํ๋์ ์ ์ธํ ๋ค,
* productsToStorageList๋ฅผ StorageDTO์ setํ์ฌ ํจ๊ป ์ธ์๋ก ์ ๋ฌ */
return order;
}
/* [2] ์ฌ๋ฃ ๊ด๋ฆฌํ๊ธฐ */
private static void manageStorage() {
do {
System.out.println("");
System.out.println("=====[ ์ฌ๋ฃ ๊ด๋ฆฌํ๊ธฐ ]=====");
System.out.println("[A] ์ฌ๋ฃ ํ์
ํ๊ธฐ");
System.out.println("[B] ์ฌ๋ฃ ์ฌ์ฉํ๊ธฐ");
System.out.println("[C] ์ํ ์ฌ๋ฃ ๊ตํ๋ฐ๊ธฐ");
System.out.println("[D] ์ค๋๋ ์ฌ๋ฃ ๋ชจ๋ ํ๊ธฐํ๊ธฐ");
System.out.println("[Z] โ ๋์๊ฐ๊ธฐ");
System.out.print("๋ฉ๋ด ์ ํ : ");
char ch = sc.nextLine().toUpperCase().charAt(0);
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
switch(ch) {
case 'A' : fpController.selectProductsBySomething(inputSearchCriteria()); break;
case 'B' : fpController.deletePickedProduct(useProduct()); break;
case 'C' : fpController.updatePickedProduct(changeProduct()); break;
case 'D' : fpController.deleteOldProducts(throwAwayOldProducts()); break;
case 'Z' : return;
}
} while(true);
}
/* [2-1] ์ฌ๋ฃ ํ์
ํ๊ธฐ */
private static SearchCriteria inputSearchCriteria() {
System.out.println("");
System.out.println("=====[ ์ฌ๋ฃ ํ์
ํ๊ธฐ ]=====");
System.out.println("| ์ ์ฒด | ์ฌ๋ฃ๋ช
๋ณ |");
System.out.print("์ฌ๋ฃ ๋ชฉ๋ก ๊ธฐ์ค ์ ํ : ");
String condition = sc.nextLine();
String value = null;
if(condition.equals("์ฌ๋ฃ๋ช
๋ณ")) {
System.out.print("์ฌ๋ฃ๋ช
์
๋ ฅ : ");
value = sc.nextLine();
}
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
return new SearchCriteria(condition, value);
}
/* [2-2] ์ฌ๋ฃ ์ฌ์ฉํ๊ธฐ */
private static Map<String, String> useProduct() {
System.out.println("");
System.out.println("=====[ ์ฌ๋ฃ ์ฌ์ฉํ๊ธฐ ]=====");
System.out.print("์ฌ์ฉํ ์ฌ๋ฃ๋ช
์
๋ ฅ : ");
String prodName = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
Map<String, String> param = new HashMap<>();
param.put("prodName", prodName);
return param;
}
/* [2-3] ์ํ ์ฌ๋ฃ ๊ตํ๋ฐ๊ธฐ */
private static Map<String, String> changeProduct() {
System.out.println("");
System.out.println("=====[ ์ํ ์ฌ๋ฃ ๊ตํ๋ฐ๊ธฐ ]=====");
System.out.print("์ํ ์ฌ๋ฃ๋ช
์
๋ ฅ : ");
String prodName = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
Map<String, String> param = new HashMap<>();
param.put("prodName", prodName);
return param;
}
/* [2-4] ์ค๋๋ ์ฌ๋ฃ ๋ชจ๋ ํ๊ธฐํ๊ธฐ */
private static Map<String, String> throwAwayOldProducts() {
System.out.println("");
System.out.println("=====[ ์ค๋๋ ์ฌ๋ฃ ๋ชจ๋ ํ๊ธฐํ๊ธฐ ]=====");
System.out.println("๋ฉฐ์น ์ด์ ์ง๋ ์ฌ๋ฃ๋ฅผ ํ๊ธฐํ์๊ฒ ์ต๋๊น?");
System.out.print("์ผ์ ์
๋ ฅ : ");
String days = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
Map<String, String> param = new HashMap<>();
param.put("days", days);
return param;
}
/* [3] ์ํ๋ ์ฌ๋ฃ ํ๋งค ์ ์ํ๊ธฐ */
private static void suggestNewProduct() {
System.out.println("");
System.out.println("=====[ ์ํ๋ ์ฌ๋ฃ ํ๋งค ์ ์ํ๊ธฐ ]=====");
System.out.print("ํ๋งค๋ฅผ ์ ์ํ ์
์ฒด๋ช
์ ์
๋ ฅํด์ฃผ์ธ์ :)\n : ");
String supplier = sc.nextLine();
System.out.print("์ํ๋ ์ฌ๋ฃ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์ :)\n : ");
String product = sc.nextLine();
System.out.print("์ํ๋ ๊ฐ๊ฒฉ์ ์ ์ํด์ฃผ์ธ์ :)\n : ");
String price = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
int intPrice = Integer.parseInt(price);
if(intPrice > 5000) {
Map<String, String> param = new HashMap<>();
param.put("supplier", supplier);
param.put("product", product);
param.put("price", price);
fpController.insertNewProduct(param);
} else {
System.out.println("์ ์ํ์ ๊ธ์ก์ด ๋๋ฌด ์ ์ด ์
์ฒด๊ฐ ๊ฑฐ์ ํ์ต๋๋ค :(");
}
}
/* [4] ์
์ฒด ๊ด๋ฆฌํ๊ธฐ */
private static void manageSupplier() {
do {
System.out.println("");
System.out.println("=====[ ์
์ฒด ๊ด๋ฆฌํ๊ธฐ ]=====");
System.out.println("[A] ๋ชจ๋ ์
์ฒด ์กฐํํ๊ธฐ");
System.out.println("[B] ์ ๋ณด ๋ณ๊ฒฝํ๊ธฐ");
System.out.println("[C] ๊ณ์ฝ ํด์งํ๊ธฐ");
System.out.println("[Z] โ ๋์๊ฐ๊ธฐ");
System.out.print("๋ฉ๋ด ์ ํ : ");
char ch = sc.nextLine().toUpperCase().charAt(0);
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
switch(ch) {
case 'A' : fpController.selectAllSupplier(); break;
case 'B' : fpController.updateSupplierInfo(modifySupplier()); break;
case 'C' : System.out.println("------------[WARNING]------------\n๊ณ์ฝ์ ํด์งํ ์, ์ฌ๊ณ์ฝ์ ๋ถ๊ฐ๋ฅํฉ๋๋ค. ๊ณ์ ์งํํ์๊ฒ ์ต๋๊น?\n(ํด๋น ์
์ฒด์ ์ฌ๋ฃ ๋ํ ์ฃผ๋ฌธ๋ถ๊ฐ)");
System.out.print("(Y/N) : ");
char yn = sc.nextLine().toUpperCase().charAt(0);
if(yn == 'N') {
return;
} else
System.out.println("์์ ํ ๊ณ์ฝ ํด์ง๋ฅผ ์ํด ์๋์ ๋ฌธ์๋ฅผ ์๋ง์ ์์๋ก ์
๋ ฅํด์ฃผ์ธ์ :)");
System.out.print("[ ofdo ]\n : ");
String word = sc.nextLine();
if(word.equals("food")) {
fpController.deleteSupplier(cancelSupplier()); break;
} else {
System.out.println("๋ฌธ์์ ์์๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์์ :( ๋ฉ์ธ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค !"); return;
}
case 'Z' : return;
}
} while(true);
}
/* [4-2] ์ ๋ณด ๋ณ๊ฒฝํ๊ธฐ */
private static Map<String, String> modifySupplier() {
System.out.println("");
System.out.println("=====[ ์ ๋ณด ๋ณ๊ฒฝํ๊ธฐ ]=====");
System.out.print("๋ณ๊ฒฝํ ์
์ฒด๋ช
์
๋ ฅ : ");
String suppName = sc.nextLine();
System.out.println("*๋ณ๊ฒฝํ๊ณ ์ ํ๋ ์ ๋ณด๋ง ์
๋ ฅํ์
๋ ๋ฉ๋๋ค !* โถ ENTER");
sc.nextLine();
System.out.print("์๋ก์ด ์ฃผ์ ์
๋ ฅ : ");
String newAddress = sc.nextLine();
System.out.print("์๋ก์ด ์ฐ๋ฝ์ฒ ์
๋ ฅ : ");
String newContactNumber = sc.nextLine();
System.out.print("๊ฑฐ๋๊ฐ๋ฅ์ฌ๋ถ ์
๋ ฅ : ");
String newOrderYn = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
Map<String, String> param = new HashMap<>();
param.put("suppName", suppName);
param.put("newAddress", newAddress);
param.put("newContactNumber", newContactNumber);
param.put("newOrderYn", newOrderYn);
return param;
}
/* [4-3] ๊ณ์ฝ ํด์งํ๊ธฐ */
private static Map<String, String> cancelSupplier() {
System.out.println("");
System.out.println("=====[ ๊ณ์ฝ ํด์งํ๊ธฐ ]=====");
System.out.print("์
์ฒด๋ช
์
๋ ฅ : ");
String suppName = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
Map<String, String> param = new HashMap<>();
param.put("suppName", suppName);
return param;
}
/* [5] ์ฃผ๋ฌธ๋ด์ญ ์กฐํํ๊ธฐ */
private static Map<String, String> manageOrderHistory() {
System.out.println("");
System.out.println("=====[ ์ฃผ๋ฌธ๋ด์ญ ์กฐํํ๊ธฐ ]=====");
System.out.println("| ์ต์ ์ | ๊ณผ๊ฑฐ์ |");
System.out.print(" : ");
String range = sc.nextLine();
System.out.println("์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์ :)");
Map<String, String> param = new HashMap<>();
param.put("range", range);
return param;
}
}
public class ResultView {
/* ์ฌ๋ฃ ๋ฆฌ์คํธ ์ถ๋ ฅ */
public void printProductsList(List<FoodProductsDTO> ProductsList) {
for(FoodProductsDTO o : ProductsList) {
System.out.println(o);
}
}
/* ์
์ฒด ๋ฆฌ์คํธ ์ถ๋ ฅ */
public void printSupplierList(List<SupplierDTO> allSupplierList) {
for(SupplierDTO o : allSupplierList) {
System.out.println(o);
}
}
/* ์ฃผ๋ฌธ๋ด์ญ ๋ฆฌ์คํธ ์ถ๋ ฅ */
public void printOrderHistoryList(List<OrderHistoryDTO> orderHistoryList) {
for(OrderHistoryDTO o : orderHistoryList) {
System.out.println(o);
}
}
/* CompleteMessage */
public void printCompleteMessage(String completeCode) {
String completeMessage = "";
switch(completeCode) {
case "successInsertOrderedProducts" : completeMessage = "์ฑ๊ณต์ ์ผ๋ก ์ฃผ๋ฌธ์ด ์๋ฃ๋์ด ์ฌ๋ฃ๊ฐ ์ฆ์ ์
๊ณ ๋์์ด์ :D"; break;
case "successDeletePickedProduct" : completeMessage = "์ฌ๋ฃ๋ฅผ ์ฌ์ฉํ์์ต๋๋ค :D"; break;
case "successUpdatePickedProduct" : completeMessage ="์ฑ์ฑํ ์ฌ๋ฃ๋ก ๊ตํ ์๋ฃ๋์์ต๋๋ค :D"; break;
case "successDeleteOldProducts" : completeMessage = "์ค๋๋ ์ฌ๋ฃ๋ฅผ ๋ชจ๋ ํ๊ธฐ ์๋ฃํ์์ต๋๋ค :D"; break;
case "successInsertNewProduct" : completeMessage = "์
์ฒด๊ฐ ํ๋งค ์ ์์ ๋ฐ์๋ค์ฌ ์ด์ ๋ถํฐ ์ฃผ๋ฌธ์ด ๊ฐ๋ฅํฉ๋๋ค :D"; break;
case "successUpdateSupplierInfo" : completeMessage = "์
์ฒด ์ ๋ณด๊ฐ ์ ์์ ์ผ๋ก ๋ณ๊ฒฝ๋์์ต๋๋ค :D"; break;
case "successDeleteSupplier" : completeMessage = "๊ณ์ฝ์ด ์ ์์ ์ผ๋ก ํด์ง๋์์ต๋๋ค :D"; break;
}
System.out.println(completeMessage);
}
/* ErrorMessages */
public void printErrorMessage(String errorCode) {
String errorMessage = "";
switch(errorCode) {
case "failSelectRandomProducts" : errorMessage = "์ค๋์ ์ฌ๋ฃ๋ฅผ ์ฐพ์ง ๋ชป ํ์ด์ :("; break;
case "failSelectProductsBySupplier" : errorMessage = "์ฌ๋ฃ๋ค์ ๋ถ๋ฌ์ค์ง ๋ชป ํ์ด์ :("; break;
case "failInsetOrderedProducts" : errorMessage = "์ฃผ๋ฌธํ์ ๋ด์ญ์ด ์ ๋ฌ๋์ง ๋ชป ํ์ด์ :("; break;
case "failInsertProductsToStorage" : errorMessage = "์
๊ณ ๋ํ ์คํจํ์ต๋๋ค :( "; break;
case "failSelectProductsBySomething" : errorMessage = "์ฌ๋ฃ ํ์
์ ์คํจํ์ต๋๋ค :("; break;
case "failDeletePickedProduct" : errorMessage = "์ฌ๋ฃ๋ฅผ ์ฌ์ฉํ์ง ๋ชป ํ์ต๋๋ค :("; break;
case "failUpdatePickedProduct" : errorMessage = "์ฌ๋ฃ๋ฅผ ๊ตํ๋ฐ์ง ๋ชป ํ์ต๋๋ค :("; break;
case "failDeleteOldProducts" : errorMessage = "ํด๋น ์ผ์๊ฐ ์ง๋ ์ฌ๋ฃ๊ฐ ์์ต๋๋ค :("; break;
case "failInsertNewProduct" : errorMessage = "๋๋ด ์ ์์ด ๊ฑฐ์ ๋นํ์ต๋๋ค :("; break;
case "failSelectAllSupplier" : errorMessage = "์
์ฒด ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ค์ง ๋ชป ํ์ต๋๋ค :("; break;
case "failUpdateSupplierInfo" : errorMessage = "์
์ฒด๋ช
์ด ์ฌ๋ฐ๋ฅด์ง ์์ ์ ๋ณด ๋ณ๊ฒฝ์ ์คํจํ์ต๋๋ค :("; break;
case "failDeleteSupplier" : errorMessage = "์
์ฒด๋ช
์ด ์ฌ๋ฐ๋ฅด์ง ์์ ๊ณ์ฝ ํด์ง์ ์คํจํ์ต๋๋ค :("; break;
case "failSelectOrderHistory" : errorMessage = "์ฃผ๋ฌธ๋ด์ญ์ ๋ถ๋ฌ์ค์ง ๋ชป ํ์ต๋๋ค :("; break;
}
System.out.println(errorMessage);
}
}
public class FoodProductsController {
private final FoodProductsService fpService;
private final ResultView rView;
// ์์ ํ๋๋ค์ ์์ฑ์์์ ์ด๊ธฐํ
public FoodProductsController() {
fpService = new FoodProductsService();
rView = new ResultView();
}
/* [1-1] ์ค๋์ ์ฌ๋ฃ ์ถ์ฒ๋ฐ๊ธฐ */
public void selectRandomProducts(List<Integer> list) {
List<FoodProductsDTO> RandomProductsList = fpService.selectRandomProducts(list);
/* ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ค Result View */
if(RandomProductsList != null) {
rView.printProductsList(RandomProductsList);
} else {
rView.printErrorMessage("failSelectRandomProducts");
}
}
/* [1-2] ์ ํต์
์ฒด ์ ํํ๊ธฐ */
public void selectProductsBySupplier(SearchCriteria searchCriteria) {
List<FoodProductsDTO> ProductsListBySupplier = fpService.selectProductsBySupplier(searchCriteria);
if(ProductsListBySupplier != null) {
rView.printProductsList(ProductsListBySupplier);
} else {
rView.printErrorMessage("failSelectProductsBySupplier");
}
}
/* [1-3A] ์ ์ฒด ์ฌ๋ฃ ์กฐํํ์ฌ ๋ฆฌ์คํธ์ ๋ด๊ธฐ */
public List<FoodProductsDTO> selectAllProducts() {
List<FoodProductsDTO> allProductsList = fpService.selectAllProducts();
return allProductsList;
}
/* [1-3B] ์ฃผ๋ฌธํ ๋ด์ญ ์ ์ฅํ๊ธฐ / [1-3C] ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
public void insertOrderedProducts(OrderHistoryDTO order) {
if(fpService.insertOrderedProducts(order)) {
rView.printCompleteMessage("successInsertOrderedProducts");
} else {
rView.printErrorMessage("failInsetOrderedProducts");
}
}
/* [1-3C] ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
// public void insertProductsToStorage(List<StorageDTO> productsToStorageList) {
//
// if(!fpService.insertProductsToStorage(productsToStorageList))
// rView.printErrorMessage("failInsertProductsToStorage");
// }
/* [2-1] ์ฌ๋ฃ ํ์
ํ๊ธฐ */
public void selectProductsBySomething(SearchCriteria searchCriteria) {
List<StorageDTO> myProductsList = fpService.selectProductsBySomething(searchCriteria);
if(myProductsList != null && !myProductsList.isEmpty()) {
for(StorageDTO products : myProductsList) {
System.out.println(products);
}
} else {
rView.printErrorMessage("failSelectProductsBySomething");
}
}
/* [2-2] ์ฌ๋ฃ ์ฌ์ฉํ๊ธฐ */
public void deletePickedProduct(Map<String, String> param) {
String prodName = param.get("prodName");
if(fpService.deletePickedProduct(prodName)) {
rView.printCompleteMessage("successDeletePickedProduct");
} else {
rView.printErrorMessage("failDeletePickedProduct");
}
}
/* [2-3] ์ํ ์ฌ๋ฃ ๊ตํ๋ฐ๊ธฐ */
public void updatePickedProduct(Map<String, String> param) {
String prodName = param.get("prodName");
if(fpService.updatePickedProduct(prodName)) {
rView.printCompleteMessage("successUpdatePickedProduct");
} else {
rView.printErrorMessage("failUpdatePickedProduct");
}
}
/* [2-4] ์ค๋๋ ์ฌ๋ฃ ๋ชจ๋ ํ๊ธฐํ๊ธฐ */
public void deleteOldProducts(Map<String, String> param) {
int days = Integer.parseInt(param.get("days"));
if(fpService.deleteOldProducts(days)) {
rView.printCompleteMessage("successDeleteOldProducts");
} else {
rView.printErrorMessage("failDeleteOldProducts");
}
}
/* [3] ์ํ๋ ์ฌ๋ฃ ํ๋งค ์ ์ํ๊ธฐ */
public void insertNewProduct(Map<String, String> param) {
FoodProductsDTO foodProducts = new FoodProductsDTO();
foodProducts.setProdName(param.get("product"));
foodProducts.setPrice(Integer.parseInt(param.get("price")));
foodProducts.setSupplierName(param.get("supplier"));
if(fpService.insertNewProduct(foodProducts)) {
rView.printCompleteMessage("successInsertNewProduct");
} else {
rView.printErrorMessage("failInsertNewProduct");
}
}
/* [4-1] ๋ชจ๋ ์
์ฒด ์กฐํํ๊ธฐ */
public void selectAllSupplier() {
List<SupplierDTO> allSupplierList = fpService.selectAllSupplier();
if(allSupplierList != null) {
rView.printSupplierList(allSupplierList);
} else {
rView.printErrorMessage("failSelectAllSupplier");
}
}
/* [4-2] ์ ๋ณด ๋ณ๊ฒฝํ๊ธฐ */
public void updateSupplierInfo(Map<String, String> param) {
SupplierDTO supplier = new SupplierDTO();
supplier.setSupplierName(param.get("suppName"));
supplier.setAddress(param.get("newAddress"));
supplier.setContactNumber(param.get("newContactNumber"));
supplier.setOrderYn(param.get("newOrderYn"));
if(fpService.updateSupplierInfo(supplier)) {
rView.printCompleteMessage("successUpdateSupplierInfo");
} else {
rView.printErrorMessage("failUpdateSupplierInfo");
}
}
/* [4-3] ๊ณ์ฝ ํด์งํ๊ธฐ */
public void deleteSupplier(Map<String, String> param) {
String suppName = param.get("suppName");
if(fpService.deleteSupplier(suppName)) {
rView.printCompleteMessage("successDeleteSupplier");
} else {
rView.printErrorMessage("failDeleteSupplier");
}
}
/* [5] ์ฃผ๋ฌธ๋ด์ญ ์กฐํํ๊ธฐ */
public void selectOrderHistory(Map<String, String> param) {
String range = param.get("range");
List<OrderHistoryDTO> orderHistoryList = fpService.selectOrderHistory(range);
if(orderHistoryList != null) {
rView.printOrderHistoryList(orderHistoryList);
} else {
rView.printErrorMessage("failSelectOrderHistory");
}
}
}
public class FoodProductsService {
private FoodProductsMapper mapper;
/* [1-1] ์ค๋์ ์ฌ๋ฃ ์ถ์ฒ๋ฐ๊ธฐ */
public List<FoodProductsDTO> selectRandomProducts(List<Integer> randomProductsList) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* Map์ ์ง์ด๋ฃ๊ธฐ */
Map<String, List<Integer>> criteria = new HashMap<>();
criteria.put("randomProductsList", randomProductsList);
List<FoodProductsDTO> productsList = mapper.selectRandomProducts(criteria);
sqls.close();
return productsList;
}
/* [1-2] ์ ํต์
์ฒด ์ ํํ๊ธฐ */
public List<FoodProductsDTO> selectProductsBySupplier(SearchCriteria searchCriteria) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
List<FoodProductsDTO> productsList = mapper.selectProductsBySupplier(searchCriteria);
sqls.close();
return productsList;
}
/* [1-3A] ์ ์ฒด ํ๋งค ์ฌ๋ฃ ์กฐํํ์ฌ ๋ฆฌ์คํธ์ ๋ด๊ธฐ */
public List<FoodProductsDTO> selectAllProducts() {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
List<FoodProductsDTO> allproductsList = mapper.selectAllProducts();
sqls.close();
return allproductsList;
}
/* [1-3B] ์ฃผ๋ฌธํ ๋ด์ญ ์ ์ฅํ๊ธฐ / [1-3C] ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
public boolean insertOrderedProducts(OrderHistoryDTO order) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* ์ฃผ๋ฌธํ ๋ด์ญ ์ ์ฅํ๊ธฐ */
int result1 = mapper.insertOrderedProducts(order);
/* ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
int result2 = 0;
for(StorageDTO storage : order.getStorageDTO()) {
result2 += mapper.insertProductsToStorage(storage);
}
if(result1 > 0 && result2 > 0) {
// ์ฃผ๋ฌธ ๋ด์ญ๊ณผ ์ฌ๋ฃ๋ค์ด ๋ชจ๋ ์ ์์ ์ผ๋ก INSERT๋์์ ๋, commit (ํ๋์ ํธ๋์ญ์
์์์ ์ํ)
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result1 > 0 && result2 > 0 ? true : false;
}
/* [1-3C] ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
public boolean insertProductsToStorage(List<StorageDTO> productsToStorageList) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* INSERT์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = 0;
for(StorageDTO storage : productsToStorageList) {
result += mapper.insertProductsToStorage(storage);
}
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [2-1] ์ฌ๋ฃ ํ์
ํ๊ธฐ */
public List<StorageDTO> selectProductsBySomething(SearchCriteria searchCriteria) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
List<StorageDTO> myProductsList = mapper.selectProductsBySomething(searchCriteria);
sqls.close();
return myProductsList;
}
/* [2-2] ์ฌ๋ฃ ์ฌ์ฉํ๊ธฐ */
public boolean deletePickedProduct(String prodName) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* DELETE์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = mapper.deletePickedProduct(prodName);
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [2-3] ์ํ ์ฌ๋ฃ ๊ตํ๋ฐ๊ธฐ */
public boolean updatePickedProduct(String prodName) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* UPDATE์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = mapper.updatePickedProduct(prodName);
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [2-4] ์ค๋๋ ์ฌ๋ฃ ๋ชจ๋ ํ๊ธฐํ๊ธฐ */
public boolean deleteOldProducts(int days) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* DELETE์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = mapper.deleteOldProducts(days);
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [3] ์ํ๋ ์ฌ๋ฃ ํ๋งค ์ ์ํ๊ธฐ */
public boolean insertNewProduct(FoodProductsDTO foodProducts) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* INSERT์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = mapper.insertNewProduct(foodProducts);
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [4-1] ๋ชจ๋ ์
์ฒด ์กฐํํ๊ธฐ */
public List<SupplierDTO> selectAllSupplier() {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
List<SupplierDTO> allSupplierList = mapper.selectAllSupplier();
sqls.close();
return allSupplierList;
}
/* [4-2] ์ ๋ณด ๋ณ๊ฒฝํ๊ธฐ */
public boolean updateSupplierInfo(SupplierDTO supplier) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* UPDATE์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = mapper.updateSupplierInfo(supplier);
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [4-3] ๊ณ์ฝ ํด์งํ๊ธฐ */
public boolean deleteSupplier(String suppName) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
/* DELETE์ด๋ฏ๋ก int๋ก ๋ฐํ๋ฐ๊ธฐ */
int result = mapper.deleteSupplier(suppName);
if(result > 0) {
sqls.commit();
} else {
sqls.rollback();
}
sqls.close();
return result > 0 ? true : false;
}
/* [5] ์ฃผ๋ฌธ๋ด์ญ ์กฐํํ๊ธฐ */
public List<OrderHistoryDTO> selectOrderHistory(String range) {
SqlSession sqls = getSqlSession();
mapper = sqls.getMapper(FoodProductsMapper.class);
List<OrderHistoryDTO> orderHistoryList = mapper.selectOrderHistory(range);
sqls.close();
return orderHistoryList;
}
}
public interface FoodProductsMapper {
/* [1-1] ์ค๋์ ์ฌ๋ฃ ์ถ์ฒ๋ฐ๊ธฐ */
List<FoodProductsDTO> selectRandomProducts(Map<String, List<Integer>> criteria);
/* [1-2] ์ ํต์
์ฒด ์ ํํ๊ธฐ */
List<FoodProductsDTO> selectProductsBySupplier(SearchCriteria searchCriteria);
/* [1-3A] ์ ์ฒด ๋ฉ๋ด ์กฐํํ์ฌ ๋ฆฌ์คํธ์ ๋ด๊ธฐ */
List<FoodProductsDTO> selectAllProducts();
/* [1-3B] ์ฃผ๋ฌธํ ๋ด์ญ ์ ์ฅํ๊ธฐ */
int insertOrderedProducts(OrderHistoryDTO order);
/* [1-3C] ์ฃผ๋ฌธํ ์ฌ๋ฃ ์ ์ฅ๊ณ ์ ์ถ๊ฐํ๊ธฐ */
int insertProductsToStorage(StorageDTO storageDTO);
/* [2-1] ์ฌ๋ฃ ํ์
ํ๊ธฐ */
List<StorageDTO> selectProductsBySomething(SearchCriteria searchCriteria);
/* [2-2] ์ฌ๋ฃ ์ฌ์ฉํ๊ธฐ */
int deletePickedProduct(String prodName);
/* [2-3] ์ํ ์ฌ๋ฃ ๊ตํ๋ฐ๊ธฐ */
int updatePickedProduct(String prodName);
/* [2-4] ์ค๋๋ ์ฌ๋ฃ ๋ชจ๋ ํ๊ธฐํ๊ธฐ */
int deleteOldProducts(int days);
/* [3] ์ํ๋ ์ฌ๋ฃ ํ๋งค ์ ์ํ๊ธฐ */
int insertNewProduct(FoodProductsDTO foodProducts);
/* [4-1] ๋ชจ๋ ์
์ฒด ์กฐํํ๊ธฐ */
List<SupplierDTO> selectAllSupplier();
/* [4-2] ์ ๋ณด ๋ณ๊ฒฝํ๊ธฐ */
int updateSupplierInfo(SupplierDTO supplier);
/* [4-3] ๊ณ์ฝ ํด์งํ๊ธฐ */
int deleteSupplier(String suppName);
/* [5] ์ฃผ๋ฌธ๋ด์ญ ์กฐํํ๊ธฐ */
List<OrderHistoryDTO> selectOrderHistory(String range);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.joyhyonie.foodProducts.mapper.FoodProductsMapper">
<resultMap type="com.joyhyonie.foodProducts.model.dto.FoodProductsDTO" id="foodProductsResultMap">
<id property="prodCode" column="PROD_CODE"/>
<result property="prodName" column="PROD_NAME"/>
<result property="price" column="PRICE"/>
<result property="supplierName" column="SUPPLIER_NAME"/>
</resultMap>
<resultMap type="com.joyhyonie.foodProducts.model.dto.OrderHistoryDTO" id="orderHistoryResultMap">
<id property="orderCode" column="ORDER_CODE"/>
<result property="orderDate" column="ORDER_DATE"/>
<result property="orderTime" column="ORDER_TIME"/>
<result property="totalPrice" column="TOTAL_PRICE"/>
</resultMap>
<resultMap type="com.joyhyonie.foodProducts.model.dto.StorageDTO" id="storageResultMap">
<id property="prodCode" column="PROD_CODE"/>
<result property="prodName" column="PROD_NAME"/>
<result property="incomingDate" column="INCOMING_DATE"/>
</resultMap>
<resultMap type="com.joyhyonie.foodProducts.model.dto.SupplierDTO" id="supplierResultMap">
<id property="supplierCode" column="SUPPLIER_CODE"/>
<result property="categoryCode" column="CATEGORY_CODE"/>
<result property="supplierName" column="SUPPLIER_NAME"/>
<result property="address" column="ADDRESS"/>
<result property="contactNumber" column="CONTACT_NUMBER"/>
<result property="orderYn" column="ORDER_YN"/>
<!-- JOIN ํ๊ธฐ ์ํด <association> ์ฌ์ฉ -->
<association property="foodCategory" javaType="com.joyhyonie.foodProducts.model.dto.FoodCategoryDTO">
<id property="categoryCode" column="CATEGORY_CODE"/>
<result property="category" column="CATEGORY"/>
</association>
</resultMap>
<select id="selectRandomProducts" parameterType="hashmap" resultMap="foodProductsResultMap">
SELECT
PROD_CODE
, PROD_NAME
, PRICE
, SUPPLIER_NAME
FROM TBL_PRODUCTS
JOIN TBL_SUPPLIER USING(SUPPLIER_NAME)
WHERE ORDER_YN = 'Y'
AND PROD_CODE IN
<foreach collection="randomProductsList" item="prodCode" open="(" separator="," close=")">
#{ prodCode }
</foreach>
ORDER BY PROD_CODE
</select>
<select id="selectProductsBySupplier" parameterType="SerchCriteria" resultMap="foodProductsResultMap">
SELECT
PROD_CODE
, PROD_NAME
, PRICE
, SUPPLIER_NAME
FROM TBL_PRODUCTS
JOIN TBL_SUPPLIER USING(SUPPLIER_NAME)
WHERE ORDER_YN = 'Y'
<choose>
<when test='value == "A"'>
AND SUPPLIER_NAME = '๊ตฝ๋ค์ ์ก'</when>
<when test='value == "B"'>
AND SUPPLIER_NAME = '๋ฐ๋คํ์ฌ๋'</when>
<when test='value == "C"'>
AND SUPPLIER_NAME = 'SING์ฑ์ฑ์'</when>
<when test='value == "D"'>
AND SUPPLIER_NAME = '๋ฒ ์ง์ํ'</when>
<when test='value == "E"'>
AND SUPPLIER_NAME = '์น์ฆFARM'</when>
<when test='value == "F"'>
AND SUPPLIER_NAME = '์ผ์๋กํธ๋'</when>
<when test='value == "G"'>
AND SUPPLIER_NAME = '์งฑ๊ตฌ๋๋ง๋ ค'</when>
<when test='value == "H"'>
AND SUPPLIER_NAME = '๊ผฌ์๋ด๋ฐฉ์๊ฐ'</when>
<when test='value == "I"'>
AND SUPPLIER_NAME = 'EGG๋จธ๋๋'</when>
</choose>
ORDER BY PROD_CODE
</select>
<select id="selectAllProducts" resultMap="foodProductsResultMap">
SELECT
PROD_CODE
, PROD_NAME
, PRICE
, SUPPLIER_NAME
FROM TBL_PRODUCTS
</select>
<insert id="insertOrderedProducts" parameterType="com.joyhyonie.foodProducts.model.dto.OrderHistoryDTO">
INSERT
INTO TBL_ORDER_HISTORY
(
ORDER_CODE
, ORDER_DATE
, ORDER_TIME
, TOTAL_PRICE
)
VALUES
(
SEQ_ORDER_CODE.NEXTVAL
, #{ orderDate }
, #{ orderTime }
, #{ totalPrice }
)
</insert>
<insert id="insertProductsToStorage" parameterType="com.joyhyonie.foodProducts.model.dto.StorageDTO">
INSERT
INTO TBL_STORAGE
(
PROD_CODE
, PROD_NAME
, INCOMING_DATE
)
VALUES
(
#{ prodCode }
, #{ prodName }
, #{ incomingDate }
)
</insert>
<select id="selectProductsBySomething" parameterType="SerchCriteria" resultMap="storageResultMap">
SELECT
PROD_CODE
, PROD_NAME
, INCOMING_DATE
FROM TBL_STORAGE
<if test="condition == '์ฌ๋ฃ๋ช
๋ณ'">
WHERE PROD_NAME LIKE '%' || #{ value } || '%'
</if>
ORDER BY INCOMING_DATE
</select>
<delete id="deletePickedProduct" parameterType="string">
DELETE
FROM TBL_STORAGE
WHERE PROD_NAME = #{ prodName }
</delete>
<update id="updatePickedProduct" parameterType="string">
UPDATE
TBL_STORAGE
SET INCOMING_DATE = SYSDATE
WHERE PROD_NAME = #{ prodName }
</update>
<delete id="deleteOldProducts" parameterType="_int">
DELETE
FROM TBL_STORAGE
WHERE ROUND(MONTHS_BETWEEN(SYSDATE, INCOMING_DATE) * 24) >= #{ days }
</delete>
<insert id="insertNewProduct" parameterType="com.joyhyonie.foodProducts.model.dto.FoodProductsDTO">
INSERT
INTO TBL_PRODUCTS
(
PROD_CODE
, PROD_NAME
, PRICE
, SUPPLIER_NAME
)
VALUES
(
SEQ_PROD_CODE.NEXTVAL
, #{ prodName }
, #{ price }
, #{ supplierName }
)
</insert>
<select id="selectAllSupplier" resultMap="supplierResultMap"> <!-- <association> ์ฌ์ฉ -->
SELECT
A.CATEGORY_CODE
, A.SUPPLIER_CODE
, A.SUPPLIER_NAME
, A.ADDRESS
, A.CONTACT_NUMBER
, A.ORDER_YN
, B.CATEGORY
FROM TBL_SUPPLIER A
JOIN TBL_FOOD_CATEGORY B ON (A.CATEGORY_CODE = B.CATEGORY_CODE)
ORDER BY CATEGORY_CODE
</select>
<update id="updateSupplierInfo" parameterType="com.joyhyonie.foodProducts.model.dto.SupplierDTO">
UPDATE
TBL_SUPPLIER
<trim prefix="SET" prefixOverrides=",">
<if test="address != null and address !=''">
ADDRESS = #{ address } </if>
<if test="contactNumber != null and contactNumber !=''">
, CONTACT_NUMBER = #{ contactNumber } </if>
<if test="orderYn != null and orderYn !=''">
, ORDER_YN = #{ orderYn } </if>
</trim>
WHERE SUPPLIER_NAME = #{ supplierName }
</update>
<delete id="deleteSupplier" parameterType="string">
DELETE
FROM TBL_SUPPLIER
WHERE SUPPLIER_NAME = #{ supplierName }
</delete>
<select id="selectOrderHistory" resultMap="orderHistoryResultMap">
SELECT
ORDER_CODE
, ORDER_DATE
, ORDER_TIME
, TOTAL_PRICE
FROM TBL_ORDER_HISTORY
ORDER BY ORDER_DATE <if test="range == '์ต์ ์'">DESC</if>, ORDER_TIME <if test="range == '์ต์ ์'">DESC</if>
</select>
</mapper>
public class Application {
public static void main(String[] args) {
new MainView().displayView();
}
}
๐ฌ Overall Comment
์ฒ์์ผ๋ก Mybatis๋ฅผ ํ์ฉํด์ MVC ๊ตฌ์กฐ๋ก ์ฝ์ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด๋ณด์๋ค. ๋ด๊ฐ ์ํ๋ ์ฃผ์ ๋ฅผ ์ ํํ์ฌ ์ ์ํ ์ ์์๊ธฐ ๋๋ฌธ์ ์ฒซ ์ ์๊ณผ์ ๋ถํฐ ์ค๋ ๊ณ ์ ๋ง ์ฌ๋ฏธ์์๋ค. DB๋ถํฐ ์ด๋ป๊ฒ ๊ตฌ์ฑํ๋ฉด ํจ์จ์ ์ผ์ง ๊ณ ๋ฏผ์ ๊ต์ฅํ ๋ง์ด ํ๊ณ ์์ ์ ์ง์ ์์ฑ๋ ํ ์ด๋ธ์ด ์ด๋ป๊ฒ ๋ณด์ด๋์ง ๋ง๋ค์ด ๋ณด๊ธฐ๋ ํ๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก ์ฝ๊ฐ ์์ ๋๊ณ ์ญ์ ๋๋ ๋ถ๋ถ์ด ์์์ผ๋, DB๋ชจ๋ธ๋ง์ ๋ฐฐ์ฐ๊ธฐ ์ ์ด์๊ธฐ ๋๋ฌธ์ ์์ ์ ํ์ฉํ DB๊ตฌ์กฐ ์์ ์ ํ์คํ ํฐ ๋์์ด ๋์๋ค.
๋ช ์๊ฐ๋์ ๊ตฌ์ฑ์ ํ๊ณ ํ ์ด๋ธ์ ์์ฑํ๊ณ ๋๋, ์ด์ ์ดํด๋ฆฝ์ค์์ ์ฝ๋๋ฅผ ์์ฑํด์ผํ๋ค. ์ฐจ๊ทผ์ฐจ๊ทผ ํด๋๋ฅผ ์์ธํ ๋๋๊ณ ์คํ๋ ์๋์ง ์ ๋ง ์์์ด ํ์ธ์ ํ๋ ๊ฒ ๊ฐ๋ค. ์ด์ ๋ด๊ฐ ์ํ๋ ๊ธฐ๋ฅ์ ํ๋ํ๋ ๋ฃ์ด๊ฐ๋ฉด ๋์๋๋ฐ, ์ด๋ฏธ ํ๋ฒ MVC๊ตฌ์กฐ๋ฅผ ์ฐ์ตํด๋ณธ ๊ฒฝํ์ด ์์์ผ๋ ์๋ก์ด ๊ธฐ๋ฅ์ ์๋ํด๋ณด๊ณ ์ ํ๋ ์์ฌ๋์ ์ด๋ฐ๋ถํฐ ๊ฝค ์ ๋ฅผ ๋จน์๋ค.
์์ ํ ์ฒซ ๊ธฐ๋ฅ์ด์๋ '์ค๋์ ์ฌ๋ฃ ์ถ์ฒ๋ฐ๊ธฐ'๋ฅผ ๋ง๋ค๊ณ ๋คํ์ค๋ฝ๊ฒ๋ ์ ์์ ์ผ๋ก ์๋์ ๋์์ผ๋, ์ด๊ฒ ์ ๊ฑธ ์ฌ๋ฃ 3๊ฐ๊ฐ ๊ณ ์ ์ ์ผ๋ก ์ถ๋ ฅ๋๋ ๊ฒ์ด ์๋ 0๊ฐ, 1๊ฐ, 2๊ฐ, 3๊ฐ ๋ฑ๋ฑ ๊ฐฏ์ ๋ํ ๋๋ค์ผ๋ก ์ถ๋ ฅ๋์ด ์ ์์ด ๋นํฉํ๋ค. ์์ธ์ด ๋๋ฌด์ง ๋ญ์ง ๋ํต ๋ชจ๋ฅด๊ฒ ์ด์ ์ ์๋๊ป ์๋ฌธ์ ๊ตฌํ๋๋ฐ, ์ ๋ง ์ฌ์ญค๋ณด๊ธฐ๋ ๋ฏผ๋งํ ๋งํผ ์ฌ์ํ๋ค. 100๋ฒ๋ถํฐ 150๋ฒ์ ์ฌ๋ฃ๋ฅผ ๋๋ค์ผ๋ก 3๊ฐ ๋ฝ์ผ๋ ค๋ฉด, (int) (Math.random() * 50)) + 100
์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํด์ผํ๋๋ฐ, (int) (Math.random() * 150)) + 100
์ผ๋ก ์์ฑํ๋ ๋น์ฐํ ๋ฒ์๋ฅผ ๋ฒ์ด๋ ์ฌ๋ฃ๋ค์ ์ถ๋ ฅ๋์ง ์์ ๊ฒ์ด์๋ค. ์ ์ ์ฐจ๋ฆฌ๊ณ ์ฝ๋๋ฅผ ์์ฑํด์ผ๊ฒ ๋ค๊ณ ๋ค์งํ ํ ๋ถ๋ถ์ด์๋ค..!
๊ทธ๋ฆฌ๊ณ ์ฌ๋ฌ๊ฐ์ง ๋์ ์ฟผ๋ฆฌ์ ์๋ฆฌ๋จผํธ๋ฅผ ์ต๋ํ ํ์ฉํ๊ณ ์, <association>
, <foreach>
, <choose>&<when>
, <if>
, <trim>
๋ฑ์ ์ฌ์ฉํ์ฌ ์ฟผ๋ฆฌ๋ฌธ์ ์์ฑํ๊ณ ํนํ '์ค๋๋ ์ฌ๋ฃ ํ๊ธฐํ๊ธฐ'๊ธฐ๋ฅ์ ์ํด ์ฌ์ฉํ๋ MONTHS_BETWEEN
์ด ๊ธฐ์ต์ ๋จ๋๋ค! ์ฟผ๋ฆฌ๋ฌธ์ ์๋ฆฌ์กฐ๋ฆฌ ์์ฑํด๋ณด๋๊ฒ ๋๋ฌด ์ฌ๋ฏธ์์ด์ ๊ผญ ํ๋ก๊ทธ๋จ์ ์ ์ํ ๋ ์ฌ๋ฌ๊ฐ์ง๋ฅผ ์ฌ์ฉํด๋ณด๊ณ ์ถ์๋๋ฐ, ์๊ฐ์ฒ๋ผ ์ ๊ตฌํ๋์ด ๊ธฐ๋ถ์ด ์ข์๋ค :)
์์
์์ ๊ทธ๋ฅ ๋ฐฐ์ด ๊ฒ๊ณผ ํ๋ฒ์ด๋ผ๋ ๋ด ๊ฒ์ผ๋ก ์ฌ์ฉํด๋ณด๋ ๊ฒ์ ์ ๋ง ์ฒ์ง์ฐจ์ด๋ผ๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์ ์์ผ๋ก๋ ๊ณ์ ๊พธ์คํ ํ์ฉํ ์์ ์ด๋ค.
๋ํ, ๊ฐ์ฅ ๋ง์ง๋ง๊น์ง ์ ๋ฅผ ๋จน์๋ ๋ถ๋ถ์ธ '์ฃผ๋ฌธ ์์ํ๊ธฐ'... ์ ๋ง ์ ๋ง ๊น๋ค๋ก์ ์ผ๋ ๋ด๊ฐ ๊ตฌํํ ๊ธฐ๋ฅ ์ค ์ ๋ง ์์ ์๊ฒ ๋จผ์ ์ ๋ณด์ด๊ณ ์ถ์ ๊ธฐ๋ฅ์ด์๋ค. ํ๋ ์ด ๋ชจ์ต์ ๋ด๊ฐ ๋ณด๊ฒ ๋๋ค๋ฉด ๊ฒจ์ฐ ์ด๊ฑฐ ๊ฐ์ง๊ณ ์ฉ์ฉ ๋งค์๋๊ฒ ๊ท์ฌ์ ๋ณด์ผ ๋ฏ ํ์ง๋ง ๊ตฌํํ๊ณ ๋์ ๋๋ฌด ๋ฟ๋ฏํ๋ค. ๋ด๊ฐ ์ํ๋ ๋ถ๋ถ์ ์ฌ์ฉ์๊ฐ ์ฌ๋ฌ ์ฌ๋ฃ๋ฅผ ๊ณ์ ์
๋ ฅํ ์ ์๊ฒ ํ ๋ค, ์ฃผ๋ฌธ์ด ๋๋๋ฉด ์ด์ก ๋ฐ ์ฃผ๋ฌธํ ์ฌ๋ฃ๋ค์ ์ถ๋ ฅํด์ฃผ๊ณ ๊ทธ์ ๋ฐ๋ผ Storage, OrderHistory ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์๋์ผ๋ก ์ ์ฅ๋๊ฒ ๋ง๋ค๋๋ก ํ๊ณ ์ถ์๋ค. ์๊ฐ๋งํผ ์์ํ ๊ณผ์ ์ ์๋์๊ณ ์ฌ๋ฌ ์ฌ๋ฃ๋ฅผ Insertํ๊ธฐ ์ํด List๋ฅผ ์ฌ์ฉํด์ผํ๋ค๋ ์ ์ด ํ์ด๋ด์ผํ ์์ ์๋ค. ํ์ง๋ง ์ ๋ง ๋ง์ฒ๋ผ ์ฝ์ง ์์๊ณ ๊ณ์ ํ ๊ฐ์ง ์ฌ๋ฃ๋ง ์ฝ์
๋์๋ค... :(
๊ณ์ ๋ถ์ก๊ณ ์๋ค๊ฐ ์๋ ๊ฒ ๊ฐ์์ ์ ์๋๊ป ์๋ฌธ์ ๊ตฌํ๊ณ Service์์ for๋ฌธ์ ์ด์ฉํ์ฌ ๊ฐ์ ํ๋ํ๋ ๋ฝ์๋ด์ด ๋๊ธฐ๋ฉด ๋๋ค๋ ๊ฒฐ์ ์ ์ธ ํํธ๋ฅผ ์ป๊ฒ ๋์๋ค. ๋๋์ด ๊ตฌํ์ด ๋์๊ณ ๋ธ ๋ฏ์ด ๊ธฐ๋ปค๋ค.
ํ์ง๋ง, ๋ด๊ฐ ์ง๋ฌธํ์ ๋ ์ ์ฒด์ ์ธ ์ฝ๋๋ฅผ ์ ์๋์ด ๋ด์ฃผ์๋ค๊ฐ Storage์ OrderHistory์ insert๋ ๋ ๊ฐ๊ธฐ ๋ค๋ฅธ ํธ๋์ญ์ ์์ ์ํ๋๊ณ ์๋ค๋ ๊ฒ์ ํ์ธํด ์ฃผ์ จ๊ณ ์ด ๋์ ํ๋์ ํธ๋์ญ์ ์์ ์ํํ๋๋ก ์ฝ๋๋ฅผ ๋ค์ ๊ณ ์ณ์ผ๋งํ๋ค. (์ ๋ง) ์ด ๋ํ ์ด๋ค ๋ฐฉ์์ผ๋ก ๊ณ ์ณ์ผํ๋์ง ๊ทธ ์์ ์ ๋ฐฐ์ฐ๊ฒ ๋์๊ณ ๋๋ด ์์ฑํ ์ ์๊ฒ ๋์ด ์ ๋ง ๋ง์ด ๋ฟ๋ฏํ๋ค.
ํ ๊ฐ์ง ๋, ์๊ฐ์ด ๋ ์์๋ค๋ฉด ์ถ๊ฐํ๊ณ ์ถ์ ์์ฌ ๋๋ ๊ธฐ๋ฅ์ด ์๋๋ฐ Storage์ ์ด๋ฏธ ์๋ ์ฌ๋ฃ๋ค์ ์ฃผ๋ฌธํ์ง ๋ชป ํ๋๋ก ํ๋ ๊ธฐ๋ฅ์ ๊ตฌํํ๊ณ ์ถ๋ค. ์ด๊ฑด ์๋ง๋ Storage๋ฅผ ์ ์ฒด ์กฐํํ ๋ค, !@@.equals()
๋ฅผ ์ด์ฉํ์ฌ ์ด ๋๋ง ์ฃผ๋ฌธ์ด ๊ฐ๋ฅํ๋๋ก ํ๊ฒ ๋ง๋ค๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค.
๊ฒฐ๊ณผ์ ์ผ๋ก ๋ด๊ฐ ์ํ๋ ์์ง๋ง ๋๋ฆ ์์ฐฌ ์ฝ์ ํ๋ก๊ทธ๋จ์ด ์์ฑ๋์ด ๊ฐํ๊ฐ ์๋กญ๊ณ ๊ธฐ๋ถ์ด ์ข๋ค :)
๋ ์ ์ฉํ ํ๋ก๊ทธ๋จ์ ๊ณ์ ํด์ ๋ง๋ค์ด ๋๊ฐ๊ณ ์ถ๋ค!