<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="java.util.UUID" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.api.doc.detail.util.DocDownloadCheckUtil" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    JSONArray jsonArray = new JSONArray();
    RecordSet rs = new RecordSet();
    User user  = HrmUserVarify.getUser(request , response) ;
    int userid = user.getUID();
    String billid = "";
    String pxfs = "";
    String sql = " select * from uf_zdyszb where ry = ?" ;
    rs.executeQuery(sql,new Object[]{userid});
    if(rs.next()){
        billid = Util.null2String(rs.getString("id"));
        pxfs = Util.null2String(rs.getString("pxfs"));
    }
    jsonArray = getCustomMenuInfoByBillid(billid);
    JSONObject jsonObject = new JSONObject();

    jsonObject.put("pxfs",pxfs);
    jsonObject.put("datas",jsonArray);
%>
<%=jsonObject.toJSONString()  %>


<%!
    /***
     *
     * @return
     */
    public JSONArray getCustomMenuInfoByBillid(String billid)
    {
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        JSONArray jsonArray = new JSONArray();
        try {
            int k=0;
            String orderby = " order by isnull(sx,0) ";
            String sql =   " select * from uf_zdyszb_dt1 where mainid = ?  " +orderby;
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{billid});
            while (rs.next()){
                String iconname = Util.null2String(rs.getString("iconname"));
                String iconuid = Util.null2String(rs.getString("iconuid"));
                String iconurl = Util.null2String(rs.getString("iconurl"));
                String linktype = Util.null2String(rs.getString("linktype"));
                String mtype = Util.null2String(rs.getString("mtype"));
                String menuid = Util.null2String(rs.getString("menuid"));
                String menulink = Util.null2String(rs.getString("menulink"));
                String menuname = Util.null2String(rs.getString("menuname"));
                String menunamemultlang = Util.null2String(rs.getString("menunamemultlang"));
                String menutype = Util.null2String(rs.getString("menutype"));
                String parentid = Util.null2String(rs.getString("parentid"));
                String syspagemenuid = Util.null2String(rs.getString("syspagemenuid"));
                String uuid = Util.null2String(rs.getString("uuid"));

                JSONObject jsonObject = new JSONObject();
                jsonObject.put("key",k);
                jsonObject.put("id",uuid);
                jsonObject.put("iconname",iconname);
                jsonObject.put("iconuid",iconuid);
                jsonObject.put("iconurl",iconurl);
                jsonObject.put("linktype",linktype);
                jsonObject.put("mType",mtype);
                jsonObject.put("menuid",menuid);
                jsonObject.put("menulink",menulink);
                jsonObject.put("menuname",menuname);
                jsonObject.put("menunamemultlang",menunamemultlang);
                jsonObject.put("menutype",menutype);
                jsonObject.put("parentId",parentid);
                //jsonObject.put("syspagemenuid",syspagemenuid);
                jsonArray.add(jsonObject);
                k++;
            }

            if(k == 0){
                jsonArray = getCustomMenuInfoByDefault("0");
            }
        }catch (Exception e){

        }
        return jsonArray;
    }


    /***
     *
     * @param lx
     * @return
     */
    public JSONArray getCustomMenuInfoByDefault(String lx)
    {
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        JSONArray jsonArray = new JSONArray();
        try {
            int k= 0;
            String sql =   " select id,mc,tb,djhtb,url from uf_tbpzb where lx = ? order by isnull(sx,0)  ";
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{lx});
            while (rs.next()){
                String id = Util.null2String(rs.getString("id"));
                String mc = Util.null2String(rs.getString("mc"));
                String lj = Util.null2String(rs.getString("url"));
                String djhtb = Util.null2String(rs.getString("djhtb"));

                String uuid = UUID.randomUUID().toString();
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("key",k);
                jsonObject.put("id",uuid);

                jsonObject.put("linktype","0");
                jsonObject.put("mType","0");
                jsonObject.put("menuid","0");
                jsonObject.put("menulink",lj);
                jsonObject.put("menuname",mc);
                jsonObject.put("menunamemultlang",mc);
                jsonObject.put("menutype","1");
                jsonObject.put("parentId","");
                jsonObject.put("djhtb",djhtb);
                jsonArray.add(jsonObject);
                k++;
            }

            for(int i=0;i<jsonArray.size();i++)
            {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String djhtb = Util.null2String(jsonObject.get("djhtb"));
                String imagefileid = "" ;
                String imagefilename = "" ;
                if(StringUtils.isNotEmpty(djhtb)){
                    sql =   " select k.imagefileid,l.imagefilename\n" +
                            " from docdetail t\n" +
                            " inner join docimagefile l on l.docid = t.id\n" +
                            " inner join imagefile k on k.imagefileid = l.imagefileid\n" +
                            " where docid= "+ djhtb;
                    rs.executeQuery(sql);
                    if(rs.next()){
                        imagefileid = Util.null2String(rs.getString("imagefileid"));
                        imagefilename = Util.null2String(rs.getString("imagefilename"));
                    }

                    String fileid = "";
                    if(StringUtils.isNotEmpty(imagefileid)){
                        try{
                            fileid = DocDownloadCheckUtil.checkPermission(imagefileid+"",null);
                        }catch (Exception e){
                            bb.writeLog("e:"+e);
                        }
                    }
                    String iconurl = "/weaver/weaver.file.FileDownload?fileid="+fileid+"";
                    jsonObject.put("iconname",imagefilename);
                    jsonObject.put("iconuid",UUID.randomUUID().toString());
                    jsonObject.put("iconurl",iconurl);
                }
            }
        }catch (Exception e){

        }
        return jsonArray;
    }

%>



