<%@ page import="java.util.Map" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%

    User user = HrmUserVarify.getUser(request, response);
    if(user==null) {
        response.sendRedirect("/login/Login.jsp");
        return;
    }

    String startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");

    RecordSet rs = new RecordSet();
    List<Map<String,Object>> cityList = new ArrayList<Map<String,Object>>();
    String sql =" select selectvalue,selectname \n" +
                "   from workflow_selectitem \n" +
                "   where fieldid in(\n" +
                "       select id from workflow_billfield \n" +
                "       where billid in( select id from workflow_bill where tablename='uf_dwjbxx' ) and fieldname='szcs' \n" +
                "       and detailtable  is null\n" +
                " ) ";
    rs.executeQuery(sql);
    while (rs.next()){
        String selectvalue = rs.getString("selectvalue");
        String selectname = rs.getString("selectname");
        Map<String,Object> cityMap = new HashMap<String,Object>();
        cityMap.put("key","City"+selectvalue);
        cityMap.put("title",selectname);
        cityList.add(cityMap);
    }


    int yjjg_total = 0;
    int ejjg_total = 0;
    int jcjj_total = 0;
    int jcyj_total = 0;
    int yzjj_total = 0;
    int yzyj_total = 0 ;
    int jsssyj_total = 0;
    int jsssej_total = 0;

    for(int i=0;i<cityList.size();i++){
        Map<String,Object> cityMap = cityList.get(i);
        int yjjg = 0;
        int ejjg = 0;
        int jcjj = 0;
        int jcyj = 0;
        int yzjj = 0;
        int yzyj = 0 ;
        int jsssyj = 0;
        int jsssej = 0;

        String cityKey = Util.null2String(cityMap.get("key")).replace("City","");

        String where = "";
        if(StringUtils.isNotBlank(startDate)){
            where += " and k.fzrq >= '"+startDate+"' ";
        }

        if(StringUtils.isNotBlank(endDate)){
            where += " and k.fzrq <= '"+endDate+"' ";
        }

        sql =   " select k.id,k.zzdj,k.zzlx\n" +
                " from uf_dwjbxx t\n" +
                " inner join uf_bmzzzsxx k on k.dwmc = t.id\n" +
                " where k.zszt=0\n" +
                " and t.szcs=" + cityKey + where ;

        rs.executeQuery(sql);
        while (rs.next()){
            String zzdj = Util.null2String(rs.getString("zzdj"));
            String zzlx = Util.null2String(rs.getString("zzlx"));
            if("0".equals(zzlx)){ // 涉密信息系统集成
                if("1".equals(zzdj)){
                    jcjj++;
                }else if("2".equals(zzdj)){
                    jcyj++;
                }
            }else if("1".equals(zzlx)){ //国家秘密载体印制
                if("1".equals(zzdj)){
                    yzjj++;
                }else if("2".equals(zzdj)){
                    yzyj++;
                }
            }else if("2".equals(zzlx)){ //武器装备科研生产单位
                if("3".equals(zzdj)){
                    yjjg++;
                }else if("4".equals(zzdj)){
                    ejjg++;
                }
            }else if("3".equals(zzlx)){ //涉密军事设施建设
                if("3".equals(zzdj)){
                        jsssyj++;
                }else if("4".equals(zzdj)){
                        jsssej++;
                }
            }
        }



        cityMap.put("yjjg",yjjg);
        cityMap.put("ejjg",ejjg);
        cityMap.put("jcjj",jcjj);
        cityMap.put("jcyj",jcyj);
        cityMap.put("yzjj",yzjj);
        cityMap.put("yzyj",yzyj);
        cityMap.put("jsssyj",jsssyj);
        cityMap.put("jsssej",jsssej);

        yjjg_total += yjjg ;
        ejjg_total += ejjg ;
        jcjj_total += jcjj ;
        jcyj_total += jcyj ;
        yzjj_total += yzjj ;
        yzyj_total += yzyj ;
        jsssyj_total += jsssyj ;
        jsssej_total += jsssej ;
    }

    Map<String,Object> totalMap = new HashMap<String,Object>();
    totalMap.put("key","total");
    totalMap.put("title","合计");
    totalMap.put("yjjg",yjjg_total);
    totalMap.put("ejjg",ejjg_total);
    totalMap.put("jcjj",jcjj_total);
    totalMap.put("jcyj",jcyj_total);
    totalMap.put("yzjj",yzjj_total);
    totalMap.put("yzyj",yzyj_total);
    totalMap.put("jsssyj",jsssyj_total);
    totalMap.put("jsssej",jsssej_total);
    cityList.add(totalMap);

    JSONObject dataJson = new JSONObject();
    dataJson.put("data",cityList);

%>

<%=dataJson.toJSONString() %>

