Skip to content

Commit

Permalink
Merge pull request #179 from in27sung/shipment1
Browse files Browse the repository at this point in the history
123
  • Loading branch information
shoqying authored Dec 17, 2024
2 parents dce96f5 + 2c202a6 commit 76cda97
Show file tree
Hide file tree
Showing 18 changed files with 2,581 additions and 30 deletions.
271 changes: 264 additions & 7 deletions stockMate/src/main/java/com/stockm8/controller/ShipmentController.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,291 @@
package com.stockm8.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stockm8.domain.vo.Criteria;
import com.stockm8.domain.vo.PageVO;
import com.stockm8.domain.vo.ProductVO;
import com.stockm8.domain.vo.ReceivingShipmentVO;
import com.stockm8.domain.vo.StockVO;
import com.stockm8.domain.vo.UserVO;
import com.stockm8.service.ReceivingService;
import com.stockm8.service.ShipmentService;
import com.stockm8.service.UserService;

@Controller
@RequestMapping(value = "/shipment/*")

public class ShipmentController {

private static final Logger logger = LoggerFactory.getLogger(ShipmentController.class);

// @Inject
// private ReceivingService rService;
@Inject
private ShipmentService sService;

@Inject
private UserService uService;

// http://localhost:8088/receiving/main
// http://localhost:8088/shipment/main
@RequestMapping(value = "/main", method = RequestMethod.GET)
public void mainGET() throws Exception {
public void mainGET(Model model, HttpServletRequest request) throws Exception {
logger.info("mainGET() 호출");

logger.info("");
// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

List<ReceivingShipmentVO> ShipmentList = sService.getShipmentList(businessId);
logger.info(ShipmentList.size() + "개");

List<ReceivingShipmentVO> YesterdayShipmentList = sService.getYesterdayShipmentList(businessId);
logger.info(YesterdayShipmentList.size() + "개");

List<ReceivingShipmentVO> TDBYShipmentList = sService.getTDBYShipmentList(businessId);
logger.info(TDBYShipmentList.size() + "개");

model.addAttribute("ShipmentList", ShipmentList);
model.addAttribute("YesterdayShipmentList", YesterdayShipmentList);
model.addAttribute("TDBYShipmentList", TDBYShipmentList);
}

// http://localhost:8088/shipment/history
@RequestMapping(value = "/history", method = RequestMethod.GET)
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, HttpServletRequest request,
Model model) throws Exception {
logger.info("historyGET() 호출");

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

List<ReceivingShipmentVO> ShipmentList;

int totalCount = 0;

ShipmentList = sService.getShipmentHistoryList(cri, businessId);
totalCount = sService.getTotalCount(businessId); // 전체 개수

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

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

// http://localhost:8088/shipment/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, HttpServletRequest request,
Model model) throws Exception {
logger.info("searchGET() 호출");

List<ReceivingShipmentVO> ShipmentList;

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

int totalCount = 0;

// 날짜와 키워드가 모두 있는 경우
if (startDate != null && endDate != null && keyword != null) {
ShipmentList = sService.getHistoryByDateRange(startDate, endDate, keyword, cri, businessId);
totalCount = sService.getTotalCountBySearch(startDate, endDate, keyword, businessId);

} else if (keyword != null) {
ShipmentList = sService.getHistoryByDateRange(null, null, keyword, cri, businessId);
totalCount = sService.getTotalCountBySearch(null, null, keyword, businessId);

} else if (startDate != null && endDate != null) {
ShipmentList = sService.getHistoryByDateRange(startDate, endDate, null, cri, businessId);
totalCount = sService.getTotalCountBySearch(startDate, endDate, null, businessId);

} else {
ShipmentList = sService.getShipmentHistoryList(cri, businessId);
totalCount = sService.getTotalCount(businessId); // 전체 개수

}

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

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

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

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

sService.insertShipment(businessId);

return "redirect:/shipment/main";
}

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

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

sService.insertShipment(businessId);

return "redirect:/shipment/history";
}

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

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

sService.insertShipment(businessId);

return "redirect:/shipment/search";
}

// http://localhost:8088/shipment/scan
@RequestMapping(value = "/scan", method = RequestMethod.GET)
public String scanGET(HttpServletRequest request) throws Exception {
logger.info("scanGET() 호출");

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

return "/shipment/scan";
}

// http://localhost:8088/shipment/scan
@RequestMapping(value = "/scan", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> scanPOST(@RequestBody Map<String, String> bar, Model model,
HttpServletRequest request) throws Exception {
logger.info("scanPOST() 호출");

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

// QR 코드 데이터 처리 로직 (예: 데이터 저장, 검증 등)
String barcode = bar.get("barcode");
Map<String, Object> response = new HashMap();

if (userId == null) {
response.put("success", false);
response.put("message", "로그인 정보가 없습니다.");
return response;
}

try {
sService.ShipmentStatusToComplete(businessId, barcode);
int remainingStock = sService.increseStockByBarcode(businessId, barcode);
int reservedQuantity = sService.decreaseReservedQuantity(businessId, barcode);
ProductVO product = sService.productNameBarcode(businessId, barcode);
if (remainingStock >= 0) {
response.put("success", true);
response.put("remainingStock", remainingStock);
response.put("reservedQuantity", reservedQuantity);
response.put("productName", product.getProductName());
response.put("productPrice", product.getProductPrice());
} else {
response.put("success", false);
response.put("message", "유효하지 않은 바코드입니다.");
}
} catch (Exception e) {
response.put("success", false);
response.put("message", e.getMessage());
}
return response;
}

// http://localhost:8088/shipment/allScan
@RequestMapping(value = "/allScan", method = RequestMethod.GET)
public String allScanGET(HttpServletRequest request) throws Exception {
logger.info("allScanGET() 호출");

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();



return "/shipment/allScan";
}





} // ReceivingController end
} // ShipmentController end
48 changes: 45 additions & 3 deletions stockMate/src/main/java/com/stockm8/persistence/ShipmentDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,53 @@

import java.util.List;

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

public interface ShipmentDAO {

// 출고 메인 오늘 들어올 리스트
public List<ReceivingShipmentVO> todayReceivingList() throws Exception;
// 입고 메인 오늘 들어올 리스트
public List<ReceivingShipmentVO> selectShipmentList(int businessId) throws Exception;

// 입고 메인 오늘 들어올 리스트
public List<ReceivingShipmentVO> selectYesterdayShipmentList(int businessId) throws Exception;

// 입고 메인 오늘 들어올 리스트
public List<ReceivingShipmentVO> selectTDBYShipmentList(int businessId) throws Exception;

// 입고 내역 히스토리
public List<ReceivingShipmentVO> selectShipmentHistoryList(Criteria cri, int businessId) throws Exception;

// 입고 내역 검색
public List<ReceivingShipmentVO> selectHistoryByDateRange(String startDate, String endDate, String keyword, Criteria cri, int businessId) throws Exception;

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

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

// recevingShipment 테이블 insert
public void insertShipment(int businessId) throws Exception;

// 바코드로 재고 조회
public List<StockVO> selectQuantityCheckByBarcode(int businessId, String barcode) throws Exception;

// 바코드로 재고 감소
public int updateIncreseStock(int businessId, String barcode) throws Exception;

// 바코드로 재고 감소 실시간 조회
public int selectStockByBarcode(int businessId, String barcode) throws Exception;

// 바코드 찍은 후 발주 수량 감소
public int selectReservedQuantity(int businessId, String barcode) throws Exception;

// 바코드 찍은 후 제품 이름 추출
public ProductVO selectProductNameBarcode(int businessId, String barcode) throws Exception;

// 수량 없을시 완료상태로 변경
public void updateShipmentStatusToComplete(int businessId, String barcode) throws Exception;

} // ShipmentDAO end
Loading

0 comments on commit 76cda97

Please sign in to comment.