package weaver.interfaces.htxc.tycgsq.action;

import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class TycgsqWriteData extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestinfo) {
        try{
            String requestid = requestinfo.getRequestid();//请求ID
            String tablename = requestinfo.getRequestManager().getBillTableName();//表单名称
            RecordSet rs = new RecordSet();
            RecordSet updateRs = new RecordSet();
            String mainSql = "select * from "+ tablename + " where requestid = "+requestid;
            JAVATools.writelog("通用采购流程办结回写关联流程mainSql"+mainSql);
            rs.execute(mainSql);
            if(rs.next()){
                String id = rs.getString("id");
                String dt4Sql = "select * from "+tablename+"_dt4 where mainid = "+id ;
                JAVATools.writelog("通用采购流程办结回写关联流程dt4Sql"+dt4Sql);
                rs.execute(dt4Sql);
                while(rs.next()){
                    String xmid = rs.getString("xmid");
                    String selectSql = "select * from uf_cgxq where id = "+xmid;
                    updateRs.execute(selectSql);
                    String gllc = "";
                    if(updateRs.next()){
                        gllc = updateRs.getString("gllc");
                    }
//                    gllc = requestid +","+gllc;
                    gllc = StringUtils.isEmpty(gllc)?requestid:gllc+","+requestid;
                    String updateSql = "update  uf_cgxq set gllc = '"+gllc+"' where id = "+xmid;
                    JAVATools.writelog("通用采购流程办结回写关联流程updateSql"+updateSql);
                    updateRs.execute(updateSql);
                }
            }
            return Action.SUCCESS;
        }catch (Exception e){
            JAVATools.writelog("通用采购流程办结回写关联流程e"+e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
