package weaver.interfaces.htsc.seal;

import com.engine.common.util.ServiceUtil;
import com.engine.htsc.mail.service.MailAutoCreateService;
import com.weaver.general.BaseBean;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.text.SimpleDateFormat;
import java.util.*;


public class SubSealAutoCreateMailAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        writeLog("----SubSealAutoCreateMailAction-------" + requestid);
        try{
            boolean flag = false;

            String mainid = "";
            String sql = "select id from "+tablename+" where requestid = "+requestid;
            writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                mainid = Util.null2String(rs.getString("id"));
            }

            sql = "select id from "+tablename+"_dt7 where mainid = '"+mainid+"' and yyfs in (1,2) and qrwlyy = '1'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                flag = true;
            }

            sql = "select id from "+tablename+"_dt8 where mainid = '"+mainid+"' and yyfs in (1,2) and qrwlyy = '1'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                flag = true;
            }

            if(flag){
                MailAutoCreateService service = ServiceUtil.getService(MailAutoCreateService.class);
                service.create(requestid);
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "流程提交失败" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
