package weaver.interfaces.htsc.equipment;


import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class EquipmentPurchaseLaunchAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet update_rs = new RecordSet();
        PropBean pb = new PropBean();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        writeLog("----EquipmentPurchaseLaunchAction-------" + requestid);
        try{
            String mainid = "";
            String glsqlc = "";
            String sql = "select id,glsqlc from "+tablename+" where requestid = '"+requestid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                mainid = Util.null2String(rs.getString("id"));
                glsqlc = Util.null2String(rs.getString("glsqlc"));
            }

            //更新申请流程中的关联采购流程
            String workflowid_dzsbsq = pb.getWorkflowIdsByUnNumber("dzsbsq");
            for(String reqid:glsqlc.split(",")){
                String workflowid = JAVATools.getWorkflowidByRequestid(reqid);
                if(workflowid.equals(workflowid_dzsbsq)){
                    String table = JAVATools.getMaintable(reqid);
                    String update_sql = "update "+table+" set glcglc = '"+requestid+"' where requestid = '"+reqid+"'";
                    writeLog(update_sql);
                    update_rs.executeUpdate(update_sql);
                }
            }

            //更新设备表中的信息
            sql = "select * from "+tablename+"_dt5 where mainid = '"+mainid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                StringBuffer update_sql = new StringBuffer("update uf_dzsbxxcx set glcglc = '"+requestid+"'");
                update_sql.append(", sbmc = '"+Util.null2String(rs.getString("sbmc"))+"'");
                update_sql.append(", xhjpz = '"+Util.null2String(rs.getString("xhjpz"))+"'");
                update_sql.append(", sl = '"+Util.null2String(rs.getString("sl"))+"'");
                update_sql.append(", yt = '"+Util.null2String(rs.getString("yt"))+"'");
                update_sql.append(", cglx = '"+Util.null2String(rs.getString("cglx"))+"'");
                update_sql.append(", dj = '"+Util.null2String(rs.getString("dj"))+"'");
                update_sql.append(", xj = '"+Util.null2String(rs.getString("xj"))+"'");
                update_sql.append(" where id = '"+Util.null2String(rs.getString("dzsbxxid"))+"'");
                writeLog(update_sql);
                update_rs.executeUpdate(update_sql.toString());
            }

            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "流程提交失败" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
