package com.engine.htsc.wdzx.service.imp;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.core.impl.Service;
import com.engine.htsc.wdzx.dao.GetcchangedetailDao;
import com.engine.htsc.wdzx.service.GetchangedetailService;

import weaver.general.Util;
import weaver.hrm.User;

import java.util.Map;

/**
 * @author xf
 * @version 1.0.0
 * @ClassName GetcchangdetailServiceImp.java
 * @createTime 2021年11月04日 10:41:00
 */
public class GetchangedetailServiceImp extends   Service implements   GetchangedetailService {


    @Override
    public JSONObject getchangdetailinfo(User user, Map<String,Object> map) {
       String wdzxid= Util.null2String(map.get("wdzxid"));
       if("".equals(wdzxid)){
           return null;
       }
       Map<String,String> returnmap= GetcchangedetailDao.getchangfile(wdzxid);
        if(returnmap==null || returnmap.size()<=0){
            return null;
        }
       JSONObject jsonObject=new JSONObject();
        int size=Util.getIntValue(Util.null2String(returnmap.get("filesize")));
        String filesize="1K";
        String docid=Util.null2String(returnmap.get("docid"));
        String imagefilename= Util.null2String(returnmap.get("imagefilename"));
        if(size>0){
            int sizevalue=size/1024;
            if(sizevalue>0){
                filesize=sizevalue+"K";
            }
        }
        try {
            String filelink = "/spa/document/index2file.jsp?f_weaver_belongto_userid=" + user.getUID() + "&f_weaver_belongto_usertype=0&id=" + docid + "&imagefileId=" + imagefilename + "&isFromAccessory=true&isrequest=1&requestid=-1&desrequestid=-1&authStr=undefined&authSignatureStr=undefined";
            String loadlink = "/weaver/weaver.file.FileDownload?fileid=" + docid + "&download=1&requestid=-1&desrequestid=-1&authStr=undefined&authSignatureStr=undefined&f_weaver_belongto_userid=" + user.getUID() + "&f_weaver_belongto_usertype=0";
            jsonObject.put("appID", "");
            jsonObject.put("fileID", docid);
            jsonObject.put("fileid", docid);
            jsonObject.put("filelink", filelink);
            jsonObject.put("filesize", filesize);
            jsonObject.put("filename", imagefilename);
            jsonObject.put("imagefileid", Util.null2String(returnmap.get("imagefileid")));

            jsonObject.put("imgSrc", "/images/filetypeicons/pdf_wev8.png");
            jsonObject.put("isImg", false);
            jsonObject.put("loadlink", loadlink);
            jsonObject.put("operatedate", Util.null2String(returnmap.get("operatedate")));
            jsonObject.put("operatetime", Util.null2String(returnmap.get("operatetime")));
            jsonObject.put("showDelete", true);
            jsonObject.put("size", size);
            jsonObject.put("uploaddate", Util.null2String(returnmap.get("imagefileid")));
            jsonObject.put("userid", 0);
            jsonObject.put("username", "文档中心");
            jsonObject.put("versionCount", "v1");
            JSONArray jsonArray=new JSONArray();
            jsonArray.add(jsonObject);
            JSONObject filedatas=new JSONObject();
            filedatas.put("filedatas",jsonArray);
            JSONObject value1=new JSONObject();
            value1.put("value",docid);
            value1.put("specialobj",filedatas);
            return value1;
        }catch (Exception exo){

        }
        return null;


    }

    @Override
    public String getversion(Map<String, Object> map) {
        String wdzxid= Util.null2String(map.get("wdzxid"));
        if("".equals(wdzxid)){
            return null;
        }
       return GetcchangedetailDao.getversion(wdzxid);
    }
}

