package kr.co.kihyun.beans.batch;

import java.io.IOException;
import java.sql.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Arrays;

import java.sql.Blob;
import java.sql.PreparedStatement;

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.SysAuth;
import kr.co.kihyun.beans.entity.TotDoc;
import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportProcess;
import kr.co.kihyun.beans.entity.TotReportType;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import kr.co.kihyun.beans.entity.ecross.IRemotePersistable;
import kr.co.kihyun.beans.entity.util.QueryImpl;
import kr.co.kihyun.io.IUploadable;
import kr.co.kihyun.lang.MString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.text.html.ServletUtil;

import java.sql.ResultSet;
import kr.co.kihyun.lang.MInteger;
import kr.co.kihyun.lang.MLong;
import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.lang.MString;

public class AcceptNote  extends DBManager {

   private static final Logger LOG = LoggerFactory.getLogger(AcceptNote.class);

	private ResultSet rs = null;    
	private int count = 0;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    PrintWriter out=null;

	public void AcceptNote(HttpServletRequest req, HttpServletResponse res) throws IOException {

		StringBuilder sql = new StringBuilder(250);
           res.setContentType("text/html;charset=UTF-8");
			out = res.getWriter();
		try {
         

            String userID = req.getParameter("userID");
            String ID = req.getParameter("id");
            String prss = req.getParameter("prss");
            
            if(prss.isEmpty() || prss.equals(null)){
                sql.append("UPDATE MOUMI_TOT_REPORT SET PRSS = '3' WHERE USER_ID = '"+userID+"' and ID = '"+ID+"'");                
            }else{
                sql.append("UPDATE MOUMI_TOT_REPORT SET PRSS = '"+prss+"' WHERE USER_ID = '"+userID+"' and ID = '"+ID+"'");
            }
            
            //rs = execQuery(sql);
            execUpdate(sql.toString());

            //System.out.println(":::수정 쿼리::"+sql.toString());

            //out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.success")));
            out.println(ServletUtil.getJavaScript("opener.location.reload();"));
            out.println(ServletUtil.getJavaScript("self.close();"));

		} 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) {
            out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.fail")));
			out.println(ServletUtil.getJavaScript("history.back();"));
			throw new RuntimeException(ex);
		} finally {
			close(rs);
			execClose();
		}

    }

}
