/**
 * @(#)file    UserListBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.6.22
 * Copyright (c) www.udapsoft.co.kr, Inc.
 */
package kr.co.udapsoft.ebid.buyer.sycs.user.biz;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.util.ValueObject;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;


public class ChangeExpiredPwdWorkerBiz extends Biz {

	public ChangeExpiredPwdWorkerBiz(HandlerStorage storage) {
		super(storage);
	}

	
	public void doBiz() throws Exception {
		
		UserCommon common = new UserCommon();
		
		boolean success = changePassWord();
		super.storage.setSuccess(success);
	}

    public boolean changePassWord() throws Exception {
    	
    	conn.begin();

    	try {
        	Persistent persistent = new PersistentImpl(conn.getConnection());
            StrBuffer sqlstr = new StrBuffer();
            
            sqlstr.append(" UPDATE  PUB0120T				\n");
        	sqlstr.append(" SET     USER_PW = F_SHA256(?)	\n");										//패스워드 변경
        	sqlstr.append("   ,     PWD_VALID_CNT = 5		\n");										//패스워드 오류 카운트 초기화(5회)
        	sqlstr.append("   ,     PWD_VALID_FROM = TO_DATE(TO_CHAR(SYSDATE+180,'YYYYMMDD'))	\n");	//패스워드 유효기간 180일 연장
        	sqlstr.append(" WHERE   UPPER(USER_SABUN) = UPPER(?)		\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("user_pw1"));
            persistent.addParameter(params.get("ACCT_ID"));
            persistent.execute();
        	return true;
    	}catch(Exception e) {
    		WAFLogger.error(this.getClass().getName() + " --> changePassWord() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();
            this.storage.setSuccess(false);  
            this.storage.setMessage(e.getMessage());            
            storage.setDetailMessage(e);
            return false;
    	}finally {
    		super.conn.end();
    	}
	}
	
}