package weaver.interfaces.htsc.workflow.global;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.workflow.action.Action;
import weaver.join.hrm.in.HrmResource;
import weaver.soa.workflow.request.RequestInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by K1810007 on 2020/10/27.
 */

public class WorkFlowLdspToDetailAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        writeLog( "----WrorFlowLdspToDetailAction start-------" + requestid );
        try {
            String tablename = requestInfo.getRequestManager().getBillTableName();//主表
            PropBean pb = new PropBean();

            String mainid = "";
            String ldsp = "";

            String sql = "select id,ldsp from " + tablename + " where requestid='" + requestid + "'";
            writeLog( sql );
            rs.executeQuery(sql);
            if(rs.next()){
                mainid = Util.null2String( rs.getString( "id" ) );//mainid
                ldsp = Util.null2String( rs.getString( "ldsp" ) );//ldsp
            }
            rs.executeUpdate( "delete from " + tablename + "_dt5 where mainid='" + mainid + "'" );
            String detailsql="";
            for (String value:ldsp.split(",")) {
                detailsql="insert into "+tablename+"_dt5(mainid,ry,xz,gh,htdelete) values(?,?,?,?,?)";
                if(!"".equals(value)){

               String  gh= JAVATools.gethrmidtoworkcode(value);

                    rs.executeQuery(detailsql,new Object[]{mainid,value,1,gh,"删除"});
                }

            }

            writeLog( "----WrorFlowLdspToDetailAction end-------" + requestid );



        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "WrorFlowLdspToDetailAction error" );
            requestInfo.getRequestManager().setMessagecontent( "流程提交异常,请联系管理员!" );
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
