package incheon.res.mng.cd.post.service.impl;

import incheon.res.mng.cd.post.mapper.MngCdPostMapper;
import incheon.res.mng.cd.post.service.MngCdPostService;
import incheon.res.mng.cd.post.vo.MngCdPost;
import incheon.res.mng.cd.post.vo.MngCdPostVO;
import org.springframework.stereotype.Service;

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

@Service
public class MngCdPostServiceImpl implements MngCdPostService {
    @Resource
    private MngCdPostMapper mngCdPostMapper;

    /**
     * @MethodDESC : 우편번호 리스트 검색
     */
    public List selectPostList(MngCdPostVO vo) throws Exception {
        return mngCdPostMapper.selectPostList(vo);
    }

    /**
     * @MethodDESC : 우편번호 count
     */
    public int countPost(MngCdPostVO vo) throws Exception {
        return mngCdPostMapper.countPost(vo);
    }

    /**
     * @MethodDESC : 우편번호 삭제
     */
    public int deletePost(MngCdPostVO vo) throws Exception {
        String postNoStr = vo.getZip1Del();
        String bdngNmStr = vo.getBdstNmDel();
        String[] postNo = postNoStr.split(",");
        String[] bdngNm = bdngNmStr.split(",");

        int result = 0;
        for (int i = 0; i < postNo.length; i++) {
            vo.setZip1(postNo[i]);
            vo.setBdstNm(bdngNm[i]);
            mngCdPostMapper.deletePost(vo);
            result++;
        }
        return result;
    }

    /**
     * @MethodDESC : 우편번호 등록
     */
    public int insertPost(MngCdPostVO vo) throws Exception {
        return mngCdPostMapper.insertPost(vo);
    }

    /**
     * @MethodDESC : 우편번호 수정 하기위한 전 처리
     */
    public MngCdPost updatePostView(MngCdPostVO vo) throws Exception {
        return mngCdPostMapper.updatePostView(vo);
    }

    /**
     * @MethodDESC : 우편번호 수정
     */
    public int updatePost(MngCdPostVO vo) throws Exception {
       return mngCdPostMapper.updatePost(vo);
    }

    /**
     * @MethodDESC : 우편번호 등록시 중복체크
     */
    public int chkPost(MngCdPostVO vo) throws Exception {
        return mngCdPostMapper.chkPost(vo);
    }
}
