package com.engine.htxc.commonutil.dao;

import com.engine.integration.util.StringUtils;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.GlobatTools.Uploadcory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName FileDao.java
 * @createTime 2022年07月01日 09:43:00
 */
public class FileDao {


   public  List<Map<String,Object>> getFileInfo(List<Map<String,Object>> doclist){
       List <Map<String,Object>> list=new ArrayList<>();
        if(doclist==null || doclist.isEmpty()){
            return list;
        }
        List<String> docidslist=new ArrayList<>();
             doclist.forEach((Map<String,Object> map)->{
           String docid=Util.null2String(map.get("docid"));
           if(!StringUtils.isBlank(docid)){
               docidslist.add(docid);
           }
       });
       if( docidslist.isEmpty()){
           return list;
       }
       String sql2="select t.docid,t.imagefileid,t.imagefilename,dt.doccreatedate as operatedate,dt.doccreatetime as operatetime,tf.imagefiletype,tf.filesize " +
               " from  docimagefile t join imagefile tf on t.imagefileid=tf.imagefileid " +
               " join docdetail dt on t.docid=dt.id where " +
               "t.docid in ("+docidslist.stream().map(item->"'"+item+"'").collect(Collectors.joining(","))+")";

       List<Map<String,Object>> data= JAVATools.GetTableToListMap(sql2,null);
       if(data==null || data.size()<=0){
           return list;
       }
       data.forEach((Map<String,Object> map2)->{
           Map<String,Integer> map= Uploadcory.coryfile(Util.null2String(map2.get("docid")));
           if(map!=null && map.size()>0){
               Map<String,Object> returnmap=new HashMap<>(8);
               String docid =Util.null2String(map.get("docid"));
               String imagefileid =Util.null2String(map.get("imagefileid"));
               returnmap.put("docid",docid);
               returnmap.put("imagefileid",imagefileid);
               returnmap.put("imagefilename",Util.null2String(map2.get("imagefilename")));
               returnmap.put("operatedate",Util.null2String(map2.get("operatedate")));
               returnmap.put("operatetime",Util.null2String(map2.get("operatetime")));
               returnmap.put("imagefiletype",Util.null2String(map2.get("imagefiletype")));
               returnmap.put("filesize",Util.null2String(map2.get("filesize")));
               returnmap.put("docimagefile",Util.null2String(map2.get("docimagefile")));
               list.add(returnmap);
           }
       });

       return list;
    }

    public  List<Map<String,Object>> getNotcoryFileInfo(List<String> docidslist){
        List <Map<String,Object>> list=new ArrayList<>();
        if(docidslist==null || docidslist.size()<=0){
            return list;
        }
        String sql2="select t.docid,t.imagefileid,t.imagefilename,t.operatedate,t.operatetime,tf.imagefiletype,tf.filesize from docimagefile t join imagefile tf on t.imagefileid=tf.imagefileid where " +
                "t.docid in ("+docidslist.stream().map(item->"'"+item+"'").collect(Collectors.joining(","))+")";

        List<Map<String,Object>> data= JAVATools.GetTableToListMap(sql2,null);
        if(data==null || data.size()<=0){
            return list;
        }
        data.forEach((Map<String,Object> map)->{
            if(map!=null && map.size()>0){
                Map<String,Object> returnmap=new HashMap<>(8);
                String docid =Util.null2String(map.get("docid"));
                String imagefileid =Util.null2String(map.get("imagefileid"));
                returnmap.put("docid",docid);
                returnmap.put("imagefileid",imagefileid);
                returnmap.put("imagefilename",Util.null2String(map.get("imagefilename")));
                returnmap.put("operatedate",Util.null2String(map.get("operatedate")));
                returnmap.put("operatetime",Util.null2String(map.get("operatetime")));
                returnmap.put("imagefiletype",Util.null2String(map.get("imagefiletype")));
                returnmap.put("filesize",Util.null2String(map.get("filesize")));
                returnmap.put("docimagefile",Util.null2String(map.get("docimagefile")));
                list.add(returnmap);
            }
        });

        return list;
    }

}
