package weaver.interfaces.htsc.seal;

import com.engine.common.util.ServiceUtil;
import com.engine.htsc.seal.service.SealChangeService;
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;

import java.util.HashMap;
import java.util.Map;

public class SealChangeEndAction extends BaseBean implements Action {

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

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

            sql = "select * from "+tablename+"_dt1 where mainid = '"+mainid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                Map<String,String> sealMap = new HashMap<>();
                sealMap.put("yyxxid",Util.null2String(rs.getString("yyxxid")));
                sealMap.put("wjmc",Util.null2String(rs.getString("wjmc")));
                sealMap.put("scwj",Util.null2String(rs.getString("scwj")));
                sealMap.put("yyhwj",Util.null2String(rs.getString("yyhwj")));
                sealMap.put("yqxdyr",Util.null2String(rs.getString("yqxdyr")));
                sealMap.put("yyfs",Util.null2String(rs.getString("yyfs")));
                sealMap.put("dzyyfs",Util.null2String(rs.getString("dzyyfs")));
                sealMap.put("dsmdy",Util.null2String(rs.getString("dsmdy")));
                sealMap.put("fwdyfs",Util.null2String(rs.getString("fwdyfs")));
                sealMap.put("wlyyfs",Util.null2String(rs.getString("wlyyfs")));
                sealMap.put("yyid",Util.null2String(rs.getString("yyid")));
                sealMap.put("yyzt",Util.null2String(rs.getString("yyzt")));
                sealMap.put("gllc",gllc);
                sealInformationService.updateSealInfo(sealMap);
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "流程提交失败" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
