package weaver.interfaces.htsc.lhhtsq;

import com.weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.DBTools;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

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

/**
 * @author xf
 * @version 1.0.0
 * @ClassName nodelastaction.java
 * @createTime 2021年12月10日 19:10:00
 */
public class nodelastaction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
       String requestid= Util.null2String(requestInfo.getRequestid());
       String talbename=Util.null2String(requestInfo.getRequestManager().getBillTableName());
       Map<String,Object> tablemap=gettablemap(requestid,talbename);
       if(tablemap==null || tablemap.size()<=0){
           return Action.SUCCESS;
       }
       String lcbh= Util.null2String(tablemap.get("lcbh"));
       String id= Util.null2String(tablemap.get("id"));
       updatestr(talbename,lcbh,id);
       return Action.SUCCESS;
    }
    private  void updatestr(String tablename,String htbh,String id){
       Map<String,String> updatemap=new HashMap<>();
       String lhht=getStr(htbh);
        updatemap.put("htbh",lhht);
        Map<String,String> wheremap=new HashMap<>();
        wheremap.put("id",id);
        JAVATools.Updatesql(updatemap,tablename,wheremap);

    }

    private  String getStr(String str){
            str=str.trim();
            String str2="";
            if(str != null && !"".equals(str)){
                for(int i=0;i<str.length();i++){
                    if(str.charAt(i)>=48 && str.charAt(i)<=57){
                        str2+=str.charAt(i);
                    }
                }

            }
        return str2;
    }


    private Map<String,Object> gettablemap(String reqid,String tablename){
        String sql="select lcbh,id from "+tablename+ " where 1=1 ";
        Map<String,String> map=new HashMap<>();
        map.put("requestid",reqid);
        return JAVATools.GetTableToMap(sql,map);
    }
}
