<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
    BaseBean bb = new BaseBean();
    User user = HrmUserVarify.getUser(request , response) ;
    int userid = user.getUID();

    List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();

    List<Map<String,Object>> riskHomeList = new ArrayList<Map<String,Object>>();

    bb.writeLog("riskHomeList:"+riskHomeList.size());
    dataList.addAll(riskHomeList);
    List<Map<String,Object>> contractList = grtContractWarning(userid);
    bb.writeLog("contractList:"+contractList.size());
    dataList.addAll(contractList);
    bb.writeLog("dataList:"+dataList.size());

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("data",dataList);
    jsonObject.put("status", "1");
    jsonObject.put("total", dataList.size());
%>
<%=jsonObject.toString()  %>

<%!
    /**
     *
     * @return
     */
    public List<Map<String,Object>> grtContractWarning(int userid){
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();

        Map<String,Object> dataMap = null;
        String timestrformart = "MM-dd" ;
        SimpleDateFormat sdf = new SimpleDateFormat(timestrformart) ;
        Calendar calendar = Calendar.getInstance() ;
        String currentDay = sdf.format(calendar.getTime()) ;
        bb.writeLog("currentDay:"+currentDay);

        String sql =" with cte as\n" +
                " (\n" +
                "    select d.id,d.managerid from hrmresource d\n" +
                "    where d.managerid=?\n" +
                "    union all\n" +
                "    select a.id,a.managerid from hrmresource a\n" +
                "    inner join cte b on a.managerid = b.id\n" +
                " )\n" +
                "  select h.id,h.lastname,datediff(Day,CONVERT(varchar(10),GETDATE(),120),enddate) as ts from hrmresource h " +
                "  where h.id in( \n" +
                "     select id from hrmresource where id= ?\n" +
                "     union all\n" +
                "     select id from cte\n" +
                "  )\n" +
                "  and datediff(Day,CONVERT(varchar(10),GETDATE(),120),enddate)<30\n" +
                "  and datediff(Day,startdate,CONVERT(varchar(10),GETDATE(),120))>0\n" +
                "  and h.startdate is not null\n" +
                "  and h.enddate is not null and len(h.startdate) > 0 and len(h.enddate) > 0 \n" +
                "  and h.status in(1,2,3,4) ";

        bb.writeLog("sql:"+sql);
        rs.executeQuery(sql,new Object[]{userid,userid});
        while (rs.next()){
            String id = Util.null2String(rs.getString("id"));
            String lastname = Util.null2String(rs.getString("lastname"));
            String ts = Util.null2String(rs.getString("ts"));
            bb.writeLog("lastname:"+lastname);
            bb.writeLog("ts:"+ts);

            dataMap = new HashMap<String, Object>();
            dataMap.put("userid",id);
            dataMap.put("fxmc","合同到期天数");
            dataMap.put("fxry",lastname);
            dataMap.put("fxlx","人事风险");
            dataMap.put("zbnum",ts);
            dataMap.put("unit","天");
            //{"fxmc":"下属工作微博连续不查看天数","fxry":"石磊","fxzb":"9","zbnum":"5","fxlx":"当责风险"},{"fxmc":"文档连续不查看天数","fxry":"王帆（南
            dataList.add(dataMap);
        }

        return dataList;
    }

%>



