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.RequestInfo;

/**
 * 生成逻辑运算出对应的权限调整清单
 */
public class PermissionReturnUpdateAction extends BaseBean implements Action {

    /**
     *
     * @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("PermissionReturnUpdateAction-requestid:"+requestid);
        bb.writeLog("PermissionReturnUpdateAction-formtable:"+formtable);
        boolean isTrue = true;
        if(StringUtils.isEmpty(requestid) && !"-1".equals(requestid)){
            String sql = " update "+formtable+" set thbj = '1' where requestid="+requestid;
            bb.writeLog("PermissionReturnUpdateAction-sql:"+sql);
            isTrue = rs.executeUpdate(sql);
        }

        if(!isTrue){
            requestInfo.getRequestManager().setMessageid("1234");
            requestInfo.getRequestManager().setMessagecontent("更新退回标识失败");
            return Action.FAILURE_AND_CONTINUE;
        }
        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;
    }

}
