package com.madeu.dao.web.webstockhistory;

import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import jakarta.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class WebStockHistorySqlMapDAO extends SqlSessionDaoSupport{

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 현재까지 전체 입고 수량/금액, 출고 수량/금액 확인
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalStockStatus(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockStatus START");
		String sqlId = "WebStockHistory.selectTotalStockStatus";
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockStatus END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고 현황 정보 촛 갯수 조회 (count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalStockStatusCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockStatusCount START");
		String sqlId = "WebStockHistory.selectTotalStockStatusCount";
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockStatusCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고 현황 리스트 정보 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListStockStatus(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectListStockStatus START");
		String sqlId = "WebStockHistory.selectListStockStatus";
		logger.debug("WebStockHistorySqlMapDAO selectListStockStatus END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고 현황 리스트 정보 조회 (List, Excel)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListStockStatusExcel(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectListStockStatusExcel START");
		String sqlId = "WebStockHistory.selectListStockStatusExcel";
		logger.debug("WebStockHistorySqlMapDAO selectListStockStatusExcel END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고내역 상단 각 타입별 수량/금액 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalStockHistoryType(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockHistoryType START");
		String sqlId = "WebStockHistory.selectTotalStockHistoryType";
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockHistoryType END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 입출고 내역 정보 촛 갯수 조회 (count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalStockHistoryCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockHistoryCount START");
		String sqlId = "WebStockHistory.selectTotalStockHistoryCount";
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockHistoryCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고 내역 리스트 정보 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListStockHistory(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectListStockHistory START");
		String sqlId = "WebStockHistory.selectListStockHistory";
		logger.debug("WebStockHistorySqlMapDAO selectListStockHistory END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고 내역 리스트 정보 조회 (List, Excel)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListStockHistoryExcel(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectListStockHistoryExcel START");
		String sqlId = "WebStockHistory.selectListStockHistoryExcel";
		logger.debug("WebStockHistorySqlMapDAO selectListStockHistoryExcel END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 당일 입고 날짜 확인 (count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> checkStockHistory(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO checkStockHistory START");
		String sqlId = "WebStockHistory.checkStockHistory";
		logger.debug("WebStockHistorySqlMapDAO checkStockHistory END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 현재 재고총액, 거래처수, 품목수 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalStockHistoryAmount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockHistoryAmount START");
		String sqlId = "WebStockHistory.selectTotalStockHistoryAmount";
		logger.debug("WebStockHistorySqlMapDAO selectTotalStockHistoryAmount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 해당 일자까지의 재고마감 상세 
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListStockHistoryDetail(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO selectListStockHistoryDetail START");
		String sqlId = "WebStockHistory.selectListStockHistoryDetail";
		logger.debug("WebStockHistorySqlMapDAO selectListStockHistoryDetail END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 입출고 현황 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertStockHistory(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO insertStockHistory START");
		String sqlId = "WebStockHistory.insertStockHistory";
		logger.debug("WebStockHistorySqlMapDAO insertStockHistory END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 입출고 현황 정보 등록 2 (재고조정)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertStockHistory2(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebStockHistorySqlMapDAO insertStockHistory2 START");
		String sqlId = "WebStockHistory.insertStockHistory2";
		logger.debug("WebStockHistorySqlMapDAO insertStockHistory2 END");
		return getSqlSession().insert(sqlId, paramMap);
	}

}
