package com.sinosoft.em.baobiao.xianlutingyun.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import com.formaction.vo.Msg; import com.persistence.DbConnection; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.exception.PersistenceException; import com.sinosoft.am.org.jdbcUtil.ORGTemplate; import com.sinosoft.cm.ex.SQLStringException; import com.sinosoft.em.alert.report.manage.SQLPreparedUtil; import com.sinosoft.em.alert.report.manage.vo.ReportKV; import com.sinosoft.em.alert.report.manage.vo.ReportProgress; import com.sinosoft.em.alert.report.manage.vo.reportDept; import com.sinosoft.em.baobiao.xianlutingyun.vo.ProjectNameVo; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; public class QueryReportProgrammeDaoImpl implements QueryReportProgrammeDao { private static SysModel sysmodel = ModelFactory.getSysmodel(); @SuppressWarnings("unused") private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); private final static Logger log = Logger.getLogger(QueryReportProgrammeDaoImpl.class); /** * 查询部门下报告填报信息 */ public List loadReportProgramme(String deptId,String planId,String reportType, String preproTime,String currprogressTime,String aftTime) throws Exception { try { String sql = "SELECT a.FD_OBJECTID,to_char(a.REPORT_TIME,'yyyy-mm-dd hh24:mi:ss'),b.real_name REPORTER_ID,to_char(a.appear_time,'yyyy-mm-dd hh24:mi:ss'),a.REPORT_TYPE,a.comp_id,b.user_id FROM REPORT_RECORDS a,sys_user_info b WHERE a.REPORTER_ID=b.user_id and "+ "a.COMP_ID='"+deptId+"'"+ " AND a.IS_DEL=0 AND a.SEND_STAT='1' AND a.appear_time>=to_char(to_date('"+currprogressTime+"','yyyy-mm-dd hh24:mi:ss')- interval '1' hour,'yyyy-mm-dd hh24:mi:ss') AND a.appear_time<=to_char(to_date('"+currprogressTime+"','yyyy-mm-dd hh24:mi:ss')+ interval '1' hour,'yyyy-mm-dd hh24:mi:ss') and a.report_type='"+reportType+"' and report_id like'%"+planId+"%' order by updatedate desc"; log.info("loadReportProgramme_sql:"+sql); List tempList = persistence.getSearchResult(99, sql.toString()); ArrayList list = new ArrayList(); if(tempList!=null && tempList.size()>0){ String[] arr = tempList.get(0); ReportProgress pro = new ReportProgress(); pro.setFd_object_id(arr[0]); pro.setWRITE_TIME_322(arr[1]); pro.setWRITER_322(arr[2]); pro.setUpdateTime(arr[3]); pro.setWRITER_ID_322(arr[6]); list.add(pro); } log.info("proList:"+list); return list; } catch (Exception e) { throw e; } } /** * 查询部门 */ public List loadReportDept(String planId,String tbzt) throws Exception { DbConnection db = new DbConnection(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { String sql = "select WRITE_DEPT_ID,EARLY_WARNING_ID,REPORT_TYPE,START_TIME,(case when " + "EXPIRATION_DATE='' then to_char(sysdate,'yyyy-mm-dd')||' 23:59:59' else EXPIRATION_DATE end)" + " as EXPIRATION_DATE,WRITE_DATE_TYPE,CIRCLE_TIME,TEMPORARY_TIME,UPDATEDATE FROM ECM_EM_ALERT_REPORT_PLAN " +"WHERE FD_OBJECTID='"+planId+"' AND IS_DEL=0 AND IS_RELEASE=1"; log.info("loadReportProgramme_sql:"+sql); conn = db.getConnection(); ps = conn.prepareStatement(sql); rs = ps.executeQuery(); //填报部门ID,可以有多个,要进行字符串截取 String deptIds = ""; //预警编号 String earlyWarningId = ""; //报告类别 String reportType = ""; //截止日期 Date expirationData = new Date(); //开始日期 Date startDate = new Date(); //填报时间表 String writeDataType = ""; //周期性 String circleTime = ""; //临时性 String temporaryTime = ""; String updatedate = ""; while(rs.next()){ deptIds = rs.getString("WRITE_DEPT_ID"); earlyWarningId = rs.getString("EARLY_WARNING_ID"); reportType = rs.getString("REPORT_TYPE"); expirationData = rs.getDate("EXPIRATION_DATE"); writeDataType = rs.getString("WRITE_DATE_TYPE"); circleTime = rs.getString("CIRCLE_TIME"); temporaryTime = rs.getString("TEMPORARY_TIME"); startDate = rs.getDate("START_TIME"); //updatedate = rs.getString("UPDATEDATE").split(" ")[0]; updatedate = rs.getString("UPDATEDATE"); } //通过判断获取离当前时间最近的计划时间 //String progressTime = judgeTime(startDate,expirationData, writeDataType, circleTime, temporaryTime,updatedate); String progressTime = getProgressTime(writeDataType, circleTime, temporaryTime,updatedate); String[] deptIdArr = deptIds.split(","); /*********打桩**********************************************/ log.info("deptIdArr:"+Arrays.toString(deptIdArr)); List depts = loadReportDeptById(deptIdArr, earlyWarningId, reportType,progressTime,planId,tbzt); return depts; } catch (Exception e) { throw e; }finally{ rs.close(); ps.close(); conn.close(); } } /** * 通过部门ID到部门表中查询出相应的部门名称 * @param planId * @param tbzt * @throws Exception * **/ public List loadDeptById(List list) throws Exception{ DbConnection db = new DbConnection(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = db.getConnection(); //生成sql语句中in的问号 String inCondition = SQLPreparedUtil.preparePlaceHolders(list.size()); log.info("inCondition:"+inCondition); String sql = "select DEPT_NAME,DEPT_ID FROM SYS_DEPARTMENT "+ "WHERE DEPT_ID "+ "IN("+inCondition+")"; log.info("sql_write_dept:"+sql); ps = conn.prepareStatement(sql); for (int i = 0; i < list.size(); i++) { ps.setString(i+1,list.get(i)); } rs = ps.executeQuery(); //用于存储部门信息 ArrayList depts = new ArrayList(); while(rs.next()){ ReportProgress dept = new ReportProgress(); dept.setDeptId(rs.getString("DEPT_ID")); dept.setDeptName(rs.getString("DEPT_NAME")); depts.add(dept); } //部门id和部门名打桩 log.info("depts:"+depts); return depts ; } catch (Exception e) { throw e; }finally{ rs.close(); ps.close(); conn.close(); } } /** * 通过部门ID到部门表中查询出相应的部门名称 * @param planId * @param tbzt * **/ public List loadReportDeptById(String[] deptIdArr,String earlyWarningId, String reportType,String progressTime, String planId, String tbzt) throws Exception{ DbConnection db = new DbConnection(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = db.getConnection(); //生成sql语句中in的问号 String inCondition = SQLPreparedUtil.preparePlaceHolders(deptIdArr.length); log.info("inCondition:"+inCondition); String sql = "select DEPT_NAME,DEPT_ID FROM SYS_DEPARTMENT "+ "WHERE DEPT_ID "+ "IN("+inCondition+")"; log.info("sql_write_dept:"+sql); ps = conn.prepareStatement(sql); for (int i = 0; i < deptIdArr.length; i++) { ps.setString(i+1,deptIdArr[i]); } rs = ps.executeQuery(); //用于存储部门信息 ArrayList depts = new ArrayList(); while(rs.next()){ reportDept dept = new reportDept(); dept.setID(rs.getString("DEPT_ID")); dept.setRESPONSIBLE_NAME_322(rs.getString("DEPT_NAME")); dept.setIconClass("icon_home"); dept.setOpen(false); dept.setEarlyWarningId(earlyWarningId);//预警编号 dept.setReportType(reportType);//报告类别 //参数,查看部门下报告填报情况时所用 dept.setParams(dept.getID()+","+planId+","+progressTime+","+dept.getReportType()+","+tbzt); depts.add(dept); } //部门id和部门名打桩 log.info("depts:"+depts); return depts ; } catch (Exception e) { throw e; }finally{ rs.close(); ps.close(); conn.close(); } } /** * 根据单位id和预警还是响应is_alert,查询相应未完成的填报要求 */ public List loadReportPlan(String deptId,String role_id) throws Exception { //系统当前时间 Long currentTime = System.currentTimeMillis(); Date currDate = new Date(currentTime); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String strcurr = dateformat.format(currDate); String sql=""; List list1 = new ArrayList(); List> allList = new ArrayList>(); List> corpList = new ArrayList>(); List> deptList = new ArrayList>(); List> list = new ArrayList>(); List nameList = new ArrayList(); Map voMap = new HashMap(); if("R002105430205".equals(role_id)||"R002105430204".equals(role_id)||"R002105430203".equals(role_id)||"R002105430202".equals(role_id)||"R002105430201".equals(role_id)||"R002105430200".equals(role_id)){//应急办角色查看本级应急办填报的计划和同级专业管理部门已发布的计划 sql="select comp_id,project_name,warning_number,FD_OBJECTID,START_TIME,UPDATEDATE,SEND_TIME,FILL_IN_SCHEDULE,ROUND_TIME,TEMPORARY_TIME,report_dept,role_id,end_time,send_stat from REPORT_SCHEDULE where (END_TIME>=TO_CHAR(TO_DATE(?,'yyyy-mm-dd'),'yyyy-mm-dd') or END_TIME IS NULL or end_time='') and TO_CHAR(TO_DATE(START_TIME,'yyyy-mm-dd'),'yyyy-mm-dd')<=TO_CHAR(TO_DATE(?,'yyyy-mm-dd'),'yyyy-mm-dd') and ((role_id=? and comp_id=?) or (role_id <>? and send_stat='1' and comp_id=?)) and is_del='0' and send_stat='1' AND (round_time is not null or TEMPORARY_TIME is not null ) order by to_number(substr(role_id,4))"; list=new ORGTemplate().query(sql, strcurr,strcurr,role_id,deptId,role_id,deptId); }else{//专业管理部门角色查看本级应急办已发布的计划和上级专业管理部门已发布的计划还有给下级的计划 sql="select comp_id,project_name,warning_number,FD_OBJECTID,START_TIME,UPDATEDATE,SEND_TIME,FILL_IN_SCHEDULE,ROUND_TIME,TEMPORARY_TIME,report_dept,role_id,end_time,send_stat from REPORT_SCHEDULE where (END_TIME>=TO_CHAR(TO_DATE(?,'yyyy-mm-dd'),'yyyy-mm-dd') or END_TIME IS NULL or end_time='') and TO_CHAR(TO_DATE(START_TIME,'yyyy-mm-dd'),'yyyy-mm-dd')<=TO_CHAR(TO_DATE(?,'yyyy-mm-dd'),'yyyy-mm-dd') and ((role_id='R002105430205'and comp_id=? and send_stat='1' and report_dept like ?) or (role_id =? and send_stat='1' and comp_id in(select parent_id from sys_department where dept_id=?)) or(comp_id=? and role_id=?)) and send_stat='1' order by to_number(substr(role_id,4))"; list=new ORGTemplate().query(sql, strcurr,strcurr,deptId,"%"+role_id+"%",role_id,deptId,deptId,role_id); } log.info("loadReportProgramme_sql:"+sql); try { for (int i = 0; i < list.size(); i++) { Map map = list.get(i); String WRITE_DATE_TYPE = map.get("FILL_IN_SCHEDULE");//填报类型 String send_stat= map.get("SEND_STAT");//发布状态 if("2".equals(send_stat)){ map.put("PROJECT_NAME", map.get("PROJECT_NAME")+"(已结束)"); } if("周期性".equals(WRITE_DATE_TYPE)){//周期性 String CIRCLE_TIME = map.get("ROUND_TIME");//周期性时间 if(!"".equals(CIRCLE_TIME.trim()) && CIRCLE_TIME.indexOf("NaN")==-1){//只有当周期性时间不为空 且 没有有错误时间格式时,才添加该条数据 String sendTime = map.get("SEND_TIME"); String sendTime1 = ""; if(sendTime!=null && !"".equals(sendTime)){ sendTime1 = sendTime.split(" ")[0]; } String currTime = strcurr.split(" ")[0];//年月日 if(sendTime1.equals(currTime)){//当发布日期与当前日期处于同一日时,再判断周期性最后那个时间点是否已经超过当前时间的时间点,比如发布时间:2-7 17:30 周期性时间:8:00,17:00 // int lastRoundTime = getLastRoundTime(CIRCLE_TIME);//取得周期性时间的最大时间的小时值 //String currHour = strcurr.split(" ")[1].split(":")[0]; // if(Integer.parseInt(currHour) < lastRoundTime){ if("R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("本级计划")){ ProjectNameVo allVo = new ProjectNameVo(); allVo.setName("本级计划"); allList.add(map); allVo.setList(allList); if(!nameList.contains("本级计划")){ nameList.add("本级计划"); } voMap.put("本级计划", allVo); }else { ProjectNameVo allVo = voMap.get("本级计划"); List> li = allVo.getList(); li.add(map); allVo.setList(li); voMap.put("本级计划", allVo); } } if(!"R002105430205".equals(role_id)){ if(checkLevel(deptId, role_id,map.get("FD_OBJECTID"))){ if(!voMap.containsKey("上级计划")){ ProjectNameVo corpVo = new ProjectNameVo(); corpVo.setName("上级计划"); corpList.add(map); corpVo.setList(corpList); if(!nameList.contains("上级计划")){ nameList.add("上级计划"); } voMap.put("上级计划", corpVo); }else { ProjectNameVo corpVo = voMap.get("上级计划"); List> li = corpVo.getList(); li.add(map); corpVo.setList(li); voMap.put("上级计划", corpVo); } } if(!"R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("下级计划")){ ProjectNameVo deptVo = new ProjectNameVo(); deptVo.setName("下级计划"); deptList.add(map); deptVo.setList(deptList); if(!nameList.contains("下级计划")){ nameList.add("下级计划"); } voMap.put("下级计划", deptVo); }else { ProjectNameVo deptVo = voMap.get("下级计划"); List> li = deptVo.getList(); li.add(map); deptVo.setList(li); voMap.put("下级计划", deptVo); } } } }else{ if("R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("本级计划")){ ProjectNameVo allVo = new ProjectNameVo(); allVo.setName("本级计划"); allList.add(map); allVo.setList(allList); if(!nameList.contains("本级计划")){ nameList.add("本级计划"); } voMap.put("本级计划", allVo); }else { ProjectNameVo allVo = voMap.get("本级计划"); List> li = allVo.getList(); li.add(map); allVo.setList(li); voMap.put("本级计划", allVo); } } if(!"R002105430205".equals(role_id)){ if(checkLevel(deptId, role_id,map.get("FD_OBJECTID"))){ if(!voMap.containsKey("上级计划")){ ProjectNameVo corpVo = new ProjectNameVo(); corpVo.setName("上级计划"); corpList.add(map); corpVo.setList(corpList); if(!nameList.contains("上级计划")){ nameList.add("上级计划"); } voMap.put("上级计划", corpVo); }else { ProjectNameVo corpVo = voMap.get("上级计划"); List> li = corpVo.getList(); li.add(map); corpVo.setList(li); voMap.put("上级计划", corpVo); } } if(!"R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("下级计划")){ ProjectNameVo deptVo = new ProjectNameVo(); deptVo.setName("下级计划"); deptList.add(map); deptVo.setList(deptList); if(!nameList.contains("下级计划")){ nameList.add("下级计划"); } voMap.put("下级计划", deptVo); }else { ProjectNameVo deptVo = voMap.get("下级计划"); List> li = deptVo.getList(); li.add(map); deptVo.setList(li); voMap.put("下级计划", deptVo); } } } } } }else{//临时性 String TEMPORARY_TIME = map.get("TEMPORARY_TIME"); if(TEMPORARY_TIME!=null && !"".equals(TEMPORARY_TIME.trim()) && TEMPORARY_TIME.indexOf("NaN")==-1){//只有当周期性时间不为空 且 没有有错误时间格式时,才添加该条数据 if("R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("本级计划")){ ProjectNameVo allVo = new ProjectNameVo(); allVo.setName("本级计划"); allList.add(map); allVo.setList(allList); if(!nameList.contains("本级计划")){ nameList.add("本级计划"); } voMap.put("本级计划", allVo); }else { ProjectNameVo allVo = voMap.get("本级计划"); List> li = allVo.getList(); li.add(map); allVo.setList(li); voMap.put("本级计划", allVo); } } if(!"R002105430205".equals(role_id)){ if(checkLevel(deptId, role_id,map.get("FD_OBJECTID"))){ if(!voMap.containsKey("上级计划")){ ProjectNameVo corpVo = new ProjectNameVo(); corpVo.setName("上级计划"); corpList.add(map); corpVo.setList(corpList); if(!nameList.contains("上级计划")){ nameList.add("上级计划"); } voMap.put("上级计划", corpVo); }else { ProjectNameVo corpVo = voMap.get("上级计划"); List> li = corpVo.getList(); li.add(map); corpVo.setList(li); voMap.put("上级计划", corpVo); } } if(!"R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("下级计划")){ ProjectNameVo deptVo = new ProjectNameVo(); deptVo.setName("下级计划"); deptList.add(map); deptVo.setList(deptList); if(!nameList.contains("下级计划")){ nameList.add("下级计划"); } voMap.put("下级计划", deptVo); }else { ProjectNameVo deptVo = voMap.get("下级计划"); List> li = deptVo.getList(); li.add(map); deptVo.setList(li); voMap.put("下级计划", deptVo); } } } } } } Collections.sort(nameList, new compareList()); for(int k=0;k loadReportPlan(String deptId,String role_id,String flag,String task_id) throws Exception { //系统当前时间 Long currentTime = System.currentTimeMillis(); Date currDate = new Date(currentTime); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String strcurr = dateformat.format(currDate); List list1 = new ArrayList(); List> allList = new ArrayList>(); List> corpList = new ArrayList>(); List> deptList = new ArrayList>(); List> list = new ArrayList>(); List nameList = new ArrayList(); Map voMap = new HashMap(); StringBuffer sb = new StringBuffer(); if(task_id.indexOf(",")>-1){ String[] arr = task_id.split(","); for (int i = 0; i < arr.length; i++) { sb.append("'"+arr[i]+"',"); } sb.deleteCharAt(sb.lastIndexOf(",")); }else{ sb.append("'"+task_id+"'"); } //根据任务ID查询 String sql = "select comp_id,project_name,warning_number,FD_OBJECTID,START_TIME,UPDATEDATE,SEND_TIME,FILL_IN_SCHEDULE,ROUND_TIME,TEMPORARY_TIME,report_dept,role_id,end_time,send_stat from REPORT_SCHEDULE where fd_objectid in("+sb.toString()+")"; log.info("loadReportProgramme_sql:"+sql); list = new ORGTemplate().query(sql); try { for (int i = 0; i < list.size(); i++) { Map map = list.get(i); String WRITE_DATE_TYPE = map.get("FILL_IN_SCHEDULE");//填报类型 String send_stat= map.get("SEND_STAT");//发布状态 if("2".equals(send_stat)){ map.put("PROJECT_NAME", map.get("PROJECT_NAME")+"(已结束)"); } if("周期性".equals(WRITE_DATE_TYPE)){//周期性 String CIRCLE_TIME = map.get("ROUND_TIME");//周期性时间 if(!"".equals(CIRCLE_TIME.trim()) && CIRCLE_TIME.indexOf("NaN")==-1){//只有当周期性时间不为空 且 没有有错误时间格式时,才添加该条数据 String sendTime = map.get("SEND_TIME"); String sendTime1 = ""; if(sendTime!=null && !"".equals(sendTime)){ sendTime1 = sendTime.split(" ")[0]; } String currTime = strcurr.split(" ")[0];//年月日 if(sendTime1.equals(currTime)){//当发布日期与当前日期处于同一日时,再判断周期性最后那个时间点是否已经超过当前时间的时间点,比如发布时间:2-7 17:30 周期性时间:8:00,17:00 // int lastRoundTime = getLastRoundTime(CIRCLE_TIME);//取得周期性时间的最大时间的小时值 //String currHour = strcurr.split(" ")[1].split(":")[0]; // if(Integer.parseInt(currHour) < lastRoundTime){ if("R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("本级计划")){ ProjectNameVo allVo = new ProjectNameVo(); allVo.setName("本级计划"); allList.add(map); allVo.setList(allList); if(!nameList.contains("本级计划")){ nameList.add("本级计划"); } voMap.put("本级计划", allVo); }else { ProjectNameVo allVo = voMap.get("本级计划"); List> li = allVo.getList(); li.add(map); allVo.setList(li); voMap.put("本级计划", allVo); } } if(!"R002105430205".equals(role_id)){ if(checkLevel(deptId, role_id,map.get("FD_OBJECTID"))){ if(!voMap.containsKey("上级计划")){ ProjectNameVo corpVo = new ProjectNameVo(); corpVo.setName("上级计划"); corpList.add(map); corpVo.setList(corpList); if(!nameList.contains("上级计划")){ nameList.add("上级计划"); } voMap.put("上级计划", corpVo); }else { ProjectNameVo corpVo = voMap.get("上级计划"); List> li = corpVo.getList(); li.add(map); corpVo.setList(li); voMap.put("上级计划", corpVo); } } if(!"R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("下级计划")){ ProjectNameVo deptVo = new ProjectNameVo(); deptVo.setName("下级计划"); deptList.add(map); deptVo.setList(deptList); if(!nameList.contains("下级计划")){ nameList.add("下级计划"); } voMap.put("下级计划", deptVo); }else { ProjectNameVo deptVo = voMap.get("下级计划"); List> li = deptVo.getList(); li.add(map); deptVo.setList(li); voMap.put("下级计划", deptVo); } } } }else{ if("R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("本级计划")){ ProjectNameVo allVo = new ProjectNameVo(); allVo.setName("本级计划"); allList.add(map); allVo.setList(allList); if(!nameList.contains("本级计划")){ nameList.add("本级计划"); } voMap.put("本级计划", allVo); }else { ProjectNameVo allVo = voMap.get("本级计划"); List> li = allVo.getList(); li.add(map); allVo.setList(li); voMap.put("本级计划", allVo); } } if(!"R002105430205".equals(role_id)){ if(checkLevel(deptId, role_id,map.get("FD_OBJECTID"))){ if(!voMap.containsKey("上级计划")){ ProjectNameVo corpVo = new ProjectNameVo(); corpVo.setName("上级计划"); corpList.add(map); corpVo.setList(corpList); if(!nameList.contains("上级计划")){ nameList.add("上级计划"); } voMap.put("上级计划", corpVo); }else { ProjectNameVo corpVo = voMap.get("上级计划"); List> li = corpVo.getList(); li.add(map); corpVo.setList(li); voMap.put("上级计划", corpVo); } } if(!"R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("下级计划")){ ProjectNameVo deptVo = new ProjectNameVo(); deptVo.setName("下级计划"); deptList.add(map); deptVo.setList(deptList); if(!nameList.contains("下级计划")){ nameList.add("下级计划"); } voMap.put("下级计划", deptVo); }else { ProjectNameVo deptVo = voMap.get("下级计划"); List> li = deptVo.getList(); li.add(map); deptVo.setList(li); voMap.put("下级计划", deptVo); } } } } } }else{//临时性 String TEMPORARY_TIME = map.get("TEMPORARY_TIME"); if(TEMPORARY_TIME!=null && !"".equals(TEMPORARY_TIME.trim()) && TEMPORARY_TIME.indexOf("NaN")==-1){//只有当周期性时间不为空 且 没有有错误时间格式时,才添加该条数据 if("R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("本级计划")){ ProjectNameVo allVo = new ProjectNameVo(); allVo.setName("本级计划"); allList.add(map); allVo.setList(allList); if(!nameList.contains("本级计划")){ nameList.add("本级计划"); } voMap.put("本级计划", allVo); }else { ProjectNameVo allVo = voMap.get("本级计划"); List> li = allVo.getList(); li.add(map); allVo.setList(li); voMap.put("本级计划", allVo); } } if(!"R002105430205".equals(role_id)){ if(checkLevel(deptId, role_id,map.get("FD_OBJECTID"))){ if(!voMap.containsKey("上级计划")){ ProjectNameVo corpVo = new ProjectNameVo(); corpVo.setName("上级计划"); corpList.add(map); corpVo.setList(corpList); if(!nameList.contains("上级计划")){ nameList.add("上级计划"); } voMap.put("上级计划", corpVo); }else { ProjectNameVo corpVo = voMap.get("上级计划"); List> li = corpVo.getList(); li.add(map); corpVo.setList(li); voMap.put("上级计划", corpVo); } } if(!"R002105430205".equals(map.get("ROLE_ID"))&& deptId.equals(map.get("COMP_ID"))){ if(!voMap.containsKey("下级计划")){ ProjectNameVo deptVo = new ProjectNameVo(); deptVo.setName("下级计划"); deptList.add(map); deptVo.setList(deptList); if(!nameList.contains("下级计划")){ nameList.add("下级计划"); } voMap.put("下级计划", deptVo); }else { ProjectNameVo deptVo = voMap.get("下级计划"); List> li = deptVo.getList(); li.add(map); deptVo.setList(li); voMap.put("下级计划", deptVo); } } } } } } Collections.sort(nameList, new compareList()); for(int k=0;k loadReportTypeName(String[] id,boolean flag) throws Exception { DbConnection db = new DbConnection(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { // String conditionOfReportType = ""; // String bm = "BM_AlertRespReportInputState"; // if(id.length==1){ // conditionOfReportType = " FD_CODE='"+id+"'"; // }else if(id.length()==3){ // String[] reportArr = id.split(","); // conditionOfReportType = " FD_CODE in ('"+reportArr[0]+"','"+reportArr[1]+"')"; // } StringBuffer condition=new StringBuffer(); for(int i=0;i-1){ condition.deleteCharAt(condition.lastIndexOf(",")); } String sql =""; if(flag){ sql = "select report_name,report_type from bm_mapforreport "+ "where report_name in("+condition.toString()+")"; }else{ sql = "select report_name,report_type from bm_mapforreport "+ "where report_type in("+condition.toString()+")"; } conn = db.getConnection(); ps = conn.prepareStatement(sql); rs = ps.executeQuery(); ArrayListlist = new ArrayList(); while(rs.next()){ ReportKV rkv = new ReportKV(); String name = rs.getString("REPORT_NAME"); String proid = rs.getString("REPORT_TYPE"); rkv.setId(proid); rkv.setName(name); list.add(rkv); } return list; } catch (Exception e) { throw e; }finally{ rs.close(); ps.close(); conn.close(); } } private String getProgressTime(String writeDataType, String circleTime, String temporaryTime, String updatedate) throws ParseException { //系统当前时间 Long currentTime = System.currentTimeMillis(); Date currDate = new Date(currentTime); //当前时间 Calendar curr = Calendar.getInstance(); curr.setTime(currDate); //日期 String _date = ""+curr.get(Calendar.YEAR)+"-" +(curr.get(Calendar.MONTH)+1)+"-"+curr.get(Calendar.DATE); //计划时间 String prograssTime = ""; SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if("周期性".equals(writeDataType)){ String[] cirTimeArr1 = circleTime.split(";"); for (int i = 0; i < cirTimeArr1.length; i++) { if(!"".equals(cirTimeArr1[i].trim())){ String timea = _date + " " +cirTimeArr1[i].trim()+":00"; if(dateformat.parse(timea).after(dateformat.parse(updatedate))){//计划时间要在发布时间之后 prograssTime += timea; if(i cirTimeArr = new ArrayList(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); //计划截止时间 Date expirationTime; expirationTime = sdf.parse(sdf1.format(expirationData)+" 23:59:59");/*+cirTimeArr[cirTimeArr.length-1]);*/ if(expirationTime != null && expirationTime.before(currDate)){ /*************/ return "";//抛出异常:当前计划已结束(过期) } for (int i = 0; i < cirTimeArr1.length; i++) { if(!"".equals(cirTimeArr1[i].trim())){ cirTimeArr.add(cirTimeArr1[i].trim()); } } //用于记录当前计划时间下标 int k = 0; if(cirTimeArr.size()>1){ //如果劈开有多个时间点,则判断哪个时间最近,取最近的时间 //cirTimeArr.get(0)格式为16:30,需再劈开 //数组长度 int arrLength = cirTimeArr.size(); //数组中第一个时间点 String hour1 = cirTimeArr.get(0).substring(0,cirTimeArr.get(0).indexOf(":")); //数组中最后一个时间点 String hour2 = cirTimeArr.get(arrLength-1).substring(0,cirTimeArr.get(arrLength-1).indexOf(":")); if(_time <= Integer.parseInt(hour1)){//如果在第一个时间点之前,则计划时间为第一个时间点 k = 0; //第二个时间点 aftProTime = _date + " " + pretime(cirTimeArr.get(1)); }else if(_time >= Integer.parseInt(hour2)){//如果在最后一个时间点之后,则计划时间为最后一个时间点 k = arrLength-1; //最后一个时间点 preProTime = _date + " " + pretime(cirTimeArr.get(arrLength-1)); }else if(Integer.parseInt(hour1) < _time && _time< Integer.parseInt(hour2)){//若是在第一个和最后一个时间点之间 int j = 0; //遍历周期性时间,判断当前时间处于哪两个时间点之间 while((j+1) <= cirTimeArr.size()-1){ hour1 = cirTimeArr.get(j).substring(0,cirTimeArr.get(j).indexOf(":")); hour2 = cirTimeArr.get(j+1).substring(0,cirTimeArr.get(j+1).indexOf(":")); if(Integer.parseInt(hour1) <= _time && _time< Integer.parseInt(hour2)){ if(_time < Integer.parseInt(hour2)-1){//如果在第二个计划时间-1小时之前,则第一个时间为计划时间 k = j; if(k != 0){ //若当前计划时间不是第一个 preProTime = _date + " " + pretime(cirTimeArr.get(k)); } aftProTime = _date + " " + pretime(cirTimeArr.get(k+1)); }else{ k = j+1; if(k != (arrLength-1)){ //若当前计划时间不是最后一个 aftProTime = _date + " " + pretime(cirTimeArr.get(k+1)); } preProTime = _date + " " + pretime(cirTimeArr.get(k)); } } j++; } } prograssTime += cirTimeArr.get(k); }else{ //若数组中只有一个值 prograssTime += cirTimeArr.get(0); } } }else if("临时性".equals(writeDataType)){ preProTime = dateformat.format(startDate); aftProTime = _date + " 23:59"; //如果填报时间表类型是临时性,临时性时间格式为:“2015-11-27 11:28,2015-12-17 10:28,2015-12-27 11:28”; String[] temArr = temporaryTime.split(","); int temArrLength = temArr.length; int k = 0; if(temArr.length>1){//两个或两个以上时间点 if(currDate.before(dateformat1.parse(temArr[0]))){//若当前时间在第一个时间点之前,则计划时间为第一个时间,监控的结尾时间为下个时间点点前一个小时 String aftDay = temArr[1].substring(0,10); String afthour = temArr[1].substring(11,13); aftProTime = aftDay + " " + afthour + ":00"; }else if(currDate.after(dateformat1.parse(temArr[temArrLength-1]))){ //若当前时间在最后时间点之后,则计划时间为最后后一个时间,监控的开始时间为上一个计划时间,监控的结尾时间为今日23点59分 k = temArrLength-1; preProTime = temArr[temArrLength-2]; }else{ int j = 0; while((j+1) <= temArrLength-1){ Date date1 = dateformat1.parse(temArr[j]); Date date2 = dateformat1.parse(temArr[j+1]); if(currDate.before(date2) && currDate.after(date1)){ Calendar caldate2 = Calendar.getInstance(); caldate2.setTime(date2);//date 换成已经已知的Date对象 caldate2.add(Calendar.HOUR_OF_DAY, -1);// 第二个计划时间的前一个小时 if(currDate.before(caldate2.getTime())){//如果在第二个计划时间-1小时之前,则第一个时间为计划时间 k = j; if(k != 0){ //若当前计划时间不是第一个,则监控开始时间为k前一个计划时间 Calendar caldate1 = Calendar.getInstance(); caldate1.setTime(dateformat1.parse(temArr[k])); caldate1.add(Calendar.HOUR_OF_DAY, -1);// 前一个小时 preProTime = dateformat1.format(caldate1.getTime()); } aftProTime = dateformat1.format(caldate2.getTime()); }else{ k = j+1; if(k != (temArrLength-1)){ //若当前计划时间不是最后一个 Calendar caldate3 = Calendar.getInstance(); caldate3.setTime(dateformat1.parse(temArr[k+1])); caldate3.add(Calendar.HOUR_OF_DAY, -1); aftProTime = dateformat1.format(caldate3.getTime()); } Calendar caldate4 = Calendar.getInstance(); caldate4.setTime(dateformat1.parse(temArr[k])); caldate4.add(Calendar.HOUR_OF_DAY, -1); preProTime = dateformat1.format(caldate4.getTime()); } } j++; } } prograssTime = temArr[k]; }else{ prograssTime = temArr[0]; } } return preProTime + "," + prograssTime + "," + aftProTime; } /** * 解析字符串,返回前一个小时时间 * 解析16:30字符串,返回15:30字符串 * @param time * @return */ private String pretime(String time){ String hour = time.substring(0,time.indexOf(":")); String minit = time.substring(time.indexOf(":"),time.length()); Integer prehour = Integer.parseInt(hour)-1; return prehour.toString()+""+minit; } // public static void main(String[] args) { // QueryReportProgrammeDaoImpl dao = new QueryReportProgrammeDaoImpl(); // try { // dao.loadReportProgramme("320144176508172800000071100000"); // } catch (Exception e) { // // e.printStackTrace(); // } // } @Override public String send(/*String fd_id, String userId,*/ String comp_id) { Msg m = new Msg(); String sql = "select c.real_name,c.mobile from sys_user_role_rel a,sys_dept_user b,sys_user_info c " + "where a.role_id='R002105430205' and a.user_id=b.user_id and b.dept_id in (" + comp_id+ ") and a.user_id=c.user_id"; log.info("sendMsgToEmergencysql====" + sql); StringBuffer sbtel = new StringBuffer(); StringBuffer sbname = new StringBuffer(); StringBuffer sb = new StringBuffer(); sbtel.append(""); sb.append(""); sbname.append(""); sb.append("{\"list\":"); try { List tempList = persistence.getSearchResult(99, sql.toString()); if (tempList == null || tempList.size() == 0) { } else { for (int i = 0; i < tempList.size(); i++) { sbtel.append(tempList.get(i)[1]==null?"18588592971":tempList.get(i)[1]+";"); sbname.append(tempList.get(i)[0]+";"); } } sb.append("\""); if(sbname.length()>0){ sb.append(sbname.substring(0, sbname.length()-1)); } sb.append("|"); if(sbtel.length()>0){ sb.append(sbtel.substring(0, sbtel.length()-1)); } sb.append("\"}"); } catch (PersistenceException e) { e.printStackTrace(); } return sb.toString(); } @Override public List loadReportDeptById(String[] deptIdArr, String earlyWarningId, String reportType, String progressTime, String planId) throws Exception { return null; } public List> loadReportPlanById(String planId){ String sql = "select FD_OBJECTID,EARLY_WARNING_ID,PROGRAMME_NAME,START_TIME,EXPIRATION_DATE,REPORT_TYPE,WRITE_DEPT_ID,WRITE_DATE_TYPE,CIRCLE_TIME,TEMPORARY_TIME,WRITER,WRITE_TIME,INPUT_DEPT,EARLY_WARNING_NAME,UPDATEDATE,IS_DEL,WRITE_DEPT_NAME,IS_RELEASE,IS_ALERT,EARLY_WARNING,USER_ID from ECM_EM_ALERT_REPORT_PLAN where FD_OBJECTID='"+planId+"'"; try { List> list = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(320, sql); return list; } catch (PersistenceException e) { e.printStackTrace(); } return null; } public List loadReportPlanByDeptId(String preTime, String aftTime, String planId, String deptId, String reportType) { String sql = "select FD_OBJECTID from ECM_EM_ALERT_REPORT_INPUT where PLAN_ID='"+planId+"' and INPUT_UNIT='"+deptId+"' and IS_RELEASE=1 and UPDATEDATE between '"+preTime+"' and '"+aftTime+"' and is_del=0 and report_type='"+reportType+"'"; try { List tempList = persistence.getSearchResult(99, sql.toString()); return tempList; } catch (PersistenceException e) { e.printStackTrace(); } return null; } public int getLastRoundTime(String params){ if(params!=null || !"".equals(params)){ if(params.indexOf(";")==-1 && params.indexOf(":")>0){ return Integer.parseInt(params.split(":")[0]); }else{ String[] timeArr = params.split(";"); int num = 0; for(int i=0;i list = new ORGTemplate().getResultList(sql, compId,"%"+compId+"%",roleId,fd_id); if(list!=null&&list.size()>0){ flag = true; } } catch (SQLStringException e) { e.printStackTrace(); } return flag; } } class compareList implements Comparator{ @Override public int compare(String o1, String o2) { int i = o1.compareTo(o2); if(i==0){ return 0; }else if(i>0){ return 1; }else{ //return -1; if(o1.equals("本级计划") && !o2.equals("上级计划")|| o2.equals("本级计划")&&!o1.equals("上级计划")){ return 1; }else{ return -1; } } } }