package com.engine.htsc.seal.jjhyy.dao;

import com.engine.integration.util.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName JjhyyDao.java
 * @createTime 2022年03月15日 14:51:00
 */
public class JjhyyDao {

    public static Map<String,Object> getyy(Map<String,Object> map){
        String requestid= Util.null2String(map.get("requestid"));
        String tablename=Util.null2String(map.get("tablename"));
        if(StringUtils.isBlank(requestid) || StringUtils.isBlank(tablename)){
            return null;
        }
        String sql = "select id,yz,zzyongtu from "+tablename+" where requestid = "+requestid;
        return JAVATools.GetTableToMap(sql,null);
    }

    public static Map<String,Object> getfileyy(Map<String,Object> map){
        String requestid= Util.null2String(map.get("requestid"));
        String tablename=Util.null2String(map.get("tablename"));
        if(StringUtils.isBlank(requestid) || StringUtils.isBlank(tablename)){
            return null;
        }
        String sql = "select id,yz from "+tablename+" where requestid = "+requestid;
        return JAVATools.GetTableToMap(sql,null);
    }
    /**
     * */
    public static void  sealfilewj(Map<String,Object> map){
        String tablename=Util.null2String(map.get("tablename"));
        String pdfid=Util.null2String(map.get("pdfid"));
        String mainid=Util.null2String(map.get("mainid"));
        String docid=Util.null2String(map.get("docid"));
        Map<String,String> setMap=new HashMap<>();
        setMap.put("zpdfhwj",pdfid);
        Map<String,String> whereMap=new HashMap<>();
        whereMap.put("mainid",mainid);
        whereMap.put("wjmc",docid);
        JAVATools.Updatesql(setMap,tablename,whereMap);
    }
    public static Map<String,Object> getmaintablelist(Map<String,Object> map){
        String tablename = Util.null2String(map.get("tablename"));
        String mainid = Util.null2String(map.get("mainid"));
        String fzid = Util.null2String(map.get("fzid"));
        if(StringUtils.isBlank(tablename) || StringUtils.isBlank(mainid) || StringUtils.isBlank(fzid)){
            return null;
        }
        String  sql = "select id,wjmc,dsmdy,dzyyfs,yqxdyr,fwdyfs from "+tablename+"_dt8 where mainid = '"+mainid+"' and fzid = '"+fzid+"'";
        return JAVATools.GetTableToMap(sql,null);
    }

    public static Map<String,Object> getfilemaintablebody(Map<String,Object> map){
        String tablename = Util.null2String(map.get("tablename"));
        String mainid = Util.null2String(map.get("mainid"));
        String docid = Util.null2String(map.get("docid"));
        if(StringUtils.isBlank(tablename) || StringUtils.isBlank(mainid) || StringUtils.isBlank(docid)){
            return null;
        }
        String sql = "select id,dsmdy,dzyyfs,yqxdyr,fwdyfs from "+tablename+"_dt7 where mainid = '"+mainid+"' and wjmc = '"+docid+"'";
        JAVATools.SetCmdwritelog("sql:"+sql);
        return JAVATools.GetTableToMap(sql,null);
    }



    public static void  updateyystatus(Map<String,Object> map) {
        String signDocid= Util.null2String(map.get("signDocid"));
        String tablename=Util.null2String(map.get("tablename"));
        String id=Util.null2String(map.get("id"));
        if(StringUtils.isBlank(signDocid) || StringUtils.isBlank(tablename) || StringUtils.isBlank(id)){
            return ;
        }
        JAVATools.SetCmdwritelog("signDocid:"+signDocid+" -tablename:"+tablename+" -id:"+id);
        Map<String,String> setmap=new HashMap<>(1);
        setmap.put("yyid",signDocid);
        Map<String,String> wheremap=new HashMap<>(1);
        wheremap.put("id",id);
        JAVATools.Updatesql(setmap,tablename,wheremap);
    }

    public static void updateyyidstatus(Map<String,Object> map){
      //  String update_sql = "update "+tablename+"_dt7 set yyid = '"+signDocid+"' where id = '"+id+"'";
        String yyid= Util.null2String(map.get("yyid"));
        String tablename=Util.null2String(map.get("tablename"));
        String id=Util.null2String(map.get("id"));
        if(StringUtils.isBlank(yyid) || StringUtils.isBlank(tablename) || StringUtils.isBlank(id)){
            return ;
        }
        JAVATools.SetCmdwritelog("yyid:"+yyid+" -tablename:"+tablename+" -id:"+id);
        Map<String,String> setmap=new HashMap<>(1);
        setmap.put("yyid",yyid);
        Map<String,String> wheremap=new HashMap<>(1);
        wheremap.put("id",id);
        JAVATools.Updatesql(setmap,tablename,wheremap);
    }

    public static void updateSignStatusForLicense(String tableName, String mainid, String fzids, String yyzt){
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();

        List<String> fzidList = Arrays.asList(fzids.split(","));
        for(String fzid:fzidList){
            String update_sql = "update "+tableName+" set yyzt = '"+yyzt+"' where mainid = '"+mainid+"' and fzid = '"+fzid+"'";
           JAVATools.SetCmdwritelog("-ceshi----"+update_sql);
            rs.executeUpdate(update_sql);
        }
    }
}
