package kr.co.kihyun.beans.batch;
import java.sql.*;
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 java.util.Calendar;
import java.util.Collections;
import java.util.Date;

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

import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.db.DBManagerCmcp;

public class GroupConinfoUpConsol  extends DBManagerCmcp {

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

    public void updateMoumiDept() {

        StringBuilder sql = new StringBuilder(250);

        Calendar oCalendar = Calendar.getInstance( );  // 현재 날짜/시간 등의 각종 정보 얻기
        Integer yyCompare = oCalendar.get(Calendar.YEAR);
        Integer monCompare = (oCalendar.get(Calendar.MONTH) + 1);
        Integer dayCompare = oCalendar.get(Calendar.DAY_OF_MONTH);
        Integer hourCompare = oCalendar.get(Calendar.HOUR_OF_DAY);
        String dateCompare = Integer.toString(yyCompare)+"-"+Integer.toString(monCompare)+"-"+Integer.toString(dayCompare)+" "+"01:00:00";//2012-07-01 01:00:00

        try {
        	//out = res.getWriter();
            sql.append("MERGE INTO MOUMI_DEPT A                                                                                                       \n");
            sql.append("USING (                                                                                                                       \n");
            sql.append("	SELECT TREE1.ORG_CODE AS ID                                                                                           \n");
            sql.append("		, TREE1.ATPT_OFCDC_ORG_CODE AS ROOT_DEPT                                                                      \n");
            sql.append("		, NULL AS HANDY_ID                                                                                            \n");
            sql.append("		, TREE1.KRA_ORG_NM AS NAME                                                                                    \n");
            sql.append("		, NULL AS ADDRESS                                                                                             \n");
            sql.append("		, DETAIL.ORG_TELNO AS PHONE                                                                                   \n");
            sql.append("		, TREE1.ORG_CODE AS PASSCODE                                                                                  \n");
            sql.append("		, NULL AS RECO_IMG                                                                                            \n");
            sql.append("		, 2 AS SYS_AUTH, TREE1.STDIL_SNO AS PRIORITY                                                                  \n");
            sql.append("		, CASE                                                                                                        \n");
            sql.append("			WHEN MASTER.ORG_CODE LIKE '%00000001' OR MASTER.ORG_CODE LIKE '%00000000' THEN NULL                   \n");
            sql.append("			ELSE TREE1.UPPER_ORG_CODE                                                                             \n");
            sql.append("		END AS UPPER_DEPT                                                                                             \n");

            /*직속기관(INSTT_CLSF_CODE='4')이고 부서가 아닌 경우 organ코드에 자신의 부서코드를 저장 */
            sql.append("                , CASE                                                                                                          \n");
            sql.append("                        WHEN MASTER.INSTT_CLSF_CODE = '4' AND MASTER.JU_ORG_INSTT_CLSF_CODE <> '4' THEN MASTER.ORG_CODE         \n");
            sql.append("                        WHEN MASTER.ORG_CODE = 'A000000001' THEN 'A000000001'         \n");
            sql.append("                        ELSE TREE1.JU_ORG_CODE                                                                                  \n");
            sql.append("                END AS ORGAN                                                                                                    \n");
            sql.append("		, NULL AS SEC_ID                                                                                                \n");
            sql.append("		, CHAR(0) AS SEQNUM                                                                                             \n");
            sql.append("		, CASE WHEN MASTER.ORG_CODE IS NULL THEN CHAR('N') ELSE CHAR('Y') END AS SEL_TYPE                               \n");

            /*조직상세 테이블에서 부서 사용유무(ORG_UON)를 사용중('Y')이면 'N'으로 미사용('N')이면 'Y'로 연계 */
            sql.append("		, CASE WHEN TREE1.ORG_UON = 'Y' AND (SCHOOL.ABSCH_YN != 'Y' OR SCHOOL.ABSCH_YN IS NULL) THEN 'N'                \n");
            sql.append("		  ELSE 'Y' END AS IS_OUT                                                                                        \n");
            sql.append("		, NULL AS LOCATION                                                                                              \n");
            sql.append("		, CASE WHEN MASTER.SCHUL_KND_SC_CODE >= '25' THEN 5 ELSE INTEGER(TRIM(MASTER.SCHUL_KND_SC_CODE)) END AS GRADE   \n");
            sql.append("		, INTEGER(TRIM(MASTER.FOND_SC_CODE)) AS FOUNDATION                                                              \n");
            sql.append("	FROM                                                                                                                    \n");
            sql.append("		TN_SYMOCMOM001 TREE1 LEFT JOIN TC_SYMOCMOC000 MASTER ON MASTER.ORG_CODE = TREE1.ORG_CODE,                       \n");
            sql.append("		TN_SYMOCMOM001 TREE2 LEFT JOIN TN_SYMOCMOC001 DETAIL ON DETAIL.ORG_CODE = TREE2.ORG_CODE,                       \n");
            sql.append("		TN_SYMOCMOM001 TREE3 LEFT JOIN TN_SYMOCMSI001 SCHOOL ON SCHOOL.ORG_CODE = TREE3.ORG_CODE                        \n");
            sql.append("	WHERE                                                                                                                   \n");
            sql.append("		TREE1.ORG_CODE = TREE2.ORG_CODE                                                                                 \n");
            sql.append("		AND TREE1.ORG_CODE = TREE3.ORG_CODE                                                                             \n");
            sql.append("		AND TREE1.ORG_BUSN_CODE = TREE2.ORG_BUSN_CODE                                                                   \n");
            sql.append("		AND TREE1.ORG_BUSN_CODE = TREE3.ORG_BUSN_CODE                                                                   \n");
            sql.append("		AND TREE1.ORG_UON = TREE2.ORG_UON                                                                               \n");
            sql.append("		AND TREE1.ORG_UON = TREE3.ORG_UON                                                                               \n");
            sql.append("		AND TREE1.APPLC_BEGIN_YMD = TREE2.APPLC_BEGIN_YMD                                                               \n");
            sql.append("		AND TREE1.APPLC_END_YMD = TREE2.APPLC_END_YMD                                                                   \n");
            sql.append("		AND TREE1.APPLC_BEGIN_YMD = TREE3.APPLC_BEGIN_YMD                                                               \n");
            sql.append("		AND TREE1.APPLC_END_YMD = TREE3.APPLC_END_YMD                                                                   \n");
            sql.append("		AND TREE1.ORG_BUSN_CODE = 'SYM00'                                                                               \n");
            //sql.append("		AND TREE1.ORG_UON = 'Y'                                                                                         \n");

            /* 기관 구분코드에서 부서와 비공식기관인 경우에만 조회 */
            sql.append("		AND TREE1.ORG_SC_CODE IN (1,3)                                                                                  \n");
            sql.append("		AND TREE1.APPLC_BEGIN_YMD <= TO_CHAR(SYSDATE, 'YYYYMMDD')                                                       \n");
            sql.append("		AND TREE1.APPLC_END_YMD >= TO_CHAR(SYSDATE, 'YYYYMMDD')                                                         \n");
            /* 최종 데이타조회 쿼리 */
            sql.append(" AND TREE1.APPLC_BEGIN_YMD=(										   									\n");
            sql.append("	SELECT													   											\n");
            sql.append("	    MAX(TREE4.APPLC_BEGIN_YMD)										   								\n");
            sql.append("	FROM                                                                                               \n");
            sql.append("			TN_SYMOCMOM001 TREE4 LEFT JOIN TC_SYMOCMOC000 MASTER ON MASTER.ORG_CODE = TREE1.ORG_CODE,  \n");
            sql.append("			TN_SYMOCMOM001 TREE5 LEFT JOIN TN_SYMOCMOC001 DETAIL ON DETAIL.ORG_CODE = TREE2.ORG_CODE,  \n");
            sql.append("			TN_SYMOCMOM001 TREE6 LEFT JOIN TN_SYMOCMSI001 SCHOOL ON SCHOOL.ORG_CODE = TREE3.ORG_CODE   \n");
            sql.append("	  WHERE                                                                                            \n");
            sql.append("			    TREE4.ORG_CODE = TREE5.ORG_CODE                                                        \n");
            sql.append("			AND TREE4.ORG_CODE = TREE6.ORG_CODE                                                        \n");
            sql.append("			AND TREE4.ORG_BUSN_CODE = TREE5.ORG_BUSN_CODE                                              \n");
            sql.append("			AND TREE4.ORG_BUSN_CODE = TREE6.ORG_BUSN_CODE                                              \n");
            sql.append("			AND TREE4.ORG_UON = TREE5.ORG_UON                                                          \n");
            sql.append("			AND TREE4.ORG_UON = TREE6.ORG_UON                                                          \n");
            sql.append("			AND TREE4.APPLC_BEGIN_YMD = TREE5.APPLC_BEGIN_YMD                                          \n");
            sql.append("			AND TREE4.APPLC_END_YMD = TREE5.APPLC_END_YMD                                              \n");
            sql.append("			AND TREE4.APPLC_BEGIN_YMD = TREE6.APPLC_BEGIN_YMD                                          \n");
            sql.append("			AND TREE4.APPLC_END_YMD = TREE6.APPLC_END_YMD                                              \n");
            sql.append("			AND TREE4.ORG_BUSN_CODE = 'SYM00'                                                          \n");
            sql.append("			AND TREE4.ORG_SC_CODE IN (1,3)                                                             \n");
            sql.append("			AND TREE4.APPLC_BEGIN_YMD <= TO_CHAR(SYSDATE, 'YYYYMMDD')                                  \n");
            sql.append("			AND TREE4.APPLC_END_YMD >= TO_CHAR(SYSDATE, 'YYYYMMDD')					   					\n");
            sql.append("	    AND TREE1.ORG_CODE=TREE4.ORG_CODE									   							\n");
            sql.append("    )													   												\n");

            sql.append(") B                                                                                                                             \n");
            sql.append("ON (A.ID = B.ID)                                                                                                                \n");
            sql.append("WHEN NOT MATCHED THEN                                                                                                           \n");
            sql.append("	INSERT (                                                                                                                \n");
            sql.append("		A.ID,                                                                                                         \n");
            sql.append("		A.ROOT_DEPT,                                                                                                  \n");
            sql.append("		A.HANDY_ID,                                                                                                   \n");
            sql.append("		A.NAME,                                                                                                       \n");
            sql.append("		A.ADDR,                                                                                                       \n");
            sql.append("		A.PHONE,                                                                                                      \n");
            sql.append("		A.PASSCODE,                                                                                                   \n");
            sql.append("		A.RECO_IMG,                                                                                                   \n");
            sql.append("		A.SYS_AUTH,                                                                                                   \n");
            sql.append("		A.PRIORITY,                                                                                                   \n");
            sql.append("		A.UPPER_DEPT,                                                                                                 \n");
            sql.append("		A.ORGAN,                                                                                                      \n");
            sql.append("		A.SEC_ID,                                                                                                     \n");
            sql.append("		A.SEQNUM,                                                                                                     \n");
            sql.append("		A.SEL_TYPE,                                                                                                   \n");
            sql.append("		A.IS_OUT,                                                                                                     \n");
            sql.append("		A.LOCATION,                                                                                                   \n");
            sql.append("		A.GRADE,                                                                                                      \n");
            sql.append("		A.FOUNDATION                                                                                                  \n");
            sql.append("	)                                                                                                                     \n");
            sql.append("	VALUES (                                                                                                              \n");
            sql.append("		B.ID,                                                                                                         \n");
            sql.append("		B.ROOT_DEPT,                                                                                                  \n");
            sql.append("		B.HANDY_ID,                                                                                                   \n");
            sql.append("		B.NAME,                                                                                                       \n");
            sql.append("		B.ADDRESS,                                                                                                    \n");
            sql.append("		B.PHONE,                                                                                                      \n");
            sql.append("		B.PASSCODE,                                                                                                   \n");
            sql.append("		B.RECO_IMG,                                                                                                   \n");
            sql.append("		B.SYS_AUTH,                                                                                                   \n");
            sql.append("		B.PRIORITY,                                                                                                   \n");
            sql.append("		B.UPPER_DEPT,                                                                                                 \n");
            sql.append("		B.ORGAN,                                                                                                      \n");
            sql.append("		B.SEC_ID,                                                                                                     \n");
            sql.append("		B.SEQNUM,                                                                                                     \n");
            sql.append("		B.SEL_TYPE,                                                                                                   \n");
            sql.append("		B.IS_OUT,                                                                                                     \n");
            sql.append("		B.LOCATION,                                                                                                   \n");
            sql.append("		B.GRADE,                                                                                                      \n");
            sql.append("		B.FOUNDATION                                                                                                  \n");
            sql.append(")                                                                                                                     \n");
            sql.append("WHEN MATCHED THEN UPDATE SET                                                                                          \n");
            sql.append("A.ID          = B.ID,                                                                                                 \n");
            sql.append("A.ROOT_DEPT   = B.ROOT_DEPT,                                                                                          \n");
            sql.append("A.HANDY_ID    = B.HANDY_ID,                                                                                           \n");
            sql.append("A.NAME        = B.NAME,                                                                                               \n");
            sql.append("A.ADDR        = B.ADDRESS,                                                                                            \n");
            sql.append("A.PHONE       = B.PHONE,                                                                                              \n");
            sql.append("A.PASSCODE    = B.PASSCODE,                                                                                           \n");
            sql.append("A.RECO_IMG    = B.RECO_IMG,                                                                                           \n");
            sql.append("A.SYS_AUTH    = B.SYS_AUTH,                                                                                           \n");
            sql.append("A.PRIORITY    = B.PRIORITY,                                                                                           \n");
            sql.append("A.UPPER_DEPT  = B.UPPER_DEPT,                                                                                         \n");
            sql.append("A.ORGAN       = B.ORGAN,                                                                                              \n");
            sql.append("A.SEC_ID      = B.SEC_ID,                                                                                             \n");
            sql.append("A.SEQNUM      = B.SEQNUM,                                                                                             \n");
            sql.append("A.SEL_TYPE    = B.SEL_TYPE,                                                                                           \n");
            sql.append("A.IS_OUT      = B.IS_OUT,                                                                                             \n");
            sql.append("A.LOCATION    = B.LOCATION,                                                                                           \n");
            sql.append("A.GRADE       = B.GRADE,                                                                                              \n");
            sql.append("A.FOUNDATION  = B.FOUNDATION                                                                                          \n");

            System.out.print("::::updateMoumiDept::::\n"+sql.toString());


            int iSuccessCount = execUpdate(sql.toString());

            System.out.println(":::: updateMoumiDept ::::");
            System.out.println(":::: execute date : " + new Date());
            System.out.println(":::: success count : " + iSuccessCount);

            return;

        } catch (SQLException sqlEx) {
            throw new RuntimeException(sqlEx);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            //close(rs);
            //execClose();
            try {
                if(rs!=null) {rs.close();}
                if(stmt!=null) {stmt.close();}
                if(con!=null) {con.close();}
            } catch (Exception e) {
                //31.오류 상황 대응 부재_CWE-390 Add by YOUNGJUN,CHO
                e.printStackTrace();
                //++++++++++++++++++++++++++++++++++++++++++++++++
            }
        }
    }


    public void updateMoumiMuser() {
        StringBuilder sql = new StringBuilder(250);

        Calendar oCalendar = Calendar.getInstance( );  // 현재 날짜/시간 등의 각종 정보 얻기
        Integer yyCompare = oCalendar.get(Calendar.YEAR);
        Integer monCompare = (oCalendar.get(Calendar.MONTH) + 1);
        Integer dayCompare = oCalendar.get(Calendar.DAY_OF_MONTH);
        Integer hourCompare = oCalendar.get(Calendar.HOUR_OF_DAY);
        String dateCompare = Integer.toString(yyCompare)+"-"+Integer.toString(monCompare)+"-"+Integer.toString(dayCompare)+" "+"01:00:00";//2012-07-01 01:00:00

        try {
        	 sql.append("MERGE INTO MOUMI_MUSER A USING (                                                                                           \n");
             sql.append("    SELECT                                                                                                                 \n");
             sql.append("    US.USRID AS ID                                                                                                         \n");
             sql.append("    , VARCHAR('1') AS PASSWD                                                                                               \n");
             sql.append("    , US.USER_NM_ENCPT AS NAME                                                                                             \n");
             sql.append("    , NULL AS SL_NO_1                                                                                                      \n");
             sql.append("    , NULL AS SL_NO_2                                                                                                      \n");
             sql.append("    , US.EMAIL_ADRES AS EMAIL                                                                                              \n");
             sql.append("    , US.OFFM_TELNO AS PHONE                                                                                               \n");
             sql.append("    , NULL AS CELL_PHONE                                                                                                   \n");
             sql.append("    , CASE WHEN US.ALL_MASTR_YN = 'Y' OR US.MNGR_YN = 'Y' THEN 9        \n");
             sql.append("     		WHEN GR.INSTT_CLSF_CODE <> '5' AND USER_SC_CODE = '6' THEN 7     \n");
             sql.append("     		WHEN GR.INSTT_CLSF_CODE = '5' AND USER_SC_CODE = '6' THEN 5      \n");
             sql.append("      		ELSE 2 END AS SYS_AUTH        								 \n");
             sql.append("    , CASE WHEN US.USE_POSBL_YN = 'Y' THEN CHAR('N') ELSE CHAR('Y') END AS DEL_TYPE                                        \n");
             sql.append("    , DT.ORG_CODE AS DEPT_ID                                                                                               \n");
             sql.append("    , 0 AS PRIORITY                                                                                                        \n");
             sql.append("    , NULL AS DUTY_NAME                                                                                                    \n");
             sql.append("    , NULL AS GW_ID                                                                                                        \n");
             sql.append("    , TIMESTAMP('1970-01-01') AS DEL_DATE                                                                                  \n");
             sql.append("    , US.P_NO AS EMP_CODE                                                                                                  \n");
             sql.append("    , NULL AS ROLES                                                                                                        \n");
             sql.append("    , 'N' AS MOD_YN                                                              \n");  /*인사이동 유무를 default로 N으로 저장 */
             sql.append("   FROM                                                                                                                    \n");
             sql.append("     TN_SYMUSMUM001 US                                                                                                     \n");
             sql.append("   , TN_SYMOCMOC001 DT                                                                                                     \n");
             sql.append("   , TC_SYMOCMOC000 GR                                                                                                     \n");
             sql.append("   WHERE                                                                                                                   \n");
             sql.append("     US.PSITN_ORG_CODE = DT.ORG_CODE                                                                                       \n");
             sql.append("     AND DT.ORG_CODE = GR.ORG_CODE                                                                                         \n");
             sql.append("     ) B                                                                                                                   \n");
             sql.append("     ON (A.ID = B.ID )    WHEN NOT MATCHED THEN                                                                            \n");
             sql.append("     INSERT (                                                                                                              \n");
             sql.append("     A.ID                                                                                                                  \n");
             sql.append("     , A.PASSWD                                                                                                            \n");
             sql.append("     , A.NAME                                                                                                              \n");
             sql.append("     , A.SL_NO_1                                                                                                           \n");
             sql.append("     , A.SL_NO_2                                                                                                           \n");
             sql.append("     , A.EMAIL                                                                                                             \n");
             sql.append("     , A.PHONE                                                                                                             \n");
             sql.append("     , A.CELL_PHONE                                                                                                        \n");
             sql.append("     , A.SYS_AUTH                                                                                                          \n");
             sql.append("     , A.DEL_TYPE                                                                                                          \n");
             sql.append("     , A.DEPT_ID                                                                                                           \n");
             sql.append("     , A.PRIORITY                                                                                                          \n");
             sql.append("     , A.DUTY_NAME                                                                                                         \n");
             sql.append("     , A.GW_ID                                                                                                             \n");
             sql.append("     , A.DEL_DATE                                                                                                          \n");
             sql.append("     , A.EMP_CODE                                                                                                          \n");
             sql.append("     , A.ROLES                                                                                                             \n");
             sql.append("     , A.MOD_YN                                                                                                            \n");
             sql.append("     )                                                                                                                     \n");
             sql.append("    VALUES     (                                                                                                           \n");
             sql.append("    B.ID                                                                                                                   \n");
             sql.append("    , B.PASSWD                                                                                                             \n");
             sql.append("    , B.NAME                                                                                                               \n");
             sql.append("    , B.SL_NO_1                                                                                                            \n");
             sql.append("    , B.SL_NO_2                                                                                                            \n");
             sql.append("    , B.EMAIL                                                                                                              \n");
             sql.append("    , B.PHONE                                                                                                              \n");
             sql.append("    , B.CELL_PHONE                                                                                                         \n");
             sql.append("    , B.SYS_AUTH                                                                                                           \n");
             sql.append("    , B.DEL_TYPE                                                                                                           \n");
             sql.append("    , B.DEPT_ID                                                                                                            \n");
             sql.append("    , B.PRIORITY                                                                                                           \n");
             sql.append("    , B.DUTY_NAME                                                                                                          \n");
             sql.append("    , B.GW_ID                                                                                                              \n");
             sql.append("    , B.DEL_DATE                                                                                                           \n");
             sql.append("    , B.EMP_CODE                                                                                                           \n");
             sql.append("    , B.ROLES                                                                                                              \n");
             sql.append("    , B.MOD_YN                                                                                                             \n");
             sql.append("    )                                                                                                                      \n");
             sql.append("    WHEN MATCHED AND A.DEPT_ID=B.DEPT_ID THEN                                                                              \n");
             sql.append("    UPDATE SET                                                                                                             \n");
             sql.append("            A.ID         = B.ID                                                                                            \n");
             sql.append("    ,       A.PASSWD     = B.PASSWD                                                                                        \n");
             sql.append("    ,       A.NAME       = B.NAME                                                                                          \n");
             sql.append("    ,       A.SL_NO_1    = B.SL_NO_1                                                                                       \n");
             sql.append("    ,       A.SL_NO_2    = B.SL_NO_2                                                                                       \n");
             sql.append("    ,       A.CELL_PHONE = B.CELL_PHONE                                                                                    \n");
             sql.append("    ,       A.DEL_TYPE   = B.DEL_TYPE                                                                                      \n");
             sql.append("    ,       A.DEPT_ID    = B.DEPT_ID                                                                                       \n");
             sql.append("    ,       A.PRIORITY   = B.PRIORITY                                                                                      \n");
             sql.append("    ,       A.DUTY_NAME  = B.DUTY_NAME                                                                                     \n");
             sql.append("    ,       A.GW_ID      = B.GW_ID                                                                                         \n");
             sql.append("    ,       A.DEL_DATE   = B.DEL_DATE                                                                                      \n");
             sql.append("    ,       A.EMP_CODE   = B.EMP_CODE                                                                                      \n");
             sql.append("    ,       A.ROLES      = B.ROLES                                                                                         \n");
             sql.append("    ,       A.MOD_YN     = 'N'                                          \n");   /*인사이동이 발생한 경우 부서 변경시 Y로 update */

             /* ---------------------------------------------------------------------------------------------------------------- */
             /* | 겸임사용자 | 인사이동 | 겸임부서선택 변경 | A.DEPT_ID != NEIS부서 | A.ORIGN_DEPT_ID != NEIS부서 | 'AND' 결과 | */
             /* ---------------------------------------------------------------------------------------------------------------- */
             /* |      X     |     X    |     해당없음      |         FALSE         |             TRUE            |    FALSE   | */
             /* |      X     |     O    |     해당없음      |         TRUE          |             TRUE            |    TRUE    | */
             /* |      O     |     X    |         X         |         FALSE         |             FALSE           |    FALSE   | */
             /* |      O     |     X    |         O         |         TRUE          |             FALSE           |    FALSE   | */
             /* |      O     |     O    |         X         |         TRUE          |             TRUE            |    TRUE    | */
             /* |      O     |     O    |         O         |         TRUE          |             TRUE            |    TRUE    | */
             /* ---------------------------------------------------------------------------------------------------------------- */
             sql.append("    WHEN MATCHED                                                                                                           \n");
             sql.append("        AND A.DEPT_ID != B.DEPT_ID                                                                                         \n");
             sql.append("        AND (A.ORIGN_DEPT_ID IS NULL OR A.ORIGN_DEPT_ID != B.DEPT_ID)                                                         \n");
             sql.append("    THEN                                                                                                                   \n");
             sql.append("    UPDATE SET                                                                                                             \n");
             sql.append("            A.ID         = B.ID                                                                                            \n");
             sql.append("    ,       A.PASSWD     = B.PASSWD                                                                                        \n");
             sql.append("    ,       A.SYS_AUTH   = B.SYS_AUTH                                  \n");    /*인사이동이 발생한 경우 나이스의 권한으로 update */
             sql.append("    ,       A.NAME       = B.NAME                                                                                          \n");
             sql.append("    ,       A.SL_NO_1    = B.SL_NO_1                                                                                       \n");
             sql.append("    ,       A.SL_NO_2    = B.SL_NO_2                                                                                       \n");
             sql.append("    ,       A.CELL_PHONE = B.CELL_PHONE                                                                                    \n");
             sql.append("    ,       A.DEL_TYPE   = B.DEL_TYPE                                                                                      \n");
             sql.append("    ,       A.DEPT_ID    = B.DEPT_ID                                                                                       \n");
             sql.append("    ,       A.PRIORITY   = B.PRIORITY                                                                                      \n");
             sql.append("    ,       A.DUTY_NAME  = B.DUTY_NAME                                                                                     \n");
             sql.append("    ,       A.GW_ID      = B.GW_ID                                                                                         \n");
             sql.append("    ,       A.DEL_DATE   = B.DEL_DATE                                                                                      \n");
             sql.append("    ,       A.EMP_CODE   = B.EMP_CODE                                                                                      \n");
             sql.append("    ,       A.ROLES      = B.ROLES                                                                                         \n");
             sql.append("    ,       A.MOD_YN     = 'N'                                          \n");   /*인사이동이 발생한 경우 부서 변경시 Y로 update */
             sql.append("    ,       A.ORIGN_DEPT_ID = NULL                                \n");    /*인사이동이 발생한 경우 원소속 부서를 NULL 로 update */

             sql.append("    WHEN MATCHED                                                                                                           \n");
             sql.append("        AND A.DEPT_ID != B.DEPT_ID                                                                                         \n");
             sql.append("        AND A.ORIGN_DEPT_ID = B.DEPT_ID                                                         \n");
             sql.append("    THEN                                                                                                                   \n");
             sql.append("    UPDATE SET                                                                                                             \n");
             sql.append("            A.ID         = B.ID                                                                                            \n");
             sql.append("    ,       A.DEL_TYPE   = B.DEL_TYPE                                                                                      \n");



            System.out.print("\n::::updateMoumiMuser::::\n"+sql.toString());


            int iSuccessCount = execUpdate(sql.toString());

            System.out.println(":::: updateMoumiMuser ::::");
            System.out.println(":::: execute date : " + new Date());
            System.out.println(":::: success count : " + iSuccessCount);

            return;

        } catch (SQLException sqlEx) {
            throw new RuntimeException(sqlEx);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            //close(rs);
            //execClose();
            try {
                if(rs!=null) {rs.close();}
                if(stmt!=null) {stmt.close();}
                if(con!=null) {con.close();}
            } catch (Exception e) {
                //31.오류 상황 대응 부재_CWE-390 Add by YOUNGJUN,CHO
                e.printStackTrace();
                //++++++++++++++++++++++++++++++++++++++++++++++++
            }
        }
    }

    /*
    기존 부서 전체의 삭제타입을 수정
   */
   public void updateDelMoumiDept(){
       StringBuilder sql = new StringBuilder(250);

       try{
           sql.append(" UPDATE MOUMI_DEPT SET IS_OUT='Y' ");

           System.out.print("\n::::DelMoumiMuser::::\n"+sql.toString());

           int iSuccessCount = execUpdate(sql.toString());


           System.out.println(":::: updateDelMoumiDept delType ::::");
           System.out.println(":::: execute date : " + new Date());
           System.out.println(":::: success count : " + iSuccessCount);
           return;

       } catch (SQLException sqlEx) {
           throw new RuntimeException(sqlEx);
       } catch (Exception ex) {
           throw new RuntimeException(ex);
       } finally {
           close(rs);
           execClose();
       }
   }


   /*
   기존 사용자 전체의 삭제타입을 수정
  */
  public void updateDelMoumiMuser(){
      StringBuilder sql = new StringBuilder(250);

      try{
          sql.append(" UPDATE MOUMI_MUSER SET DEL_TYPE='Y' \n ");

          int iSuccessCount = execUpdate(sql.toString());

          System.out.println(":::: updateDelMoumimUuer delType ::::");
          System.out.println(":::: execute date : " + new Date());
          System.out.println(":::: success count : " + iSuccessCount);
          return;

      } catch (SQLException sqlEx) {
          throw new RuntimeException(sqlEx);
      } catch (Exception ex) {
          throw new RuntimeException(ex);
      } finally {
          close(rs);
          execClose();
      }
  }
}
