Skip to content

Commit

Permalink
수정1
Browse files Browse the repository at this point in the history
  • Loading branch information
shoqying committed Dec 16, 2024
1 parent 5cca173 commit 1daf786
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 76 deletions.
10 changes: 10 additions & 0 deletions stockMate/src/main/java/com/stockm8/persistence/ReceivingDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

public interface ReceivingDAO {

Expand All @@ -30,5 +31,14 @@ public interface ReceivingDAO {

// recevingShipment 테이블 insert
public void insertReceiving(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;

} // ReceivingDAO end
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

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

@Repository
public class ReceivingDAOImpl implements ReceivingDAO {

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

private static final String NAMESPACE = "com.stockm8.mapper.ReceivingShipmentMapper.";
private static final String NAMESPACE = "com.stockm8.mappers.receivingMapper.";

// 디비 연결 객체 주입
@Inject
Expand All @@ -28,23 +29,23 @@ public class ReceivingDAOImpl implements ReceivingDAO {
// 입고 메인 오늘 들어올 리스트
@Override
public List<ReceivingShipmentVO> selectReceivingList(int businessId) throws Exception {
logger.info("ReceivingList() 호출");
logger.info("selectReceivingList() 호출");

return sqlSession.selectList(NAMESPACE + "getReceivingList", businessId);
}

// 입고 메인 오늘 들어올 리스트
@Override
public List<ReceivingShipmentVO> selectYesterdayReceivingList(int businessId) throws Exception {
logger.info("ReceivingList() 호출");
logger.info("selectYesterdayReceivingList() 호출");

return sqlSession.selectList(NAMESPACE + "getYesterdayReceivingList", businessId);
}

// 입고 메인 오늘 들어올 리스트
@Override
public List<ReceivingShipmentVO> selectTDBYReceivingList(int businessId) throws Exception {
logger.info("ReceivingList() 호출");
logger.info("selectTDBYReceivingList() 호출");

return sqlSession.selectList(NAMESPACE + "getTDBYReceivingList", businessId);
}
Expand Down Expand Up @@ -100,7 +101,36 @@ public void insertReceiving(int businessId) throws Exception {
sqlSession.insert(NAMESPACE + "insertReceiving", businessId);
}

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

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

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

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

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



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,5 @@ public interface StockDAO {
// 카테고리 목록 조회
public List<CategoryVO> selectAllCategories() 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;

}
29 changes: 0 additions & 29 deletions stockMate/src/main/java/com/stockm8/persistence/StockDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,36 +95,7 @@ public List<CategoryVO> selectAllCategories() throws Exception {



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

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

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

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

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

}

Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ public void insertReceiving(int businessId) throws Exception {
@Override
public int increseStockByBarcode(int businessId, String barcode) throws Exception {
logger.info("increseStockByBarcode() 호출");
List<StockVO> stock = sdao.selectQuantityCheckByBarcode(businessId, barcode);
List<StockVO> stock = rdao.selectQuantityCheckByBarcode(businessId, barcode);
if (stock == null) {
return -1; // 유효하지 않은 바코드
}

int updatedRows = sdao.updateIncreseStock(businessId, barcode);
int updatedRows = rdao.updateIncreseStock(businessId, barcode);
if (updatedRows > 0) {
return sdao.selectStockByBarcode(businessId, barcode); // 증가 후 남은 재고 반환
return rdao.selectStockByBarcode(businessId, barcode); // 증가 후 남은 재고 반환
} else {
throw new RuntimeException("재고 업데이트 실패");
}
Expand Down
39 changes: 33 additions & 6 deletions stockMate/src/main/resources/mappers/receivingMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stockm8.mappers.receivingMapper">

<resultMap type="com.stockm8.domain.vo.ReceivingShipmentVO" id="receivingshipmentMap">
<resultMap type="com.stockm8.domain.vo.ReceivingShipmentVO" id="receivingShipmentMap">
<id property="productId" column="product_id"/>
<result property="receivingShipmentNo" column="receiving_shipment_no"/>
<result property="createdAt" column="created_at"/>
Expand Down Expand Up @@ -57,7 +57,7 @@
</insert>

<!-- 오늘 입고 예정 리스트 -->
<select id="getReceivingList" resultMap="receivingshipmentMap">
<select id="getReceivingList" resultMap="receivingShipmentMap">
select
r.receiving_shipment_no,
r.transaction_type,
Expand All @@ -79,7 +79,7 @@
</select>

<!-- 어제 입고 리스트 -->
<select id="getYesterdayReceivingList" resultMap="receivingshipmentMap">
<select id="getYesterdayReceivingList" resultMap="receivingShipmentMap">
select
r.receiving_shipment_no,
r.transaction_type,
Expand All @@ -101,7 +101,7 @@
</select>

<!-- 그저께 입고 리스트 -->
<select id="getTDBYReceivingList" resultMap="receivingshipmentMap">
<select id="getTDBYReceivingList" resultMap="receivingShipmentMap">
select
r.receiving_shipment_no,
r.transaction_type,
Expand All @@ -123,7 +123,7 @@
</select>

<!-- 입고 내역 히스토리 -->
<select id="getReceivingHistoryList" resultMap="receivingshipmentMap">
<select id="getReceivingHistoryList" resultMap="receivingShipmentMap">
select
r.receiving_shipment_no,
r.transaction_type,
Expand All @@ -146,7 +146,7 @@
</select>

<!-- 입고 내역 검색 -->
<select id="getHistoryByDateRange" parameterType="map" resultMap="receivingshipmentMap">
<select id="getHistoryByDateRange" parameterType="map" resultMap="receivingShipmentMap">
SELECT
r.receiving_shipment_no,
r.transaction_type,
Expand Down Expand Up @@ -211,5 +211,32 @@
AND u.business_id = #{businessId}
</select>

<!-- receiving scan을 위한 매퍼 -->
<!-- 바코드로 제품 조회 -->
<select id="selectQuantityCheckByBarcode" resultType="com.stockm8.domain.vo.StockVO">
SELECT s.product_id, p.product_name, s.total_quantity, s.warehouse_id
FROM stocks s
JOIN products p ON p.product_id = s.product_id
WHERE p.product_barcode = #{barcode} AND s.business_id = #{businessId}
</select>

<!-- 바코드로 재고 1 감소 -->
<update id="updateIncreseStock">
UPDATE stocks s
JOIN products p on p.product_id = s.product_id
SET s.total_quantity = s.total_quantity + 1
WHERE p.product_barcode = #{barcode} AND s.business_id = #{businessId}
AND s.total_quantity > 0
</update>

<!-- 바코드로 남은 재고 조회 -->
<select id="selectStockByBarcode" resultType="int">
SELECT s.total_quantity
FROM stocks s
JOIN products p on p.product_id = s.product_id
WHERE p.product_barcode = #{barcode} AND s.business_id = #{businessId}
</select>
<!-- receiving scan을 위한 매퍼 -->


</mapper>
27 changes: 1 addition & 26 deletions stockMate/src/main/resources/mappers/stockMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,31 +211,6 @@
WHERE business_id = #{businessId} AND is_deleted = 0
</select>

<!-- receiving scan을 위한 매퍼 -->
<!-- 바코드로 제품 조회 -->
<select id="selectQuantityCheckByBarcode" resultType="com.stockm8.domain.vo.StockVO">
SELECT s.product_id, p.product_name, s.total_quantity, s.warehouse_id
FROM stocks s
JOIN products p ON p.product_id = s.product_id
WHERE p.product_barcode = #{barcode} AND s.business_id = #{businessId}
</select>

<!-- 바코드로 재고 1 감소 -->
<update id="updateIncreseStock">
UPDATE stocks s
JOIN products p on p.product_id = s.product_id
SET s.total_quantity = s.total_quantity + 1
WHERE p.product_barcode = #{barcode} AND s.business_id = #{businessId}
AND s.total_quantity > 0
</update>

<!-- 바코드로 남은 재고 조회 -->
<select id="selectStockByBarcode" resultType="int">
SELECT s.total_quantity
FROM stocks s
JOIN products p on p.product_id = s.product_id
WHERE p.product_barcode = #{barcode} AND s.business_id = #{businessId}
</select>
<!-- receiving scan을 위한 매퍼 -->


</mapper>

0 comments on commit 1daf786

Please sign in to comment.