package com.webclient.beans.servlet;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.poi.util.IOUtils;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.server.MXServer;
import psdi.util.MXException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.rmi.RemoteException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * app文件上传
 * （主要是图片上传）
 * createBy liuxq  2023-9-15
 */
@Path("/udFilePic")
//@WebServlet(urlPatterns = "/udFilePic/*")
public class UploadFileServlet extends HttpServlet {
    //--移动端上传图片-start---------------------------------------------------------------------------------------------------------------------
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("----------doGet start-------");
        String type = request.getParameter("type");//参数在body方式使用,在header中不好使
        System.out.println("request type="+type);
        if ("read".equals(type)) {
            //预览
            System.out.println("file----read====");
            getFileData(response, request);
        } else if ("download".equals(type)) {
            //下载
            System.out.println("file----download====");
            processDownload(request, response);
        } else if ("delete".equals(type)) {
            //删除
            System.out.println("file----delete====");
            deleteFile(response, request);
        }
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("----------doPost start-------");
        //上传
        processUpload(request, response);
    }

    /**
     *  app端附件上传（主要是图片上传）
     */
    public void processUpload(HttpServletRequest request, HttpServletResponse response)
    {
        String uploadPath = "";
        String userName = request.getHeader("userid");
        String reference = request.getHeader("reference");
        String fileType = request.getHeader("filetype");
        System.out.println("userName:"+userName);
        System.out.println("reference:"+reference);
        System.out.println("fileType:"+fileType);
        try {
            System.out.println("URLDecoder.decode(fileType)):"+URLDecoder.decode(fileType));
            if (!fileType.equals(URLDecoder.decode(fileType))) {
                fileType = URLDecoder.decode(fileType, "UTF-8");
            }
            System.out.println("URLDecoder.decode(reference):"+URLDecoder.decode(reference));
            if (!reference.equals(URLDecoder.decode(reference))) {
                reference = URLDecoder.decode(reference, "UTF-8");
            }
        } catch (UnsupportedEncodingException e3) {
            e3.printStackTrace();
        }
        System.out.println("fileType_2==" + fileType);
        String filePath = "Attachments";//文件夹
        if (fileType.equalsIgnoreCase("Diagrams")) {
            filePath = "DIAGRAMS";
        } else if (fileType.equalsIgnoreCase("Images")) {
            filePath = "IMAGES";
        } else if (fileType.equalsIgnoreCase("整改照片")) {
            filePath = "整改照片";
        } else {
            filePath = fileType;
        }
//            uploadPath = MXServer.getMXServer().getProperty("mxe.doclink.doctypes.defpath") + "\\" + filePath + "\\";
        uploadPath = "/sunda/eamfile/attachments/";//linux服务器路径
//        uploadPath = "F:\\picture\\";
        System.out.println("uploadPath==" + uploadPath);
        if ("".equals(uploadPath)) {
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(false));
            responseMap.put("errcode", "203");
            responseMap.put("errmsg", "Unable to obtain upload path");//无法获取上传路径
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try
            {
                sendResponse(jsonResponse, response);
            }
            catch (Exception e1)
            {
                e1.printStackTrace();
            }
        }
        File uploadFile = new File(uploadPath);
        int ownerid = Integer.parseInt(request.getHeader("ownerid"));
        String ownertable = request.getHeader("ownertable").toUpperCase();
        if (!uploadFile.exists()) {
            uploadFile.mkdirs();
        }
        try {
            request.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(false));
            responseMap.put("errcode", "205");
            responseMap.put("errmsg", "upload faile,"+e1.getMessage());
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try {
                sendResponse(jsonResponse, response);
            }
            catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        response.setCharacterEncoding("utf-8");
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        System.out.println("isMultipart===" + isMultipart);
        InputStream input = null;
        if (isMultipart) {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            factory.setSizeThreshold(1048576);
//            String tempFilepath = "F:\\temp";
            String tempFilepath = "/sunda/eamfile/temp/";
            File tempFile = new File(tempFilepath);
            if (!tempFile.exists()) {
                tempFile.mkdirs();
            }
            factory.setRepository(tempFile);
            ServletFileUpload upload = new ServletFileUpload(factory);
            upload.setFileSizeMax(52428800L);
            upload.setSizeMax(52428800L);
            upload.setHeaderEncoding("UTF-8");
            List<FileItem> items = null;
            try {
                items = upload.parseRequest(request);
            }
            catch (FileUploadException e) {
                e.printStackTrace();
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(false));
                responseMap.put("errcode", "202");
                responseMap.put("errmsg", "Parsing request exception, please check if the request is correct");//解析request异常，请检查request是否正确
                String jsonResponse = JSONObject.toJSONString(responseMap);
                try {
                    sendResponse(jsonResponse, response);
                }
                catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            if (items != null) {
                Iterator<FileItem> iter = items.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem)iter.next();
                    if (item.isFormField()) {
                        String name = item.getFieldName();
                        String value = item.getString();
                        System.out.println("属性:" + name + "属性值:" + value);
                    }
                    else {
                        String fieldName = item.getFieldName();
                        String fileName = item.getName();
                        //文件名后加个随机数，防止同一秒内同时上传文件时，文件名相同，产生覆盖问题。
                        int num=  (int)(Math.random()*100+1);
                        String s= Integer.toString(num);
                        fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
                        String fileNameb = fileName.substring(0,fileName.lastIndexOf("."));
                        String fileNamel = fileName.substring(fileName.lastIndexOf("."));
                        fileName = new StringBuffer(fileNameb).append(s).append(fileNamel).toString();
                        try {
                            item.write(new File(uploadPath, fileName));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        //向附件表进行插入
                        setFileDoclink(fileName, ownerid, ownertable, uploadPath, userName, fileType, reference);
                    }
                }
            }
            else {
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(false));
                responseMap.put("errcode", "204");
                responseMap.put("errmsg", "The number of files obtained is 0. Please check if the files have been uploaded");//获取的文件数量为0，请检查文件是否上传
                String jsonResponse = JSONObject.toJSONString(responseMap);
                try {
                    sendResponse(jsonResponse, response);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            try {
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(true));
                responseMap.put("errcode", "200");
                responseMap.put("errmsg", "upload success");//上传文件成功
                String jsonResponse = JSONObject.toJSONString(responseMap);
                sendResponse(jsonResponse, response);
            } catch (IOException e) {
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(false));
                responseMap.put("errcode", "205");
                responseMap.put("errmsg", "upload failure,"+e.getMessage());//报错
                String jsonResponse = JSONObject.toJSONString(responseMap);
                try {
                    sendResponse(jsonResponse, response);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(false));
            responseMap.put("errcode", "201");
            responseMap.put("errmsg", "Error in obtaining uploaded file");//获取上传文件错误
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try {
                sendResponse(jsonResponse, response);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

    /**
     * 附件下载
     * @param request
     * @param response
     */
    public void processDownload(HttpServletRequest request, HttpServletResponse response)
    {
        int BUFFER_SIZE = 4096;
        InputStream in = null;
        OutputStream out = null;
        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            response.setContentType("application/octet-stream");
            String docinfoid = request.getParameter("docinfoid");
            String downloadPath = "";
            MboSetRemote docinfoSet = MXServer.getMXServer().getMboSet("DOCINFO", MXServer.getMXServer().getSystemUserInfo());
            docinfoSet.setWhere(" docinfoid='" + docinfoid + "'");
            docinfoSet.reset();
            String fileName = "";
            String fileType = "";
            if (!docinfoSet.isEmpty()) {
                System.out.println("1-------------" + docinfoSet.getMbo(0).getString("URLNAME"));
                downloadPath = docinfoSet.getMbo(0).getString("URLNAME");
                fileName = docinfoSet.getMbo(0).getString("DESCRIPTION");
                fileType = docinfoSet.getMbo(0).getString("URLNAME").substring(docinfoSet.getMbo(0).getString("URLNAME").lastIndexOf("\\") + 1);
            } else {
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(false));
                responseMap.put("errcode", "206");
                responseMap.put("errmsg", "Failed to download file. Please check if the parameter values are correct");//下载文件失败，请检查参数值是否正确
                String jsonResponse = JSONObject.toJSONString(responseMap);
                try {
                    sendResponse(jsonResponse, response);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            File file = new File(downloadPath);
            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileType, "UTF-8"));
            response.setContentLength((int)file.length());
            response.setHeader("Accept-Ranges", "bytes");
            response.setContentType("application/octet-stream");
            int readLength = 0;
            in = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
            out = new BufferedOutputStream(response.getOutputStream());
            byte[] buffer = new byte[BUFFER_SIZE];
            while ((readLength = in.read(buffer)) > 0) {
                byte[] bytes = new byte[readLength];
                System.arraycopy(buffer, 0, bytes, 0, readLength);
                out.write(bytes);
            }
            out.flush();
        } catch (Exception e) {
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(false));
            responseMap.put("errcode", "205");
            responseMap.put("errmsg", "download failure"+e.getMessage());
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try {
                sendResponse(jsonResponse, response);
            }
            catch (Exception e1) {
                e1.printStackTrace();
            }
            if (in != null) {
                try {
                    in.close();
                }
                catch (IOException localIOException) {}
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException localIOException1) {}
            }
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException localIOException2) {}
            }
            if (out != null) {
                try {
                    out.close();
                }
                catch (IOException localIOException3) {}
            }
        }
    }

    //向附件相关表插入数据
    public void setFileDoclink(String fileName, int ownerid, String ownertable, String uploadPath, String CREATEBY, String fileType, String reference)
    {
        try {
            if ((!fileName.equalsIgnoreCase("")) && (!ownertable.equalsIgnoreCase("")) && (ownerid > 1)) {
                SimpleDateFormat ftd = new SimpleDateFormat("yyyyMMddHHmmss");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date UPLOADDATE = sdf.parse(sdf.format(new Date())); //系统生成上传日期
                MboSetRemote doclinksSet = MXServer.getMXServer().getMboSet("DOCLINKS",MXServer.getMXServer().getSystemUserInfo());
                MboSetRemote docinfoSet = MXServer.getMXServer().getMboSet("DOCINFO",MXServer.getMXServer().getSystemUserInfo());
                //-附件表插入start----------------------------------------------------------------------------------------------
                //docinfo
                MboRemote docinfoMbo = docinfoSet.add();
                Integer DOCINFOID = docinfoMbo.getInt("DOCINFOID");//表ID
                String CONTENTUID= String.valueOf(DOCINFOID);
                String LANGCODE = "ZH";
                int SHOW = 0; int USEDEFAULTFILEPATH = 0; int PRINTTHRULINKDFLT = 0;
                String DOCUMENT = CONTENTUID;//暂时这样设置
                String DESCRIPTION = fileName;//文件名
                String CHANGEBY = CREATEBY;
                String DOCTYPE = "Attachments";//固定值
                String URLTYPE = "FILE";//固定值
                String URLNAME = uploadPath+fileName;// /sunda/eamfile/attachments/企业微信截图_1694773145947.png
                docinfoMbo.setValue("CONTENTUID",CONTENTUID,11L);
                docinfoMbo.setValue("LANGCODE",LANGCODE,11L);
                docinfoMbo.setValue("SHOW",SHOW,11L);
                docinfoMbo.setValue("USEDEFAULTFILEPATH",USEDEFAULTFILEPATH,11L);
                docinfoMbo.setValue("PRINTTHRULINKDFLT",PRINTTHRULINKDFLT,11L);
                docinfoMbo.setValue("DOCUMENT",DOCUMENT,11L);
                docinfoMbo.setValue("DESCRIPTION",DESCRIPTION,11L);
                docinfoMbo.setValue("CREATEDATE",UPLOADDATE,11L);
                docinfoMbo.setValue("CHANGEDATE",UPLOADDATE,11L);
                docinfoMbo.setValue("CHANGEBY",CREATEBY,11L);
                docinfoMbo.setValue("CREATEBY",CREATEBY,11L);
                docinfoMbo.setValue("DOCTYPE",DOCTYPE,11L);
                docinfoMbo.setValue("URLTYPE",URLTYPE,11L);
                docinfoMbo.setValue("URLNAME",URLNAME,11L);
                docinfoMbo.getThisMboSet().save(11L);
                docinfoSet.close();
                //doclinks
                MboRemote doclinksMbo = doclinksSet.add();
                doclinksMbo.setValue("DOCUMENT",DOCUMENT,11L);
                doclinksMbo.setValue("OWNERTABLE",ownertable,11L);
                doclinksMbo.setValue("OWNERID",ownerid,11L);
                doclinksMbo.setValue("DOCTYPE",DOCTYPE,11L);
                doclinksMbo.setValue("GETLATESTVERSION",1,11L);
                doclinksMbo.setValue("CREATEDATE",UPLOADDATE,11L);
                doclinksMbo.setValue("CHANGEDATE",UPLOADDATE,11L);
                doclinksMbo.setValue("CHANGEBY",CREATEBY,11L);
                doclinksMbo.setValue("CREATEBY",CREATEBY,11L);
                doclinksMbo.setValue("PRINTTHRULINK",0,11L);
                doclinksMbo.setValue("COPYLINKTOWO",0,11L);
                doclinksMbo.setValue("DOCINFOID",DOCINFOID,11L);
                doclinksMbo.getThisMboSet().save(11L);
                doclinksSet.close();
                //-附件表插入end----------------------------------------------------------------------------------------------
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (MXException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 获取文件列表
     * @param response
     * @param request
     */
    public void getFileData(HttpServletResponse response, HttpServletRequest request)
    {
        JSONArray dataArray = new JSONArray();
        String ownertable = request.getParameter("ownertable");
        String owneridStr = request.getParameter("ownerid");
        Integer ownerid = Integer.parseInt(owneridStr);
        System.out.println("ownertable:"+ownertable);
        System.out.println("ownerid:"+ownerid);
        try
        {
            MboSetRemote doclinksSet = MXServer.getMXServer().getMboSet("DOCLINKS", MXServer.getMXServer().getSystemUserInfo());
            doclinksSet.setWhere("  ownerid='" + ownerid + "'  and ownertable='" + ownertable + "' ");
            doclinksSet.reset();
            if (!doclinksSet.isEmpty()) {
                for (int i = 0; i < doclinksSet.count(); i++)
                {
                    JSONObject dataObject = new JSONObject();
                    dataObject.put("docinfoid", Integer.valueOf(doclinksSet.getMbo(i).getInt("DOCINFOID")));
                    dataObject.put("filedescription", doclinksSet.getMbo(i).getString("DOCINFO.DESCRIPTION"));
                    dataObject.put("createdate", doclinksSet.getMbo(i).getString("CREATEDATE"));
                    dataArray.add(dataObject);
                }
                doclinksSet.close();
            }
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(true));
            responseMap.put("errcode", "200");
            responseMap.put("errmsg", "Successfully obtained attachment list");//获取附件列表成功
            responseMap.put("data", dataArray);
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try {
                sendResponse(jsonResponse, response);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return;
        }
        catch (RemoteException e) {
            e.printStackTrace();
        } catch (MXException e) {
            e.printStackTrace();
        }
    }

    /**
     * 删除文件
     * @param response
     * @param request
     */
    private void deleteFile(HttpServletResponse response, HttpServletRequest request)
    {
        String docinfoid = request.getParameter("docinfoid");
        String useruid = request.getParameter("useruid");//登录人
        if ((useruid == null) || ("".equals(useruid)))
        {
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(false));
            responseMap.put("errcode", "206");
            responseMap.put("errmsg", "Failed to delete file. The parameter 'current login user uid' cannot be empty");//删除文件失败，参数当前登录人useruid不能为空
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try
            {
                sendResponse(jsonResponse, response);
            }
            catch (Exception e1)
            {
                e1.printStackTrace();
            }
        }
        try
        {
            MboSetRemote maxuserSet = MXServer.getMXServer().getMboSet("MAXUSER", MXServer.getMXServer().getSystemUserInfo());
            maxuserSet.setWhere("maxuserid='" + useruid + "'");
            String userid = "";
            if (!maxuserSet.isEmpty())
            {
                userid = maxuserSet.getMbo(0).getString("userid");
                System.out.println("userid==" + userid);
            }
            MboSetRemote doclinksSet = MXServer.getMXServer().getMboSet("DOCLINKS", MXServer.getMXServer().getSystemUserInfo());
            doclinksSet.setWhere(" docinfoid="+docinfoid+"");
            doclinksSet.reset();
            if (!doclinksSet.isEmpty()) {
                String createby = doclinksSet.getMbo(0).getString("createby");
                if (createby.equals(useruid)) {
                    System.out.println("username==" + doclinksSet.getMbo(0).getUserName());
                    doclinksSet.getMbo(0).delete();
                } else {
                    Map<String, Object> responseMap = new HashMap();
                    responseMap.put("flag", Boolean.valueOf(false));
                    responseMap.put("errcode", "207");
                    responseMap.put("errmsg", "Failed to delete file. The attachment was not uploaded by myself and cannot be deleted!");//删除文件失败，该附件不是本人上传，无法删除!
                    String jsonResponse = JSONObject.toJSONString(responseMap);
                    try
                    {
                        sendResponse(jsonResponse, response);
                    }
                    catch (Exception e1)
                    {
                        e1.printStackTrace();
                    }
                }
            } else {
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(false));
                responseMap.put("errcode", "205");
                responseMap.put("errmsg", "Failed to delete file. Please check if the parameters are correct");//删除文件失败，请检查参数是否正确
                String jsonResponse = JSONObject.toJSONString(responseMap);
                try {
                    sendResponse(jsonResponse, response);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            doclinksSet.save();
            doclinksSet.close();
            MboSetRemote docinfoSet = MXServer.getMXServer().getMboSet("DOCINFO", MXServer.getMXServer().getSystemUserInfo());
            docinfoSet.setWhere("   docinfoid='" + docinfoid + "'  ");
            docinfoSet.reset();
            if (!docinfoSet.isEmpty()) {
                String filePathToDelete = docinfoSet.getMbo(0).getString("URLNAME");
                File fileToDelete = new File(filePathToDelete);
                if (fileToDelete.exists() && fileToDelete.isFile()) {
                    fileToDelete.delete();
                }
                docinfoSet.getMbo(0).delete();
            } else {
                Map<String, Object> responseMap = new HashMap();
                responseMap.put("flag", Boolean.valueOf(false));
                responseMap.put("errcode", "205");
                responseMap.put("errmsg", "Failed to delete file. Please check if the parameters are correct");//删除文件失败，请检查参数是否正确
                String jsonResponse = JSONObject.toJSONString(responseMap);
                try {
                    sendResponse(jsonResponse, response);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            docinfoSet.save();
            docinfoSet.close();
            Map<String, Object> responseMap = new HashMap();
            responseMap.put("flag", Boolean.valueOf(true));
            responseMap.put("errcode", "200");
            responseMap.put("errmsg", "delete success");//删除附件成功
            String jsonResponse = JSONObject.toJSONString(responseMap);
            try {
                sendResponse(jsonResponse, response);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return;
        }
        catch (RemoteException e) {
            e.printStackTrace();
        } catch (MXException e) {
            e.printStackTrace();
        }
    }

    private void sendResponse(String responseString, HttpServletResponse response)
            throws Exception
    {
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter pw = null;
        try
        {
            pw = response.getWriter();
            pw.write(responseString);
            pw.flush();
        }
        finally
        {
            IOUtils.closeQuietly(pw);
        }
    }

    //-移动端上传图片-end----------------------------------------------------------



    /**
     * 图片查看,不区分在线和离线
     */
    @POST
    @Path("/viewPicture")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public JSONObject viewPicture(String received) throws RemoteException, MXException {
        //定义返回对象
        JSONObject returnDate = new JSONObject();
        JSONArray fileArr = new JSONArray();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        JSONObject jsonObject = JSONObject.parseObject(received);
        //参数
        String OBJECTNAME = jsonObject.getString("OBJECTNAME");//表名
        String ID = jsonObject.getString("ID");//表ID
        MboSetRemote doclinksSet = MXServer.getMXServer().getMboSet("DOCLINKS",MXServer.getMXServer().getSystemUserInfo());
        MboSetRemote docinfoSet = MXServer.getMXServer().getMboSet("DOCINFO",MXServer.getMXServer().getSystemUserInfo());
        doclinksSet.setWhere("OWNERTABLE='"+OBJECTNAME+"' and OWNERID="+ID+"");
        doclinksSet.reset();
        if(doclinksSet!=null && !doclinksSet.isEmpty()){
            for(int i=0;i<doclinksSet.count();i++){
                MboRemote doclinksMbo = doclinksSet.getMbo(i);
                int DOCINFOID = doclinksMbo.getInt("DOCINFOID");
                docinfoSet.setWhere("DOCINFOID="+DOCINFOID+"");
                docinfoSet.reset();
                if(docinfoSet!=null && !docinfoSet.isEmpty()){
                    MboRemote docinfoMbo = docinfoSet.getMbo(0);
                    String description = docinfoMbo.getString("DESCRIPTION");
                    fileArr.add(description);
                }
            }
            returnDate.put("errcode","200");
            returnDate.put("errmsg","get success");
            returnDate.put("file",fileArr);
        }else{
            returnDate.put("errcode","200");
            returnDate.put("errmsg","get success");
            returnDate.put("file",fileArr);
        }
        return returnDate;
    }


}
