/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sikd.ikonsol.ejb.dao;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.ikonsol.model.MonitoringProvinsi;

/**
 *
 * @author Imam Bhoim
 */
public class MonitoringProvinsiDao implements IDAO<MonitoringProvinsi>, Serializable {

    private SqlSessionFactory sqlSessionFactory = null;
    private SqlSession session = null;

    public MonitoringProvinsiDao(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public MonitoringProvinsi createNew() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<MonitoringProvinsi> findAll() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<MonitoringProvinsi> findByCriteria(String sql) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public MonitoringProvinsi findByID(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public MonitoringProvinsi findByKode(String kode) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public MonitoringProvinsi save(MonitoringProvinsi obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public MonitoringProvinsi update(MonitoringProvinsi obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteByID(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteByPK(String pk) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public List<MonitoringProvinsi> findAllByTahunLaporanMP(int tahun, int idlaporan, int idbas, String kdPeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("idlaporan", idlaporan);
        map.put("idbas", idbas);
        map.put("kdPeriode", kdPeriode);
        List<MonitoringProvinsi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("MonitoringProvinsiMapper.selectMonitoringProvinsiMon", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<MonitoringProvinsi> findAllByTahunLaporanMW(int tahun, int idlaporan, int idbas, String kdPeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("idlaporan", idlaporan);
        map.put("idbas", idbas);
        map.put("kdPeriode", kdPeriode);
        List<MonitoringProvinsi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("MonitoringProvinsiMapper.selectMonitoringWilayahMon", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<MonitoringProvinsi> findAllByTahunLaporanMN(int tahun, int idbas, String kdPeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("idbas", idbas);
        map.put("kdPeriode", kdPeriode);
        List<MonitoringProvinsi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("MonitoringProvinsiMapper.selectMonitoringNasionalMon", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<MonitoringProvinsi> findAllByTahunLaporanMPLak(int tahun, int idlaporan, String kdPeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("idlaporan", idlaporan);
        map.put("kdPeriode", kdPeriode);
        if (idlaporan == 4) {
            List<MonitoringProvinsi> list = null;
            session = sqlSessionFactory.openSession();
            try {

                list = session.selectList("MonitoringProvinsiMapper.selectMonitoringProvinsiLakMon", map);

            } finally {
                session.close();
            }
            return list;
        } else if (idlaporan == 5) {
            List<MonitoringProvinsi> list = null;
            session = sqlSessionFactory.openSession();
            try {

                list = session.selectList("MonitoringProvinsiMapper.selectMonitoringProvinsiLpeMon", map);

            } finally {
                session.close();
            }
            return list;
        } else {
            List<MonitoringProvinsi> list = null;
            session = sqlSessionFactory.openSession();
            try {

                list = session.selectList("MonitoringProvinsiMapper.selectMonitoringProvinsiLpsalMon", map);

            } finally {
                session.close();
            }
            return list;
        }
    }

    public List<MonitoringProvinsi> findAllByTahunLaporanMWLak(int tahun, int idlaporan, String kdPeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("idlaporan", idlaporan);
        map.put("kdPeriode", kdPeriode);
        if (idlaporan == 4) {
            List<MonitoringProvinsi> list = null;
            session = sqlSessionFactory.openSession();
            try {

                list = session.selectList("MonitoringProvinsiMapper.selectMonitoringWilayahLakMon", map);

            } finally {
                session.close();
            }
            return list;
        } else if (idlaporan == 5) {
            List<MonitoringProvinsi> list = null;
            session = sqlSessionFactory.openSession();
            try {

                list = session.selectList("MonitoringProvinsiMapper.selectMonitoringWilayahLpeMon", map);

            } finally {
                session.close();
            }
            return list;
        } else {
            List<MonitoringProvinsi> list = null;
            session = sqlSessionFactory.openSession();
            try {

                list = session.selectList("MonitoringProvinsiMapper.selectMonitoringWilayahLpsalMon", map);

            } finally {
                session.close();
            }
            return list;
        }
    }

    public List<MonitoringProvinsi> findAllByTahunLaporanMNLak(int tahun, String kdPeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("kdPeriode", kdPeriode);
        List<MonitoringProvinsi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("MonitoringProvinsiMapper.selectMonitoringNasionalLakMon", map);

        } finally {
            session.close();
        }
        return list;
    }

}
