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

import incheon.res.mng.cd.cchk.mapper.MngCdCchkMapper;
import incheon.res.mng.cd.cchk.service.MngCdCchkService;
import incheon.res.mng.cd.cchk.vo.MngCdCchkVO;
import org.springframework.stereotype.Service;

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

@Service
public class MngCdCchkServiceImpl implements MngCdCchkService {
    @Resource
    private MngCdCchkMapper mngCdCchkMapper;

    /**
     * @MethodDESC : 체크코드 리스트 검색
     */
    public List selectCchkList(MngCdCchkVO vo) throws Exception{
        return mngCdCchkMapper.selectCchkList(vo);
    }

    /**
     * @MethodDESC : 코드설명 리스트
     */
    public List selectCdeexpList(MngCdCchkVO vo) throws Exception{
        return mngCdCchkMapper.selectCdeexpList(vo);
    }


    /**
     * @MethodDESC : 체크코드 count
     */
    public int countCchk(MngCdCchkVO vo) throws Exception{
        return mngCdCchkMapper.countCchk(vo);
    }

    /**
     * @MethodDESC : 체크코드 등록
     */
    public int insertCchk(MngCdCchkVO vo) throws Exception{
       return mngCdCchkMapper.insertCchk(vo);
    }

    /**
     * @MethodDESC : 체크코드 삭제
     */
    public int deleteCchk(MngCdCchkVO vo) throws Exception{
        String tblNamStr = vo.getUseTblNmDel();
        String allCdeStr = vo.getWholCd();
        String [] tblNam = tblNamStr.split(",");
        String [] allCde = allCdeStr.split(",");

        int result = 0;

        for(int i = 0;i<tblNam.length;i++){
            vo.setUseTblNm(tblNam[i]);
            vo.setWholCd(allCde[i]);
            mngCdCchkMapper.deleteCchk(vo);
            result++;
        }

        return result;
    }
}
