package weaver.interfaces.secondev.zjpicc;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;

/**
 * 生成逻辑运算出对应的权限调整清单
 */
public class PermissionAdjAction extends BaseBean implements Action {
    Log log = LogFactory.getLog(PermissionAdjAction.class);

    /**
     *
     * @param requestInfo
     * @return
     */

    @Override
    public String execute(RequestInfo requestInfo) {

        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        String requestid = Util.null2String(requestInfo.getRequestid());
        String formtable = requestInfo.getRequestManager().getBillTableName();
        bb.writeLog("PermissionAdjAction-requestid:"+requestid);
        bb.writeLog("PermissionAdjAction-formtable:"+formtable);
        int taskcount = 0;
        if(StringUtils.isNotBlank(requestid)){
            String sql = " select id from uf_qxtzqd where ylcid='"+requestid+"' ";
            bb.writeLog("PermissionAdjAction-sql:"+sql);
            rs.executeQuery(sql);
            while (rs.next()){
                taskcount++;
            }
//            String sql = " select thbj from "+formtable+" where requestid="+requestid;
//            bb.writeLog("PermissionAdjAction-sql:"+sql);
//            rs.executeQuery(sql);
//            if(rs.next()){
//                thbj = Util.null2String(rs.getString("thbj"));
//            }
        }
        bb.writeLog("PermissionAdjAction-taskcount:"+taskcount);
        if(taskcount == 0){
            new Thread(new DoDataRunnable(requestInfo)).start();
        }

        return Action.SUCCESS;
    }

    public String docompany(String id){
        String dsid=id;
        String sql = "select SUBCOMPANYCODE,SUPSUBCOMID  from hrmsubcompany h where id="+id;
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        String code = Util.null2String(rs.getString("SUBCOMPANYCODE"));
        String hcode = code.substring(4,8);
        if(!"0000".equals(hcode)){
            dsid = Util.null2String(rs.getString("SUPSUBCOMID"));
        }

        return dsid;
    }

}
