Skip to content

Commit

Permalink
Merge pull request #131 from in27sung/receivingsearch_01
Browse files Browse the repository at this point in the history
Receivingsearch 01
  • Loading branch information
shoqying authored Dec 11, 2024
2 parents 6ca03fe + 8f5d13a commit 48ec8b5
Show file tree
Hide file tree
Showing 10 changed files with 579 additions and 62 deletions.
133 changes: 103 additions & 30 deletions stockMate/src/main/java/com/stockm8/controller/ReceivingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,59 +43,132 @@ public void mainGET(Model model) throws Exception {
model.addAttribute("ReceivingList", ReceivingList);
model.addAttribute("YesterdayReceivingList", YesterdayReceivingList);
model.addAttribute("TDBYReceivingList", TDBYReceivingList);

}

// http://localhost:8088/receiving/history
@RequestMapping(value = "/history", method = RequestMethod.GET)
public String historyGET(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "keyword", required = false) String keyword,
Criteria cri,
Model model) throws Exception {
public void historyGET(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "keyword", required = false) String keyword,
Criteria cri,
Model model) throws Exception {
logger.info("historyGET() 호출");

List<ReceivingShipmentVO> ReceivingList;

int totalCount = 0;

ReceivingList = rService.getReceivingHistoryList(cri);
totalCount = rService.getTotalCount(); // 전체 개수

PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount);
model.addAttribute("pageVO", pageVO);

logger.info(ReceivingList.size() + "개");
model.addAttribute("ReceivingList", ReceivingList);
}

// http://localhost:8088/receiving/search
@RequestMapping(value = "/search", method = RequestMethod.GET)
public void searchGET(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "keyword", required = false) String keyword,
Criteria cri,
Model model) throws Exception {
logger.info("searchGET() 호출");

List<ReceivingShipmentVO> ReceivingList;

int totalCount = 0;

// 날짜와 키워드가 모두 있는 경우
if (startDate != null && endDate != null && keyword != null) {
ReceivingList = rService.getHistoryByDateRange(startDate, endDate, keyword, cri);
int totalCount = rService.getTotalCountBySearch(startDate, endDate, keyword, cri);
PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount); // 총 개수를 검색 조건에 맞게 계산
model.addAttribute("pageVO", pageVO);
totalCount = rService.getTotalCountBySearch(startDate, endDate, keyword);

} else if (keyword != null) {
ReceivingList = rService.getHistoryByDateRange(null, null, keyword, cri);
int totalCount = rService.getTotalCountBySearch(null, null, keyword, cri);
PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount);
model.addAttribute("pageVO", pageVO);
totalCount = rService.getTotalCountBySearch(null, null, keyword);

} else if (startDate != null && endDate != null) {
ReceivingList = rService.getHistoryByDateRange(startDate, endDate, null, cri);
int totalCount = rService.getTotalCountBySearch(startDate, endDate, null, cri);
PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount);
model.addAttribute("pageVO", pageVO);
totalCount = rService.getTotalCountBySearch(startDate, endDate, null);

} else {
ReceivingList = rService.getReceivingHistoryList(cri);
int totalCount = rService.getTotalCount(); // 전체 개수
PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount);
model.addAttribute("pageVO", pageVO);
totalCount = rService.getTotalCount(); // 전체 개수

}

PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount);
model.addAttribute("pageVO", pageVO);

logger.info(ReceivingList.size() + "개");
model.addAttribute("ReceivingList", ReceivingList);

return "/receiving/history";
}

// 새로고침
@RequestMapping(value = "/insert1", method = RequestMethod.POST)
public String insert1POST() throws Exception {
logger.info("insertPOST() 호출");

rService.insertReceiving();

return "redirect:/receiving/main";
}

// 새로고침
@RequestMapping(value = "/insert2", method = RequestMethod.POST)
public String insert2POST() throws Exception {
logger.info("insertPOST() 호출");

rService.insertReceiving();

return "redirect:/receiving/history";
}

// 새로고침
@RequestMapping(value = "/insert3", method = RequestMethod.POST)
public String insert3POST() throws Exception {
logger.info("insertPOST() 호출");

rService.insertReceiving();

return "redirect:/receiving/search";
}


// http://localhost:8088/receiving/scanner
@RequestMapping(value = "/scanner", method = RequestMethod.GET)
public String scannerGET(@RequestParam(value = "qrData", required = false) String qrData, Model model) throws Exception {
logger.info("scannerGET() 호출");
// QR 코드 데이터 처리 로직 (예: 데이터 저장, 검증 등)
logger.info("받은 QR 코드 데이터: " + qrData);

// 처리 결과를 JSP로 전달
model.addAttribute("qrData", qrData);

return "/receiving/scanner";
}

@RequestMapping(value = "/scanner", method = RequestMethod.POST)
public String scannePOST(@RequestParam(value = "qrData", required = false) String qrData, Model model) throws Exception {
logger.info("scannerGET() 호출");
// QR 코드 데이터 처리 로직 (예: 데이터 저장, 검증 등)
logger.info("받은 QR 코드 데이터: " + qrData);

// 처리 결과를 JSP로 전달
model.addAttribute("qrData", qrData);

return "/receiving/scanner";
}






} // ReceivingController end
} // ReceivingController end
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ public interface ReceivingDAO {
public List<ReceivingShipmentVO> selectHistoryByDateRange(String startDate, String endDate, String keyword, Criteria cri) throws Exception;

// 검색시 모든 리스트 개수
public int selectTotalCountBySearch(String startDate, String endDate, String keyword, Criteria cri) throws Exception;
public int selectTotalCountBySearch(String startDate, String endDate, String keyword) throws Exception;

// 리스트 모든 개수
public int selectTotalCount() throws Exception;

// rs 테이블 insert
public void insertReceiving() throws Exception;

} // ReceivingDAO end
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ public List<ReceivingShipmentVO> selectHistoryByDateRange(String startDate, Stri
}

@Override
public int selectTotalCountBySearch(String startDate, String endDate, String keyword, Criteria cri) throws Exception {
public int selectTotalCountBySearch(String startDate, String endDate, String keyword) throws Exception {

Map<String, Object> paramMap = new HashMap<>();
paramMap.put("startDate", startDate);
paramMap.put("endDate", endDate);
paramMap.put("keyword", keyword);
paramMap.put("cri", cri);
return sqlSession.selectOne(NAMESPACE + "getTotalCountBySearch", paramMap);
}

Expand All @@ -88,6 +87,14 @@ public int selectTotalCount() throws Exception {

return sqlSession.selectOne(NAMESPACE + "getTotalCount");
}

@Override
public void insertReceiving() throws Exception {
logger.info("insertReceiving() 호출");
sqlSession.insert(NAMESPACE + "insertReceiving");
}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.stockm8.domain.vo.Criteria;
import com.stockm8.domain.vo.ReceivingShipmentVO;


@Mapper
public interface ReceivingService {

// 메인 입고 리스트
Expand All @@ -24,9 +26,12 @@ public interface ReceivingService {
public List<ReceivingShipmentVO> getHistoryByDateRange(String startDate, String endDate, String keyword, Criteria cri) throws Exception;

// 입고 내역 검색
public int getTotalCountBySearch(String startDate, String endDate, String keyword, Criteria cri) throws Exception;
public int getTotalCountBySearch(String startDate, String endDate, String keyword) throws Exception;

// 글 모든 개수
public int getTotalCount() throws Exception;

// rs 테이블 insert
public void insertReceiving() throws Exception;

} // ReceivingService end
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ public List<ReceivingShipmentVO> getHistoryByDateRange(String startDate, String
}

@Override
public int getTotalCountBySearch(String startDate, String endDate, String keyword,
Criteria cri) throws Exception {
public int getTotalCountBySearch(String startDate, String endDate, String keyword) throws Exception {
logger.info("getTotalCountBySearch() 호출");
return rdao.selectTotalCountBySearch(startDate, endDate, keyword, cri);
return rdao.selectTotalCountBySearch(startDate, endDate, keyword);
}

@Override
public int getTotalCount() throws Exception {
logger.info("getTotalCount() 호출");
return rdao.selectTotalCount();
}

@Override
public void insertReceiving() throws Exception {
logger.info("insertReceiving() 호출");
rdao.insertReceiving();
}




Expand Down
66 changes: 47 additions & 19 deletions stockMate/src/main/resources/mappers/receivingMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,36 @@
<result property="price" column="price"/>
</resultMap>



<!-- 테이블에 입고 데이터 입력 -->
<insert id="insertReceiving">
INSERT INTO receiving_shipment (
transaction_type,
status,
product_id,
change_quantity,
transaction_unit,
order_item_id,
stock_id,
warehouse_id,
created_by
)
SELECT
'in',
'pending',
p.product_id,
o.quantity,
p.base_unit,
o.order_item_id,
s.stock_id,
o.warehouse_id,
u.created_by
FROM products p
JOIN order_items o ON o.product_id = p.product_id
JOIN stocks s ON s.product_id = p.product_id
JOIN users u ON u.business_id = p.business_id;
</insert>

<!-- 오늘 입고 예정 리스트 -->
<select id="getReceivingList" resultMap="receivingshipmentMap">
select
Expand All @@ -40,9 +68,9 @@
r.change_quantity,
r.transaction_unit,
r.memo
from test_receiving_shipment r
join test_products p on r.product_id = p.product_id
join test_warehouses w on w.warehouse_id = r.warehouse_id
from receiving_shipment r
join products p on r.product_id = p.product_id
join warehouses w on w.warehouse_id = r.warehouse_id
where Date(r.created_at) = CURRENT_DATE and r.status = 'pending' and r.transaction_type = 'in'
order by r.receiving_shipment_no desc
limit 0, 20
Expand All @@ -61,9 +89,9 @@
r.change_quantity,
r.transaction_unit,
r.memo
from test_receiving_shipment r
join test_products p on r.product_id = p.product_id
join test_warehouses w on w.warehouse_id = r.warehouse_id
from receiving_shipment r
join products p on r.product_id = p.product_id
join warehouses w on w.warehouse_id = r.warehouse_id
where Date(r.created_at) = DATE_ADD(CURRENT_DATE, INTERVAL -1 DAY)
order by r.receiving_shipment_no desc
limit 0, 20
Expand All @@ -82,9 +110,9 @@
r.change_quantity,
r.transaction_unit,
r.memo
from test_receiving_shipment r
join test_products p on r.product_id = p.product_id
join test_warehouses w on w.warehouse_id = r.warehouse_id
from receiving_shipment r
join products p on r.product_id = p.product_id
join warehouses w on w.warehouse_id = r.warehouse_id
where Date(r.created_at) = DATE_ADD(CURRENT_DATE, INTERVAL -2 DAY)
order by r.receiving_shipment_no desc
limit 0, 20
Expand All @@ -104,9 +132,9 @@
r.transaction_unit,
p.price,
r.memo
from test_receiving_shipment r
join test_products p on r.product_id = p.product_id
join test_warehouses w on w.warehouse_id = r.warehouse_id
from receiving_shipment r
join products p on r.product_id = p.product_id
join warehouses w on w.warehouse_id = r.warehouse_id
where transaction_type = 'in'
order by r.receiving_shipment_no desc
limit #{startPage},#{pageSize};
Expand All @@ -126,9 +154,9 @@
r.transaction_unit,
p.price,
r.memo
FROM test_receiving_shipment r
JOIN test_products p ON r.product_id = p.product_id
JOIN test_warehouses w ON w.warehouse_id = r.warehouse_id
FROM receiving_shipment r
JOIN products p ON r.product_id = p.product_id
JOIN warehouses w ON w.warehouse_id = r.warehouse_id
<where>
<if test="startDate != ''">
r.created_at &gt;= #{startDate}
Expand All @@ -148,8 +176,8 @@
<!-- 키워드 검색시 모든 개수 카운트 -->
<select id="getTotalCountBySearch" parameterType="map" resultType="int">
SELECT COUNT(*)
FROM test_receiving_shipment r
JOIN test_products p ON r.product_id = p.product_id
FROM receiving_shipment r
JOIN products p ON r.product_id = p.product_id
<where>
<if test="startDate != ''">
r.created_at &gt;= #{startDate}
Expand All @@ -168,7 +196,7 @@
<!-- 입출고 모든 개수 카운트 -->
<select id="getTotalCount" resultType="int">
select count(*)
from test_receiving_shipment
from receiving_shipment
where transaction_type = 'in'
</select>

Expand Down
Loading

0 comments on commit 48ec8b5

Please sign in to comment.