package incheon.res.com.ntce.service.impl;

import incheon.res.com.ntce.mapper.UngisComNtceMapper;
import incheon.res.com.ntce.service.UngisComNtceService;
import incheon.res.com.ntce.vo.UngisComNtceVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("ungisComNtceService")
public class UngisComNtceServiceImpl implements UngisComNtceService {
	
	@Resource
	private UngisComNtceMapper ungisComNtceMapper;
	
	/**
	 * 공통공지사항의 일련번호의 최대값
	 */
	public int selectComNtceMaxTmpSeq() throws Exception {	
		return ungisComNtceMapper.selectComNtceMaxTmpSeq();
	}

	/**
	 * 일련번호에 따른 공통공지사항상세조회
	 */
	public UngisComNtceVO selectComNtce(UngisComNtceVO vo) throws Exception {
		
		List ntce = ungisComNtceMapper.selectComNtce(vo);
		int ntCnt = ntce.size();
		UngisComNtceVO ntceVO = new UngisComNtceVO();
		if(ntCnt == 0){
			ntceVO.setBrdSub("작성된 공지사항이 없습니다.");
			ntceVO.setBrdDes("");
		}else{
			ntceVO = (UngisComNtceVO)ntce.get(0);
		}
		
		return ntceVO;
	}

	public UngisComNtceVO selectIntroComNtce() throws Exception {
		//일련번호 최대값
		int maxTmpSeq = selectComNtceMaxTmpSeq();
		String strTmpSeq =  String.valueOf(maxTmpSeq);
		//VO에 일련번호 최대값 세팅
		UngisComNtceVO searchVO = new UngisComNtceVO();
		searchVO.setTmpSeq(strTmpSeq);
		
		UngisComNtceVO ntceVO = selectComNtce(searchVO);
		
		return ntceVO;
	}

	public void updateComNtceHitVst(UngisComNtceVO vo) throws Exception {
		ungisComNtceMapper.updateComNtceHitVst(vo);
	}

	public List selectComNtceList(UngisComNtceVO vo) throws Exception{
		return ungisComNtceMapper.selectComNtceList(vo);
	}
	
	public int selectComNtceCount(UngisComNtceVO vo) throws Exception{
		return ungisComNtceMapper.selectComNtceCount(vo);
	}
}
