/*************************************************************************************************
	프로그램명		: ReReportCancle.java
	프로그램설명	: 재보고 취소 관련 쿼리
	작성자				:
	작성일				:
	변경일				:
**************************************************************************************************/

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

import java.sql.*;
import java.util.*;
import java.text.*;

import kr.co.kihyun.db.*;
import kr.co.kihyun.lang.Encoder;
import kr.co.kihyun.util.MUtil;
import kr.co.kihyun.moumi.report.MReport;

public class ReportRecall extends DBManager{

	ResultSet rs = null;

	public int reportRecall(String docID, String deptID, String userID){
		String sql = "";
		int succNum = 0;

		try{
			int count=0;

			sql = "select count(doc_type) from tot_report where doc_id='"+docID+"' and dept_id='"+deptID+"' and user_id='"+userID+"' and doc_type=1";
			rs = execQuery(sql);
			rs.next();
			count = rs.getInt(1);

			if(count == 0){
				sql = "select count(doc_type) from tot_report where doc_id='"+docID+"' and dept_id='"+deptID+"' and doc_type=0";
				rs = execQuery(sql);
				rs.next();
				count = rs.getInt(1);

				if (count == 1){
					sql = "update tot_report set prss="+MReport.TEMP+", reg_date=null, recog="+MReport.NOT_RECOG+", recog_num=0 where doc_id='"+docID+"' and dept_id='"+deptID+"' and doc_type=0";
				}else{
					return succNum;
				}
			}else if (count == 1){
				sql = "update tot_report set prss="+MReport.TEMP+", reg_date=null, recog="+MReport.NOT_RECOG+", recog_num=0 where doc_id='"+docID+"' and dept_id='"+deptID+"' and user_id='"+userID+"' and doc_type=1";
			}else{
				return succNum;
			}
			//sql = "update tot_report set prss="+MReport.TEMP+", user_id='' where doc_id='"+docID+"' and dept_id='"+deptID+"'";
			succNum = execUpdate(sql);

			if(succNum > 0){
				sql="delete from repoadm where doc_id='"+docID+"' and dept_id='"+deptID+"' and repuser_id='"+userID+"'";
				execUpdate(sql);
			}

			return succNum;

		}catch(SQLException sqlEx){
                        //18.시스템 데이터 정보노출 : Update by YOUNGJUN,CHO
			//System.out.println(SQLMessage.getMessage(sqlEx, "ReportRecall.reportRecall()", sql));
                        sqlEx.printStackTrace();
                        //================================================
			return succNum;
		}catch(Exception ex){
			ex.printStackTrace();
			return succNum;
		}finally{
			close(rs);
			execClose();
		}
	}
}
