package weaver.interfaces.htsc.seal;


import com.engine.common.util.ServiceUtil;
import com.engine.htsc.seal.entity.SealInfoEntity;
import com.engine.htsc.seal.service.SealInformationService;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class SealApplicationInfoAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        writeLog("----SealApplicationInfoAction-------" + requestid);
        try{
            SealInformationService sealInformationService = ServiceUtil.getService(SealInformationService.class);

            String mainid = "";
            String lcbh = "";
            String ngr = "";
            String yygly = "";
            String yz = "";
            String sql = "select id,lcbh,ngr,yzgly,yz from "+tablename+" where requestid = '"+requestid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                mainid = Util.null2String(rs.getString("id"));
                lcbh = Util.null2String(rs.getString("lcbh"));
                ngr = Util.null2String(rs.getString("ngr"));
                yygly = Util.null2String(rs.getString("yzgly"));
                yz = Util.null2String(rs.getString("yz"));
            }

            sql = "select * from "+tablename+"_dt7 where mainid = '"+mainid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                SealInfoEntity sealInfo = new SealInfoEntity();
                sealInfo.setGllc(requestid);
                sealInfo.setLcbh(lcbh);
                sealInfo.setNgr(ngr);
                sealInfo.setYygly(yygly);
                sealInfo.setYz(yz);
                sealInfo.setYywj(Util.null2String(rs.getString("yyhwj")));
                sealInfo.setYwj(Util.null2String(rs.getString("wjmc")));
                sealInfo.setYqxdyr(Util.null2String(rs.getString("yqxdyr")));
                sealInfo.setYyfs(Util.null2String(rs.getString("yyfs")));
                sealInfo.setDzyyfs(Util.null2String(rs.getString("dzyyfs")));
                sealInfo.setDsmdy(Util.null2String(rs.getString("dsmdy")));
                sealInfo.setFwdyfs(Util.null2String(rs.getString("fwdyfs")));
                sealInfo.setWlyyfs(Util.null2String(rs.getString("wlyyfs")));
                sealInfo.setYyid(Util.null2String(rs.getString("yyid")));
                sealInfo.setSfzz("0");
                sealInfo.setWjzt(checkoutWjzt(Util.null2String(rs.getString("yyzt"))));
                sealInformationService.createSealInfo(sealInfo);
            }

            sql = "select * from "+tablename+"_dt8 where mainid = '"+mainid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                SealInfoEntity sealInfo = new SealInfoEntity();
                sealInfo.setGllc(requestid);
                sealInfo.setLcbh(lcbh);
                sealInfo.setNgr(ngr);
                sealInfo.setYygly(yygly);
                sealInfo.setYz(yz);
                sealInfo.setYywj(Util.null2String(rs.getString("yyhwj")));
                sealInfo.setYwj(Util.null2String(rs.getString("wjmc")));
                sealInfo.setYqxdyr(Util.null2String(rs.getString("yqxdyr")));
                sealInfo.setYyfs(Util.null2String(rs.getString("yyfs")));
                sealInfo.setDzyyfs(Util.null2String(rs.getString("dzyyfs")));
                sealInfo.setDsmdy(Util.null2String(rs.getString("dsmdy")));
                sealInfo.setFwdyfs(Util.null2String(rs.getString("fwdyfs")));
                sealInfo.setWlyyfs(Util.null2String(rs.getString("wlyyfs")));
                sealInfo.setYyid(Util.null2String(rs.getString("yyid")));
                sealInfo.setSfzz("1");
                sealInfo.setWjzt(checkoutWjzt(Util.null2String(rs.getString("yyzt"))));
                sealInformationService.createSealInfo(sealInfo);
            }

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

    private String checkoutWjzt(String yyzt){
        String wjzt = "0";
        if("2".equals(yyzt)){
            wjzt = "1";
        }
        return wjzt;
    }
}
