<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="com.engine.portrait.util.PortraitUtil" %>
<%@ page import="com.engine.portrait.util.CommonUtil" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.*" %>
<%@ page import="com.engine.kq.service.impl.KQMyAttendanceServiceImpl" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.engine.common.util.ParamUtil" %>
<%@ page import="com.engine.kq.service.KQMyAttendanceService" %>
<%@ page import="com.engine.common.util.ServiceUtil" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    BaseBean bb = new BaseBean();
    User user = HrmUserVarify.getUser(request , response);

    Map<String,Object> apiDatas = getService(user).getHrmKQReportInfo(ParamUtil.request2Map(request), user);
    JSONObject dataJson = new JSONObject(apiDatas);

    String zjkqnj = "0.0";
    String lnkqnj = "0.0";
    String jnkqnj = "0.0";

    if(StringUtils.isNotEmpty(dataJson.toJSONString())){
        if(dataJson.containsKey("status")){
            if("1".equals(dataJson.getString("status"))){
                if(dataJson.containsKey("groupitem4")){
                    JSONObject groupitem4 = dataJson.getJSONObject("groupitem4");
                    out.print("groupitem4:"+groupitem4+"<br>");
                    if(groupitem4.containsKey("items")){
                        JSONArray items = groupitem4.getJSONArray("items");
                        for(int i=0;i<items.size();i++){
                            JSONObject itemJson = items.getJSONObject(i);

                            String title = itemJson.getString("title");
                            out.print("title:"+title+"<br>");
                            if("年假".equals(title.trim()) || title.trim().contains("年假")){
                                out.print("itemJson:"+itemJson+"<br>");
                                JSONArray itemArray = itemJson.getJSONArray("item");
                                out.print("itemArray:"+itemArray.size()+"<br>");
                                for(int k=0;k<itemArray.size();k++){
                                    JSONObject itemData = itemArray.getJSONObject(k);
                                    out.print("itemData:"+itemData+"<br>");
                                    String itemTitle = itemData.getString("title");
                                    String itemValue = itemData.getString("value");
                                    out.print("itemTitle:"+itemTitle+"<br>");
                                    out.print("itemValue:"+itemValue+"<br>");

                                    if("总计可请天数".equals(itemTitle)){
                                        zjkqnj = itemValue;
                                    }
                                    if("历年可请天数".equals(itemTitle)){
                                        lnkqnj = itemValue;
                                    }
                                    if("今年可请天数".equals(itemTitle)){
                                        jnkqnj = itemValue;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    out.print("zjkqnj:"+zjkqnj+"lnkqnj:"+lnkqnj+"jnkqnj:"+jnkqnj);

    JSONObject jsonObject = new JSONObject();

    jsonObject.put("zjkqnj",zjkqnj);
    jsonObject.put("lnkqnj",lnkqnj);
    jsonObject.put("jnkqnj",jnkqnj);

%>
<%=jsonObject.toString()  %>


<%!

    /***
     *
     * @param userid
     * @param itemid
     * @return
     */
    private String getQuerySql(String userid,String itemid) {

        BaseBean bb = new BaseBean();
        StringBuilder sqlSB = new StringBuilder();

        if(StringUtils.isNotEmpty(itemid))
        {
            sqlSB.append(" select e.id as itemdataid,e.userid,e.itemvalue,e.otherinfo as itemdata,d.* from (SELECT a.moduleid,a.name ,b.subname,b.subid ,b.iconname,b.iconcolor,b.iconbgcolor,c.id as itemid,c.iszeroshow,c.name as itemname,c.tipsinfo,c.isability,c.isnegative,c.overcolor,c.showorder")
                    .append(" FROM wr_individualitem_module a join wr_individualitem_submodule b on a.moduleid = b.moduleid ")
                    .append(" join wr_individualitem_info c on b.subid = c.subid ")
                    .append(" where a.status = 1 and b.status = 1 and  c.status = 1 ");
            if (!CommonUtil.hasSubordinate(userid)) {
                sqlSB.append(" and a.moduleid != 3 ");
            }
            String shareSql = "";
            try {
                shareSql = PortraitUtil.getShareBizidSql("10",userid);
            } catch (Exception e) {
                bb.writeLog("获取shareSql失败,userid="+userid+",type=10,"+e);
            }
            if (StringUtils.isNotEmpty(shareSql)) {
                sqlSB.append(" and b.subid in (").append(shareSql).append(")");
            }
            sqlSB.append(" ) d join wr_individualitem_detail e on e.itemid = d.itemid ").append(" WHERE e.userid = ? and e.type = ? ");
            sqlSB.append(" and d.itemid = "+itemid);
            sqlSB.append(" order by d.moduleid asc,d.showorder asc");
        }
        return sqlSB.toString();
    }

%>

<%!

    private KQMyAttendanceService getService(User user){
        return (KQMyAttendanceService) ServiceUtil.getService(KQMyAttendanceServiceImpl.class, user);
    }

%>



