package com.engine.htxc.eseal.dao;

import com.engine.htxc.commonutil.db.DbTools;
import com.engine.htxc.eseal.config.EsealConfig;
import com.engine.integration.util.StringUtils;
import weaver.general.StringUtil;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

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

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName EsealTableLink.java
 * @createTime 2022年07月04日 00:47:00
 */
public class EsealTableLinkDao {
    DbTools dbTools=new DbTools();
    public boolean insertlink(Map<String,Object> map,EsealConfig esealConfig){
       if(map==null || map.size()<=0){
           return false;
       }
       String flownum= Util.null2String(map.get("flownum"));

       if(StringUtils.isBlank(flownum)){
           return false;
       }
       if(selectlink(flownum,esealConfig)){
           return true;
       }
       Map<String,String> setmap=new HashMap<>();
       setmap.put("flownum",flownum);
       setmap.put("glzb",esealConfig.linktalbeenum);
      return dbTools.insert(esealConfig.linktalbe,setmap);

    }

    private  boolean selectlink(String flownum,EsealConfig esealConfig){
        if(StringUtils.isBlank(flownum)){
            return false;
        }
        String sql="select glzb from "+esealConfig.linktalbe+" where 1=1 and flownum=? ";

        Map<String,Object> retmap= dbTools.getsqltomap(sql,flownum);
        if(retmap!=null && retmap.size()>0) {
            return true;
        }else
        {
            return false;
        }

    }
}
