package weaver.interfaces.htxc.tycgrwd;

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

/**
 * 这个action是用来处理采购任务单结束后将流程关联到采购项目的
 *
 */
public class TycgrwdGllcAction 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 ufRs = new RecordSet();
            String mainSql = "select * from "+tablename+" where requestid = "+requestid;
            rs.execute(mainSql);
            rs.next();
            String id = rs.getString("id");//采购任务单id
            String dtSql = "select * from "+tablename+"_dt5 where mainid = "+id;
            rs.execute(dtSql);
            while(rs.next()){
                String xmid = rs.getString("xmid");
                String sql = "select * from uf_cgxq where id = " +xmid;
                ufRs.execute(sql);
                if(ufRs.next()){
                    String gllc = ufRs.getString("gllc");
                    gllc = StringUtils.isEmpty(gllc)?requestid:gllc+","+requestid;
                    String updateSql = "update uf_cgxq set gllc ='"+gllc+"' where id = "+xmid;
                    ufRs.execute(updateSql);
                }
            }
        }catch (Exception e){
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
