package kr.co.kihyun.beans.totsys.report;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.jdo.PersistenceManager;

import kr.co.kihyun.beans.entity.AssignType;
import kr.co.kihyun.beans.entity.MDept;
import kr.co.kihyun.beans.entity.MUser;
import kr.co.kihyun.beans.entity.MoumiEntity;
import kr.co.kihyun.beans.entity.TotDoc;
import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportType;
import kr.co.kihyun.beans.entity.TotTable;
import kr.co.kihyun.beans.entity.util.QueryImpl;
import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.lang.MString;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReportDataUpdate extends DBManager {
	private static final Logger LOG = LoggerFactory.getLogger(ReportUpdate.class);

	private ResultSet rs = null;

        public void update_is_tot_report(Long docID)
	{
		StringBuilder sql = new StringBuilder(250);
		StringBuilder sqlParam = new StringBuilder(250);

		try {

                    sql.append("UPDATE IFDBMGR.IS_MOUMI_TOT_REPORT        ")
                       .append("	SET MANAGEMENTCODE = CM_FROM_PARTY_ID  ")
                       .append("	WHERE DOC_ID    = " + docID + " AND IS_APLIED = 'N' ");
                    
                    execUpdate(sql.toString());
                    
		} catch (SQLException sqlEx) {
			LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}",
					new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql });
			throw new RuntimeException(sqlEx);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			close(rs);
			execClose();
		}
	}


        //20160509 추가
        /**
         * 업데이트 메소드(교육청 자료 조회 관련 IR_MOUMI_TOT_REPORT 테이블에서 IS_APLIED 값을 Y로 초기화)
         * @param params - 검색조건맵
         * @참조페이지 - report_list.jsp / total_reports.jsp
         */
        public int update_IR_TOT_REPORT_IsAplied(Long docID) {

            StringBuilder sql = new StringBuilder(250);
            StringBuilder sqlParam = new StringBuilder(250);

            int cnt = 0;
            
            try {

                sql.append("UPDATE IFDBMGR.IR_MOUMI_TOT_REPORT ")
                   .append("	SET IS_APLIED = 'Y'  ")
                   .append("	WHERE DOC_ID    = " + docID )
                   .append("    AND (IS_APLIED = 'N' OR IS_APLIED IS NULL) ");

                cnt = execUpdate(sql.toString());

            } catch (SQLException sqlEx) {
                    LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}",
                                    new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql });
                    throw new RuntimeException(sqlEx);
            } catch (Exception ex) {
                    throw new RuntimeException(ex);
            } finally {
                    close(rs);
                    execClose();
}

            return cnt;
        }

    
}
