package egovframework.com.mtdata.cmmnty.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.egovframe.rte.fdl.idgnr.EgovIdGnrService;
import org.springframework.stereotype.Service;

import egovframework.com.mtdata.cmmn.vo.BasicVO;
import egovframework.com.mtdata.cmmnty.mapper.CmmntyMapper;
import egovframework.com.mtdata.cmmnty.service.CmmntyService;
import egovframework.com.mtdata.cmmnty.vo.CmmntyVO;

@Service("CmmntyService")
public class CmmntyServiceImpl extends EgovAbstractServiceImpl implements CmmntyService {

	/** CmmntyMapper */
	@Resource(name = "CmmntyMapper")
	private CmmntyMapper cmmntyMapper;

	/** ID Generation */
	@Resource(name = "egovIdGnrService")
	private EgovIdGnrService egovIdGnrService;

	/**
	 * 글을 등록한다.
	 * @param vo - 등록할 정보가 담긴 CmmntyVO
	 * @return 등록 결과
	 * @exception Exception
	 */
	@Override
	public int insertCmmnty(CmmntyVO vo) throws Exception {
//		public String insertCmmnty(CmmntyVO vo) throws Exception {

		/** ID Generation Service */
		String id = egovIdGnrService.getNextStringId();
		vo.setCmmntyId(id);

		return cmmntyMapper.insertCmmnty(vo);
	}

	/**
	 * 글을 수정한다.
	 * @param vo - 수정할 정보가 담긴 CmmntyVO
	 * @return void형
	 * @exception Exception
	 */
	@Override
	public void updateCmmnty(CmmntyVO vo) throws Exception {
		cmmntyMapper.updateCmmnty(vo);
	}

	/**
	 * 글을 삭제한다.
	 * @param vo - 삭제할 정보가 담긴 CmmntyVO
	 * @return void형
	 * @exception Exception
	 */
	@Override
	public void deleteCmmnty(CmmntyVO vo) throws Exception {
		cmmntyMapper.deleteCmmnty(vo);
	}

	/**
	 * 글을 조회한다.
	 * @param vo - 조회할 정보가 담긴 CmmntyVO
	 * @return 조회한 글
	 * @exception Exception
	 */
	@Override
	public CmmntyVO selectCmmnty(CmmntyVO vo) throws Exception {
		CmmntyVO resultVO = cmmntyMapper.selectCmmnty(vo);
		if (resultVO == null)
			throw processException("info.nodata.msg");
		return resultVO;
	}

	/**
	 * 글 목록을 조회한다.
	 * @param searchVO - 조회할 정보가 담긴 VO
	 * @return 글 목록
	 * @exception Exception
	 */
	@Override
	public List<CmmntyVO> selectCmmntyList(BasicVO searchVO) throws Exception {
		return cmmntyMapper.selectCmmntyList(searchVO);
	}

	/**
	 * 글 총 갯수를 조회한다.
	 * @param searchVO - 조회할 정보가 담긴 VO
	 * @return 글 총 갯수
	 * @exception
	 */
	@Override
	public int selectCmmntyListTotCnt(BasicVO searchVO) {
		return cmmntyMapper.selectCmmntyListTotCnt(searchVO);
	}

}
