package weaver.interfaces.htsc.equipment;


import com.engine.common.util.ServiceUtil;
import com.engine.htsc.equipment.entity.EquipmentEntity;
import com.engine.htsc.equipment.service.EquipmentInformationService;
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 EquipmentApplicationEndAction extends BaseBean implements Action {

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

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

            sql = "select * from "+tablename+"_dt5 where mainid = '"+mainid+"'";
            writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                EquipmentEntity equipmentEntity = new EquipmentEntity();
                equipmentEntity.setMxid(Util.null2String(rs.getString("id")));
                equipmentEntity.setSbmc(Util.null2String(rs.getString("sbmc")));
                equipmentEntity.setXhjpz(Util.null2String(rs.getString("xhjpz")));
                equipmentEntity.setSl(Util.null2String(rs.getString("sl")));
                equipmentEntity.setYt(Util.null2String(rs.getString("yt")));
                equipmentEntity.setCglx(Util.null2String(rs.getString("cglx")));
                equipmentEntity.setDj(Util.null2String(rs.getString("dj")));
                equipmentEntity.setXj(Util.null2String(rs.getString("xj")));
                equipmentEntity.setSqr(ngr);
                equipmentEntity.setSzbm(szbm);
                equipmentEntity.setGlsqlc(requestid);
                equipmentInformationService.createEquipmentInfo(equipmentEntity);
            }

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