Skip to content

Commit

Permalink
Merge pull request #215 from in27sung/shipment5
Browse files Browse the repository at this point in the history
입고 바코드 완료
  • Loading branch information
shoqying authored Dec 19, 2024
2 parents ee2b5ef + 81ffc86 commit 40aee5c
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,11 +20,14 @@
import org.springframework.web.bind.annotation.ResponseBody;

import com.stockm8.domain.vo.Criteria;
import com.stockm8.domain.vo.OrderVO;
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.OrderProcessor;
import com.stockm8.service.OrderService;
import com.stockm8.service.ReceivingService;
import com.stockm8.service.UserService;

Expand Down Expand Up @@ -205,7 +209,8 @@ public String insert3POST(HttpServletRequest request) throws Exception {
// http://localhost:8088/receiving/scan
@RequestMapping(value = "/scan", method = RequestMethod.GET)
public void scanGET(HttpServletRequest request, Model model,
@RequestParam(value = "receivingShipmentNo", required = false) Integer receivingShipmentNo) throws Exception {
@RequestParam(value = "receivingShipmentNo", required = false) Integer receivingShipmentNo,
@RequestParam(value = "orderItemId", required = false) Integer orderItemId) throws Exception {
logger.info("scanGET() 호출");

// 세션에서 userId 가져오기
Expand All @@ -216,57 +221,65 @@ public void scanGET(HttpServletRequest request, Model model,
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

List<ReceivingShipmentVO> rsn = rService.getReceivingShipmentNo(businessId, receivingShipmentNo);
List<ReceivingShipmentVO> rsn = rService.getReceivingShipmentNo(businessId, receivingShipmentNo, orderItemId);

model.addAttribute("rsn", rsn);
model.addAttribute("receivingShipmentNo", receivingShipmentNo);
model.addAttribute("orderItemId", orderItemId);
}

// http://localhost:8088/receiving/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 가져오기
public Map<String, Object> scanPOST(@RequestBody Map<String, Object> payload,
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();

// JSON 본문에서 값 추출
String barcode = (String) payload.get("barcode");
Integer receivingShipmentNo = (Integer) payload.get("receivingShipmentNo");
Integer orderItemId = (Integer) payload.get("orderItemId");
model.addAttribute("receivingShipmentNo", receivingShipmentNo);
model.addAttribute("orderItemId", orderItemId);

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


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

try {
rService.ReceivingStatusToComplete(businessId, barcode);
int remainingStock = rService.increseStockByBarcode(businessId, barcode);
int reservedQuantity = rService.decreaseReservedQuantity(businessId, barcode);
ProductVO product = rService.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;
}
rService.ReceivingStatusToComplete(businessId, barcode, receivingShipmentNo);
int remainingStock = rService.increseStockByBarcode(businessId, barcode, receivingShipmentNo, orderItemId);
int reservedQuantity = rService.decreaseReservedQuantity(businessId, barcode, receivingShipmentNo, orderItemId);
ProductVO product = rService.productNameBarcode(businessId, barcode, receivingShipmentNo);

if (reservedQuantity >= 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());
logger.info("예외 발생" + e);
}
return response;
}

// http://localhost:8088/receiving/allScan
@RequestMapping(value = "/allScan", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ShipmentController {

@Inject
private UserService uService;

// http://localhost:8088/shipment/main
@RequestMapping(value = "/main", method = RequestMethod.GET)
public void mainGET(Model model, HttpServletRequest request) throws Exception {
Expand Down Expand Up @@ -205,7 +205,8 @@ public String insert3POST(HttpServletRequest request) throws Exception {

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

// 세션에서 userId 가져오기
Expand All @@ -216,7 +217,9 @@ public String scanGET(HttpServletRequest request) throws Exception {
UserVO user = uService.getUserById(userId);
int businessId = user.getBusinessId();

return "/shipment/scan";
List<ReceivingShipmentVO> rsn = sService.getReceivingShipmentNo(businessId, receivingShipmentNo);

model.addAttribute("rsn", rsn);
}

// http://localhost:8088/shipment/scan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class OrderItemVO {
private int productId; // 주문 상품 ID
private int warehouseId; // 창고 ID
private int quantity; // 주문 수량
private int changeQuantity; // 바뀐 주문 수량
private double unitPrice; // 제품 단가
private String remarks; // 특정 상품에 대한 비고 사항
private double stotalPrice; // 주문 1건의 전체 총 금액
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ public interface ReceivingDAO {
public void insertReceiving(int businessId) throws Exception;

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

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

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

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

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

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

// 입출고 번호를 누를시 스캔으로가서 특정 리스트 보여주기
public List<ReceivingShipmentVO> selectReceivingShipmentNo(int businessId, Integer receivingShipmentNo) throws Exception;
public List<ReceivingShipmentVO> selectReceivingShipmentNo(int businessId, Integer receivingShipmentNo, int orderItemId) throws Exception;

} // ReceivingDAO end
Original file line number Diff line number Diff line change
Expand Up @@ -103,70 +103,82 @@ public void insertReceiving(int businessId) throws Exception {
}

@Override
public List<StockVO> selectQuantityCheckByBarcode(int businessId, String barcode) throws Exception {
public List<StockVO> selectQuantityCheckByBarcode(int businessId, String barcode, Integer receivingShipmentNo) throws Exception {
logger.info("selectReceiving() 호출");
Map<String, Object> paramMap = new HashMap();
paramMap.put("businessId", businessId);
paramMap.put("barcode", barcode);
paramMap.put("receivingShipmentNo", receivingShipmentNo);

return sqlSession.selectList(NAMESPACE + "selectQuantityCheckByBarcode", paramMap);
}

@Override
public int updateIncreseStock(int businessId, String barcode) throws Exception {
public int updateIncreseStock(int businessId, String barcode, Integer receivingShipmentNo, Integer orderItemId) throws Exception {
logger.info("updateDecreaseStock() 호출");
// 매개변수 묶기
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("barcode", barcode);
params.put("receivingShipmentNo", receivingShipmentNo);
params.put("orderItemId", orderItemId);


// SQL 실행
return sqlSession.update(NAMESPACE + "updateIncreseStock", params);
}

@Override
public int selectStockByBarcode(int businessId, String barcode) throws Exception {
public int selectStockByBarcode(int businessId, String barcode, Integer receivingShipmentNo, Integer orderItemId) throws Exception {
logger.info("selectStockByBarcode() 호출");
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("barcode", barcode);
params.put("receivingShipmentNo", receivingShipmentNo);
params.put("orderItemId", orderItemId);
return sqlSession.selectOne(NAMESPACE + "selectStockByBarcode", params);
}

@Override
public int selectReservedQuantity(int businessId, String barcode) throws Exception {
public int selectReservedQuantity(int businessId, String barcode, Integer receivingShipmentNo, Integer orderItemId) throws Exception {
logger.info("selectReservedQuantity() 호출");
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("barcode", barcode);
params.put("receivingShipmentNo", receivingShipmentNo);
params.put("orderItemId", orderItemId);
return sqlSession.selectOne(NAMESPACE + "selectReservedQuantity", params);
}

@Override
public ProductVO selectProductNameBarcode(int businessId, String barcode) throws Exception {
public ProductVO selectProductNameBarcode(int businessId, String barcode, Integer receivingShipmentNo) throws Exception {
logger.info("selectProductNameBarcode() 호출");
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("barcode", barcode);
params.put("receivingShipmentNo", receivingShipmentNo);
return sqlSession.selectOne(NAMESPACE + "selectProductNameBarcode", params);
}

@Override
public void updateReceivingStatusToComplete(int businessId, String barcode) throws Exception {
public void updateReceivingStatusToComplete(int businessId, String barcode, Integer receivingShipmentNo) throws Exception {
logger.info("updateReceivingStatusToComplete() 호출");
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("barcode", barcode);
params.put("receivingShipmentNo", receivingShipmentNo);
sqlSession.update(NAMESPACE + "updateReceivingStatusToComplete", params);

}

@Override
public List<ReceivingShipmentVO> selectReceivingShipmentNo(int businessId, Integer receivingShipmentNo) throws Exception {
public List<ReceivingShipmentVO> selectReceivingShipmentNo(int businessId, Integer receivingShipmentNo, int orderItemId) throws Exception {
logger.info("selecttReceivingShipmentNo() 호출");
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("receivingShipmentNo", receivingShipmentNo);
params.put("orderItemId", orderItemId);

return sqlSession.selectList(NAMESPACE + "getReceivingShipmentNo", params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ public interface ShipmentDAO {

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

// 입출고 번호를 누를시 스캔으로가서 특정 리스트 보여주기
public List<ReceivingShipmentVO> selectReceivingShipmentNo(int businessId, Integer receivingShipmentNo) throws Exception;

} // ShipmentDAO end
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public int updateIncreseStock(int businessId, String barcode) throws Exception {
params.put("barcode", barcode);

// SQL 실행
return sqlSession.update(NAMESPACE + "updateIncreseStock", params);
return sqlSession.update(NAMESPACE + "updateDecreaseStock", params);
}

@Override
Expand Down Expand Up @@ -161,6 +161,15 @@ public void updateShipmentStatusToComplete(int businessId, String barcode) throw

}

@Override
public List<ReceivingShipmentVO> selectReceivingShipmentNo(int businessId, Integer receivingShipmentNo) throws Exception {
logger.info("selecttReceivingShipmentNo() 호출");
Map<String, Object> params = new HashMap<>();
params.put("businessId", businessId);
params.put("receivingShipmentNo", receivingShipmentNo);
return sqlSession.selectList(NAMESPACE + "getReceivingShipmentNo", params);
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.ibatis.annotations.Mapper;

import com.stockm8.domain.vo.Criteria;
import com.stockm8.domain.vo.OrderItemVO;
import com.stockm8.domain.vo.ProductVO;
import com.stockm8.domain.vo.ReceivingShipmentVO;
import com.stockm8.domain.vo.StockVO;
Expand All @@ -13,7 +14,7 @@
public interface ReceivingService {

// 메인 입고 리스트
public List<ReceivingShipmentVO> getReceivingList(int businessId) throws Exception;
public List<ReceivingShipmentVO> getReceivingList(Integer businessId) throws Exception;

// 메인 어제 입고 리스트
public List<ReceivingShipmentVO> getYesterdayReceivingList(int businessId) throws Exception;
Expand All @@ -37,19 +38,19 @@ public interface ReceivingService {
public void insertReceiving(int businessId) throws Exception;

// 바코드 찍은 후 재고수량 증가
public int increseStockByBarcode(int businessId, String barcode) throws Exception;
public int increseStockByBarcode(int businessId, String barcode, Integer receivingShipmentNo, Integer orderItemId) throws Exception;

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

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

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

// 입출고 번호를 누를시 스캔으로가서 특정 리스트 보여주기
public List<ReceivingShipmentVO> getReceivingShipmentNo(int businessId, Integer receivingShipmentNo) throws Exception;
public List<ReceivingShipmentVO> getReceivingShipmentNo(int businessId, Integer receivingShipmentNo, int rderItemId) throws Exception;


} // ReceivingService end
Loading

0 comments on commit 40aee5c

Please sign in to comment.