package com.engine.htxc.eseal.dao;

import com.engine.integration.util.StringUtils;
import com.weaver.formmodel.mobile.mec.handler.List;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;

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

public class SendSignetDao {
    /***
     *
     * @return
     */
    public static String getTableByRequestid(String requestid){
        RecordSet rs = new RecordSet();
        String formid = "formtable_main_" ;

        String sql =" select abs(t.formid) as formid \n" +
                " from workflow_base t\n" +
                " inner join workflow_requestbase l on l.workflowid = t.id\n" +
                " where l.requestid="+requestid+"" ;
        rs.execute(sql);
        if(rs.next()){
            formid = formid+ Util.getIntValues(rs.getString("formid"));
        }
        return formid;
    }

    public static Map<String,Object> getesealInfo(String requestid, String detailtable, String formtable){
        BaseBean bb=new BaseBean();
        String sql="";
        String GW_GZZDTYPE=Util.null2String(new PropBean().getPropName("GW_GZZDTYPE"));
        String gzddnumber=Util.null2String(JAVATools.getmainunnumber(Util.null2String(requestid)));
        if(!"".equals(GW_GZZDTYPE)&&!"".equals(gzddnumber)&&GW_GZZDTYPE.indexOf(gzddnumber)>=0){
            sql=" select t.id,t.wh, t.ngr,t.fs,t.szbm,t.szjg,t.lxfs,t.jjcd,t.ngrq , (select yzbh from uf_yinzhang where id=t.yz) as yz,  t.zwpdf," +
                    " (select wm_concat_old(wdid) from " + detailtable + "  where sfyy='1' and sflzlc=1   and  mainid=t.id and  (fjpdflx is null or fjpdflx!='1' ) ) as fjid " +
                    " from " + formtable + " t " +
                    " where sfcwgz=0 and requestid='" + requestid + "'";
        }else{
            sql=" select t.id,t.wh, t.ngr,t.fs,t.szbm,t.szjg,t.lxfs,t.jjcd,t.ngrq , (select yzbh from uf_yinzhang where id=t.yz) as yz, t.zwpdf," +
                    " (select wm_concat_old(wdid) from " + detailtable + "  where sfyy='1' and sflzlc=1  and  mainid=t.id) as fjid " +
                    " from " + formtable + " t " +
                    " where sfcwgz=0 and requestid='" + requestid + "'";
        }

        bb.writeLog("【自动触发用印单】sql:" + sql);
        bb.writeLog("【自动触发用印单】获取流程主表信息sql，主表表单是:" + formtable);
        return JAVATools.GetTableToMap(sql,null);
    }

    public static String filedistinct(String a,String b){
        String value="";
        if("".equals(a)&& "".equals(b)){
            return value;
        }
        if("".equals(a)){
            value=b;
        }else if("".equals(b)){
            value=a;
        }else{
            value=a+","+b;
        }
        return value;
    }

    public static void updatewfstatus(Map<String,Object> map){
        if(map==null || map.size()<=0){
            return ;
        }
        String id=Util.null2String(map.get("id"));
        String tablename=Util.null2String(map.get("tablename"));
        if(StringUtils.isBlank(id) || StringUtils.isBlank(tablename)){
            return ;
        }
        String htoagllc=Util.null2String(map.get("htoagllc"));

        Map<String,String> wheremap=new HashMap<>(1);
        wheremap.put("id",id);
        Map<String,String> setmap=new HashMap<>(2);
        setmap.put("htoagllc",htoagllc);
;
        JAVATools.Updatesql(setmap,tablename,wheremap);
    }
}
