package weaver.interfaces.htsc.GlobatTools;

import weaver.conn.RecordSet;
import weaver.docs.category.SecCategoryComInfo;
import weaver.docs.docs.DocComInfo;
import weaver.docs.docs.DocImageManager;
import weaver.docs.docs.DocManager;
import weaver.docs.docs.DocViewer;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import weaver.wechat.util.Utils;
import java.util.HashMap;
import java.util.Map;



/**
 * @ClassName NewDocUtil
 * @Author K1810015
 * @Date 2022/3/3 16:53
 * Version 1.0
 */
public class NewDocUtil {


    /**
     * @title createdocdetail
     * @author K1810015
     * @updateTime 2022/3/11 15:04
     * @Remark 创建docdetail表
     * @throws
     */
    public static int createdocdetail(Map<String,Object> map){
        String title=Utils.null2String(map.get("title"));
        String body=Utils.null2String(map.get("body"));
        int creater=Utils.getIntValue(Utils.null2String(map.get("creater")),0);
        String rq=Utils.null2String(map.get("rq"));
        String docextendname=Utils.null2String(map.get("docextendname"));
        int maincategory=Utils.getIntValue(Utils.null2String(map.get("maincategory")),0);
        int subcategory=Utils.getIntValue(Utils.null2String(map.get("subcategory")),0);
        int seccategory=Utils.getIntValue(Utils.null2String(map.get("seccategory")),0);
        int doctype=Utils.getIntValue(Utils.null2String(map.get("doctype")),0);
        RecordSet rs = new RecordSet();
        BaseBean bs = new BaseBean();
        try{
            int docLanguage = 7 ;
            int sec = seccategory;
            ResourceComInfo r = new ResourceComInfo();
            int departmentid = Integer.parseInt(r.getDepartmentID(creater+""));
            bs.writeLog("departmentid:"+departmentid);
            SecCategoryComInfo secCategoryComInfo=new SecCategoryComInfo();

            DocComInfo docComInfo=new DocComInfo();
            DocManager docManager=new DocManager();
            DocViewer docViewer=new DocViewer();

            String nowTime= TimeUtil.getOnlyCurrentTimeString();

            String pubishdate = rq;
            String publishtime = nowTime;

            RecordSet recordSet = new RecordSet();
            int newDocId = docManager.getNextDocId(recordSet);

            docManager.setId(newDocId);
            docManager.setDocsubject(title);
            docManager.setMaincategory(maincategory);
            docManager.setSubcategory(subcategory);
            docManager.setSeccategory(sec);
            docManager.setLanguageid(docLanguage);
            docManager.setDocstatus("1");

            docManager.setDoccreaterid(creater);
            docManager.setDocdepartmentid(departmentid);
            docManager.setDocCreaterType("1");
            docManager.setUsertype("1");
            docManager.setOwnerid(creater);
            docManager.setOwnerType("1");
            docManager.setDoclastmoduserid(creater);
            docManager.setDocLastModUserType("1");

            docManager.setDoccreatedate(pubishdate);
            docManager.setDoclastmoddate(pubishdate);
            docManager.setDoccreatetime(publishtime);
            docManager.setDoclastmodtime(publishtime);

            docManager.setDoclangurage(docLanguage);

            docManager.setKeyword(title);
            docManager.setIsapprover("0");
            docManager.setIsreply("");
            docManager.setDocreplyable("1");
            docManager.setAccessorycount(1);
            docManager.setParentids(newDocId+"");
            docManager.setOrderable(secCategoryComInfo.getSecOrderable(seccategory)+"");
            docManager.setUserid(1);
            docManager.setDocCode("");
            docManager.setDocEditionId(docManager.getNextEditionId(recordSet));
            docManager.setDocEdition(1);
            docManager.setDoccontent(body);
            docManager.setDocType(doctype);
            docManager.setDocextendname(docextendname);
            docManager.AddDocInfo();
            docComInfo.addDocInfoCache("" + newDocId);
            docViewer.setDocShareByDoc("" + newDocId);
            docManager.AddShareInfo();

            return newDocId;
        } catch(Exception e){
            e.printStackTrace();
            return -1;
        }
    }

    /**
     * @title createdocimagefile
     * @author K1810015
     * @updateTime 2022/3/11 15:04
     * @Remark 创建docimagefile表
     * @throws
     */
    public static void createdocimagefile(Map<String,Object> map){
        DocImageManager imgManger = new DocImageManager();
        String docid= Utils.null2String(map.get("docid"));
        String imagefileid=Utils.null2String(map.get("imagefileid"));
        String imagefilename=Utils.null2String(map.get("imagefilename"));
        String ext=Utils.null2String(map.get("docextendname"));
        int versionid=Utils.getIntValue(Utils.null2String(map.get("imagefilename")),0);
        int operateruserid=Utils.getIntValue(Utils.null2String(map.get("operateruserid")),0);

        String operatedate=Utils.null2String(map.get("operatedate"));
        String operatetime=Utils.null2String(map.get("operatetime"));

        if (ext.equalsIgnoreCase("doc")) {
            imgManger.setDocfiletype("3");
        } else if (ext.equalsIgnoreCase("xls")) {
            imgManger.setDocfiletype("4");
        } else if (ext.equalsIgnoreCase("ppt")) {
            imgManger.setDocfiletype("5");
        } else if (ext.equalsIgnoreCase("wps")) {
            imgManger.setDocfiletype("6");
        } else if (ext.equalsIgnoreCase("docx")) {
            imgManger.setDocfiletype("7");
        } else if (ext.equalsIgnoreCase("xlsx")) {
            imgManger.setDocfiletype("8");
        } else if (ext.equalsIgnoreCase("pptx")) {
            imgManger.setDocfiletype("9");
        } else if (ext.equalsIgnoreCase("et")) {
            imgManger.setDocfiletype("10");
        } else {
            imgManger.setDocfiletype("2");
        }
        imgManger.setDocid(Util.getIntValue(docid, 0));
        imgManger.setImagefileid(Util.getIntValue(imagefileid, 0));
        imgManger.setImagefilename(imagefilename);
        imgManger.setimagefilewidth(0);
        imgManger.setImagefileheight(0);
        imgManger.setIsextfile("1");
        imgManger.setImagefielsize(0);
        imgManger.setVersionId(versionid);
        imgManger.setOperatedate(operatedate);
        imgManger.setOperatetime(operatetime);
        imgManger.setOperateuserid(operateruserid);
        imgManger.AddDocImageInfo();
    }

    /**
     * @title createimagefile
     * @author K1810015
     * @updateTime 2022/3/11 15:05
     * @Remark 创建imagefile表
     * @throws
     */
    public static  void createimagefile(Map<String,Object> map){

            String tablename = "imagefile";
            String imagefileid = Utils.null2String(map.get("imagefileid"));
            String imagefiletype = Utils.null2String(map.get("imagefiletype"));
            String filesize = Utils.null2String(map.get("filesize"));
            String imagefilename= Utils.null2String(map.get("imagefilename"));
            String aescode=Utils.null2String(map.get("aescode"));
            String tokenkey=Utils.null2String(map.get("tokenkey"));
            String ftpconfigid=Utils.null2String(map.get("ftpconfigid"));
            String isaesencrypt=Utils.null2String(map.get("isaesencrypt"));
            String imagefileused=Utils.null2String(map.get("imagefileused"));
            String iszip=Utils.null2String(map.get("iszip"));
            String filerealpath=Utils.null2String(map.get("filerealpath"));
            Map<String, String> filemap = new HashMap<>(11);
            filemap.put("imagefileid", imagefileid);
            filemap.put("imagefilename", imagefilename);
            filemap.put("imagefiletype", imagefiletype);
            filemap.put("imagefileused",imagefileused);
            filemap.put("filerealpath",filerealpath);
            filemap.put("iszip", iszip);
            filemap.put("fileSize", filesize);
            filemap.put("tokenkey",tokenkey);
            filemap.put("aescode",aescode);
            filemap.put("ftpconfigid",ftpconfigid);
            filemap.put("isaesencrypt",isaesencrypt);

         JAVATools.Excetesql(filemap, tablename);


    }
}
