GPUtil.jsp 23.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
<%@ page import="weaver.general.Util"%>
<%@ page import="java.util.Map.Entry"%>
<%@ page import="java.util.*"%>
<%@ page import="weaver.conn.RecordSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<%! 
	/**
	 * 把所有分部的数据放到集合中
	 * @return
	 */
	private LinkedHashMap<String,LinkedHashMap<String, String>> getWorkerResult(weaver.conn.RecordSet rs){
        LinkedHashMap<String,LinkedHashMap<String, String>> map = new LinkedHashMap<String,LinkedHashMap<String, String>>();
        String id = null;
        String showname = null;
        String exist = null;
        String without = null;
        String scoring = null;
        String assessing = null;
        String back = null;
        String finish = null;
        String oscoring = null;
        String oassessing = null;
        String oback = null;
        LinkedHashMap<String, String> curValues = null;
        while(rs.next()){
            id = null2String(rs.getString("id"));
            showname = null2String(rs.getString("showname"));
            exist = null2String(rs.getString("exist"));
            without = null2String(rs.getString("without"),"0");
            scoring = null2String(rs.getString("scoring"),"0");
            assessing = null2String(rs.getString("assessing"),"0");
            back = null2String(rs.getString("back"),"0");
            finish = null2String(rs.getString("finish"),"0");
            oscoring = null2String(rs.getString("oscoring"),"0");
            oassessing = null2String(rs.getString("oassessing"),"0");
            oback = null2String(rs.getString("oback"),"0");
            curValues = new LinkedHashMap<String, String>();
            curValues.put("id",id);
            curValues.put("showname",showname);
            curValues.put("exist",exist);
            curValues.put("without",without);
            curValues.put("scoring",scoring);
            curValues.put("assessing",assessing);
            curValues.put("back",back);
            curValues.put("finish",finish);
            curValues.put("oscoring",oscoring);
            curValues.put("oassessing",oassessing);
            curValues.put("oback",oback);
            map.put(id,curValues);
        }
        return map;
    }
	/**
	 * 构建查询sql
	 *
	 * @param year 年
	 * @param month 月
	 * @param isSqlServer 是否sqlserver数据库
	 * @return
	 */
	public String getSubcpySearchSql(String year,String month,boolean isSqlServer){
		year = "".equals(year)?""+Calendar.getInstance().get(Calendar.YEAR):year;
		String type = "1";
		String type2 = month;
		String sql = null;
		RecordSet rs = new RecordSet();
		String dbType = rs.getDBType();

	    //如果是sql server数据库
	    if("sqlserver".equals(dbType)){
		    sql = "SELECT  sc.id , "+
	        "        sc.subcompanyname showname, "+
	        "        ISNULL(A.exist, 0) exist , "+
	        "        ISNULL(B.without, 0) without , "+
	        "        ISNULL(C.scoring, 0) scoring , "+
	        "        ISNULL(D.assessing, 0) assessing , "+
	        "        ISNULL(BK.back, 0) back , "+
	        "        ISNULL(E.finish, 0) finish, "+
	        "        ISNULL(F.oscoring, 0) oscoring , "+
	        "        ISNULL(G.oassessing, 0) oassessing,  "+
	        "        ISNULL(OBK.oback, 0) oback  "+
	        "FROM    HrmSubCompany sc "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) exist "+
	        "                    FROM    HrmResource hrm "+
	        "                    WHERE   hrm.status<=3 AND EXISTS ( SELECT 1 "+
	        "                                     FROM   GP_AccessProgram ap "+
	        "                                     WHERE  hrm.id = ap.userid "+
	        "                                            AND ap.status = 3 ) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) A ON A.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) without "+
	        "                    FROM    HrmResource hrm "+
	        "                    WHERE   hrm.status<=3 AND hrm.id NOT in ( SELECT ap.userid "+
	        "                                     FROM   GP_AccessProgram ap "+
	        "                                     WHERE  ap.status = 3 ) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) B ON B.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) scoring "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 0 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND GETDATE()<Cast(score.enddate AS DATETIME) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) C ON C.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) assessing "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 1 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND GETDATE()<SCORE.enddate "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) D ON D.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) back "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 2 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND GETDATE()<SCORE.enddate "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) BK ON D.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) finish "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 3 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) E ON E.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) oscoring "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 0 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND GETDATE()>CAST(score.enddate AS DATETIME) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) F ON F.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) oassessing "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 1 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND GETDATE()>CAST(score.enddate AS DATETIME) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) G ON G.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) oback "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 2 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND GETDATE()>CAST(score.enddate AS DATETIME) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) OBK ON OBK.subcompanyid1 = sc.id ";
	    }else if("mysql".equals(dbType)) {
			sql = "SELECT  sc.id , "+
					"        sc.subcompanyname showname, "+
					"        IFNULL(A.exist, 0) exist , "+
					"        IFNULL(B.without, 0) without , "+
					"        IFNULL(C.scoring, 0) scoring , "+
					"        IFNULL(D.assessing, 0) assessing , "+
					"        IFNULL(BK.back, 0) back , "+
					"        IFNULL(E.finish, 0) finish, "+
					"        IFNULL(F.oscoring, 0) oscoring , "+
					"        IFNULL(G.oassessing, 0) oassessing,  "+
					"        IFNULL(OBK.oback, 0) oback  "+
					"FROM    HrmSubCompany sc "+
					"        LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) exist "+
					"                    FROM    HrmResource hrm "+
					"                    WHERE   hrm.status<=3 AND EXISTS ( SELECT 1 "+
					"                                     FROM   GP_AccessProgram ap "+
					"                                     WHERE  hrm.id = ap.userid "+
					"                                            AND ap.status = 3 ) "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) A ON A.subcompanyid1 = sc.id "+
					"        LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) without "+
					"                    FROM    HrmResource hrm "+
					"                    WHERE   hrm.status<=3 AND hrm.id NOT in ( SELECT ap.userid "+
					"                                     FROM   GP_AccessProgram ap "+
					"                                     WHERE  ap.status = 3 ) "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) B ON B.subcompanyid1 = sc.id "+
					"        LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) scoring "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 0 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                            AND CURRENT_TIMESTAMP(3)<Cast(score.enddate AS DATETIME) "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) C ON C.subcompanyid1 = sc.id "+
					"         LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) assessing "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 1 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                            AND CURRENT_TIMESTAMP(3)<SCORE.enddate "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) D ON D.subcompanyid1 = sc.id "+
					"         LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) back "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 2 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                            AND CURRENT_TIMESTAMP(3)<SCORE.enddate "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) BK ON D.subcompanyid1 = sc.id "+
					"        LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) finish "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 3 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) E ON E.subcompanyid1 = sc.id "+
					"        LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) oscoring "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 0 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                            AND CURRENT_TIMESTAMP(3)>CAST(score.enddate AS DATETIME) "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) F ON F.subcompanyid1 = sc.id "+
					"         LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) oassessing "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 1 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                            AND CURRENT_TIMESTAMP(3)>CAST(score.enddate AS DATETIME) "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) G ON G.subcompanyid1 = sc.id "+
					"         LEFT JOIN ( SELECT  subcompanyid1 , "+
					"                            COUNT(1) oback "+
					"                    FROM    HrmResource hrm , "+
					"                            GP_AccessScore score "+
					"                    WHERE   hrm.id = score.userid "+
					"                            AND hrm.status<=3 "+
					"                            AND score.status = 2 "+
					"                            AND year = '"+year+"' "+
					"                            AND type1 = '"+type+"' "+
					"                            AND type2 = '"+type2+"' "+
					"                            AND CURRENT_TIMESTAMP(3)>CAST(score.enddate AS DATETIME) "+
					"                    GROUP BY subcompanyid1 "+
					"                  ) OBK ON OBK.subcompanyid1 = sc.id ";
		} else{
		    sql = "SELECT  sc.id , "+
	        "        sc.subcompanyname showname, "+
	        "        NVL(A.exist, 0) exist , "+
	        "        NVL(B.without, 0) without , "+
	        "        NVL(C.scoring, 0) scoring , "+
	        "        NVL(D.assessing, 0) assessing , "+
	        "        NVL(BK.back, 0) back , "+
	        "        NVL(E.finish, 0) finish, "+
	        "        NVL(F.oscoring, 0) oscoring , "+
	        "        NVL(G.oassessing, 0) oassessing,  "+
	        "        NVL(OBK.oback, 0) oback  "+
	        "FROM    HrmSubCompany sc "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) exist "+
	        "                    FROM    HrmResource hrm "+
	        "                    WHERE   hrm.status<=3 AND EXISTS ( SELECT 1 "+
	        "                                     FROM   GP_AccessProgram ap "+
	        "                                     WHERE  hrm.id = ap.userid "+
	        "                                            AND ap.status = 3 ) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) A ON A.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) without "+
	        "                    FROM    HrmResource hrm "+
	        "                    WHERE   hrm.status<=3 AND hrm.id NOT in ( SELECT ap.userid "+
	        "                                     FROM   GP_AccessProgram ap "+
	        "                                     WHERE  ap.status = 3 ) "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) B ON B.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) scoring "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 0 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND SYSDATE<=TO_DATE(score.enddate,'yyyy-mm-dd') "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) C ON C.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) assessing "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 1 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND SYSDATE<=TO_DATE(score.enddate,'yyyy-mm-dd') "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) D ON D.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) back "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 2 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND SYSDATE<=TO_DATE(score.enddate,'yyyy-mm-dd') "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) BK ON D.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) finish "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 3 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) E ON E.subcompanyid1 = sc.id "+
	        "        LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) oscoring "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 0 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND SYSDATE>TO_DATE(score.enddate,'yyyy-mm-dd') "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) F ON F.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) oassessing "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 1 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND SYSDATE>TO_DATE(score.enddate,'yyyy-mm-dd') "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) G ON G.subcompanyid1 = sc.id "+
	        "         LEFT JOIN ( SELECT  subcompanyid1 , "+
	        "                            COUNT(1) oback "+
	        "                    FROM    HrmResource hrm , "+
	        "                            GP_AccessScore score "+
	        "                    WHERE   hrm.id = score.userid "+
	        "                            AND hrm.status<=3 "+
	        "                            AND score.status = 2 "+
	        "                            AND year = '"+year+"' "+
	        "                            AND type1 = '"+type+"' "+
	        "                            AND type2 = '"+type2+"' "+ 
	        "                            AND SYSDATE>TO_DATE(score.enddate,'yyyy-mm-dd') "+
	        "                    GROUP BY subcompanyid1 "+
	        "                  ) OBK ON OBK.subcompanyid1 = sc.id ";
	    }
	    return sql;
	}
%>